gpt4 book ai didi

javascript - 为什么这个 Web MIDI API 代码没有检测到 MIDI 事件?

转载 作者:太空狗 更新时间:2023-10-29 11:13:26 27 4
gpt4 key购买 nike

我正在编写一个 Chrome 应用程序,使用当前稳定版本的 Chrome (42.0.2311.152)。我在 Linux 和我的 Chromebook 上都遇到了这个问题。

我有一个正在被识别的 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 键盘上的键时,没有检测到任何事件。

我做错了什么?

最佳答案

根据 http://caniuse.com/#feat=midi , MIDI 支持已添加到 Chrome 43。要让网络 MIDI 在旧版本的 chrome 中工作,您需要在 chrome 设置中将其作为“实验性功能”启用,并且您需要安装 jazz 插件 http://jazz-soft.net/doc/Jazz-Plugin/ .

我已经跳过了让“实验性”MIDI 在我的计算机上工作的重重障碍,但在您的情况下,更新浏览器可能是最简单的方法。

关于javascript - 为什么这个 Web MIDI API 代码没有检测到 MIDI 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30473683/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com