diff --git a/README.md b/README.md index 31d6575..3070c64 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,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 b29d06a..412a8be 100644 --- a/javascript/JZZ.js +++ b/javascript/JZZ.js @@ -13,7 +13,7 @@ })(this, function() { var _scope = typeof window === 'undefined' ? global : window; - var _version = '1.0.4'; + var _version = '1.0.5'; 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 9be4da1..a591ded 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).JZZ&&t.JZZ.MIDI)return;t.JZZ=e()}}(this,function(){var o,r,n,t,i,e="undefined"==typeof window?global:window,s="1.0.4",u=Date.now||function(){return(new Date).getTime()},a=u(),h="undefined"!=typeof performance&&performance.now?function(){return performance.now()}:function(){return u()-a},f=function(t){setTimeout(t,0)};function c(){(this._orig=this)._ready=!1,this._queue=[],this._log=[]}function p(t,e){this._bad?e instanceof Function&&e.apply(this,[new Error(this._err())]):t instanceof Function&&t.apply(this,[this])}function l(t,e){this._bad?t._crash(this._err()):setTimeout(function(){t._resume()},e)}function d(t){this._bad&&t._break(this._err()),t._resume()}function _(t,n,r){t[r]=function(){var t=arguments,e=n._image();return this._push(d,[e]),e[r].apply(e,t)}}function m(t){this._bad||(t instanceof Function?t.apply(this):console.log(t))}function g(t){this._bad&&(t instanceof Function?t.apply(this):console.log(t))}function v(t){this._bad?t._crash(this._err()):(this._break("Closed"),t._resume())}function y(t){if(t.length){var e=t.shift();if(t.length){var n=this;this._slip(g,[function(){y.apply(n,[t])}])}try{this._repair(),e.apply(this)}catch(t){this._break(t.toString())}}else this._break()}function C(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 pt(t){for(var e,n=[],r=0;r=this.type&&(this.frame=this.type-1),this},ht.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},ht.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,ft.apply(this),this},ht.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,ft.apply(this),this},ht.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,ft.apply(this),this},ht.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},ht.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))),ft.apply(this),this},ht.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},ht.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},ht.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},ht.prototype.read=function(t){if(t instanceof lt||(t=lt.apply(null,arguments)),240==t[0]&&127==t[1]&&1==t[3]&&1==t[4]&&247==t[9])return this.type=[24,25,29.97,30][t[5]>>5&3],this.hour=31&t[5],this.minute=t[6],this.second=t[7],this.frame=t[8],this.quarter=0,this._=void 0,this._b=void 0,!(this._f=void 0);if(241!=t[0]||void 0===t[1])return!1;var e=t[1]>>4,n=15&t[1];return 0==e?7==this._&&(7==this._f&&(this.reset(ct(this._a)),this.incrFrame()),this.incrFrame()):3==e?4==this._&&this.decrFrame():4==e?3==this._&&this.incrFrame():7==e&&0===this._&&(0===this._b&&(this.reset(ct(this._a)),this.decrFrame()),this.decrFrame()),this._a||(this._a=[]),this._a[e]=n,this._f=this._f===e-1||0==e?e:void 0,this._b=this._b===1+e||7==e?e:void 0,this._=e,this.quarter=e,!0},ht.prototype.toString=function(){return pt([this.hour,this.minute,this.second,this.frame])},at.SMPTE=ht;var dt={};((lt.prototype=[]).constructor=lt).noteValue=function(t){return void 0===t?void 0:dt[t.toString().toLowerCase()]},lt.programValue=function(t){return t},lt.freq=function(t,e){return void 0===e&&(e=440),e*Math.pow(2,(vt(lt.noteValue(t),t)-69)/12)};var _t={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(n in _t)if(_t.hasOwnProperty(n))for(i=0;i<12&&!(127<(t=_t[n]+12*i));i++)0<(dt[n+i]=t)&&(dt[n+"b"+i]=t-1,dt[n+"bb"+i]=t-2),t<127&&(dt[n+"#"+i]=t+1,dt[n+"##"+i]=t+2);for(i=0;i<128;i++)dt[i]=i;function mt(t){throw RangeError("Bad MIDI value: "+t)}function gt(t){return U(t),parseInt(t)}function vt(t,e){return(t!=parseInt(t)||t<0||127>7}var wt={noteOff:function(t,e,n){return void 0===n&&(n=64),[128+gt(t),vt(lt.noteValue(e),e),vt(n)]},noteOn:function(t,e,n){return void 0===n&&(n=127),[144+gt(t),vt(lt.noteValue(e),e),vt(n)]},aftertouch:function(t,e,n){return[160+gt(t),vt(lt.noteValue(e),e),vt(n)]},control:function(t,e,n){return[176+gt(t),vt(e),vt(n)]},program:function(t,e){return[192+gt(t),vt(lt.programValue(e),e)]},pressure:function(t,e){return[208+gt(t),vt(e)]},pitchBend:function(t,e){return[224+gt(t),Ct(e),bt(e)]},bankMSB:function(t,e){return[176+gt(t),0,vt(e)]},bankLSB:function(t,e){return[176+gt(t),32,vt(e)]},modMSB:function(t,e){return[176+gt(t),1,vt(e)]},modLSB:function(t,e){return[176+gt(t),33,vt(e)]},breathMSB:function(t,e){return[176+gt(t),2,vt(e)]},breathLSB:function(t,e){return[176+gt(t),34,vt(e)]},footMSB:function(t,e){return[176+gt(t),4,vt(e)]},footLSB:function(t,e){return[176+gt(t),36,vt(e)]},portamentoMSB:function(t,e){return[176+gt(t),5,vt(e)]},portamentoLSB:function(t,e){return[176+gt(t),37,vt(e)]},volumeMSB:function(t,e){return[176+gt(t),7,vt(e)]},volumeLSB:function(t,e){return[176+gt(t),39,vt(e)]},balanceMSB:function(t,e){return[176+gt(t),8,vt(e)]},balanceLSB:function(t,e){return[176+gt(t),40,vt(e)]},panMSB:function(t,e){return[176+gt(t),10,vt(e)]},panLSB:function(t,e){return[176+gt(t),42,vt(e)]},expressionMSB:function(t,e){return[176+gt(t),11,vt(e)]},expressionLSB:function(t,e){return[176+gt(t),43,vt(e)]},damper:function(t,e){return[176+gt(t),64,e?127:0]},portamento:function(t,e){return[176+gt(t),65,e?127:0]},sostenuto:function(t,e){return[176+gt(t),66,e?127:0]},soft:function(t,e){return[176+gt(t),67,e?127:0]},allSoundOff:function(t){return[176+gt(t),120,0]},allNotesOff:function(t){return[176+gt(t),123,0]}},St={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,Ct(t),bt(t)]},songSelect:function(t){return[243,vt(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 Mt(t,e){var n=new lt;return n.ff=yt(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: "+kt(Dt(t)))},smfBPM:function(t){return Ot.smfTempo(Math.round(6e7/t))},smfSMPTE:function(t){if(t instanceof ht)return Mt(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 Mt(84,t);var e=t instanceof Array?t:Array.prototype.slice.call(arguments);return e.splice(0,0,30),Ot.smfSMPTE(new ht(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,Mt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return Mt(88,t)}else{if(t==parseInt(t)&&e==parseInt(e)&&e&&!(e&e-1)){for(i=t,o=0,s=e,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=r==parseInt(r)?r:8,Mt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return Mt(88,t)}throw RangeError("Wrong time signature: "+kt(Dt(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 Mt(89,t);throw RangeError("Incorrect key signature: "+kt(t))},smfSequencer:function(t){return Mt(127,Dt(t))}};function It(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,arguments)),this}}function At(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,[this._chan].concat(Array.prototype.slice.call(arguments)))),this}}function Et(t,e){lt[t]=function(){return new lt(e.apply(0,arguments))}}function xt(t,e){lt[t]=function(){return e.apply(0,arguments)}}function Pt(t,r){Et(t,r),Z.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"}[i])?t+" -- "+e:9==i?t+" -- "+(this[2]?"Note On":"Note Off"):11!=i?t:t+" -- "+(e=(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]])||"Undefined")},lt.prototype._stamp=function(t){return this._from.push(t._orig?t._orig:t),this},lt.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=Ut.indexOf(t.charAt(a++)))>>2,r=(3&o)<<6|(s=Ut.indexOf(t.charAt(a++))),u+=String.fromCharCode(e),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(r));return u},at.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++]=Ut.charAt(e)+Ut.charAt(n)+Ut.charAt(r)+Ut.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},at.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 Gt=[],Zt={},Vt={},Jt=e.Promise;function Wt(t,e,n){this.name=t,this.message=e,this.code=n}function Ht(t,e){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=e,this.defaultPrevented=!1,this.eventPhase=0,this.path=[],this.port=t,this.returnValue=!0,this.srcElement=e,this.target=e,this.timeStamp=h(),this.type="statechange"}function Qt(t,e){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=t,this.data=e,this.defaultPrevented=!1,this.eventPhase=0,this.path=[],this.receivedTime=h(),this.returnValue=!0,this.srcElement=t,this.target=t,this.timeStamp=this.receivedTime,this.type="midimessage"}function Kt(t,e){t&&(t.onstatechange&&t.onstatechange(new Ht(t,t)),e.onstatechange&&e.onstatechange(new Ht(t,e)))}function $t(n,r){var i=this,o=!1,e=null,s=null;this.type="input",this.id=r.id,this.name=r.name,this.manufacturer=r.man,this.version=r.ver,Object.defineProperty(this,"state",{get:function(){return r.connected?"connected":"disconnected"},enumerable:!0}),Object.defineProperty(this,"connection",{get:function(){return o?r.proxy?"open":"pending":"closed"},enumerable:!0}),Object.defineProperty(this,"onmidimessage",{get:function(){return s},set:function(t){t instanceof Function?(s=t,o||i.open()):s=null},enumerable:!0}),Object.defineProperty(this,"onstatechange",{get:function(){return e},set:function(t){e=t instanceof Function?t:null},enumerable:!0}),this.open=function(){return new Jt(function(t,e){o?t(i):r.open().then(function(){o||(o=!0,Kt(i,n)),t(i)},function(){e(new Wt("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new Jt(function(t){o&&(o=!1,r.close(),Kt(i,n)),t(i)})},Object.freeze(this)}function Xt(t){for(var e,n;t.length;){for(e=0;et.length)return;for(e=1;e>1&3],(1&t[7])<<4|t[6],t[5]<<4|t[4],t[3]<<4|t[2],t[1]<<4|t[0]]}function pt(t){for(var e,n=[],r=0;r=this.type&&(this.frame=this.type-1),this},ht.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},ht.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,ft.apply(this),this},ht.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,ft.apply(this),this},ht.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,ft.apply(this),this},ht.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},ht.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))),ft.apply(this),this},ht.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},ht.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},ht.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},ht.prototype.read=function(t){if(t instanceof lt||(t=lt.apply(null,arguments)),240==t[0]&&127==t[1]&&1==t[3]&&1==t[4]&&247==t[9])return this.type=[24,25,29.97,30][t[5]>>5&3],this.hour=31&t[5],this.minute=t[6],this.second=t[7],this.frame=t[8],this.quarter=0,this._=void 0,this._b=void 0,!(this._f=void 0);if(241!=t[0]||void 0===t[1])return!1;var e=t[1]>>4,n=15&t[1];return 0==e?7==this._&&(7==this._f&&(this.reset(ct(this._a)),this.incrFrame()),this.incrFrame()):3==e?4==this._&&this.decrFrame():4==e?3==this._&&this.incrFrame():7==e&&0===this._&&(0===this._b&&(this.reset(ct(this._a)),this.decrFrame()),this.decrFrame()),this._a||(this._a=[]),this._a[e]=n,this._f=this._f===e-1||0==e?e:void 0,this._b=this._b===1+e||7==e?e:void 0,this._=e,this.quarter=e,!0},ht.prototype.toString=function(){return pt([this.hour,this.minute,this.second,this.frame])},at.SMPTE=ht;var dt={};((lt.prototype=[]).constructor=lt).noteValue=function(t){return void 0===t?void 0:dt[t.toString().toLowerCase()]},lt.programValue=function(t){return t},lt.freq=function(t,e){return void 0===e&&(e=440),e*Math.pow(2,(vt(lt.noteValue(t),t)-69)/12)};var _t={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(n in _t)if(_t.hasOwnProperty(n))for(i=0;i<12&&!(127<(t=_t[n]+12*i));i++)0<(dt[n+i]=t)&&(dt[n+"b"+i]=t-1,dt[n+"bb"+i]=t-2),t<127&&(dt[n+"#"+i]=t+1,dt[n+"##"+i]=t+2);for(i=0;i<128;i++)dt[i]=i;function mt(t){throw RangeError("Bad MIDI value: "+t)}function gt(t){return U(t),parseInt(t)}function vt(t,e){return(t!=parseInt(t)||t<0||127>7}var wt={noteOff:function(t,e,n){return void 0===n&&(n=64),[128+gt(t),vt(lt.noteValue(e),e),vt(n)]},noteOn:function(t,e,n){return void 0===n&&(n=127),[144+gt(t),vt(lt.noteValue(e),e),vt(n)]},aftertouch:function(t,e,n){return[160+gt(t),vt(lt.noteValue(e),e),vt(n)]},control:function(t,e,n){return[176+gt(t),vt(e),vt(n)]},program:function(t,e){return[192+gt(t),vt(lt.programValue(e),e)]},pressure:function(t,e){return[208+gt(t),vt(e)]},pitchBend:function(t,e){return[224+gt(t),Ct(e),bt(e)]},bankMSB:function(t,e){return[176+gt(t),0,vt(e)]},bankLSB:function(t,e){return[176+gt(t),32,vt(e)]},modMSB:function(t,e){return[176+gt(t),1,vt(e)]},modLSB:function(t,e){return[176+gt(t),33,vt(e)]},breathMSB:function(t,e){return[176+gt(t),2,vt(e)]},breathLSB:function(t,e){return[176+gt(t),34,vt(e)]},footMSB:function(t,e){return[176+gt(t),4,vt(e)]},footLSB:function(t,e){return[176+gt(t),36,vt(e)]},portamentoMSB:function(t,e){return[176+gt(t),5,vt(e)]},portamentoLSB:function(t,e){return[176+gt(t),37,vt(e)]},volumeMSB:function(t,e){return[176+gt(t),7,vt(e)]},volumeLSB:function(t,e){return[176+gt(t),39,vt(e)]},balanceMSB:function(t,e){return[176+gt(t),8,vt(e)]},balanceLSB:function(t,e){return[176+gt(t),40,vt(e)]},panMSB:function(t,e){return[176+gt(t),10,vt(e)]},panLSB:function(t,e){return[176+gt(t),42,vt(e)]},expressionMSB:function(t,e){return[176+gt(t),11,vt(e)]},expressionLSB:function(t,e){return[176+gt(t),43,vt(e)]},damper:function(t,e){return[176+gt(t),64,e?127:0]},portamento:function(t,e){return[176+gt(t),65,e?127:0]},sostenuto:function(t,e){return[176+gt(t),66,e?127:0]},soft:function(t,e){return[176+gt(t),67,e?127:0]},allSoundOff:function(t){return[176+gt(t),120,0]},allNotesOff:function(t){return[176+gt(t),123,0]}},St={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,Ct(t),bt(t)]},songSelect:function(t){return[243,vt(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 Mt(t,e){var n=new lt;return n.ff=yt(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: "+kt(Dt(t)))},smfBPM:function(t){return Ot.smfTempo(Math.round(6e7/t))},smfSMPTE:function(t){if(t instanceof ht)return Mt(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 Mt(84,t);var e=t instanceof Array?t:Array.prototype.slice.call(arguments);return e.splice(0,0,30),Ot.smfSMPTE(new ht(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,Mt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return Mt(88,t)}else{if(t==parseInt(t)&&e==parseInt(e)&&e&&!(e&e-1)){for(i=t,o=0,s=e,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=r==parseInt(r)?r:8,Mt(88,String.fromCharCode(i)+String.fromCharCode(o)+String.fromCharCode(s)+String.fromCharCode(u))}if(4==(""+t).length)return Mt(88,t)}throw RangeError("Wrong time signature: "+kt(Dt(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 Mt(89,t);throw RangeError("Incorrect key signature: "+kt(t))},smfSequencer:function(t){return Mt(127,Dt(t))}};function It(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,arguments)),this}}function At(t,e,n){t.prototype[e]=function(){return this.send(n.apply(0,[this._chan].concat(Array.prototype.slice.call(arguments)))),this}}function Et(t,e){lt[t]=function(){return new lt(e.apply(0,arguments))}}function xt(t,e){lt[t]=function(){return e.apply(0,arguments)}}function Pt(t,r){Et(t,r),Z.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"}[i])?t+" -- "+e:9==i?t+" -- "+(this[2]?"Note On":"Note Off"):11!=i?t:t+" -- "+(e=(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]])||"Undefined")},lt.prototype._stamp=function(t){return this._from.push(t._orig?t._orig:t),this},lt.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=Ut.indexOf(t.charAt(a++)))>>2,r=(3&o)<<6|(s=Ut.indexOf(t.charAt(a++))),u+=String.fromCharCode(e),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(r));return u},at.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++]=Ut.charAt(e)+Ut.charAt(n)+Ut.charAt(r)+Ut.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},at.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 Gt=[],Zt={},Vt={},Jt=e.Promise;function Wt(t,e,n){this.name=t,this.message=e,this.code=n}function Ht(t,e){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=e,this.defaultPrevented=!1,this.eventPhase=0,this.path=[],this.port=t,this.returnValue=!0,this.srcElement=e,this.target=e,this.timeStamp=h(),this.type="statechange"}function Qt(t,e){this.bubbles=!1,this.cancelBubble=!1,this.cancelable=!1,this.currentTarget=t,this.data=e,this.defaultPrevented=!1,this.eventPhase=0,this.path=[],this.receivedTime=h(),this.returnValue=!0,this.srcElement=t,this.target=t,this.timeStamp=this.receivedTime,this.type="midimessage"}function Kt(t,e){t&&(t.onstatechange&&t.onstatechange(new Ht(t,t)),e.onstatechange&&e.onstatechange(new Ht(t,e)))}function $t(n,r){var i=this,o=!1,e=null,s=null;this.type="input",this.id=r.id,this.name=r.name,this.manufacturer=r.man,this.version=r.ver,Object.defineProperty(this,"state",{get:function(){return r.connected?"connected":"disconnected"},enumerable:!0}),Object.defineProperty(this,"connection",{get:function(){return o?r.proxy?"open":"pending":"closed"},enumerable:!0}),Object.defineProperty(this,"onmidimessage",{get:function(){return s},set:function(t){t instanceof Function?(s=t,o||i.open()):s=null},enumerable:!0}),Object.defineProperty(this,"onstatechange",{get:function(){return e},set:function(t){e=t instanceof Function?t:null},enumerable:!0}),this.open=function(){return new Jt(function(t,e){o?t(i):r.open().then(function(){o||(o=!0,Kt(i,n)),t(i)},function(){e(new Wt("InvalidAccessError","Port is not available",15))})})},this.close=function(){return new Jt(function(t){o&&(o=!1,r.close(),Kt(i,n)),t(i)})},Object.freeze(this)}function Xt(t){for(var e,n;t.length;){for(e=0;et.length)return;for(e=1;e