嘿,我正在尝试将 MIDI 数据从 Java 类发送到通过 USB 连接的 MIDI 设备。我像 2 年前那样做过一次,它奏效了,但不知何故我再也找不到这个项目了。
示例 Java 代码运行良好;
myMsg = new ShortMessage();
myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93);
timeStamp = -1;
Receiver rcvr = MidiSystem.getReceiver();
rcvr.send(myMsg, timeStamp);
简单的东西。5 行代码和消息出现在设备上。问题是,这样,只有标准设备被设置并准备好接收 MIDI。我不能要求我的用户每次想要使用我的应用程序时都将他们想要的设备设置为标准设备。(Receiver
作为我连接到的物理设备输入的输出目的地/端口)
我现在正在尝试通过执行以下操作来设置接收器:
MidiDevice.Info[] infoA=MidiSystem.getMidiDeviceInfo();//array where all the device info goes
for (int x=0;x<infoA.length;x++){
System.out.println("in "+infoA[x]); //this displays all the devices
}
MidiSystem.getMidiDevice(infoA[d]); //d is set to an integer that represents the item number on the device list of the device I wanna send MIDI to
System.out.println(infoA[d]);//last check if the correct device is selected
MidiDevice MidiOutDevice = MidiSystem.getMidiDevice(infoA[d]); //setting this to "my" device in order to set the Receiver
maschineReceiver= MidiOutDevice.getReceiver();
Sequencer MidiOutSequencer = MidiSystem.getSequencer();
MidiOutSequencer.getTransmitter().setReceiver(maschineReceiver); //probably unnecessary last 2 line but I gave this a try in case it helps
如果我现在这样做maschineReceiver.send(myMsg, timeStamp);
,什么都不会发生。我也尝试了不同的设备,但并没有变得更好。我确信这不是一件非常困难的事情,因为这是我在 2 年前实现的,当时我的编码技能很糟糕,但我现在找不到错误,无论我多久重读一次 Java文档,无论我做什么,它都不起作用。
提前致谢