3

I'm writing a Chrome app, using the current stable build of Chrome (42.0.2311.152). I have this problem both on Linux and on my Chromebook.

I have a USB MIDI keyboard which is being recognized, but no MIDI events are detected. I have checked with other programs and am sure my device is sending MIDI events.

Here's my code:

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();
};

The console output I get is:

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] }

That is, the devices are recognized, and the onmidimessage handler appears to be set.

Yet, no events are detected when I press the keys on my MIDI keyboard.

What am I doing wrong?

Xan
  • 74,770
  • 16
  • 179
  • 206
fcahoon
  • 73
  • 1
  • 6
  • Are you receiving on the correct MIDI channel? Is the keyboard actually transmitting on that channel? – Robert Harvey May 27 '15 at 05:16
  • My reading of [the spec](http://webaudio.github.io/web-midi-api/) led me to believe that all MIDI messages received should invoke the handler, regardless of MIDI channel. Of course, I could be mistaken. – fcahoon May 27 '15 at 13:43
  • My experience of MIDI in general is that the receiving device could be filtering by channel. Check your receiving device's documentation and see if it needs to be programmed to specify the receive channel, or if you can set it to OMNI (receive on all channels). – Robert Harvey May 27 '15 at 14:13

1 Answers1

2

According to http://caniuse.com/#feat=midi, MIDI support was added to Chrome 43. To get web MIDI working in older versions of chrome, you need to enable it as an 'experimental feature' in the chrome settings, and you need to install the jazz plugin http://jazz-soft.net/doc/Jazz-Plugin/.

I've jumped through the hoops of getting 'experimental' MIDI working on my computer, but in your case it'll probably be easiest to just update your browser.

Raphael Serota
  • 2,157
  • 10
  • 17