Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将MIDI与Java声音API结合使用?_Java_Audio_Midi_Javasound - Fatal编程技术网

如何将MIDI与Java声音API结合使用?

如何将MIDI与Java声音API结合使用?,java,audio,midi,javasound,Java,Audio,Midi,Javasound,我尝试用JavaSoundAPI实现一个简单的MIDI播放器。我不熟悉Java,但不熟悉MIDI编程。我无法正确理解soundAPI。我想做的是选择一个设备,打开它,向它发送短MIDI消息,然后关闭它。使用SoundAPI时,必须执行上述操作,此外还必须抓取发射器和接收器,打开发射器并将消息发送给接收器(对吗??) 我设法掌握了MIDI系统,并列出了所有可用设备的属性,这对于初学者来说很好。我可以打开设备,但在打开发射机时会抛出MidiUnavailableException异常。我已经总结了在

我尝试用JavaSoundAPI实现一个简单的MIDI播放器。我不熟悉Java,但不熟悉MIDI编程。我无法正确理解soundAPI。我想做的是选择一个设备,打开它,向它发送短MIDI消息,然后关闭它。使用SoundAPI时,必须执行上述操作,此外还必须抓取发射器和接收器,打开发射器并将消息发送给接收器(对吗??)

我设法掌握了MIDI系统,并列出了所有可用设备的属性,这对于初学者来说很好。我可以打开设备,但在打开发射机时会抛出
MidiUnavailableException
异常。我已经总结了在下面的函数
send\u simple\u message
中必须遵循的所有步骤。我有两个问题:

  • 我的推理正确吗?我现在还不想使用音序器,我现在尝试重建一种使用MIDI的特定方式,这是我在Delphi中使用Windows API时习惯的方式:打开设备,向其发送消息,并在准备好后关闭它
  • 如果是这样,为什么在尝试打开变送器时引发异常?这发生在我尝试打开的所有MIDI设备上
任何帮助都将不胜感激

  public int send_simple_message (int device_no, int byte_1, int byte_2, int byte_3) throws InvalidMidiDataException
  {
     MidiDevice Current_Device; // Refers to MIDI device
     Transmitter Sender;        // its Transmitter
     Receiver Getter;           // the sender of the transmitter
     ShortMessage message;      // MIDI message to be sent to Receiver

     try 
     {  // Get requested device
        Current_Device = MidiSystem.getMidiDevice (Device_Info [device_no]);
        System.out.println ("Selected: " + Current_Device.getDeviceInfo ().getName ());

        Current_Device.open();
        System.out.println ("Opened: " + Current_Device.getDeviceInfo ().getName ());

        Sender = Current_Device.getTransmitter (); // <== throws exception
        System.out.println ("Transmitter: " + Sender.toString ());

        Getter = Sender.getReceiver ();
        message = new ShortMessage (byte_1, byte_2, byte_3);
        Getter.send (message, -1);

        Sender.close ();
        Current_Device.close ();
     } catch (MidiUnavailableException e)
     {
        System.err.println ("MIDI device is unavailable");
        return MIDI_OPEN_NOT_AVAILABLE;
     } // try..catch
     return MIDI_ACTION_OK;
  } // send_simple_message //
public int send_simple_消息(int device_no,int byte_1,int byte_2,int byte_3)引发InvalidMidDataException
{
MIDI设备当前\u设备;//指MIDI设备
发送器发送器;//它的发送器
Receiver Getter;//发送器的发送器
短消息;//要发送给接收方的MIDI消息
尝试
{//获取请求的设备
当前设备=MidiSystem.getMidiDevice(设备信息[设备编号]);
System.out.println(“选中:“+Current_Device.getDeviceInfo().getName());
当前_设备。打开();
System.out.println(“打开:+Current_Device.getDeviceInfo().getName());

发送方=当前设备。getTransmitter();//1)为了更快地获得更好的帮助,请发布一个。2)如果第一个
尝试
失败,第二个和第三个也会失败。为什么不把它们都放在一个
try
块中呢?@Andrew,说得好。我根据你的建议缩写了代码。我使用多个
try
的原因是,我可以更好地找出失败的原因对于这个例子,
println
就足够了。”…我根据您的建议缩写了代码。“
1)”如果需要所有代码来满足其余部分,则“short”通常可以高达150 LOC。2)其余部分不满足。