MIDI instruments

Anyone know how to select/load different instruments into Java’s MIDI API. MidiSystem.getSynthesizer().getAvailableInstruments() returns nothing. I have tried other ways, including trying to load a Soundbank file. Nothing has worked. The API exists to do this, but is it just not implemented?

The default sound is piano and I want to try other instruments, especially guitar.

It seems that what you want to change is not the synthesizer but the patch, or more specifically, do a ‘program change’.
Probably something like:


ShortMessage msg = new ShortMessage();
msg.setMessage(ShortMessage.ROGRAM_CHANGE, 1, 2);
MidiSystem.getReceiver().send(msg, -1);

This will set program 2 on midi channel 1.
Or have a look at MidiChannel.programChange(int bank, int program) or MidiChannel.programChange(int program).
Mind you, I’ve never used MIDI using JavaSound and I didn’t actually test this but maybe this will point you in the right direction :stuck_out_tongue:

Thanks. I 'll give it a try.

At first, I coulnd’t figure out how to use the PROGRAM_CHANGE, but I found a table of what the values mean on the Internet, so now I have it.

Thanks erikd.

[quote]Anyone know how to select/load different instruments into Java’s MIDI API. MidiSystem.getSynthesizer().getAvailableInstruments() returns nothing. I have tried other ways, including trying to load a Soundbank file. Nothing has worked. The API exists to do this, but is it just not implemented?

The default sound is piano and I want to try other instruments, especially guitar.
[/quote]
You need to open the synth first before calling getAvailableInstruments and loading soundbanks.