This may be a stupid question, but it's hard for me to figure it out.
I wrote a method that uses LinkedList to navigate through loaded MIDI instruments. I want to make the next and previous button so that every time you click the button, you go through the LinkedList.
If I hardcode itr.next();or itr.previous();several times, I can go through LinkedList
public void setInsturment(Synthesizer start,MidiChannel currentChannel[])
{
try
{
start.open();
Soundbank bank = start.getDefaultSoundbank();
start.loadAllInstruments(bank);
LinkedList<Instrument> currentInstrument = new LinkedList<Instrument>();
Instrument instrs[] = start.getLoadedInstruments();
currentInstrument.add(instrs[0]);
currentInstrument.add(instrs[1]);
currentInstrument.add(instrs[2]);
currentInstrument.add(instrs[3]);
currentInstrument.add(instrs[4]);
ListIterator itr = currentInstrument.listIterator();
itr.next();
itr.next();
itr.next();
currentChannel[1].programChange(0,itr.nextIndex());
}
catch(MidiUnavailableException e)
{
System.out.print("error");
}
}
I have a lot of problems creating a button that can go through the list. Is there an effective way to do this? I tried something like this without success.
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == nextButton)
{
sound.nextInstrument();
}
public void nextInstrument()
{
itr.next();
}
Thanks in advance guys!
source
share