/
JZZ.js
1 lines (1 loc) · 61.5 KB
/
JZZ.js
1
!function(t,n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define("JZZ",[],n);else{if((t=t||window).JZZ&&t.JZZ.MIDI)return;t.JZZ=n()}}(this,function(){var o,r,t,i,n="undefined"==typeof window?global:window,e="1.1.9",s=Date.now||function(){return(new Date).getTime()},u=s(),a="undefined"!=typeof performance&&performance.now?function(){return performance.now()}:function(){return s()-u},h=function(t){setTimeout(t,0)};function c(){(this._orig=this)._ready=!1,this._queue=[],this._log=[]}function f(t,n){this._bad?n instanceof Function&&n.apply(this,[new Error(this._err())]):t instanceof Function&&t.apply(this,[this])}function p(t,n){this._bad?t._crash(this._err()):setTimeout(function(){t._resume()},n)}function l(t){this._bad&&t._break(this._err()),t._resume()}function d(t,e,r){t[r]=function(){var t=arguments,n=e._image();return this._push(l,[n]),n[r].apply(n,t)}}function _(t){this._bad||(t instanceof Function?t.apply(this):console.log(t))}function m(t){this._bad&&(t instanceof Function?t.apply(this):console.log(t))}function g(t){this._bad?t._crash(this._err()):(this._break("Closed"),t._resume())}function v(t){if(t.length){var n,e=t.shift();t.length&&(n=this)._slip(m,[function(){v.apply(n,[t])}]);try{this._repair(),e.apply(this)}catch(t){this._break(t.toString())}}else this._break()}function y(t,n){for(var e=0;e<t.length;e++)if(t[e]===n)return;t.push(n)}function b(t,n){for(var e=0;e<t.length;e++)if(t[e]===n)return void t.splice(e,1)}function S(){c.apply(this)}function C(t,n,e){if(void 0===n)return C(t,[],[]);if(t instanceof Object){for(var r,i=0;i<n.length;i++)if(n[i]===t)return e[i];for(var o in r=t instanceof Array?[]:{},n.push(t),e.push(r),t)t.hasOwnProperty(o)&&(r[o]=C(t[o],n,e));return r}return t}c.prototype._exec=function(){for(;this._ready&&this._queue.length;){var t=this._queue.shift();t[0].apply(this,t[1])}},c.prototype._push=function(t,n){this._queue.push([t,n]),c.prototype._exec.apply(this)},c.prototype._slip=function(t,n){this._queue.unshift([t,n])},c.prototype._pause=function(){this._ready=!1},c.prototype._resume=function(){this._ready=!0,c.prototype._exec.apply(this)},c.prototype._break=function(t){this._orig._bad=!0,this._orig._log.push(t||"Unknown JZZ error")},c.prototype._repair=function(){this._orig._bad=!1},c.prototype._crash=function(t){this._break(t),this._resume()},c.prototype._err=function(){return this._log[this._log.length-1]},c.prototype.log=function(){return C(this._log)},c.prototype._dup=function(){function t(){}t.prototype=this._orig;var n=new t;return n._ready=!1,n._queue=[],n},c.prototype._image=function(){return this._dup()},c.prototype._thenable=function(){if(this.then)return this;function t(){}var e=this;t.prototype=e;var n=new t;return n.then=function(t,n){return e._push(f,[t,n]),this},n},c.prototype.wait=function(t){if(!t)return this;var n=this._image();return this._push(p,[n,t]),n._thenable()},c.prototype.and=function(t){return this._push(_,[t]),this._thenable()},c.prototype.or=function(t){return this._push(m,[t]),this._thenable()},c.prototype._info={},c.prototype.info=function(){var t=C(this._orig._info);return void 0===t.engine&&(t.engine="none"),void 0===t.sysex&&(t.sysex=!0),t},c.prototype.name=function(){return this.info().name},c.prototype.close=function(){var t=new c;return this._close&&this._push(this._close,[]),this._push(g,[t]),t._thenable()},(S.prototype=new c)._info={name:"JZZ.js",ver:e,version:e,inputs:[],outputs:[]};var w,M=[],x=[],B=[],I=[];function A(){var t,n;for(w._info.engine=W._type,w._info.version=W._version,w._info.sysex=W._sysex,w._info.inputs=[],w._info.outputs=[],M=[],x=[],W._allOuts={},W._allIns={},t=0;t<W._outs.length;t++)((n=W._outs[t]).engine=W)._allOuts[n.name]=n,w._info.outputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:W._type}),M.push(n);for(t=0;t<H._outs.length;t++)n=H._outs[t],w._info.outputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:n.type}),M.push(n);for(t=0;t<W._ins.length;t++)((n=W._ins[t]).engine=W)._allIns[n.name]=n,w._info.inputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:W._type}),x.push(n);for(t=0;t<H._ins.length;t++)n=H._ins[t],w._info.inputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:n.type}),x.push(n);if(w._watcher&&w._watcher._handles.length){var e=function(t,n,e,r){if(!function(t,n,e,r){var i;if(t.length!=e.length||n.length!=r.length)return!0;for(i=0;i<t.length;i++)if(t[i].name!=e[i].name)return!0;for(i=0;i<n.length;i++)if(n[i].name!=r[i].name)return!0;return!1}(t,n,e,r))return;var i,o=[],s=[],u=[],a=[],h={};for(i=0;i<t.length;i++)h[t[i].name]=!0;for(i=0;i<e.length;i++)h[e[i].name]||o.push(e[i]);for(h={},i=0;i<e.length;i++)h[e[i].name]=!0;for(i=0;i<t.length;i++)h[t[i].name]||u.push(t[i]);for(h={},i=0;i<n.length;i++)h[n[i].name]=!0;for(i=0;i<r.length;i++)h[r[i].name]||s.push(r[i]);for(h={},i=0;i<r.length;i++)h[r[i].name]=!0;for(i=0;i<n.length;i++)h[n[i].name]||a.push(n[i]);return{inputs:{added:o,removed:u},outputs:{added:s,removed:a}}}(I,B,w._info.inputs,w._info.outputs);if(e){for(r=0;r<e.inputs.removed.length;r++)(n=W._inMap[e.inputs.removed[r].name])&&n._closeAll();for(r=0;r<e.outputs.removed.length;r++)(n=W._outMap[e.outputs.removed[r].name])&&n._closeAll();!function(t){for(o=0;o<w._watcher._handles.length;o++)w._watcher._handles[o].apply(w,[t])}(e)}}I=w._info.inputs,B=w._info.outputs}function O(){this._bad||W._refresh(this)}function E(t,n){var e;t instanceof Function&&(t=t(n)),t instanceof Array||(t=[t]);for(var r=[],i=[],o=n.slice(),s=r,u=0;u<t.length;u++)if(void 0===t[u])s=i;else if(t[u]instanceof RegExp)for(e=0;e<o.length;e++)t[u].test(o[e].name)&&(s.push(o[e]),o.splice(e,1),e--);else for(e=0;e<o.length;e++)(t[u]+""==e+""||t[u]===o[e].name||t[u]instanceof Object&&t[u].name===o[e].name)&&(s.push(o[e]),o.splice(e,1),e--);return s==r?r:r.concat(o).concat(i)}function P(t,n){var e=n instanceof RegExp?"Port matching "+n+" not found":n instanceof Object||void 0===n?"Port not found":'Port "'+n+'" not found';t._crash(e)}function T(t,n){if(this._bad)t._crash(this._err());else{var e=E(n,M);if(!e.length)return void P(t,n);for(var r=0;r<e.length;r++)e[r]=function(t){return function(){t.engine._openOut(this,t.name)}}(e[r]);t._slip(v,[e]),t._resume()}}function F(t,n){if(this._bad)t._crash(this._err());else{var e=E(n,x);if(!e.length)return void P(t,n);for(var r=0;r<e.length;r++)e[r]=function(t){return function(){t.engine._openIn(this,t.name)}}(e[r]);t._slip(v,[e]),t._resume()}}function L(t,n){this._bad?t._crash():(t._slip(G,[n]),t._resume())}function q(){c.apply(this),this._handles=[],this._outs=[]}function D(t){this._bad||this._receive(t)}function k(t){this._emit(t)}function j(t){t instanceof Function?y(this._orig._handles,t):y(this._orig._outs,t)}function z(t){void 0===t?(this._orig._handles=[],this._orig._outs=[]):t instanceof Function?b(this._orig._handles,t):b(this._orig._outs,t)}function R(t,n){this._orig._mpe||(this._orig._mpe=new jt),this._orig._mpe.setup(t,n)}function N(t){if(t!=parseInt(t)||t<0||15<t)throw RangeError("Bad channel value (must not be less than 0 or more than 15): "+t)}function U(){c.apply(this),this._handles=[],d(this,w,"refresh"),d(this,w,"openMidiOut"),d(this,w,"openMidiIn"),d(this,w,"onChange"),d(this,w,"close")}function G(t){t instanceof Function&&(this._orig._handles.length||W._watch(),y(this._orig._handles,t))}function V(t){void 0===t?this._orig._handles=[]:b(this._orig._handles,t),this._orig._handles.length||W._unwatch()}S.prototype.refresh=function(){return this._push(O,[]),this._thenable()},S.prototype.openMidiOut=function(t){var n=new q;return this._push(O,[]),this._push(T,[n,t]),n._thenable()},S.prototype._openMidiOutNR=function(t){var n=new q;return this._push(T,[n,t]),n._thenable()},S.prototype.openMidiIn=function(t){var n=new q;return this._push(O,[]),this._push(F,[n,t]),n._thenable()},S.prototype._openMidiInNR=function(t){var n=new q;return this._push(F,[n,t]),n._thenable()},S.prototype.onChange=function(t){this._orig._watcher||(this._orig._watcher=new U);var n=this._orig._watcher._image();return this._push(L,[n,t]),n._thenable()},S.prototype._close=function(){W._close()},(q.prototype=new c)._filter=function(t){var n,e;return this._orig._mpe&&(e=0,this._handles&&this._handles.length&&(e=this._handles.length,n=this._handles[0]),this._outs&&this._outs.length&&(e=this._outs.length,n=this._outs[0]),1!=e||n._mpe||(t=this._orig._mpe.filter(t))),t},q.prototype._receive=function(t){this._emit(this._filter(t))},q.prototype.send=function(){return this._push(D,[ct.apply(null,arguments)]),this._thenable()},q.prototype.note=function(t,n,e,r){return this.noteOn(t,n,e),void 0===this._ch&&void 0===this._master?0<r&&this.wait(r).noteOff(t,n):0<e&&this.wait(e).noteOff(t),this._thenable()},q.prototype._emit=function(t){for(var n=0;n<this._handles.length;n++)this._handles[n].apply(this,[ct(t)._stamp(this)]);for(n=0;n<this._outs.length;n++){var e=ct(t);e._stamped(this._outs[n])||this._outs[n].send(e._stamp(this))}},q.prototype.emit=function(t){return this._push(k,[t]),this._thenable()},q.prototype.connect=function(t){return this._push(j,[t]),this._thenable()},q.prototype.disconnect=function(t){return this._push(z,[t]),this._thenable()},q.prototype.connected=function(){return this._orig._handles.length+this._orig._outs.length},q.prototype._image=function(){var t=this._dup();return t._ch=this._ch,t._sxid=this._sxid,t._master=this._master,t._band=this._band,t},q.prototype._ch=void 0,q.prototype._sxid=127,q.prototype._master=void 0,q.prototype._band=void 0,q.prototype.sxId=function(t){if(void 0===t&&(t=q.prototype._sxid),t==this._sxid)return this._thenable();t=mt(t);var n=this._image();return n._sxid=t,this._push(l,[n]),n._thenable()},q.prototype.ch=function(t){if(t==this._ch||void 0===t&&void 0===this._ch)return this._thenable();var n=this._image();return void 0!==t&&(t=_t(t)),n._ch=t,n._master=void 0,n._band=void 0,this._push(l,[n]),n._thenable()},q.prototype.mpe=function(t,n){if(t==this._master&&n==this._band||void 0===t&&void 0===this._master)return this._thenable();if(void 0!==t&&jt.validate(t,n),!n)return this.ch(t);var e=this._image();return e._ch=void 0,e._master=t,e._band=n,this._push(R,[t,n]),this._push(l,[e]),e._thenable()},(U.prototype=new c).connect=function(t){return this._push(G,[t]),this._thenable()},U.prototype.disconnect=function(t){return this._push(V,[t]),this._thenable()};var Z,J,W={_outs:[],_ins:[]},H={_outs:[],_ins:[]};function Q(){if("undefined"!=typeof module&&module.exports)return t=require("jazz-midi"),W._type="node",W._main=t,W._pool=[],W._newPlugin=function(){return new t.MIDI},void rt();var t;this._break()}function K(){var t=document.createElement("div");t.style.visibility="hidden",document.body.appendChild(t);var n,e=document.createElement("object");if(e.style.visibility="hidden",e.style.width="0px",e.style.height="0px",e.classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90",e.type="audio/x-jazz",document.body.appendChild(e),e.isJazz)return n=e,W._type="plugin",W._main=n,W._pool=[n],W._newPlugin=function(){var t=document.createElement("object");return t.style.visibility="hidden",t.style.width="0px",n.style.height="0px",t.classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90",t.type="audio/x-jazz",document.body.appendChild(t),t.isJazz?t:void 0},void rt();this._break()}if("undefined"!=typeof navigator&&navigator.requestMIDIAccess){Z=navigator,J=navigator.requestMIDIAccess;try{-1!=J.toString().indexOf("JZZ(")&&(J=void 0)}catch(t){}}function $(){if(J){var n=this;return J.call(Z,{}).then(function(t){it(t),n._resume()},function(t){n._crash(t)}),void this._pause()}this._break()}function X(){if(J){var n=this;return J.call(Z,{sysex:!0}).then(function(t){it(t,!0),n._resume()},function(t){n._crash(t)}),void this._pause()}this._break()}function Y(){var s,u,a=this;this._pause(),document.addEventListener("jazz-midi-msg",function t(){if(s=!0,u=u||document.getElementById("jazz-midi-msg")){var n,e,r,i=[];try{i=JSON.parse(u.innerText)}catch(t){}u.innerText="",document.removeEventListener("jazz-midi-msg",t),"version"===i[0]?(n=u,e=i[2],W._type="extension",W._version=e,W._sysex=!0,W._pool=[],W._outs=[],W._ins=[],W._inArr=[],W._outArr=[],W._inMap={},W._outMap={},W._outsW=[],W._insW=[],W.refreshClients=[],W._msg=n,W._newPlugin=function(){var t={id:W._pool.length};W._pool.push(t),t.id?document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["new"]})):t.ready=!0},W._newPlugin(),W._refresh=function(t){W.refreshClients.push(t),t._pause(),h(function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["refresh"]}))})},W._openOut=function(t,n){var e,r=W._outMap[n];r||(W._pool.length<=W._outArr.length&&W._newPlugin(),e=W._pool[W._outArr.length],((r={name:n,clients:[],info:{name:n,manufacturer:W._allOuts[n].manufacturer,version:W._allOuts[n].version,type:"MIDI-out",sysex:W._sysex,engine:W._type},_start:function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["openout",e.id,n]}))},_close:function(t){W._closeOut(t)},_closeAll:o,_receive:function(t){var n;t.length&&((n=t.slice()).splice(0,0,"play",e.id),document.dispatchEvent(new CustomEvent("jazz-midi",{detail:n})))}}).plugin=e).output=r,W._outArr.push(r),W._outMap[n]=r),y((t._orig._impl=r).clients,t._orig),t._info=r.info,t._receive=function(t){r._receive(t)},t._close=function(){r._close(this)},r.open||(t._pause(),r.plugin.ready&&r._start())},W._openIn=function(t,n){var e,r=W._inMap[n];r||(W._pool.length<=W._inArr.length&&W._newPlugin(),e=W._pool[W._inArr.length],((r={name:n,clients:[],info:{name:n,manufacturer:W._allIns[n].manufacturer,version:W._allIns[n].version,type:"MIDI-in",sysex:W._sysex,engine:W._type},_start:function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["openin",e.id,n]}))},_close:function(t){W._closeIn(t)},_closeAll:o}).plugin=e).input=r,W._inArr.push(r),W._inMap[n]=r),y((t._orig._impl=r).clients,t._orig),t._info=r.info,t._close=function(){r._close(this)},r.open||(t._pause(),r.plugin.ready&&r._start())},W._closeOut=function(t){var n=t._impl;b(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["closeout",n.plugin.id]})))},W._closeIn=function(t){var n=t._impl;b(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["closein",n.plugin.id]})))},W._close=function(){W._unwatch()},W._watch=function(){W._insW=W._ins,W._outsW=W._outs,r=setInterval(function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["refresh"]}))},250)},W._unwatch=function(){clearInterval(r),r=void 0},document.addEventListener("jazz-midi-msg",function(){var t,n,e,r=W._msg.innerText.split("\n");for(W._msg.innerText="",n=0;n<r.length;n++){var i=[];try{i=JSON.parse(r[n])}catch(t){}if(i.length)if("refresh"===i[0]){if(i[1].ins){for(e=0;e<i[1].ins.length;e++)i[1].ins[e].type=W._type;W._ins=i[1].ins}if(i[1].outs){for(e=0;e<i[1].outs.length;e++)i[1].outs[e].type=W._type;W._outs=i[1].outs}for(A(),e=0;e<W.refreshClients.length;e++)W.refreshClients[e]._resume();W.refreshClients=[]}else if("version"===i[0]){var o=W._pool[i[1]];o&&(o.ready=!0,o.input&&o.input._start(),o.output&&o.output._start())}else if("openout"===i[0]){if(t=W._pool[i[1]].output)if(i[2]==t.name){if(t.open=!0,t.clients)for(e=0;e<t.clients.length;e++)t.clients[e]._resume()}else if(t.clients)for(e=0;e<t.clients.length;e++)t.clients[e]._crash()}else if("openin"===i[0]){if(t=W._pool[i[1]].input)if(i[2]==t.name){if(t.open=!0,t.clients)for(e=0;e<t.clients.length;e++)t.clients[e]._resume()}else if(t.clients)for(e=0;e<t.clients.length;e++)t.clients[e]._crash()}else if("midi"===i[0]&&(t=W._pool[i[1]].input)&&t.clients)for(e=0;e<t.clients.length;e++){var s=ct(i.slice(3));t.clients[e]._emit(s)}}}),a._resume()):a._crash()}function o(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}});try{document.dispatchEvent(new Event("jazz-midi"))}catch(t){}h(function(){s||a._crash()})}function tt(){this._pause();var t=this;h(function(){t._crash()})}function nt(t){for(var n=[],e=function(t){var n=["node","extension","plugin","webmidi"];if(!t||!t.engine)return n;var e,r,i,o=t.engine instanceof Array?t.engine:[t.engine],s={},u=[],a=[];for(i=0;i<o.length;i++){var h=o[i].toString().toLowerCase();s[h]||(s[h]=!0,"none"===h&&(e=!0),"etc"!==h&&void 0!==h||(r=!0),r?a.push(h):u.push(h),b(n,h))}(r||u.length||a.length)&&(e=!1);return e?[]:u.concat(r?n:a)}(t),r=0;r<e.length;r++)"webmidi"==e[r]?(t&&!0===t.sysex&&n.push(X),t&&!0===t.sysex&&!0!==t.degrade||n.push($)):"node"==e[r]?(n.push(Q),n.push(tt)):"extension"==e[r]?n.push(Y):"plugin"==e[r]&&n.push(K);return n.push(et),n}function et(){W._type="none",W._version=e,W._sysex=!0,W._outs=[],W._ins=[],W._refresh=function(){A()},W._watch=function(){},W._unwatch=function(){},W._close=function(){}}function rt(){var t;function s(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}W._inArr=[],W._outArr=[],W._inMap={},W._outMap={},W._outsW=[],W._insW=[],W._version=W._main.version,W._sysex=!0,W._refresh=function(){var t,n;for(W._outs=[],W._ins=[],t=0;(n=W._main.MidiOutInfo(t)).length;t++)W._outs.push({type:W._type,name:n[0],manufacturer:n[1],version:n[2]});for(t=0;(n=W._main.MidiInInfo(t)).length;t++)W._ins.push({type:W._type,name:n[0],manufacturer:n[1],version:n[2]});A()},W._openOut=function(t,n){var e,r=W._outMap[n];if(r||(W._pool.length<=W._outArr.length&&W._pool.push(W._newPlugin()),r={name:n,clients:[],info:{name:n,manufacturer:W._allOuts[n].manufacturer,version:W._allOuts[n].version,type:"MIDI-out",sysex:W._sysex,engine:W._type},_close:function(t){W._closeOut(t)},_closeAll:s,_receive:function(t){t.length&&this.plugin.MidiOutRaw(t.slice())}},e=W._pool[W._outArr.length],r.plugin=e,W._outArr.push(r),W._outMap[n]=r),!r.open){var i=r.plugin.MidiOutOpen(n);if(i!==n)return i&&r.plugin.MidiOutClose(),void t._break();r.open=!0}y((t._orig._impl=r).clients,t._orig),t._info=r.info,t._receive=function(t){r._receive(t)},t._close=function(){r._close(this)}},W._openIn=function(t,n){var e,r,i=W._inMap[n];if(i||(W._pool.length<=W._inArr.length&&W._pool.push(W._newPlugin()),(i={name:n,clients:[],info:{name:n,manufacturer:W._allIns[n].manufacturer,version:W._allIns[n].version,type:"MIDI-in",sysex:W._sysex,engine:W._type},_close:function(t){W._closeIn(t)},_closeAll:s,handle:function(t,n){for(var e=0;e<this.clients.length;e++){var r=ct(n);this.clients[e]._emit(r)}}}).onmidi=(r=i,function(t,n){r.handle(t,n)}),e=W._pool[W._inArr.length],i.plugin=e,W._inArr.push(i),W._inMap[n]=i),!i.open){var o=i.plugin.MidiInOpen(n,i.onmidi);if(o!==n)return o&&i.plugin.MidiInClose(),void t._break();i.open=!0}y((t._orig._impl=i).clients,t._orig),t._info=i.info,t._close=function(){i._close(this)}},W._closeOut=function(t){var n=t._impl;b(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,n.plugin.MidiOutClose())},W._closeIn=function(t){var n=t._impl;b(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,n.plugin.MidiInClose())},W._close=function(){for(var t=0;t<W._inArr.length;t++)W._inArr[t].open&&W._inArr[t].plugin.MidiInClose();W._unwatch()},W._watch=function(){t=t||setInterval(function(){W._refresh()},250)},W._unwatch=function(){t&&clearInterval(t),t=void 0}}function it(t,n){var e;function o(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}W._type="webmidi",W._version=43,W._sysex=!!n,W._access=t,W._inMap={},W._outMap={},W._outsW=[],W._insW=[],W._refresh=function(){W._outs=[],W._ins=[],W._access.outputs.forEach(function(t){W._outs.push({type:W._type,name:t.name,manufacturer:t.manufacturer,version:t.version})}),W._access.inputs.forEach(function(t){W._ins.push({type:W._type,name:t.name,manufacturer:t.manufacturer,version:t.version})}),A()},W._openOut=function(t,n){var e,r=(r=W._outMap[n])||{name:n,clients:[],info:{name:n,manufacturer:W._allOuts[n].manufacturer,version:W._allOuts[n].version,type:"MIDI-out",sysex:W._sysex,engine:W._type},_close:function(t){W._closeOut(t)},_closeAll:o,_receive:function(t){r.dev&&t.length&&this.dev.send(t.slice())}};W._access.outputs.forEach(function(t){t.name===n&&(e=t)}),e?(r.dev=e,W._outMap[n]=r,y((t._orig._impl=r).clients,t._orig),t._info=r.info,t._receive=function(t){r._receive(t)},t._close=function(){r._close(this)},r.dev.open&&(t._pause(),r.dev.open().then(function(){t._resume()},function(){t._crash()}))):t._break()},W._openIn=function(t,n){var e,r,i=(i=W._inMap[n])||{name:n,clients:[],info:{name:n,manufacturer:W._allIns[n].manufacturer,version:W._allIns[n].version,type:"MIDI-in",sysex:W._sysex,engine:W._type},_close:function(t){W._closeIn(t)},_closeAll:o,handle:function(t){for(var n=0;n<this.clients.length;n++){var e=ct([].slice.call(t.data));this.clients[n]._emit(e)}}};W._access.inputs.forEach(function(t){t.name===n&&(e=t)}),e?(i.dev=e,i.dev.onmidimessage=(r=i,function(t){r.handle(t)}),W._inMap[n]=i,y((t._orig._impl=i).clients,t._orig),t._info=i.info,t._close=function(){i._close(this)},i.dev.open&&(t._pause(),i.dev.open().then(function(){t._resume()},function(){t._crash()}))):t._break()},W._closeOut=function(t){var n=t._impl;b(n.clients,t._orig),n.clients.length||(n.dev&&n.dev.close&&n.dev.close(),n.dev=void 0)},W._closeIn=function(t){var n=t._impl;b(n.clients,t._orig),n.clients.length||(n.dev&&(n.dev.onmidimessage=null,n.dev.close&&n.dev.close()),n.dev=void 0)},W._close=function(){W._unwatch()},W._watch=function(){W._access.onstatechange=function(){e=!0,h(function(){e&&(W._refresh(),e=!1)})}},W._unwatch=function(){W._access.onstatechange=void 0}}function ot(t){var n;return w||(n=t,zt(),(w=new S)._options=n,w._push(v,[nt(n)]),w.refresh(),w._resume()),w._thenable()}function st(){var t=this instanceof st?this:t=new st;return st.prototype.reset.apply(t,arguments),t}function ut(){29.97==this.type&&!this.second&&this.frame<2&&this.minute%10&&(this.frame=2)}function at(t){return[[24,25,29.97,30][t[7]>>1&3],(1&t[7])<<4|t[6],t[5]<<4|t[4],t[3]<<4|t[2],t[1]<<4|t[0]]}function ht(t){for(var n,e=[],r=0;r<t.length;r++)e[r]=(n=t[r])<10?"0"+n:n;return e.join(":")}function ct(t){var n=this instanceof ct?this:n=new ct;if(t instanceof ct){for(r in n._from=t._from.slice(),t)t.hasOwnProperty(r)&&"_from"!=r&&(n[r]=t[r]);return n}if(n._from=[],void 0===t)return n;for(var e=t instanceof Array?t:arguments,r=0;r<e.length;r++)i=e[r],1==r&&(128<=n[0]&&n[0]<=175&&(i=ct.noteValue(i)),192<=n[0]&&n[0]<=207&&(i=ct.programValue(i))),(i!=parseInt(i)||i<0||255<i)&&dt(e[r]),n.push(i);return n}(ot.JZZ=ot).version=e,ot.info=function(){return S.prototype.info()},S.prototype.Widget=ot.Widget=function(t){var n=new q;if(t instanceof Object)for(var e in t)t.hasOwnProperty(e)&&(n[e]=t[e]);return n._resume(),n},ot.addMidiIn=function(t,n){var e=C(n._info||{});e.name=t,e.type=e.type||"javascript",e.manufacturer=e.manufacturer||"virtual",e.version=e.version||"0.0";var r={_info:function(){return e},_openIn:function(t){t._pause(),t._info=C(e),t._close=function(){n.disconnect(t)},n.connect(t),t._resume()}};return ot.lib.registerMidiIn(t,r)},ot.addMidiOut=function(t,n){var e=C(n._info||{});e.name=t,e.type=e.type||"javascript",e.manufacturer=e.manufacturer||"virtual",e.version=e.version||"0.0";var r={_info:function(){return e},_openOut:function(t){t._pause(),t._info=C(e),t._close=function(){t.disconnect()},j.apply(t,[n]),t._resume()}};return ot.lib.registerMidiOut(t,r)},st.prototype.reset=function(t){if(t instanceof st)return this.setType(t.getType()),this.setHour(t.getHour()),this.setMinute(t.getMinute()),this.setSecond(t.getSecond()),this.setFrame(t.getFrame()),this.setQuarter(t.getQuarter()),this;var n=t instanceof Array?t:arguments;return this.setType(n[0]),this.setHour(n[1]),this.setMinute(n[2]),this.setSecond(n[3]),this.setFrame(n[4]),this.setQuarter(n[5]),this},st.prototype.isFullFrame=function(){return 0==this.quarter||4==this.quarter},st.prototype.getType=function(){return this.type},st.prototype.getHour=function(){return this.hour},st.prototype.getMinute=function(){return this.minute},st.prototype.getSecond=function(){return this.second},st.prototype.getFrame=function(){return this.frame},st.prototype.getQuarter=function(){return this.quarter},st.prototype.setType=function(t){if(void 0===t||24==t)this.type=24;else if(25==t)this.type=25;else if(29.97==t)this.type=29.97,ut.apply(this);else{if(30!=t)throw RangeError("Bad SMPTE frame rate: "+t);this.type=30}return this.frame>=this.type&&(this.frame=this.type-1),this},st.prototype.setHour=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||24<=t)throw RangeError("Bad SMPTE hours value: "+t);return this.hour=t,this},st.prototype.setMinute=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE minutes value: "+t);return this.minute=t,ut.apply(this),this},st.prototype.setSecond=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE seconds value: "+t);return this.second=t,ut.apply(this),this},st.prototype.setFrame=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||t>=this.type)throw RangeError("Bad SMPTE frame number: "+t);return this.frame=t,ut.apply(this),this},st.prototype.setQuarter=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||8<=t)throw RangeError("Bad SMPTE quarter frame: "+t);return this.quarter=t,this},st.prototype.incrFrame=function(){return this.frame++,this.frame>=this.type&&(this.frame=0,this.second++,60<=this.second&&(this.second=0,this.minute++,60<=this.minute&&(this.minute=0,this.hour=23<=this.hour?0:this.hour+1))),ut.apply(this),this},st.prototype.decrFrame=function(){return!this.second&&2==this.frame&&29.97==this.type&&this.minute%10&&(this.frame=0),this.frame--,this.frame<0&&(this.frame=29.97==this.type?29:this.type-1,this.second--,this.second<0&&(this.second=59,this.minute--,this.minute<0&&(this.minute=59,this.hour=this.hour?this.hour-1:23))),this},st.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},st.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},st.prototype.read=function(t){if(t instanceof ct||(t=ct.apply(null,arguments)),240==t[0]&&127==t[1]&&1==t[3]&&1==t[4]&&247==t[9])return this.type=[24,25,29.97,30][t[5]>>5&3],this.hour=31&t[5],this.minute=t[6],this.second=t[7],this.frame=t[8],this.quarter=0,this._=void 0,this._b=void 0,!(this._f=void 0);if(241!=t[0]||void 0===t[1])return!1;var n=t[1]>>4,e=15&t[1];return 0==n?7==this._&&(7==this._f&&(this.reset(at(this._a)),this.incrFrame()),this.incrFrame()):3==n?4==this._&&this.decrFrame():4==n?3==this._&&this.incrFrame():7==n&&0===this._&&(0===this._b&&(this.reset(at(this._a)),this.decrFrame()),this.decrFrame()),this._a||(this._a=[]),this._a[n]=e,this._f=this._f===n-1||0==n?n:void 0,this._b=this._b===1+n||7==n?n:void 0,this._=n,this.quarter=n,!0},st.prototype.toString=function(){return ht([this.hour,this.minute,this.second,this.frame])},ot.SMPTE=st,ct.prototype=[],ct.prototype.constructor=ct;var ft={};function pt(){}ct.noteValue=function(t){return void 0===t?void 0:ft[t.toString().toLowerCase()]},ct.programValue=function(t){return t},ct.freq=function(t,n){return void 0===n&&(n=440),n*Math.pow(2,(mt(ct.noteValue(t),t)-69)/12)},ct.shift=function(t,n){return void 0===n&&(n=440),12*Math.log2(t/n)},ct.to14b=function(t){return t<=0?0:1<=t?16383:Math.floor(16384*t)},(pt.prototype=ct)._sxid=127,ct.sxId=function(t){if(void 0===t&&(t=ct._sxid),t==this._sxid)return this;t=mt(t);var n=new pt;return n._ch=this._ch,n._sxid=t,n},ct.ch=function(t){if(t==this._ch||void 0===t&&void 0===this._ch)return this;var n=new pt;return void 0!==t&&(t=_t(t)),n._ch=t,n._sxid=this._sxid,n};var lt={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(Pt in lt)if(lt.hasOwnProperty(Pt))for(i=0;i<12&&!(127<(t=lt[Pt]+12*i));i++)0<(ft[Pt+i]=t)&&(ft[Pt+"b"+i]=t-1,ft[Pt+"bb"+i]=t-2),t<127&&(ft[Pt+"#"+i]=t+1,ft[Pt+"##"+i]=t+2);for(i=0;i<128;i++)ft[i]=i;function dt(t){throw RangeError("Bad MIDI value: "+t)}function _t(t){return N(t),parseInt(t)}function mt(t,n){return(t!=parseInt(t)||t<0||127<t)&&dt(void 0===n?t:n),parseInt(t)}function gt(t,n){return(t!=parseInt(t)||t<0||255<t)&&dt(void 0===n?t:n),parseInt(t)}function vt(t){return(t!=parseInt(t)||t<0||16383<t)&&dt(t),127&parseInt(t)}function yt(t){return(t!=parseInt(t)||t<0||16383<t)&&dt(t),parseInt(t)>>7}var bt={noteOff:function(t,n,e){return void 0===e&&(e=64),[128+_t(t),mt(ct.noteValue(n),n),mt(e)]},noteOn:function(t,n,e){return void 0===e&&(e=127),[144+_t(t),mt(ct.noteValue(n),n),mt(e)]},aftertouch:function(t,n,e){return[160+_t(t),mt(ct.noteValue(n),n),mt(e)]}},St={control:function(t,n,e){return[176+_t(t),mt(n),mt(e)]},program:function(t,n){return[192+_t(t),mt(ct.programValue(n),n)]},pressure:function(t,n){return[208+_t(t),mt(n)]},pitchBend:function(t,n,e){return void 0===e?[224+_t(t),vt(n),yt(n)]:[224+_t(t),mt(e),mt(n)]},pitchBendF:function(t,n){return St.pitchBend(t,ct.to14b((n+1)/2))},bankMSB:function(t,n){return[176+_t(t),0,mt(n)]},bankLSB:function(t,n){return[176+_t(t),32,mt(n)]},modMSB:function(t,n){return[176+_t(t),1,mt(n)]},modLSB:function(t,n){return[176+_t(t),33,mt(n)]},breathMSB:function(t,n){return[176+_t(t),2,mt(n)]},breathLSB:function(t,n){return[176+_t(t),34,mt(n)]},footMSB:function(t,n){return[176+_t(t),4,mt(n)]},footLSB:function(t,n){return[176+_t(t),36,mt(n)]},portamentoMSB:function(t,n){return[176+_t(t),5,mt(n)]},portamentoLSB:function(t,n){return[176+_t(t),37,mt(n)]},dataMSB:function(t,n){return[176+_t(t),6,mt(n)]},dataLSB:function(t,n){return[176+_t(t),38,mt(n)]},volumeMSB:function(t,n){return[176+_t(t),7,mt(n)]},volumeLSB:function(t,n){return[176+_t(t),39,mt(n)]},balanceMSB:function(t,n){return[176+_t(t),8,mt(n)]},balanceLSB:function(t,n){return[176+_t(t),40,mt(n)]},panMSB:function(t,n){return[176+_t(t),10,mt(n)]},panLSB:function(t,n){return[176+_t(t),42,mt(n)]},expressionMSB:function(t,n){return[176+_t(t),11,mt(n)]},expressionLSB:function(t,n){return[176+_t(t),43,mt(n)]},damper:function(t,n){return void 0===n&&(n=!0),[176+_t(t),64,n?127:0]},portamento:function(t,n){return void 0===n&&(n=!0),[176+_t(t),65,n?127:0]},sostenuto:function(t,n){return void 0===n&&(n=!0),[176+_t(t),66,n?127:0]},soft:function(t,n){return void 0===n&&(n=!0),[176+_t(t),67,n?127:0]},legato:function(t,n){return void 0===n&&(n=!0),[176+_t(t),68,n?127:0]},ptc:function(t,n){return[176+_t(t),84,mt(ct.noteValue(n),n)]},dataIncr:function(t){return[176+_t(t),96,0]},dataDecr:function(t){return[176+_t(t),97,0]},nrpnLSB:function(t,n){return[176+_t(t),98,mt(n)]},nrpnMSB:function(t,n){return[176+_t(t),99,mt(n)]},rpnLSB:function(t,n){return[176+_t(t),100,mt(n)]},rpnMSB:function(t,n){return[176+_t(t),101,mt(n)]},allSoundOff:function(t){return[176+_t(t),120,0]},resetAllControllers:function(t){return[176+_t(t),121,0]},localControl:function(t,n){return[176+_t(t),122,n?127:0]},allNotesOff:function(t){return[176+_t(t),123,0]},omni:function(t,n){return void 0===n&&(n=!0),[176+_t(t),n?125:124,0]},mono:function(t,n){return void 0===n&&(n=1),[176+_t(t),126,mt(n)]},poly:function(t){return[176+_t(t),127,0]}},Ct={mtc:function(t){return[241,function(t){var n;switch(!t.backwards&&4<=t.quarter?t.decrFrame():t.backwards&&t.quarter<4&&t.incrFrame(),t.quarter>>1){case 0:n=t.frame;break;case 1:n=t.second;break;case 2:n=t.minute;break;default:n=t.hour}return 1&t.quarter?n>>=4:n&=15,7==t.quarter&&(25==t.type?n|=2:29.97==t.type?n|=4:30==t.type&&(n|=6)),!t.backwards&&4<=t.quarter?t.incrFrame():t.backwards&&t.quarter<4&&t.decrFrame(),n|t.quarter<<4}(t)]},songPosition:function(t,n){return void 0===n?[242,vt(t),yt(t)]:[242,mt(n),mt(t)]},songSelect:function(t){return[243,mt(t)]},tune:function(){return[246]},clock:function(){return[248]},start:function(){return[250]},continue:function(){return[251]},stop:function(){return[252]},active:function(){return[254]},sxIdRequest:function(){return[240,126,this._sxid,6,1,247]},sxFullFrame:function(t){return[240,127,this._sxid,1,1,25==(n=t).type?32|n.hour:29.97==n.type?64|n.hour:30==n.type?96|n.hour:n.hour,t.getMinute(),t.getSecond(),t.getFrame(),247];var n},sxMasterVolume:function(t){return t=ct.to14b(t),[240,127,this._sxid,4,1,vt(t),yt(t),247]},sxMasterFineTuning:function(t){return t=ct.to14b((t%1+1)/2),[240,127,this._sxid,4,3,vt(t),yt(t),247]},sxMasterCoarseTuning:function(t){return[240,127,this._sxid,4,4,0,64+t-t%1,247]},reset:function(){return[255]}},wt={bank:function(t,n,e){return void 0===e?[St.bankMSB(t,yt(n)),St.bankLSB(t,vt(n))]:[St.bankMSB(t,n),St.bankLSB(t,e)]},modF:function(t,n){return wt.mod(t,ct.to14b(n))},mod:function(t,n,e){return void 0===e?[St.modMSB(t,yt(n)),St.modLSB(t,vt(n))]:[St.modMSB(t,n),St.modLSB(t,e)]},breathF:function(t,n){return wt.breath(t,ct.to14b(n))},breath:function(t,n,e){return void 0===e?[St.breathMSB(t,yt(n)),St.breathLSB(t,vt(n))]:[St.breathMSB(t,n),St.breathLSB(t,e)]},footF:function(t,n){return wt.foot(t,ct.to14b(n))},foot:function(t,n,e){return void 0===e?[St.footMSB(t,yt(n)),St.footLSB(t,vt(n))]:[St.footMSB(t,n),St.footLSB(t,e)]},portamentoTimeF:function(t,n){return wt.portamentoTime(t,ct.to14b(n))},portamentoTime:function(t,n,e){return void 0===e?[St.portamentoMSB(t,yt(n)),St.portamentoLSB(t,vt(n))]:[St.portamentoMSB(t,n),St.portamentoLSB(t,e)]},dataF:function(t,n){return wt.data(t,ct.to14b(n))},data:function(t,n,e){return void 0===e?[St.dataMSB(t,yt(n)),St.dataLSB(t,vt(n))]:[St.dataMSB(t,n),St.dataLSB(t,e)]},volumeF:function(t,n){return wt.volume(t,ct.to14b(n))},volume:function(t,n,e){return void 0===e?[St.volumeMSB(t,yt(n)),St.volumeLSB(t,vt(n))]:[St.volumeMSB(t,n),St.volumeLSB(t,e)]},balanceF:function(t,n){return wt.balance(t,ct.to14b((n+1)/2))},balance:function(t,n,e){return void 0===e?[St.balanceMSB(t,yt(n)),St.balanceLSB(t,vt(n))]:[St.balanceMSB(t,n),St.balanceLSB(t,e)]},panF:function(t,n){return wt.pan(t,ct.to14b((n+1)/2))},pan:function(t,n,e){return void 0===e?[St.panMSB(t,yt(n)),St.panLSB(t,vt(n))]:[St.panMSB(t,n),St.panLSB(t,e)]},expressionF:function(t,n){return wt.expression(t,ct.to14b(n))},expression:function(t,n,e){return void 0===e?[St.expressionMSB(t,yt(n)),St.expressionLSB(t,vt(n))]:[St.expressionMSB(t,n),St.expressionLSB(t,e)]},nrpn:function(t,n,e){return void 0===e?[St.nrpnMSB(t,yt(n)),St.nrpnLSB(t,vt(n))]:[St.nrpnMSB(t,n),St.nrpnLSB(t,e)]},rpn:function(t,n,e){return void 0===e?[St.rpnMSB(t,yt(n)),St.rpnLSB(t,vt(n))]:[St.rpnMSB(t,n),St.rpnLSB(t,e)]},rpnPitchBendRange:function(t,n){return wt.rpn(t,0,0).concat(wt.data(t,mt(n-n%1),Math.floor(n%1*128)))},rpnFineTuning:function(t,n){return wt.rpn(t,0,1).concat(wt.dataF(t,(n%1+1)/2))},rpnCoarseTuning:function(t,n){return wt.rpn(t,0,2).concat([St.dataMSB(t,64+n-n%1)])},rpnTuning:function(t,n){return wt.rpnCoarseTuning(t,n).concat(wt.rpnFineTuning(t,n))},rpnTuningA:function(t,n){return wt.rpnTuning(t,ct.shift(n))}},Mt={sxMasterTuning:function(t){return[Ct.sxMasterCoarseTuning.call(this,t),Ct.sxMasterFineTuning.call(this,t)]},sxMasterTuningA:function(t){return Mt.sxMasterTuning.call(this,ct.shift(t))}};function xt(t,n){var e=new ct;return e.ff=gt(t),e.dd=void 0===n?"":function(t){t=""+t;for(var n=0;n<t.length;n++)255<t.charCodeAt(n)&&dt(t[n]);return t}(n),e}var Bt={smf:function(t){if(t instanceof ct)return new ct(t);var n=t instanceof Array?t:arguments,e=gt(n[0]),r="";return 2==n.length?r=Ft(n[1]):2<n.length&&(r=Ft(Array.prototype.slice.call(n,1))),xt(e,r)},smfSeqNumber:function(t){if(t==parseInt(t)){if(t<0||65535<t)throw RangeError("Sequence number out of range: "+t);t=String.fromCharCode(t>>8)+String.fromCharCode(255&t)}else if(0==(t=""+t).length)t="\0\0";else if(1==t.length)t="\0"+t;else if(2<t.length)throw RangeError("Sequence number out of range: "+kt(t));return xt(0,t)},smfText:function(t){return xt(1,ot.lib.toUTF8(t))},smfCopyright:function(t){return xt(2,ot.lib.toUTF8(t))},smfSeqName:function(t){return xt(3,ot.lib.toUTF8(t))},smfInstrName:function(t){return xt(4,ot.lib.toUTF8(t))},smfLyric:function(t){return xt(5,ot.lib.toUTF8(t))},smfMarker:function(t){return xt(6,ot.lib.toUTF8(t))},smfCuePoint:function(t){return xt(7,ot.lib.toUTF8(t))},smfProgName:function(t){return xt(8,ot.lib.toUTF8(t))},smfDevName:function(t){return xt(9,ot.lib.toUTF8(t))},smfChannelPrefix:function(t){if(t==parseInt(t))N(t),t=String.fromCharCode(t);else if(0==(t=""+t).length)t="\0";else if(1<t.length||15<t.charCodeAt(0))throw RangeError("Channel number out of range: "+kt(t));return xt(32,t)},smfMidiPort:function(t){if(t==parseInt(t)){if(t<0||127<t)throw RangeError("Port number out of range: "+t);t=String.fromCharCode(t)}else if(0==(t=""+t).length)t="\0";else if(1<t.length||127<t.charCodeAt(0))throw RangeError("Port number out of range: "+kt(t));return xt(33,t)},smfEndOfTrack:function(t){if(""!=Ft(t))throw RangeError("Unexpected data: "+kt(Ft(t)));return xt(47)},smfTempo:function(t){if(3==(""+t).length)return xt(81,t);if(t==parseInt(t)&&0<t&&t<=16777215)return xt(81,String.fromCharCode(t>>16)+String.fromCharCode(t>>8&255)+String.fromCharCode(255&t));throw RangeError("Out of range: "+kt(Ft(t)))},smfBPM:function(t){return Bt.smfTempo(Math.round(6e7/t))},smfSMPTE:function(t){if(t instanceof st)return xt(84,String.fromCharCode(t.hour)+String.fromCharCode(t.minute)+String.fromCharCode(t.second)+String.fromCharCode(t.frame)+String.fromCharCode(t.quarter%4*25));if(5==(""+t).length)return xt(84,t);var n=t instanceof Array?t:Array.prototype.slice.call(arguments);return n.splice(0,0,30),Bt.smfSMPTE(new st(n))},smfTimeSignature:function(t,n,e,r){var i,o,s,u,a=(""+t).match(/^\s*(\d+)\s*\/\s*(\d+)\s*$/);if(a){if(i=parseInt(a[1]),o=parseInt(a[2]),0<i&&i<=255&&o&&!(o&o-1)){for(s=o,o=0,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=e==parseInt(e)?e:8,xt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return xt(88,t)}else{if(t==parseInt(t)&&n==parseInt(n)&&n&&!(n&n-1)){for(i=t,o=0,s=n,s>>=1;s;s>>=1)o++;return s=e==parseInt(e)?e:24,u=r==parseInt(r)?r:8,xt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return xt(88,t)}throw RangeError("Wrong time signature: "+kt(Ft(t)))},smfKeySignature:function(t){var n,e,r=(t=""+t).match(/^\s*([A-H][b#]?)\s*(|maj|major|dur|m|min|minor|moll)\s*$/i);if(r&&(n={CB:0,GB:1,DB:2,AB:3,EB:4,BB:5,F:6,C:7,G:8,D:9,A:10,E:11,B:12,H:12,"F#":13,"C#":14,"G#":15,"D#":16,"A#":17}[r[1].toUpperCase()],e={"":0,MAJ:0,MAJOR:0,DUR:0,M:1,MIN:1,MINOR:1,MOLL:1}[r[2].toUpperCase()],void 0!==n&&void 0!==e&&(e&&(n-=3),-7<=(n-=7)&&n<0?t=String.fromCharCode(256+n)+String.fromCharCode(e):0<=n&&n<=7&&(t=String.fromCharCode(n)+String.fromCharCode(e)))),2==t.length&&t.charCodeAt(1)<=1&&(t.charCodeAt(0)<=7||t.charCodeAt(0)<=255&&249<=t.charCodeAt(0)))return xt(89,t);throw RangeError("Incorrect key signature: "+kt(t))},smfSequencer:function(t){return xt(127,Ft(t))}},It={};for(i in Ct)Ct.hasOwnProperty(i)&&function(t,n){ct[t]=function(){return new ct(n.apply(this,arguments))},It[t]=function(){return this.send(n.apply(this,arguments))}}(i,Ct[i]);for(i in Bt)Bt.hasOwnProperty(i)&&function(t,n){ct[t]=function(){return n.apply(this,arguments)},It[t]=function(){return this.send(n.apply(this,arguments))}}(i,Bt[i]);for(i in Mt)Mt.hasOwnProperty(i)&&function(t,r){ct[t]=function(){for(var t=[],n=r.apply(this,arguments),e=0;e<n.length;e++)t.push(new ct(n[e]));return t},It[t]=function(){for(var t=r.apply(this,arguments),n=this,e=0;e<t.length;e++)n=n.send(t[e]);return n}}(i,Mt[i]);for(i in bt)bt.hasOwnProperty(i)&&function(t,n){ct[t]=function(){return new ct(n.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))))},It[t]=function(){if(void 0===this._master)return this.send(n.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))));var t=new ct(n.apply(this,[this._master].concat(Array.prototype.slice.call(arguments))));return t._mpe=t[1],this.send(t)}}(i,bt[i]);for(i in St)St.hasOwnProperty(i)&&function(t,r){ct[t]=function(){return new ct(r.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))))},It[t]=function(){if(void 0===this._master)return this.send(r.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))));var t,n=Array.prototype.slice.call(arguments);n.length<r.length?n=[this._master].concat(n):(t=mt(ct.noteValue(n[0],n[0])),n[0]=this._master);var e=new ct(r.apply(this,n));return e._mpe=t,this.send(e)}}(i,St[i]);for(i in wt)wt.hasOwnProperty(i)&&function(t,s){ct[t]=function(){for(var t=[],n=s.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))),e=0;e<n.length;e++)t.push(new ct(n[e]));return t},It[t]=function(){var t,n,e;if(void 0!==this._master){var r,i=Array.prototype.slice.call(arguments);for(i.length<s.length?i=[this._master].concat(i):(r=mt(ct.noteValue(i[0],i[0])),i[0]=this._master),n=s.apply(this,i),e=this,t=0;t<n.length;t++){var o=ct(n[t]);o._mpe=r,e=e.send(o)}return e}for(n=s.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))),e=this,t=0;t<n.length;t++)e=e.send(n[t]);return e}}(i,wt[i]);function At(t){for(i in It)It.hasOwnProperty(i)&&(t.prototype[i]=It[i])}At(q);for(var Ot,Et={a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15},Pt=0;Pt<16;Pt++)Et[Pt]=Pt;function Tt(t){for(var n=[],e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function Ft(t){return t instanceof Array?function(t){for(var n="",e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return n}(t):void 0===t?"":""+t}function Lt(t){return(t<16?"0":"")+t.toString(16)}function qt(t){for(var n=[],e=0;e<t.length;e++)n[e]=Lt(t[e]);return n.join(" ")}function Dt(t){return t.length?": "+qt(Tt(t)):""}function kt(t){return t.length?": "+function(t){for(var n="",e=0;e<t.length;e++)"\n"==t[e]?n+="\\n":"\r"==t[e]?n+="\\r":"\t"==t[e]?n+="\\t":t.charCodeAt(e)<32?n+="\\x"+Lt(t.charCodeAt(e)):n+=t[e];return n}(ot.lib.fromUTF8(t)):""}function jt(){var t=this instanceof jt?this:t=new jt;return t.reset(),arguments.length&&jt.prototype.setup.apply(t,arguments),t}function zt(){var t,e;Ot||"undefined"==typeof window||(t=window.AudioContext||window.webkitAudioContext)&&((Ot=new t)&&!Ot.createGain&&(Ot.createGain=Ot.createGainNode),e=function(){if("running"!=Ot.state){Ot.resume();var t=Ot.createOscillator(),n=Ot.createGain();try{n.gain.value=0}catch(t){}n.gain.setTargetAtTime(0,Ot.currentTime,.01),t.connect(n),n.connect(Ot.destination),t.start||(t.start=t.noteOn),t.stop||(t.stop=t.noteOff),t.start(.1),t.stop(.11)}else document.removeEventListener("touchstart",e),document.removeEventListener("touchend",e),document.removeEventListener("mousedown",e),document.removeEventListener("keydown",e)},document.addEventListener("touchstart",e),document.addEventListener("touchend",e),document.addEventListener("mousedown",e),document.addEventListener("keydown",e),e())}ct.prototype.getChannel=function(){if(32==this.ff&&1==this.dd.length&&this.dd.charCodeAt(0)<16)return this.dd.charCodeAt(0);var t=this[0];return void 0===t||t<128||239<t?void 0:15&t},ct.prototype.setChannel=function(t){return void 0===(t=Et[t])||(32==this.ff?this.dd=String.fromCharCode(t):void 0!==(n=this[0])&&128<=n&&n<=239&&(this[0]=240&n|t)),this;var n},ct.prototype.getNote=function(){var t=this[0];if(!(void 0===t||t<128||175<t))return this[1]},ct.prototype.setNote=function(t){var n=this[0];return void 0===n||n<128||175<n||void 0!==(t=ct.noteValue(t))&&(this[1]=t),this},ct.prototype.getVelocity=function(){var t=this[0];if(!(void 0===t||t<128||159<t))return this[2]},ct.prototype.setVelocity=function(t){var n=this[0];return void 0===n||n<128||159<n||0<=(t=parseInt(t))&&t<128&&(this[2]=t),this},ct.prototype.getSysExId=function(){if(240==this[0])return this[2]},ct.prototype.setSysExId=function(t){return 240==this[0]&&2<this.length&&0<=(t=parseInt(t))&&t<128&&(this[2]=t),this},ct.prototype.getData=function(){if(void 0!==this.dd)return this.dd.toString()},ct.prototype.setData=function(t){return this.dd=Ft(t),this},ct.prototype.getText=function(){if(void 0!==this.dd)return ot.lib.fromUTF8(this.dd)},ct.prototype.setText=function(t){return this.dd=ot.lib.toUTF8(t),this},ct.prototype.getTempo=function(){if(81==this.ff&&void 0!==this.dd)return 65536*this.dd.charCodeAt(0)+256*this.dd.charCodeAt(1)+this.dd.charCodeAt(2)},ct.prototype.getBPM=function(){var t=this.getTempo();if(t)return 6e7/t},ct.prototype.getTimeSignature=function(){if(88==this.ff&&void 0!==this.dd)return[this.dd.charCodeAt(0),1<<this.dd.charCodeAt(1)]},ct.prototype.getKeySignature=function(){if(89==this.ff&&void 0!==this.dd){var t=this.dd.charCodeAt(0),n=this.dd.charCodeAt(1);if(128&t&&(t-=256),-7<=t&&t<=7&&0<=n&&n<=1)return[t,["Cb","Gb","Db","Ab","Eb","Bb","F","C","G","D","A","E","B","F#","C#","G#","D#","A#"][n?t+10:t+7],!!n]}},ct.prototype.isNoteOn=function(){var t=this[0];return!(void 0===t||t<144||159<t)&&0<this[2]},ct.prototype.isNoteOff=function(){var t=this[0];return!(void 0===t||t<128||159<t)&&(t<144||0==this[2])},ct.prototype.isSysEx=function(){return 240==this[0]},ct.prototype.isFullSysEx=function(){return 240==this[0]&&247==this[this.length-1]},ct.prototype.isSMF=function(){return 0<=this.ff&&this.ff<=127},ct.prototype.isEOT=function(){return 47==this.ff},ct.prototype.isTempo=function(){return 81==this.ff},ct.prototype.isTimeSignature=function(){return 88==this.ff},ct.prototype.isKeySignature=function(){return 89==this.ff},ct.prototype.toString=function(){if(!this.length){if(void 0===this.ff)return"empty";var t,n,e="ff"+Lt(this.ff)+" -- ";return 0==this.ff?e+="Sequence Number: "+function(t){for(var n=0,e=0;e<t.length;e++)n=(n<<8)+t.charCodeAt(e);return n}(this.dd):0<this.ff&&this.ff<10?e+=["","Text","Copyright","Sequence Name","Instrument Name","Lyric","Marker","Cue Point","Program Name","Device Name"][this.ff]+kt(this.dd):32==this.ff?e+="Channel Prefix"+Dt(this.dd):33==this.ff?e+="MIDI Port"+Dt(this.dd):47==this.ff?e+="End of Track"+Dt(this.dd):81==this.ff?e+="Tempo: "+Math.round(100*this.getBPM())/100+" bpm":84==this.ff?e+="SMPTE Offset: "+ht(Tt(this.dd)):88==this.ff?(t=1<<this.dd.charCodeAt(1),e+="Time Signature: "+this.dd.charCodeAt(0)+"/"+t,e+=" "+this.dd.charCodeAt(2)+" "+this.dd.charCodeAt(3)):89==this.ff?(e+="Key Signature: ",(n=this.getKeySignature())?(e+=n[1],n[2]&&(e+=" min")):e+="invalid"):127==this.ff?e+="Sequencer Specific"+Dt(this.dd):e+="SMF"+Dt(this.dd),e}if(e=qt(this),this[0]<128)return e;if(r={241:"MIDI Time Code",242:"Song Position",243:"Song Select",244:"Undefined",245:"Undefined",246:"Tune request",248:"Timing clock",249:"Undefined",250:"Start",251:"Continue",252:"Stop",253:"Undefined",254:"Active Sensing",255:"Reset"}[this[0]])return e+" -- "+r;var r,i=this[0]>>4;return(r={8:"Note Off",10:"Aftertouch",12:"Program Change",13:"Channel Aftertouch",14:"Pitch Wheel"}[i])?e+" -- "+r:9==i?e+" -- "+(this[2]?"Note On":"Note Off"):11!=i?e:e+" -- "+(r=(r={0:"Bank Select MSB",1:"Modulation Wheel MSB",2:"Breath Controller MSB",4:"Foot Controller MSB",5:"Portamento Time MSB",6:"Data Entry MSB",7:"Channel Volume MSB",8:"Balance MSB",10:"Pan MSB",11:"Expression Controller MSB",12:"Effect Control 1 MSB",13:"Effect Control 2 MSB",16:"General Purpose Controller 1 MSB",17:"General Purpose Controller 2 MSB",18:"General Purpose Controller 3 MSB",19:"General Purpose Controller 4 MSB",32:"Bank Select LSB",33:"Modulation Wheel LSB",34:"Breath Controller LSB",36:"Foot Controller LSB",37:"Portamento Time LSB",38:"Data Entry LSB",39:"Channel Volume LSB",40:"Balance LSB",42:"Pan LSB",43:"Expression Controller LSB",44:"Effect control 1 LSB",45:"Effect control 2 LSB",48:"General Purpose Controller 1 LSB",49:"General Purpose Controller 2 LSB",50:"General Purpose Controller 3 LSB",51:"General Purpose Controller 4 LSB",64:"Damper Pedal On/Off",65:"Portamento On/Off",66:"Sostenuto On/Off",67:"Soft Pedal On/Off",68:"Legato On/Off",69:"Hold 2",70:"Sound Controller 1",71:"Sound Controller 2",72:"Sound Controller 3",73:"Sound Controller 4",74:"Sound Controller 5",75:"Sound Controller 6",76:"Sound Controller 7",77:"Sound Controller 8",78:"Sound Controller 9",79:"Sound Controller 10",80:"General Purpose Controller 5",81:"General Purpose Controller 6",82:"General Purpose Controller 7",83:"General Purpose Controller 8",84:"Portamento Control",88:"High Resolution Velocity Prefix",91:"Effects 1 Depth",92:"Effects 2 Depth",93:"Effects 3 Depth",94:"Effects 4 Depth",95:"Effects 5 Depth",96:"Data Increment",97:"Data Decrement",98:"Non-Registered Parameter Number LSB",99:"Non-Registered Parameter Number MSB",100:"Registered Parameter Number LSB",101:"Registered Parameter Number MSB",120:"All Sound Off",121:"Reset All Controllers",122:"Local Control On/Off",123:"All Notes Off",124:"Omni Mode Off",125:"Omni Mode On",126:"Mono Mode On",127:"Poly Mode On"}[this[1]])||"Undefined")},ct.prototype._stamp=function(t){return this._from.push(t._orig?t._orig:t),this},ct.prototype._unstamp=function(t){var n;return void 0===t?this._from=[]:(t._orig&&(t=t._orig),-1<(n=this._from.indexOf(t))&&this._from.splice(n,1)),this},ct.prototype._stamped=function(t){t._orig&&(t=t._orig);for(var n=0;n<this._from.length;n++)if(this._from[n]==t)return!0;return!1},ot.MIDI=ct,jt.validate=function(t){var n=t instanceof Array?t:arguments;if(n[0]!=parseInt(n[0])||n[0]<0||14<n[0])throw RangeError("Bad master channel value: "+n[0]);if(n[1]!=parseInt(n[1])||n[1]<0||15<n[0]+n[1])throw RangeError("Bad zone size value: "+n[1])},jt.prototype.reset=function(){for(var t=0;t<16;t++)this[t]={band:0,master:t}},jt.prototype.setup=function(t,n){var e;jt.validate(t,n);var r=t+n;if((this[t].master!=t||this[t].band!=n)&&(n||this[t].band)){for(this[t].band?r<(e=t+this[t].band)&&(r=e):this[t].master==t-1?(e=t-1,r<(e+=this[e].band)&&(r=e),this[t-1]={band:0,master:t-1}):this[t].master!=t&&(e=this[t].master,r<(e+=this[e].band)&&(r=e),this[this[t].master].band=t-this[t].master-1),this[t].master=t,this[t].band=n,e=t+1;e<=t+n;e++)this[e].band&&r<e+this[e].band&&(r=e+this[e].band),this[e]={band:0,master:t};for(;e<=r;e++)this[e]={band:0,master:e}}},jt.prototype.filter=function(t){var n=t.getChannel();if(!this[n]||!this[this[n].master].band)return t;var e,r,i,o=this[n].master,s=this[o].band;if(void 0!==t._mpe){for(i=256,e=o+1;e<=o+s;e++)if(this[e].notes){for(i>this[e].notes.length&&(i=this[n=e].notes.length),r=0;r<this[e].notes.length;r++)if(this[e].notes[r]==t._mpe){n=e,i=-1;break}}else 0<i&&(n=e,i=0);t.setChannel(n),t._mpe=void 0}return n==o||(t.isNoteOn()?(this[n].notes||(this[n].notes=[]),y(this[n].notes,t.getNote())):t.isNoteOff()&&this[n].notes&&b(this[n].notes,t.getNote())),t},ot.MPE=jt,(ot.lib={}).now=a,ot.lib.schedule=h,ot.lib.openMidiOut=function(t,n){var e=new q;return n._openOut(e),e._info=n._info(t),e},ot.lib.openMidiIn=function(t,n){var e=new q;return n._openIn(e),e._info=n._info(t),e},ot.lib.registerMidiOut=function(t,n){for(var e=n._info(t),r=0;r<H._outs.length;r++)if(H._outs[r].name==e.name)return!1;return e.engine=n,H._outs.push(e),w&&(A(),w._bad&&(w._repair(),w._resume())),!0},ot.lib.registerMidiIn=function(t,n){for(var e=n._info(t),r=0;r<H._ins.length;r++)if(H._ins[r].name==e.name)return!1;return e.engine=n,H._ins.push(e),w&&(A(),w._bad&&(w._repair(),w._resume())),!0},ot.lib.copyMidiHelpers=At,ot.lib.getAudioContext=function(){return zt(),Ot};var Rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";ot.lib.fromBase64=function(t){var n,e,r,i,o,s,u="",a=0;for(t=t.replace(/[^A-Za-z0-9+/=]/g,"");a<t.length;)n=Rt.indexOf(t.charAt(a++))<<2|(i=Rt.indexOf(t.charAt(a++)))>>4,e=(15&i)<<4|(o=Rt.indexOf(t.charAt(a++)))>>2,r=(3&o)<<6|(s=Rt.indexOf(t.charAt(a++))),u+=String.fromCharCode(n),64!=o&&(u+=String.fromCharCode(e)),64!=s&&(u+=String.fromCharCode(r));return u},ot.lib.toBase64=function(t){var n,e,r,i,o,s=0,u=0,a="",h=[];if(!t)return t;for(;n=(o=t.charCodeAt(s++)<<16|t.charCodeAt(s++)<<8|t.charCodeAt(s++))>>18&63,e=o>>12&63,r=o>>6&63,i=63&o,h[u++]=Rt.charAt(n)+Rt.charAt(e)+Rt.charAt(r)+Rt.charAt(i),s<t.length;);a=h.join("");var c=t.length%3;return c?a.slice(0,c-3)+"===".slice(c):a},ot.lib.fromUTF8=function(t){t=void 0===t?"":""+t;for(var n,e,r="",i=0;i<t.length;i++){if(255<(n=t.charCodeAt(i)))return t;if(n<128)r+=t[i];else if(192==(224&n)){if(n=(31&n)<<6,++i>=t.length)return t;if(128!=(192&(e=t.charCodeAt(i))))return t;n+=63&e,r+=String.fromCharCode(n)}else if(224==(240&n)){if(n=(15&n)<<12,++i>=t.length)return t;if(128!=(192&(e=t.charCodeAt(i))))return t;if(n+=(63&e)<<6,++i>=t.length)return t;if(128!=(192&(e=t.charCodeAt(i))))return t;n+=63&e,r+=String.fromCharCode(n)}else if(240==(248&n)){if(n=(7&n)<<18,++i>=t.length)return t;if(128!=(192&(e=t.charCodeAt(i))))return t;if(n+=(63&e)<<12,++i>=t.length)return t;if(128!=(192&(e=t.charCodeAt(i))))return t;if(n+=(63&e)<<6,++i>=t.length)return t;if(128!=(192&(e=t.charCodeAt(i))))return t;if(1114111<(n+=63&e))return t;n-=65536,r+=String.fromCharCode(55296+(n>>10)),r+=String.fromCharCode(56320+(1023&n))}}return r},ot.lib.toUTF8=function(t){t=void 0===t?"":""+t;for(var n,e="",r=0;r<t.length;r++)(n=t.charCodeAt(r))<128?e+=t[r]:(n<2048?e+=String.fromCharCode(192+(n>>6)):(n<65536?e+=String.fromCharCode(224+(n>>12)):(e+=String.fromCharCode(240+(n>>18)),e+=String.fromCharCode(128+(n>>12&63))),e+=String.fromCharCode(128+(n>>6&63))),e+=String.fromCharCode(128+(63&n)));return e};var Nt=[],Ut={},Gt={},Vt=n.Promise;function Zt(t,n,e){this.name=t,this.message=n,this.code=e}function Jt(t,n){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=n,this.defaultPrevented=!1,this.eventPhase=0,this.path=[],this.port=t,this.returnValue=!0,this.srcElement=n,this.target=n,this.timeStamp=a(),this.type="statechange"}function Wt(t,n){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=t,this.data=n,this.defaultPrevented=!1,this.eventPhase=0,this.path=[],this.receivedTime=a(),this.returnValue=!0,this.srcElement=t,this.target=t,this.timeStamp=this.receivedTime,this.type="midimessage"}function Ht(t,n){t&&(t.onstatechange&&t.onstatechange(new Jt(t,t)),n.onstatechange&&n.onstatechange(new Jt(t,n)))}function Qt(e,r){var i=this,o=!1,n=null,s=null;this.type="input",this.id=r.id,this.name=r.name,this.manufacturer=r.man,this.version=r.ver,Object.defineProperty(this,"state",{get:function(){return r.connected?"connected":"disconnected"},enumerable:!0}),Object.defineProperty(this,"connection",{get:function(){return o?r.proxy?"open":"pending":"closed"},enumerable:!0}),Object.defineProperty(this,"onmidimessage",{get:function(){return s},set:function(t){if(t instanceof Function){if(s=t,!o)try{i.open()}catch(t){}}else s=null},enumerable:!0}),Object.defineProperty(this,"onstatechange",{get:function(){return n},set:function(t){n=t instanceof Function?t:null},enumerable:!0}),this.open=function(){return new Vt(function(t,n){o?t(i):r.open().then(function(){o||(o=!0,Ht(i,e)),t(i)},function(){n(new Zt("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new Vt(function(t){o&&(o=!1,r.close(),Ht(i,e)),t(i)})},Object.freeze(this)}function Kt(t){for(var n,e;t.length;){for(n=0;n<t.length&&!(t[n]==parseInt(t[n])&&128<=t[n]&&t[n]<=255&&247!=t[n]);n++);if(t.splice(0,n),!t.length)return;if(240==t[0]){for(n=1;n<t.length&&247!=t[n];n++);if(n==t.length)return;return t.splice(0,n+1)}if((e=Xt(t[0])+1)>t.length)return;for(n=1;n<e&&!(t[n]!=parseInt(t[n])||t[n]<0||128<=t[n]);n++);if(n==e)return t.splice(0,n);t.splice(0,n)}}function $t(t,n,e,r){var i=this;this.id=t,this.name=n,this.man=e,this.ver=r,this.connected=!0,this.ports=[],this.pending=[],this.proxy=void 0,this.queue=[],this.onmidi=function(t){var n;for(i.queue=i.queue.concat(t.slice()),n=Kt(i.queue);n;n=Kt(i.queue))for(o=0;o<i.ports.length;o++)i.ports[o][0].onmidimessage&&(240!=n[0]||i.ports[o][1])&&i.ports[o][0].onmidimessage(new Wt(i,new Uint8Array(n)))}}function Xt(t){return 128<=t&&t<=191||224<=t&&t<=239||242==t?2:192<=t&&t<=223||241==t||243==t?1:0}"function"!=typeof Vt&&((Vt=function(t){this.executor=t}).prototype.then=function(t,n){"function"!=typeof t&&(t=function(){}),"function"!=typeof n&&(n=function(){}),this.executor(t,n)}),$t.prototype.open=function(){var r=this;return new Vt(function(t,n){var e;r.proxy||!r.connected?t():(r.pending.push([t,n]),1==r.pending.length&&ot().openMidiIn(r.name).or(function(){for(e=0;e<r.pending.length;e++)r.pending[e][1]();r.pending=[]}).and(function(){for(r.proxy=this,r.proxy.connect(r.onmidi),e=0;e<r.pending.length;e++)r.pending[e][0]();r.pending=[]}))})},$t.prototype.close=function(){var t;if(this.proxy){for(t=0;t<this.ports.length;t++)if("open"==this.ports[t].connection)return;this.proxy.close(),this.proxy=void 0}},$t.prototype.disconnect=function(){this.connected=!1,this.proxy&&(this.proxy.close(),this.proxy=void 0)},$t.prototype.reconnect=function(){var t,n,e=this,r=[];for(this.connected=!0,t=0;t<Nt.length;t++)"closed"==(n=Nt[t].inputs.get(this.id)).connection?Ht(n,Nt[t]):r.push([n,Nt[t]]);r.length&&ot()._openMidiInNR(e.name).or(function(){for(t=0;t<r.length;t++)r[t][0].close()}).and(function(){for(e.proxy=this,e.proxy.connect(e.onmidi),t=0;t<r.length;t++)Ht(r[t][0],r[t][1])})};var Yt="Failed to execute 'send' on 'MIDIOutput': ";function tn(r,i){var o=this,s=!1,n=null;this.type="output",this.id=i.id,this.name=i.name,this.manufacturer=i.man,this.version=i.ver,Object.defineProperty(this,"state",{get:function(){return i.connected?"connected":"disconnected"},enumerable:!0}),Object.defineProperty(this,"connection",{get:function(){return s?i.proxy?"open":"pending":"closed"},enumerable:!0}),Object.defineProperty(this,"onstatechange",{get:function(){return n},set:function(t){n=t instanceof Function?t:null},enumerable:!0}),this.open=function(){return new Vt(function(t,n){s?t(o):i.open().then(function(){s||(s=!0,Ht(o,r)),t(o)},function(){n(new Zt("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new Vt(function(t){s&&(s=!1,o.clear(),i.close(),Ht(o,r)),t(o)})},this.clear=function(){},this.send=function(t,n){if(!function(t,n){for(var e,r,i=[],o=0;o<t.length;o++)if(t[o]!=parseInt(t[o])||t[o]<0||255<t[o])throw TypeError(Yt+t[o]+" is not a UInt8 value.");for(o=e=0;o<t.length;o++)if(e){if(127<t[o])throw TypeError(Yt+"Unexpected status byte at index "+o+" ("+t[o]+").");r.push(t[o]),e--}else{if(t[o]<128)throw TypeError(Yt+"Running status is not allowed at index "+o+" ("+t[o]+").");if(247==t[o])throw TypeError(Yt+"Unexpected end of system exclusive message at index "+o+" ("+t[o]+").");if(r=[t[o]],i.push(r),240==t[o]){if(!n)throw new Zt("InvalidAccessError",Yt+"System exclusive messag is not allowed at index "+o+" ("+t[o]+").",15);for(e=-1;o<t.length;o++)if(r.push(t[o]),247==t[o]){e=0;break}}else e=Xt(t[o])}if(e)throw TypeError(Yt+"Message is incomplete")}(t,r.sysexEnabled),!i.connected)throw new Zt("InvalidStateError","Port is not connected",11);var e;s?(e=a())<n?setTimeout(function(){i.proxy.send(t)},n-e):i.proxy.send(t):this.open().then(function(){o.send(t,n)})},Object.freeze(this)}function nn(t,n,e,r){this.id=t,this.name=n,this.man=e,this.ver=r,this.connected=!0,this.ports=[],this.pending=[],this.proxy=void 0}function en(r){this.has=function(t){return r.hasOwnProperty(t)&&r[t].connected},this.keys=function(){try{var t=new Map;for(var n in r)this.has(n)&&t.set(n,this.get(n));return t.keys()}catch(t){}},this.values=function(){try{var t=new Map;for(var n in r)this.has(n)&&t.set(n,this.get(n));return t.values()}catch(t){}},this.entries=function(){try{var t=new Map;for(var n in r)this.has(n)&&t.set(n,this.get(n));return t.entries()}catch(t){}},this.forEach=function(t,n){for(var e in void 0===n&&(n=this),r)this.has(e)&&t.call(n,this.get(e),e,this)},Object.defineProperty(this,"size",{get:function(){var t=0;for(var n in r)this.has(n)&&t++;return t},enumerable:!0})}function rn(n,e){this.get=function(t){if(Gt.hasOwnProperty(t)&&Gt[t].connected)return e[t]||(e[t]=new Qt(n,Gt[t]),Gt[t].ports.push([e[t],n.sysexEnabled])),e[t]},Object.freeze(this)}function on(n,e){this.get=function(t){if(Ut.hasOwnProperty(t)&&Ut[t].connected)return e[t]||(e[t]=new tn(n,Ut[t]),Ut[t].ports.push([e[t],n.sysexEnabled])),e[t]},Object.freeze(this)}function sn(t){for(var n,e,r,i=0;i<t.inputs.added.length;i++)e=t.inputs.added[i],Gt.hasOwnProperty(e.id)||(Gt[e.id]=new $t(e.id,e.name,e.manufacturer,e.version)),Gt[e.id].reconnect();for(i=0;i<t.outputs.added.length;i++)e=t.outputs.added[i],Ut.hasOwnProperty(e.id)||(Ut[e.id]=new nn(e.id,e.name,e.manufacturer,e.version)),Ut[e.id].reconnect();for(i=0;i<t.inputs.removed.length;i++)if(e=t.inputs.removed[i],Gt.hasOwnProperty(e.id)){for(r=[],n=0;n<Nt.length;n++)r.push([Nt[n].inputs.get(e.id),Nt[n]]);for(Gt[e.id].disconnect(),n=0;n<r.length;n++)Ht(r[n][0],r[n][1])}for(i=0;i<t.outputs.removed.length;i++)if(e=t.outputs.removed[i],Ut.hasOwnProperty(e.id)){for(r=[],n=0;n<Nt.length;n++)r.push([Nt[n].outputs.get(e.id),Nt[n]]);for(Ut[e.id].disconnect(),n=0;n<r.length;n++)Ht(r[n][0],r[n][1])}}function un(t){var n,e=null;this.sysexEnabled=t,this.inputs=new rn(this,{}),this.outputs=new on(this,{}),Object.defineProperty(this,"onstatechange",{get:function(){return e},set:function(t){e=t instanceof Function?t:null},enumerable:!0}),Object.freeze(this);for(var r=w._info,i=0;i<r.inputs.length;i++)n=r.inputs[i],Gt.hasOwnProperty(n.id)||(Gt[n.id]=new $t(n.id,n.name,n.manufacturer,n.version));for(i=0;i<r.outputs.length;i++)n=r.outputs[i],Ut.hasOwnProperty(n.id)||(Ut[n.id]=new nn(n.id,n.name,n.manufacturer,n.version));Nt.length||ot().onChange(sn),Nt.push(this)}return nn.prototype.open=function(){var r=this;return new Vt(function(t,n){var e;r.proxy||!r.connected?t():(r.pending.push([t,n]),1==r.pending.length&&ot().openMidiOut(r.name).or(function(){for(e=0;e<r.pending.length;e++)r.pending[e][1]();r.pending=[]}).and(function(){for(r.proxy=this,e=0;e<r.pending.length;e++)r.pending[e][0]();r.pending=[]}))})},nn.prototype.close=function(){var t;if(this.proxy){for(t=0;t<this.ports.length;t++)if("open"==this.ports[t].connection)return;this.proxy.close(),this.proxy=void 0}},nn.prototype.disconnect=function(){this.connected=!1,this.proxy&&(this.proxy.close(),this.proxy=void 0)},nn.prototype.reconnect=function(){var t,n,e=this,r=[];for(this.connected=!0,t=0;t<Nt.length;t++)"closed"==(n=Nt[t].outputs.get(this.id)).connection?Ht(n,Nt[t]):r.push([n,Nt[t]]);r.length&&ot()._openMidiOutNR(e.name).or(function(){for(t=0;t<r.length;t++)r[t][0].close()}).and(function(){for(e.proxy=this,t=0;t<r.length;t++)Ht(r[t][0],r[t][1])})},(rn.prototype=new en(Gt)).constructor=rn,(on.prototype=new en(Ut)).constructor=on,ot.requestMIDIAccess=function(i){return new Vt(function(e,r){ot.JZZ(i).or(function(){}).and(function(){var t,n=!(!i||!i.sysex);n&&!this.info().sysex?r(new Zt("SecurityError","Sysex is not allowed",18)):(t=new un(n),e(t))})})},"undefined"==typeof navigator||navigator.requestMIDIAccess||(navigator.requestMIDIAccess=ot.requestMIDIAccess),ot.close=function(){W._close&&W._close()},ot});