I am trying to play a list of music strings using a for loop.
While the first music string is played correctly along with the base, the second and the subsequent do not play simultaneously.
Am i missing something here?
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws InterruptedException {
List<String> musicStringList = new ArrayList<>();
musicStringList.add("G5i Ri G5i Ri G5i Ri G5i Ri G5i Ri G5i Ri G5i Ri G5i Ri");
musicStringList.add("D5i Ri D5i Ri D5i Ri D5i Ri D5i Ri D5i Ri D5i Ri D5i Ri");
musicStringList.add("E5i Ri E5i Ri E5i Ri E5i Ri E5i Ri E5i Ri E5i Ri E5i Ri");
Player player = new Player();
String base = "Cmajw Gmajw";
for (int i = 0; i < musicStringList.size(); i++) {
List<Pattern> patterns = new ArrayList<>();
String voice = musicStringList.get(i);
Pattern p0 = new Pattern(voice);
p0.setInstrument("Flute");
Pattern p1 = new Pattern(base);
p1.setInstrument("Piano");
patterns.add(p0);
patterns.add(p1);
for (int j = 0; j < patterns.size(); j++) {
patterns.get(j).setVoice(j);
}
Pattern[] patternsArr = patterns.toArray(new Pattern[0]);
player.play(patternsArr);
}
}