I've been trying to understand how to use the Web MIDI API on chrome. I'm trying to follow the information on the MDN docs and I'm able to get information about the Virtual MIDI Piano Keyboard I have installed on my macOS.
Using the following code I can verify that I'm able to get the information about the MIDI device
navigator.requestMIDIAccess()
.then(onMIDISuccess, onMIDIFailure);
function onMIDISuccess(midiAccess) {
console.log(midiAccess);
var inputs = midiAccess.inputs;
var outputs = midiAccess.outputs;
}
function onMIDIFailure() {
console.log('Could not access your MIDI devices.');
}
But I don't get prompted to allow the website access to my MIDI device as I would expect.
I tried then to use the code snipped found on the MDN docs to get onmidimessage
.
// Printing all messages to console
navigator.requestMIDIAccess().then(midiAccess => {
Array.from(midiAccess.inputs).forEach(input => {
input[1].onmidimessage = console.log;
})
});
https://developer.mozilla.org/en-US/docs/Web/API/MIDIMessageEvent
I don't get any error, I can console.log(input[1])
and see results. But when I then hit the keys on the Virtual MIDI Piano Keyboard there is no activity, I'm not seeing anything logged to the console.
So I'm very confused and can't find any information about how to get this to work. Does anybody have any ideas on how to get the events from the MIDI device?