【问题标题】:How can i send a Midi Message to a specific Midi Port如何将 Midi 消息发送到特定的 Midi 端口
【发布时间】:2018-07-09 02:03:13
【问题描述】:

我想将 Note_On 消息发送到一个名为 LoopBe (Link to Site) 的虚拟 Midi 接口。如何获取 Receiver 对象(Java)? 我尝试了下面的代码,但在 rcvr.send() 上出现 NullPointerException。

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());
        }
    }
  }
}

我尝试了rcvr = MidiSystem.getReceiver(),它成功了,但它会将消息发送到 com.sun.media.sound.MidiOutDevice$MidiOutReceiver@404b9385。

【问题讨论】:

    标签: java midi javasound


    【解决方案1】:

    您应该在使用该设备之前open

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 2015-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多