I overlooked something simple. The default Sequencer
returned by MidiSystem.getSequencer();
has a Transmitter which in turn has a setReceiver()
method to add a MIDI Out device. But you must have the correct MIDI Out device. I had chosen a wrong device by accident.
So first the correct output device is chosen by looking through the DeviceInfos
array, picking the correct device, then instatiating the the Sequencer
with the correct Receiver
.
MidiDevice.Info[] MidiDeviceInfos = MidiSystem.getMidiDeviceInfo();
//find the suitable device number here, based on some criteria
MidiDevice MidiOutDevice = MidiSystem.getMidiDevice(MidiDeviceInfos[DEVICE_NUMBER]);
Receiver MidiOutReceiver = MidiOutDevice.getReceiver();
Sequencer MidiOutSequencer = MidiSystem.getSequencer();
//Add the new MIDI out device here.
MidiOutSequencer.getTransmitter().setReceiver(MidiOutReceiver);
MidiOutSequencer.open();
Now you can open()
a file and play()
it, but since the default MIDI Out device is also used you may hear General MIDI/Soundfont MIDI sounds too. This threw me off at first but now the MIDI device will also be sending the opened sequence out of your added Receiver
.