-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
JZZ.js
1 lines (1 loc) · 90.3 KB
/
JZZ.js
1
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define("JZZ",[],n):(t=t||window).JZZ&&t.JZZ.MIDI||(t.JZZ=n())}(this,function(){var o,L,n,i,t="undefined"==typeof window?global:window,D="1.7.2",q=Date.now||function(){return(new Date).getTime()},G=q(),j="undefined"!=typeof performance&&performance.now?function(){return performance.now()}:function(){return q()-G},z=function(t){setTimeout(t,0)};function U(){}function a(t){return"function"==typeof t}function e(){(this._orig=this)._ready=!1,this._queue=[],this._log=[]}function V(t,n){this._bad?a(n)&&n.apply(this,[new Error(this._err())]):a(t)&&t.apply(this,[this])}function W(t,n){this._bad?t._crash(this._err()):setTimeout(function(){t._resume()},n)}function s(t){this._bad&&t._break(this._err()),t._resume()}function Z(t,e,r){t[r]=function(){var t=arguments,n=e._image();return this._push(s,[n]),n[r].apply(n,t)}}function J(t){this._bad||(a(t)?t.apply(this):console.log(t))}function X(t){this._bad&&(a(t)?t.apply(this):console.log(t))}function H(t){this._bad?t._crash(this._err()):(this._break("Closed"),t._resume())}function Q(t){if(t.length){var n,e=t.shift();t.length&&(n=this)._slip(X,[function(){Q.apply(n,[t])}]);try{this._repair(),e.apply(this)}catch(t){this._break(t.toString())}}else this._break()}function c(t,n){for(var e=0;e<t.length;e++)if(t[e]===n)return;t.push(n)}function h(t,n){for(var e=0;e<t.length;e++)if(t[e]===n)return void t.splice(e,1)}function r(){e.apply(this)}function u(t,n){for(var e in t)t.hasOwnProperty(e)&&n.call(this,e)}function K(n,e,r){if(void 0===e)return K(n,[],[]);if(n instanceof Object){for(var i,t=0;t<e.length;t++)if(e[t]===n)return r[t];return i=n instanceof Array?[]:{},e.push(n),r.push(i),u(n,function(t){i[t]=K(n[t],e,r)}),i}return n}e.prototype._exec=function(){for(;this._ready&&this._queue.length;){var t=this._queue.shift();t[0].apply(this,t[1])}},e.prototype._push=function(t,n){this._queue.push([t,n]),e.prototype._exec.apply(this)},e.prototype._slip=function(t,n){this._queue.unshift([t,n])},e.prototype._pause=function(){this._ready=!1},e.prototype._resume=function(){this._ready=!0,e.prototype._exec.apply(this)},e.prototype._break=function(t){this._orig._bad=!0,this._orig._log.push(t||"Unknown JZZ error")},e.prototype._repair=function(){this._orig._bad=!1},e.prototype._crash=function(t){this._break(t),this._resume()},e.prototype._err=function(){return this._log[this._log.length-1]},e.prototype.log=function(){return K(this._log)},e.prototype._dup=function(){function t(){}t.prototype=this._orig;var n=new t;return n._ready=!1,n._queue=[],n},e.prototype._image=function(){return this._dup()},e.prototype._thenable=function(){if(this.then)return this;function t(){}var e=this,n=(t.prototype=e,new t);return n.then=function(t,n){return e._push(V,[t,n]),this},n},e.prototype.wait=function(t){if(!t)return this;var n=this._image();return this._push(W,[n,t]),n._thenable()},e.prototype.and=function(t){return this._push(J,[t]),this._thenable()},e.prototype.or=function(t){return this._push(X,[t]),this._thenable()},e.prototype._info={},e.prototype.info=function(){var t=K(this._orig._info);return void 0===t.engine&&(t.engine="none"),void 0===t.sysex&&(t.sysex=!0),t},e.prototype.name=function(){return this.info().name},e.prototype.close=function(){var t=new e;return this._close&&this._push(this._close,[]),this._push(H,[t]),t._thenable()},(r.prototype=new e)._info={name:"JZZ.js",ver:D,version:D,inputs:[],outputs:[]};var f,Y=[],$=[],tt=[],nt=[],et={},rt={};function it(){var t,n;for(f._info.engine=d._type,f._info.version=d._version,f._info.sysex=d._sysex,f._info.inputs=[],f._info.outputs=[],Y=[],$=[],d._allOuts={},d._allIns={},t=0;t<d._outs.length;t++)n=d._outs[t],et[n.name]||((n.engine=d)._allOuts[n.name]=n,f._info.outputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:d._type}),Y.push(n));for(t=0;t<xt._outs.length;t++)n=xt._outs[t],et[n.name]||(f._info.outputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:n.type}),Y.push(n));for(t=0;t<d._ins.length;t++)n=d._ins[t],rt[n.name]||((n.engine=d)._allIns[n.name]=n,f._info.inputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:d._type}),$.push(n));for(t=0;t<xt._ins.length;t++)n=xt._ins[t],rt[n.name]||(f._info.inputs.push({id:n.name,name:n.name,manufacturer:n.manufacturer,version:n.version,engine:n.type}),$.push(n));if(f._watcher&&f._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 1;for(i=0;i<t.length;i++)if(t[i].name!=e[i].name)return 1;for(i=0;i<n.length;i++)if(n[i].name!=r[i].name)return 1;return}(t,n,e,r)){var i,o=[],s=[],u=[],a=[],c={};for(i=0;i<t.length;i++)c[t[i].name]=!0;for(i=0;i<e.length;i++)c[e[i].name]||o.push(e[i]);for(c={},i=0;i<e.length;i++)c[e[i].name]=!0;for(i=0;i<t.length;i++)c[t[i].name]||u.push(t[i]);for(c={},i=0;i<n.length;i++)c[n[i].name]=!0;for(i=0;i<r.length;i++)c[r[i].name]||s.push(r[i]);for(c={},i=0;i<r.length;i++)c[r[i].name]=!0;for(i=0;i<n.length;i++)c[n[i].name]||a.push(n[i]);return{inputs:{added:o,removed:u},outputs:{added:s,removed:a}}}}(nt,tt,f._info.inputs,f._info.outputs);if(e){for(L=0;L<e.inputs.removed.length;L++)(n=d._inMap[e.inputs.removed[L].name])&&n._closeAll();for(L=0;L<e.outputs.removed.length;L++)(n=d._outMap[e.outputs.removed[L].name])&&n._closeAll();var r=e;for(o=0;o<f._watcher._handles.length;o++)f._watcher._handles[o].apply(f,[r])}}nt=f._info.inputs,tt=f._info.outputs}function ot(){this._bad||d._refresh(this)}function st(t,n){(t=a(t)?t(n):t)instanceof Array||(t=[t]);for(var e,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 ut(t,n){n=n instanceof RegExp?"Port matching "+n+" not found":n instanceof Object||void 0===n?"Port not found":'Port "'+n+'" not found';t._crash(n)}function at(t,n){if(this._bad)t._crash(this._err());else{var e=st(n,Y);if(e.length){for(var r=0;r<e.length;r++)e[r]=function(t){return function(){t.engine._openOut(this,t.name)}}(e[r]);t._slip(Q,[e]),t._resume()}else ut(t,n)}}function ct(t,n){if(this._bad)t._crash(this._err());else{var e=st(n,$);if(e.length){for(var r=0;r<e.length;r++)e[r]=function(t){return function(){t.engine._openIn(this,t.name)}}(e[r]);t._slip(Q,[e]),t._resume()}else ut(t,n)}}function ht(t,n){this._bad?t._crash():(t._slip(yt,[n]),t._resume())}function p(){e.apply(this),this._handles=[],this._outs=[]}function ft(t){this._bad||this._receive(t)}function pt(t){return t.isMidi2?new E(t):_.apply(null,arguments)}function lt(t){this._emit(t)}function dt(t){a(t)?c(this._orig._handles,t):c(this._orig._outs,t)}function gt(t){void 0===t?(this._orig._handles=[],this._orig._outs=[]):a(t)?h(this._orig._handles,t):h(this._orig._outs,t)}function mt(t,n){this._orig._mpe||(this._orig._mpe=new B),this._orig._mpe.setup(t,n)}function _t(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 l(t){e.apply(this),this._sink=t}function vt(){e.apply(this),this._handles=[],Z(this,f,"refresh"),Z(this,f,"openMidiOut"),Z(this,f,"openMidiIn"),Z(this,f,"onChange"),Z(this,f,"close")}function yt(t){a(t)&&(this._orig._handles.length||d._watch(),c(this._orig._handles,t))}function bt(t){void 0===t?this._orig._handles=[]:h(this._orig._handles,t),this._orig._handles.length||d._unwatch()}r.prototype.refresh=function(){return this._push(ot,[]),this._thenable()},r.prototype.openMidiOut=function(t){var n=new p;return this._push(ot,[]),this._push(at,[n,t]),n._thenable()},r.prototype._openMidiOutNR=function(t){var n=new p;return this._push(at,[n,t]),n._thenable()},r.prototype.openMidiIn=function(t){var n=new p;return this._push(ot,[]),this._push(ct,[n,t]),n._thenable()},r.prototype._openMidiInNR=function(t){var n=new p;return this._push(ct,[n,t]),n._thenable()},r.prototype.onChange=function(t){this._orig._watcher||(this._orig._watcher=new vt);var n=this._orig._watcher._image();return this._push(ht,[n,t]),n._thenable()},r.prototype._close=function(){d._close()},(p.prototype=new e)._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},p.prototype._receive=function(t){this._emit(this._filter(t))},p.prototype.send=function(){return this._push(ft,[pt.apply(null,arguments)]),this._thenable()},p.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()},p.prototype._emit=function(t){for(var n,e=0;e<this._handles.length;e++)n=pt(t),this._handles[e].apply(this,[n._stamp(this)]);for(e=0;e<this._outs.length;e++)(n=pt(t))._stamped(this._outs[e])||this._outs[e].send(n._stamp(this))},p.prototype.emit=function(t){return this._push(lt,[t]),this._thenable()},p.prototype.connect=function(t){return this._push(dt,[t]),this._thenable()},p.prototype.disconnect=function(t){return this._push(gt,[t]),this._thenable()},p.prototype.connected=function(){return this._orig._handles.length+this._orig._outs.length},p.prototype._image=function(){var t=this._dup();return t._gr=this._gr,t._ch=this._ch,t._sxid=this._sxid,t._master=this._master,t._band=this._band,t},p.prototype._sxid=127,p.prototype.sxId=function(t){if((t=void 0===t?p.prototype._sxid:t)==this._sxid)return this._thenable();t=C(t);var n=this._image();return n._sxid=t,this._push(s,[n]),n._thenable()},p.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=y(t)),n._ch=t,n._master=void 0,n._band=void 0,this._push(s,[n]),n._thenable()},p.prototype.MIDI1=function(){var t=this._image();return t._ch=void 0,t._sxid=p.prototype._sxid,t._master=void 0,t._band=void 0,this._push(s,[t]),t._thenable()},p.prototype.MIDI2=function(){var t=this._image(),t=(t._ch=void 0,t._sxid=p.prototype._sxid,t._master=void 0,t._band=void 0,new l(t));return this._push(s,[t]),t._thenable()},p.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&&B.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(mt,[t,n]),this._push(s,[e]),e._thenable()},(l.prototype=new e)._sxid=p.prototype._sxid,l.prototype._receive=function(t){this._sink._receive(t)},l.prototype.send=function(){return this._push(ft,[E.apply(null,arguments)]),this._thenable()},l.prototype._image=p.prototype._image,l.prototype.connect=function(t){return this._sink.connect(t),this._push(s,[this._sink]),this._thenable()},l.prototype.disconnect=function(t){return this._sink.disconnect(t),this._push(s,[this._sink]),this._thenable()},l.prototype.connected=function(){return this._sink.connected()},l.prototype.sxId=p.prototype.sxId,l.prototype.ch=p.prototype.ch,l.prototype.gr=function(t){if(t==this._gr||void 0===t&&void 0===this._gr)return this._thenable();var n=this._image();return void 0!==t&&(t=C(t)),n._gr=t,this._push(s,[n]),n._thenable()},l.prototype.MIDI1=function(){var t=this._sink._image();return this._push(s,[t]),t._thenable()},l.prototype.MIDI2=function(){var t=this._image();return t._gr=void 0,t._ch=void 0,t._sxid=p.prototype._sxid,this._push(s,[t]),t._thenable()},(vt.prototype=new e).connect=function(t){return this._push(yt,[t]),this._thenable()},vt.prototype.disconnect=function(t){return this._push(bt,[t]),this._thenable()};var Ct,Mt,d={_outs:[],_ins:[]},xt={_outs:[],_ins:[]};function St(){if("undefined"!=typeof module&&module.exports){var t=require("jazz-midi");if(t)return n=t,d._type="node",d._main=n,d._pool=[],d._newPlugin=function(){return new n.MIDI},void Ft()}var n;this._break()}function Tt(){var n,t=document.createElement("div"),t=(t.style.visibility="hidden",document.body.appendChild(t),document.createElement("object"));if(t.style.visibility="hidden",t.style.width="0px",t.style.height="0px",t.classid="CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90",t.type="audio/x-jazz",document.body.appendChild(t),t.isJazz)return n=t,d._type="plugin",d._main=n,d._pool=[n],d._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 Ft();this._break()}function wt(){if("undefined"!=typeof navigator&&navigator.requestMIDIAccess){Ct=navigator,Mt=navigator.requestMIDIAccess;try{-1!=Mt.toString().indexOf("JZZ(")&&(Mt=void 0)}catch(t){}}}function It(){var n;if(wt(),Mt)return n=this,Mt.call(Ct,{}).then(function(t){Nt(t),n._resume()},function(t){n._crash(t)}),void this._pause();this._break()}function At(){var n;if(wt(),Mt)return n=this,Mt.call(Ct,{sysex:!0}).then(function(t){Nt(t,!0),n._resume()},function(t){n._crash(t)}),void this._pause();this._break()}function Bt(){var r,o,s=this;function u(t){r=!0;var n,e,t=t.detail;if(!t){if(!(o=o||document.getElementById("jazz-midi-msg")))return;try{t=JSON.parse(o.innerText)}catch(t){}o.innerText=""}function i(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}document.removeEventListener("jazz-midi-msg",u),"version"===t[0]?(n=o,t=t[2],d._type="extension",d._version=t,d._sysex=!0,d._pool=[],d._outs=[],d._ins=[],d._inArr=[],d._outArr=[],d._inMap={},d._outMap={},d._outsW=[],d._insW=[],d.refreshClients=[],d._msg=n,d._newPlugin=function(){var t={id:d._pool.length};d._pool.push(t),t.id?document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["new"]})):t.ready=!0},d._newPlugin(),d._refresh=function(t){d.refreshClients.push(t),t._pause(),z(function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["refresh"]}))})},d._openOut=function(t,n){var e,r=d._outMap[n];r||(d._pool.length<=d._outArr.length&&d._newPlugin(),e=d._pool[d._outArr.length],((r={name:n,clients:[],info:{name:n,manufacturer:d._allOuts[n].manufacturer,version:d._allOuts[n].version,type:"MIDI-out",sysex:d._sysex,engine:d._type},_start:function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["openout",e.id,n]}))},_close:function(t){d._closeOut(t)},_closeAll:i,_receive:function(t){t.length&&((t=t.slice()).splice(0,0,"play",e.id),document.dispatchEvent(new CustomEvent("jazz-midi",{detail:t})))}}).plugin=e).output=r,d._outArr.push(r),d._outMap[n]=r),c((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())},d._openIn=function(t,n){var e,r=d._inMap[n];r||(d._pool.length<=d._inArr.length&&d._newPlugin(),e=d._pool[d._inArr.length],((r={name:n,clients:[],info:{name:n,manufacturer:d._allIns[n].manufacturer,version:d._allIns[n].version,type:"MIDI-in",sysex:d._sysex,engine:d._type},_start:function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["openin",e.id,n]}))},_close:function(t){d._closeIn(t)},_closeAll:i}).plugin=e).input=r,d._inArr.push(r),d._inMap[n]=r),c((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())},d._closeOut=function(t){var n=t._impl;h(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["closeout",n.plugin.id]})))},d._closeIn=function(t){var n=t._impl;h(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["closein",n.plugin.id]})))},d._close=function(){d._unwatch()},d._watch=function(){d._insW=d._ins,d._outsW=d._outs,e=setInterval(function(){document.dispatchEvent(new CustomEvent("jazz-midi",{detail:["refresh"]}))},250)},d._unwatch=function(){clearInterval(e),e=void 0},document.addEventListener("jazz-midi-msg",function(t){var n,e,r,i=t.detail?[t.detail]:void 0;if(!i)for(i=d._msg.innerText.split("\n"),d._msg.innerText="",n=0;n<i.length;n++)try{i[n]=JSON.parse(i[n])}catch(t){i[n]=[]}for(n=0;n<i.length;n++){var o=i[n];if(o.length)if("refresh"===o[0]){if(o[1].ins){for(e=0;e<o[1].ins.length;e++)o[1].ins[e].type=d._type;d._ins=o[1].ins}if(o[1].outs){for(e=0;e<o[1].outs.length;e++)o[1].outs[e].type=d._type;d._outs=o[1].outs}for(it(),e=0;e<d.refreshClients.length;e++)d.refreshClients[e]._resume();d.refreshClients=[]}else if("version"===o[0]){var s=d._pool[o[1]];s&&(s.ready=!0,s.input&&s.input._start(),s.output&&s.output._start())}else if("openout"===o[0]){if(r=d._pool[o[1]].output)if(o[2]==r.name){if(r.open=!0,r.clients)for(e=0;e<r.clients.length;e++)r.clients[e]._resume()}else if(r.clients)for(e=0;e<r.clients.length;e++)r.clients[e]._crash()}else if("openin"===o[0]){if(r=d._pool[o[1]].input)if(o[2]==r.name){if(r.open=!0,r.clients)for(e=0;e<r.clients.length;e++)r.clients[e]._resume()}else if(r.clients)for(e=0;e<r.clients.length;e++)r.clients[e]._crash()}else if("midi"===o[0]&&(r=d._pool[o[1]].input)&&r.clients)for(e=0;e<r.clients.length;e++){var u=_(o.slice(3));r.clients[e]._emit(u)}}}),s._resume()):s._crash()}this._pause();try{document.addEventListener("jazz-midi-msg",u),document.dispatchEvent(new Event("jazz-midi"))}catch(t){}setTimeout(function(){r||s._crash()},50)}function Et(){this._pause();var t=this;z(function(){t._crash()})}function Pt(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 c=o[i].toString().toLowerCase();s[c]||(s[c]=!0,"none"===c&&(e=!0),((r="etc"!==c&&void 0!==c?r:!0)?a:u).push(c),h(n,c))}(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(At),t&&!0===t.sysex&&!0!==t.degrade||n.push(It)):"node"==e[r]?(n.push(St),n.push(Et)):"extension"==e[r]?n.push(Bt):"plugin"==e[r]&&n.push(Tt);return n.push(Ot),n}function Ot(){d._type="none",d._version=D,d._sysex=!0,d._outs=[],d._ins=[],d._refresh=function(){it()},d._watch=U,d._unwatch=U,d._close=U}function Ft(){var t;function o(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}d._inArr=[],d._outArr=[],d._inMap={},d._outMap={},d._outsW=[],d._insW=[],d._version=d._main.version,d._sysex=!0,d._refresh=function(){var t,n;for(d._outs=[],d._ins=[],t=0;(n=d._main.MidiOutInfo(t)).length;t++)d._outs.push({type:d._type,name:n[0],manufacturer:n[1],version:n[2]});for(t=0;(n=d._main.MidiInInfo(t)).length;t++)d._ins.push({type:d._type,name:n[0],manufacturer:n[1],version:n[2]});it()},d._openOut=function(t,n){var e=d._outMap[n];if(e||(d._pool.length<=d._outArr.length&&d._pool.push(d._newPlugin()),e={name:n,clients:[],info:{name:n,manufacturer:d._allOuts[n].manufacturer,version:d._allOuts[n].version,type:"MIDI-out",sysex:d._sysex,engine:d._type},_close:function(t){d._closeOut(t)},_closeAll:o,_receive:function(t){t.length&&this.plugin.MidiOutRaw(t.slice())}},r=d._pool[d._outArr.length],e.plugin=r,d._outArr.push(e),d._outMap[n]=e),!e.open){var r=e.plugin.MidiOutOpen(n);if(r!==n)return r&&e.plugin.MidiOutClose(),void t._break();e.open=!0}c((t._orig._impl=e).clients,t._orig),t._info=e.info,t._receive=function(t){e._receive(t)},t._close=function(){e._close(this)}},d._openIn=function(t,n){var e,r=d._inMap[n];if(r||(d._pool.length<=d._inArr.length&&d._pool.push(d._newPlugin()),(r={name:n,clients:[],info:{name:n,manufacturer:d._allIns[n].manufacturer,version:d._allIns[n].version,type:"MIDI-in",sysex:d._sysex,engine:d._type},_close:function(t){d._closeIn(t)},_closeAll:o,handle:function(t,n){for(var e=0;e<this.clients.length;e++){var r=_(n);this.clients[e]._emit(r)}}}).onmidi=(e=r,function(t,n){e.handle(t,n)}),i=d._pool[d._inArr.length],r.plugin=i,d._inArr.push(r),d._inMap[n]=r),!r.open){var i=r.plugin.MidiInOpen(n,r.onmidi);if(i!==n)return i&&r.plugin.MidiInClose(),void t._break();r.open=!0}c((t._orig._impl=r).clients,t._orig),t._info=r.info,t._close=function(){r._close(this)}},d._closeOut=function(t){var n=t._impl;h(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,n.plugin.MidiOutClose())},d._closeIn=function(t){var n=t._impl;h(n.clients,t._orig),!n.clients.length&&n.open&&(n.open=!1,n.plugin.MidiInClose())},d._close=function(){for(var t=0;t<d._inArr.length;t++)d._inArr[t].open&&d._inArr[t].plugin.MidiInClose();d._unwatch()},d._watch=function(){t=t||setInterval(function(){d._refresh()},250)},d._unwatch=function(){t&&clearInterval(t),t=void 0}}function Nt(t,n){var e;function o(){for(var t=0;t<this.clients.length;t++)this._close(this.clients[t])}d._type="webmidi",d._version=43,d._sysex=!!n,d._access=t,d._inMap={},d._outMap={},d._outsW=[],d._insW=[],d._refresh=function(){d._outs=[],d._ins=[],d._access.outputs.forEach(function(t){d._outs.push({type:d._type,name:t.name,manufacturer:t.manufacturer,version:t.version})}),d._access.inputs.forEach(function(t){d._ins.push({type:d._type,name:t.name,manufacturer:t.manufacturer,version:t.version})}),it()},d._openOut=function(t,n){var e,r=(r=d._outMap[n])||{name:n,clients:[],info:{name:n,manufacturer:d._allOuts[n].manufacturer,version:d._allOuts[n].version,type:"MIDI-out",sysex:d._sysex,engine:d._type},_close:function(t){d._closeOut(t)},_closeAll:o,_receive:function(t){r.dev&&t.length&&this.dev.send(t.slice())}};d._access.outputs.forEach(function(t){t.name===n&&(e=t)}),e?(r.dev=e,d._outMap[n]=r,c((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()},d._openIn=function(t,n){var e,r,i=(i=d._inMap[n])||{name:n,clients:[],info:{name:n,manufacturer:d._allIns[n].manufacturer,version:d._allIns[n].version,type:"MIDI-in",sysex:d._sysex,engine:d._type},_close:function(t){d._closeIn(t)},_closeAll:o,handle:function(t){for(var n=0;n<this.clients.length;n++){var e=_([].slice.call(t.data));this.clients[n]._emit(e)}}};d._access.inputs.forEach(function(t){t.name===n&&(e=t)}),e?(i.dev=e,i.dev.onmidimessage=(r=i,function(t){r.handle(t)}),d._inMap[n]=i,c((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()},d._closeOut=function(t){var n=t._impl;h(n.clients,t._orig),n.clients.length||(n.dev&&n.dev.close&&n.dev.close(),n.dev=void 0)},d._closeIn=function(t){var n=t._impl;h(n.clients,t._orig),n.clients.length||(n.dev&&(n.dev.onmidimessage=null,n.dev.close&&n.dev.close()),n.dev=void 0)},d._close=function(){d._unwatch()},d._watch=function(){d._access.onstatechange=function(){e=!0,z(function(){e&&(d._refresh(),e=!1)})}},d._unwatch=function(){d._access.onstatechange=void 0}}var g=function(t){return f||(t=t,(f=new r)._options=t,f._push(Q,[Pt(t)]),f.refresh(),f._resume()),f._thenable()};function m(){var t=this instanceof m?this:new m;return m.prototype.reset.apply(t,arguments),t}function kt(){29.97==this.type&&!this.second&&this.frame<2&&this.minute%10&&(this.frame=2)}function Rt(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 Lt(t){for(var n,e=[],r=0;r<t.length;r++)e[r]=(n=r?t[r]:31&t[r])<10?"0"+n:n;return e.join(":")}function _(n){var e=this instanceof _?this:new _;if(n instanceof _)return e._from=n._from.slice(),u(n,function(t){"_from"!=t&&(e[t]=n[t])}),e;if(e._from=[],void 0===n)return e;for(var t=n instanceof Array?n:arguments,r=0;r<t.length;r++)i=t[r],1==r&&(128<=e[0]&&e[0]<=175&&(i=_.noteValue(i)),192<=e[0]&&e[0]<=207&&(i=_.programValue(i))),(i!=parseInt(i)||i<0||255<i)&&jt(t[r]),e.push(i);return e}(g.JZZ=g).version=D,g.info=function(){return r.prototype.info()},g.Widget=function(n){var e=new p;return n instanceof Object&&u(n,function(t){e[t]=n[t]}),e._resume(),e},r.prototype.Widget=g.Widget,g.addMidiIn=function(t,n){var e=K(n._info||{});return e.name=t,e.type=e.type||"javascript",e.manufacturer=e.manufacturer||"virtual",e.version=e.version||"0.0",g.lib.registerMidiIn(t,{_info:function(){return e},_openIn:function(t){t._pause(),t._info=K(e),t._close=function(){n.disconnect(t)},n.connect(t),t._resume()}})},r.prototype.addMidiIn=g.addMidiIn,g.addMidiOut=function(t,n){var e=K(n._info||{});return e.name=t,e.type=e.type||"javascript",e.manufacturer=e.manufacturer||"virtual",e.version=e.version||"0.0",g.lib.registerMidiOut(t,{_info:function(){return e},_openOut:function(t){t._pause(),t._info=K(e),t._close=function(){t.disconnect()},dt.apply(t,[n]),t._resume()}})},r.prototype.addMidiOut=g.addMidiOut,g.maskMidiIn=function(t){rt[t]=!0},r.prototype.maskMidiIn=g.maskMidiIn,g.unmaskMidiIn=function(t){delete rt[t]},r.prototype.unmaskMidiIn=g.unmaskMidiIn,g.maskMidiOut=function(t){et[t]=!0},r.prototype.maskMidiOut=g.maskMidiOut,g.unmaskMidiOut=function(t){delete et[t]},r.prototype.unmaskMidiOut=g.unmaskMidiOut,m.prototype.reset=function(t){if(t instanceof m)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},m.prototype.isFullFrame=function(){return 0==this.quarter||4==this.quarter},m.prototype.getType=function(){return this.type},m.prototype.getHour=function(){return this.hour},m.prototype.getMinute=function(){return this.minute},m.prototype.getSecond=function(){return this.second},m.prototype.getFrame=function(){return this.frame},m.prototype.getQuarter=function(){return this.quarter},m.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,kt.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},m.prototype.setHour=function(t){if((t=void 0===t?0:t)!=parseInt(t)||t<0||24<=t)throw RangeError("Bad SMPTE hours value: "+t);return this.hour=t,this},m.prototype.setMinute=function(t){if((t=void 0===t?0:t)!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE minutes value: "+t);return this.minute=t,kt.apply(this),this},m.prototype.setSecond=function(t){if((t=void 0===t?0:t)!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE seconds value: "+t);return this.second=t,kt.apply(this),this},m.prototype.setFrame=function(t){if((t=void 0===t?0:t)!=parseInt(t)||t<0||t>=this.type)throw RangeError("Bad SMPTE frame number: "+t);return this.frame=t,kt.apply(this),this},m.prototype.setQuarter=function(t){if((t=void 0===t?0:t)!=parseInt(t)||t<0||8<=t)throw RangeError("Bad SMPTE quarter frame: "+t);return this.quarter=t,this},m.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))),kt.apply(this),this},m.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},m.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},m.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},m.prototype.read=function(t){return 240==(t=t instanceof _?t:_.apply(null,arguments))[0]&&127==t[1]&&1==t[3]&&1==t[4]&&247==t[9]?(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)):241==t[0]&&void 0!==t[1]&&(n=t[1]>>4,e=15&t[1],0==n?7==this._&&(7==this._f&&(this.reset(Rt(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(Rt(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);var n,e},m.prototype.toString=function(){return Lt([this.hour,this.minute,this.second,this.frame])},g.SMPTE=m,r.prototype.SMPTE=m,_.prototype=[],_.prototype.constructor=_;var v={};function Dt(t){if(t!=parseFloat(t))throw TypeError("Not a number: "+t)}function qt(){}_.noteValue=function(t){return void 0===t?void 0:v[t.toString().toLowerCase()]},_.programValue=function(t){return t},_.octaveValue=function(t){var n=v[t.toString().toLowerCase()];return void 0===(n=void 0===n?v[t.toString().toLowerCase()+"1"]:n)?void 0:n%12},_.freq=function(t,n){return Dt(n=void 0===n?440:n),t!=parseFloat(t)&&(t=M(t)),n*Math.pow(2,(t-69)/12)},_.shift=function(t,n){return void 0===n&&(n=440),Dt(t),Dt(n),12*Math.log2(t/n)},_.midi=function(t,n){return t!=parseFloat(t)?M(t):_.shift(t,n)+69},_.to7b=function(t){return Dt(t),t<=0?0:1<=t?127:Math.floor(128*t)},_.to14b=function(t){return Dt(t),t<=0?0:1<=t?16383:Math.floor(16384*t)},_.to21b=function(t){return void 0===t?2097151:(Dt(t),t<=0?0:(t=(Math.floor(t)<<14)+_.to14b(t-Math.floor(t)))<2097151?t:2097150)},(qt.prototype=_)._sxid=127,_.sxId=function(t){if((t=void 0===t?_._sxid:t)==this._sxid)return this;t=C(t);var n=new qt;return n._ch=this._ch,n._sxid=t,n},_.ch=function(t){if(t==this._ch||void 0===t&&void 0===this._ch)return this;var n=new qt;return void 0!==t&&(t=y(t)),n._ch=t,n._sxid=this._sxid,n};var Gt={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(u(Gt,function(t){for(i=0;i<12&&!(127<(n=Gt[t]+12*i));i++)v[t+i]=n,0<(v[t+"♮"+i]=n)&&(v[t+"b"+i]=n-1,v[t+"♭"+i]=n-1,v[t+"bb"+i]=n-2,v[t+"♭♭"+i]=n-2,v[t+"𝄫"+i]=n-2),n<127&&(v[t+"#"+i]=n+1,v[t+"♯"+i]=n+1,v[t+"##"+i]=n+2,v[t+"♯♯"+i]=n+2,v[t+"𝄪"+i]=n+2)}),i=0;i<128;i++)v[i]=i;function jt(t){throw RangeError("Bad MIDI value: "+t)}function zt(t){throw TypeError("Invalid value: "+t)}function y(t){return _t(t),parseInt(t)}function b(t){if(t!=parseInt(t)||t<0||15<t)throw RangeError("Expected a 4-bit value: "+t);return parseInt(t)}function C(t,n){return(t!=parseInt(t)||t<0||127<t)&&jt(void 0===n?t:n),parseInt(t)}function Ut(t){return(t!=parseInt(t)||t<0||255<t)&&jt(t),parseInt(t)}function Vt(t){return(t!=parseInt(t)||t<0||16383<t)&&jt(t),parseInt(t)}function Wt(t){if(t!=parseInt(t)||t<0||65535<t)throw RangeError("Expected a 16-bit value: "+t);return parseInt(t)}function M(t){return C(_.noteValue(t),t)}function x(t){return 127&Vt(t)}function S(t){return Vt(t)>>7}function Zt(t){return[t>>14,t>>7&127,127&t]}function Jt(t,n){if(t!=parseFloat(t)&&zt(void 0===n?t:n),t<0||1<t)throw RangeError("Out of range: "+(void 0===n?t:n));return parseFloat(t)}function Xt(t){return void 0===t||t?127:126}function Ht(e){for(var r,i=[],o={},t=(u(e,function(t){var n;if(((n=e[t])!=parseInt(n)||n<0||2097151<n)&&jt(n),r=parseInt(n),(t=M(t))in o)throw RangeError("Duplicate MIDI value: "+t);i.push(t),o[t]=r}),i.sort(),[i.length]),n=0;n<i.length;n++)t=t.concat([i[n]],Zt(o[i[n]]));return t}function Qt(n){var e={};return u(n,function(t){e[t]=_.to21b(n[t]==parseFloat(n[t])?n[t]:M(n[t]))}),e}function Kt(n){var e={};return u(n,function(t){e[t]=_.to21b(_.midi(n[t]))}),e}var Yt={noteOff:function(t,n,e){return void 0===e&&(e=64),[128+y(t),M(n),C(e)]},noteOn:function(t,n,e){return void 0===e&&(e=127),[144+y(t),M(n),C(e)]},aftertouch:function(t,n,e){return[160+y(t),M(n),C(e)]}},T={control:function(t,n,e){return[176+y(t),C(n),C(e)]},program:function(t,n){return[192+y(t),C(_.programValue(n),n)]},pressure:function(t,n){return[208+y(t),C(n)]},pitchBend:function(t,n,e){return void 0===e?[224+y(t),x(n),S(n)]:[224+y(t),C(e),C(n)]},pitchBendF:function(t,n){return T.pitchBend(t,_.to14b((n+1)/2))},bankMSB:function(t,n){return[176+y(t),0,C(n)]},bankLSB:function(t,n){return[176+y(t),32,C(n)]},modMSB:function(t,n){return[176+y(t),1,C(n)]},modLSB:function(t,n){return[176+y(t),33,C(n)]},breathMSB:function(t,n){return[176+y(t),2,C(n)]},breathLSB:function(t,n){return[176+y(t),34,C(n)]},footMSB:function(t,n){return[176+y(t),4,C(n)]},footLSB:function(t,n){return[176+y(t),36,C(n)]},portamentoMSB:function(t,n){return[176+y(t),5,C(n)]},portamentoLSB:function(t,n){return[176+y(t),37,C(n)]},dataMSB:function(t,n){return[176+y(t),6,C(n)]},dataLSB:function(t,n){return[176+y(t),38,C(n)]},volumeMSB:function(t,n){return[176+y(t),7,C(n)]},volumeLSB:function(t,n){return[176+y(t),39,C(n)]},balanceMSB:function(t,n){return[176+y(t),8,C(n)]},balanceLSB:function(t,n){return[176+y(t),40,C(n)]},panMSB:function(t,n){return[176+y(t),10,C(n)]},panLSB:function(t,n){return[176+y(t),42,C(n)]},expressionMSB:function(t,n){return[176+y(t),11,C(n)]},expressionLSB:function(t,n){return[176+y(t),43,C(n)]},damper:function(t,n){return void 0===n&&(n=!0),[176+y(t),64,n?127:0]},portamento:function(t,n){return void 0===n&&(n=!0),[176+y(t),65,n?127:0]},sostenuto:function(t,n){return void 0===n&&(n=!0),[176+y(t),66,n?127:0]},soft:function(t,n){return void 0===n&&(n=!0),[176+y(t),67,n?127:0]},legato:function(t,n){return void 0===n&&(n=!0),[176+y(t),68,n?127:0]},hold2:function(t,n){return void 0===n&&(n=!0),[176+y(t),69,n?127:0]},soundVariation:function(t,n){return[176+y(t),70,M(n)]},filterResonance:function(t,n){return[176+y(t),71,M(n)]},releaseTime:function(t,n){return[176+y(t),72,M(n)]},attackTime:function(t,n){return[176+y(t),73,M(n)]},brightness:function(t,n){return[176+y(t),74,M(n)]},decayTime:function(t,n){return[176+y(t),75,M(n)]},vibratoRate:function(t,n){return[176+y(t),76,M(n)]},vibratoDepth:function(t,n){return[176+y(t),77,M(n)]},vibratoDelay:function(t,n){return[176+y(t),78,M(n)]},ptc:function(t,n){return[176+y(t),84,M(n)]},dataIncr:function(t){return[176+y(t),96,0]},dataDecr:function(t){return[176+y(t),97,0]},nrpnLSB:function(t,n){return[176+y(t),98,C(n)]},nrpnMSB:function(t,n){return[176+y(t),99,C(n)]},rpnLSB:function(t,n){return[176+y(t),100,C(n)]},rpnMSB:function(t,n){return[176+y(t),101,C(n)]},allSoundOff:function(t){return[176+y(t),120,0]},resetAllControllers:function(t){return[176+y(t),121,0]},localControl:function(t,n){return void 0===n&&(n=!0),[176+y(t),122,n?127:0]},allNotesOff:function(t){return[176+y(t),123,0]},omni:function(t,n){return void 0===n&&(n=!0),[176+y(t),n?125:124,0]},mono:function(t,n){return void 0===n&&(n=1),[176+y(t),126,C(n)]},poly:function(t){return[176+y(t),127,0]}};function $t(t,n,e,r){return void 0!==n?[C(t),C(n),C(e),C(r)]:((t!=parseInt(t)||t<0||65535<i)&&zt(t),[(t=parseInt(t))>>12&15,t>>8&15,t>>4&15,15&t])}function tn(t){return Dt(t),Math.round(1e3*t+1024)}var nn={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,x(t),S(t)]:[242,C(n),C(t)]},songSelect:function(t){return[243,C(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]},reset:function(){return[255]}},w={sxIdRequest:function(){return[240,126,this._sxid,6,1,247]},sxTuningDumpRequest:function(t,n){return void 0===n?[240,126,this._sxid,8,0,C(t),247]:[240,126,this._sxid,8,3,C(t),C(n),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,n){return void 0===n?[240,127,this._sxid,4,1,x(t),S(t),247]:[240,127,this._sxid,4,1,C(n),C(t),247]},sxMasterVolumeF:function(t){return w.sxMasterVolume.call(this,_.to14b(Jt(t)))},sxMasterFineTuning:function(t,n){return void 0===n?[240,127,this._sxid,4,3,x(t),S(t),247]:[240,127,this._sxid,4,3,C(n),C(t),247]},sxMasterFineTuningF:function(t){return w.sxMasterFineTuning.call(this,_.to14b(Jt((t%1+1)/2,t)))},sxMasterCoarseTuning:function(t){return[240,127,this._sxid,4,4,0,C(t),247]},sxMasterCoarseTuningF:function(t){return w.sxMasterCoarseTuning.call(this,t-t%1+64)},sxNoteTuning:function(t,n,e,r){return n==parseInt(n)?[240,Xt(r),this._sxid,8,7,C(t),C(n)].concat(Ht(e),[247]):[240,127,this._sxid,8,2,C(t)].concat(Ht(n),[247])},sxNoteTuningF:function(t,n,e,r){return n==parseInt(n)?w.sxNoteTuning.call(this,t,n,Qt(e),r):w.sxNoteTuning.call(this,t,Qt(n))},sxNoteTuningHZ:function(t,n,e,r){return n==parseInt(n)?w.sxNoteTuning.call(this,t,n,Kt(e),r):w.sxNoteTuning.call(this,t,Kt(n))},sxScaleTuning1:function(t,n,e){return t==parseInt(t)?[240,Xt(e),this._sxid,8,8].concat(Zt(Wt(t)),function(t){var n=[];if(!(t instanceof Array)||12!=t.length)throw TypeError("Expected an array of size 12");for(var e=0;e<12;e++)n.push(C(t[e]));return n}(n),[247]):w.sxScaleTuning1.call(this,65535,t,n)},sxScaleTuning1F:function(t,n,e){if(t!=parseInt(t))return w.sxScaleTuning1F.call(this,65535,t,n);for(var r=[],i=0;i<n.length;i++){if(n[i]<-.64||.63<n[i])throw RangeError("Out of range: "+n[i]);r.push(Math.floor(100*n[i]+64))}return w.sxScaleTuning1.call(this,t,r,e)},sxScaleTuning2:function(t,n,e){return t==parseInt(t)?[240,Xt(e),this._sxid,8,9].concat(Zt(Wt(t)),function(t){var n=[];if(!(t instanceof Array)||12!=t.length)throw TypeError("Expected an array of size 12");for(var e=0;e<12;e++)n.push(S(t[e])),n.push(x(t[e]));return n}(n),[247]):w.sxScaleTuning2.call(this,65535,t,n)},sxScaleTuning2F:function(t,n,e){if(t!=parseInt(t))return w.sxScaleTuning2F.call(this,65535,t,n);for(var r=[],i=0;i<n.length;i++){var o=(n[i]+1)/2;if(o<-1||1<o)throw RangeError("Out of range: "+n[i]);r.push(_.to14b((n[i]+1)/2))}return w.sxScaleTuning2.call(this,t,r,e)},sxGM:function(t){return[240,126,this._sxid,9,(t=void 0===t?1:t)?2==t?3:1:2,247]},sxGS:function(t){for(var n=void 0===t?[64,0,127,0]:t instanceof Array?t:arguments,e=0,r=[240,65,this._sxid,66,18],i=0;i<n.length;i++){var o=C(n[i]);r.push(o),e+=o}return r.push((e%=128)?128-e:0),r.push(247),r},sxXG:function(t){for(var n=void 0===t?[0,0,126,0]:t instanceof Array?t:arguments,e=127==this._sxid?0:this._sxid,r=(15<e&&jt("Bad Yamaha device number: "+e),[240,67,16+e,76]),i=0;i<n.length;i++)r.push(C(n[i]));return r.push(247),r},sxMidiSoft:function(t,n){var e=[240,0,32,36,0,C(t||0)];n=void 0===n?"":""+n;for(var r=0;r<n.length;r++)e.push(C(n.charCodeAt(r)));return e.push(247),e},gsMasterVolume:function(t){return w.sxGS.call(this,[64,0,4,C(t)])},gsMasterVolumeF:function(t){return w.gsMasterVolume.call(this,_.to7b(Jt(t)))},gsMasterFineTuning:function(t,n,e,r){return t=$t(t,n,e,r),w.sxGS.call(this,[64,0,0,t[0],t[1],t[2],t[3]])},gsMasterFineTuningF:function(t){return w.gsMasterFineTuning.call(this,tn(t%1))},gsMasterCoarseTuning:function(t){return w.sxGS.call(this,[64,0,5,C(t)])},gsMasterCoarseTuningF:function(t){return w.gsMasterCoarseTuning.call(this,t-t%1+64)},gsOctaveTuning:function(t,n,e){return w.sxGS.call(this,[64,16+[1,2,3,4,5,6,7,8,9,0,11,12,13,14,15][y(t)],64+_.octaveValue(n),C(e)])},gsOctaveTuningF:function(t,n,e){if(e<-.64||.63<e)throw RangeError("Out of range: "+e);return w.gsOctaveTuning.call(this,t,n,Math.floor(100*e+64))},xgMasterVolume:function(t){return w.sxXG.call(this,[0,0,4,C(t)])},xgMasterVolumeF:function(t){return w.xgMasterVolume.call(this,_.to7b(Jt(t)))},xgMasterFineTuning:function(t,n,e,r){return t=$t(t,n,e,r),w.sxXG.call(this,[0,0,0,t[0],t[1],t[2],t[3]])},xgMasterFineTuningF:function(t){return w.xgMasterFineTuning.call(this,tn(t%1))},xgMasterCoarseTuning:function(t){return w.sxXG.call(this,[0,0,6,C(t)])},xgMasterCoarseTuningF:function(t){return w.xgMasterCoarseTuning.call(this,t-t%1+64)},xgOctaveTuning:function(t,n,e){return w.sxXG.call(this,[8,y(t),65+_.octaveValue(n),C(e)])},xgOctaveTuningF:function(t,n,e){if(e<-.64||.63<e)throw RangeError("Out of range: "+e);return w.xgOctaveTuning.call(this,t,n,Math.floor(100*e+64))}},I=(w.sxScaleTuning=w.sxScaleTuning2,w.sxScaleTuningF=w.sxScaleTuning2F,w.sxMasterTranspose=w.sxMasterCoarseTuning,w.sxMasterTransposeF=w.sxMasterCoarseTuningF,w.gsMasterTranspose=w.gsMasterCoarseTuning,w.gsMasterTransposeF=w.gsMasterCoarseTuningF,w.xgMasterTranspose=w.xgMasterCoarseTuning,w.xgMasterTransposeF=w.xgMasterCoarseTuningF,{bank:function(t,n,e){return void 0===e?[T.bankMSB(t,S(n)),T.bankLSB(t,x(n))]:[T.bankMSB(t,n),T.bankLSB(t,e)]},modF:function(t,n){return I.mod(t,_.to14b(n))},mod:function(t,n,e){return void 0===e?[T.modMSB(t,S(n)),T.modLSB(t,x(n))]:[T.modMSB(t,n),T.modLSB(t,e)]},breathF:function(t,n){return I.breath(t,_.to14b(n))},breath:function(t,n,e){return void 0===e?[T.breathMSB(t,S(n)),T.breathLSB(t,x(n))]:[T.breathMSB(t,n),T.breathLSB(t,e)]},footF:function(t,n){return I.foot(t,_.to14b(n))},foot:function(t,n,e){return void 0===e?[T.footMSB(t,S(n)),T.footLSB(t,x(n))]:[T.footMSB(t,n),T.footLSB(t,e)]},portamentoTimeF:function(t,n){return I.portamentoTime(t,_.to14b(n))},portamentoTime:function(t,n,e){return void 0===e?[T.portamentoMSB(t,S(n)),T.portamentoLSB(t,x(n))]:[T.portamentoMSB(t,n),T.portamentoLSB(t,e)]},dataF:function(t,n){return I.data(t,_.to14b(n))},data:function(t,n,e){return void 0===e?[T.dataMSB(t,S(n)),T.dataLSB(t,x(n))]:[T.dataMSB(t,n),T.dataLSB(t,e)]},volumeF:function(t,n){return I.volume(t,_.to14b(n))},volume:function(t,n,e){return void 0===e?[T.volumeMSB(t,S(n)),T.volumeLSB(t,x(n))]:[T.volumeMSB(t,n),T.volumeLSB(t,e)]},balanceF:function(t,n){return I.balance(t,_.to14b((n+1)/2))},balance:function(t,n,e){return void 0===e?[T.balanceMSB(t,S(n)),T.balanceLSB(t,x(n))]:[T.balanceMSB(t,n),T.balanceLSB(t,e)]},panF:function(t,n){return I.pan(t,_.to14b((n+1)/2))},pan:function(t,n,e){return void 0===e?[T.panMSB(t,S(n)),T.panLSB(t,x(n))]:[T.panMSB(t,n),T.panLSB(t,e)]},expressionF:function(t,n){return I.expression(t,_.to14b(n))},expression:function(t,n,e){return void 0===e?[T.expressionMSB(t,S(n)),T.expressionLSB(t,x(n))]:[T.expressionMSB(t,n),T.expressionLSB(t,e)]},nrpn:function(t,n,e){return void 0===e?[T.nrpnMSB(t,S(n)),T.nrpnLSB(t,x(n))]:[T.nrpnMSB(t,n),T.nrpnLSB(t,e)]},rpn:function(t,n,e){return void 0===e?[T.rpnMSB(t,S(n)),T.rpnLSB(t,x(n))]:[T.rpnMSB(t,n),T.rpnLSB(t,e)]},rpnPitchBendRange:function(t,n,e){return I.rpn(t,0,0).concat(I.data(t,n,e))},rpnPitchBendRangeF:function(t,n){return I.rpnPitchBendRange(t,C(n-n%1),Math.floor(n%1*100))},rpnFineTuning:function(t,n,e){return I.rpn(t,0,1).concat(I.data(t,n,e))},rpnFineTuningF:function(t,n){return I.rpn(t,0,1).concat(I.dataF(t,(n%1+1)/2))},rpnCoarseTuning:function(t,n){return I.rpn(t,0,2).concat([T.dataMSB(t,n)])},rpnCoarseTuningF:function(t,n){return I.rpn(t,0,2).concat([T.dataMSB(t,n-n%1+64)])},rpnTuning:function(t,n,e,r){return I.rpnCoarseTuning(t,n).concat(I.rpnFineTuning(t,e,r))},rpnTuningF:function(t,n){return I.rpnCoarseTuningF(t,n).concat(I.rpnFineTuningF(t,n))},rpnTuningA:function(t,n){return I.rpnTuningF(t,_.shift(n))},rpnSelectTuningProgram:function(t,n){return I.rpn(t,0,3).concat([T.dataMSB(t,n)])},rpnSelectTuningBank:function(t,n){return I.rpn(t,0,4).concat([T.dataMSB(t,n)])},rpnSelectTuning:function(t,n,e){return void 0===e?I.rpnSelectTuningProgram(t,n):I.rpnSelectTuningBank(t,n).concat(I.rpnSelectTuningProgram(t,e))},rpnModulationDepthRange:function(t,n,e){return I.rpn(t,0,5).concat(I.data(t,n,e))},rpnModulationDepthRangeF:function(t,n){return I.rpnModulationDepthRange(t,C(n-n%1),Math.floor(n%1*128))},rpnNull:function(t){return I.rpn(t,127,127)},mode1:function(t){return[T.omni(t,!0),T.poly(t)]},mode2:function(t){return[T.omni(t,!0),T.mono(t)]},mode3:function(t){return[T.omni(t,!1),T.poly(t)]},mode4:function(t){return[T.omni(t,!1),T.mono(t)]}}),en={sxMasterTuning:function(t,n,e){return[w.sxMasterCoarseTuning.call(this,t),w.sxMasterFineTuning.call(this,n,e)]},sxMasterTuningF:function(t){return[w.sxMasterCoarseTuningF.call(this,t),w.sxMasterFineTuningF.call(this,t)]},gsMasterTuningF:function(t){return[w.gsMasterCoarseTuningF.call(this,t),w.gsMasterFineTuningF.call(this,t)]},xgMasterTuningF:function(t){return[w.xgMasterCoarseTuningF.call(this,t),w.xgMasterFineTuningF.call(this,t)]},sxMasterTuningA:function(t){return en.sxMasterTuningF.call(this,_.shift(t))},gsMasterTuningA:function(t){return en.gsMasterTuningF.call(this,_.shift(t))},xgMasterTuningA:function(t){return en.xgMasterTuningF.call(this,_.shift(t))},gsScaleTuning:function(t,n){var e=[];if(12!=n.length)throw RangeError("Wrong input size: "+n.length);for(var r=0;r<12;r++)e.push(w.gsOctaveTuning.call(this,t,r,n[r]));return e},gsScaleTuningF:function(t,n){var e=[];if(12!=n.length)throw RangeError("Wrong input size: "+n.length);for(var r=0;r<12;r++)e.push(w.gsOctaveTuningF.call(this,t,r,n[r]));return e},xgScaleTuning:function(t,n){var e=[];if(12!=n.length)throw RangeError("Wrong input size: "+n.length);for(var r=0;r<12;r++)e.push(w.xgOctaveTuning.call(this,t,r,n[r]));return e},xgScaleTuningF:function(t,n){var e=[];if(12!=n.length)throw RangeError("Wrong input size: "+n.length);for(var r=0;r<12;r++)e.push(w.xgOctaveTuningF.call(this,t,r,n[r]));return e}};function A(t,n){var e=new _;return e.ff=Ut(t),e.dd=void 0===n?"":function(t){t=""+t;for(var n=0;n<t.length;n++)255<t.charCodeAt(n)&&jt(t[n]);return t}(n),e}var rn={smf:function(t){if(t instanceof _)return new _(t);var n=t instanceof Array?t:arguments,e=Ut(n[0]),r="";return 2==n.length?r=fn(n[1]):2<n.length&&(r=fn(Array.prototype.slice.call(n,1))),A(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"+_n(t));return A(0,t)},smfText:function(t){return A(1,g.lib.toUTF8(t))},smfCopyright:function(t){return A(2,g.lib.toUTF8(t))},smfSeqName:function(t){return A(3,g.lib.toUTF8(t))},smfInstrName:function(t){return A(4,g.lib.toUTF8(t))},smfLyric:function(t){return A(5,g.lib.toUTF8(t))},smfMarker:function(t){return A(6,g.lib.toUTF8(t))},smfCuePoint:function(t){return A(7,g.lib.toUTF8(t))},smfProgName:function(t){return A(8,g.lib.toUTF8(t))},smfDevName:function(t){return A(9,g.lib.toUTF8(t))},smfChannelPrefix:function(t){if(t==parseInt(t))_t(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"+_n(t));return A(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"+_n(t));return A(33,t)},smfEndOfTrack:function(t){if(""!=fn(t))throw RangeError("Unexpected data"+_n(fn(t)));return A(47)},smfTempo:function(t){if(3==(""+t).length)return A(81,t);if(t==parseInt(t)&&0<t&&t<=16777215)return A(81,String.fromCharCode(t>>16)+String.fromCharCode(t>>8&255)+String.fromCharCode(255&t));throw RangeError("Out of range"+_n(fn(t)))},smfBPM:function(t){return rn.smfTempo(Math.round(6e7/t))},smfSMPTE:function(t){if(t instanceof m)return A(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 A(84,t);var n=t instanceof Array?t:Array.prototype.slice.call(arguments);return n.splice(0,0,30),rn.smfSMPTE(new m(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<256&&0<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,A(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return A(88,t)}else if(t==parseInt(t)&&n==parseInt(n)){if(0<t&&t<256&&0<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,A(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return A(88,t);t=t+"/"+n}else if(4==(""+t).length)return A(88,t);throw RangeError("Wrong time signature"+_n(fn(""+t)))},smfKeySignature:function(t){var n,e=(t=""+t).match(/^\s*([A-H][b#]?)\s*(|maj|major|dur|m|min|minor|moll)\s*$/i);if(e&&(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}[e[1].toUpperCase()],e={"":0,MAJ:0,MAJOR:0,DUR:0,M:1,MIN:1,MINOR:1,MOLL:1}[e[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 A(89,t);throw RangeError("Incorrect key signature"+_n(t))},smfSequencer:function(t){return A(127,fn(t))}},on={};function sn(t,n){_[t]=function(){return new _(n.apply(this,arguments))},on[t]=function(){return this.send(n.apply(this,arguments))}}function un(n){u(on,function(t){n.prototype[t]=on[t]})}u(nn,function(t){sn(t,nn[t])}),u(w,function(t){sn(t,w[t])}),u(rn,function(t){var n;n=rn[t=t],_[t]=function(){return n.apply(this,arguments)},on[t]=function(){return this.send(n.apply(this,arguments))}}),u(en,function(t){var r;r=en[t=t],_[t]=function(){for(var t=[],n=r.apply(this,arguments),e=0;e<n.length;e++)t.push(new _(n[e]));return t},on[t]=function(){for(var t=r.apply(this,arguments),n=this,e=0;e<t.length;e++)n=n.send(t[e]);return n}}),u(Yt,function(t){var n;n=Yt[t=t],_[t]=function(){return new _(n.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))))},on[t]=function(){var t;return void 0!==this._master?((t=new _(n.apply(this,[this._master].concat(Array.prototype.slice.call(arguments)))))._mpe=t[1],this.send(t)):this.send(n.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))))}}),u(T,function(t){var e;e=T[t=t],_[t]=function(){return new _(e.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))))},on[t]=function(){var t,n;return void 0!==this._master?((n=Array.prototype.slice.call(arguments)).length<e.length?n=[this._master].concat(n):(t=M(n[0]),n[0]=this._master),(n=new _(e.apply(this,n)))._mpe=t,this.send(n)):this.send(e.apply(this,void 0===this._ch?arguments:[this._ch].concat(Array.prototype.slice.call(arguments))))}}),u(I,function(t){var s;s=I[t=t],_[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 _(n[e]));return t},on[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=M(i[0]),i[0]=this._master),n=s.apply(this,i),e=this,t=0;t<n.length;t++){var o=_(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}}),un(p);for(var an={a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15},cn=0;cn<16;cn++)an[cn]=cn;function hn(t){for(var n=[],e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function fn(t){if(t instanceof Array){for(var n=t,e="",r=0;r<n.length;r++)e+=String.fromCharCode(n[r]);return e}return void 0===t?"":""+t}function pn(t){return(t<16?"0":"")+t.toString(16)}function ln(t){for(var n=[],e=0;e<t.length;e++)n.push(pn(t[e]));return n.join(" ")}function dn(t){for(var n=[],e=0;e<t.length;e++)e&&e%4==0&&n.push(" "),n.push(pn(t[e]));return n.join("")}function gn(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"+pn(t.charCodeAt(e)):n+=t[e];return n}function mn(t){return t.length?": "+ln(hn(t)):""}function _n(t){return t.length?": "+gn(g.lib.fromUTF8(t)):""}function vn(){var t;for(this._cc=[],t=0;t<16;t++)this._cc[t]={}}function yn(t){if(!t.length||t[0]<128)return t;if(255==t[0])return this._clear(),t;var n,e,r,i=15&t[0],o=t[0]>>4;if(12==o)t._bm=this._cc[i].bm,t._bl=this._cc[i].bl,g.MIDI.programName&&t.label(g.MIDI.programName(t[1],t._bm,t._bl));else if(11==o)switch(t[1]){case 0:this._cc[i].bm=t[2];break;case 32:this._cc[i].bl=t[2];break;case 98:this._cc[i].nl=t[2],this._cc[i].rn="n";break;case 99:this._cc[i].nm=t[2],this._cc[i].rn="n";break;case 100:this._cc[i].rl=t[2],this._cc[i].rn="r";break;case 101:this._cc[i].rm=t[2],this._cc[i].rn="r";break;case 6:case 38:case 96:case 97:"r"==this._cc[i].rn&&(t._rm=this._cc[i].rm,t._rl=this._cc[i].rl,t.label((r=this._cc[i].rm,e=this._cc[i].rl,r=void 0===r?"??":pn(r),e=void 0===e?"??":pn(e),"RPN "+r+" "+e+((r={"0000":"Pitch Bend Sensitivity","0001":"Channel Fine Tune","0002":"Channel Coarse Tune","0003":"Select Tuning Program","0004":"Select Tuning Bank","0005":"Vibrato Depth Range","7f7f":"NONE"}[r+""+e])?": "+r:"")))),"n"==this._cc[i].rn&&(t._nm=this._cc[i].rm,t._nl=this._cc[i].nl,t.label((e=this._cc[i].nm,r=this._cc[i].nl,"NRPN "+(void 0===e?"??":pn(e))+" "+(void 0===r?"??":pn(r)))))}else t.isFullSysEx()&&(127==t[1]?4==t[3]?(n={1:"Master Volume",2:"Master Balance",3:"Master Fine Tuning",4:"Master Coarse Tuning"}[t[4]])&&t.label(n):8==t[3]&&(n={2:"Note Tuning",7:"Note Tuning, Bank",8:"Scale Tuning, 1 byte format",9:"Scale Tuning, 2 byte format"}[t[4]])&&t.label(n):126==t[1]?6==t[3]?1==t[4]?t.label("Device ID Request"):2==t[4]&&t.label("Device ID Response"):8==t[3]?(n={0:"Bulk Tuning Dump Request",1:"Bulk Tuning Dump",3:"Bulk Tuning Dump Request, Bank",4:"Bulk Tuning Dump, Bank",5:"Scale Tuning Dump, 1 byte format",6:"Scale Tuning Dump, 2 byte format",7:"Note Tuning, Bank",8:"Scale Tuning, 1 byte format",9:"Scale Tuning, 2 byte format"}[t[4]])&&t.label(n):9==t[3]&&(1==t[4]?(t.label("GM1 System On"),this._clear(),this._gm="1"):2==t[4]?(t.label("GM System Off"),this._clear(),this._gm="0"):3==t[4]&&(t.label("GM2 System On"),this._clear(),this._gm="2")):67==t[1]?16==(240&t[2])&&76==t[3]&&(0==t[4]&&0==t[5]&&126==t[6]&&0==t[7]?(t.label("XG System On"),this._clear(),this._gm="Y"):0==t[4]&&0==t[5]&&0==t[6]?t.label("XG Master Tuning"):0==t[4]&&0==t[5]&&4==t[6]?t.label("XG Master Volume"):0==t[4]&&0==t[5]&&6==t[6]?t.label("XG Master Transpose"):8==t[4]&&t[5]<16&&65<=t[6]&&t[6]<=76?t.label("XG Scale Tuning"):t.label("XG Parameter")):65==t[1]&&66==t[3]&&18==t[4]&&(64==t[5]&&(0==t[6]?127==t[7]&&0==t[8]&&65==t[9]?(t.label("GS Reset"),this._clear(),this._gm="R"):0==t[7]?t.label("GS Master Tuning"):4==t[7]?t.label("GS Master Volume"):5==t[7]?t.label("GS Master Transpose"):t.label("GS Parameter"):16==(240&t[6])&&21==t[7]?t.label("GS Drum Part Change"):16==(240&t[6])&&64<=t[7]&&t[7]<=75?t.label("GS Scale Tuning"):t.label("GS Parameter")),65==t[5]&&t.label("GS Parameter")));return t}function bn(){var t=new p;return t._clear=vn,t._read=yn,t._receive=function(t){this._emit(this._read(t))},t._clear(),t._resume(),t}function B(){var t=this instanceof B?this:new B;return t.reset(),arguments.length&&B.prototype.setup.apply(t,arguments),t}function E(n){var e=this instanceof E?this:new E;if(n instanceof E)return e._from=n._from.slice(),u(n,function(t){"_from"!=t&&(e[t]=n[t])}),e;e._from=[];for(var t=(n=void 0===n?[0,0,0,0]:n)instanceof Array?n:arguments,r=e.length=0;r<t.length;r++)((i=t[r])!=parseInt(i)||i<0||255<i)&&jt(t[r]),e.push(i);if(e.length!=[4,4,4,8,8,16,4,4,8,8,8,12,12,16,16,16][e[0]>>4])throw RangeError("Wrong UMP size");return e}function Cn(){}_.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},_.prototype.setChannel=function(t){return void 0===(t=an[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},_.prototype.getNote=function(){var t=this[0];if(!(void 0===t||t<128||175<t))return this[1]},_.prototype.setNote=function(t){var n=this[0];return void 0===n||n<128||175<n||void 0!==(t=_.noteValue(t))&&(this[1]=t),this},_.prototype.getVelocity=function(){var t=this[0];if(!(void 0===t||t<128||159<t))return this[2]},_.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},_.prototype.getSysExId=function(){if(240==this[0])return this[2]},_.prototype.setSysExId=function(t){return 240==this[0]&&2<this.length&&0<=(t=parseInt(t))&&t<128&&(this[2]=t),this},_.prototype.getData=function(){if(void 0!==this.dd)return this.dd.toString()},_.prototype.setData=function(t){return this.dd=fn(t),this},_.prototype.getText=function(){if(void 0!==this.dd)return t=this.ff,n=this.dd,e=n,127==t&&void 0!==e&&67==e.charCodeAt(0)&&123==e.charCodeAt(1)&&1==n.charCodeAt(2)?(t=this.dd.charCodeAt(3),e=this.dd.charCodeAt(4),0<=t&&t<=127&&0<=e&&e<=127?(n=t>>4,0<(t=15&t)&&t<8&&n<7?(t=["C","D","E","F","G","A","B"][t-1]+["bbb","bb","b","","#","##","###"][n],34<e?t+"?":t+["","6","Maj7","Maj7(#11)","(9)","Maj7(9)","6(9)","aug","m","m6","m7","m7b5","m(9)","m7(9)","m7(11)","m+7","m+7(9)","dim","dim7","7","7sus4","7b5","7(9)","7(#11)","7(13)","7(b9)","7(b13)","7(#9)","Maj7aug","7aug","1+8","1+5","sus4","1+2+5","cc"][e]):"-"):"-"):g.lib.fromUTF8(this.dd);var t,n,e;if(this.isMidiSoft()){for(var r=[],i=6;i<this.length-1;i++)r.push(String.fromCharCode(this[i]));return r.join("")}},_.prototype.setText=function(t){return this.dd=g.lib.toUTF8(t),this},_.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)},_.prototype.getBPM=function(){var t=this.getTempo();if(t)return 6e7/t},_.prototype.getTimeSignature=function(){if(88==this.ff&&void 0!==this.dd)return[this.dd.charCodeAt(0),1<<this.dd.charCodeAt(1)]},_.prototype.getTimeSignature4=function(){var t;if(88==this.ff&&void 0!==this.dd)return t=[this.dd.charCodeAt(0),1<<this.dd.charCodeAt(1)],4==this.dd.length&&t.push(this.dd.charCodeAt(2),this.dd.charCodeAt(3)),t},_.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]}},_.prototype.isNoteOn=function(){var t=this[0];return!(void 0===t||t<144||159<t)&&0<this[2]},_.prototype.isNoteOff=function(){var t=this[0];return!(void 0===t||t<128||159<t)&&(t<144||0==this[2])},_.prototype.isSysEx=function(){return 240==this[0]},_.prototype.isFullSysEx=function(){return 240==this[0]&&247==this[this.length-1]},_.prototype.isMidiSoft=function(){return this.isFullSysEx()&&0==this[1]&&32==this[2]&&36==this[3]&&0==this[4]},_.prototype.isSMF=function(){return 0<=this.ff&&this.ff<=127},_.prototype.isEOT=function(){return 47==this.ff},_.prototype.isText=function(){return 1==this.ff},_.prototype.isCopyright=function(){return 2==this.ff},_.prototype.isSeqName=function(){return 3==this.ff},_.prototype.isInstrName=function(){return 4==this.ff},_.prototype.isLyric=function(){return 5==this.ff},_.prototype.isMarker=function(){return 6==this.ff},_.prototype.isCuePoint=function(){return 7==this.ff},_.prototype.isProgName=function(){return 8==this.ff},_.prototype.isDevName=function(){return 9==this.ff},_.prototype.isTempo=function(){return 81==this.ff},_.prototype.isTimeSignature=function(){return 88==this.ff},_.prototype.isKeySignature=function(){return 89==this.ff},_.prototype.isGmReset=function(){return this.match([240,126,[0,0],9,[0,0],247])},_.prototype.isGsReset=function(){return this.match([240,65,[0,0],66,18,64,0,127,0,65,247])},_.prototype.isXgReset=function(){return this.match([240,67,[16,240],76,0,0,126,0,247])},_.prototype.match=function(t){for(var n,e=0;e<t.length;e++)if(void 0===(n=t[e][1])){if(this[e]!=t[e])return!1}else if((this[e]&n)!=(t[e][0]&n))return!1;return!0},_.prototype.label=function(t){return this.lbl=this.lbl?this.lbl+", "+t:t,this},_.prototype.toString=function(){return this.lbl?this._str()+" ("+this.lbl+")":this._str()},_.prototype._str=function(){var t,n;if(this.length)t=ln(this);else{if(void 0===this.ff)return"empty";t="ff"+pn(this.ff)}return(n=this._string())?t+" -- "+n:t},_.prototype._string=function(){var t="";if(!this.length){if(0==this.ff)t+="Sequence Number: "+function(t){for(var n=0,e=0;e<t.length;e++)n=(n<<8)+t.charCodeAt(e);return n}(this.dd);else if(0<this.ff&&this.ff<10)t+=["","Text","Copyright","Sequence Name","Instrument Name","Lyric","Marker","Cue Point","Program Name","Device Name"][this.ff]+_n(this.dd);else if(32==this.ff)t+="Channel Prefix"+mn(this.dd);else if(33==this.ff)t+="MIDI Port"+mn(this.dd);else if(47==this.ff)t+="End of Track"+mn(this.dd);else if(81==this.ff)t+="Tempo: "+Math.round(100*this.getBPM())/100+" bpm";else if(84==this.ff)t+="SMPTE Offset: "+Lt(hn(this.dd));else if(88==this.ff)var n=1<<this.dd.charCodeAt(1),t=(t+="Time Signature: "+this.dd.charCodeAt(0)+"/"+n)+(" "+this.dd.charCodeAt(2)+" "+this.dd.charCodeAt(3));else if(89==this.ff){t+="Key Signature: ";n=this.getKeySignature();n?(t+=n[1],n[2]&&(t+=" min")):t+="invalid"}else if(127==this.ff){if(67==this.dd.charCodeAt(0)&&123==this.dd.charCodeAt(1))return t=(t+="[XF:"+pn(this.dd.charCodeAt(2))+"]")+((e={0:"Version",1:"Chord",2:"Rehearsal Mark",3:"Phrase Mark",4:"Max Phrase Mark",5:"Fingering Number",12:"Guide Track Flag",16:"Guitar Info",18:"Chord Voicing",127:"XG Song Data Number"}[this.dd.charCodeAt(2)])?" "+e:"")+": ",0==this.dd.charCodeAt(2)?t+this.dd.substr(3,4)+" "+ln(hn(this.dd.substr(7))):1==this.dd.charCodeAt(2)?t+this.getText():t+ln(hn(this.dd.substr(3)));t+="Sequencer Specific"+mn(this.dd)}else t+="SMF"+mn(this.dd);return t}if(e={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;if(this.isMidiSoft())return e=(e=gn(this.getText()))&&" "+e,"[K:"+pn(this[5])+"]"+e;var e,n=this[0]>>4;return(e={8:"Note Off",10:"Aftertouch",12:"Program Change",13:"Channel Aftertouch",14:"Pitch Wheel"}[n])?e:9==n?this[2]?"Note On":"Note Off":11!=n?t:(e={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",31:"Karaoke",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",65:"Portamento",66:"Sostenuto",67:"Soft Pedal",68:"Legato",69:"Hold 2",70:"Sound Variation",71:"Filter Resonance",72:"Release Time",73:"Attack Time",74:"Brightness",75:"Decay Time",76:"Vibrato Rate",77:"Vibrato Depth",78:"Vibrato Delay",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]],64<=this[1]&&this[1]<=69&&(e+=this[2]<64?" Off":" On"),e||"Undefined")},_.prototype._stamp=function(t){return this._from.push(t._orig||t),this},_.prototype._unstamp=function(t){return void 0===t?this._from=[]:(t._orig&&(t=t._orig),-1<(t=this._from.indexOf(t))&&this._from.splice(t,1)),this},_.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},g.MIDI=_,r.prototype.MIDI=_,g.Context=bn,r.prototype.Context=bn,B.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])},B.prototype.reset=function(){for(var t=0;t<16;t++)this[t]={band:0,master:t}},B.prototype.setup=function(t,n){B.validate(t,n);var e,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}}},B.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=[]),c(this[n].notes,t.getNote())):t.isNoteOff()&&this[n].notes&&h(this[n].notes,t.getNote())),t},g.MPE=B,((E.prototype=[]).constructor=E).prototype.isMidi2=!0,E.prototype.dump=function(){for(var t="",n=0;n<this.length;n++)t+=String.fromCharCode(this[n]);return t},(Cn.prototype=E)._sxid=127,E.sxId=function(t){if((t=void 0===t?E._sxid:t)==this._sxid)return this;t=C(t);var n=new Cn;return n._ch=this._ch,n._gr=this._gr,n._sxid=t,n},E.ch=function(t){if(t==this._ch||void 0===t&&void 0===this._ch)return this;var n=new Cn;return void 0!==t&&(t=y(t)),n._ch=t,n._gr=this._gr,n._sxid=this._sxid,n},E.gr=function(t){if(t==this._gr||void 0===t&&void 0===this._gr)return this;var n=new Cn;return void 0!==t&&(t=b(t)),n._ch=this._ch,n._gr=t,n._sxid=this._sxid,n},E.prototype.getGroup=function(){var t;if(this[0])return t=this[0]>>4,1==t||2==t||3==t||4==t||5==t||13==t?15&this[0]:void 0};var Mn=[0,0,0,0,0,0,0,0,0,0,0,0,0],xn={noop:function(){return[0,0,0,0]},umpClock:function(t){return[0,16,(t=Wt(t))>>8,255&t]},umpTimestamp:function(t){return[0,32,(t=Wt(t))>>8,255&t]},umpTicksPQN:function(t){return[0,48,(t=Wt(t))>>8,255&t]},umpDelta:function(t){return[0,64+((t=function(t){if(t!=parseInt(t)||t<0||1048575<t)throw RangeError("Expected a 20-bit value: "+t);return parseInt(t)}(t=t||0))>>16),t>>8&255,255&t]},umpStartClip:function(){return[240,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},umpEndClip:function(){return[240,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},Sn={umpTempo:function(t,n){return[208+b(t),16,0,0,n>>24,n>>16&255,n>>8&255,255&n,0,0,0,0,0,0,0,0]},umpBPM:function(t,n){return Sn.umpTempo(t,Math.round(6e9/n))},umpTimeSignature:function(t,n,e){var r,i,o,s=(""+n).match(/^\s*(\d+)\s*\/\s*(\d+)\s*$/);if(s?(r=parseInt(s[1]),i=parseInt(s[2])):n==parseInt(n)&&e==parseInt(e)&&(r=parseInt(n),i=parseInt(e)),0<r&&r<256&&0<i&&!(i&i-1)){for(o=0,i>>=1;i;i>>=1)o++;if((i=Math.round(32*r/(1<<o)))<256)return[208+b(t),16,0,1,r,o,i,0,0,0,0,0,0,0,0,0]}throw RangeError("Wrong time signature "+n+(void 0===e?"":"/"+e))}},Tn={umpMetadata:function(t,n){return P.umpCustomText(t,0,1,1,0,n)},umpProjectName:function(t,n){return P.umpCustomText(t,0,1,1,1,n)},umpCompositionName:function(t,n){return P.umpCustomText(t,0,1,1,2,n)},umpClipName:function(t,n){return P.umpCustomText(t,0,1,1,3,n)},umpCopyright:function(t,n){return P.umpCustomText(t,0,1,1,4,n)},umpComposerName:function(t,n){return P.umpCustomText(t,0,1,1,5,n)},umpLyricistName:function(t,n){return P.umpCustomText(t,0,1,1,6,n)},umpArrangerName:function(t,n){return P.umpCustomText(t,0,1,1,7,n)},umpPublisherName:function(t,n){return P.umpCustomText(t,0,1,1,8,n)},umpPerformerName:function(t,n){return P.umpCustomText(t,0,1,1,9,n)},umpAccPerformerName:function(t,n){return P.umpCustomText(t,0,1,1,10,n)},umpRecordingDate:function(t,n){return P.umpCustomText(t,0,1,1,11,n)},umpRecordingLocation:function(t,n){return P.umpCustomText(t,0,1,1,12,n)},umpText:function(t,n){return P.umpCustomText(t,0,1,2,0,n)},umpLyrics:function(t,n){return P.umpCustomText(t,0,1,2,1,n)},umpLyricsLanguage:function(t,n){return P.umpCustomText(t,0,1,2,2,n)},umpRuby:function(t,n){return P.umpCustomText(t,0,1,2,3,n)},umpRubyLanguage:function(t,n){return P.umpCustomText(t,0,1,2,4,n)}},wn={umpNoteOn:function(t,n,e,r,i,o){return i=i||0,o=o||0,r=Wt(r=void 0===r?65535:r),o=Wt(o),[64+b(t),144+y(n),M(e),Ut(i),r>>8,255&r,o>>8,255&o]},umpNoteOff:function(t,n,e,r,i,o){return i=i||0,o=o||0,r=Wt(r=r||0),o=Wt(o),[64+b(t),128+y(n),M(e),Ut(i),r>>8,255&r,o>>8,255&o]},umpProgram:function(t,n,e,r,i){return void 0===r&&void 0===i?[64+b(t),192+y(n),0,0,M(e),0,0,0]:[64+b(t),192+y(n),0,1,M(e),0,M(r),M(i)]}},P={umpCustomText:function(t,n,e,r,i,o){var s,u=[];for(o=g.lib.toUTF8(""+o),s=0;s<o.length;s++)u.push(o.charCodeAt(s));for(u=An(u,12),s=0;s<u.length;s++)u[s]=[208+b(t),64*In(u.length,s)+(e?16:0)+y(n),r,i].concat(u[s],Mn).slice(0,16);return u},umpCMetadata:function(t,n,e){return P.umpCustomText(t,n,0,1,0,e)},umpCProjectName:function(t,n,e){return P.umpCustomText(t,n,0,1,1,e)},umpCCompositionName:function(t,n,e){return P.umpCustomText(t,n,0,1,2,e)},umpCClipName:function(t,n,e){return P.umpCustomText(t,n,0,1,3,e)},umpCCopyright:function(t,n,e){return P.umpCustomText(t,n,0,1,4,e)},umpCComposerName:function(t,n,e){return P.umpCustomText(t,n,0,1,5,e)},umpCLyricistName:function(t,n,e){return P.umpCustomText(t,n,0,1,6,e)},umpCArrangerName:function(t,n,e){return P.umpCustomText(t,n,0,1,7,e)},umpCPublisherName:function(t,n,e){return P.umpCustomText(t,n,0,1,8,e)},umpCPerformerName:function(t,n,e){return P.umpCustomText(t,n,0,1,9,e)},umpCAccPerformerName:function(t,n,e){return P.umpCustomText(t,n,0,1,10,e)},umpCRecordingDate:function(t,n,e){return P.umpCustomText(t,n,0,1,11,e)},umpCRecordingLocation:function(t,n,e){return P.umpCustomText(t,n,0,1,12,e)},umpCText:function(t,n,e){return P.umpCustomText(t,n,0,2,0,e)},umpCLyrics:function(t,n,e){return P.umpCustomText(t,n,0,2,1,e)},umpCLyricsLanguage:function(t,n,e){return P.umpCustomText(t,n,0,2,2,e)},umpCRuby:function(t,n,e){return P.umpCustomText(t,n,0,2,3,e)},umpCRubyLanguage:function(t,n,e){return P.umpCustomText(t,n,0,2,4,e)}},O={};function In(t,n){return 1==t?0:0==n?1:n==t-1?3:2}function An(t,n){for(var e=[],r=t;r.length;r=r.slice(n))e.push(r.slice(0,n));return e.length?e:[[]]}function Bn(t,n){for(var e=An(n.slice(1,n.length-1),6),r=0;r<e.length;r++)e[r]=new E([48+t,16*In(e.length,r)+e[r].length].concat(e[r],Mn).slice(0,8));return e}function En(t,n){E[t]=function(){var t=Array.prototype.slice.call(arguments);return void 0!==this._gr&&(t=[this._gr].concat(t)),new E([32+b((t=void 0!==this._ch?[t[0]].concat([this._ch]).concat(t.slice(1)):t)[0])].concat(n.apply(this,t.slice(1)),Mn).slice(0,4))},O[t]=function(){var t=Array.prototype.slice.call(arguments);return void 0!==this._gr&&(t=[this._gr].concat(t)),void 0!==this._ch&&(t=[t[0]].concat([this._ch]).concat(t.slice(1))),this.send([32+b(t[0])].concat(n.apply(this,t.slice(1)),Mn).slice(0,4))}}function Pn(n){u(O,function(t){n.prototype[t]=O[t]})}u(xn,function(t){var n;n=xn[t=t],E[t]=function(){return new E(n.apply(this,arguments))},O[t]=function(){return this.send(n.apply(this,arguments))}}),u(Sn,function(t){var n;n=Sn[t=t],E[t]=function(){var t=Array.prototype.slice.call(arguments);return void 0!==this._gr&&(t=[this._gr].concat(t)),new E(n.apply(this,t))},O[t]=function(){var t=Array.prototype.slice.call(arguments);return void 0!==this._gr&&(t=[this._gr].concat(t)),this.send(n.apply(this,t))}}),u(Tn,function(t){var r;r=Tn[t=t],E[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),r.apply(this,t)),e=0;e<n.length;e++)n[e]=new E(n[e]);return n},O[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),r.apply(this,t)),e=0;e<n.length;e++)this.send(n[e]);return this}}),u(wn,function(t){var n;n=wn[t=t],E[t]=function(){var t=Array.prototype.slice.call(arguments);return void 0!==this._gr&&(t=[this._gr].concat(t)),void 0!==this._ch&&(t=[t[0]].concat([this._ch]).concat(t.slice(1))),new E(n.apply(this,t))},O[t]=function(){var t=Array.prototype.slice.call(arguments);return void 0!==this._gr&&(t=[this._gr].concat(t)),void 0!==this._ch&&(t=[t[0]].concat([this._ch]).concat(t.slice(1))),this.send(n.apply(this,t))}}),u(P,function(t){var r;r=P[t=t],E[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),void 0!==this._ch&&(t=[t[0]].concat([this._ch]).concat(t.slice(1))),r.apply(this,t)),e=0;e<n.length;e++)n[e]=new E(n[e]);return n},O[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),void 0!==this._ch&&(t=[t[0]].concat([this._ch]).concat(t.slice(1))),r.apply(this,t)),e=0;e<n.length;e++)this.send(n[e]);return this}}),u(nn,function(t){var n;n=nn[t=t],E[t]=function(){var t=Array.prototype.slice.call(arguments);return new E([16+b((t=void 0!==this._gr?[this._gr].concat(t):t)[0])].concat(n.apply(this,t.slice(1)),Mn).slice(0,4))},O[t]=function(){var t=Array.prototype.slice.call(arguments);return void 0!==this._gr&&(t=[this._gr].concat(t)),this.send([16+b(t[0])].concat(n.apply(this,t.slice(1)),Mn).slice(0,4))}}),u(Yt,function(t){En(t,Yt[t])}),u(T,function(t){En(t,T[t])}),u(I,function(t){var i;i=I[t=t],E[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),void 0!==this._ch&&(t=[t[0]].concat([this._ch]).concat(t.slice(1))),i.apply(this,t.slice(1))),e=0;e<n.length;e++)n[e]=new E([32+b(t[0])].concat(n[e],Mn).slice(0,4));return n},O[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),void 0!==this._ch&&(t=[t[0]].concat([this._ch]).concat(t.slice(1))),i.apply(this,t.slice(1))),e=this,r=0;r<n.length;r++)e=e.send([32+b(t[0])].concat(n[r],Mn).slice(0,4));return e}}),u(w,function(t){var i;i=w[t=t],E[t]=function(){var t=Array.prototype.slice.call(arguments);return Bn(b((t=void 0!==this._gr?[this._gr].concat(t):t)[0]),i.apply(this,t.slice(1)))},O[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=Bn(b((t=void 0!==this._gr?[this._gr].concat(t):t)[0]),i.apply(this,t.slice(1))),e=this,r=0;r<n.length;r++)e=e.send(n[r]);return e}}),u(en,function(t){var s;s=en[t=t],E[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),s.apply(this,t.slice(1))),e=[],r=0;r<n.length;r++)e=e.concat(Bn(b(t[0]),n[r]));return e},O[t]=function(){for(var t=Array.prototype.slice.call(arguments),n=(void 0!==this._gr&&(t=[this._gr].concat(t)),s.apply(this,t.slice(1))),e=this,r=0;r<n.length;r++)for(var i=Bn(b(t[0]),n[r]),o=0;o<i.length;o++)e=e.send(i[o]);return e}}),Pn(l),E.prototype.getTempo=function(){if(this.isTempo())return(this[4]<<24)+(this[5]<<16)+(this[6]<<8)+this[7]},E.prototype.getBPM=function(){var t=this.getTempo();if(t)return Math.round(6e9/t)},E.prototype.getTimeSignature=function(){if(this.isTimeSignature())return[this[4],1<<this[5]]},E.prototype.getTicksPQN=function(){if(this.isTicksPQN())return(this[2]<<8)+this[3]},E.prototype.getDelta=function(){if(this.isDelta())return((15&this[1])<<16)+(this[2]<<8)+this[3]},E.prototype.isTempo=function(){return this[0]>>4==13&&this[1]>>4==1&&0==this[2]&&0==this[3]},E.prototype.isTimeSignature=function(){return this[0]>>4==13&&this[1]>>4==1&&0==this[2]&&1==this[3]},E.prototype.isTicksPQN=function(){return 0==this[0]&&this[1]>>4==3},E.prototype.isDelta=function(){return 0==this[0]&&this[1]>>4==4},E.prototype.isStartClip=function(){return this.match([240,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},E.prototype.isEndClip=function(){return this.match([240,33,0,0,0,0,0,0,0,0,0,0,0,0,0,0])},E.prototype.isNoteOn=function(){var t=(this[0]||0)>>4,n=(this[1]||0)>>4;return 4==t?9==n:2==t&&(9==n&&!!this[3])},E.prototype.isNoteOff=function(){var t=(this[0]||0)>>4,n=(this[1]||0)>>4;return 4==t?8==n:2==t&&(8==n||9==n&&!this[3])},E.prototype.toString=_.prototype.toString,E.prototype._str=function(){var t=this._string();return t?dn(this)+" -- "+t:dn(this)},E.prototype._string=function(){var t,n,e=this[0]>>4;return 1==e||2==e?new _(this.slice(1))._string():(0==e?n=["NOOP","JR Clock","JR Timestamp","Ticks Per Quarter Note","Delta Ticks"][t=this[1]>>4]:3==e?n="SysEx":4==e?n={0:"Registered Per-Note Controller",1:"Assignable Per-Note Controller",2:"Registered Controller",3:"Assignable Controller",4:"Relative Registered Controller",5:"Relative Assignable Controller",6:"Per-Note Pitch Bend",8:"Note Off",9:"Note On",10:"Poly Pressure",11:"Control Change",12:"Program Change",13:"Channel Pressure",14:"Pitch Bend",15:"Per-Note Management"}[t=this[1]>>4]:5==e?n="Data":13==e&&(0==(t=this[2])?(n={0:"Tempo ",1:"Time Signature ",2:"Metronome",5:"Key Signature",6:"Chord Name"}[t=this[3]],0==t?n+=this.getBPM()+" BPM":1==t&&(n+=this.getTimeSignature().join("/"))):1==t?n={0:"Metadata",1:"Project Name",2:"Composition Name",3:"Clip Name",4:"Copyright",5:"Composer Name",6:"Lyricist Name",7:"Arranger Name",8:"Publisher Name",9:"Primary Performer Name",10:"Accompanying Performer Name",11:"Recording Date",12:"Recording Location"}[t=this[3]]||"Unknown Text":2==t&&(n={0:"Text",1:"Lyrics",2:"Lyrics Language",3:"Ruby",4:"Ruby Language"}[t=this[3]]||"Unknown Text")),15==e?{32:"Start of Clip",33:"End of Clip"}[this[1]]:n)},E.prototype._stamp=_.prototype._stamp,E.prototype._unstamp=_.prototype._unstamp,E.prototype._stamped=_.prototype._stamped,E.prototype.match=_.prototype.match,g.UMP=E,g.MIDI2=r.prototype.UMP=E,r.prototype.MIDI2=E,g.lib={},g.lib.now=j,g.lib.schedule=z;var On,F,Fn=[],Nn=0;try{function kn(){for(var t=Fn.length,n=0;n<t;n++)Fn.shift()();20<++Nn&&On&&(On.terminate(),On=void 0)}function Rn(t){Fn.push(t),Nn=0,On||((On=new Worker(Ln)).onmessage=kn)}var Ln=URL.createObjectURL(new Blob(["(",function(){!function t(){postMessage({}),setTimeout(t,0)}()}.toString(),")()"],{type:"application/javascript"}));Rn(function(){g.lib.schedule=Rn})}catch(t){}g.lib.openMidiOut=function(t,n){var e=new p;return n._openOut(e),e._info=n._info(t),e},g.lib.openMidiIn=function(t,n){var e=new p;return n._openIn(e),e._info=n._info(t),e},g.lib.registerMidiOut=function(t,n){for(var e=n._info(t),r=0;r<xt._outs.length;r++)if(xt._outs[r].name==e.name)return!1;return e.engine=n,xt._outs.push(e),f&&(it(),f._bad&&(f._repair(),f._resume())),!0},g.lib.registerMidiIn=function(t,n){for(var e=n._info(t),r=0;r<xt._ins.length;r++)if(xt._ins[r].name==e.name)return!1;return e.engine=n,xt._ins.push(e),f&&(it(),f._bad&&(f._repair(),f._resume())),!0},g.lib.copyMidiHelpers=un,g.lib.copyMidi2Helpers=Pn,g.lib.copyUmpHelpers=Pn,g.lib.getAudioContext=function(){var t,e;return F||"undefined"==typeof window||(t=window.AudioContext||window.webkitAudioContext)&&((F=new t)&&!F.createGain&&(F.createGain=F.createGainNode),e=function(){if("running"!=F.state){F.resume();var t=F.createOscillator(),n=F.createGain();try{n.gain.value=0}catch(t){}n.gain.setTargetAtTime(0,F.currentTime,.01),t.connect(n),n.connect(F.destination),t.start||(t.start=t.noteOn),t.stop||(t.stop=t.noteOff),t.start(.1),t.stop(.11)}else"undefined"!=typeof document&&(document.removeEventListener("touchstart",e),document.removeEventListener("touchend",e),document.removeEventListener("mousedown",e),document.removeEventListener("keydown",e))},"undefined"!=typeof document&&(document.addEventListener("touchstart",e),document.addEventListener("touchend",e),document.addEventListener("mousedown",e),document.addEventListener("keydown",e)),e()),F};var Dn="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",N=(g.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;)r=Dn.indexOf(t.charAt(a++)),n=(15&(i=Dn.indexOf(t.charAt(a++))))<<4|(o=Dn.indexOf(t.charAt(a++)))>>2,e=(3&o)<<6|(s=Dn.indexOf(t.charAt(a++))),u+=String.fromCharCode(r<<2|i>>4),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(e));return u},g.lib.toBase64=function(t){var n,e,r,i,o=0,s=0,u="",a=[];if(!t)return t;for(;n=(i=t.charCodeAt(o++)<<16|t.charCodeAt(o++)<<8|t.charCodeAt(o++))>>12&63,e=i>>6&63,r=63&i,a[s++]=Dn.charAt(i>>18&63)+Dn.charAt(n)+Dn.charAt(e)+Dn.charAt(r),o<t.length;);var u=a.join(""),c=t.length%3;return c?u.slice(0,c-3)+"===".slice(c):u},g.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=(r+=String.fromCharCode(55296+(n>>10)))+String.fromCharCode(56320+(1023&n))}}return r},g.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]:e=n<2048?(e+=String.fromCharCode(192+(n>>6)))+String.fromCharCode(128+(63&n)):n<65536?(e=(e+=String.fromCharCode(224+(n>>12)))+String.fromCharCode(128+(n>>6&63)))+String.fromCharCode(128+(63&n)):(e=(e=(e+=String.fromCharCode(240+(n>>18)))+String.fromCharCode(128+(n>>12&63)))+String.fromCharCode(128+(n>>6&63)))+String.fromCharCode(128+(63&n));return e},[]),k={},R={},qn=t.Promise;function Gn(t,n,e){this.name=t,this.message=n,this.code=e}function jn(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=j(),this.type="statechange"}function zn(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=j(),this.returnValue=!0,this.srcElement=t,this.target=t,this.timeStamp=this.receivedTime,this.type="midimessage"}function Un(t,n){t&&(t.onstatechange&&t.onstatechange(new jn(t,t)),n.onstatechange&&n.onstatechange(new jn(t,n)))}function Vn(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){a(t)?(s=t,o||i.open().then(U,U)):s=null},enumerable:!0}),Object.defineProperty(this,"onstatechange",{get:function(){return n},set:function(t){n=a(t)?t:null},enumerable:!0}),this.open=function(){return new qn(function(t,n){o?t(i):r.open().then(function(){o||(o=!0,Un(i,e)),t(i)},function(){n(new Gn("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new qn(function(t){o&&(o=!1,r.close(),Un(i,e)),t(i)})},Object.freeze(this)}function Wn(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++);return n==t.length?void 0:t.splice(0,n+1)}if((e=Jn(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 Zn(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=Wn(i.queue);n;n=Wn(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 zn(i,new Uint8Array(n)))}}function Jn(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 qn&&((qn=function(t){this.executor=t}).prototype.then=function(t,n){this.executor(t="function"!=typeof t?U:t,n="function"!=typeof n?U:n)}),Zn.prototype.open=function(){var r=this;return new qn(function(t,n){var e;r.proxy||!r.connected?t():(r.pending.push([t,n]),1==r.pending.length&&g().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=[]}))})},Zn.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}},Zn.prototype.disconnect=function(){this.connected=!1,this.proxy&&(this.proxy.close(),this.proxy=void 0)},Zn.prototype.reconnect=function(){var t,n,e=this,r=[];for(this.connected=!0,t=0;t<N.length;t++)"closed"==(n=N[t].inputs.get(this.id)).connection?Un(n,N[t]):r.push([n,N[t]]);r.length&&g()._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++)Un(r[t][0],r[t][1])})};var Xn="Failed to execute 'send' on 'MIDIOutput': ";function Hn(c,h){var f=this,p=!1,n=null;this.type="output",this.id=h.id,this.name=h.name,this.manufacturer=h.man,this.version=h.ver,Object.defineProperty(this,"state",{get:function(){return h.connected?"connected":"disconnected"},enumerable:!0}),Object.defineProperty(this,"connection",{get:function(){return p?h.proxy?"open":"pending":"closed"},enumerable:!0}),Object.defineProperty(this,"onstatechange",{get:function(){return n},set:function(t){n=a(t)?t:null},enumerable:!0}),this.open=function(){return new qn(function(t,n){p?t(f):h.open().then(function(){p||(p=!0,Un(f,c)),t(f)},function(){n(new Gn("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new qn(function(t){p&&(p=!1,f.clear(),h.close(),Un(f,c)),t(f)})},this.clear=function(){},this.send=function(t,n){for(var e,r,i,o=t,s=c.sysexEnabled,u=[],a=0;a<o.length;a++)if(o[a]!=parseInt(o[a])||o[a]<0||255<o[a])throw TypeError(Xn+o[a]+" is not a UInt8 value.");for(a=e=0;a<o.length;a++)if(e){if(127<o[a])throw TypeError(Xn+"Unexpected status byte at index "+a+" ("+o[a]+").");r.push(o[a]),e--}else{if(o[a]<128)throw TypeError(Xn+"Running status is not allowed at index "+a+" ("+o[a]+").");if(247==o[a])throw TypeError(Xn+"Unexpected end of system exclusive message at index "+a+" ("+o[a]+").");if(r=[o[a]],u.push(r),240==o[a]){if(!s)throw new Gn("InvalidAccessError",Xn+"System exclusive messag is not allowed at index "+a+" ("+o[a]+").",15);for(e=-1;a<o.length;a++)if(r.push(o[a]),247==o[a]){e=0;break}}else e=Jn(o[a])}if(e)throw TypeError(Xn+"Message is incomplete");if(!h.connected)throw new Gn("InvalidStateError","Port is not connected",11);p?(i=j())<n?setTimeout(function(){h.proxy.send(t)},n-i):h.proxy.send(t):this.open().then(function(){f.send(t,n)},U)},Object.freeze(this)}function Qn(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 Kn(r){this.has=function(t){return r.hasOwnProperty(t)&&r[t].connected},this.keys=function(){try{var t,n=new Map;for(t in r)this.has(t)&&n.set(t,this.get(t));return n.keys()}catch(t){}},this.values=function(){try{var t,n=new Map;for(t in r)this.has(t)&&n.set(t,this.get(t));return n.values()}catch(t){}},this.entries=function(){try{var t,n=new Map;for(t in r)this.has(t)&&n.set(t,this.get(t));return n.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,n=0;for(t in r)this.has(t)&&n++;return n},enumerable:!0})}function Yn(n,e){this.get=function(t){if(R.hasOwnProperty(t)&&R[t].connected)return e[t]||(e[t]=new Vn(n,R[t]),R[t].ports.push([e[t],n.sysexEnabled])),e[t]},Object.freeze(this)}function $n(n,e){this.get=function(t){if(k.hasOwnProperty(t)&&k[t].connected)return e[t]||(e[t]=new Hn(n,k[t]),k[t].ports.push([e[t],n.sysexEnabled])),e[t]},Object.freeze(this)}function te(t){for(var n,e,r,i=0;i<t.inputs.added.length;i++)e=t.inputs.added[i],R.hasOwnProperty(e.id)||(R[e.id]=new Zn(e.id,e.name,e.manufacturer,e.version)),R[e.id].reconnect();for(i=0;i<t.outputs.added.length;i++)e=t.outputs.added[i],k.hasOwnProperty(e.id)||(k[e.id]=new Qn(e.id,e.name,e.manufacturer,e.version)),k[e.id].reconnect();for(i=0;i<t.inputs.removed.length;i++)if(e=t.inputs.removed[i],R.hasOwnProperty(e.id)){for(r=[],n=0;n<N.length;n++)r.push([N[n].inputs.get(e.id),N[n]]);for(R[e.id].disconnect(),n=0;n<r.length;n++)Un(r[n][0],r[n][1])}for(i=0;i<t.outputs.removed.length;i++)if(e=t.outputs.removed[i],k.hasOwnProperty(e.id)){for(r=[],n=0;n<N.length;n++)r.push([N[n].outputs.get(e.id),N[n]]);for(k[e.id].disconnect(),n=0;n<r.length;n++)Un(r[n][0],r[n][1])}}function ne(t){for(var n,e=null,r=(this.sysexEnabled=t,this.inputs=new Yn(this,{}),this.outputs=new $n(this,{}),Object.defineProperty(this,"onstatechange",{get:function(){return e},set:function(t){e=a(t)?t:null},enumerable:!0}),Object.freeze(this),f._info),i=0;i<r.inputs.length;i++)n=r.inputs[i],R.hasOwnProperty(n.id)||(R[n.id]=new Zn(n.id,n.name,n.manufacturer,n.version));for(i=0;i<r.outputs.length;i++)n=r.outputs[i],k.hasOwnProperty(n.id)||(k[n.id]=new Qn(n.id,n.name,n.manufacturer,n.version));N.length||g().onChange(te),N.push(this)}return Qn.prototype.open=function(){var r=this;return new qn(function(t,n){var e;r.proxy||!r.connected?t():(r.pending.push([t,n]),1==r.pending.length&&g().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=[]}))})},Qn.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}},Qn.prototype.disconnect=function(){this.connected=!1,this.proxy&&(this.proxy.close(),this.proxy=void 0)},Qn.prototype.reconnect=function(){var t,n,e=this,r=[];for(this.connected=!0,t=0;t<N.length;t++)"closed"==(n=N[t].outputs.get(this.id)).connection?Un(n,N[t]):r.push([n,N[t]]);r.length&&g()._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++)Un(r[t][0],r[t][1])})},(Yn.prototype=new Kn(R)).constructor=Yn,($n.prototype=new Kn(k)).constructor=$n,g.requestMIDIAccess=function(r){return new qn(function(n,e){g.JZZ(r).or(function(){}).and(function(){var t=!(!r||!r.sysex);t&&!this.info().sysex?e(new Gn("SecurityError","Sysex is not allowed",18)):(t=new ne(t),n(t))})})},"undefined"==typeof navigator||navigator.requestMIDIAccess||(navigator.requestMIDIAccess=g.requestMIDIAccess),g.close=function(){d._close&&d._close()},g});