!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).MidiPlayer=t()}}(function(){return function(){return function t(e,r,n){function i(o,a){if(!r[o]){if(!e[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(s)return s(o,!0);var h=new Error("Cannot find module '"+o+"'");throw h.code="MODULE_NOT_FOUND",h}var f=r[o]={exports:{}};e[o][0].call(f.exports,function(t){var r=e[o][1][t];return i(r||t)},f,f.exports,t,e,r,n)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o0?u-4:u;var f=0;for(e=0;e>16&255,a[f++]=n>>8&255,a[f++]=255&n;2===o?(n=i[t.charCodeAt(e)]<<2|i[t.charCodeAt(e+1)]>>4,a[f++]=255&n):1===o&&(n=i[t.charCodeAt(e)]<<10|i[t.charCodeAt(e+1)]<<4|i[t.charCodeAt(e+2)]>>2,a[f++]=n>>8&255,a[f++]=255&n);return a},r.fromByteArray=function(t){for(var e,r=t.length,i=r%3,s="",o=[],a=16383,u=0,h=r-i;uh?h:u+a));1===i?(e=t[r-1],s+=n[e>>2],s+=n[e<<4&63],s+="=="):2===i&&(e=(t[r-2]<<8)+t[r-1],s+=n[e>>10],s+=n[e>>4&63],s+=n[e<<2&63],s+="=");return o.push(s),o.join("")};for(var n=[],i=[],s="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=o.length;a0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function f(t,e,r){for(var i,s,o=[],a=e;a>18&63]+n[s>>12&63]+n[s>>6&63]+n[63&s]);return o.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},{}],2:[function(t,e,r){"use strict";var n=t("base64-js"),i=t("ieee754");r.Buffer=a,r.SlowBuffer=function(t){+t!=t&&(t=0);return a.alloc(+t)},r.INSPECT_MAX_BYTES=50;var s=2147483647;function o(t){if(t>s)throw new RangeError("Invalid typed array length");var e=new Uint8Array(t);return e.__proto__=a.prototype,e}function a(t,e,r){if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return f(t)}return u(t,e,r)}function u(t,e,r){if("number"==typeof t)throw new TypeError('"value" argument must not be a number');return D(t)?function(t,e,r){if(e<0||t.byteLength=s)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+s.toString(16)+" bytes");return 0|t}function p(t,e){if(a.isBuffer(t))return t.length;if(O(t)||D(t))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return _(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return P(t).length;default:if(n)return _(t).length;e=(""+e).toLowerCase(),n=!0}}function y(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function g(t,e,r,n,i){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),R(r=+r)&&(r=i?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(i)return-1;r=t.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof e&&(e=a.from(e,n)),a.isBuffer(e))return 0===e.length?-1:d(t,e,r,n,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):d(t,[e],r,n,i);throw new TypeError("val must be string, number or Buffer")}function d(t,e,r,n,i){var s,o=1,a=t.length,u=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;o=2,a/=2,u/=2,r/=2}function h(t,e){return 1===o?t[e]:t.readUInt16BE(e*o)}if(i){var f=-1;for(s=r;sa&&(r=a-u),s=r;s>=0;s--){for(var c=!0,l=0;li&&(n=i):n=i;var s=e.length;if(s%2!=0)throw new TypeError("Invalid hex string");n>s/2&&(n=s/2);for(var o=0;o239?4:h>223?3:h>191?2:1;if(i+c<=r)switch(c){case 1:h<128&&(f=h);break;case 2:128==(192&(s=t[i+1]))&&(u=(31&h)<<6|63&s)>127&&(f=u);break;case 3:s=t[i+1],o=t[i+2],128==(192&s)&&128==(192&o)&&(u=(15&h)<<12|(63&s)<<6|63&o)>2047&&(u<55296||u>57343)&&(f=u);break;case 4:s=t[i+1],o=t[i+2],a=t[i+3],128==(192&s)&&128==(192&o)&&128==(192&a)&&(u=(15&h)<<18|(63&s)<<12|(63&o)<<6|63&a)>65535&&u<1114112&&(f=u)}null===f?(f=65533,c=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),i+=c}return function(t){var e=t.length;if(e<=k)return String.fromCharCode.apply(String,t);var r="",n=0;for(;nthis.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return S(this,e,r);case"utf8":case"utf-8":return w(this,e,r);case"ascii":return E(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return m(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return I(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}.apply(this,arguments)},a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),""},a.prototype.compare=function(t,e,r,n,i){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),e<0||r>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&e>=r)return 0;if(n>=i)return-1;if(e>=r)return 1;if(this===t)return 0;for(var s=(i>>>=0)-(n>>>=0),o=(r>>>=0)-(e>>>=0),u=Math.min(s,o),h=this.slice(n,i),f=t.slice(e,r),c=0;c>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var i=this.length-e;if((void 0===r||r>i)&&(r=i),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var s,o,a,u,h,f,c,l,p,y=!1;;)switch(n){case"hex":return v(this,t,e,r);case"utf8":case"utf-8":return l=e,p=r,N(_(t,(c=this).length-l),c,l,p);case"ascii":return b(this,t,e,r);case"latin1":case"binary":return b(this,t,e,r);case"base64":return u=this,h=e,f=r,N(P(t),u,h,f);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return o=e,a=r,N(function(t,e){for(var r,n,i,s=[],o=0;o>8,i=r%256,s.push(i),s.push(n);return s}(t,(s=this).length-o),s,o,a);default:if(y)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),y=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var k=4096;function E(t,e,r){var n="";r=Math.min(t.length,r);for(var i=e;in)&&(r=n);for(var i="",s=e;sr)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,i,s){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function C(t,e,r,n,i,s){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(t,e,r,n,s){return e=+e,r>>>=0,s||C(t,0,r,4),i.write(t,e,r,n,23,4),r+4}function x(t,e,r,n,s){return e=+e,r>>>=0,s||C(t,0,r,8),i.write(t,e,r,n,52,8),r+8}a.prototype.slice=function(t,e){var r=this.length;(t=~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),(e=void 0===e?r:~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),e>>=0,e>>>=0,r||A(t,e,this.length);for(var n=this[t],i=1,s=0;++s>>=0,e>>>=0,r||A(t,e,this.length);for(var n=this[t+--e],i=1;e>0&&(i*=256);)n+=this[t+--e]*i;return n},a.prototype.readUInt8=function(t,e){return t>>>=0,e||A(t,1,this.length),this[t]},a.prototype.readUInt16LE=function(t,e){return t>>>=0,e||A(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUInt16BE=function(t,e){return t>>>=0,e||A(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUInt32LE=function(t,e){return t>>>=0,e||A(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUInt32BE=function(t,e){return t>>>=0,e||A(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,e,r){t>>>=0,e>>>=0,r||A(t,e,this.length);for(var n=this[t],i=1,s=0;++s=(i*=128)&&(n-=Math.pow(2,8*e)),n},a.prototype.readIntBE=function(t,e,r){t>>>=0,e>>>=0,r||A(t,e,this.length);for(var n=e,i=1,s=this[t+--n];n>0&&(i*=256);)s+=this[t+--n]*i;return s>=(i*=128)&&(s-=Math.pow(2,8*e)),s},a.prototype.readInt8=function(t,e){return t>>>=0,e||A(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},a.prototype.readInt16LE=function(t,e){t>>>=0,e||A(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt16BE=function(t,e){t>>>=0,e||A(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},a.prototype.readInt32LE=function(t,e){return t>>>=0,e||A(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,e){return t>>>=0,e||A(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,e){return t>>>=0,e||A(t,4,this.length),i.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,e){return t>>>=0,e||A(t,4,this.length),i.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,e){return t>>>=0,e||A(t,8,this.length),i.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,e){return t>>>=0,e||A(t,8,this.length),i.read(this,t,!1,52,8)},a.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e>>>=0,r>>>=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var i=1,s=0;for(this[e]=255&t;++s>>=0,r>>>=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var i=r-1,s=1;for(this[e+i]=255&t;--i>=0&&(s*=256);)this[e+i]=t/s&255;return e+r},a.prototype.writeUInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,255,0),this[e]=255&t,e+1},a.prototype.writeUInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeUInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeUInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},a.prototype.writeUInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);B(this,t,e,r,i-1,-i)}var s=0,o=1,a=0;for(this[e]=255&t;++s>0)-a&255;return e+r},a.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e>>>=0,!n){var i=Math.pow(2,8*r-1);B(this,t,e,r,i-1,-i)}var s=r-1,o=1,a=0;for(this[e+s]=255&t;--s>=0&&(o*=256);)t<0&&0===a&&0!==this[e+s+1]&&(a=1),this[e+s]=(t/o>>0)-a&255;return e+r},a.prototype.writeInt8=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},a.prototype.writeInt16LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},a.prototype.writeInt16BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},a.prototype.writeInt32LE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},a.prototype.writeInt32BE=function(t,e,r){return t=+t,e>>>=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},a.prototype.writeFloatLE=function(t,e,r){return L(this,t,e,!0,r)},a.prototype.writeFloatBE=function(t,e,r){return L(this,t,e,!1,r)},a.prototype.writeDoubleLE=function(t,e,r){return x(this,t,e,!0,r)},a.prototype.writeDoubleBE=function(t,e,r){return x(this,t,e,!1,r)},a.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e=0;--i)t[i+e]=this[i+r];else if(s<1e3)for(i=0;i>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(s=e;s55295&&r<57344){if(!i){if(r>56319){(e-=3)>-1&&s.push(239,191,189);continue}if(o+1===n){(e-=3)>-1&&s.push(239,191,189);continue}i=r;continue}if(r<56320){(e-=3)>-1&&s.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,r<128){if((e-=1)<0)break;s.push(r)}else if(r<2048){if((e-=2)<0)break;s.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;s.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;s.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return s}function P(t){return n.toByteArray(function(t){if((t=t.trim().replace(U,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function N(t,e,r,n){for(var i=0;i=e.length||i>=t.length);++i)e[i+r]=t[i];return i}function D(t){return t instanceof ArrayBuffer||null!=t&&null!=t.constructor&&"ArrayBuffer"===t.constructor.name&&"number"==typeof t.byteLength}function O(t){return"function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(t)}function R(t){return t!=t}},{"base64-js":1,ieee754:3}],3:[function(t,e,r){r.read=function(t,e,r,n,i){var s,o,a=8*i-n-1,u=(1<>1,f=-7,c=r?i-1:0,l=r?-1:1,p=t[e+c];for(c+=l,s=p&(1<<-f)-1,p>>=-f,f+=a;f>0;s=256*s+t[e+c],c+=l,f-=8);for(o=s&(1<<-f)-1,s>>=-f,f+=n;f>0;o=256*o+t[e+c],c+=l,f-=8);if(0===s)s=1-h;else{if(s===u)return o?NaN:1/0*(p?-1:1);o+=Math.pow(2,n),s-=h}return(p?-1:1)*o*Math.pow(2,s-n)},r.write=function(t,e,r,n,i,s){var o,a,u,h=8*s-i-1,f=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:s-1,y=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=f):(o=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-o))<1&&(o--,u*=2),(e+=o+c>=1?l/u:l*Math.pow(2,1-c))*u>=2&&(o++,u/=2),o+c>=f?(a=0,o=f):o+c>=1?(a=(e*u-1)*Math.pow(2,i),o+=c):(a=e*Math.pow(2,c-1)*Math.pow(2,i),o=0));i>=8;t[r+p]=255&a,p+=y,a/=256,i-=8);for(o=o<0;t[r+p]=255&o,p+=y,o/=256,h-=8);t[r+p-y]|=128*g}},{}],4:[function(t,e,r){"use strict";for(var n={VERSION:"2.0.3",NOTES:[],CIRCLE_OF_FOURTHS:["C","F","Bb","Eb","Ab","Db","Gb","Cb","Fb","Bbb","Ebb","Abb"],CIRCLE_OF_FIFTHS:["C","G","D","A","E","B","F#","C#","G#","D#","A#","E#"]},i=[["C"],["C#","Db"],["D"],["D#","Eb"],["E"],["F"],["F#","Gb"],["G"],["G#","Ab"],["A"],["A#","Bb"],["B"]],s=0,o=function(t){i.forEach(function(e){e.forEach(function(e){return n.NOTES[s]=e+t}),s++})},a=-1;a<=9;a++)o(a);r.Constants=n},{}],5:[function(t,e,r){"use strict";var n=t("./player"),i=t("./utils"),s=t("./constants");e.exports={Player:n.Player,Utils:i.Utils,Constants:s.Constants}},{"./constants":4,"./player":6,"./utils":8}],6:[function(t,e,r){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function t(t,e){for(var r=0;r100)throw"Percent must be number between 1 and 100.";return this.skipToTick(Math.round(t/100*this.totalTicks)),this}},{key:"skipToSeconds",value:function(t){var e=this.getSongTime();if(t<0||t>e)throw t+" seconds not within song time of "+e;return this.skipToPercent(t/e*100),this}},{key:"isPlaying",value:function(){return this.setIntervalId>0||"object"===n(this.setIntervalId)}},{key:"dryRun",value:function(){for(this.resetTracks();!this.endOfFile();)this.playLoop(!0);return this.events=this.getEvents(),this.totalEvents=this.getTotalEvents(),this.totalTicks=this.getTotalTicks(),this.startTick=0,this.startTime=0,this.resetTracks(),this.triggerPlayerEvent("fileLoaded",this),this}},{key:"resetTracks",value:function(){return this.tracks.forEach(function(t){return t.reset()}),this}},{key:"getEvents",value:function(){return this.tracks.map(function(t){return t.events})}},{key:"getTotalTicks",value:function(){return Math.max.apply(null,this.tracks.map(function(t){return t.delta}))}},{key:"getTotalEvents",value:function(){return this.tracks.reduce(function(t,e){return{events:{length:t.events.length+e.events.length}}},{events:{length:0}}).events.length}},{key:"getSongTime",value:function(){return this.totalTicks/this.division/this.tempo*60}},{key:"getSongTimeRemaining",value:function(){return Math.round((this.totalTicks-this.tick)/this.division/this.tempo*60)}},{key:"getSongPercentRemaining",value:function(){return Math.round(this.getSongTimeRemaining()/this.getSongTime()*100)}},{key:"bytesProcessed",value:function(){return 14+8*this.tracks.length+this.tracks.reduce(function(t,e){return{pointer:t.pointer+e.pointer}},{pointer:0}).pointer}},{key:"eventsPlayed",value:function(){return this.tracks.reduce(function(t,e){return{eventIndex:t.eventIndex+e.eventIndex}},{eventIndex:0}).eventIndex}},{key:"endOfFile",value:function(){return this.isPlaying()?this.eventsPlayed()==this.totalEvents:this.bytesProcessed()==this.buffer.length}},{key:"getCurrentTick",value:function(){return Math.round(((new Date).getTime()-this.startTime)/1e3*(this.division*(this.tempo/60)))+this.startTick}},{key:"emitEvent",value:function(t){return this.triggerPlayerEvent("midiEvent",t),this}},{key:"on",value:function(t,e){return this.eventListeners.hasOwnProperty(t)||(this.eventListeners[t]=[]),this.eventListeners[t].push(e),this}},{key:"triggerPlayerEvent",value:function(t,e){return this.eventListeners.hasOwnProperty(t)&&this.eventListeners[t].forEach(function(t){return t(e||{})}),this}}]),e}();r.Player=a},{"./track":7,"./utils":8,fs:"fs"}],7:[function(t,e,r){"use strict";var n=function(){function t(t,e){for(var r=0;r=t)return this.eventIndex=e,this}},{key:"getCurrentByte",value:function(){return this.data[this.pointer]}},{key:"getDeltaByteCount",value:function(){for(var t=this.getCurrentByte(),e=1;t>=128;)t=this.data[this.pointer+e],e++;return e}},{key:"getDelta",value:function(){return s.readVarInt(this.data.subarray(this.pointer,this.pointer+this.getDeltaByteCount()))}},{key:"handleEvent",value:function(t,e){if(e=e||!1){var r=t-this.lastTick>=this.getDelta();if(this.pointer=0?e.keySignature=i.CIRCLE_OF_FIFTHS[e.data[0]]:e.data[0]<0&&(e.keySignature=i.CIRCLE_OF_FOURTHS[Math.abs(e.data[0])]),0==e.data[1]?e.keySignature+=" Major":1==e.data[1]&&(e.keySignature+=" Minor");break;case 127:e.name="Sequencer-Specific Meta-event";break;default:e.name="Unknown: "+this.data[t+1].toString(16)}var n=this.data[this.pointer+r+2];this.pointer+=r+3+n}else if(240==this.data[t]){e.name="Sysex";n=this.data[this.pointer+r+1];this.pointer+=r+2+n}else this.data[t]<128?(e.running=!0,e.noteNumber=this.data[t],e.noteName=i.NOTES[this.data[t]],e.velocity=this.data[t+1],this.lastStatus<=143?(e.name="Note off",e.channel=this.lastStatus-128+1):this.lastStatus<=159&&(e.name="Note on",e.channel=this.lastStatus-144+1),this.pointer+=r+2):(this.lastStatus=this.data[t],this.data[t]<=143?(e.name="Note off",e.channel=this.lastStatus-128+1,e.noteNumber=this.data[t+1],e.noteName=i.NOTES[this.data[t+1]],e.velocity=Math.round(this.data[t+2]/127*100),this.pointer+=r+3):this.data[t]<=159?(e.name="Note on",e.channel=this.lastStatus-144+1,e.noteNumber=this.data[t+1],e.noteName=i.NOTES[this.data[t+1]],e.velocity=Math.round(this.data[t+2]/127*100),this.pointer+=r+3):this.data[t]<=175?(e.name="Polyphonic Key Pressure",e.channel=this.lastStatus-160+1,e.note=i.NOTES[this.data[t+1]],e.pressure=event[2],this.pointer+=r+3):this.data[t]<=191?(e.name="Controller Change",e.channel=this.lastStatus-176+1,e.number=this.data[t+1],e.value=this.data[t+2],this.pointer+=r+3):this.data[t]<=207?(e.name="Program Change",e.channel=this.lastStatus-192+1,e.value=this.data[t+1],this.pointer+=r+2):this.data[t]<=223?(e.name="Channel Key Pressure",e.channel=this.lastStatus-208+1,this.pointer+=r+2):this.data[t]<=239?(e.name="Pitch Bend",e.channel=this.lastStatus-224+1,this.pointer+=r+3):e.name="Unknown. Pointer: "+this.pointer.toString()+" "+t.toString()+" "+this.data.length);return this.delta+=e.delta,this.events.push(e),e}},{key:"endOfTrack",value:function(){return 255==this.data[this.pointer+1]&&47==this.data[this.pointer+2]&&0==this.data[this.pointer+3]}}]),t}();e.exports.Track=o},{"./constants":4,"./utils":8}],8:[function(t,e,r){(function(t){"use strict";var e=function(){function t(t,e){for(var r=0;r>>0).toString(2)}},{key:"readVarInt",value:function(t){var e=0;return t.forEach(function(t){128&t?(e+=127&t,e<<=7):e+=t}),e}},{key:"atob",value:function(t){function e(e){return t.apply(this,arguments)}return e.toString=function(){return t.toString()},e}(function(e){return"function"==typeof atob?atob(e):new t(e,"base64").toString("binary")})}]),r}();r.Utils=n}).call(this,t("buffer").Buffer)},{buffer:2}]},{},[5])(5)});