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

Updated to the WebMIDI API implementation in Chrome 43 #60

Closed abudaan closed 9 years ago

abudaan commented 9 years ago

Changes

MIDIInput and MIDIOutput:

MIDIAccess:

When a device is connected or disconnected a MIDIConnectionEvent is dispatched from both the MIDIAccess and the MIDIInput or MIDIOutput that has been connected or disconnected.

The dispatched events are no longer instances of the generic Event, they are instances of the classes MIDIMessageEvent or MIDIConnectionEvent.

NPM

The polyfill has been setup in es6 modules for better maintainability. I have created a npm package that contains the necessary build tools and scripts. This package updates the web-midi-api package that Sema made earlier; it would be great if Sema updates his version after the merge and then push the updated version to npm. Or maybe it is handier to update the npm package directly from Chris' repository if that is possible?

The jazz-midi package has been added to the dependencies and the primary entry point for the web-midi-api package (index.js) has been updated and moved to the /lib folder. The test.js file has moved to the /examples/nodejs folder. It worked on Linux (Ubuntu 15.04 64bits) but not on OSX and Windows. Also the test script of the jazz-midi package failed on OSX and Windows.

On OSX 10.10.3 with nodejs 0.12.2 I got this error:

OSX: no suitable image found.  Did find:
  /Users/abudaan/workspace/jazznode/node_modules/jazz-midi/bin/macos64/jazz.node: mach-o, but wrong architecture

On Windows 8.1 with nodejs 0.12.2 I got this error:

module.js:355
  Module._extensions[extension](this, filename);
                               ^
Error: error:
193C:\Workspace\jazznode\node_modules\jazz-midi\bin\win32\jazz.node
    at Error (native)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous>
(C:\Workspace\jazznode\node_modules\jazz-midi\index.js:9:16)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

Caveats

The methods open() and close() of MIDIInput and MIDIOutput call MidiInClose() and MidiOutClose() respectively on the Jazz instance. On Linux this resulted in a lot of crashes of the plugin, so I decided to open the device upon initialization and leave it open when close() is called. Only the value of connection gets updated when close() or open() are called. I got the impression that the plugin crashes a bit more often on Windows as well, so maybe we should implement the same trick for Windows.

To keep track of devices being connecting and disconnected I use OnConnectMidiIn, OnConnectMidiOut, OnDisconnectMidiIn and OnDisconnectMidiOut. But in the documentation of the Jazz plugin it says: "Monitoring MIDI connections may be a resource-consuming operation. Don't use it unless you really need it.". We might consider polling the MIDIAccess.inputs and MIDIAccess.outputs by requestAnimationFrame or setInterval instead.

Updates

Currently the MIDIConnectionEventInit and MIDIOutput.clear() are not yet implemented, I will add these as soon as Chrome has implemented them.

jazz-soft commented 9 years ago

Update jazz-midi package to the latest version. It now works with both node.js 0.10.* and 0.12.*

abudaan commented 9 years ago

I have tested with version 1.4.2, that is the lateste version right? This is how I tested it on OSX:

npm install jazz-midi
cd node_modules/jazz-midi
node test.js
jazz-soft commented 9 years ago

Works fine on my Mac. Let's move this discussion to http://jazz-soft.org - it's a kind of off-topic here.

abudaan commented 9 years ago

Okay let's move this discussion to your forum, although it is not completely off-topic since we want the WebMIDIAPIShim to work with both the browser plugin and the nodejs version of Jazz.

notator commented 9 years ago

If you move to http://jazz-soft.org, could you leave a link to the topic (or its title) here? Thanks.

jazz-soft commented 9 years ago

James, you can start a new branch or use http://jazz-soft.org/bb/viewtopic.php?f=2&t=898

cwilso commented 9 years ago

Sorry it's taken me a few days to get to review this. Thanks for all your work!

abudaan commented 9 years ago

No problem, thanks for merging!