Reputation: 1608
I'm having trouble setting the instrument in the javax.sound.midi package.
Synthesizer synthesizer = MidiSystem.getSynthesizer();
MidiChannel[] channels = synthesizer.getChannels();
channels[0].programChange(5);
System.out.println(channels[0].getProgram());
From the documentation on MidiChannel, calls to channels[0].programChange(int) should change instrument that the MidiChannel is set to and immediately reflected in channels[0].getProgram(). However my program prints "0", indicating nothing has changed.
Later on in the code, I'm using MidiChannel.getSequencer() to play midi sound successfully (although only with the default instrument.)
Am I going about trying to set the instrument in the wrong way?
Upvotes: 4
Views: 4157
Reputation: 9966
I came across the same problem as you, although we're not using the exact same implementation for making MIDI messages feel free to look at my question as it may be of some use to you:
Changing instrument in Java during playback
Upvotes: 3