嗨,我正在尝试将来自Java类的MIDI数据发送到通过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);
简单的东西。只需要五行代码,消息就能出现在设备上。问题是,这种方式只设置了标准设备,并且准备好接收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);
,什么都不会发生。我也尝试了不同的设备,但情况并没有好转。我确信这不是一件非常困难的事情,因为两年前我还是个编码技能很差的人,但我现在无论怎么重读Java文档,都找不到错误,无论我怎么做都不起作用。提前感谢你。
MidiOutDevice.open();
? - sasankad