我如何将Midi消息发送到特定的Midi端口

我如何将Midi消息发送到特定的Midi端口

本文介绍了我如何将Midi消息发送到特定的Midi端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将Note_On消息发送到名为LoopBe的虚拟Midi接口(链接到站点).如何获取Receiver对象(Java)?我尝试了下面的代码,但在rcvr.send()上收到了NullPointerException.

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

我尝试了rcvr = MidiSystem.getReceiver(),它起作用了,但是它将消息发送到com.sun.media.sound.MidiOutDevice$MidiOutReceiver@404b9385.

I tried rcvr = MidiSystem.getReceiver() and it worked, but it sends the message to com.sun.media.sound.MidiOutDevice$MidiOutReceiver@404b9385.

推荐答案

您应打开设备,然后再使用它.

这篇关于我如何将Midi消息发送到特定的Midi端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 16:50