cwilso / WebMIDIAPIShim

Polyfill using the Jazz NPAPI MIDI plugin to implement the Web MIDI API on Mac and Windows.
380 stars 53 forks source link

Shim updated according to the latest W3C draft #56

Closed abudaan closed 9 years ago

abudaan commented 9 years ago

In short:

MIDIAccess.inputs and MIDIAccess.outputs are still implemented as functions in Chromium. Therefor I have also added a wrapper for Chromium's WebMIDI implementation, see the init method.

According to the new draft it should be possible to loop over inputs and outputs like so:

MIDIAccess.inputs.forEach(function(key, value){
    console.log('input id:', key, ' input name:', value.name);
});

But in Chrome's WebMIDI implementation this doesn't work yet. The functionality is implemented in the shim and works correctly but to make the examples work with both the Jazz plugin and native WebMIDI, I have used the iterator in the web examples to loop over inputs and outputs:

var iterator = MIDIAccess.inputs.values();
var data;
while((data = iterator.next()).done !== true){
    port = data.value;
    console.log('input id:', port.id, ' input name:', port.name);
}
notator commented 9 years ago

Many thanks for that! I haven't tested it all, but it solved a big problem I've been facing recently -- writing client code that works both in Firefox with the Jazz plugin, and in Chrome with its Web-MIDI-API flag enabled. All I needed was to adapt the code in the comment above:

var iterator = MIDIAccess.inputs.values();
var data;
while((data = iterator.next()).done !== true){
    port = data.value;
    console.log('input id:', port.id, ' input name:', port.name);
}

Bravo, and thanks again.