diff --git a/package.json b/package.json index fd4277c..0b41819 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "SpessaSynth", - "version": "3.22.4", + "version": "3.22.5", "type": "module", "scripts": { "start": "node src/website/server/server.js", diff --git a/src/spessasynth_lib/synthetizer/worklet_processor.min.js b/src/spessasynth_lib/synthetizer/worklet_processor.min.js index 5ff11bf..fe0c99c 100644 --- a/src/spessasynth_lib/synthetizer/worklet_processor.min.js +++ b/src/spessasynth_lib/synthetizer/worklet_processor.min.js @@ -10,7 +10,7 @@ var cs=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(A,e)=>( `," ")),this.RMIDInfo.INAM&&(this.rawMidiName=this.RMIDInfo[$e.name],this.midiName=Z(this.rawMidiName,this.rawMidiName.length,void 0,!1).replaceAll(` `," "),g=!0),this.RMIDInfo.IALB&&!this.RMIDInfo.IPRD&&(this.RMIDInfo.IPRD=this.RMIDInfo.IALB),this.RMIDInfo.PRD&&!this.RMIDInfo.IALB&&(this.RMIDInfo.IALB=this.RMIDInfo.IPRD),this.bankOffset=1,this.RMIDInfo[$e.bankOffset]&&(this.bankOffset=k(this.RMIDInfo[$e.bankOffset],2))}}C&&(this.bankOffset=0)}else n=s;let B=this.readMIDIChunk(n);if(B.type!=="MThd")throw V(),new SyntaxError(`Invalid MIDI Header! Expected "MThd", got "${B.type}"`);if(B.size!==6)throw V(),new RangeError(`Invalid MIDI header chunk size! Expected 6, got ${B.size}`);this.format=$A(B.data,2),this.tracksAmount=$A(B.data,2),this.timeDivision=$A(B.data,2),this.keyRange={min:127,max:0},this.lyrics=[],this.tempoChanges=[{ticks:0,tempo:120}];let d=null,l=null;this.lastVoiceEventTick=0,this.midiPorts=[];let u=0;this.midiPortChannelOffsets=[],this.usedChannelsOnTrack=[],this.tracks=[];for(let S=0;S0&&(U+=this.tracks[S-1][this.tracks[S-1].length-1].ticks);w.data.currentIndexthis.lastVoiceEventTick&&(this.lastVoiceEventTick=U),W=ds[i>>4],(i&240)===F.noteOn){J.add(tA);let IA=w.data[w.data.currentIndex];this.keyRange.min=Math.min(this.keyRange.min,IA),this.keyRange.max=Math.max(this.keyRange.max,IA)}R=i;break}let K=new Y(W),$=w.data.slice(w.data.currentIndex,w.data.currentIndex+W);w.data.currentIndex+=W,K.set($,0);let EA=new Ce(U,i,K);switch(D.push(EA),tA){case-2:switch(i){case F.setTempo:this.tempoChanges.push({ticks:U,tempo:6e7/$A($,3)});break;case F.marker:switch(Z(K,K.length).trim().toLowerCase()){default:break;case"start":case"loopstart":d=U;break;case"loopend":l=U}K.currentIndex=0;break;case F.midiPort:let mA=K[0];this.midiPorts[S]=mA,this.midiPortChannelOffsets[mA]===void 0&&(this.midiPortChannelOffsets[mA]=u,u+=16);break;case F.copyright:o||(this.copyright+=Z(K,K.length,void 0,!1)+` `);break;case F.lyric:this.lyrics.push(K)}break;case-3:if(K.slice(0,7).every((IA,mA)=>Ho[mA]===IA)){let IA=K.slice(7,$.length-3),mA=Z(IA,IA.length)+` -`;this.copyright+=mA,m(`%cDecoded Roland SC message! %c${mA}`,r.recognized,r.value)}break;default:if((i&240)===F.controllerChange)switch(K[0]){case 2:case 116:d=U;break;case 4:case 117:l===null?l=U:l=0;break;case 0:C&&K[1]!==0&&K[1]!==127&&(m("%cDLS RMIDI with offset 1 detected!",r.recognized),this.bankOffset=1)}}}this.tracks.push(D),this.usedChannelsOnTrack.push(J),m(`%cParsed %c${this.tracks.length}%c / %c${this.tracksAmount}`,r.info,r.value,r.info,r.value)}m("%cAll tracks parsed correctly!",r.recognized),yA("%cCorrecting loops, ports and detecting notes...",r.info);let c=[];for(let S of this.tracks){let D=S.find(w=>(w.messageStatusByte&240)===F.noteOn);D&&c.push(D.ticks)}this.firstNoteOn=Math.min(...c),m(`%cFirst note-on detected at: %c${this.firstNoteOn}%c ticks!`,r.info,r.recognized,r.info),d!==null&&l===null?(d=this.firstNoteOn,l=this.lastVoiceEventTick):(d===null&&(d=this.firstNoteOn),(l===null||l===0)&&(l=this.lastVoiceEventTick)),this.loop={start:d,end:l},m(`%cLoop points: start: %c${this.loop.start}%c end: %c${this.loop.end}`,r.info,r.recognized,r.info,r.recognized);let p=0;for(let S of this.midiPorts)if(S!==-1){p=S;break}if(this.midiPorts=this.midiPorts.map(S=>S===-1?p:S),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0]),this.midiPortChannelOffsets.length<2?m("%cNo additional MIDI Ports detected.",r.info):m("%cMIDI Ports detected!",r.recognized),!g)if(this.tracks.length>1){if(this.tracks[0].find(S=>S.messageStatusByte>=F.noteOn&&S.messageStatusByteD.messageStatusByte===F.trackName);S&&(this.rawMidiName=S.messageData,this.midiName=Z(S.messageData,S.messageData.length,void 0,!1))}}else{let S=this.tracks[0].find(D=>D.messageStatusByte===F.trackName);S&&(this.rawMidiName=S.messageData,this.midiName=Z(S.messageData,S.messageData.length,void 0,!1))}if(this.fileName=e,this.midiName=this.midiName.trim(),this.midiName.length===0){m("%cNo name detected. Using the alt name!",r.info),this.midiName=ls(e),this.rawMidiName=new Uint8Array(this.midiName.length);for(let S=0;Su>l?u:l),s=[];for(let l=0;l{g[p]>=c.length||c[g[p]].ticks0;){let l=Q(),u=t.tracks[l];if(g[l]>=u.length){C--;continue}let c=u[g[l]];if(g[l]++,c.messageStatusByte===F.midiPort){B[l]=c.messageData[0];continue}let p=c.messageStatusByte&240;if(p!==F.noteOn&&p!==F.controllerChange&&p!==F.programChange&&p!==F.systemExclusive)continue;let S=(c.messageStatusByte&15)+t.midiPortChannelOffsets[B[l]]||0,D=s[S];switch(p){case F.programChange:D.program=c.messageData[0],n(D);break;case F.controllerChange:if(c.messageData[0]!==y.bankSelect||d==="gs"&&D.drums)continue;let w=c.messageData[1],J=Math.max(0,w-t.bankOffset);if(d==="xg"){let N=w===120||w===126||w===127;N!==D.drums?(D.drums=N,D.bank=D.drums?128:J,n(D)):D.bank=D.drums?128:J;continue}s[S].bank=J;break;case F.noteOn:if(c.messageData[1]===0)continue;n(D),o[D.string].add(`${c.messageData[0]}-${c.messageData[1]}`);break;case F.systemExclusive:if(c.messageData[0]!==65||c.messageData[2]!==66||c.messageData[3]!==18||c.messageData[4]!==64||!(c.messageData[5]&16)||c.messageData[6]!==21){c.messageData[0]===67&&c.messageData[2]===76&&c.messageData[5]===126&&c.messageData[6]===0&&(d="xg");continue}let R=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][c.messageData[5]&15]+t.midiPortChannelOffsets[B[l]],U=!!(c.messageData[7]>0&&c.messageData[5]>>4);D=s[R],D.drums=U,D.bank=U?128:0,n(D);break}}for(let l of Object.keys(o))o[l].size===0&&(m(`%cDetected change but no keys for %c${l}`,r.info,r.value),delete o[l]);return V(),o}function Ls(t,A){this.midiPortChannelOffset===0&&(this.midiPortChannelOffset+=16,this.midiPortChannelOffsets[A]=0),this.midiPortChannelOffsets[A]===void 0&&(this.synth.workletProcessorChannels.length{this.assignMIDIPort(s,e)}),this.duration=this.midiData.duration,this.firstNoteTime=Qe(this.midiData.firstNoteOn,this.midiData),m(`%cTotal song time: ${Dt(Math.ceil(this.duration)).time}`,r.recognized),this.post(FA.songChange,[new ze(this.midiData),this.songIndex,A]),this.duration<=1&&(T(`%cVery short song: (${Dt(Math.round(this.duration)).time}). Disabling loop!`,r.warn),this.loop=!1),A)this.play(!0);else{let e=this._skipToFirstNoteOn?this.midiData.firstNoteOn-1:0;this.setTimeTicks(e),this.pause()}}function Ts(t,A=!0){this.songs=t.reduce((e,s)=>{if(s.duration)return e.push(s),e;try{e.push(new et(s.binary,s.altName||""))}catch(n){return this.post(FA.midiError,n.message),e}return e},[]),!(this.songs.length<1)&&(this.songIndex=0,this.songs.length>1&&(this.loop=!1),this.loadNewSequence(this.songs[this.songIndex],A))}function Hs(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex++,this.songIndex%=this.songs.length,this.loadNewSequence(this.songs[this.songIndex])}function Ys(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex--,this.songIndex<0&&(this.songIndex=this.songs.length-1),this.loadNewSequence(this.songs[this.songIndex])}var KA=new Int16Array(127);KA[y.mainVolume]=100;KA[y.expressionController]=127;KA[y.pan]=64;KA[y.releaseTime]=64;KA[y.brightness]=64;KA[y.reverbDepth]=0;function Js(t,A=void 0){this.oneTickToSeconds=60/(120*this.midiData.timeDivision),this.synth.resetAllControllers(),this.sendMIDIReset(),this._resetTimers();let e=this.synth.workletProcessorChannels.length,s=Array(e).fill(8192),n=[];for(let C=0;CC===y.dataDecrement||C===y.dataIncrement||C===y.dataEntryMsb||C===y.dataDecrement||C===y.lsbForControl6DataEntry||C===y.RPNLsb||C===y.RPNMsb||C===y.NRPNLsb||C===y.NRPNMsb||C===y.bankSelect||C===y.lsbForControl0BankSelect||C===y.resetAllControllers,g=[];for(let C=0;C=A)break}else if(this.playedTime>=t)break;let B=Re(Q.messageStatusByte),d=B.channel+(this.midiPortChannelOffsets[this.midiPorts[C]]||0);switch(B.status){case F.noteOn:case F.noteOff:case F.keySignature:break;case F.pitchBend:s[d]=Q.messageData[1]<<7|Q.messageData[0];break;case F.programChange:let u=n[d];u.program=Q.messageData[0],u.actualBank=u.bank;break;case F.controllerChange:let c=Q.messageData[0];if(o(c)){let p=Q.messageData[1];if(c===y.bankSelect){n[d].bank=p;break}this.sendMIDIMessages?this.sendMIDICC(d,c,p):this.synth.controllerChange(d,c,p)}else g[d]===void 0&&(g[d]=Array.from(KA)),g[d][c]=Q.messageData[1];break;default:this._processEvent(Q,C);break}this.eventIndex[C]++,C=this._findFirstEventIndex();let l=this.tracks[C][this.eventIndex[C]];if(l===void 0)return this.stop(),!1;this.playedTime+=this.oneTickToSeconds*(l.ticks-Q.ticks)}if(this.sendMIDIMessages){for(let C=0;C>7,s[C]&127),g[C]!==void 0&&g[C].forEach((Q,B)=>{Q!==KA[B]&&!o(B)&&this.sendMIDICC(C,B,Q)}),n[C].program>=0&&n[C].actualBank>=0){let Q=n[C].actualBank;this.sendMIDICC(C,y.bankSelect,Q),this.sendMIDIProgramChange(C,n[C].program)}}else for(let C=0;C>7,s[C]&127),g[C]!==void 0&&g[C].forEach((Q,B)=>{Q!==KA[B]&&!o(B)&&this.synth.controllerChange(C,B,Q)}),n[C].program>=0&&n[C].actualBank>=0){let Q=n[C].actualBank;this.synth.controllerChange(C,y.bankSelect,Q),this.synth.programChange(C,n[C].program)}return!0}function vs(t=!1){if(this.midiData!==void 0){if(t){this.pausedTime=void 0,this.currentTime=0;return}if(this.currentTime>=this.duration){this.pausedTime=void 0,this.currentTime=0;return}this.paused&&(this._recalculateStartTime(this.pausedTime),this.pausedTime=void 0),this.sendMIDIMessages||this.playingNotes.forEach(A=>{this.synth.noteOn(A.channel,A.midiNote,A.velocity,!1,!0)}),this.setProcessHandler()}}function qs(t){this.stop(),this.playingNotes=[],this.pausedTime=void 0,this.post(FA.timeChange,currentTime-Qe(t,this.midiData));let A=this._playTo(0,t);this._recalculateStartTime(this.playedTime),A&&this.play()}function Ps(t){this.absoluteStartTime=currentTime-t/this._playbackRate}function Ks(t,A){switch(t){default:break;case wA.loadNewSongList:this.loadNewSongList(A[0],A[1]);break;case wA.pause:this.pause();break;case wA.play:this.play(A);break;case wA.stop:this.stop();break;case wA.setTime:this.currentTime=A;break;case wA.changeMIDIMessageSending:this.sendMIDIMessages=A;break;case wA.setPlaybackRate:this.playbackRate=A;break;case wA.setLoop:this.loop=A;break;case wA.changeSong:A?this.nextSong():this.previousSong();break;case wA.getMIDI:this.post(FA.getMIDI,this.midiData);break;case wA.setSkipToFirstNote:this._skipToFirstNoteOn=A;break;case wA.setPreservePlaybackState:this.preservePlaybackState=A}}function Os(t,A=void 0){this.synth.enableEventSystem&&this.synth.post({messageType:uA.sequencerSpecific,messageData:{messageType:t,messageData:A}})}function Vs(t){this.post(FA.midiEvent,t)}function Zs(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([F.controllerChange|t,A,e])}function Xs(t,A){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([F.programChange|t,A])}function Ws(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([F.pitchBend|t,e,A])}function _s(){if(this.sendMIDIMessages){this.sendMIDIMessage([F.reset]);for(let t=0;tthis.duration||A<0){this._skipToFirstNoteOn?this.setTimeTicks(this.midiData.firstNoteOn-1):this.setTimeTicks(0);return}if(this._skipToFirstNoteOn&&Azs?440*Math.pow(2,(t-6900)/1200):Nt[~~t-tt]}var Lt=-1660,Yo=1600,bt=new Float32Array((Yo-Lt)*100+1);for(let t=0;t.5?1:0,s?e*2-1:e;case QA.concave:return s?(e=e*2-1,e<0?-XA[~~(e*-CA)]:XA[~~(e*CA)]):XA[~~(e*CA)];case QA.convex:return s?(e=e*2-1,e<0?-oe[~~(e*-CA)]:oe[~~(e*CA)]):oe[~~(e*CA)]}}var Ut=1,Tt=new Float32Array(1e3);for(let t=0;t=e.loopEnd;)s-=o;let C=~~s,Q=C+1;for(;Q>=e.loopEnd;)Q-=o;let B=s-C,d=n[Q],l=n[C];A[g]=l+(d-l)*B,s+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end){t.finished=!0;return}let Q=s-g,B=n[C],d=n[g];A[o]=d+(B-d)*Q,s+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=s}function $s(t,A){let e=t.sample,s=e.cursor,n=e.loopEnd-e.loopStart,o=e.sampleData;if(t.sample.isLooping)for(let g=0;g=e.loopEnd;)s-=n;let C=~~s+1;for(;C>=e.loopEnd;)C-=n;A[g]=o[C],s+=e.playbackStep*t.currentTuningCalculated}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let g=0;g=e.end){t.finished=!0;return}A[g]=o[C],s+=e.playbackStep*t.currentTuningCalculated}}e.cursor=s}function An(t,A){let e=t.sample,s=e.cursor,n=e.sampleData;if(e.isLooping){let o=e.loopEnd-e.loopStart;for(let g=0;g=e.loopEnd;)s-=o;let C=~~s,Q=C+1,B=Q+1,d=B+1,l=s-C;Q>=e.loopEnd&&(Q-=o),B>=e.loopEnd&&(B-=o),d>=e.loopEnd&&(d-=o);let u=n[C],c=n[Q],p=n[B],S=n[d],D=.5*(p-u),w=u-2.5*c+2*p-.5*S,J=.5*(S-u)+1.5*(c-p);A[g]=((J*l+w)*l+D)*l+c,s+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end||Q>=e.end||B>=e.end){t.finished=!0;return}let l=n[g],u=n[C],c=n[Q],p=n[B],S=.5*(c-l),D=l-2.5*u+2*c-.5*p,w=.5*(p-l)+1.5*(u-c);A[o]=((w*d+D)*d+S)*d+u,s+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=s}var le=class t{a0=0;a1=0;a2=0;a3=0;a4=0;x1=0;x2=0;y1=0;y2=0;reasonanceCb=0;reasonanceGain=1;cutoffCents=13500;cutoffHz=2e4;static apply(A,e,s,n){if(n&&s>13499&&A.filter.reasonanceCb===0)return;let o=A.filter;(o.cutoffCents!==s||o.reasonanceCb!==A.modulatedGenerators[a.initialFilterQ])&&(o.cutoffCents=s,o.reasonanceCb=A.modulatedGenerators[a.initialFilterQ],t.calculateCoefficients(o));for(let g=0;g=Ht}static startRelease(A){A.volumeEnvelope.releaseStartTimeSamples=A.volumeEnvelope.currentSampleTime,A.volumeEnvelope.currentReleaseGain=OA(A.volumeEnvelope.currentAttenuationDb),t.recalculate(A)}static recalculate(A){let e=A.volumeEnvelope,s=B=>Math.max(0,Math.floor(JA(B)*e.sampleRate));e.attenuationTarget=Math.max(0,Math.min(A.modulatedGenerators[a.initialAttenuation],1440))/10,e.sustainDbRelative=Math.min(GA,A.modulatedGenerators[a.sustainVolEnv]/10);let n=Math.min(GA,e.sustainDbRelative);e.attackDuration=s(A.modulatedGenerators[a.attackVolEnv]);let o=A.modulatedGenerators[a.decayVolEnv],g=(60-A.targetKey)*A.modulatedGenerators[a.keyNumToVolEnvDecay],C=n/GA;e.decayDuration=s(o+g)*C,e.releaseDuration=s(A.modulatedGenerators[a.releaseVolEnv]),e.delayEnd=s(A.modulatedGenerators[a.delayVolEnv]),e.attackEnd=e.attackDuration+e.delayEnd;let Q=(60-A.targetKey)*A.modulatedGenerators[a.keyNumToVolEnvHold];if(e.holdEnd=s(A.modulatedGenerators[a.holdVolEnv]+Q)+e.attackEnd,e.decayEnd=e.decayDuration+e.holdEnd,e.state===0&&e.attackEnd===0&&(e.state=2),A.isInRelease){let B=Math.max(0,Math.min(GA,e.sustainDbRelative)),d=B/GA;switch(e.decayDuration=s(o+g)*d,e.state){case 0:e.releaseStartDb=GA;break;case 1:let u=1-(e.attackEnd-e.releaseStartTimeSamples)/e.attackDuration;e.releaseStartDb=20*Math.log10(u)*-1;break;case 2:e.releaseStartDb=0;break;case 3:e.releaseStartDb=(1-(e.decayEnd-e.releaseStartTimeSamples)/e.decayDuration)*B;break;case 4:e.releaseStartDb=B;break}e.releaseStartDb=Math.max(0,Math.min(e.releaseStartDb,GA)),e.releaseStartDb>=Ht&&(A.finished=!0),e.currentReleaseGain=OA(e.releaseStartDb);let l=(GA-e.releaseStartDb)/GA;e.releaseDuration*=l}}static apply(A,e,s,n){let o=A.volumeEnvelope,g=s/10,C=n;if(A.isInRelease){let B=o.currentSampleTime-o.releaseStartTimeSamples;if(B>=o.releaseDuration){for(let l=0;l=e.length)return;o.state++;case 1:for(;o.currentSampleTime=e.length)return}o.state++;case 2:for(;o.currentSampleTime=e.length)return;o.state++;case 3:for(;o.currentSampleTime=e.length)return;o.state++;case 4:for(o.canEndOnSilentSustain&&o.sustainDbRelative>=Ht&&(A.finished=!0);;)if(o.attenuation+=(o.attenuationTarget-o.attenuation)*C,e[Q]*=OA(o.sustainDbRelative+g+o.attenuation),o.currentAttenuationDb=o.sustainDbRelative,o.currentSampleTime++,++Q>=e.length)return}}};var tn=.05;function sn(t,A,e,s,n,o){if(A.isInRelease||currentTime>=A.releaseStartTime&&(A.isInRelease=!0,TA.startRelease(A),UA.startRelease(A),A.sample.loopingMode===3&&(A.sample.isLooping=!1)),A.modulatedGenerators[a.initialAttenuation]>2500){A.isInRelease&&(A.finished=!0);return}let g=A.targetKey,C=A.modulatedGenerators[a.fineTune]+t.customControllers[aA.channelTuning]+t.customControllers[aA.channelTransposeFine]+t.customControllers[aA.masterTuning]+t.channelOctaveTuning[A.midiNote%12]+t.keyCentTuning[A.midiNote],Q=A.modulatedGenerators[a.coarseTune]+t.customControllers[aA.channelTuningSemitones],B=this.tunings[t.preset.program]?.[A.realKey];B?.midiNote>=0&&(g=B.midiNote,C+=B.centTuning),C+=(g-A.sample.rootKey)*A.modulatedGenerators[a.scaleTuning];let d=A.modulatedGenerators[a.vibLfoToPitch];if(d!==0){let i=A.startTime+JA(A.modulatedGenerators[a.delayVibLFO]),tA=Ge(A.modulatedGenerators[a.freqVibLFO]),W=st(i,tA,currentTime);C+=W*(d*t.customControllers[aA.modulationMultiplier])}let l=A.modulatedGenerators[a.initialFilterFc],u=l,c=A.modulatedGenerators[a.modLfoToPitch],p=A.modulatedGenerators[a.modLfoToVolume],S=A.modulatedGenerators[a.modLfoToFilterFc],D=0;if(c+S+p!==0){let i=A.startTime+JA(A.modulatedGenerators[a.delayModLFO]),tA=Ge(A.modulatedGenerators[a.freqModLFO]),W=st(i,tA,currentTime);C+=W*(c*t.customControllers[aA.modulationMultiplier]),D=-W*p,u+=W*S}if(t.channelVibrato.depth>0){let i=st(A.startTime+t.channelVibrato.delay,t.channelVibrato.rate,currentTime);i&&(C+=i*t.channelVibrato.depth)}let w=A.modulatedGenerators[a.modEnvToPitch],J=A.modulatedGenerators[a.modEnvToFilterFc],R=UA.getValue(A,currentTime);u+=R*J,C+=R*w;let U=~~(C+Q*100);U!==A.currentTuningCents&&(A.currentTuningCents=U,A.currentTuningCalculated=Math.pow(2,U/1200));let N=new Float32Array(e.length);switch(this.interpolationType){case ce.linear:default:js(A,N);break;case ce.nearestNeighbor:$s(A,N);break;case ce.fourthOrder:An(A,N)}le.apply(A,N,u,l>13499),TA.apply(A,N,D,this.volumeEnvelopeSmoothingFactor),this.panVoice(A,N,e,s,n,o)}function vo(t,A){let e=0;return t.drumChannel&&(e+=5),A.isInRelease&&(e-=5),e+=A.velocity/25,e-=A.volumeEnvelope.state,A.isInRelease&&(e-=5),e-=A.volumeEnvelope.currentAttenuationDb/50,e}function nn(t){let A=[];for(let s of this.workletProcessorChannels)for(let n of s.voices)if(!n.finished){let o=vo(s,n);A.push({channel:s,voice:n,priority:o})}A.sort((s,n)=>s.priority-n.priority);let e=A.slice(0,t);for(let{channel:s,voice:n}of e){let o=s.voices.indexOf(n);o>-1&&s.voices.splice(o,1)}}function on(t){t.releaseStartTime=currentTime,t.releaseStartTime-t.startTimean=t);var qo=function(t){var A,e,s,n,o,g,C,Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",B="",d=0;t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");do n=Q.indexOf(t.charAt(d++)),o=Q.indexOf(t.charAt(d++)),g=Q.indexOf(t.charAt(d++)),C=Q.indexOf(t.charAt(d++)),A=n<<2|o>>4,e=(15&o)<<4|g>>2,s=(3&g)<<6|C,B+=String.fromCharCode(A),g!==64&&(B+=String.fromCharCode(e)),C!==64&&(B+=String.fromCharCode(s));while(d1&&(i.thisProgram=process.argv[1].replace(/\\/g,"/")),i.arguments=process.argv.slice(2),typeof module<"u",process.on("uncaughtException",function(I){if(!(I instanceof De))throw I}),process.on("unhandledRejection",function(I,E){process.exit(1)}),i.quit=function(I){process.exit(I)},i.inspect=function(){return"[Emscripten Module object]"}):EA?(typeof read<"u"&&(i.read=function(E){return read(E)}),i.readBinary=function(E){var h;return typeof readbuffer=="function"?new Uint8Array(readbuffer(E)):(zA(typeof(h=read(E,"binary"))=="object"),h)},typeof scriptArgs<"u"?i.arguments=scriptArgs:typeof arguments<"u"&&(i.arguments=arguments),typeof quit=="function"&&(i.quit=function(I){quit(I)})):(W||K)&&(W?document.currentScript&&(IA=document.currentScript.src):IA=self.location.href,IA=IA.indexOf("blob:")!==0?IA.split("/").slice(0,-1).join("/")+"/":"",i.read=function(E){var h=new XMLHttpRequest;return h.open("GET",E,!1),h.send(null),h.responseText},K&&(i.readBinary=function(E){var h=new XMLHttpRequest;return h.open("GET",E,!1),h.responseType="arraybuffer",h.send(null),new Uint8Array(h.response)}),i.readAsync=function(E,h,f){var G=new XMLHttpRequest;G.open("GET",E,!0),G.responseType="arraybuffer",G.onload=function(){if(G.status==200||G.status==0&&G.response){h(G.response);return}f()},G.onerror=f,G.send(null)},i.setWindowTitle=function(I){document.title=I});var be=i.print||(typeof console<"u"?console.log.bind(console):typeof print<"u"?print:null),xA=i.printErr||(typeof printErr<"u"?printErr:typeof console<"u"&&console.warn.bind(console)||be);for(t in tA)tA.hasOwnProperty(t)&&(i[t]=tA[t]);function Le(I){var E=c;return c=c+I+15&-16,E}function _t(I){var E=Q[R>>2],h=E+I+15&-16;return Q[R>>2]=h,h>=BA&&!rs()?(Q[R>>2]=E,0):E}function zt(I,E){return E||(E=16),I=Math.ceil(I/E)*E}function So(I){switch(I){case"i1":case"i8":return 1;case"i16":return 2;case"i32":case"float":return 4;case"i64":case"double":return 8;default:if(I[I.length-1]==="*")return 4;if(I[0]!=="i")return 0;var E=parseInt(I.substr(1));return zA(E%8==0),E/8}}function pe(I){pe.shown||(pe.shown={}),pe.shown[I]||(pe.shown[I]=1,xA(I))}tA=void 0;var Do={"f64-rem":function(I,E){return I%E},debugger:function(){}},Ct=[];function zo(I,E){for(var h=0,f=h;f>>0)+4294967296*+(E>>>0):+(I>>>0)+4294967296*+(0|E)}function Bt(I,E,h){return h&&h.length?i["dynCall_"+I].apply(null,[E].concat(h)):i["dynCall_"+I].call(null,E)}var Ue=0,jt=0;function zA(I,E){I||ZA("Assertion failed: "+E)}function $t(I){var E=i["_"+I];return zA(E,"Cannot call unknown function "+I+", make sure it is exported"),E}var As={stackSave:function(){mt()},stackRestore:function(){ft()},arrayToC:function(I){var E,h,f=qe(I.length);return E=I,h=f,n.set(E,h),f},stringToC:function(I){var E=0;if(I!=null&&I!==0){var h=(I.length<<2)+1;E=qe(h),ss(I,E,h)}return E}},ko={string:As.stringToC,array:As.arrayToC};function es(I,E,h,f,G){var P=$t(I),_=[],M=0;if(f)for(var hA=0;hA>0]=E;break;case"i16":g[I>>1]=E;break;case"i32":Q[I>>2]=E;break;case"i64":tempI64=[E>>>0,+Mo(tempDouble=E)>=1?tempDouble>0?(0|bo(+Cs(tempDouble/4294967296),4294967295))>>>0:~~+No((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0],Q[I>>2]=tempI64[0],Q[I+4>>2]=tempI64[1];break;case"float":d[I>>2]=E;break;case"double":l[I>>3]=E;break;default:ZA("invalid type for setValue: "+h)}}function er(I,E,h){switch((E=E||"i8").charAt(E.length-1)==="*"&&(E="i32"),E){case"i1":case"i8":return n[I>>0];case"i16":return g[I>>1];case"i32":case"i64":return Q[I>>2];case"float":return d[I>>2];case"double":return l[I>>3];default:ZA("invalid type for getValue: "+E)}return null}function tr(I,E,h,f){typeof I=="number"?(P=!0,_=I):(P=!1,_=I.length);var G=typeof E=="string"?E:null;if(M=h==4?f:[typeof ve=="function"?ve:Le,qe,Le,_t][h===void 0?2:h](Math.max(_,G?1:E.length)),P){for(f=M,zA((3&M)==0),hA=M+(-4&_);f>2]=0;for(hA=M+_;f>0]=0;return M}if(G==="i8")return I.subarray||I.slice?o.set(I,M):o.set(new Uint8Array(I),M),M;for(var P,_,M,hA,oA,rA,sA,q=0;q<_;){var pA=I[q];if((oA=G||E[q])===0){q++;continue}oA=="i64"&&(oA="i32"),wo(M+q,pA,oA),sA!==oA&&(rA=So(oA),sA=oA),q+=rA}return M}function sr(I){return p?ut?ve(I):_t(I):Le(I)}function Te(I,E){if(E===0||!I)return"";for(var h,f,G,P=0,_=0;P|=f=o[I+_>>0],(f!=0||E)&&(_++,!E||_!=E););E||(E=_);var M="";if(P<128){for(;E>0;)G=String.fromCharCode.apply(String,o.subarray(I,I+Math.min(E,1024))),M=M?M+G:G,I+=1024,E-=1024;return M}return h=I,function(oA,rA){for(var sA=rA;oA[sA];)++sA;if(sA-rA>16&&oA.subarray&&ts)return ts.decode(oA.subarray(rA,sA));for(var q,pA,MA,NA,bA,se,LA="";;){if(!(q=oA[rA++]))return LA;if(!(128&q)){LA+=String.fromCharCode(q);continue}if(pA=63&oA[rA++],(224&q)==192){LA+=String.fromCharCode((31&q)<<6|pA);continue}if(MA=63&oA[rA++],(240&q)==224?q=(15&q)<<12|pA<<6|MA:(NA=63&oA[rA++],(248&q)==240?q=(7&q)<<18|pA<<12|MA<<6|NA:(bA=63&oA[rA++],q=(252&q)==248?(3&q)<<24|pA<<18|MA<<12|NA<<6|bA:(1&q)<<30|pA<<24|MA<<18|NA<<12|bA<<6|(se=63&oA[rA++]))),q<65536)LA+=String.fromCharCode(q);else{var ke=q-65536;LA+=String.fromCharCode(55296|ke>>10,56320|1023&ke)}}}(o,h)}function nr(I){for(var E="";;){var h=n[I++>>0];if(!h)return E;E+=String.fromCharCode(h)}}function or(I,E){return function(f,G,P){for(var _=0;_>0]=f.charCodeAt(_);P||(n[G>>0]=0)}(I,E,!1)}var ts=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function He(I,E,h,f){if(!(f>0))return 0;for(var G=h,P=h+f-1,_=0;_=55296&&M<=57343&&(M=65536+((1023&M)<<10)|1023&I.charCodeAt(++_)),M<=127){if(h>=P)break;E[h++]=M}else if(M<=2047){if(h+1>=P)break;E[h++]=192|M>>6,E[h++]=128|63&M}else if(M<=65535){if(h+2>=P)break;E[h++]=224|M>>12,E[h++]=128|M>>6&63,E[h++]=128|63&M}else if(M<=2097151){if(h+3>=P)break;E[h++]=240|M>>18,E[h++]=128|M>>12&63,E[h++]=128|M>>6&63,E[h++]=128|63&M}else if(M<=67108863){if(h+4>=P)break;E[h++]=248|M>>24,E[h++]=128|M>>18&63,E[h++]=128|M>>12&63,E[h++]=128|M>>6&63,E[h++]=128|63&M}else{if(h+5>=P)break;E[h++]=252|M>>30,E[h++]=128|M>>24&63,E[h++]=128|M>>18&63,E[h++]=128|M>>12&63,E[h++]=128|M>>6&63,E[h++]=128|63&M}}return E[h]=0,h-G}function ss(I,E,h){return He(I,o,E,h)}function Ye(I){for(var E=0,h=0;h=55296&&f<=57343&&(f=65536+((1023&f)<<10)|1023&I.charCodeAt(++h)),f<=127?++E:f<=2047?E+=2:f<=65535?E+=3:f<=2097151?E+=4:f<=67108863?E+=5:E+=6}return E}var ns=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0;function rr(I){for(var E=I,h=E>>1;g[h];)++h;if((E=h<<1)-I>32&&ns)return ns.decode(o.subarray(I,E));for(var f=0,G="";;){var P=g[I+2*f>>1];if(P==0)return G;++f,G+=String.fromCharCode(P)}}function ir(I,E,h){if(h===void 0&&(h=2147483647),h<2)return 0;for(var f=E,G=(h-=2)<2*I.length?h/2:I.length,P=0;P>1]=_,E+=2}return g[E>>1]=0,E-f}function ar(I){return 2*I.length}function Ir(I){for(var E=0,h="";;){var f=Q[I+4*E>>2];if(f==0)return h;if(++E,f>=65536){var G=f-65536;h+=String.fromCharCode(55296|G>>10,56320|1023&G)}else h+=String.fromCharCode(f)}}function gr(I,E,h){if(h===void 0&&(h=2147483647),h<4)return 0;for(var f=E,G=f+h-4,P=0;P=55296&&_<=57343&&(_=65536+((1023&_)<<10)|1023&I.charCodeAt(++P)),Q[E>>2]=_,(E+=4)+4>G)break}return Q[E>>2]=0,E-f}function Cr(I){for(var E=0,h=0;h=55296&&f<=57343&&++h,E+=4}return E}function Er(I){var E=Ye(I)+1,h=ve(E);return h&&He(I,n,h,E),h}function Br(I){var E=Ye(I)+1,h=qe(E);return He(I,n,h,E),h}function hr(I){return I}function Qr(){var I,E=function(){var f=Error();if(!f.stack){try{throw Error(0)}catch(G){f=G}if(!f.stack)return"(no stack trace available)"}return f.stack.toString()}();return i.extraStackTrace&&(E+=` +`;this.copyright+=mA,m(`%cDecoded Roland SC message! %c${mA}`,r.recognized,r.value)}break;default:if((i&240)===F.controllerChange)switch(K[0]){case 2:case 116:d=U;break;case 4:case 117:l===null?l=U:l=0;break;case 0:C&&K[1]!==0&&K[1]!==127&&(m("%cDLS RMIDI with offset 1 detected!",r.recognized),this.bankOffset=1)}}}this.tracks.push(D),this.usedChannelsOnTrack.push(J),m(`%cParsed %c${this.tracks.length}%c / %c${this.tracksAmount}`,r.info,r.value,r.info,r.value)}m("%cAll tracks parsed correctly!",r.recognized),yA("%cCorrecting loops, ports and detecting notes...",r.info);let c=[];for(let S of this.tracks){let D=S.find(w=>(w.messageStatusByte&240)===F.noteOn);D&&c.push(D.ticks)}this.firstNoteOn=Math.min(...c),m(`%cFirst note-on detected at: %c${this.firstNoteOn}%c ticks!`,r.info,r.recognized,r.info),d!==null&&l===null?(d=this.firstNoteOn,l=this.lastVoiceEventTick):(d===null&&(d=this.firstNoteOn),(l===null||l===0)&&(l=this.lastVoiceEventTick)),this.loop={start:d,end:l},m(`%cLoop points: start: %c${this.loop.start}%c end: %c${this.loop.end}`,r.info,r.recognized,r.info,r.recognized);let p=0;for(let S of this.midiPorts)if(S!==-1){p=S;break}if(this.midiPorts=this.midiPorts.map(S=>S===-1?p:S),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0]),this.midiPortChannelOffsets.length<2?m("%cNo additional MIDI Ports detected.",r.info):m("%cMIDI Ports detected!",r.recognized),!g)if(this.tracks.length>1){if(this.tracks[0].find(S=>S.messageStatusByte>=F.noteOn&&S.messageStatusByteD.messageStatusByte===F.trackName);S&&(this.rawMidiName=S.messageData,this.midiName=Z(S.messageData,S.messageData.length,void 0,!1))}}else{let S=this.tracks[0].find(D=>D.messageStatusByte===F.trackName);S&&(this.rawMidiName=S.messageData,this.midiName=Z(S.messageData,S.messageData.length,void 0,!1))}if(this.fileName=e,this.midiName=this.midiName.trim(),this.midiName.length===0){m("%cNo name detected. Using the alt name!",r.info),this.midiName=ls(e),this.rawMidiName=new Uint8Array(this.midiName.length);for(let S=0;Su>l?u:l),s=[];for(let l=0;l{g[p]>=c.length||c[g[p]].ticks0;){let l=Q(),u=t.tracks[l];if(g[l]>=u.length){C--;continue}let c=u[g[l]];if(g[l]++,c.messageStatusByte===F.midiPort){B[l]=c.messageData[0];continue}let p=c.messageStatusByte&240;if(p!==F.noteOn&&p!==F.controllerChange&&p!==F.programChange&&p!==F.systemExclusive)continue;let S=(c.messageStatusByte&15)+t.midiPortChannelOffsets[B[l]]||0,D=s[S];switch(p){case F.programChange:D.program=c.messageData[0],n(D);break;case F.controllerChange:if(c.messageData[0]!==y.bankSelect||d==="gs"&&D.drums)continue;let w=c.messageData[1],J=Math.max(0,w-t.bankOffset);if(d==="xg"){let N=w===120||w===126||w===127;N!==D.drums?(D.drums=N,D.bank=D.drums?128:J,n(D)):D.bank=D.drums?128:J;continue}s[S].bank=J;break;case F.noteOn:if(c.messageData[1]===0)continue;n(D),o[D.string].add(`${c.messageData[0]}-${c.messageData[1]}`);break;case F.systemExclusive:if(c.messageData[0]!==65||c.messageData[2]!==66||c.messageData[3]!==18||c.messageData[4]!==64||!(c.messageData[5]&16)||c.messageData[6]!==21){c.messageData[0]===67&&c.messageData[2]===76&&c.messageData[5]===126&&c.messageData[6]===0&&(d="xg");continue}let R=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][c.messageData[5]&15]+t.midiPortChannelOffsets[B[l]],U=!!(c.messageData[7]>0&&c.messageData[5]>>4);D=s[R],D.drums=U,D.bank=U?128:0,n(D);break}}for(let l of Object.keys(o))o[l].size===0&&(m(`%cDetected change but no keys for %c${l}`,r.info,r.value),delete o[l]);return V(),o}function Ls(t,A){this.midiPortChannelOffset===0&&(this.midiPortChannelOffset+=16,this.midiPortChannelOffsets[A]=0),this.midiPortChannelOffsets[A]===void 0&&(this.synth.workletProcessorChannels.length{this.assignMIDIPort(s,e)}),this.duration=this.midiData.duration,this.firstNoteTime=Qe(this.midiData.firstNoteOn,this.midiData),m(`%cTotal song time: ${Dt(Math.ceil(this.duration)).time}`,r.recognized),this.post(FA.songChange,[new ze(this.midiData),this.songIndex,A]),this.duration<=1&&(T(`%cVery short song: (${Dt(Math.round(this.duration)).time}). Disabling loop!`,r.warn),this.loop=!1),A)this.play(!0);else{let e=this._skipToFirstNoteOn?this.midiData.firstNoteOn-1:0;this.setTimeTicks(e),this.pause()}}function Ts(t,A=!0){this.songs=t.reduce((e,s)=>{if(s.duration)return e.push(s),e;try{e.push(new et(s.binary,s.altName||""))}catch(n){return this.post(FA.midiError,n.message),e}return e},[]),!(this.songs.length<1)&&(this.songIndex=0,this.songs.length>1&&(this.loop=!1),this.loadNewSequence(this.songs[this.songIndex],A))}function Hs(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex++,this.songIndex%=this.songs.length,this.loadNewSequence(this.songs[this.songIndex])}function Ys(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex--,this.songIndex<0&&(this.songIndex=this.songs.length-1),this.loadNewSequence(this.songs[this.songIndex])}var KA=new Int16Array(127);KA[y.mainVolume]=100;KA[y.expressionController]=127;KA[y.pan]=64;KA[y.releaseTime]=64;KA[y.brightness]=64;KA[y.reverbDepth]=0;function Js(t,A=void 0){this.oneTickToSeconds=60/(120*this.midiData.timeDivision),this.synth.resetAllControllers(),this.sendMIDIReset(),this._resetTimers();let e=this.synth.workletProcessorChannels.length,s=Array(e).fill(8192),n=[];for(let C=0;CC===y.dataDecrement||C===y.dataIncrement||C===y.dataEntryMsb||C===y.dataDecrement||C===y.lsbForControl6DataEntry||C===y.RPNLsb||C===y.RPNMsb||C===y.NRPNLsb||C===y.NRPNMsb||C===y.bankSelect||C===y.lsbForControl0BankSelect||C===y.resetAllControllers,g=[];for(let C=0;C=A)break}else if(this.playedTime>=t)break;let B=Re(Q.messageStatusByte),d=B.channel+(this.midiPortChannelOffsets[this.midiPorts[C]]||0);switch(B.status){case F.noteOn:case F.noteOff:case F.keySignature:break;case F.pitchBend:s[d]=Q.messageData[1]<<7|Q.messageData[0];break;case F.programChange:let u=n[d];u.program=Q.messageData[0],u.actualBank=u.bank;break;case F.controllerChange:let c=Q.messageData[0];if(o(c)){let p=Q.messageData[1];if(c===y.bankSelect){n[d].bank=p;break}this.sendMIDIMessages?this.sendMIDICC(d,c,p):this.synth.controllerChange(d,c,p)}else g[d]===void 0&&(g[d]=Array.from(KA)),g[d][c]=Q.messageData[1];break;default:this._processEvent(Q,C);break}this.eventIndex[C]++,C=this._findFirstEventIndex();let l=this.tracks[C][this.eventIndex[C]];if(l===void 0)return this.stop(),!1;this.playedTime+=this.oneTickToSeconds*(l.ticks-Q.ticks)}if(this.sendMIDIMessages){for(let C=0;C>7,s[C]&127),g[C]!==void 0&&g[C].forEach((Q,B)=>{Q!==KA[B]&&!o(B)&&this.sendMIDICC(C,B,Q)}),n[C].program>=0&&n[C].actualBank>=0){let Q=n[C].actualBank;this.sendMIDICC(C,y.bankSelect,Q),this.sendMIDIProgramChange(C,n[C].program)}}else for(let C=0;C>7,s[C]&127),g[C]!==void 0&&g[C].forEach((Q,B)=>{Q!==KA[B]&&!o(B)&&this.synth.controllerChange(C,B,Q)}),n[C].program>=0&&n[C].actualBank>=0){let Q=n[C].actualBank;this.synth.controllerChange(C,y.bankSelect,Q),this.synth.programChange(C,n[C].program)}return!0}function vs(t=!1){if(this.midiData!==void 0){if(t){this.pausedTime=void 0,this.currentTime=0;return}if(this.currentTime>=this.duration){this.pausedTime=void 0,this.currentTime=0;return}this.paused&&(this._recalculateStartTime(this.pausedTime),this.pausedTime=void 0),this.sendMIDIMessages||this.playingNotes.forEach(A=>{this.synth.noteOn(A.channel,A.midiNote,A.velocity,!1,!0)}),this.setProcessHandler()}}function qs(t){this.stop(),this.playingNotes=[],this.pausedTime=void 0,this.post(FA.timeChange,currentTime-Qe(t,this.midiData));let A=this._playTo(0,t);this._recalculateStartTime(this.playedTime),A&&this.play()}function Ps(t){this.absoluteStartTime=currentTime-t/this._playbackRate}function Ks(t,A){switch(t){default:break;case wA.loadNewSongList:this.loadNewSongList(A[0],A[1]);break;case wA.pause:this.pause();break;case wA.play:this.play(A);break;case wA.stop:this.stop();break;case wA.setTime:this.currentTime=A;break;case wA.changeMIDIMessageSending:this.sendMIDIMessages=A;break;case wA.setPlaybackRate:this.playbackRate=A;break;case wA.setLoop:this.loop=A;break;case wA.changeSong:A?this.nextSong():this.previousSong();break;case wA.getMIDI:this.post(FA.getMIDI,this.midiData);break;case wA.setSkipToFirstNote:this._skipToFirstNoteOn=A;break;case wA.setPreservePlaybackState:this.preservePlaybackState=A}}function Os(t,A=void 0){this.synth.enableEventSystem&&this.synth.post({messageType:uA.sequencerSpecific,messageData:{messageType:t,messageData:A}})}function Vs(t){this.post(FA.midiEvent,t)}function Zs(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([F.controllerChange|t,A,e])}function Xs(t,A){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([F.programChange|t,A])}function Ws(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([F.pitchBend|t,e,A])}function _s(){if(this.sendMIDIMessages){this.sendMIDIMessage([F.reset]);for(let t=0;tthis.duration||A<0){this._skipToFirstNoteOn?this.setTimeTicks(this.midiData.firstNoteOn-1):this.setTimeTicks(0);return}if(this._skipToFirstNoteOn&&Azs?440*Math.pow(2,(t-6900)/1200):Nt[~~t-tt]}var Lt=-1660,Yo=1600,bt=new Float32Array((Yo-Lt)*100+1);for(let t=0;t.5?1:0,s?e*2-1:e;case QA.concave:return s?(e=e*2-1,e<0?-XA[~~(e*-CA)]:XA[~~(e*CA)]):XA[~~(e*CA)];case QA.convex:return s?(e=e*2-1,e<0?-oe[~~(e*-CA)]:oe[~~(e*CA)]):oe[~~(e*CA)]}}var Ut=1,Tt=new Float32Array(1e3);for(let t=0;t=e.loopEnd;)s-=o;let C=~~s,Q=C+1;for(;Q>=e.loopEnd;)Q-=o;let B=s-C,d=n[Q],l=n[C];A[g]=l+(d-l)*B,s+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end){t.finished=!0;return}let Q=s-g,B=n[C],d=n[g];A[o]=d+(B-d)*Q,s+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=s}function $s(t,A){let e=t.sample,s=e.cursor,n=e.loopEnd-e.loopStart,o=e.sampleData;if(t.sample.isLooping)for(let g=0;g=e.loopEnd;)s-=n;let C=~~s+1;for(;C>=e.loopEnd;)C-=n;A[g]=o[C],s+=e.playbackStep*t.currentTuningCalculated}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let g=0;g=e.end){t.finished=!0;return}A[g]=o[C],s+=e.playbackStep*t.currentTuningCalculated}}e.cursor=s}function An(t,A){let e=t.sample,s=e.cursor,n=e.sampleData;if(e.isLooping){let o=e.loopEnd-e.loopStart;for(let g=0;g=e.loopEnd;)s-=o;let C=~~s,Q=C+1,B=Q+1,d=B+1,l=s-C;Q>=e.loopEnd&&(Q-=o),B>=e.loopEnd&&(B-=o),d>=e.loopEnd&&(d-=o);let u=n[C],c=n[Q],p=n[B],S=n[d],D=.5*(p-u),w=u-2.5*c+2*p-.5*S,J=.5*(S-u)+1.5*(c-p);A[g]=((J*l+w)*l+D)*l+c,s+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end||Q>=e.end||B>=e.end){t.finished=!0;return}let l=n[g],u=n[C],c=n[Q],p=n[B],S=.5*(c-l),D=l-2.5*u+2*c-.5*p,w=.5*(p-l)+1.5*(u-c);A[o]=((w*d+D)*d+S)*d+u,s+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=s}var en=.001,GA=100,Ht=90,Jo=15e-6,TA=class t{currentSampleTime=0;sampleRate;currentAttenuationDb=GA;state=0;releaseStartDb=GA;releaseStartTimeSamples=0;currentReleaseGain=1;attackDuration=0;decayDuration=0;releaseDuration=0;attenuation=0;attenuationTarget=0;sustainDbRelative=0;delayEnd=0;attackEnd=0;holdEnd=0;decayEnd=0;constructor(A,e){this.sampleRate=A,this.canEndOnSilentSustain=e/10>=Ht}static startRelease(A){A.volumeEnvelope.releaseStartTimeSamples=A.volumeEnvelope.currentSampleTime,A.volumeEnvelope.currentReleaseGain=OA(A.volumeEnvelope.currentAttenuationDb),t.recalculate(A)}static recalculate(A){let e=A.volumeEnvelope,s=B=>Math.max(0,Math.floor(JA(B)*e.sampleRate));e.attenuationTarget=Math.max(0,Math.min(A.modulatedGenerators[a.initialAttenuation],1440))/10,e.sustainDbRelative=Math.min(GA,A.modulatedGenerators[a.sustainVolEnv]/10);let n=Math.min(GA,e.sustainDbRelative);e.attackDuration=s(A.modulatedGenerators[a.attackVolEnv]);let o=A.modulatedGenerators[a.decayVolEnv],g=(60-A.targetKey)*A.modulatedGenerators[a.keyNumToVolEnvDecay],C=n/GA;e.decayDuration=s(o+g)*C,e.releaseDuration=s(A.modulatedGenerators[a.releaseVolEnv]),e.delayEnd=s(A.modulatedGenerators[a.delayVolEnv]),e.attackEnd=e.attackDuration+e.delayEnd;let Q=(60-A.targetKey)*A.modulatedGenerators[a.keyNumToVolEnvHold];if(e.holdEnd=s(A.modulatedGenerators[a.holdVolEnv]+Q)+e.attackEnd,e.decayEnd=e.decayDuration+e.holdEnd,e.state===0&&e.attackEnd===0&&(e.state=2),A.isInRelease){let B=Math.max(0,Math.min(GA,e.sustainDbRelative)),d=B/GA;switch(e.decayDuration=s(o+g)*d,e.state){case 0:e.releaseStartDb=GA;break;case 1:let u=1-(e.attackEnd-e.releaseStartTimeSamples)/e.attackDuration;e.releaseStartDb=20*Math.log10(u)*-1;break;case 2:e.releaseStartDb=0;break;case 3:e.releaseStartDb=(1-(e.decayEnd-e.releaseStartTimeSamples)/e.decayDuration)*B;break;case 4:e.releaseStartDb=B;break}e.releaseStartDb=Math.max(0,Math.min(e.releaseStartDb,GA)),e.releaseStartDb>=Ht&&(A.finished=!0),e.currentReleaseGain=OA(e.releaseStartDb);let l=(GA-e.releaseStartDb)/GA;e.releaseDuration*=l}}static apply(A,e,s,n){let o=A.volumeEnvelope,g=s/10,C=n;if(A.isInRelease){let B=o.currentSampleTime-o.releaseStartTimeSamples;if(B>=o.releaseDuration){for(let l=0;l=e.length)return;o.state++;case 1:for(;o.currentSampleTime=e.length)return}o.state++;case 2:for(;o.currentSampleTime=e.length)return;o.state++;case 3:for(;o.currentSampleTime=e.length)return;o.state++;case 4:for(o.canEndOnSilentSustain&&o.sustainDbRelative>=Ht&&(A.finished=!0);;)if(o.attenuation+=(o.attenuationTarget-o.attenuation)*C,e[Q]*=OA(o.sustainDbRelative+g+o.attenuation),o.currentAttenuationDb=o.sustainDbRelative,o.currentSampleTime++,++Q>=e.length)return}}};var le=class t{a0=0;a1=0;a2=0;a3=0;a4=0;x1=0;x2=0;y1=0;y2=0;reasonanceCb=0;reasonanceGain=1;cutoffCents=13501;cutoffHz=20001;static apply(A,e,s,n){if(n&&s>13499&&A.filter.reasonanceCb===0)return;let o=A.filter;(o.cutoffCents!==s||o.reasonanceCb!==A.modulatedGenerators[a.initialFilterQ])&&(o.cutoffCents=s,o.reasonanceCb=A.modulatedGenerators[a.initialFilterQ],t.calculateCoefficients(o));for(let g=0;g=A.releaseStartTime&&(A.isInRelease=!0,TA.startRelease(A),UA.startRelease(A),A.sample.loopingMode===3&&(A.sample.isLooping=!1)),A.modulatedGenerators[a.initialAttenuation]>2500){A.isInRelease&&(A.finished=!0);return}let g=A.targetKey,C=A.modulatedGenerators[a.fineTune]+t.customControllers[aA.channelTuning]+t.customControllers[aA.channelTransposeFine]+t.customControllers[aA.masterTuning]+t.channelOctaveTuning[A.midiNote%12]+t.keyCentTuning[A.midiNote],Q=A.modulatedGenerators[a.coarseTune]+t.customControllers[aA.channelTuningSemitones],B=this.tunings[t.preset.program]?.[A.realKey];B?.midiNote>=0&&(g=B.midiNote,C+=B.centTuning),C+=(g-A.sample.rootKey)*A.modulatedGenerators[a.scaleTuning];let d=A.modulatedGenerators[a.vibLfoToPitch];if(d!==0){let i=A.startTime+JA(A.modulatedGenerators[a.delayVibLFO]),tA=Ge(A.modulatedGenerators[a.freqVibLFO]),W=st(i,tA,currentTime);C+=W*(d*t.customControllers[aA.modulationMultiplier])}let l=A.modulatedGenerators[a.initialFilterFc],u=l,c=A.modulatedGenerators[a.modLfoToPitch],p=A.modulatedGenerators[a.modLfoToVolume],S=A.modulatedGenerators[a.modLfoToFilterFc],D=0;if(c+S+p!==0){let i=A.startTime+JA(A.modulatedGenerators[a.delayModLFO]),tA=Ge(A.modulatedGenerators[a.freqModLFO]),W=st(i,tA,currentTime);C+=W*(c*t.customControllers[aA.modulationMultiplier]),D=-W*p,u+=W*S}if(t.channelVibrato.depth>0){let i=st(A.startTime+t.channelVibrato.delay,t.channelVibrato.rate,currentTime);i&&(C+=i*t.channelVibrato.depth)}let w=A.modulatedGenerators[a.modEnvToPitch],J=A.modulatedGenerators[a.modEnvToFilterFc],R=UA.getValue(A,currentTime);u+=R*J,C+=R*w;let U=~~(C+Q*100);U!==A.currentTuningCents&&(A.currentTuningCents=U,A.currentTuningCalculated=Math.pow(2,U/1200));let N=new Float32Array(e.length);switch(this.interpolationType){case ce.linear:default:js(A,N);break;case ce.nearestNeighbor:$s(A,N);break;case ce.fourthOrder:An(A,N)}le.apply(A,N,u,l>13499),TA.apply(A,N,D,this.volumeEnvelopeSmoothingFactor),this.panVoice(A,N,e,s,n,o)}function vo(t,A){let e=0;return t.drumChannel&&(e+=5),A.isInRelease&&(e-=5),e+=A.velocity/25,e-=A.volumeEnvelope.state,A.isInRelease&&(e-=5),e-=A.volumeEnvelope.currentAttenuationDb/50,e}function nn(t){let A=[];for(let s of this.workletProcessorChannels)for(let n of s.voices)if(!n.finished){let o=vo(s,n);A.push({channel:s,voice:n,priority:o})}A.sort((s,n)=>s.priority-n.priority);let e=A.slice(0,t);for(let{channel:s,voice:n}of e){let o=s.voices.indexOf(n);o>-1&&s.voices.splice(o,1)}}function on(t){t.releaseStartTime=currentTime,t.releaseStartTime-t.startTimean=t);var qo=function(t){var A,e,s,n,o,g,C,Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",B="",d=0;t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");do n=Q.indexOf(t.charAt(d++)),o=Q.indexOf(t.charAt(d++)),g=Q.indexOf(t.charAt(d++)),C=Q.indexOf(t.charAt(d++)),A=n<<2|o>>4,e=(15&o)<<4|g>>2,s=(3&g)<<6|C,B+=String.fromCharCode(A),g!==64&&(B+=String.fromCharCode(e)),C!==64&&(B+=String.fromCharCode(s));while(d1&&(i.thisProgram=process.argv[1].replace(/\\/g,"/")),i.arguments=process.argv.slice(2),typeof module<"u",process.on("uncaughtException",function(I){if(!(I instanceof De))throw I}),process.on("unhandledRejection",function(I,E){process.exit(1)}),i.quit=function(I){process.exit(I)},i.inspect=function(){return"[Emscripten Module object]"}):EA?(typeof read<"u"&&(i.read=function(E){return read(E)}),i.readBinary=function(E){var h;return typeof readbuffer=="function"?new Uint8Array(readbuffer(E)):(zA(typeof(h=read(E,"binary"))=="object"),h)},typeof scriptArgs<"u"?i.arguments=scriptArgs:typeof arguments<"u"&&(i.arguments=arguments),typeof quit=="function"&&(i.quit=function(I){quit(I)})):(W||K)&&(W?document.currentScript&&(IA=document.currentScript.src):IA=self.location.href,IA=IA.indexOf("blob:")!==0?IA.split("/").slice(0,-1).join("/")+"/":"",i.read=function(E){var h=new XMLHttpRequest;return h.open("GET",E,!1),h.send(null),h.responseText},K&&(i.readBinary=function(E){var h=new XMLHttpRequest;return h.open("GET",E,!1),h.responseType="arraybuffer",h.send(null),new Uint8Array(h.response)}),i.readAsync=function(E,h,f){var G=new XMLHttpRequest;G.open("GET",E,!0),G.responseType="arraybuffer",G.onload=function(){if(G.status==200||G.status==0&&G.response){h(G.response);return}f()},G.onerror=f,G.send(null)},i.setWindowTitle=function(I){document.title=I});var be=i.print||(typeof console<"u"?console.log.bind(console):typeof print<"u"?print:null),xA=i.printErr||(typeof printErr<"u"?printErr:typeof console<"u"&&console.warn.bind(console)||be);for(t in tA)tA.hasOwnProperty(t)&&(i[t]=tA[t]);function Le(I){var E=c;return c=c+I+15&-16,E}function _t(I){var E=Q[R>>2],h=E+I+15&-16;return Q[R>>2]=h,h>=BA&&!rs()?(Q[R>>2]=E,0):E}function zt(I,E){return E||(E=16),I=Math.ceil(I/E)*E}function So(I){switch(I){case"i1":case"i8":return 1;case"i16":return 2;case"i32":case"float":return 4;case"i64":case"double":return 8;default:if(I[I.length-1]==="*")return 4;if(I[0]!=="i")return 0;var E=parseInt(I.substr(1));return zA(E%8==0),E/8}}function pe(I){pe.shown||(pe.shown={}),pe.shown[I]||(pe.shown[I]=1,xA(I))}tA=void 0;var Do={"f64-rem":function(I,E){return I%E},debugger:function(){}},Ct=[];function zo(I,E){for(var h=0,f=h;f>>0)+4294967296*+(E>>>0):+(I>>>0)+4294967296*+(0|E)}function Bt(I,E,h){return h&&h.length?i["dynCall_"+I].apply(null,[E].concat(h)):i["dynCall_"+I].call(null,E)}var Ue=0,jt=0;function zA(I,E){I||ZA("Assertion failed: "+E)}function $t(I){var E=i["_"+I];return zA(E,"Cannot call unknown function "+I+", make sure it is exported"),E}var As={stackSave:function(){mt()},stackRestore:function(){ft()},arrayToC:function(I){var E,h,f=qe(I.length);return E=I,h=f,n.set(E,h),f},stringToC:function(I){var E=0;if(I!=null&&I!==0){var h=(I.length<<2)+1;E=qe(h),ss(I,E,h)}return E}},ko={string:As.stringToC,array:As.arrayToC};function es(I,E,h,f,G){var P=$t(I),_=[],M=0;if(f)for(var hA=0;hA>0]=E;break;case"i16":g[I>>1]=E;break;case"i32":Q[I>>2]=E;break;case"i64":tempI64=[E>>>0,+Mo(tempDouble=E)>=1?tempDouble>0?(0|bo(+Cs(tempDouble/4294967296),4294967295))>>>0:~~+No((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0],Q[I>>2]=tempI64[0],Q[I+4>>2]=tempI64[1];break;case"float":d[I>>2]=E;break;case"double":l[I>>3]=E;break;default:ZA("invalid type for setValue: "+h)}}function er(I,E,h){switch((E=E||"i8").charAt(E.length-1)==="*"&&(E="i32"),E){case"i1":case"i8":return n[I>>0];case"i16":return g[I>>1];case"i32":case"i64":return Q[I>>2];case"float":return d[I>>2];case"double":return l[I>>3];default:ZA("invalid type for getValue: "+E)}return null}function tr(I,E,h,f){typeof I=="number"?(P=!0,_=I):(P=!1,_=I.length);var G=typeof E=="string"?E:null;if(M=h==4?f:[typeof ve=="function"?ve:Le,qe,Le,_t][h===void 0?2:h](Math.max(_,G?1:E.length)),P){for(f=M,zA((3&M)==0),hA=M+(-4&_);f>2]=0;for(hA=M+_;f>0]=0;return M}if(G==="i8")return I.subarray||I.slice?o.set(I,M):o.set(new Uint8Array(I),M),M;for(var P,_,M,hA,oA,rA,sA,q=0;q<_;){var pA=I[q];if((oA=G||E[q])===0){q++;continue}oA=="i64"&&(oA="i32"),wo(M+q,pA,oA),sA!==oA&&(rA=So(oA),sA=oA),q+=rA}return M}function sr(I){return p?ut?ve(I):_t(I):Le(I)}function Te(I,E){if(E===0||!I)return"";for(var h,f,G,P=0,_=0;P|=f=o[I+_>>0],(f!=0||E)&&(_++,!E||_!=E););E||(E=_);var M="";if(P<128){for(;E>0;)G=String.fromCharCode.apply(String,o.subarray(I,I+Math.min(E,1024))),M=M?M+G:G,I+=1024,E-=1024;return M}return h=I,function(oA,rA){for(var sA=rA;oA[sA];)++sA;if(sA-rA>16&&oA.subarray&&ts)return ts.decode(oA.subarray(rA,sA));for(var q,pA,MA,NA,bA,se,LA="";;){if(!(q=oA[rA++]))return LA;if(!(128&q)){LA+=String.fromCharCode(q);continue}if(pA=63&oA[rA++],(224&q)==192){LA+=String.fromCharCode((31&q)<<6|pA);continue}if(MA=63&oA[rA++],(240&q)==224?q=(15&q)<<12|pA<<6|MA:(NA=63&oA[rA++],(248&q)==240?q=(7&q)<<18|pA<<12|MA<<6|NA:(bA=63&oA[rA++],q=(252&q)==248?(3&q)<<24|pA<<18|MA<<12|NA<<6|bA:(1&q)<<30|pA<<24|MA<<18|NA<<12|bA<<6|(se=63&oA[rA++]))),q<65536)LA+=String.fromCharCode(q);else{var ke=q-65536;LA+=String.fromCharCode(55296|ke>>10,56320|1023&ke)}}}(o,h)}function nr(I){for(var E="";;){var h=n[I++>>0];if(!h)return E;E+=String.fromCharCode(h)}}function or(I,E){return function(f,G,P){for(var _=0;_>0]=f.charCodeAt(_);P||(n[G>>0]=0)}(I,E,!1)}var ts=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function He(I,E,h,f){if(!(f>0))return 0;for(var G=h,P=h+f-1,_=0;_=55296&&M<=57343&&(M=65536+((1023&M)<<10)|1023&I.charCodeAt(++_)),M<=127){if(h>=P)break;E[h++]=M}else if(M<=2047){if(h+1>=P)break;E[h++]=192|M>>6,E[h++]=128|63&M}else if(M<=65535){if(h+2>=P)break;E[h++]=224|M>>12,E[h++]=128|M>>6&63,E[h++]=128|63&M}else if(M<=2097151){if(h+3>=P)break;E[h++]=240|M>>18,E[h++]=128|M>>12&63,E[h++]=128|M>>6&63,E[h++]=128|63&M}else if(M<=67108863){if(h+4>=P)break;E[h++]=248|M>>24,E[h++]=128|M>>18&63,E[h++]=128|M>>12&63,E[h++]=128|M>>6&63,E[h++]=128|63&M}else{if(h+5>=P)break;E[h++]=252|M>>30,E[h++]=128|M>>24&63,E[h++]=128|M>>18&63,E[h++]=128|M>>12&63,E[h++]=128|M>>6&63,E[h++]=128|63&M}}return E[h]=0,h-G}function ss(I,E,h){return He(I,o,E,h)}function Ye(I){for(var E=0,h=0;h=55296&&f<=57343&&(f=65536+((1023&f)<<10)|1023&I.charCodeAt(++h)),f<=127?++E:f<=2047?E+=2:f<=65535?E+=3:f<=2097151?E+=4:f<=67108863?E+=5:E+=6}return E}var ns=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0;function rr(I){for(var E=I,h=E>>1;g[h];)++h;if((E=h<<1)-I>32&&ns)return ns.decode(o.subarray(I,E));for(var f=0,G="";;){var P=g[I+2*f>>1];if(P==0)return G;++f,G+=String.fromCharCode(P)}}function ir(I,E,h){if(h===void 0&&(h=2147483647),h<2)return 0;for(var f=E,G=(h-=2)<2*I.length?h/2:I.length,P=0;P>1]=_,E+=2}return g[E>>1]=0,E-f}function ar(I){return 2*I.length}function Ir(I){for(var E=0,h="";;){var f=Q[I+4*E>>2];if(f==0)return h;if(++E,f>=65536){var G=f-65536;h+=String.fromCharCode(55296|G>>10,56320|1023&G)}else h+=String.fromCharCode(f)}}function gr(I,E,h){if(h===void 0&&(h=2147483647),h<4)return 0;for(var f=E,G=f+h-4,P=0;P=55296&&_<=57343&&(_=65536+((1023&_)<<10)|1023&I.charCodeAt(++P)),Q[E>>2]=_,(E+=4)+4>G)break}return Q[E>>2]=0,E-f}function Cr(I){for(var E=0,h=0;h=55296&&f<=57343&&++h,E+=4}return E}function Er(I){var E=Ye(I)+1,h=ve(E);return h&&He(I,n,h,E),h}function Br(I){var E=Ye(I)+1,h=qe(E);return He(I,n,h,E),h}function hr(I){return I}function Qr(){var I,E=function(){var f=Error();if(!f.stack){try{throw Error(0)}catch(G){f=G}if(!f.stack)return"(no stack trace available)"}return f.stack.toString()}();return i.extraStackTrace&&(E+=` `+i.extraStackTrace()),(I=E).replace(/__Z[\w\d_]+/g,function(h){var f,G=f=h;return h===G?h:h+" ["+G+"]"})}function ht(I,E){return I%E>0&&(I+=E-I%E),I}function os(I){i.buffer=s=I}function Qt(){i.HEAP8=n=new Int8Array(s),i.HEAP16=g=new Int16Array(s),i.HEAP32=Q=new Int32Array(s),i.HEAPU8=o=new Uint8Array(s),i.HEAPU16=C=new Uint16Array(s),i.HEAPU32=B=new Uint32Array(s),i.HEAPF32=d=new Float32Array(s),i.HEAPF64=l=new Float64Array(s)}function rs(){var I=i.usingWasm?65536:16777216,E=2147483648-I;if(Q[R>>2]>E)return!1;var h=BA;for(BA=Math.max(BA,16777216);BA>2];)BA=BA<=536870912?ht(2*BA,I):Math.min(ht((3*BA+2147483648)/4,I),E);var f=i.reallocBuffer(BA);return f&&f.byteLength==BA?(os(f),Qt(),!0):(BA=h,!1)}u=c=S=D=w=J=R=0,p=!1,i.reallocBuffer||(i.reallocBuffer=function(I){try{if(ArrayBuffer.transfer)E=ArrayBuffer.transfer(s,I);else{var E,h=n;E=new ArrayBuffer(I),new Int8Array(E).set(h)}}catch{return!1}return!!Lo(E)&&E});try{(U=Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get))(new ArrayBuffer(4))}catch{U=function(E){return E.byteLength}}var ct=i.TOTAL_STACK||5242880,BA=i.TOTAL_MEMORY||16777216;function Fo(){return BA}function ye(I){for(;I.length>0;){var E=I.shift();if(typeof E=="function"){E();continue}var h=E.func;typeof h=="number"?E.arg===void 0?i.dynCall_v(h):i.dynCall_vi(h,E.arg):h(E.arg===void 0?null:E.arg)}}BA=0?I:E<=32?2*Math.abs(1<=f&&(E<=32||I>f)&&(I=-2*f+I),I}var Mo=Math.abs,No=Math.ceil,Cs=Math.floor,bo=Math.min,te=0,dt=null,Se=null;function pr(I){return I}i.preloadedImages={},i.preloadedAudios={};var Es="data:application/octet-stream;base64,";function Je(I){return String.prototype.startsWith?I.startsWith(Es):I.indexOf(Es)===0}(function(){var E="main.wast",h="main.wasm",f="main.temp.asm.js";Je(E)||(E=mA(E)),Je(h)||(h=mA(h)),Je(f)||(f=mA(f));var G={global:null,env:null,asm2wasm:Do,parent:i},P=null;function _(sA){return sA}function M(){try{if(i.wasmBinary)return new Uint8Array(i.wasmBinary);if(i.readBinary)return i.readBinary(h);throw"both async and sync fetching of the wasm failed"}catch(sA){ZA(sA)}}i.asmPreload=i.asm;var hA=i.reallocBuffer,oA=function(sA){sA=ht(sA,i.usingWasm?65536:16777216);var q=i.buffer.byteLength;if(i.usingWasm)try{var pA=i.wasmMemory.grow((sA-q)/65536);return pA!==-1?i.buffer=i.wasmMemory.buffer:null}catch{return null}};i.reallocBuffer=function(sA){return rA==="asmjs"?hA(sA):oA(sA)};var rA="";i.asm=function(sA,q,pA){var MA;if(!(q=MA=q).table){var NA,bA=i.wasmTableSize;bA===void 0&&(bA=1024);var se=i.wasmMaxTableSize;typeof WebAssembly=="object"&&typeof WebAssembly.Table=="function"?se!==void 0?q.table=new WebAssembly.Table({initial:bA,maximum:se,element:"anyfunc"}):q.table=new WebAssembly.Table({initial:bA,element:"anyfunc"}):q.table=Array(bA),i.wasmTable=q.table}return q.memoryBase||(q.memoryBase=i.STATIC_BASE),q.tableBase||(q.tableBase=0),NA=function(ke,Ie,yt){if(typeof WebAssembly!="object")return xA("no native wasm support detected"),!1;if(!(i.wasmMemory instanceof WebAssembly.Memory))return xA("no native wasm Memory in use"),!1;function Pe(vA,qA){if((P=vA.exports).memory){var we,St,Qs;we=P.memory,St=i.buffer,we.byteLength0?h:Ye(I)+1,G=Array(f),P=He(I,G,0,G.length);return E&&(G.length=P),G}function kr(I){for(var E=[],h=0;h255&&(f&=255),E.push(String.fromCharCode(f))}return E.join("")}c+=16,R=Le(4),w=(S=D=zt(c))+ct,J=zt(w),Q[R>>2]=J,p=!0,i.wasmTableSize=4,i.wasmMaxTableSize=4,i.asmGlobalArg={},i.asmLibraryArg={abort:ZA,assert:zA,enlargeMemory:rs,getTotalMemory:Fo,abortOnCannotGrowMemory:function(){ZA("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+BA+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")},invoke_iii:function(E,h,f){var G=mt();try{return i.dynCall_iii(E,h,f)}catch(P){if(ft(G),typeof P!="number"&&P!=="longjmp")throw P;i.setThrew(1,0)}},___assert_fail:function(E,h,f,G){ZA("Assertion failed: "+Te(E)+", at: "+[h?Te(h):"unknown filename",f,G?Te(G):"unknown function"])},___setErrNo:function(E){return i.___errno_location&&(Q[i.___errno_location()>>2]=E),E},_abort:function(){i.abort()},_emscripten_memcpy_big:function(E,h,f){return o.set(o.subarray(h,h+f),E),E},_llvm_floor_f64:Cs,DYNAMICTOP_PTR:R,tempDoublePtr:kA,ABORT:Ue,STACKTOP:D,STACK_MAX:w};var Bs=i.asm(i.asmGlobalArg,i.asmLibraryArg,s);i.asm=Bs,i.___errno_location=function(){return i.asm.___errno_location.apply(null,arguments)};var Lo=i._emscripten_replace_memory=function(){return i.asm._emscripten_replace_memory.apply(null,arguments)};i._free=function(){return i.asm._free.apply(null,arguments)};var ve=i._malloc=function(){return i.asm._malloc.apply(null,arguments)};i._memcpy=function(){return i.asm._memcpy.apply(null,arguments)},i._memset=function(){return i.asm._memset.apply(null,arguments)},i._sbrk=function(){return i.asm._sbrk.apply(null,arguments)},i._stb_vorbis_js_channels=function(){return i.asm._stb_vorbis_js_channels.apply(null,arguments)},i._stb_vorbis_js_close=function(){return i.asm._stb_vorbis_js_close.apply(null,arguments)},i._stb_vorbis_js_decode=function(){return i.asm._stb_vorbis_js_decode.apply(null,arguments)},i._stb_vorbis_js_open=function(){return i.asm._stb_vorbis_js_open.apply(null,arguments)},i._stb_vorbis_js_sample_rate=function(){return i.asm._stb_vorbis_js_sample_rate.apply(null,arguments)},i.establishStackSpace=function(){return i.asm.establishStackSpace.apply(null,arguments)},i.getTempRet0=function(){return i.asm.getTempRet0.apply(null,arguments)},i.runPostSets=function(){return i.asm.runPostSets.apply(null,arguments)},i.setTempRet0=function(){return i.asm.setTempRet0.apply(null,arguments)},i.setThrew=function(){return i.asm.setThrew.apply(null,arguments)};var qe=i.stackAlloc=function(){return i.asm.stackAlloc.apply(null,arguments)},ft=i.stackRestore=function(){return i.asm.stackRestore.apply(null,arguments)},mt=i.stackSave=function(){return i.asm.stackSave.apply(null,arguments)};function De(I){this.name="ExitStatus",this.message="Program terminated with exit("+I+")",this.status=I}function pt(I){I=I||i.arguments,!(te>0)&&(function(){if(i.preRun)for(typeof i.preRun=="function"&&(i.preRun=[i.preRun]);i.preRun.length;)Go(i.preRun.shift());ye(is)}(),!(te>0)&&(i.calledRun||(i.setStatus?(i.setStatus("Running..."),setTimeout(function(){setTimeout(function(){i.setStatus("")},1),E()},1)):E())));function E(){!i.calledRun&&(i.calledRun=!0,Ue||(ut||(ut=!0,ye(lt)),ye(as),i.onRuntimeInitialized&&i.onRuntimeInitialized(),function(){if(i.postRun)for(typeof i.postRun=="function"&&(i.postRun=[i.postRun]);i.postRun.length;)xo(i.postRun.shift());ye(gs)}()))}}function wr(I,E){(!E||!i.noExitRuntime||I!==0)&&(i.noExitRuntime||(Ue=!0,jt=I,D=N,ye(Is),Ro=!0,i.onExit&&i.onExit(I)),i.quit(I,new De(I)))}function ZA(I){throw i.onAbort&&i.onAbort(I),I!==void 0?(be(I),xA(I),I=JSON.stringify(I)):I="",Ue=!0,jt=1,"abort("+I+"). Build with -s ASSERTIONS=1 for more info."}if(i.dynCall_iii=function(){return i.asm.dynCall_iii.apply(null,arguments)},i.asm=Bs,i.ccall=es,i.cwrap=function(E,h,f,G){var P=(f=f||[]).every(function(_){return _==="number"});return h!=="string"&&P&&!G?$t(E):function(){return es(E,h,f,arguments,G)}},De.prototype=Error(),De.prototype.constructor=De,Se=function I(){i.calledRun||pt(),i.calledRun||(Se=I)},i.run=pt,i.abort=ZA,i.preInit)for(typeof i.preInit=="function"&&(i.preInit=[i.preInit]);i.preInit.length>0;)i.preInit.pop()();i.noExitRuntime=!0,pt(),i.onRuntimeInitialized=()=>{rn=!0,an()},VA.decode=function(I){return function(h){if(!rn)throw Error("Not initialized");var f={};function G(Ie){return new Int32Array(i.HEAPU8.buffer,Ie,1)[0]}function P(Ie,yt){var Pe=new ArrayBuffer(yt*Float32Array.BYTES_PER_ELEMENT),ge=new Float32Array(Pe);return ge.set(new Float32Array(i.HEAPU8.buffer,Ie,yt)),ge}f.open=i.cwrap("stb_vorbis_js_open","number",[]),f.close=i.cwrap("stb_vorbis_js_close","void",["number"]),f.channels=i.cwrap("stb_vorbis_js_channels","number",["number"]),f.sampleRate=i.cwrap("stb_vorbis_js_sample_rate","number",["number"]),f.decode=i.cwrap("stb_vorbis_js_decode","number",["number","number","number","number","number"]);var _,M,hA,oA,rA=f.open(),sA=(_=h,M=h.byteLength,hA=i._malloc(M),(oA=new Uint8Array(i.HEAPU8.buffer,hA,M)).set(new Uint8Array(_,0,M)),oA),q=i._malloc(4),pA=i._malloc(4),MA=f.decode(rA,sA.byteOffset,sA.byteLength,q,pA);if(i._free(sA.byteOffset),MA<0)throw f.close(rA),i._free(q),Error("stbvorbis decode failed: "+MA);for(var NA=f.channels(rA),bA=Array(NA),se=new Int32Array(i.HEAPU32.buffer,G(q),NA),LA=0;LA=0&&(s=this.workletProcessorChannels[e]),t.messageType){case AA.noteOn:this.noteOn(e,A[0],A[1],A[2]);break;case AA.noteOff:this.noteOff(e,A);break;case AA.pitchWheel:this.pitchWheel(e,A[0],A[1]);break;case AA.ccChange:this.controllerChange(e,A[0],A[1],A[2]);break;case AA.customcCcChange:s.customControllers[A[0]]=A[1];break;case AA.killNote:this.killNote(e,A);break;case AA.programChange:this.programChange(e,A[0],A[1]);break;case AA.channelPressure:this.channelPressure(e,A);break;case AA.polyPressure:this.polyPressure(e,A[0],A[1]);break;case AA.ccReset:e===HA?this.resetAllControllers():this.resetControllers(e);break;case AA.systemExclusive:this.systemExclusive(A);break;case AA.setChannelVibrato:if(e===HA)for(let g=0;g{let e=(A.midiControllers[gA+O.pitchWheelRange]>>7)+(A.midiControllers[gA+O.pitchWheelRange]&127)/127;return{voicesAmount:A.voices.length,pitchBend:A.midiControllers[gA+O.pitchWheel],pitchBendRangeSemitones:e,isMuted:A.isMuted,isDrum:A.drumChannel}});this.post({messageType:uA.channelProperties,messageData:t})}function Po(t,A,e){let s=t,n=A<<7|e;return t===127&&A===127&&e===127?{midiNote:-1,centTuning:null}:{midiNote:s,centTuning:n*.0061}}function En(t,A=0){let e=t[0];if(!(this.deviceID!==HA&&t[1]!==127&&this.deviceID!==t[1]))switch(e){default:T(`%cUnrecognized SysEx: %c${lA(t)}`,r.warn,r.unrecognized);break;case 126:case 127:switch(t[2]){case 4:let n;switch(t[3]){case 1:let o=t[5]<<7|t[4];this.setMIDIVolume(o/16384),m(`%cMaster Volume. Volume: %c${o}`,r.info,r.value);break;case 2:let C=((t[5]<<7|t[4])-8192)/8192;this.setMasterPan(C),m(`%cMaster Pan. Pan: %c${C}`,r.info,r.value);break;case 3:let Q=(t[5]<<7|t[6])-8192;n=Math.floor(Q/81.92),this.setMasterTuning(n),m(`%cMaster Fine Tuning. Cents: %c${n}`,r.info,r.value);break;case 4:n=(t[5]-64)*100,this.setMasterTuning(n),m(`%cMaster Coarse Tuning. Cents: %c${n}`,r.info,r.value);break;default:T(`%cUnrecognized MIDI Device Control Real-time message: %c${lA(t)}`,r.warn,r.unrecognized)}break;case 9:t[3]===1?(m("%cGM system on",r.info),this.system="gm"):t[3]===3?(m("%cGM2 system on",r.info),this.system="gm2"):(m("%cGM system off, defaulting to GS",r.info),this.system="gs");break;case 8:switch(t[3]){case 2:case 7:let o=4;t[3]===7&&o++;let g=t[o++],C=t[o++];for(let B=0;B>1&1)===1&&this.setOctaveTuning(15+A,Q);for(let B=0;B<7;B++)(t[5]>>B&1)===1&&this.setOctaveTuning(7+B+A,Q);for(let B=0;B<7;B++)(t[6]>>B&1)===1&&this.setOctaveTuning(B+A,Q);m(`%cMIDI Octave Scale ${t[3]===8?"(1 byte)":"(2 bytes)"} tuning via Tuning: %c${Q.join(" ")}`,r.info,r.value);break;default:T(`%cUnrecognized MIDI Tuning standard message: %c${lA(t)}`,r.warn,r.unrecognized);break}break;default:T(`%cUnrecognized MIDI Realtime/non realtime message: %c${lA(t)}`,r.warn,r.unrecognized)}break;case 65:let s=function(){T(`%cUnrecognized Roland %cGS %cSysEx: %c${lA(t)}`,r.warn,r.recognized,r.warn,r.unrecognized)};if(t[2]===66&&t[3]===18){let n=t[7];if(t[6]===127){n===0?(m("%cGS Reset received!",r.info),this.resetAllControllers(!1),this.system="gs"):n===127&&(m("%cGS system off, switching to GM2",r.info),this.resetAllControllers(!1),this.system="gm2");return}else if(t[4]===64){if((t[5]&16)>0){let o=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][t[5]&15]+A;switch(t[6]){default:s();break;case 21:let g=n>0&&t[5]>>4;this.setDrums(o,g),m(`%cChannel %c${o}%c ${g?"is now a drum channel":"now isn't a drum channel"}%c via: %c${lA(t)}`,r.info,r.value,r.recognized,r.info,r.value);return;case 22:let C=n-64;this.transposeChannel(o,C),m(`%cChannel %c${o}%c pitch shift. Semitones %c${C}%c, with %c${lA(t)}`,r.info,r.recognized,r.info,r.value,r.info,r.value);return;case 28:let Q=n;Q===0&&(Q=Math.floor(Math.random()*128)),this.controllerChange(o,y.pan,Q);break;case 33:this.controllerChange(o,y.chorusDepth,n);break;case 34:this.controllerChange(o,y.reverbDepth,n);break;case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:let B=t.length-9,d=new Int8Array(12);for(let u=0;u=this.workletProcessorChannels.length)return;let o=t[6];switch(t[5]){case 1:this.controllerChange(n,y.bankSelect,o);break;case 2:this.controllerChange(n,y.lsbForControl0BankSelect,o);break;case 3:this.programChange(n,o);break;case 8:let g=this.workletProcessorChannels[n];if(g.drumChannel)return;let C=o-64;g.channelTransposeKeyShift=C;break;case 11:this.controllerChange(n,y.mainVolume,o);break;case 14:let Q=o;Q===0&&(Q=Math.floor(Math.random()*127)),this.controllerChange(n,y.pan,Q);break;case 19:this.controllerChange(n,y.reverbDepth,o);break;case 18:this.controllerChange(n,y.chorusDepth,o);break;default:T(`%cUnrecognized Yamaha XG Part Setup: %c${t[5].toString(16).toUpperCase()}`,r.warn,r.unrecognized)}}else this.system==="xg"&&T(`%cUnrecognized Yamaha XG SysEx: %c${lA(t)}`,r.warn,r.unrecognized);else this.system==="xg"&&T(`%cUnrecognized Yamaha SysEx: %c${lA(t)}`,r.warn,r.unrecognized);break}}var Ko=1e3/200;function Bn(t,A,e){if(A.transformAmount===0)return A.currentValue=0,0;let s;if(A.sourceUsesCC)s=t[A.sourceIndex];else{let B=A.sourceIndex+gA;switch(A.sourceIndex){case O.noController:s=16383;break;case O.noteOnKeyNum:s=e.midiNote<<7;break;case O.noteOnVelocity:s=e.velocity<<7;break;case O.polyPressure:s=e.pressure<<7;break;default:s=t[B];break}}let n=ie[A.sourceCurveType][A.sourcePolarity][A.sourceDirection][s],o;if(A.secSrcUsesCC)o=t[A.secSrcIndex];else{let B=A.secSrcIndex+gA;switch(A.secSrcIndex){case O.noController:o=16383;break;case O.noteOnKeyNum:o=e.midiNote<<7;break;case O.noteOnVelocity:o=e.velocity<<7;break;case O.polyPressure:o=e.pressure<<7;break;default:o=t[B]}}let g=ie[A.secSrcCurveType][A.secSrcPolarity][A.secSrcDirection][o],C=A.transformAmount;A.isEffectModulator&&C<=1e3&&(C*=Ko,C=Math.min(C,1e3));let Q=n*g*C;return A.transformType===2&&(Q=Math.abs(Q)),A.currentValue=Q,Q}function WA(t,A,e=-1,s=0){let n=t.modulators,o=t.generators,g=t.modulatedGenerators;if(e===-1){g.set(o),n.forEach(B=>{let d=L[B.modulatorDestination],l=g[B.modulatorDestination]+Bn(A,B,t);g[B.modulatorDestination]=Math.max(d.min,Math.min(l,d.max))}),TA.recalculate(t),UA.recalculate(t);return}let C=new Set([a.initialAttenuation,a.delayVolEnv,a.attackVolEnv,a.holdVolEnv,a.decayVolEnv,a.sustainVolEnv,a.releaseVolEnv,a.keyNumToVolEnvHold,a.keyNumToVolEnvDecay]),Q=new Set;n.forEach(B=>{if(B.sourceUsesCC===e&&B.sourceIndex===s||B.secSrcUsesCC===e&&B.secSrcIndex===s){let d=B.modulatorDestination;Q.has(d)||(g[d]=o[d],Bn(A,B,t),n.forEach(l=>{if(l.modulatorDestination===d){let u=L[B.modulatorDestination],c=g[B.modulatorDestination]+l.currentValue;g[B.modulatorDestination]=Math.max(u.min,Math.min(c,u.max))}}),Q.add(d))}}),[...Q].some(B=>C.has(B))&&TA.recalculate(t),UA.recalculate(t)}var ie=[];for(let t=0;t<4;t++){ie[t]=[[new Float32Array(CA),new Float32Array(CA)],[new Float32Array(CA),new Float32Array(CA)]];for(let A=0;A200&&e<40||this.highPerformanceMode&&e<10||g.isMuted)return;let C=A+g.channelTransposeKeyShift,Q=C;if(A>127||A<0)return;let B=g.preset.program;this.tunings[B]?.[A]?.midiNote>=0&&(Q=this.tunings[B]?.[A].midiNote),g.velocityOverride>0&&(e=g.velocityOverride);let d=this.keyModifierManager.getVelocity(t,A);d>-1&&(e=d);let l=this.getWorkletVoices(t,Q,e,g,o,C,s),u=g.voices;l.forEach(c=>{let p=c.generators[a.exclusiveClass];p!==0&&u.forEach(N=>{N.generators[a.exclusiveClass]===p&&(this.releaseVoice(N),N.modulatedGenerators[a.releaseVolEnv]=-7e3,N.modulatedGenerators[a.releaseModEnv]=-7e3,TA.recalculate(N),UA.recalculate(N))}),WA(c,g.midiControllers);let S=c.modulatedGenerators[a.startAddrsOffset]+c.modulatedGenerators[a.startAddrsCoarseOffset]*32768,D=c.modulatedGenerators[a.endAddrOffset]+c.modulatedGenerators[a.endAddrsCoarseOffset]*32768,w=c.modulatedGenerators[a.startloopAddrsOffset]+c.modulatedGenerators[a.startloopAddrsCoarseOffset]*32768,J=c.modulatedGenerators[a.endloopAddrsOffset]+c.modulatedGenerators[a.endloopAddrsCoarseOffset]*32768,R=c.sample,U=N=>Math.max(0,Math.min(R.sampleData.length-1,N));if(R.cursor=U(R.cursor+S),R.end=U(R.end+D),R.loopStart=U(R.loopStart+w),R.loopEnd=U(R.loopEnd+J),R.loopEndthis.voiceCap&&this.voiceKilling(l.length),u.push(...l),n&&(this.sendChannelProperties(),this.callEvent("noteon",{midiNote:A,channel:t,velocity:e}))}function Qn(t,A){if(A>127||A<0){T("Received a noteOn for note",A,"Ignoring.");return}let e=A+this.workletProcessorChannels[t].channelTransposeKeyShift;if(this.highPerformanceMode&&!this.workletProcessorChannels[t].drumChannel){this.killNote(t,e);return}this.workletProcessorChannels[t].voices.forEach(n=>{n.realKey!==e||n.isInRelease===!0||(this.workletProcessorChannels[t].holdPedal?this.workletProcessorChannels[t].sustainedVoices.push(n):this.releaseVoice(n))}),this.callEvent("noteoff",{midiNote:A,channel:t})}function cn(t,A){this.workletProcessorChannels[t].voices.forEach(e=>{e.realKey===A&&(e.modulatedGenerators[a.releaseVolEnv]=-12e3,this.releaseVoice(e))})}function ln(t,A=!1){let e=this.workletProcessorChannels[t].voices;A?(e.length=0,this.workletProcessorChannels[t].sustainedVoices.length=0,this.sendChannelProperties()):(e.forEach(s=>{s.isInRelease||this.releaseVoice(s)}),this.workletProcessorChannels[t].sustainedVoices.forEach(s=>{this.releaseVoice(s)}))}function un(t=!1){m("%cStop all received!",r.info);for(let A=0;AWA(n,this.workletProcessorChannels[t].midiControllers,0,O.pitchWheel)),this.sendChannelProperties()}function kn(t,A){let e=this.workletProcessorChannels[t];e.midiControllers[gA+O.channelPressure]=A<<7,this.workletProcessorChannels[t].voices.forEach(s=>WA(s,e.midiControllers,0,O.channelPressure)),this.callEvent("channelpressure",{channel:t,pressure:A})}function wn(t,A,e){this.workletProcessorChannels[t].voices.forEach(s=>{s.midiNote===A&&(s.pressure=e,WA(s,this.workletProcessorChannels[t].midiControllers,0,O.polyPressure))}),this.callEvent("polypressure",{channel:t,midiNote:A,pressure:e})}function Fn(t,A){if(A.length!==12)throw new Error("Tuning is not the length of 12.");this.workletProcessorChannels[t].channelOctaveTuning=A}function Rn(t,A,e,s=!1){let n=this.workletProcessorChannels[t];if(n===void 0){T(`Trying to access channel ${t} which does not exist... ignoring!`);return}if(A>127){if(!s)return;switch(A){default:return;case xt.velocityOverride:n.velocityOverride=e}}if(A>=y.lsbForControl1ModulationWheel&&A<=y.lsbForControl13EffectControl2&&A!==y.lsbForControl6DataEntry){let o=A-32;if(n.lockedControllers[o])return;n.midiControllers[o]=n.midiControllers[o]&16256|e&127,n.voices.forEach(g=>WA(g,n.midiControllers,1,o))}switch(A){case y.allNotesOff:this.stopAll(t);break;case y.allSoundOff:this.stopAll(t,!0);break;case y.bankSelect:let o=e;if(!s){switch(this.system){case"gm":m(`%cIgnoring the Bank Select (${e}), as the synth is in GM mode.`,r.info);return;case"xg":o===120||o===126||o===127?this.setDrums(t,!0):t%16!==SA&&this.setDrums(t,!1);break;case"gm2":o===120&&this.setDrums(t,!0)}n.drumChannel&&(o=128),o===128&&!n.drumChannel&&(o=PA(n))}jA(n,o);break;case y.lsbForControl0BankSelect:this.system==="xg"?n.drumChannel||e!==127&&jA(n,e):this.system==="gm2"&&jA(n,e);break;case y.RPNLsb:n.RPValue=n.RPValue<<7|e,n.dataEntryState=fA.RPFine;break;case y.RPNMsb:n.RPValue=e,n.dataEntryState=fA.RPCoarse;break;case y.NRPNMsb:n.NRPCoarse=e,n.dataEntryState=fA.NRPCoarse;break;case y.NRPNLsb:n.NRPFine=e,n.dataEntryState=fA.NRPFine;break;case y.dataEntryMsb:this.dataEntryCoarse(t,e);break;case y.lsbForControl6DataEntry:this.dataEntryFine(t,e);break;case y.resetAllControllers:this.resetControllers(t);break;case y.sustainPedal:e>=64?n.holdPedal=!0:(n.holdPedal=!1,n.sustainedVoices.forEach(g=>{this.releaseVoice(g)}),n.sustainedVoices=[]);break;default:if(n.lockedControllers[A])return;n.midiControllers[A]=e<<7,n.voices.forEach(g=>WA(g,n.midiControllers,1,A));break}this.callEvent("controllerchange",{channel:t,controllerNumber:A,controllerValue:e})}function Gn(t){this.midiVolume=t,this.setMasterPan(this.pan)}function xn(t){this.masterGain=t*Jt,this.setMasterPan(this.pan)}function Mn(t){this.pan=t,t=t/2+.5,this.panLeft=1-t,this.panRight=t}function Nn(t,A){A&&this.stopAll(t,!0),this.workletProcessorChannels[t].isMuted=A,this.sendChannelProperties(),this.callEvent("mutechannel",{channel:t,isMuted:A})}function bn(t){this.workletProcessorChannels[t].lockGSNRPNParams=!0,this.workletProcessorChannels[t].channelVibrato.rate=0,this.workletProcessorChannels[t].channelVibrato.delay=0,this.workletProcessorChannels[t].channelVibrato.depth=0}function Ln(t,A,e,s){this.workletProcessorChannels[t].lockGSNRPNParams||(this.workletProcessorChannels[t].channelVibrato.rate=e,this.workletProcessorChannels[t].channelVibrato.delay=s,this.workletProcessorChannels[t].channelVibrato.depth=A)}function Un(t,A){let e=this.workletProcessorChannels[t],s=()=>{e.channelVibrato.delay===0&&e.channelVibrato.rate===0&&e.channelVibrato.depth===0&&(e.channelVibrato.depth=50,e.channelVibrato.rate=8,e.channelVibrato.delay=.6)};switch(e.dataEntryState){default:case fA.Idle:break;case fA.NRPFine:if(this.system!=="gs"||e.lockGSNRPNParams)return;switch(e.NRPCoarse){default:if(A===64)return;T(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16).toUpperCase()} 0x${e.NRPFine.toString(16).toUpperCase()})%c data value: %c${A}`,r.warn,r.recognized,r.warn,r.unrecognized,r.warn,r.value);break;case 1:switch(e.NRPFine){default:if(A===64)return;T(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16)} 0x${e.NRPFine.toString(16)})%c data value: %c${A}`,r.warn,r.recognized,r.warn,r.unrecognized,r.warn,r.value);break;case 8:if(A===64)return;s(),e.channelVibrato.rate=A/64*8,m(`%cVibrato rate for %c${t}%c is now set to %c${A} = ${e.channelVibrato.rate}%cHz.`,r.info,r.recognized,r.info,r.value,r.info);break;case 9:if(A===64)return;s(),e.channelVibrato.depth=A/2,m(`%cVibrato depth for %c${t}%c is now set to %c${A} = ${e.channelVibrato.depth}%c cents range of detune.`,r.info,r.recognized,r.info,r.value,r.info);break;case 10:if(A===64)return;s(),e.channelVibrato.delay=A/64/3,m(`%cVibrato delay for %c${t}%c is now set to %c${A} = ${e.channelVibrato.delay}%c seconds.`,r.info,r.recognized,r.info,r.value,r.info);break;case 32:let g=A;this.controllerChange(t,y.brightness,A),m(`%cFilter cutoff for %c${t}%c is now set to %c${g}`,r.info,r.recognized,r.info,r.value)}break;case 24:let n=A-64;e.keyCentTuning[e.NRPFine]=n*100,m(`%cGS drum key tuning. MIDI note: %c${e.NRPFine}%c semitones: %c${n}`,r.info,r.recognized,r.info,r.value);break;case 29:let o=A;this.controllerChange(t,y.reverbDepth,o),m(`%cGS Drum reverb for %c${t}%c: %c${o}`,r.info,r.recognized,r.info,r.value);break}break;case fA.RPCoarse:case fA.RPFine:switch(e.RPValue){default:T(`%cUnrecognized RPN for %c${t}%c: %c(0x${e.RPValue.toString(16)})%c data value: %c${A}`,r.warn,r.recognized,r.warn,r.unrecognized,r.warn,r.value);break;case 0:e.midiControllers[gA+O.pitchWheelRange]=A<<7,m(`%cChannel ${t} bend range. Semitones: %c${A}`,r.info,r.value);break;case 2:this.setChannelTuningSemitones(t,A-64);break;case 1:this.setChannelTuning(t,A-64,!1);break;case 5:this.setModulationDepth(t,A*100);break;case 16383:this.resetParameters(t);break}}}function Tn(t,A){let e=this.workletProcessorChannels[t];switch(e.dataEntryState){default:break;case fA.RPCoarse:case fA.RPFine:switch(e.RPValue){default:break;case 0:if(A===0)break;e.midiControllers[gA+O.pitchWheelRange]|=A;let s=(e.midiControllers[gA+O.pitchWheelRange]>>7)+A/127;m(`%cChannel ${t} bend range. Semitones: %c${s}`,r.info,r.value);break;case 1:let o=e.customControllers[aA.channelTuning]<<7|A;this.setChannelTuning(t,o*.01220703125);break;case 5:let C=e.customControllers[aA.modulationMultiplier]*50+A/128*100;this.setModulationDepth(t,C);break;case 16383:this.resetParameters(t);break}}}function Hn(t=!0){t&&m("%cResetting all controllers!",r.info),this.callEvent("allcontrollerreset",void 0);for(let A=0;A>7});if(this.workletProcessorChannels[A].lockedControllers[gA+O.pitchWheel]===!1){let s=this.workletProcessorChannels[A].midiControllers[gA+O.pitchWheel],n=s>>7,o=s&127;this.callEvent("pitchwheel",{channel:A,MSB:n,LSB:o})}}this.tunings=[],this.tunings=[];for(let A=0;127>A;A++)this.tunings.push([]);this.setMIDIVolume(1),this.system=_e}function Yn(t){let A=this.workletProcessorChannels[t],s=A.lockedControllers.reduce((o,g,C)=>(g&&o.push(C),o),[]).map(o=>({ccNum:o,ccVal:A.midiControllers[o]}));A.channelOctaveTuning.fill(0),A.keyCentTuning.fill(0),A.midiControllers.set(Ft),A.channelVibrato={rate:0,depth:0,delay:0},A.holdPedal=!1,s.forEach(o=>{A.midiControllers[o.ccNum]=o.ccVal});let n=A.customControllers[aA.channelTransposeFine];A.customControllers.set(Gt),A.customControllers[aA.channelTransposeFine]=n,this.resetParameters(t)}function Jn(t){let A=this.workletProcessorChannels[t];A.NRPCoarse=0,A.NRPFine=0,A.RPValue=0,A.dataEntryState=fA.Idle}function vn(){let t=4;for(let s of this.instruments)t+=s.instrumentZones.reduce((n,o)=>(o.generators=o.generators.filter(g=>g.generatorType!==a.sampleID&&g.generatorType!==a.keyRange&&g.generatorType!==a.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:a.velRange,generatorValue:o.velRange.max<<8|o.velRange.min}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:a.keyRange,generatorValue:o.keyRange.max<<8|o.keyRange.min}),o.isGlobal||o.generators.push({generatorType:a.sampleID,generatorValue:this.samples.indexOf(o.sample)}),o.generators.length*4+n),0);let A=new Y(t),e=0;for(let s of this.instruments)for(let n of s.instrumentZones){n.generatorZoneStartIndex=e;for(let o of n.generators)v(A,o.generatorType),v(A,o.generatorValue),e++}return cA(A,0),nA(new eA("igen",A.length,A))}function qn(t,A,e,s,n){let o=this.samples.map((B,d)=>{e&&B.compressSample(s,n);let l=B.getRawData();return m(`%cEncoded sample %c${d}. ${B.sampleName}%c of %c${this.samples.length}`,r.info,r.recognized,r.info,r.recognized),l}),g=this.samples.reduce((B,d,l)=>B+o[l].length+46,0),C=new Y(g);this.samples.forEach((B,d)=>{let l=o[d],u,c,p=l.length;B.isCompressed?(u=C.currentIndex,c=u+l.length):(u=C.currentIndex/2,c=u+l.length/2,p+=46),t.push(u),C.set(l,C.currentIndex),C.currentIndex+=p,A.push(c)});let Q=nA(new eA("smpl",C.length,C),new Y([115,100,116,97]));return nA(new eA("LIST",Q.length,Q))}function Pn(t,A){let s=new Y(46*(this.samples.length+1));return this.samples.forEach((n,o)=>{RA(s,n.sampleName,20);let g=t[o];cA(s,g);let C=A[o];cA(s,C);let Q=n.sampleLoopStartIndex+g,B=n.sampleLoopEndIndex+g;n.isCompressed&&(Q-=g,B-=g),cA(s,Q),cA(s,B),cA(s,n.sampleRate),s[s.currentIndex++]=n.samplePitch,s[s.currentIndex++]=n.samplePitchCorrection,v(s,n.sampleLink),v(s,n.sampleType)}),RA(s,"EOS",46),nA(new eA("shdr",s.length,s))}function Kn(){let t=10;for(let s of this.instruments)t+=s.instrumentZones.reduce((n,o)=>o.modulators.length*10+n,0);let A=new Y(t),e=0;for(let s of this.instruments)for(let n of s.instrumentZones){n.modulatorZoneStartIndex=e;for(let o of n.modulators)v(A,o.sourceEnum),v(A,o.modulatorDestination),v(A,o.transformAmount),v(A,o.secondarySourceEnum),v(A,o.transformType),e++}return he(A,0,10),nA(new eA("imod",A.length,A))}function On(){let t=this.instruments.reduce((o,g)=>g.instrumentZones.length*4+o,4),A=new Y(t),e=0,s=0,n=0;for(let o of this.instruments){o.instrumentZoneIndex=e;for(let g of o.instrumentZones)g.zoneID=e,v(A,s),v(A,n),s+=g.generators.length,n+=g.modulators.length,e++}return v(A,s),v(A,n),nA(new eA("ibag",A.length,A))}function Vn(){let t=this.instruments.length*22+22,A=new Y(t),e=0,s=0;for(let n of this.instruments)RA(A,n.instrumentName,20),v(A,e),e+=n.instrumentZones.length,n.instrumentID=s,s++;return RA(A,"EOI",20),v(A,e),nA(new eA("inst",A.length,A))}function Zn(){let t=4;for(let s of this.presets)t+=s.presetZones.reduce((n,o)=>(o.generators=o.generators.filter(g=>g.generatorType!==a.instrument&&g.generatorType!==a.keyRange&&g.generatorType!==a.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:a.velRange,generatorValue:o.velRange.max<<8|o.velRange.min}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:a.keyRange,generatorValue:o.keyRange.max<<8|o.keyRange.min}),o.isGlobal||o.generators.push({generatorType:a.instrument,generatorValue:this.instruments.indexOf(o.instrument)}),o.generators.length*4+n),0);let A=new Y(t),e=0;for(let s of this.presets)for(let n of s.presetZones){n.generatorZoneStartIndex=e;for(let o of n.generators)v(A,o.generatorType),v(A,o.generatorValue);e+=n.generators.length}return v(A,0),v(A,0),nA(new eA("pgen",A.length,A))}function Xn(){let t=10;for(let s of this.presets)t+=s.presetZones.reduce((n,o)=>o.modulators.length*10+n,0);let A=new Y(t),e=0;for(let s of this.presets)for(let n of s.presetZones){n.modulatorZoneStartIndex=e;for(let o of n.modulators)v(A,o.sourceEnum),v(A,o.modulatorDestination),v(A,o.transformAmount),v(A,o.secondarySourceEnum),v(A,o.transformType),e++}return he(A,0,10),nA(new eA("pmod",A.length,A))}function Wn(){let t=this.presets.reduce((o,g)=>g.presetZones.length*4+o,4),A=new Y(t),e=0,s=0,n=0;for(let o of this.presets){o.presetZoneStartIndex=e;for(let g of o.presetZones)g.zoneID=e,v(A,s),v(A,n),s+=g.generators.length,n+=g.modulators.length,e++}return v(A,s),v(A,n),nA(new eA("pbag",A.length,A))}function _n(){let t=this.presets.length*38+38,A=new Y(t),e=0;for(let s of this.presets)RA(A,s.presetName,20),v(A,s.program),v(A,s.bank),v(A,e),cA(A,s.library),cA(A,s.genre),cA(A,s.morphology),e+=s.presetZones.length;return RA(A,"EOP",20),v(A,0),v(A,0),v(A,e),cA(A,0),cA(A,0),cA(A,0),nA(new eA("phdr",A.length,A))}var Oo={compress:!1,compressionQuality:.5,compressionFunction:void 0};function zn(t=Oo){if(t.compress&&typeof t.compressionFunction!="function")throw new TypeError("No compression function supplied but compression enabled.");yA("%cSaving soundfont...",r.info),m(`%cCompression: %c${t?.compress||"false"}%c quality: %c${t?.compressionQuality||"none"}`,r.info,r.recognized,r.info,r.recognized),m("%cWriting INFO...",r.info);let A=[];this.soundFontInfo.ISFT="SpessaSynth",t?.compress&&(this.soundFontInfo.ifil="3.0");for(let[U,N]of Object.entries(this.soundFontInfo))if(U==="ifil"||U==="iver"){let i=parseInt(N.split(".")[0]),tA=parseInt(N.split(".")[1]),W=new Y(4);v(W,i),v(W,tA),A.push(nA(new eA(U,4,W)))}else if(U==="DMOD")A.push(nA(new eA(U,N.length,N)));else{let i=new Y(N.length);RA(i,N),A.push(nA(new eA(U,N.length,i)))}let e=Fe([new Y([73,78,70,79]),...A]),s=nA(new eA("LIST",e.length,e));m("%cWriting SDTA...",r.info);let n=[],o=[],g=qn.call(this,n,o,t?.compress,t?.compressionQuality??.5,t.compressionFunction);m("%cWriting PDTA...",r.info),m("%cWriting SHDR...",r.info);let C=Pn.call(this,n,o);m("%cWriting IGEN...",r.info);let Q=vn.call(this);m("%cWriting IMOD...",r.info);let B=Kn.call(this);m("%cWriting IBAG...",r.info);let d=On.call(this);m("%cWriting INST...",r.info);let l=Vn.call(this),u=Zn.call(this);m("%cWriting PMOD...",r.info);let c=Xn.call(this);m("%cWriting PBAG...",r.info);let p=Wn.call(this);m("%cWriting PHDR...",r.info);let S=_n.call(this),D=Fe([new Y([112,100,116,97]),S,p,c,u,l,d,B,Q,C]),w=nA(new eA("LIST",D.length,D));m("%cWriting the output file...",r.info);let J=Fe([new Y([115,102,98,107]),s,g,w]),R=nA(new eA("RIFF",J.length,J));return m(`%cSaved succesfully! Final file size: %c${R.length}`,r.info,r.recognized),V(),R}var ae=class t{constructor(A=void 0){this.soundFontInfo={},this.presets=[],this.samples=[],this.instruments=[],this.defaultModulators=Oe.map(e=>j.copy(e)),A?.presets&&(this.presets.push(...A.presets),this.soundFontInfo=A.info)}static mergeSoundfonts(...A){let e=A.shift(),s=e.presets;for(;A.length;)A.shift().presets.forEach(o=>{s.find(g=>g.bank===o.bank&&g.program===o.program)===void 0&&s.push(o)});return new t({presets:s,info:e.soundFontInfo})}removeUnusedElements(){this.instruments.forEach(A=>{A.useCount<1&&A.instrumentZones.forEach(e=>{e.isGlobal||e.sample.useCount--})}),this.instruments=this.instruments.filter(A=>A.useCount>0),this.samples=this.samples.filter(A=>A.useCount>0)}deleteInstrument(A){if(A.useCount>0)throw new Error(`Cannot delete an instrument that has ${A.useCount} usages.`);this.instruments.splice(this.instruments.indexOf(A),1),A.deleteInstrument(),this.removeUnusedElements()}deletePreset(A){A.deletePreset(),this.presets.splice(this.presets.indexOf(A),1),this.removeUnusedElements()}deleteSample(A){if(A.useCount>0)throw new Error(`Cannot delete sample that has ${A.useCount} usages.`);this.samples.splice(this.samples.indexOf(A),1),this.removeUnusedElements()}setSampleIDOffset(A){this.presets.forEach(e=>e.sampleIDOffset=A)}getPresetNoFallback(A,e,s=!1){let n=this.presets.find(o=>o.bank===A&&o.program===e);if(n)return n;if(s!==!1)return A===128?this.presets.find(o=>o.bank===128):this.presets.find(o=>o.program===e)}getPreset(A,e){let s=this.presets.find(n=>n.bank===A&&n.program===e);return s||(A===128?(s=this.presets.find(n=>n.bank===128&&n.program===e),s||(s=this.presets.find(n=>n.bank===128))):s=this.presets.find(n=>n.program===e&&n.bank!==128),s&&T(`%cPreset ${A}.${e} not found. Replaced with %c${s.presetName} (${s.bank}.${s.program})`,r.warn,r.recognized)),s||(T(`Preset ${e} not found. Defaulting to`,this.presets[0].presetName),s=this.presets[0]),s}getPresetByName(A){let e=this.presets.find(s=>s.presetName===A);return e||(T("Preset not found. Defaulting to:",this.presets[0].presetName),e=this.presets[0]),e}parsingError(A){throw new Error(`SF parsing error: ${A} The file may be corrupted.`)}};ae.prototype.write=zn;function jn(t){yA("%cLoading instruments...",r.info);for(let A=0;AA.deleteZone()),this.presetZones.length=0}deleteZone(A){this.presetZones[A].deleteZone(),this.presetZones.splice(A,1)}preload(A,e){for(let s=A;s{o.sample.isSampleLoaded||o.sample.getAudioData()})}preloadSpecific(A,e){this.getSamplesAndGenerators(A,e).forEach(s=>{s.sample.isSampleLoaded||s.sample.getAudioData()})}getSamplesAndGenerators(A,e){let s=this.foundSamplesAndGenerators[A][e];if(s)return s;if(this.presetZones.length<1)return[];function n(l,u,c){return c>=l&&c<=u}function o(l,u){l.push(...u.filter(c=>!l.find(p=>p.generatorType===c.generatorType)))}function g(l,u){l.push(...u.filter(c=>!l.find(p=>j.isIdentical(c,p))))}let C=[],Q=this.presetZones[0].isGlobal?[...this.presetZones[0].generators]:[],B=this.presetZones[0].isGlobal?[...this.presetZones[0].modulators]:[];return this.presetZones.filter(l=>n(l.keyRange.min,l.keyRange.max,A)&&n(l.velRange.min,l.velRange.max,e)&&!l.isGlobal).forEach(l=>{if(l.instrument.instrumentZones.length<1)return;let u=l.generators,c=l.modulators,p=l.instrument.instrumentZones[0].isGlobal?[...l.instrument.instrumentZones[0].generators]:[],S=l.instrument.instrumentZones[0].isGlobal?[...l.instrument.instrumentZones[0].modulators]:[];l.instrument.instrumentZones.filter(w=>n(w.keyRange.min,w.keyRange.max,A)&&n(w.velRange.min,w.velRange.max,e)&&!w.isGlobal).forEach(w=>{let J=[...w.generators],R=[...w.modulators];o(u,Q),o(J,p),g(c,B),g(R,S),g(R,this.defaultModulators);let U=[...R];for(let N=0;Nj.isIdentical(i,W));tA!==-1?U[tA]=U[tA].sumTransform(i):U.push(i)}C.push({instrumentGenerators:J,presetGenerators:u,modulators:U,sample:w.sample,sampleID:w.generators.find(N=>N.generatorType===a.sampleID).generatorValue})})}),this.foundSamplesAndGenerators[A][e]=C,C}};var xe=class{velRange={min:0,max:127};keyRange={min:0,max:127};isGlobal=!1;generators=[];modulators=[]};var ee=class extends xe{sample=void 0;useCount=0;deleteZone(){this.useCount--,!this.isGlobal&&this.sample.useCount--}},de=class extends xe{instrument=void 0;deleteZone(){this.isGlobal||this.instrument.removeUseCount()}};var fe=class{constructor(){this.instrumentName="",this.instrumentZones=[],this._useCount=0}get useCount(){return this._useCount}addUseCount(){this._useCount++,this.instrumentZones.forEach(A=>A.useCount++)}removeUseCount(){this._useCount--;for(let A=0;AA.deleteZone()),this.instrumentZones.length=0}safeDeleteZone(A){return this.instrumentZones[A].useCount--,this.instrumentZones[A].useCount<1?(this.deleteZone(A),!0):!1}deleteZone(A){this.instrumentZones[A].deleteZone(),this.instrumentZones.splice(A,1)}};var nt=class extends ue{constructor(A,e){super(Oe),this.program=e&127,this.bank=A>>8&127,A>>31&&(this.bank=128),this.DLSInstrument=new fe,this.DLSInstrument.addUseCount();let n=new de;n.instrument=this.DLSInstrument,this.presetZones=[n]}};function $n(t){this.verifyHeader(t,"LIST"),this.verifyText(Z(t.chunkData,4),"ins ");let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(X(t.chunkData));let e=A.find(c=>c.header==="insh");if(!e)throw V(),new Error("No instrument header!");let s=k(e.chunkData,4),n=k(e.chunkData,4),o=k(e.chunkData,4),g=new nt(n,o),C="unnamedPreset",Q=DA(A,"INFO");if(Q){let c=X(Q.chunkData);for(;c.header!=="INAM";)c=X(Q.chunkData);C=Z(c.chunkData,c.chunkData.length).trim()}g.presetName=C,g.DLSInstrument.instrumentName=C,ne(`%cParsing %c"${C}"%c...`,r.info,r.recognized,r.info);let B=DA(A,"lrgn");if(!B)throw V(),new Error("No region list!");let d=new ee;d.isGlobal=!0;let l=DA(A,"lart"),u=DA(A,"lar2");this.readLart(l,u,d),g.DLSInstrument.instrumentZones.push(d);for(let c=0;c>10&15;w===QA.linear&&D!==QA.linear&&(w=D);let J=s>>14&1,R=s>>15&1;g===a.initialAttenuation&&(R=!R),l=YA(w,J,R,C.isCC,C.enum)}let u=s>>4&15,c=s>>8&1,p=s>>9&1,S=YA(u,c,p,d.isCC,d.enum);if(Q){let D=S;S=l,l=D}return new j({srcEnum:l,secSrcEnum:S,dest:g,transform:0,amt:n})}function vt(t,A){let e=t.chunkData,s=[],n=[];k(e,4);let o=k(e,4);for(let g=0;g>16;if(C===0&&Q===0&&d===0){let c;switch(B){case x.pan:c=new b(a.pan,u);break;case x.gain:c=new b(a.initialAttenuation,-u*10/.4);break;case x.filterCutoff:c=new b(a.initialFilterFc,u);break;case x.filterQ:c=new b(a.initialFilterQ,u);break;case x.modLfoFreq:c=new b(a.freqModLFO,u);break;case x.modLfoDelay:c=new b(a.delayModLFO,u);break;case x.vibLfoFreq:c=new b(a.freqVibLFO,u);break;case x.vibLfoDelay:c=new b(a.delayVibLFO,u);break;case x.volEnvDelay:c=new b(a.delayVolEnv,u);break;case x.volEnvAttack:c=new b(a.attackVolEnv,u);break;case x.volEnvHold:c=new b(a.holdVolEnv,u);break;case x.volEnvDecay:c=new b(a.decayVolEnv,u);break;case x.volEnvRelease:c=new b(a.releaseVolEnv,u);break;case x.volEnvSustain:let p=(1e3-u)/10;c=new b(a.sustainVolEnv,p*10);break;case x.modEnvDelay:c=new b(a.delayModEnv,u);break;case x.modEnvAttack:c=new b(a.attackModEnv,u);break;case x.modEnvHold:c=new b(a.holdModEnv,u);break;case x.modEnvDecay:c=new b(a.decayModEnv,u);break;case x.modEnvRelease:c=new b(a.releaseModEnv,u);break;case x.modEnvSustain:let S=1e3-u;c=new b(a.sustainModEnv,S);break;case x.reverbSend:c=new b(a.reverbEffectsSend,u);break;case x.chorusSend:c=new b(a.chorusEffectsSend,u);break;case x.pitch:let D=Math.floor(u/100),w=Math.floor(u-D*100);c=new b(a.fineTune,w),s.push(new b(a.coarseTune,D));break}c&&s.push(c)}else{let c=!0;if(Q===z.none)if(C===z.modLfo&&B===x.pitch)s.push(new b(a.modLfoToPitch,u));else if(C===z.modLfo&&B===x.gain)s.push(new b(a.modLfoToVolume,u));else if(C===z.modLfo&&B===x.filterCutoff)s.push(new b(a.modLfoToFilterFc,u));else if(C===z.vibratoLfo&&B===x.pitch)s.push(new b(a.vibLfoToPitch,u));else if(C===z.modEnv&&B===x.pitch)s.push(new b(a.modEnvToPitch,u));else if(C===z.modEnv&&B===x.filterCutoff)s.push(new b(a.modEnvToFilterFc,u));else if(C===z.keyNum&&B===x.volEnvHold){s.push(new b(a.keyNumToVolEnvHold,u/-128));let p=Math.round(60/128*u);s.forEach(S=>{S.generatorType===a.holdVolEnv&&(S.generatorValue+=p)})}else if(C===z.keyNum&&B===x.volEnvDecay){s.push(new b(a.keyNumToVolEnvDecay,u/-128));let p=Math.round(60/128*u);s.forEach(S=>{S.generatorType===a.decayVolEnv&&(S.generatorValue+=p)})}else if(C===z.keyNum&&B===x.modEnvHold){s.push(new b(a.keyNumToModEnvHold,u/-128));let p=Math.round(60/128*u);s.forEach(S=>{S.generatorType===a.holdModEnv&&(S.generatorValue+=p)})}else if(C===z.keyNum&&B===x.modEnvDecay){s.push(new b(a.keyNumToModEnvDecay,u/-128));let p=Math.round(60/128*u);s.forEach(S=>{S.generatorType===a.decayModEnv&&(S.generatorValue+=p)})}else c=!1;else c=!1;if(c===!1){let p=eo(C,Q,B,d,u);p?(n.push(p),m("%cSucceeded converting to SF2 Modulator!",r.recognized)):T("Failed converting to SF2 Modulator!")}}}return n.find(g=>g.modulatorDestination===a.reverbEffectsSend)===void 0&&n.push(new j({srcEnum:219,dest:a.reverbEffectsSend,amt:1e3,secSrcEnum:0,transform:0})),n.find(g=>g.modulatorDestination===a.chorusEffectsSend)===void 0&&n.push(new j({srcEnum:221,dest:a.chorusEffectsSend,amt:1e3,secSrcEnum:0,transform:0})),A&&n.push(new j({srcEnum:129,dest:a.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0}),new j({srcEnum:13,dest:a.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0})),{modulators:n,generators:s}}function to(t,A,e){if(t)for(;t.chunkData.currentIndext.chunkData.currentIndex;)A.push(X(t.chunkData));let e=A.find(W=>W.header==="rgnh"),s=k(e.chunkData,2),n=k(e.chunkData,2),o=k(e.chunkData,2),g=k(e.chunkData,2),C=new ot({min:s,max:n},{min:o,max:g});k(e.chunkData,2);let Q=k(e.chunkData,2);Q!==0&&C.generators.push(new b(a.exclusiveClass,Q));let B=DA(A,"lart"),d=DA(A,"lar2");this.readLart(B,d,C),C.isGlobal=!1;let l=A.find(W=>W.header==="wsmp");k(l.chunkData,4);let u=k(l.chunkData,2),c=Ae(l.chunkData[l.chunkData.currentIndex++],l.chunkData[l.chunkData.currentIndex++]),S=(k(l.chunkData,4)|0)/-655360;k(l.chunkData,4);let D=k(l.chunkData,4),w,J={start:0,end:0};if(D===0)w=0;else{k(l.chunkData,4),k(l.chunkData,4)===0?w=1:w=3,J.start=k(l.chunkData,4);let K=k(l.chunkData,4);J.end=J.start+K}let R=A.find(W=>W.header==="wlnk");if(R===void 0)return;k(R.chunkData,2),k(R.chunkData,2),k(R.chunkData,4);let U=k(R.chunkData,4),N=this.samples[U];if(N===void 0)throw new Error("Invalid sample ID!");let tA=(S||N.sampleDbAttenuation)*10/.4;return C.setWavesample(tA,w,J,u,N,U,c),C}var me=class{constructor(A,e,s,n,o,g,C,Q){this.sampleName=A,this.sampleRate=e,this.samplePitch=s,this.samplePitchCorrection=n,this.sampleLink=o,this.sampleType=g,this.sampleLoopStartIndex=C,this.sampleLoopEndIndex=Q,this.isCompressed=(g&16)>0,this.compressedData=void 0,this.useCount=0}getRawData(){let A=new Error("Not implemented");throw A.name="NotImplementedError",A}compressSample(A,e){if(!this.isCompressed)try{this.compressedData=e([this.getAudioData()],1,this.sampleRate,A),this.sampleType|=16,this.isCompressed=!0}catch{T(`Failed to compress ${this.sampleName}. Leaving as uncompressed!`),this.isCompressed=!1,this.compressedData=void 0,this.sampleType&=-17}}getAudioData(){let A=new Error("Not implemented");throw A.name="NotImplementedError",A}};var rt=class extends me{sampleDbAttenuation;sampleData;constructor(A,e,s,n,o,g,C,Q){super(A,e,s,n,0,1,o,g-1),this.sampleData=C,this.sampleDbAttenuation=Q}getAudioData(){return this.sampleData}getRawData(){if(this.isCompressed){if(!this.compressedData)throw new Error("Compressed but no data?? This shouldn't happen!!");return this.compressedData}let A=new Uint8Array(this.sampleData.length*2);for(let e=0;e>8&255}return A}};function no(t){yA("%cLoading Wave samples...",r.recognized);let A=0;for(;t.chunkData.currentIndexK.header==="fmt ");if(!n)throw new Error("No fmt chunk in the wave file!");let o=k(n.chunkData,2);if(o!==1)throw new Error(`Only PCM format in WAVE is supported. Fmt reports ${o}`);let g=k(n.chunkData,2);if(g!==1)throw new Error(`Only mono samples are supported. Fmt reports ${g} channels`);let C=k(n.chunkData,4);k(n.chunkData,4),k(n.chunkData,2);let Q=k(n.chunkData,2),B=Q/8,d=Math.pow(2,B*8-1),l=Math.pow(2,B*8),u,c=!1;Q===8?(u=255,c=!0):u=d;let p=s.find(K=>K.header==="data");p||this.parsingError("No data chunk in the WAVE chunk!");let S=p.size/B,D=new Float32Array(S);for(let K=0;K=d&&($-=l),D[K]=$/u)}let w=60,J=0,R=0,U=D.length-1,N=0,i=s.find(K=>K.header==="wsmp");if(i){if(k(i.chunkData,4),w=k(i.chunkData,2),J=Ae(i.chunkData[i.chunkData.currentIndex++],i.chunkData[i.chunkData.currentIndex++]),N=(k(i.chunkData,4)|0)/-655360,k(i.chunkData,4),k(i.chunkData,4)===1){k(i.chunkData,8),R=k(i.chunkData,4);let EA=k(i.chunkData,4);U=R+EA}}else T("No wsmp chunk in wave... using sane defaults.");let tA=DA(s,"INFO"),W=`Unnamed ${A}`;if(tA){let K=X(tA.chunkData);for(;K.header!=="INAM"&&tA.chunkData.currentIndexQ.header==="colh");o||(V(),this.parsingError("No colh chunk!")),this.instrumentAmount=k(o.chunkData,4),m(`%cInstruments amount: %c${this.instrumentAmount}`,r.info,r.recognized);let g=DA(s,"wvpl");g||(V(),this.parsingError("No wvpl chunk!")),this.readDLSSamples(g);let C=DA(s,"lins");C||(V(),this.parsingError("No lins chunk!")),this.readDLSInstrumentList(C),this.presets.sort((Q,B)=>Q.program-B.program+(Q.bank-B.bank)),m(`%cParsing finished! %c"${this.soundFontInfo.INAM||"UNNAMED"}"%c has %c${this.presets.length} %cpresets, diff --git a/src/spessasynth_lib/synthetizer/worklet_system/worklet_methods/voice_control.js b/src/spessasynth_lib/synthetizer/worklet_system/worklet_methods/voice_control.js index 17a9947..cd44090 100644 --- a/src/spessasynth_lib/synthetizer/worklet_system/worklet_methods/voice_control.js +++ b/src/spessasynth_lib/synthetizer/worklet_system/worklet_methods/voice_control.js @@ -7,11 +7,11 @@ import { getSampleNearest, interpolationTypes } from "../worklet_utilities/wavetable_oscillator.js"; -import { WorkletLowpassFilter } from "../worklet_utilities/lowpass_filter.js"; import { MIN_NOTE_LENGTH } from "../main_processor.js"; import { WorkletVolumeEnvelope } from "../worklet_utilities/volume_envelope.js"; import { generatorTypes } from "../../../soundfont/basic_soundfont/generator.js"; import { customControllers } from "../worklet_utilities/controller_tables.js"; +import { WorkletLowpassFilter } from "../worklet_utilities/lowpass_filter.js"; export const PAN_SMOOTHING_FACTOR = 0.05; diff --git a/src/spessasynth_lib/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js b/src/spessasynth_lib/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js index 7de9f01..f166ee4 100644 --- a/src/spessasynth_lib/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js +++ b/src/spessasynth_lib/synthetizer/worklet_system/worklet_utilities/lowpass_filter.js @@ -79,15 +79,16 @@ export class WorkletLowpassFilter /** * Cutoff frequency in cents + * Note: defaults to 13501 to cause a recalculation even at initial fc being 13500 * @type {number} */ - cutoffCents = 13500; + cutoffCents = 13501; /** * Cutoff frequency in Hz * @type {number} */ - cutoffHz = 20000; + cutoffHz = 20001; /** * Applies a low-pass filter to the given buffer