@logue/smfplayer
Version:
smfplayer.js is JavaScript based Standard Midi Player for WebMidiLink based synthesizer.
2 lines • 48 kB
JavaScript
/*! For license information please see smf.player.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("SMF",[],t):"object"==typeof exports?exports.SMF=t():e.SMF=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{var e={454:(e,t,n)=>{"use strict";n.d(t,{Z:()=>f});var r=n(579),i=n(994);function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(e,t)}function c(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=h(e);if(t){var i=h(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return l(this,n)}}function l(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function h(e){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},h(e)}var f=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}(h,e);var t,n,a,l=c(h);function h(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return o(this,h),l.call(this,e,t)}return t=h,(n=[{key:"parse",value:function(){this.parseHeader(),this.parseTracks(),this.toPlainTrack()}},{key:"parseHeader",value:function(){var e=this.input.Settings;this.encoder=new TextEncoder(e.Encoding||"shift_jis"),this.title=e.Title,this.author=e.Source,this.timeDivision=0|e.TimeBase||32;var t=[];t.push(new i.Sj("SystemExclusive",0,0,[126,127,9,1])),t.push(new i.FL("SequenceTrackName",0,0,[this.title])),t.push(new i.FL("CopyrightNotice",0,0,[this.author])),t.push(new i.FL("TextEvent",0,0,[e.Memo])),t.push(new i.FL("TimeSignature",0,0,[0|e.TimeSignatureNN||4,0|e.TimeSignatureDD||4,0,0])),t.push(new i.FL("EndOfTrack",0,0)),this.tracks.push(t),delete this.input["3MLE EXTENSION"],delete this.input.Settings}},{key:"parseTracks",value:function(){var e=this.input,t=[],n=[],a=[];for(var o in this.input)Object.prototype.hasOwnProperty.call(this.input,o)&&(o.match(/^Channel(\d+)$/i)&&(n[(0|RegExp.$1)-1]=Object.keys(e[o]).join("").replace(/\/\*([^*]|\*[^/])*\*\//g,"")),o.match(/^ChannelProperty(\d+)$/i)&&(a[(0|RegExp.$1)-1]={name:e[o].Name,instrument:0|e[o].Patch,panpot:0|e[o].Pan}));var s=[];for(var u in n)Object.prototype.hasOwnProperty.call(n,u)&&(void 0!==a[u]?s[u]={mml:n[u],name:a[u].name||"",instrument:a[u].instrument||0,panpot:a[u].panpot||64}:s[u]={mml:n[u],name:"",instrument:0,panpot:64});for(var c in s)if(Object.prototype.hasOwnProperty.call(s,c)){var l=0|c,h=[];if(""===s[c].mml)return;h.push(new i.FL("InsturumentName",0,48,[s[c].name])),h.push(new i.gQ("ProgramChange",0,96,l,s[c].instrument)),h.push(new i.gQ("ControlChange",0,154,l,10,s[c].panpot));var f=new r.Z({timeDivision:this.timeDivision,channel:l,timeOffset:386,mml:s[c].mml});h=h.concat(f.events),t.push(f.endTime),h.concat(new i.FL("EndOfTrack",0,Math.max(t))),this.tracks.push(h)}this.numberOfTracks=this.tracks.length}}])&&s(t.prototype,n),a&&s(t,a),h}(n(888).Z)},579:(e,t,n)=>{"use strict";n.d(t,{Z:()=>u});var r=n(994);function i(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return a(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,s=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){u=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(u)throw o}}}}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var u=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};o(this,e),this.timeDivision=0|t.timeDivision||96,this.channel=0|t.channel,this.timeOffset=0|t.timeOffset,this.PATTERN=/[a-glnortv<>][+#-]?\d*\.?&?/g,this.NOTE_TABLE={c:0,d:2,e:4,f:5,g:7,a:9,b:11},this.MINIM=2*this.timeDivision,this.SEMIBREVE=4*this.timeDivision,this.VELOCITY_MAGNIFICATION=7,this.mml=t.mml,this.events=[],this.plainEvents=[],this.endTime=0,this.noteOffNegativeOffset=2,this.ignoreTempo=!1|t.igonreTempo,this.maxOctave=8|t.maxOctave,this.minOctave=0|t.minOctave,this.octaveMode=0|t.octaveMode,this.minNote=12|t.minNote,this.maxNote=98|t.minNote,this.parse()}var t,n,a;return t=e,(n=[{key:"parse",value:function(){var e=[];try{e=this.mml.toLowerCase().match(this.PATTERN)}catch(e){return}if(e){var t,n=this.timeOffset,a=this.timeDivision,o=0,s=8,u=4,c=!1,l=[],h=i(e);try{for(h.s();!(t=h.n()).done;){var f=t.value,p=0|a,m="",y=0;if(f.match(/([lotv<>])([1-9]\d*|0?)(\.?)(&?)/))switch(m=RegExp.$1.toLowerCase(),y=0|RegExp.$2,c&&"&"!==RegExp.$4&&(c=!1,l.push(new r.gQ("NoteOff",0,n-this.noteOffNegativeOffset,this.channel,o))),m){case"l":y>=1&&y<=this.MINIM&&(a=Math.floor(this.SEMIBREVE/y),"."===RegExp.$3&&(a=Math.floor(1.5*a)));break;case"o":y>=this.minOctave&&y<=this.maxOctave&&(u=y);break;case"t":l.push(new r.FL("SetTempo",0,n,[Math.floor(6e7/y)]));break;case"v":y>=0&&y<=15&&(s=y);break;case"<":u=u<=this.minOctave?this.minOctave:u-1;break;case">":u=u>=this.maxOctave?this.maxOctave:u+1}else if(f.match(/([a-gn])([+#-]?)(\d*)(\.?)(&?)/)){var v=0;switch(m=RegExp.$1.toLowerCase(),y=0|RegExp.$3,"n"===m?v=y:(y>=1&&y<=this.MINIM&&(p=Math.floor(this.SEMIBREVE/y)),"."===RegExp.$4&&(p=Math.floor(1.5*p)),2!==this.octaveMode&&(v=12*u+this.NOTE_TABLE[m],"+"===RegExp.$2||"#"===RegExp.$2?v++:"-"===RegExp.$2&&v--)),this.octaveMode){case 1:for(;v<this.minNote;)v+=12;for(;v>this.maxNote;)v-=12;v+=12;break;case 2:v=this.maxNote;break;default:v+=12}c?v!==o&&l.push(new r.gQ("NoteOff",0,n-this.noteOffNegativeOffset,this.channel,o)):l.push(new r.gQ("NoteOn",0,n,this.channel,v,s*this.VELOCITY_MAGNIFICATION)),n+=p,"&"===RegExp.$5?(c=!0,o=v):(c=!1,l.push(new r.gQ("NoteOff",0,n-this.noteOffNegativeOffset,this.channel,v)))}else f.match(/R(\d*)(\.?)/i)&&((y=0|RegExp.$1)>=1&&y<=this.MINIM&&(p=Math.floor(this.SEMIBREVE/y)),"."===RegExp.$2&&(p=Math.floor(1.5*p)),n+=p)}}catch(e){h.e(e)}finally{h.f()}this.events=l,this.endTime=n}}}])&&s(t.prototype,n),a&&s(t,a),e}()},656:(e,t,n)=>{"use strict";n.d(t,{Z:()=>r});const r={version:"0.3.6",date:"2021-11-04T14:34:02.764Z"}},994:(e,t,n)=>{"use strict";function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&a(e,t)}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(e,t)}function o(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=u(e);if(t){var i=u(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return s(this,n)}}function s(e,t){if(t&&("object"===r(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}n.d(t,{gQ:()=>h,Sj:()=>f,FL:()=>p});var l=function e(t,n,r){c(this,e),this.subtype=t,this.deltaTime=n,this.time=r},h=function(e){i(n,e);var t=o(n);function n(e,r,i,a,o,s){var u;return c(this,n),(u=t.call(this,e,r,i)).channel=a,u.parameter1=o,u.parameter2=s,u}return n}(l),f=function(e){i(n,e);var t=o(n);function n(e,r,i,a){var o;return c(this,n),(o=t.call(this,e,r,i)).data=a,o}return n}(l),p=function(e){i(n,e);var t=o(n);function n(e,r,i,a){var o;return c(this,n),(o=t.call(this,e,r,i)).data=a,o}return n}(l)},764:(e,t,n)=>{"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.d(t,{Z:()=>a});var a=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,e),this.input=t,this.ip=n.index||0,this.timeDivision=n.timeDivision||48,this.header={},this.dataInformation={},this.tracks=[]}var t,n,a;return t=e,(n=[{key:"parse",value:function(){this.parseHeader(),this.parseDataInformation(),this.parseTracks()}},{key:"parseHeader",value:function(){var e=this.input,t=this.ip,n=this.header={},r=String.fromCharCode(e[t++],e[t++],e[t++],e[t++]);if("melo"!==r)throw new Error("invalid MFi signature:"+r);n.fileLength=(e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++])>>>0,n.trackOffset=(e[t++]<<16|e[t++])+t,n.dataMajorType=e[t++],n.dataMinorType=e[t++],n.numberOfTracks=e[t++],this.ip=t}},{key:"parseDataInformation",value:function(){for(var e,t,n=this.input,r=this.ip,i=this.dataInformation={copy:null,date:null,exst:null,note:null,prot:null,sorc:null,titl:null,trac:null,vers:null};r<this.header.trackOffset;)switch(e=String.fromCharCode(n[r++],n[r++],n[r++],n[r++]),t=n[r++]<<8|n[r++],e){case"titl":case"copy":case"vers":case"date":case"prot":i[e]=String.fromCharCode.apply(null,n.subarray(r,r+=t));break;case"sorc":i[e]=n[r++];break;case"note":i[e]=n[r++]<<8|n[r++];break;case"exst":break;default:i[e]=n.subarray(r,r+=t)}this.ip=r}},{key:"parseTracks",value:function(){var e,t,n,r,i,a,o,s,u,c=this.input,l=this.ip,h=this.tracks=[],f=function(){var e,t=c[l++]<<8|c[l++],n=l+t,r=[];if(1!==c[l++])throw new Error("invalid EditInstrument const value:"+c[l-1]);for(;l<n;)(e={}).part=c[l++]>>4&3,e.modulator={ML:c[l]>>5,VIV:c[l]>>4&1,EG:c[l]>>3&1,SUS:c[l]>>2&1,RR:(3&c[l++])<<2|c[l]>>6,DR:c[l]>>4&15,AR:(3&c[l++])<<2|c[l]>>6,SL:c[l]>>4&15,TL:(3&c[l++])<<4|c[l]>>4,WF:c[l]>>3&1,FB:7&c[l++]},e.carrier={ML:c[l]>>5,VIV:c[l]>>4&1,EG:c[l]>>3&1,SUS:c[l]>>2&1,RR:(3&c[l++])<<2|c[l]>>6,DR:c[l]>>4&15,AR:(3&c[l++])<<2|c[l]>>6,SL:c[l]>>4&15,TL:(3&c[l++])<<4|c[l]>>4,WF:c[l]>>3&1,FB:7&c[l++]},e.octaveSelect=3&c[l++],r.push(e);return r},p=function(){if(1!==c[l++])throw new Error("invalid Vibrato const value:"+c[l-1]);return{part:c[l++]>>5&3,switch:c[l++]>>6}},m=function(){var e=c[l++]<<8|c[l++],t=l+e;if(17!==c[l++])throw new Error("invalid DeviceSpecific const value:"+c[l-1]);return{data:c.subarray(l,l+=t-l)}};for(s=0,u=this.header.numberOfTracks;s<u;++s){if("trac"!==(e=String.fromCharCode(c[l++],c[l++],c[l++],c[l++])))throw new Error("invalid track signature:"+e);for(t=c[l++]<<24|c[l++]<<16|c[l++]<<8|c[l++],n=l+t,o=h[s]=[];l<n;){if((a={key:null,length:null,octaveShift:null,subType:null,type:null,value:{},velocity:null,voice:null}).deltaTime=c[l++],255!==(r=c[l++]))a.type="note",a.subType="Note",a.voice=r>>6,a.key=63&r,1===this.dataInformation.note&&(i=c[l++],a.velocity=i>>2,a.octaveShift=3&i);else switch(a.type="meta",(r=c[l++])>>4){case 11:switch(15&r){case 0:a.subType="MasterVolume",a.value=c[l++];break;case 10:a.subType="DrumScale",a.value={channel:c[l]>>3&7,drum:1&c[l++]};break;default:throw new Error("unknown message type:"+r.toString(16))}break;case 12:a.subType="SetTempo",a.value={timeBase:7==(7&r)?NaN:Math.pow(2,7&r)*(0==(8&r)?6:15),tempo:c[l++]};break;case 13:switch(15&r){case 0:a.subType="Point",a.value=c[l++];break;case 13:a.subType="Loop",a.value={id:c[l]>>6,count:c[l]>>2&15,point:3&c[l++]};break;case 14:a.subType="Nop",a.value=c[l++];break;case 15:a.subType="EndOfTrack",a.value=c[l++];break;default:throw new Error("unkwnon message type:"+r.toString(16))}break;case 14:switch(15&r){case 0:a.subType="InstrumentLowPart",a.value={part:c[l]>>6,instrument:63&c[l++]};break;case 1:a.subType="InstrumentHighPart",a.value={part:c[l]>>6,instrument:1&c[l++]};break;case 2:a.subType="Volume",a.value={part:c[l]>>6,volume:63&c[l++]};break;case 3:a.subType="Valance",a.value={part:c[l]>>6,valance:63&c[l++]};break;case 4:a.subType="PitchBend",a.value={part:c[l]>>6,value:63&c[l++]};break;case 5:a.subType="ChannelAssign",a.value={part:c[l]>>6,channel:63&c[l++]};break;case 6:a.subType="VolumeChange",a.value={part:c[l]>>6,volume:(63&c[l++])<<26>>26};break;case 7:a.subType="PitchBendRange",a.value={part:c[l]>>6,value:63&c[l++]};break;case 9:a.subType="MasterCoarseTuning",a.value={part:c[l]>>6,value:63&c[l++]};break;case 10:a.subType="Modulation",a.value={part:c[l]>>6,depth:63&c[l++]};break;default:throw new Error("unkwnon message type:"+r.toString(16))}break;case 15:switch(15&r){case 0:a.subType="EditInstrument",a.value=f();break;case 1:a.subType="Vibrato",a.value=p();break;case 15:a.subType="DeviceSpecific",a.value=m();break;default:throw new Error("unkwnon message type:"+r.toString(16))}break;default:throw new Error("unkwnon message type:"+r.toString(16))}o.push(a)}l=n}this.ip=l}},{key:"convertToMidiTracks",value:function(){this.timeDivision;var e,t,n,r,i,a,o,s,u,c,l,h,f,p,m=[],y=[],v=this.tracks,d=[];for(c=0;c<16;++c)y[c]=[],d[c]=0;for(c=0,l=v.length;c<l;++c){for(r=[],i=a=h=0,f=(e=v[c]).length;h<f;++h)switch(i+=(t=e[h]).deltaTime,t.id=a,t.time=i,t.subType){case"Nop":break;case"Note":r[a++]=t,r[a]={id:a,type:"internal",subType:"NoteOff",time:i+t.length,key:t.key,voice:t.voice,velocity:t.velocity,octaveShift:t.octaveShift},a++;break;case"InstrumentHighPart":if(n=t,"InstrumentLowPart"!==(t=e[++h]).subType)throw new Error("broken instrument");r[a]={id:a,type:"internal",subType:"ProgramChange",time:i,part:t.value.part,instrument:n.value.instrument<<6|t.value.instrument},a++;break;default:r[a++]=t}for(r.sort((function(e,t){return e.time>t.time?1:e.time<t.time?-1:e.id>t.id?1:e.id<t.id?-1:0})),m[c]=[],i=h=0,f=r.length;h<f;++h){switch(i=(t=r[h]).time,t.subType){case"Note":o=this.applyOctaveShift(t.key+45,t.octaveShift),9===(p=4*c+t.voice)&&(o-=10),y[p].push(this.deltaTimeToByteArray(i-d[p]).concat(144|p,o,2*t.velocity));break;case"NoteOff":o=this.applyOctaveShift(t.key+45,t.octaveShift),9===(p=4*c+t.voice)&&(o-=10),y[p].push(this.deltaTimeToByteArray(i-d[p]).concat(128|p,o,2*t.velocity));break;case"ProgramChange":y[p=4*c+t.part].push(this.deltaTimeToByteArray(i-d[p]).concat(192|p,t.instrument));break;case"SetTempo":s=288e7/(t.value.tempo*t.value.timeBase),y[p=0].push(this.deltaTimeToByteArray(i-d[p]).concat(255,81,3,s>>16&255,s>>8&255,255&s));break;case"Loop":s=t.value.count,u="LOOP_"+(0===t.value.point?"START":"END")+"=ID:"+t.value.id+",COUNT:"+(0===s?-1:s),y[p=0].push(this.deltaTimeToByteArray(i-d[p]).concat([255,6,u.length],u.split("").map((function(e){return e.charCodeAt(0)}))));break;case"MasterVolume":s=t.value,y[p=0].push(this.deltaTimeToByteArray(i-d[p]).concat(240,7,127,127,4,1,s,s,247));break;case"Modulation":y[p=4*c+t.value.part].push(this.deltaTimeToByteArray(i-d[p]).concat(176|p,1,2*t.value.depth));break;case"Volume":y[p=4*c+t.value.part].push(this.deltaTimeToByteArray(i-d[p]).concat(176|p,7,2*t.value.volume));break;case"Valance":y[p=4*c+t.value.part].push(this.deltaTimeToByteArray(i-d[p]).concat(176|p,10,2*(t.value.valance-32)+64));break;case"PitchBend":y[p=4*c+t.value.part].push(this.deltaTimeToByteArray(i-d[p]).concat(224|p,2*t.value.value,2*t.value.value));break;case"PitchBendRange":y[p=4*c+t.value.part].push(this.deltaTimeToByteArray(i-d[p]).concat(176|p,100,0),[0,176|p,101,0],[0,176|p,6,2*t.value.value]);break;case"MasterCoarseTuning":y[p=4*c+t.value.part].push(this.deltaTimeToByteArray(i-d[p]).concat(176|p,100,0),[0,176|p,101,2],[0,176|p,6,2*t.value.value]);break;default:continue}d[p]=t.time}}return this.toSMF(y)}},{key:"applyOctaveShift",value:function(e,t){var n=[0,12,-24,-12];if(void 0!==n[t])return e+n[t];throw new Error("invalid OctaveShift value:"+t)}},{key:"toSMF",value:function(e){var t,n,r,i,a,o,s=[77,84,104,100,0,0,0,6,0,1,0,16,0,48];if(void 0!==this.dataInformation.copy){var u=function(e){var t,n=e.length,r=new Array(n);for(t=0;t<n;++t)r[t]=e.charCodeAt(t);return r}(this.dataInformation.copy);i=u.length,u=[0,255,2].concat(this.deltaTimeToByteArray(i),u),e[0].unshift(u)}for(r=0,i=e.length;r<i;++r){var c=e[r];for(n=[],a=0,o=c.length;a<o;++a)Array.prototype.push.apply(n,c[a]);t=[77,84,114,107,(o=n.length)>>24&255,o>>16&255,o>>8&255,255&o],s=s.concat(t,n)}return new Uint8Array(s)}},{key:"deltaTimeToByteArray",value:function(e){for(var t=[];e>=128;)t.unshift(127&e|(0===t.length?0:128)),e>>>=7;return t.unshift(e|(0===t.length?0:128)),t}}])&&i(t.prototype,n),a&&i(t,a),e}()},418:(e,t,n)=>{"use strict";n.d(t,{Z:()=>y});var r=n(579),i=n(888),a=n(994);function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,i,a=[],o=!0,s=!1;try{for(n=n.call(e);!(o=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);o=!0);}catch(e){s=!0,i=e}finally{try{o||null==n.return||n.return()}finally{if(s)throw i}}return a}(e,t)||function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function h(e,t){return h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},h(e,t)}function f(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=m(e);if(t){var i=m(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return p(this,n)}}function p(e,t){if(t&&("object"===o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}var y=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&h(e,t)}(u,e);var t,n,i,o=f(u);function u(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return c(this,u),(t=o.call(this,e,n)).input=String.fromCharCode.apply("",new Uint16Array(e)).split(/\r\n|\r|\n/)||[],t.tracks=[],t.plainTracks=[],t.numberOfTracks=1,t.timeDivision=n.timeDivision||96,t}return t=u,(n=[{key:"parse",value:function(){this.parseHeader(),this.parseTracks(),this.toPlainTrack()}},{key:"parseHeader",value:function(){this.encoder=new TextEncoder("utf-8");var e=["mml-track","name","program","songProgram","panpot"],t={},n=-1;t.track=[];for(var r=0;r<this.input.length;r++){var i=this.input[r].trim();if(0!==r){var o=s(i.split("="),2),u=o[0],c=o[1];e.includes(u)?"mml-track"===u?(n++,t.track[n]={},t.track[n].mml=c):t.track[n][u]="name"===u?c:0|c:t[u]=c}else if("[mml-score]"!==i)throw new Error("Not MabiIcco File.")}this.title=t.title,this.author=t.author;var l=""!==t.tempo?t.tempo.split("T"):[0,120];this.timeDivision=96,this.tempo=0|l[1];var h=t.time.split("/"),f=[];f.push(new a.Sj("SystemExclusive",0,0,[126,127,9,1])),f.push(new a.FL("SequenceTrackName",0,0,[this.title])),f.push(new a.FL("CopyrightNotice",0,0,[this.author])),f.push(new a.FL("TimeSignature",0,0,[0|h[0]||4,0|h[1]||4,0,0])),f.push(new a.FL("SetTempo",0,0,[Math.floor(6e7/this.tempo)])),f.push(new a.FL("EndOfTrack",0,0)),this.tracks.push(f),this.input=t.track}},{key:"parseTracks",value:function(){for(var e=[],t=[],n=0;n<this.input.length;n++){var i=this.input[n];if(i.mml.match(/^(?:MML@)(.*)/gm)){var o=RegExp.$1.split(",");e.push(new a.FL("InsturumentName",0,48,[i.name])),e.push(new a.gQ("ProgramChange",0,96,n,i.program)),-1!==i.songProgram&&e.push(new a.gQ("ProgramChange",0,112,15,i.songProgram)),e.push(new a.gQ("ControlChange",0,154,n,10,i.panpot));for(var s=0;s<i.mml.length;s++){var u=n;if(3===s&&-1!==i.songProgram&&(u=15),void 0!==o[s]){var c=new r.Z({timeDivision:this.timeDivision,channel:u,timeOffset:386,mml:o[s],igonoreTempo:1===u});e=e.concat(c.events),t.push(c.endTime)}}e.concat(new a.FL("EndOfTrack",0,Math.max(t))),this.tracks.push(e)}}this.numberOfTracks=this.tracks.length}}])&&l(t.prototype,n),i&&l(t,i),u}(i.Z)},888:(e,t,n)=>{"use strict";n.d(t,{Z:()=>h});var r=n(579),i=n(915),a=n.n(i),o=n(994);function s(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var h=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};c(this,e);var r=String.fromCharCode.apply("",new Uint16Array(t));this.input=a().parse(r)||{},this.tracks=[],this.plainTracks=[],this.numberOfTracks=1,this.timeDivision=n.timeDivision||96}var t,n,i;return t=e,(n=[{key:"parse",value:function(){this.parseHeader(),this.parseTracks(),this.toPlainTrack()}},{key:"parseHeader",value:function(){this.encoder=new TextEncoder("shift_jis");var e=this.input.infomation;this.title=e.title,this.author=e.auther,this.timeDivision=0|e.timeBase||96,this.mmsInstTable=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,65,66,67,68,69,70,71,72,73,74,75,76,18];var t=[];t.push(new o.Sj("SystemExclusive",0,0,[126,127,9,1])),t.push(new o.FL("SequenceTrackName",0,0,[this.title])),t.push(new o.FL("CopyrightNotice",0,0,[this.author])),t.push(new o.FL("TimeSignature",0,0,[0|e.rythmNum||4,0|e.rythmBase||4,0,0])),t.push(new o.FL("EndOfTrack",0,0)),this.tracks.push(t),delete this.input.infomation,delete this.input["mms-file"]}},{key:"parseTracks",value:function(){var e=[],t=[],n=0;for(var i in this.input)if(Object.prototype.hasOwnProperty.call(this.input,i)){var a=this.input[i],s=[a.ch0_mml,a.ch1_mml,a.ch2_mml],u=Number(a.panpot)+64;for(var c in e.push(new o.FL("InsturumentName",0,48,[a.name])),e.push(new o.gQ("ProgramChange",0,96,n,0|this.mmsInstTable[a.instrument])),e.push(new o.gQ("ControlChange",0,154,n,10,u)),s)if(Object.prototype.hasOwnProperty.call(s,c)){var l=new r.Z({timeDivision:this.timeDivision,channel:n,timeOffset:386,mml:s[c]});e=e.concat(l.events),t.push(l.endTime)}n++,e.concat(new o.FL("EndOfTrack",0,Math.max(t))),this.tracks.push(e)}this.numberOfTracks=this.tracks.length}},{key:"toPlainTrack",value:function(){for(var e=0;e<this.tracks.length;e++){var t,n=[],r=[],i=s(this.tracks[e]);try{for(i.s();!(t=i.n()).done;){var a=t.value,u=void 0;if(a instanceof o.gQ)switch(a.subtype){case"NoteOn":u=0===a.parameter2?new Uint8Array([128|a.channel,a.parameter1,a.parameter2]):new Uint8Array([144|a.channel,a.parameter1,a.parameter2]);break;case"NoteOff":u=new Uint8Array([128|a.channel,a.parameter1,a.parameter2]);break;case"ControlChange":u=new Uint8Array([176|a.channel,a.parameter1,a.parameter2]);break;case"ProgramChange":u=new Uint8Array([192|a.channel,a.parameter1])}else if(a instanceof o.FL){var c=this.encoder.encode(a.data);switch(a.subtype){case"TextEvent":u=new Uint8Array([255,1].concat(c));break;case"SequenceTrackName":u=new Uint8Array([255,3].concat(c));break;case"CopyrightNotice":u=new Uint8Array([255,2].concat(c));break;case"InsturumentName":u=new Uint8Array([255,4].concat(c));break;case"SetTempo":u=new Uint8Array([255,81].concat(c));break;case"TimeSignature":u=new Uint8Array([255,88].concat(c));break;case"EndOfTrack":u=new Uint8Array([255,47])}}else a instanceof o.Sj&&(u=new Uint8Array([240,5].concat(a.data)));r=r.concat(u)}}catch(e){i.e(e)}finally{i.f()}n=n.concat(r),this.plainTracks[e]=n}}}])&&l(t.prototype,n),i&&l(t,i),e}()},225:(e,t,n)=>{"use strict";n.d(t,{Z:()=>y});var r=n(579),i=n(888),a=n(994);function o(e){return o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},o(e)}function s(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return u(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return u(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,i=function(){};return{s:i,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){s=!0,a=e},f:function(){try{o||null==n.return||n.return()}finally{if(s)throw a}}}}function u(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function h(e,t){return h=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},h(e,t)}function f(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,r=m(e);if(t){var i=m(this).constructor;n=Reflect.construct(r,arguments,i)}else n=r.apply(this,arguments);return p(this,n)}}function p(e,t){if(t&&("object"===o(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}var y=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&h(e,t)}(u,e);var t,n,i,o=f(u);function u(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};c(this,u),(t=o.call(this,e,n)).encoder=new TextEncoder("utf-8");var r=new DOMParser,i=r.parseFromString(String.fromCharCode.apply("",new Uint16Array(e)),"text/xml");return t.input=i.querySelectorAll("ms2 > *"),t.tracks=[],t.plainTracks=[],t.numberOfTracks=1,t.timeDivision=n.timeDivision||96,t}return t=u,(n=[{key:"parse",value:function(){this.parseTracks(),this.toPlainTrack()}},{key:"parseTracks",value:function(){var e,t=[],n=[],i=s(this.input);try{for(i.s();!(e=i.n()).done;){var o=e.value,u=new r.Z({timeDivision:this.timeDivision,channel:0,mml:this.input[o].textContent.trim(),ignoreTempo:!1});t=t.concat(u.events),n.push(u.endTime)}}catch(e){i.e(e)}finally{i.f()}t.concat(new a.FL("EndOfTrack",0,Math.max(n))),this.tracks.push(t)}}])&&l(t.prototype,n),i&&l(t,i),u}(i.Z)},135:(e,t,n)=>{"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}n.d(t,{Z:()=>a});var a=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};r(this,e),this.input=t,this.ip=n.index||0,this.length=n.length||t.length-this.ip,this.chunkList=[],this.offset=this.ip,this.padding=void 0===n.padding||n.padding,this.bigEndian=void 0!==n.bigEndian&&n.bigEndian}var t,n,a;return t=e,(n=[{key:"parse",value:function(){var e=this.length+this.offset;for(this.chunkList=[];this.ip<e;)this.parseChunk()}},{key:"parseChunk",value:function(){var e,t=this.input,n=this.ip;this.chunkList.push(new o(String.fromCharCode(t[n++],t[n++],t[n++],t[n++]),e=this.bigEndian?(t[n++]<<24|t[n++]<<16|t[n++]<<8|t[n++])>>>0:(t[n++]|t[n++]<<8|t[n++]<<16|t[n++]<<24)>>>0,n)),n+=e,this.padding&&1==(n-this.offset&1)&&n++,this.ip=n}},{key:"getChunk",value:function(e){var t=this.chunkList[e];return void 0===t?null:t}},{key:"getNumberOfChunks",value:function(){return this.chunkList.length}}])&&i(t.prototype,n),a&&i(t,a),e}(),o=function e(t,n,i){r(this,e),this.type=t,this.size=n,this.offset=i}},782:(e,t,n)=>{"use strict";n.d(t,{default:()=>u});var r=n(994),i=n(656),a=n(135);function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var u=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};o(this,e),n.padding=!1,n.bigEndian=!0,this.input=t,this.ip=n.index||0,this.chunkIndex=0,this.riffParser_=new a.Z(t,n),this.formatType=0,this.numberOfTracks=0,this.timeDivision=480,this.tracks=[],this.plainTracks=[],this.version=i.Z.version,this.build=i.Z.build}var t,n,u;return t=e,(n=[{key:"parse",value:function(){var e,t=0;for(this.riffParser_.parse(),this.parseHeaderChunk(),t=0,e=this.numberOfTracks;t<e;++t)this.parseTrackChunk()}},{key:"parseHeaderChunk",value:function(){var e=this.riffParser_.getChunk(this.chunkIndex++),t=this.input,n=e.offset;if(!e||"MThd"!==e.type)throw new Error("invalid header signature");this.formatType=t[n++]<<8|t[n++],this.numberOfTracks=t[n++]<<8|t[n++],this.timeDivision=t[n++]<<8|t[n++]}},{key:"parseTrackChunk",value:function(){var e,t,n,i=this.riffParser_.getChunk(this.chunkIndex++),a=this.input,o=i.offset,s=0,u=0,c=0,l=-1,h=-1,f=0,p=0,m=0,y=0,v=0,d=function(){var e=0;f=0;do{e=e<<7|127&(f=a[o++])}while(0!=(128&f));return e};if(!i||"MTrk"!==i.type)throw new Error("invalid header signature");e=i.offset+i.size;for(var b=[],g=[];o<e;){p+=s=d(),m=o,c=15&(v=a[o++]),(u=v>>4&15)<8?(u=l,c=h,v=l<<4|h,o--,m--):(l=u,h=c);var k=[null,null,null,null,null,null,null,null,"NoteOff","NoteOn","NoteAftertouch","ControlChange","ProgramChange","ChannelAftertouch","PitchBend"];switch(u){case 8:case 9:case 10:case 11:case 13:case 14:t=new r.gQ(k[u],s,p,c,a[o++],a[o++]);break;case 12:t=new r.gQ(k[u],s,p,c,a[o++]);break;case 15:switch(c){case 0:if(f=d(),247!==a[o+f-1])throw new Error("invalid SysEx event");t=new r.Sj("SystemExclusive",s,p,a.subarray(o,(o+=f)-1));break;case 7:f=d(),t=new r.Sj("SystemExclusive(F7)",s,p,a.subarray(o,o+=f));break;case 15:switch(u=a[o++],f=d(),u){case 0:t=new r.FL("SequenceNumber",s,p,[a[o++],a[o++]]);break;case 1:t=new r.FL("TextEvent",s,p,[String.fromCharCode.apply(null,a.subarray(o,o+=f))]);break;case 2:t=new r.FL("CopyrightNotice",s,p,[String.fromCharCode.apply(null,a.subarray(o,o+=f))]);break;case 3:t=new r.FL("SequenceTrackName",s,p,[String.fromCharCode.apply(null,a.subarray(o,o+=f))]);break;case 4:t=new r.FL("InstrumentName",s,p,[String.fromCharCode.apply(null,a.subarray(o,o+=f))]);break;case 5:t=new r.FL("Lyrics",s,p,[String.fromCharCode.apply(null,a.subarray(o,o+=f))]);break;case 6:t=new r.FL("Marker",s,p,[String.fromCharCode.apply(null,a.subarray(o,o+=f))]);break;case 7:t=new r.FL("CuePoint",s,p,[String.fromCharCode.apply(null,a.subarray(o,o+=f))]);break;case 32:t=new r.FL("MidiChannelPrefix",s,p,[a[o++]]);break;case 47:t=new r.FL("EndOfTrack",s,p,[]);break;case 81:t=new r.FL("SetTempo",s,p,[a[o++]<<16|a[o++]<<8|a[o++]]);break;case 84:t=new r.FL("SmpteOffset",s,p,[a[o++],a[o++],a[o++],a[o++],a[o++]]);break;case 88:t=new r.FL("TimeSignature",s,p,[a[o++],a[o++],a[o++],a[o++]]);break;case 89:t=new r.FL("KeySignature",s,p,[a[o++],a[o++]]);break;case 127:t=new r.FL("SequencerSpecific",s,p,[a.subarray(o,o+=f)]);break;default:t=new r.FL("Unknown",s,p,[u,a.subarray(o,o+=f)])}}break;default:throw new Error("invalid status")}y=o-m,(n=a.subarray(m,m+y))[0]=v,t instanceof r.gQ&&"NoteOn"===t.subtype&&0===t.parameter2&&(t.subtype=k[8],n=new Uint8Array([128|t.channel,t.parameter1,t.parameter2])),g.push(n),b.push(t)}this.tracks.push(b),this.plainTracks.push(g)}}])&&s(t.prototype,n),u&&s(t,u),e}()},915:e=>{const{hasOwnProperty:t}=Object.prototype,n="undefined"!=typeof process&&"win32"===process.platform?"\r\n":"\n",r=(e,t)=>{const a=[];let o="";"string"==typeof t?t={section:t,whitespace:!1}:(t=t||Object.create(null)).whitespace=!0===t.whitespace;const u=t.whitespace?" = ":"=";for(const t of Object.keys(e)){const r=e[t];if(r&&Array.isArray(r))for(const e of r)o+=s(t+"[]")+u+s(e)+"\n";else r&&"object"==typeof r?a.push(t):o+=s(t)+u+s(r)+n}t.section&&o.length&&(o="["+s(t.section)+"]"+n+o);for(const s of a){const a=i(s).join("\\."),u=(t.section?t.section+".":"")+a,{whitespace:c}=t,l=r(e[s],{section:u,whitespace:c});o.length&&l.length&&(o+=n),o+=l}return o},i=e=>e.replace(/\1/g,"LITERAL\\1LITERAL").replace(/\\\./g,"").split(/\./).map((e=>e.replace(/\1/g,"\\.").replace(/\2LITERAL\\1LITERAL\2/g,""))),a=e=>{const n=Object.create(null);let r=n,a=null;const o=/^\[([^\]]*)\]$|^([^=]+)(=(.*))?$/i,s=e.split(/[\r\n]+/g);for(const e of s){if(!e||e.match(/^\s*[;#]/))continue;const i=e.match(o);if(!i)continue;if(void 0!==i[1]){if(a=u(i[1]),"__proto__"===a){r=Object.create(null);continue}r=n[a]=n[a]||Object.create(null);continue}const s=u(i[2]),c=s.length>2&&"[]"===s.slice(-2),l=c?s.slice(0,-2):s;if("__proto__"===l)continue;const h=!i[3]||u(i[4]),f="true"===h||"false"===h||"null"===h?JSON.parse(h):h;c&&(t.call(r,l)?Array.isArray(r[l])||(r[l]=[r[l]]):r[l]=[]),Array.isArray(r[l])?r[l].push(f):r[l]=f}const c=[];for(const e of Object.keys(n)){if(!t.call(n,e)||"object"!=typeof n[e]||Array.isArray(n[e]))continue;const r=i(e);let a=n;const o=r.pop(),s=o.replace(/\\\./g,".");for(const e of r)"__proto__"!==e&&(t.call(a,e)&&"object"==typeof a[e]||(a[e]=Object.create(null)),a=a[e]);a===n&&s===o||(a[s]=n[e],c.push(e))}for(const e of c)delete n[e];return n},o=e=>'"'===e.charAt(0)&&'"'===e.slice(-1)||"'"===e.charAt(0)&&"'"===e.slice(-1),s=e=>"string"!=typeof e||e.match(/[=\r\n]/)||e.match(/^\[/)||e.length>1&&o(e)||e!==e.trim()?JSON.stringify(e):e.replace(/;/g,"\\;").replace(/#/g,"\\#"),u=(e,t)=>{if(e=(e||"").trim(),!o(e)){let t=!1,n="";for(let r=0,i=e.length;r<i;r++){const i=e.charAt(r);if(t)-1!=="\\;#".indexOf(i)?n+=i:n+="\\"+i,t=!1;else{if(-1!==";#".indexOf(i))break;"\\"===i?t=!0:n+=i}}return t&&(n+="\\"),n.trim()}"'"===e.charAt(0)&&(e=e.substr(1,e.length-2));try{e=JSON.parse(e)}catch(e){}return e};e.exports={parse:a,decode:a,stringify:r,encode:r,safe:s,unsafe:u}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var a=t[r]={exports:{}};return e[r](a,a.exports,n),a.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";n.r(r),n.d(r,{Player:()=>h});var e=n(418),t=n(888),i=n(225),a=n(656),o=n(764),s=n(782),u=n(454);function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function l(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var h=function(){function n(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"#wml";c(this,n),this.tempo=5e5,this.webMidiLink=null,this.resume=0,this.pause=!0,this.ready=!1,this.position=0,this.track=[],this.timer=0,this.sequence={},this.enableCC111Loop=!1,this.enableFalcomLoop=!1,this.enableMFiLoop=!1,this.enableLoop=!1,this.tempoRate=1,this.masterVolume=16383,this.textEvent="",this.sequenceName="",this.copyright="",this.lyrics="",this.webMidiLink=null,this.length=0,this.time=0,this.timeTotal=0,this.loaded=0,this.window=window,this.target=this.window.document.querySelector(e),this.version=a.Z.version,this.build=a.Z.build}var r,h,f;return r=n,h=[{key:"setCC111Loop",value:function(e){this.enableCC111Loop=e}},{key:"setFalcomLoop",value:function(e){this.enableFalcomLoop=e}},{key:"setMFiLoop",value:function(e){this.enableMFiLoop=e}},{key:"setLoop",value:function(e){this.enableLoop=e}},{key:"stop",value:function(){var e;if(this.pause=!0,this.resume=window.performance.now(),this.webMidiLink)for(e=0;e<16;++e)this.webMidiLink.contentWindow.postMessage("midi,b"+e.toString(16)+",78,0","*")}},{key:"getWebMidiLink",value:function(){return this.webMidiLink}},{key:"init",value:function(){this.stop(),this.initSequence(),this.pause=!0,this.track=null,this.resume=-1,this.text=null,this.sequence=null,this.sequenceName=null,this.copyright=null,this.lyrics=null,this.textEvent=null,this.length=0,this.position=0,this.time=0,this.timeTotal=0,this.window.clearTimeout(this.timer);var e=this;this.ready?this.sendInitMessage():this.window.addEventListener("message",(function(t){"link,ready"===t.data&&e.sendInitMessage()}),!1)}},{key:"initSequence",value:function(){this.tempo=5e5,this.position=0,this.sendInitMessage(),this.pause=!1}},{key:"play",value:function(){var e=this,t=this;if(!this.webMidiLink)throw new Error("WebMidiLink not found");this.ready?this.track&&(this.length=this.track.length,this.track instanceof Array&&this.position>=this.length&&(this.position=0),this.playSequence()):this.window.addEventListener("message",(function(n){"link,ready"===n.data&&(t.ready=!0,t.webMidiLink.style.height=e.webMidiLink.contentWindow.document.body.scrollHeight+"px",t.playSequence())}),!1)}},{key:"onSequenceEnd",value:function(){this.webMidiLink.contentWindow.postMessage("endoftrack","*")}},{key:"sendInitMessage",value:function(){var e,t=this.webMidiLink.contentWindow;for(e=0;e<16;++e)t.postMessage("midi,b"+e.toString(16)+",128,0","*"),t.postMessage("midi,b"+e.toString(16)+",07,64","*"),t.postMessage("midi,b"+e.toString(16)+",0a,40","*"),t.postMessage("midi,e"+e.toString(16)+",00,40","*"),t.postMessage("midi,b"+e.toString(16)+",64,00","*"),t.postMessage("midi,b"+e.toString(16)+",65,00","*"),t.postMessage("midi,b"+e.toString(16)+",06,02","*"),t.postMessage("midi,b"+e.toString(16)+",26,00","*");this.sendGmReset()}},{key:"setWebMidiLink",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"./wml.html",n=this,r=function(e){if("string"==typeof e.data){var t=e.data.split(",");"link"===t[0]&&("ready"===t[1]?(n.ready=!0,n.loaded=100,n.setMasterVolume(n.masterVolume)):"progress"===t[1]&&(n.loaded=Math.round(t[2]/t[3]*1e4)))}};if("string"==typeof t){this.webMidiLink&&this.webMidiLink.parentNode.removeChild(this.webMidiLink),this.target.firstChild&&this.target.removeChild(this.target.firstChild);var i=this.webMidiLink=this.window.document.createElement("iframe");i.src=t,i.className="wml",this.target.appendChild(i),this.window.addEventListener("message",r,!1);var a=function(){i.style.height=e.webMidiLink.contentWindow.document.body.scrollHeight+"px"};this.window.addEventListener("load",a,!1);var o=0;this.window.addEventListener("resize",(function(){o>0&&clearTimeout(o),o=setTimeout(a,100)}),!1)}else this.webMidiLink.addEventListener("message",r,!1)}},{key:"setMasterVolume",value:function(e){this.masterVolume=e,this.webMidiLink&&this.webMidiLink.contentWindow.postMessage("midi,f0,7f,7f,04,01,"+[("0"+(127&e).toString(16)).substr(-2),("0"+(e>>7&127).toString(16)).substr(-2),"7f"].join(","),"*")}},{key:"setTempoRate",value:function(e){this.tempoRate=e}},{key:"playSequence",value:function(){var e=this,t=this,n=this.sequence.timeDivision,r=this.track,i=this.webMidiLink.contentWindow,a=this.position||0,o=[],s=function s(){var u,c,l,h=r[a].time,f=r.length,p=window.performance.now();if(!t.pause){do{switch((u=r[a].event).subtype){case"TextEvent":t.textEvent=u.data[0];break;case"Lyrics":t.lyrics=u.data[0];break;case"Maker":if(t.enableFalcomLoop)switch(u.data[0]){case"A":o[0]={pos:a};break;case"B":if(o[0]&&"number"==typeof o[0].pos)return a=o[0].pos,t.timer=t.window.setTimeout(s,0),void(t.position=a)}if(t.enableMFiLoop&&(c=u.data[0].match(/^LOOP_(START|END)=ID:(\d+),COUNT:(-?\d+)$/)))if("START"===c[1])o[0|c[2]]=o[c[2]]||{pos:a,count:0|c[3]};else if("END"===c[1]&&t.enableMFiLoop){if(0!==(l=o[0|c[2]]).count)return l.count>0&&l.count--,a=l.pos,t.timer=t.window.setTimeout(s,0),void(t.position=a);o[0|c[2]]=null}break;case"SetTempo":t.tempo=u.data[0]}"ControlChange"===u.subtype&&111===u.parameter1&&(o[0]={pos:a}),i.postMessage(r[a++].webMidiLink,"*")}while(a<f&&r[a].time===h);return a<f?(p=window.performance.now()-p,t.timer=t.window.setTimeout(s,t.tempo/(1e3*n)*(r[a].time-h-p)*(1/t.tempoRate))):(t.pause=!0,t.enableCC111Loop&&o[0]&&"number"==typeof o[0].pos?a=o[0].pos:t.enableLoop&&(t.initSequence(),t.playSequence())),t.position=a,t.time=h,e.timeTotal===h?(e.onSequenceEnd(),2):void 0}t.resume=p-t.resume};this.pause?(this.timer=t.window.setTimeout(s,this.resume),this.pause=!1,this.resume=-1):this.timer=t.window.setTimeout(s,this.tempo/1e3*n*this.track[0].time)}},{key:"loadMidiFile",value:function(e){var t=new s.default(e);this.init(),t.parse(),this.mergeMidiTracks(t)}},{key:"loadMldFile",value:function(e){var t=new o.Z(e);this.init(),t.parse(),this.mergeMidiTracks(t.convertToMidiTracks())}},{key:"loadMs2MmlFile",value:function(e){var t=new i.Z(e);this.init(),t.parse(),this.mergeMidiTracks(t)}},{key:"loadMakiMabiSequenceFile",value:function(e){var n=new t.Z(e);this.init(),n.parse(),this.mergeMidiTracks(n)}},{key:"load3MleFile",value:function(e){var t=new u.Z(e);this.init(),t.parse(),this.mergeMidiTracks(t)}},{key:"loadMabiIccoFile",value:function(t){var n=new e.Z(t);this.init(),n.parse(),this.mergeMidiTracks(n)}},{key:"mergeMidiTracks",value:function(e){var t,n,r,i,a,o=this.track=[],s=e.tracks,u=new Array(s.length),c=e.plainTracks;for(n=0,r=s.length;n<r;++n)u[n]=0;for(n=0,r=s.length;n<r;++n)for(i=0,a=(t=s[n]).length;i<a;++i)0!==e.formatType&&0!==n||("SequenceTrackName"===t[i].subtype?this.sequenceName=t[i].data[0]:"CopyrightNotice"===t[i].subtype&&(this.copyright=t[i].data[0])),o.push({track:n,eventId:i,time:t[i].time,event:t[i],webMidiLink:"midi,"+Array.prototype.map.call(c[n][i],(function(e){return e.toString(16)})).join(",")});o.sort((function(e,t){return e.time>t.time?1:e.time<t.time?-1:e.track>t.track?1:e.track<t.track?-1:e.eventId>t.eventId?1:e.eventId<t.eventId?-1:0})),this.timeTotal=o.slice(-1)[0].time,this.sequence=e}},{key:"getSequenceName",value:function(){return this.sequenceName}},{key:"getCopyright",value:function(){return this.copyright}},{key:"getLyrics",value:function(){return this.lyrics}},{key:"getTextEvent",value:function(){return this.textEvent}},{key:"getPosition",value:function(){return this.position}},{key:"setPosition",value:function(e){this.position=e}},{key:"getLength",value:function(){return this.length}},{key:"sendGmReset",value:function(){this.webMidiLink&&this.webMidiLink.contentWindow.postMessage("midi,F0,7E,7F,09,01,F7","*")}},{key:"sendAllSoundOff",value:function(){this.webMidiLink&&this.webMidiLink.contentWindow.postMessage("midi,b0,78,0","*")}},{key:"getTempo",value:function(){return Math.floor(60/(this.tempo/1e6))}},{key:"tick2time",value:function(e){var t=e*(this.tempo/1e6/this.sequence.timeDivision)|0,n=t%3600,r=n%60;return Math.floor(t/3600)+":"+Math.floor(n/60).toString().padStart(2,"0")+":"+Math.ceil(r).toString().padStart(2,"0")}},{key:"getTime",value:function(){return this.tick2time(this.time)}},{key:"getTotalTime",value:function(){return this.tick2time(this.timeTotal)}}],h&&l(r.prototype,h),f&&l(r,f),n}()})(),r})()}));