/
JZZ.js
1 lines (1 loc) · 56.2 KB
/
JZZ.js
1
!function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define("JZZ",[],e);else{if((t=t||window).JZZ&&t.JZZ.MIDI)return;t.JZZ=e()}}(this,function(){var o,r,t,i,e="undefined"==typeof window?global:window,n="1.1.4",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,e){this._bad?e instanceof Function&&e.apply(this,[new Error(this._err())]):t instanceof Function&&t.apply(this,[this])}function p(t,e){this._bad?t._crash(this._err()):setTimeout(function(){t._resume()},e)}function l(t){this._bad&&t._break(this._err()),t._resume()}function d(t,n,r){t[r]=function(){var t=arguments,e=n._image();return this._push(l,[e]),e[r].apply(e,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 e,n=t.shift();t.length&&(e=this)._slip(m,[function(){v.apply(e,[t])}]);try{this._repair(),n.apply(this)}catch(t){this._break(t.toString())}}else this._break()}function y(t,e){for(var n=0;n<t.length;n++)if(t[n]===e)return;t.push(e)}function C(t,e){for(var n=0;n<t.length;n++)if(t[n]===e)return void t.splice(n,1)}function b(){c.apply(this)}function w(t,e,n){if(void 0===e)return w(t,[],[]);if(t instanceof Object){for(var r,i=0;i<e.length;i++)if(e[i]===t)return n[i];for(var o in r=t instanceof Array?[]:{},e.push(t),n.push(r),t)t.hasOwnProperty(o)&&(r[o]=w(t[o],e,n));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,e){this._queue.push([t,e]),c.prototype._exec.apply(this)},c.prototype._slip=function(t,e){this._queue.unshift([t,e])},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 w(this._log)},c.prototype._image=function(){function t(){}t.prototype=this._orig;var e=new t;return e._ready=!1,e._queue=[],e},c.prototype._thenable=function(){function t(){}var n=this;t.prototype=n;var e=new t;return e.then=function(t,e){return n._push(f,[t,e]),this},e},c.prototype.wait=function(t){if(!t)return this;var e=this._image();return this._push(p,[e,t]),e._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=w(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()},(b.prototype=new c)._info={name:"JZZ.js",ver:n,version:n,inputs:[],outputs:[]};var S,M=[],O=[],I=[],A=[];function E(){var t,e;for(S._info.engine=Q._type,S._info.version=Q._version,S._info.sysex=Q._sysex,S._info.inputs=[],S._info.outputs=[],M=[],O=[],Q._allOuts={},Q._allIns={},t=0;t<Q._outs.length;t++)((e=Q._outs[t]).engine=Q)._allOuts[e.name]=e,S._info.outputs.push({id:e.name,name:e.name,manufacturer:e.manufacturer,version:e.version,engine:Q._type}),M.push(e);for(t=0;t<K._outs.length;t++)e=K._outs[t],S._info.outputs.push({id:e.name,name:e.name,manufacturer:e.manufacturer,version:e.version,engine:e.type}),M.push(e);for(t=0;t<Q._ins.length;t++)((e=Q._ins[t]).engine=Q)._allIns[e.name]=e,S._info.inputs.push({id:e.name,name:e.name,manufacturer:e.manufacturer,version:e.version,engine:Q._type}),O.push(e);for(t=0;t<K._ins.length;t++)e=K._ins[t],S._info.inputs.push({id:e.name,name:e.name,manufacturer:e.manufacturer,version:e.version,engine:e.type}),O.push(e);if(S._watcher&&S._watcher._handles.length){var n=function(t,e,n,r){if(!function(t,e,n,r){var i;if(t.length!=n.length||e.length!=r.length)return!0;for(i=0;i<t.length;i++)if(t[i].name!=n[i].name)return!0;for(i=0;i<e.length;i++)if(e[i].name!=r[i].name)return!0;return!1}(t,e,n,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<n.length;i++)h[n[i].name]||o.push(n[i]);for(h={},i=0;i<n.length;i++)h[n[i].name]=!0;for(i=0;i<t.length;i++)h[t[i].name]||u.push(t[i]);for(h={},i=0;i<e.length;i++)h[e[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<e.length;i++)h[e[i].name]||a.push(e[i]);return{inputs:{added:o,removed:u},outputs:{added:s,removed:a}}}(A,I,S._info.inputs,S._info.outputs);if(n){for(r=0;r<n.inputs.removed.length;r++)(e=Q._inMap[n.inputs.removed[r].name])&&e._closeAll();for(r=0;r<n.outputs.removed.length;r++)(e=Q._outMap[n.outputs.removed[r].name])&&e._closeAll();!function(t){for(o=0;o<S._watcher._handles.length;o++)S._watcher._handles[o].apply(S,[t])}(n)}}A=S._info.inputs,I=S._info.outputs}function x(){this._bad||Q._refresh(this)}function P(t,e){var n;t instanceof Function&&(t=t(e)),t instanceof Array||(t=[t]);for(var r=[],i=[],o=e.slice(),s=r,u=0;u<t.length;u++)if(void 0===t[u])s=i;else if(t[u]instanceof RegExp)for(n=0;n<o.length;n++)t[u].test(o[n].name)&&(s.push(o[n]),o.splice(n,1),n--);else for(n=0;n<o.length;n++)(t[u]+""==n+""||t[u]===o[n].name||t[u]instanceof Object&&t[u].name===o[n].name)&&(s.push(o[n]),o.splice(n,1),n--);return s==r?r:r.concat(o).concat(i)}function B(t,e){var n=e instanceof RegExp?"Port matching "+e+" not found":e instanceof Object||void 0===e?"Port not found":'Port "'+e+'" not found';t._crash(n)}function T(t,e){if(this._bad)t._crash(this._err());else{var n=P(e,M);if(!n.length)return void B(t,e);for(var r=0;r<n.length;r++)n[r]=function(t){return function(){t.engine._openOut(this,t.name)}}(n[r]);t._slip(v,[n]),t._resume()}}function F(t,e){if(this._bad)t._crash(this._err());else{var n=P(e,O);if(!n.length)return void B(t,e);for(var r=0;r<n.length;r++)n[r]=function(t){return function(){t.engine._openIn(this,t.name)}}(n[r]);t._slip(v,[n]),t._resume()}}function q(t,e){this._bad?t._crash():(t._slip(V,[e]),t._resume())}function D(){c.apply(this),this._handles=[],this._outs=[]}function L(t){this._bad||this._receive(t)}function j(t){this._emit(t)}function z(t){t instanceof Function?y(this._orig._handles,t):y(this._orig._outs,t)}function k(t){void 0===t?(this._orig._handles=[],this._orig._outs=[]):t instanceof Function?C(this._orig._handles,t):C(this._orig._outs,t)}function N(t,e){this._orig._mpe||(this._orig._mpe=new jt),this._orig._mpe.setup(t,e)}function R(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(t,e){D.apply(this),this._port=t._orig,this._chan=e,d(this,this._port,"ch"),d(this,this._port,"mpe"),d(this,this._port,"connect"),d(this,this._port,"disconnect"),d(this,this._port,"close")}function G(t,e,n){D.apply(this),this._port=t._orig,this._master=e,this._band=n,d(this,this._port,"ch"),d(this,this._port,"mpe"),d(this,this._port,"connect"),d(this,this._port,"disconnect"),d(this,this._port,"close")}function Z(){c.apply(this),this._handles=[],d(this,S,"refresh"),d(this,S,"openMidiOut"),d(this,S,"openMidiIn"),d(this,S,"onChange"),d(this,S,"close")}function V(t){t instanceof Function&&(this._orig._handles.length||Q._watch(),y(this._orig._handles,t))}function J(t){void 0===t?this._orig._handles=[]:C(this._orig._handles,t),this._orig._handles.length||Q._unwatch()}b.prototype.refresh=function(){return this._push(x,[]),this._thenable()},b.prototype.openMidiOut=function(t){var e=new D;return this._push(x,[]),this._push(T,[e,t]),e._thenable()},b.prototype._openMidiOutNR=function(t){var e=new D;return this._push(T,[e,t]),e._thenable()},b.prototype.openMidiIn=function(t){var e=new D;return this._push(x,[]),this._push(F,[e,t]),e._thenable()},b.prototype._openMidiInNR=function(t){var e=new D;return this._push(F,[e,t]),e._thenable()},b.prototype.onChange=function(t){this._orig._watcher||(this._orig._watcher=new Z);var e=this._orig._watcher._image();return this._push(q,[e,t]),e._thenable()},b.prototype._close=function(){Q._close()},(D.prototype=new c)._filter=function(t){var e,n;return this._orig._mpe&&(n=0,this._handles&&this._handles.length&&(n=this._handles.length,e=this._handles[0]),this._outs&&this._outs.length&&(n=this._outs.length,e=this._outs[0]),1!=n||e._mpe||(t=this._orig._mpe.filter(t))),t},D.prototype._receive=function(t){this._emit(this._filter(t))},D.prototype.send=function(){return this._push(L,[pt.apply(null,arguments)]),this._thenable()},D.prototype.note=function(t,e,n,r){return this.noteOn(t,e,n),0<r&&this.wait(r).noteOff(t,e),this._thenable()},D.prototype._emit=function(t){for(var e=0;e<this._handles.length;e++)this._handles[e].apply(this,[pt(t)._stamp(this)]);for(e=0;e<this._outs.length;e++){var n=pt(t);n._stamped(this._outs[e])||this._outs[e].send(n._stamp(this))}},D.prototype.emit=function(t){return this._push(j,[t]),this._thenable()},D.prototype.connect=function(t){return this._push(z,[t]),this._thenable()},D.prototype.disconnect=function(t){return this._push(k,[t]),this._thenable()},D.prototype.connected=function(){return this._orig._handles.length+this._orig._outs.length},D.prototype.ch=function(t){if(void 0===t)return this;R(t);var e=new U(this,t);return this._push(l,[e]),e._thenable()},D.prototype.mpe=function(t,e){if(void 0===t&&void 0===e)return this;jt.validate(t,e);var n=e?new G(this,t,e):new U(this,t);return this._push(N,[t,e]),this._push(l,[n]),n._thenable()},(U.prototype=new D).channel=function(){return this._chan},U.prototype._receive=function(t){this._port._receive(t)},U.prototype.note=function(t,e,n){return this.noteOn(t,e),n&&this.wait(n).noteOff(t),this._thenable()},(G.prototype=new D).channel=function(){return this._master},G.prototype._receive=function(t){this._port._receive(t)},G.prototype.note=function(t,e,n){return this.noteOn(t,e),n&&this.wait(n).noteOff(t),this._thenable()},(Z.prototype=new c).connect=function(t){return this._push(V,[t]),this._thenable()},Z.prototype.disconnect=function(t){return this._push(J,[t]),this._thenable()};var W,H,Q={_outs:[],_ins:[]},K={_outs:[],_ins:[]};function $(){if("undefined"!=typeof module&&module.exports)return t=require("jazz-midi"),Q._type="node",Q._main=t,Q._pool=[],Q._newPlugin=function(){return new t.MIDI},void ot();var t;this._break()}function X(){var t=document.createElement("div");t.style.visibility="hidden",document.body.appendChild(t);var e,n=document.createElement("object");if(n.style.visibility="hidden",n.style.width="0px",n.style.height="0px",n.classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90",n.type="audio/x-jazz",document.body.appendChild(n),n.isJazz)return e=n,Q._type="plugin",Q._main=e,Q._pool=[e],Q._newPlugin=function(){var t=document.createElement("object");return t.style.visibility="hidden",t.style.width="0px",e.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 ot();this._break()}if("undefined"!=typeof navigator&&navigator.requestMIDIAccess){W=navigator,H=navigator.requestMIDIAccess;try{-1!=H.toString().indexOf("JZZ(")&&(H=void 0)}catch(t){}}function Y(){if(H){var e=this;return H.call(W,{}).then(function(t){st(t),e._resume()},function(t){e._crash(t)}),void this._pause()}this._break()}function tt(){if(H){var e=this;return H.call(W,{sysex:!0}).then(function(t){st(t,!0),e._resume()},function(t){e._crash(t)}),void this._pause()}this._break()}function et(){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 e,n,r,i=[];try{i=JSON.parse(u.innerText)}catch(t){}u.innerText="",document.removeEventListener("jazz-midi-msg",t),"version"===i[0]?(e=u,n=i[2],Q._type="extension",Q._version=n,Q._sysex=!0,Q._pool=[],Q._outs=[],Q._ins=[],Q._inArr=[],Q._outArr=[],Q._inMap={},Q._outMap={},Q._outsW=[],Q._insW=[],Q.refreshClients=[],Q._msg=e,Q._newPlugin=function(){var t={id:Q._pool.length};Q._pool.push(t),t.id?document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["new"]})):t.ready=!0},Q._newPlugin(),Q._refresh=function(t){Q.refreshClients.push(t),t._pause(),h(function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["refresh"]}))})},Q._openOut=function(t,e){var n,r=Q._outMap[e];r||(Q._pool.length<=Q._outArr.length&&Q._newPlugin(),n=Q._pool[Q._outArr.length],((r={name:e,clients:[],info:{name:e,manufacturer:Q._allOuts[e].manufacturer,version:Q._allOuts[e].version,type:"MIDI-out",sysex:Q._sysex,engine:Q._type},_start:function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["openout",n.id,e]}))},_close:function(t){Q._closeOut(t)},_closeAll:o,_receive:function(t){var e;t.length&&((e=t.slice()).splice(0,0,"play",n.id),document.dispatchEvent(new CustomEvent("jazz-midi",{detail:e})))}}).plugin=n).output=r,Q._outArr.push(r),Q._outMap[e]=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())},Q._openIn=function(t,e){var n,r=Q._inMap[e];r||(Q._pool.length<=Q._inArr.length&&Q._newPlugin(),n=Q._pool[Q._inArr.length],((r={name:e,clients:[],info:{name:e,manufacturer:Q._allIns[e].manufacturer,version:Q._allIns[e].version,type:"MIDI-in",sysex:Q._sysex,engine:Q._type},_start:function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["openin",n.id,e]}))},_close:function(t){Q._closeIn(t)},_closeAll:o}).plugin=n).input=r,Q._inArr.push(r),Q._inMap[e]=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())},Q._closeOut=function(t){var e=t._impl;C(e.clients,t._orig),!e.clients.length&&e.open&&(e.open=!1,document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["closeout",e.plugin.id]})))},Q._closeIn=function(t){var e=t._impl;C(e.clients,t._orig),!e.clients.length&&e.open&&(e.open=!1,document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["closein",e.plugin.id]})))},Q._close=function(){Q._unwatch()},Q._watch=function(){Q._insW=Q._ins,Q._outsW=Q._outs,r=setInterval(function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["refresh"]}))},250)},Q._unwatch=function(){clearInterval(r),r=void 0},document.addEventListener("jazz-midi-msg",function(){var t,e,n,r=Q._msg.innerText.split("\n");for(Q._msg.innerText="",e=0;e<r.length;e++){var i=[];try{i=JSON.parse(r[e])}catch(t){}if(i.length)if("refresh"===i[0]){if(i[1].ins){for(n=0;n<i[1].ins.length;n++)i[1].ins[n].type=Q._type;Q._ins=i[1].ins}if(i[1].outs){for(n=0;n<i[1].outs.length;n++)i[1].outs[n].type=Q._type;Q._outs=i[1].outs}for(E(),n=0;n<Q.refreshClients.length;n++)Q.refreshClients[n]._resume();Q.refreshClients=[]}else if("version"===i[0]){var o=Q._pool[i[1]];o&&(o.ready=!0,o.input&&o.input._start(),o.output&&o.output._start())}else if("openout"===i[0]){if(t=Q._pool[i[1]].output)if(i[2]==t.name){if(t.open=!0,t.clients)for(n=0;n<t.clients.length;n++)t.clients[n]._resume()}else if(t.clients)for(n=0;n<t.clients.length;n++)t.clients[n]._crash()}else if("openin"===i[0]){if(t=Q._pool[i[1]].input)if(i[2]==t.name){if(t.open=!0,t.clients)for(n=0;n<t.clients.length;n++)t.clients[n]._resume()}else if(t.clients)for(n=0;n<t.clients.length;n++)t.clients[n]._crash()}else if("midi"===i[0]&&(t=Q._pool[i[1]].input)&&t.clients)for(n=0;n<t.clients.length;n++){var s=pt(i.slice(3));t.clients[n]._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 nt(){this._pause();var t=this;h(function(){t._crash()})}function rt(t){for(var e=[],n=function(t){var e=["node","extension","plugin","webmidi"];if(!t||!t.engine)return e;var n,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&&(n=!0),"etc"!==h&&void 0!==h||(r=!0),r?a.push(h):u.push(h),C(e,h))}(r||u.length||a.length)&&(n=!1);return n?[]:u.concat(r?e:a)}(t),r=0;r<n.length;r++)"webmidi"==n[r]?(t&&!0===t.sysex&&e.push(tt),t&&!0===t.sysex&&!0!==t.degrade||e.push(Y)):"node"==n[r]?(e.push($),e.push(nt)):"extension"==n[r]?e.push(et):"plugin"==n[r]&&e.push(X);return e.push(it),e}function it(){Q._type="none",Q._version=n,Q._sysex=!0,Q._outs=[],Q._ins=[],Q._refresh=function(){E()},Q._watch=function(){},Q._unwatch=function(){},Q._close=function(){}}function ot(){var t;function s(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}Q._inArr=[],Q._outArr=[],Q._inMap={},Q._outMap={},Q._outsW=[],Q._insW=[],Q._version=Q._main.version,Q._sysex=!0,Q._refresh=function(){var t,e;for(Q._outs=[],Q._ins=[],t=0;(e=Q._main.MidiOutInfo(t)).length;t++)Q._outs.push({type:Q._type,name:e[0],manufacturer:e[1],version:e[2]});for(t=0;(e=Q._main.MidiInInfo(t)).length;t++)Q._ins.push({type:Q._type,name:e[0],manufacturer:e[1],version:e[2]});E()},Q._openOut=function(t,e){var n,r=Q._outMap[e];if(r||(Q._pool.length<=Q._outArr.length&&Q._pool.push(Q._newPlugin()),r={name:e,clients:[],info:{name:e,manufacturer:Q._allOuts[e].manufacturer,version:Q._allOuts[e].version,type:"MIDI-out",sysex:Q._sysex,engine:Q._type},_close:function(t){Q._closeOut(t)},_closeAll:s,_receive:function(t){t.length&&this.plugin.MidiOutRaw(t.slice())}},n=Q._pool[Q._outArr.length],r.plugin=n,Q._outArr.push(r),Q._outMap[e]=r),!r.open){var i=r.plugin.MidiOutOpen(e);if(i!==e)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)}},Q._openIn=function(t,e){var n,r,i=Q._inMap[e];if(i||(Q._pool.length<=Q._inArr.length&&Q._pool.push(Q._newPlugin()),(i={name:e,clients:[],info:{name:e,manufacturer:Q._allIns[e].manufacturer,version:Q._allIns[e].version,type:"MIDI-in",sysex:Q._sysex,engine:Q._type},_close:function(t){Q._closeIn(t)},_closeAll:s,handle:function(t,e){for(var n=0;n<this.clients.length;n++){var r=pt(e);this.clients[n]._emit(r)}}}).onmidi=(r=i,function(t,e){r.handle(t,e)}),n=Q._pool[Q._inArr.length],i.plugin=n,Q._inArr.push(i),Q._inMap[e]=i),!i.open){var o=i.plugin.MidiInOpen(e,i.onmidi);if(o!==e)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)}},Q._closeOut=function(t){var e=t._impl;C(e.clients,t._orig),!e.clients.length&&e.open&&(e.open=!1,e.plugin.MidiOutClose())},Q._closeIn=function(t){var e=t._impl;C(e.clients,t._orig),!e.clients.length&&e.open&&(e.open=!1,e.plugin.MidiInClose())},Q._close=function(){for(var t=0;t<Q._inArr.length;t++)Q._inArr[t].open&&Q._inArr[t].plugin.MidiInClose();Q._unwatch()},Q._watch=function(){t=t||setInterval(function(){Q._refresh()},250)},Q._unwatch=function(){t&&clearInterval(t),t=void 0}}function st(t,e){var n;function o(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}Q._type="webmidi",Q._version=43,Q._sysex=!!e,Q._access=t,Q._inMap={},Q._outMap={},Q._outsW=[],Q._insW=[],Q._refresh=function(){Q._outs=[],Q._ins=[],Q._access.outputs.forEach(function(t){Q._outs.push({type:Q._type,name:t.name,manufacturer:t.manufacturer,version:t.version})}),Q._access.inputs.forEach(function(t){Q._ins.push({type:Q._type,name:t.name,manufacturer:t.manufacturer,version:t.version})}),E()},Q._openOut=function(t,e){var n,r=(r=Q._outMap[e])||{name:e,clients:[],info:{name:e,manufacturer:Q._allOuts[e].manufacturer,version:Q._allOuts[e].version,type:"MIDI-out",sysex:Q._sysex,engine:Q._type},_close:function(t){Q._closeOut(t)},_closeAll:o,_receive:function(t){r.dev&&t.length&&this.dev.send(t.slice())}};Q._access.outputs.forEach(function(t){t.name===e&&(n=t)}),n?(r.dev=n,Q._outMap[e]=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()},Q._openIn=function(t,e){var n,r,i=(i=Q._inMap[e])||{name:e,clients:[],info:{name:e,manufacturer:Q._allIns[e].manufacturer,version:Q._allIns[e].version,type:"MIDI-in",sysex:Q._sysex,engine:Q._type},_close:function(t){Q._closeIn(t)},_closeAll:o,handle:function(t){for(var e=0;e<this.clients.length;e++){var n=pt([].slice.call(t.data));this.clients[e]._emit(n)}}};Q._access.inputs.forEach(function(t){t.name===e&&(n=t)}),n?(i.dev=n,i.dev.onmidimessage=(r=i,function(t){r.handle(t)}),Q._inMap[e]=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()},Q._closeOut=function(t){var e=t._impl;C(e.clients,t._orig),e.clients.length||(e.dev&&e.dev.close&&e.dev.close(),e.dev=void 0)},Q._closeIn=function(t){var e=t._impl;C(e.clients,t._orig),e.clients.length||(e.dev&&(e.dev.onmidimessage=null,e.dev.close&&e.dev.close()),e.dev=void 0)},Q._close=function(){Q._unwatch()},Q._watch=function(){Q._access.onstatechange=function(){n=!0,h(function(){n&&(Q._refresh(),n=!1)})}},Q._unwatch=function(){Q._access.onstatechange=void 0}}function ut(t){var e;return S||(e=t,zt(),(S=new b)._options=e,S._push(v,[rt(e)]),S.refresh(),S._resume()),S._thenable()}function at(){var t=this instanceof at?this:t=new at;return at.prototype.reset.apply(t,arguments),t}function ht(){29.97==this.type&&!this.second&&this.frame<2&&this.minute%10&&(this.frame=2)}function ct(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 ft(t){for(var e,n=[],r=0;r<t.length;r++)n[r]=(e=t[r])<10?"0"+e:e;return n.join(":")}function pt(t){var e=this instanceof pt?this:e=new pt;if(t instanceof pt){for(r in e._from=t._from.slice(),t)t.hasOwnProperty(r)&&"_from"!=r&&(e[r]=t[r]);return e}if(e._from=[],void 0===t)return e;for(var n=t instanceof Array?t:arguments,r=0;r<n.length;r++)i=n[r],1==r&&(128<=e[0]&&e[0]<=175&&(i=pt.noteValue(i)),192<=e[0]&&e[0]<=207&&(i=pt.programValue(i))),(i!=parseInt(i)||i<0||255<i)&&_t(n[r]),e.push(i);return e}(ut.JZZ=ut).version=n,ut.info=function(){return b.prototype.info()},b.prototype.Widget=ut.Widget=function(t){var e=new D;if(t instanceof Object)for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e._resume(),e},ut.addMidiIn=function(t,e){var n=w(e._info||{});n.name=t,n.type=n.type||"javascript",n.manufacturer=n.manufacturer||"virtual",n.version=n.version||"0.0";var r={_info:function(){return n},_openIn:function(t){t._pause(),t._info=w(n),t._close=function(){e.disconnect(t)},e.connect(t),t._resume()}};return ut.lib.registerMidiIn(t,r)},ut.addMidiOut=function(t,e){var n=w(e._info||{});n.name=t,n.type=n.type||"javascript",n.manufacturer=n.manufacturer||"virtual",n.version=n.version||"0.0";var r={_info:function(){return n},_openOut:function(t){t._pause(),t._info=w(n),t._close=function(){t.disconnect()},z.apply(t,[e]),t._resume()}};return ut.lib.registerMidiOut(t,r)},at.prototype.reset=function(t){if(t instanceof at)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 e=t instanceof Array?t:arguments;return this.setType(e[0]),this.setHour(e[1]),this.setMinute(e[2]),this.setSecond(e[3]),this.setFrame(e[4]),this.setQuarter(e[5]),this},at.prototype.isFullFrame=function(){return 0==this.quarter||4==this.quarter},at.prototype.getType=function(){return this.type},at.prototype.getHour=function(){return this.hour},at.prototype.getMinute=function(){return this.minute},at.prototype.getSecond=function(){return this.second},at.prototype.getFrame=function(){return this.frame},at.prototype.getQuarter=function(){return this.quarter},at.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,ht.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},at.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},at.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,ht.apply(this),this},at.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,ht.apply(this),this},at.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,ht.apply(this),this},at.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},at.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))),ht.apply(this),this},at.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},at.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},at.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},at.prototype.read=function(t){if(t instanceof pt||(t=pt.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 e=t[1]>>4,n=15&t[1];return 0==e?7==this._&&(7==this._f&&(this.reset(ct(this._a)),this.incrFrame()),this.incrFrame()):3==e?4==this._&&this.decrFrame():4==e?3==this._&&this.incrFrame():7==e&&0===this._&&(0===this._b&&(this.reset(ct(this._a)),this.decrFrame()),this.decrFrame()),this._a||(this._a=[]),this._a[e]=n,this._f=this._f===e-1||0==e?e:void 0,this._b=this._b===1+e||7==e?e:void 0,this._=e,this.quarter=e,!0},at.prototype.toString=function(){return ft([this.hour,this.minute,this.second,this.frame])},ut.SMPTE=at,pt.prototype=[],pt.prototype.constructor=pt;var lt={};pt.noteValue=function(t){return void 0===t?void 0:lt[t.toString().toLowerCase()]},pt.programValue=function(t){return t},pt.freq=function(t,e){return void 0===e&&(e=440),e*Math.pow(2,(gt(pt.noteValue(t),t)-69)/12)};var dt={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(Pt in dt)if(dt.hasOwnProperty(Pt))for(i=0;i<12&&!(127<(t=dt[Pt]+12*i));i++)0<(lt[Pt+i]=t)&&(lt[Pt+"b"+i]=t-1,lt[Pt+"bb"+i]=t-2),t<127&&(lt[Pt+"#"+i]=t+1,lt[Pt+"##"+i]=t+2);for(i=0;i<128;i++)lt[i]=i;function _t(t){throw RangeError("Bad MIDI value: "+t)}function mt(t){return R(t),parseInt(t)}function gt(t,e){return(t!=parseInt(t)||t<0||127<t)&&_t(void 0===e?t:e),parseInt(t)}function vt(t,e){return(t!=parseInt(t)||t<0||255<t)&&_t(void 0===e?t:e),parseInt(t)}function yt(t){return(t!=parseInt(t)||t<0||16383<t)&&_t(t),127&parseInt(t)}function Ct(t){return(t!=parseInt(t)||t<0||16383<t)&&_t(t),parseInt(t)>>7}var bt={noteOff:function(t,e,n){return void 0===n&&(n=64),[128+mt(t),gt(pt.noteValue(e),e),gt(n)]},noteOn:function(t,e,n){return void 0===n&&(n=127),[144+mt(t),gt(pt.noteValue(e),e),gt(n)]},aftertouch:function(t,e,n){return[160+mt(t),gt(pt.noteValue(e),e),gt(n)]},control:function(t,e,n){return[176+mt(t),gt(e),gt(n)]},program:function(t,e){return[192+mt(t),gt(pt.programValue(e),e)]},pressure:function(t,e){return[208+mt(t),gt(e)]},pitchBend:function(t,e){return[224+mt(t),yt(e),Ct(e)]},bankMSB:function(t,e){return[176+mt(t),0,gt(e)]},bankLSB:function(t,e){return[176+mt(t),32,gt(e)]},modMSB:function(t,e){return[176+mt(t),1,gt(e)]},modLSB:function(t,e){return[176+mt(t),33,gt(e)]},breathMSB:function(t,e){return[176+mt(t),2,gt(e)]},breathLSB:function(t,e){return[176+mt(t),34,gt(e)]},footMSB:function(t,e){return[176+mt(t),4,gt(e)]},footLSB:function(t,e){return[176+mt(t),36,gt(e)]},portamentoMSB:function(t,e){return[176+mt(t),5,gt(e)]},portamentoLSB:function(t,e){return[176+mt(t),37,gt(e)]},volumeMSB:function(t,e){return[176+mt(t),7,gt(e)]},volumeLSB:function(t,e){return[176+mt(t),39,gt(e)]},balanceMSB:function(t,e){return[176+mt(t),8,gt(e)]},balanceLSB:function(t,e){return[176+mt(t),40,gt(e)]},panMSB:function(t,e){return[176+mt(t),10,gt(e)]},panLSB:function(t,e){return[176+mt(t),42,gt(e)]},expressionMSB:function(t,e){return[176+mt(t),11,gt(e)]},expressionLSB:function(t,e){return[176+mt(t),43,gt(e)]},damper:function(t,e){return[176+mt(t),64,e?127:0]},portamento:function(t,e){return[176+mt(t),65,e?127:0]},sostenuto:function(t,e){return[176+mt(t),66,e?127:0]},soft:function(t,e){return[176+mt(t),67,e?127:0]},allSoundOff:function(t){return[176+mt(t),120,0]},allNotesOff:function(t){return[176+mt(t),123,0]}},wt={mtc:function(t){return[241,function(t){var e;switch(!t.backwards&&4<=t.quarter?t.decrFrame():t.backwards&&t.quarter<4&&t.incrFrame(),t.quarter>>1){case 0:e=t.frame;break;case 1:e=t.second;break;case 2:e=t.minute;break;default:e=t.hour}return 1&t.quarter?e>>=4:e&=15,7==t.quarter&&(25==t.type?e|=2:29.97==t.type?e|=4:30==t.type&&(e|=6)),!t.backwards&&4<=t.quarter?t.incrFrame():t.backwards&&t.quarter<4&&t.decrFrame(),e|t.quarter<<4}(t)]},songPosition:function(t){return[242,yt(t),Ct(t)]},songSelect:function(t){return[243,gt(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,127,6,1,247]},sxFullFrame:function(t){return[240,127,127,1,1,25==(e=t).type?32|e.hour:29.97==e.type?64|e.hour:30==e.type?96|e.hour:e.hour,t.getMinute(),t.getSecond(),t.getFrame(),247];var e},reset:function(){return[255]}};function St(t,e){var n=new pt;return n.ff=vt(t),n.dd=void 0===e?"":function(t){t=""+t;for(var e=0;e<t.length;e++)255<t.charCodeAt(e)&&_t(t[e]);return t}(e),n}var Mt={smf:function(t){if(t instanceof pt)return new pt(t);var e=t instanceof Array?t:arguments,n=vt(e[0]),r="";return 2==e.length?r=Tt(e[1]):2<e.length&&(r=Tt(Array.prototype.slice.call(e,1))),St(n,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: "+Lt(t));return St(0,t)},smfText:function(t){return St(1,ut.lib.toUTF8(t))},smfCopyright:function(t){return St(2,ut.lib.toUTF8(t))},smfSeqName:function(t){return St(3,ut.lib.toUTF8(t))},smfInstrName:function(t){return St(4,ut.lib.toUTF8(t))},smfLyric:function(t){return St(5,ut.lib.toUTF8(t))},smfMarker:function(t){return St(6,ut.lib.toUTF8(t))},smfCuePoint:function(t){return St(7,ut.lib.toUTF8(t))},smfProgName:function(t){return St(8,ut.lib.toUTF8(t))},smfDevName:function(t){return St(9,ut.lib.toUTF8(t))},smfChannelPrefix:function(t){if(t==parseInt(t))R(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: "+Lt(t));return St(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: "+Lt(t));return St(33,t)},smfEndOfTrack:function(t){if(""!=Tt(t))throw RangeError("Unexpected data: "+Lt(Tt(t)));return St(47)},smfTempo:function(t){if(3==(""+t).length)return St(81,t);if(t==parseInt(t)&&0<t&&t<=16777215)return St(81,String.fromCharCode(t>>16)+String.fromCharCode(t>>8&255)+String.fromCharCode(255&t));throw RangeError("Out of range: "+Lt(Tt(t)))},smfBPM:function(t){return Mt.smfTempo(Math.round(6e7/t))},smfSMPTE:function(t){if(t instanceof at)return St(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 St(84,t);var e=t instanceof Array?t:Array.prototype.slice.call(arguments);return e.splice(0,0,30),Mt.smfSMPTE(new at(e))},smfTimeSignature:function(t,e,n,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=e==parseInt(e)?e:24,u=n==parseInt(n)?n:8,St(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return St(88,t)}else{if(t==parseInt(t)&&e==parseInt(e)&&e&&!(e&e-1)){for(i=t,o=0,s=e,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=r==parseInt(r)?r:8,St(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return St(88,t)}throw RangeError("Wrong time signature: "+Lt(Tt(t)))},smfKeySignature:function(t){var e,n,r=(t=""+t).match(/^\s*([A-H][b#]?)\s*(|maj|major|dur|m|min|minor|moll)\s*$/i);if(r&&(e={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()],n={"":0,MAJ:0,MAJOR:0,DUR:0,M:1,MIN:1,MINOR:1,MOLL:1}[r[2].toUpperCase()],void 0!==e&&void 0!==n&&(n&&(e-=3),-7<=(e-=7)&&e<0?t=String.fromCharCode(256+e)+String.fromCharCode(n):0<=e&&e<=7&&(t=String.fromCharCode(e)+String.fromCharCode(n)))),2==t.length&&t.charCodeAt(1)<=1&&(t.charCodeAt(0)<=7||t.charCodeAt(0)<=255&&249<=t.charCodeAt(0)))return St(89,t);throw RangeError("Incorrect key signature: "+Lt(t))},smfSequencer:function(t){return St(127,Tt(t))}};function Ot(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,arguments)),this}}function It(t,e){pt[t]=function(){return new pt(e.apply(0,arguments))}}for(Pt in wt)wt.hasOwnProperty(Pt)&&It(Pt,wt[Pt]);for(Pt in Mt)Mt.hasOwnProperty(Pt)&&function(t,e){pt[t]=function(){return e.apply(0,arguments)}}(Pt,Mt[Pt]);for(Pt in bt)bt.hasOwnProperty(Pt)&&function(t,r){It(t,r),G.prototype[t]=function(){var t,e=Array.prototype.slice.call(arguments);e.length<r.length?e=[this._master].concat(e):(t=gt(pt.noteValue(e[0],e[0])),e[0]=this._master);var n=r.apply(0,e);return n.mpe=t,this.send(n),this}}(Pt,bt[Pt]);function At(t,e){for(Pt in wt)wt.hasOwnProperty(Pt)&&Ot(t,Pt,wt[Pt]);for(Pt in Mt)Mt.hasOwnProperty(Pt)&&Ot(t,Pt,Mt[Pt]);for(Pt in bt)bt.hasOwnProperty(Pt)&&Ot(t,Pt,bt[Pt]);if(e)for(Pt in bt)bt.hasOwnProperty(Pt)&&function(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,[this._chan].concat(Array.prototype.slice.call(arguments)))),this}}(e,Pt,bt[Pt])}At(D,U),G.prototype.noteOn=function(t,e){var n=pt.noteOn(this._master,t,e);return n._mpe=n[1],this.send(n),this},G.prototype.noteOff=function(t,e){var n=pt.noteOff(this._master,t,e);return n._mpe=n[1],this.send(n),this},G.prototype.aftertouch=function(t,e){var n=pt.aftertouch(this._master,t,e);return n._mpe=n[1],this.send(n),this};for(var Et,xt={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++)xt[Pt]=Pt;function Bt(t){for(var e=[],n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}function Tt(t){return t instanceof Array?function(t){for(var e="",n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e}(t):void 0===t?"":""+t}function Ft(t){return(t<16?"0":"")+t.toString(16)}function qt(t){for(var e=[],n=0;n<t.length;n++)e[n]=Ft(t[n]);return e.join(" ")}function Dt(t){return t.length?": "+qt(Bt(t)):""}function Lt(t){return t.length?": "+function(t){for(var e="",n=0;n<t.length;n++)"\n"==t[n]?e+="\\n":"\r"==t[n]?e+="\\r":"\t"==t[n]?e+="\\t":t.charCodeAt(n)<32?e+="\\x"+Ft(t.charCodeAt(n)):e+=t[n];return e}(ut.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,n;Et||"undefined"==typeof window||(t=window.AudioContext||window.webkitAudioContext)&&((Et=new t)&&!Et.createGain&&(Et.createGain=Et.createGainNode),n=function(){if("running"!=Et.state){Et.resume();var t=Et.createOscillator(),e=Et.createGain();try{e.gain.value=0}catch(t){}e.gain.setTargetAtTime(0,Et.currentTime,.01),t.connect(e),e.connect(Et.destination),t.start||(t.start=t.noteOn),t.stop||(t.stop=t.noteOff),t.start(.1),t.stop(.11)}else document.removeEventListener("touchstart",n),document.removeEventListener("touchend",n),document.removeEventListener("mousedown",n),document.removeEventListener("keydown",n)},document.addEventListener("touchstart",n),document.addEventListener("touchend",n),document.addEventListener("mousedown",n),document.addEventListener("keydown",n),n())}pt.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},pt.prototype.setChannel=function(t){return void 0===(t=xt[t])||(32==this.ff?this.dd=String.fromCharCode(t):void 0!==(e=this[0])&&128<=e&&e<=239&&(this[0]=240&e|t)),this;var e},pt.prototype.getNote=function(){var t=this[0];if(!(void 0===t||t<128||175<t))return this[1]},pt.prototype.setNote=function(t){var e=this[0];return void 0===e||e<128||175<e||void 0!==(t=pt.noteValue(t))&&(this[1]=t),this},pt.prototype.getVelocity=function(){var t=this[0];if(!(void 0===t||t<128||159<t))return this[2]},pt.prototype.setVelocity=function(t){var e=this[0];return void 0===e||e<128||159<e||0<=(t=parseInt(t))&&t<128&&(this[2]=t),this},pt.prototype.getSysExChannel=function(){if(240==this[0])return this[2]},pt.prototype.setSysExChannel=function(t){return 240==this[0]&&2<this.length&&0<=(t=parseInt(t))&&t<128&&(this[2]=t),this},pt.prototype.getData=function(){if(void 0!==this.dd)return this.dd.toString()},pt.prototype.setData=function(t){return this.dd=Tt(t),this},pt.prototype.getText=function(){if(void 0!==this.dd)return ut.lib.fromUTF8(this.dd)},pt.prototype.setText=function(t){return this.dd=ut.lib.toUTF8(t),this},pt.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)},pt.prototype.getBPM=function(){var t=this.getTempo();if(t)return 6e7/t},pt.prototype.getTimeSignature=function(){if(88==this.ff&&void 0!==this.dd)return[this.dd.charCodeAt(0),1<<this.dd.charCodeAt(1)]},pt.prototype.getKeySignature=function(){if(89==this.ff&&void 0!==this.dd){var t=this.dd.charCodeAt(0),e=this.dd.charCodeAt(1);if(128&t&&(t-=256),-7<=t&&t<=7&&0<=e&&e<=1)return[t,["Cb","Gb","Db","Ab","Eb","Bb","F","C","G","D","A","E","B","F#","C#","G#","D#","A#"][e?t+10:t+7],!!e]}},pt.prototype.isNoteOn=function(){var t=this[0];return!(void 0===t||t<144||159<t)&&0<this[2]},pt.prototype.isNoteOff=function(){var t=this[0];return!(void 0===t||t<128||159<t)&&(t<144||0==this[2])},pt.prototype.isSysEx=function(){return 240==this[0]},pt.prototype.isFullSysEx=function(){return 240==this[0]&&247==this[this.length-1]},pt.prototype.isSMF=function(){return 0<=this.ff&&this.ff<=127},pt.prototype.isEOT=function(){return 47==this.ff},pt.prototype.isTempo=function(){return 81==this.ff},pt.prototype.isTimeSignature=function(){return 88==this.ff},pt.prototype.isKeySignature=function(){return 89==this.ff},pt.prototype.toString=function(){if(!this.length){if(void 0===this.ff)return"empty";var t,e,n="ff"+Ft(this.ff)+" -- ";return 0==this.ff?n+="Sequence Number: "+function(t){for(var e=0,n=0;n<t.length;n++)e=(e<<8)+t.charCodeAt(n);return e}(this.dd):0<this.ff&&this.ff<10?n+=["","Text","Copyright","Sequence Name","Instrument Name","Lyric","Marker","Cue Point","Program Name","Device Name"][this.ff]+Lt(this.dd):32==this.ff?n+="Channel Prefix"+Dt(this.dd):33==this.ff?n+="MIDI Port"+Dt(this.dd):47==this.ff?n+="End of Track"+Dt(this.dd):81==this.ff?n+="Tempo: "+Math.round(100*this.getBPM())/100+" bpm":84==this.ff?n+="SMPTE Offset: "+ft(Bt(this.dd)):88==this.ff?(t=1<<this.dd.charCodeAt(1),n+="Time Signature: "+this.dd.charCodeAt(0)+"/"+t,n+=" "+this.dd.charCodeAt(2)+" "+this.dd.charCodeAt(3)):89==this.ff?(n+="Key Signature: ",(e=this.getKeySignature())?(n+=e[1],e[2]&&(n+=" min")):n+="invalid"):127==this.ff?n+="Sequencer Specific"+Dt(this.dd):n+="SMF"+Dt(this.dd),n}if(n=qt(this),this[0]<128)return n;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 n+" -- "+r;var r,i=this[0]>>4;return(r={8:"Note Off",10:"Aftertouch",12:"Program Change",13:"Channel Aftertouch",14:"Pitch Wheel"}[i])?n+" -- "+r:9==i?n+" -- "+(this[2]?"Note On":"Note Off"):11!=i?n:n+" -- "+(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 Footswitch",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")},pt.prototype._stamp=function(t){return this._from.push(t._orig?t._orig:t),this},pt.prototype._unstamp=function(t){var e;return void 0===t?this._from=[]:(t._orig&&(t=t._orig),-1<(e=this._from.indexOf(t))&&this._from.splice(e,1)),this},pt.prototype._stamped=function(t){t._orig&&(t=t._orig);for(var e=0;e<this._from.length;e++)if(this._from[e]==t)return!0;return!1},ut.MIDI=pt,jt.validate=function(t){var e=t instanceof Array?t:arguments;if(e[0]!=parseInt(e[0])||e[0]<0||14<e[0])throw RangeError("Bad master channel value: "+e[0]);if(e[1]!=parseInt(e[1])||e[1]<0||15<e[0]+e[1])throw RangeError("Bad zone size value: "+e[1])},jt.prototype.reset=function(){for(var t=0;t<16;t++)this[t]={band:0,master:t}},jt.prototype.setup=function(t,e){var n;jt.validate(t,e);var r=t+e;if((this[t].master!=t||this[t].band!=e)&&(e||this[t].band)){for(this[t].band?r<(n=t+this[t].band)&&(r=n):this[t].master==t-1?(n=t-1,r<(n+=this[n].band)&&(r=n),this[t-1]={band:0,master:t-1}):this[t].master!=t&&(n=this[t].master,r<(n+=this[n].band)&&(r=n),this[this[t].master].band=t-this[t].master-1),this[t].master=t,this[t].band=e,n=t+1;n<=t+e;n++)this[n].band&&r<n+this[n].band&&(r=n+this[n].band),this[n]={band:0,master:t};for(;n<=r;n++)this[n]={band:0,master:n}}},jt.prototype.filter=function(t){var e=t.getChannel();if(!this[e]||!this[this[e].master].band)return t;var n,r,i,o=this[e].master,s=this[o].band;if(void 0!==t._mpe){for(i=256,n=o+1;n<=o+s;n++)if(this[n].notes){for(i>this[n].notes.length&&(i=this[e=n].notes.length),r=0;r<this[n].notes.length;r++)if(this[n].notes[r]==t._mpe){e=n,i=-1;break}}else 0<i&&(e=n,i=0);t.setChannel(e),t._mpe=void 0}return e==o||(t.isNoteOn()?(this[e].notes||(this[e].notes=[]),y(this[e].notes,t.getNote())):t.isNoteOff()&&this[e].notes&&C(this[e].notes,t.getNote())),t},ut.MPE=jt,(ut.lib={}).now=a,ut.lib.schedule=h,ut.lib.openMidiOut=function(t,e){var n=new D;return e._openOut(n),n._info=e._info(t),n},ut.lib.openMidiIn=function(t,e){var n=new D;return e._openIn(n),n._info=e._info(t),n},ut.lib.registerMidiOut=function(t,e){for(var n=e._info(t),r=0;r<K._outs.length;r++)if(K._outs[r].name==n.name)return!1;return n.engine=e,K._outs.push(n),S&&(E(),S._bad&&(S._repair(),S._resume())),!0},ut.lib.registerMidiIn=function(t,e){for(var n=e._info(t),r=0;r<K._ins.length;r++)if(K._ins[r].name==n.name)return!1;return n.engine=e,K._ins.push(n),S&&(E(),S._bad&&(S._repair(),S._resume())),!0},ut.lib.copyMidiHelpers=At,ut.lib.getAudioContext=function(){return zt(),Et};var kt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";ut.lib.fromBase64=function(t){var e,n,r,i,o,s,u="",a=0;for(t=t.replace(/[^A-Za-z0-9+/=]/g,"");a<t.length;)e=kt.indexOf(t.charAt(a++))<<2|(i=kt.indexOf(t.charAt(a++)))>>4,n=(15&i)<<4|(o=kt.indexOf(t.charAt(a++)))>>2,r=(3&o)<<6|(s=kt.indexOf(t.charAt(a++))),u+=String.fromCharCode(e),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(r));return u},ut.lib.toBase64=function(t){var e,n,r,i,o,s=0,u=0,a="",h=[];if(!t)return t;for(;e=(o=t.charCodeAt(s++)<<16|t.charCodeAt(s++)<<8|t.charCodeAt(s++))>>18&63,n=o>>12&63,r=o>>6&63,i=63&o,h[u++]=kt.charAt(e)+kt.charAt(n)+kt.charAt(r)+kt.charAt(i),s<t.length;);a=h.join("");var c=t.length%3;return c?a.slice(0,c-3)+"===".slice(c):a},ut.lib.fromUTF8=function(t){t=void 0===t?"":""+t;for(var e,n,r="",i=0;i<t.length;i++){if(255<(e=t.charCodeAt(i)))return t;if(e<128)r+=t[i];else if(192==(224&e)){if(e=(31&e)<<6,++i>=t.length)return t;if(128!=(192&(n=t.charCodeAt(i))))return t;e+=63&n,r+=String.fromCharCode(e)}else if(224==(240&e)){if(e=(15&e)<<12,++i>=t.length)return t;if(128!=(192&(n=t.charCodeAt(i))))return t;if(e+=(63&n)<<6,++i>=t.length)return t;if(128!=(192&(n=t.charCodeAt(i))))return t;e+=63&n,r+=String.fromCharCode(e)}else if(240==(248&e)){if(e=(7&e)<<18,++i>=t.length)return t;if(128!=(192&(n=t.charCodeAt(i))))return t;if(e+=(63&n)<<12,++i>=t.length)return t;if(128!=(192&(n=t.charCodeAt(i))))return t;if(e+=(63&n)<<6,++i>=t.length)return t;if(128!=(192&(n=t.charCodeAt(i))))return t;if(1114111<(e+=63&n))return t;e-=65536,r+=String.fromCharCode(55296+(e>>10)),r+=String.fromCharCode(56320+(1023&e))}}return r},ut.lib.toUTF8=function(t){t=void 0===t?"":""+t;for(var e,n="",r=0;r<t.length;r++)(e=t.charCodeAt(r))<128?n+=t[r]:(e<2048?n+=String.fromCharCode(192+(e>>6)):(e<65536?n+=String.fromCharCode(224+(e>>12)):(n+=String.fromCharCode(240+(e>>18)),n+=String.fromCharCode(128+(e>>12&63))),n+=String.fromCharCode(128+(e>>6&63))),n+=String.fromCharCode(128+(63&e)));return n};var Nt=[],Rt={},Ut={},Gt=e.Promise;function Zt(t,e,n){this.name=t,this.message=e,this.code=n}function Vt(t,e){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=e,this.defaultPrevented=!1,this.eventPhase=0,this.path=[],this.port=t,this.returnValue=!0,this.srcElement=e,this.target=e,this.timeStamp=a(),this.type="statechange"}function Jt(t,e){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=t,this.data=e,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 Wt(t,e){t&&(t.onstatechange&&t.onstatechange(new Vt(t,t)),e.onstatechange&&e.onstatechange(new Vt(t,e)))}function Ht(n,r){var i=this,o=!1,e=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 e},set:function(t){e=t instanceof Function?t:null},enumerable:!0}),this.open=function(){return new Gt(function(t,e){o?t(i):r.open().then(function(){o||(o=!0,Wt(i,n)),t(i)},function(){e(new Zt("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new Gt(function(t){o&&(o=!1,r.close(),Wt(i,n)),t(i)})},Object.freeze(this)}function Qt(t){for(var e,n;t.length;){for(e=0;e<t.length&&!(t[e]==parseInt(t[e])&&128<=t[e]&&t[e]<=255&&247!=t[e]);e++);if(t.splice(0,e),!t.length)return;if(240==t[0]){for(e=1;e<t.length&&247!=t[e];e++);if(e==t.length)return;return t.splice(0,e+1)}if((n=$t(t[0])+1)>t.length)return;for(e=1;e<n&&!(t[e]!=parseInt(t[e])||t[e]<0||128<=t[e]);e++);if(e==n)return t.splice(0,e);t.splice(0,e)}}function Kt(t,e,n,r){var i=this;this.id=t,this.name=e,this.man=n,this.ver=r,this.connected=!0,this.ports=[],this.pending=[],this.proxy=void 0,this.queue=[],this.onmidi=function(t){var e;for(i.queue=i.queue.concat(t.slice()),e=Qt(i.queue);e;e=Qt(i.queue))for(o=0;o<i.ports.length;o++)i.ports[o][0].onmidimessage&&(240!=e[0]||i.ports[o][1])&&i.ports[o][0].onmidimessage(new Jt(i,new Uint8Array(e)))}}function $t(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 Gt&&((Gt=function(t){this.executor=t}).prototype.then=function(t,e){"function"!=typeof t&&(t=function(){}),"function"!=typeof e&&(e=function(){}),this.executor(t,e)}),Kt.prototype.open=function(){var r=this;return new Gt(function(t,e){var n;r.proxy||!r.connected?t():(r.pending.push([t,e]),1==r.pending.length&&ut().openMidiIn(r.name).or(function(){for(n=0;n<r.pending.length;n++)r.pending[n][1]();r.pending=[]}).and(function(){for(r.proxy=this,r.proxy.connect(r.onmidi),n=0;n<r.pending.length;n++)r.pending[n][0]();r.pending=[]}))})},Kt.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}},Kt.prototype.disconnect=function(){this.connected=!1,this.proxy&&(this.proxy.close(),this.proxy=void 0)},Kt.prototype.reconnect=function(){var t,e,n=this,r=[];for(this.connected=!0,t=0;t<Nt.length;t++)"closed"==(e=Nt[t].inputs.get(this.id)).connection?Wt(e,Nt[t]):r.push([e,Nt[t]]);r.length&&ut()._openMidiInNR(n.name).or(function(){for(t=0;t<r.length;t++)r[t][0].close()}).and(function(){for(n.proxy=this,n.proxy.connect(n.onmidi),t=0;t<r.length;t++)Wt(r[t][0],r[t][1])})};var Xt="Failed to execute 'send' on 'MIDIOutput': ";function Yt(r,i){var o=this,s=!1,e=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 e},set:function(t){e=t instanceof Function?t:null},enumerable:!0}),this.open=function(){return new Gt(function(t,e){s?t(o):i.open().then(function(){s||(s=!0,Wt(o,r)),t(o)},function(){e(new Zt("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new Gt(function(t){s&&(s=!1,o.clear(),i.close(),Wt(o,r)),t(o)})},this.clear=function(){},this.send=function(t,e){if(!function(t,e){for(var n,r,i=[],o=0;o<t.length;o++)if(t[o]!=parseInt(t[o])||t[o]<0||255<t[o])throw TypeError(Xt+t[o]+" is not a UInt8 value.");for(o=n=0;o<t.length;o++)if(n){if(127<t[o])throw TypeError(Xt+"Unexpected status byte at index "+o+" ("+t[o]+").");r.push(t[o]),n--}else{if(t[o]<128)throw TypeError(Xt+"Running status is not allowed at index "+o+" ("+t[o]+").");if(247==t[o])throw TypeError(Xt+"Unexpected end of system exclusive message at index "+o+" ("+t[o]+").");if(r=[t[o]],i.push(r),240==t[o]){if(!e)throw new Zt("InvalidAccessError",Xt+"System exclusive messag is not allowed at index "+o+" ("+t[o]+").",15);for(n=-1;o<t.length;o++)if(r.push(t[o]),247==t[o]){n=0;break}}else n=$t(t[o])}if(n)throw TypeError(Xt+"Message is incomplete")}(t,r.sysexEnabled),!i.connected)throw new Zt("InvalidStateError","Port is not connected",11);var n;s?(n=a())<e?setTimeout(function(){i.proxy.send(t)},e-n):i.proxy.send(t):this.open().then(function(){o.send(t,e)})},Object.freeze(this)}function te(t,e,n,r){this.id=t,this.name=e,this.man=n,this.ver=r,this.connected=!0,this.ports=[],this.pending=[],this.proxy=void 0}function ee(r){this.has=function(t){return r.hasOwnProperty(t)&&r[t].connected},this.keys=function(){try{var t=new Map;for(var e in r)this.has(e)&&t.set(e,this.get(e));return t.keys()}catch(t){}},this.values=function(){try{var t=new Map;for(var e in r)this.has(e)&&t.set(e,this.get(e));return t.values()}catch(t){}},this.entries=function(){try{var t=new Map;for(var e in r)this.has(e)&&t.set(e,this.get(e));return t.entries()}catch(t){}},this.forEach=function(t,e){for(var n in void 0===e&&(e=this),r)this.has(n)&&t.call(e,this.get(n),n,this)},Object.defineProperty(this,"size",{get:function(){var t=0;for(var e in r)this.has(e)&&t++;return t},enumerable:!0})}function ne(e,n){this.get=function(t){if(Ut.hasOwnProperty(t)&&Ut[t].connected)return n[t]||(n[t]=new Ht(e,Ut[t]),Ut[t].ports.push([n[t],e.sysexEnabled])),n[t]},Object.freeze(this)}function re(e,n){this.get=function(t){if(Rt.hasOwnProperty(t)&&Rt[t].connected)return n[t]||(n[t]=new Yt(e,Rt[t]),Rt[t].ports.push([n[t],e.sysexEnabled])),n[t]},Object.freeze(this)}function ie(t){for(var e,n,r,i=0;i<t.inputs.added.length;i++)n=t.inputs.added[i],Ut.hasOwnProperty(n.id)||(Ut[n.id]=new Kt(n.id,n.name,n.manufacturer,n.version)),Ut[n.id].reconnect();for(i=0;i<t.outputs.added.length;i++)n=t.outputs.added[i],Rt.hasOwnProperty(n.id)||(Rt[n.id]=new te(n.id,n.name,n.manufacturer,n.version)),Rt[n.id].reconnect();for(i=0;i<t.inputs.removed.length;i++)if(n=t.inputs.removed[i],Ut.hasOwnProperty(n.id)){for(r=[],e=0;e<Nt.length;e++)r.push([Nt[e].inputs.get(n.id),Nt[e]]);for(Ut[n.id].disconnect(),e=0;e<r.length;e++)Wt(r[e][0],r[e][1])}for(i=0;i<t.outputs.removed.length;i++)if(n=t.outputs.removed[i],Rt.hasOwnProperty(n.id)){for(r=[],e=0;e<Nt.length;e++)r.push([Nt[e].outputs.get(n.id),Nt[e]]);for(Rt[n.id].disconnect(),e=0;e<r.length;e++)Wt(r[e][0],r[e][1])}}function oe(t){var e,n=null;this.sysexEnabled=t,this.inputs=new ne(this,{}),this.outputs=new re(this,{}),Object.defineProperty(this,"onstatechange",{get:function(){return n},set:function(t){n=t instanceof Function?t:null},enumerable:!0}),Object.freeze(this);for(var r=S._info,i=0;i<r.inputs.length;i++)e=r.inputs[i],Ut.hasOwnProperty(e.id)||(Ut[e.id]=new Kt(e.id,e.name,e.manufacturer,e.version));for(i=0;i<r.outputs.length;i++)e=r.outputs[i],Rt.hasOwnProperty(e.id)||(Rt[e.id]=new te(e.id,e.name,e.manufacturer,e.version));Nt.length||ut().onChange(ie),Nt.push(this)}return te.prototype.open=function(){var r=this;return new Gt(function(t,e){var n;r.proxy||!r.connected?t():(r.pending.push([t,e]),1==r.pending.length&&ut().openMidiOut(r.name).or(function(){for(n=0;n<r.pending.length;n++)r.pending[n][1]();r.pending=[]}).and(function(){for(r.proxy=this,n=0;n<r.pending.length;n++)r.pending[n][0]();r.pending=[]}))})},te.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}},te.prototype.disconnect=function(){this.connected=!1,this.proxy&&(this.proxy.close(),this.proxy=void 0)},te.prototype.reconnect=function(){var t,e,n=this,r=[];for(this.connected=!0,t=0;t<Nt.length;t++)"closed"==(e=Nt[t].outputs.get(this.id)).connection?Wt(e,Nt[t]):r.push([e,Nt[t]]);r.length&&ut()._openMidiOutNR(n.name).or(function(){for(t=0;t<r.length;t++)r[t][0].close()}).and(function(){for(n.proxy=this,t=0;t<r.length;t++)Wt(r[t][0],r[t][1])})},(ne.prototype=new ee(Ut)).constructor=ne,(re.prototype=new ee(Rt)).constructor=re,ut.requestMIDIAccess=function(i){return new Gt(function(n,r){ut.JZZ(i).or(function(){}).and(function(){var t,e=!(!i||!i.sysex);e&&!this.info().sysex?r(new Zt("SecurityError","Sysex is not allowed",18)):(t=new oe(e),n(t))})})},"undefined"==typeof navigator||navigator.requestMIDIAccess||(navigator.requestMIDIAccess=ut.requestMIDIAccess),ut.close=function(){Q._close&&Q._close()},ut});