I am using a track to play my noteOn/noteOff events and everything works as intended, the problem I am having is that I would like to change the instruments that is being used within the track.
I've come up with the following code which is designed invoke the "program change" command on all the MIDI channels with the new instrument, the problem I am having is working out how to apply this to the track so the instruments is different.
public void LoadInstrument()
for(int i = 0; i < instruments.length; i++)
if(instruments.getName() == "Clean Guitar")
instrumentToLoad = instruments[i];
drumPatch = instrumentToLoad.getPatch();
I've seen that you can send the Track a PROGRAM_CHANGE event to signify the instrument is changing but I'm not sure how to go about creating the object to hold the necessary information and adding it to the Track.
(Apologies for the poor code layout, I can't seem to find a suitable markup type)
After doing a little more digging around I've found the solution:
ShortMessage instrumentChange = new ShortMessage();
instrumentChange.setMessage(ShortMessage.PROGRAM_CHANGE, 0, 6,0);
//MidiEvent instrumentChange = new MidiEvent(ShortMessage.PROGRAM_CHANGE,drumPatch.getBank(),drumPatch.getProgram());
Note: The "**6**" parameter in the .setMessage method is the number of the instrument to play.