diff --git a/.eslintrc.js b/.eslintrc.js index d2cc01f..90b4f48 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,7 +26,8 @@ module.exports = { }, "rules": { "no-console" : "off", - "no-empty" : ["warn", { "allowEmptyCatch": true }] + "no-empty" : ["warn", { "allowEmptyCatch": true }], + "no-prototype-builtins" : "off" } } ] diff --git a/README.md b/README.md index 8f3b4a4..fe77cc8 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ by running `npm remove midi-test --save-dev`. ##### CDN // the latest version, or - // any particular version + // any particular version //... ##### CommonJS (Browserify and Node.js command line applications) diff --git a/javascript/JZZ.js b/javascript/JZZ.js index a6027d3..ab10940 100644 --- a/javascript/JZZ.js +++ b/javascript/JZZ.js @@ -13,7 +13,7 @@ })(this, function() { var _scope = typeof window === 'undefined' ? global : window; - var _version = '0.8.2'; + var _version = '0.8.3'; var i, j, k, m, n; var _time = Date.now || function () { return new Date().getTime(); }; diff --git a/minified/JZZ.js b/minified/JZZ.js index bc228c9..6a6884f 100644 --- a/minified/JZZ.js +++ b/minified/JZZ.js @@ -1 +1 @@ -!function(t,e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define("JZZ",[],e);else{if(t||(t=window),t.JZZ&&t.JZZ.MIDI)return;t.JZZ=e()}}(this,function(){var e,u,n,t,i,r="undefined"==typeof window?global:window,o="0.8.2",s=Date.now||function(){return(new Date).getTime()},a=s(),h="undefined"!=typeof performance&&performance.now?function(){return performance.now()}:function(){return s()-a};function f(){(this._orig=this)._ready=!1,this._queue=[],this._err=[]}function c(t,e){setTimeout(function(){t._resume()},e)}function p(t){t._resume()}function l(t,n,r){t[r]=function(){var t=arguments,e=n._image();return this._push(p,[e]),e[r].apply(e,t)}}function d(t){t instanceof Function?t.apply(this):console.log(t)}function _(t){t instanceof Function?t.apply(this):console.log(t)}function m(t){this._break("closed"),t._resume()}function g(t){if(t.length){var e=t.shift();if(t.length){var n=this;this._slip(_,[function(){g.apply(n,[t])}])}try{this._repair(),e.apply(this)}catch(t){this._break(t.toString())}}else this._break()}function v(t,e){for(var n=0;n>1&3],(1&t[7])<<4|t[6],t[5]<<4|t[4],t[3]<<4|t[2],t[1]<<4|t[0]]}function ut(t){for(var e,n=[],r=0;r=this.type&&(this.frame=29.97==this.type?29:this.type-1),this},it.prototype.setHour=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||24<=t)throw RangeError("Bad SMPTE hours value: "+t);return this.hour=t,this},it.prototype.setMinute=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE minutes value: "+t);return this.minute=t,ot.apply(this),this},it.prototype.setSecond=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE seconds value: "+t);return this.second=t,ot.apply(this),this},it.prototype.setFrame=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||t>=this.type)throw RangeError("Bad SMPTE frame number: "+t);return this.frame=t,ot.apply(this),this},it.prototype.setQuarter=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||8<=t)throw RangeError("Bad SMPTE quarter frame: "+t);return this.quarter=t,this},it.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))),ot.apply(this),this},it.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},it.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},it.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},it.prototype.read=function(t){if(t instanceof at||(t=at.apply(null,arguments)),240==t[0]&&127==t[1]&&1==t[3]&&1==t[4]&&247==t[9])return this.type=[24,25,29.97,30][t[5]>>5&3],this.hour=31&t[5],this.minute=t[6],this.second=t[7],this.frame=t[8],this.quarter=0,this._=void 0,this._b=void 0,!(this._f=void 0);if(241!=t[0]||void 0===t[1])return!1;var e=t[1]>>4,n=15&t[1];return 0==e?7==this._&&(7==this._f&&(this.reset(st(this._a)),this.incrFrame()),this.incrFrame()):3==e?4==this._&&this.decrFrame():4==e?3==this._&&this.incrFrame():7==e&&0===this._&&(0===this._b&&(this.reset(st(this._a)),this.decrFrame()),this.decrFrame()),this._a||(this._a=[]),this._a[e]=n,this._f=this._f===e-1||0==e?e:void 0,this._b=this._b===1+e||7==e?e:void 0,this._=e,this.quarter=e,!0},it.prototype.toString=function(){return ut([this.hour,this.minute,this.second,this.frame])},rt.SMPTE=it;var ht={};((at.prototype=[]).constructor=at).noteValue=function(t){return void 0===t?void 0:ht[t.toString().toLowerCase()]},at.programValue=function(t){return t},at.freq=function(t,e){return void 0===e&&(e=440),e*Math.pow(2,(lt(at.noteValue(t),t)-69)/12)};var ft={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(n in ft)if(ft.hasOwnProperty(n))for(i=0;i<12&&!(127<(t=ft[n]+12*i));i++)0<(ht[n+i]=t)&&(ht[n+"b"+i]=t-1,ht[n+"bb"+i]=t-2),t<127&&(ht[n+"#"+i]=t+1,ht[n+"##"+i]=t+2);for(i=0;i<128;i++)ht[i]=i;function ct(t){throw RangeError("Bad MIDI value: "+t)}function pt(t){return(t!=parseInt(t)||t<0||15>7}var gt={noteOff:function(t,e,n){return void 0===n&&(n=64),[128+pt(t),lt(at.noteValue(e),e),lt(n)]},noteOn:function(t,e,n){return void 0===n&&(n=127),[144+pt(t),lt(at.noteValue(e),e),lt(n)]},aftertouch:function(t,e,n){return[160+pt(t),lt(at.noteValue(e),e),lt(n)]},control:function(t,e,n){return[176+pt(t),lt(e),lt(n)]},program:function(t,e){return[192+pt(t),lt(at.programValue(e),e)]},pressure:function(t,e){return[208+pt(t),lt(e)]},pitchBend:function(t,e){return[224+pt(t),_t(e),mt(e)]},bankMSB:function(t,e){return[176+pt(t),0,lt(e)]},bankLSB:function(t,e){return[176+pt(t),32,lt(e)]},modMSB:function(t,e){return[176+pt(t),1,lt(e)]},modLSB:function(t,e){return[176+pt(t),33,lt(e)]},breathMSB:function(t,e){return[176+pt(t),2,lt(e)]},breathLSB:function(t,e){return[176+pt(t),34,lt(e)]},footMSB:function(t,e){return[176+pt(t),4,lt(e)]},footLSB:function(t,e){return[176+pt(t),36,lt(e)]},portamentoMSB:function(t,e){return[176+pt(t),5,lt(e)]},portamentoLSB:function(t,e){return[176+pt(t),37,lt(e)]},volumeMSB:function(t,e){return[176+pt(t),7,lt(e)]},volumeLSB:function(t,e){return[176+pt(t),39,lt(e)]},balanceMSB:function(t,e){return[176+pt(t),8,lt(e)]},balanceLSB:function(t,e){return[176+pt(t),40,lt(e)]},panMSB:function(t,e){return[176+pt(t),10,lt(e)]},panLSB:function(t,e){return[176+pt(t),42,lt(e)]},expressionMSB:function(t,e){return[176+pt(t),11,lt(e)]},expressionLSB:function(t,e){return[176+pt(t),43,lt(e)]},damper:function(t,e){return[176+pt(t),64,e?127:0]},portamento:function(t,e){return[176+pt(t),65,e?127:0]},sostenuto:function(t,e){return[176+pt(t),66,e?127:0]},soft:function(t,e){return[176+pt(t),67,e?127:0]},allSoundOff:function(t){return[176+pt(t),120,0]},allNotesOff:function(t){return[176+pt(t),123,0]}},vt={mtc:function(t){return[241,function(t){var e;switch(!t.backwards&&4<=t.quarter?t.decrFrame():t.backwards&&t.quarter<4&&t.incrFrame(),t.quarter>>1){case 0:e=t.frame;break;case 1:e=t.second;break;case 2:e=t.minute;break;default:e=t.hour}return 1&t.quarter?e>>=4:e&=15,7==t.quarter&&(25==t.type?e|=2:29.97==t.type?e|=4:30==t.type&&(e|=6)),!t.backwards&&4<=t.quarter?t.incrFrame():t.backwards&&t.quarter<4&&t.decrFrame(),e|t.quarter<<4}(t)]},songPosition:function(t){return[242,_t(t),mt(t)]},songSelect:function(t){return[243,lt(t)]},tune:function(){return[246]},clock:function(){return[248]},start:function(){return[250]},continue:function(){return[251]},stop:function(){return[252]},active:function(){return[254]},sxIdRequest:function(){return[240,126,127,6,1,247]},sxFullFrame:function(t){return[240,127,127,1,1,function(t){return 25==t.type?32|t.hour:29.97==t.type?64|t.hour:30==t.type?96|t.hour:t.hour}(t),t.getMinute(),t.getSecond(),t.getFrame(),247]},reset:function(){return[255]}};function yt(t,e){var n=new at;return n.ff=dt(t),n.dd=void 0===e?"":function(t){t=""+t;for(var e=0;e>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>16)+String.fromCharCode(t>>8&255)+String.fromCharCode(255&t));throw RangeError("Out of range: "+qt(Pt(t)))},smfBPM:function(t){return Ct.smfTempo(Math.round(6e7/t))},smfSMPTE:function(t){if(t instanceof it)return yt(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 yt(84,t);var e=t instanceof Array?t:Array.prototype.slice.call(arguments);return e.splice(0,0,30),Ct.smfSMPTE(new it(e))},smfTimeSignature:function(t,e,n,r){var i,o,s,u,a=(""+t).match(/^\s*(\d+)\s*\/\s*(\d+)\s*$/);if(a){if(i=parseInt(a[1]),o=parseInt(a[2]),0>=1;s;s>>=1)o++;return s=e==parseInt(e)?e:24,u=n==parseInt(n)?n:8,yt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return yt(88,t)}else{if(!(t!=parseInt(t)||e!=parseInt(e)||e&e-1)){for(i=t,o=0,s=e,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=r==parseInt(r)?r:8,yt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return yt(88,t)}throw RangeError("Wrong time signature: "+qt(Pt(t)))},smfKeySignature:function(t){var e=(t=""+t).match(/^\s*([A-H][b#]?)\s*(|maj|major|dur|m|min|minor|moll)\s*$/i);if(e){var 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()],r={"":0,MAJ:0,MAJOR:0,DUR:0,M:1,MIN:1,MINOR:1,MOLL:1}[e[2].toUpperCase()];void 0!==n&&void 0!==r&&(r&&(n-=3),-7<=(n-=7)&&n<0?t=String.fromCharCode(256+n)+String.fromCharCode(r):0<=n&&n<=7&&(t=String.fromCharCode(n)+String.fromCharCode(r)))}if(2==t.length&&t.charCodeAt(1)<=1&&(t.charCodeAt(0)<=7||t.charCodeAt(0)<=255&&249<=t.charCodeAt(0)))return yt(89,t);throw RangeError("Incorrect key signature: "+qt(t))},smfSequencer:function(t){return yt(127,Pt(t))}};function St(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,arguments)),this}}function wt(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,[this._chan].concat(Array.prototype.slice.call(arguments)))),this}}function bt(t,e){at[t]=function(){return new at(e.apply(0,arguments))}}function Mt(t,e){at[t]=function(){return e.apply(0,arguments)}}function At(t,r){bt(t,r),N.prototype[t]=function(){var t,e=Array.prototype.slice.call(arguments);e.length>4;return(e={8:"Note Off",10:"Aftertouch",12:"Program Change",13:"Channel Aftertouch",14:"Pitch Wheel"}[s])?t+" -- "+e:9==s?t+" -- "+(this[2]?"Note On":"Note Off"):11!=s?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",32:"Bank Select LSB",33:"Modulation Wheel LSB",34:"Breath Controller LSB",36:"Foot Controller LSB",37:"Portamento Time LSB",38:"Data Entry LSB",39:"Channel Volume LSB",40:"Balance LSB",42:"Pan LSB",43:"Expression Controller LSB",44:"Effect control 1 LSB",45:"Effect control 2 LSB",48:"General Purpose Controller 1 LSB",49:"General Purpose Controller 2 LSB",50:"General Purpose Controller 3 LSB",51:"General Purpose Controller 4 LSB",64:"Damper Pedal On/Off",65:"Portamento On/Off",66:"Sostenuto On/Off",67:"Soft Pedal On/Off",68:"Legato Footswitch",69:"Hold 2",70:"Sound Controller 1",71:"Sound Controller 2",72:"Sound Controller 3",73:"Sound Controller 4",74:"Sound Controller 5",75:"Sound Controller 6",76:"Sound Controller 7",77:"Sound Controller 8",78:"Sound Controller 9",79:"Sound Controller 10",80:"General Purpose Controller 5",81:"General Purpose Controller 6",82:"General Purpose Controller 7",83:"General Purpose Controller 8",84:"Portamento Control",88:"High Resolution Velocity Prefix",91:"Effects 1 Depth",92:"Effects 2 Depth",93:"Effects 3 Depth",94:"Effects 4 Depth",95:"Effects 5 Depth",96:"Data Increment",97:"Data Decrement",98:"Non-Registered Parameter Number LSB",99:"Non-Registered Parameter Number MSB",100:"Registered Parameter Number LSB",101:"Registered Parameter Number MSB",120:"All Sound Off",121:"Reset All Controllers",122:"Local Control On/Off",123:"All Notes Off",124:"Omni Mode Off",125:"Omni Mode On",126:"Mono Mode On",127:"Poly Mode On"}[this[1]])||(e="Undefined"),t+" -- "+e)},at.prototype._stamp=function(t){return this._from.push(t._orig?t._orig:t),this},at.prototype._unstamp=function(t){if(void 0===t)this._from=[];else{t._orig&&(t=t._orig);var e=this._from.indexOf(t);-1this[n].notes.length&&(i=this[e=n].notes.length),r=0;r>4,n=(15&i)<<4|(o=zt.indexOf(t.charAt(a++)))>>2,r=(3&o)<<6|(s=zt.indexOf(t.charAt(a++))),u+=String.fromCharCode(e),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(r));return u},rt.lib.toBase64=function(t){var e,n,r,i,o,s=0,u=0,a="",h=[];if(!t)return t;for(;e=(o=t.charCodeAt(s++)<<16|t.charCodeAt(s++)<<8|t.charCodeAt(s++))>>18&63,n=o>>12&63,r=o>>6&63,i=63&o,h[u++]=zt.charAt(e)+zt.charAt(n)+zt.charAt(r)+zt.charAt(i),s=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;n+=63&r,i+=String.fromCharCode(n)}else if(224==(240&n)){if(n=(15&n)<<12,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(n+=(63&r)<<6,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;n+=63&r,i+=String.fromCharCode(n)}else if(240==(248&n)){if(n=(7&n)<<18,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(n+=(63&r)<<12,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(n+=(63&r)<<6,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(1114111<(n+=63&r))return t;n-=65536,i+=String.fromCharCode(55296+(n>>10)),i+=String.fromCharCode(56320+(1023&n))}}return i},rt.lib.toUTF8=function(t){t=void 0===t?"":""+t;var e,n,r="";for(e=0;e>6)):(n<65536?r+=String.fromCharCode(224+(n>>12)):(r+=String.fromCharCode(240+(n>>18)),r+=String.fromCharCode(128+(n>>12&63))),r+=String.fromCharCode(128+(n>>6&63))),r+=String.fromCharCode(128+(63&n)));return r};var Nt,Rt=[],jt={},Wt={},Ut={},Gt={};function Vt(){}var Zt=r.Promise;"function"!=typeof Zt&&((Zt=function(t){this.executor=t}).prototype.then=function(t,e){"function"!=typeof t&&(t=function(){}),"function"!=typeof e&&(e=function(){}),this.executor(t,e)});var Jt=r.Map;function Ht(){for(var t=new Array(64),e=0;e<64;e++)t[e]=Math.floor(16*Math.random()%16).toString(16).toUpperCase();return t.join("")}function Qt(t,e){return e?(Wt[t]||(Wt[t]=Ht()),Wt[t]):(jt[t]||(jt[t]=Ht()),jt[t])}function Kt(){this.sysexEnabled=!0,this.outputs=new Jt,this.inputs=new Jt;var i=this;function o(t){return function(){Nt(new $t(t,i))}}function e(t){var e,n,r;for(e=0;eh()?setTimeout(function(){n.send(r)},e-h()):n.send(r)}else{var o=this;o.open().then(function(){o.send(t,e)},Vt)}},te.prototype.onmidimessage=function(){},te.prototype.open=function(){var n=this;return new Zt(function(e,t){Gt[n.name]?e(n):(n._resolves||(n._resolves=[]),n._resolves.push(e),1==n._resolves.length&&rt().openMidiIn(n.name).or(t).and(function(){Gt[n.name]=this,n.state="connected",n.connection="open",this.connect(function(t){n.onmidimessage(new Xt(n,new Uint8Array(t)))});for(var t=0;t>1&3],(1&t[7])<<4|t[6],t[5]<<4|t[4],t[3]<<4|t[2],t[1]<<4|t[0]]}function ut(t){for(var e,n=[],r=0;r=this.type&&(this.frame=29.97==this.type?29:this.type-1),this},it.prototype.setHour=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||24<=t)throw RangeError("Bad SMPTE hours value: "+t);return this.hour=t,this},it.prototype.setMinute=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE minutes value: "+t);return this.minute=t,ot.apply(this),this},it.prototype.setSecond=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||60<=t)throw RangeError("Bad SMPTE seconds value: "+t);return this.second=t,ot.apply(this),this},it.prototype.setFrame=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||t>=this.type)throw RangeError("Bad SMPTE frame number: "+t);return this.frame=t,ot.apply(this),this},it.prototype.setQuarter=function(t){if(void 0===t&&(t=0),t!=parseInt(t)||t<0||8<=t)throw RangeError("Bad SMPTE quarter frame: "+t);return this.quarter=t,this},it.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))),ot.apply(this),this},it.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},it.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},it.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},it.prototype.read=function(t){if(t instanceof at||(t=at.apply(null,arguments)),240==t[0]&&127==t[1]&&1==t[3]&&1==t[4]&&247==t[9])return this.type=[24,25,29.97,30][t[5]>>5&3],this.hour=31&t[5],this.minute=t[6],this.second=t[7],this.frame=t[8],this.quarter=0,this._=void 0,this._b=void 0,!(this._f=void 0);if(241!=t[0]||void 0===t[1])return!1;var e=t[1]>>4,n=15&t[1];return 0==e?7==this._&&(7==this._f&&(this.reset(st(this._a)),this.incrFrame()),this.incrFrame()):3==e?4==this._&&this.decrFrame():4==e?3==this._&&this.incrFrame():7==e&&0===this._&&(0===this._b&&(this.reset(st(this._a)),this.decrFrame()),this.decrFrame()),this._a||(this._a=[]),this._a[e]=n,this._f=this._f===e-1||0==e?e:void 0,this._b=this._b===1+e||7==e?e:void 0,this._=e,this.quarter=e,!0},it.prototype.toString=function(){return ut([this.hour,this.minute,this.second,this.frame])},rt.SMPTE=it;var ht={};((at.prototype=[]).constructor=at).noteValue=function(t){return void 0===t?void 0:ht[t.toString().toLowerCase()]},at.programValue=function(t){return t},at.freq=function(t,e){return void 0===e&&(e=440),e*Math.pow(2,(lt(at.noteValue(t),t)-69)/12)};var ft={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(n in ft)if(ft.hasOwnProperty(n))for(i=0;i<12&&!(127<(t=ft[n]+12*i));i++)0<(ht[n+i]=t)&&(ht[n+"b"+i]=t-1,ht[n+"bb"+i]=t-2),t<127&&(ht[n+"#"+i]=t+1,ht[n+"##"+i]=t+2);for(i=0;i<128;i++)ht[i]=i;function ct(t){throw RangeError("Bad MIDI value: "+t)}function pt(t){return(t!=parseInt(t)||t<0||15>7}var gt={noteOff:function(t,e,n){return void 0===n&&(n=64),[128+pt(t),lt(at.noteValue(e),e),lt(n)]},noteOn:function(t,e,n){return void 0===n&&(n=127),[144+pt(t),lt(at.noteValue(e),e),lt(n)]},aftertouch:function(t,e,n){return[160+pt(t),lt(at.noteValue(e),e),lt(n)]},control:function(t,e,n){return[176+pt(t),lt(e),lt(n)]},program:function(t,e){return[192+pt(t),lt(at.programValue(e),e)]},pressure:function(t,e){return[208+pt(t),lt(e)]},pitchBend:function(t,e){return[224+pt(t),_t(e),mt(e)]},bankMSB:function(t,e){return[176+pt(t),0,lt(e)]},bankLSB:function(t,e){return[176+pt(t),32,lt(e)]},modMSB:function(t,e){return[176+pt(t),1,lt(e)]},modLSB:function(t,e){return[176+pt(t),33,lt(e)]},breathMSB:function(t,e){return[176+pt(t),2,lt(e)]},breathLSB:function(t,e){return[176+pt(t),34,lt(e)]},footMSB:function(t,e){return[176+pt(t),4,lt(e)]},footLSB:function(t,e){return[176+pt(t),36,lt(e)]},portamentoMSB:function(t,e){return[176+pt(t),5,lt(e)]},portamentoLSB:function(t,e){return[176+pt(t),37,lt(e)]},volumeMSB:function(t,e){return[176+pt(t),7,lt(e)]},volumeLSB:function(t,e){return[176+pt(t),39,lt(e)]},balanceMSB:function(t,e){return[176+pt(t),8,lt(e)]},balanceLSB:function(t,e){return[176+pt(t),40,lt(e)]},panMSB:function(t,e){return[176+pt(t),10,lt(e)]},panLSB:function(t,e){return[176+pt(t),42,lt(e)]},expressionMSB:function(t,e){return[176+pt(t),11,lt(e)]},expressionLSB:function(t,e){return[176+pt(t),43,lt(e)]},damper:function(t,e){return[176+pt(t),64,e?127:0]},portamento:function(t,e){return[176+pt(t),65,e?127:0]},sostenuto:function(t,e){return[176+pt(t),66,e?127:0]},soft:function(t,e){return[176+pt(t),67,e?127:0]},allSoundOff:function(t){return[176+pt(t),120,0]},allNotesOff:function(t){return[176+pt(t),123,0]}},vt={mtc:function(t){return[241,function(t){var e;switch(!t.backwards&&4<=t.quarter?t.decrFrame():t.backwards&&t.quarter<4&&t.incrFrame(),t.quarter>>1){case 0:e=t.frame;break;case 1:e=t.second;break;case 2:e=t.minute;break;default:e=t.hour}return 1&t.quarter?e>>=4:e&=15,7==t.quarter&&(25==t.type?e|=2:29.97==t.type?e|=4:30==t.type&&(e|=6)),!t.backwards&&4<=t.quarter?t.incrFrame():t.backwards&&t.quarter<4&&t.decrFrame(),e|t.quarter<<4}(t)]},songPosition:function(t){return[242,_t(t),mt(t)]},songSelect:function(t){return[243,lt(t)]},tune:function(){return[246]},clock:function(){return[248]},start:function(){return[250]},continue:function(){return[251]},stop:function(){return[252]},active:function(){return[254]},sxIdRequest:function(){return[240,126,127,6,1,247]},sxFullFrame:function(t){return[240,127,127,1,1,function(t){return 25==t.type?32|t.hour:29.97==t.type?64|t.hour:30==t.type?96|t.hour:t.hour}(t),t.getMinute(),t.getSecond(),t.getFrame(),247]},reset:function(){return[255]}};function yt(t,e){var n=new at;return n.ff=dt(t),n.dd=void 0===e?"":function(t){t=""+t;for(var e=0;e>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>16)+String.fromCharCode(t>>8&255)+String.fromCharCode(255&t));throw RangeError("Out of range: "+qt(Pt(t)))},smfBPM:function(t){return Ct.smfTempo(Math.round(6e7/t))},smfSMPTE:function(t){if(t instanceof it)return yt(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 yt(84,t);var e=t instanceof Array?t:Array.prototype.slice.call(arguments);return e.splice(0,0,30),Ct.smfSMPTE(new it(e))},smfTimeSignature:function(t,e,n,r){var i,o,s,u,a=(""+t).match(/^\s*(\d+)\s*\/\s*(\d+)\s*$/);if(a){if(i=parseInt(a[1]),o=parseInt(a[2]),0>=1;s;s>>=1)o++;return s=e==parseInt(e)?e:24,u=n==parseInt(n)?n:8,yt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return yt(88,t)}else{if(!(t!=parseInt(t)||e!=parseInt(e)||e&e-1)){for(i=t,o=0,s=e,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=r==parseInt(r)?r:8,yt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return yt(88,t)}throw RangeError("Wrong time signature: "+qt(Pt(t)))},smfKeySignature:function(t){var e=(t=""+t).match(/^\s*([A-H][b#]?)\s*(|maj|major|dur|m|min|minor|moll)\s*$/i);if(e){var 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()],r={"":0,MAJ:0,MAJOR:0,DUR:0,M:1,MIN:1,MINOR:1,MOLL:1}[e[2].toUpperCase()];void 0!==n&&void 0!==r&&(r&&(n-=3),-7<=(n-=7)&&n<0?t=String.fromCharCode(256+n)+String.fromCharCode(r):0<=n&&n<=7&&(t=String.fromCharCode(n)+String.fromCharCode(r)))}if(2==t.length&&t.charCodeAt(1)<=1&&(t.charCodeAt(0)<=7||t.charCodeAt(0)<=255&&249<=t.charCodeAt(0)))return yt(89,t);throw RangeError("Incorrect key signature: "+qt(t))},smfSequencer:function(t){return yt(127,Pt(t))}};function St(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,arguments)),this}}function wt(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,[this._chan].concat(Array.prototype.slice.call(arguments)))),this}}function bt(t,e){at[t]=function(){return new at(e.apply(0,arguments))}}function Mt(t,e){at[t]=function(){return e.apply(0,arguments)}}function At(t,r){bt(t,r),N.prototype[t]=function(){var t,e=Array.prototype.slice.call(arguments);e.length>4;return(e={8:"Note Off",10:"Aftertouch",12:"Program Change",13:"Channel Aftertouch",14:"Pitch Wheel"}[s])?t+" -- "+e:9==s?t+" -- "+(this[2]?"Note On":"Note Off"):11!=s?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",32:"Bank Select LSB",33:"Modulation Wheel LSB",34:"Breath Controller LSB",36:"Foot Controller LSB",37:"Portamento Time LSB",38:"Data Entry LSB",39:"Channel Volume LSB",40:"Balance LSB",42:"Pan LSB",43:"Expression Controller LSB",44:"Effect control 1 LSB",45:"Effect control 2 LSB",48:"General Purpose Controller 1 LSB",49:"General Purpose Controller 2 LSB",50:"General Purpose Controller 3 LSB",51:"General Purpose Controller 4 LSB",64:"Damper Pedal On/Off",65:"Portamento On/Off",66:"Sostenuto On/Off",67:"Soft Pedal On/Off",68:"Legato Footswitch",69:"Hold 2",70:"Sound Controller 1",71:"Sound Controller 2",72:"Sound Controller 3",73:"Sound Controller 4",74:"Sound Controller 5",75:"Sound Controller 6",76:"Sound Controller 7",77:"Sound Controller 8",78:"Sound Controller 9",79:"Sound Controller 10",80:"General Purpose Controller 5",81:"General Purpose Controller 6",82:"General Purpose Controller 7",83:"General Purpose Controller 8",84:"Portamento Control",88:"High Resolution Velocity Prefix",91:"Effects 1 Depth",92:"Effects 2 Depth",93:"Effects 3 Depth",94:"Effects 4 Depth",95:"Effects 5 Depth",96:"Data Increment",97:"Data Decrement",98:"Non-Registered Parameter Number LSB",99:"Non-Registered Parameter Number MSB",100:"Registered Parameter Number LSB",101:"Registered Parameter Number MSB",120:"All Sound Off",121:"Reset All Controllers",122:"Local Control On/Off",123:"All Notes Off",124:"Omni Mode Off",125:"Omni Mode On",126:"Mono Mode On",127:"Poly Mode On"}[this[1]])||(e="Undefined"),t+" -- "+e)},at.prototype._stamp=function(t){return this._from.push(t._orig?t._orig:t),this},at.prototype._unstamp=function(t){if(void 0===t)this._from=[];else{t._orig&&(t=t._orig);var e=this._from.indexOf(t);-1this[n].notes.length&&(i=this[e=n].notes.length),r=0;r>4,n=(15&i)<<4|(o=zt.indexOf(t.charAt(a++)))>>2,r=(3&o)<<6|(s=zt.indexOf(t.charAt(a++))),u+=String.fromCharCode(e),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(r));return u},rt.lib.toBase64=function(t){var e,n,r,i,o,s=0,u=0,a="",h=[];if(!t)return t;for(;e=(o=t.charCodeAt(s++)<<16|t.charCodeAt(s++)<<8|t.charCodeAt(s++))>>18&63,n=o>>12&63,r=o>>6&63,i=63&o,h[u++]=zt.charAt(e)+zt.charAt(n)+zt.charAt(r)+zt.charAt(i),s=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;n+=63&r,i+=String.fromCharCode(n)}else if(224==(240&n)){if(n=(15&n)<<12,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(n+=(63&r)<<6,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;n+=63&r,i+=String.fromCharCode(n)}else if(240==(248&n)){if(n=(7&n)<<18,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(n+=(63&r)<<12,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(n+=(63&r)<<6,++e>=t.length)return t;if(128!=(192&(r=t.charCodeAt(e))))return t;if(1114111<(n+=63&r))return t;n-=65536,i+=String.fromCharCode(55296+(n>>10)),i+=String.fromCharCode(56320+(1023&n))}}return i},rt.lib.toUTF8=function(t){t=void 0===t?"":""+t;var e,n,r="";for(e=0;e>6)):(n<65536?r+=String.fromCharCode(224+(n>>12)):(r+=String.fromCharCode(240+(n>>18)),r+=String.fromCharCode(128+(n>>12&63))),r+=String.fromCharCode(128+(n>>6&63))),r+=String.fromCharCode(128+(63&n)));return r};var Nt,Rt=[],jt={},Wt={},Ut={},Gt={};function Vt(){}var Zt=r.Promise;"function"!=typeof Zt&&((Zt=function(t){this.executor=t}).prototype.then=function(t,e){"function"!=typeof t&&(t=function(){}),"function"!=typeof e&&(e=function(){}),this.executor(t,e)});var Jt=r.Map;function Ht(){for(var t=new Array(64),e=0;e<64;e++)t[e]=Math.floor(16*Math.random()%16).toString(16).toUpperCase();return t.join("")}function Qt(t,e){return e?(Wt[t]||(Wt[t]=Ht()),Wt[t]):(jt[t]||(jt[t]=Ht()),jt[t])}function Kt(){this.sysexEnabled=!0,this.outputs=new Jt,this.inputs=new Jt;var i=this;function o(t){return function(){Nt(new $t(t,i))}}function e(t){var e,n,r;for(e=0;eh()?setTimeout(function(){n.send(r)},e-h()):n.send(r)}else{var o=this;o.open().then(function(){o.send(t,e)},Vt)}},te.prototype.onmidimessage=function(){},te.prototype.open=function(){var n=this;return new Zt(function(e,t){Gt[n.name]?e(n):(n._resolves||(n._resolves=[]),n._resolves.push(e),1==n._resolves.length&&rt().openMidiIn(n.name).or(t).and(function(){Gt[n.name]=this,n.state="connected",n.connection="open",this.connect(function(t){n.onmidimessage(new Xt(n,new Uint8Array(t)))});for(var t=0;t