diff --git a/package.json b/package.json index 743044de..2112d4a0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "SpessaSynth", - "version": "3.21.3", + "version": "3.21.4-pan-test", "type": "module", "scripts": { "start": "node src/website/server/server.js" diff --git a/src/spessasynth_lib/soundfont/basic_soundfont/modulator.js b/src/spessasynth_lib/soundfont/basic_soundfont/modulator.js index def56d21..f845cac3 100644 --- a/src/spessasynth_lib/soundfont/basic_soundfont/modulator.js +++ b/src/spessasynth_lib/soundfont/basic_soundfont/modulator.js @@ -206,7 +206,8 @@ export const defaultModulators = [ new Modulator({ srcEnum: 0x020E, dest: generatorTypes.fineTune, amt: 12700, secSrcEnum: 0x0010, transform: 0 }), // pan to uhh, pan - new Modulator({ srcEnum: 0x028A, dest: generatorTypes.pan, amt: 1000, secSrcEnum: 0x0, transform: 0 }), + // amount is 500 instead of 1000, see #59 + new Modulator({ srcEnum: 0x028A, dest: generatorTypes.pan, amt: 500, secSrcEnum: 0x0, transform: 0 }), // expression to attenuation new Modulator({ diff --git a/src/spessasynth_lib/synthetizer/worklet_processor.min.js b/src/spessasynth_lib/synthetizer/worklet_processor.min.js index 9f715807..f5749203 100644 --- a/src/spessasynth_lib/synthetizer/worklet_processor.min.js +++ b/src/spessasynth_lib/synthetizer/worklet_processor.min.js @@ -6,7 +6,7 @@ var Bn=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(A,e)=>( Transform type: ${this.transformType} -`}},pt=960,yt=cA.concave;function TA(t,A,e,n,s){return t<<10|A<<9|e<<8|n<<7|s}var Pe=[new j({srcEnum:TA(yt,0,1,0,K.noteOnVelocity),dest:g.initialAttenuation,amt:pt,secSrcEnum:0,transform:0}),new j({srcEnum:129,dest:g.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new j({srcEnum:TA(yt,0,1,1,m.mainVolume),dest:g.initialAttenuation,amt:pt,secSrcEnum:0,transform:0}),new j({srcEnum:13,dest:g.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new j({srcEnum:526,dest:g.fineTune,amt:12700,secSrcEnum:16,transform:0}),new j({srcEnum:650,dest:g.pan,amt:1e3,secSrcEnum:0,transform:0}),new j({srcEnum:TA(yt,0,1,1,m.expressionController),dest:g.initialAttenuation,amt:pt,secSrcEnum:0,transform:0}),new j({srcEnum:219,dest:g.reverbEffectsSend,amt:750,secSrcEnum:0,transform:0}),new j({srcEnum:221,dest:g.chorusEffectsSend,amt:750,secSrcEnum:0,transform:0}),new j({srcEnum:TA(cA.linear,0,0,0,K.polyPressure),dest:g.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new j({srcEnum:TA(cA.linear,0,0,1,m.tremoloDepth),dest:g.modLfoToVolume,amt:24,secSrcEnum:0,transform:0}),new j({srcEnum:TA(cA.linear,1,0,1,m.releaseTime),dest:g.releaseVolEnv,amt:1200,secSrcEnum:0,transform:0}),new j({srcEnum:TA(cA.linear,1,0,1,m.brightness),dest:g.initialFilterFc,amt:6e3,secSrcEnum:0,transform:0}),new j({srcEnum:TA(cA.linear,1,0,1,m.timbreHarmonicContent),dest:g.initialFilterQ,amt:250,secSrcEnum:0,transform:0})];var EA=128,Ke=147,St=new Int16Array(Ke).fill(0),dA=(t,A)=>St[t]=A<<7;dA(m.mainVolume,100);dA(m.balance,64);dA(m.expressionController,127);dA(m.pan,64);dA(m.timbreHarmonicContent,64);dA(m.releaseTime,64);dA(m.attackTime,64);dA(m.brightness,64);dA(m.soundController6,64);dA(m.soundController7,64);dA(m.soundController8,64);dA(m.soundController9,64);dA(m.generalPurposeController6,64);dA(m.generalPurposeController8,64);dA(EA+K.pitchWheel,64);dA(EA+K.pitchWheelRange,2);var gA={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},Dt=Object.keys(gA).length,kt=new Float32Array(Dt);kt[gA.modulationMultiplier]=1;var fA={Idle:0,RPCoarse:1,RPFine:2,NRPCoarse:3,NRPFine:4,DataCoarse:5,DataFine:6};function yn(t=!1){let A={midiControllers:new Int16Array(Ke),lockedControllers:Array(Ke).fill(!1),customControllers:new Float32Array(Dt),NRPCoarse:0,NRPFine:0,RPValue:0,dataEntryState:fA.Idle,voices:[],sustainedVoices:[],cachedVoices:[],preset:this.defaultPreset,presetUsesOverride:!1,channelTransposeKeyShift:0,channelOctaveTuning:new Int8Array(12),keyCentTuning:new Int16Array(128),channelVibrato:{delay:0,depth:0,rate:0},velocityOverride:0,lockGSNRPNParams:!1,holdPedal:!1,isMuted:!1,drumChannel:!1,lockPreset:!1};for(let e=0;e<128;e++)A.cachedVoices.push([]);this.workletProcessorChannels.push(A),this.resetControllers(this.workletProcessorChannels.length-1),this.sendChannelProperties(),t&&this.callEvent("newchannel",void 0)}var wt={velocityOverride:128};var Sn="spessasynth-worklet-system",Dn=350,SA=9,Ve=16,Oe="gs";var bA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10},wA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6};function zA(t,A){let e=0;for(let n=8*(A-1);n>=0;n-=8)e|=t[t.currentIndex++]<>>0}function kn(t,A){if(this.ignoreEvents)return;if(this.sendMIDIMessages&&t.messageStatusByte>=128){this.sendMIDIMessage([t.messageStatusByte,...t.messageData]);return}let e=we(t.messageStatusByte),n=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(e.channel+=n,e.status){case F.noteOn:let s=t.messageData[1];if(s>0)this.synth.noteOn(e.channel,t.messageData[0],s),this.playingNotes.push({midiNote:t.messageData[0],channel:e.channel,velocity:s});else{this.synth.noteOff(e.channel,t.messageData[0]);let I=this.playingNotes.findIndex(C=>C.midiNote===t.messageData[0]&&C.channel===e.channel);I!==-1&&this.playingNotes.splice(I,1)}break;case F.noteOff:this.synth.noteOff(e.channel,t.messageData[0]);let o=this.playingNotes.findIndex(I=>I.midiNote===t.messageData[0]&&I.channel===e.channel);o!==-1&&this.playingNotes.splice(o,1);break;case F.pitchBend:this.synth.pitchWheel(e.channel,t.messageData[1],t.messageData[0]);break;case F.controllerChange:this.synth.controllerChange(e.channel,t.messageData[0],t.messageData[1]);break;case F.programChange:this.synth.programChange(e.channel,t.messageData[0]);break;case F.polyPressure:this.synth.polyPressure(e.channel,t.messageData[0],t.messageData[1]);break;case F.channelPressure:this.synth.channelPressure(e.channel,t.messageData[0]);break;case F.systemExclusive:this.synth.systemExclusive(t.messageData,n);break;case F.setTempo:this.oneTickToSeconds=60/(No(t)*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),T("invalid tempo! falling back to 120 BPM"));break;case F.timeSignature:case F.endOfTrack:case F.midiChannelPrefix:case F.songPosition:case F.activeSensing:case F.keySignature:case F.sequenceNumber:case F.sequenceSpecific:break;case F.text:case F.lyric:case F.copyright:case F.trackName:case F.marker:case F.cuePoint:case F.instrumentName:case F.programName:this.post(wA.textEvent,[t.messageData,e.status]);break;case F.midiPort:this.assignMIDIPort(A,t.messageData[0]);break;case F.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:T(`%cUnrecognized Event: %c${t.messageStatusByte}%c status byte: %c${Object.keys(F).find(I=>F[I]===e.status)}`,r.warn,r.unrecognized,r.warn,r.value);break}}function wn(){for(let t=0;t<16;t++)this.synth.createWorkletChannel(!0),t===SA&&this.synth.setDrums(this.synth.workletProcessorChannels.length-1,!0)}function No(t){return t.messageData.currentIndex=0,6e7/zA(t.messageData,3)}function Fn(){let t=this.currentTime;for(;this.playedTime1&&this.nextSong();return}let n=this.tracks[A][this.eventIndex[A]];if(this.playedTime+=this.oneTickToSeconds*(n.ticks-e.ticks),this.midiData.loop.end<=e.ticks&&this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}else if(t>=this.duration){if(this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function Rn(){let t=0,A=1/0;return this.tracks.forEach((e,n)=>{this.eventIndex[n]>=e.length||e[this.eventIndex[n]].ticks>>0}function Ee(t,A,e){for(let n=0;n>n*8&255}function J(t,A){t[t.currentIndex++]=A&255,t[t.currentIndex++]=A>>8}function lA(t,A){Ee(t,A,4)}function jA(t,A){let e=A<<8|t;return e>32767?e-65536:e}function Gn(t){return t>127?t-256:t}function V(t,A,e=void 0,n=!0){if(e){let s=t.slice(t.currentIndex,t.currentIndex+A);return t.currentIndex+=A,new TextDecoder(e.replace(/[^\x20-\x7E]/g,"")).decode(s.buffer)}else{let s=!1,o="";for(let I=0;I127){if(n){s=!0;continue}else if(C===0){s=!0;continue}}o+=String.fromCharCode(C)}}return o}}function FA(t,A,e=0){e>0&&A.length>e&&(A=A.slice(0,e));for(let n=0;nA.length)for(let n=0;ne.header!=="LIST"?!1:(e.chunkData.currentIndex=0,V(e.chunkData,4)===A))}function Xe(t){let A=0;for(;t;){let e=t[t.currentIndex++];if(A=A<<7|e&127,e>>7!==1)break}return A}var We={name:"INAM",album:"IPRD",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"};var _e=class{constructor(){this.timeDivision=0,this.duration=0,this.tempoChanges=[{ticks:0,tempo:120}],this.copyright="",this.tracksAmount=0,this.lyrics=[],this.firstNoteOn=0,this.keyRange={min:0,max:127},this.lastVoiceEventTick=0,this.midiPorts=[0],this.midiPortChannelOffsets=[0],this.usedChannelsOnTrack=[],this.loop={start:0,end:0},this.midiName="",this.fileName="",this.rawMidiName=void 0,this.embeddedSoundFont=void 0,this.format=0,this.RMIDInfo={},this.bankOffset=0,this.tracks=[]}};function Be(t,A){let e=0;for(;t>0;){let n=A.tempoChanges.find(o=>o.ticksSt[t]=A<<7;dA(m.mainVolume,100);dA(m.balance,64);dA(m.expressionController,127);dA(m.pan,64);dA(m.timbreHarmonicContent,64);dA(m.releaseTime,64);dA(m.attackTime,64);dA(m.brightness,64);dA(m.soundController6,64);dA(m.soundController7,64);dA(m.soundController8,64);dA(m.soundController9,64);dA(m.generalPurposeController6,64);dA(m.generalPurposeController8,64);dA(EA+K.pitchWheel,64);dA(EA+K.pitchWheelRange,2);var gA={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},Dt=Object.keys(gA).length,kt=new Float32Array(Dt);kt[gA.modulationMultiplier]=1;var fA={Idle:0,RPCoarse:1,RPFine:2,NRPCoarse:3,NRPFine:4,DataCoarse:5,DataFine:6};function yn(t=!1){let A={midiControllers:new Int16Array(Ke),lockedControllers:Array(Ke).fill(!1),customControllers:new Float32Array(Dt),NRPCoarse:0,NRPFine:0,RPValue:0,dataEntryState:fA.Idle,voices:[],sustainedVoices:[],cachedVoices:[],preset:this.defaultPreset,presetUsesOverride:!1,channelTransposeKeyShift:0,channelOctaveTuning:new Int8Array(12),keyCentTuning:new Int16Array(128),channelVibrato:{delay:0,depth:0,rate:0},velocityOverride:0,lockGSNRPNParams:!1,holdPedal:!1,isMuted:!1,drumChannel:!1,lockPreset:!1};for(let e=0;e<128;e++)A.cachedVoices.push([]);this.workletProcessorChannels.push(A),this.resetControllers(this.workletProcessorChannels.length-1),this.sendChannelProperties(),t&&this.callEvent("newchannel",void 0)}var wt={velocityOverride:128};var Sn="spessasynth-worklet-system",Dn=350,SA=9,Ve=16,Oe="gs";var bA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10},wA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6};function zA(t,A){let e=0;for(let n=8*(A-1);n>=0;n-=8)e|=t[t.currentIndex++]<>>0}function kn(t,A){if(this.ignoreEvents)return;if(this.sendMIDIMessages&&t.messageStatusByte>=128){this.sendMIDIMessage([t.messageStatusByte,...t.messageData]);return}let e=we(t.messageStatusByte),n=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(e.channel+=n,e.status){case F.noteOn:let s=t.messageData[1];if(s>0)this.synth.noteOn(e.channel,t.messageData[0],s),this.playingNotes.push({midiNote:t.messageData[0],channel:e.channel,velocity:s});else{this.synth.noteOff(e.channel,t.messageData[0]);let I=this.playingNotes.findIndex(C=>C.midiNote===t.messageData[0]&&C.channel===e.channel);I!==-1&&this.playingNotes.splice(I,1)}break;case F.noteOff:this.synth.noteOff(e.channel,t.messageData[0]);let o=this.playingNotes.findIndex(I=>I.midiNote===t.messageData[0]&&I.channel===e.channel);o!==-1&&this.playingNotes.splice(o,1);break;case F.pitchBend:this.synth.pitchWheel(e.channel,t.messageData[1],t.messageData[0]);break;case F.controllerChange:this.synth.controllerChange(e.channel,t.messageData[0],t.messageData[1]);break;case F.programChange:this.synth.programChange(e.channel,t.messageData[0]);break;case F.polyPressure:this.synth.polyPressure(e.channel,t.messageData[0],t.messageData[1]);break;case F.channelPressure:this.synth.channelPressure(e.channel,t.messageData[0]);break;case F.systemExclusive:this.synth.systemExclusive(t.messageData,n);break;case F.setTempo:this.oneTickToSeconds=60/(No(t)*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),T("invalid tempo! falling back to 120 BPM"));break;case F.timeSignature:case F.endOfTrack:case F.midiChannelPrefix:case F.songPosition:case F.activeSensing:case F.keySignature:case F.sequenceNumber:case F.sequenceSpecific:break;case F.text:case F.lyric:case F.copyright:case F.trackName:case F.marker:case F.cuePoint:case F.instrumentName:case F.programName:this.post(wA.textEvent,[t.messageData,e.status]);break;case F.midiPort:this.assignMIDIPort(A,t.messageData[0]);break;case F.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:T(`%cUnrecognized Event: %c${t.messageStatusByte}%c status byte: %c${Object.keys(F).find(I=>F[I]===e.status)}`,r.warn,r.unrecognized,r.warn,r.value);break}}function wn(){for(let t=0;t<16;t++)this.synth.createWorkletChannel(!0),t===SA&&this.synth.setDrums(this.synth.workletProcessorChannels.length-1,!0)}function No(t){return t.messageData.currentIndex=0,6e7/zA(t.messageData,3)}function Fn(){let t=this.currentTime;for(;this.playedTime1&&this.nextSong();return}let n=this.tracks[A][this.eventIndex[A]];if(this.playedTime+=this.oneTickToSeconds*(n.ticks-e.ticks),this.midiData.loop.end<=e.ticks&&this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}else if(t>=this.duration){if(this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function Rn(){let t=0,A=1/0;return this.tracks.forEach((e,n)=>{this.eventIndex[n]>=e.length||e[this.eventIndex[n]].ticks>>0}function Ee(t,A,e){for(let n=0;n>n*8&255}function J(t,A){t[t.currentIndex++]=A&255,t[t.currentIndex++]=A>>8}function lA(t,A){Ee(t,A,4)}function jA(t,A){let e=A<<8|t;return e>32767?e-65536:e}function Gn(t){return t>127?t-256:t}function V(t,A,e=void 0,n=!0){if(e){let s=t.slice(t.currentIndex,t.currentIndex+A);return t.currentIndex+=A,new TextDecoder(e.replace(/[^\x20-\x7E]/g,"")).decode(s.buffer)}else{let s=!1,o="";for(let I=0;I127){if(n){s=!0;continue}else if(C===0){s=!0;continue}}o+=String.fromCharCode(C)}}return o}}function FA(t,A,e=0){e>0&&A.length>e&&(A=A.slice(0,e));for(let n=0;nA.length)for(let n=0;ne.header!=="LIST"?!1:(e.chunkData.currentIndex=0,V(e.chunkData,4)===A))}function Xe(t){let A=0;for(;t;){let e=t[t.currentIndex++];if(A=A<<7|e&127,e>>7!==1)break}return A}var We={name:"INAM",album:"IPRD",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"};var _e=class{constructor(){this.timeDivision=0,this.duration=0,this.tempoChanges=[{ticks:0,tempo:120}],this.copyright="",this.tracksAmount=0,this.lyrics=[],this.firstNoteOn=0,this.keyRange={min:0,max:127},this.lastVoiceEventTick=0,this.midiPorts=[0],this.midiPortChannelOffsets=[0],this.usedChannelsOnTrack=[],this.loop={start:0,end:0},this.midiName="",this.fileName="",this.rawMidiName=void 0,this.embeddedSoundFont=void 0,this.format=0,this.RMIDInfo={},this.bankOffset=0,this.tracks=[]}};function Be(t,A){let e=0;for(;t>0;){let n=A.tempoChanges.find(o=>o.ticks0&&(b+=this.tracks[S-1][this.tracks[S-1].length-1].ticks);w.data.currentIndexthis.lastVoiceEventTick&&(this.lastVoiceEventTick=b),_=cn[i>>4],(i&240)===F.noteOn){G.add(sA);let rA=w.data[w.data.currentIndex];this.keyRange.min=Math.min(this.keyRange.min,rA),this.keyRange.max=Math.max(this.keyRange.max,rA)}x=i;break}let v=new Y(_),z=w.data.slice(w.data.currentIndex,w.data.currentIndex+_);w.data.currentIndex+=_,v.set(z,0);let oA=new Ie(b,i,v);switch(k.push(oA),sA){case-2:switch(i){case F.setTempo:this.tempoChanges.push({ticks:b,tempo:6e7/zA(z,3)});break;case F.marker:switch(V(v,v.length).trim().toLowerCase()){default:break;case"start":case"loopstart":d=b;break;case"loopend":c=b}v.currentIndex=0;break;case F.midiPort:let CA=v[0];this.midiPorts[S]=CA,this.midiPortChannelOffsets[CA]===void 0&&(this.midiPortChannelOffsets[CA]=l,l+=16);break;case F.copyright:o||(this.copyright+=V(v,v.length,void 0,!1)+` `);break;case F.lyric:this.lyrics.push(v)}break;case-3:if(v.slice(0,7).every((rA,CA)=>bo[CA]===rA)){let rA=v.slice(7,z.length-3),CA=V(rA,rA.length)+` diff --git a/src/website/minified/demo_main.min.js b/src/website/minified/demo_main.min.js index 848305b9..22c6ff99 100644 --- a/src/website/minified/demo_main.min.js +++ b/src/website/minified/demo_main.min.js @@ -6,7 +6,7 @@ var EC=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(r,l)=>( Transform type: ${this.transformType} -`}},NB=960,GB=Gr.concave;function Nr(o,r,l,g,f){return o<<10|r<<9|l<<8|g<<7|f}var pC=[new oe({srcEnum:Nr(GB,0,1,0,Ft.noteOnVelocity),dest:v1.initialAttenuation,amt:NB,secSrcEnum:0,transform:0}),new oe({srcEnum:129,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(GB,0,1,1,B3.mainVolume),dest:v1.initialAttenuation,amt:NB,secSrcEnum:0,transform:0}),new oe({srcEnum:13,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new oe({srcEnum:526,dest:v1.fineTune,amt:12700,secSrcEnum:16,transform:0}),new oe({srcEnum:650,dest:v1.pan,amt:1e3,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(GB,0,1,1,B3.expressionController),dest:v1.initialAttenuation,amt:NB,secSrcEnum:0,transform:0}),new oe({srcEnum:219,dest:v1.reverbEffectsSend,amt:750,secSrcEnum:0,transform:0}),new oe({srcEnum:221,dest:v1.chorusEffectsSend,amt:750,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,0,0,0,Ft.polyPressure),dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,0,0,1,B3.tremoloDepth),dest:v1.modLfoToVolume,amt:24,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,1,0,1,B3.releaseTime),dest:v1.releaseVolEnv,amt:1200,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,1,0,1,B3.brightness),dest:v1.initialFilterFc,amt:6e3,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,1,0,1,B3.timbreHarmonicContent),dest:v1.initialFilterQ,amt:250,secSrcEnum:0,transform:0})];var C$=128,ry=147,Ub=new Int16Array(ry).fill(0),ni=(o,r)=>Ub[o]=r<<7;ni(B3.mainVolume,100);ni(B3.balance,64);ni(B3.expressionController,127);ni(B3.pan,64);ni(B3.timbreHarmonicContent,64);ni(B3.releaseTime,64);ni(B3.attackTime,64);ni(B3.brightness,64);ni(B3.soundController6,64);ni(B3.soundController7,64);ni(B3.soundController8,64);ni(B3.soundController9,64);ni(B3.generalPurposeController6,64);ni(B3.generalPurposeController8,64);ni(C$+Ft.pitchWheel,64);ni(C$+Ft.pitchWheelRange,2);var QC={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},ny=Object.keys(QC).length,Pb=new Float32Array(ny);Pb[QC.modulationMultiplier]=1;var sy={velocityOverride:128};var Ob="spessasynth-worklet-system",UB=350,Di=9,qb=16;var ch=class{constructor(r,l,g=!0,f=void 0,S=iy){Y5("%cInitializing SpessaSynth synthesizer...",_1.info),this.context=r.context;let n0=f?.oneOutput===!0;this.eventHandler=new mC,this._voiceCap=UB,this._outputsAmount=qb,this.channelsAmount=this._outputsAmount,this.resolveWhenReady=void 0,this.isReady=new Promise(g0=>this.resolveWhenReady=g0),this.channelProperties=[];for(let g0=0;g0this.handleMessage(g0.data),this.soundfontManager=new BC(this),this._snapshotCallback=void 0,this.sequencerCallbackFunction=void 0,S.reverbEnabled&&!n0&&(this.reverbProcessor=ty(this.context,S.reverbImpulseResponse),this.reverbProcessor.connect(r),this.worklet.connect(this.reverbProcessor,0)),S.chorusEnabled&&!n0&&(this.chorusProcessor=new CC(r,S.chorusConfig),this.worklet.connect(this.chorusProcessor.input,1)),n0)this.worklet.connect(r,0);else for(let g0=2;g0{this.channelsAmount++})}get voiceCap(){return this._voiceCap}set voiceCap(r){this._setMasterParam(Qm.voicesCap,r),this._voiceCap=r}get highPerformanceMode(){return this._highPerformanceMode}set highPerformanceMode(r){this._highPerformanceMode=r}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}setLogLevel(r,l,g,f){this.post({channelNumber:Ci,messageType:c8.setLogLevel,messageData:[r,l,g,f]})}_setMasterParam(r,l){this.post({channelNumber:Ci,messageType:c8.setMasterParameter,messageData:[r,l]})}setInterpolationType(r){this._setMasterParam(Qm.interpolationType,r)}handleMessage(r){let l=r.messageData;switch(r.messageType){case m$.channelProperties:this.channelProperties=l,this._voicesAmount=this.channelProperties.reduce((g,f)=>g+f.voicesAmount,0);break;case m$.eventCall:this.eventHandler.callEvent(l.eventName,l.eventData);break;case m$.sequencerSpecific:this.sequencerCallbackFunction&&this.sequencerCallbackFunction(l.messageType,l.messageData);break;case m$.synthesizerSnapshot:this._snapshotCallback&&this._snapshotCallback(l);break;case m$.ready:this.resolveWhenReady();break;case m$.soundfontError:x4(new Error(l)),this.eventHandler.callEvent("soundfonterror",l);break}}async getSynthesizerSnapshot(){return new Promise(r=>{this._snapshotCallback=l=>{this._snapshotCallback=void 0,r(l)},this.post({messageType:c8.requestSynthesizerSnapshot,messageData:void 0,channelNumber:Ci})})}addNewChannel(r=!0){this.channelProperties.push({voicesAmount:0,pitchBend:0,pitchBendRangeSemitones:0,isMuted:!1,isDrum:!1}),r&&this.post({channelNumber:0,messageType:c8.addNewChannel,messageData:null})}setVibrato(r,l){this.post({channelNumber:r,messageType:c8.setChannelVibrato,messageData:l})}connectIndividualOutputs(r){if(r.length!==this._outputsAmount)throw new Error(`input nodes amount differs from the system's outputs amount! +`}},NB=960,GB=Gr.concave;function Nr(o,r,l,g,f){return o<<10|r<<9|l<<8|g<<7|f}var pC=[new oe({srcEnum:Nr(GB,0,1,0,Ft.noteOnVelocity),dest:v1.initialAttenuation,amt:NB,secSrcEnum:0,transform:0}),new oe({srcEnum:129,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(GB,0,1,1,B3.mainVolume),dest:v1.initialAttenuation,amt:NB,secSrcEnum:0,transform:0}),new oe({srcEnum:13,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new oe({srcEnum:526,dest:v1.fineTune,amt:12700,secSrcEnum:16,transform:0}),new oe({srcEnum:650,dest:v1.pan,amt:500,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(GB,0,1,1,B3.expressionController),dest:v1.initialAttenuation,amt:NB,secSrcEnum:0,transform:0}),new oe({srcEnum:219,dest:v1.reverbEffectsSend,amt:750,secSrcEnum:0,transform:0}),new oe({srcEnum:221,dest:v1.chorusEffectsSend,amt:750,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,0,0,0,Ft.polyPressure),dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,0,0,1,B3.tremoloDepth),dest:v1.modLfoToVolume,amt:24,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,1,0,1,B3.releaseTime),dest:v1.releaseVolEnv,amt:1200,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,1,0,1,B3.brightness),dest:v1.initialFilterFc,amt:6e3,secSrcEnum:0,transform:0}),new oe({srcEnum:Nr(Gr.linear,1,0,1,B3.timbreHarmonicContent),dest:v1.initialFilterQ,amt:250,secSrcEnum:0,transform:0})];var C$=128,ry=147,Ub=new Int16Array(ry).fill(0),ni=(o,r)=>Ub[o]=r<<7;ni(B3.mainVolume,100);ni(B3.balance,64);ni(B3.expressionController,127);ni(B3.pan,64);ni(B3.timbreHarmonicContent,64);ni(B3.releaseTime,64);ni(B3.attackTime,64);ni(B3.brightness,64);ni(B3.soundController6,64);ni(B3.soundController7,64);ni(B3.soundController8,64);ni(B3.soundController9,64);ni(B3.generalPurposeController6,64);ni(B3.generalPurposeController8,64);ni(C$+Ft.pitchWheel,64);ni(C$+Ft.pitchWheelRange,2);var QC={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},ny=Object.keys(QC).length,Pb=new Float32Array(ny);Pb[QC.modulationMultiplier]=1;var sy={velocityOverride:128};var Ob="spessasynth-worklet-system",UB=350,Di=9,qb=16;var ch=class{constructor(r,l,g=!0,f=void 0,S=iy){Y5("%cInitializing SpessaSynth synthesizer...",_1.info),this.context=r.context;let n0=f?.oneOutput===!0;this.eventHandler=new mC,this._voiceCap=UB,this._outputsAmount=qb,this.channelsAmount=this._outputsAmount,this.resolveWhenReady=void 0,this.isReady=new Promise(g0=>this.resolveWhenReady=g0),this.channelProperties=[];for(let g0=0;g0this.handleMessage(g0.data),this.soundfontManager=new BC(this),this._snapshotCallback=void 0,this.sequencerCallbackFunction=void 0,S.reverbEnabled&&!n0&&(this.reverbProcessor=ty(this.context,S.reverbImpulseResponse),this.reverbProcessor.connect(r),this.worklet.connect(this.reverbProcessor,0)),S.chorusEnabled&&!n0&&(this.chorusProcessor=new CC(r,S.chorusConfig),this.worklet.connect(this.chorusProcessor.input,1)),n0)this.worklet.connect(r,0);else for(let g0=2;g0{this.channelsAmount++})}get voiceCap(){return this._voiceCap}set voiceCap(r){this._setMasterParam(Qm.voicesCap,r),this._voiceCap=r}get highPerformanceMode(){return this._highPerformanceMode}set highPerformanceMode(r){this._highPerformanceMode=r}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}setLogLevel(r,l,g,f){this.post({channelNumber:Ci,messageType:c8.setLogLevel,messageData:[r,l,g,f]})}_setMasterParam(r,l){this.post({channelNumber:Ci,messageType:c8.setMasterParameter,messageData:[r,l]})}setInterpolationType(r){this._setMasterParam(Qm.interpolationType,r)}handleMessage(r){let l=r.messageData;switch(r.messageType){case m$.channelProperties:this.channelProperties=l,this._voicesAmount=this.channelProperties.reduce((g,f)=>g+f.voicesAmount,0);break;case m$.eventCall:this.eventHandler.callEvent(l.eventName,l.eventData);break;case m$.sequencerSpecific:this.sequencerCallbackFunction&&this.sequencerCallbackFunction(l.messageType,l.messageData);break;case m$.synthesizerSnapshot:this._snapshotCallback&&this._snapshotCallback(l);break;case m$.ready:this.resolveWhenReady();break;case m$.soundfontError:x4(new Error(l)),this.eventHandler.callEvent("soundfonterror",l);break}}async getSynthesizerSnapshot(){return new Promise(r=>{this._snapshotCallback=l=>{this._snapshotCallback=void 0,r(l)},this.post({messageType:c8.requestSynthesizerSnapshot,messageData:void 0,channelNumber:Ci})})}addNewChannel(r=!0){this.channelProperties.push({voicesAmount:0,pitchBend:0,pitchBendRangeSemitones:0,isMuted:!1,isDrum:!1}),r&&this.post({channelNumber:0,messageType:c8.addNewChannel,messageData:null})}setVibrato(r,l){this.post({channelNumber:r,messageType:c8.setChannelVibrato,messageData:l})}connectIndividualOutputs(r){if(r.length!==this._outputsAmount)throw new Error(`input nodes amount differs from the system's outputs amount! Expected ${this._outputsAmount} got ${r.length}`);for(let l=0;l127||l<0)throw new Error(`Invalid controller number: ${l}`);g=Math.floor(g),l=Math.floor(l),this.post({channelNumber:r,messageType:c8.ccChange,messageData:[l,g,f]})}resetControllers(){this.post({channelNumber:Ci,messageType:c8.ccReset,messageData:void 0})}channelPressure(r,l){this.post({channelNumber:r,messageType:c8.channelPressure,messageData:l})}polyPressure(r,l,g){this.post({channelNumber:r,messageType:c8.polyPressure,messageData:[l,g]})}post(r){this.worklet.port.postMessage(r)}pitchWheel(r,l,g){this.post({channelNumber:r,messageType:c8.pitchWheel,messageData:[l,g]})}transpose(r){this.transposeChannel(Ci,r,!1)}transposeChannel(r,l,g=!1){this.post({channelNumber:r,messageType:c8.transpose,messageData:[l,g]})}setMainVolume(r){this._setMasterParam(Qm.mainVolume,r)}setMasterPan(r){this._setMasterParam(Qm.masterPan,r)}setPitchBendRange(r,l){this.controllerChange(r,B3.RPNMsb,0),this.controllerChange(r,B3.dataEntryMsb,l),this.controllerChange(r,B3.RPNMsb,127),this.controllerChange(r,B3.RPNLsb,127),this.controllerChange(r,B3.dataEntryMsb,0)}programChange(r,l,g=!1){this.post({channelNumber:r,messageType:c8.programChange,messageData:[l,g]})}velocityOverride(r,l){this.post({channelNumber:r,messageType:c8.ccChange,messageData:[sy.velocityOverride,l,!0]})}lockController(r,l,g){this.post({channelNumber:r,messageType:c8.lockController,messageData:[l,g]})}muteChannel(r,l){this.post({channelNumber:r,messageType:c8.muteChannel,messageData:l})}async reloadSoundFont(r){x4("reloadSoundFont is deprecated. Please use the soundfontManager property instead."),await this.soundfontManager.reloadManager(r)}systemExclusive(r){this.post({channelNumber:Ci,messageType:c8.systemExclusive,messageData:Array.from(r)})}setDrums(r,l){this.post({channelNumber:r,messageType:c8.setDrums,messageData:l})}sendMessage(r){let l=ey(r[0]);switch(l.status){case K3.noteOn:let g=r[2];g>0?this.noteOn(l.channel,r[1],g):this.noteOff(l.channel,r[1]);break;case K3.noteOff:this.noteOff(l.channel,r[1]);break;case K3.pitchBend:this.pitchWheel(l.channel,r[2],r[1]);break;case K3.controllerChange:this.controllerChange(l.channel,r[1],r[2]);break;case K3.programChange:this.programChange(l.channel,r[1]);break;case K3.polyPressure:this.polyPressure(l.channel,r[0],r[1]);break;case K3.channelPressure:this.channelPressure(l.channel,r[1]);break;case K3.systemExclusive:this.systemExclusive(new V3(r.slice(1)));break;case K3.reset:this.stopAll(!0),this.resetControllers();break;default:break}}reverbateEverythingBecauseWhyNot(){for(let r=0;r{this.pressedKeys.delete(g),this.releaseNote(g,this.channel),this.synth.noteOff(this.channel,g)},r=(g,f)=>{let S;if(bn)S=127;else{let E0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let m0=f.clientX-E0.left,g0=E0.width;S=Math.floor((g0-m0)/g0*127)}else{let m0=f.clientY-E0.top,g0=E0.height;S=Math.floor(m0/g0*127)}}this.synth.noteOn(this.channel,g,S,this.enableDebugging)},l=g=>{let f=g.touches?Array.from(g.touches):[g],S=new Set;f.forEach(n0=>{let E0=document.elementFromPoint(n0.clientX,n0.clientY),m0=parseInt(E0.id.replace("note",""));S.add(m0),!(isNaN(m0)||m0<0||this.pressedKeys.has(m0))&&(this.pressedKeys.add(m0),r(m0,n0))}),this.pressedKeys.forEach(n0=>{S.has(n0)||o(n0)})};bn||(document.addEventListener("mousedown",g=>{this.mouseHeld=!0,l(g)}),document.addEventListener("mouseup",()=>{this.mouseHeld=!1,this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.onmousemove=g=>{this.mouseHeld&&l(g)},this.keyboard.onmouseleave=()=>{this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.ontouchstart=l.bind(this),this.keyboard.ontouchend=l.bind(this),this.keyboard.ontouchmove=l.bind(this)}var Ay=20,wm=class{constructor(r,l){this.mouseHeld=!1,this.pressedKeys=new Set,this.mode="light",this.enableDebugging=!1,this.sizeChangeAnimationId=-1,this.modeChangeAnimationId=-1,this._keyRange={min:0,max:127},document.addEventListener("keydown",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,B3.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,B3.sustainPedal,0),this.keyboard.style.filter="")}),this.synth=l,this.channel=0,this.channelColors=r,this._shown=!0,this._createKeyboard(),this.synth.eventHandler.addEvent("noteon","keyboard-note-on",g=>{this.pressNote(g.midiNote,g.channel,g.velocity)}),this.synth.eventHandler.addEvent("noteoff","keyboard-note-off",g=>{this.releaseNote(g.midiNote,g.channel)}),this.synth.eventHandler.addEvent("stopall","keyboard-stop-all",()=>{this.clearNotes()}),this.synth.eventHandler.addEvent("mutechannel","keyboard-mute-channel",g=>{if(g.isMuted)for(let f=0;f<128;f++)this.releaseNote(f,g.channel)})}get shown(){return this._shown}set shown(r){r===!0?this.keyboard.style.display="":this.keyboard.style.display="none",this._shown=r}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this.setKeyRange(r,!0)}_createKeyboard(){this.keyboard=document.getElementById("keyboard"),this.keyboard.innerHTML="",this.keys=[],this.keyColors=[];for(let r=this._keyRange.min;r=0&&(S=l(r-1)),r<127&&(n0=l(r+1)),n0&&S?g.classList.add("between_sharps"):S?g.classList.add("left_sharp"):n0&&g.classList.add("right_sharp")}return g}toggleMode(r=!0){if(this.mode==="light"?this.mode="dark":this.mode="light",!r){this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")});return}this.modeChangeAnimationId&&clearTimeout(this.modeChangeAnimationId),this.keyboard.classList.add("mode_transform"),document.body.scrollHeight<=window.innerHeight&&document.body.classList.add("no_scroll"),this.modeChangeAnimationId=setTimeout(()=>{this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")}),this.keyboard.classList.remove("mode_transform"),setTimeout(()=>document.body.classList.remove("no_scroll"),500)},500)}setKeyRange(r,l=!0){Math.abs(r.max-r.min)<12&&(r.min-=6,r.max=r.min+12);let f=900/(r.max-r.min+5),S=document.styleSheets[0].cssRules,n0;for(let E0 of S)if(E0.selectorText==="#keyboard .key"){n0=E0;break}if(n0.style.setProperty("--pressed-transform-skew",`${8e-4/(f/7)}`),l){this.sizeChangeAnimationId&&clearTimeout(this.sizeChangeAnimationId);let E0=getComputedStyle(this.keyboard),m0=parseFloat(E0.getPropertyValue("--current-min-height").replace(/[^\d.]+/g,"")),g0=this.keyboard.getBoundingClientRect().height,f1=f/m0,x=g0*f1-g0,X0=(this._keyRange.min+this._keyRange.max)/2,F0=(r.min+r.max)/2;this._keyRange=r;let b1=this.keys.find(Y2=>Y2.classList.contains("sharp_key")).getBoundingClientRect().width,l2=(X0-F0)*b1,y1=parseFloat(E0.getPropertyValue("--key-border-radius").replace(/[^\d.]+/g,""));this.keyboard.style.marginTop=`${x}px`,this.keyboard.style.transition="",this.keyboard.style.transform=`scale(${f1}) translateX(${l2}px)`,this.keyboard.style.setProperty("--key-border-radius",`${y1/f1}vmin`),this.sizeChangeAnimationId=setTimeout(()=>{this.keyboard.style.setProperty("--current-min-height",`${f}`),this.keyboard.style.transition="none",this.keyboard.style.transform="",this.keyboard.style.marginTop="",this.keyboard.style.setProperty("--key-border-radius",""),this._createKeyboard(),setTimeout(()=>this.keyboard.style.transition="",75)},500)}else this.keyboard.style.setProperty("--current-min-height",`${f}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let f=this.keys[r-this._keyRange.min];if(f===void 0)return;f.classList.add("pressed");let S=f.classList.contains("sharp_key"),n0=g/127,E0=this.channelColors[l%16].match(/\d+(\.\d+)?/g).map(parseFloat),m0;if(!S&&this.mode==="light"?m0=`rgba(${E0.slice(0,3).map(f1=>255-(255-f1)*n0).join(", ")}, ${E0[3]})`:m0=`rgba(${E0.slice(0,3).map(f1=>f1*n0).join(", ")}, ${E0[3]})`,f.style.background=m0,this.mode==="dark"){let g0=Ay*n0;f.style.boxShadow=`${m0} 0px 0px ${g0}px ${g0/5}px`}this.keyColors[r-this._keyRange.min].push(this.channelColors[l%16])}releaseNote(r,l){let g=this.keys[r-this._keyRange.min];if(g===void 0)return;l%=this.channelColors.length;let f=this.keyColors[r-this._keyRange.min];if(!f)return;let S=f.findLastIndex(n0=>n0===this.channelColors[l]);S!==-1&&(f.splice(S,1),g.style.background=f[f.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${Ay}px ${f[f.length-1]}`),f.length<1&&(g.classList.remove("pressed"),g.style.background="",g.style.boxShadow=""))}clearNotes(){this.keys.forEach((r,l)=>{r.classList.remove("pressed"),r.style.background="",r.style.boxShadow="",this.keyColors[l]=[]})}};wm.prototype._handlePointers=oy;function B$(o,r){let l=o.replace(/[^\d,]/g,"").split(",");return`rgb(${r(parseInt(l[0]))}, ${r(parseInt(l[1]))}, ${r(parseInt(l[2]))})`}var Yb="#000";function ay(o,r,l){o.forEach(g=>{if(g.pressedProgress===0)return;r.fillStyle=g.color;let f=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*f,l){r.fillRect(g.xPos,g.yPos-g.height*f,g.width,g.height*(f*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*f,g.yPos,g.width*(f*2+1),g.height),r.globalAlpha=1}),o.forEach(g=>{r.fillStyle=g.color,r.save(),r.translate(g.xPos,g.yPos),r.fillRect(0,0,g.width,g.height),r.restore(),r.strokeStyle=Yb,r.lineWidth=g.stroke,r.strokeRect(g.xPos,g.yPos,g.width,g.height)})}var PB=!1;function $y(o=!0,r=!1){let l=(this.seq===void 0||this?.seq?.paused===!0)&&this.synth.voicesAmount===0&&!r;if(!this.renderBool||l)if(PB){o&&requestAnimationFrame(this.render.bind(this));return}else PB=!0;else PB=!1;if(o&&this.drawingContext.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderAnalysers&&!this.synth.highPerformanceMode&&this.renderWaveforms(),this.renderNotes&&this.noteTimes){let S=this.computeNotePositions(this.synth.highPerformanceMode);this.synth.highPerformanceMode||ay(S,this.drawingContext,this.sideways)}let g=performance.now()-this.frameTimeStart;this.frameTimeStart=performance.now();let f=1e3/g;this.drawingContext.textBaseline="hanging",this.drawingContext.textAlign="end",this.drawingContext.font=`${yC}px system-ui`,this.drawingContext.fillStyle="white",this.drawingContext.strokeStyle="white",this.drawingContext.fillText(`${this.notesOnScreen} notes`,this.canvas.width,yC*2+5),this.drawingContext.fillText(this.version,this.canvas.width,5),this.drawingContext.fillText(Math.round(f).toString()+" FPS",this.canvas.width,yC+5),this.onRender&&this.onRender(),o&&requestAnimationFrame(this.render.bind(this))}function ly(o=!1){this.notesOnScreen=0;let r=this.sideways?this.canvas.height:this.canvas.width,l=this.sideways?this.canvas.width:this.canvas.height,g=this.keyRange.max-this.keyRange.min,f=r/(g+1),S=f-Q$*2,n0=this.noteFallingTimeMs/1e3,E0=this.noteAfterTriggerTimeMs/1e3,m0=this.seq.currentHighResolutionTime,g0=m0-E0,f1=n0+E0,x=g0+f1,X0=gy/f1,F0=[];this.synth.channelProperties.forEach(l2=>{if(this.showVisualPitch){let y1=l2.pitchBend-8192+this.visualPitchBendOffset;F0.push(l2.pitchBendRangeSemitones*(y1/8192*f))}else F0.push(0)});let b1=[];return this.noteTimes.forEach((l2,y1)=>{if(l2.renderStartIndex>=l2.notes.length||!this.renderChannels[y1])return;let Y2=l2.renderStartIndex,T2=l2.notes,V2=T2[Y2],i3=-1;for(;V2.start<=x&&(Y2++,!(this.notesOnScreen>hy));){let r3=V2.start+V2.length;if(r3>g0&&V2.length>0){let A0=V2.length/f1*l-Q$*2;if(this.notesOnScreen<1e3||A0>X0){i3===-1&&(i3=Y2-1);let y5=(V2.start-g0)/f1*l,T3;if(this._notesFall?T3=l-A0-y5+Q$:T3=y5+Q$,V2.midiNotethis.keyRange.max){if(Y2>=T2.length)break;V2=T2[Y2];continue}let $3=V2.midiNote-this.keyRange.min,w6=f*$3+Q$,s6,o9,V4,r4;if(this.sideways?(s6=T3,o9=w6,r4=S,V4=A0):(o9=T3,s6=w6,V4=S,r4=A0),this.notesOnScreen++,o)this.drawingContext.fillStyle=this.plainColors[y1],this.drawingContext.fillRect(s6+p$+Q$,o9+p$,V4-p$*2,r4-p$*2);else{let V6;if(V2.start>m0||r3=T2.length)break;V2=T2[Y2]}i3>-1&&(l2.renderStartIndex=i3)}),b1.sort((l2,y1)=>y1.height-l2.height),b1}function uy(){let o=this.canvas.width/4,r=this.canvas.height/4;this.channelAnalysers.forEach((l,g)=>{let f=g%4,S=Math.floor(g/4),n0=!1;for(let x=g;x0){n0=!0;break}if(!n0){let x=this.canvas.width/4,X0=this.canvas.height/4,F0=x*f,b1=X0*S+X0/2;this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this.drawingContext.moveTo(F0,b1),this.drawingContext.lineTo(F0+x,b1),this.drawingContext.stroke();return}let E0=new Float32Array(l.frequencyBinCount);l.getFloatTimeDomainData(E0);let m0=o*f,g0=r*S+r/2,f1=this.waveMultiplier*r;if(this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this._stabilizeWaveforms){let x=E0.length/4,X0=o/x,F0=Math.floor(x/2),b1=E0.length-F0;for(let T2=b1;T2>=1;T2--)if(E0[T2-1]<0&&E0[T2]>=0){b1=T2;break}let l2=m0,y1=b1-F0,Y2=b1+F0;for(let T2=y1;T2{this.renderChannels[r.channel]=!r.isMuted}),this.updateFftSize()}function Iy(){for(let o=0;o4096?this.delayNode.delayTime.value=f/this.synth.context.sampleRate/2:this.delayNode.delayTime.value=0)}}function Ey(o){o.connectIndividualOutputs(this.channelAnalysers),o.eventHandler.addEvent("drumchange","renderer-drum-change",()=>{this.updateFftSize()})}function my(){for(let o of this.channelAnalysers)o.disconnect();Y5("%cAnalysers disconnected!",_1.recognized)}function Cy(o){this.seq=o,this.seq.addOnTimeChangeEvent(()=>this.resetIndexes(),"renderer-time-change"),this.seq.addOnSongChangeEvent(async r=>{if(this.calculateNoteTimes(await this.seq.getMIDI()),this.resetIndexes(),r.RMIDInfo?.IPIC!==void 0){let l=new Blob([r.RMIDInfo?.IPIC.buffer]),g=URL.createObjectURL(l),f=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${f}), rgba(0, 0, 0, ${f})), center center / cover url("${g}")`}else this.canvas.style.background=""},"renderer-song-change")}function By(){this.noteTimes&&this.noteTimes.forEach(o=>o.renderStartIndex=0)}function OB(o,r){let l=0;for(let g=8*(r-1);g>=0;g-=8)l|=o[o.currentIndex++]<>>0}function km(o,r){let l=new Array(r).fill(0);for(let g=r-1;g>=0;g--)l[g]=o&255,o>>=8;return l}var gh=.02;function py(o){function r(g0){return g0.messageData=new V3(g0.messageData.buffer),g0.messageData.currentIndex=0,6e7/OB(g0.messageData,3)}let l=[],f=o.tracks.flat();f.sort((g0,f1)=>g0.ticks-f1.ticks);for(let g0=0;g0<16;g0++)l.push({renderStartIndex:0,notes:[]});let S=0,n0=60/(120*o.timeDivision),E0=0,m0=0;for(;E0>4,x=g0.messageStatusByte&15;if(f1===8){let X0=l[x].notes.findLast(F0=>F0.midiNote===g0.messageData[0]&&F0.length===-1);if(X0){let F0=S-X0.start;X0.length=F0F0.midiNote===g0.messageData[0]&&F0.length===-1);if(X0){let F0=S-X0.start;X0.length=F0=f.length)break;S+=n0*(f[E0].ticks-g0.ticks)}m0>0&&l.forEach((g0,f1)=>g0.notes.filter(x=>x.length===-1).forEach(x=>{let X0=S-x.start;x.length=X0r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this._keyRange=r}toggleDarkMode(){this.canvas.classList.toggle("light_mode")}computeColors(){this.channelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,B$(r,g=>g*kC)),l.addColorStop(1,r),l}),this.darkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,B$(r,g=>g*kC*wC)),l.addColorStop(1,B$(r,g=>g*wC)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,B$(r,g=>g*kC)),l.addColorStop(1,r),l}),this.sidewaysDarkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,B$(r,g=>g*kC*wC)),l.addColorStop(1,B$(r,g=>g*wC)),l})}};_i.prototype.render=$y;_i.prototype.computeNotePositions=ly;_i.prototype.createChannelAnalysers=dy;_i.prototype.updateFftSize=Iy;_i.prototype.connectChannelAnalysers=Ey;_i.prototype.disconnectChannelAnalysers=my;_i.prototype.connectSequencer=Cy;_i.prototype.calculateNoteTimes=py;_i.prototype.resetIndexes=By;_i.prototype.renderWaveforms=uy;function o3(o,r){let l=0;for(let g=0;g>>0}function l7(o,r,l){for(let g=0;g>g*8&255}function Q9(o,r){o[o.currentIndex++]=r&255,o[o.currentIndex++]=r>>8}function c7(o,r){l7(o,r,4)}function LA(o,r){let l=r<<8|o;return l>32767?l-65536:l}function Qy(o){return o>127?o-256:o}function Ee(o,r,l=void 0,g=!0){if(l){let f=o.slice(o.currentIndex,o.currentIndex+r);return o.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(f.buffer)}else{let f=!1,S="";for(let n0=0;n0127){if(g){f=!0;continue}else if(E0===0){f=!0;continue}}S+=String.fromCharCode(E0)}}return S}}function RA(o,r=0){let l=o.length;r>0&&(l=r);let g=new V3(l);return g7(g,o,r),g}function g7(o,r,l=0){l>0&&r.length>l&&(r=r.slice(0,l));for(let g=0;gr.length)for(let g=0;gl.header!=="LIST"?!1:(l.chunkData.currentIndex=0,Ee(l.chunkData,4)===r))}function vC(o){let r=[o&127];for(o>>=7;o>0;)r.unshift(o&127|128),o>>=7;return r}function SC(o){let r=[];for(let f of o.tracks){let S=[],n0=0,E0;for(let m0 of f){let g0=m0.ticks-n0,f1;m0.messageStatusByte<=K3.keySignature||m0.messageStatusByte===K3.sequenceSpecific?f1=[255,m0.messageStatusByte,...vC(m0.messageData.length),...m0.messageData]:m0.messageStatusByte===K3.systemExclusive?f1=[240,...vC(m0.messageData.length),...m0.messageData]:(f1=[],E0!==m0.messageStatusByte&&(E0=m0.messageStatusByte,f1.push(m0.messageStatusByte)),f1.push(...m0.messageData)),S.push(...vC(g0)),S.push(...f1),n0+=g0}r.push(new Uint8Array(S))}function l(f,S){for(let n0=0;n0{o.tracks.forEach((b1,l2)=>{if(o.midiPorts[l2]===F0)for(let y1=b1.length-1;y1>=0;y1--)b1[y1].messageStatusByte>=128&&b1[y1].messageStatusByte<240&&(b1[y1].messageStatusByte&15)===X0&&b1.splice(y1,1)})};g.forEach(X0=>{let F0=X0%16,b1=X0-F0,l2=o.midiPortChannelOffsets.findIndex(y1=>y1===b1);S(F0,l2),Y5(`%cRemoving channel %c${X0}%c!`,_1.info,_1.recognized,_1.info)});let n0=!1,E0="gs",m0=[],g0=[];o.tracks.forEach((X0,F0)=>{X0.forEach(b1=>{let l2=b1.messageStatusByte&240;l2===K3.controllerChange?m0.push({track:F0,message:b1,channel:b1.messageStatusByte&15}):l2===K3.programChange?g0.push({track:F0,message:b1,channel:b1.messageStatusByte&15}):b1.messageStatusByte===K3.systemExclusive&&(b1.messageData[0]===67&&b1.messageData[2]===76&&b1.messageData[5]===126&&b1.messageData[6]===0?(Y5("%cXG system on detected",_1.info),E0="xg",n0=!0):b1.messageData[0]===67&&b1.messageData[2]===76&&b1.messageData[3]===8&&b1.messageData[5]===3&&g0.push({track:F0,message:b1,channel:b1.messageData[4]}))})});let f1=(X0,F0,b1)=>o.tracks.reduce((l2,y1,Y2)=>{if(o.usedChannelsOnTrack[Y2].has(X0)&&o.midiPorts[Y2]===F0){let T2;b1?T2=y1.findIndex(V2=>(V2.messageStatusByte&240)===K3.noteOn):T2=y1.findIndex(V2=>V2.messageStatusByte>128&&V2.messageStatusByte<240&&(V2.messageStatusByte&15)===X0&&!(V2.messageStatusByte&K3.controllerChange===240&&(V2.messageData[0]===B3.resetAllControllers||V2.messageData[0]===B3.allNotesOff||V2.messageData[0]===B3.allSoundOff))),T2!==-1&&l2.push({index:T2,track:Y2})}return l2},[]),x=(X0,F0,b1)=>{let l2=m0.filter(y1=>y1.channel===X0&&y1.message.messageData[0]===b1&&o.midiPorts[y1.track]===F0);for(let y1=0;y1{let F0=X0.channel,b1=F0%16,l2=F0-b1,y1=o.midiPortChannelOffsets.findIndex(A0=>A0===l2),Y2=X0.controllerValue,T2=X0.controllerNumber;x(b1,y1,T2),Y5(`%cNo controller %c${T2}%c on channel %c${F0}%c found. Adding it!`,_1.info,_1.unrecognized,_1.info,_1.value,_1.info);let V2=f1(b1,y1,!0);if(V2.length===0){x4("Program change but no notes... ignoring!");return}let i3=V2.reduce((A0,y5)=>o.tracks[y5.track][y5.index].ticks{let F0=X0.channel%16,b1=X0.channel-F0,l2=o.midiPortChannelOffsets.findIndex($3=>$3===b1),y1=X0.isDrum?0:X0.bank,Y2=X0.program,T2=g0.filter($3=>o.midiPorts[$3.track]===l2&&$3.channel===F0);if(x(F0,l2,B3.bankSelect),x(F0,l2,B3.lsbForControl0BankSelect),(X0.isDrum||y1>0)&&!n0&&(o.tracks.forEach($3=>{for(let w6=0;w6<$3.length;w6++){let s6=$3[w6];if(s6.messageStatusByte===K3.systemExclusive)if(s6.messageData[0]===65&&s6.messageData[2]===66&&s6.messageData[6]===127){n0=!0,Y5("%cGS on detected!",_1.recognized);break}else s6.messageData[0]===126&&s6.messageData[2]===9&&(Y5("%cGM/2 on detected, removing!",_1.info),$3.splice(w6,1),w6--)}}),!n0)){let $3=0;o.tracks[0][0].messageStatusByte===K3.trackName&&$3++,o.tracks[0].splice($3,0,qB(0)),Y5("%cGS on not detected. Adding it.",_1.info),n0=!0}for(let $3 of T2)o.tracks[$3.track].splice(o.tracks[$3.track].indexOf($3.message),1);let V2=f1(F0,l2,b1>0);if(V2.length===0){x4("Program change but no notes... ignoring!");return}let i3=V2.reduce(($3,w6)=>o.tracks[w6.track][w6.index].ticks{if(o.midiPorts[T2]!==b1||!o.usedChannelsOnTrack[T2].has(F0))return;let V2=K3.noteOn|F0,i3=K3.noteOff|F0,r3=K3.polyPressure|F0;Y2.forEach(A0=>{A0.messageStatusByte!==V2&&A0.messageStatusByte!==i3&&A0.messageStatusByte!==r3||(A0.messageData[0]=Math.max(0,Math.min(127,A0.messageData[0]+l2)))})}),y1!==0){let Y2=o.tracks.find((s6,o9)=>o.usedChannelsOnTrack[o9].has(X0.channel));if(Y2===void 0){x4(`Channel ${X0.channel} unused but transpose requested???`);continue}let T2=K3.noteOn|X0.channel%16,V2=Y2.findIndex(s6=>s6.messageStatusByte===T2);if(V2===-1){x4(`No notes on channel ${X0.channel} but transpose requested???`);continue}let i3=Y2[V2].ticks,r3=y1*64+64,A0=K3.controllerChange|X0.channel%16,y5=new mi(i3,A0,new V3([B3.RPNMsb,0])),T3=new mi(i3,A0,new V3([B3.RPNLsb,1])),$3=new mi(i3,A0,new V3([B3.dataEntryMsb,r3])),w6=new mi(i3,A0,new V3([B3.lsbForControl6DataEntry,0]));Y2.splice(V2,0,w6),Y2.splice(V2,0,$3),Y2.splice(V2,0,T3),Y2.splice(V2,0,y5)}}i4()}function hh(o,r){let l=[],g=[],f=[],S=[];r.channelSnapshots.forEach((n0,E0)=>{if(n0.isMuted){g.push(E0);return}let m0=n0.channelTransposeKeyShift+n0.customControllers[QC.channelTransposeFine]/100;m0!==0&&l.push({channel:E0,keyShift:m0}),n0.lockPreset&&f.push({channel:E0,program:n0.program,bank:n0.bank,isDrum:n0.drumChannel}),n0.lockedControllers.forEach((g0,f1)=>{if(!g0||f1>127||f1===B3.bankSelect)return;let x=n0.midiControllers[f1]>>7;S.push({channel:E0,controllerNumber:f1,controllerValue:x})})}),Wb(o,f,S,g,l)}var Mt={name:"INAM",album:"IPRD",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"},FA="utf-8",jb="Created using SpessaSynth";function wy(o,r,l,g=0,f="Shift_JIS",S={},n0=!0){if(gr("%cWriting the RMIDI File...",_1.info),Y5(`%cConfiguration: Bank offset: %c${g}%c, encoding: %c${f}`,_1.info,_1.value,_1.info,_1.value),Y5("metadata",S),Y5("Initial bank offset",r.bankOffset),n0){let Y2=function(){let r3=0,A0=1/0;return r.tracks.forEach((y5,T3)=>{l2[T3]>=y5.length||y5[l2[T3]].ticksA0>r3?A0:r3),i3=[];for(let r3=0;r30;){let r3=Y2(),A0=r.tracks[r3];if(l2[r3]>=A0.length){y1--;continue}let y5=A0[l2[r3]];l2[r3]++;let T3=r.midiPortChannelOffsets[T2[r3]];if(y5.messageStatusByte===K3.midiPort){T2[r3]=y5.messageData[0];continue}let $3=y5.messageStatusByte&240;if($3!==K3.controllerChange&&$3!==K3.programChange&&$3!==K3.systemExclusive)continue;if($3===K3.systemExclusive){if(y5.messageData[0]!==65||y5.messageData[2]!==66||y5.messageData[3]!==18||y5.messageData[4]!==64||!(y5.messageData[5]&16)||y5.messageData[6]!==21){y5.messageData[0]===67&&y5.messageData[2]===76&&y5.messageData[5]===126&&y5.messageData[6]===0?F0="xg":y5.messageData[0]===65&&y5.messageData[2]===66&&y5.messageData[6]===127?F0="gs":y5.messageData[0]===126&&y5.messageData[2]===9&&(F0="gm",b1.push({tNum:r3,e:y5}));continue}let o9=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][y5.messageData[5]&15]+T3;i3[o9].drums=!!(y5.messageData[7]>0&&y5.messageData[5]>>4);continue}let w6=(y5.messageStatusByte&15)+T3,s6=i3[w6];if($3===K3.programChange){s6.drums?l.presets.findIndex(r4=>r4.program===y5.messageData[0]&&r4.bank===128)===-1&&(y5.messageData[0]=l.presets.find(r4=>r4.bank===128)?.program||0):l.presets.findIndex(r4=>r4.program===y5.messageData[0]&&r4.bank!==128)===-1&&(y5.messageData[0]=l.presets.find(r4=>r4.bank!==128)?.program||0),s6.program=y5.messageData[0];let o9=Math.max(0,s6.lastBank?.messageData[1]-r.bankOffset),V4=s6.drums?128:o9;if(s6.lastBank===void 0)continue;if(F0==="xg"&&s6.drums&&(i3[w6].lastBank.messageData[1]=127),l.presets.findIndex(r4=>r4.bank===V4&&r4.program===y5.messageData[0])===-1){let r4=l.presets.find(V6=>V6.program===y5.messageData[0])?.bank+g||g;s6.lastBank.messageData[1]=r4,Y5(`%cNo preset %c${V4}:${y5.messageData[0]}%c. Changing bank to ${r4}.`,_1.info,_1.recognized,_1.info)}else{let V6=(V4===128?F0==="xg"?127:0:o9)+g;s6.lastBank.messageData[1]=V6,Y5(`%cPreset %c${V4}:${y5.messageData[0]}%c exists. Changing bank to ${V6}.`,_1.info,_1.recognized,_1.info)}continue}y5.messageData[0]===B3.bankSelect&&(s6.hasBankSelect=!0,F0==="xg"&&(s6.drums=y5.messageData[1]===120||y5.messageData[1]===126||y5.messageData[1]===127),s6.lastBank=y5)}if(i3.forEach((r3,A0)=>{if(r3.hasBankSelect===!0)return;let y5=A0%16,T3=K3.programChange|y5,$3=Math.floor(A0/16)*16,w6=r.midiPortChannelOffsets.indexOf($3),s6=r.tracks.find((V6,We)=>r.midiPorts[We]===w6&&r.usedChannelsOnTrack[We].has(y5));if(s6===void 0)return;let o9=s6.findIndex(V6=>V6.messageStatusByte===T3);if(o9===-1){let V6=s6.findIndex(Vi=>Vi.messageStatusByte>128&&Vi.messageStatusByte<240&&(Vi.messageStatusByte&15)===y5);if(V6===-1)return;let We=s6[V6].ticks,Or=l.getPreset(0,0).program;s6.splice(V6,0,new mi(We,K3.programChange|y5,new V3([Or]))),o9=V6}Y5(`%cAdding bank select for %c${A0}`,_1.info,_1.recognized);let V4=s6[o9].ticks,r4=l.getPreset(0,r3.program)?.bank+g||g;s6.splice(o9,0,new mi(V4,K3.controllerChange|y5,new V3([B3.bankSelect,r4])))}),F0!=="gs"&&F0!=="xg"){for(let A0 of b1)r.tracks[A0.tNum].splice(r.tracks[A0.tNum].indexOf(A0.e),1);let r3=0;r.tracks[0][0].messageStatusByte===K3.trackName&&r3++,r.tracks[0].splice(r3,0,qB(0))}}let E0=new V3(SC(r).buffer),m0=[RA("INFO")],g0=new TextEncoder;if(m0.push(Ze(Mt.software,g0.encode("SpessaSynth"),!0)),S.name!==void 0?(m0.push(Ze(Mt.name,g0.encode(S.name),!0)),f=FA):m0.push(Ze(Mt.name,r.rawMidiName,!0)),S.creationDate!==void 0)f=FA,m0.push(Ze(Mt.creationDate,g0.encode(S.creationDate),!0));else{let F0=new Date().toLocaleString(void 0,{weekday:"long",year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"numeric"});m0.push(Ze(Mt.creationDate,RA(F0),!0))}if(S.comment!==void 0&&(f=FA,m0.push(Ze(Mt.comment,g0.encode(S.comment)))),S.engineer!==void 0&&m0.push(Ze(Mt.engineer,g0.encode(S.engineer),!0)),S.album!==void 0&&(f=FA,m0.push(Ze(Mt.album,g0.encode(S.album),!0))),S.artist!==void 0&&(f=FA,m0.push(Ze(Mt.artist,g0.encode(S.artist),!0))),S.genre!==void 0&&(f=FA,m0.push(Ze(Mt.genre,g0.encode(S.genre),!0))),S.picture!==void 0&&m0.push(Ze(Mt.picture,new Uint8Array(S.picture))),S.copyright!==void 0)f=FA,m0.push(Ze(Mt.copyright,g0.encode(S.copyright),!0));else{let F0=r.copyright.length>0?r.copyright:jb;m0.push(Ze(Mt.copyright,RA(F0)))}let f1=new V3(2);l7(f1,g,2),m0.push(Ze(Mt.bankOffset,f1)),S.midiEncoding!==void 0&&(m0.push(Ze(Mt.midiEncoding,g0.encode(S.midiEncoding))),f=FA),m0.push(Ze(Mt.encoding,RA(f)));let x=Sn(m0),X0=Sn([RA("RMID"),Ze("data",E0),Ze("LIST",x),o]);return Y5("%cFinished!",_1.info),i4(),Ze("RIFF",X0)}function vm(o,r){let l=0;for(;o>0;){let g=r.tempoChanges.find(S=>S.ticks=128){this.MIDIout.send(g);return}break;case MA.songChange:let f=l[0];this.songIndex=l[1],this.midiData=f,this.hasDummyData=!1,this.absoluteStartTime=0,this.duration=this.midiData.duration,Object.entries(this.onSongChange).forEach(E0=>E0[1](f)),this.unpause();break;case MA.textEvent:let S=l;this.onTextEvent&&this.onTextEvent(S[0],S[1]);break;case MA.timeChange:let n0=this.synth.currentTime-l;Object.entries(this.onTimeChange).forEach(E0=>E0[1](n0)),this.unpause(),this._recalculateStartTime(n0);break;case MA.pause:this.pausedTime=this.currentTime,this.isFinished=l,this.isFinished&&Object.entries(this.onSongEnded).forEach(E0=>E0[1]());break;case MA.midiError:if(this.onError)this.onError(l);else throw new Error(l);return;case MA.getMIDI:this._getMIDIResolve&&this._getMIDIResolve(l)}}_recalculateStartTime(r){this.absoluteStartTime=this.synth.currentTime-r/this._playbackRate,this.highResTimeOffset=(this.synth.currentTime-performance.now()/1e3)*this._playbackRate}async getMIDI(){return new Promise(r=>{this._getMIDIResolve=r,this._sendMessage(Li.getMIDI,void 0)})}loadNewSongList(r){this.pause(),this.midiData=ky,this.hasDummyData=!0,this.duration=99999,this._sendMessage(Li.loadNewSongList,r),this.songIndex=0,this.songsAmount=r.length,this.songsAmount>1&&(this.loop=!1)}connectMidiOutput(r){this.resetMIDIOut(),this.MIDIout=r,this._sendMessage(Li.changeMIDIMessageSending,r!==void 0),this.currentTime-=.1}pause(){if(this.paused){x4("Already paused");return}this.pausedTime=this.currentTime,this._sendMessage(Li.pause)}unpause(){this.pausedTime=void 0,this.isFinished=!1}play(r=!1){this.isFinished&&(r=!0),this._recalculateStartTime(this.pausedTime||0),this.unpause(),this._sendMessage(Li.play,r)}stop(){this._sendMessage(Li.stop)}};var Sm=["Shift_JIS","windows-1250","utf-8","utf-16","utf-16le","utf-16be","latin1","ISO-8859-1","ISO-8859-2","ISO-8859-3","ISO-8859-4","ISO-8859-5","ISO-8859-6","ISO-8859-7","ISO-8859-8","ISO-8859-9","ISO-8859-10","ISO-8859-11","ISO-8859-13","ISO-8859-14","ISO-8859-15","ISO-8859-16","windows-1251","windows-1252","windows-1253","windows-1254","windows-1255","windows-1256","windows-1257","windows-1258","EUC-JP","ISO-2022-JP","EUC-KR","Big5","GB18030"];function vy(o){return` `}function y$(o){return` diff --git a/src/website/minified/local_main.min.js b/src/website/minified/local_main.min.js index 8a40c23a..d44f1933 100644 --- a/src/website/minified/local_main.min.js +++ b/src/website/minified/local_main.min.js @@ -6,7 +6,7 @@ var hC=(o=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(o,{get:(r,l)=>( Transform type: ${this.transformType} -`}},xB=960,RB=Nr.concave;function Tr(o,r,l,g,f){return o<<10|r<<9|l<<8|g<<7|f}var EC=[new se({srcEnum:Tr(RB,0,1,0,Rt.noteOnVelocity),dest:v1.initialAttenuation,amt:xB,secSrcEnum:0,transform:0}),new se({srcEnum:129,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(RB,0,1,1,B3.mainVolume),dest:v1.initialAttenuation,amt:xB,secSrcEnum:0,transform:0}),new se({srcEnum:13,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new se({srcEnum:526,dest:v1.fineTune,amt:12700,secSrcEnum:16,transform:0}),new se({srcEnum:650,dest:v1.pan,amt:1e3,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(RB,0,1,1,B3.expressionController),dest:v1.initialAttenuation,amt:xB,secSrcEnum:0,transform:0}),new se({srcEnum:219,dest:v1.reverbEffectsSend,amt:750,secSrcEnum:0,transform:0}),new se({srcEnum:221,dest:v1.chorusEffectsSend,amt:750,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,0,0,0,Rt.polyPressure),dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,0,0,1,B3.tremoloDepth),dest:v1.modLfoToVolume,amt:24,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,1,0,1,B3.releaseTime),dest:v1.releaseVolEnv,amt:1200,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,1,0,1,B3.brightness),dest:v1.initialFilterFc,amt:6e3,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,1,0,1,B3.timbreHarmonicContent),dest:v1.initialFilterQ,amt:250,secSrcEnum:0,transform:0})];var m$=128,XQ=147,Fb=new Int16Array(XQ).fill(0),ni=(o,r)=>Fb[o]=r<<7;ni(B3.mainVolume,100);ni(B3.balance,64);ni(B3.expressionController,127);ni(B3.pan,64);ni(B3.timbreHarmonicContent,64);ni(B3.releaseTime,64);ni(B3.attackTime,64);ni(B3.brightness,64);ni(B3.soundController6,64);ni(B3.soundController7,64);ni(B3.soundController8,64);ni(B3.soundController9,64);ni(B3.generalPurposeController6,64);ni(B3.generalPurposeController8,64);ni(m$+Rt.pitchWheel,64);ni(m$+Rt.pitchWheelRange,2);var mC={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},ey=Object.keys(mC).length,Mb=new Float32Array(ey);Mb[mC.modulationMultiplier]=1;var ty={velocityOverride:128};var Tb="spessasynth-worklet-system",LB=350,Di=9,Nb=16;var ah=class{constructor(r,l,g=!0,f=void 0,D=jQ){W5("%cInitializing SpessaSynth synthesizer...",_1.info),this.context=r.context;let o0=f?.oneOutput===!0;this.eventHandler=new uC,this._voiceCap=LB,this._outputsAmount=Nb,this.channelsAmount=this._outputsAmount,this.resolveWhenReady=void 0,this.isReady=new Promise(c0=>this.resolveWhenReady=c0),this.channelProperties=[];for(let c0=0;c0this.handleMessage(c0.data),this.soundfontManager=new IC(this),this._snapshotCallback=void 0,this.sequencerCallbackFunction=void 0,D.reverbEnabled&&!o0&&(this.reverbProcessor=KQ(this.context,D.reverbImpulseResponse),this.reverbProcessor.connect(r),this.worklet.connect(this.reverbProcessor,0)),D.chorusEnabled&&!o0&&(this.chorusProcessor=new fC(r,D.chorusConfig),this.worklet.connect(this.chorusProcessor.input,1)),o0)this.worklet.connect(r,0);else for(let c0=2;c0{this.channelsAmount++})}get voiceCap(){return this._voiceCap}set voiceCap(r){this._setMasterParam(Cm.voicesCap,r),this._voiceCap=r}get highPerformanceMode(){return this._highPerformanceMode}set highPerformanceMode(r){this._highPerformanceMode=r}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}setLogLevel(r,l,g,f){this.post({channelNumber:Ci,messageType:c8.setLogLevel,messageData:[r,l,g,f]})}_setMasterParam(r,l){this.post({channelNumber:Ci,messageType:c8.setMasterParameter,messageData:[r,l]})}setInterpolationType(r){this._setMasterParam(Cm.interpolationType,r)}handleMessage(r){let l=r.messageData;switch(r.messageType){case E$.channelProperties:this.channelProperties=l,this._voicesAmount=this.channelProperties.reduce((g,f)=>g+f.voicesAmount,0);break;case E$.eventCall:this.eventHandler.callEvent(l.eventName,l.eventData);break;case E$.sequencerSpecific:this.sequencerCallbackFunction&&this.sequencerCallbackFunction(l.messageType,l.messageData);break;case E$.synthesizerSnapshot:this._snapshotCallback&&this._snapshotCallback(l);break;case E$.ready:this.resolveWhenReady();break;case E$.soundfontError:Ie(new Error(l)),this.eventHandler.callEvent("soundfonterror",l);break}}async getSynthesizerSnapshot(){return new Promise(r=>{this._snapshotCallback=l=>{this._snapshotCallback=void 0,r(l)},this.post({messageType:c8.requestSynthesizerSnapshot,messageData:void 0,channelNumber:Ci})})}addNewChannel(r=!0){this.channelProperties.push({voicesAmount:0,pitchBend:0,pitchBendRangeSemitones:0,isMuted:!1,isDrum:!1}),r&&this.post({channelNumber:0,messageType:c8.addNewChannel,messageData:null})}setVibrato(r,l){this.post({channelNumber:r,messageType:c8.setChannelVibrato,messageData:l})}connectIndividualOutputs(r){if(r.length!==this._outputsAmount)throw new Error(`input nodes amount differs from the system's outputs amount! +`}},xB=960,RB=Nr.concave;function Tr(o,r,l,g,f){return o<<10|r<<9|l<<8|g<<7|f}var EC=[new se({srcEnum:Tr(RB,0,1,0,Rt.noteOnVelocity),dest:v1.initialAttenuation,amt:xB,secSrcEnum:0,transform:0}),new se({srcEnum:129,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(RB,0,1,1,B3.mainVolume),dest:v1.initialAttenuation,amt:xB,secSrcEnum:0,transform:0}),new se({srcEnum:13,dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new se({srcEnum:526,dest:v1.fineTune,amt:12700,secSrcEnum:16,transform:0}),new se({srcEnum:650,dest:v1.pan,amt:500,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(RB,0,1,1,B3.expressionController),dest:v1.initialAttenuation,amt:xB,secSrcEnum:0,transform:0}),new se({srcEnum:219,dest:v1.reverbEffectsSend,amt:750,secSrcEnum:0,transform:0}),new se({srcEnum:221,dest:v1.chorusEffectsSend,amt:750,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,0,0,0,Rt.polyPressure),dest:v1.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,0,0,1,B3.tremoloDepth),dest:v1.modLfoToVolume,amt:24,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,1,0,1,B3.releaseTime),dest:v1.releaseVolEnv,amt:1200,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,1,0,1,B3.brightness),dest:v1.initialFilterFc,amt:6e3,secSrcEnum:0,transform:0}),new se({srcEnum:Tr(Nr.linear,1,0,1,B3.timbreHarmonicContent),dest:v1.initialFilterQ,amt:250,secSrcEnum:0,transform:0})];var m$=128,XQ=147,Fb=new Int16Array(XQ).fill(0),ni=(o,r)=>Fb[o]=r<<7;ni(B3.mainVolume,100);ni(B3.balance,64);ni(B3.expressionController,127);ni(B3.pan,64);ni(B3.timbreHarmonicContent,64);ni(B3.releaseTime,64);ni(B3.attackTime,64);ni(B3.brightness,64);ni(B3.soundController6,64);ni(B3.soundController7,64);ni(B3.soundController8,64);ni(B3.soundController9,64);ni(B3.generalPurposeController6,64);ni(B3.generalPurposeController8,64);ni(m$+Rt.pitchWheel,64);ni(m$+Rt.pitchWheelRange,2);var mC={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},ey=Object.keys(mC).length,Mb=new Float32Array(ey);Mb[mC.modulationMultiplier]=1;var ty={velocityOverride:128};var Tb="spessasynth-worklet-system",LB=350,Di=9,Nb=16;var ah=class{constructor(r,l,g=!0,f=void 0,D=jQ){W5("%cInitializing SpessaSynth synthesizer...",_1.info),this.context=r.context;let o0=f?.oneOutput===!0;this.eventHandler=new uC,this._voiceCap=LB,this._outputsAmount=Nb,this.channelsAmount=this._outputsAmount,this.resolveWhenReady=void 0,this.isReady=new Promise(c0=>this.resolveWhenReady=c0),this.channelProperties=[];for(let c0=0;c0this.handleMessage(c0.data),this.soundfontManager=new IC(this),this._snapshotCallback=void 0,this.sequencerCallbackFunction=void 0,D.reverbEnabled&&!o0&&(this.reverbProcessor=KQ(this.context,D.reverbImpulseResponse),this.reverbProcessor.connect(r),this.worklet.connect(this.reverbProcessor,0)),D.chorusEnabled&&!o0&&(this.chorusProcessor=new fC(r,D.chorusConfig),this.worklet.connect(this.chorusProcessor.input,1)),o0)this.worklet.connect(r,0);else for(let c0=2;c0{this.channelsAmount++})}get voiceCap(){return this._voiceCap}set voiceCap(r){this._setMasterParam(Cm.voicesCap,r),this._voiceCap=r}get highPerformanceMode(){return this._highPerformanceMode}set highPerformanceMode(r){this._highPerformanceMode=r}get currentTime(){return this.context.currentTime}get voicesAmount(){return this._voicesAmount}setLogLevel(r,l,g,f){this.post({channelNumber:Ci,messageType:c8.setLogLevel,messageData:[r,l,g,f]})}_setMasterParam(r,l){this.post({channelNumber:Ci,messageType:c8.setMasterParameter,messageData:[r,l]})}setInterpolationType(r){this._setMasterParam(Cm.interpolationType,r)}handleMessage(r){let l=r.messageData;switch(r.messageType){case E$.channelProperties:this.channelProperties=l,this._voicesAmount=this.channelProperties.reduce((g,f)=>g+f.voicesAmount,0);break;case E$.eventCall:this.eventHandler.callEvent(l.eventName,l.eventData);break;case E$.sequencerSpecific:this.sequencerCallbackFunction&&this.sequencerCallbackFunction(l.messageType,l.messageData);break;case E$.synthesizerSnapshot:this._snapshotCallback&&this._snapshotCallback(l);break;case E$.ready:this.resolveWhenReady();break;case E$.soundfontError:Ie(new Error(l)),this.eventHandler.callEvent("soundfonterror",l);break}}async getSynthesizerSnapshot(){return new Promise(r=>{this._snapshotCallback=l=>{this._snapshotCallback=void 0,r(l)},this.post({messageType:c8.requestSynthesizerSnapshot,messageData:void 0,channelNumber:Ci})})}addNewChannel(r=!0){this.channelProperties.push({voicesAmount:0,pitchBend:0,pitchBendRangeSemitones:0,isMuted:!1,isDrum:!1}),r&&this.post({channelNumber:0,messageType:c8.addNewChannel,messageData:null})}setVibrato(r,l){this.post({channelNumber:r,messageType:c8.setChannelVibrato,messageData:l})}connectIndividualOutputs(r){if(r.length!==this._outputsAmount)throw new Error(`input nodes amount differs from the system's outputs amount! Expected ${this._outputsAmount} got ${r.length}`);for(let l=0;l127||l<0)throw new Error(`Invalid controller number: ${l}`);g=Math.floor(g),l=Math.floor(l),this.post({channelNumber:r,messageType:c8.ccChange,messageData:[l,g,f]})}resetControllers(){this.post({channelNumber:Ci,messageType:c8.ccReset,messageData:void 0})}channelPressure(r,l){this.post({channelNumber:r,messageType:c8.channelPressure,messageData:l})}polyPressure(r,l,g){this.post({channelNumber:r,messageType:c8.polyPressure,messageData:[l,g]})}post(r){this.worklet.port.postMessage(r)}pitchWheel(r,l,g){this.post({channelNumber:r,messageType:c8.pitchWheel,messageData:[l,g]})}transpose(r){this.transposeChannel(Ci,r,!1)}transposeChannel(r,l,g=!1){this.post({channelNumber:r,messageType:c8.transpose,messageData:[l,g]})}setMainVolume(r){this._setMasterParam(Cm.mainVolume,r)}setMasterPan(r){this._setMasterParam(Cm.masterPan,r)}setPitchBendRange(r,l){this.controllerChange(r,B3.RPNMsb,0),this.controllerChange(r,B3.dataEntryMsb,l),this.controllerChange(r,B3.RPNMsb,127),this.controllerChange(r,B3.RPNLsb,127),this.controllerChange(r,B3.dataEntryMsb,0)}programChange(r,l,g=!1){this.post({channelNumber:r,messageType:c8.programChange,messageData:[l,g]})}velocityOverride(r,l){this.post({channelNumber:r,messageType:c8.ccChange,messageData:[ty.velocityOverride,l,!0]})}lockController(r,l,g){this.post({channelNumber:r,messageType:c8.lockController,messageData:[l,g]})}muteChannel(r,l){this.post({channelNumber:r,messageType:c8.muteChannel,messageData:l})}async reloadSoundFont(r){Ie("reloadSoundFont is deprecated. Please use the soundfontManager property instead."),await this.soundfontManager.reloadManager(r)}systemExclusive(r){this.post({channelNumber:Ci,messageType:c8.systemExclusive,messageData:Array.from(r)})}setDrums(r,l){this.post({channelNumber:r,messageType:c8.setDrums,messageData:l})}sendMessage(r){let l=VQ(r[0]);switch(l.status){case K3.noteOn:let g=r[2];g>0?this.noteOn(l.channel,r[1],g):this.noteOff(l.channel,r[1]);break;case K3.noteOff:this.noteOff(l.channel,r[1]);break;case K3.pitchBend:this.pitchWheel(l.channel,r[2],r[1]);break;case K3.controllerChange:this.controllerChange(l.channel,r[1],r[2]);break;case K3.programChange:this.programChange(l.channel,r[1]);break;case K3.polyPressure:this.polyPressure(l.channel,r[0],r[1]);break;case K3.channelPressure:this.channelPressure(l.channel,r[1]);break;case K3.systemExclusive:this.systemExclusive(new V3(r.slice(1)));break;case K3.reset:this.stopAll(!0),this.resetControllers();break;default:break}}reverbateEverythingBecauseWhyNot(){for(let r=0;r{this.pressedKeys.delete(g),this.releaseNote(g,this.channel),this.synth.noteOff(this.channel,g)},r=(g,f)=>{let D;if(xA)D=127;else{let E0=this.keys[0].getBoundingClientRect();if(this.keyboard.classList.contains("sideways")){let m0=f.clientX-E0.left,c0=E0.width;D=Math.floor((c0-m0)/c0*127)}else{let m0=f.clientY-E0.top,c0=E0.height;D=Math.floor(m0/c0*127)}}this.synth.noteOn(this.channel,g,D,this.enableDebugging)},l=g=>{let f=g.touches?Array.from(g.touches):[g],D=new Set;f.forEach(o0=>{let E0=document.elementFromPoint(o0.clientX,o0.clientY),m0=parseInt(E0.id.replace("note",""));D.add(m0),!(isNaN(m0)||m0<0||this.pressedKeys.has(m0))&&(this.pressedKeys.add(m0),r(m0,o0))}),this.pressedKeys.forEach(o0=>{D.has(o0)||o(o0)})};xA||(document.addEventListener("mousedown",g=>{this.mouseHeld=!0,l(g)}),document.addEventListener("mouseup",()=>{this.mouseHeld=!1,this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.onmousemove=g=>{this.mouseHeld&&l(g)},this.keyboard.onmouseleave=()=>{this.pressedKeys.forEach(g=>{o(g)})}),this.keyboard.ontouchstart=l.bind(this),this.keyboard.ontouchend=l.bind(this),this.keyboard.ontouchmove=l.bind(this)}var ry=20,pm=class{constructor(r,l){this.mouseHeld=!1,this.pressedKeys=new Set,this.mode="light",this.enableDebugging=!1,this.sizeChangeAnimationId=-1,this.modeChangeAnimationId=-1,this._keyRange={min:0,max:127},document.addEventListener("keydown",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,B3.sustainPedal,127),this.keyboard.style.filter="brightness(0.5)")}),document.addEventListener("keyup",g=>{g.key==="Shift"&&(this.synth.controllerChange(this.channel,B3.sustainPedal,0),this.keyboard.style.filter="")}),this.synth=l,this.channel=0,this.channelColors=r,this._shown=!0,this._createKeyboard(),this.synth.eventHandler.addEvent("noteon","keyboard-note-on",g=>{this.pressNote(g.midiNote,g.channel,g.velocity)}),this.synth.eventHandler.addEvent("noteoff","keyboard-note-off",g=>{this.releaseNote(g.midiNote,g.channel)}),this.synth.eventHandler.addEvent("stopall","keyboard-stop-all",()=>{this.clearNotes()}),this.synth.eventHandler.addEvent("mutechannel","keyboard-mute-channel",g=>{if(g.isMuted)for(let f=0;f<128;f++)this.releaseNote(f,g.channel)})}get shown(){return this._shown}set shown(r){r===!0?this.keyboard.style.display="":this.keyboard.style.display="none",this._shown=r}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this.setKeyRange(r,!0)}_createKeyboard(){this.keyboard=document.getElementById("keyboard"),this.keyboard.innerHTML="",this.keys=[],this.keyColors=[];for(let r=this._keyRange.min;r=0&&(D=l(r-1)),r<127&&(o0=l(r+1)),o0&&D?g.classList.add("between_sharps"):D?g.classList.add("left_sharp"):o0&&g.classList.add("right_sharp")}return g}toggleMode(r=!0){if(this.mode==="light"?this.mode="dark":this.mode="light",!r){this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")});return}this.modeChangeAnimationId&&clearTimeout(this.modeChangeAnimationId),this.keyboard.classList.add("mode_transform"),document.body.scrollHeight<=window.innerHeight&&document.body.classList.add("no_scroll"),this.modeChangeAnimationId=setTimeout(()=>{this.keys.forEach(g=>{g.classList.contains("flat_key")&&g.classList.toggle("flat_dark_key")}),this.keyboard.classList.remove("mode_transform"),setTimeout(()=>document.body.classList.remove("no_scroll"),500)},500)}setKeyRange(r,l=!0){Math.abs(r.max-r.min)<12&&(r.min-=6,r.max=r.min+12);let f=900/(r.max-r.min+5),D=document.styleSheets[0].cssRules,o0;for(let E0 of D)if(E0.selectorText==="#keyboard .key"){o0=E0;break}if(o0.style.setProperty("--pressed-transform-skew",`${8e-4/(f/7)}`),l){this.sizeChangeAnimationId&&clearTimeout(this.sizeChangeAnimationId);let E0=getComputedStyle(this.keyboard),m0=parseFloat(E0.getPropertyValue("--current-min-height").replace(/[^\d.]+/g,"")),c0=this.keyboard.getBoundingClientRect().height,f1=f/m0,x=c0*f1-c0,X0=(this._keyRange.min+this._keyRange.max)/2,F0=(r.min+r.max)/2;this._keyRange=r;let b1=this.keys.find(Y2=>Y2.classList.contains("sharp_key")).getBoundingClientRect().width,l2=(X0-F0)*b1,y1=parseFloat(E0.getPropertyValue("--key-border-radius").replace(/[^\d.]+/g,""));this.keyboard.style.marginTop=`${x}px`,this.keyboard.style.transition="",this.keyboard.style.transform=`scale(${f1}) translateX(${l2}px)`,this.keyboard.style.setProperty("--key-border-radius",`${y1/f1}vmin`),this.sizeChangeAnimationId=setTimeout(()=>{this.keyboard.style.setProperty("--current-min-height",`${f}`),this.keyboard.style.transition="none",this.keyboard.style.transform="",this.keyboard.style.marginTop="",this.keyboard.style.setProperty("--key-border-radius",""),this._createKeyboard(),setTimeout(()=>this.keyboard.style.transition="",75)},500)}else this.keyboard.style.setProperty("--current-min-height",`${f}`),this._keyRange=r,this._createKeyboard()}selectChannel(r){this.channel=r}pressNote(r,l,g){let f=this.keys[r-this._keyRange.min];if(f===void 0)return;f.classList.add("pressed");let D=f.classList.contains("sharp_key"),o0=g/127,E0=this.channelColors[l%16].match(/\d+(\.\d+)?/g).map(parseFloat),m0;if(!D&&this.mode==="light"?m0=`rgba(${E0.slice(0,3).map(f1=>255-(255-f1)*o0).join(", ")}, ${E0[3]})`:m0=`rgba(${E0.slice(0,3).map(f1=>f1*o0).join(", ")}, ${E0[3]})`,f.style.background=m0,this.mode==="dark"){let c0=ry*o0;f.style.boxShadow=`${m0} 0px 0px ${c0}px ${c0/5}px`}this.keyColors[r-this._keyRange.min].push(this.channelColors[l%16])}releaseNote(r,l){let g=this.keys[r-this._keyRange.min];if(g===void 0)return;l%=this.channelColors.length;let f=this.keyColors[r-this._keyRange.min];if(!f)return;let D=f.findLastIndex(o0=>o0===this.channelColors[l]);D!==-1&&(f.splice(D,1),g.style.background=f[f.length-1],this.mode==="dark"&&(g.style.boxShadow=`0px 0px ${ry}px ${f[f.length-1]}`),f.length<1&&(g.classList.remove("pressed"),g.style.background="",g.style.boxShadow=""))}clearNotes(){this.keys.forEach((r,l)=>{r.classList.remove("pressed"),r.style.background="",r.style.boxShadow="",this.keyColors[l]=[]})}};pm.prototype._handlePointers=iy;function C$(o,r){let l=o.replace(/[^\d,]/g,"").split(",");return`rgb(${r(parseInt(l[0]))}, ${r(parseInt(l[1]))}, ${r(parseInt(l[2]))})`}var Ub="#000";function ny(o,r,l){o.forEach(g=>{if(g.pressedProgress===0)return;r.fillStyle=g.color;let f=g.pressedProgress*g.velocity;if(r.globalAlpha=.5*f,l){r.fillRect(g.xPos,g.yPos-g.height*f,g.width,g.height*(f*2+1)),r.globalAlpha=1;return}r.fillRect(g.xPos-g.width*f,g.yPos,g.width*(f*2+1),g.height),r.globalAlpha=1}),o.forEach(g=>{r.fillStyle=g.color,r.save(),r.translate(g.xPos,g.yPos),r.fillRect(0,0,g.width,g.height),r.restore(),r.strokeStyle=Ub,r.lineWidth=g.stroke,r.strokeRect(g.xPos,g.yPos,g.width,g.height)})}var FB=!1;function sy(o=!0,r=!1){let l=(this.seq===void 0||this?.seq?.paused===!0)&&this.synth.voicesAmount===0&&!r;if(!this.renderBool||l)if(FB){o&&requestAnimationFrame(this.render.bind(this));return}else FB=!0;else FB=!1;if(o&&this.drawingContext.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderAnalysers&&!this.synth.highPerformanceMode&&this.renderWaveforms(),this.renderNotes&&this.noteTimes){let D=this.computeNotePositions(this.synth.highPerformanceMode);this.synth.highPerformanceMode||ny(D,this.drawingContext,this.sideways)}let g=performance.now()-this.frameTimeStart;this.frameTimeStart=performance.now();let f=1e3/g;this.drawingContext.textBaseline="hanging",this.drawingContext.textAlign="end",this.drawingContext.font=`${CC}px system-ui`,this.drawingContext.fillStyle="white",this.drawingContext.strokeStyle="white",this.drawingContext.fillText(`${this.notesOnScreen} notes`,this.canvas.width,CC*2+5),this.drawingContext.fillText(this.version,this.canvas.width,5),this.drawingContext.fillText(Math.round(f).toString()+" FPS",this.canvas.width,CC+5),this.onRender&&this.onRender(),o&&requestAnimationFrame(this.render.bind(this))}function oy(o=!1){this.notesOnScreen=0;let r=this.sideways?this.canvas.height:this.canvas.width,l=this.sideways?this.canvas.width:this.canvas.height,g=this.keyRange.max-this.keyRange.min,f=r/(g+1),D=f-p$*2,o0=this.noteFallingTimeMs/1e3,E0=this.noteAfterTriggerTimeMs/1e3,m0=this.seq.currentHighResolutionTime,c0=m0-E0,f1=o0+E0,x=c0+f1,X0=ay/f1,F0=[];this.synth.channelProperties.forEach(l2=>{if(this.showVisualPitch){let y1=l2.pitchBend-8192+this.visualPitchBendOffset;F0.push(l2.pitchBendRangeSemitones*(y1/8192*f))}else F0.push(0)});let b1=[];return this.noteTimes.forEach((l2,y1)=>{if(l2.renderStartIndex>=l2.notes.length||!this.renderChannels[y1])return;let Y2=l2.renderStartIndex,T2=l2.notes,V2=T2[Y2],i3=-1;for(;V2.start<=x&&(Y2++,!(this.notesOnScreen>$y));){let r3=V2.start+V2.length;if(r3>c0&&V2.length>0){let A0=V2.length/f1*l-p$*2;if(this.notesOnScreen<1e3||A0>X0){i3===-1&&(i3=Y2-1);let y5=(V2.start-c0)/f1*l,T3;if(this._notesFall?T3=l-A0-y5+p$:T3=y5+p$,V2.midiNotethis.keyRange.max){if(Y2>=T2.length)break;V2=T2[Y2];continue}let $3=V2.midiNote-this.keyRange.min,w6=f*$3+p$,s6,o9,J4,r4;if(this.sideways?(s6=T3,o9=w6,r4=D,J4=A0):(o9=T3,s6=w6,J4=D,r4=A0),this.notesOnScreen++,o)this.drawingContext.fillStyle=this.plainColors[y1],this.drawingContext.fillRect(s6+B$+p$,o9+B$,J4-B$*2,r4-B$*2);else{let V6;if(V2.start>m0||r3=T2.length)break;V2=T2[Y2]}i3>-1&&(l2.renderStartIndex=i3)}),b1.sort((l2,y1)=>y1.height-l2.height),b1}function ly(){let o=this.canvas.width/4,r=this.canvas.height/4;this.channelAnalysers.forEach((l,g)=>{let f=g%4,D=Math.floor(g/4),o0=!1;for(let x=g;x0){o0=!0;break}if(!o0){let x=this.canvas.width/4,X0=this.canvas.height/4,F0=x*f,b1=X0*D+X0/2;this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this.drawingContext.moveTo(F0,b1),this.drawingContext.lineTo(F0+x,b1),this.drawingContext.stroke();return}let E0=new Float32Array(l.frequencyBinCount);l.getFloatTimeDomainData(E0);let m0=o*f,c0=r*D+r/2,f1=this.waveMultiplier*r;if(this.drawingContext.lineWidth=this.lineThickness,this.drawingContext.strokeStyle=this.channelColors[g],this.drawingContext.beginPath(),this._stabilizeWaveforms){let x=E0.length/4,X0=o/x,F0=Math.floor(x/2),b1=E0.length-F0;for(let T2=b1;T2>=1;T2--)if(E0[T2-1]<0&&E0[T2]>=0){b1=T2;break}let l2=m0,y1=b1-F0,Y2=b1+F0;for(let T2=y1;T2{this.renderChannels[r.channel]=!r.isMuted}),this.updateFftSize()}function hy(){for(let o=0;o4096?this.delayNode.delayTime.value=f/this.synth.context.sampleRate/2:this.delayNode.delayTime.value=0)}}function uy(o){o.connectIndividualOutputs(this.channelAnalysers),o.eventHandler.addEvent("drumchange","renderer-drum-change",()=>{this.updateFftSize()})}function fy(){for(let o of this.channelAnalysers)o.disconnect();W5("%cAnalysers disconnected!",_1.recognized)}function dy(o){this.seq=o,this.seq.addOnTimeChangeEvent(()=>this.resetIndexes(),"renderer-time-change"),this.seq.addOnSongChangeEvent(async r=>{if(this.calculateNoteTimes(await this.seq.getMIDI()),this.resetIndexes(),r.RMIDInfo?.IPIC!==void 0){let l=new Blob([r.RMIDInfo?.IPIC.buffer]),g=URL.createObjectURL(l),f=this.canvas.classList.contains("light_mode")?0:.9;this.canvas.style.background=`linear-gradient(rgba(0, 0, 0, ${f}), rgba(0, 0, 0, ${f})), center center / cover url("${g}")`}else this.canvas.style.background=""},"renderer-song-change")}function Iy(){this.noteTimes&&this.noteTimes.forEach(o=>o.renderStartIndex=0)}function MB(o,r){let l=0;for(let g=8*(r-1);g>=0;g-=8)l|=o[o.currentIndex++]<>>0}function Qm(o,r){let l=new Array(r).fill(0);for(let g=r-1;g>=0;g--)l[g]=o&255,o>>=8;return l}var $h=.02;function Ey(o){function r(c0){return c0.messageData=new V3(c0.messageData.buffer),c0.messageData.currentIndex=0,6e7/MB(c0.messageData,3)}let l=[],f=o.tracks.flat();f.sort((c0,f1)=>c0.ticks-f1.ticks);for(let c0=0;c0<16;c0++)l.push({renderStartIndex:0,notes:[]});let D=0,o0=60/(120*o.timeDivision),E0=0,m0=0;for(;E0>4,x=c0.messageStatusByte&15;if(f1===8){let X0=l[x].notes.findLast(F0=>F0.midiNote===c0.messageData[0]&&F0.length===-1);if(X0){let F0=D-X0.start;X0.length=F0<$h&&x===Di?$h:F0}m0--}else if(f1===9)if(c0.messageData[1]===0){let X0=l[x].notes.findLast(F0=>F0.midiNote===c0.messageData[0]&&F0.length===-1);if(X0){let F0=D-X0.start;X0.length=F0<$h&&x===Di?$h:F0}m0--}else l[c0.messageStatusByte&15].notes.push({midiNote:c0.messageData[0],start:D,length:-1,velocity:c0.messageData[1]/127}),m0++;else c0.messageStatusByte===81&&(o0=60/(r(c0)*o.timeDivision));if(++E0>=f.length)break;D+=o0*(f[E0].ticks-c0.ticks)}m0>0&&l.forEach((c0,f1)=>c0.notes.filter(x=>x.length===-1).forEach(x=>{let X0=D-x.start;x.length=X0<$h&&f1===Di?$h:X0})),this.noteTimes=l,W5("%cFinished loading note times and ready to render the sequence!",_1.info)}var Pb=1024,Ob=4096,qb=2,Hb=2,BC=.6,pC=.5,B$=1,p$=1,CC=12,Ay=.6,ay=2,$y=81572,_i=class{onRender;constructor(r,l,g,f,D=""){this.noteFallingTimeMs=1e3,this.noteAfterTriggerTimeMs=0,this._keyRange={min:0,max:127},this.version="v"+D,this.visualPitchBendOffset=0,this.lineThickness=Hb,this._normalAnalyserFft=Pb,this._drumAnalyserFft=Ob,this.waveMultiplier=qb,this._notesFall=!0,this.sideways=!1,this._renderBool=!0,this.renderAnalysers=!0,this.renderNotes=!0,this.drawActiveNotes=!0,this.showVisualPitch=!0,this._stabilizeWaveforms=!0,this.renderChannels=Array(16).fill(!0),this.canvas=g,this.drawingContext=this.canvas.getContext("2d"),this.plainColors=r,this.computeColors(),this.synth=l,this.delayNode=f,this.notesOnScreen=0,this.channelAnalysers=[],this.createChannelAnalysers(l),this.connectChannelAnalysers(l)}get stabilizeWaveforms(){return this._stabilizeWaveforms}set stabilizeWaveforms(r){this._stabilizeWaveforms=r,this.updateFftSize()}get direction(){return this._notesFall?"down":"up"}set direction(r){this._notesFall=r==="down"}get normalAnalyserFft(){return this._normalAnalyserFft}set normalAnalyserFft(r){this._normalAnalyserFft=r,this.updateFftSize()}get drumAnalyserFft(){return this._drumAnalyserFft}set drumAnalyserFft(r){this._drumAnalyserFft=r,this.updateFftSize()}get renderBool(){return this._renderBool}set renderBool(r){this._renderBool=r,r===!0?this.connectChannelAnalysers(this.synth):this.disconnectChannelAnalysers()}get keyRange(){return this._keyRange}set keyRange(r){if(r.max===void 0||r.min===void 0)throw new TypeError("No min or max property!");if(r.min>r.max){let l=r.min;r.min=r.max,r.max=l}r.min=Math.max(0,r.min),r.max=Math.min(127,r.max),this._keyRange=r}toggleDarkMode(){this.canvas.classList.toggle("light_mode")}computeColors(){this.channelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,C$(r,g=>g*pC)),l.addColorStop(1,r),l}),this.darkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,this.canvas.width/128,0);return l.addColorStop(0,C$(r,g=>g*pC*BC)),l.addColorStop(1,C$(r,g=>g*BC)),l}),this.sidewaysChannelColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,C$(r,g=>g*pC)),l.addColorStop(1,r),l}),this.sidewaysDarkerColors=this.plainColors.map(r=>{let l=this.drawingContext.createLinearGradient(0,0,0,this.canvas.width/128);return l.addColorStop(0,C$(r,g=>g*pC*BC)),l.addColorStop(1,C$(r,g=>g*BC)),l})}};_i.prototype.render=sy;_i.prototype.computeNotePositions=oy;_i.prototype.createChannelAnalysers=gy;_i.prototype.updateFftSize=hy;_i.prototype.connectChannelAnalysers=uy;_i.prototype.disconnectChannelAnalysers=fy;_i.prototype.connectSequencer=dy;_i.prototype.calculateNoteTimes=Ey;_i.prototype.resetIndexes=Iy;_i.prototype.renderWaveforms=ly;function o3(o,r){let l=0;for(let g=0;g>>0}function $7(o,r,l){for(let g=0;g>g*8&255}function Q9(o,r){o[o.currentIndex++]=r&255,o[o.currentIndex++]=r>>8}function l7(o,r){$7(o,r,4)}function RA(o,r){let l=r<<8|o;return l>32767?l-65536:l}function my(o){return o>127?o-256:o}function Ee(o,r,l=void 0,g=!0){if(l){let f=o.slice(o.currentIndex,o.currentIndex+r);return o.currentIndex+=r,new TextDecoder(l.replace(/[^\x20-\x7E]/g,"")).decode(f.buffer)}else{let f=!1,D="";for(let o0=0;o0127){if(g){f=!0;continue}else if(E0===0){f=!0;continue}}D+=String.fromCharCode(E0)}}return D}}function LA(o,r=0){let l=o.length;r>0&&(l=r);let g=new V3(l);return c7(g,o,r),g}function c7(o,r,l=0){l>0&&r.length>l&&(r=r.slice(0,l));for(let g=0;gr.length)for(let g=0;gl.header!=="LIST"?!1:(l.chunkData.currentIndex=0,Ee(l.chunkData,4)===r))}function QC(o){let r=[o&127];for(o>>=7;o>0;)r.unshift(o&127|128),o>>=7;return r}function yC(o){let r=[];for(let f of o.tracks){let D=[],o0=0,E0;for(let m0 of f){let c0=m0.ticks-o0,f1;m0.messageStatusByte<=K3.keySignature||m0.messageStatusByte===K3.sequenceSpecific?f1=[255,m0.messageStatusByte,...QC(m0.messageData.length),...m0.messageData]:m0.messageStatusByte===K3.systemExclusive?f1=[240,...QC(m0.messageData.length),...m0.messageData]:(f1=[],E0!==m0.messageStatusByte&&(E0=m0.messageStatusByte,f1.push(m0.messageStatusByte)),f1.push(...m0.messageData)),D.push(...QC(c0)),D.push(...f1),o0+=c0}r.push(new Uint8Array(D))}function l(f,D){for(let o0=0;o0{o.tracks.forEach((b1,l2)=>{if(o.midiPorts[l2]===F0)for(let y1=b1.length-1;y1>=0;y1--)b1[y1].messageStatusByte>=128&&b1[y1].messageStatusByte<240&&(b1[y1].messageStatusByte&15)===X0&&b1.splice(y1,1)})};g.forEach(X0=>{let F0=X0%16,b1=X0-F0,l2=o.midiPortChannelOffsets.findIndex(y1=>y1===b1);D(F0,l2),W5(`%cRemoving channel %c${X0}%c!`,_1.info,_1.recognized,_1.info)});let o0=!1,E0="gs",m0=[],c0=[];o.tracks.forEach((X0,F0)=>{X0.forEach(b1=>{let l2=b1.messageStatusByte&240;l2===K3.controllerChange?m0.push({track:F0,message:b1,channel:b1.messageStatusByte&15}):l2===K3.programChange?c0.push({track:F0,message:b1,channel:b1.messageStatusByte&15}):b1.messageStatusByte===K3.systemExclusive&&(b1.messageData[0]===67&&b1.messageData[2]===76&&b1.messageData[5]===126&&b1.messageData[6]===0?(W5("%cXG system on detected",_1.info),E0="xg",o0=!0):b1.messageData[0]===67&&b1.messageData[2]===76&&b1.messageData[3]===8&&b1.messageData[5]===3&&c0.push({track:F0,message:b1,channel:b1.messageData[4]}))})});let f1=(X0,F0,b1)=>o.tracks.reduce((l2,y1,Y2)=>{if(o.usedChannelsOnTrack[Y2].has(X0)&&o.midiPorts[Y2]===F0){let T2;b1?T2=y1.findIndex(V2=>(V2.messageStatusByte&240)===K3.noteOn):T2=y1.findIndex(V2=>V2.messageStatusByte>128&&V2.messageStatusByte<240&&(V2.messageStatusByte&15)===X0&&!(V2.messageStatusByte&K3.controllerChange===240&&(V2.messageData[0]===B3.resetAllControllers||V2.messageData[0]===B3.allNotesOff||V2.messageData[0]===B3.allSoundOff))),T2!==-1&&l2.push({index:T2,track:Y2})}return l2},[]),x=(X0,F0,b1)=>{let l2=m0.filter(y1=>y1.channel===X0&&y1.message.messageData[0]===b1&&o.midiPorts[y1.track]===F0);for(let y1=0;y1{let F0=X0.channel,b1=F0%16,l2=F0-b1,y1=o.midiPortChannelOffsets.findIndex(A0=>A0===l2),Y2=X0.controllerValue,T2=X0.controllerNumber;x(b1,y1,T2),W5(`%cNo controller %c${T2}%c on channel %c${F0}%c found. Adding it!`,_1.info,_1.unrecognized,_1.info,_1.value,_1.info);let V2=f1(b1,y1,!0);if(V2.length===0){Ie("Program change but no notes... ignoring!");return}let i3=V2.reduce((A0,y5)=>o.tracks[y5.track][y5.index].ticks{let F0=X0.channel%16,b1=X0.channel-F0,l2=o.midiPortChannelOffsets.findIndex($3=>$3===b1),y1=X0.isDrum?0:X0.bank,Y2=X0.program,T2=c0.filter($3=>o.midiPorts[$3.track]===l2&&$3.channel===F0);if(x(F0,l2,B3.bankSelect),x(F0,l2,B3.lsbForControl0BankSelect),(X0.isDrum||y1>0)&&!o0&&(o.tracks.forEach($3=>{for(let w6=0;w6<$3.length;w6++){let s6=$3[w6];if(s6.messageStatusByte===K3.systemExclusive)if(s6.messageData[0]===65&&s6.messageData[2]===66&&s6.messageData[6]===127){o0=!0,W5("%cGS on detected!",_1.recognized);break}else s6.messageData[0]===126&&s6.messageData[2]===9&&(W5("%cGM/2 on detected, removing!",_1.info),$3.splice(w6,1),w6--)}}),!o0)){let $3=0;o.tracks[0][0].messageStatusByte===K3.trackName&&$3++,o.tracks[0].splice($3,0,TB(0)),W5("%cGS on not detected. Adding it.",_1.info),o0=!0}for(let $3 of T2)o.tracks[$3.track].splice(o.tracks[$3.track].indexOf($3.message),1);let V2=f1(F0,l2,b1>0);if(V2.length===0){Ie("Program change but no notes... ignoring!");return}let i3=V2.reduce(($3,w6)=>o.tracks[w6.track][w6.index].ticks{if(o.midiPorts[T2]!==b1||!o.usedChannelsOnTrack[T2].has(F0))return;let V2=K3.noteOn|F0,i3=K3.noteOff|F0,r3=K3.polyPressure|F0;Y2.forEach(A0=>{A0.messageStatusByte!==V2&&A0.messageStatusByte!==i3&&A0.messageStatusByte!==r3||(A0.messageData[0]=Math.max(0,Math.min(127,A0.messageData[0]+l2)))})}),y1!==0){let Y2=o.tracks.find((s6,o9)=>o.usedChannelsOnTrack[o9].has(X0.channel));if(Y2===void 0){Ie(`Channel ${X0.channel} unused but transpose requested???`);continue}let T2=K3.noteOn|X0.channel%16,V2=Y2.findIndex(s6=>s6.messageStatusByte===T2);if(V2===-1){Ie(`No notes on channel ${X0.channel} but transpose requested???`);continue}let i3=Y2[V2].ticks,r3=y1*64+64,A0=K3.controllerChange|X0.channel%16,y5=new mi(i3,A0,new V3([B3.RPNMsb,0])),T3=new mi(i3,A0,new V3([B3.RPNLsb,1])),$3=new mi(i3,A0,new V3([B3.dataEntryMsb,r3])),w6=new mi(i3,A0,new V3([B3.lsbForControl6DataEntry,0]));Y2.splice(V2,0,w6),Y2.splice(V2,0,$3),Y2.splice(V2,0,T3),Y2.splice(V2,0,y5)}}i4()}function lh(o,r){let l=[],g=[],f=[],D=[];r.channelSnapshots.forEach((o0,E0)=>{if(o0.isMuted){g.push(E0);return}let m0=o0.channelTransposeKeyShift+o0.customControllers[mC.channelTransposeFine]/100;m0!==0&&l.push({channel:E0,keyShift:m0}),o0.lockPreset&&f.push({channel:E0,program:o0.program,bank:o0.bank,isDrum:o0.drumChannel}),o0.lockedControllers.forEach((c0,f1)=>{if(!c0||f1>127||f1===B3.bankSelect)return;let x=o0.midiControllers[f1]>>7;D.push({channel:E0,controllerNumber:f1,controllerValue:x})})}),Jb(o,f,D,g,l)}var Lt={name:"INAM",album:"IPRD",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"},FA="utf-8",Vb="Created using SpessaSynth";function By(o,r,l,g=0,f="Shift_JIS",D={},o0=!0){if(cr("%cWriting the RMIDI File...",_1.info),W5(`%cConfiguration: Bank offset: %c${g}%c, encoding: %c${f}`,_1.info,_1.value,_1.info,_1.value),W5("metadata",D),W5("Initial bank offset",r.bankOffset),o0){let Y2=function(){let r3=0,A0=1/0;return r.tracks.forEach((y5,T3)=>{l2[T3]>=y5.length||y5[l2[T3]].ticksA0>r3?A0:r3),i3=[];for(let r3=0;r30;){let r3=Y2(),A0=r.tracks[r3];if(l2[r3]>=A0.length){y1--;continue}let y5=A0[l2[r3]];l2[r3]++;let T3=r.midiPortChannelOffsets[T2[r3]];if(y5.messageStatusByte===K3.midiPort){T2[r3]=y5.messageData[0];continue}let $3=y5.messageStatusByte&240;if($3!==K3.controllerChange&&$3!==K3.programChange&&$3!==K3.systemExclusive)continue;if($3===K3.systemExclusive){if(y5.messageData[0]!==65||y5.messageData[2]!==66||y5.messageData[3]!==18||y5.messageData[4]!==64||!(y5.messageData[5]&16)||y5.messageData[6]!==21){y5.messageData[0]===67&&y5.messageData[2]===76&&y5.messageData[5]===126&&y5.messageData[6]===0?F0="xg":y5.messageData[0]===65&&y5.messageData[2]===66&&y5.messageData[6]===127?F0="gs":y5.messageData[0]===126&&y5.messageData[2]===9&&(F0="gm",b1.push({tNum:r3,e:y5}));continue}let o9=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][y5.messageData[5]&15]+T3;i3[o9].drums=!!(y5.messageData[7]>0&&y5.messageData[5]>>4);continue}let w6=(y5.messageStatusByte&15)+T3,s6=i3[w6];if($3===K3.programChange){s6.drums?l.presets.findIndex(r4=>r4.program===y5.messageData[0]&&r4.bank===128)===-1&&(y5.messageData[0]=l.presets.find(r4=>r4.bank===128)?.program||0):l.presets.findIndex(r4=>r4.program===y5.messageData[0]&&r4.bank!==128)===-1&&(y5.messageData[0]=l.presets.find(r4=>r4.bank!==128)?.program||0),s6.program=y5.messageData[0];let o9=Math.max(0,s6.lastBank?.messageData[1]-r.bankOffset),J4=s6.drums?128:o9;if(s6.lastBank===void 0)continue;if(F0==="xg"&&s6.drums&&(i3[w6].lastBank.messageData[1]=127),l.presets.findIndex(r4=>r4.bank===J4&&r4.program===y5.messageData[0])===-1){let r4=l.presets.find(V6=>V6.program===y5.messageData[0])?.bank+g||g;s6.lastBank.messageData[1]=r4,W5(`%cNo preset %c${J4}:${y5.messageData[0]}%c. Changing bank to ${r4}.`,_1.info,_1.recognized,_1.info)}else{let V6=(J4===128?F0==="xg"?127:0:o9)+g;s6.lastBank.messageData[1]=V6,W5(`%cPreset %c${J4}:${y5.messageData[0]}%c exists. Changing bank to ${V6}.`,_1.info,_1.recognized,_1.info)}continue}y5.messageData[0]===B3.bankSelect&&(s6.hasBankSelect=!0,F0==="xg"&&(s6.drums=y5.messageData[1]===120||y5.messageData[1]===126||y5.messageData[1]===127),s6.lastBank=y5)}if(i3.forEach((r3,A0)=>{if(r3.hasBankSelect===!0)return;let y5=A0%16,T3=K3.programChange|y5,$3=Math.floor(A0/16)*16,w6=r.midiPortChannelOffsets.indexOf($3),s6=r.tracks.find((V6,We)=>r.midiPorts[We]===w6&&r.usedChannelsOnTrack[We].has(y5));if(s6===void 0)return;let o9=s6.findIndex(V6=>V6.messageStatusByte===T3);if(o9===-1){let V6=s6.findIndex(Ji=>Ji.messageStatusByte>128&&Ji.messageStatusByte<240&&(Ji.messageStatusByte&15)===y5);if(V6===-1)return;let We=s6[V6].ticks,qr=l.getPreset(0,0).program;s6.splice(V6,0,new mi(We,K3.programChange|y5,new V3([qr]))),o9=V6}W5(`%cAdding bank select for %c${A0}`,_1.info,_1.recognized);let J4=s6[o9].ticks,r4=l.getPreset(0,r3.program)?.bank+g||g;s6.splice(o9,0,new mi(J4,K3.controllerChange|y5,new V3([B3.bankSelect,r4])))}),F0!=="gs"&&F0!=="xg"){for(let A0 of b1)r.tracks[A0.tNum].splice(r.tracks[A0.tNum].indexOf(A0.e),1);let r3=0;r.tracks[0][0].messageStatusByte===K3.trackName&&r3++,r.tracks[0].splice(r3,0,TB(0))}}let E0=new V3(yC(r).buffer),m0=[LA("INFO")],c0=new TextEncoder;if(m0.push(Ze(Lt.software,c0.encode("SpessaSynth"),!0)),D.name!==void 0?(m0.push(Ze(Lt.name,c0.encode(D.name),!0)),f=FA):m0.push(Ze(Lt.name,r.rawMidiName,!0)),D.creationDate!==void 0)f=FA,m0.push(Ze(Lt.creationDate,c0.encode(D.creationDate),!0));else{let F0=new Date().toLocaleString(void 0,{weekday:"long",year:"numeric",month:"long",day:"numeric",hour:"numeric",minute:"numeric"});m0.push(Ze(Lt.creationDate,LA(F0),!0))}if(D.comment!==void 0&&(f=FA,m0.push(Ze(Lt.comment,c0.encode(D.comment)))),D.engineer!==void 0&&m0.push(Ze(Lt.engineer,c0.encode(D.engineer),!0)),D.album!==void 0&&(f=FA,m0.push(Ze(Lt.album,c0.encode(D.album),!0))),D.artist!==void 0&&(f=FA,m0.push(Ze(Lt.artist,c0.encode(D.artist),!0))),D.genre!==void 0&&(f=FA,m0.push(Ze(Lt.genre,c0.encode(D.genre),!0))),D.picture!==void 0&&m0.push(Ze(Lt.picture,new Uint8Array(D.picture))),D.copyright!==void 0)f=FA,m0.push(Ze(Lt.copyright,c0.encode(D.copyright),!0));else{let F0=r.copyright.length>0?r.copyright:Vb;m0.push(Ze(Lt.copyright,LA(F0)))}let f1=new V3(2);$7(f1,g,2),m0.push(Ze(Lt.bankOffset,f1)),D.midiEncoding!==void 0&&(m0.push(Ze(Lt.midiEncoding,c0.encode(D.midiEncoding))),f=FA),m0.push(Ze(Lt.encoding,LA(f)));let x=bn(m0),X0=bn([LA("RMID"),Ze("data",E0),Ze("LIST",x),o]);return W5("%cFinished!",_1.info),i4(),Ze("RIFF",X0)}function ym(o,r){let l=0;for(;o>0;){let g=r.tempoChanges.find(D=>D.ticks=128){this.MIDIout.send(g);return}break;case MA.songChange:let f=l[0];this.songIndex=l[1],this.midiData=f,this.hasDummyData=!1,this.absoluteStartTime=0,this.duration=this.midiData.duration,Object.entries(this.onSongChange).forEach(E0=>E0[1](f)),this.unpause();break;case MA.textEvent:let D=l;this.onTextEvent&&this.onTextEvent(D[0],D[1]);break;case MA.timeChange:let o0=this.synth.currentTime-l;Object.entries(this.onTimeChange).forEach(E0=>E0[1](o0)),this.unpause(),this._recalculateStartTime(o0);break;case MA.pause:this.pausedTime=this.currentTime,this.isFinished=l,this.isFinished&&Object.entries(this.onSongEnded).forEach(E0=>E0[1]());break;case MA.midiError:if(this.onError)this.onError(l);else throw new Error(l);return;case MA.getMIDI:this._getMIDIResolve&&this._getMIDIResolve(l)}}_recalculateStartTime(r){this.absoluteStartTime=this.synth.currentTime-r/this._playbackRate,this.highResTimeOffset=(this.synth.currentTime-performance.now()/1e3)*this._playbackRate}async getMIDI(){return new Promise(r=>{this._getMIDIResolve=r,this._sendMessage(Ri.getMIDI,void 0)})}loadNewSongList(r){this.pause(),this.midiData=py,this.hasDummyData=!0,this.duration=99999,this._sendMessage(Ri.loadNewSongList,r),this.songIndex=0,this.songsAmount=r.length,this.songsAmount>1&&(this.loop=!1)}connectMidiOutput(r){this.resetMIDIOut(),this.MIDIout=r,this._sendMessage(Ri.changeMIDIMessageSending,r!==void 0),this.currentTime-=.1}pause(){if(this.paused){Ie("Already paused");return}this.pausedTime=this.currentTime,this._sendMessage(Ri.pause)}unpause(){this.pausedTime=void 0,this.isFinished=!1}play(r=!1){this.isFinished&&(r=!0),this._recalculateStartTime(this.pausedTime||0),this.unpause(),this._sendMessage(Ri.play,r)}stop(){this._sendMessage(Ri.stop)}};var wm=["Shift_JIS","windows-1250","utf-8","utf-16","utf-16le","utf-16be","latin1","ISO-8859-1","ISO-8859-2","ISO-8859-3","ISO-8859-4","ISO-8859-5","ISO-8859-6","ISO-8859-7","ISO-8859-8","ISO-8859-9","ISO-8859-10","ISO-8859-11","ISO-8859-13","ISO-8859-14","ISO-8859-15","ISO-8859-16","windows-1251","windows-1252","windows-1253","windows-1254","windows-1255","windows-1256","windows-1257","windows-1258","EUC-JP","ISO-2022-JP","EUC-KR","Big5","GB18030"];function Qy(o){return` `}function Q$(o){return`