2015-05-27 70 views
3

我正在使用Chrome的當前穩定版本(42.0.2311.152)編寫Chrome應用程序。我在Linux和Chromebook上都遇到了這個問題。爲什麼這個Web MIDI API代碼沒有檢測到MIDI事件?

我有一個USB MIDI鍵盤被識別,但沒有檢測到MIDI事件。我檢查過其他程序,並確定我的設備正在發送MIDI事件。

這裏是我的代碼:

function midihandler(event) { 
    console.log("Received MIDI event"); 
    var msg = "Recieved MIDI event "; 
    for (i=0 ; i < event.data.length ; i++) { 
    msg += "0x" + event.data[i].toString(16) + " "; 
    } 
    console.log(msg); 
} 

function setupMIDI() { 
    navigator.requestMIDIAccess().then(
    function (m) { 
     console.log("MIDI initialized"); 
     m.inputs.forEach(
     function (entry) { 
      console.log("detected MIDI input device " + entry.name); 
      entry.onmidimessage = midihandler; 
      for (var key in entry) { 
      console.log("entry." + key + " = " + entry[key]); 
      } 
     } 
    ); 
    }, 
    function (msg) { console.log("error initializing MIDI: " + msg); } 
    ); 
} 


window.onload = function() { 
    console.log("window.onload called"); 
    setupMIDI(); 
}; 

控制檯輸出我得到的是:

window.onload called 
MIDI initialized 
detected MIDI input device MPKmini2 MIDI 1 
entry.onmidimessage = function midihandler(event) { 
    console.log("Received MIDI event"); 
    var msg = "Recieved MIDI event "; 
    for (i=0 ; i < event.data.length ; i++) { 
    msg += "0x" + event.data[i].toString(16) + " "; 
    } 
    console.log(msg); 
} 
entry.ondisconnect = null 
entry.version = USB-Audio/ALSA library version 1.0.25 
entry.type = input 
entry.name = MPKmini2 MIDI 1 
entry.manufacturer = AKAI 
entry.id = 24:0 MPKmini2 MIDI 1 
entry.addEventListener = function addEventListener() { [native code] } 
entry.removeEventListener = function removeEventListener() { [native code] } 
entry.dispatchEvent = function dispatchEvent() { [native code] } 
detected MIDI input device Midi Through Port-0 
entry.onmidimessage = function midihandler(event) { 
    console.log("Received MIDI event"); 
    var msg = "Recieved MIDI event "; 
    for (i=0 ; i < event.data.length ; i++) { 
    msg += "0x" + event.data[i].toString(16) + " "; 
    } 
    console.log(msg); 
} 
entry.ondisconnect = null 
entry.version = ALSA library version 1.0.25 
entry.type = input 
entry.name = Midi Through Port-0 
entry.manufacturer = 
entry.id = 14:0 Midi Through Port-0 
entry.addEventListener = function addEventListener() { [native code] } 
entry.removeEventListener = function removeEventListener() { [native code] } 
entry.dispatchEvent = function dispatchEvent() { [native code] } 

也就是說,設備被識別出來,並onmidimessage處理器似乎設置。

但是,當我按下MIDI鍵盤上的按鍵時,未檢測到事件。

我在做什麼錯?

+0

您是否在正確的MIDI通道上接收?鍵盤是否真的在該頻道上傳輸? –

+0

我對[the spec](http://webaudio.github.io/web-midi-api/)的閱讀使我相信,無論MIDI通道如何,接收到的所有MIDI消息都應調用處理程序。當然,我可能會誤解。 – fcahoon

+0

我對MIDI的使用經驗總的來說就是接收設備可以通過頻道進行過濾。檢查接收設備的文檔,看看它是否需要編程來指定接收通道,或者是否可以將其設置爲OMNI(在所有通道上接收)。 –

回答

2

根據http://caniuse.com/#feat=midi,MIDI支持已添加到Chrome 43中。爲了使網絡MIDI能夠在舊版本的chrome中工作,您需要在chrome設置中將其啓用爲「實驗功能」,並且您需要安裝爵士樂插件http://jazz-soft.net/doc/Jazz-Plugin/

我已經跳過了讓'實驗性'MIDI在我的電腦上工作的箍環,但在您的情況下,它可能會更容易更新您的瀏覽器。