diff --git a/README.md b/README.md index 73deb58..cf1d576 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ or [**Mozilla Add-ons**](https://addons.mozilla.org/en-US/firefox/addon/jazz-mid ## Install -**npm install jzz --save** -or **bower install jzz** -or **yarn add jzz** +`npm install jzz --save` +or `bower install jzz` +or `yarn add jzz` or get the full development version and minified scripts from [**Github**](https://github.com/jazz-soft/JZZ) *Note:* in the (unlikely) case you get into trouble installing the diff --git a/javascript/JZZ.js b/javascript/JZZ.js index 8f3507e..4f0b3b8 100644 --- a/javascript/JZZ.js +++ b/javascript/JZZ.js @@ -12,7 +12,7 @@ })(this, function() { var _scope = typeof window === 'undefined' ? global : window; - var _version = '0.5.5'; + var _version = '0.5.6'; 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 2703819..e29915d 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.JZZ&&t.JZZ.MIDI)return;t.JZZ=e()}}(this,function(){var e,r,n,t,o,i="undefined"==typeof window?global:window,s="0.5.5",u=Date.now||function(){return(new Date).getTime()},a=u(),h="undefined"!=typeof performance&&performance.now?function(){return performance.now()}:function(){return u()-a};function c(){(this._orig=this)._ready=!1,this._queue=[],this._err=[]}function f(t,e){setTimeout(function(){t._resume()},e)}function l(t){t._resume()}function p(t,n,i){t[i]=function(){var t=arguments,e=n._image();return this._push(l,[e]),e[i].apply(e,t)}}function _(t){t instanceof Function?t.apply(this):console.log(t)}function d(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(d,[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=[],i=0;i=this.type&&(this.frame=29.97==this.type?29:this.type-1),this},rt.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},rt.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},rt.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},rt.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},rt.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},rt.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},rt.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},rt.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},rt.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},rt.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]){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===e+1||7==e?e:void 0,this._=e,this.quarter=e,!0}return!1},rt.prototype.toString=function(){return ut([this.hour,this.minute,this.second,this.frame])},it.SMPTE=rt;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,(pt(at.noteValue(t),t)-69)/12)};var ct={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(n in ct)if(ct.hasOwnProperty(n))for(o=0;o<12&&!(127<(t=ct[n]+12*o));o++)0<(ht[n+o]=t)&&(ht[n+"b"+o]=t-1,ht[n+"bb"+o]=t-2),t<127&&(ht[n+"#"+o]=t+1,ht[n+"##"+o]=t+2);for(o=0;o<128;o++)ht[o]=o;function ft(t){throw RangeError("Bad MIDI value: "+t)}function lt(t){return(t!=parseInt(t)||t<0||15>7}function mt(t){t=""+t;for(var e=0;e>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),dt(t)]},songSelect:function(t){return[243,pt(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,(e=t,25==e.type?32|e.hour:29.97==e.type?64|e.hour:30==e.type?96|e.hour:e.hour),t.getMinute(),t.getSecond(),t.getFrame(),247];var e},reset:function(){return[255]}};function yt(t,e){var n=new at;return n.ff=pt(t),n.dd=void 0===e?"":mt(e),n}var Ct={smf:function(t){if(t instanceof at)return new at(t);var e=t instanceof Array?t:arguments,n=pt(e[0]),i="";2==e.length?i=Pt(e[1]):2>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 rt)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));var e=""+t;if(5==e.length&&e.charCodeAt(4)<100)return new rt(30,e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3),e.charCodeAt(4)/25),yt(84,t);var n=t instanceof Array?t:Array.prototype.slice.call(arguments);return n.splice(0,0,30),Ct.smfSMPTE(new rt(n))},smfTimeSignature:function(t,e,n,i){var r,o,s,u,a=(""+t).match(/^\s*(\d+)\s*\/\s*(\d+)\s*$/);if(a){if(r=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(r)+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(r=t,o=0,s=e,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=i==parseInt(i)?i:8,yt(88,String.fromCharCode(r)+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()],i={"":0,MAJ:0,MAJOR:0,DUR:0,M:1,MIN:1,MINOR:1,MOLL:1}[e[2].toUpperCase()];void 0!==n&&void 0!==i&&(i&&(n-=3),-7<=(n-=7)&&n<0?t=String.fromCharCode(256+n)+String.fromCharCode(i):0<=n&&n<=7&&(t=String.fromCharCode(n)+String.fromCharCode(i)))}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))},smfMetaEvent: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 Mt(t,e){at[t]=function(){return new at(e.apply(0,arguments))}}function bt(t,e){at[t]=function(){return e.apply(0,arguments)}}function At(t,i){Mt(t,i),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&&(r=this[e=n].notes.length),i=0;i>4,n=(15&r)<<4|(o=zt.indexOf(t.charAt(a++)))>>2,i=(3&o)<<6|(s=zt.indexOf(t.charAt(a++))),u+=String.fromCharCode(e),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(i));return u},it.lib.toBase64=function(t){var e,n,i,r,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,i=o>>6&63,r=63&o,h[u++]=zt.charAt(e)+zt.charAt(n)+zt.charAt(i)+zt.charAt(r),s=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;n+=63&i,r+=String.fromCharCode(n)}else if(224==(240&n)){if(n=(15&n)<<12,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(n+=(63&i)<<6,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;n+=63&i,r+=String.fromCharCode(n)}else if(240==(248&n)){if(n=(7&n)<<18,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(n+=(63&i)<<12,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(n+=(63&i)<<6,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(1114111<(n+=63&i))return t;n-=65536,r+=String.fromCharCode(55296+(n>>10)),r+=String.fromCharCode(56320+(1023&n))}}return r},it.lib.toUTF8=function(t){t=""+t;var e,n,i="";for(e=0;e>6)):(n<65536?i+=String.fromCharCode(224+(n>>12)):(i+=String.fromCharCode(240+(n>>18)),i+=String.fromCharCode(128+(n>>12&63))),i+=String.fromCharCode(128+(n>>6&63))),i+=String.fromCharCode(128+(63&n)));return i};var Nt,jt=[],Rt={},Wt={},Ut={},Gt={};function Vt(){}var Jt=i.Promise;"function"!=typeof Jt&&((Jt=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 Zt=i.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]):(Rt[t]||(Rt[t]=Ht()),Rt[t])}function Kt(){this.sysexEnabled=!0,this.outputs=new Zt,this.inputs=new Zt;var r=this;function o(t){return function(){Nt(new $t(t,r))}}function e(t){var e,n,i;for(e=0;eh()?setTimeout(function(){n.send(i)},e-h()):n.send(i)}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 Jt(function(e,t){Gt[n.name]?e(n):(n._resolves||(n._resolves=[]),n._resolves.push(e),1==n._resolves.length&&it().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=[],i=0;i=this.type&&(this.frame=29.97==this.type?29:this.type-1),this},rt.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},rt.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},rt.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},rt.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},rt.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},rt.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},rt.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},rt.prototype.incrQF=function(){return this.backwards=!1,this.quarter=this.quarter+1&7,0!=this.quarter&&4!=this.quarter||this.incrFrame(),this},rt.prototype.decrQF=function(){return this.backwards=!0,this.quarter=this.quarter+7&7,3!=this.quarter&&7!=this.quarter||this.decrFrame(),this},rt.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===e+1||7==e?e:void 0,this._=e,this.quarter=e,!0},rt.prototype.toString=function(){return ut([this.hour,this.minute,this.second,this.frame])},it.SMPTE=rt;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,(pt(at.noteValue(t),t)-69)/12)};var ct={c:0,d:2,e:4,f:5,g:7,a:9,b:11,h:11};for(n in ct)if(ct.hasOwnProperty(n))for(o=0;o<12&&!(127<(t=ct[n]+12*o));o++)0<(ht[n+o]=t)&&(ht[n+"b"+o]=t-1,ht[n+"bb"+o]=t-2),t<127&&(ht[n+"#"+o]=t+1,ht[n+"##"+o]=t+2);for(o=0;o<128;o++)ht[o]=o;function ft(t){throw RangeError("Bad MIDI value: "+t)}function lt(t){return(t!=parseInt(t)||t<0||15>7}function mt(t){t=""+t;for(var e=0;e>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),dt(t)]},songSelect:function(t){return[243,pt(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,(e=t,25==e.type?32|e.hour:29.97==e.type?64|e.hour:30==e.type?96|e.hour:e.hour),t.getMinute(),t.getSecond(),t.getFrame(),247];var e},reset:function(){return[255]}};function yt(t,e){var n=new at;return n.ff=pt(t),n.dd=void 0===e?"":mt(e),n}var Ct={smf:function(t){if(t instanceof at)return new at(t);var e=t instanceof Array?t:arguments,n=pt(e[0]),i="";2==e.length?i=Pt(e[1]):2>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 rt)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));var e=""+t;if(5==e.length&&e.charCodeAt(4)<100)return new rt(30,e.charCodeAt(0),e.charCodeAt(1),e.charCodeAt(2),e.charCodeAt(3),e.charCodeAt(4)/25),yt(84,t);var n=t instanceof Array?t:Array.prototype.slice.call(arguments);return n.splice(0,0,30),Ct.smfSMPTE(new rt(n))},smfTimeSignature:function(t,e,n,i){var r,o,s,u,a=(""+t).match(/^\s*(\d+)\s*\/\s*(\d+)\s*$/);if(a){if(r=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(r)+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(r=t,o=0,s=e,s>>=1;s;s>>=1)o++;return s=n==parseInt(n)?n:24,u=i==parseInt(i)?i:8,yt(88,String.fromCharCode(r)+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()],i={"":0,MAJ:0,MAJOR:0,DUR:0,M:1,MIN:1,MINOR:1,MOLL:1}[e[2].toUpperCase()];void 0!==n&&void 0!==i&&(i&&(n-=3),-7<=(n-=7)&&n<0?t=String.fromCharCode(256+n)+String.fromCharCode(i):0<=n&&n<=7&&(t=String.fromCharCode(n)+String.fromCharCode(i)))}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))},smfMetaEvent: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 Mt(t,e){at[t]=function(){return new at(e.apply(0,arguments))}}function bt(t,e){at[t]=function(){return e.apply(0,arguments)}}function At(t,i){Mt(t,i),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&&(r=this[e=n].notes.length),i=0;i>4,n=(15&r)<<4|(o=zt.indexOf(t.charAt(a++)))>>2,i=(3&o)<<6|(s=zt.indexOf(t.charAt(a++))),u+=String.fromCharCode(e),64!=o&&(u+=String.fromCharCode(n)),64!=s&&(u+=String.fromCharCode(i));return u},it.lib.toBase64=function(t){var e,n,i,r,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,i=o>>6&63,r=63&o,h[u++]=zt.charAt(e)+zt.charAt(n)+zt.charAt(i)+zt.charAt(r),s=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;n+=63&i,r+=String.fromCharCode(n)}else if(224==(240&n)){if(n=(15&n)<<12,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(n+=(63&i)<<6,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;n+=63&i,r+=String.fromCharCode(n)}else if(240==(248&n)){if(n=(7&n)<<18,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(n+=(63&i)<<12,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(n+=(63&i)<<6,++e>=t.length)return t;if(128!=(192&(i=t.charCodeAt(e))))return t;if(1114111<(n+=63&i))return t;n-=65536,r+=String.fromCharCode(55296+(n>>10)),r+=String.fromCharCode(56320+(1023&n))}}return r},it.lib.toUTF8=function(t){t=""+t;var e,n,i="";for(e=0;e>6)):(n<65536?i+=String.fromCharCode(224+(n>>12)):(i+=String.fromCharCode(240+(n>>18)),i+=String.fromCharCode(128+(n>>12&63))),i+=String.fromCharCode(128+(n>>6&63))),i+=String.fromCharCode(128+(63&n)));return i};var Nt,jt=[],Rt={},Wt={},Ut={},Gt={};function Vt(){}var Jt=i.Promise;"function"!=typeof Jt&&((Jt=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 Zt=i.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]):(Rt[t]||(Rt[t]=Ht()),Rt[t])}function Kt(){this.sysexEnabled=!0,this.outputs=new Zt,this.inputs=new Zt;var r=this;function o(t){return function(){Nt(new $t(t,r))}}function e(t){var e,n,i;for(e=0;eh()?setTimeout(function(){n.send(i)},e-h()):n.send(i)}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 Jt(function(e,t){Gt[n.name]?e(n):(n._resolves||(n._resolves=[]),n._resolves.push(e),1==n._resolves.length&&it().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