问题
I want to send Note_On Message to a virtual Midi Interface called LoopBe (Link to Site). How do i get the Receiver object (Java)?
I tried the Code below but I get a NullPointerException on rcvr.send()
.
public class test {
public static Receiver rcvr;
public static void main(String[] args) throws InvalidMidiDataException, MidiUnavailableException {
String scene = "Test";
getReceiver();
ShortMessage myMsg = new ShortMessage();
// Nachricht Channel Note Lautstärke
myMsg.setMessage(ShortMessage.NOTE_ON, 0, 1, 127);
rcvr.send(myMsg, -1);
System.out.println("Szene " + scene + " ausgelöst");
}
public static void getReceiver() throws MidiUnavailableException {
MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
for(Info devices : infos )
{
System.out.println(devices.getName() + " : " + devices.getDescription());
if(devices.getName() == "LoopBe Internal MIDI" && devices.getDescription() == "No details available") {
MidiDevice device = MidiSystem.getMidiDevice(devices);
rcvr = device.getReceiver();
System.out.println("Receiver: " + rcvr.toString());
}
}
}
}
I tried rcvr = MidiSystem.getReceiver()
and it worked, but it sends the message to com.sun.media.sound.MidiOutDevice$MidiOutReceiver@404b9385.
回答1:
You should open the device before using it.
来源:https://stackoverflow.com/questions/51232939/how-can-i-send-a-midi-message-to-a-specific-midi-port