spessasynth_lib 4.2.5 → 4.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ var qA=(A=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(A,{get:(e,t)=>(
3
3
  Secondary source: ${this.secondarySource.toString()}
4
4
  to: ${this.destinationName}
5
5
  amount: ${this.transformAmount}`+(this.transformType===2?"absolute value":"")}write(e,t){te(e,this.primarySource.toSourceEnum()),te(e,this.destination),te(e,this.transformAmount),te(e,this.secondarySource.toSourceEnum()),te(e,this.transformType),t&&t.mod++}sumTransform(e){let t=hn.copyFrom(this);return t.transformAmount+=e.transformAmount,t}},be=class extends Re{constructor(A,e,t,s,n){let a=(A===219||A===221)&&e===0&&(t===g.reverbEffectsSend||t===g.chorusEffectsSend),o=A===Xa&&e===0&&t===g.initialFilterQ;super(cA.fromSourceEnum(A),cA.fromSourceEnum(e),t,s,n,a,o),this.destination>Br&&(this.destination=g.INVALID)}},xs=960,Hs=me.concave,Yr=[new be(gA(Hs,!1,!0,!1,Ae.noteOnVelocity),0,g.initialAttenuation,xs,0),new be(129,0,g.vibLfoToPitch,50,0),new be(gA(Hs,!1,!0,!0,u.mainVolume),0,g.initialAttenuation,xs,0),new be(13,0,g.vibLfoToPitch,50,0),new be(526,16,g.fineTune,12700,0),new be(650,0,g.pan,500,0),new be(gA(Hs,!1,!0,!0,u.expressionController),0,g.initialAttenuation,xs,0),new be(219,0,g.reverbEffectsSend,200,0),new be(221,0,g.chorusEffectsSend,200,0)],qr=[new be(gA(me.convex,!0,!1,!0,u.attackTime),0,g.attackVolEnv,6e3,0),new be(gA(me.linear,!0,!1,!0,u.releaseTime),0,g.releaseVolEnv,3600,0),new be(gA(me.linear,!0,!1,!0,u.decayTime),0,g.decayVolEnv,3600,0),new be(gA(me.linear,!0,!1,!0,u.brightness),0,g.initialFilterFc,9600,0),new be(Xa,0,g.initialFilterQ,200,0),new be(gA(me.switch,!1,!1,!0,u.softPedal),0,g.initialAttenuation,50,0),new be(gA(me.switch,!1,!1,!0,u.softPedal),0,g.initialFilterFc,-2400,0),new be(gA(me.linear,!0,!1,!0,u.balance),0,g.pan,500,0)],Za=[...Yr,...qr],Gn=class{isLooping=!1;sampleData;playbackStep=0;loopStart=0;loopEnd=0;loopLength=0;end=0;cursor=0},Jr=class extends Gn{process(A,e,t){let s=e*this.playbackStep,n=this.sampleData,{loopEnd:a,loopLength:o,loopStart:i,end:r}=this,h=this.cursor;if(this.isLooping)for(let I=0;I<A;I++){h>i&&(h=i+(h-i)%o);let c=h|0,l=c+1;l>=a&&(l-=o);let B=h-c,d=n[l],p=n[c];t[I]=p+(d-p)*B,h+=s}else for(let I=0;I<A;I++){let c=h|0,l=c+1;if(l>=r)return!1;let B=h-c,d=n[l],p=n[c];t[I]=p+(d-p)*B,h+=s}return this.cursor=h,!0}},Kr=class extends Gn{process(A,e,t){let s=e*this.playbackStep,n=this.sampleData,{loopLength:a,loopStart:o,end:i}=this,r=this.cursor;if(this.isLooping)for(let h=0;h<A;h++)r>o&&(r=o+(r-o)%a),t[h]=n[r|0],r+=s;else for(let h=0;h<A;h++){if(r>=i)return!1;t[h]=n[r|0],r+=s}return this.cursor=r,!0}},Vr=class extends Gn{process(A,e,t){let s=e*this.playbackStep,n=this.sampleData,{loopEnd:a,loopLength:o,loopStart:i,end:r}=this,h=this.cursor;if(this.isLooping)for(let I=0;I<A;I++){h>i&&(h=i+(h-i)%o);let c=h|0,l=c+1,B=c+2,d=c+3,p=h-c;l>=a&&(l-=o),B>=a&&(B-=o),d>=a&&(d-=o);let w=n[c],G=n[l],F=n[B],b=n[d],k=(F-w)*.5,O=G-F,C=k+O,Y=C+O+(b-G)*.5,q=C+Y;t[I]=((Y*p-q)*p+k)*p+G,h+=s}else for(let I=0;I<A;I++){let c=h|0,l=c+1,B=c+2,d=c+3,p=h-c;if(d>=r)return!1;let w=n[c],G=n[l],F=n[B],b=n[d],k=(F-w)*.5,O=G-F,C=k+O,Y=C+O+(b-G)*.5,q=C+Y;t[I]=((Y*p-q)*p+k)*p+G,h+=s}return this.cursor=h,!0}},Xr=-2320,Zr=1e3/200,gn=class{oscillators=[new Jr,new Kr,new Vr];wavetable=this.oscillators[Ya.interpolationType];filter;generators=new Int16Array(ot);modulatedGenerators=new Int16Array(ot);modulators=new Array;modulatorValues=new Int16Array(64);modEnv=new Or;volEnv;buffer=new Float32Array(_e);resonanceOffset=0;priority=0;isActive=!1;hasRendered=!1;isInRelease=!1;isHeld=!1;channel=0;velocity=0;midiNote=0;rootKey=0;targetKey=0;pressure=0;gainModifier=1;loopingMode=0;startTime=0;releaseStartTime=1/0;tuningCents=0;tuningRatio=1;currentPan=0;realKey=60;portamentoFromKey=-1;portamentoDuration=0;overridePan=0;pitchOffset=0;reverbSend=1;chorusSend=1;delaySend=1;exclusiveClass=0;overrideReleaseVolEnv=0;constructor(A){this.volEnv=new Hr(A),this.filter=new Rn(A)}computeModulator(A,e,t){let s=this.modulators[t];if(s.transformAmount===0)return this.modulatorValues[t]=0,0;let n=s.primarySource.getValue(A,e,this),a=s.secondarySource.getValue(A,e,this),o=s.transformAmount;s.isEffectModulator&&o<=1e3&&(o*=Zr,o=Math.min(o,1e3));let i=n*a*o;return s.transformType===2&&(i=Math.abs(i)),s.isDefaultResonantModulator&&(this.resonanceOffset=Math.max(0,i/2)),this.modulatorValues[t]=i,i}exclusiveRelease(A,e=Ni){this.overrideReleaseVolEnv=Xr,this.isInRelease=!1,this.releaseVoice(A,e)}releaseVoice(A,e=Li){this.releaseStartTime=A,this.releaseStartTime-this.startTime<e&&(this.releaseStartTime=this.startTime+e)}setup(A,e,t,s,n){this.startTime=A,this.isActive=!0,this.isInRelease=!1,this.hasRendered=!1,this.isHeld=!1,this.releaseStartTime=1/0,this.pressure=0,this.channel=e,this.midiNote=t,this.velocity=s,this.realKey=n,this.overrideReleaseVolEnv=0,this.portamentoDuration=0,this.portamentoFromKey=-1}},Wr=class{sampleData;generators;modulators;exclusiveClass;targetKey;velocity;rootKey;loopStart;loopEnd;playbackStep;loopingMode;constructor(A,e,t,s){let n=A.sample,a=A.generators;this.modulators=A.modulators,this.generators=a,this.rootKey=n.originalKey,a[g.overridingRootKey]>-1&&(this.rootKey=a[g.overridingRootKey]),this.targetKey=e,a[g.keyNum]>-1&&(this.targetKey=a[g.keyNum]),this.velocity=t,a[g.velocity]>-1&&(this.velocity=a[g.velocity]),this.exclusiveClass=a[g.exclusiveClass],this.loopStart=n.loopStart,this.loopEnd=n.loopEnd,this.sampleData=n.getAudioData(),this.playbackStep=n.sampleRate/s*Math.pow(2,n.pitchCorrection/1200),this.loopingMode=a[g.sampleModes]}};function Aa(A,e,t){if(t<A)return 0;let s=(t-A)/(1/e)+.25;return Math.abs(s-~~(s+.5))*4-1}var zr=Math.PI*2;function _r(A,e,t){if(t<A)return 0;let s=t-A;return Math.sin(zr*e*s)}var ta=Math.PI/2,_t=-500,Wa=500,Mn=Wa-_t,za=new Float32Array(Mn+1),_a=new Float32Array(Mn+1);for(let A=_t;A<=Wa;A++){let e=(A-_t)/Mn,t=A-_t;za[t]=Math.cos(ta*e),_a[t]=Math.sin(ta*e)}function $r(A,e,t,s,n,a){if(!A.isInRelease&&e>=A.releaseStartTime&&(A.isInRelease=!0,A.volEnv.startRelease(A),A.modEnv.startRelease(A),A.loopingMode===3&&(A.wavetable.isLooping=!1)),A.hasRendered=!0,!A.isActive)return;let o=A.targetKey,i=A.pitchOffset+A.modulatedGenerators[g.fineTune]+this.octaveTuning[A.midiNote]+this.channelTuningCents,r=A.modulatedGenerators[g.coarseTune],h=this.synthCore.tunings[this.preset.program*128+A.realKey];if(h!==-1&&(o=Math.trunc(h),i+=(h-o)*100),A.portamentoFromKey>-1){let P=Math.min((e-A.startTime)/A.portamentoDuration,1),H=o-A.portamentoFromKey;r-=H*(1-P)}i+=(o-A.rootKey)*A.modulatedGenerators[g.scaleTuning];let I=0,c=0,l=A.modulatedGenerators[g.vibLfoToPitch],B=A.modulatedGenerators[g.vibLfoToVolume],d=A.modulatedGenerators[g.vibLfoToFilterFc];if(l!==0||B!==0||d!==0){let P=A.startTime+ss(A.modulatedGenerators[g.delayVibLFO]),H=nn(A.modulatedGenerators[g.freqVibLFO]),y=Aa(P,H,e);i+=y*(l*this.customControllers[Ce.modulationMultiplier]),c+=-y*B,I+=y*d}let p=A.modulatedGenerators[g.modLfoToPitch],w=A.modulatedGenerators[g.modLfoToVolume],G=A.modulatedGenerators[g.modLfoToFilterFc];if(p!==0||G!==0||w!==0){let P=A.startTime+ss(A.modulatedGenerators[g.delayModLFO]),H=nn(A.modulatedGenerators[g.freqModLFO]),y=Aa(P,H,e);i+=y*(p*this.customControllers[Ce.modulationMultiplier]),c+=-y*w,I+=y*G}this.midiControllers[u.modulationWheel]==0&&this.channelVibrato.depth>0&&(i+=_r(A.startTime+this.channelVibrato.delay,this.channelVibrato.rate,e)*this.channelVibrato.depth);let F=A.modulatedGenerators[g.modEnvToPitch],b=A.modulatedGenerators[g.modEnvToFilterFc];if(b!==0||F!==0){let P=A.modEnv.process(A,e);I+=P*b,i+=P*F}c-=A.resonanceOffset;let k=i+r*100|0;k!==A.tuningCents&&(A.tuningCents=k,A.tuningRatio=Math.pow(2,k/1200));let O=wA(A.modulatedGenerators[g.initialAttenuation]);A.buffer.length<a&&(se(`Buffer size has changed from ${A.buffer.length} to ${a}!
6
- This will cause a memory allocation!`),A.buffer=new Float32Array(a));let C=A.buffer;if(A.loopingMode===2&&!A.isInRelease){A.isActive=A.volEnv.process(a,C,O,c);return}A.isActive=A.wavetable.process(a,A.tuningRatio,C);{let P=A.filter,H=A.modulatedGenerators[g.initialFilterFc];P.initialized?P.currentInitialFc+=(H-P.currentInitialFc)*Rn.smoothingConstant:(P.initialized=!0,P.currentInitialFc=H);let y=P.currentInitialFc+I,R=A.modulatedGenerators[g.initialFilterQ];if(P.currentInitialFc>13499&&y>13499&&R===0)P.currentInitialFc=13500;else{(Math.abs(P.lastTargetCutoff-y)>1||P.resonanceCb!==R)&&(P.lastTargetCutoff=y,P.resonanceCb=R,P.calculateCoefficients(y));let{a0:J,a1:ee,a2:ie,a3:Qe,a4:Ie}=P,{x1:le,x2:re,y1:ce,y2:ye}=P;for(let z=0;z<a;z++){let oe=C[z],Ge=J*oe+ee*le+ie*re-Qe*ce-ye*Ie;re=le,le=oe,ye=ce,ce=Ge,C[z]=Ge}P.x1=le,P.x2=re,P.y1=ce,P.y2=ye}}let Y=A.volEnv.process(a,C,O,c);A.isActive=A.isActive&&Y;let q;A.overridePan?q=A.overridePan:(A.currentPan+=(A.modulatedGenerators[g.pan]-A.currentPan)*this.synthCore.panSmoothingFactor,q=A.currentPan);let x=this.synthCore.masterParameters.masterGain*this.synthCore.midiVolume*A.gainModifier,M=q+500|0,U=za[M]*x*this.synthCore.panLeft,K=_a[M]*x*this.synthCore.panRight;if(this.insertionEnabled){let P=this.synthCore.insertionInputL,H=this.synthCore.insertionInputR;for(let y=0;y<a;y++){let R=C[y];P[y]+=U*R,H[y]+=K*R}return}for(let P=0;P<a;P++){let H=C[P],y=P+n;t[y]+=U*H,s[y]+=K*H}if(!this.synthCore.enableEffects)return;let S=A.modulatedGenerators[g.reverbEffectsSend]*A.reverbSend;if(S>0){let P=this.synthCore.masterParameters.reverbGain*x*(S/1e3),H=this.synthCore.reverbInput;for(let y=0;y<a;y++)H[y]+=P*C[y]}let T=A.modulatedGenerators[g.chorusEffectsSend]*A.chorusSend;if(T>0){let P=this.synthCore.masterParameters.chorusGain*(T/1e3)*x,H=this.synthCore.chorusInput;for(let y=0;y<a;y++)H[y]+=P*C[y]}if(this.synthCore.delayActive){let P=this.midiControllers[u.variationDepth]*A.delaySend;if(P>0){let H=x*this.synthCore.masterParameters.delayGain*((P>>7)/127),y=this.synthCore.delayInput;for(let R=0;R<a;R++)y[R]+=H*C[R]}}}var NA={pitchWheelRange:0,fineTuning:1,coarseTuning:2,modulationDepth:5,resetParameters:16383},Ve={partParameter:1,drumPitch:24,drumPitchFine:25,drumLevel:26,drumPan:28,drumReverb:29,drumChorus:30,drumDelay:31,awe32:127,SF2:120},LA={vibratoRate:8,vibratoDepth:9,vibratoDelay:10,TVFFilterCutoff:32,TVFFilterResonance:33,EGAttackTime:99,EGDecayTime:100,EGReleaseTime:102},Oe=(A,e,t,s)=>{s.length>0&&(s=" "+s),D(`%c${e} for %c${A}%c is now set to %c${t}%c${s}.`,E.info,E.recognized,E.info,E.value,E.info)},Os=A=>{A.channelVibrato.delay===0&&A.channelVibrato.rate===0&&A.channelVibrato.depth===0&&(A.channelVibrato.depth=50,A.channelVibrato.rate=8,A.channelVibrato.delay=.6)};function jr(A){switch(this.midiControllers[u.dataEntryMSB]=A<<7,this.dataEntryState){default:case $e.Idle:break;case $e.NRPCoarse:case $e.NRPFine:{let e=this.midiControllers[u.nonRegisteredParameterMSB]>>7,t=this.midiControllers[u.nonRegisteredParameterLSB]>>7,s=this.midiControllers[u.dataEntryLSB]>>7;if(this.synthCore.masterParameters.drumLock&&e>=Ve.drumPitch&&e<=Ve.drumDelay)return;switch(e){default:{if(A===64)return;D(`%cUnrecognized NRPN for %c${this.channel}%c: %c(0x${t.toString(16).toUpperCase()} 0x${t.toString(16).toUpperCase()})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value);break}case Ve.partParameter:{let n=this.synthCore.masterParameters.nprnParamLock,a=this.synthCore.masterParameters.customVibratoLock||n;switch(t){default:{if(A===64)return;D(`%cUnrecognized NRPN for %c${this.channel}%c: %c(0x${e.toString(16)} 0x${t.toString(16)})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value);break}case LA.vibratoRate:{if(a||A===64)return;Os(this),this.channelVibrato.rate=A/64*8,Oe(this.channel,"Vibrato rate",`${A} = ${this.channelVibrato.rate}`,"Hz");break}case LA.vibratoDepth:{if(a||A===64)return;Os(this),this.channelVibrato.depth=A/2,Oe(this.channel,"Vibrato depth",`${A} = ${this.channelVibrato.depth}`,"cents of detune");break}case LA.vibratoDelay:{if(a||A===64)return;Os(this),this.channelVibrato.delay=A/64/3,Oe(this.channel,"Vibrato delay",`${A} = ${this.channelVibrato.delay}`,"seconds");break}case LA.TVFFilterCutoff:{if(n)return;this.controllerChange(u.brightness,A),Oe(this.channel,"Filter cutoff",A.toString(),"");break}case LA.TVFFilterResonance:{if(n)return;this.controllerChange(u.filterResonance,A),Oe(this.channel,"Filter resonance",A.toString(),"");break}case LA.EGAttackTime:{if(n)return;this.controllerChange(u.attackTime,A),Oe(this.channel,"EG attack time",A.toString(),"");break}case LA.EGDecayTime:{if(n)return;this.controllerChange(u.decayTime,A),Oe(this.channel,"EG decay time",A.toString(),"");break}case LA.EGReleaseTime:{if(n)return;this.controllerChange(u.releaseTime,A),Oe(this.channel,"EG release time",A.toString(),"");break}}break}case Ve.drumPitch:{let n=this.channelSystem==="xg"?(A-64)*100:(A-64)*50;this.drumParams[t].pitch=n,Oe(this.channel,`Drum ${t} pitch`,n,"cents");break}case Ve.drumPitchFine:{let n=A-64;this.drumParams[t].pitch+=n,Oe(this.channel,`Drum ${t} pitch fine`,this.drumParams[t].pitch,"cents");break}case Ve.drumLevel:{this.drumParams[t].gain=A/120,Oe(this.channel,`Drum ${t} level`,A,"");break}case Ve.drumPan:{this.drumParams[t].pan=A,Oe(this.channel,`Drum ${t} pan`,A,"");break}case Ve.drumReverb:{this.drumParams[t].reverbGain=A/127,Oe(this.channel,`Drum ${t} reverb level`,A,"");break}case Ve.drumChorus:{this.drumParams[t].chorusGain=A/127,Oe(this.channel,`Drum ${t} chorus level`,A,"");break}case Ve.drumDelay:{this.drumParams[t].delayGain=A/127,Oe(this.channel,`Drum ${t} delay level`,A,"");break}case Ve.awe32:break;case Ve.SF2:{if(t>100)break;let n=this.customControllers[Ce.sf2NPRNGeneratorLSB],a=(A<<7|s)-8192;this.setGeneratorOffset(n,a);break}}break}case $e.RPCoarse:case $e.RPFine:{let e=this.midiControllers[u.registeredParameterMSB]|this.midiControllers[u.registeredParameterLSB]>>7;switch(e){default:{D(`%cUnrecognized RPN for %c${this.channel}%c: %c(0x${e.toString(16)})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value);break}case NA.pitchWheelRange:{this.midiControllers[ve+Ae.pitchWheelRange]=A<<7,Oe(this.channel,"Pitch wheel range",A.toString(),"semitones");break}case NA.coarseTuning:{let t=A-64;this.setCustomController(Ce.channelTuningSemitones,t),Oe(this.channel,"Coarse tuning",t.toString(),"semitones");break}case NA.fineTuning:{this.setTuning(A-64,!1);break}case NA.modulationDepth:{this.setModulationDepth(A*100);break}case NA.resetParameters:{this.resetParameters();break}}}}}var eo=[g.delayModLFO,g.freqModLFO,g.delayVibLFO,g.freqVibLFO,g.delayModEnv,g.attackModEnv,g.holdModEnv,g.decayModEnv,g.sustainModEnv,g.releaseModEnv,g.delayVolEnv,g.attackVolEnv,g.holdVolEnv,g.decayVolEnv,g.sustainVolEnv,g.releaseVolEnv,g.fineTune,g.modLfoToPitch,g.vibLfoToPitch,g.modEnvToPitch,g.modLfoToVolume,g.initialFilterFc,g.initialFilterQ,g.modLfoToFilterFc,g.modEnvToFilterFc,g.chorusEffectsSend,g.reverbEffectsSend],kA=(A,e,t)=>Math.max(e,Math.min(t,A)),Vt=A=>Math.max(-32768,1200*Math.log2(A/1e3)),Ao=A=>6900+1200*Math.log2(A/440);function to(A,e,t){let s=t<<7|e;s-=8192;let n=eo[A];n||se(`Invalid AWE32 LSB: %c${A}`,E.unrecognized);let a,o,i,r;switch(n){default:break;case g.delayModLFO:case g.delayVibLFO:case g.delayVolEnv:case g.delayModEnv:{a=4*kA(s,0,5900),this.setGeneratorOverride(n,Vt(a));break}case g.attackVolEnv:case g.attackModEnv:{a=kA(s,0,5940),this.setGeneratorOverride(n,Vt(a));break}case g.holdVolEnv:case g.holdModEnv:{a=kA(s,0,8191),this.setGeneratorOverride(n,Vt(a));break}case g.decayModEnv:case g.decayVolEnv:case g.releaseVolEnv:case g.releaseModEnv:{a=4*kA(s,0,5940),this.setGeneratorOverride(n,Vt(a));break}case g.freqVibLFO:case g.freqModLFO:{o=.084*e,this.setGeneratorOverride(n,Ao(o),!0);break}case g.sustainVolEnv:case g.sustainModEnv:{i=e*7.5,this.setGeneratorOverride(n,i);break}case g.fineTune:{this.setGeneratorOverride(n,s,!0);break}case g.modLfoToPitch:case g.vibLfoToPitch:{r=kA(s,-127,127)*9.375,this.setGeneratorOverride(n,r,!0);break}case g.modEnvToPitch:{r=kA(s,-127,127)*9.375,this.setGeneratorOverride(n,r);break}case g.modLfoToVolume:{i=1.875*e,this.setGeneratorOverride(n,i,!0);break}case g.initialFilterFc:{let h=4335+59*e;this.setGeneratorOverride(n,h,!0);break}case g.initialFilterQ:{i=215*(e/127),this.setGeneratorOverride(n,i,!0);break}case g.modLfoToFilterFc:{r=kA(s,-64,63)*56.25,this.setGeneratorOverride(n,r,!0);break}case g.modEnvToFilterFc:{r=kA(s,-64,63)*56.25,this.setGeneratorOverride(n,r);break}case g.chorusEffectsSend:case g.reverbEffectsSend:{this.setGeneratorOverride(n,kA(s,0,255)*(1e3/255));break}}}function so(A){switch(this.midiControllers[u.dataEntryLSB]=A<<7,this.dataEntryState){default:break;case $e.RPCoarse:case $e.RPFine:{switch(this.midiControllers[u.registeredParameterMSB]|this.midiControllers[u.registeredParameterLSB]>>7){default:break;case NA.pitchWheelRange:{if(A===0)break;this.midiControllers[ve+Ae.pitchWheelRange]|=A;let t=(this.midiControllers[ve+Ae.pitchWheelRange]>>7)+A/128;D(`%cChannel ${this.channel} pitch wheel range. Semitones: %c${t}`,E.info,E.value);break}case NA.fineTuning:{let s=this.customControllers[Ce.channelTuning]<<7|A;this.setTuning(s*.01220703125);break}case NA.modulationDepth:{let s=this.customControllers[Ce.modulationMultiplier]*50+A/128*100;this.setModulationDepth(s);break}case 16383:{this.resetParameters();break}}break}case $e.NRPFine:{let e=this.midiControllers[u.nonRegisteredParameterMSB]>>7,t=this.midiControllers[u.nonRegisteredParameterLSB]>>7;if(e===Ve.SF2)return;e===Ve.awe32?to.call(this,t,A,this.midiControllers[u.dataEntryMSB]>>7):D(`%cUnrecognized NRPN LSB for %c${this.channel}%c: %c(0x${t.toString(16).toUpperCase()} 0x${t.toString(16).toUpperCase()})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value)}}}function no(A,e,t=!0){if(A>127)throw new Error("Invalid MIDI Controller.");if(A>=u.modulationWheelLSB&&A<=u.effectControl2LSB&&A!==u.dataEntryLSB){let s=A-32;if(this.lockedControllers[s])return;this.midiControllers[s]=this.midiControllers[s]&16256|e&127,this.computeModulatorsAll(1,s)}if(!this.lockedControllers[A]){switch(this.midiControllers[A]=e<<7,A){case u.omniModeOff:case u.omniModeOn:case u.allNotesOff:{this.stopAllNotes();break}case u.allSoundOff:{this.stopAllNotes(!0);break}case u.polyModeOn:{this.stopAllNotes(!0),this.polyMode=!0;break}case u.monoModeOn:{this.stopAllNotes(!0),this.polyMode=!1;break}case u.bankSelect:{this.setBankMSB(e),this.channel%16===FA&&Fe.isSystemXG(this.channelSystem)&&this.setBankMSB(127);break}case u.bankSelectLSB:{this.setBankLSB(e);break}case u.variationDepth:{this.synthCore.delayActive=!0;break}case u.registeredParameterLSB:{this.dataEntryState=$e.RPFine;break}case u.registeredParameterMSB:{this.dataEntryState=$e.RPCoarse;break}case u.nonRegisteredParameterMSB:{this.customControllers[Ce.sf2NPRNGeneratorLSB]=0,this.dataEntryState=$e.NRPCoarse;break}case u.nonRegisteredParameterLSB:{if(this.midiControllers[u.nonRegisteredParameterMSB]>>7===Ve.SF2)switch(this.customControllers[Ce.sf2NPRNGeneratorLSB]%100!==0&&(this.customControllers[Ce.sf2NPRNGeneratorLSB]=0),e){case 100:{this.customControllers[Ce.sf2NPRNGeneratorLSB]+=100;break}case 101:{this.customControllers[Ce.sf2NPRNGeneratorLSB]+=1e3;break}case 102:{this.customControllers[Ce.sf2NPRNGeneratorLSB]+=1e4;break}default:e<100&&(this.customControllers[Ce.sf2NPRNGeneratorLSB]+=e)}this.dataEntryState=$e.NRPFine;break}case u.dataEntryMSB:{this.dataEntryCoarse(e);break}case u.dataEntryLSB:{this.dataEntryFine(e);break}case u.resetAllControllers:{this.resetControllersRP15Compliant();break}case u.sustainPedal:{if(e<64){let s=0;if(this.voiceCount>0){for(let n of this.synthCore.voices)if(n.channel===this.channel&&n.isActive&&n.isHeld&&(n.isHeld=!1,n.releaseVoice(this.synthCore.currentTime),++s>=this.voiceCount))break}}break}default:{this.computeModulatorsAll(1,A);break}}t&&this.synthCore.callEvent("controllerChange",{channel:this.channel,controllerNumber:A,controllerValue:e})}}var ao=40;function io(A){if(A<1)return 0;{let e=[1,2,4,8,16,32,64,80,96,112,120,124],t=[1,.5,.25,.125,.0625,.03125,.0625,.0625,.0625,.125,.25,1/3],s=[-.16653127382501215,.11863875218299408,.029479047361245264,-.005442312089231738,.1451520875973037,-.005056281449558275,-.005095486882876532,.03334009551111544,-.09361368678020432,.14132569702451822,-.15805565301011382,-.09918856955881927],n=[.028212773333433472,-.3388502064992847,-.15839529890929713,-.12398131766775483,-.2874848552685111,.012254866302537692,.005957797193345771,-.03745899330347374,.12911781869810196,-.15867193224162568,.504406322732748,.3786845131875458],a=[.7218950861255283,.5574536226347168,.47133893237025826,.48597095327079914,.44336276333518854,.6076986311801551,.30851975971827794,.30514889345633955,.3302511933827384,.153822885219165,.1302280559047337,.49865530675491687],o=[-2.2218487496163566,-1.6382721639824072,-1.3010299956639813,-.958607314841775,-.6020599913279624,-.3010299956639812,.31386722036915343,.6232492903979004,.9242792860618817,1.290034611362518,1.4265112613645752,1.9030899869919435],r=[2,4,8,16,32,64,80,96,112,120,124].findLastIndex(I=>I<A)+1,h=(A-e[r])*t[r];return Math.exp(2.302585092994046*(((s[r]*h+n[r])*h+a[r])*h+o[r]))/ao}}function ro(A,e){return io(A)*e}var Xt=(A,e,t)=>Math.max(e,Math.min(t,A));function oo(A,e){if(e<1){this.noteOff(A);return}if(e=Math.min(127,e),this.synthCore.masterParameters.blackMIDIMode&&this.synthCore.voiceCount>200&&e<40||this.synthCore.masterParameters.blackMIDIMode&&e<10||this._isMuted||!this.preset)return;let t=A+this.keyShift+this.customControllers[Ce.channelKeyShift],s=t;if(t>127||t<0)return;let n=this.preset.program,a=this.synthCore.tunings[n*128+t];a>=0&&(s=Math.trunc(a)),this.synthCore.masterParameters.monophonicRetriggerMode&&this.killNote(A);let o=this.synthCore.keyModifierManager.getVelocity(this.channel,t);o>-1&&(e=o);let i=this.synthCore.keyModifierManager.getGain(this.channel,t),r=-1,h=0,I=this.midiControllers[u.portamentoTime]>>7,c=this.midiControllers[u.portamentoControl]>>7;if(!this.drumChannel&&c!==s&&this.midiControllers[u.portamentoOnOff]>=8192&&I>0){if(c>0){let b=Math.abs(s-c);h=ro(I,b),r=c}this.controllerChange(u.portamentoControl,s)}if(!this.polyMode){let b=0;if(this.voiceCount>0){for(let k of this.synthCore.voices)if(k.isActive&&k.channel===this.channel&&(k.exclusiveRelease(this.synthCore.currentTime,0),++b>=this.voiceCount))break}}let l=this.synthCore.getVoices(this.channel,s,e),B=0,d=0,p=0,w=1,G=1,F=1;if(this.randomPan&&(B=Math.round(Math.random()*1e3-500)),this.drumChannel){let b=this.drumParams[s];if(!b.rxNoteOn)return;let k=b.pan;if(k!==64){let O=Math.max(-63,Math.min(k-64+((this.midiControllers[u.pan]>>7)-64),63))||1;B=k===0?Math.round(Math.random()*1e3-500):O/63*500}p=b.pitch,d=b.exclusiveClass,w=b.reverbGain,G=b.chorusGain,F=b.delayGain,i===1&&(i=b.gain)}for(let b of l){let k=this.synthCore.assignVoice();if(k.setup(this.synthCore.currentTime,this.channel,s,e,t),k.wavetable=k.oscillators[this.synthCore.masterParameters.interpolationType],k.generators.set(b.generators),k.exclusiveClass=d||b.exclusiveClass,k.rootKey=b.rootKey,k.loopingMode=b.loopingMode,k.wavetable.sampleData=b.sampleData,k.wavetable.playbackStep=b.playbackStep,k.targetKey=b.targetKey,this.sysExModulators.modulatorList.length>0){k.modulators=[...b.modulators];for(let M of this.sysExModulators.modulatorList){let U=k.modulators.findIndex(K=>Re.isIdentical(K,M.mod));U===-1?k.modulators.push(M.mod):k.modulators[U]=M.mod}}else k.modulators=b.modulators;if(k.modulators.length>k.modulatorValues.length&&(se(`${k.modulators.length} modulators! Increasing modulatorValues table.`),k.modulatorValues=new Int16Array(k.modulators.length)),this.generatorOverridesEnabled)for(let[M,U]of this.generatorOverrides.entries())U!==Ra&&(k.generators[M]=U);if(k.exclusiveClass!==0&&this.polyMode){let M=0;if(this.voiceCount>0){for(let U of this.synthCore.voices)if(U.isActive&&U.channel===this.channel&&U.exclusiveClass===k.exclusiveClass&&U.hasRendered&&(U.exclusiveRelease(this.synthCore.currentTime),++M>=this.voiceCount))break}}this.computeModulators(k),k.volEnv.init(k),k.modEnv.init(k),k.filter.init();let O=k.modulatedGenerators[g.startAddrsOffset]+k.modulatedGenerators[g.startAddrsCoarseOffset]*32768,C=k.modulatedGenerators[g.endAddrOffset]+k.modulatedGenerators[g.endAddrsCoarseOffset]*32768,Y=k.modulatedGenerators[g.startloopAddrsOffset]+k.modulatedGenerators[g.startloopAddrsCoarseOffset]*32768,q=k.modulatedGenerators[g.endloopAddrsOffset]+k.modulatedGenerators[g.endloopAddrsCoarseOffset]*32768,x=b.sampleData.length-1;if(k.wavetable.cursor=Xt(O,0,x),k.wavetable.end=Xt(x+C,0,x),k.wavetable.loopStart=Xt(b.loopStart+Y,0,x),k.wavetable.loopEnd=Xt(b.loopEnd+q,0,x),k.wavetable.loopEnd<k.wavetable.loopStart){let M=k.wavetable.loopStart;k.wavetable.loopStart=k.wavetable.loopEnd,k.wavetable.loopEnd=M}k.wavetable.loopEnd-k.wavetable.loopStart<1&&(k.loopingMode===1||k.loopingMode===3)&&(k.loopingMode=0),k.wavetable.loopLength=k.wavetable.loopEnd-k.wavetable.loopStart,k.wavetable.isLooping=k.loopingMode===1||k.loopingMode===3,k.portamentoFromKey=r,k.portamentoDuration=h,k.overridePan=B,k.gainModifier=i,k.pitchOffset=p,k.reverbSend=w,k.chorusSend=G,k.delaySend=F,k.currentPan=Math.max(-500,Math.min(500,B||k.modulatedGenerators[g.pan]))}this.voiceCount+=l.length,this.sendChannelProperty(),this.synthCore.callEvent("noteOn",{midiNote:A,channel:this.channel,velocity:e})}function ho(A){if(A>127||A<0){se("Received a noteOn for note",A,"Ignoring.");return}let e=A+this.keyShift+this.customControllers[Ce.channelKeyShift];if(this.synthCore.masterParameters.blackMIDIMode&&!this.drumChannel||this.drumChannel&&this.drumParams[e].rxNoteOff){this.killNote(e),this.synthCore.callEvent("noteOff",{midiNote:A,channel:this.channel});return}let t=this.midiControllers[u.sustainPedal]>=8192,s=0;if(this.voiceCount>0){for(let n of this.synthCore.voices)if(n.channel===this.channel&&n.isActive&&n.realKey===e&&!n.isInRelease&&(t?n.isHeld=!0:n.releaseVoice(this.synthCore.currentTime),++s>=this.voiceCount))break}this.synthCore.callEvent("noteOff",{midiNote:A,channel:this.channel})}function go(A){if(this.lockPreset)return;this.patch.program=A;let e=this.synthCore.soundBankManager.getPreset(this.patch,this.channelSystem);!e&&(e=this.synthCore.missingPresetHandler(this.patch,this.channelSystem),!e)||(this.preset=e,e.isAnyDrums!==this.drumChannel&&this.setDrumFlag(e.isAnyDrums),this.resetDrumParams(),this.synthCore.callEvent("programChange",{channel:this.channel,bankLSB:this.preset.bankLSB,bankMSB:this.preset.bankMSB,program:this.preset.program,isGMGSDrum:this.preset.isGMGSDrum}),this.sendChannelProperty())}var Io=class{modulatorList=[];resetModulators(){this.modulatorList=[]}setModulator(A,e,t,s=!1,n=!1){let a=this.getModulatorID(A,e,s,n);t===0&&this.deleteModulator(a);let o=this.modulatorList.find(i=>i.id===a);if(o)o.mod.transformAmount=t;else{let i,r;A>=ve?(i=A-ve,r=!1):(i=A,r=!0);let h=new Re(new cA(i,me.linear,r,s),new cA,e,t,0);this.modulatorList.push({mod:h,id:a})}}getModulatorID(A,e,t,s){return`${A}-${e}-${t}-${s}`}deleteModulator(A){this.modulatorList=this.modulatorList.filter(e=>e.id!==A)}};function co(A,e=-1,t=0){let s=A.modulators,n=A.generators;if(this.generatorOffsetsEnabled){n=new Int16Array(n);for(let r=0;r<n.length;r++)n[r]+=this.generatorOffsets[r]}let a=A.modulatedGenerators,o=this.perNotePitch?this.pitchWheels[A.realKey]:this.midiControllers[Ae.pitchWheel+ve];if(e===-1){a.set(n);for(let r=0;r<s.length;r++){let h=s[r];a[h.destination]=Math.min(32767,Math.max(-32768,a[h.destination]+A.computeModulator(this.midiControllers,o,r)))}for(let r=0;r<a.length;r++){let h=oA[r];h&&(a[r]=Math.min(h.max,Math.max(h.min,a[r])))}return}let i=!!e;for(let r=0;r<s.length;r++){let h=s[r];if(h.primarySource.isCC===i&&h.primarySource.index===t||h.secondarySource.isCC===i&&h.secondarySource.index===t){let I=h.destination,c=n[I];A.computeModulator(this.midiControllers,o,r);for(let B=0;B<s.length;B++)s[B].destination===I&&(c+=A.modulatorValues[B]);let l=oA[I];a[I]=Math.max(l.min,Math.min(c,l.max))}}}var lo=class{midiControllers=new Int16Array($s);pitchWheels=new Int16Array(128).fill(8192);lockedControllers=new Array($s).fill(!1);customControllers=new Float32Array(Ua);octaveTuning=new Int8Array(128);drumParams=[];sysExModulators=new Io;keyShift=0;drumChannel=!1;randomPan=!1;insertionEnabled=!1;cc1=16;cc2=17;drumMap=0;dataEntryState=$e.Idle;patch={bankMSB:0,bankLSB:0,program:0,isGMGSDrum:!1};preset;lockPreset=!1;lockedSystem="gs";channelVibrato={delay:0,depth:0,rate:0};polyMode=!0;voiceCount=0;channel;rxChannel;synthCore;noteOn=oo.bind(this);noteOff=ho.bind(this);programChange=go.bind(this);controllerChange=no.bind(this);resetControllers=Qr.bind(this);resetPreset=fr.bind(this);resetControllersRP15Compliant=ur.bind(this);resetParameters=mr.bind(this);dataEntryFine=so.bind(this);dataEntryCoarse=jr.bind(this);renderVoice=$r.bind(this);perNotePitch=!1;channelTuningCents=0;generatorOffsets=new Int16Array(ot);generatorOffsetsEnabled=!1;generatorOverrides=new Int16Array(ot);generatorOverridesEnabled=!1;computeModulators=co.bind(this);previousVoiceCount=0;constructor(A,e,t){this.synthCore=A,this.preset=e,this.channel=t,this.rxChannel=t,this.resetGeneratorOverrides(),this.resetGeneratorOffsets();for(let s=0;s<128;s++)this.drumParams.push(new js);this.resetDrumParams(),this.resetVibratoParams()}_isMuted=!1;get isMuted(){return this._isMuted}get channelSystem(){return this.lockPreset?this.lockedSystem:this.synthCore.masterParameters.midiSystem}clearVoiceCount(){this.previousVoiceCount=this.voiceCount,this.voiceCount=0}updateVoiceCount(){this.voiceCount!==this.previousVoiceCount&&this.sendChannelProperty()}transposeChannel(A,e=!1){this.drumChannel||(A+=this.synthCore.masterParameters.transposition);let t=Math.trunc(A),s=this.keyShift+this.customControllers[Ce.channelTransposeFine]/100;this.drumChannel&&!e||A===s||(t!==this.keyShift&&this.stopAllNotes(),this.keyShift=t,this.setCustomController(Ce.channelTransposeFine,(A-t)*100),this.sendChannelProperty())}setOctaveTuning(A){if(A.length!==12)throw new Error("Tuning is not the length of 12.");for(let e=0;e<128;e++)this.octaveTuning[e]=A[e%12]}setModulationDepth(A){A=Math.round(A),D(`%cChannel ${this.channel} modulation depth. Cents: %c${A}`,E.info,E.value),this.setCustomController(Ce.modulationMultiplier,A/50)}setTuning(A,e=!0){A=Math.round(A),this.setCustomController(Ce.channelTuning,A),e&&D(`%cFine tuning for %c${this.channel}%c is now set to %c${A}%c cents.`,E.info,E.recognized,E.info,E.value,E.info)}pitchWheel(A,e=-1){if(!this.lockedControllers[ve+Ae.pitchWheel]){if(e===-1)this.perNotePitch=!1,this.midiControllers[ve+Ae.pitchWheel]=A,this.computeModulatorsAll(0,Ae.pitchWheel),this.sendChannelProperty();else{this.perNotePitch||this.pitchWheels.fill(this.midiControllers[ve+Ae.pitchWheel]),this.perNotePitch=!0,this.pitchWheels[e]=A;let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.isActive&&s.channel===this.channel&&s.midiNote===e&&(this.computeModulators(s,0,Ae.polyPressure),++t>=this.voiceCount))break}}this.synthCore.callEvent("pitchWheel",{channel:this.channel,pitch:A,midiNote:e})}}channelPressure(A){this.midiControllers[ve+Ae.channelPressure]=A<<7,this.updateChannelTuning(),this.computeModulatorsAll(0,Ae.channelPressure),this.synthCore.callEvent("channelPressure",{channel:this.channel,pressure:A})}polyPressure(A,e){let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.isActive&&s.channel===this.channel&&s.midiNote===A&&(s.pressure=e,this.computeModulators(s,0,Ae.polyPressure),++t>=this.voiceCount))break}this.synthCore.callEvent("polyPressure",{channel:this.channel,midiNote:A,pressure:e})}setCustomController(A,e){this.customControllers[A]=e,this.updateChannelTuning()}updateChannelTuning(){this.channelTuningCents=this.customControllers[Ce.channelTuning]+this.customControllers[Ce.channelTransposeFine]+this.customControllers[Ce.masterTuning]+this.customControllers[Ce.channelTuningSemitones]*100}setPresetLock(A){this.lockPreset!==A&&(this.lockPreset=A,A&&(this.lockedSystem=this.synthCore.masterParameters.midiSystem))}setDrums(A){if(Fe.isSystemXG(this.channelSystem))if(A)this.setBankMSB(Fe.getDrumBank(this.channelSystem)),this.setBankLSB(0);else{if(this.channel%16===FA)throw new Error(`Cannot disable drums on channel ${this.channel} for XG.`);this.setBankMSB(0),this.setBankLSB(0)}else this.setGSDrums(A);this.setDrumFlag(A),this.programChange(this.patch.program)}setPatch(A){this.setBankMSB(A.bankMSB),this.setBankLSB(A.bankLSB),this.setGSDrums(A.isGMGSDrum),this.programChange(A.program)}setGSDrums(A){A!==this.patch.isGMGSDrum&&(this.setBankLSB(0),this.setBankMSB(0),this.patch.isGMGSDrum=A)}resetGeneratorOverrides(){this.generatorOverrides.fill(Ra),this.generatorOverridesEnabled=!1}setGeneratorOverride(A,e,t=!1){if(this.generatorOverrides[A]=e,this.generatorOverridesEnabled=!0,t){let s=0;if(this.voiceCount>0){for(let n of this.synthCore.voices)if(n.channel===this.channel&&n.isActive&&(n.generators[A]=e,this.computeModulators(n),++s>=this.voiceCount))break}}}resetGeneratorOffsets(){this.generatorOffsets.fill(0),this.generatorOffsetsEnabled=!1}setGeneratorOffset(A,e){this.generatorOffsets[A]=e*oA[A].nrpn,this.generatorOffsetsEnabled=!0;let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.channel===this.channel&&s.isActive&&(this.computeModulators(s),++t>=this.voiceCount))break}}killNote(A,e=-12e3){A+=this.customControllers[Ce.channelKeyShift];let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.channel===this.channel&&s.isActive&&s.realKey===A&&(s.overrideReleaseVolEnv=e,s.isInRelease=!1,s.releaseVoice(this.synthCore.currentTime),++t>=this.voiceCount))break}}stopAllNotes(A=!1){if(A){let e=0;if(this.voiceCount>0){for(let t of this.synthCore.voices)if(t.channel===this.channel&&t.isActive&&(t.isActive=!1,++e>=this.voiceCount))break}this.clearVoiceCount(),this.updateVoiceCount()}else{let e=0;if(this.voiceCount>0){for(let t of this.synthCore.voices)if(t.channel===this.channel&&t.isActive&&(t.releaseVoice(this.synthCore.currentTime),++e>=this.voiceCount))break}}this.synthCore.callEvent("stopAll",{channel:this.channel,force:A})}muteChannel(A){A&&this.stopAllNotes(!0),this._isMuted=A,this.sendChannelProperty(),this.synthCore.callEvent("muteChannel",{channel:this.channel,isMuted:A})}sendChannelProperty(){if(!this.synthCore.enableEventSystem)return;let A={voicesAmount:this.voiceCount,pitchWheel:this.midiControllers[ve+Ae.pitchWheel],pitchWheelRange:this.midiControllers[ve+Ae.pitchWheelRange]/128,isMuted:this.isMuted,transposition:this.keyShift+this.customControllers[Ce.channelTransposeFine]/100,isDrum:this.drumChannel,isEFX:this.insertionEnabled};this.synthCore.callEvent("channelPropertyChange",{channel:this.channel,property:A})}resetDrumParams(){if(!(this.synthCore.masterParameters.drumLock||!this.drumChannel))for(let A=0;A<128;A++){let e=this.drumParams[A];e.pitch=0,e.gain=1,e.exclusiveClass=0,e.pan=64,e.reverbGain=wn[A]/127,e.chorusGain=0,e.delayGain=0,e.rxNoteOn=!0,e.rxNoteOff=!1}}resetVibratoParams(){this.synthCore.masterParameters.customVibratoLock||(this.channelVibrato.rate=0,this.channelVibrato.depth=0,this.channelVibrato.delay=0)}computeModulatorsAll(A,e){let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.channel===this.channel&&s.isActive&&(this.computeModulators(s,A,e),++t>=this.voiceCount))break}}setBankMSB(A){this.lockPreset||(this.patch.bankMSB=A)}setBankLSB(A){this.lockPreset||(this.patch.bankLSB=A)}setDrumFlag(A){this.lockPreset||!this.preset||this.drumChannel!==A&&(A?(this.keyShift=0,this.drumChannel=!0):this.drumChannel=!1,this.synthCore.callEvent("drumChange",{channel:this.channel,isDrumChannel:this.drumChannel}))}},sa=4,He=class{generatorType;generatorValue=0;constructor(A,e,t=!0){if(this.generatorType=A,e===void 0)throw new Error("No value provided.");if(this.generatorValue=Math.round(e),t){let s=oA[A];s!==void 0&&(this.generatorValue=Math.max(s.min,Math.min(s.max,this.generatorValue)))}}write(A){te(A,this.generatorType),te(A,this.generatorValue)}toString(){return`${Object.keys(g).find(A=>g[A]===this.generatorType)}: ${this.generatorValue}`}},Co=4,ls=class{velRange={min:-1,max:127};keyRange={min:-1,max:127};generators=[];modulators=[];get hasKeyRange(){return this.keyRange.min!==-1}get hasVelRange(){return this.velRange.min!==-1}get fineTuning(){let A=this.getGenerator(g.coarseTune,0),e=this.getGenerator(g.fineTune,0);return A*100+e}set fineTuning(A){let e=Math.trunc(A/100),t=A%100;this.setGenerator(g.coarseTune,e),this.setGenerator(g.fineTune,t)}addToGenerator(A,e,t=!0){let s=this.getGenerator(A,oA[A].def);this.setGenerator(A,e+s,t)}setGenerator(A,e,t=!0){switch(A){case g.sampleID:throw new Error("Use setSample()");case g.instrument:throw new Error("Use setInstrument()");case g.velRange:case g.keyRange:throw new Error("Set the range manually")}if(e===null){this.generators=this.generators.filter(n=>n.generatorType!==A);return}let s=this.generators.findIndex(n=>n.generatorType===A);s===-1?this.addGenerators(new He(A,e,t)):this.generators[s]=new He(A,e,t)}addGenerators(...A){for(let e of A)switch(e.generatorType){default:{this.generators.push(e);break}case g.sampleID:case g.instrument:break;case g.velRange:{this.velRange.min=e.generatorValue&127,this.velRange.max=e.generatorValue>>8&127;break}case g.keyRange:this.keyRange.min=e.generatorValue&127,this.keyRange.max=e.generatorValue>>8&127}}addModulators(...A){this.modulators.push(...A)}getGenerator(A,e){return this.generators.find(t=>t.generatorType===A)?.generatorValue??e}copyFrom(A){this.generators=A.generators.map(e=>new He(e.generatorType,e.generatorValue,!1)),this.modulators=A.modulators.map(Re.copyFrom.bind(Re)),this.velRange={...A.velRange},this.keyRange={...A.keyRange}}getWriteGenerators(A){let e=this.generators.filter(t=>t.generatorType!==g.sampleID&&t.generatorType!==g.instrument&&t.generatorType!==g.keyRange&&t.generatorType!==g.velRange);if(!A)throw new Error("No bank provided! ");return this.hasVelRange&&e.unshift(new He(g.velRange,this.velRange.max<<8|Math.max(this.velRange.min,0),!1)),this.hasKeyRange&&e.unshift(new He(g.keyRange,this.keyRange.max<<8|Math.max(this.keyRange.min,0),!1)),e}},$a=class extends ls{},ja=class extends ls{parentPreset;constructor(A,e){super(),this.parentPreset=A,this._instrument=e,this._instrument.linkTo(this.parentPreset)}_instrument;get instrument(){return this._instrument}set instrument(A){this._instrument&&this._instrument.unlinkFrom(this.parentPreset),this._instrument=A,this._instrument.linkTo(this.parentPreset)}getWriteGenerators(A){let e=super.getWriteGenerators(A);if(!A)throw new Error("Instrument ID cannot be determined without the sound bank itself.");let t=A.instruments.indexOf(this.instrument);if(t===-1)throw new Error(`${this.instrument.name} does not exist in ${A.soundBankInfo.name}! Cannot write instrument generator.`);return e.push(new He(g.instrument,t,!1)),e}},ei=class extends ls{parentInstrument;useCount;constructor(A,e){super(),this.parentInstrument=A,this._sample=e,e.linkTo(this.parentInstrument),this.useCount=A.useCount}_sample;get sample(){return this._sample}set sample(A){this._sample&&this._sample.unlinkFrom(this.parentInstrument),this._sample=A,A.linkTo(this.parentInstrument)}getWriteGenerators(A){let e=super.getWriteGenerators(A),t=A.samples.indexOf(this.sample);if(t===-1)throw new Error(`${this.sample.name} does not exist in ${A.soundBankInfo.name}! Cannot write sampleID generator.`);return e.push(new He(g.sampleID,t,!1)),e}},Eo=22,Bo=new Set([g.velRange,g.keyRange,g.instrument,g.sampleID,g.exclusiveClass,g.endOper,g.sampleModes,g.startloopAddrsOffset,g.startloopAddrsCoarseOffset,g.endloopAddrsOffset,g.endloopAddrsCoarseOffset,g.startAddrsOffset,g.startAddrsCoarseOffset,g.endAddrOffset,g.endAddrsCoarseOffset,g.initialAttenuation,g.fineTune,g.coarseTune,g.keyNumToVolEnvHold,g.keyNumToVolEnvDecay,g.keyNumToModEnvHold,g.keyNumToModEnvDecay]),Ft=class{name="";zones=[];globalZone=new $a;linkedTo=[];get useCount(){return this.linkedTo.length}createZone(A){let e=new ei(this,A);return this.zones.push(e),e}linkTo(A){this.linkedTo.push(A);for(let e of this.zones)e.useCount++}unlinkFrom(A){let e=this.linkedTo.indexOf(A);if(e===-1){se(`Cannot unlink ${A.name} from ${this.name}: not linked.`);return}this.linkedTo.splice(e,1);for(let t of this.zones)t.useCount--}deleteUnusedZones(){this.zones=this.zones.filter(A=>{let e=A.useCount>0;return e||A.sample.unlinkFrom(this),e})}delete(){if(this.useCount>0)throw new Error(`Cannot delete an instrument that is used by: ${this.linkedTo.map(A=>A.name).toString()}.`);for(let A of this.zones)A.sample.unlinkFrom(this)}deleteZone(A,e=!1){let t=this.zones[A];return t.useCount-=1,t.useCount<1||e?(t.sample.unlinkFrom(this),this.zones.splice(A,1),!0):!1}globalize(){let A=this.globalZone;for(let s=0;s<58;s++){if(Bo.has(s))continue;s=s;let n={},a=oA[s]?.def||0;n[a]=0;for(let o of this.zones){let i=o.getGenerator(s,void 0);i===void 0?n[a]++:n[i]===void 0?n[i]=1:n[i]++;let r;switch(s){default:continue;case g.decayVolEnv:{r=g.keyNumToVolEnvDecay;break}case g.holdVolEnv:{r=g.keyNumToVolEnvHold;break}case g.decayModEnv:{r=g.keyNumToModEnvDecay;break}case g.holdModEnv:r=g.keyNumToModEnvHold}if(o.getGenerator(r,void 0)!==void 0){n={};break}}if(Object.keys(n).length>0){let o=["0",0];for(let[r,h]of Object.entries(n))h>o[1]&&(o=[r,h]);let i=Number.parseInt(o[0]);i!==a&&A.setGenerator(s,i,!1);for(let r of this.zones){let h=r.getGenerator(s,void 0);h===void 0?i!==a&&r.setGenerator(s,a):h===i&&r.setGenerator(s,null)}}}let t=this.zones[0].modulators.map(s=>Re.copyFrom(s));for(let s of t){let n=!0;for(let a of this.zones){if(!n)continue;a.modulators.find(i=>Re.isIdentical(i,s))||(n=!1)}if(n){A.addModulators(Re.copyFrom(s));for(let a of this.zones){let o=a.modulators.find(i=>Re.isIdentical(i,s));o&&o.transformAmount===s.transformAmount&&a.modulators.splice(a.modulators.indexOf(o),1)}}}}write(A,e){D(`%cWriting ${this.name}...`,E.info),Te(A.pdta,this.name.slice(0,20),20),Te(A.xdta,this.name.slice(20),20),te(A.pdta,e&65535),te(A.xdta,e>>>16)}},Qo=38,Rt=class dA{parentSoundBank;name="";program=0;bankMSB=0;bankLSB=0;isGMGSDrum=!1;zones=[];globalZone;library=0;genre=0;morphology=0;constructor(e,t=new $a){this.parentSoundBank=e,this.globalZone=t}get isXGDrums(){return this.parentSoundBank.isXGBank&&Fe.isXGDrums(this.bankMSB)}get isAnyDrums(){let e=this.parentSoundBank.isXGBank;return this.isGMGSDrum||e&&Fe.isXGDrums(this.bankMSB)}static isInRange(e,t){return t>=e.min&&t<=e.max}static addUniqueModulators(e,t){for(let s of t)e.some(n=>Re.isIdentical(s,n))||e.push(s)}static subtractRanges(e,t){return{min:Math.max(e.min,t.min),max:Math.min(e.max,t.max)}}delete(){for(let e of this.zones)e.instrument?.unlinkFrom(this)}deleteZone(e){this.zones[e]?.instrument?.unlinkFrom(this),this.zones.splice(e,1)}createZone(e){let t=new ja(this,e);return this.zones.push(t),t}preload(e,t){for(let s=e;s<t+1;s++)for(let n=0;n<128;n++)for(let a of this.getVoiceParameters(s,n))a.sample.getAudioData()}matches(e){return CA.matches(this,e)}getVoiceParameters(e,t){let s=new Array;for(let n of this.zones){if(!dA.isInRange(n.hasKeyRange?n.keyRange:this.globalZone.keyRange,e)||!dA.isInRange(n.hasVelRange?n.velRange:this.globalZone.velRange,t))continue;let a=n.instrument;if(!a||a.zones.length===0)continue;let o=new Int16Array(ot);for(let r of this.globalZone.generators)o[r.generatorType]=r.generatorValue;for(let r of n.generators)o[r.generatorType]=r.generatorValue;let i=[...n.modulators];dA.addUniqueModulators(i,this.globalZone.modulators);for(let r of a.zones){if(!dA.isInRange(r.hasKeyRange?r.keyRange:a.globalZone.keyRange,e)||!dA.isInRange(r.hasVelRange?r.velRange:a.globalZone.velRange,t))continue;let h=[...r.modulators];dA.addUniqueModulators(h,a.globalZone.modulators),dA.addUniqueModulators(h,this.parentSoundBank.defaultModulators);for(let c of i){let l=h.findIndex(B=>Re.isIdentical(c,B));l===-1?h.push(c):h[l]=h[l].sumTransform(c)}let I=new Int16Array(_s);for(let c of a.globalZone.generators)I[c.generatorType]=c.generatorValue;for(let c of r.generators)I[c.generatorType]=c.generatorValue;for(let c=0;c<I.length;c++)I[c]=Math.max(-32768,Math.min(32767,I[c]+o[c]));I[g.initialAttenuation]=Math.floor(I[g.initialAttenuation]*.4),s.push({sample:r.sample,generators:I,modulators:h})}}return s}toMIDIString(){return CA.toMIDIString(this)}toString(){return CA.toNamedMIDIString(this)}toFlattenedInstrument(){let e=(h,I)=>{h.push(...I.filter(c=>!h.some(l=>l.generatorType===c.generatorType)))},t=(h,I)=>{h.push(...I.filter(c=>!h.some(l=>Re.isIdentical(c,l))))},s=new Ft;s.name=this.name;let n=[],a=[],o=this.globalZone;n.push(...o.generators),a.push(...o.modulators);let i=o.keyRange,r=o.velRange;for(let h of this.zones){if(!h.instrument)throw new Error("No instrument in a preset zone.");let I=h.keyRange;h.hasKeyRange||(I=i);let c=h.velRange;h.hasVelRange||(c=r);let l=h.generators.map(O=>new He(O.generatorType,O.generatorValue));e(l,n);let B=[...h.modulators];t(B,a);let d=h.instrument,p=d.zones,w=[],G=[],F=d.globalZone;w.push(...F.generators),G.push(...F.modulators);let b=F.keyRange,k=F.velRange;for(let O of p){if(!O.sample)throw new Error("No sample in an instrument zone.");let C=O.keyRange;O.hasKeyRange||(C=b);let Y=O.velRange;if(O.hasVelRange||(Y=k),C=dA.subtractRanges(C,I),Y=dA.subtractRanges(Y,c),C.max<C.min||Y.max<Y.min)continue;let q=O.generators.map(S=>new He(S.generatorType,S.generatorValue));e(q,w);let x=[...O.modulators];t(x,G);let M=[...x];for(let S of B){let T=M.findIndex(P=>Re.isIdentical(S,P));T===-1?M.push(S):M[T]=M[T].sumTransform(S)}let U=q.map(S=>new He(S.generatorType,S.generatorValue));for(let S of l){if(S.generatorType===g.velRange||S.generatorType===g.keyRange||S.generatorType===g.instrument||S.generatorType===g.endOper||S.generatorType===g.sampleModes)continue;let T=q.findIndex(P=>P.generatorType===S.generatorType);if(T===-1){let P=oA[S.generatorType].def+S.generatorValue;U.push(new He(S.generatorType,P))}else{let P=U[T].generatorValue+S.generatorValue;U[T]=new He(S.generatorType,P)}}U=U.filter(S=>S.generatorType!==g.sampleID&&S.generatorType!==g.keyRange&&S.generatorType!==g.velRange&&S.generatorType!==g.endOper&&S.generatorType!==g.instrument&&S.generatorValue!==oA[S.generatorType].def);let K=s.createZone(O.sample);K.keyRange=C,K.velRange=Y,K.keyRange.min===0&&K.keyRange.max===127&&(K.keyRange.min=-1),K.velRange.min===0&&K.velRange.max===127&&(K.velRange.min=-1),K.addGenerators(...U),K.addModulators(...M)}}return s}write(e,t){D(`%cWriting ${this.name}...`,E.info),Te(e.pdta,this.name.slice(0,20),20),Te(e.xdta,this.name.slice(20),20),te(e.pdta,this.program);let s=this.bankMSB;this.isGMGSDrum?s=128:this.bankMSB===0&&(s=this.bankLSB),te(e.pdta,s),e.xdta.currentIndex+=4,te(e.pdta,t&65535),te(e.xdta,t>>16),Be(e.pdta,this.library),Be(e.pdta,this.genre),Be(e.pdta,this.morphology),e.xdta.currentIndex+=12}};function na(A,e){let t=e?A.find(s=>s.isXGDrums):A.find(s=>s.isGMGSDrum);return t||(A.find(s=>s.isAnyDrums)??A[0])}function Ai(A,e,t){if(A.length===0)throw new Error("No presets!");e.isGMGSDrum&&Fe.isSystemXG(t)&&(e={...e,isGMGSDrum:!1,bankLSB:0,bankMSB:Fe.getDrumBank(t)});let{isGMGSDrum:s,bankLSB:n,bankMSB:a,program:o}=e,i=Fe.isSystemXG(t),r=Fe.isXGDrums(a)&&i,h=A.find(l=>l.matches(e));if(h&&(!r||r&&h.isXGDrums))return h;let I=l=>{D(`%cPreset %c${CA.toMIDIString(e)}%c not found. (${t}) Replaced with %c${l.toString()}`,E.warn,E.unrecognized,E.warn,E.value)};if(s){let l=A.find(B=>B.isGMGSDrum&&B.program===o);return l||(l=A.find(B=>B.isAnyDrums&&B.program===o),l)?(I(l),l):(l=na(A,!1),I(l),l)}if(r){let l=A.find(B=>B.program===o&&B.isXGDrums);return l||(l=A.find(B=>B.isAnyDrums&&B.program===o),l)?(I(l),l):(l=na(A,!0),I(l),l)}let c=A.filter(l=>l.program===o&&!l.isAnyDrums);if(c.length===0)return I(A[0]),A[0];if(h=i?c.find(l=>l.bankLSB===n):c.find(l=>l.bankMSB===a),h)return I(h),h;if(n!==64||!i){let l=Math.max(a,n);if(h=c.find(B=>B.bankLSB===l||B.bankMSB===l),h)return I(h),h}return I(c[0]),c[0]}var fo=class extends Rt{constructor(A,e){super(A.parentSoundBank,A.globalZone),this.bankMSB=Fe.addBankOffset(A.bankMSB,e,A.isXGDrums),this.name=A.name,this.bankLSB=A.bankLSB,this.isGMGSDrum=A.isGMGSDrum,this.program=A.program,this.genre=A.genre,this.morphology=A.morphology,this.library=A.library,this.zones=A.zones}},uo=class{soundBankList=[];presetListChangeCallback;selectablePresetList=[];constructor(A){this.presetListChangeCallback=A}_presetList=[];get presetList(){return[...this._presetList]}get priorityOrder(){return this.soundBankList.map(A=>A.id)}set priorityOrder(A){this.soundBankList.sort((e,t)=>A.indexOf(e.id)-A.indexOf(t.id)),this.generatePresetList()}deleteSoundBank(A){if(this.soundBankList.length===0){se("1 soundbank left. Aborting!");return}let e=this.soundBankList.findIndex(t=>t.id===A);if(e===-1)throw new Error(`No sound bank with id "${A}"`);this.soundBankList.splice(e,1),this.generatePresetList()}addSoundBank(A,e,t=0){let s=this.soundBankList.find(n=>n.id===e);s===void 0?this.soundBankList.push({id:e,soundBank:A,bankOffset:t}):(s.soundBank=A,s.bankOffset=t),this.generatePresetList()}getPreset(A,e){if(!(this.soundBankList.length===0||this.selectablePresetList.length===0))return Ai(this.selectablePresetList,A,e)}destroy(){for(let A of this.soundBankList)A.soundBank.destroySoundBank();this.soundBankList=[]}generatePresetList(){let A=new Array,e=new Set;for(let t of this.soundBankList){let s=t.soundBank,n=t.bankOffset;for(let a of s.presets){let o=new fo(a,n);e.has(o.toMIDIString())||(e.add(o.toMIDIString()),A.push(o))}}A.sort(CA.sorter.bind(CA)),this.selectablePresetList=A,this._presetList=A.map(t=>({bankMSB:t.bankMSB,bankLSB:t.bankLSB,program:t.program,isGMGSDrum:t.isGMGSDrum,name:t.name,isAnyDrums:t.isAnyDrums})),this.presetListChangeCallback()}};function mo(A,e){switch(this.masterParameters[A]=e,A){default:break;case"masterPan":{let t=e;t=t/2+.5,this.panLeft=Math.cos(Math.PI/2*t),this.panRight=Math.sin(Math.PI/2*t);break}case"voiceCap":{let t=Math.min(e,1e6);this.masterParameters.voiceCap=t;for(let s=t;s<this.voices.length;s++)this.voices[s].isActive=!1;if(t>this.voices.length){se(`Allocating ${t-this.voices.length} new voices!`);for(let s=this.voices.length;s<t;s++)this.voices.push(new gn(this.sampleRate))}break}case"transposition":{let t=e;this.masterParameters.transposition=0;for(let s of this.midiChannels)s.transposeChannel(t);this.masterParameters.transposition=t}}this.callEvent("masterParameterChange",{parameter:A,value:e})}function po(A){return this.masterParameters[A]}function yo(){return{...this.masterParameters}}function DA(A,e,t,s){D(`%cChannel %c${A}%c ${t} is now set to %c${e} ${s}.`,E.info,E.recognized,E.info,E.value)}function qe(A,e){D(`%cUnrecognized %c${e} %cSysEx: %c${os(A)}`,E.warn,E.recognized,E.warn,E.unrecognized)}function aa(A,e,t){let s=A,n=e<<7|t;return A===127&&e===127&&t===127?-1:s+n*61e-6}function So(A,e=0){switch(A[2]){case 4:{let t;switch(A[3]){case 1:{let s=A[5]<<7|A[4];this.setMIDIVolume(s/16384),D(`%cMaster Volume. Volume: %c${s}`,E.info,E.value);break}case 2:{let n=((A[5]<<7|A[4])-8192)/8192;this.setMasterParameter("masterPan",n),D(`%cMaster Pan. Pan: %c${n}`,E.info,E.value);break}case 3:{let s=(A[5]<<7|A[6])-8192;t=Math.floor(s/81.92),this.setMasterTuning(t),D(`%cMaster Fine Tuning. Cents: %c${t}`,E.info,E.value);break}case 4:{t=(A[5]-64)*100,this.setMasterTuning(t),D(`%cMaster Coarse Tuning. Cents: %c${t}`,E.info,E.value);break}default:D(`%cUnrecognized MIDI Device Control Real-time message: %c${os(A)}`,E.warn,E.unrecognized)}break}case 9:{A[3]===1?(D("%cGM1 system on",E.info),this.resetAllControllers("gm")):A[3]===3?(D("%cGM2 system on",E.info),this.resetAllControllers("gm2")):(D("%cGM system off, defaulting to GS",E.info),this.setMasterParameter("midiSystem","gs"));break}case 8:{let t=4;switch(A[3]){case 1:{let s=A[t++],n=IA(A,16,t);if(t+=16,A.length<384){se(`The Bulk Tuning Dump is too short! (${A.length} bytes, at least 384 are expected)`);return}for(let a=0;a<128;a++)this.tunings[s*128+a]=aa(A[t++],A[t++],A[t++]);D(`%cBulk Tuning Dump %c${n}%c Program: %c${s}`,E.info,E.value,E.info,E.recognized);break}case 2:case 7:{A[3]===7&&t++;let s=A[t++],n=A[t++];for(let a=0;a<n;a++){let o=A[t++];this.tunings[s*128+o]=aa(A[t++],A[t++],A[t++])}D(`%cSingle Note Tuning. Program: %c${s}%c Keys affected: %c${n}`,E.info,E.recognized,E.info,E.recognized);break}case 9:case 8:{let s=new Int8Array(12);if(A[3]===8)for(let n=0;n<12;n++)s[n]=A[7+n]-64;else for(let n=0;n<24;n+=2){let a=(A[7+n]<<7|A[8+n])-8192;s[n/2]=Math.floor(a/81.92)}(A[4]&1)===1&&this.midiChannels[14+e].setOctaveTuning(s),(A[4]>>1&1)===1&&this.midiChannels[15+e].setOctaveTuning(s);for(let n=0;n<7;n++)(A[5]>>n&1)===1&&this.midiChannels[7+n+e].setOctaveTuning(s);for(let n=0;n<7;n++)(A[6]>>n&1)===1&&this.midiChannels[n+e].setOctaveTuning(s);D(`%cMIDI Octave Scale ${A[3]===8?"(1 byte)":"(2 bytes)"} tuning via Tuning: %c${s.join(" ")}`,E.info,E.value);break}default:{qe(A,"MIDI Tuning Standard");break}}break}default:qe(A,"General MIDI")}}var _=(A,e)=>{D(`%cRoland GS ${A}%c is now set to %c${e}%c.`,E.recognized,E.info,E.value,E.info)};function ko(A,e=0){if(A[3]===18)switch(A[2]){case 66:{let t=A[4],s=A[5],n=A[6],a=Math.min(A[7],127);if(t===0&&s===0&&n===127&&a===0){D("%cGS Reset received!",E.info),this.resetAllControllers("gs");return}if(t===64){if(s===0){switch(n){case 0:{let i=((a<<12|A[8]<<8|A[9]<<4|A[10])-1024)/10;this.setMasterTuning(i),_("Master Tune",i);break}case 4:{_("Master Volume",a);break}case 5:{let o=a-64;_("Master Key-Shift",o),this.setMasterTuning(o*100);break}case 6:{_("Master Pan",a),this.setMasterParameter("masterPan",(a-64)/64);break}case 127:{a===0?(D("%cGS Reset received!",E.info),this.resetAllControllers("gs")):a===127&&(D("%cGS system off, switching to GM",E.info),this.resetAllControllers("gm"));break}default:{qe(A,"Roland GS");break}}return}if(s===1){let o=n>=48&&n<=55,i=n>=56&&n<=64,r=n>=80&&n<=90;if(o&&this.masterParameters.reverbLock||i&&this.masterParameters.chorusLock||r&&this.masterParameters.delayLock)return;switch(this.delayActive||=n===64||r,n){default:{D(`%cUnsupported Patch Common parameter: %c${n.toString(16)}`,E.warn,E.unrecognized);break}case 0:{let h=IA(A,16,7);_(`Patch Name for ${n&15}`,h);break}case 48:{this.setReverbMacro(a),_("Reverb Macro",a);break}case 49:{this.reverbProcessor.character=a,_("Reverb Character",a),this.callEvent("effectChange",{effect:"reverb",parameter:"character",value:a});break}case 50:{this.reverbProcessor.preLowpass=a,_("Reverb Pre-LPF",a),this.callEvent("effectChange",{effect:"reverb",parameter:"preLowpass",value:a});break}case 51:{this.reverbProcessor.level=a,_("Reverb Level",a),this.callEvent("effectChange",{effect:"reverb",parameter:"level",value:a});break}case 52:{this.reverbProcessor.time=a,_("Reverb Time",a),this.callEvent("effectChange",{effect:"reverb",parameter:"time",value:a});break}case 53:{this.reverbProcessor.delayFeedback=a,_("Reverb Delay Feedback",a),this.callEvent("effectChange",{effect:"reverb",parameter:"delayFeedback",value:a});break}case 54:break;case 55:{this.reverbProcessor.preDelayTime=a,_("Reverb Predelay Time",a),this.callEvent("effectChange",{effect:"reverb",parameter:"preDelayTime",value:a});break}case 56:{this.setChorusMacro(a),_("Chorus Macro",a);break}case 57:{this.chorusProcessor.preLowpass=a,_("Pre-LPF",a),this.callEvent("effectChange",{effect:"chorus",parameter:"preLowpass",value:a});break}case 58:{this.chorusProcessor.level=a,_("Chorus Level",a),this.callEvent("effectChange",{effect:"chorus",parameter:"level",value:a});break}case 59:{this.chorusProcessor.feedback=a,_("Chorus Feedback",a),this.callEvent("effectChange",{effect:"chorus",parameter:"feedback",value:a});break}case 60:{this.chorusProcessor.delay=a,_("Chorus Delay",a),this.callEvent("effectChange",{effect:"chorus",parameter:"delay",value:a});break}case 61:{this.chorusProcessor.rate=a,_("Chorus Rate",a),this.callEvent("effectChange",{effect:"chorus",parameter:"rate",value:a});break}case 62:{this.chorusProcessor.depth=a,_("Chorus Depth",a),this.callEvent("effectChange",{effect:"chorus",parameter:"depth",value:a});break}case 63:{this.chorusProcessor.sendLevelToReverb=a,_("Chorus Send Level To Reverb",a),this.callEvent("effectChange",{effect:"chorus",parameter:"sendLevelToReverb",value:a});break}case 64:{this.chorusProcessor.sendLevelToDelay=a,_("Chorus Send Level To Delay",a),this.callEvent("effectChange",{effect:"chorus",parameter:"sendLevelToDelay",value:a});break}case 80:{this.setDelayMacro(a),_("Delay Macro",a);break}case 81:{this.delayProcessor.preLowpass=a,_("Delay Pre-LPF",a),this.callEvent("effectChange",{effect:"delay",parameter:"preLowpass",value:a});break}case 82:{this.delayProcessor.timeCenter=a,_("Delay Time Center",a),this.callEvent("effectChange",{effect:"delay",parameter:"timeCenter",value:a});break}case 83:{this.delayProcessor.timeRatioLeft=a,_("Delay Time Ratio Left",a),this.callEvent("effectChange",{effect:"delay",parameter:"timeRatioLeft",value:a});break}case 84:{this.delayProcessor.timeRatioRight=a,_("Delay Time Ratio Right",a),this.callEvent("effectChange",{effect:"delay",parameter:"timeRatioRight",value:a});break}case 85:{this.delayProcessor.levelCenter=a,_("Delay Level Center",a),this.callEvent("effectChange",{effect:"delay",parameter:"levelCenter",value:a});break}case 86:{this.delayProcessor.levelLeft=a,_("Delay Level Left",a),this.callEvent("effectChange",{effect:"delay",parameter:"levelLeft",value:a});break}case 87:{this.delayProcessor.levelRight=a,_("Delay Level Right",a),this.callEvent("effectChange",{effect:"delay",parameter:"levelRight",value:a});break}case 88:{this.delayProcessor.level=a,_("Delay Level",a),this.callEvent("effectChange",{effect:"delay",parameter:"level",value:a});break}case 89:{this.delayProcessor.feedback=a,_("Delay Feedback",a),this.callEvent("effectChange",{effect:"delay",parameter:"feedback",value:a});break}case 90:{this.delayProcessor.sendLevelToReverb=a,_("Delay Send Level To Reverb",a),this.callEvent("effectChange",{effect:"delay",parameter:"sendLevelToReverb",value:a});break}}break}if(s===3){if(this.masterParameters.insertionEffectLock)return;if(n>=3&&n<=25&&(this.insertionParams[n-3]=a),n>=3&&n<=22){this.insertionProcessor.setParameter(n,a),_(`EFX Parameter ${n-2}`,a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}switch(n){default:{qe(A,"Roland GS EFX");return}case 0:{let o=a<<8|A[8],i=this.insertionEffects.get(o);i?(_("EFX Type",o.toString(16)),this.insertionProcessor=i):(this.insertionProcessor=this.insertionFallback,D(`%cUnsupported EFX processor: %c${o.toString(16)}%c, using Thru.`,E.warn,E.unrecognized,E.warn)),this.resetInsertionParams(),this.insertionProcessor.reset(),this.callEvent("effectChange",{effect:"insertion",parameter:0,value:o});return}case 23:{this.insertionProcessor.sendLevelToReverb=a/127*Wt,_("EFX Send Level to Reverb",a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}case 24:{this.insertionProcessor.sendLevelToChorus=a/127*Wt,_("EFX Send Level to Chorus",a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}case 25:{this.insertionProcessor.sendLevelToDelay=a/127*Wt,this.delayActive=!0,_("EFX Send Level to Delay",a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}}}if(s>>4===1){let o=it(s&15)+e,i=this.midiChannels[o];switch(n){default:{qe(A,"Roland GS");return}case 0:{i.controllerChange(u.bankSelect,a),i.programChange(A[8]);break}case 2:{i.rxChannel=a===16?-1:a+e,this.customChannelNumbers||=i.rxChannel!==i.channel,_(`Rx. Channel on ${o}`,i.rxChannel);break}case 19:{i.polyMode=a===1,_(`Mono/poly on ${o}`,i.polyMode?"POLY":"MONO");break}case 20:{_(`Assign mode on ${o}`,a);break}case 21:{i.drumMap=a;let r=a>0;i.setGSDrums(r),_(`Drums on ${o}`,r.toString());return}case 22:{let r=a-64;i.setCustomController(Ce.channelKeyShift,r),_(`Key shift on ${o}`,r);return}case 25:{i.controllerChange(u.mainVolume,a);return}case 28:{let r=a;r===0?(i.randomPan=!0,_(`Random pan on ${o}`,"ON")):(i.randomPan=!1,i.controllerChange(u.pan,r));break}case 31:{i.cc1=a,_("CC1 Controller Number",a);break}case 32:{i.cc2=a,_("CC2 Controller Number",a);break}case 33:{i.controllerChange(u.chorusDepth,a);break}case 34:{i.controllerChange(u.reverbDepth,a);break}case 42:{let h=((a<<7|A[8])-8192)/81.92;i.setTuning(h);break}case 44:{i.controllerChange(u.variationDepth,a);break}case 48:{i.controllerChange(u.vibratoRate,a);break}case 49:{i.controllerChange(u.vibratoDepth,a);break}case 50:{i.controllerChange(u.brightness,a);break}case 51:{i.controllerChange(u.filterResonance,a);break}case 52:{i.controllerChange(u.attackTime,a);break}case 53:{i.controllerChange(u.decayTime,a);break}case 54:{i.controllerChange(u.releaseTime,a);break}case 55:{i.controllerChange(u.vibratoDelay,a);break}case 64:{let r=A.length-9,h=new Int8Array(12);for(let c=0;c<r;c++)h[c]=A[c+7]-64;i.setOctaveTuning(h);let I=a-64;_(`Octave Scale Tuning on ${o}`,h.join(", ")),i.setTuning(I);break}}return}if(s>>4===2){let o=it(s&15)+e,i=this.midiChannels[o],r=a-64,h=r/64,I=a/128,c=(l,B,d=!1)=>{switch(n&15){case 0:{l===ve+Ae.pitchWheel?(i.controllerChange(u.registeredParameterMSB,0),i.controllerChange(u.registeredParameterLSB,0),i.controllerChange(u.dataEntryMSB,Math.floor(r))):(i.sysExModulators.setModulator(l,g.fineTune,r*100,d),DA(o,r,`${B} pitch control`,"semitones"));break}case 1:{i.sysExModulators.setModulator(l,g.initialFilterFc,h*9600,d),DA(o,h*9600,`${B} pitch control`,"cents");break}case 2:{i.sysExModulators.setModulator(l,g.initialAttenuation,h*960,d),DA(o,h*960,`${B} amplitude`,"cB");break}case 4:{i.sysExModulators.setModulator(l,g.vibLfoToPitch,I*600,d),DA(o,I*600,`${B} LFO1 pitch depth`,"cents");break}case 5:{i.sysExModulators.setModulator(l,g.vibLfoToFilterFc,I*2400,d),DA(o,I*2400,`${B} LFO1 filter depth`,"cents");break}case 6:{i.sysExModulators.setModulator(l,g.vibLfoToVolume,h*960,d),DA(o,h*960,`${B} LFO1 amplitude depth`,"cB");break}case 8:{i.sysExModulators.setModulator(l,g.modLfoToPitch,I*600,d),DA(o,I*600,`${B} LFO2 pitch depth`,"cents");break}case 9:{i.sysExModulators.setModulator(l,g.modLfoToFilterFc,I*2400,d),DA(o,I*2400,`${B} LFO2 filter depth`,"cents");break}case 10:{i.sysExModulators.setModulator(l,g.modLfoToVolume,h*960,d),DA(o,h*960,`${B} LFO2 amplitude depth`,"cB");break}}};switch(n&240){default:{qe(A,"Roland GS Patch Parameter Controller");break}case 0:{c(u.modulationWheel,"mod wheel");break}case 16:{c(ve+Ae.pitchWheel,"pitch wheel",!0);break}case 32:{c(ve+Ae.channelPressure,"channel pressure");break}case 48:{c(ve+Ae.polyPressure,"poly pressure");break}case 64:{c(i.cc1,"CC1");break}case 80:c(i.cc2,"CC2")}return}if(s>>4===4){let o=it(s&15)+e,i=this.midiChannels[o];switch(n){default:{qe(A,"Roland GS Patch Part Parameter");break}case 0:case 1:{i.controllerChange(u.bankSelectLSB,a);break}case 34:{if(this.masterParameters.insertionEffectLock)return;let r=a===1;i.insertionEnabled=r,this.insertionActive||=r,_(`Insertion for ${o}`,r?"ON":"OFF"),this.callEvent("effectChange",{effect:"insertion",parameter:r?-1:-2,value:o})}}return}qe(A,"Roland GS Patch Parameter");return}if(t===65){if(this.masterParameters.drumLock)return;let o=(s>>4)+1,i=n;switch(s&15){default:{qe(A,"Roland GS Drum Setup");return}case 0:{let h=IA(A,12,7);_(`Patch Name for MAP${o}`,h);break}case 1:{let h=(a-60)*50;for(let I of this.midiChannels)I.drumMap===o&&(I.drumParams[i].pitch=h);_(`Drum Pitch for MAP${o}, key ${i}`,h);break}case 2:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].gain=a/120);_(`Drum Level for MAP${o}, key ${i}`,a);break}case 3:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].exclusiveClass=a);_(`Drum Assign Group for MAP${o}, key ${i}`,a);break}case 4:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].pan=a);_(`Drum Pan for MAP${o}, key ${i}`,a);break}case 5:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].reverbGain=a/127);_(`Drum Reverb for MAP${o}, key ${i}`,a);break}case 6:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].chorusGain=a/127);_(`Drum Chorus for MAP${o}, key ${i}`,a);break}case 7:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].rxNoteOff=a===1);_(`Drum Note Off for MAP${o}, key ${i}`,a===1);break}case 8:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].rxNoteOn=a===1);_(`Drum Note On for MAP${o}, key ${i}`,a===1);break}case 9:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].delayGain=a/127);_(`Drum Delay for MAP${o}, key ${i}`,a);break}}return}qe(A,"Roland GS");return}case 69:{A[4]===16&&(A[5]===0?this.callEvent("synthDisplay",[...A]):A[5]===1?this.callEvent("synthDisplay",[...A]):qe(A,"Roland GS Display"));return}case 22:if(A[4]===16){this.setMIDIVolume(A[7]/100),D(`%cRoland Master Volume control set to: %c${A[7]}`,E.info,E.value);return}else qe(A,"Roland")}else{qe(A,"Roland");return}}var Ye=(A,e)=>{D(`%cYamaha XG ${A}%c for is now set to %c${e}%c.`,E.recognized,E.info,E.value,E.info)};function Do(A,e=0){if(A[2]===76){let t=A[3],s=A[4],n=A[5],a=A[6];if(t===0&&s===0){switch(n){case 0:{{let i=(((A[6]&15)<<12|(A[7]&15)<<8|(A[8]&15)<<4|A[9]&15)-1024)/10;this.setMasterTuning(i),Ye("Master Tune",i)}break}case 4:{this.setMIDIVolume(a/127),Ye("Master Volume",a);break}case 5:{let o=127-a;this.setMIDIVolume(o/127),Ye("Master Attenuation",a);break}case 6:{let o=a-64;this.setMasterParameter("transposition",o),Ye("Master Transpose",o);break}case 127:case 126:{D("%cXG system on",E.info),this.resetAllControllers("xg");break}}return}if(t===2&&s===1){let o,i=n;i<=21?o="Reverb":i<=35?o="Chorus":o="Variation",D(`%cUnsupported XG ${o} Parameter: %c${i.toString(16)}`,E.warn,E.unrecognized);return}if(t===8){if(!Fe.isSystemXG(this.masterParameters.midiSystem))return;let o=s+e;if(o>=this.midiChannels.length)return;let i=this.midiChannels[o];switch(n){case 1:{i.controllerChange(u.bankSelect,a);break}case 2:{i.controllerChange(u.bankSelectLSB,a);break}case 3:{i.programChange(a);break}case 4:{i.rxChannel=a+e,this.customChannelNumbers||=i.rxChannel!==i.channel,Ye(`Rev. Channel on ${o}`,i.rxChannel);break}case 5:{i.polyMode=a===1,Ye(`Mono/poly on ${o}`,i.polyMode?"POLY":"MONO");break}case 7:{i.setDrums(a!=0);break}case 8:{if(i.drumChannel)break;let r=a-64;i.setCustomController(Ce.channelKeyShift,r),Ye(`Key shift on ${o}`,r);break}case 11:{i.controllerChange(u.mainVolume,a);break}case 14:{let r=a;r===0?(i.randomPan=!0,Ye(`Random Pan for ${o}`,"ON")):i.controllerChange(u.pan,r);break}case 18:{i.controllerChange(u.chorusDepth,a);break}case 19:{i.controllerChange(u.reverbDepth,a);break}case 21:{i.controllerChange(u.vibratoRate,a);break}case 22:{i.controllerChange(u.vibratoDepth,a);break}case 23:{i.controllerChange(u.vibratoDelay,a);break}case 24:{i.controllerChange(u.brightness,a);break}case 25:{i.controllerChange(u.filterResonance,a);break}case 26:{i.controllerChange(u.attackTime,a);break}case 27:{i.controllerChange(u.decayTime,a);break}case 28:{i.controllerChange(u.releaseTime,a);break}default:D(`%cUnsupported Yamaha XG Part Setup: %c${A[5].toString(16).toUpperCase()}%c for channel ${o}`,E.warn,E.unrecognized,E.warn)}return}if(t>>4===3){if(this.masterParameters.drumLock)return;let o=s;switch(n){default:{qe([n],"Yamaha XG Drum Setup");return}case 0:{let i=(a-64)*100;for(let r of this.midiChannels)r.drumChannel&&(r.drumParams[o].pitch=i);Ye(`Drum Pitch, key ${o}`,i);break}case 1:{let i=a-64;for(let r of this.midiChannels)r.drumChannel&&(r.drumParams[o].pitch+=i);Ye(`Drum Pitch Fine, key ${o}`,i);break}case 2:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].gain=a/120);Ye(`Drum Level, key ${o}`,a);break}case 3:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].exclusiveClass=a);Ye(`Drum Alternate Group, key ${o}`,a);break}case 4:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].pan=a);Ye(`Drum Pan, key ${o}`,a);break}case 5:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].reverbGain=a/127);Ye(`Drum Reverb, key ${o}`,a);break}case 6:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].chorusGain=a/127);Ye(`Drum Chorus, key ${o}`,a);break}case 9:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].rxNoteOff=a===1);Ye(`Drum Note Off, key ${o}`,a===1);break}case 10:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].rxNoteOn=a===1);Ye(`Drum Note On, key ${o}`,a===1);break}}return}t===6||t===7?this.callEvent("synthDisplay",[...A]):Fe.isSystemXG(this.masterParameters.midiSystem)&&qe(A,"Yamaha XG")}else qe(A,"Yamaha")}function wo(A,e=0){e+=this.portSelectChannelOffset;let t=A[0];if(!(this.masterParameters.deviceID!==gt&&A[1]!==127&&this.masterParameters.deviceID!==A[1]))switch(t){default:{D(`%cUnknown manufacturer: %c${os(A)}`,E.warn,E.unrecognized);break}case 126:case 127:{So.call(this,A,e);break}case 65:{ko.call(this,A,e);break}case 67:{Do.call(this,A,e);break}case 245:{if(A.length<2)return;for(this.portSelectChannelOffset=(A[1]-1)*16;this.midiChannels.length<=this.portSelectChannelOffset;){D(`%cPort select, channel offset %c${this.portSelectChannelOffset}%c. Creating a new port!`,E.info,E.value,E.info);for(let s=0;s<16;s++)this.createMIDIChannel(!0)}break}}}var ti=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=0;reset(){}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c}=this;for(let l=0;l<r;l++){let B=A[l],d=e[l],p=i+l;t[p]+=B,s[p]+=d;let w=(B+d)*.5;n[l]+=w*h,a[l]+=w*I,o[l]+=w*c}}setParameter(A,e){}},vA=class{static data=[[0,200,200,0,0,.05,.05,315,250,200,250,100,-180,0],[.1,205,205,.1,5,.1,.1,315,250,200,250,110,-180,1],[.2,210,210,.2,10,.15,.15,315,250,200,250,120,-180,2],[.3,215,215,.3,15,.2,.2,315,250,200,250,130,-180,3],[.4,220,220,.4,20,.25,.25,315,250,200,250,140,-180,4],[.5,225,225,.5,25,.3,.3,315,250,200,250,150,-180,5],[.6,230,230,.6,30,.35,.35,315,250,200,250,160,-168,5],[.7,235,235,.7,35,.4,.4,315,250,200,250,170,-168,5],[.8,240,240,.8,40,.45,.45,400,315,250,315,180,-168,5],[.9,245,245,.9,45,.5,.5,400,315,250,315,190,-168,5],[1,250,250,1,50,.55,.55,400,315,250,315,200,-156,5],[1.1,255,255,1.1,55,.6,.6,400,315,250,315,210,-156,5],[1.2,260,260,1.2,60,.65,.65,400,315,250,315,220,-156,5],[1.3,265,265,1.3,65,.7,.7,400,315,250,315,230,-156,5],[1.4,270,270,1.4,70,.75,.75,400,315,250,315,240,-144,5],[1.5,275,275,1.5,75,.8,.8,400,315,250,315,250,-144,5],[1.6,280,280,1.6,80,.85,.85,500,400,315,400,260,-144,5],[1.7,285,285,1.7,85,.9,.9,500,400,315,400,270,-144,5],[1.8,290,290,1.8,90,.95,.95,500,400,315,400,280,-132,5],[1.9,295,295,1.9,95,1,1,500,400,315,400,290,-132,5],[2,300,300,2,100,1.05,1.05,500,400,315,400,300,-132,5],[2.1,305,305,2.1,105,1.1,1.1,500,400,315,400,320,-132,5],[2.2,310,310,2.2,110,1.15,1.15,500,400,315,400,340,-120,5],[2.3,315,315,2.3,115,1.2,1.2,500,400,315,400,360,-120,5],[2.4,320,320,2.4,120,1.25,1.25,630,500,400,500,380,-120,5],[2.5,325,325,2.5,125,1.3,1.3,630,500,400,500,400,-120,5],[2.6,330,330,2.6,130,1.35,1.35,630,500,400,500,420,-108,5],[2.7,335,335,2.7,135,1.4,1.4,630,500,400,500,440,-108,5],[2.8,340,340,2.8,140,1.45,1.45,630,500,400,500,460,-108,5],[2.9,345,345,2.9,145,1.5,1.5,630,500,400,500,480,-108,5],[3,350,350,3,150,1.55,1.55,630,500,400,500,500,-96,6],[3.1,355,355,3.1,155,1.6,1.6,630,500,400,500,520,-96,6],[3.2,360,360,3.2,160,1.65,1.65,800,630,500,630,540,-96,6],[3.3,365,365,3.3,165,1.7,1.7,800,630,500,630,560,-96,6],[3.4,370,370,3.4,170,1.75,1.75,800,630,500,630,580,-84,6],[3.5,375,375,3.5,175,1.8,1.8,800,630,500,630,600,-84,6],[3.6,380,380,3.6,180,1.85,1.85,800,630,500,630,620,-84,6],[3.7,385,385,3.7,185,1.9,1.9,800,630,500,630,640,-84,6],[3.8,390,390,3.8,190,1.95,1.95,800,630,500,630,660,-72,6],[3.9,395,395,3.9,195,2,2,800,630,500,630,680,-72,6],[4,400,400,4,200,2.05,2.05,1e3,800,630,800,700,-72,6],[4.1,405,405,4.1,205,2.1,2.1,1e3,800,630,800,720,-72,6],[4.2,410,410,4.2,210,2.15,2.15,1e3,800,630,800,740,-60,6],[4.3,415,415,4.3,215,2.2,2.2,1e3,800,630,800,760,-60,6],[4.4,420,420,4.4,220,2.25,2.25,1e3,800,630,800,780,-60,6],[4.5,425,425,4.5,225,2.3,2.3,1e3,800,630,800,800,-60,6],[4.6,430,430,4.6,230,2.35,2.35,1e3,800,630,800,820,-48,6],[4.7,435,435,4.7,235,2.4,2.4,1e3,800,630,800,840,-48,6],[4.8,440,440,4.8,240,2.45,2.45,1250,1e3,800,1e3,860,-48,9],[4.9,445,445,4.9,245,2.5,2.5,1250,1e3,800,1e3,880,-48,9],[5,450,450,5,250,2.55,2.55,1250,1e3,800,1e3,900,-36,9],[5.5,455,455,5.5,255,2.6,2.6,1250,1e3,800,1e3,920,-36,9],[6,460,460,6,260,2.65,2.65,1250,1e3,800,1e3,940,-36,9],[6.5,465,465,6.5,265,2.7,2.7,1250,1e3,800,1e3,960,-36,9],[7,470,470,7,270,2.75,2.75,1250,1e3,800,1e3,980,-24,9],[7.5,475,475,7.5,275,2.8,2.8,1250,1e3,800,1e3,1e3,-24,9],[8,480,480,8,280,2.85,2.85,1600,1250,1e3,1250,1100,-24,9],[8.5,485,485,8.5,285,2.9,2.9,1600,1250,1e3,1250,1200,-24,9],[9,490,490,9,290,2.95,2.95,1600,1250,1e3,1250,1300,-12,9],[9.5,495,495,9.5,295,3,3,1600,1250,1e3,1250,1400,-12,9],[10,500,500,10,300,3.05,3.05,1600,1250,1e3,1250,1500,-12,9],[11,505,505,11,305,3.1,3.1,1600,1250,1e3,1250,1600,-12,9],[12,510,510,12,310,3.15,3.15,1600,1250,1e3,1250,1700,0,9],[13,515,515,13,315,3.2,3.2,1600,1250,1e3,1250,1800,0,9],[14,520,520,14,320,3.25,3.25,2e3,1600,1250,1600,1900,0,12],[15,525,525,15,325,3.3,3.3,2e3,1600,1250,1600,2e3,0,12],[16,530,530,16,330,3.35,3.35,2e3,1600,1250,1600,2100,12,12],[17,535,535,17,335,3.4,3.4,2e3,1600,1250,1600,2200,12,12],[18,540,540,18,340,3.45,3.45,2e3,1600,1250,1600,2300,12,12],[19,545,545,19,345,3.5,3.5,2e3,1600,1250,1600,2400,12,12],[20,550,550,20,350,3.55,3.55,2e3,1600,1250,1600,2500,24,12],[21,560,555,21,355,3.6,3.6,2e3,1600,1250,1600,2600,24,12],[22,570,560,22,360,3.65,3.65,2500,2e3,1600,2e3,2700,24,12],[23,580,565,23,365,3.7,3.7,2500,2e3,1600,2e3,2800,24,12],[24,590,570,24,370,3.75,3.75,2500,2e3,1600,2e3,2900,36,12],[25,600,575,25,375,3.8,3.8,2500,2e3,1600,2e3,3e3,36,12],[26,610,580,26,380,3.85,3.85,2500,2e3,1600,2e3,3100,36,12],[27,620,585,27,385,3.9,3.9,2500,2e3,1600,2e3,3200,36,12],[28,630,590,28,390,3.95,3.95,2500,2e3,1600,2e3,3300,48,12],[29,640,595,29,395,4,4,2500,2e3,1600,2e3,3400,48,12],[30,650,600,30,400,4.05,4.05,3150,2500,2e3,2500,3500,48,10],[31,660,610,31,405,4.1,4.1,3150,2500,2e3,2500,3600,48,10],[32,670,620,32,410,4.15,4.15,3150,2500,2e3,2500,3700,60,10],[33,680,630,33,415,4.2,4.2,3150,2500,2e3,2500,3800,60,10],[34,690,640,34,420,4.25,4.25,3150,2500,2e3,2500,3900,60,10],[35,700,650,35,425,4.3,4.3,3150,2500,2e3,2500,4e3,60,10],[36,710,660,36,430,4.35,4.35,3150,2500,2e3,2500,4100,72,10],[37,720,670,37,435,4.4,4.4,3150,2500,2e3,2500,4200,72,10],[38,730,680,38,440,4.45,4.45,4e3,3150,2500,3150,4300,72,11],[39,740,690,39,445,4.5,4.5,4e3,3150,2500,3150,4400,72,11],[40,750,700,40,450,4.55,4.55,4e3,3150,2500,3150,4500,84,11],[41,760,710,50,455,4.6,4.6,4e3,3150,2500,3150,4600,84,11],[42,770,720,60,460,4.65,4.65,4e3,3150,2500,3150,4700,84,11],[43,780,730,70,465,4.7,4.7,4e3,3150,2500,3150,4800,84,11],[44,790,740,80,470,4.75,4.75,4e3,3150,2500,3150,4900,96,11],[45,800,750,90,475,4.8,4.8,4e3,3150,2500,3150,5e3,96,11],[46,810,760,100,480,4.85,4.85,5e3,4e3,3150,4e3,5100,96,12],[47,820,770,110,485,4.9,4.9,5e3,4e3,3150,4e3,5200,96,12],[48,830,780,120,490,4.95,4.95,5e3,4e3,3150,4e3,5300,108,12],[49,840,790,130,495,5,5,5e3,4e3,3150,4e3,5400,108,12],[50,850,800,140,500,5.1,5.05,5e3,4e3,3150,4e3,5500,108,12],[52,860,810,150,505,5.2,5.1,5e3,4e3,3150,4e3,5600,108,12],[54,870,820,160,510,5.3,5.15,5e3,4e3,3150,4e3,5700,120,12],[56,880,830,170,515,5.4,5.2,5e3,4e3,3150,4e3,5800,120,12],[58,890,840,180,520,5.5,5.25,6300,5e3,4e3,5e3,5900,120,13],[60,900,850,190,525,5.6,5.3,6300,5e3,4e3,5e3,6e3,120,13],[62,910,860,200,530,5.7,5.35,6300,5e3,4e3,5e3,6100,132,13],[64,920,870,210,535,5.8,5.4,6300,5e3,4e3,5e3,6200,132,13],[66,930,880,220,540,5.9,5.45,6300,5e3,4e3,5e3,6300,132,13],[68,940,890,230,545,6,5.5,6300,5e3,4e3,5e3,6400,132,13],[70,950,900,240,550,6.1,5.55,6300,5e3,4e3,5e3,6500,144,13],[72,960,910,250,555,6.2,5.6,6300,5e3,4e3,5e3,6600,144,13],[74,970,920,260,560,6.3,5.65,8e3,6300,5e3,6300,6700,144,14],[76,980,930,270,565,6.4,5.7,8e3,6300,5e3,6300,6800,144,14],[78,990,940,280,570,6.5,5.75,8e3,6300,5e3,6300,6900,156,14],[80,1e3,950,290,575,6.6,5.8,8e3,6300,5e3,6300,7e3,156,14],[82,1e3,960,300,580,6.7,5.85,8e3,6300,5e3,6300,7100,156,14],[84,1e3,970,320,585,6.8,5.9,8e3,6300,5e3,6300,7200,156,14],[86,1e3,980,340,590,6.9,5.95,8e3,6300,5e3,6300,7300,168,14],[88,1e3,990,360,595,7,6,8e3,6300,5e3,6300,7400,168,14],[90,1e3,1e3,380,600,7.5,6.05,13500,8e3,6300,13500,7500,168,15],[92,1e3,1e3,400,605,8,6.1,13500,8e3,6300,13500,7600,168,15],[94,1e3,1e3,420,610,8.5,6.15,13500,8e3,6300,13500,7700,-180,15],[96,1e3,1e3,440,615,9,6.2,13500,8e3,6300,13500,7800,-180,15],[98,1e3,1e3,460,620,9.5,6.25,13500,8e3,6300,13500,7900,-180,15],[100,1e3,1e3,480,625,10,6.3,13500,8e3,6300,13500,8e3,-180,15],[100,1e3,1e3,500,630,10,6.35,13500,8e3,6300,13500,8e3,-180,15],[100,1e3,1e3,500,635,10,6.4,13500,8e3,6300,13500,8e3,-180,15]];static preDelayTime(A){return this.data[A][0]}static delayTime1(A){return this.data[A][1]}static delayTime2(A){return this.data[A][2]}static delayTime3(A){return this.data[A][3]}static delayTime4(A){return this.data[A][4]}static rate1(A){return this.data[A][5]}static rate2(A){return this.data[A][6]}static hfDamp(A){return this.data[A][7]}static cutoffFreq(A){return this.data[A][8]}static eqFreq(A){return this.data[A][9]}static lpf(A){return this.data[A][10]}static manual(A){return this.data[A][11]}static azimuth(A){return this.data[A][12]}static accl(A){return this.data[A][13]}},ia=Math.PI/2,$t=-64,si=63,Ln=si-$t,is=new Float32Array(Ln+1),rs=new Float32Array(Ln+1);for(let A=$t;A<=si;A++){let e=(A-$t)/Ln,t=A-$t;is[t]=Math.cos(ia*e),rs[t]=Math.sin(ia*e)}function we(A){A.x1=A.x2=A.y1=A.y2=0}var je={b0:1,b1:0,b2:0,a0:1,a1:0,a2:0};function XA(A,e,t,s,n){let a=e.b0*A+e.b1*s.x1+e.b2*s.x2-e.a1*s.y1-e.a2*s.y2;s.x2=s.x1,s.x1=A,s.y2=s.y1,s.y1=a;let o=t.b0*a+t.b1*n.x1+t.b2*n.x2-t.a1*n.y1-t.a2*n.y2;return n.x2=n.x1,n.x1=a,n.y2=n.y1,n.y1=o,o}function QA(A,e,t){let s=e.b0*A+e.b1*t.x1+e.b2*t.x2-e.a1*t.y1-e.a2*t.y2;return t.x2=t.x1,t.x1=A,t.y2=t.y1,t.y1=s,s}function UA(A,e,t,s,n){let a=Math.pow(10,e/40),o=2*Math.PI*t/s,i=Math.cos(o),I=Math.sin(o)/2*Math.sqrt((a+1/a)*(1/1-1)+2),c,l,B,d,p,w;n?(c=a*(a+1-(a-1)*i+2*Math.sqrt(a)*I),l=2*a*(a-1-(a+1)*i),B=a*(a+1-(a-1)*i-2*Math.sqrt(a)*I),d=a+1+(a-1)*i+2*Math.sqrt(a)*I,p=-2*(a-1+(a+1)*i),w=a+1+(a-1)*i-2*Math.sqrt(a)*I):(c=a*(a+1+(a-1)*i+2*Math.sqrt(a)*I),l=-2*a*(a-1+(a+1)*i),B=a*(a+1+(a-1)*i-2*Math.sqrt(a)*I),d=a+1-(a-1)*i+2*Math.sqrt(a)*I,p=2*(a-1-(a+1)*i),w=a+1-(a-1)*i-2*Math.sqrt(a)*I),A.b0=c/d,A.b1=l/d,A.b2=B/d,A.a0=1,A.a1=p/d,A.a2=w/d}var Ne={x1:0,x2:0,y1:0,y2:0},bo=class{type=256;sendLevelToReverb=0;sendLevelToChorus=0;sendLevelToDelay=0;sampleRate;level=1;lowFreq=400;lowGain=5;hiFreq=8e3;hiGain=-12;m1Freq=1600;m1Q=.5;m1Gain=8;m2Freq=1e3;m2Q=.5;m2Gain=-8;lowCoeffs={...je};m1Coeffs={...je};m2Coeffs={...je};hiCoeffs={...je};lowStateL={...Ne};lowStateR={...Ne};m1StateL={...Ne};m1StateR={...Ne};m2StateL={...Ne};m2StateR={...Ne};hiStateL={...Ne};hiStateR={...Ne};constructor(A){this.sampleRate=A,this.reset(),this.updateCoefficients()}reset(){this.level=1,this.lowFreq=400,this.lowGain=5,this.hiGain=-12,this.hiFreq=8e3,this.m1Freq=1600,this.m1Q=.5,this.m1Gain=8,this.m2Freq=1e3,this.m2Q=.5,this.m2Gain=-8,we(this.lowStateL),we(this.lowStateR),we(this.m1StateL),we(this.m1StateR),we(this.m2StateL),we(this.m2StateR),we(this.hiStateL),we(this.hiStateR),this.updateCoefficients()}setParameter(A,e){switch(A){default:break;case 3:{this.lowFreq=e===1?400:200;break}case 4:{this.lowGain=e-64;break}case 5:{this.hiFreq=e===1?8e3:4e3;break}case 6:{this.hiGain=e-64;break}case 7:{this.m1Freq=vA.eqFreq(e);break}case 8:{this.m1Q=[.5,1,2,4,9][e]||1;break}case 9:{this.m1Gain=e-64;break}case 10:{this.m2Freq=vA.eqFreq(e);break}case 11:{this.m2Q=[.5,1,2,4,9][e]||1;break}case 12:{this.m2Gain=e-64;break}case 22:{this.level=e/127;break}}this.updateCoefficients()}process(A,e,t,s,n,a,o,i,r){let{level:h,sendLevelToChorus:I,sendLevelToDelay:c,sendLevelToReverb:l,lowCoeffs:B,lowStateL:d,lowStateR:p,m1Coeffs:w,m1StateL:G,m1StateR:F,m2StateL:b,m2StateR:k,m2Coeffs:O,hiCoeffs:C,hiStateL:Y,hiStateR:q}=this;for(let x=0;x<r;x++){let M=A[x],U=e[x];M=QA(M,B,d),U=QA(U,B,p),M=QA(M,w,G),U=QA(U,w,F),M=QA(M,O,b),U=QA(U,O,k),M=QA(M,C,Y),U=QA(U,C,q);let K=i+x;t[K]+=M*h,s[K]+=U*h;let S=.5*(M+U);n[x]+=S*l,a[x]+=S*I,o[x]+=S*c}}updateCoefficients(){vo(this.lowCoeffs,this.lowFreq,this.lowGain/2,this.sampleRate),ra(this.m1Coeffs,this.m1Freq,this.m1Gain,this.m1Q,this.sampleRate),ra(this.m2Coeffs,this.m2Freq,this.m2Gain,this.m2Q,this.sampleRate),Fo(this.hiCoeffs,this.hiFreq,this.hiGain/2,this.sampleRate)}},ni=1;function ra(A,e,t,s,n){let a=Math.pow(10,t/40),o=2*Math.PI*e/n,i=Math.cos(o),h=Math.sin(o)/(2*s),I=1+h*a,c=-2*i,l=1-h*a,B=1+h/a,d=-2*i,p=1-h/a;A.a0=1,A.a1=d/B,A.a2=p/B,A.b0=I/B,A.b1=c/B,A.b2=l/B}function vo(A,e,t,s){let n=Math.pow(10,t/40),a=2*Math.PI*e/s,o=Math.cos(a),r=Math.sin(a)/2*Math.sqrt((n+1/n)*(1/ni-1)+2),h=n*(n+1-(n-1)*o+2*Math.sqrt(n)*r),I=2*n*(n-1-(n+1)*o),c=n*(n+1-(n-1)*o-2*Math.sqrt(n)*r),l=n+1+(n-1)*o+2*Math.sqrt(n)*r,B=-2*(n-1+(n+1)*o),d=n+1+(n-1)*o-2*Math.sqrt(n)*r;A.a0=1,A.a1=B/l,A.a2=d/l,A.b0=h/l,A.b1=I/l,A.b2=c/l}function Fo(A,e,t,s){let n=Math.pow(10,t/40),a=2*Math.PI*e/s,o=Math.cos(a),r=Math.sin(a)/2*Math.sqrt((n+1/n)*(1/ni-1)+2),h=n*(n+1+(n-1)*o+2*Math.sqrt(n)*r),I=-2*n*(n-1+(n+1)*o),c=n*(n+1+(n-1)*o-2*Math.sqrt(n)*r),l=n+1-(n-1)*o+2*Math.sqrt(n)*r,B=2*(n-1-(n+1)*o),d=n+1-(n-1)*o-2*Math.sqrt(n)*r;A.a0=1,A.a1=B/l,A.a2=d/l,A.b0=h/l,A.b1=I/l,A.b2=c/l}var st=8,Ys=128,oa=4,qs=600,Ro=.9,ha=.35,ai=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=288;manual=620;rate=.85;depth=64/Ys;reso=16/127;mix=1;lowGain=0;hiGain=0;prevInL;prevOutL;prevInR;prevOutR;lowShelfCoef={...je};highShelfCoef={...je};manualOffset=qs;lowShelfStateL={x1:0,x2:0,y1:0,y2:0};lowShelfStateR={x1:0,x2:0,y1:0,y2:0};highShelfStateL={x1:0,x2:0,y1:0,y2:0};highShelfStateR={x1:0,x2:0,y1:0,y2:0};prevL=0;prevR=0;level=104/127;phase=ha;sampleRate;constructor(A){this.sampleRate=A,this.prevInL=new Float32Array(st),this.prevOutL=new Float32Array(st),this.prevInR=new Float32Array(st),this.prevOutR=new Float32Array(st),this.reset()}reset(){this.phase=ha,this.setManual(620),this.rate=.85,this.depth=64/Ys,this.reso=16/127,this.mix=1,this.lowGain=0,this.hiGain=0,this.level=104/127,we(this.highShelfStateL),we(this.highShelfStateR),we(this.lowShelfStateL),we(this.lowShelfStateR),this.updateShelves(),this.clearAllPass()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,manual:B,manualOffset:d,mix:p,lowShelfCoef:w,lowShelfStateR:G,lowShelfStateL:F,highShelfCoef:b,highShelfStateL:k,highShelfStateR:O,prevInL:C,prevInR:Y,prevOutL:q,prevOutR:x,sampleRate:M,depth:U}=this,{prevL:K,prevR:S,phase:T}=this,P=this.rate/this.sampleRate,H=this.reso*Ro;for(let y=0;y<r;y++){let R=XA(A[y],w,b,F,k),J=XA(e[y],w,b,G,O),ee=2*Math.abs(T-.5);(T+=P)>=1&&(T-=1);let ie=1-U*ee,Qe=d+B*ie,Ie=Math.tan(Math.PI*Qe/M),le=Math.max(-.9999,Math.min(.9999,(1-Ie)/(1+Ie))),re=R+H*K,ce=J+H*S;for(let Ee=0;Ee<st;Ee++){let Ue=-le*re+C[Ee]+le*q[Ee];C[Ee]=re,q[Ee]=Ue,re=Ue;let Je=-le*ce+Y[Ee]+le*x[Ee];Y[Ee]=ce,x[Ee]=Je,ce=Je}K=re,S=ce;let ye=(R+re*p)*l,z=(J+ce*p)*l,oe=i+y;t[oe]+=ye,s[oe]+=z;let Ge=(ye+z)*.5;n[y]+=Ge*h,a[y]+=Ge*I,o[y]+=Ge*c}this.phase=T,this.prevL=K,this.prevR=S}setParameter(A,e){switch(A){default:break;case 3:{this.setManual(vA.manual(e));break}case 4:{this.rate=vA.rate1(e);break}case 5:{this.depth=e/Ys;break}case 6:{this.reso=e/127;break}case 7:{this.mix=e/127;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}setManual(A){A>1e3?(this.manualOffset=qs*1.5*oa,this.manual=A):(this.manualOffset=qs,this.manual=A*oa)}clearAllPass(){this.prevR=0,this.prevL=0;for(let A=0;A<st;A++)this.prevInL[A]=0,this.prevOutL[A]=0,this.prevInR[A]=0,this.prevOutR[A]=0}updateShelves(){UA(this.lowShelfCoef,this.lowGain,200,this.sampleRate,!0),UA(this.highShelfCoef,this.hiGain,4e3,this.sampleRate,!1)}},ga=Math.PI*2,Go=.935,Mo=2,Lo=.01,Ia=127,No=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=294;modWave=1;modRate=3.05;modDepth=96;lowGain=0;hiGain=0;level=Ia/127;currentPan=0;phase=0;lsCoeffs={...je};hsCoeffs={...je};lsStateR={...Ne};lsStateL={...Ne};hsStateR={...Ne};hsStateL={...Ne};sampleRate;constructor(A){this.sampleRate=A,this.reset()}reset(){this.modWave=1,this.modRate=3.05,this.modDepth=96,this.lowGain=0,this.hiGain=0,this.level=Ia/127,this.currentPan=0,this.phase=0,we(this.hsStateR),we(this.hsStateL),we(this.lsStateR),we(this.lsStateL),this.updateShelves()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,lsCoeffs:B,lsStateL:d,lsStateR:p,hsCoeffs:w,hsStateR:G,hsStateL:F,modWave:b}=this,k=Math.pow(this.modDepth/127,Mo),O=2/(1+k)*Go,C=this.modRate/this.sampleRate,{phase:Y,currentPan:q}=this;for(let x=0;x<r;x++){let M=XA(A[x],B,w,d,F),U=XA(e[x],B,w,p,G),K;switch(b){default:{K=1-4*Math.abs(Y-.5);break}case 1:{K=Y>.5?-1:-Math.cos((Y-.75)*ga);break}case 2:{K=Math.sin(ga*Y);break}case 3:{K=1-2*Y;break}case 4:{K=2*Y-1;break}}(Y+=C)>=1&&(Y-=1),q+=(K-q)*Lo;let S=q*k,T=(1-S)*.5*O,P=(1+S)*.5*O,H=M*l*T,y=U*l*P,R=i+x;t[R]+=H,s[R]+=y;let J=(H+y)*.5;n[x]+=J*h,a[x]+=J*I,o[x]+=J*c}this.currentPan=q,this.phase=Y}setParameter(A,e){switch(A){default:break;case 3:{this.modWave=e;break}case 4:{this.modRate=vA.rate1(e);break}case 5:{this.modDepth=e;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}updateShelves(){UA(this.lsCoeffs,this.lowGain,200,this.sampleRate,!0),UA(this.hsCoeffs,this.hiGain,4e3,this.sampleRate,!1)}},ca=96,To=.1,Uo=.1,Po=27,xo=28,Ho=-28,Oo=400,Yo=.62,qo=.005,ii=5,la=ii*.5,ri=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=289;filType=1;sens=0;manual=68;peak=62;rate=2.05;depth=72;polarity=1;pan=0;lowGain=0;hiGain=0;level=ca/127;coeffs={...je};state={...Ne};hpCoeffs={...je};hpState={...Ne};phase=0;lsCoeffs={...je};hsCoeffs={...je};lsState={...Ne};hsState={...Ne};sampleRate;lastFc=this.manual;attackCoeff;releaseCoeff;envelope=0;constructor(A){this.sampleRate=A,this.attackCoeff=Math.exp(-1/(To*A)),this.releaseCoeff=Math.exp(-1/(Uo*A)),this.reset()}reset(){this.filType=1,this.sens=0,this.setManual(68),this.peak=62,this.rate=2.05,this.depth=72,this.polarity=1,this.lowGain=0,this.hiGain=0,this.pan=0,this.level=ca/127,this.phase=.2,this.lastFc=this.manual,we(this.hsState),we(this.lsState),we(this.state),we(this.hpState),this.updateShelves()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,lsCoeffs:B,lsState:d,hsCoeffs:p,hsState:w,coeffs:G,state:F,sampleRate:b,filType:k,manual:O,pan:C,attackCoeff:Y,releaseCoeff:q,hpState:x,hpCoeffs:M}=this,{phase:U,lastFc:K,envelope:S}=this,T=this.rate/this.sampleRate,P=Math.pow(10,this.peak/127*xo/20),H=Math.pow(10,this.peak/127*Ho/20),y=this.polarity===0?-1:ii,R=this.depth/127*y,J=this.sens/127,ee=C+64|0,ie=is[ee],Qe=rs[ee];for(let Ie=0;Ie<r;Ie++){let le=XA((A[Ie]+e[Ie])*.5,B,p,d,w),re=Math.abs(le);S=re>S?Y*S+(1-Y)*re:q*S+(1-q)*re;let ce=2*Math.abs(U-.5)*R;(U+=T)>=1&&(U-=1);let ye=ce>=la||y<0?1:Math.sin(ce*Math.PI/(2*la)),z=O*(1+J*S*Po),oe=Math.max(20,z*(1+ye*ce)),Ge=Math.max(10,oe);K+=(Ge-K)*qo,Jo(G,K,P,b);let Ee=le;k===1&&(Ko(M,Oo,H,b),Ee=QA(Ee,M,x));let Ue=QA(Ee,G,F)*l,Je=Ue*ie,PA=Ue*Qe,uA=i+Ie;t[uA]+=Je,s[uA]+=PA,n[Ie]+=Ue*h,a[Ie]+=Ue*I,o[Ie]+=Ue*c}this.phase=U,this.lastFc=K,this.envelope=S}setParameter(A,e){switch(A){default:break;case 3:{this.filType=e;break}case 4:{this.sens=e;break}case 5:{this.setManual(e);break}case 6:{this.peak=e;break}case 7:{this.rate=vA.rate1(e);break}case 8:{this.depth=e;break}case 9:{this.polarity=e;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 21:{this.pan=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}setManual(A){let e=A*Yo,t=vA.manual(Math.floor(e)),s=vA.manual(Math.ceil(e)),n=e-Math.floor(e);this.manual=t+(s-t)*n}updateShelves(){UA(this.lsCoeffs,this.lowGain,200,this.sampleRate,!0),UA(this.hsCoeffs,this.hiGain,4e3,this.sampleRate,!1)}};function Jo(A,e,t,s){let n=2*Math.PI*e/s,a=Math.cos(n),i=Math.sin(n)/(2*t),r=1-a,h=r/2,I=h,c=1+i,l=-2*a,B=1-i;A.a0=1,A.a1=l/c,A.a2=B/c,A.b0=h/c,A.b1=r/c,A.b2=I/c}function Ko(A,e,t,s){let n=2*Math.PI*e/s,a=Math.cos(n),i=Math.sin(n)/(2*t),r=(1+a)/2,h=-(1+a),I=r,c=1+i,l=-2*a,B=1-i;A.a0=1,A.a1=l/c,A.a2=B/c,A.b0=r/c,A.b1=h/c,A.b2=I/c}var Ca=127,Vo=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=4360;phPan=0;awPan=127;level=Ca/127;phaser;autoWah;bufferPh=new Float32Array(_e);bufferAw=new Float32Array(_e);constructor(A){this.phaser=new ai(A),this.autoWah=new ri(A),this.phaser.sendLevelToReverb=0,this.phaser.sendLevelToChorus=0,this.phaser.sendLevelToDelay=0,this.autoWah.sendLevelToReverb=0,this.autoWah.sendLevelToChorus=0,this.autoWah.sendLevelToDelay=0,this.reset()}reset(){this.phPan=0,this.awPan=127,this.level=Ca/127,this.phaser.reset(),this.autoWah.reset(),this.phaser.setParameter(22,127),this.autoWah.setParameter(22,127)}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l}=this;r>this.bufferPh.length&&(this.bufferPh=new Float32Array(r),this.bufferAw=new Float32Array(r));let{bufferPh:B,bufferAw:d}=this;this.bufferPh.fill(0),this.phaser.process(A,A,B,B,B,B,B,0,r),this.bufferAw.fill(0),this.autoWah.process(e,e,d,d,d,d,d,0,r);let p=this.phPan|0,w=is[p],G=rs[p],F=this.awPan|0,b=is[F],k=rs[F];for(let O=0;O<r;O++){let C=B[O]*.5*l,Y=d[O]*.5*l,q=C*w+Y*b,x=C*G+Y*k,M=i+O;t[M]+=q,s[M]+=x;let U=(q+x)*.5;n[O]+=U*h,a[O]+=U*I,o[O]+=U*c}}setParameter(A,e){if(A>=3&&A<=7){this.phaser.setParameter(A,e);return}if(A>=8&&A<=14){this.autoWah.setParameter(A-5,e);return}switch(A){default:break;case 18:{this.phPan=e;break}case 19:{this.phaser.setParameter(22,e);break}case 20:{this.awPan=e;break}case 21:{this.autoWah.setParameter(22,e);break}case 22:{this.level=e/127;break}}}},Ea=127,Ba=Math.PI*2,Xo=.01,Zo=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=293;modWave=1;modRate=3.05;modDepth=96;lowGain=0;hiGain=0;level=Ea/127;phase=0;currentGain=1;lsCoeffs={...je};hsCoeffs={...je};lsStateR={...Ne};lsStateL={...Ne};hsStateR={...Ne};hsStateL={...Ne};sampleRate;constructor(A){this.sampleRate=A,this.reset()}reset(){this.modWave=1,this.modRate=3.05,this.modDepth=96,this.lowGain=0,this.hiGain=0,this.level=Ea/127,this.phase=0,this.currentGain=1,we(this.hsStateR),we(this.hsStateL),we(this.lsStateR),we(this.lsStateL),this.updateShelves()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,lsCoeffs:B,lsStateL:d,lsStateR:p,hsCoeffs:w,hsStateR:G,hsStateL:F,modDepth:b,modWave:k}=this,O=this.modRate/this.sampleRate,{currentGain:C,phase:Y}=this;for(let q=0;q<r;q++){let x=XA(A[q],B,w,d,F),M=XA(e[q],B,w,p,G),U;switch(k){default:{U=1-4*Math.abs(Y-.5);break}case 1:{U=Y>.5?-1:-Math.cos((Y-.75)*Ba);break}case 2:{U=Math.sin(Ba*Y);break}case 3:{U=1-2*Y;break}case 4:{U=2*Y-1;break}}(Y+=O)>=1&&(Y-=1);let K=1-(U/2+.5)*(b/127);C+=(K-C)*Xo;let S=x*l*C,T=M*l*C,P=i+q;t[P]+=S,s[P]+=T;let H=(S+T)*.5;n[q]+=H*h,a[q]+=H*I,o[q]+=H*c}this.phase=Y,this.currentGain=C}setParameter(A,e){switch(A){default:break;case 3:{this.modWave=e;break}case 4:{this.modRate=vA.rate1(e);break}case 5:{this.modDepth=e;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}updateShelves(){UA(this.lsCoeffs,this.lowGain,200,this.sampleRate,!0),UA(this.hsCoeffs,this.hiGain,4e3,this.sampleRate,!1)}},Wo=[ti,bo,ai,No,ri,Vo,Zo],zo=.01,_o=.05,$o=class{voices;midiChannels=[];insertionInputL=new Float32Array(_e);insertionInputR=new Float32Array(_e);reverbInput=new Float32Array(_e);chorusInput=new Float32Array(_e);delayInput=new Float32Array(_e);delayActive=!1;soundBankManager=new uo(this.updatePresetList.bind(this));keyModifierManager=new Nr;sampleRate;tunings=new Float32Array(16384).fill(-1);masterParameters={...Ya};currentTime=0;midiVolume=1;enableEffects;enableEventSystem;panLeft=Math.cos(Math.PI/4);panRight=Math.cos(Math.PI/4);defaultPreset;drumPreset;gainSmoothingFactor;panSmoothingFactor;eventCallbackHandler;missingPresetHandler;cachedVoices=new Map;setMasterParameter=mo.bind(this);getMasterParameter=po.bind(this);getAllMasterParameters=yo.bind(this);systemExclusive=wo.bind(this);voiceCount=0;customChannelNumbers=!1;reverbProcessor;chorusProcessor;delayProcessor;insertionFallback=new ti;insertionProcessor=this.insertionFallback;insertionEffects=new Map;insertionActive=!1;portSelectChannelOffset=0;insertionParams=new Uint8Array(23).fill(255);lastPriorityAssignmentTime=0;eventQueue=[];sampleTime;constructor(A,e,t,s){this.eventCallbackHandler=A,this.missingPresetHandler=e,this.sampleRate=t,this.sampleTime=1/t,this.currentTime=s.initialTime,this.enableEffects=s.enableEffects,this.enableEventSystem=s.enableEventSystem,this.gainSmoothingFactor=zo*(44100/t),this.panSmoothingFactor=_o*(44100/t),Rn.initCache(this.sampleRate),this.reverbProcessor=s.reverbProcessor,this.chorusProcessor=s.chorusProcessor,this.delayProcessor=s.delayProcessor;for(let n of Wo)this.registerInsertionProcessor(n);this.resetInsertionParams(),this.voices=[];for(let n=0;n<this.masterParameters.voiceCap;n++)this.voices.push(new gn(this.sampleRate))}controllerChange(A,e,t){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.controllerChange(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].controllerChange(e,t)}noteOn(A,e,t){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.noteOn(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].noteOn(e,t)}noteOff(A,e){if(this.customChannelNumbers){for(let t of this.midiChannels)t.rxChannel===A&&t.noteOff(e);return}this.midiChannels[A+this.portSelectChannelOffset].noteOff(e)}polyPressure(A,e,t){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.polyPressure(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].polyPressure(e,t)}channelPressure(A,e){if(this.customChannelNumbers){for(let t of this.midiChannels)t.rxChannel===A&&t.channelPressure(e);return}this.midiChannels[A+this.portSelectChannelOffset].channelPressure(e)}pitchWheel(A,e,t=-1){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.pitchWheel(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].pitchWheel(e,t)}programChange(A,e){if(this.customChannelNumbers){for(let t of this.midiChannels)t.rxChannel===A&&t.programChange(e);return}this.midiChannels[A+this.portSelectChannelOffset].programChange(e)}assignVoice(){for(let e=0;e<this.masterParameters.voiceCap;e++){let t=this.voices[e];if(!t.isActive)return t.priority=1/0,t}if(this.masterParameters.autoAllocateVoices){let e=new gn(this.sampleRate);return this.voices.push(e),this.masterParameters.voiceCap++,this.callEvent("masterParameterChange",{parameter:"voiceCap",value:this.masterParameters.voiceCap}),e}this.assignVoicePriorities();let A=this.voices[0];for(let e=0;e<this.masterParameters.voiceCap;e++){let t=this.voices[e];t.priority<A.priority&&(A=t)}return A.priority=1/0,A}stopAllChannels(A){D("%cStop all received!",E.info);for(let e of this.midiChannels)e.stopAllNotes(A)}processMessage(A,e=0,t=Mi){let s=t.time;s>this.currentTime?(this.eventQueue.push({message:A,channelOffset:e,time:s}),this.eventQueue.sort((n,a)=>n.time-a.time)):this.processMessageInternal(A,e)}destroySynthProcessor(){this.voices.length=0;for(let A of this.midiChannels)A.lockedControllers=[],A.preset=void 0;this.clearCache(),this.midiChannels.length=0,this.soundBankManager.destroy()}getVoices(A,e,t){let s=this.midiChannels[A],n=this.keyModifierManager.hasOverridePatch(A,e),a=s.preset;if(n){let o=this.keyModifierManager.getPatch(A,e);a=this.soundBankManager.getPreset(o,this.masterParameters.midiSystem)}return a?this.getVoicesForPreset(a,e,t):[]}createMIDIChannel(A){let e=new lo(this,this.defaultPreset,this.midiChannels.length);this.midiChannels.push(e),A&&(this.callEvent("newChannel",void 0),e.sendChannelProperty(),e.setDrums(!0))}resetAllControllers(A=un){if(this.callEvent("allControllerReset",void 0),this.setMasterParameter("midiSystem",A),this.tunings.fill(-1),this.portSelectChannelOffset=0,this.customChannelNumbers=!1,this.setMIDIVolume(1),this.setReverbMacro(4),this.setChorusMacro(2),this.setDelayMacro(0),this.masterParameters.delayLock||(this.delayActive=!1),this.resetInsertion(),!(!this.drumPreset||!this.defaultPreset))for(let e=0;e<this.midiChannels.length;e++){let t=this.midiChannels[e];t.resetControllers(!1),t.resetPreset();for(let s=0;s<128;s++)this.midiChannels[e].lockedControllers[s]&&this.callEvent("controllerChange",{channel:e,controllerNumber:s,controllerValue:this.midiChannels[e].midiControllers[s]>>7});if(!this.midiChannels[e].lockedControllers[ve+Ae.pitchWheel]){let s=this.midiChannels[e].midiControllers[ve+Ae.pitchWheel];this.callEvent("pitchWheel",{channel:e,pitch:s,midiNote:-1})}if(!this.midiChannels[e].lockedControllers[ve+Ae.channelPressure]){let s=this.midiChannels[e].midiControllers[ve+Ae.channelPressure]>>7;this.callEvent("channelPressure",{channel:e,pressure:s})}}}process(A,e,t=0,s=0){this.processSplit([[A,e]],A,e,t,s)}processSplit(A,e,t,s=0,n=0){if(this.eventQueue.length>0){let r=this.currentTime;for(;this.eventQueue[0]?.time<=r;){let h=this.eventQueue.shift();h&&this.processMessageInternal(h.message,h.channelOffset)}}s=Math.max(s,0);let a=n||A[0][0].length-s;this.enableEffects&&(this.reverbInput.length<a?(se("Buffer size has increased, this will cause a memory allocation!"),this.reverbInput=new Float32Array(a),this.chorusInput=new Float32Array(a),this.delayInput=new Float32Array(a),this.insertionInputL=new Float32Array(a),this.insertionInputR=new Float32Array(a)):(this.reverbInput.fill(0),this.chorusInput.fill(0),this.delayActive&&this.delayInput.fill(0),this.insertionActive&&(this.insertionInputL.fill(0),this.insertionInputR.fill(0))));for(let r of this.midiChannels)r.clearVoiceCount();this.voiceCount=0;let o=this.masterParameters.voiceCap,i=A.length;for(let r=0;r<o;r++){let h=this.voices[r],I=this.midiChannels[h.channel];if(!h.isActive||I.isMuted)continue;let c=h.channel%i;I.renderVoice(h,this.currentTime,A[c][0],A[c][1],s,a),I.voiceCount++,this.voiceCount++}if(this.enableEffects){let{chorusInput:r,delayInput:h,reverbInput:I,insertionInputR:c,insertionInputL:l}=this;this.insertionActive&&this.insertionProcessor.process(l,c,e,t,I,r,h,s,a),this.chorusProcessor.process(r,e,t,I,h,s,a),this.delayActive&&this.masterParameters.midiSystem!=="xg"&&this.delayProcessor.process(h,e,t,I,s,a),this.reverbProcessor.process(I,e,t,s,a)}for(let r of this.midiChannels)r.updateVoiceCount();this.currentTime+=a*this.sampleTime}getVoicesForPreset(A,e,t){let s=this.getCachedVoice(A,e,t);if(s!==void 0)return s;let n=new Array;for(let a of A.getVoiceParameters(e,t)){let o=a.sample;if(a.sample.getAudioData()===void 0){se(`Discarding invalid sample: ${o.name}`);continue}n.push(new Wr(a,e,t,this.sampleRate))}return this.setCachedVoice(A,e,t,n),n}clearCache(){this.cachedVoices.clear()}getInsertionSnapshot(){return{type:this.insertionProcessor.type,params:this.insertionParams.slice(),channels:this.midiChannels.map(A=>A.insertionEnabled)}}callEvent(A,e){this.eventCallbackHandler(A,e)}resetInsertionParams(){this.insertionParams.fill(255),this.insertionParams[20]=40,this.insertionParams[21]=0,this.insertionParams[22]=0}resetInsertion(){this.masterParameters.insertionEffectLock||(this.insertionActive=!1,this.insertionProcessor=this.insertionFallback,this.insertionProcessor.reset(),this.insertionProcessor.sendLevelToReverb=40/127*Wt,this.insertionProcessor.sendLevelToChorus=0,this.insertionProcessor.sendLevelToDelay=0,this.resetInsertionParams(),this.callEvent("effectChange",{effect:"insertion",parameter:0,value:this.insertionProcessor.type}))}setMIDIVolume(A){this.midiVolume=Math.pow(A,Math.E)}setMasterTuning(A){A=Math.round(A);for(let e of this.midiChannels)e.setCustomController(Ce.masterTuning,A)}setReverbMacro(A){if(this.masterParameters.reverbLock)return;let e=this.reverbProcessor;switch(e.level=64,e.preDelayTime=0,e.character=A,A){case 0:{e.character=0,e.preLowpass=3,e.time=80,e.delayFeedback=0,e.preDelayTime=0;break}case 1:{e.preLowpass=4,e.time=56,e.delayFeedback=0;break}case 2:{e.preLowpass=0,e.time=72,e.delayFeedback=0;break}case 3:{e.preLowpass=4,e.time=72,e.delayFeedback=0;break}case 4:{e.preLowpass=0,e.time=64,e.delayFeedback=0;break}case 5:{e.preLowpass=0,e.time=88,e.delayFeedback=0;break}case 6:{e.preLowpass=0,e.time=32,e.delayFeedback=40;break}case 7:{e.preLowpass=0,e.time=64,e.delayFeedback=32;break}default:{se(`Invalid reverb macro: ${A}`);return}}this.callEvent("effectChange",{effect:"reverb",parameter:"macro",value:A})}setChorusMacro(A){if(this.masterParameters.chorusLock)return;let e=this.chorusProcessor;switch(e.level=64,e.preLowpass=0,e.delay=127,e.sendLevelToDelay=0,e.sendLevelToReverb=0,A){case 0:{e.feedback=0,e.delay=112,e.rate=3,e.depth=5;break}case 1:{e.feedback=5,e.delay=80,e.rate=9,e.depth=19;break}case 2:{e.feedback=8,e.delay=80,e.rate=3,e.depth=19;break}case 3:{e.feedback=16,e.delay=64,e.rate=9,e.depth=16;break}case 4:{e.feedback=64,e.delay=127,e.rate=2,e.depth=24;break}case 5:{e.feedback=112,e.delay=127,e.rate=1,e.depth=5;break}case 6:{e.feedback=0,e.depth=127,e.rate=0,e.depth=127;break}case 7:{e.feedback=80,e.depth=127,e.rate=0,e.depth=127;break}default:{se(`Invalid chorus macro: ${A}`);return}}this.callEvent("effectChange",{effect:"chorus",parameter:"macro",value:A})}setDelayMacro(A){if(this.masterParameters.delayLock)return;let e=this.delayProcessor;switch(e.level=64,e.preLowpass=0,e.sendLevelToReverb=0,e.levelRight=e.levelLeft=0,e.levelCenter=127,A){case 0:{e.timeCenter=97,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=80;break}case 1:{e.timeCenter=106,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=80;break}case 2:{e.timeCenter=115,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=72;break}case 3:{e.timeCenter=83,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=72;break}case 4:{e.timeCenter=105,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=125,e.levelRight=60,e.feedback=74;break}case 5:{e.timeCenter=109,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=125,e.levelRight=60,e.feedback=71;break}case 6:{e.timeCenter=115,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=120,e.levelRight=64,e.feedback=73;break}case 7:{e.timeCenter=93,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=120,e.levelRight=64,e.feedback=72;break}case 8:{e.timeCenter=109,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=114,e.levelRight=60,e.feedback=61,e.sendLevelToReverb=36;break}case 9:{e.timeCenter=110,e.timeRatioLeft=21,e.timeRatioRight=32,e.levelCenter=97,e.levelLeft=127,e.levelRight=67,e.feedback=40;break}default:{se(`Invalid delay macro: ${A}`);return}}this.callEvent("effectChange",{effect:"delay",parameter:"macro",value:A})}getCachedVoice(A,e,t){return this.cachedVoices.get(this.getCachedVoiceIndex(A,e,t))}setCachedVoice(A,e,t,s){this.cachedVoices.set(this.getCachedVoiceIndex(A,e,t),s)}registerInsertionProcessor(A){let e=new A(this.sampleRate);this.insertionEffects.set(e.type,e)}processMessageInternal(A,e){let t=fn(A[0]),s=t.channel+e;switch(t.status){case N.noteOn:{let n=A[2];n>0?this.noteOn(s,A[1],n):this.noteOff(s,A[1]);break}case N.noteOff:{this.noteOff(s,A[1]);break}case N.pitchWheel:{this.pitchWheel(s,A[2]<<7|A[1]);break}case N.controllerChange:{this.controllerChange(s,A[1],A[2]);break}case N.programChange:{this.programChange(s,A[1]);break}case N.polyPressure:{this.polyPressure(s,A[1],A[2]);break}case N.channelPressure:{this.channelPressure(s,A[1]);break}case N.systemExclusive:{this.systemExclusive(new $(A.slice(1)),e);break}case N.reset:{this.stopAllChannels(!1),this.resetAllControllers();break}default:break}}assignVoicePriorities(){if(this.lastPriorityAssignmentTime===this.currentTime)return;D("%cPolyphony exceeded, stealing voices",E.warn),this.lastPriorityAssignmentTime=this.currentTime;let A=this.masterParameters.voiceCap;for(let e=0;e<A;e++){let t=this.voices[e];t.priority=0,this.midiChannels[t.channel].drumChannel&&(t.priority+=5),t.isInRelease&&(t.priority-=5),t.priority+=t.velocity/25,t.priority-=t.volEnv.state,t.isInRelease&&(t.priority-=5),t.priority-=t.volEnv.attenuationCb/200}}updatePresetList(){let A=this.soundBankManager.presetList;this.clearCache(),this.callEvent("presetListChange",A),this.getDefaultPresets();for(let e of this.midiChannels)e.setPresetLock(!1);this.resetAllControllers()}getDefaultPresets(){this.defaultPreset=this.soundBankManager.getPreset({bankLSB:0,bankMSB:0,program:0,isGMGSDrum:!1},"xg"),this.drumPreset=this.soundBankManager.getPreset({bankLSB:0,bankMSB:0,program:0,isGMGSDrum:!0},"gs")}getCachedVoiceIndex(A,e,t){let s=A.bankMSB,n=A.bankLSB,{isGMGSDrum:a,program:o}=A;return a&&(s=128,n=0),s+n*128+o*16384+2097152*e+268435456*t}},Js=20;async function jo(A,e,t,s,n,a,o){let i=0,r=0,h=[];for(let l of A.samples){s&&a&&await l.compressSample(a),n&&l.setAudioData(l.getAudioData(),l.sampleRate);let B=l.getRawData(!0);i++,await o?.(l.name,i,A.samples.length),D(`%cEncoded sample %c${i}. ${l.name}%c of %c${A.samples.length}%c. Compressed: %c${l.isCompressed}%c.`,E.info,E.recognized,E.info,E.recognized,E.info,l.isCompressed?E.recognized:E.unrecognized,E.info),r+=B.length+(l.isCompressed?0:92),h.push(B)}r%2!==0&&r++;let I=new $(r+Js);Te(I,"LIST"),bt(I,r+Js-8,4),Te(I,"sdta"),Te(I,"smpl"),bt(I,r,4);let c=0;for(let[l,B]of A.samples.entries()){let d=h[l];I.set(d,c+Js);let p,w;B.isCompressed?(p=c,w=p+d.length):(p=c/2,w=p+d.length/2,c+=92),c+=d.length,e.push(p),t.push(w)}return I}var eh=48e3,Cs=class{name;sampleRate;originalKey;pitchCorrection;linkedSample;sampleType;loopStart;loopEnd;linkedTo=[];dataOverridden=!0;compressedData;audioData;constructor(A,e,t,s,n,a,o){this.name=A,this.sampleRate=e,this.originalKey=t,this.pitchCorrection=s,this.loopStart=a,this.loopEnd=o,this.sampleType=n}get isCompressed(){return this.compressedData!==void 0}get isLinked(){return this.sampleType===xe.rightSample||this.sampleType===xe.leftSample||this.sampleType===xe.linkedSample}get useCount(){return this.linkedTo.length}getRawData(A){return this.compressedData&&A&&!this.dataOverridden?this.compressedData:this.encodeS16LE()}resampleData(A){let e=this.getAudioData(),t=A/this.sampleRate,s=new Float32Array(Math.floor(e.length*t));for(let n=0;n<s.length;n++)s[n]=e[Math.floor(n*(1/t))];e=s,this.sampleRate=A,this.loopStart=Math.floor(this.loopStart*t),this.loopEnd=Math.floor(this.loopEnd*t),this.audioData=e}async compressSample(A){if(!this.isCompressed)try{let e=this.getAudioData();(this.sampleRate<8e3||this.sampleRate>96e3)&&(this.resampleData(eh),e=this.getAudioData());let t=await A(e,this.sampleRate);this.setCompressedData(t)}catch(e){se(`Failed to compress ${this.name}. Leaving as uncompressed!`,e),this.compressedData=void 0}}setSampleType(A){if(this.sampleType=A,this.isLinked||(this.linkedSample&&(this.linkedSample.linkedSample=void 0,this.linkedSample.sampleType=A),this.linkedSample=void 0),(A&32768)>0)throw new Error("ROM samples are not supported.")}unlinkSample(){this.setSampleType(xe.monoSample)}setLinkedSample(A,e){if(A.linkedSample)throw new Error(`${A.name} is linked tp ${A.linkedSample.name}. Unlink it first.`);switch(this.linkedSample=A,A.linkedSample=this,e){case xe.leftSample:{this.setSampleType(xe.leftSample),A.setSampleType(xe.rightSample);break}case xe.rightSample:{this.setSampleType(xe.rightSample),A.setSampleType(xe.leftSample);break}case xe.linkedSample:{this.setSampleType(xe.linkedSample),A.setSampleType(xe.linkedSample);break}default:throw new Error("Invalid sample type: "+e)}}linkTo(A){this.linkedTo.push(A)}unlinkFrom(A){let e=this.linkedTo.indexOf(A);if(e===-1){se(`Cannot unlink ${A.name} from ${this.name}: not linked.`);return}this.linkedTo.splice(e,1)}getAudioData(){if(this.audioData)return this.audioData;if(this.isCompressed)return this.audioData=this.decodeVorbis(),this.audioData;throw new Error("Sample data is undefined for a BasicSample instance.")}setAudioData(A,e){this.audioData=A,this.sampleRate=e,this.dataOverridden=!0,this.compressedData=void 0}setCompressedData(A){this.audioData=void 0,this.compressedData=A,this.dataOverridden=!1}encodeS16LE(){let A=this.getAudioData(),e=new Int16Array(A.length),t=A.length;for(let s=0;s<t;s++){let n=A[s]*32768;n>32767?n=32767:n<-32768&&(n=-32768),e[s]=n}return new $(e.buffer)}decodeVorbis(){if(this.audioData)return this.audioData;if(!this.compressedData)throw new Error("Compressed data is missing.");try{let e=cs.decode(this.compressedData).data[0];if(e===void 0)return se(`Error decoding sample ${this.name}: Vorbis decode returned undefined.`),new Float32Array(0);for(let t=0;t<e.length;t++)e[t]=Math.max(-1,Math.min(e[t],.999969482421875));return e}catch(A){return se(`Error decoding sample ${this.name}: ${A}`),new Float32Array(this.loopEnd+1)}}},Ah=class extends Cs{constructor(){super("",44100,60,0,xe.monoSample,0,0)}},In=16,th=class extends Cs{linkedSampleIndex;s16leData;startByteOffset;endByteOffset;sampleID;constructor(A,e,t,s,n,a,o,i,r,h,I,c){let l=(h&In)>0;h&=~In,super(A,a,o,i,h,s-e/2,n-e/2),this.dataOverridden=!1,this.name=A,this.startByteOffset=e,this.endByteOffset=t,this.sampleID=c;let B=I instanceof $?I.currentIndex:0;I instanceof $?l?(this.loopStart+=this.startByteOffset/2,this.loopEnd+=this.startByteOffset/2,this.setCompressedData(I.slice(this.startByteOffset/2+B,this.endByteOffset/2+B))):this.s16leData=I.slice(B+this.startByteOffset,B+this.endByteOffset):this.setAudioData(I.slice(this.startByteOffset/2,this.endByteOffset/2),a),this.linkedSampleIndex=r}getLinkedSample(A){if(this.linkedSample||!this.isLinked)return;let e=A[this.linkedSampleIndex];e?e.linkedSample?(D(`%cInvalid linked sample for ${this.name}: ${e.name} is already linked to ${e.linkedSample.name}`,E.warn),this.unlinkSample()):this.setLinkedSample(e,this.sampleType):(D(`%cInvalid linked sample for ${this.name}. Setting to mono.`,E.warn),this.unlinkSample())}getAudioData(){if(this.audioData)return this.audioData;if(this.isCompressed)return super.getAudioData();if(!this.s16leData)throw console.error(this),new Error("Unexpected lack of audio data.");let A=this.endByteOffset-this.startByteOffset;if(A<1)return se(`Invalid sample ${this.name}! Invalid length: ${A}`),new Float32Array(1);let e=new Float32Array(A/2),t=new Int16Array(this.s16leData.buffer);for(let[s,n]of t.entries())e[s]=n/32768;return this.audioData=e,e}getRawData(A){return this.dataOverridden||this.compressedData?super.getRawData(A):this.s16leData??new Uint8Array(0)}};function da(A,e,t=!0){let s=[],n=0;for(;A.data.length>A.data.currentIndex;){let a=sh(n,A.data,e);s.push(a),n++}if(s.pop(),t)for(let a of s)a.getLinkedSample(s);return s}function sh(A,e,t){let s=pe(e,20),n=V(e,4)*2,a=V(e,4)*2,o=V(e,4),i=V(e,4),r=V(e,4),h=e[e.currentIndex++];h>127&&(h=60);let I=bi(e[e.currentIndex++]),c=V(e,2),l=V(e,2);return new th(s,n,a,o,i,r,h,I,c,l,t,A)}function nh(A,e,t){let n=46*(A.samples.length+1),a=new $(n),o=new $(n),i=0;for(let[I,c]of A.samples.entries()){Te(a,c.name.slice(0,20),20),Te(o,c.name.slice(20),20);let l=e[I];Be(a,l),o.currentIndex+=4;let B=t[I];Be(a,B),o.currentIndex+=4;let d=c.loopStart+l,p=c.loopEnd+l;c.isCompressed&&(d-=l,p-=l),Be(a,d),Be(a,p),Be(a,c.sampleRate),a[a.currentIndex++]=c.originalKey,a[a.currentIndex++]=c.pitchCorrection,o.currentIndex+=14;let w=c.linkedSample?A.samples.indexOf(c.linkedSample):0;te(a,Math.max(0,w)&65535),te(o,Math.max(0,w)>>16),i=Math.max(i,w);let G=c.sampleType;c.isCompressed&&(G|=In),te(a,G),o.currentIndex+=2}Te(a,"EOS",46),Te(o,"EOS",46);let r=de("shdr",a),h=de("shdr",o);return{pdta:r,xdta:h}}function Qa(A,e=!1){let t=e?A.presets:A.instruments,s=e?"pgen":"igen",n=e?"pmod":"imod",a=e?"pbag":"ibag",o=e?"phdr":"inst",i=e?Qo:Eo,r=0,h=new Array,I=0,c=new Array,l=new Array,B=new Array,d=0,p=new Array,w=x=>{h.push(r);let M=x.getWriteGenerators(A);r+=M.length,l.push(...M),c.push(I);let U=x.modulators;I+=U.length,B.push(...U)};for(let x of t){p.push(d),w(x.globalZone);for(let M of x.zones)w(M);d+=x.zones.length+1}l.push(new He(0,0,!1)),B.push(new be(0,0,0,0,0)),h.push(r),c.push(I),p.push(d);let G=l.length*sa,F=new $(G);for(let x of l)x.write(F);let b=B.length*wt,k=new $(b);for(let x of B)x.write(k);let O=c.length*Co,C={pdta:new $(O),xdta:new $(O)};for(let[x,M]of c.entries()){let U=h[x];te(C.pdta,U&65535),te(C.pdta,M&65535),te(C.xdta,U>>16),te(C.xdta,M>>16)}let Y=(t.length+1)*i,q={pdta:new $(Y),xdta:new $(Y)};for(let[x,M]of t.entries())M.write(q,p[x]);return e?(Te(q.pdta,"EOP",20),q.pdta.currentIndex+=4,te(q.pdta,d&65535),q.pdta.currentIndex+=12,Te(q.xdta,"",20),q.xdta.currentIndex+=4,te(q.xdta,d>>16),q.xdta.currentIndex+=12):(Te(q.pdta,"EOI",20),te(q.pdta,d&65535),Te(q.xdta,"",20),te(q.xdta,d>>16)),{writeXdta:Math.max(r,I,d)>65535,gen:{pdta:de(s,F),xdta:de(n,new $(sa))},mod:{pdta:de(n,k),xdta:de(n,new $(wt))},bag:{pdta:de(a,C.pdta),xdta:de(a,C.xdta)},hdr:{pdta:de(o,q.pdta),xdta:de(o,q.xdta)}}}var cn={compress:!1,compressionFunction:void 0,progressFunction:void 0,writeDefaultModulators:!0,writeExtendedLimits:!0,decompress:!1};async function ah(A,e=cn){let t=Qn(e,cn);if(t?.compress){if(typeof t?.compressionFunction!="function")throw new TypeError("No compression function supplied but compression enabled.");if(t?.decompress)throw new Error("Decompressed and compressed at the same time.")}Xe("%cSaving soundbank...",E.info),D(`%cCompression: %c${t?.compress||"false"}%c`,E.info,E.recognized,E.info,E.recognized),tA("%cWriting INFO...",E.info);let s=[];A.soundBankInfo.software="SpessaSynth",(t?.compress||A.samples.some(b=>b.isCompressed))&&(A.soundBankInfo.version.major=3,A.soundBankInfo.version.minor=0),t?.decompress&&(A.soundBankInfo.version.major=2,A.soundBankInfo.version.minor=4);let n=(b,k)=>{s.push(de(b,fA(k,!0,!0)))},a=new $(4);if(te(a,A.soundBankInfo.version.major),te(a,A.soundBankInfo.version.minor),s.push(de("ifil",a)),A.soundBankInfo.romVersion){let b=new $(4);te(b,A.soundBankInfo.romVersion.major),te(b,A.soundBankInfo.romVersion.minor),s.push(de("iver",b))}let o=(A.soundBankInfo?.comment??"")+(A.soundBankInfo.subject?`
6
+ This will cause a memory allocation!`),A.buffer=new Float32Array(a));let C=A.buffer;if(A.loopingMode===2&&!A.isInRelease){A.isActive=A.volEnv.process(a,C,O,c);return}A.isActive=A.wavetable.process(a,A.tuningRatio,C);{let P=A.filter,H=A.modulatedGenerators[g.initialFilterFc];P.initialized?P.currentInitialFc+=(H-P.currentInitialFc)*Rn.smoothingConstant:(P.initialized=!0,P.currentInitialFc=H);let y=P.currentInitialFc+I,R=A.modulatedGenerators[g.initialFilterQ];if(P.currentInitialFc>13499&&y>13499&&R===0)P.currentInitialFc=13500;else{(Math.abs(P.lastTargetCutoff-y)>1||P.resonanceCb!==R)&&(P.lastTargetCutoff=y,P.resonanceCb=R,P.calculateCoefficients(y));let{a0:J,a1:ee,a2:ie,a3:Qe,a4:Ie}=P,{x1:le,x2:re,y1:ce,y2:ye}=P;for(let z=0;z<a;z++){let oe=C[z],Ge=J*oe+ee*le+ie*re-Qe*ce-ye*Ie;re=le,le=oe,ye=ce,ce=Ge,C[z]=Ge}P.x1=le,P.x2=re,P.y1=ce,P.y2=ye}}let Y=A.volEnv.process(a,C,O,c);A.isActive=A.isActive&&Y;let q;A.overridePan?q=A.overridePan:(A.currentPan+=(A.modulatedGenerators[g.pan]-A.currentPan)*this.synthCore.panSmoothingFactor,q=A.currentPan);let x=this.synthCore.masterParameters.masterGain*this.synthCore.midiVolume*A.gainModifier,M=q+500|0,U=za[M]*x*this.synthCore.panLeft,K=_a[M]*x*this.synthCore.panRight;if(this.insertionEnabled){let P=this.synthCore.insertionInputL,H=this.synthCore.insertionInputR;for(let y=0;y<a;y++){let R=C[y];P[y]+=U*R,H[y]+=K*R}return}for(let P=0;P<a;P++){let H=C[P],y=P+n;t[y]+=U*H,s[y]+=K*H}if(!this.synthCore.enableEffects)return;let S=A.modulatedGenerators[g.reverbEffectsSend]*A.reverbSend;if(S>0){let P=this.synthCore.masterParameters.reverbGain*x*(S/1e3),H=this.synthCore.reverbInput;for(let y=0;y<a;y++)H[y]+=P*C[y]}let T=A.modulatedGenerators[g.chorusEffectsSend]*A.chorusSend;if(T>0){let P=this.synthCore.masterParameters.chorusGain*(T/1e3)*x,H=this.synthCore.chorusInput;for(let y=0;y<a;y++)H[y]+=P*C[y]}if(this.synthCore.delayActive){let P=this.midiControllers[u.variationDepth]*A.delaySend;if(P>0){let H=x*this.synthCore.masterParameters.delayGain*((P>>7)/127),y=this.synthCore.delayInput;for(let R=0;R<a;R++)y[R]+=H*C[R]}}}var NA={pitchWheelRange:0,fineTuning:1,coarseTuning:2,modulationDepth:5,resetParameters:16383},Ve={partParameter:1,drumPitch:24,drumPitchFine:25,drumLevel:26,drumPan:28,drumReverb:29,drumChorus:30,drumDelay:31,awe32:127,SF2:120},LA={vibratoRate:8,vibratoDepth:9,vibratoDelay:10,TVFFilterCutoff:32,TVFFilterResonance:33,EGAttackTime:99,EGDecayTime:100,EGReleaseTime:102},Oe=(A,e,t,s)=>{s.length>0&&(s=" "+s),D(`%c${e} for %c${A}%c is now set to %c${t}%c${s}.`,E.info,E.recognized,E.info,E.value,E.info)},Os=A=>{A.channelVibrato.delay===0&&A.channelVibrato.rate===0&&A.channelVibrato.depth===0&&(A.channelVibrato.depth=50,A.channelVibrato.rate=8,A.channelVibrato.delay=.6)};function jr(A){switch(this.midiControllers[u.dataEntryMSB]=A<<7,this.dataEntryState){default:case $e.Idle:break;case $e.NRPCoarse:case $e.NRPFine:{let e=this.midiControllers[u.nonRegisteredParameterMSB]>>7,t=this.midiControllers[u.nonRegisteredParameterLSB]>>7,s=this.midiControllers[u.dataEntryLSB]>>7;if(this.synthCore.masterParameters.drumLock&&e>=Ve.drumPitch&&e<=Ve.drumDelay)return;switch(e){default:{if(A===64)return;D(`%cUnrecognized NRPN for %c${this.channel}%c: %c(0x${t.toString(16).toUpperCase()} 0x${t.toString(16).toUpperCase()})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value);break}case Ve.partParameter:{let n=this.synthCore.masterParameters.nprnParamLock,a=this.synthCore.masterParameters.customVibratoLock||n;switch(t){default:{if(A===64)return;D(`%cUnrecognized NRPN for %c${this.channel}%c: %c(0x${e.toString(16)} 0x${t.toString(16)})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value);break}case LA.vibratoRate:{if(a||A===64)return;Os(this),this.channelVibrato.rate=A/64*8,Oe(this.channel,"Vibrato rate",`${A} = ${this.channelVibrato.rate}`,"Hz");break}case LA.vibratoDepth:{if(a||A===64)return;Os(this),this.channelVibrato.depth=A/2,Oe(this.channel,"Vibrato depth",`${A} = ${this.channelVibrato.depth}`,"cents of detune");break}case LA.vibratoDelay:{if(a||A===64)return;Os(this),this.channelVibrato.delay=A/64/3,Oe(this.channel,"Vibrato delay",`${A} = ${this.channelVibrato.delay}`,"seconds");break}case LA.TVFFilterCutoff:{if(n)return;this.controllerChange(u.brightness,A),Oe(this.channel,"Filter cutoff",A.toString(),"");break}case LA.TVFFilterResonance:{if(n)return;this.controllerChange(u.filterResonance,A),Oe(this.channel,"Filter resonance",A.toString(),"");break}case LA.EGAttackTime:{if(n)return;this.controllerChange(u.attackTime,A),Oe(this.channel,"EG attack time",A.toString(),"");break}case LA.EGDecayTime:{if(n)return;this.controllerChange(u.decayTime,A),Oe(this.channel,"EG decay time",A.toString(),"");break}case LA.EGReleaseTime:{if(n)return;this.controllerChange(u.releaseTime,A),Oe(this.channel,"EG release time",A.toString(),"");break}}break}case Ve.drumPitch:{let n=this.channelSystem==="xg"?(A-64)*100:(A-64)*50;this.drumParams[t].pitch=n,Oe(this.channel,`Drum ${t} pitch`,n,"cents");break}case Ve.drumPitchFine:{let n=A-64;this.drumParams[t].pitch+=n,Oe(this.channel,`Drum ${t} pitch fine`,this.drumParams[t].pitch,"cents");break}case Ve.drumLevel:{this.drumParams[t].gain=A/120,Oe(this.channel,`Drum ${t} level`,A,"");break}case Ve.drumPan:{this.drumParams[t].pan=A,Oe(this.channel,`Drum ${t} pan`,A,"");break}case Ve.drumReverb:{this.drumParams[t].reverbGain=A/127,Oe(this.channel,`Drum ${t} reverb level`,A,"");break}case Ve.drumChorus:{this.drumParams[t].chorusGain=A/127,Oe(this.channel,`Drum ${t} chorus level`,A,"");break}case Ve.drumDelay:{this.drumParams[t].delayGain=A/127,Oe(this.channel,`Drum ${t} delay level`,A,"");break}case Ve.awe32:break;case Ve.SF2:{if(t>100)break;let n=this.customControllers[Ce.sf2NPRNGeneratorLSB],a=(A<<7|s)-8192;this.setGeneratorOffset(n,a);break}}break}case $e.RPCoarse:case $e.RPFine:{let e=this.midiControllers[u.registeredParameterMSB]|this.midiControllers[u.registeredParameterLSB]>>7;switch(e){default:{D(`%cUnrecognized RPN for %c${this.channel}%c: %c(0x${e.toString(16)})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value);break}case NA.pitchWheelRange:{this.midiControllers[ve+Ae.pitchWheelRange]=A<<7,Oe(this.channel,"Pitch wheel range",A.toString(),"semitones");break}case NA.coarseTuning:{let t=A-64;this.setCustomController(Ce.channelTuningSemitones,t),Oe(this.channel,"Coarse tuning",t.toString(),"semitones");break}case NA.fineTuning:{this.setTuning(A-64,!1);break}case NA.modulationDepth:{this.setModulationDepth(A*100);break}case NA.resetParameters:{this.resetParameters();break}}}}}var eo=[g.delayModLFO,g.freqModLFO,g.delayVibLFO,g.freqVibLFO,g.delayModEnv,g.attackModEnv,g.holdModEnv,g.decayModEnv,g.sustainModEnv,g.releaseModEnv,g.delayVolEnv,g.attackVolEnv,g.holdVolEnv,g.decayVolEnv,g.sustainVolEnv,g.releaseVolEnv,g.fineTune,g.modLfoToPitch,g.vibLfoToPitch,g.modEnvToPitch,g.modLfoToVolume,g.initialFilterFc,g.initialFilterQ,g.modLfoToFilterFc,g.modEnvToFilterFc,g.chorusEffectsSend,g.reverbEffectsSend],kA=(A,e,t)=>Math.max(e,Math.min(t,A)),Vt=A=>Math.max(-32768,1200*Math.log2(A/1e3)),Ao=A=>6900+1200*Math.log2(A/440);function to(A,e,t){let s=t<<7|e;s-=8192;let n=eo[A];n||se(`Invalid AWE32 LSB: %c${A}`,E.unrecognized);let a,o,i,r;switch(n){default:break;case g.delayModLFO:case g.delayVibLFO:case g.delayVolEnv:case g.delayModEnv:{a=4*kA(s,0,5900),this.setGeneratorOverride(n,Vt(a));break}case g.attackVolEnv:case g.attackModEnv:{a=kA(s,0,5940),this.setGeneratorOverride(n,Vt(a));break}case g.holdVolEnv:case g.holdModEnv:{a=kA(s,0,8191),this.setGeneratorOverride(n,Vt(a));break}case g.decayModEnv:case g.decayVolEnv:case g.releaseVolEnv:case g.releaseModEnv:{a=4*kA(s,0,5940),this.setGeneratorOverride(n,Vt(a));break}case g.freqVibLFO:case g.freqModLFO:{o=.084*e,this.setGeneratorOverride(n,Ao(o),!0);break}case g.sustainVolEnv:case g.sustainModEnv:{i=e*7.5,this.setGeneratorOverride(n,i);break}case g.fineTune:{this.setGeneratorOverride(n,s,!0);break}case g.modLfoToPitch:case g.vibLfoToPitch:{r=kA(s,-127,127)*9.375,this.setGeneratorOverride(n,r,!0);break}case g.modEnvToPitch:{r=kA(s,-127,127)*9.375,this.setGeneratorOverride(n,r);break}case g.modLfoToVolume:{i=1.875*e,this.setGeneratorOverride(n,i,!0);break}case g.initialFilterFc:{let h=4335+59*e;this.setGeneratorOverride(n,h,!0);break}case g.initialFilterQ:{i=215*(e/127),this.setGeneratorOverride(n,i,!0);break}case g.modLfoToFilterFc:{r=kA(s,-64,63)*56.25,this.setGeneratorOverride(n,r,!0);break}case g.modEnvToFilterFc:{r=kA(s,-64,63)*56.25,this.setGeneratorOverride(n,r);break}case g.chorusEffectsSend:case g.reverbEffectsSend:{this.setGeneratorOverride(n,kA(s,0,255)*(1e3/255));break}}}function so(A){switch(this.midiControllers[u.dataEntryLSB]=A<<7,this.dataEntryState){default:break;case $e.RPCoarse:case $e.RPFine:{switch(this.midiControllers[u.registeredParameterMSB]|this.midiControllers[u.registeredParameterLSB]>>7){default:break;case NA.pitchWheelRange:{if(A===0)break;this.midiControllers[ve+Ae.pitchWheelRange]|=A;let t=(this.midiControllers[ve+Ae.pitchWheelRange]>>7)+A/128;D(`%cChannel ${this.channel} pitch wheel range. Semitones: %c${t}`,E.info,E.value);break}case NA.fineTuning:{let s=this.customControllers[Ce.channelTuning]<<7|A;this.setTuning(s*.01220703125);break}case NA.modulationDepth:{let s=this.customControllers[Ce.modulationMultiplier]*50+A/128*100;this.setModulationDepth(s);break}case 16383:{this.resetParameters();break}}break}case $e.NRPFine:{let e=this.midiControllers[u.nonRegisteredParameterMSB]>>7,t=this.midiControllers[u.nonRegisteredParameterLSB]>>7;if(e===Ve.SF2)return;e===Ve.awe32?to.call(this,t,A,this.midiControllers[u.dataEntryMSB]>>7):D(`%cUnrecognized NRPN LSB for %c${this.channel}%c: %c(0x${t.toString(16).toUpperCase()} 0x${t.toString(16).toUpperCase()})%c data value: %c${A}`,E.warn,E.recognized,E.warn,E.unrecognized,E.warn,E.value)}}}function no(A,e,t=!0){if(A>127)throw new Error("Invalid MIDI Controller.");if(A>=u.modulationWheelLSB&&A<=u.effectControl2LSB&&A!==u.dataEntryLSB){let s=A-32;if(this.lockedControllers[s])return;this.midiControllers[s]=this.midiControllers[s]&16256|e&127,this.computeModulatorsAll(1,s)}if(!this.lockedControllers[A]){switch(this.midiControllers[A]=e<<7,A){case u.omniModeOff:case u.omniModeOn:case u.allNotesOff:{this.stopAllNotes();break}case u.allSoundOff:{this.stopAllNotes(!0);break}case u.polyModeOn:{this.stopAllNotes(!0),this.polyMode=!0;break}case u.monoModeOn:{this.stopAllNotes(!0),this.polyMode=!1;break}case u.bankSelect:{this.setBankMSB(e),this.channel%16===FA&&Fe.isSystemXG(this.channelSystem)&&this.setBankMSB(127);break}case u.bankSelectLSB:{this.setBankLSB(e);break}case u.variationDepth:{this.synthCore.delayActive=!0;break}case u.registeredParameterLSB:{this.dataEntryState=$e.RPFine;break}case u.registeredParameterMSB:{this.dataEntryState=$e.RPCoarse;break}case u.nonRegisteredParameterMSB:{this.customControllers[Ce.sf2NPRNGeneratorLSB]=0,this.dataEntryState=$e.NRPCoarse;break}case u.nonRegisteredParameterLSB:{if(this.midiControllers[u.nonRegisteredParameterMSB]>>7===Ve.SF2)switch(this.customControllers[Ce.sf2NPRNGeneratorLSB]%100!==0&&(this.customControllers[Ce.sf2NPRNGeneratorLSB]=0),e){case 100:{this.customControllers[Ce.sf2NPRNGeneratorLSB]+=100;break}case 101:{this.customControllers[Ce.sf2NPRNGeneratorLSB]+=1e3;break}case 102:{this.customControllers[Ce.sf2NPRNGeneratorLSB]+=1e4;break}default:e<100&&(this.customControllers[Ce.sf2NPRNGeneratorLSB]+=e)}this.dataEntryState=$e.NRPFine;break}case u.dataEntryMSB:{this.dataEntryCoarse(e);break}case u.dataEntryLSB:{this.dataEntryFine(e);break}case u.resetAllControllers:{this.resetControllersRP15Compliant();break}case u.sustainPedal:{if(e<64){let s=0;if(this.voiceCount>0){for(let n of this.synthCore.voices)if(n.channel===this.channel&&n.isActive&&n.isHeld&&(n.isHeld=!1,n.releaseVoice(this.synthCore.currentTime),++s>=this.voiceCount))break}}break}default:{this.computeModulatorsAll(1,A);break}}t&&this.synthCore.callEvent("controllerChange",{channel:this.channel,controllerNumber:A,controllerValue:e})}}var ao=40;function io(A){if(A<1)return 0;{let e=[1,2,4,8,16,32,64,80,96,112,120,124],t=[1,.5,.25,.125,.0625,.03125,.0625,.0625,.0625,.125,.25,1/3],s=[-.16653127382501215,.11863875218299408,.029479047361245264,-.005442312089231738,.1451520875973037,-.005056281449558275,-.005095486882876532,.03334009551111544,-.09361368678020432,.14132569702451822,-.15805565301011382,-.09918856955881927],n=[.028212773333433472,-.3388502064992847,-.15839529890929713,-.12398131766775483,-.2874848552685111,.012254866302537692,.005957797193345771,-.03745899330347374,.12911781869810196,-.15867193224162568,.504406322732748,.3786845131875458],a=[.7218950861255283,.5574536226347168,.47133893237025826,.48597095327079914,.44336276333518854,.6076986311801551,.30851975971827794,.30514889345633955,.3302511933827384,.153822885219165,.1302280559047337,.49865530675491687],o=[-2.2218487496163566,-1.6382721639824072,-1.3010299956639813,-.958607314841775,-.6020599913279624,-.3010299956639812,.31386722036915343,.6232492903979004,.9242792860618817,1.290034611362518,1.4265112613645752,1.9030899869919435],i=[2,4,8,16,32,64,80,96,112,120,124],r=-1;for(let I=i.length-1;I>=0;I--)if(i[I]<A){r=I;break}r+=1;let h=(A-e[r])*t[r];return Math.exp(2.302585092994046*(((s[r]*h+n[r])*h+a[r])*h+o[r]))/ao}}function ro(A,e){return io(A)*e}var Xt=(A,e,t)=>Math.max(e,Math.min(t,A));function oo(A,e){if(e<1){this.noteOff(A);return}if(e=Math.min(127,e),this.synthCore.masterParameters.blackMIDIMode&&this.synthCore.voiceCount>200&&e<40||this.synthCore.masterParameters.blackMIDIMode&&e<10||this._isMuted||!this.preset)return;let t=A+this.keyShift+this.customControllers[Ce.channelKeyShift],s=t;if(t>127||t<0)return;let n=this.preset.program,a=this.synthCore.tunings[n*128+t];a>=0&&(s=Math.trunc(a)),this.synthCore.masterParameters.monophonicRetriggerMode&&this.killNote(A);let o=this.synthCore.keyModifierManager.getVelocity(this.channel,t);o>-1&&(e=o);let i=this.synthCore.keyModifierManager.getGain(this.channel,t),r=-1,h=0,I=this.midiControllers[u.portamentoTime]>>7,c=this.midiControllers[u.portamentoControl]>>7;if(!this.drumChannel&&c!==s&&this.midiControllers[u.portamentoOnOff]>=8192&&I>0){if(c>0){let b=Math.abs(s-c);h=ro(I,b),r=c}this.controllerChange(u.portamentoControl,s)}if(!this.polyMode){let b=0;if(this.voiceCount>0){for(let k of this.synthCore.voices)if(k.isActive&&k.channel===this.channel&&(k.exclusiveRelease(this.synthCore.currentTime,0),++b>=this.voiceCount))break}}let l=this.synthCore.getVoices(this.channel,s,e),B=0,d=0,p=0,w=1,G=1,F=1;if(this.randomPan&&(B=Math.round(Math.random()*1e3-500)),this.drumChannel){let b=this.drumParams[s];if(!b.rxNoteOn)return;let k=b.pan;if(k!==64){let O=Math.max(-63,Math.min(k-64+((this.midiControllers[u.pan]>>7)-64),63))||1;B=k===0?Math.round(Math.random()*1e3-500):O/63*500}p=b.pitch,d=b.exclusiveClass,w=b.reverbGain,G=b.chorusGain,F=b.delayGain,i===1&&(i=b.gain)}for(let b of l){let k=this.synthCore.assignVoice();if(k.setup(this.synthCore.currentTime,this.channel,s,e,t),k.wavetable=k.oscillators[this.synthCore.masterParameters.interpolationType],k.generators.set(b.generators),k.exclusiveClass=d||b.exclusiveClass,k.rootKey=b.rootKey,k.loopingMode=b.loopingMode,k.wavetable.sampleData=b.sampleData,k.wavetable.playbackStep=b.playbackStep,k.targetKey=b.targetKey,this.sysExModulators.modulatorList.length>0){k.modulators=[...b.modulators];for(let M of this.sysExModulators.modulatorList){let U=k.modulators.findIndex(K=>Re.isIdentical(K,M.mod));U===-1?k.modulators.push(M.mod):k.modulators[U]=M.mod}}else k.modulators=b.modulators;if(k.modulators.length>k.modulatorValues.length&&(se(`${k.modulators.length} modulators! Increasing modulatorValues table.`),k.modulatorValues=new Int16Array(k.modulators.length)),this.generatorOverridesEnabled)for(let[M,U]of this.generatorOverrides.entries())U!==Ra&&(k.generators[M]=U);if(k.exclusiveClass!==0&&this.polyMode){let M=0;if(this.voiceCount>0){for(let U of this.synthCore.voices)if(U.isActive&&U.channel===this.channel&&U.exclusiveClass===k.exclusiveClass&&U.hasRendered&&(U.exclusiveRelease(this.synthCore.currentTime),++M>=this.voiceCount))break}}this.computeModulators(k),k.volEnv.init(k),k.modEnv.init(k),k.filter.init();let O=k.modulatedGenerators[g.startAddrsOffset]+k.modulatedGenerators[g.startAddrsCoarseOffset]*32768,C=k.modulatedGenerators[g.endAddrOffset]+k.modulatedGenerators[g.endAddrsCoarseOffset]*32768,Y=k.modulatedGenerators[g.startloopAddrsOffset]+k.modulatedGenerators[g.startloopAddrsCoarseOffset]*32768,q=k.modulatedGenerators[g.endloopAddrsOffset]+k.modulatedGenerators[g.endloopAddrsCoarseOffset]*32768,x=b.sampleData.length-1;if(k.wavetable.cursor=Xt(O,0,x),k.wavetable.end=Xt(x+C,0,x),k.wavetable.loopStart=Xt(b.loopStart+Y,0,x),k.wavetable.loopEnd=Xt(b.loopEnd+q,0,x),k.wavetable.loopEnd<k.wavetable.loopStart){let M=k.wavetable.loopStart;k.wavetable.loopStart=k.wavetable.loopEnd,k.wavetable.loopEnd=M}k.wavetable.loopEnd-k.wavetable.loopStart<1&&(k.loopingMode===1||k.loopingMode===3)&&(k.loopingMode=0),k.wavetable.loopLength=k.wavetable.loopEnd-k.wavetable.loopStart,k.wavetable.isLooping=k.loopingMode===1||k.loopingMode===3,k.portamentoFromKey=r,k.portamentoDuration=h,k.overridePan=B,k.gainModifier=i,k.pitchOffset=p,k.reverbSend=w,k.chorusSend=G,k.delaySend=F,k.currentPan=Math.max(-500,Math.min(500,B||k.modulatedGenerators[g.pan]))}this.voiceCount+=l.length,this.sendChannelProperty(),this.synthCore.callEvent("noteOn",{midiNote:A,channel:this.channel,velocity:e})}function ho(A){if(A>127||A<0){se("Received a noteOn for note",A,"Ignoring.");return}let e=A+this.keyShift+this.customControllers[Ce.channelKeyShift];if(this.synthCore.masterParameters.blackMIDIMode&&!this.drumChannel||this.drumChannel&&this.drumParams[e].rxNoteOff){this.killNote(e),this.synthCore.callEvent("noteOff",{midiNote:A,channel:this.channel});return}let t=this.midiControllers[u.sustainPedal]>=8192,s=0;if(this.voiceCount>0){for(let n of this.synthCore.voices)if(n.channel===this.channel&&n.isActive&&n.realKey===e&&!n.isInRelease&&(t?n.isHeld=!0:n.releaseVoice(this.synthCore.currentTime),++s>=this.voiceCount))break}this.synthCore.callEvent("noteOff",{midiNote:A,channel:this.channel})}function go(A){if(this.lockPreset)return;this.patch.program=A;let e=this.synthCore.soundBankManager.getPreset(this.patch,this.channelSystem);!e&&(e=this.synthCore.missingPresetHandler(this.patch,this.channelSystem),!e)||(this.preset=e,e.isAnyDrums!==this.drumChannel&&this.setDrumFlag(e.isAnyDrums),this.resetDrumParams(),this.synthCore.callEvent("programChange",{channel:this.channel,bankLSB:this.preset.bankLSB,bankMSB:this.preset.bankMSB,program:this.preset.program,isGMGSDrum:this.preset.isGMGSDrum}),this.sendChannelProperty())}var Io=class{modulatorList=[];resetModulators(){this.modulatorList=[]}setModulator(A,e,t,s=!1,n=!1){let a=this.getModulatorID(A,e,s,n);t===0&&this.deleteModulator(a);let o=this.modulatorList.find(i=>i.id===a);if(o)o.mod.transformAmount=t;else{let i,r;A>=ve?(i=A-ve,r=!1):(i=A,r=!0);let h=new Re(new cA(i,me.linear,r,s),new cA,e,t,0);this.modulatorList.push({mod:h,id:a})}}getModulatorID(A,e,t,s){return`${A}-${e}-${t}-${s}`}deleteModulator(A){this.modulatorList=this.modulatorList.filter(e=>e.id!==A)}};function co(A,e=-1,t=0){let s=A.modulators,n=A.generators;if(this.generatorOffsetsEnabled){n=new Int16Array(n);for(let r=0;r<n.length;r++)n[r]+=this.generatorOffsets[r]}let a=A.modulatedGenerators,o=this.perNotePitch?this.pitchWheels[A.realKey]:this.midiControllers[Ae.pitchWheel+ve];if(e===-1){a.set(n);for(let r=0;r<s.length;r++){let h=s[r];a[h.destination]=Math.min(32767,Math.max(-32768,a[h.destination]+A.computeModulator(this.midiControllers,o,r)))}for(let r=0;r<a.length;r++){let h=oA[r];h&&(a[r]=Math.min(h.max,Math.max(h.min,a[r])))}return}let i=!!e;for(let r=0;r<s.length;r++){let h=s[r];if(h.primarySource.isCC===i&&h.primarySource.index===t||h.secondarySource.isCC===i&&h.secondarySource.index===t){let I=h.destination,c=n[I];A.computeModulator(this.midiControllers,o,r);for(let B=0;B<s.length;B++)s[B].destination===I&&(c+=A.modulatorValues[B]);let l=oA[I];a[I]=Math.max(l.min,Math.min(c,l.max))}}}var lo=class{midiControllers=new Int16Array($s);pitchWheels=new Int16Array(128).fill(8192);lockedControllers=new Array($s).fill(!1);customControllers=new Float32Array(Ua);octaveTuning=new Int8Array(128);drumParams=[];sysExModulators=new Io;keyShift=0;drumChannel=!1;randomPan=!1;insertionEnabled=!1;cc1=16;cc2=17;drumMap=0;dataEntryState=$e.Idle;patch={bankMSB:0,bankLSB:0,program:0,isGMGSDrum:!1};preset;lockPreset=!1;lockedSystem="gs";channelVibrato={delay:0,depth:0,rate:0};polyMode=!0;voiceCount=0;channel;rxChannel;synthCore;noteOn=oo.bind(this);noteOff=ho.bind(this);programChange=go.bind(this);controllerChange=no.bind(this);resetControllers=Qr.bind(this);resetPreset=fr.bind(this);resetControllersRP15Compliant=ur.bind(this);resetParameters=mr.bind(this);dataEntryFine=so.bind(this);dataEntryCoarse=jr.bind(this);renderVoice=$r.bind(this);perNotePitch=!1;channelTuningCents=0;generatorOffsets=new Int16Array(ot);generatorOffsetsEnabled=!1;generatorOverrides=new Int16Array(ot);generatorOverridesEnabled=!1;computeModulators=co.bind(this);previousVoiceCount=0;constructor(A,e,t){this.synthCore=A,this.preset=e,this.channel=t,this.rxChannel=t,this.resetGeneratorOverrides(),this.resetGeneratorOffsets();for(let s=0;s<128;s++)this.drumParams.push(new js);this.resetDrumParams(),this.resetVibratoParams()}_isMuted=!1;get isMuted(){return this._isMuted}get channelSystem(){return this.lockPreset?this.lockedSystem:this.synthCore.masterParameters.midiSystem}clearVoiceCount(){this.previousVoiceCount=this.voiceCount,this.voiceCount=0}updateVoiceCount(){this.voiceCount!==this.previousVoiceCount&&this.sendChannelProperty()}transposeChannel(A,e=!1){this.drumChannel||(A+=this.synthCore.masterParameters.transposition);let t=Math.trunc(A),s=this.keyShift+this.customControllers[Ce.channelTransposeFine]/100;this.drumChannel&&!e||A===s||(t!==this.keyShift&&this.stopAllNotes(),this.keyShift=t,this.setCustomController(Ce.channelTransposeFine,(A-t)*100),this.sendChannelProperty())}setOctaveTuning(A){if(A.length!==12)throw new Error("Tuning is not the length of 12.");for(let e=0;e<128;e++)this.octaveTuning[e]=A[e%12]}setModulationDepth(A){A=Math.round(A),D(`%cChannel ${this.channel} modulation depth. Cents: %c${A}`,E.info,E.value),this.setCustomController(Ce.modulationMultiplier,A/50)}setTuning(A,e=!0){A=Math.round(A),this.setCustomController(Ce.channelTuning,A),e&&D(`%cFine tuning for %c${this.channel}%c is now set to %c${A}%c cents.`,E.info,E.recognized,E.info,E.value,E.info)}pitchWheel(A,e=-1){if(!this.lockedControllers[ve+Ae.pitchWheel]){if(e===-1)this.perNotePitch=!1,this.midiControllers[ve+Ae.pitchWheel]=A,this.computeModulatorsAll(0,Ae.pitchWheel),this.sendChannelProperty();else{this.perNotePitch||this.pitchWheels.fill(this.midiControllers[ve+Ae.pitchWheel]),this.perNotePitch=!0,this.pitchWheels[e]=A;let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.isActive&&s.channel===this.channel&&s.midiNote===e&&(this.computeModulators(s,0,Ae.polyPressure),++t>=this.voiceCount))break}}this.synthCore.callEvent("pitchWheel",{channel:this.channel,pitch:A,midiNote:e})}}channelPressure(A){this.midiControllers[ve+Ae.channelPressure]=A<<7,this.updateChannelTuning(),this.computeModulatorsAll(0,Ae.channelPressure),this.synthCore.callEvent("channelPressure",{channel:this.channel,pressure:A})}polyPressure(A,e){let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.isActive&&s.channel===this.channel&&s.midiNote===A&&(s.pressure=e,this.computeModulators(s,0,Ae.polyPressure),++t>=this.voiceCount))break}this.synthCore.callEvent("polyPressure",{channel:this.channel,midiNote:A,pressure:e})}setCustomController(A,e){this.customControllers[A]=e,this.updateChannelTuning()}updateChannelTuning(){this.channelTuningCents=this.customControllers[Ce.channelTuning]+this.customControllers[Ce.channelTransposeFine]+this.customControllers[Ce.masterTuning]+this.customControllers[Ce.channelTuningSemitones]*100}setPresetLock(A){this.lockPreset!==A&&(this.lockPreset=A,A&&(this.lockedSystem=this.synthCore.masterParameters.midiSystem))}setDrums(A){if(Fe.isSystemXG(this.channelSystem))if(A)this.setBankMSB(Fe.getDrumBank(this.channelSystem)),this.setBankLSB(0);else{if(this.channel%16===FA)throw new Error(`Cannot disable drums on channel ${this.channel} for XG.`);this.setBankMSB(0),this.setBankLSB(0)}else this.setGSDrums(A);this.setDrumFlag(A),this.programChange(this.patch.program)}setPatch(A){this.setBankMSB(A.bankMSB),this.setBankLSB(A.bankLSB),this.setGSDrums(A.isGMGSDrum),this.programChange(A.program)}setGSDrums(A){A!==this.patch.isGMGSDrum&&(this.setBankLSB(0),this.setBankMSB(0),this.patch.isGMGSDrum=A)}resetGeneratorOverrides(){this.generatorOverrides.fill(Ra),this.generatorOverridesEnabled=!1}setGeneratorOverride(A,e,t=!1){if(this.generatorOverrides[A]=e,this.generatorOverridesEnabled=!0,t){let s=0;if(this.voiceCount>0){for(let n of this.synthCore.voices)if(n.channel===this.channel&&n.isActive&&(n.generators[A]=e,this.computeModulators(n),++s>=this.voiceCount))break}}}resetGeneratorOffsets(){this.generatorOffsets.fill(0),this.generatorOffsetsEnabled=!1}setGeneratorOffset(A,e){this.generatorOffsets[A]=e*oA[A].nrpn,this.generatorOffsetsEnabled=!0;let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.channel===this.channel&&s.isActive&&(this.computeModulators(s),++t>=this.voiceCount))break}}killNote(A,e=-12e3){A+=this.customControllers[Ce.channelKeyShift];let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.channel===this.channel&&s.isActive&&s.realKey===A&&(s.overrideReleaseVolEnv=e,s.isInRelease=!1,s.releaseVoice(this.synthCore.currentTime),++t>=this.voiceCount))break}}stopAllNotes(A=!1){if(A){let e=0;if(this.voiceCount>0){for(let t of this.synthCore.voices)if(t.channel===this.channel&&t.isActive&&(t.isActive=!1,++e>=this.voiceCount))break}this.clearVoiceCount(),this.updateVoiceCount()}else{let e=0;if(this.voiceCount>0){for(let t of this.synthCore.voices)if(t.channel===this.channel&&t.isActive&&(t.releaseVoice(this.synthCore.currentTime),++e>=this.voiceCount))break}}this.synthCore.callEvent("stopAll",{channel:this.channel,force:A})}muteChannel(A){A&&this.stopAllNotes(!0),this._isMuted=A,this.sendChannelProperty(),this.synthCore.callEvent("muteChannel",{channel:this.channel,isMuted:A})}sendChannelProperty(){if(!this.synthCore.enableEventSystem)return;let A={voicesAmount:this.voiceCount,pitchWheel:this.midiControllers[ve+Ae.pitchWheel],pitchWheelRange:this.midiControllers[ve+Ae.pitchWheelRange]/128,isMuted:this.isMuted,transposition:this.keyShift+this.customControllers[Ce.channelTransposeFine]/100,isDrum:this.drumChannel,isEFX:this.insertionEnabled};this.synthCore.callEvent("channelPropertyChange",{channel:this.channel,property:A})}resetDrumParams(){if(!(this.synthCore.masterParameters.drumLock||!this.drumChannel))for(let A=0;A<128;A++){let e=this.drumParams[A];e.pitch=0,e.gain=1,e.exclusiveClass=0,e.pan=64,e.reverbGain=wn[A]/127,e.chorusGain=0,e.delayGain=0,e.rxNoteOn=!0,e.rxNoteOff=!1}}resetVibratoParams(){this.synthCore.masterParameters.customVibratoLock||(this.channelVibrato.rate=0,this.channelVibrato.depth=0,this.channelVibrato.delay=0)}computeModulatorsAll(A,e){let t=0;if(this.voiceCount>0){for(let s of this.synthCore.voices)if(s.channel===this.channel&&s.isActive&&(this.computeModulators(s,A,e),++t>=this.voiceCount))break}}setBankMSB(A){this.lockPreset||(this.patch.bankMSB=A)}setBankLSB(A){this.lockPreset||(this.patch.bankLSB=A)}setDrumFlag(A){this.lockPreset||!this.preset||this.drumChannel!==A&&(A?(this.keyShift=0,this.drumChannel=!0):this.drumChannel=!1,this.synthCore.callEvent("drumChange",{channel:this.channel,isDrumChannel:this.drumChannel}))}},sa=4,He=class{generatorType;generatorValue=0;constructor(A,e,t=!0){if(this.generatorType=A,e===void 0)throw new Error("No value provided.");if(this.generatorValue=Math.round(e),t){let s=oA[A];s!==void 0&&(this.generatorValue=Math.max(s.min,Math.min(s.max,this.generatorValue)))}}write(A){te(A,this.generatorType),te(A,this.generatorValue)}toString(){return`${Object.keys(g).find(A=>g[A]===this.generatorType)}: ${this.generatorValue}`}},Co=4,ls=class{velRange={min:-1,max:127};keyRange={min:-1,max:127};generators=[];modulators=[];get hasKeyRange(){return this.keyRange.min!==-1}get hasVelRange(){return this.velRange.min!==-1}get fineTuning(){let A=this.getGenerator(g.coarseTune,0),e=this.getGenerator(g.fineTune,0);return A*100+e}set fineTuning(A){let e=Math.trunc(A/100),t=A%100;this.setGenerator(g.coarseTune,e),this.setGenerator(g.fineTune,t)}addToGenerator(A,e,t=!0){let s=this.getGenerator(A,oA[A].def);this.setGenerator(A,e+s,t)}setGenerator(A,e,t=!0){switch(A){case g.sampleID:throw new Error("Use setSample()");case g.instrument:throw new Error("Use setInstrument()");case g.velRange:case g.keyRange:throw new Error("Set the range manually")}if(e===null){this.generators=this.generators.filter(n=>n.generatorType!==A);return}let s=this.generators.findIndex(n=>n.generatorType===A);s===-1?this.addGenerators(new He(A,e,t)):this.generators[s]=new He(A,e,t)}addGenerators(...A){for(let e of A)switch(e.generatorType){default:{this.generators.push(e);break}case g.sampleID:case g.instrument:break;case g.velRange:{this.velRange.min=e.generatorValue&127,this.velRange.max=e.generatorValue>>8&127;break}case g.keyRange:this.keyRange.min=e.generatorValue&127,this.keyRange.max=e.generatorValue>>8&127}}addModulators(...A){this.modulators.push(...A)}getGenerator(A,e){return this.generators.find(t=>t.generatorType===A)?.generatorValue??e}copyFrom(A){this.generators=A.generators.map(e=>new He(e.generatorType,e.generatorValue,!1)),this.modulators=A.modulators.map(Re.copyFrom.bind(Re)),this.velRange={...A.velRange},this.keyRange={...A.keyRange}}getWriteGenerators(A){let e=this.generators.filter(t=>t.generatorType!==g.sampleID&&t.generatorType!==g.instrument&&t.generatorType!==g.keyRange&&t.generatorType!==g.velRange);if(!A)throw new Error("No bank provided! ");return this.hasVelRange&&e.unshift(new He(g.velRange,this.velRange.max<<8|Math.max(this.velRange.min,0),!1)),this.hasKeyRange&&e.unshift(new He(g.keyRange,this.keyRange.max<<8|Math.max(this.keyRange.min,0),!1)),e}},$a=class extends ls{},ja=class extends ls{parentPreset;constructor(A,e){super(),this.parentPreset=A,this._instrument=e,this._instrument.linkTo(this.parentPreset)}_instrument;get instrument(){return this._instrument}set instrument(A){this._instrument&&this._instrument.unlinkFrom(this.parentPreset),this._instrument=A,this._instrument.linkTo(this.parentPreset)}getWriteGenerators(A){let e=super.getWriteGenerators(A);if(!A)throw new Error("Instrument ID cannot be determined without the sound bank itself.");let t=A.instruments.indexOf(this.instrument);if(t===-1)throw new Error(`${this.instrument.name} does not exist in ${A.soundBankInfo.name}! Cannot write instrument generator.`);return e.push(new He(g.instrument,t,!1)),e}},ei=class extends ls{parentInstrument;useCount;constructor(A,e){super(),this.parentInstrument=A,this._sample=e,e.linkTo(this.parentInstrument),this.useCount=A.useCount}_sample;get sample(){return this._sample}set sample(A){this._sample&&this._sample.unlinkFrom(this.parentInstrument),this._sample=A,A.linkTo(this.parentInstrument)}getWriteGenerators(A){let e=super.getWriteGenerators(A),t=A.samples.indexOf(this.sample);if(t===-1)throw new Error(`${this.sample.name} does not exist in ${A.soundBankInfo.name}! Cannot write sampleID generator.`);return e.push(new He(g.sampleID,t,!1)),e}},Eo=22,Bo=new Set([g.velRange,g.keyRange,g.instrument,g.sampleID,g.exclusiveClass,g.endOper,g.sampleModes,g.startloopAddrsOffset,g.startloopAddrsCoarseOffset,g.endloopAddrsOffset,g.endloopAddrsCoarseOffset,g.startAddrsOffset,g.startAddrsCoarseOffset,g.endAddrOffset,g.endAddrsCoarseOffset,g.initialAttenuation,g.fineTune,g.coarseTune,g.keyNumToVolEnvHold,g.keyNumToVolEnvDecay,g.keyNumToModEnvHold,g.keyNumToModEnvDecay]),Ft=class{name="";zones=[];globalZone=new $a;linkedTo=[];get useCount(){return this.linkedTo.length}createZone(A){let e=new ei(this,A);return this.zones.push(e),e}linkTo(A){this.linkedTo.push(A);for(let e of this.zones)e.useCount++}unlinkFrom(A){let e=this.linkedTo.indexOf(A);if(e===-1){se(`Cannot unlink ${A.name} from ${this.name}: not linked.`);return}this.linkedTo.splice(e,1);for(let t of this.zones)t.useCount--}deleteUnusedZones(){this.zones=this.zones.filter(A=>{let e=A.useCount>0;return e||A.sample.unlinkFrom(this),e})}delete(){if(this.useCount>0)throw new Error(`Cannot delete an instrument that is used by: ${this.linkedTo.map(A=>A.name).toString()}.`);for(let A of this.zones)A.sample.unlinkFrom(this)}deleteZone(A,e=!1){let t=this.zones[A];return t.useCount-=1,t.useCount<1||e?(t.sample.unlinkFrom(this),this.zones.splice(A,1),!0):!1}globalize(){let A=this.globalZone;for(let s=0;s<58;s++){if(Bo.has(s))continue;s=s;let n={},a=oA[s]?.def||0;n[a]=0;for(let o of this.zones){let i=o.getGenerator(s,void 0);i===void 0?n[a]++:n[i]===void 0?n[i]=1:n[i]++;let r;switch(s){default:continue;case g.decayVolEnv:{r=g.keyNumToVolEnvDecay;break}case g.holdVolEnv:{r=g.keyNumToVolEnvHold;break}case g.decayModEnv:{r=g.keyNumToModEnvDecay;break}case g.holdModEnv:r=g.keyNumToModEnvHold}if(o.getGenerator(r,void 0)!==void 0){n={};break}}if(Object.keys(n).length>0){let o=["0",0];for(let[r,h]of Object.entries(n))h>o[1]&&(o=[r,h]);let i=Number.parseInt(o[0]);i!==a&&A.setGenerator(s,i,!1);for(let r of this.zones){let h=r.getGenerator(s,void 0);h===void 0?i!==a&&r.setGenerator(s,a):h===i&&r.setGenerator(s,null)}}}let t=this.zones[0].modulators.map(s=>Re.copyFrom(s));for(let s of t){let n=!0;for(let a of this.zones){if(!n)continue;a.modulators.find(i=>Re.isIdentical(i,s))||(n=!1)}if(n){A.addModulators(Re.copyFrom(s));for(let a of this.zones){let o=a.modulators.find(i=>Re.isIdentical(i,s));o&&o.transformAmount===s.transformAmount&&a.modulators.splice(a.modulators.indexOf(o),1)}}}}write(A,e){D(`%cWriting ${this.name}...`,E.info),Te(A.pdta,this.name.slice(0,20),20),Te(A.xdta,this.name.slice(20),20),te(A.pdta,e&65535),te(A.xdta,e>>>16)}},Qo=38,Rt=class dA{parentSoundBank;name="";program=0;bankMSB=0;bankLSB=0;isGMGSDrum=!1;zones=[];globalZone;library=0;genre=0;morphology=0;constructor(e,t=new $a){this.parentSoundBank=e,this.globalZone=t}get isXGDrums(){return this.parentSoundBank.isXGBank&&Fe.isXGDrums(this.bankMSB)}get isAnyDrums(){let e=this.parentSoundBank.isXGBank;return this.isGMGSDrum||e&&Fe.isXGDrums(this.bankMSB)}static isInRange(e,t){return t>=e.min&&t<=e.max}static addUniqueModulators(e,t){for(let s of t)e.some(n=>Re.isIdentical(s,n))||e.push(s)}static subtractRanges(e,t){return{min:Math.max(e.min,t.min),max:Math.min(e.max,t.max)}}delete(){for(let e of this.zones)e.instrument?.unlinkFrom(this)}deleteZone(e){this.zones[e]?.instrument?.unlinkFrom(this),this.zones.splice(e,1)}createZone(e){let t=new ja(this,e);return this.zones.push(t),t}preload(e,t){for(let s=e;s<t+1;s++)for(let n=0;n<128;n++)for(let a of this.getVoiceParameters(s,n))a.sample.getAudioData()}matches(e){return CA.matches(this,e)}getVoiceParameters(e,t){let s=new Array;for(let n of this.zones){if(!dA.isInRange(n.hasKeyRange?n.keyRange:this.globalZone.keyRange,e)||!dA.isInRange(n.hasVelRange?n.velRange:this.globalZone.velRange,t))continue;let a=n.instrument;if(!a||a.zones.length===0)continue;let o=new Int16Array(ot);for(let r of this.globalZone.generators)o[r.generatorType]=r.generatorValue;for(let r of n.generators)o[r.generatorType]=r.generatorValue;let i=[...n.modulators];dA.addUniqueModulators(i,this.globalZone.modulators);for(let r of a.zones){if(!dA.isInRange(r.hasKeyRange?r.keyRange:a.globalZone.keyRange,e)||!dA.isInRange(r.hasVelRange?r.velRange:a.globalZone.velRange,t))continue;let h=[...r.modulators];dA.addUniqueModulators(h,a.globalZone.modulators),dA.addUniqueModulators(h,this.parentSoundBank.defaultModulators);for(let c of i){let l=h.findIndex(B=>Re.isIdentical(c,B));l===-1?h.push(c):h[l]=h[l].sumTransform(c)}let I=new Int16Array(_s);for(let c of a.globalZone.generators)I[c.generatorType]=c.generatorValue;for(let c of r.generators)I[c.generatorType]=c.generatorValue;for(let c=0;c<I.length;c++)I[c]=Math.max(-32768,Math.min(32767,I[c]+o[c]));I[g.initialAttenuation]=Math.floor(I[g.initialAttenuation]*.4),s.push({sample:r.sample,generators:I,modulators:h})}}return s}toMIDIString(){return CA.toMIDIString(this)}toString(){return CA.toNamedMIDIString(this)}toFlattenedInstrument(){let e=(h,I)=>{h.push(...I.filter(c=>!h.some(l=>l.generatorType===c.generatorType)))},t=(h,I)=>{h.push(...I.filter(c=>!h.some(l=>Re.isIdentical(c,l))))},s=new Ft;s.name=this.name;let n=[],a=[],o=this.globalZone;n.push(...o.generators),a.push(...o.modulators);let i=o.keyRange,r=o.velRange;for(let h of this.zones){if(!h.instrument)throw new Error("No instrument in a preset zone.");let I=h.keyRange;h.hasKeyRange||(I=i);let c=h.velRange;h.hasVelRange||(c=r);let l=h.generators.map(O=>new He(O.generatorType,O.generatorValue));e(l,n);let B=[...h.modulators];t(B,a);let d=h.instrument,p=d.zones,w=[],G=[],F=d.globalZone;w.push(...F.generators),G.push(...F.modulators);let b=F.keyRange,k=F.velRange;for(let O of p){if(!O.sample)throw new Error("No sample in an instrument zone.");let C=O.keyRange;O.hasKeyRange||(C=b);let Y=O.velRange;if(O.hasVelRange||(Y=k),C=dA.subtractRanges(C,I),Y=dA.subtractRanges(Y,c),C.max<C.min||Y.max<Y.min)continue;let q=O.generators.map(S=>new He(S.generatorType,S.generatorValue));e(q,w);let x=[...O.modulators];t(x,G);let M=[...x];for(let S of B){let T=M.findIndex(P=>Re.isIdentical(S,P));T===-1?M.push(S):M[T]=M[T].sumTransform(S)}let U=q.map(S=>new He(S.generatorType,S.generatorValue));for(let S of l){if(S.generatorType===g.velRange||S.generatorType===g.keyRange||S.generatorType===g.instrument||S.generatorType===g.endOper||S.generatorType===g.sampleModes)continue;let T=q.findIndex(P=>P.generatorType===S.generatorType);if(T===-1){let P=oA[S.generatorType].def+S.generatorValue;U.push(new He(S.generatorType,P))}else{let P=U[T].generatorValue+S.generatorValue;U[T]=new He(S.generatorType,P)}}U=U.filter(S=>S.generatorType!==g.sampleID&&S.generatorType!==g.keyRange&&S.generatorType!==g.velRange&&S.generatorType!==g.endOper&&S.generatorType!==g.instrument&&S.generatorValue!==oA[S.generatorType].def);let K=s.createZone(O.sample);K.keyRange=C,K.velRange=Y,K.keyRange.min===0&&K.keyRange.max===127&&(K.keyRange.min=-1),K.velRange.min===0&&K.velRange.max===127&&(K.velRange.min=-1),K.addGenerators(...U),K.addModulators(...M)}}return s}write(e,t){D(`%cWriting ${this.name}...`,E.info),Te(e.pdta,this.name.slice(0,20),20),Te(e.xdta,this.name.slice(20),20),te(e.pdta,this.program);let s=this.bankMSB;this.isGMGSDrum?s=128:this.bankMSB===0&&(s=this.bankLSB),te(e.pdta,s),e.xdta.currentIndex+=4,te(e.pdta,t&65535),te(e.xdta,t>>16),Be(e.pdta,this.library),Be(e.pdta,this.genre),Be(e.pdta,this.morphology),e.xdta.currentIndex+=12}};function na(A,e){let t=e?A.find(s=>s.isXGDrums):A.find(s=>s.isGMGSDrum);return t||(A.find(s=>s.isAnyDrums)??A[0])}function Ai(A,e,t){if(A.length===0)throw new Error("No presets!");e.isGMGSDrum&&Fe.isSystemXG(t)&&(e={...e,isGMGSDrum:!1,bankLSB:0,bankMSB:Fe.getDrumBank(t)});let{isGMGSDrum:s,bankLSB:n,bankMSB:a,program:o}=e,i=Fe.isSystemXG(t),r=Fe.isXGDrums(a)&&i,h=A.find(l=>l.matches(e));if(h&&(!r||r&&h.isXGDrums))return h;let I=l=>{D(`%cPreset %c${CA.toMIDIString(e)}%c not found. (${t}) Replaced with %c${l.toString()}`,E.warn,E.unrecognized,E.warn,E.value)};if(s){let l=A.find(B=>B.isGMGSDrum&&B.program===o);return l||(l=A.find(B=>B.isAnyDrums&&B.program===o),l)?(I(l),l):(l=na(A,!1),I(l),l)}if(r){let l=A.find(B=>B.program===o&&B.isXGDrums);return l||(l=A.find(B=>B.isAnyDrums&&B.program===o),l)?(I(l),l):(l=na(A,!0),I(l),l)}let c=A.filter(l=>l.program===o&&!l.isAnyDrums);if(c.length===0)return I(A[0]),A[0];if(h=i?c.find(l=>l.bankLSB===n):c.find(l=>l.bankMSB===a),h)return I(h),h;if(n!==64||!i){let l=Math.max(a,n);if(h=c.find(B=>B.bankLSB===l||B.bankMSB===l),h)return I(h),h}return I(c[0]),c[0]}var fo=class extends Rt{constructor(A,e){super(A.parentSoundBank,A.globalZone),this.bankMSB=Fe.addBankOffset(A.bankMSB,e,A.isXGDrums),this.name=A.name,this.bankLSB=A.bankLSB,this.isGMGSDrum=A.isGMGSDrum,this.program=A.program,this.genre=A.genre,this.morphology=A.morphology,this.library=A.library,this.zones=A.zones}},uo=class{soundBankList=[];presetListChangeCallback;selectablePresetList=[];constructor(A){this.presetListChangeCallback=A}_presetList=[];get presetList(){return[...this._presetList]}get priorityOrder(){return this.soundBankList.map(A=>A.id)}set priorityOrder(A){this.soundBankList.sort((e,t)=>A.indexOf(e.id)-A.indexOf(t.id)),this.generatePresetList()}deleteSoundBank(A){if(this.soundBankList.length===0){se("1 soundbank left. Aborting!");return}let e=this.soundBankList.findIndex(t=>t.id===A);if(e===-1)throw new Error(`No sound bank with id "${A}"`);this.soundBankList.splice(e,1),this.generatePresetList()}addSoundBank(A,e,t=0){let s=this.soundBankList.find(n=>n.id===e);s===void 0?this.soundBankList.push({id:e,soundBank:A,bankOffset:t}):(s.soundBank=A,s.bankOffset=t),this.generatePresetList()}getPreset(A,e){if(!(this.soundBankList.length===0||this.selectablePresetList.length===0))return Ai(this.selectablePresetList,A,e)}destroy(){for(let A of this.soundBankList)A.soundBank.destroySoundBank();this.soundBankList=[]}generatePresetList(){let A=new Array,e=new Set;for(let t of this.soundBankList){let s=t.soundBank,n=t.bankOffset;for(let a of s.presets){let o=new fo(a,n);e.has(o.toMIDIString())||(e.add(o.toMIDIString()),A.push(o))}}A.sort(CA.sorter.bind(CA)),this.selectablePresetList=A,this._presetList=A.map(t=>({bankMSB:t.bankMSB,bankLSB:t.bankLSB,program:t.program,isGMGSDrum:t.isGMGSDrum,name:t.name,isAnyDrums:t.isAnyDrums})),this.presetListChangeCallback()}};function mo(A,e){switch(this.masterParameters[A]=e,A){default:break;case"masterPan":{let t=e;t=t/2+.5,this.panLeft=Math.cos(Math.PI/2*t),this.panRight=Math.sin(Math.PI/2*t);break}case"voiceCap":{let t=Math.min(e,1e6);this.masterParameters.voiceCap=t;for(let s=t;s<this.voices.length;s++)this.voices[s].isActive=!1;if(t>this.voices.length){se(`Allocating ${t-this.voices.length} new voices!`);for(let s=this.voices.length;s<t;s++)this.voices.push(new gn(this.sampleRate))}break}case"transposition":{let t=e;this.masterParameters.transposition=0;for(let s of this.midiChannels)s.transposeChannel(t);this.masterParameters.transposition=t}}this.callEvent("masterParameterChange",{parameter:A,value:e})}function po(A){return this.masterParameters[A]}function yo(){return{...this.masterParameters}}function DA(A,e,t,s){D(`%cChannel %c${A}%c ${t} is now set to %c${e} ${s}.`,E.info,E.recognized,E.info,E.value)}function qe(A,e){D(`%cUnrecognized %c${e} %cSysEx: %c${os(A)}`,E.warn,E.recognized,E.warn,E.unrecognized)}function aa(A,e,t){let s=A,n=e<<7|t;return A===127&&e===127&&t===127?-1:s+n*61e-6}function So(A,e=0){switch(A[2]){case 4:{let t;switch(A[3]){case 1:{let s=A[5]<<7|A[4];this.setMIDIVolume(s/16384),D(`%cMaster Volume. Volume: %c${s}`,E.info,E.value);break}case 2:{let n=((A[5]<<7|A[4])-8192)/8192;this.setMasterParameter("masterPan",n),D(`%cMaster Pan. Pan: %c${n}`,E.info,E.value);break}case 3:{let s=(A[5]<<7|A[6])-8192;t=Math.floor(s/81.92),this.setMasterTuning(t),D(`%cMaster Fine Tuning. Cents: %c${t}`,E.info,E.value);break}case 4:{t=(A[5]-64)*100,this.setMasterTuning(t),D(`%cMaster Coarse Tuning. Cents: %c${t}`,E.info,E.value);break}default:D(`%cUnrecognized MIDI Device Control Real-time message: %c${os(A)}`,E.warn,E.unrecognized)}break}case 9:{A[3]===1?(D("%cGM1 system on",E.info),this.resetAllControllers("gm")):A[3]===3?(D("%cGM2 system on",E.info),this.resetAllControllers("gm2")):(D("%cGM system off, defaulting to GS",E.info),this.setMasterParameter("midiSystem","gs"));break}case 8:{let t=4;switch(A[3]){case 1:{let s=A[t++],n=IA(A,16,t);if(t+=16,A.length<384){se(`The Bulk Tuning Dump is too short! (${A.length} bytes, at least 384 are expected)`);return}for(let a=0;a<128;a++)this.tunings[s*128+a]=aa(A[t++],A[t++],A[t++]);D(`%cBulk Tuning Dump %c${n}%c Program: %c${s}`,E.info,E.value,E.info,E.recognized);break}case 2:case 7:{A[3]===7&&t++;let s=A[t++],n=A[t++];for(let a=0;a<n;a++){let o=A[t++];this.tunings[s*128+o]=aa(A[t++],A[t++],A[t++])}D(`%cSingle Note Tuning. Program: %c${s}%c Keys affected: %c${n}`,E.info,E.recognized,E.info,E.recognized);break}case 9:case 8:{let s=new Int8Array(12);if(A[3]===8)for(let n=0;n<12;n++)s[n]=A[7+n]-64;else for(let n=0;n<24;n+=2){let a=(A[7+n]<<7|A[8+n])-8192;s[n/2]=Math.floor(a/81.92)}(A[4]&1)===1&&this.midiChannels[14+e].setOctaveTuning(s),(A[4]>>1&1)===1&&this.midiChannels[15+e].setOctaveTuning(s);for(let n=0;n<7;n++)(A[5]>>n&1)===1&&this.midiChannels[7+n+e].setOctaveTuning(s);for(let n=0;n<7;n++)(A[6]>>n&1)===1&&this.midiChannels[n+e].setOctaveTuning(s);D(`%cMIDI Octave Scale ${A[3]===8?"(1 byte)":"(2 bytes)"} tuning via Tuning: %c${s.join(" ")}`,E.info,E.value);break}default:{qe(A,"MIDI Tuning Standard");break}}break}default:qe(A,"General MIDI")}}var _=(A,e)=>{D(`%cRoland GS ${A}%c is now set to %c${e}%c.`,E.recognized,E.info,E.value,E.info)};function ko(A,e=0){if(A[3]===18)switch(A[2]){case 66:{let t=A[4],s=A[5],n=A[6],a=Math.min(A[7],127);if(t===0&&s===0&&n===127&&a===0){D("%cGS Reset received!",E.info),this.resetAllControllers("gs");return}if(t===64){if(s===0){switch(n){case 0:{let i=((a<<12|A[8]<<8|A[9]<<4|A[10])-1024)/10;this.setMasterTuning(i),_("Master Tune",i);break}case 4:{_("Master Volume",a);break}case 5:{let o=a-64;_("Master Key-Shift",o),this.setMasterTuning(o*100);break}case 6:{_("Master Pan",a),this.setMasterParameter("masterPan",(a-64)/64);break}case 127:{a===0?(D("%cGS Reset received!",E.info),this.resetAllControllers("gs")):a===127&&(D("%cGS system off, switching to GM",E.info),this.resetAllControllers("gm"));break}default:{qe(A,"Roland GS");break}}return}if(s===1){let o=n>=48&&n<=55,i=n>=56&&n<=64,r=n>=80&&n<=90;if(o&&this.masterParameters.reverbLock||i&&this.masterParameters.chorusLock||r&&this.masterParameters.delayLock)return;switch(this.delayActive||=n===64||r,n){default:{D(`%cUnsupported Patch Common parameter: %c${n.toString(16)}`,E.warn,E.unrecognized);break}case 0:{let h=IA(A,16,7);_(`Patch Name for ${n&15}`,h);break}case 48:{this.setReverbMacro(a),_("Reverb Macro",a);break}case 49:{this.reverbProcessor.character=a,_("Reverb Character",a),this.callEvent("effectChange",{effect:"reverb",parameter:"character",value:a});break}case 50:{this.reverbProcessor.preLowpass=a,_("Reverb Pre-LPF",a),this.callEvent("effectChange",{effect:"reverb",parameter:"preLowpass",value:a});break}case 51:{this.reverbProcessor.level=a,_("Reverb Level",a),this.callEvent("effectChange",{effect:"reverb",parameter:"level",value:a});break}case 52:{this.reverbProcessor.time=a,_("Reverb Time",a),this.callEvent("effectChange",{effect:"reverb",parameter:"time",value:a});break}case 53:{this.reverbProcessor.delayFeedback=a,_("Reverb Delay Feedback",a),this.callEvent("effectChange",{effect:"reverb",parameter:"delayFeedback",value:a});break}case 54:break;case 55:{this.reverbProcessor.preDelayTime=a,_("Reverb Predelay Time",a),this.callEvent("effectChange",{effect:"reverb",parameter:"preDelayTime",value:a});break}case 56:{this.setChorusMacro(a),_("Chorus Macro",a);break}case 57:{this.chorusProcessor.preLowpass=a,_("Pre-LPF",a),this.callEvent("effectChange",{effect:"chorus",parameter:"preLowpass",value:a});break}case 58:{this.chorusProcessor.level=a,_("Chorus Level",a),this.callEvent("effectChange",{effect:"chorus",parameter:"level",value:a});break}case 59:{this.chorusProcessor.feedback=a,_("Chorus Feedback",a),this.callEvent("effectChange",{effect:"chorus",parameter:"feedback",value:a});break}case 60:{this.chorusProcessor.delay=a,_("Chorus Delay",a),this.callEvent("effectChange",{effect:"chorus",parameter:"delay",value:a});break}case 61:{this.chorusProcessor.rate=a,_("Chorus Rate",a),this.callEvent("effectChange",{effect:"chorus",parameter:"rate",value:a});break}case 62:{this.chorusProcessor.depth=a,_("Chorus Depth",a),this.callEvent("effectChange",{effect:"chorus",parameter:"depth",value:a});break}case 63:{this.chorusProcessor.sendLevelToReverb=a,_("Chorus Send Level To Reverb",a),this.callEvent("effectChange",{effect:"chorus",parameter:"sendLevelToReverb",value:a});break}case 64:{this.chorusProcessor.sendLevelToDelay=a,_("Chorus Send Level To Delay",a),this.callEvent("effectChange",{effect:"chorus",parameter:"sendLevelToDelay",value:a});break}case 80:{this.setDelayMacro(a),_("Delay Macro",a);break}case 81:{this.delayProcessor.preLowpass=a,_("Delay Pre-LPF",a),this.callEvent("effectChange",{effect:"delay",parameter:"preLowpass",value:a});break}case 82:{this.delayProcessor.timeCenter=a,_("Delay Time Center",a),this.callEvent("effectChange",{effect:"delay",parameter:"timeCenter",value:a});break}case 83:{this.delayProcessor.timeRatioLeft=a,_("Delay Time Ratio Left",a),this.callEvent("effectChange",{effect:"delay",parameter:"timeRatioLeft",value:a});break}case 84:{this.delayProcessor.timeRatioRight=a,_("Delay Time Ratio Right",a),this.callEvent("effectChange",{effect:"delay",parameter:"timeRatioRight",value:a});break}case 85:{this.delayProcessor.levelCenter=a,_("Delay Level Center",a),this.callEvent("effectChange",{effect:"delay",parameter:"levelCenter",value:a});break}case 86:{this.delayProcessor.levelLeft=a,_("Delay Level Left",a),this.callEvent("effectChange",{effect:"delay",parameter:"levelLeft",value:a});break}case 87:{this.delayProcessor.levelRight=a,_("Delay Level Right",a),this.callEvent("effectChange",{effect:"delay",parameter:"levelRight",value:a});break}case 88:{this.delayProcessor.level=a,_("Delay Level",a),this.callEvent("effectChange",{effect:"delay",parameter:"level",value:a});break}case 89:{this.delayProcessor.feedback=a,_("Delay Feedback",a),this.callEvent("effectChange",{effect:"delay",parameter:"feedback",value:a});break}case 90:{this.delayProcessor.sendLevelToReverb=a,_("Delay Send Level To Reverb",a),this.callEvent("effectChange",{effect:"delay",parameter:"sendLevelToReverb",value:a});break}}break}if(s===3){if(this.masterParameters.insertionEffectLock)return;if(n>=3&&n<=25&&(this.insertionParams[n-3]=a),n>=3&&n<=22){this.insertionProcessor.setParameter(n,a),_(`EFX Parameter ${n-2}`,a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}switch(n){default:{qe(A,"Roland GS EFX");return}case 0:{let o=a<<8|A[8],i=this.insertionEffects.get(o);i?(_("EFX Type",o.toString(16)),this.insertionProcessor=i):(this.insertionProcessor=this.insertionFallback,D(`%cUnsupported EFX processor: %c${o.toString(16)}%c, using Thru.`,E.warn,E.unrecognized,E.warn)),this.resetInsertionParams(),this.insertionProcessor.reset(),this.callEvent("effectChange",{effect:"insertion",parameter:0,value:o});return}case 23:{this.insertionProcessor.sendLevelToReverb=a/127*Wt,_("EFX Send Level to Reverb",a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}case 24:{this.insertionProcessor.sendLevelToChorus=a/127*Wt,_("EFX Send Level to Chorus",a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}case 25:{this.insertionProcessor.sendLevelToDelay=a/127*Wt,this.delayActive=!0,_("EFX Send Level to Delay",a),this.callEvent("effectChange",{effect:"insertion",parameter:n,value:a});return}}}if(s>>4===1){let o=it(s&15)+e,i=this.midiChannels[o];switch(n){default:{qe(A,"Roland GS");return}case 0:{i.controllerChange(u.bankSelect,a),i.programChange(A[8]);break}case 2:{i.rxChannel=a===16?-1:a+e,this.customChannelNumbers||=i.rxChannel!==i.channel,_(`Rx. Channel on ${o}`,i.rxChannel);break}case 19:{i.polyMode=a===1,_(`Mono/poly on ${o}`,i.polyMode?"POLY":"MONO");break}case 20:{_(`Assign mode on ${o}`,a);break}case 21:{i.drumMap=a;let r=a>0;i.setGSDrums(r),_(`Drums on ${o}`,r.toString());return}case 22:{let r=a-64;i.setCustomController(Ce.channelKeyShift,r),_(`Key shift on ${o}`,r);return}case 25:{i.controllerChange(u.mainVolume,a);return}case 28:{let r=a;r===0?(i.randomPan=!0,_(`Random pan on ${o}`,"ON")):(i.randomPan=!1,i.controllerChange(u.pan,r));break}case 31:{i.cc1=a,_("CC1 Controller Number",a);break}case 32:{i.cc2=a,_("CC2 Controller Number",a);break}case 33:{i.controllerChange(u.chorusDepth,a);break}case 34:{i.controllerChange(u.reverbDepth,a);break}case 42:{let h=((a<<7|A[8])-8192)/81.92;i.setTuning(h);break}case 44:{i.controllerChange(u.variationDepth,a);break}case 48:{i.controllerChange(u.vibratoRate,a);break}case 49:{i.controllerChange(u.vibratoDepth,a);break}case 50:{i.controllerChange(u.brightness,a);break}case 51:{i.controllerChange(u.filterResonance,a);break}case 52:{i.controllerChange(u.attackTime,a);break}case 53:{i.controllerChange(u.decayTime,a);break}case 54:{i.controllerChange(u.releaseTime,a);break}case 55:{i.controllerChange(u.vibratoDelay,a);break}case 64:{let r=A.length-9,h=new Int8Array(12);for(let c=0;c<r;c++)h[c]=A[c+7]-64;i.setOctaveTuning(h);let I=a-64;_(`Octave Scale Tuning on ${o}`,h.join(", ")),i.setTuning(I);break}}return}if(s>>4===2){let o=it(s&15)+e,i=this.midiChannels[o],r=a-64,h=r/64,I=a/128,c=(l,B,d=!1)=>{switch(n&15){case 0:{l===ve+Ae.pitchWheel?(i.controllerChange(u.registeredParameterMSB,0),i.controllerChange(u.registeredParameterLSB,0),i.controllerChange(u.dataEntryMSB,Math.floor(r))):(i.sysExModulators.setModulator(l,g.fineTune,r*100,d),DA(o,r,`${B} pitch control`,"semitones"));break}case 1:{i.sysExModulators.setModulator(l,g.initialFilterFc,h*9600,d),DA(o,h*9600,`${B} pitch control`,"cents");break}case 2:{i.sysExModulators.setModulator(l,g.initialAttenuation,h*960,d),DA(o,h*960,`${B} amplitude`,"cB");break}case 4:{if(l===u.modulationWheel){let p=I*600;i.customControllers[Ce.modulationMultiplier]=p/50}else i.sysExModulators.setModulator(l,g.vibLfoToPitch,I*600,d),DA(o,I*600,`${B} LFO1 pitch depth`,"cents");break}case 5:{i.sysExModulators.setModulator(l,g.vibLfoToFilterFc,I*2400,d),DA(o,I*2400,`${B} LFO1 filter depth`,"cents");break}case 6:{i.sysExModulators.setModulator(l,g.vibLfoToVolume,h*960,d),DA(o,h*960,`${B} LFO1 amplitude depth`,"cB");break}case 8:{i.sysExModulators.setModulator(l,g.modLfoToPitch,I*600,d),DA(o,I*600,`${B} LFO2 pitch depth`,"cents");break}case 9:{i.sysExModulators.setModulator(l,g.modLfoToFilterFc,I*2400,d),DA(o,I*2400,`${B} LFO2 filter depth`,"cents");break}case 10:{i.sysExModulators.setModulator(l,g.modLfoToVolume,h*960,d),DA(o,h*960,`${B} LFO2 amplitude depth`,"cB");break}}};switch(n&240){default:{qe(A,"Roland GS Patch Parameter Controller");break}case 0:{c(u.modulationWheel,"mod wheel");break}case 16:{c(ve+Ae.pitchWheel,"pitch wheel",!0);break}case 32:{c(ve+Ae.channelPressure,"channel pressure");break}case 48:{c(ve+Ae.polyPressure,"poly pressure");break}case 64:{c(i.cc1,"CC1");break}case 80:c(i.cc2,"CC2")}return}if(s>>4===4){let o=it(s&15)+e,i=this.midiChannels[o];switch(n){default:{qe(A,"Roland GS Patch Part Parameter");break}case 0:case 1:{i.controllerChange(u.bankSelectLSB,a);break}case 34:{if(this.masterParameters.insertionEffectLock)return;let r=a===1;i.insertionEnabled=r,this.insertionActive||=r,_(`Insertion for ${o}`,r?"ON":"OFF"),this.callEvent("effectChange",{effect:"insertion",parameter:r?-1:-2,value:o})}}return}qe(A,"Roland GS Patch Parameter");return}if(t===65){if(this.masterParameters.drumLock)return;let o=(s>>4)+1,i=n;switch(s&15){default:{qe(A,"Roland GS Drum Setup");return}case 0:{let h=IA(A,12,7);_(`Patch Name for MAP${o}`,h);break}case 1:{let h=(a-60)*50;for(let I of this.midiChannels)I.drumMap===o&&(I.drumParams[i].pitch=h);_(`Drum Pitch for MAP${o}, key ${i}`,h);break}case 2:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].gain=a/120);_(`Drum Level for MAP${o}, key ${i}`,a);break}case 3:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].exclusiveClass=a);_(`Drum Assign Group for MAP${o}, key ${i}`,a);break}case 4:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].pan=a);_(`Drum Pan for MAP${o}, key ${i}`,a);break}case 5:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].reverbGain=a/127);_(`Drum Reverb for MAP${o}, key ${i}`,a);break}case 6:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].chorusGain=a/127);_(`Drum Chorus for MAP${o}, key ${i}`,a);break}case 7:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].rxNoteOff=a===1);_(`Drum Note Off for MAP${o}, key ${i}`,a===1);break}case 8:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].rxNoteOn=a===1);_(`Drum Note On for MAP${o}, key ${i}`,a===1);break}case 9:{for(let h of this.midiChannels)h.drumMap===o&&(h.drumParams[i].delayGain=a/127);_(`Drum Delay for MAP${o}, key ${i}`,a);break}}return}qe(A,"Roland GS");return}case 69:{A[4]===16&&(A[5]===0?this.callEvent("synthDisplay",[...A]):A[5]===1?this.callEvent("synthDisplay",[...A]):qe(A,"Roland GS Display"));return}case 22:if(A[4]===16){this.setMIDIVolume(A[7]/100),D(`%cRoland Master Volume control set to: %c${A[7]}`,E.info,E.value);return}else qe(A,"Roland")}else{qe(A,"Roland");return}}var Ye=(A,e)=>{D(`%cYamaha XG ${A}%c for is now set to %c${e}%c.`,E.recognized,E.info,E.value,E.info)};function Do(A,e=0){if(A[2]===76){let t=A[3],s=A[4],n=A[5],a=A[6];if(t===0&&s===0){switch(n){case 0:{{let i=(((A[6]&15)<<12|(A[7]&15)<<8|(A[8]&15)<<4|A[9]&15)-1024)/10;this.setMasterTuning(i),Ye("Master Tune",i)}break}case 4:{this.setMIDIVolume(a/127),Ye("Master Volume",a);break}case 5:{let o=127-a;this.setMIDIVolume(o/127),Ye("Master Attenuation",a);break}case 6:{let o=a-64;this.setMasterParameter("transposition",o),Ye("Master Transpose",o);break}case 127:case 126:{D("%cXG system on",E.info),this.resetAllControllers("xg");break}}return}if(t===2&&s===1){let o,i=n;i<=21?o="Reverb":i<=35?o="Chorus":o="Variation",D(`%cUnsupported XG ${o} Parameter: %c${i.toString(16)}`,E.warn,E.unrecognized);return}if(t===8){if(!Fe.isSystemXG(this.masterParameters.midiSystem))return;let o=s+e;if(o>=this.midiChannels.length)return;let i=this.midiChannels[o];switch(n){case 1:{i.controllerChange(u.bankSelect,a);break}case 2:{i.controllerChange(u.bankSelectLSB,a);break}case 3:{i.programChange(a);break}case 4:{i.rxChannel=a+e,this.customChannelNumbers||=i.rxChannel!==i.channel,Ye(`Rev. Channel on ${o}`,i.rxChannel);break}case 5:{i.polyMode=a===1,Ye(`Mono/poly on ${o}`,i.polyMode?"POLY":"MONO");break}case 7:{i.setDrums(a!=0);break}case 8:{if(i.drumChannel)break;let r=a-64;i.setCustomController(Ce.channelKeyShift,r),Ye(`Key shift on ${o}`,r);break}case 11:{i.controllerChange(u.mainVolume,a);break}case 14:{let r=a;r===0?(i.randomPan=!0,Ye(`Random Pan for ${o}`,"ON")):i.controllerChange(u.pan,r);break}case 18:{i.controllerChange(u.chorusDepth,a);break}case 19:{i.controllerChange(u.reverbDepth,a);break}case 21:{i.controllerChange(u.vibratoRate,a);break}case 22:{i.controllerChange(u.vibratoDepth,a);break}case 23:{i.controllerChange(u.vibratoDelay,a);break}case 24:{i.controllerChange(u.brightness,a);break}case 25:{i.controllerChange(u.filterResonance,a);break}case 26:{i.controllerChange(u.attackTime,a);break}case 27:{i.controllerChange(u.decayTime,a);break}case 28:{i.controllerChange(u.releaseTime,a);break}default:D(`%cUnsupported Yamaha XG Part Setup: %c${A[5].toString(16).toUpperCase()}%c for channel ${o}`,E.warn,E.unrecognized,E.warn)}return}if(t>>4===3){if(this.masterParameters.drumLock)return;let o=s;switch(n){default:{qe([n],"Yamaha XG Drum Setup");return}case 0:{let i=(a-64)*100;for(let r of this.midiChannels)r.drumChannel&&(r.drumParams[o].pitch=i);Ye(`Drum Pitch, key ${o}`,i);break}case 1:{let i=a-64;for(let r of this.midiChannels)r.drumChannel&&(r.drumParams[o].pitch+=i);Ye(`Drum Pitch Fine, key ${o}`,i);break}case 2:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].gain=a/120);Ye(`Drum Level, key ${o}`,a);break}case 3:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].exclusiveClass=a);Ye(`Drum Alternate Group, key ${o}`,a);break}case 4:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].pan=a);Ye(`Drum Pan, key ${o}`,a);break}case 5:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].reverbGain=a/127);Ye(`Drum Reverb, key ${o}`,a);break}case 6:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].chorusGain=a/127);Ye(`Drum Chorus, key ${o}`,a);break}case 9:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].rxNoteOff=a===1);Ye(`Drum Note Off, key ${o}`,a===1);break}case 10:{for(let i of this.midiChannels)i.drumChannel&&(i.drumParams[o].rxNoteOn=a===1);Ye(`Drum Note On, key ${o}`,a===1);break}}return}t===6||t===7?this.callEvent("synthDisplay",[...A]):Fe.isSystemXG(this.masterParameters.midiSystem)&&qe(A,"Yamaha XG")}else qe(A,"Yamaha")}function wo(A,e=0){e+=this.portSelectChannelOffset;let t=A[0];if(!(this.masterParameters.deviceID!==gt&&A[1]!==127&&this.masterParameters.deviceID!==A[1]))switch(t){default:{D(`%cUnknown manufacturer: %c${os(A)}`,E.warn,E.unrecognized);break}case 126:case 127:{So.call(this,A,e);break}case 65:{ko.call(this,A,e);break}case 67:{Do.call(this,A,e);break}case 245:{if(A.length<2)return;for(this.portSelectChannelOffset=(A[1]-1)*16;this.midiChannels.length<=this.portSelectChannelOffset;){D(`%cPort select, channel offset %c${this.portSelectChannelOffset}%c. Creating a new port!`,E.info,E.value,E.info);for(let s=0;s<16;s++)this.createMIDIChannel(!0)}break}}}var ti=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=0;reset(){}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c}=this;for(let l=0;l<r;l++){let B=A[l],d=e[l],p=i+l;t[p]+=B,s[p]+=d;let w=(B+d)*.5;n[l]+=w*h,a[l]+=w*I,o[l]+=w*c}}setParameter(A,e){}},vA=class{static data=[[0,200,200,0,0,.05,.05,315,250,200,250,100,-180,0],[.1,205,205,.1,5,.1,.1,315,250,200,250,110,-180,1],[.2,210,210,.2,10,.15,.15,315,250,200,250,120,-180,2],[.3,215,215,.3,15,.2,.2,315,250,200,250,130,-180,3],[.4,220,220,.4,20,.25,.25,315,250,200,250,140,-180,4],[.5,225,225,.5,25,.3,.3,315,250,200,250,150,-180,5],[.6,230,230,.6,30,.35,.35,315,250,200,250,160,-168,5],[.7,235,235,.7,35,.4,.4,315,250,200,250,170,-168,5],[.8,240,240,.8,40,.45,.45,400,315,250,315,180,-168,5],[.9,245,245,.9,45,.5,.5,400,315,250,315,190,-168,5],[1,250,250,1,50,.55,.55,400,315,250,315,200,-156,5],[1.1,255,255,1.1,55,.6,.6,400,315,250,315,210,-156,5],[1.2,260,260,1.2,60,.65,.65,400,315,250,315,220,-156,5],[1.3,265,265,1.3,65,.7,.7,400,315,250,315,230,-156,5],[1.4,270,270,1.4,70,.75,.75,400,315,250,315,240,-144,5],[1.5,275,275,1.5,75,.8,.8,400,315,250,315,250,-144,5],[1.6,280,280,1.6,80,.85,.85,500,400,315,400,260,-144,5],[1.7,285,285,1.7,85,.9,.9,500,400,315,400,270,-144,5],[1.8,290,290,1.8,90,.95,.95,500,400,315,400,280,-132,5],[1.9,295,295,1.9,95,1,1,500,400,315,400,290,-132,5],[2,300,300,2,100,1.05,1.05,500,400,315,400,300,-132,5],[2.1,305,305,2.1,105,1.1,1.1,500,400,315,400,320,-132,5],[2.2,310,310,2.2,110,1.15,1.15,500,400,315,400,340,-120,5],[2.3,315,315,2.3,115,1.2,1.2,500,400,315,400,360,-120,5],[2.4,320,320,2.4,120,1.25,1.25,630,500,400,500,380,-120,5],[2.5,325,325,2.5,125,1.3,1.3,630,500,400,500,400,-120,5],[2.6,330,330,2.6,130,1.35,1.35,630,500,400,500,420,-108,5],[2.7,335,335,2.7,135,1.4,1.4,630,500,400,500,440,-108,5],[2.8,340,340,2.8,140,1.45,1.45,630,500,400,500,460,-108,5],[2.9,345,345,2.9,145,1.5,1.5,630,500,400,500,480,-108,5],[3,350,350,3,150,1.55,1.55,630,500,400,500,500,-96,6],[3.1,355,355,3.1,155,1.6,1.6,630,500,400,500,520,-96,6],[3.2,360,360,3.2,160,1.65,1.65,800,630,500,630,540,-96,6],[3.3,365,365,3.3,165,1.7,1.7,800,630,500,630,560,-96,6],[3.4,370,370,3.4,170,1.75,1.75,800,630,500,630,580,-84,6],[3.5,375,375,3.5,175,1.8,1.8,800,630,500,630,600,-84,6],[3.6,380,380,3.6,180,1.85,1.85,800,630,500,630,620,-84,6],[3.7,385,385,3.7,185,1.9,1.9,800,630,500,630,640,-84,6],[3.8,390,390,3.8,190,1.95,1.95,800,630,500,630,660,-72,6],[3.9,395,395,3.9,195,2,2,800,630,500,630,680,-72,6],[4,400,400,4,200,2.05,2.05,1e3,800,630,800,700,-72,6],[4.1,405,405,4.1,205,2.1,2.1,1e3,800,630,800,720,-72,6],[4.2,410,410,4.2,210,2.15,2.15,1e3,800,630,800,740,-60,6],[4.3,415,415,4.3,215,2.2,2.2,1e3,800,630,800,760,-60,6],[4.4,420,420,4.4,220,2.25,2.25,1e3,800,630,800,780,-60,6],[4.5,425,425,4.5,225,2.3,2.3,1e3,800,630,800,800,-60,6],[4.6,430,430,4.6,230,2.35,2.35,1e3,800,630,800,820,-48,6],[4.7,435,435,4.7,235,2.4,2.4,1e3,800,630,800,840,-48,6],[4.8,440,440,4.8,240,2.45,2.45,1250,1e3,800,1e3,860,-48,9],[4.9,445,445,4.9,245,2.5,2.5,1250,1e3,800,1e3,880,-48,9],[5,450,450,5,250,2.55,2.55,1250,1e3,800,1e3,900,-36,9],[5.5,455,455,5.5,255,2.6,2.6,1250,1e3,800,1e3,920,-36,9],[6,460,460,6,260,2.65,2.65,1250,1e3,800,1e3,940,-36,9],[6.5,465,465,6.5,265,2.7,2.7,1250,1e3,800,1e3,960,-36,9],[7,470,470,7,270,2.75,2.75,1250,1e3,800,1e3,980,-24,9],[7.5,475,475,7.5,275,2.8,2.8,1250,1e3,800,1e3,1e3,-24,9],[8,480,480,8,280,2.85,2.85,1600,1250,1e3,1250,1100,-24,9],[8.5,485,485,8.5,285,2.9,2.9,1600,1250,1e3,1250,1200,-24,9],[9,490,490,9,290,2.95,2.95,1600,1250,1e3,1250,1300,-12,9],[9.5,495,495,9.5,295,3,3,1600,1250,1e3,1250,1400,-12,9],[10,500,500,10,300,3.05,3.05,1600,1250,1e3,1250,1500,-12,9],[11,505,505,11,305,3.1,3.1,1600,1250,1e3,1250,1600,-12,9],[12,510,510,12,310,3.15,3.15,1600,1250,1e3,1250,1700,0,9],[13,515,515,13,315,3.2,3.2,1600,1250,1e3,1250,1800,0,9],[14,520,520,14,320,3.25,3.25,2e3,1600,1250,1600,1900,0,12],[15,525,525,15,325,3.3,3.3,2e3,1600,1250,1600,2e3,0,12],[16,530,530,16,330,3.35,3.35,2e3,1600,1250,1600,2100,12,12],[17,535,535,17,335,3.4,3.4,2e3,1600,1250,1600,2200,12,12],[18,540,540,18,340,3.45,3.45,2e3,1600,1250,1600,2300,12,12],[19,545,545,19,345,3.5,3.5,2e3,1600,1250,1600,2400,12,12],[20,550,550,20,350,3.55,3.55,2e3,1600,1250,1600,2500,24,12],[21,560,555,21,355,3.6,3.6,2e3,1600,1250,1600,2600,24,12],[22,570,560,22,360,3.65,3.65,2500,2e3,1600,2e3,2700,24,12],[23,580,565,23,365,3.7,3.7,2500,2e3,1600,2e3,2800,24,12],[24,590,570,24,370,3.75,3.75,2500,2e3,1600,2e3,2900,36,12],[25,600,575,25,375,3.8,3.8,2500,2e3,1600,2e3,3e3,36,12],[26,610,580,26,380,3.85,3.85,2500,2e3,1600,2e3,3100,36,12],[27,620,585,27,385,3.9,3.9,2500,2e3,1600,2e3,3200,36,12],[28,630,590,28,390,3.95,3.95,2500,2e3,1600,2e3,3300,48,12],[29,640,595,29,395,4,4,2500,2e3,1600,2e3,3400,48,12],[30,650,600,30,400,4.05,4.05,3150,2500,2e3,2500,3500,48,10],[31,660,610,31,405,4.1,4.1,3150,2500,2e3,2500,3600,48,10],[32,670,620,32,410,4.15,4.15,3150,2500,2e3,2500,3700,60,10],[33,680,630,33,415,4.2,4.2,3150,2500,2e3,2500,3800,60,10],[34,690,640,34,420,4.25,4.25,3150,2500,2e3,2500,3900,60,10],[35,700,650,35,425,4.3,4.3,3150,2500,2e3,2500,4e3,60,10],[36,710,660,36,430,4.35,4.35,3150,2500,2e3,2500,4100,72,10],[37,720,670,37,435,4.4,4.4,3150,2500,2e3,2500,4200,72,10],[38,730,680,38,440,4.45,4.45,4e3,3150,2500,3150,4300,72,11],[39,740,690,39,445,4.5,4.5,4e3,3150,2500,3150,4400,72,11],[40,750,700,40,450,4.55,4.55,4e3,3150,2500,3150,4500,84,11],[41,760,710,50,455,4.6,4.6,4e3,3150,2500,3150,4600,84,11],[42,770,720,60,460,4.65,4.65,4e3,3150,2500,3150,4700,84,11],[43,780,730,70,465,4.7,4.7,4e3,3150,2500,3150,4800,84,11],[44,790,740,80,470,4.75,4.75,4e3,3150,2500,3150,4900,96,11],[45,800,750,90,475,4.8,4.8,4e3,3150,2500,3150,5e3,96,11],[46,810,760,100,480,4.85,4.85,5e3,4e3,3150,4e3,5100,96,12],[47,820,770,110,485,4.9,4.9,5e3,4e3,3150,4e3,5200,96,12],[48,830,780,120,490,4.95,4.95,5e3,4e3,3150,4e3,5300,108,12],[49,840,790,130,495,5,5,5e3,4e3,3150,4e3,5400,108,12],[50,850,800,140,500,5.1,5.05,5e3,4e3,3150,4e3,5500,108,12],[52,860,810,150,505,5.2,5.1,5e3,4e3,3150,4e3,5600,108,12],[54,870,820,160,510,5.3,5.15,5e3,4e3,3150,4e3,5700,120,12],[56,880,830,170,515,5.4,5.2,5e3,4e3,3150,4e3,5800,120,12],[58,890,840,180,520,5.5,5.25,6300,5e3,4e3,5e3,5900,120,13],[60,900,850,190,525,5.6,5.3,6300,5e3,4e3,5e3,6e3,120,13],[62,910,860,200,530,5.7,5.35,6300,5e3,4e3,5e3,6100,132,13],[64,920,870,210,535,5.8,5.4,6300,5e3,4e3,5e3,6200,132,13],[66,930,880,220,540,5.9,5.45,6300,5e3,4e3,5e3,6300,132,13],[68,940,890,230,545,6,5.5,6300,5e3,4e3,5e3,6400,132,13],[70,950,900,240,550,6.1,5.55,6300,5e3,4e3,5e3,6500,144,13],[72,960,910,250,555,6.2,5.6,6300,5e3,4e3,5e3,6600,144,13],[74,970,920,260,560,6.3,5.65,8e3,6300,5e3,6300,6700,144,14],[76,980,930,270,565,6.4,5.7,8e3,6300,5e3,6300,6800,144,14],[78,990,940,280,570,6.5,5.75,8e3,6300,5e3,6300,6900,156,14],[80,1e3,950,290,575,6.6,5.8,8e3,6300,5e3,6300,7e3,156,14],[82,1e3,960,300,580,6.7,5.85,8e3,6300,5e3,6300,7100,156,14],[84,1e3,970,320,585,6.8,5.9,8e3,6300,5e3,6300,7200,156,14],[86,1e3,980,340,590,6.9,5.95,8e3,6300,5e3,6300,7300,168,14],[88,1e3,990,360,595,7,6,8e3,6300,5e3,6300,7400,168,14],[90,1e3,1e3,380,600,7.5,6.05,13500,8e3,6300,13500,7500,168,15],[92,1e3,1e3,400,605,8,6.1,13500,8e3,6300,13500,7600,168,15],[94,1e3,1e3,420,610,8.5,6.15,13500,8e3,6300,13500,7700,-180,15],[96,1e3,1e3,440,615,9,6.2,13500,8e3,6300,13500,7800,-180,15],[98,1e3,1e3,460,620,9.5,6.25,13500,8e3,6300,13500,7900,-180,15],[100,1e3,1e3,480,625,10,6.3,13500,8e3,6300,13500,8e3,-180,15],[100,1e3,1e3,500,630,10,6.35,13500,8e3,6300,13500,8e3,-180,15],[100,1e3,1e3,500,635,10,6.4,13500,8e3,6300,13500,8e3,-180,15]];static preDelayTime(A){return this.data[A][0]}static delayTime1(A){return this.data[A][1]}static delayTime2(A){return this.data[A][2]}static delayTime3(A){return this.data[A][3]}static delayTime4(A){return this.data[A][4]}static rate1(A){return this.data[A][5]}static rate2(A){return this.data[A][6]}static hfDamp(A){return this.data[A][7]}static cutoffFreq(A){return this.data[A][8]}static eqFreq(A){return this.data[A][9]}static lpf(A){return this.data[A][10]}static manual(A){return this.data[A][11]}static azimuth(A){return this.data[A][12]}static accl(A){return this.data[A][13]}},ia=Math.PI/2,$t=-64,si=63,Ln=si-$t,is=new Float32Array(Ln+1),rs=new Float32Array(Ln+1);for(let A=$t;A<=si;A++){let e=(A-$t)/Ln,t=A-$t;is[t]=Math.cos(ia*e),rs[t]=Math.sin(ia*e)}function we(A){A.x1=A.x2=A.y1=A.y2=0}var je={b0:1,b1:0,b2:0,a0:1,a1:0,a2:0};function XA(A,e,t,s,n){let a=e.b0*A+e.b1*s.x1+e.b2*s.x2-e.a1*s.y1-e.a2*s.y2;s.x2=s.x1,s.x1=A,s.y2=s.y1,s.y1=a;let o=t.b0*a+t.b1*n.x1+t.b2*n.x2-t.a1*n.y1-t.a2*n.y2;return n.x2=n.x1,n.x1=a,n.y2=n.y1,n.y1=o,o}function QA(A,e,t){let s=e.b0*A+e.b1*t.x1+e.b2*t.x2-e.a1*t.y1-e.a2*t.y2;return t.x2=t.x1,t.x1=A,t.y2=t.y1,t.y1=s,s}function UA(A,e,t,s,n){let a=Math.pow(10,e/40),o=2*Math.PI*t/s,i=Math.cos(o),I=Math.sin(o)/2*Math.sqrt((a+1/a)*(1/1-1)+2),c,l,B,d,p,w;n?(c=a*(a+1-(a-1)*i+2*Math.sqrt(a)*I),l=2*a*(a-1-(a+1)*i),B=a*(a+1-(a-1)*i-2*Math.sqrt(a)*I),d=a+1+(a-1)*i+2*Math.sqrt(a)*I,p=-2*(a-1+(a+1)*i),w=a+1+(a-1)*i-2*Math.sqrt(a)*I):(c=a*(a+1+(a-1)*i+2*Math.sqrt(a)*I),l=-2*a*(a-1+(a+1)*i),B=a*(a+1+(a-1)*i-2*Math.sqrt(a)*I),d=a+1-(a-1)*i+2*Math.sqrt(a)*I,p=2*(a-1-(a+1)*i),w=a+1-(a-1)*i-2*Math.sqrt(a)*I),A.b0=c/d,A.b1=l/d,A.b2=B/d,A.a0=1,A.a1=p/d,A.a2=w/d}var Ne={x1:0,x2:0,y1:0,y2:0},bo=class{type=256;sendLevelToReverb=0;sendLevelToChorus=0;sendLevelToDelay=0;sampleRate;level=1;lowFreq=400;lowGain=5;hiFreq=8e3;hiGain=-12;m1Freq=1600;m1Q=.5;m1Gain=8;m2Freq=1e3;m2Q=.5;m2Gain=-8;lowCoeffs={...je};m1Coeffs={...je};m2Coeffs={...je};hiCoeffs={...je};lowStateL={...Ne};lowStateR={...Ne};m1StateL={...Ne};m1StateR={...Ne};m2StateL={...Ne};m2StateR={...Ne};hiStateL={...Ne};hiStateR={...Ne};constructor(A){this.sampleRate=A,this.reset(),this.updateCoefficients()}reset(){this.level=1,this.lowFreq=400,this.lowGain=5,this.hiGain=-12,this.hiFreq=8e3,this.m1Freq=1600,this.m1Q=.5,this.m1Gain=8,this.m2Freq=1e3,this.m2Q=.5,this.m2Gain=-8,we(this.lowStateL),we(this.lowStateR),we(this.m1StateL),we(this.m1StateR),we(this.m2StateL),we(this.m2StateR),we(this.hiStateL),we(this.hiStateR),this.updateCoefficients()}setParameter(A,e){switch(A){default:break;case 3:{this.lowFreq=e===1?400:200;break}case 4:{this.lowGain=e-64;break}case 5:{this.hiFreq=e===1?8e3:4e3;break}case 6:{this.hiGain=e-64;break}case 7:{this.m1Freq=vA.eqFreq(e);break}case 8:{this.m1Q=[.5,1,2,4,9][e]||1;break}case 9:{this.m1Gain=e-64;break}case 10:{this.m2Freq=vA.eqFreq(e);break}case 11:{this.m2Q=[.5,1,2,4,9][e]||1;break}case 12:{this.m2Gain=e-64;break}case 22:{this.level=e/127;break}}this.updateCoefficients()}process(A,e,t,s,n,a,o,i,r){let{level:h,sendLevelToChorus:I,sendLevelToDelay:c,sendLevelToReverb:l,lowCoeffs:B,lowStateL:d,lowStateR:p,m1Coeffs:w,m1StateL:G,m1StateR:F,m2StateL:b,m2StateR:k,m2Coeffs:O,hiCoeffs:C,hiStateL:Y,hiStateR:q}=this;for(let x=0;x<r;x++){let M=A[x],U=e[x];M=QA(M,B,d),U=QA(U,B,p),M=QA(M,w,G),U=QA(U,w,F),M=QA(M,O,b),U=QA(U,O,k),M=QA(M,C,Y),U=QA(U,C,q);let K=i+x;t[K]+=M*h,s[K]+=U*h;let S=.5*(M+U);n[x]+=S*l,a[x]+=S*I,o[x]+=S*c}}updateCoefficients(){vo(this.lowCoeffs,this.lowFreq,this.lowGain/2,this.sampleRate),ra(this.m1Coeffs,this.m1Freq,this.m1Gain,this.m1Q,this.sampleRate),ra(this.m2Coeffs,this.m2Freq,this.m2Gain,this.m2Q,this.sampleRate),Fo(this.hiCoeffs,this.hiFreq,this.hiGain/2,this.sampleRate)}},ni=1;function ra(A,e,t,s,n){let a=Math.pow(10,t/40),o=2*Math.PI*e/n,i=Math.cos(o),h=Math.sin(o)/(2*s),I=1+h*a,c=-2*i,l=1-h*a,B=1+h/a,d=-2*i,p=1-h/a;A.a0=1,A.a1=d/B,A.a2=p/B,A.b0=I/B,A.b1=c/B,A.b2=l/B}function vo(A,e,t,s){let n=Math.pow(10,t/40),a=2*Math.PI*e/s,o=Math.cos(a),r=Math.sin(a)/2*Math.sqrt((n+1/n)*(1/ni-1)+2),h=n*(n+1-(n-1)*o+2*Math.sqrt(n)*r),I=2*n*(n-1-(n+1)*o),c=n*(n+1-(n-1)*o-2*Math.sqrt(n)*r),l=n+1+(n-1)*o+2*Math.sqrt(n)*r,B=-2*(n-1+(n+1)*o),d=n+1+(n-1)*o-2*Math.sqrt(n)*r;A.a0=1,A.a1=B/l,A.a2=d/l,A.b0=h/l,A.b1=I/l,A.b2=c/l}function Fo(A,e,t,s){let n=Math.pow(10,t/40),a=2*Math.PI*e/s,o=Math.cos(a),r=Math.sin(a)/2*Math.sqrt((n+1/n)*(1/ni-1)+2),h=n*(n+1+(n-1)*o+2*Math.sqrt(n)*r),I=-2*n*(n-1+(n+1)*o),c=n*(n+1+(n-1)*o-2*Math.sqrt(n)*r),l=n+1-(n-1)*o+2*Math.sqrt(n)*r,B=2*(n-1-(n+1)*o),d=n+1-(n-1)*o-2*Math.sqrt(n)*r;A.a0=1,A.a1=B/l,A.a2=d/l,A.b0=h/l,A.b1=I/l,A.b2=c/l}var st=8,Ys=128,oa=4,qs=600,Ro=.9,ha=.35,ai=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=288;manual=620;rate=.85;depth=64/Ys;reso=16/127;mix=1;lowGain=0;hiGain=0;prevInL;prevOutL;prevInR;prevOutR;lowShelfCoef={...je};highShelfCoef={...je};manualOffset=qs;lowShelfStateL={x1:0,x2:0,y1:0,y2:0};lowShelfStateR={x1:0,x2:0,y1:0,y2:0};highShelfStateL={x1:0,x2:0,y1:0,y2:0};highShelfStateR={x1:0,x2:0,y1:0,y2:0};prevL=0;prevR=0;level=104/127;phase=ha;sampleRate;constructor(A){this.sampleRate=A,this.prevInL=new Float32Array(st),this.prevOutL=new Float32Array(st),this.prevInR=new Float32Array(st),this.prevOutR=new Float32Array(st),this.reset()}reset(){this.phase=ha,this.setManual(620),this.rate=.85,this.depth=64/Ys,this.reso=16/127,this.mix=1,this.lowGain=0,this.hiGain=0,this.level=104/127,we(this.highShelfStateL),we(this.highShelfStateR),we(this.lowShelfStateL),we(this.lowShelfStateR),this.updateShelves(),this.clearAllPass()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,manual:B,manualOffset:d,mix:p,lowShelfCoef:w,lowShelfStateR:G,lowShelfStateL:F,highShelfCoef:b,highShelfStateL:k,highShelfStateR:O,prevInL:C,prevInR:Y,prevOutL:q,prevOutR:x,sampleRate:M,depth:U}=this,{prevL:K,prevR:S,phase:T}=this,P=this.rate/this.sampleRate,H=this.reso*Ro;for(let y=0;y<r;y++){let R=XA(A[y],w,b,F,k),J=XA(e[y],w,b,G,O),ee=2*Math.abs(T-.5);(T+=P)>=1&&(T-=1);let ie=1-U*ee,Qe=d+B*ie,Ie=Math.tan(Math.PI*Qe/M),le=Math.max(-.9999,Math.min(.9999,(1-Ie)/(1+Ie))),re=R+H*K,ce=J+H*S;for(let Ee=0;Ee<st;Ee++){let Ue=-le*re+C[Ee]+le*q[Ee];C[Ee]=re,q[Ee]=Ue,re=Ue;let Je=-le*ce+Y[Ee]+le*x[Ee];Y[Ee]=ce,x[Ee]=Je,ce=Je}K=re,S=ce;let ye=(R+re*p)*l,z=(J+ce*p)*l,oe=i+y;t[oe]+=ye,s[oe]+=z;let Ge=(ye+z)*.5;n[y]+=Ge*h,a[y]+=Ge*I,o[y]+=Ge*c}this.phase=T,this.prevL=K,this.prevR=S}setParameter(A,e){switch(A){default:break;case 3:{this.setManual(vA.manual(e));break}case 4:{this.rate=vA.rate1(e);break}case 5:{this.depth=e/Ys;break}case 6:{this.reso=e/127;break}case 7:{this.mix=e/127;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}setManual(A){A>1e3?(this.manualOffset=qs*1.5*oa,this.manual=A):(this.manualOffset=qs,this.manual=A*oa)}clearAllPass(){this.prevR=0,this.prevL=0;for(let A=0;A<st;A++)this.prevInL[A]=0,this.prevOutL[A]=0,this.prevInR[A]=0,this.prevOutR[A]=0}updateShelves(){UA(this.lowShelfCoef,this.lowGain,200,this.sampleRate,!0),UA(this.highShelfCoef,this.hiGain,4e3,this.sampleRate,!1)}},ga=Math.PI*2,Go=.935,Mo=2,Lo=.01,Ia=127,No=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=294;modWave=1;modRate=3.05;modDepth=96;lowGain=0;hiGain=0;level=Ia/127;currentPan=0;phase=0;lsCoeffs={...je};hsCoeffs={...je};lsStateR={...Ne};lsStateL={...Ne};hsStateR={...Ne};hsStateL={...Ne};sampleRate;constructor(A){this.sampleRate=A,this.reset()}reset(){this.modWave=1,this.modRate=3.05,this.modDepth=96,this.lowGain=0,this.hiGain=0,this.level=Ia/127,this.currentPan=0,this.phase=0,we(this.hsStateR),we(this.hsStateL),we(this.lsStateR),we(this.lsStateL),this.updateShelves()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,lsCoeffs:B,lsStateL:d,lsStateR:p,hsCoeffs:w,hsStateR:G,hsStateL:F,modWave:b}=this,k=Math.pow(this.modDepth/127,Mo),O=2/(1+k)*Go,C=this.modRate/this.sampleRate,{phase:Y,currentPan:q}=this;for(let x=0;x<r;x++){let M=XA(A[x],B,w,d,F),U=XA(e[x],B,w,p,G),K;switch(b){default:{K=1-4*Math.abs(Y-.5);break}case 1:{K=Y>.5?-1:-Math.cos((Y-.75)*ga);break}case 2:{K=Math.sin(ga*Y);break}case 3:{K=1-2*Y;break}case 4:{K=2*Y-1;break}}(Y+=C)>=1&&(Y-=1),q+=(K-q)*Lo;let S=q*k,T=(1-S)*.5*O,P=(1+S)*.5*O,H=M*l*T,y=U*l*P,R=i+x;t[R]+=H,s[R]+=y;let J=(H+y)*.5;n[x]+=J*h,a[x]+=J*I,o[x]+=J*c}this.currentPan=q,this.phase=Y}setParameter(A,e){switch(A){default:break;case 3:{this.modWave=e;break}case 4:{this.modRate=vA.rate1(e);break}case 5:{this.modDepth=e;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}updateShelves(){UA(this.lsCoeffs,this.lowGain,200,this.sampleRate,!0),UA(this.hsCoeffs,this.hiGain,4e3,this.sampleRate,!1)}},ca=96,To=.1,Uo=.1,Po=27,xo=28,Ho=-28,Oo=400,Yo=.62,qo=.005,ii=5,la=ii*.5,ri=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=289;filType=1;sens=0;manual=68;peak=62;rate=2.05;depth=72;polarity=1;pan=0;lowGain=0;hiGain=0;level=ca/127;coeffs={...je};state={...Ne};hpCoeffs={...je};hpState={...Ne};phase=0;lsCoeffs={...je};hsCoeffs={...je};lsState={...Ne};hsState={...Ne};sampleRate;lastFc=this.manual;attackCoeff;releaseCoeff;envelope=0;constructor(A){this.sampleRate=A,this.attackCoeff=Math.exp(-1/(To*A)),this.releaseCoeff=Math.exp(-1/(Uo*A)),this.reset()}reset(){this.filType=1,this.sens=0,this.setManual(68),this.peak=62,this.rate=2.05,this.depth=72,this.polarity=1,this.lowGain=0,this.hiGain=0,this.pan=0,this.level=ca/127,this.phase=.2,this.lastFc=this.manual,we(this.hsState),we(this.lsState),we(this.state),we(this.hpState),this.updateShelves()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,lsCoeffs:B,lsState:d,hsCoeffs:p,hsState:w,coeffs:G,state:F,sampleRate:b,filType:k,manual:O,pan:C,attackCoeff:Y,releaseCoeff:q,hpState:x,hpCoeffs:M}=this,{phase:U,lastFc:K,envelope:S}=this,T=this.rate/this.sampleRate,P=Math.pow(10,this.peak/127*xo/20),H=Math.pow(10,this.peak/127*Ho/20),y=this.polarity===0?-1:ii,R=this.depth/127*y,J=this.sens/127,ee=C+64|0,ie=is[ee],Qe=rs[ee];for(let Ie=0;Ie<r;Ie++){let le=XA((A[Ie]+e[Ie])*.5,B,p,d,w),re=Math.abs(le);S=re>S?Y*S+(1-Y)*re:q*S+(1-q)*re;let ce=2*Math.abs(U-.5)*R;(U+=T)>=1&&(U-=1);let ye=ce>=la||y<0?1:Math.sin(ce*Math.PI/(2*la)),z=O*(1+J*S*Po),oe=Math.max(20,z*(1+ye*ce)),Ge=Math.max(10,oe);K+=(Ge-K)*qo,Jo(G,K,P,b);let Ee=le;k===1&&(Ko(M,Oo,H,b),Ee=QA(Ee,M,x));let Ue=QA(Ee,G,F)*l,Je=Ue*ie,PA=Ue*Qe,uA=i+Ie;t[uA]+=Je,s[uA]+=PA,n[Ie]+=Ue*h,a[Ie]+=Ue*I,o[Ie]+=Ue*c}this.phase=U,this.lastFc=K,this.envelope=S}setParameter(A,e){switch(A){default:break;case 3:{this.filType=e;break}case 4:{this.sens=e;break}case 5:{this.setManual(e);break}case 6:{this.peak=e;break}case 7:{this.rate=vA.rate1(e);break}case 8:{this.depth=e;break}case 9:{this.polarity=e;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 21:{this.pan=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}setManual(A){let e=A*Yo,t=vA.manual(Math.floor(e)),s=vA.manual(Math.ceil(e)),n=e-Math.floor(e);this.manual=t+(s-t)*n}updateShelves(){UA(this.lsCoeffs,this.lowGain,200,this.sampleRate,!0),UA(this.hsCoeffs,this.hiGain,4e3,this.sampleRate,!1)}};function Jo(A,e,t,s){let n=2*Math.PI*e/s,a=Math.cos(n),i=Math.sin(n)/(2*t),r=1-a,h=r/2,I=h,c=1+i,l=-2*a,B=1-i;A.a0=1,A.a1=l/c,A.a2=B/c,A.b0=h/c,A.b1=r/c,A.b2=I/c}function Ko(A,e,t,s){let n=2*Math.PI*e/s,a=Math.cos(n),i=Math.sin(n)/(2*t),r=(1+a)/2,h=-(1+a),I=r,c=1+i,l=-2*a,B=1-i;A.a0=1,A.a1=l/c,A.a2=B/c,A.b0=r/c,A.b1=h/c,A.b2=I/c}var Ca=127,Vo=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=4360;phPan=0;awPan=127;level=Ca/127;phaser;autoWah;bufferPh=new Float32Array(_e);bufferAw=new Float32Array(_e);constructor(A){this.phaser=new ai(A),this.autoWah=new ri(A),this.phaser.sendLevelToReverb=0,this.phaser.sendLevelToChorus=0,this.phaser.sendLevelToDelay=0,this.autoWah.sendLevelToReverb=0,this.autoWah.sendLevelToChorus=0,this.autoWah.sendLevelToDelay=0,this.reset()}reset(){this.phPan=0,this.awPan=127,this.level=Ca/127,this.phaser.reset(),this.autoWah.reset(),this.phaser.setParameter(22,127),this.autoWah.setParameter(22,127)}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l}=this;r>this.bufferPh.length&&(this.bufferPh=new Float32Array(r),this.bufferAw=new Float32Array(r));let{bufferPh:B,bufferAw:d}=this;this.bufferPh.fill(0),this.phaser.process(A,A,B,B,B,B,B,0,r),this.bufferAw.fill(0),this.autoWah.process(e,e,d,d,d,d,d,0,r);let p=this.phPan|0,w=is[p],G=rs[p],F=this.awPan|0,b=is[F],k=rs[F];for(let O=0;O<r;O++){let C=B[O]*.5*l,Y=d[O]*.5*l,q=C*w+Y*b,x=C*G+Y*k,M=i+O;t[M]+=q,s[M]+=x;let U=(q+x)*.5;n[O]+=U*h,a[O]+=U*I,o[O]+=U*c}}setParameter(A,e){if(A>=3&&A<=7){this.phaser.setParameter(A,e);return}if(A>=8&&A<=14){this.autoWah.setParameter(A-5,e);return}switch(A){default:break;case 18:{this.phPan=e;break}case 19:{this.phaser.setParameter(22,e);break}case 20:{this.awPan=e;break}case 21:{this.autoWah.setParameter(22,e);break}case 22:{this.level=e/127;break}}}},Ea=127,Ba=Math.PI*2,Xo=.01,Zo=class{sendLevelToReverb=40/127;sendLevelToChorus=0;sendLevelToDelay=0;type=293;modWave=1;modRate=3.05;modDepth=96;lowGain=0;hiGain=0;level=Ea/127;phase=0;currentGain=1;lsCoeffs={...je};hsCoeffs={...je};lsStateR={...Ne};lsStateL={...Ne};hsStateR={...Ne};hsStateL={...Ne};sampleRate;constructor(A){this.sampleRate=A,this.reset()}reset(){this.modWave=1,this.modRate=3.05,this.modDepth=96,this.lowGain=0,this.hiGain=0,this.level=Ea/127,this.phase=0,this.currentGain=1,we(this.hsStateR),we(this.hsStateL),we(this.lsStateR),we(this.lsStateL),this.updateShelves()}process(A,e,t,s,n,a,o,i,r){let{sendLevelToReverb:h,sendLevelToChorus:I,sendLevelToDelay:c,level:l,lsCoeffs:B,lsStateL:d,lsStateR:p,hsCoeffs:w,hsStateR:G,hsStateL:F,modDepth:b,modWave:k}=this,O=this.modRate/this.sampleRate,{currentGain:C,phase:Y}=this;for(let q=0;q<r;q++){let x=XA(A[q],B,w,d,F),M=XA(e[q],B,w,p,G),U;switch(k){default:{U=1-4*Math.abs(Y-.5);break}case 1:{U=Y>.5?-1:-Math.cos((Y-.75)*Ba);break}case 2:{U=Math.sin(Ba*Y);break}case 3:{U=1-2*Y;break}case 4:{U=2*Y-1;break}}(Y+=O)>=1&&(Y-=1);let K=1-(U/2+.5)*(b/127);C+=(K-C)*Xo;let S=x*l*C,T=M*l*C,P=i+q;t[P]+=S,s[P]+=T;let H=(S+T)*.5;n[q]+=H*h,a[q]+=H*I,o[q]+=H*c}this.phase=Y,this.currentGain=C}setParameter(A,e){switch(A){default:break;case 3:{this.modWave=e;break}case 4:{this.modRate=vA.rate1(e);break}case 5:{this.modDepth=e;break}case 19:{this.lowGain=e-64;break}case 20:{this.hiGain=e-64;break}case 22:{this.level=e/127;break}}this.updateShelves()}updateShelves(){UA(this.lsCoeffs,this.lowGain,200,this.sampleRate,!0),UA(this.hsCoeffs,this.hiGain,4e3,this.sampleRate,!1)}},Wo=[ti,bo,ai,No,ri,Vo,Zo],zo=.01,_o=.05,$o=class{voices;midiChannels=[];insertionInputL=new Float32Array(_e);insertionInputR=new Float32Array(_e);reverbInput=new Float32Array(_e);chorusInput=new Float32Array(_e);delayInput=new Float32Array(_e);delayActive=!1;soundBankManager=new uo(this.updatePresetList.bind(this));keyModifierManager=new Nr;sampleRate;tunings=new Float32Array(16384).fill(-1);masterParameters={...Ya};currentTime=0;midiVolume=1;enableEffects;enableEventSystem;panLeft=Math.cos(Math.PI/4);panRight=Math.cos(Math.PI/4);defaultPreset;drumPreset;gainSmoothingFactor;panSmoothingFactor;eventCallbackHandler;missingPresetHandler;cachedVoices=new Map;setMasterParameter=mo.bind(this);getMasterParameter=po.bind(this);getAllMasterParameters=yo.bind(this);systemExclusive=wo.bind(this);voiceCount=0;customChannelNumbers=!1;reverbProcessor;chorusProcessor;delayProcessor;insertionFallback=new ti;insertionProcessor=this.insertionFallback;insertionEffects=new Map;insertionActive=!1;portSelectChannelOffset=0;insertionParams=new Uint8Array(23).fill(255);lastPriorityAssignmentTime=0;eventQueue=[];sampleTime;constructor(A,e,t,s){this.eventCallbackHandler=A,this.missingPresetHandler=e,this.sampleRate=t,this.sampleTime=1/t,this.currentTime=s.initialTime,this.enableEffects=s.enableEffects,this.enableEventSystem=s.enableEventSystem,this.gainSmoothingFactor=zo*(44100/t),this.panSmoothingFactor=_o*(44100/t),Rn.initCache(this.sampleRate),this.reverbProcessor=s.reverbProcessor,this.chorusProcessor=s.chorusProcessor,this.delayProcessor=s.delayProcessor;for(let n of Wo)this.registerInsertionProcessor(n);this.resetInsertionParams(),this.voices=[];for(let n=0;n<this.masterParameters.voiceCap;n++)this.voices.push(new gn(this.sampleRate))}controllerChange(A,e,t){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.controllerChange(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].controllerChange(e,t)}noteOn(A,e,t){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.noteOn(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].noteOn(e,t)}noteOff(A,e){if(this.customChannelNumbers){for(let t of this.midiChannels)t.rxChannel===A&&t.noteOff(e);return}this.midiChannels[A+this.portSelectChannelOffset].noteOff(e)}polyPressure(A,e,t){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.polyPressure(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].polyPressure(e,t)}channelPressure(A,e){if(this.customChannelNumbers){for(let t of this.midiChannels)t.rxChannel===A&&t.channelPressure(e);return}this.midiChannels[A+this.portSelectChannelOffset].channelPressure(e)}pitchWheel(A,e,t=-1){if(this.customChannelNumbers){for(let s of this.midiChannels)s.rxChannel===A&&s.pitchWheel(e,t);return}this.midiChannels[A+this.portSelectChannelOffset].pitchWheel(e,t)}programChange(A,e){if(this.customChannelNumbers){for(let t of this.midiChannels)t.rxChannel===A&&t.programChange(e);return}this.midiChannels[A+this.portSelectChannelOffset].programChange(e)}assignVoice(){for(let e=0;e<this.masterParameters.voiceCap;e++){let t=this.voices[e];if(!t.isActive)return t.priority=1/0,t}if(this.masterParameters.autoAllocateVoices){let e=new gn(this.sampleRate);return this.voices.push(e),this.masterParameters.voiceCap++,this.callEvent("masterParameterChange",{parameter:"voiceCap",value:this.masterParameters.voiceCap}),e}this.assignVoicePriorities();let A=this.voices[0];for(let e=0;e<this.masterParameters.voiceCap;e++){let t=this.voices[e];t.priority<A.priority&&(A=t)}return A.priority=1/0,A}stopAllChannels(A){D("%cStop all received!",E.info);for(let e of this.midiChannels)e.stopAllNotes(A)}processMessage(A,e=0,t=Mi){let s=t.time;s>this.currentTime?(this.eventQueue.push({message:A,channelOffset:e,time:s}),this.eventQueue.sort((n,a)=>n.time-a.time)):this.processMessageInternal(A,e)}destroySynthProcessor(){this.voices.length=0;for(let A of this.midiChannels)A.lockedControllers=[],A.preset=void 0;this.clearCache(),this.midiChannels.length=0,this.soundBankManager.destroy()}getVoices(A,e,t){let s=this.midiChannels[A],n=this.keyModifierManager.hasOverridePatch(A,e),a=s.preset;if(n){let o=this.keyModifierManager.getPatch(A,e);a=this.soundBankManager.getPreset(o,this.masterParameters.midiSystem)}return a?this.getVoicesForPreset(a,e,t):[]}createMIDIChannel(A){let e=new lo(this,this.defaultPreset,this.midiChannels.length);this.midiChannels.push(e),A&&(this.callEvent("newChannel",void 0),e.sendChannelProperty(),e.setDrums(!0))}resetAllControllers(A=un){if(this.callEvent("allControllerReset",void 0),this.setMasterParameter("midiSystem",A),this.tunings.fill(-1),this.portSelectChannelOffset=0,this.customChannelNumbers=!1,this.setMIDIVolume(1),this.setReverbMacro(4),this.setChorusMacro(2),this.setDelayMacro(0),this.masterParameters.delayLock||(this.delayActive=!1),this.resetInsertion(),!(!this.drumPreset||!this.defaultPreset))for(let e=0;e<this.midiChannels.length;e++){let t=this.midiChannels[e];t.resetControllers(!1),t.resetPreset();for(let s=0;s<128;s++)this.midiChannels[e].lockedControllers[s]&&this.callEvent("controllerChange",{channel:e,controllerNumber:s,controllerValue:this.midiChannels[e].midiControllers[s]>>7});if(!this.midiChannels[e].lockedControllers[ve+Ae.pitchWheel]){let s=this.midiChannels[e].midiControllers[ve+Ae.pitchWheel];this.callEvent("pitchWheel",{channel:e,pitch:s,midiNote:-1})}if(!this.midiChannels[e].lockedControllers[ve+Ae.channelPressure]){let s=this.midiChannels[e].midiControllers[ve+Ae.channelPressure]>>7;this.callEvent("channelPressure",{channel:e,pressure:s})}}}process(A,e,t=0,s=0){this.processSplit([[A,e]],A,e,t,s)}processSplit(A,e,t,s=0,n=0){if(this.eventQueue.length>0){let r=this.currentTime;for(;this.eventQueue[0]?.time<=r;){let h=this.eventQueue.shift();h&&this.processMessageInternal(h.message,h.channelOffset)}}s=Math.max(s,0);let a=n||A[0][0].length-s;this.enableEffects&&(this.reverbInput.length<a?(se("Buffer size has increased, this will cause a memory allocation!"),this.reverbInput=new Float32Array(a),this.chorusInput=new Float32Array(a),this.delayInput=new Float32Array(a),this.insertionInputL=new Float32Array(a),this.insertionInputR=new Float32Array(a)):(this.reverbInput.fill(0),this.chorusInput.fill(0),this.delayActive&&this.delayInput.fill(0),this.insertionActive&&(this.insertionInputL.fill(0),this.insertionInputR.fill(0))));for(let r of this.midiChannels)r.clearVoiceCount();this.voiceCount=0;let o=this.masterParameters.voiceCap,i=A.length;for(let r=0;r<o;r++){let h=this.voices[r],I=this.midiChannels[h.channel];if(!h.isActive||I.isMuted)continue;let c=h.channel%i;I.renderVoice(h,this.currentTime,A[c][0],A[c][1],s,a),I.voiceCount++,this.voiceCount++}if(this.enableEffects){let{chorusInput:r,delayInput:h,reverbInput:I,insertionInputR:c,insertionInputL:l}=this;this.insertionActive&&this.insertionProcessor.process(l,c,e,t,I,r,h,s,a),this.chorusProcessor.process(r,e,t,I,h,s,a),this.delayActive&&this.masterParameters.midiSystem!=="xg"&&this.delayProcessor.process(h,e,t,I,s,a),this.reverbProcessor.process(I,e,t,s,a)}for(let r of this.midiChannels)r.updateVoiceCount();this.currentTime+=a*this.sampleTime}getVoicesForPreset(A,e,t){let s=this.getCachedVoice(A,e,t);if(s!==void 0)return s;let n=new Array;for(let a of A.getVoiceParameters(e,t)){let o=a.sample;if(a.sample.getAudioData()===void 0){se(`Discarding invalid sample: ${o.name}`);continue}n.push(new Wr(a,e,t,this.sampleRate))}return this.setCachedVoice(A,e,t,n),n}clearCache(){this.cachedVoices.clear()}getInsertionSnapshot(){return{type:this.insertionProcessor.type,params:this.insertionParams.slice(),channels:this.midiChannels.map(A=>A.insertionEnabled)}}callEvent(A,e){this.eventCallbackHandler(A,e)}resetInsertionParams(){this.insertionParams.fill(255),this.insertionParams[20]=40,this.insertionParams[21]=0,this.insertionParams[22]=0}resetInsertion(){this.masterParameters.insertionEffectLock||(this.insertionActive=!1,this.insertionProcessor=this.insertionFallback,this.insertionProcessor.reset(),this.insertionProcessor.sendLevelToReverb=40/127*Wt,this.insertionProcessor.sendLevelToChorus=0,this.insertionProcessor.sendLevelToDelay=0,this.resetInsertionParams(),this.callEvent("effectChange",{effect:"insertion",parameter:0,value:this.insertionProcessor.type}))}setMIDIVolume(A){this.midiVolume=Math.pow(A,Math.E)}setMasterTuning(A){A=Math.round(A);for(let e of this.midiChannels)e.setCustomController(Ce.masterTuning,A)}setReverbMacro(A){if(this.masterParameters.reverbLock)return;let e=this.reverbProcessor;switch(e.level=64,e.preDelayTime=0,e.character=A,A){case 0:{e.character=0,e.preLowpass=3,e.time=80,e.delayFeedback=0,e.preDelayTime=0;break}case 1:{e.preLowpass=4,e.time=56,e.delayFeedback=0;break}case 2:{e.preLowpass=0,e.time=72,e.delayFeedback=0;break}case 3:{e.preLowpass=4,e.time=72,e.delayFeedback=0;break}case 4:{e.preLowpass=0,e.time=64,e.delayFeedback=0;break}case 5:{e.preLowpass=0,e.time=88,e.delayFeedback=0;break}case 6:{e.preLowpass=0,e.time=32,e.delayFeedback=40;break}case 7:{e.preLowpass=0,e.time=64,e.delayFeedback=32;break}default:{se(`Invalid reverb macro: ${A}`);return}}this.callEvent("effectChange",{effect:"reverb",parameter:"macro",value:A})}setChorusMacro(A){if(this.masterParameters.chorusLock)return;let e=this.chorusProcessor;switch(e.level=64,e.preLowpass=0,e.delay=127,e.sendLevelToDelay=0,e.sendLevelToReverb=0,A){case 0:{e.feedback=0,e.delay=112,e.rate=3,e.depth=5;break}case 1:{e.feedback=5,e.delay=80,e.rate=9,e.depth=19;break}case 2:{e.feedback=8,e.delay=80,e.rate=3,e.depth=19;break}case 3:{e.feedback=16,e.delay=64,e.rate=9,e.depth=16;break}case 4:{e.feedback=64,e.delay=127,e.rate=2,e.depth=24;break}case 5:{e.feedback=112,e.delay=127,e.rate=1,e.depth=5;break}case 6:{e.feedback=0,e.depth=127,e.rate=0,e.depth=127;break}case 7:{e.feedback=80,e.depth=127,e.rate=0,e.depth=127;break}default:{se(`Invalid chorus macro: ${A}`);return}}this.callEvent("effectChange",{effect:"chorus",parameter:"macro",value:A})}setDelayMacro(A){if(this.masterParameters.delayLock)return;let e=this.delayProcessor;switch(e.level=64,e.preLowpass=0,e.sendLevelToReverb=0,e.levelRight=e.levelLeft=0,e.levelCenter=127,A){case 0:{e.timeCenter=97,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=80;break}case 1:{e.timeCenter=106,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=80;break}case 2:{e.timeCenter=115,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=72;break}case 3:{e.timeCenter=83,e.timeRatioRight=e.timeRatioLeft=1,e.feedback=72;break}case 4:{e.timeCenter=105,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=125,e.levelRight=60,e.feedback=74;break}case 5:{e.timeCenter=109,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=125,e.levelRight=60,e.feedback=71;break}case 6:{e.timeCenter=115,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=120,e.levelRight=64,e.feedback=73;break}case 7:{e.timeCenter=93,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=120,e.levelRight=64,e.feedback=72;break}case 8:{e.timeCenter=109,e.timeRatioLeft=12,e.timeRatioRight=24,e.levelCenter=0,e.levelLeft=114,e.levelRight=60,e.feedback=61,e.sendLevelToReverb=36;break}case 9:{e.timeCenter=110,e.timeRatioLeft=21,e.timeRatioRight=32,e.levelCenter=97,e.levelLeft=127,e.levelRight=67,e.feedback=40;break}default:{se(`Invalid delay macro: ${A}`);return}}this.callEvent("effectChange",{effect:"delay",parameter:"macro",value:A})}getCachedVoice(A,e,t){return this.cachedVoices.get(this.getCachedVoiceIndex(A,e,t))}setCachedVoice(A,e,t,s){this.cachedVoices.set(this.getCachedVoiceIndex(A,e,t),s)}registerInsertionProcessor(A){let e=new A(this.sampleRate);this.insertionEffects.set(e.type,e)}processMessageInternal(A,e){let t=fn(A[0]),s=t.channel+e;switch(t.status){case N.noteOn:{let n=A[2];n>0?this.noteOn(s,A[1],n):this.noteOff(s,A[1]);break}case N.noteOff:{this.noteOff(s,A[1]);break}case N.pitchWheel:{this.pitchWheel(s,A[2]<<7|A[1]);break}case N.controllerChange:{this.controllerChange(s,A[1],A[2]);break}case N.programChange:{this.programChange(s,A[1]);break}case N.polyPressure:{this.polyPressure(s,A[1],A[2]);break}case N.channelPressure:{this.channelPressure(s,A[1]);break}case N.systemExclusive:{this.systemExclusive(new $(A.slice(1)),e);break}case N.reset:{this.stopAllChannels(!1),this.resetAllControllers();break}default:break}}assignVoicePriorities(){if(this.lastPriorityAssignmentTime===this.currentTime)return;D("%cPolyphony exceeded, stealing voices",E.warn),this.lastPriorityAssignmentTime=this.currentTime;let A=this.masterParameters.voiceCap;for(let e=0;e<A;e++){let t=this.voices[e];t.priority=0,this.midiChannels[t.channel].drumChannel&&(t.priority+=5),t.isInRelease&&(t.priority-=5),t.priority+=t.velocity/25,t.priority-=t.volEnv.state,t.isInRelease&&(t.priority-=5),t.priority-=t.volEnv.attenuationCb/200}}updatePresetList(){let A=this.soundBankManager.presetList;this.clearCache(),this.callEvent("presetListChange",A),this.getDefaultPresets();for(let e of this.midiChannels)e.setPresetLock(!1);this.resetAllControllers()}getDefaultPresets(){this.defaultPreset=this.soundBankManager.getPreset({bankLSB:0,bankMSB:0,program:0,isGMGSDrum:!1},"xg"),this.drumPreset=this.soundBankManager.getPreset({bankLSB:0,bankMSB:0,program:0,isGMGSDrum:!0},"gs")}getCachedVoiceIndex(A,e,t){let s=A.bankMSB,n=A.bankLSB,{isGMGSDrum:a,program:o}=A;return a&&(s=128,n=0),s+n*128+o*16384+2097152*e+268435456*t}},Js=20;async function jo(A,e,t,s,n,a,o){let i=0,r=0,h=[];for(let l of A.samples){s&&a&&await l.compressSample(a),n&&l.setAudioData(l.getAudioData(),l.sampleRate);let B=l.getRawData(!0);i++,await o?.(l.name,i,A.samples.length),D(`%cEncoded sample %c${i}. ${l.name}%c of %c${A.samples.length}%c. Compressed: %c${l.isCompressed}%c.`,E.info,E.recognized,E.info,E.recognized,E.info,l.isCompressed?E.recognized:E.unrecognized,E.info),r+=B.length+(l.isCompressed?0:92),h.push(B)}r%2!==0&&r++;let I=new $(r+Js);Te(I,"LIST"),bt(I,r+Js-8,4),Te(I,"sdta"),Te(I,"smpl"),bt(I,r,4);let c=0;for(let[l,B]of A.samples.entries()){let d=h[l];I.set(d,c+Js);let p,w;B.isCompressed?(p=c,w=p+d.length):(p=c/2,w=p+d.length/2,c+=92),c+=d.length,e.push(p),t.push(w)}return I}var eh=48e3,Cs=class{name;sampleRate;originalKey;pitchCorrection;linkedSample;sampleType;loopStart;loopEnd;linkedTo=[];dataOverridden=!0;compressedData;audioData;constructor(A,e,t,s,n,a,o){this.name=A,this.sampleRate=e,this.originalKey=t,this.pitchCorrection=s,this.loopStart=a,this.loopEnd=o,this.sampleType=n}get isCompressed(){return this.compressedData!==void 0}get isLinked(){return this.sampleType===xe.rightSample||this.sampleType===xe.leftSample||this.sampleType===xe.linkedSample}get useCount(){return this.linkedTo.length}getRawData(A){return this.compressedData&&A&&!this.dataOverridden?this.compressedData:this.encodeS16LE()}resampleData(A){let e=this.getAudioData(),t=A/this.sampleRate,s=new Float32Array(Math.floor(e.length*t));for(let n=0;n<s.length;n++)s[n]=e[Math.floor(n*(1/t))];e=s,this.sampleRate=A,this.loopStart=Math.floor(this.loopStart*t),this.loopEnd=Math.floor(this.loopEnd*t),this.audioData=e}async compressSample(A){if(!this.isCompressed)try{let e=this.getAudioData();(this.sampleRate<8e3||this.sampleRate>96e3)&&(this.resampleData(eh),e=this.getAudioData());let t=await A(e,this.sampleRate);this.setCompressedData(t)}catch(e){se(`Failed to compress ${this.name}. Leaving as uncompressed!`,e),this.compressedData=void 0}}setSampleType(A){if(this.sampleType=A,this.isLinked||(this.linkedSample&&(this.linkedSample.linkedSample=void 0,this.linkedSample.sampleType=A),this.linkedSample=void 0),(A&32768)>0)throw new Error("ROM samples are not supported.")}unlinkSample(){this.setSampleType(xe.monoSample)}setLinkedSample(A,e){if(A.linkedSample)throw new Error(`${A.name} is linked tp ${A.linkedSample.name}. Unlink it first.`);switch(this.linkedSample=A,A.linkedSample=this,e){case xe.leftSample:{this.setSampleType(xe.leftSample),A.setSampleType(xe.rightSample);break}case xe.rightSample:{this.setSampleType(xe.rightSample),A.setSampleType(xe.leftSample);break}case xe.linkedSample:{this.setSampleType(xe.linkedSample),A.setSampleType(xe.linkedSample);break}default:throw new Error("Invalid sample type: "+e)}}linkTo(A){this.linkedTo.push(A)}unlinkFrom(A){let e=this.linkedTo.indexOf(A);if(e===-1){se(`Cannot unlink ${A.name} from ${this.name}: not linked.`);return}this.linkedTo.splice(e,1)}getAudioData(){if(this.audioData)return this.audioData;if(this.isCompressed)return this.audioData=this.decodeVorbis(),this.audioData;throw new Error("Sample data is undefined for a BasicSample instance.")}setAudioData(A,e){this.audioData=A,this.sampleRate=e,this.dataOverridden=!0,this.compressedData=void 0}setCompressedData(A){this.audioData=void 0,this.compressedData=A,this.dataOverridden=!1}encodeS16LE(){let A=this.getAudioData(),e=new Int16Array(A.length),t=A.length;for(let s=0;s<t;s++){let n=A[s]*32768;n>32767?n=32767:n<-32768&&(n=-32768),e[s]=n}return new $(e.buffer)}decodeVorbis(){if(this.audioData)return this.audioData;if(!this.compressedData)throw new Error("Compressed data is missing.");try{let e=cs.decode(this.compressedData).data[0];if(e===void 0)return se(`Error decoding sample ${this.name}: Vorbis decode returned undefined.`),new Float32Array(0);for(let t=0;t<e.length;t++)e[t]=Math.max(-1,Math.min(e[t],.999969482421875));return e}catch(A){return se(`Error decoding sample ${this.name}: ${A}`),new Float32Array(this.loopEnd+1)}}},Ah=class extends Cs{constructor(){super("",44100,60,0,xe.monoSample,0,0)}},In=16,th=class extends Cs{linkedSampleIndex;s16leData;startByteOffset;endByteOffset;sampleID;constructor(A,e,t,s,n,a,o,i,r,h,I,c){let l=(h&In)>0;h&=~In,super(A,a,o,i,h,s-e/2,n-e/2),this.dataOverridden=!1,this.name=A,this.startByteOffset=e,this.endByteOffset=t,this.sampleID=c;let B=I instanceof $?I.currentIndex:0;I instanceof $?l?(this.loopStart+=this.startByteOffset/2,this.loopEnd+=this.startByteOffset/2,this.setCompressedData(I.slice(this.startByteOffset/2+B,this.endByteOffset/2+B))):this.s16leData=I.slice(B+this.startByteOffset,B+this.endByteOffset):this.setAudioData(I.slice(this.startByteOffset/2,this.endByteOffset/2),a),this.linkedSampleIndex=r}getLinkedSample(A){if(this.linkedSample||!this.isLinked)return;let e=A[this.linkedSampleIndex];e?e.linkedSample?(D(`%cInvalid linked sample for ${this.name}: ${e.name} is already linked to ${e.linkedSample.name}`,E.warn),this.unlinkSample()):this.setLinkedSample(e,this.sampleType):(D(`%cInvalid linked sample for ${this.name}. Setting to mono.`,E.warn),this.unlinkSample())}getAudioData(){if(this.audioData)return this.audioData;if(this.isCompressed)return super.getAudioData();if(!this.s16leData)throw console.error(this),new Error("Unexpected lack of audio data.");let A=this.endByteOffset-this.startByteOffset;if(A<1)return se(`Invalid sample ${this.name}! Invalid length: ${A}`),new Float32Array(1);let e=new Float32Array(A/2),t=new Int16Array(this.s16leData.buffer);for(let[s,n]of t.entries())e[s]=n/32768;return this.audioData=e,e}getRawData(A){return this.dataOverridden||this.compressedData?super.getRawData(A):this.s16leData??new Uint8Array(0)}};function da(A,e,t=!0){let s=[],n=0;for(;A.data.length>A.data.currentIndex;){let a=sh(n,A.data,e);s.push(a),n++}if(s.pop(),t)for(let a of s)a.getLinkedSample(s);return s}function sh(A,e,t){let s=pe(e,20),n=V(e,4)*2,a=V(e,4)*2,o=V(e,4),i=V(e,4),r=V(e,4),h=e[e.currentIndex++];h>127&&(h=60);let I=bi(e[e.currentIndex++]),c=V(e,2),l=V(e,2);return new th(s,n,a,o,i,r,h,I,c,l,t,A)}function nh(A,e,t){let n=46*(A.samples.length+1),a=new $(n),o=new $(n),i=0;for(let[I,c]of A.samples.entries()){Te(a,c.name.slice(0,20),20),Te(o,c.name.slice(20),20);let l=e[I];Be(a,l),o.currentIndex+=4;let B=t[I];Be(a,B),o.currentIndex+=4;let d=c.loopStart+l,p=c.loopEnd+l;c.isCompressed&&(d-=l,p-=l),Be(a,d),Be(a,p),Be(a,c.sampleRate),a[a.currentIndex++]=c.originalKey,a[a.currentIndex++]=c.pitchCorrection,o.currentIndex+=14;let w=c.linkedSample?A.samples.indexOf(c.linkedSample):0;te(a,Math.max(0,w)&65535),te(o,Math.max(0,w)>>16),i=Math.max(i,w);let G=c.sampleType;c.isCompressed&&(G|=In),te(a,G),o.currentIndex+=2}Te(a,"EOS",46),Te(o,"EOS",46);let r=de("shdr",a),h=de("shdr",o);return{pdta:r,xdta:h}}function Qa(A,e=!1){let t=e?A.presets:A.instruments,s=e?"pgen":"igen",n=e?"pmod":"imod",a=e?"pbag":"ibag",o=e?"phdr":"inst",i=e?Qo:Eo,r=0,h=new Array,I=0,c=new Array,l=new Array,B=new Array,d=0,p=new Array,w=x=>{h.push(r);let M=x.getWriteGenerators(A);r+=M.length,l.push(...M),c.push(I);let U=x.modulators;I+=U.length,B.push(...U)};for(let x of t){p.push(d),w(x.globalZone);for(let M of x.zones)w(M);d+=x.zones.length+1}l.push(new He(0,0,!1)),B.push(new be(0,0,0,0,0)),h.push(r),c.push(I),p.push(d);let G=l.length*sa,F=new $(G);for(let x of l)x.write(F);let b=B.length*wt,k=new $(b);for(let x of B)x.write(k);let O=c.length*Co,C={pdta:new $(O),xdta:new $(O)};for(let[x,M]of c.entries()){let U=h[x];te(C.pdta,U&65535),te(C.pdta,M&65535),te(C.xdta,U>>16),te(C.xdta,M>>16)}let Y=(t.length+1)*i,q={pdta:new $(Y),xdta:new $(Y)};for(let[x,M]of t.entries())M.write(q,p[x]);return e?(Te(q.pdta,"EOP",20),q.pdta.currentIndex+=4,te(q.pdta,d&65535),q.pdta.currentIndex+=12,Te(q.xdta,"",20),q.xdta.currentIndex+=4,te(q.xdta,d>>16),q.xdta.currentIndex+=12):(Te(q.pdta,"EOI",20),te(q.pdta,d&65535),Te(q.xdta,"",20),te(q.xdta,d>>16)),{writeXdta:Math.max(r,I,d)>65535,gen:{pdta:de(s,F),xdta:de(n,new $(sa))},mod:{pdta:de(n,k),xdta:de(n,new $(wt))},bag:{pdta:de(a,C.pdta),xdta:de(a,C.xdta)},hdr:{pdta:de(o,q.pdta),xdta:de(o,q.xdta)}}}var cn={compress:!1,compressionFunction:void 0,progressFunction:void 0,writeDefaultModulators:!0,writeExtendedLimits:!0,decompress:!1};async function ah(A,e=cn){let t=Qn(e,cn);if(t?.compress){if(typeof t?.compressionFunction!="function")throw new TypeError("No compression function supplied but compression enabled.");if(t?.decompress)throw new Error("Decompressed and compressed at the same time.")}Xe("%cSaving soundbank...",E.info),D(`%cCompression: %c${t?.compress||"false"}%c`,E.info,E.recognized,E.info,E.recognized),tA("%cWriting INFO...",E.info);let s=[];A.soundBankInfo.software="SpessaSynth",(t?.compress||A.samples.some(b=>b.isCompressed))&&(A.soundBankInfo.version.major=3,A.soundBankInfo.version.minor=0),t?.decompress&&(A.soundBankInfo.version.major=2,A.soundBankInfo.version.minor=4);let n=(b,k)=>{s.push(de(b,fA(k,!0,!0)))},a=new $(4);if(te(a,A.soundBankInfo.version.major),te(a,A.soundBankInfo.version.minor),s.push(de("ifil",a)),A.soundBankInfo.romVersion){let b=new $(4);te(b,A.soundBankInfo.romVersion.major),te(b,A.soundBankInfo.romVersion.minor),s.push(de("iver",b))}let o=(A.soundBankInfo?.comment??"")+(A.soundBankInfo.subject?`
7
7
  ${A.soundBankInfo.subject}`:"");for(let[b,k]of Object.entries(A.soundBankInfo)){let O=b,C=k;if(C)switch(O){case"name":{n("INAM",C);break}case"comment":{n("ICMT",o);break}case"copyright":{n("ICOP",C);break}case"creationDate":{n("ICRD",C.toISOString());break}case"engineer":{n("IENG",C);break}case"product":{n("IPRD",C);break}case"romInfo":{n("irom",C);break}case"software":{n("ISFT",C);break}case"soundEngine":{n("isng",C);break}case"subject":break}}if(A.defaultModulators.some(b=>!Za.some(k=>Re.isIdentical(k,b,!0)))&&t?.writeDefaultModulators){let b=A.defaultModulators;D(`%cWriting %c${b.length}%c default modulators...`,E.info,E.recognized,E.info);let k=wt+b.length*wt,O=new $(k);for(let C of b)C.write(O);bt(O,0,wt),s.push(de("DMOD",O))}j(),D("%cWriting SDTA...",E.info);let r=[],h=[],I=await jo(A,r,h,t.compress,t.decompress,t?.compressionFunction,t?.progressFunction);D("%cWriting PDTA...",E.info),D("%cWriting SHDR...",E.info);let c=nh(A,r,h);tA("%cWriting instruments...",E.info);let l=Qa(A,!1);j(),tA("%cWriting presets...",E.info);let B=Qa(A,!0);j();let d=[B.hdr,B.bag,B.mod,B.gen,l.hdr,l.bag,l.mod,l.gen,c],p=Ze("pdta",d.map(b=>b.pdta),!0);if(t.writeExtendedLimits&&(l.writeXdta||B.writeXdta||A.presets.some(b=>b.name.length>20)||A.instruments.some(b=>b.name.length>20)||A.samples.some(b=>b.name.length>20))){D("%cWriting the xdta chunk as writeExendedLimits is enabled and at least one condition was met.",E.info,E.value);let b=Ze("xdta",d.map(k=>k.xdta),!0);s.push(b)}let G=Ze("INFO",s,!0);D("%cWriting the output file...",E.info);let F=Ze("RIFF",[fA("sfbk"),G,I,p]);return D(`%cSaved succesfully! Final file size: %c${F.length}`,E.info,E.recognized),j(),F.buffer}var It=class{static verifyHeader(A,...e){for(let t of e)if(A.header.toLowerCase()===t.toLowerCase())return;this.parsingError(`Invalid DLS chunk header! Expected "${e.join(", or ")}" got "${A.header.toLowerCase()}"`)}static verifyText(A,...e){for(let t of e)if(A.toLowerCase()===t.toLowerCase())return;this.parsingError(`FourCC error: Expected "${e.join(", or ")}" got "${A.toLowerCase()}"`)}static parsingError(A){throw j(),new Error(`DLS parse error: ${A} The file may be corrupted.`)}static verifyAndReadList(A,...e){this.verifyHeader(A,"LIST"),A.data.currentIndex=0,this.verifyText(pe(A.data,4),...e);let t=[];for(;A.data.length>A.data.currentIndex;)t.push(ge(A.data));return t}},pt=20,Ks=16,rt=class kt extends It{gain=0;unityNote=60;fineTune=0;loops=new Array;fulOptions=2;static copyFrom(e){let t=new kt;return t.unityNote=e.unityNote,t.gain=e.gain,t.fineTune=e.fineTune,t.loops=e.loops.map(s=>({...s})),t.fulOptions=e.fulOptions,t}static read(e){this.verifyHeader(e,"wsmp");let t=new kt,s=V(e.data,4);if(s!==pt&&se(`Wsmp cbSize mismatch: got ${s}, expected ${pt}.`),t.unityNote=V(e.data,2),t.fineTune=dn(e.data[e.data.currentIndex++],e.data[e.data.currentIndex++]),t.gain=V(e.data,4)|0,t.fulOptions=V(e.data,4),V(e.data,4)!==0){let a=V(e.data,4);a!==Ks&&se(`CbSize for loop in wsmp mismatch. Expected ${pt}, got ${a}.`);let o=V(e.data,4),i=V(e.data,4),r=V(e.data,4);t.loops.push({loopStart:i,loopLength:r,loopType:o})}return t}static fromSFSample(e){let t=new kt;return t.unityNote=e.originalKey,t.fineTune=e.pitchCorrection,(e.loopEnd!==0||e.loopStart!==0)&&t.loops.push({loopStart:e.loopStart,loopLength:e.loopEnd-e.loopStart,loopType:_n.forward}),t}static fromSFZone(e){let t=new kt;t.unityNote=e.getGenerator(g.overridingRootKey,e.sample.originalKey),e.getGenerator(g.scaleTuning,100)===0&&e.keyRange.max-e.keyRange.min===0&&(t.unityNote=e.keyRange.min),t.fineTune=e.fineTuning+e.sample.pitchCorrection;let s=e.getGenerator(g.initialAttenuation,0)*.4;t.gain=-s<<16;let n=e.getGenerator(g.sampleModes,0);if(n!==0){let a=e.sample.loopStart+e.getGenerator(g.startloopAddrsOffset,0)+e.getGenerator(g.startloopAddrsCoarseOffset,0)*32768,o=e.sample.loopEnd+e.getGenerator(g.endloopAddrsOffset,0)+e.getGenerator(g.endloopAddrsCoarseOffset,0)*32768,i;switch(n){case 1:default:{i=0;break}case 3:i=1}t.loops.push({loopType:i,loopStart:a,loopLength:o-a})}return t}toSFZone(e,t){let s=0,n=this.loops[0];n&&(s=n.loopType===_n.loopAndRelease?3:1),s!==0&&e.setGenerator(g.sampleModes,s);let i=-(this.gain>>16)/.4;if(i!==0&&e.setGenerator(g.initialAttenuation,i),e.fineTuning=this.fineTune-t.pitchCorrection,this.unityNote!==t.originalKey&&e.setGenerator(g.overridingRootKey,this.unityNote),n){let r=n.loopStart-t.loopStart,I=n.loopStart+n.loopLength-t.loopEnd;if(r!==0){let c=r%32768;e.setGenerator(g.startloopAddrsOffset,c);let l=Math.trunc(r/32768);l!==0&&e.setGenerator(g.startloopAddrsCoarseOffset,l)}if(I!==0){let c=I%32768;e.setGenerator(g.endloopAddrsOffset,c);let l=Math.trunc(I/32768);l!==0&&e.setGenerator(g.endloopAddrsCoarseOffset,l)}}}write(){let e=new $(pt+this.loops.length*Ks);Be(e,pt),te(e,this.unityNote),te(e,this.fineTune),Be(e,this.gain),Be(e,this.fulOptions),Be(e,this.loops.length);for(let t of this.loops)Be(e,Ks),Be(e,t.loopType),Be(e,t.loopStart),Be(e,t.loopLength);return de("wsmp",e)}},Vs={PCM:1,ALAW:6};function ih(A,e){let t=Math.pow(2,e*8-1),s=Math.pow(2,e*8),n,a=!1;e===1?(n=255,a=!0):n=t;let o=A.length/e,i=new Float32Array(o);if(e===2){let r=new Int16Array(A.buffer);for(let[h,I]of r.entries())i[h]=I/32768}else for(let r=0;r<i.length;r++){let h=V(A,e);a?i[r]=h/n-.5:(h>=t&&(h-=s),i[r]=h/n)}return i}function rh(A,e){let t=A.length/e,s=new Float32Array(t);for(let n=0;n<s.length;n++){let a=V(A,e),o=a^85;o&=127;let i=o>>4,r=o&15;i>0&&(r+=16),r=(r<<4)+8,i>1&&(r=r<<i-1);let h=a>127?r:-r;s[n]=h/32678}return s}var oh=class extends Cs{wFormatTag;bytesPerSample;rawData;constructor(A,e,t,s,n,a,o,i,r){super(A,e,t,s,xe.monoSample,n,a),this.dataOverridden=!1,this.rawData=o.data,this.wFormatTag=i,this.bytesPerSample=r}getAudioData(){if(!this.rawData)return new Float32Array(0);if(!this.audioData){let A;switch(this.wFormatTag){default:{se(`Failed to decode sample. Unknown wFormatTag: ${this.wFormatTag}`),A=new Float32Array(this.rawData.length/this.bytesPerSample);break}case Vs.PCM:{A=ih(this.rawData,this.bytesPerSample);break}case Vs.ALAW:{A=rh(this.rawData,this.bytesPerSample);break}}this.setAudioData(A,this.sampleRate)}return this.audioData??new Float32Array(0)}getRawData(A){return this.dataOverridden||this.isCompressed?super.getRawData(A):this.wFormatTag===Vs.PCM&&this.bytesPerSample===2?this.rawData:this.encodeS16LE()}},fa=class ln extends It{waveSample=new rt;wFormatTag;bytesPerSample;sampleRate;dataChunk;name="Unnamed sample";constructor(e,t,s,n){super(),this.wFormatTag=e,this.bytesPerSample=t,this.sampleRate=s,this.dataChunk=n}static read(e){let t=this.verifyAndReadList(e,"wave"),s=t.find(B=>B.header==="fmt ");if(!s)throw new Error("No fmt chunk in the wave file!");let n=V(s.data,2),a=V(s.data,2);if(a!==1)throw new Error(`Only mono samples are supported. Fmt reports ${a} channels.`);let o=V(s.data,4);V(s.data,4),V(s.data,2);let r=V(s.data,2)/8,h=t.find(B=>B.header==="data");if(!h)throw new Error("No data chunk in the WAVE chunk!");let I=new ln(n,r,o,h),c=TA(t,"INFO");if(c){let B=ge(c.data);for(;B.header!=="INAM"&&c.data.currentIndex<c.data.length;)B=ge(c.data);B.header==="INAM"&&(I.name=pe(B.data,B.size).trim())}let l=t.find(B=>B.header==="wsmp");return l&&(I.waveSample=rt.read(l)),I}static fromSFSample(e){let t=e.getRawData(!1),s=new ln(1,2,e.sampleRate,new va("data",t.length,new $(t.buffer)));return s.name=e.name,s.waveSample=rt.fromSFSample(e),s}toSFSample(e){let t=this.waveSample.unityNote,s=this.waveSample.fineTune,n=Math.trunc(s/100);t+=n,s-=n*100;let a=0,o=0,i=this.waveSample.loops?.[0];i&&(a=i.loopStart,o=i.loopStart+i.loopLength);let r=new oh(this.name,this.sampleRate,t,s,a,o,this.dataChunk,this.wFormatTag,this.bytesPerSample);e.addSamples(r)}write(){let e=this.writeFmt(),t=this.waveSample.write(),s=de("data",this.dataChunk.data),n=de("INAM",fA(this.name,!0)),a=de("INFO",n,!1,!0);return D(`%cSaved %c${this.name}%c successfully!`,E.recognized,E.value,E.recognized),Ze("wave",[e,t,s,a],!0)}writeFmt(){let e=new $(18);return te(e,this.wFormatTag),te(e,1),Be(e,this.sampleRate),Be(e,this.sampleRate*2),te(e,2),te(e,this.bytesPerSample*8),de("fmt ",e)}},oi=new be(219,0,g.reverbEffectsSend,1e3,0),hi=new be(221,0,g.chorusEffectsSend,1e3,0),hh=new be(129,0,g.vibLfoToPitch,0,0),gh=new be(13,0,g.vibLfoToPitch,0,0),hA=class Cn{source;transform;bipolar;invert;constructor(e=Z.none,t=me.linear,s=!1,n=!1){this.source=e,this.transform=t,this.bipolar=s,this.invert=n}get sourceName(){return Object.keys(Z).find(e=>Z[e]===this.source)??this.source.toString()}get transformName(){return Object.keys(me).find(e=>me[e]===this.transform)??this.transform.toString()}static copyFrom(e){return new Cn(e.source,e.transform,e.bipolar,e.invert)}static fromSFSource(e){let t;if(e.isCC)switch(e.index){case u.modulationWheel:{t=Z.modulationWheel;break}case u.mainVolume:{t=Z.volume;break}case u.pan:{t=Z.pan;break}case u.expressionController:{t=Z.expression;break}case u.chorusDepth:{t=Z.chorus;break}case u.reverbDepth:{t=Z.reverb;break}}else switch(e.index){case Ae.noController:{t=Z.none;break}case Ae.noteOnKeyNum:{t=Z.keyNum;break}case Ae.noteOnVelocity:{t=Z.velocity;break}case Ae.pitchWheel:{t=Z.pitchWheel;break}case Ae.pitchWheelRange:{t=Z.pitchWheelRange;break}case Ae.polyPressure:{t=Z.polyPressure;break}case Ae.channelPressure:t=Z.channelPressure}if(t!==void 0)return new Cn(t,e.curveType,e.isBipolar,e.isNegative)}toString(){return`${this.sourceName} ${this.transformName} ${this.bipolar?"bipolar":"unipolar"} ${this.invert?"inverted":"positive"}`}toTransformFlag(){return this.transform|(this.bipolar?1:0)<<4|(this.invert?1:0)<<5}toSFSource(){let e,t=!1;switch(this.source){default:case Z.modLfo:case Z.vibratoLfo:case Z.coarseTune:case Z.fineTune:case Z.modEnv:return;case Z.keyNum:{e=Ae.noteOnKeyNum;break}case Z.none:{e=Ae.noController;break}case Z.modulationWheel:{e=u.modulationWheel,t=!0;break}case Z.pan:{e=u.pan,t=!0;break}case Z.reverb:{e=u.reverbDepth,t=!0;break}case Z.chorus:{e=u.chorusDepth,t=!0;break}case Z.expression:{e=u.expressionController,t=!0;break}case Z.volume:{e=u.mainVolume,t=!0;break}case Z.velocity:{e=Ae.noteOnVelocity;break}case Z.polyPressure:{e=Ae.polyPressure;break}case Z.channelPressure:{e=Ae.channelPressure;break}case Z.pitchWheel:{e=Ae.pitchWheel;break}case Z.pitchWheelRange:{e=Ae.pitchWheelRange;break}}if(e!==void 0)return new cA(e,this.transform,t,this.bipolar,this.invert)}},Ih=new Set([g.sampleModes,g.initialAttenuation,g.keyRange,g.velRange,g.sampleID,g.fineTune,g.coarseTune,g.startAddrsOffset,g.startAddrsCoarseOffset,g.endAddrOffset,g.endAddrsCoarseOffset,g.startloopAddrsOffset,g.startloopAddrsCoarseOffset,g.endloopAddrsOffset,g.endloopAddrsCoarseOffset,g.overridingRootKey,g.exclusiveClass]),yt=class JA{source;control;destination;scale;transform;constructor(e=new hA,t=new hA,s,n,a){this.source=e,this.control=t,this.destination=s,this.transform=n,this.scale=a}get isStaticParameter(){return this.source.source===Z.none&&this.control.source===Z.none}get shortScale(){return this.scale>>16}get transformName(){return Object.keys(me).find(e=>me[e]===this.transform)??this.transform.toString()}get destinationName(){return Object.keys(L).find(e=>L[e]===this.destination)??this.destination.toString()}static read(e){let t=V(e,2),s=V(e,2),n=V(e,2),a=V(e,2),o=V(e,4)|0,i=a&15,r=a>>4&15,h=KA(a,8),I=KA(a,9),c=new hA(s,r,h,I),l=a>>10&15,B=KA(a,14),d=KA(a,15),p=new hA(t,l,B,d);return new JA(p,c,n,i,o)}static fromSFModulator(e,t){let s=I=>{se(`Failed converting SF modulator into DLS:
8
8
  ${e.toString()}
9
9
  (${I})`)};if(e.transformType!==0){s("Absolute transform type is not supported");return}if(Re.isIdentical(e,hi,!0)||Re.isIdentical(e,oi,!0))return;let n=hA.fromSFSource(e.primarySource);if(!n){s("Invalid primary source");return}let a=hA.fromSFSource(e.secondarySource);if(!a){s("Invalid secondary source");return}let o=JA.fromSFDestination(e.destination,e.transformAmount);if(o===void 0){s("Invalid destination");return}let i=e.transformAmount,r;if(typeof o=="number")r=o;else if(r=o.destination,i=o.amount,o.source!==Z.none){if(a.source!==Z.none&&n.source!==Z.none){s("Articulation generators with secondary source are not supported");return}n.source!==Z.none&&(a=n),n=new hA(o.source,me.linear,o.isBipolar)}let h=new JA(n,a,r,0,i<<16);t.connectionBlocks.push(h)}static copyFrom(e){return new JA(hA.copyFrom(e.source),hA.copyFrom(e.control),e.destination,e.transform,e.scale)}static fromSFGenerator(e,t){if(Ih.has(e.generatorType))return;let s=r=>{se(`Failed converting SF2 generator into DLS: