如何将 Midi 消息发送到特定的 Midi 端口
How can i send a Midi Message to a specific Midi Port
我想发送 Note_On 消息到一个名为 LoopBe (Link to Site) 的虚拟 Midi 接口。我如何获得接收者对象 (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。
您应该 open 使用设备。
我想发送 Note_On 消息到一个名为 LoopBe (Link to Site) 的虚拟 Midi 接口。我如何获得接收者对象 (Java)?
我尝试了下面的代码,但在 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。
您应该 open 使用设备。