Closed bjornm closed 9 years ago
The patch above was buggy. Here's a better one. Note that it is not possible to maintain a synchronous shim where the underlying behavior is async. It just "happens" to work as long as you do not expect the Midinput / MidiOutput to work until after a few ms. Here goes:
--- a/dartclient/web/js/WebMIDIAPI.js +++ b/dartclient/web/js/WebMIDIAPI.js @@ -16,7 +16,7 @@ // Initialize the MIDI library. (function (global) { 'use strict';
var midiIO, _requestMIDIAccess, _delayedInit, MIDIAccess, _onReady, _onNotReady, MIDIPort, MIDIInput, MIDIOutput, _midiProc;
function Promise() {
@@ -78,18 +78,29 @@ document.body.appendChild(insertionPoint); } insertionPoint.appendChild(o1);
if (this.objRef.isJazz)
};
_requestMIDIAccess = function _requestMIDIAccess() { var access = new MIDIAccess(); @@ -100,23 +111,25 @@
function MIDIAccess() { this._jazzInstances = new Array();
}.bind(this));
};
_onNotReady = function() { if (this._promise) this._promise.fail( { code: 1 } ); }; @@ -159,6 +172,10 @@ this.onmidimessage = null;
var inputInstance = null;
this._input = this._jazzInstance.MidiInOpen( this._index, _midiProc.bind(this) );
};
// Introduced in DOM Level 2: @@ -322,6 +340,10 @@ this.version = "";
var outputInstance = null;
this._jazzInstance.MidiOutOpen(this.name);
};
function _sendLater() {
Sorry about the spamming - the code above looks like a mess so I sent a pull request instead.
The demo index.html works in Safari but not in 33.0.1750.70 beta.
Got it to work again by introducing window.setTimeout between creating the plugin object elements and checking for .isJazz. Maybe Chrome changed plugin initialization to a more async nature? Here's a quick-n-dirty patch, you probably want to clean it up a little bit:
diff --git a/WebMIDIAPI.js b/WebMIDIAPI.js index d06b09a..eb4ceb6 100755 --- a/WebMIDIAPI.js +++ b/WebMIDIAPI.js @@ -16,7 +16,7 @@ // Initialize the MIDI library. (function (global) { 'use strict';
var midiIO, _requestMIDIAccess, _delayedInit, MIDIAccess, _onReady, MIDIPort, MIDIInput, MIDIOutput, _midiProc;
function Promise() {
@@ -78,18 +78,20 @@ document.body.appendChild(insertionPoint); } insertionPoint.appendChild(o1);
};
_requestMIDIAccess = function _requestMIDIAccess() { var access = new MIDIAccess(); @@ -100,15 +102,19 @@
function MIDIAccess() { this._jazzInstances = new Array();
this._jazzInstances.push( instance ); this._promise = new Promise;
};
_onReady = function _onReady() {