簡體   English   中英

Java設置MIDI輸出接收器

[英]Java set MIDI Out receiver

嘿我正在嘗試將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充當我連接的物理設備輸入的輸出目標/端口)

我現在正嘗試通過執行以下操作來設置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文檔,它無論我做什么都行不通。

提前致謝

要為您的程序實際預留設備,您需要使用openMidiDevice方法:

if (!(device.isOpen())) {
    try {
      device.open();
  } catch (MidiUnavailableException e) {
          // Handle or throw exception...
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM