sskates
sskates

Reputation: 1608

Setting instrument channels using the javax.sound.midi package

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

Answers (1)

Jamie Keeling
Jamie Keeling

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

Related Questions