I am trying to create a program that can play notes to an MIDI Keyboard. I couldn't get the whole program to work, but am now trying to create a smaller proof of concept program to try and work it out.
For this I am trying to play a .mid file to the keyboard (A Casio CTK-3000), MidiPlay can play to the keyboard. The problem is that when I try to play to the keyboard in my program, it just plays nothing. My code is below:
public class midiOut {
public static void main(String[] args) throws IOException, MidiUnavailableException, InvalidMidiDataException
{
while(true) {
//List Midi Devices
MidiDevice.Info[] midiInfo = MidiSystem.getMidiDeviceInfo();
int i = 0;
for (MidiDevice.Info info : midiInfo) {
System.out.println(i + ": " +info.getName());
i+=1;
}
//Select Device
Scanner in = new Scanner(System.in);
int input = in.nextInt();
if(input == -1)
{
break;
}
//Get Device and Open it
MidiDevice selectedDevice = MidiSystem.getMidiDevice(midiInfo[input]);
System.out.println(selectedDevice.getDeviceInfo().getName());
selectedDevice.open();
//Get Sequencer and Receiver, load the File and start playing
Receiver receiver = selectedDevice.getReceiver();
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.getTransmitter().setReceiver(receiver);
sequencer.open();
sequencer.setSequence(MidiSystem.getSequence(new File("C:\\Users\\Harris Mirza\\Downloads\\PennyLane.mid")));
sequencer.start();
selectedDevice.close();
}
}
}