How can i send a Midi Message to a specific Midi Port

孤街浪徒 提交于 2020-01-16 18:59:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!