midi-audio-player 1.1.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +472 -86
- package/dist/index.js +1733 -232
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +4 -4
- package/dist/midi-audio-player.js +1732 -232
- package/dist/midi-audio-player.min.js +13 -14
- package/index.d.ts +905 -0
- package/index.js +0 -1
- package/package.json +21 -18
- package/src/libraries/audiocompressor.js +186 -0
- package/src/libraries/indexeddbstorage.js +107 -0
- package/src/midiaudioplayer.js +1378 -51
- package/bin/cli.js +0 -27
- package/dist/midi-audio-player.js.map +0 -7
- package/dist/midi-audio-player.min.js.map +0 -7
- package/src/downloader.js +0 -33
- package/src/presets/defaultpreset.json +0 -116
- package/src/webaudiofontplayer.js +0 -264
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
███╗ ███╗██╗██████╗ ██╗ █████╗ ██╗ ██╗██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗ ██╗ ██╗███████╗██████╗
|
|
4
|
+
████╗ ████║██║██╔══██╗██║██╔══██╗██║ ██║██╔══██╗██║██╔═══██╗██╔══██╗██║ ██╔══██╗╚██╗ ██╔╝██╔════╝██╔══██╗
|
|
5
|
+
██╔████╔██║██║██║ ██║██║███████║██║ ██║██║ ██║██║██║ ██║██████╔╝██║ ███████║ ╚████╔╝ █████╗ ██████╔╝
|
|
6
|
+
██║╚██╔╝██║██║██║ ██║██║██╔══██║██║ ██║██║ ██║██║██║ ██║██╔═══╝ ██║ ██╔══██║ ╚██╔╝ ██╔══╝ ██╔══██╗
|
|
7
|
+
██║ ╚═╝ ██║██║██████╔╝██║██║ ██║╚██████╔╝██████╔╝██║╚██████╔╝██║ ███████╗██║ ██║ ██║ ███████╗██║ ██║
|
|
8
|
+
╚═╝ ╚═╝╚═╝╚═════╝ ╚═╝╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝
|
|
9
|
+
|
|
10
|
+
Version: 2.0.1
|
|
11
|
+
Build: 2026-05-31 02:44:14
|
|
12
|
+
Author: Maxime Larrivée-Roy <mlarriveeroy@gmail.com>
|
|
13
|
+
Github: https://github.com/webaudiofonts/midi-audio-player/
|
|
14
|
+
Website: https://webaudiofonts.com/midiaudioplayer/
|
|
9
15
|
|
|
10
|
-
Version: 1.1.2
|
|
11
|
-
Généré: 2026-05-10 00:19:40
|
|
12
|
-
Auteur: Maxime Larrivée-Roy <mlarriveeroy@gmail.com>
|
|
13
|
-
Github: https://github.com/ZmotriN/midi-audio-player/
|
|
14
|
-
Website: https://zmotrin.github.io/midi-audio-player/
|
|
15
|
-
|
|
16
16
|
*/
|
|
17
|
-
(()=>{function k(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}function v(n,t){for(var V=0;V<t.length;V++){var q=t[V];q.enumerable=q.enumerable||!1,q.configurable=!0,"value"in q&&(q.writable=!0),Object.defineProperty(n,q.key,q)}}function b(n,t,V){return t&&v(n.prototype,t),V&&v(n,V),Object.defineProperty(n,"prototype",{writable:!1}),n}var c={VERSION:"2.0.17",NOTES:[],HEADER_CHUNK_LENGTH:14,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#"]},E=[["C"],["C#","Db"],["D"],["D#","Eb"],["E"],["F"],["F#","Gb"],["G"],["G#","Ab"],["A"],["A#","Bb"],["B"]],M=0,w=function(t){E.forEach(function(V){V.forEach(function(q){return c.NOTES[M]=q+t}),M++})};for(T=-1;T<=9;T++)w(T);var T,r=(function(){function n(){k(this,n)}return b(n,null,[{key:"byteToHex",value:function(V){return("0"+V.toString(16)).slice(-2)}},{key:"bytesToHex",value:function(V){var q=[];return V.forEach(function(e){return q.push(n.byteToHex(e))}),q.join("")}},{key:"hexToNumber",value:function(V){return parseInt(V,16)}},{key:"bytesToNumber",value:function(V){return n.hexToNumber(n.bytesToHex(V))}},{key:"bytesToLetters",value:function(V){var q=[];return V.forEach(function(e){return q.push(String.fromCharCode(e))}),q.join("")}},{key:"decToBinary",value:function(V){return(V>>>0).toString(2)}},{key:"getVarIntLength",value:function(V){for(var q=V[0],e=1;q>=128;)q=V[e],e++;return e}},{key:"readVarInt",value:function(V){var q=0;return V.forEach(function(e){var a=e;a&128?(q+=a&127,q<<=7):q+=a}),q}},{key:"atob",value:(function(t){function V(q){return t.apply(this,arguments)}return V.toString=function(){return t.toString()},V})(function(t){return typeof atob=="function"?atob(t):Buffer.from(t,"base64").toString("binary")})}]),n})(),U=(function(){function n(t,V){k(this,n),this.enabled=!0,this.eventIndex=0,this.pointer=0,this.lastTick=0,this.lastStatus=null,this.index=t,this.data=V,this.delta=0,this.runningDelta=0,this.events=[];var q=this.data.subarray(this.data.length-3,this.data.length);if(!(q[0]===255&&q[1]===47&&q[2]===0))throw"Invalid MIDI file; Last three bytes of track "+this.index+"must be FF 2F 00 to mark end of track"}return b(n,[{key:"reset",value:function(){return this.enabled=!0,this.eventIndex=0,this.pointer=0,this.lastTick=0,this.lastStatus=null,this.delta=0,this.runningDelta=0,this}},{key:"enable",value:function(){return this.enabled=!0,this}},{key:"disable",value:function(){return this.enabled=!1,this}},{key:"setEventIndexByTick",value:function(V){V=V||0;for(var q=0;q<this.events.length;q++)if(this.events[q].tick>=V)return this.eventIndex=q,this}},{key:"getCurrentByte",value:function(){return this.data[this.pointer]}},{key:"getDeltaByteCount",value:function(){return r.getVarIntLength(this.data.subarray(this.pointer))}},{key:"getDelta",value:function(){return r.readVarInt(this.data.subarray(this.pointer,this.pointer+this.getDeltaByteCount()))}},{key:"handleEvent",value:function(V,q){if(q=q||!1,q){var e=V-this.lastTick,a=this.getDelta(),A=e>=a;if(this.pointer<this.data.length&&(q||A)){var i=this.parseEvent();if(this.enabled)return i}}else{for(var s=[];this.events[this.eventIndex]&&this.events[this.eventIndex].tick<=V;)this.enabled&&s.push(this.events[this.eventIndex]),this.eventIndex++;if(s.length>0)return s}return null}},{key:"getStringData",value:function(V){var q=r.getVarIntLength(this.data.subarray(V+2)),e=r.readVarInt(this.data.subarray(V+2,V+2+q)),a=r.bytesToLetters(this.data.subarray(V+2+q,V+2+q+e));return a}},{key:"parseEvent",value:function(){var V=this.pointer+this.getDeltaByteCount(),q={},e=this.getDeltaByteCount();if(q.track=this.index+1,q.delta=this.getDelta(),this.lastTick=this.lastTick+q.delta,this.runningDelta+=q.delta,q.tick=this.runningDelta,q.byteIndex=this.pointer,this.data[V]==255){switch(this.data[V+1]){case 0:q.name="Sequence Number";break;case 1:q.name="Text Event",q.string=this.getStringData(V);break;case 2:q.name="Copyright Notice";break;case 3:q.name="Sequence/Track Name",q.string=this.getStringData(V);break;case 4:q.name="Instrument Name",q.string=this.getStringData(V);break;case 5:q.name="Lyric",q.string=this.getStringData(V);break;case 6:q.name="Marker",q.string=this.getStringData(V);break;case 7:q.name="Cue Point",q.string=this.getStringData(V);break;case 9:q.name="Device Name",q.string=this.getStringData(V);break;case 32:q.name="MIDI Channel Prefix";break;case 33:q.name="MIDI Port",q.data=r.bytesToNumber([this.data[V+3]]);break;case 47:q.name="End of Track";break;case 81:q.name="Set Tempo",q.data=Math.round(6e7/r.bytesToNumber(this.data.subarray(V+3,V+6))),this.tempo=q.data;break;case 84:q.name="SMTPE Offset";break;case 88:q.name="Time Signature",q.data=this.data.subarray(V+3,V+7),q.timeSignature=""+q.data[0]+"/"+Math.pow(2,q.data[1]);break;case 89:q.name="Key Signature",q.data=this.data.subarray(V+3,V+5);var a=q.data[0]>127?q.data[0]-256:q.data[0];a>=0?q.keySignature=c.CIRCLE_OF_FIFTHS[a]:q.keySignature=c.CIRCLE_OF_FOURTHS[Math.abs(a)],q.data[1]==0?q.keySignature+=" Major":q.data[1]==1&&(q.keySignature+=" Minor");break;case 127:q.name="Sequencer-Specific Meta-event";break;default:q.name="Unknown: "+this.data[V+1].toString(16);break}var A=r.getVarIntLength(this.data.subarray(V+2)),i=r.readVarInt(this.data.subarray(V+2,V+2+A));this.pointer+=e+2+A+i}else if(this.data[V]===240){q.name="Sysex";var s=r.getVarIntLength(this.data.subarray(V+1)),h=r.readVarInt(this.data.subarray(V+1,V+1+s));q.data=this.data.subarray(V+1+s,V+1+s+h),this.pointer+=e+1+s+h}else if(this.data[V]===247){q.name="Sysex (escape)";var o=r.getVarIntLength(this.data.subarray(V+1)),u=r.readVarInt(this.data.subarray(V+1,V+1+o));q.data=this.data.subarray(V+1+o,V+1+o+u),this.pointer+=e+1+o+u}else if(this.data[V]<128)if(q.running=!0,q.noteNumber=this.data[V],q.noteName=c.NOTES[this.data[V]],q.velocity=this.data[V+1],this.lastStatus<=143)q.name="Note off",q.channel=this.lastStatus-128+1,this.pointer+=e+2;else if(this.lastStatus<=159)q.name="Note on",q.channel=this.lastStatus-144+1,this.pointer+=e+2;else if(this.lastStatus<=175)q.name="Polyphonic Key Pressure",q.channel=this.lastStatus-160+1,q.note=c.NOTES[this.data[V]],q.pressure=this.data[V+1],this.pointer+=e+2;else if(this.lastStatus<=191)q.name="Controller Change",q.channel=this.lastStatus-176+1,q.number=this.data[V],q.value=this.data[V+1],this.pointer+=e+2;else if(this.lastStatus<=207)q.name="Program Change",q.channel=this.lastStatus-192+1,q.value=this.data[V+1],this.pointer+=e+1;else if(this.lastStatus<=223)q.name="Channel Key Pressure",q.channel=this.lastStatus-208+1,this.pointer+=e+1;else if(this.lastStatus<=239)q.name="Pitch Bend",q.channel=this.lastStatus-224+1,q.value=(this.data[V+1]&127)<<7|this.data[V]&127,this.pointer+=e+2;else throw"Unknown event (running): ".concat(this.lastStatus);else if(this.lastStatus=this.data[V],this.data[V]<=143)q.name="Note off",q.channel=this.lastStatus-128+1,q.noteNumber=this.data[V+1],q.noteName=c.NOTES[this.data[V+1]],q.velocity=Math.round(this.data[V+2]/127*100),this.pointer+=e+3;else if(this.data[V]<=159)q.name="Note on",q.channel=this.lastStatus-144+1,q.noteNumber=this.data[V+1],q.noteName=c.NOTES[this.data[V+1]],q.velocity=Math.round(this.data[V+2]/127*100),this.pointer+=e+3;else if(this.data[V]<=175)q.name="Polyphonic Key Pressure",q.channel=this.lastStatus-160+1,q.note=c.NOTES[this.data[V+1]],q.pressure=this.data[V+2],this.pointer+=e+3;else if(this.data[V]<=191)q.name="Controller Change",q.channel=this.lastStatus-176+1,q.number=this.data[V+1],q.value=this.data[V+2],this.pointer+=e+3;else if(this.data[V]<=207)q.name="Program Change",q.channel=this.lastStatus-192+1,q.value=this.data[V+1],this.pointer+=e+2;else if(this.data[V]<=223)q.name="Channel Key Pressure",q.channel=this.lastStatus-208+1,this.pointer+=e+2;else if(this.data[V]<=239)q.name="Pitch Bend",q.channel=this.lastStatus-224+1,q.value=(this.data[V+2]&127)<<7|this.data[V+1]&127,this.pointer+=e+3;else throw"Unknown event: ".concat(this.data[V]);return this.delta+=q.delta,this.events.push(q),q}},{key:"endOfTrack",value:function(){return this.data[this.pointer+1]==255&&this.data[this.pointer+2]==47&&this.data[this.pointer+3]==0}}]),n})();Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach});var B=(function(){function n(t,V){k(this,n),this.sampleRate=5,this.startTime=0,this.buffer=V||null,this.midiChunksByteLength=null,this.division,this.format,this.setTimeoutId=!1,this.scheduledTime=0,this.tracks=[],this.instruments=[],this.defaultTempo=120,this.tempo=null,this.startTick=0,this.tick=0,this.lastTick=null,this.inLoop=!1,this.totalTicks=0,this.events=[],this.totalEvents=0,this.tempoMap=[],this.eventListeners={},typeof t=="function"&&this.on("midiEvent",t)}return b(n,[{key:"loadFile",value:function(V){throw"loadFile is only supported on Node.js"}},{key:"loadArrayBuffer",value:function(V){return this.buffer=new Uint8Array(V),this.fileLoaded()}},{key:"loadDataUri",value:function(V){for(var q=r.atob(V.split(",")[1]),e=new Uint8Array(q.length),a=0;a<q.length;a++)e[a]=q.charCodeAt(a);return this.buffer=e,this.fileLoaded()}},{key:"getFilesize",value:function(){return this.buffer?this.buffer.length:0}},{key:"fileLoaded",value:function(){if(!this.validate())throw"Invalid MIDI file; should start with MThd";return this.defaultTempo=120,this.setTempo(this.defaultTempo).getDivision().getFormat().getTracks().dryRun()}},{key:"validate",value:function(){return r.bytesToLetters(this.buffer.subarray(0,4))==="MThd"}},{key:"getFormat",value:function(){return this.format=r.bytesToNumber(this.buffer.subarray(8,10)),this}},{key:"getTracks",value:function(){this.tracks=[];for(var V=0;V<this.buffer.length;){if(r.bytesToLetters(this.buffer.subarray(V,V+4))=="MTrk"){var q=r.bytesToNumber(this.buffer.subarray(V+4,V+8));this.tracks.push(new U(this.tracks.length,this.buffer.subarray(V+8,V+8+q)))}V+=r.bytesToNumber(this.buffer.subarray(V+4,V+8))+8}var e=0;return this.tracks.forEach(function(a){e+=8+a.data.length}),this.midiChunksByteLength=c.HEADER_CHUNK_LENGTH+e,this}},{key:"enableTrack",value:function(V){return this.tracks[V-1].enable(),this}},{key:"disableTrack",value:function(V){return this.tracks[V-1].disable(),this}},{key:"getDivision",value:function(){return this.division=r.bytesToNumber(this.buffer.subarray(12,c.HEADER_CHUNK_LENGTH)),this}},{key:"playLoop",value:function(V){this.inLoop||(this.inLoop=!0,this.tick=this.getCurrentTick(),this.tracks.forEach(function(q,e){if(!V&&this.endOfFile())this.stop(),this.triggerPlayerEvent("endOfFile");else{var a=q.handleEvent(this.tick,V);if(V&&a)a.hasOwnProperty("name")&&a.name==="Set Tempo"&&this.setTempo(a.data),a.hasOwnProperty("name")&&a.name==="Program Change"&&(this.instruments.includes(a.value)||this.instruments.push(a.value));else if(a){var A=Array.isArray(a)?a:[a];A.forEach(function(i){i.hasOwnProperty("name")&&i.name==="Set Tempo"&&this.setTempo(i.data),this.emitEvent(i)},this)}}},this),!V&&this.isPlaying()&&this.triggerPlayerEvent("playing",{tick:this.tick}),this.inLoop=!1)}},{key:"setTempo",value:function(V){return this.tempo=V,this}},{key:"setStartTime",value:function(V){return this.startTime=V,this}},{key:"play",value:function(){if(this.isPlaying())throw"Already playing...";return this.startTime||(this.startTime=new Date().getTime()),this.scheduledTime=Date.now(),this.schedulePlayLoop(this.sampleRate),this}},{key:"schedulePlayLoop",value:function(V){var q=this;this.setTimeoutId=setTimeout(function(){if(q.playLoop(),q.setTimeoutId!==!1){q.scheduledTime+=q.sampleRate;var e=Date.now()-q.scheduledTime;q.schedulePlayLoop(Math.max(0,q.sampleRate-e))}},V)}},{key:"pause",value:function(){return clearTimeout(this.setTimeoutId),this.setTimeoutId=!1,this.scheduledTime=0,this.startTick=this.tick,this.startTime=0,this}},{key:"stop",value:function(){return clearTimeout(this.setTimeoutId),this.setTimeoutId=!1,this.scheduledTime=0,this.startTick=0,this.startTime=0,this.resetTracks(),this}},{key:"skipToTick",value:function(V){this.stop(),this.startTick=V;for(var q=this.tempoMap.length-1;q>=0;q--)if(this.tempoMap[q].tick<=V){this.setTempo(this.tempoMap[q].tempo);break}return this.collectStateAtTick(V).forEach(function(e){this.emitEvent(e)},this),this.tracks.forEach(function(e){e.setEventIndexByTick(V)}),this}},{key:"collectStateAtTick",value:function(V){var q={};return this.events.forEach(function(e){e.forEach(function(a){if(!(a.tick>=V)){var A;a.name==="Program Change"?A="pc:"+a.channel:a.name==="Controller Change"?A="cc:"+a.channel+":"+a.number:a.name==="Pitch Bend"&&(A="pb:"+a.channel),A&&(q[A]=a)}})}),Object.keys(q).map(function(e){return q[e]})}},{key:"skipToPercent",value:function(V){if(V<0||V>100)throw"Percent must be number between 1 and 100.";return this.skipToTick(Math.round(V/100*this.totalTicks)),this}},{key:"skipToSeconds",value:function(V){var q=this.getSongTime();if(V<0||V>q)throw V+" seconds not within song time of "+q;return this.skipToTick(this.secondsToTicks(V)),this}},{key:"isPlaying",value:function(){return this.setTimeoutId!==!1}},{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.buildTempoMap(),this.startTick=0,this.startTime=0,this.resetTracks(),this.triggerPlayerEvent("fileLoaded",this),this}},{key:"resetTracks",value:function(){return this.tracks.forEach(function(V){return V.reset()}),this}},{key:"getEvents",value:function(){return this.tracks.map(function(V){return V.events})}},{key:"getTotalTicks",value:function(){return Math.max.apply(null,this.tracks.map(function(V){return V.delta}))}},{key:"getTotalEvents",value:function(){return this.tracks.reduce(function(V,q){return{events:{length:V.events.length+q.events.length}}},{events:{length:0}}).events.length}},{key:"buildTempoMap",value:function(){var V=[];return this.events.forEach(function(q){q.forEach(function(e){e.name==="Set Tempo"&&V.push({tick:e.tick,tempo:e.data})})}),V.sort(function(q,e){return q.tick-e.tick}),this.tempoMap=[{tick:0,tempo:this.defaultTempo}],V.forEach(function(q){var e=this.tempoMap[this.tempoMap.length-1];q.tick===e.tick?e.tempo=q.tempo:this.tempoMap.push({tick:q.tick,tempo:q.tempo})},this),this}},{key:"ticksToSeconds",value:function(V,q){for(var e=0,a=V,A=0;A<this.tempoMap.length;A++){var i=this.tempoMap[A],s=A+1<this.tempoMap.length?this.tempoMap[A+1].tick:q;if(!(s<=V)){var h=Math.max(i.tick,V),o=Math.min(s,q);if(h>=q)break;var u=o-h;e+=u/this.division/i.tempo*60,a=o}}if(a<q){var d=this.tempoMap[this.tempoMap.length-1];e+=(q-a)/this.division/d.tempo*60}return e}},{key:"secondsToTicks",value:function(V){for(var q=V,e=0,a=0;a<this.tempoMap.length;a++){var A=this.tempoMap[a],i=a+1<this.tempoMap.length?this.tempoMap[a+1].tick:1/0,s=i-A.tick,h=s/this.division/A.tempo*60;if(q<=h)return e=A.tick+Math.round(q/60*A.tempo*this.division),e;q-=h,e=i}return this.totalTicks}},{key:"getSongTime",value:function(){return this.ticksToSeconds(0,this.totalTicks)}},{key:"getSongTimeRemaining",value:function(){return Math.round(this.ticksToSeconds(this.getCurrentTick(),this.totalTicks))}},{key:"getSongPercentRemaining",value:function(){return Math.round(this.getSongTimeRemaining()/this.getSongTime()*100)}},{key:"bytesProcessed",value:function(){return c.HEADER_CHUNK_LENGTH+this.tracks.length*8+this.tracks.reduce(function(V,q){return{pointer:V.pointer+q.pointer}},{pointer:0}).pointer}},{key:"eventsPlayed",value:function(){return this.tracks.reduce(function(V,q){return{eventIndex:V.eventIndex+q.eventIndex}},{eventIndex:0}).eventIndex}},{key:"endOfFile",value:function(){return this.isPlaying()?this.totalTicks-this.tick<=0:this.bytesProcessed()>=this.midiChunksByteLength}},{key:"getCurrentTick",value:function(){if(!this.startTime)return this.startTick;var V=(new Date().getTime()-this.startTime)/1e3,q=this.ticksToSeconds(0,this.startTick);return this.secondsToTicks(q+V)}},{key:"emitEvent",value:function(V){return this.triggerPlayerEvent("midiEvent",V),this}},{key:"on",value:function(V,q){return this.eventListeners.hasOwnProperty(V)||(this.eventListeners[V]=[]),this.eventListeners[V].push(q),this}},{key:"triggerPlayerEvent",value:function(V,q){return this.eventListeners.hasOwnProperty(V)&&this.eventListeners[V].forEach(function(e){return e(q||{})}),this}}]),n})(),S={Player:B,Utils:r,Constants:c};var p=class{#V=null;#e=null;#q=[];#t=.05;#i=1e-6;constructor(t,V){this.#V=t,this.#e=V,this.#e.zones.map(q=>this.#r(q))}queueWaveTable(t,V,q,e,a){this.#V.state==="suspended"&&this.#V.resume().catch(()=>{});let A=this.#o(e),i=this.#u(V);if(!i?.buffer)return null;let s=i.originalPitch-100*i.coarseTune-i.fineTune,h=Math.pow(2,(100*V-s)/1200),o=Math.max(t,this.#V.currentTime),u=q+this.#t,d=i.loopStart>=1&&i.loopStart<i.loopEnd;d||(u=Math.min(u,i.buffer.duration/h));let f=this.#h();this.#s(f,i,A,o,u,q);let l=this.#V.createBufferSource();if(l.buffer=i.buffer,l.playbackRate.setValueAtTime(h,0),a?.length>0&&(l.playbackRate.setValueAtTime(h,o),a.forEach(m=>{let y=Math.pow(2,(100*(V+m.delta)-s)/1200);l.playbackRate.linearRampToValueAtTime(y,o+m.when)})),l.loop=d,d){let m=i.delay??0;l.loopStart=i.loopStart/i.sampleRate+m,l.loopEnd=i.loopEnd/i.sampleRate+m}return l.connect(f),l.start(o,i.delay??0),l.stop(o+u),f.audioBufferSourceNode=l,f.when=o,f.duration=u,f}queueChord(t,V,q,e,a,A){let i=this.#o(a);return q.map((s,h)=>this.queueWaveTable(this.#V,this.#V.destination,t,V,s,e,i-Math.random()*.01,A?.[h])).filter(Boolean)}async cancelQueue(){this.#q.forEach(t=>{t.gain.cancelScheduledValues(0),t.gain.setValueAtTime(this.#i,this.#V.currentTime),t.when=-1;try{t.audioBufferSourceNode?.disconnect()}catch{}})}#r(t){if(t.buffer)return Promise.resolve(t);if(t.delay=0,t.sample){let V=atob(t.sample),q=V.length,e=new Uint8Array(q);for(let s=0;s<q;s++)e[s]=V.charCodeAt(s);let a=new Int16Array(e.buffer),A=a.length;t.buffer=this.#V.createBuffer(1,A,t.sampleRate);let i=t.buffer.getChannelData(0);for(let s=0;s<A;s++)i[s]=a[s]/32768;return this.#a(t),t}else if(t.file){let V=atob(t.file),q=new Uint8Array(V.length);for(let e=0;e<V.length;e++)q[e]=V.charCodeAt(e);this.#V.decodeAudioData(q.buffer,e=>(t.buffer=e,this.#a(t),t),e=>(console.error("Audio decoding error:",e),!1))}else return this.#a(t),t}#a(t){t.loopStart=this.#A(t.loopStart,0),t.loopEnd=this.#A(t.loopEnd,0),t.coarseTune=this.#A(t.coarseTune,0),t.fineTune=this.#A(t.fineTune,0),t.originalPitch=this.#A(t.originalPitch,6e3),t.sampleRate=this.#A(t.sampleRate,44100)}#s(t,V,q,e,a,A){t.gain.setValueAtTime(this.#n(0),this.#V.currentTime);let i=Math.min(A,a-this.#t),s=V.ahdsr&&V.ahdsr.length>0?V.ahdsr:[{duration:0,volume:1},{duration:i,volume:1}];t.gain.cancelScheduledValues(e);let h=(s[0]?.volume??1)*q;t.gain.setValueAtTime(this.#n(h),e);let o=0,u=s[0]?.volume??1;for(let d of s){let{duration:f,volume:l}=d;if(f<=0)continue;let m=i-o;if(f>m){let y=m/f,C=u+y*(l-u);t.gain.linearRampToValueAtTime(this.#n(q*C),e+i);break}o+=f,u=l,t.gain.linearRampToValueAtTime(this.#n(q*u),e+o)}t.gain.linearRampToValueAtTime(this.#n(0),e+i+this.#t)}#h(){let t=this.#q.find(V=>V.target===this.#V.destination&&this.#V.currentTime>V.when+V.duration+.001);if(t){if(t.audioBufferSourceNode){try{t.audioBufferSourceNode.stop(0),t.audioBufferSourceNode.disconnect()}catch{}t.audioBufferSourceNode=null}}else t=this.#V.createGain(),t.gain.value=0,t.target=this.#V.destination,t.connect(this.#V.destination),t.cancel=()=>{t.when+t.duration>this.#V.currentTime&&(t.gain.cancelScheduledValues(0),t.gain.setTargetAtTime(this.#i,this.#V.currentTime,.1),t.when=this.#V.currentTime+1e-5,t.duration=0)},this.#q.push(t);return t}#u(t){let V=this.#e.zones.findLast(q=>t>=q.keyRangeLow&&t<=q.keyRangeHigh+1);return V&&this.#r(V),V}#o(t){let V=t?1*t:.5;return Math.min(V,.8)}#n(t){return t>this.#i?t:this.#i}#A(t,V){return typeof t=="number"?t:V}};var x={zones:[{midi:81,originalPitch:4200,keyRangeLow:0,keyRangeHigh:43,loopStart:256,loopEnd:768,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAAGAACgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCg//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJALAAAAAAAAABgA5CeiPAAAAAAAAAAAAAAAAAAAA//vUxAAAB+gfQ1TwACTywCx/NYAJAABZOW7fg6F8L8A3AOwb5L2e7x5R5EoCADB8HwfPxACAYrB8H8oCDsHw/lAQdlwPqDHh/UCEp4fhiU8/ynv6BAGOZS1NzNUNm83W5HHJGz4Kk0TfzwzSZu8CgJ3TZ11pu3hi1hoxY8qMFcPAcBX40CM1RcwUo9EFQgiY2VPldy90c24GUwVQROZnA0ZXohQyMsyIBlAWEQK/zrsHfSBGmF4i+yiKKKNrP5FDrYJM+8XdeIRR1FaEwk0mLq5Upl0G35bBliJz8DxCcgSVtAYMpU27BVbW0tSXOzHsLU+88MTkCQ3PwO05aTrtqwF1G2YFHc7M1hamc5RYnJXbn6S9OU7L2apytcaEpk5bQVbXIszWrUzuzNatW5HKL05K+z9Jyip+vcyqG3yZTDELa1DcIazEIXV3jW1lV3jW1lV7h/M/7h/M/7h/9/+f/f/n/3/58qr2JTUtyqvYlNy3TXbFLct012xS3Kemu0lLWp6arSexu7G62Ja2Ja2Ja0QsKrWx13Wb36/a/7/ew5kMjLhQNcmAxqICUIjQsMqB4zeSzGokEALDBOxI2OrTTJJMLBUwcCQYAVMDdlQ0A6Zkis4q5jIAQzknMdGQMBLAltWVxZrJm4ma0hGaGCmrpKmfS87RrhMci3muq5p4+b4wKbPCqVlsBQHbcmCKhmxoZcGGmnZmJeZOEmiGS7nGjrWX5mn+j92HZJcMqKDIgYz0vMnJTHwUzYoMiIGdQNMuTIbj/U13dLc1aMqCjSTkzEvMpCTQjQy4qMkBjPTGR3X9pMI1N9q1aWtWpqtUyspMhBTOCwyYkMeAjNSsyUjMdATMCYyIgpZJZygGm+AqXGzWrWqtWzWrWjGgAy0lMhHwEXmVERjw4AigycfMdGwMVmSDhjQwCiSU1solVxiNamhqlpYZx3jllljvHLWWLlv/F3cfyKO+/8vfx/JY/7/y9/H8lj/v/Pv5Dk5D8bn4xGJyNxuf1llvHHWWW8cdZZbx//u0xLeAL2H/Z7nNkIFVkCR3sMAFx1llvHHWVbHGrllWAbmu1l2+wACIJmablgZJEkGiBRmRmRKSQMOakoAW1jywyxmXRDkBISlWnK1b7K0xdxcdLomjI+e1lat9latrlly7rLnrbVat8FFQgpgKeCmxTcgrgVVMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",anchor:.00533333},{midi:81,originalPitch:5400,keyRangeLow:44,keyRangeHigh:55,loopStart:128,loopEnd:384,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAAEsADMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzMzM//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJATAAAAAAAAABLAMEvhQAAAAAAAAAAAAAAAAAAAA//vUxAAACSwNaVQwACRXSC6/NYAIAAa9txyS8qHAwMDPlz5QEIIROfLn1AhBBy3lz/BCt5c/wQz5c/RBCXPlw/EEEHLPlz9EEOt8QQQcs+XPykQVh8uH4gcIHLD6w+JgcGkGbGakSCqjColKJDEMCR4mYQ8kQZ1UAiwCAIbAc4b1maEch6LAEVzMhwxuYQGCgLBWbmQSPi+kAzkOM6i/Ei2XrGgFiMbisXednEOO7NP9KJdLKedbxd7vvezh3pl/YdmreFqxnZjEgf+NyN/I1TXaWzqnqWqTOzTyyihuX0cMUlNa3S81TYWrGd63q/RRuno4xSUUbt3YzSYU1fuH8z/uH8zp6OMUlFK6e/KKTG5zKZy+ax/+4fzP+4fzP70rp78opL1PXv0lSzVy+tjjVyyrY41e4fzf91/N/3X83/dfzf91/N/3X5/3D+b/uv5v+6/m/7r/3/6/9/+sst446yy3jVyyrY41csq2ONXLKtjjVyyrKiLXdbW5JI24SEB1CQjhFAAXAIxdxbUKO0ekXEuKphJ5DkSgYKJVFFxQVwUwFDcRcUFcFcCjsTYoK4K4FHYmxQXwrgUdibFBfCvCjsTcRXhXhT8TcRXhXhT8TcRXhXhT8TcRXhXhT8TcakxBTUUzLjk5LjWqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//tkxMWDzQgxS7zzACgAADSAAAAEqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",anchor:.00266667},{midi:81,originalPitch:6600,keyRangeLow:56,keyRangeHigh:67,loopStart:64,loopEnd:192,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAAE4ADs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJAXAAAAAAAAABODQyktQAAAAAAAAAAAAAAAAAAAA//vkxAAABywBgbQAACYVyC6/P9AwKAASUcckkt4YWD4fLn1AhBCJz5c+oEFghy5/ghy5+cghy7+GKZd/DHLn1HIYk5d/DHL+6H5d5TOdLnbLTLKrBqyq+vlkqeD4lCzTAngBgvMYACAAGg+NZZoFwogYAGAZCwCsDgBJsJhRJLyYvYUvg4BLFAA9AKpqYxQCumE3hMhEBIkBkBLuNR5oOGzUbs0Jk7jR1yTFgpzGY2TMgWV8qtT4fmaf4xDKgxlNgzTGRZScSFbPVQxarGZbWMLiNMUC1MshXMJx+MRSeaZHnuceOvbGrV2ls6MOQUMAAnMDAzMMgRMAQkMCQufiahT9zMJfim7ul5rIDBEFgJBgHgoHQuBANAwFA1WkUbqzssyns944flv09UjUcU9kjkkk9UjZfjOyzKep8Z2kxucyq9+ax9JFNJNJNZNFNFNVNJNJNbKRRvGQxjKejfJ2Udq/9bf1darY41U0U0U1U0k0k+k0U0U+U0k0k+k0e5/zD+5/zD+5/zX93/Nf3f81/d////////7/9f+//X/v/1/7/9Jop8ppJpJ9Jop6qwppJ7KxJGp6qwpHKrKxI2qqqwo3KrKxI2qqq9RuVWV8jaqqr1G5TEFNRTMuOTkuNVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//sUxNoDwAAB/hwAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",anchor:.00133333},{midi:81,originalPitch:7800,keyRangeLow:68,keyRangeHigh:79,loopStart:32,loopEnd:96,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAADwADm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJAZAAAAAAAAAA8CsVDBMAAAAAAAAAAAAAAAAAAAA//vExAAABmQBjaAAACGQBa9497AdtbAkWdckklxRyjhQ5BBYYqOFHRAXDHKHOGOUOcMco7nOJHawxynnOU5cMcHOXOcHOl3NXGMqsiEAqoMI8QsSUcIsgeiQgJISFCg5ABAyw+VQaiK8yY18FNiuxBUorwU0FdiC4ivimgrsQXEV4KaCuxBcTfBXAv4isTfiuBf6KxN+L4r8RUU3wXoL+JsU3wXoL+JsV3gvRSpMQU1FMy45OS41qqqqqqqqqqqqqqqqqqqqqqqq6goZoAABEOiCXDs8P3G8oicJAhZjVVVBlsStNFVVUT8StNVMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//sUxOuDxEQnByYExigAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",anchor:66667e-8},{midi:81,originalPitch:9e3,keyRangeLow:80,keyRangeHigh:91,loopStart:16,loopEnd:48,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAADwADm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJAaAAAAAAAAAA8ChXkahAAAAAAAAAAAAAAAAAAAA//vExAAABkQDh+AAACGUhq9895iZZVlzMgFEYk0nBACCLQfD6gTB8/qBDBwMflC4f/gQMfqBMH/4OHP4Df+XBw5+UBN/6wJu1fapqZhlttyF2FyUYQ0W0QkFSJiRIro4TAYk8aQCAQCAKjiRIkSr+xQUFOBQUV/5BQU4KChv+CgoL4KCu/4QUN8KCn/8UFN8FFf/wgp/hQ3/8FBXYgoL/+FBX5BQ3/8FBfigopVMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//sUxNoDwAAB/gAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",anchor:33333e-8},{midi:81,originalPitch:10200,keyRangeLow:92,keyRangeHigh:103,loopStart:8,loopEnd:56,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAADwADm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJAaAAAAAAAAAA8AljJJeAAAAAAAAAAAAAAAAAAAA//vExAAABmgDh+AAACG7Cq649JmAh3unfGYwJRhSgQBBEXB8PjogBDn8EwfP6gQdicP/g4GOXB/lHfgmH905/UclwcOf/8oA/2r/qekIFM1D+AxK8OEgo9IhpLSJFdJaehzC3CbBom0GChJpEiRn/tRxIkSJT6OJJB3BUFXSwNB3BUFQVgqCoaqBoGsqd4iBo8oGgaTWCoaxEDR6VBUFTpUFQV//BoGoiBoO//rxKCv//iIGv/+WTEFNRTMuOTkuNVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVMQU1FMy45OS41VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV//sUxNoDwAAB/gAAACAAADSAAAAEVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV",anchor:16667e-8},{midi:81,originalPitch:11400,keyRangeLow:104,keyRangeHigh:115,loopStart:12,loopEnd:52,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAADwADm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJAaAAAAAAAAAA8CNr1v4AAAAAAAAAAAAAAAAAAAA//vExAAAB1SVheCEbeI4SC349ApomIy4jYiPtA6x5AACs4xjvkAAPmMY/wAXzGMf4AL/X+IgG4PvwQOfIQQOZcH//wQlwfBA5/1h/iB2sP/17/1GMvIAEJ8BiUYMEW0NSAKQjJWj5HCbB/EGHqQ5m2plUuYL1WvVqeGZmb/VVVf9mZr/1VVX9hYGwKgFgbB9TCwNgbB8BG6lKUreYxjfKUrfQxvylK3oYxjeUKAgICJYoCAgICUvoYxvylL9DGN9SlL9P+UrfMYxjOoYCAgIUb6lL////////qUpSzASTEFNRTMuOTkuNaqqqqpMQU1FMy45OS41qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//sUxNoDwAAB/gAAACAAADSAAAAEqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",anchor:8333e-8},{midi:81,originalPitch:12600,keyRangeLow:116,keyRangeHigh:127,loopStart:6,loopEnd:42,coarseTune:0,fineTune:0,sampleRate:48e3,ahdsr:!1,file:"SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU3LjcyLjEwMQAAAAAAAAAAAAAA//tUwAAAAAAAAAAAAAAAAAAAAAAAWGluZwAAAA8AAAACAAAEIADo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo6Ojo//////////////////////////////////////////////////////////////////8AAAAATGF2YzU3Ljk2AAAAAAAAAAAAAAAAJAaQAAAAAAAABCDWHfeqAAAAAAAAAAAAAAAAAAAA//vUxAAACUUrfeCE1eMLSCx88a54l3jMh4t/trUApEAAAUAGYxja+WMYx/yAAH+MY/+AYx/4AAX8xjH/7/8AF//zHyAMdoIAgAAADAYWTt4IA/Kc5/////////y4Pg/v3FZropQkAAAEiDVBBhkjdBSk5JyDlHqDmWi+kJRsJiOZ69eva6x+zAQEBCm/9VVVb/9mVVL/9mZmP/6qqqn/8ZlVV/6zMzM3/VCgICanXX+5I2JRJHaana+SSNwIQEQAwAQAQEw6j5KBCASACACAKAmBGHcdr5RNR2jtJRsed/DkTU1NTra/3Oc5znf+1rWuc7/3Na1ra/9znOc7/9rWtc7/9zWta3/4c5znO/9rTU1NXOvbW4lDtDyHkPI7TqQIQAxMQU1FMy45OS41qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpMQU1FMy45OS41qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq//sUxNoDwAABpAAAACAAADSAAAAEqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq",anchor:4167e-8}]};var g=class extends S.Player{#V=null;#e=null;#q=null;#t={preset:x,volume:.012,onEndFile:null};constructor(t={}){super(V=>this.#r(V)),this.#t={...this.#t,...t},this.#q=new Map,this.#V=new(window.AudioContext||window.webkitAudioContext),this.#e=new p(this.#V,this.#t.preset),this.on("endOfFile",async()=>{await new Promise(V=>requestAnimationFrame(()=>setTimeout(V,1))),await this.#i()})}async load(t){this.isPlaying()&&this.stop(),this.#s(),await this.loadArrayBuffer(t)}async play(t=null){t&&await this.load(t),await this.#V.resume(),await super.play()}async pause(){await super.pause(),await this.#s(),await this.#e.cancelQueue()}async stop(){await super.stop(),await this.#s(),await this.#e.cancelQueue()}async#i(){typeof this.#t.onEndFile=="function"&&await this.#t.onEndFile()}async#r(t){if(t.name!=="Note on"&&t.name!=="Note off"||!this.isPlaying()||t.noteNumber===void 0)return;let V=this.#V.currentTime;switch(t.name){case"Note on":if(t.velocity>0&&t.velocity<=127){this.#a(t.noteNumber);let q=t.velocity/127*this.#t.volume,e=this.#e.queueWaveTable(0,t.noteNumber,2,q);this.#q.set(t.noteNumber,e)}else this.#a(t.noteNumber);break;case"Note off":this.#a(t.noteNumber);break}}#a(t){let V=this.#q.get(t);V&&(V.cancel(),this.#q.delete(t))}#s(){this.#q&&(this.#q.forEach((t,V)=>{t&&t.cancel&&t.cancel()}),this.#q.clear())}};typeof window<"u"&&(window.MidiAudioPlayer=g);var Q=g;})();
|
|
18
|
-
//# sourceMappingURL=midi-audio-player.min.js.map
|
|
17
|
+
(()=>{function B(f,e){if(!(f instanceof e))throw new TypeError("Cannot call a class as a function")}function j(f,e){for(var t=0;t<e.length;t++){var s=e[t];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(f,s.key,s)}}function V(f,e,t){return e&&j(f.prototype,e),t&&j(f,t),Object.defineProperty(f,"prototype",{writable:!1}),f}var P={VERSION:"2.0.17",NOTES:[],HEADER_CHUNK_LENGTH:14,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#"]},W=[["C"],["C#","Db"],["D"],["D#","Eb"],["E"],["F"],["F#","Gb"],["G"],["G#","Ab"],["A"],["A#","Bb"],["B"]],H=0,G=function(e){W.forEach(function(t){t.forEach(function(s){return P.NOTES[H]=s+e}),H++})};for(R=-1;R<=9;R++)G(R);var R,w=(function(){function f(){B(this,f)}return V(f,null,[{key:"byteToHex",value:function(t){return("0"+t.toString(16)).slice(-2)}},{key:"bytesToHex",value:function(t){var s=[];return t.forEach(function(i){return s.push(f.byteToHex(i))}),s.join("")}},{key:"hexToNumber",value:function(t){return parseInt(t,16)}},{key:"bytesToNumber",value:function(t){return f.hexToNumber(f.bytesToHex(t))}},{key:"bytesToLetters",value:function(t){var s=[];return t.forEach(function(i){return s.push(String.fromCharCode(i))}),s.join("")}},{key:"decToBinary",value:function(t){return(t>>>0).toString(2)}},{key:"getVarIntLength",value:function(t){for(var s=t[0],i=1;s>=128;)s=t[i],i++;return i}},{key:"readVarInt",value:function(t){var s=0;return t.forEach(function(i){var a=i;a&128?(s+=a&127,s<<=7):s+=a}),s}},{key:"atob",value:(function(e){function t(s){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t})(function(e){return typeof atob=="function"?atob(e):Buffer.from(e,"base64").toString("binary")})}]),f})(),Q=(function(){function f(e,t){B(this,f),this.enabled=!0,this.eventIndex=0,this.pointer=0,this.lastTick=0,this.lastStatus=null,this.index=e,this.data=t,this.delta=0,this.runningDelta=0,this.events=[];var s=this.data.subarray(this.data.length-3,this.data.length);if(!(s[0]===255&&s[1]===47&&s[2]===0))throw"Invalid MIDI file; Last three bytes of track "+this.index+"must be FF 2F 00 to mark end of track"}return V(f,[{key:"reset",value:function(){return this.enabled=!0,this.eventIndex=0,this.pointer=0,this.lastTick=0,this.lastStatus=null,this.delta=0,this.runningDelta=0,this}},{key:"enable",value:function(){return this.enabled=!0,this}},{key:"disable",value:function(){return this.enabled=!1,this}},{key:"setEventIndexByTick",value:function(t){t=t||0;for(var s=0;s<this.events.length;s++)if(this.events[s].tick>=t)return this.eventIndex=s,this}},{key:"getCurrentByte",value:function(){return this.data[this.pointer]}},{key:"getDeltaByteCount",value:function(){return w.getVarIntLength(this.data.subarray(this.pointer))}},{key:"getDelta",value:function(){return w.readVarInt(this.data.subarray(this.pointer,this.pointer+this.getDeltaByteCount()))}},{key:"handleEvent",value:function(t,s){if(s=s||!1,s){var i=t-this.lastTick,a=this.getDelta(),o=i>=a;if(this.pointer<this.data.length&&(s||o)){var n=this.parseEvent();if(this.enabled)return n}}else{for(var r=[];this.events[this.eventIndex]&&this.events[this.eventIndex].tick<=t;)this.enabled&&r.push(this.events[this.eventIndex]),this.eventIndex++;if(r.length>0)return r}return null}},{key:"getStringData",value:function(t){var s=w.getVarIntLength(this.data.subarray(t+2)),i=w.readVarInt(this.data.subarray(t+2,t+2+s)),a=w.bytesToLetters(this.data.subarray(t+2+s,t+2+s+i));return a}},{key:"parseEvent",value:function(){var t=this.pointer+this.getDeltaByteCount(),s={},i=this.getDeltaByteCount();if(s.track=this.index+1,s.delta=this.getDelta(),this.lastTick=this.lastTick+s.delta,this.runningDelta+=s.delta,s.tick=this.runningDelta,s.byteIndex=this.pointer,this.data[t]==255){switch(this.data[t+1]){case 0:s.name="Sequence Number";break;case 1:s.name="Text Event",s.string=this.getStringData(t);break;case 2:s.name="Copyright Notice";break;case 3:s.name="Sequence/Track Name",s.string=this.getStringData(t);break;case 4:s.name="Instrument Name",s.string=this.getStringData(t);break;case 5:s.name="Lyric",s.string=this.getStringData(t);break;case 6:s.name="Marker",s.string=this.getStringData(t);break;case 7:s.name="Cue Point",s.string=this.getStringData(t);break;case 9:s.name="Device Name",s.string=this.getStringData(t);break;case 32:s.name="MIDI Channel Prefix";break;case 33:s.name="MIDI Port",s.data=w.bytesToNumber([this.data[t+3]]);break;case 47:s.name="End of Track";break;case 81:s.name="Set Tempo",s.data=Math.round(6e7/w.bytesToNumber(this.data.subarray(t+3,t+6))),this.tempo=s.data;break;case 84:s.name="SMTPE Offset";break;case 88:s.name="Time Signature",s.data=this.data.subarray(t+3,t+7),s.timeSignature=""+s.data[0]+"/"+Math.pow(2,s.data[1]);break;case 89:s.name="Key Signature",s.data=this.data.subarray(t+3,t+5);var a=s.data[0]>127?s.data[0]-256:s.data[0];a>=0?s.keySignature=P.CIRCLE_OF_FIFTHS[a]:s.keySignature=P.CIRCLE_OF_FOURTHS[Math.abs(a)],s.data[1]==0?s.keySignature+=" Major":s.data[1]==1&&(s.keySignature+=" Minor");break;case 127:s.name="Sequencer-Specific Meta-event";break;default:s.name="Unknown: "+this.data[t+1].toString(16);break}var o=w.getVarIntLength(this.data.subarray(t+2)),n=w.readVarInt(this.data.subarray(t+2,t+2+o));this.pointer+=i+2+o+n}else if(this.data[t]===240){s.name="Sysex";var r=w.getVarIntLength(this.data.subarray(t+1)),c=w.readVarInt(this.data.subarray(t+1,t+1+r));s.data=this.data.subarray(t+1+r,t+1+r+c),this.pointer+=i+1+r+c}else if(this.data[t]===247){s.name="Sysex (escape)";var h=w.getVarIntLength(this.data.subarray(t+1)),l=w.readVarInt(this.data.subarray(t+1,t+1+h));s.data=this.data.subarray(t+1+h,t+1+h+l),this.pointer+=i+1+h+l}else if(this.data[t]<128)if(s.running=!0,s.noteNumber=this.data[t],s.noteName=P.NOTES[this.data[t]],s.velocity=this.data[t+1],this.lastStatus<=143)s.name="Note off",s.channel=this.lastStatus-128+1,this.pointer+=i+2;else if(this.lastStatus<=159)s.name="Note on",s.channel=this.lastStatus-144+1,this.pointer+=i+2;else if(this.lastStatus<=175)s.name="Polyphonic Key Pressure",s.channel=this.lastStatus-160+1,s.note=P.NOTES[this.data[t]],s.pressure=this.data[t+1],this.pointer+=i+2;else if(this.lastStatus<=191)s.name="Controller Change",s.channel=this.lastStatus-176+1,s.number=this.data[t],s.value=this.data[t+1],this.pointer+=i+2;else if(this.lastStatus<=207)s.name="Program Change",s.channel=this.lastStatus-192+1,s.value=this.data[t+1],this.pointer+=i+1;else if(this.lastStatus<=223)s.name="Channel Key Pressure",s.channel=this.lastStatus-208+1,this.pointer+=i+1;else if(this.lastStatus<=239)s.name="Pitch Bend",s.channel=this.lastStatus-224+1,s.value=(this.data[t+1]&127)<<7|this.data[t]&127,this.pointer+=i+2;else throw"Unknown event (running): ".concat(this.lastStatus);else if(this.lastStatus=this.data[t],this.data[t]<=143)s.name="Note off",s.channel=this.lastStatus-128+1,s.noteNumber=this.data[t+1],s.noteName=P.NOTES[this.data[t+1]],s.velocity=Math.round(this.data[t+2]/127*100),this.pointer+=i+3;else if(this.data[t]<=159)s.name="Note on",s.channel=this.lastStatus-144+1,s.noteNumber=this.data[t+1],s.noteName=P.NOTES[this.data[t+1]],s.velocity=Math.round(this.data[t+2]/127*100),this.pointer+=i+3;else if(this.data[t]<=175)s.name="Polyphonic Key Pressure",s.channel=this.lastStatus-160+1,s.note=P.NOTES[this.data[t+1]],s.pressure=this.data[t+2],this.pointer+=i+3;else if(this.data[t]<=191)s.name="Controller Change",s.channel=this.lastStatus-176+1,s.number=this.data[t+1],s.value=this.data[t+2],this.pointer+=i+3;else if(this.data[t]<=207)s.name="Program Change",s.channel=this.lastStatus-192+1,s.value=this.data[t+1],this.pointer+=i+2;else if(this.data[t]<=223)s.name="Channel Key Pressure",s.channel=this.lastStatus-208+1,this.pointer+=i+2;else if(this.data[t]<=239)s.name="Pitch Bend",s.channel=this.lastStatus-224+1,s.value=(this.data[t+2]&127)<<7|this.data[t+1]&127,this.pointer+=i+3;else throw"Unknown event: ".concat(this.data[t]);return this.delta+=s.delta,this.events.push(s),s}},{key:"endOfTrack",value:function(){return this.data[this.pointer+1]==255&&this.data[this.pointer+2]==47&&this.data[this.pointer+3]==0}}]),f})();Uint8Array.prototype.forEach||Object.defineProperty(Uint8Array.prototype,"forEach",{value:Array.prototype.forEach});var Z=(function(){function f(e,t){B(this,f),this.sampleRate=5,this.startTime=0,this.buffer=t||null,this.midiChunksByteLength=null,this.division,this.format,this.setTimeoutId=!1,this.scheduledTime=0,this.tracks=[],this.instruments=[],this.defaultTempo=120,this.tempo=null,this.startTick=0,this.tick=0,this.lastTick=null,this.inLoop=!1,this.totalTicks=0,this.events=[],this.totalEvents=0,this.tempoMap=[],this.eventListeners={},typeof e=="function"&&this.on("midiEvent",e)}return V(f,[{key:"loadFile",value:function(t){throw"loadFile is only supported on Node.js"}},{key:"loadArrayBuffer",value:function(t){return this.buffer=new Uint8Array(t),this.fileLoaded()}},{key:"loadDataUri",value:function(t){for(var s=w.atob(t.split(",")[1]),i=new Uint8Array(s.length),a=0;a<s.length;a++)i[a]=s.charCodeAt(a);return this.buffer=i,this.fileLoaded()}},{key:"getFilesize",value:function(){return this.buffer?this.buffer.length:0}},{key:"fileLoaded",value:function(){if(!this.validate())throw"Invalid MIDI file; should start with MThd";return this.defaultTempo=120,this.setTempo(this.defaultTempo).getDivision().getFormat().getTracks().dryRun()}},{key:"validate",value:function(){return w.bytesToLetters(this.buffer.subarray(0,4))==="MThd"}},{key:"getFormat",value:function(){return this.format=w.bytesToNumber(this.buffer.subarray(8,10)),this}},{key:"getTracks",value:function(){this.tracks=[];for(var t=0;t<this.buffer.length;){if(w.bytesToLetters(this.buffer.subarray(t,t+4))=="MTrk"){var s=w.bytesToNumber(this.buffer.subarray(t+4,t+8));this.tracks.push(new Q(this.tracks.length,this.buffer.subarray(t+8,t+8+s)))}t+=w.bytesToNumber(this.buffer.subarray(t+4,t+8))+8}var i=0;return this.tracks.forEach(function(a){i+=8+a.data.length}),this.midiChunksByteLength=P.HEADER_CHUNK_LENGTH+i,this}},{key:"enableTrack",value:function(t){return this.tracks[t-1].enable(),this}},{key:"disableTrack",value:function(t){return this.tracks[t-1].disable(),this}},{key:"getDivision",value:function(){return this.division=w.bytesToNumber(this.buffer.subarray(12,P.HEADER_CHUNK_LENGTH)),this}},{key:"playLoop",value:function(t){this.inLoop||(this.inLoop=!0,this.tick=this.getCurrentTick(),this.tracks.forEach(function(s,i){if(!t&&this.endOfFile())this.stop(),this.triggerPlayerEvent("endOfFile");else{var a=s.handleEvent(this.tick,t);if(t&&a)a.hasOwnProperty("name")&&a.name==="Set Tempo"&&this.setTempo(a.data),a.hasOwnProperty("name")&&a.name==="Program Change"&&(this.instruments.includes(a.value)||this.instruments.push(a.value));else if(a){var o=Array.isArray(a)?a:[a];o.forEach(function(n){n.hasOwnProperty("name")&&n.name==="Set Tempo"&&this.setTempo(n.data),this.emitEvent(n)},this)}}},this),!t&&this.isPlaying()&&this.triggerPlayerEvent("playing",{tick:this.tick}),this.inLoop=!1)}},{key:"setTempo",value:function(t){return this.tempo=t,this}},{key:"setStartTime",value:function(t){return this.startTime=t,this}},{key:"play",value:function(){if(this.isPlaying())throw"Already playing...";return this.startTime||(this.startTime=new Date().getTime()),this.scheduledTime=Date.now(),this.schedulePlayLoop(this.sampleRate),this}},{key:"schedulePlayLoop",value:function(t){var s=this;this.setTimeoutId=setTimeout(function(){if(s.playLoop(),s.setTimeoutId!==!1){s.scheduledTime+=s.sampleRate;var i=Date.now()-s.scheduledTime;s.schedulePlayLoop(Math.max(0,s.sampleRate-i))}},t)}},{key:"pause",value:function(){return clearTimeout(this.setTimeoutId),this.setTimeoutId=!1,this.scheduledTime=0,this.startTick=this.tick,this.startTime=0,this}},{key:"stop",value:function(){return clearTimeout(this.setTimeoutId),this.setTimeoutId=!1,this.scheduledTime=0,this.startTick=0,this.startTime=0,this.resetTracks(),this}},{key:"skipToTick",value:function(t){this.stop(),this.startTick=t;for(var s=this.tempoMap.length-1;s>=0;s--)if(this.tempoMap[s].tick<=t){this.setTempo(this.tempoMap[s].tempo);break}return this.collectStateAtTick(t).forEach(function(i){this.emitEvent(i)},this),this.tracks.forEach(function(i){i.setEventIndexByTick(t)}),this}},{key:"collectStateAtTick",value:function(t){var s={};return this.events.forEach(function(i){i.forEach(function(a){if(!(a.tick>=t)){var o;a.name==="Program Change"?o="pc:"+a.channel:a.name==="Controller Change"?o="cc:"+a.channel+":"+a.number:a.name==="Pitch Bend"&&(o="pb:"+a.channel),o&&(s[o]=a)}})}),Object.keys(s).map(function(i){return s[i]})}},{key:"skipToPercent",value:function(t){if(t<0||t>100)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 s=this.getSongTime();if(t<0||t>s)throw t+" seconds not within song time of "+s;return this.skipToTick(this.secondsToTicks(t)),this}},{key:"isPlaying",value:function(){return this.setTimeoutId!==!1}},{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.buildTempoMap(),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,s){return{events:{length:t.events.length+s.events.length}}},{events:{length:0}}).events.length}},{key:"buildTempoMap",value:function(){var t=[];return this.events.forEach(function(s){s.forEach(function(i){i.name==="Set Tempo"&&t.push({tick:i.tick,tempo:i.data})})}),t.sort(function(s,i){return s.tick-i.tick}),this.tempoMap=[{tick:0,tempo:this.defaultTempo}],t.forEach(function(s){var i=this.tempoMap[this.tempoMap.length-1];s.tick===i.tick?i.tempo=s.tempo:this.tempoMap.push({tick:s.tick,tempo:s.tempo})},this),this}},{key:"ticksToSeconds",value:function(t,s){for(var i=0,a=t,o=0;o<this.tempoMap.length;o++){var n=this.tempoMap[o],r=o+1<this.tempoMap.length?this.tempoMap[o+1].tick:s;if(!(r<=t)){var c=Math.max(n.tick,t),h=Math.min(r,s);if(c>=s)break;var l=h-c;i+=l/this.division/n.tempo*60,a=h}}if(a<s){var m=this.tempoMap[this.tempoMap.length-1];i+=(s-a)/this.division/m.tempo*60}return i}},{key:"secondsToTicks",value:function(t){for(var s=t,i=0,a=0;a<this.tempoMap.length;a++){var o=this.tempoMap[a],n=a+1<this.tempoMap.length?this.tempoMap[a+1].tick:1/0,r=n-o.tick,c=r/this.division/o.tempo*60;if(s<=c)return i=o.tick+Math.round(s/60*o.tempo*this.division),i;s-=c,i=n}return this.totalTicks}},{key:"getSongTime",value:function(){return this.ticksToSeconds(0,this.totalTicks)}},{key:"getSongTimeRemaining",value:function(){return Math.round(this.ticksToSeconds(this.getCurrentTick(),this.totalTicks))}},{key:"getSongPercentRemaining",value:function(){return Math.round(this.getSongTimeRemaining()/this.getSongTime()*100)}},{key:"bytesProcessed",value:function(){return P.HEADER_CHUNK_LENGTH+this.tracks.length*8+this.tracks.reduce(function(t,s){return{pointer:t.pointer+s.pointer}},{pointer:0}).pointer}},{key:"eventsPlayed",value:function(){return this.tracks.reduce(function(t,s){return{eventIndex:t.eventIndex+s.eventIndex}},{eventIndex:0}).eventIndex}},{key:"endOfFile",value:function(){return this.isPlaying()?this.totalTicks-this.tick<=0:this.bytesProcessed()>=this.midiChunksByteLength}},{key:"getCurrentTick",value:function(){if(!this.startTime)return this.startTick;var t=(new Date().getTime()-this.startTime)/1e3,s=this.ticksToSeconds(0,this.startTick);return this.secondsToTicks(s+t)}},{key:"emitEvent",value:function(t){return this.triggerPlayerEvent("midiEvent",t),this}},{key:"on",value:function(t,s){return this.eventListeners.hasOwnProperty(t)||(this.eventListeners[t]=[]),this.eventListeners[t].push(s),this}},{key:"triggerPlayerEvent",value:function(t,s){return this.eventListeners.hasOwnProperty(t)&&this.eventListeners[t].forEach(function(i){return i(s||{})}),this}}]),f})(),U={Player:Z,Utils:w,Constants:P};var _=class ${#s=null;#r=null;#t=null;#n=[];#a=.05;#h=1e-6;#o=2;#e=null;#l=.7;#u=1;#c=null;#m=!1;#d=8192;#p=new Set;constructor(e,t,s=null,i=null){this.#s=t,this.#r=s,this.#e=this.#s.createGain(),this.#e.gain.setValueAtTime(this.#l,this.#s.currentTime),this.#c=this.#s.createGain(),this.#c.gain.setValueAtTime(this.#u,this.#s.currentTime),this.#e.connect(this.#c),this.#c.connect(this.#r?this.#r.input:this.#s.destination),this.setPreset(e).then(()=>{typeof i=="function"&&i()})}get preset(){return this.#t}set preset(e){this.setPreset(e)}static load(e,t,s=null){return new Promise(i=>{let a=new $(e,t,s,()=>i(a))})}async setPreset(e){this.#t=e,await Promise.all(this.#t.zones.map(t=>this.#y(t)))}close(){let e=this.#s.currentTime;this.#n.forEach(t=>{try{t.gain.cancelScheduledValues(0),t.audioBufferSourceNode&&(t.audioBufferSourceNode.stop(e),t.audioBufferSourceNode.disconnect(),t.audioBufferSourceNode=null)}catch{}try{t.disconnect()}catch{}}),this.#n=[],this.#p.clear();try{this.#e.disconnect()}catch{}try{this.#c.disconnect()}catch{}this.#e=null,this.#c=null,this.#t=null,this.#r=null,this.#s=null}queueWaveTable(e,t,s,i,a){this.#s.state==="suspended"&&this.#s.resume().catch(()=>{});let o=this.#E(i),n=this.#x(Math.round(t));if(!n?.buffer)return null;let r=n.originalPitch-100*n.coarseTune-n.fineTune,c=t*100,h=(this.#d-8192)/8192*this.#o*100,l=c-r+h,m=Math.pow(2,l/1200),u=Math.max(e,this.#s.currentTime),d=s+this.#a,p=n.loopStart>=1&&n.loopStart<n.loopEnd;p||(d=Math.min(d,n.buffer.duration/m));let y=this.#i();this.#g(y,n,o,u,d,s);let k=this.#s.createBufferSource();if(k.buffer=n.buffer,k.playbackRate.setValueAtTime(m,0),a?.length>0&&(k.playbackRate.setValueAtTime(m,u),a.forEach(g=>{let S=(t+g.delta)*100-r+h,x=Math.pow(2,S/1200);k.playbackRate.linearRampToValueAtTime(x,u+g.when)})),k.loop=p,p){let g=n.delay??0;k.loopStart=n.loopStart/n.sampleRate+g,k.loopEnd=n.loopEnd/n.sampleRate+g}return k.connect(y),k.start(u,n.delay??0),k.stop(u+d),y.audioBufferSourceNode=k,y.when=u,y.duration=d,y.pitch=t,y.baseDetune=r,y}async cancelQueue(){this.#n.forEach(e=>{e.gain.cancelScheduledValues(0),e.gain.setValueAtTime(this.#h,this.#s.currentTime),e.when=-1;try{e.audioBufferSourceNode?.disconnect()}catch{}})}isSustainActive(){return this.#m}registerSustainNote(e){this.#p.add(e)}setPitchBend(e){this.#d=e;let t=e-8192,s=t>=0?t/8191*this.#o:t/8192*this.#o,i=this.#s.currentTime;this.#n.forEach(a=>{if(a.audioBufferSourceNode&&a.when+a.duration>i){let o=a.pitch*100,n=a.baseDetune,r=s*100,c=o-n+r,h=Math.pow(2,c/1200);a.audioBufferSourceNode.playbackRate.cancelScheduledValues(i),a.audioBufferSourceNode.playbackRate.setTargetAtTime(h,i,.015)}})}setController(e,t){let s=this.#s.currentTime,i=Math.max(0,Math.min(127,t))/127;switch(e){case 7:this.#l=i,this.#e.gain.setTargetAtTime(this.#l,s,.05);break;case 11:this.#u=i,this.#c.gain.setTargetAtTime(this.#u,s,.03);break;case 64:this.#m=t>=64,this.#m||(this.#p.forEach(a=>a()),this.#p.clear());break}}async#y(e){if(e.buffer)return e;if(e.delay=0,e.file){let t=atob(e.file),s=Uint8Array.from(t,i=>i.charCodeAt(0));try{e.buffer=await this.#s.decodeAudioData(s.buffer),this.#T(e)}catch(i){return console.error("Audio decoding error:",i),console.warn(this.#t),!1}}else this.#T(e);return e}#T(e){e.loopStart=this.#k(e.loopStart,0),e.loopEnd=this.#k(e.loopEnd,0),e.coarseTune=this.#k(e.coarseTune,0),e.fineTune=this.#k(e.fineTune,0),e.originalPitch=this.#k(e.originalPitch,6e3)}#g(e,t,s,i,a,o){e.gain.setValueAtTime(this.#h,this.#s.currentTime);let n=Math.min(o,a-this.#a),r=t.ahdsr&&t.ahdsr.length>0?t.ahdsr:[{duration:0,volume:1},{duration:n,volume:1}];e.gain.cancelScheduledValues(i);let c=(r[0]?.volume??1)*s;e.gain.linearRampToValueAtTime(this.#b(c),i+.002);let h=0,l=r[0]?.volume??1;for(let m of r){let{duration:u,volume:d}=m;if(u<=0)continue;let p=n-h;if(u>p){let y=p/u,k=l+y*(d-l);e.gain.exponentialRampToValueAtTime(this.#b(s*k),i+n);break}h+=u,l=d,e.gain.exponentialRampToValueAtTime(this.#b(s*l),i+h)}e.gain.exponentialRampToValueAtTime(this.#h,i+n+this.#a)}#i(e){let t=e||this.#e,s=this.#s.currentTime,i=this.#n.find(a=>a.target===t&&s>a.when+a.duration+.05);if(!i&&this.#n.length>=64){let a=this.#n.filter(o=>o.target===t);a.length>0&&(a.sort((o,n)=>o.when-n.when),i=a[0])}if(i){if(i.audioBufferSourceNode){try{i.audioBufferSourceNode.stop(0),i.audioBufferSourceNode.disconnect()}catch{}i.audioBufferSourceNode=null}i.gain.cancelScheduledValues(0),i.gain.setValueAtTime(this.#h,s)}else i=this.#s.createGain(),i.gain.value=0,i.target=t,i.connect(t),this.#n.push(i);return i.cancel=(a=!1)=>{let o=this.#s.currentTime;if(a&&i.audioBufferSourceNode){try{i.audioBufferSourceNode.stop(0),i.audioBufferSourceNode.disconnect()}catch{}i.audioBufferSourceNode=null}i.when+i.duration>o&&(i.gain.cancelScheduledValues(0),i.gain.setTargetAtTime(this.#h,o,a?.005:.02),i.when=o+1e-5,i.duration=0)},i}#x(e){return this.#t.zones.findLast(t=>e>=t.keyRangeLow&&e<=t.keyRangeHigh)}#E(e){let t=e?1*e:.5;return Math.min(t,.8)}#b(e){return e>this.#h?e:this.#h}#k(e,t){return typeof e=="number"?e:t}};typeof window<"u"&&(window.WebAudioFontPlayer=_);var q=_;var D=class f{#s=null;#r=null;#t=null;#n=null;#a=null;#h=null;#o=null;#e=0;#l=new Map;static#u=[32,64,128,256,512,1024,2048,4096,8192,16384];static#c=new Map([[32,.7],[64,.8],[128,.9],[256,1],[512,1.1],[1024,1.2],[2048,1.4],[4096,1.6],[8192,1.8],[16384,2]]);constructor(e,t,s){this.#t=e,this.#s=this.#t.createGain();let i=this.#s;[32,64,128,256,512,1024,2048,4096,8192,16384].forEach(o=>{i=this.#m(i,o);let n=o<1e3?o:o/1024+"k";this["band".concat(n)]=i}),this.#e=s,this.#h=this.#t.createConvolver(),this.#o=this.#t.createGain(),this.#o.gain.setValueAtTime(s,this.#t.currentTime),this.#d(1.5,2),this.#n=this.#t.createDynamicsCompressor(),this.#n.threshold.setValueAtTime(-10,this.#t.currentTime),this.#n.ratio.setValueAtTime(20,this.#t.currentTime),this.#n.attack.setValueAtTime(.001,this.#t.currentTime),this.#n.release.setValueAtTime(.1,this.#t.currentTime),this.#n.knee.setValueAtTime(0,this.#t.currentTime),this.#a=this.#t.createAnalyser(),this.#a.fftSize=256,this.#a.smoothingTimeConstant=.6,this.#r=this.#t.createGain(),this.#r.gain.setValueAtTime(t,this.#t.currentTime),i.connect(this.#r),this.#r.connect(this.#n),this.#r.connect(this.#h),this.#h.connect(this.#o),this.#n.connect(this.#a),this.#o.connect(this.#a),this.#a.connect(this.#t.destination)}get eqFrequencies(){return f.#u}get analyser(){return this.#a||null}get input(){return this.#s}get reverb(){return this.#e}set reverb(e){this.#e=Math.max(0,Math.min(1,e)),this.#o.gain.setTargetAtTime(this.#e,this.#t.currentTime,.1)}get masterVolume(){return this.#r.gain.value}set masterVolume(e){let t=Math.max(0,Math.min(1,e)),s=Math.pow(t,2);this.#r.gain.setTargetAtTime(s,this.#t.currentTime,.01)}killReverbTail(){let e=this.#t.currentTime;this.#o.gain.cancelScheduledValues(e),this.#o.gain.setValueAtTime(0,e)}restoreReverb(){this.reverb=this.#e}setEQ(e,t=.04){let s=this.#t.currentTime,i=12;for(let[a,o]of Object.entries(e)){let n=Number(a),r=this.#l.get(n);if(!r)continue;let c=Math.max(-i,Math.min(i,o));r.filter.gain.setTargetAtTime(c,s,t),r.gain=c}}getEQ(){let e={};for(let[t,s]of this.#l)e[t]=s.gain;return e}resetEQ(e=.04){let t={};for(let s of f.#u)t[s]=0;this.setEQ(t,e)}setEQPreset(e){let t={flat:{32:0,64:0,128:0,256:0,512:0,1024:0,2048:0,4096:0,8192:0,16384:0},bass:{32:7,64:6,128:4,256:2,512:0,1024:-1,2048:-1,4096:0,8192:0,16384:0},treble:{32:0,64:0,128:0,256:0,512:0,1024:1,2048:3,4096:5,8192:7,16384:8},vocal:{32:-3,64:-2,128:0,256:2,512:4,1024:5,2048:4,4096:2,8192:1,16384:0},loudness:{32:6,64:4,128:1,256:0,512:-1,1024:-1,2048:0,4096:2,8192:4,16384:5},classical:{32:4,64:3,128:2,256:0,512:0,1024:0,2048:0,4096:2,8192:3,16384:4},jazz:{32:4,64:3,128:1,256:0,512:-1,1024:-1,2048:0,4096:1,8192:3,16384:4},electronic:{32:6,64:5,128:2,256:-1,512:-2,1024:-1,2048:2,4096:4,8192:5,16384:6}},s=t[e];if(!s)throw new Error('Preset EQ unkown: "'.concat(e,'". Avaiables: ').concat(Object.keys(t).join(", ")));this.setEQ(s)}#m(e,t){let s=this.#t.createBiquadFilter();s.type="peaking",s.frequency.setValueAtTime(t,this.#t.currentTime),s.gain.setValueAtTime(0,this.#t.currentTime);let i=f.#c.get(t)??1;return s.Q.setValueAtTime(i,this.#t.currentTime),this.#l.set(t,{filter:s,gain:0}),e.connect(s),s}#d(e,t){let s=this.#t.sampleRate,i=s*e,a=this.#t.createBuffer(2,i,s),n=Math.floor(.015*s);for(let r=0;r<a.numberOfChannels;r++){let c=a.getChannelData(r),h=0,l=r===1?Math.floor(.002*s):0;for(let m=0;m<i;m++){if(m<n){c[m]=0;continue}let u=(m-n)/s,d=Math.exp(-u*(t/e)),p=Math.max(.01,.2*Math.exp(-u*2.5));h=(Math.random()*2-1)*p+h*(1-p);let k=h*d;u<.04&&(m%123===0||m%234===0)&&(k+=(Math.random()*2-1)*.2*(.04-u)/.04),m+l<i?c[m+l]=k:c[m]=k}}this.#h.buffer=a}};var J="MidiAudioPlayer",A="KeyValues";var M=null,F=1;async function O(f=F){return M&&f!==F&&(M.close(),M=null,F=f),M||new Promise((e,t)=>{let s=indexedDB.open(J,f);s.onupgradeneeded=i=>{let a=i.target.result;a.objectStoreNames.contains(A)||a.createObjectStore(A)},s.onsuccess=i=>{M=i.target.result,e(M)},s.onerror=i=>t(i.target.error)})}var X={async setVersion(f){await O(f)},async setItem(f,e,t=!1){let s=await O(),i=e,a=!1;if(t){let n=JSON.stringify(e),c=new Blob([n]).stream().pipeThrough(new CompressionStream("gzip"));i=await new Response(c).arrayBuffer(),a=!0}let o={data:i,isCompressed:a};return new Promise((n,r)=>{let l=s.transaction(A,"readwrite").objectStore(A).put(o,f);l.onsuccess=()=>n(),l.onerror=()=>r(l.error)})},async getItem(f){let e=await O(),t=await new Promise((s,i)=>{let n=e.transaction(A,"readonly").objectStore(A).get(f);n.onsuccess=()=>s(n.result),n.onerror=()=>i(n.error)});if(!t)return null;if(t.isCompressed){let i=new Blob([t.data]).stream().pipeThrough(new DecompressionStream("gzip")),o=await new Response(i).text();return JSON.parse(o)}return t.data},async removeItem(f){let e=await O();return new Promise((t,s)=>{let o=e.transaction(A,"readwrite").objectStore(A).delete(f);o.onsuccess=()=>t(),o.onerror=()=>s(o.error)})},async clear(){let f=await O();return new Promise((e,t)=>{let a=f.transaction(A,"readwrite").objectStore(A).clear();a.onsuccess=()=>e(),a.onerror=()=>t(a.error)})}},I=X;var z=(f,e,t)=>Math.min(Math.max(f,e),t),L=class f extends U.Player{static ENDPOINT="https://webaudiofonts.com/presets/";static DEFAULT_PRESET=-1;static REFERENCE_GAIN=.15;static KARAOKE_CHANNEL=0;#s=null;#r=null;#t=null;#n=null;#a={};#h={};#o={};#e={};#l={};#u={};#c={};#m=null;#d=null;#p=null;#y=null;#T=!1;#g="";#i={endpoint:f.ENDPOINT,volume:.6,reverb:.3,onEndFile:null,localCache:!0,presetRandom:!1,karaoke:!1,karaokeDelay:0,muteExpression:!1,maxCharPerLine:48,eqPreset:"flat",preferred:[],presets:[]};constructor(e={}){super(),this.#i={...this.#i,...e},this.#p=this.#x(),this.#r=new(window.AudioContext||window.webkitAudioContext),this.#t=new D(this.#r,this.#i.volume,this.#i.reverb),this.#t.setEQPreset(this.#i.eqPreset),this.#i.karaoke&&this.#C("intro")}get catalog(){return this.getCatalog()}get channels(){return this.#e}get channelStates(){return this.#h}get volume(){return this.#i.volume}set volume(e){this.#i.volume=z(e,0,1),this.#t.masterVolume=this.#i.volume}get volumes(){return this.#u}get reverb(){return this.#t.reverb}set reverb(e){this.#t.reverb=e}get muteExpression(){return this.#i.muteExpression}set muteExpression(e){this.#i.muteExpression=!!e}get eqFrequencies(){return this.#t.eqFrequencies}get eq(){return this.#t.getEQ()}getEQ(){return this.#t.getEQ()}setEQ(e){this.#t.setEQ(e)}setEQPreset(e){this.#t.setEQPreset(e)}setChannelVolume(e,t){this.#u[e]=t,this.#E()}async#x(){await Promise.all(this.#i.presets.map(async e=>{let t=await this.findPreset(e);t&&(this.#c[t.program]=t)}))}async findPreset(e){let t=null;return(await this.getCategories()).some(i=>{if(i.instruments.some(a=>{if(t=a.presets.find(o=>o.id==e),t)return t.category=i.name,t.instrument=a.name,t.program=a.program,!0}),t)return!0}),t}async close(){Object.keys(this.#e).forEach(e=>this.#e[e].close()),await this.#r.close()}async getCatalog(){if(this.#s)return this.#s;let e=this.#i.localCache?await sessionStorage.getItem("waf_catalog"):null;if(e)this.#s=JSON.parse(e);else{this.#f("Downloading catalog...");let i=await fetch("".concat(this.#i.endpoint,"catalog.json"));if(!i.ok)throw new Error("Impossible to download catalog: ".concat(i.status));this.#s=await i.json(),this.#i.localCache&&await sessionStorage.setItem("waf_catalog",JSON.stringify(this.#s))}let t=new Date(this.#s.updatedAt).getTime();return(await I.getItem("waf_catalog_version")||1)<t&&(await I.clear(),I.setItem("waf_catalog_version",t)),this.#s}async getCategories(){return(await this.getCatalog()).categories}async getProgramInstruments(e){let t=await this.getCategories(),s=[];return await Promise.all(t.map(async i=>i.instruments.filter(a=>a.program==e).forEach(a=>{a.presets.forEach(o=>{o.instrument=i.name+" / "+a.name,s.push(o)})}))),s}async getPreset(e){try{if(typeof e=="object")return e;let t="waf_preset_".concat(e),s=this.#i.localCache?await I.getItem(t):null;if(s)return JSON.parse(s);this.#f("Downloading preset ".concat(e,"..."));let a=await(await fetch("".concat(f.ENDPOINT).concat(e,".json"))).json();if(a.zones===void 0)throw console.error("Invalid preset: ".concat($id)),new Error("Invalid preset: ".concat($id));return this.#i.localCache&&await I.setItem(t,JSON.stringify(a),!0),a}catch{throw console.error("Invalid preset: ".concat(e)),new Error("Invalid preset: ".concat(e))}}async loadPreset(e,t){let s=await this.findPreset(e);if(!s)throw new Error("Invalid preset: ".concat(e));this.#c[s.program]=s;let i=await this.getPreset(e);await this.#e[t].setPreset(i),this.#E()}async load(e,t){typeof e=="string"&&(this.#f("Downloading song..."),e=await(await fetch(e)).arrayBuffer()),typeof t=="string"&&(this.#f("Downloading setup..."),t=await(await fetch(t)).json()),this.#m=await this.hashBuffer(e),await this.#p,this.isPlaying()&&this.stop(),this.#v(),await Promise.all(Object.values(this.#e).map(async n=>n.close())),this.#e={},this.#o={},this.#a={},this.#g="",this.#f("Loading buffer...");try{await this.loadArrayBuffer(e)}catch{await this.loadArrayBuffer(await this.#R(e))}this.#f("Loading instruments..."),this.#l=await this.#N(),this.#h=Object.keys(this.#l).reduce((n,r)=>({...n,[r]:!1}),{}),this.#u=Object.keys(this.#l).reduce((n,r)=>({...n,[r]:1}),{}),t?.volumes!==void 0&&await Promise.all(Object.keys(t.volumes).map(async n=>{this.#u[n]!==void 0&&(this.#u[n]=t.volumes[n])}));let s=new Set,i={};t?.presets!==void 0&&await Promise.all(Object.keys(t.presets).map(async n=>{let r=await this.findPreset(t.presets[n]);r&&(i[n]=await this.getPreset(r.id),s.add(r.program))}));let a=await this.#M();Object.values(this.#l).length||this.#f("Error: no instrument found");let o=Promise.all([...a].map(async n=>{if(s.has(n))return;let r=null;this.#c[n]!==void 0?r=await this.getPreset(this.#c[n].id):this.#i.presetRandom?r=await this.#I(n):r=await this.#L(n),this.#o[n]=r}));this.#i.karaoke&&(this.#f("Generating karaoke frames..."),this.#y=null,await this.#V(),this.#g&&this.#C("title",this.#g)),this.#f("Trim midi events..."),this.#B(),queueMicrotask(()=>this.triggerPlayerEvent("computed")),await o,await Promise.all(Object.keys(this.#l).map(async n=>{this.#e[n]&&this.#e[n].close(),i[n]!==void 0?this.#e[n]=await this.#P(i[n]):this.#e[n]=await this.#P(this.#o[this.#l[n]])})),this.#f("Initializing instrument states..."),await this.#k(),await this.triggerPlayerEvent("presetsLoaded",this.#o),await this.#E(),this.#f("Player ready")}async getSongSetup(){let e={hash:this.#m,presets:{},volumes:{}};return Object.keys(this.#e).map(async t=>e.presets[t]=this.#e[t].preset.id),e.volumes=this.#u,e}async getTrainingPresets(){return await Promise.all(Object.values(this.#c).map(async e=>e.id))}async play(e=null){if(this.#r.state==="suspended")try{await this.#r.resume()}catch{return!1}return e&&await this.load(e),await Promise.all(Object.keys(this.#e).map(async t=>await this.#e[t]?.cancelQueue())),this.#t.restoreReverb(),this.isPlaying()||(this.startTime||(this.startTime=new Date().getTime()),this.scheduledTime=Date.now(),this.schedulePlayLoop(this.sampleRate)),!0}async pause(){await super.pause(),this.#t.killReverbTail(),await this.#v(),await Promise.all(Object.keys(this.#e).map(async e=>await this.#e[e]?.cancelQueue()))}async stop(e=!1){return await super.stop(),this.setTimeoutId=!1,e||(this.#t.killReverbTail(),await Promise.all(Object.keys(this.#e).map(async t=>await this.#e[t]?.cancelQueue()))),await this.#v(),this.#i.karaoke&&this.#C("intro"),this}getRealTimeVolume(){let e=this.#t.analyser,t=new Uint8Array(e.frequencyBinCount);e.getByteFrequencyData(t);let s=0;for(let i=0;i<t.length;i++)s+=t[i];return s/(t.length*100)}getSongTimeRemaining(){return this.ticksToSeconds(this.getCurrentTick(),this.totalTicks)}async skipToSeconds(e){let t=this.getSongTime();if(e<0||e>t)throw e+" seconds not within song time of "+t;return await this.skipToTick(this.secondsToTicks(e)),this}async generateWaveformSVG(e=1e3){if(!this.totalTicks||!this.events)return"";let t=new Array(e).fill(0),s=this.totalTicks/e,i=this.events.flatMap((u,d)=>u.map(p=>({...p,computedChannel:p.channel!==void 0?p.channel:d}))).filter(u=>u.name==="Controller Change"||u.name==="Program Change"||u.name==="Note on"&&u.velocity>0).sort((u,d)=>u.tick-d.tick),a=new Map,o=new Map;i.forEach(u=>{let d=Math.floor(u.tick/s);if(d>=e)return;let p=u.computedChannel;if(a.has(p)||a.set(p,100),o.has(p)||o.set(p,127),u.name==="Controller Change")u.number===7?a.set(p,u.value):u.number===11&&o.set(p,u.value);else if(u.name==="Note on"){let y=a.get(p)/127,k=o.get(p)/127,g=u.velocity*y*k;t[d]+=g}});let n=t.reduce((u,d)=>isNaN(d)?u:d>u?d:u,0),r=n>0?t.map(u=>isNaN(u)?0:u/n):t.fill(0),c=e,h=c/5,l=r.map((u,d)=>{let p=d,y=Math.max(0,Math.min(h,h-u*h));return"".concat(p,",").concat(y.toFixed(2))}),m="M 0,".concat(h," L ").concat(l.join(" L ")," L ").concat(c,",").concat(h);return'<svg class="midiaudioplayer-waveform" viewBox="0 0 '.concat(c," ").concat(h,'" preserveAspectRatio="none"><path d="').concat(m,'" fill="none" stroke-linecap="round" stroke-linejoin="round" /></svg>')}async hashBuffer(e,t="SHA-256"){let s=await crypto.subtle.digest(t,e);return Array.from(new Uint8Array(s)).map(a=>a.toString(16).padStart(2,"0")).join("")}async#E(){this.#d&&clearTimeout(this.#d),this.#d=setTimeout(async()=>{let e=await this.getSongSetup();queueMicrotask(()=>this.triggerPlayerEvent("setupChange",e))},1e3)}async triggerPlayerEvent(e,t){e!="fileLoaded"&&(e=="computed"?(this.#n=await this.#F(),super.triggerPlayerEvent(e,{title:this.#g,karaoke:this.#T,vocalChannel:this.#n,tempo:this.tempo,division:this.division,duration:this.getSongTime(),sampleRate:this.sampleRate,totalTicks:this.totalTicks,totalEvents:this.totalEvents,channels:await this.#l})):e=="endOfFile"&&this.#i.karaoke?queueMicrotask(()=>super.triggerPlayerEvent(e,t)):super.triggerPlayerEvent(e,t))}async playLoop(e){if(this.inLoop)return;if(!e&&this.endOfFile()&&this.tick>0){await this.stop(!0),this.tick=0,this.triggerPlayerEvent("endOfFile");return}this.inLoop=!0,this.tick=this.getCurrentTick();let t=this.tracks.length;for(let s=0;s<t;s++){let i=this.tracks[s].handleEvent(this.tick,e);if(!i)continue;let a=i.constructor===Array,o=a?i.length:1;for(let n=0;n<o;n++){let r=a?i[n]:i,{name:c,data:h,value:l}=r;c==="Set Tempo"&&this.setTempo(h),e?c==="Program Change"&&!this.instruments.includes(l)&&this.instruments.push(l):this.emitEvent(r)}}!e&&this.isPlaying()&&this.triggerPlayerEvent("playing",{tick:this.tick}),this.inLoop=!1}schedulePlayLoop(e){this.setTimeoutId=setTimeout(()=>{if(this.setTimeoutId===!1)return;this.playLoop();let t=this.#r.currentTime;this._lastAudioTime||(this._lastAudioTime=t);let s=t-this._lastAudioTime;this._lastAudioTime=t;let i=this.sampleRate/1e3,a=s-i,o=Math.max(0,this.sampleRate-a*1e3);this.schedulePlayLoop(o)},e)}emitEvent(e){this.#D(e)}ticksToSeconds(e,t){if(t===void 0&&(t=e,e=0),e>=t)return 0;let s=0,i=this.tempoMap.length,a=60/this.division,o=0,n=i-1,r=0;for(;o<=n;){let h=o+n>>1;this.tempoMap[h].tick<=e?(r=h,o=h+1):n=h-1}let c=e;for(let h=r;h<i;h++){let l=this.tempoMap[h],m=h+1<i?this.tempoMap[h+1].tick:t;if(m<=e)continue;let u=Math.max(l.tick,e),d=Math.min(m,t);if(u>=t)break;s+=(d-u)/l.tempo*a,c=d}if(c<t){let h=this.tempoMap[i-1];s+=(t-c)/h.tempo*a}return s}secondsToTicks(e){let t=e,s=this.tempoMap.length,i=60/this.division;for(let a=0;a<s;a++){let o=this.tempoMap[a],c=((a+1<s?this.tempoMap[a+1].tick:1/0)-o.tick)/o.tempo*i;if(t<=c)return o.tick+Math.round(t*o.tempo/i);t-=c}return this.totalTicks}getTickBeforeSeconds(e,t){if(e<=0)return 0;let s=this.ticksToSeconds(0,e),i=Math.max(0,s-t);return this.secondsToTicks(i)}async skipToTick(e){let t=Math.max(0,Math.min(e,this.totalTicks||0)),s=this.isPlaying();if(this.#v(),Object.keys(this.channels).forEach(i=>this.channels[i]?.cancelQueue?.()),s&&super.pause(),this.startTick=t,this.tick=t,this.tempoMap&&this.tempoMap.length>0){for(let i=this.tempoMap.length-1;i>=0;i--)if(this.tempoMap[i].tick<=t){this.setTempo(this.tempoMap[i].tempo);break}}try{let i=[],a=[],o=[],n=[];this.#b(t).forEach(r=>{let c=r.channel;if(!((c===void 0||!this.channels[c])&&r.name!=="Karaoke Event"))switch(r.name){case"Controller Change":i[r.channel]=r;break;case"Program Change":a[r.channel]=r;break;case"Pitch Bend":o[r.channel]=r;break;case"Karaoke Event":n[r.channel]=r;break}}),i.forEach(r=>this.emitEvent(r)),a.forEach(r=>this.emitEvent(r)),o.forEach(r=>this.emitEvent(r)),n.forEach(r=>this.triggerPlayerEvent("karaoke",{type:r.type,tick:r.tick,html:r.text}))}catch(i){console.warn("Chase MIDI Error:",i),this.#f("Chase MIDI Error:",i)}return this.tracks&&this.tracks.length>0&&this.tracks.forEach((i,a)=>{let o=this.events[a];if(o&&o.length>0){let n=0,r=o.length-1,c=o.length;for(;n<=r;){let h=n+r>>1;o[h].tick>=t?(c=h,r=h-1):n=h+1}i.eventIndex=c}else typeof i.setEventIndexByTick=="function"&&i.setEventIndexByTick(t)}),s?this.play():this.triggerPlayerEvent("playing",{tick:t}),this}#b(e){let t={};if(!this.events)return[];for(let s=0;s<this.events.length;s++){let i=this.events[s];if(!i||i.length===0)continue;let a=0,o=i.length-1,n=i.length;for(;a<=o;){let r=a+o>>1;i[r].tick>=e?(n=r,o=r-1):a=r+1}for(let r=0;r<n;r++){let c=i[r],h;c.name==="Program Change"?h="pc:"+c.channel:c.name==="Controller Change"?h="cc:"+c.channel+":"+c.number:c.name==="Pitch Bend"?h="pb:"+c.channel:c.name==="Karaoke Event"&&(h="ke:"+c.channel),h&&(t[h]=c)}}return Object.keys(t).map(s=>t[s])}async#k(){this.events&&this.#b(1).forEach(e=>{let t=e.channel;if(this.#e[t])switch(e.name){case"Controller Change":this.#e[t].setController(e.number,e.value);break;case"Pitch Bend":this.#e[t].setPitchBend?.(e.value);break;case"Program Change":e.value>=0&&e.value<=127&&this.#o[e.value+1]!==void 0&&e.channel!=10&&this.#e[t].preset?.program!==e.value+1&&this.#e[t].setPreset(this.#o[e.value+1]);break}})}async#N(){let e={},t=new Set;return this.events.forEach(s=>{s.forEach(i=>{if(i.name==="Program Change"&&i.value>=0&&i.value<=127){if(e[i.channel])return;i.channel==10?e[i.channel]=-1:e[i.channel]=i.value+1}else i.name==="Note on"&&i.channel==10?(e[i.channel]=-1,t.add(10)):i.name==="Note on"&&t.add(i.channel)})}),Object.keys(e).forEach(s=>{t.has(Number(s))||delete e[s]}),e}async#M(){let e=new Set;return this.events.forEach(t=>{t.forEach(s=>{s.name==="Program Change"&&s.value>=0&&s.value<=127?e.add(s.channel==10?-1:s.value+1):s.name==="Note on"&&s.channel==10&&e.add(-1)})}),e}async#I(e){let t=await this.getProgramInstruments(e);if(!t.length)return null;let s=null;return this.#i.preferred.some(i=>{let a=new RegExp("_".concat(i,"$"),"i"),o=t.filter(n=>a.test(n.id));if(o.length)return s=o[Math.floor(Math.random()*o.length)],!0}),s||(s=t[Math.floor(Math.random()*t.length)]),this.#c[e]=s,await this.getPreset(s.id)}async#L(e){let t=await this.getProgramInstruments(e);if(!t.length)return null;let s=null;return this.#i.preferred.some(i=>{let a=new RegExp("_".concat(i,"$"),"i");if(s=t.find(o=>a.test(o.id)),s)return!0}),s||(s=t[0]),this.#c[e]=s,await this.getPreset(s.id)}async#P(e){return new q(e,this.#r,this.#t)}async#D(e){if(this.isPlaying())switch(e.name){case"Note on":if(e.tick<this.tick-100||e.noteNumber===void 0||e.channel==this.#n&&this.#i.muteExpression)return;if(e.velocity>0&&e.velocity<=127){if(this.#S(e.channel,e.noteNumber),this.#u[e.channel]==0)return;let t=e.velocity/127,s=f.REFERENCE_GAIN*Math.pow(t,2)*this.#u[e.channel],i=this.#e[e.channel]?.queueWaveTable(0,e.noteNumber,2,s);i&&this.#O(e.channel,e.noteNumber,i)}else this.#S(e.channel,e.noteNumber);break;case"Note off":if(e.noteNumber===void 0)return;this.#S(e.channel,e.noteNumber);break;case"Controller Change":this.#e[e.channel]?.setController(e.number,e.value);break;case"Pitch Bend":this.#e[e.channel]?.setPitchBend?.(e.value);break;case"Program Change":return;case"Karaoke Event":if(e.tick<this.tick-this.secondsToTicks(10))return;this.triggerPlayerEvent("karaoke",{type:e.type,tick:e.tick,html:e.text});break}}#O(e,t,s){this.#a[e]||(this.#a[e]=new Map),this.#a[e].set(t,s),this.#w();let i=(s.duration||0)*1e3;s.cleanupTimer=setTimeout(()=>{this.#a[e]?.get(t)===s&&(this.#a[e].delete(t),this.#w())},i+50)}#S(e,t){let s=this.#e[e],i=this.#a[e]?.get(t);if(i){i.cleanupTimer&&clearTimeout(i.cleanupTimer);let a=()=>{this.#a[e]?.delete(t),this.#w()};s&&s.isSustainActive()?s.registerSustainNote(()=>i.cancel(!1)):i.cancel(!1),a()}}#v(){Object.keys(this.#a).forEach(e=>{this.#a[e].forEach((t,s)=>{t&&(t.cleanupTimer&&clearTimeout(t.cleanupTimer),t.cancel&&t.cancel(!0)),this.#a[e]?.delete(s)})}),this.#w()}async#w(){let e=!1,t={};Object.keys(this.#e).forEach(s=>{let i=!!(this.#a[s]?.size&&this.#a[s].size>0);t[s]=i,this.#h[s]!==i&&(e=!0)}),e&&(this.#h=t,this.triggerPlayerEvent("channelState",this.#h))}async#R(e){let t=new Uint8Array(e),s=new DataView(e);if(String.fromCharCode(...t.slice(0,4))!=="MThd")throw new Error("Invalid MIDI file (MThd missing)");let a=s.getUint32(4),o=s.getUint16(8),n=s.getUint16(10),r=s.getUint16(12),c=[255,47,0],h=[],l=8+a;for(;l<t.length&&!(l+8>t.length);){let g=String.fromCharCode(...t.slice(l,l+4)),T=s.getUint32(l+4),S=l+8,x=S+T;if(g!=="MTrk"){let C=Math.min(x,t.length);h.push({tag:g,data:t.slice(l,C),repaired:!1}),l=x;continue}let E=h.filter(C=>C.tag==="MTrk").length+1,b=Math.min(T,t.length-S),v=t.slice(S,S+b),N=v.slice(-3);if(N[0]===255&&N[1]===47&&N[2]===0&&b===T)h.push({tag:g,data:v,repaired:!1});else{let C;if(b<T){let tt=T-b,K=v.slice(-2);K[0]===255&&K[1]===47?(C=new Uint8Array(v.length+1),C.set(v),C[v.length]=0):(C=new Uint8Array(v.length+3),C.set(v),C.set(c,v.length))}else C=new Uint8Array(v.length+3),C.set(v),C.set(c,v.length);h.push({tag:g,data:C,repaired:!0})}l=x}let m=h.filter(g=>g.tag==="MTrk").length,u=14+h.reduce((g,T)=>g+8+T.data.length,0),d=new Uint8Array(u),p=new DataView(d.buffer);d.set([77,84,104,100],0),p.setUint32(4,6),p.setUint16(8,o),p.setUint16(10,m),p.setUint16(12,r);let y=14;for(let g of h){let T=g.tag.split("").map(S=>S.charCodeAt(0));d.set(T,y),p.setUint32(y+4,g.data.length),d.set(g.data,y+8),y+=8+g.data.length}let k=h.filter(g=>g.repaired).length;return d.buffer}#B(){if(!this.events||this.events.length===0)return;let e=1/0,t=0;if(this.events.forEach(n=>{n.forEach(r=>{(r.name==="Note on"||r.name==="Note off")&&(r.tick<e&&(e=r.tick),r.tick>t&&(t=r.tick))})}),e===1/0)return;let s=[];this.events.forEach((n,r)=>{n.forEach(c=>{let h=c.name==="Program Change"||c.name==="Controller Change"||c.name==="Pitch Bend"||c.name==="Set Tempo";c.tick<e&&h&&s.push({event:c,trackIdx:r})})});let i=Object.fromEntries(this.events.map((n,r)=>[r,[]])),a=new Set;for(let n=s.length-1;n>=0;n--){let{event:r,trackIdx:c}=s[n],h=r.channel!==void 0?r.channel:"track-".concat(c),l=null;if(r.name==="Program Change"?l="pc:".concat(h):r.name==="Controller Change"?l="cc:".concat(h,":").concat(r.number):r.name==="Pitch Bend"?l="pb:".concat(h):r.name==="Set Tempo"&&(l="tempo"),l&&!a.has(l)){a.add(l);let m={...r,tick:0};i[c].push(m)}}let o=this.events.map((n,r)=>{let c=[];return n.forEach(l=>{let m=l.name==="Program Change"||l.name==="Controller Change"||l.name==="Pitch Bend"||l.name==="Set Tempo",u=l.name==="Text Event"||l.name==="Lyric Event"||l.name==="Track Name"||l.name==="Karaoke Event";if(l.tick<e)!m&&(u||r===0)&&(l.tick=0,c.push(l));else{l.tick=l.tick-e;let d=t-e;l.tick>d&&(l.tick=d),c.push(l)}}),[...i[r]||[],...c].sort((l,m)=>l.tick-m.tick)});this.events=o,this.totalTicks=t-e,typeof this.computeTempoMap=="function"&&this.computeTempoMap()}async#A(){if(this.#y)return this.#y;let e={language:"",title:"",paragraphs:[]},t=null,s=0;if(this.events.forEach(c=>{let h=c.filter(m=>m.name==="Text Event"||m.name==="Lyric Event"||m.name==="Cue Point"||m.name==="Marker"||m.name==="Track Name"),l=h.filter(m=>{let u=m.string||m.text||"";return u&&!u.startsWith("@")}).length;l>s&&(s=l,t=h)}),!t||t.length===0)return e;let i=t.sort((c,h)=>c.tick-h.tick),a=[],o=[],n=[],r=0;for(i.forEach(c=>{let h=this.#K(c.string||"");if(!h||/^Track-/i.test(h.trim())||/^Piste/i.test(h.trim())||h.trim()===""||c.tick===0&&h.length>20)return;if(h.startsWith("@L")){e.language=h.substring(2).trim();return}if(h.startsWith("@T")){e.title+=(e.title?" / ":"")+h.substring(2).trim();return}if(h.startsWith("@")||h.startsWith("(")||h.startsWith("PART")||/^\d+\s+\d+/.test(h.trim()))return;if(/^(Verse|Chorus|Bridge|Break|Intro|End\.)/i.test(h.trim())){let k=h.startsWith("\\")||h.startsWith("/"),g=n.length===0||c.tick-r>500;if((k||g)&&(n.length>0&&(o.push({tick:n[0].tick,blocks:n}),n=[]),o.length>0)){for(;o.length>4;){let T=o.splice(0,4);a.push({tick:T[0].tick,lines:T})}o.length>0&&(a.push({tick:o[0].tick,lines:o}),o=[])}return}let l=!1;if(n.length>0){let g=n[n.length-1].text,T=h.trimLeft();if(T.length>0){let S=/^[A-Z]/.test(T)||/^'[A-Z]/.test(T),x=/^[A-Z]/.test(g.trim())||/^'[A-Z]/.test(g.trim());S&&!g.endsWith(" ")&&g.trim()!="o"&&!x&&c.tick>r&&(l=!0),h.startsWith('"')&&g.endsWith('"')&&(l=!0),h.startsWith('"')&&(g.endsWith(")")||g.endsWith(')"'))&&(l=!0),T.startsWith('"')&&g.trimRight().endsWith(")")&&(l=!0)}}let m=h.startsWith("\\"),u=h.startsWith("/")||l;(m||u)&&(h.startsWith("\\")||h.startsWith("/"))&&(h=h.substring(1)),h=h.replace(/[\r\n]/g,"");let d=!1;r>0&&c.tick>r&&this.ticksToSeconds(r,c.tick)>2.5&&(d=!0);let y=n.reduce((k,g)=>k+g.text.length,0)+h.length>this.#i.maxCharPerLine;if((u||m||d||y)&&(n.length>0&&(o.push({tick:n[0].tick,blocks:n}),n=[]),o.length>0)){if(m||d){for(;o.length>4;){let k=o.splice(0,4);a.push({tick:k[0].tick,lines:k})}o.length>0&&(a.push({tick:o[0].tick,lines:o}),o=[])}else if(o.length>=6){let k=o.splice(0,4);a.push({tick:k[0].tick,lines:k})}}h.length>0&&(n.push({text:h,tick:c.tick}),r=c.tick)}),n.length>0&&o.push({tick:n[0].tick,blocks:n});o.length>4;){let c=o.splice(0,4);a.push({tick:c[0].tick,lines:c})}return o.length>0&&a.push({tick:o[0].tick,lines:o}),a=a.filter(c=>!(c.lines.length==1&&c.lines[0].blocks.length==1&&["intro","outro","sfx","solo","chorus","verse","bridge","break","end"].includes(c.lines[0].blocks[0].text.toLowerCase().trim()))),a.length<=2&&(a=[]),e.paragraphs=a,this.#y=e,e}async#V(){let e=await this.#A();if(!e.paragraphs.length){this.#T=!1,this.events[f.KARAOKE_CHANNEL].push({text:'<span class="karaoke-intro"></span>',name:"Karaoke Event",type:"intro",tick:0,channel:f.KARAOKE_CHANNEL}),this.events[f.KARAOKE_CHANNEL]=this.events[f.KARAOKE_CHANNEL].sort((l,m)=>l.tick-m.tick);return}this.#T=!0,this.#g=e.title;let t=0,s=this.secondsToTicks(this.#i.karaokeDelay),i=this.secondsToTicks(3),a=this.secondsToTicks(5),o=this.secondsToTicks(7),n=this.secondsToTicks(10),r=[];e.paragraphs.forEach((l,m)=>{l.lines.forEach((u,d)=>{u.blocks.forEach(p=>{r.push({block:p,lineIdx:d,paraIdx:m,paragraph:l,fastLinesText:l.lines.map(y=>y.blocks.map(k=>k.text).join(""))})})})});let c=[];e.paragraphs.forEach((l,m)=>{let u=this.getTickBeforeSeconds(l.tick,5);u<t&&(u=t+(l.tick-t)/2),m===0&&u<20&&(u=20),c[m]=u;let p=l.lines.map(y=>y.blocks.map(k=>k.text).join("")).map(y=>'<span class="karaoke-coming">'.concat(y,"</span>")).join("<br/>");if(this.events[f.KARAOKE_CHANNEL].push({text:p,name:"Karaoke Event",type:"lyric",tick:u,channel:f.KARAOKE_CHANNEL}),l.lines.length>0){let y=l.lines[l.lines.length-1];y.blocks.length>0&&(t=y.blocks[y.blocks.length-1].tick)}}),(c[0]||0)>25&&this.events[f.KARAOKE_CHANNEL].push({text:'<span class="karaoke-clear"></span>',name:"Karaoke Event",type:"clear",tick:5,channel:f.KARAOKE_CHANNEL}),r.forEach((l,m)=>{let u=l.block,d=l.lineIdx,p=l.paraIdx,y=l.paragraph,k=l.fastLinesText,g=(S=!1)=>y.lines.map((x,E)=>{if(E<d)return'<span class="karaoke-played">'.concat(k[E],"</span>");if(E>d)return'<span class="karaoke-coming">'.concat(k[E],"</span>");let b="";return x.blocks.forEach(v=>{let N="coming";S||v.tick<u.tick?N="played":v.tick===u.tick&&(N="playing"),b+='<span class="karaoke-'.concat(N,'">').concat(v.text,"</span>")}),b}).join("<br>");this.events[f.KARAOKE_CHANNEL].push({text:g(!1),name:"Karaoke Event",type:"lyric",tick:u.tick-s,channel:f.KARAOKE_CHANNEL});let T=r[m+1];if(T){let S=T.block.tick-u.tick;if(S>i){let x=u.tick+i,E=u.tick+o,b=S>n&&p>0;if(T.paraIdx!==p){let v=c[T.paraIdx];x>=v&&(x=v-1),b&&(E>=v||v-E<i)&&(b=!1)}x>u.tick&&this.events[f.KARAOKE_CHANNEL].push({text:g(!0),name:"Karaoke Event",type:"lyric",tick:x-s,channel:f.KARAOKE_CHANNEL}),b&&E>x&&this.events[f.KARAOKE_CHANNEL].push({text:'<span class="karaoke-clear"></span>',name:"Karaoke Event",type:"clear",tick:E-s,channel:f.KARAOKE_CHANNEL})}}t=u.tick}),this.totalTicks-t>this.secondsToTicks(5)?this.events[f.KARAOKE_CHANNEL].push({text:'<span class="karaoke-clear"></span>',name:"Karaoke Event",type:"clear",tick:t+this.secondsToTicks(5),channel:f.KARAOKE_CHANNEL}):this.events[f.KARAOKE_CHANNEL].push({text:'<span class="karaoke-clear"></span>',name:"Karaoke Event",type:"clear",tick:this.totalTicks-1,channel:f.KARAOKE_CHANNEL}),this.events[f.KARAOKE_CHANNEL]=this.events[f.KARAOKE_CHANNEL].sort((l,m)=>l.tick-m.tick)}async#F(){let e=await this.#A();if(!e?.paragraphs?.length)return null;let t=e.paragraphs.flatMap(c=>c.lines.flatMap(h=>h.blocks.map(l=>l.tick)));if(t.length===0)return null;let s=this.division?this.division/2:48,i=48,a=84,o=Object.keys(this.#l).map(Number).filter(c=>c!==10),n=null,r=-1/0;for(let c of o){let h=this.events.flatMap(E=>E.filter(b=>b.name==="Note on"&&b.velocity>0&&b.channel===c));if(h.length===0)continue;let m=t.filter(E=>h.some(b=>Math.abs(b.tick-E)<=s)).length/t.length,d=h.filter(E=>E.noteNumber>=i&&E.noteNumber<=a).length/h.length;if(d<.3)continue;let p=[...h].sort((E,b)=>E.tick-b.tick),y=this.division/8||6,g=1-p.filter((E,b)=>b>0&&Math.abs(E.tick-p[b-1].tick)<y).length/Math.max(h.length-1,1),T=h.length/Math.max(t.length,1),S=T<.3?T/.3:T>5?Math.max(0,1-(T-5)/10):1,x=m*.45+d*.35+g*.15+S*.05;x>r&&(r=x,n=c)}return r>=.4?n:null}#K(e){if(!e)return"";let t=new Uint8Array(e.length);for(let a=0;a<e.length;a++)t[a]=e.charCodeAt(a)&255;let i=new TextDecoder("windows-1252").decode(t);return i=i.replace(/ÿ/g,""),i=i.replace(/’/g,"'"),i=i.replace(/`/g,"'"),i}#C(e="clear",t=""){let s='<span class="karaoke-'.concat(e,'">').concat(t.replace(/\s\/\s/g,"<br>"),"</span>");this.#i.karaoke&&(e=="title"?queueMicrotask(()=>this.triggerPlayerEvent("karaoke",{type:e,title:t,html:s})):queueMicrotask(()=>this.triggerPlayerEvent("karaoke",{type:e,html:s})))}#f(e,t=!1){queueMicrotask(()=>this.triggerPlayerEvent("logs",e))}};typeof window<"u"&&(window.MidiAudioPlayer=L);var ut=L;})();
|