From 991d66d6ebac154c0bd6414cb1849c626ee6cfda Mon Sep 17 00:00:00 2001 From: spessasus Date: Sat, 28 Dec 2024 14:34:14 +0100 Subject: [PATCH] minify --- .../synthetizer/worklet_processor.min.js | 24 +++++++++---------- .../worklet_system/main_processor.js | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/spessasynth_lib/synthetizer/worklet_processor.min.js b/src/spessasynth_lib/synthetizer/worklet_processor.min.js index 70dc169..4bbc75e 100644 --- a/src/spessasynth_lib/synthetizer/worklet_processor.min.js +++ b/src/spessasynth_lib/synthetizer/worklet_processor.min.js @@ -1,19 +1,19 @@ -var Ds=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(A,e)=>(typeof require<"u"?require:A)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var b=class extends Uint8Array{currentIndex;constructor(A){super(A),this.currentIndex=0}};function cA(t){let A=t.reduce((n,o)=>n+o.length,0),e=new b(A),s=0;for(let n of t)e.set(n,s),s+=n.length;return e}function Ut(t){t=Math.floor(t);let A=Math.floor(t/60),e=Math.round(t-A*60);return{minutes:A,seconds:e,time:`${A.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}}function ks(t){return t.trim().replaceAll(".mid","").replaceAll(".rmi","").replaceAll("_"," ")}function SA(t){let A="";for(let e=0;e=128&&A<=224&&(s=e,n=A),{status:n,channel:s}}var k={bankSelect:0,modulationWheel:1,breathController:2,footController:4,portamentoTime:5,dataEntryMsb:6,mainVolume:7,balance:8,pan:10,expressionController:11,effectControl1:12,effectControl2:13,generalPurposeController1:16,generalPurposeController2:17,generalPurposeController3:18,generalPurposeController4:19,lsbForControl0BankSelect:32,lsbForControl1ModulationWheel:33,lsbForControl2BreathController:34,lsbForControl4FootController:36,lsbForControl5PortamentoTime:37,lsbForControl6DataEntry:38,lsbForControl7MainVolume:39,lsbForControl8Balance:40,lsbForControl10Pan:42,lsbForControl11ExpressionController:43,lsbForControl12EffectControl1:44,lsbForControl13EffectControl2:45,sustainPedal:64,portamentoOnOff:65,sostenutoPedal:66,softPedal:67,legatoFootswitch:68,hold2Pedal:69,soundVariation:70,timbreHarmonicContent:71,releaseTime:72,attackTime:73,brightness:74,soundController6:75,soundController7:76,soundController8:77,soundController9:78,soundController10:79,generalPurposeController5:80,generalPurposeController6:81,generalPurposeController7:82,generalPurposeController8:83,portamentoControl:84,reverbDepth:91,tremoloDepth:92,chorusDepth:93,detuneDepth:94,phaserDepth:95,dataIncrement:96,dataDecrement:97,NRPNLsb:98,NRPNMsb:99,RPNLsb:100,RPNMsb:101,allSoundOff:120,resetAllControllers:121,localControlOnOff:122,allNotesOff:123,omniModeOff:124,omniModeOn:125,monoModeOn:126,polyModeOn:127},Fs={8:2,9:2,10:2,11:2,12:1,13:1,14:2};var sA={noteOff:0,noteOn:1,ccChange:2,programChange:3,channelPressure:4,polyPressure:5,killNote:6,ccReset:7,setChannelVibrato:8,soundFontManager:9,stopAll:10,killNotes:11,muteChannel:12,addNewChannel:13,customcCcChange:14,debugMessage:15,systemExclusive:16,setMasterParameter:17,setDrums:18,pitchWheel:19,transpose:20,highPerformanceMode:21,lockController:22,sequencerSpecific:23,requestSynthesizerSnapshot:24,setLogLevel:25,keyModifierManager:26,setEffectsGain:27,destroyWorklet:28},me={mainVolume:0,masterPan:1,voicesCap:2,interpolationType:3},OA=-1,DA={channelProperties:0,eventCall:1,reportedCurrentTime:2,sequencerSpecific:3,synthesizerSnapshot:4,ready:5,soundfontError:6,identify:7};var Rs=!1,Gs=!0,Xe=!1,Ms=!0;function xs(t,A,e,s){Rs=t,Gs=A,Xe=e,Ms=s}function p(...t){Rs&&console.info(...t)}function T(...t){Gs&&console.warn(...t)}function Ns(...t){Ms&&console.table(...t)}function Ce(...t){Xe&&console.group(...t)}function QA(...t){Xe&&console.groupCollapsed(...t)}function V(){Xe&&console.groupEnd()}var pe={reloadSoundFont:0,addNewSoundFont:2,deleteSoundFont:3,rearrangeSoundFonts:4};var r={INVALID:-1,startAddrsOffset:0,endAddrOffset:1,startloopAddrsOffset:2,endloopAddrsOffset:3,startAddrsCoarseOffset:4,modLfoToPitch:5,vibLfoToPitch:6,modEnvToPitch:7,initialFilterFc:8,initialFilterQ:9,modLfoToFilterFc:10,modEnvToFilterFc:11,endAddrsCoarseOffset:12,modLfoToVolume:13,unused1:14,chorusEffectsSend:15,reverbEffectsSend:16,pan:17,unused2:18,unused3:19,unused4:20,delayModLFO:21,freqModLFO:22,delayVibLFO:23,freqVibLFO:24,delayModEnv:25,attackModEnv:26,holdModEnv:27,decayModEnv:28,sustainModEnv:29,releaseModEnv:30,keyNumToModEnvHold:31,keyNumToModEnvDecay:32,delayVolEnv:33,attackVolEnv:34,holdVolEnv:35,decayVolEnv:36,sustainVolEnv:37,releaseVolEnv:38,keyNumToVolEnvHold:39,keyNumToVolEnvDecay:40,instrument:41,reserved1:42,keyRange:43,velRange:44,startloopAddrsCoarseOffset:45,keyNum:46,velocity:47,initialAttenuation:48,reserved2:49,endloopAddrsCoarseOffset:50,coarseTune:51,fineTune:52,sampleID:53,sampleModes:54,reserved3:55,scaleTuning:56,exclusiveClass:57,overridingRootKey:58,unused5:59,endOper:60},J=[];J[r.startAddrsOffset]={min:0,max:32768,def:0};J[r.endAddrOffset]={min:-32768,max:32768,def:0};J[r.startloopAddrsOffset]={min:-32768,max:32768,def:0};J[r.endloopAddrsOffset]={min:-32768,max:32768,def:0};J[r.startAddrsCoarseOffset]={min:0,max:32768,def:0};J[r.modLfoToPitch]={min:-12e3,max:12e3,def:0};J[r.vibLfoToPitch]={min:-12e3,max:12e3,def:0};J[r.modEnvToPitch]={min:-12e3,max:12e3,def:0};J[r.initialFilterFc]={min:1500,max:13500,def:13500};J[r.initialFilterQ]={min:0,max:960,def:0};J[r.modLfoToFilterFc]={min:-12e3,max:12e3,def:0};J[r.modEnvToFilterFc]={min:-12e3,max:12e3,def:0};J[r.endAddrsCoarseOffset]={min:-32768,max:32768,def:0};J[r.modLfoToVolume]={min:-960,max:960,def:0};J[r.chorusEffectsSend]={min:0,max:1e3,def:0};J[r.reverbEffectsSend]={min:0,max:1e3,def:0};J[r.pan]={min:-500,max:500,def:0};J[r.delayModLFO]={min:-12e3,max:5e3,def:-12e3};J[r.freqModLFO]={min:-16e3,max:4500,def:0};J[r.delayVibLFO]={min:-12e3,max:5e3,def:-12e3};J[r.freqVibLFO]={min:-16e3,max:4500,def:0};J[r.delayModEnv]={min:-32768,max:5e3,def:-32768};J[r.attackModEnv]={min:-32768,max:8e3,def:-32768};J[r.holdModEnv]={min:-12e3,max:5e3,def:-12e3};J[r.decayModEnv]={min:-12e3,max:8e3,def:-12e3};J[r.sustainModEnv]={min:0,max:1e3,def:0};J[r.releaseModEnv]={min:-7200,max:8e3,def:-12e3};J[r.keyNumToModEnvHold]={min:-1200,max:1200,def:0};J[r.keyNumToModEnvDecay]={min:-1200,max:1200,def:0};J[r.delayVolEnv]={min:-12e3,max:5e3,def:-12e3};J[r.attackVolEnv]={min:-12e3,max:8e3,def:-12e3};J[r.holdVolEnv]={min:-12e3,max:5e3,def:-12e3};J[r.decayVolEnv]={min:-12e3,max:8e3,def:-12e3};J[r.sustainVolEnv]={min:0,max:1440,def:0};J[r.releaseVolEnv]={min:-7200,max:8e3,def:-12e3};J[r.keyNumToVolEnvHold]={min:-1200,max:1200,def:0};J[r.keyNumToVolEnvDecay]={min:-1200,max:1200,def:0};J[r.startloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};J[r.keyNum]={min:-1,max:127,def:-1};J[r.velocity]={min:-1,max:127,def:-1};J[r.initialAttenuation]={min:-250,max:1440,def:0};J[r.endloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};J[r.coarseTune]={min:-120,max:120,def:0};J[r.fineTune]={min:-12700,max:12700,def:0};J[r.scaleTuning]={min:0,max:1200,def:100};J[r.exclusiveClass]={min:0,max:99999,def:0};J[r.overridingRootKey]={min:-1,max:127,def:-1};J[r.sampleModes]={min:0,max:3,def:0};var N=class{generatorType=r.INVALID;generatorValue=0;constructor(A=r.INVALID,e=0,s=!0){if(this.generatorType=A,e===void 0)throw new Error("No value provided.");if(this.generatorValue=Math.round(e),s){let n=J[A];n!==void 0&&(this.generatorValue=Math.max(n.min,Math.min(n.max,this.generatorValue)))}}};function bs(t,A,e){let s=J[t]||{min:0,max:32768,def:0},n=A.find(B=>B.generatorType===t),o=0;n&&(o=n.generatorValue);let i=e.find(B=>B.generatorType===t),a=s.def;i&&(a=i.generatorValue);let C=a+o;return t===r.initialAttenuation?C:Math.max(s.min,Math.min(s.max,C))}var q={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},uA={linear:0,concave:1,convex:2,switch:3},P=class t{currentValue=0;constructor(A){this.sourceEnum=A.srcEnum,this.modulatorDestination=A.dest,this.secondarySourceEnum=A.secSrcEnum,this.transformAmount=A.amt,this.transformType=A.transform,this.modulatorDestination>58&&(this.modulatorDestination=r.INVALID),this.sourcePolarity=this.sourceEnum>>9&1,this.sourceDirection=this.sourceEnum>>8&1,this.sourceUsesCC=this.sourceEnum>>7&1,this.sourceIndex=this.sourceEnum&127,this.sourceCurveType=this.sourceEnum>>10&3,this.secSrcPolarity=this.secondarySourceEnum>>9&1,this.secSrcDirection=this.secondarySourceEnum>>8&1,this.secSrcUsesCC=this.secondarySourceEnum>>7&1,this.secSrcIndex=this.secondarySourceEnum&127,this.secSrcCurveType=this.secondarySourceEnum>>10&3,this.isEffectModulator=(this.sourceEnum===219||this.sourceEnum===221)&&this.secondarySourceEnum===0&&(this.modulatorDestination===r.reverbEffectsSend||this.modulatorDestination===r.chorusEffectsSend)}static copy(A){return new t({srcEnum:A.sourceEnum,secSrcEnum:A.secondarySourceEnum,transform:A.transformType,amt:A.transformAmount,dest:A.modulatorDestination})}static isIdentical(A,e,s=!1){return A.sourceEnum===e.sourceEnum&&A.modulatorDestination===e.modulatorDestination&&A.secondarySourceEnum===e.secondarySourceEnum&&A.transformType===e.transformType&&(!s||A.transformAmount===e.transformAmount)}sumTransform(A){return new t({srcEnum:this.sourceEnum,secSrcEnum:this.secondarySourceEnum,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+A.transformAmount})}debugString(){function A(n,o){return Object.keys(n).find(i=>n[i]===o)}let e=A(uA,this.sourceCurveType);e+=this.sourcePolarity===0?" unipolar ":" bipolar ",e+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?e+=A(k,this.sourceIndex):e+=A(q,this.sourceIndex);let s=A(uA,this.secSrcCurveType);return s+=this.secSrcPolarity===0?" unipolar ":" bipolar ",s+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?s+=A(k,this.secSrcIndex):s+=A(q,this.secSrcIndex),`Modulator: +var Fn=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(A,e)=>(typeof require<"u"?require:A)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var b=class extends Uint8Array{currentIndex;constructor(A){super(A),this.currentIndex=0}};function cA(t){let A=t.reduce((s,o)=>s+o.length,0),e=new b(A),n=0;for(let s of t)e.set(s,n),n+=s.length;return e}function vt(t){t=Math.floor(t);let A=Math.floor(t/60),e=Math.round(t-A*60);return{minutes:A,seconds:e,time:`${A.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}}function Rn(t){return t.trim().replaceAll(".mid","").replaceAll(".rmi","").replaceAll("_"," ")}function SA(t){let A="";for(let e=0;e=128&&A<=224&&(n=e,s=A),{status:s,channel:n}}var k={bankSelect:0,modulationWheel:1,breathController:2,footController:4,portamentoTime:5,dataEntryMsb:6,mainVolume:7,balance:8,pan:10,expressionController:11,effectControl1:12,effectControl2:13,generalPurposeController1:16,generalPurposeController2:17,generalPurposeController3:18,generalPurposeController4:19,lsbForControl0BankSelect:32,lsbForControl1ModulationWheel:33,lsbForControl2BreathController:34,lsbForControl4FootController:36,lsbForControl5PortamentoTime:37,lsbForControl6DataEntry:38,lsbForControl7MainVolume:39,lsbForControl8Balance:40,lsbForControl10Pan:42,lsbForControl11ExpressionController:43,lsbForControl12EffectControl1:44,lsbForControl13EffectControl2:45,sustainPedal:64,portamentoOnOff:65,sostenutoPedal:66,softPedal:67,legatoFootswitch:68,hold2Pedal:69,soundVariation:70,timbreHarmonicContent:71,releaseTime:72,attackTime:73,brightness:74,soundController6:75,soundController7:76,soundController8:77,soundController9:78,soundController10:79,generalPurposeController5:80,generalPurposeController6:81,generalPurposeController7:82,generalPurposeController8:83,portamentoControl:84,reverbDepth:91,tremoloDepth:92,chorusDepth:93,detuneDepth:94,phaserDepth:95,dataIncrement:96,dataDecrement:97,NRPNLsb:98,NRPNMsb:99,RPNLsb:100,RPNMsb:101,allSoundOff:120,resetAllControllers:121,localControlOnOff:122,allNotesOff:123,omniModeOff:124,omniModeOn:125,monoModeOn:126,polyModeOn:127},Mn={8:2,9:2,10:2,11:2,12:1,13:1,14:2};var nA={noteOff:0,noteOn:1,ccChange:2,programChange:3,channelPressure:4,polyPressure:5,killNote:6,ccReset:7,setChannelVibrato:8,soundFontManager:9,stopAll:10,killNotes:11,muteChannel:12,addNewChannel:13,customcCcChange:14,debugMessage:15,systemExclusive:16,setMasterParameter:17,setDrums:18,pitchWheel:19,transpose:20,highPerformanceMode:21,lockController:22,sequencerSpecific:23,requestSynthesizerSnapshot:24,setLogLevel:25,keyModifierManager:26,setEffectsGain:27,destroyWorklet:28},me={mainVolume:0,masterPan:1,voicesCap:2,interpolationType:3},VA=-1,DA={channelProperties:0,eventCall:1,reportedCurrentTime:2,sequencerSpecific:3,synthesizerSnapshot:4,ready:5,soundfontError:6,identify:7};var xn=!1,Nn=!0,Xe=!1,bn=!0;function Ln(t,A,e,n){xn=t,Nn=A,Xe=e,bn=n}function p(...t){xn&&console.info(...t)}function T(...t){Nn&&console.warn(...t)}function Un(...t){bn&&console.table(...t)}function Ce(...t){Xe&&console.group(...t)}function QA(...t){Xe&&console.groupCollapsed(...t)}function O(){Xe&&console.groupEnd()}var pe={reloadSoundFont:0,addNewSoundFont:2,deleteSoundFont:3,rearrangeSoundFonts:4};var r={INVALID:-1,startAddrsOffset:0,endAddrOffset:1,startloopAddrsOffset:2,endloopAddrsOffset:3,startAddrsCoarseOffset:4,modLfoToPitch:5,vibLfoToPitch:6,modEnvToPitch:7,initialFilterFc:8,initialFilterQ:9,modLfoToFilterFc:10,modEnvToFilterFc:11,endAddrsCoarseOffset:12,modLfoToVolume:13,unused1:14,chorusEffectsSend:15,reverbEffectsSend:16,pan:17,unused2:18,unused3:19,unused4:20,delayModLFO:21,freqModLFO:22,delayVibLFO:23,freqVibLFO:24,delayModEnv:25,attackModEnv:26,holdModEnv:27,decayModEnv:28,sustainModEnv:29,releaseModEnv:30,keyNumToModEnvHold:31,keyNumToModEnvDecay:32,delayVolEnv:33,attackVolEnv:34,holdVolEnv:35,decayVolEnv:36,sustainVolEnv:37,releaseVolEnv:38,keyNumToVolEnvHold:39,keyNumToVolEnvDecay:40,instrument:41,reserved1:42,keyRange:43,velRange:44,startloopAddrsCoarseOffset:45,keyNum:46,velocity:47,initialAttenuation:48,reserved2:49,endloopAddrsCoarseOffset:50,coarseTune:51,fineTune:52,sampleID:53,sampleModes:54,reserved3:55,scaleTuning:56,exclusiveClass:57,overridingRootKey:58,unused5:59,endOper:60},J=[];J[r.startAddrsOffset]={min:0,max:32768,def:0};J[r.endAddrOffset]={min:-32768,max:32768,def:0};J[r.startloopAddrsOffset]={min:-32768,max:32768,def:0};J[r.endloopAddrsOffset]={min:-32768,max:32768,def:0};J[r.startAddrsCoarseOffset]={min:0,max:32768,def:0};J[r.modLfoToPitch]={min:-12e3,max:12e3,def:0};J[r.vibLfoToPitch]={min:-12e3,max:12e3,def:0};J[r.modEnvToPitch]={min:-12e3,max:12e3,def:0};J[r.initialFilterFc]={min:1500,max:13500,def:13500};J[r.initialFilterQ]={min:0,max:960,def:0};J[r.modLfoToFilterFc]={min:-12e3,max:12e3,def:0};J[r.modEnvToFilterFc]={min:-12e3,max:12e3,def:0};J[r.endAddrsCoarseOffset]={min:-32768,max:32768,def:0};J[r.modLfoToVolume]={min:-960,max:960,def:0};J[r.chorusEffectsSend]={min:0,max:1e3,def:0};J[r.reverbEffectsSend]={min:0,max:1e3,def:0};J[r.pan]={min:-500,max:500,def:0};J[r.delayModLFO]={min:-12e3,max:5e3,def:-12e3};J[r.freqModLFO]={min:-16e3,max:4500,def:0};J[r.delayVibLFO]={min:-12e3,max:5e3,def:-12e3};J[r.freqVibLFO]={min:-16e3,max:4500,def:0};J[r.delayModEnv]={min:-32768,max:5e3,def:-32768};J[r.attackModEnv]={min:-32768,max:8e3,def:-32768};J[r.holdModEnv]={min:-12e3,max:5e3,def:-12e3};J[r.decayModEnv]={min:-12e3,max:8e3,def:-12e3};J[r.sustainModEnv]={min:0,max:1e3,def:0};J[r.releaseModEnv]={min:-7200,max:8e3,def:-12e3};J[r.keyNumToModEnvHold]={min:-1200,max:1200,def:0};J[r.keyNumToModEnvDecay]={min:-1200,max:1200,def:0};J[r.delayVolEnv]={min:-12e3,max:5e3,def:-12e3};J[r.attackVolEnv]={min:-12e3,max:8e3,def:-12e3};J[r.holdVolEnv]={min:-12e3,max:5e3,def:-12e3};J[r.decayVolEnv]={min:-12e3,max:8e3,def:-12e3};J[r.sustainVolEnv]={min:0,max:1440,def:0};J[r.releaseVolEnv]={min:-7200,max:8e3,def:-12e3};J[r.keyNumToVolEnvHold]={min:-1200,max:1200,def:0};J[r.keyNumToVolEnvDecay]={min:-1200,max:1200,def:0};J[r.startloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};J[r.keyNum]={min:-1,max:127,def:-1};J[r.velocity]={min:-1,max:127,def:-1};J[r.initialAttenuation]={min:-250,max:1440,def:0};J[r.endloopAddrsCoarseOffset]={min:-32768,max:32768,def:0};J[r.coarseTune]={min:-120,max:120,def:0};J[r.fineTune]={min:-12700,max:12700,def:0};J[r.scaleTuning]={min:0,max:1200,def:100};J[r.exclusiveClass]={min:0,max:99999,def:0};J[r.overridingRootKey]={min:-1,max:127,def:-1};J[r.sampleModes]={min:0,max:3,def:0};var N=class{generatorType=r.INVALID;generatorValue=0;constructor(A=r.INVALID,e=0,n=!0){if(this.generatorType=A,e===void 0)throw new Error("No value provided.");if(this.generatorValue=Math.round(e),n){let s=J[A];s!==void 0&&(this.generatorValue=Math.max(s.min,Math.min(s.max,this.generatorValue)))}}};function Tn(t,A,e){let n=J[t]||{min:0,max:32768,def:0},s=A.find(B=>B.generatorType===t),o=0;s&&(o=s.generatorValue);let i=e.find(B=>B.generatorType===t),a=n.def;i&&(a=i.generatorValue);let C=a+o;return t===r.initialAttenuation?C:Math.max(n.min,Math.min(n.max,C))}var q={noController:0,noteOnVelocity:2,noteOnKeyNum:3,polyPressure:10,channelPressure:13,pitchWheel:14,pitchWheelRange:16,link:127},uA={linear:0,concave:1,convex:2,switch:3},P=class t{currentValue=0;constructor(A){this.sourceEnum=A.srcEnum,this.modulatorDestination=A.dest,this.secondarySourceEnum=A.secSrcEnum,this.transformAmount=A.amt,this.transformType=A.transform,this.modulatorDestination>58&&(this.modulatorDestination=r.INVALID),this.sourcePolarity=this.sourceEnum>>9&1,this.sourceDirection=this.sourceEnum>>8&1,this.sourceUsesCC=this.sourceEnum>>7&1,this.sourceIndex=this.sourceEnum&127,this.sourceCurveType=this.sourceEnum>>10&3,this.secSrcPolarity=this.secondarySourceEnum>>9&1,this.secSrcDirection=this.secondarySourceEnum>>8&1,this.secSrcUsesCC=this.secondarySourceEnum>>7&1,this.secSrcIndex=this.secondarySourceEnum&127,this.secSrcCurveType=this.secondarySourceEnum>>10&3,this.isEffectModulator=(this.sourceEnum===219||this.sourceEnum===221)&&this.secondarySourceEnum===0&&(this.modulatorDestination===r.reverbEffectsSend||this.modulatorDestination===r.chorusEffectsSend)}static copy(A){return new t({srcEnum:A.sourceEnum,secSrcEnum:A.secondarySourceEnum,transform:A.transformType,amt:A.transformAmount,dest:A.modulatorDestination})}static isIdentical(A,e,n=!1){return A.sourceEnum===e.sourceEnum&&A.modulatorDestination===e.modulatorDestination&&A.secondarySourceEnum===e.secondarySourceEnum&&A.transformType===e.transformType&&(!n||A.transformAmount===e.transformAmount)}sumTransform(A){return new t({srcEnum:this.sourceEnum,secSrcEnum:this.secondarySourceEnum,dest:this.modulatorDestination,transform:this.transformType,amt:this.transformAmount+A.transformAmount})}debugString(){function A(s,o){return Object.keys(s).find(i=>s[i]===o)}let e=A(uA,this.sourceCurveType);e+=this.sourcePolarity===0?" unipolar ":" bipolar ",e+=this.sourceDirection===0?"forwards ":"backwards ",this.sourceUsesCC?e+=A(k,this.sourceIndex):e+=A(q,this.sourceIndex);let n=A(uA,this.secSrcCurveType);return n+=this.secSrcPolarity===0?" unipolar ":" bipolar ",n+=this.secSrcCurveType===0?"forwards ":"backwards ",this.secSrcUsesCC?n+=A(k,this.secSrcIndex):n+=A(q,this.secSrcIndex),`Modulator: Source: ${e} - Secondary source: ${s} + Secondary source: ${n} Destination: ${A(r,this.modulatorDestination)} Trasform amount: ${this.transformAmount} Transform type: ${this.transformType} -`}},Tt=960,vt=uA.concave;function VA(t,A,e,s,n){return t<<10|A<<9|e<<8|s<<7|n}var gr=[new P({srcEnum:VA(vt,0,1,0,q.noteOnVelocity),dest:r.initialAttenuation,amt:Tt,secSrcEnum:0,transform:0}),new P({srcEnum:129,dest:r.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new P({srcEnum:VA(vt,0,1,1,k.mainVolume),dest:r.initialAttenuation,amt:Tt,secSrcEnum:0,transform:0}),new P({srcEnum:13,dest:r.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new P({srcEnum:526,dest:r.fineTune,amt:12700,secSrcEnum:16,transform:0}),new P({srcEnum:650,dest:r.pan,amt:500,secSrcEnum:0,transform:0}),new P({srcEnum:VA(vt,0,1,1,k.expressionController),dest:r.initialAttenuation,amt:Tt,secSrcEnum:0,transform:0}),new P({srcEnum:219,dest:r.reverbEffectsSend,amt:200,secSrcEnum:0,transform:0}),new P({srcEnum:221,dest:r.chorusEffectsSend,amt:200,secSrcEnum:0,transform:0})],Ir=[new P({srcEnum:VA(uA.linear,0,0,0,q.polyPressure),dest:r.vibLfoToPitch,amt:50,secSrcEnum:0,transform:0}),new P({srcEnum:VA(uA.linear,0,0,1,k.tremoloDepth),dest:r.modLfoToVolume,amt:24,secSrcEnum:0,transform:0}),new P({srcEnum:VA(uA.linear,1,0,1,k.releaseTime),dest:r.releaseVolEnv,amt:1200,secSrcEnum:0,transform:0}),new P({srcEnum:VA(uA.linear,1,0,1,k.brightness),dest:r.initialFilterFc,amt:6e3,secSrcEnum:0,transform:0}),new P({srcEnum:VA(uA.linear,1,0,1,k.timbreHarmonicContent),dest:r.initialFilterQ,amt:250,secSrcEnum:0,transform:0})],_e=gr.concat(Ir);var dA=128,ze=147,ye=new Int16Array(ze).fill(0),kA=(t,A)=>ye[t]=A<<7;kA(k.mainVolume,100);kA(k.balance,64);kA(k.expressionController,127);kA(k.pan,64);kA(k.timbreHarmonicContent,64);kA(k.releaseTime,64);kA(k.attackTime,64);kA(k.brightness,64);kA(k.soundController6,64);kA(k.soundController7,64);kA(k.soundController8,64);kA(k.soundController9,64);kA(k.generalPurposeController6,64);kA(k.generalPurposeController8,64);kA(dA+q.pitchWheel,64);kA(dA+q.pitchWheelRange,2);var hA={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},Ht=Object.keys(hA).length,Yt=new Float32Array(Ht);Yt[hA.modulationMultiplier]=1;var wA={Idle:0,RPCoarse:1,RPFine:2,NRPCoarse:3,NRPFine:4,DataCoarse:5,DataFine:6};function Ls(t=!1){let A={midiControllers:new Int16Array(ze),lockedControllers:Array(ze).fill(!1),customControllers:new Float32Array(Ht),NRPCoarse:0,NRPFine:0,RPValue:0,dataEntryState:wA.Idle,voices:[],sustainedVoices:[],cachedVoices:[],preset:this.defaultPreset,presetUsesOverride:!1,channelTransposeKeyShift:0,channelOctaveTuning:new Int8Array(12),keyCentTuning:new Int16Array(128),channelVibrato:{delay:0,depth:0,rate:0},velocityOverride:0,lockGSNRPNParams:!1,holdPedal:!1,isMuted:!1,drumChannel:!1,lockPreset:!1};for(let e=0;e<128;e++)A.cachedVoices.push([]);this.workletProcessorChannels.push(A),this.resetControllers(this.workletProcessorChannels.length-1),this.sendChannelProperties(),t&&this.callEvent("newchannel",void 0)}function se(t,A){t.lockPreset||(t.bank=A)}function XA(t){return t.drumChannel?128:t.bank}var Jt={velocityOverride:128};var je={addMapping:0,deleteMapping:1,clearMappings:2},$e=class{_keyMappings=[];handleMessage(A,e){switch(A){default:return;case je.addMapping:this.addMapping(...e);break;case je.clearMappings:this.clearMappings();break;case je.deleteMapping:this.deleteMapping(...e)}}addMapping(A,e,s){this._keyMappings[A]===void 0&&(this._keyMappings[A]=[]),this._keyMappings[A][e]=s}deleteMapping(A,e){this._keyMappings[A]?.[e]!==void 0&&(this._keyMappings[A][e]=void 0)}clearMappings(){this._keyMappings=[]}setMappings(A){this._keyMappings=A}getMappings(){return this._keyMappings}getVelocity(A,e){let s=this._keyMappings[A]?.[e];return s?s.velocity:-1}hasOverridePatch(A,e){let s=this._keyMappings[A]?.[e]?.patch?.bank;return s!==void 0&&s>=0}getPatch(A,e){let s=this._keyMappings[A]?.[e];if(s)return s.patch;throw new Error("No modifier.")}};var Us="spessasynth-worklet-system",Ts=350,GA=9,At=16,et="gs";var NA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10,setPreservePlaybackState:11},bA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6};function _A(t,A){let e=0;for(let s=8*(A-1);s>=0;s-=8)e|=t[t.currentIndex++]<>>0}function vs(t,A){if(this.ignoreEvents)return;if(this.sendMIDIMessages&&t.messageStatusByte>=128){this.sendMIDIMessage([t.messageStatusByte,...t.messageData]);return}let e=be(t.messageStatusByte),s=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(e.channel+=s,e.status){case M.noteOn:let n=t.messageData[1];if(n>0)this.synth.noteOn(e.channel,t.messageData[0],n),this.playingNotes.push({midiNote:t.messageData[0],channel:e.channel,velocity:n});else{this.synth.noteOff(e.channel,t.messageData[0]);let i=this.playingNotes.findIndex(a=>a.midiNote===t.messageData[0]&&a.channel===e.channel);i!==-1&&this.playingNotes.splice(i,1)}break;case M.noteOff:this.synth.noteOff(e.channel,t.messageData[0]);let o=this.playingNotes.findIndex(i=>i.midiNote===t.messageData[0]&&i.channel===e.channel);o!==-1&&this.playingNotes.splice(o,1);break;case M.pitchBend:this.synth.pitchWheel(e.channel,t.messageData[1],t.messageData[0]);break;case M.controllerChange:this.synth.controllerChange(e.channel,t.messageData[0],t.messageData[1]);break;case M.programChange:this.synth.programChange(e.channel,t.messageData[0]);break;case M.polyPressure:this.synth.polyPressure(e.channel,t.messageData[0],t.messageData[1]);break;case M.channelPressure:this.synth.channelPressure(e.channel,t.messageData[0]);break;case M.systemExclusive:this.synth.systemExclusive(t.messageData,s);break;case M.setTempo:this.oneTickToSeconds=60/(Er(t)*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),T("invalid tempo! falling back to 120 BPM"));break;case M.timeSignature:case M.endOfTrack:case M.midiChannelPrefix:case M.songPosition:case M.activeSensing:case M.keySignature:case M.sequenceNumber:case M.sequenceSpecific:break;case M.text:case M.lyric:case M.copyright:case M.trackName:case M.marker:case M.cuePoint:case M.instrumentName:case M.programName:this.post(bA.textEvent,[t.messageData,e.status]);break;case M.midiPort:this.assignMIDIPort(A,t.messageData[0]);break;case M.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:T(`%cUnrecognized Event: %c${t.messageStatusByte}%c status byte: %c${Object.keys(M).find(i=>M[i]===e.status)}`,g.warn,g.unrecognized,g.warn,g.value);break}}function Hs(){for(let t=0;t<16;t++)this.synth.createWorkletChannel(!0),t===GA&&this.synth.setDrums(this.synth.workletProcessorChannels.length-1,!0)}function Er(t){return t.messageData.currentIndex=0,6e7/_A(t.messageData,3)}function Ys(){let t=this.currentTime;for(;this.playedTime1&&this.nextSong();return}let s=this.tracks[A][this.eventIndex[A]];if(this.playedTime+=this.oneTickToSeconds*(s.ticks-e.ticks),this.midiData.loop.end<=e.ticks&&this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}else if(t>=this.duration){if(this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function Js(){let t=0,A=1/0;return this.tracks.forEach((e,s)=>{this.eventIndex[s]>=e.length||e[this.eventIndex[s]].ticks>>0}function De(t,A,e){for(let s=0;s>s*8&255}function L(t,A){t[t.currentIndex++]=A&255,t[t.currentIndex++]=A>>8}function K(t,A){De(t,A,4)}function ne(t,A){let e=A<<8|t;return e>32767?e-65536:e}function Ps(t){return t>127?t-256:t}function _(t,A,e=void 0,s=!0){if(e){let n=t.slice(t.currentIndex,t.currentIndex+A);return t.currentIndex+=A,new TextDecoder(e.replace(/[^\x20-\x7E]/g,"")).decode(n.buffer)}else{let n=!1,o="";for(let i=0;i127)&&a!==10){if(s){n=!0;continue}else if(a===0){n=!0;continue}}o+=String.fromCharCode(a)}}return o}}function qs(t,A=0){let e=t.length;A>0&&(e=A);let s=new b(e);return yA(s,t,A),s}function Be(t){return qs(t,t.length+1)}function yA(t,A,e=0){e>0&&A.length>e&&(A=A.slice(0,e));for(let s=0;sA.length)for(let s=0;se.header!=="LIST"?!1:(e.chunkData.currentIndex=0,_(e.chunkData,4)===A))}function st(t){let A=0;for(;t;){let e=t[t.currentIndex++];if(A=A<<7|e&127,e>>7!==1)break}return A}var nt={name:"INAM",album:"IPRD",album2:"IALB",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"};var ot=class t extends Se{embeddedSoundFont=void 0;tracks=[];static copyFrom(A){let e=new t;return e.midiName=A.midiName,e.midiNameUsesFileName=A.midiNameUsesFileName,e.fileName=A.fileName,e.timeDivision=A.timeDivision,e.duration=A.duration,e.copyright=A.copyright,e.tracksAmount=A.tracksAmount,e.firstNoteOn=A.firstNoteOn,e.keyRange={...A.keyRange},e.lastVoiceEventTick=A.lastVoiceEventTick,e.loop={...A.loop},e.format=A.format,e.bankOffset=A.bankOffset,e.tempoChanges=[...A.tempoChanges],e.lyrics=A.lyrics.map(s=>new Uint8Array(s)),e.midiPorts=[...A.midiPorts],e.midiPortChannelOffsets=[...A.midiPortChannelOffsets],e.usedChannelsOnTrack=A.usedChannelsOnTrack.map(s=>new Set(s)),e.rawMidiName=A.rawMidiName?new Uint8Array(A.rawMidiName):void 0,e.embeddedSoundFont=A.embeddedSoundFont?A.embeddedSoundFont.slice():void 0,e.RMIDInfo={...A.RMIDInfo},e.tracks=A.tracks.map(s=>[...s]),e}flush(){let A=[];for(let n of this.tracks){n.sort((i,a)=>i.ticks-a.ticks);let o=n.find(i=>(i.messageStatusByte&240)===M.noteOn);o&&A.push(o.ticks)}this.firstNoteOn=Math.min(...A),this.lastVoiceEventTick=0,this.tempoChanges=[{ticks:0,tempo:120}],this.midiPorts=[],this.midiPortChannelOffsets=[];let e=0;this.usedChannelsOnTrack=this.tracks.map(()=>new Set),this.tracks.forEach((n,o)=>{this.midiPorts.push(-1),n.forEach(i=>{if(i.messageStatusByte>=128&&i.messageStatusByte<240&&i.ticks>this.lastVoiceEventTick&&(this.lastVoiceEventTick=i.ticks),i.messageStatusByte===M.setTempo)this.tempoChanges.push({ticks:i.ticks,tempo:6e7/_A(i.messageData,3)});else if((i.messageStatusByte&240)===M.noteOn)this.usedChannelsOnTrack[o].add(i.messageData[0]);else if(i.messageStatusByte===M.midiPort){let a=i.messageData[0];this.midiPorts[o]=a,this.midiPortChannelOffsets[a]===void 0&&(this.midiPortChannelOffsets[a]=e,e+=16)}})}),this.loop={start:this.firstNoteOn,end:this.lastVoiceEventTick},this.tempoChanges.reverse(),this.duration=he(this.lastVoiceEventTick,this);let s=0;for(let n of this.midiPorts)if(n!==-1){s=n;break}this.midiPorts=this.midiPorts.map(n=>n===-1?s:n),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0])}};function he(t,A){let e=0;for(;t>0;){let s=A.tempoChanges.find(o=>o.ticks0&&(x+=this.tracks[y-1][this.tracks[y-1].length-1].ticks);w.data.currentIndexthis.lastVoiceEventTick&&(this.lastVoiceEventTick=x),Z=Fs[I>>4],(I&240)===M.noteOn){H.add(rA);let nA=w.data[w.data.currentIndex];this.keyRange.min=Math.min(this.keyRange.min,nA),this.keyRange.max=Math.max(this.keyRange.max,nA)}R=I;break}let AA=new b(Z),$=w.data.slice(w.data.currentIndex,w.data.currentIndex+Z);w.data.currentIndex+=Z,AA.set($,0);let IA=new fe(x,I,AA);switch(S.push(IA),rA){case-2:switch(I){case M.setTempo:this.tempoChanges.push({ticks:x,tempo:6e7/_A($,3)});break;case M.marker:switch(_(AA,AA.length).trim().toLowerCase()){default:break;case"start":case"loopstart":d=x;break;case"loopend":Q=x}AA.currentIndex=0;break;case M.midiPort:let iA=AA[0];this.midiPorts[y]=iA,this.midiPortChannelOffsets[iA]===void 0&&(this.midiPortChannelOffsets[iA]=l,l+=16);break;case M.copyright:o||(this.copyright+=_(AA,AA.length,void 0,!1)+` -`);break;case M.lyric:this.lyrics.push(AA)}break;case-3:if(AA.slice(0,7).every((nA,iA)=>Cr[iA]===nA)){let nA=AA.slice(7,$.length-3),iA=_(nA,nA.length)+` -`;this.copyright+=iA,p(`%cDecoded Roland SC message! %c${iA}`,g.recognized,g.value)}break;default:if((I&240)===M.controllerChange)switch(AA[0]){case 2:case 116:d=x;break;case 4:case 117:Q===null?Q=x:Q=0;break;case 0:a&&AA[1]!==0&&AA[1]!==127&&(p("%cDLS RMIDI with offset 1 detected!",g.recognized),this.bankOffset=1)}}}this.tracks.push(S),this.usedChannelsOnTrack.push(H),p(`%cParsed %c${this.tracks.length}%c / %c${this.tracksAmount}`,g.info,g.value,g.info,g.value)}p("%cAll tracks parsed correctly!",g.recognized),QA("%cCorrecting loops, ports and detecting notes...",g.info);let c=[];for(let y of this.tracks){let S=y.find(w=>(w.messageStatusByte&240)===M.noteOn);S&&c.push(S.ticks)}this.firstNoteOn=Math.min(...c),p(`%cFirst note-on detected at: %c${this.firstNoteOn}%c ticks!`,g.info,g.recognized,g.info),d!==null&&Q===null?(d=this.firstNoteOn,Q=this.lastVoiceEventTick):(d===null&&(d=this.firstNoteOn),(Q===null||Q===0)&&(Q=this.lastVoiceEventTick)),this.loop={start:d,end:Q},p(`%cLoop points: start: %c${this.loop.start}%c end: %c${this.loop.end}`,g.info,g.recognized,g.info,g.recognized);let f=0;for(let y of this.midiPorts)if(y!==-1){f=y;break}if(this.midiPorts=this.midiPorts.map(y=>y===-1?f:y),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0]),this.midiPortChannelOffsets.length<2?p("%cNo additional MIDI Ports detected.",g.info):p("%cMIDI Ports detected!",g.recognized),!i)if(this.tracks.length>1){if(this.tracks[0].find(y=>y.messageStatusByte>=M.noteOn&&y.messageStatusByteS.messageStatusByte===M.trackName);y&&(this.rawMidiName=y.messageData,this.midiName=_(y.messageData,y.messageData.length,void 0,!1))}}else{let y=this.tracks[0].find(S=>S.messageStatusByte===M.trackName);y&&(this.rawMidiName=y.messageData,this.midiName=_(y.messageData,y.messageData.length,void 0,!1))}if(this.fileName=e,this.midiName=this.midiName.trim(),this.midiNameUsesFileName=!1,this.midiName.length===0){p("%cNo name detected. Using the alt name!",g.info),this.midiName=ks(e),this.midiNameUsesFileName=!0,this.rawMidiName=new Uint8Array(this.midiName.length);for(let y=0;yl>Q?l:Q),s=[];for(let Q=0;Q{i[f]>=c.length||c[i[f]].ticks0;){let Q=C(),l=t.tracks[Q];if(i[Q]>=l.length){a--;continue}let c=l[i[Q]];if(i[Q]++,c.messageStatusByte===M.midiPort){B[Q]=c.messageData[0];continue}let f=c.messageStatusByte&240;if(f!==M.noteOn&&f!==M.controllerChange&&f!==M.programChange&&f!==M.systemExclusive)continue;let y=(c.messageStatusByte&15)+t.midiPortChannelOffsets[B[Q]]||0,S=s[y];switch(f){case M.programChange:S.program=c.messageData[0],n(S);break;case M.controllerChange:if(c.messageData[0]!==k.bankSelect||d==="gs"&&S.drums)continue;let w=c.messageData[1],H=Math.max(0,w-t.bankOffset);if(d==="xg"){let G=w===120||w===126||w===127;G!==S.drums?(S.drums=G,S.bank=S.drums?128:H,n(S)):S.bank=S.drums?128:H;continue}s[y].bank=H;break;case M.noteOn:if(c.messageData[1]===0)continue;n(S),o[S.string].add(`${c.messageData[0]}-${c.messageData[1]}`);break;case M.systemExclusive:if(c.messageData[0]!==65||c.messageData[2]!==66||c.messageData[3]!==18||c.messageData[4]!==64||!(c.messageData[5]&16)||c.messageData[6]!==21){c.messageData[0]===67&&c.messageData[2]===76&&c.messageData[5]===126&&c.messageData[6]===0&&(d="xg");continue}let R=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][c.messageData[5]&15]+t.midiPortChannelOffsets[B[Q]],x=!!(c.messageData[7]>0&&c.messageData[5]>>4);S=s[R],S.drums=x,S.bank=x?128:0,n(S);break}}for(let Q of Object.keys(o))o[Q].size===0&&(p(`%cDetected change but no keys for %c${Q}`,g.info,g.value),delete o[Q]);return V(),o}function Vs(t,A){this.midiData.usedChannelsOnTrack[t].size!==0&&(this.midiPortChannelOffset===0&&(this.midiPortChannelOffset+=16,this.midiPortChannelOffsets[A]=0),this.midiPortChannelOffsets[A]===void 0&&(this.synth.workletProcessorChannels.length{this.assignMIDIPort(s,e)}),this.duration=this.midiData.duration,this.firstNoteTime=he(this.midiData.firstNoteOn,this.midiData),p(`%cTotal song time: ${Ut(Math.ceil(this.duration)).time}`,g.recognized),this.post(bA.songChange,[new tt(this.midiData),this.songIndex,A]),this.duration<=1&&(T(`%cVery short song: (${Ut(Math.round(this.duration)).time}). Disabling loop!`,g.warn),this.loop=!1),A)this.play(!0);else{let e=this._skipToFirstNoteOn?this.midiData.firstNoteOn-1:0;this.setTimeTicks(e),this.pause()}}function Zs(t,A=!0){this.songs=t.reduce((e,s)=>{if(s.duration)return e.push(s),e;try{e.push(new rt(s.binary,s.altName||""))}catch(n){return this.post(bA.midiError,n.message),e}return e},[]),!(this.songs.length<1)&&(this.songIndex=0,this.songs.length>1&&(this.loop=!1),this.loadNewSequence(this.songs[this.songIndex],A))}function Ws(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex++,this.songIndex%=this.songs.length,this.loadNewSequence(this.songs[this.songIndex])}function Xs(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex--,this.songIndex<0&&(this.songIndex=this.songs.length-1),this.loadNewSequence(this.songs[this.songIndex])}var Le=ye.slice(0,128);function _s(t,A=void 0){this.oneTickToSeconds=60/(120*this.midiData.timeDivision),this.synth.resetAllControllers(),this.sendMIDIReset(),this._resetTimers();let e=this.synth.workletProcessorChannels.length,s=Array(e).fill(8192),n=[];for(let a=0;aa===k.dataDecrement||a===k.dataIncrement||a===k.dataEntryMsb||a===k.dataDecrement||a===k.lsbForControl6DataEntry||a===k.RPNLsb||a===k.RPNMsb||a===k.NRPNLsb||a===k.NRPNMsb||a===k.bankSelect||a===k.lsbForControl0BankSelect||a===k.resetAllControllers,i=[];for(let a=0;a=A)break}else if(this.playedTime>=t)break;let B=be(C.messageStatusByte),d=B.channel+(this.midiPortChannelOffsets[this.midiPorts[a]]||0);switch(B.status){case M.noteOn:case M.noteOff:case M.keySignature:break;case M.pitchBend:s[d]=C.messageData[1]<<7|C.messageData[0];break;case M.programChange:let l=n[d];l.program=C.messageData[0],l.actualBank=l.bank;break;case M.controllerChange:let c=C.messageData[0];if(o(c)){let f=C.messageData[1];if(c===k.bankSelect){n[d].bank=f;break}else c===k.resetAllControllers&&(i[d]=Array.from(Le));this.sendMIDIMessages?this.sendMIDICC(d,c,f):this.synth.controllerChange(d,c,f)}else i[d]===void 0&&(i[d]=Array.from(Le)),i[d][c]=C.messageData[1];break;default:this._processEvent(C,a);break}this.eventIndex[a]++,a=this._findFirstEventIndex();let Q=this.tracks[a][this.eventIndex[a]];if(Q===void 0)return this.stop(),!1;this.playedTime+=this.oneTickToSeconds*(Q.ticks-C.ticks)}if(this.sendMIDIMessages){for(let a=0;a>7,s[a]&127),i[a]!==void 0&&i[a].forEach((C,B)=>{C!==Le[B]&&!o(B)&&this.sendMIDICC(a,B,C)}),n[a].program>=0&&n[a].actualBank>=0){let C=n[a].actualBank;this.sendMIDICC(a,k.bankSelect,C),this.sendMIDIProgramChange(a,n[a].program)}}else for(let a=0;a>7,s[a]&127),i[a]!==void 0&&i[a].forEach((C,B)=>{C!==Le[B]&&!o(B)&&this.synth.controllerChange(a,B,C)}),n[a].program>=0&&n[a].actualBank>=0){let C=n[a].actualBank;this.synth.controllerChange(a,k.bankSelect,C),this.synth.programChange(a,n[a].program)}return!0}function zs(t=!1){if(this.midiData!==void 0){if(t){this.pausedTime=void 0,this.currentTime=0;return}if(this.currentTime>=this.duration){this.pausedTime=void 0,this.currentTime=0;return}this.paused&&(this._recalculateStartTime(this.pausedTime),this.pausedTime=void 0),this.sendMIDIMessages||this.playingNotes.forEach(A=>{this.synth.noteOn(A.channel,A.midiNote,A.velocity,!1,!0)}),this.setProcessHandler()}}function js(t){this.stop(),this.playingNotes=[],this.pausedTime=void 0,this.post(bA.timeChange,currentTime-he(t,this.midiData));let A=this._playTo(0,t);this._recalculateStartTime(this.playedTime),A&&this.play()}function $s(t){this.absoluteStartTime=currentTime-t/this._playbackRate}function An(t,A){switch(t){default:break;case NA.loadNewSongList:this.loadNewSongList(A[0],A[1]);break;case NA.pause:this.pause();break;case NA.play:this.play(A);break;case NA.stop:this.stop();break;case NA.setTime:this.currentTime=A;break;case NA.changeMIDIMessageSending:this.sendMIDIMessages=A;break;case NA.setPlaybackRate:this.playbackRate=A;break;case NA.setLoop:this.loop=A;break;case NA.changeSong:A?this.nextSong():this.previousSong();break;case NA.getMIDI:this.post(bA.getMIDI,this.midiData);break;case NA.setSkipToFirstNote:this._skipToFirstNoteOn=A;break;case NA.setPreservePlaybackState:this.preservePlaybackState=A}}function en(t,A=void 0){this.synth.enableEventSystem&&this.synth.post({messageType:DA.sequencerSpecific,messageData:{messageType:t,messageData:A}})}function tn(t){this.post(bA.midiEvent,t)}function sn(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([M.controllerChange|t,A,e])}function nn(t,A){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([M.programChange|t,A])}function on(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([M.pitchBend|t,e,A])}function rn(){if(this.sendMIDIMessages){this.sendMIDIMessage([M.reset]);for(let t=0;tthis.duration||A<0){this._skipToFirstNoteOn?this.setTimeTicks(this.midiData.firstNoteOn-1):this.setTimeTicks(0);return}if(this._skipToFirstNoteOn&&Aan?440*Math.pow(2,(t-6900)/1200):qt[~~t-it]}var Vt=-1660,Br=1600,Ot=new Float32Array((Br-Vt)*100+1);for(let t=0;t.5?1:0,s?e*2-1:e;case uA.concave:return s?(e=e*2-1,e<0?-$A[~~(e*-fA)]:$A[~~(e*fA)]):$A[~~(e*fA)];case uA.convex:return s?(e=e*2-1,e<0?-ce[~~(e*-fA)]:ce[~~(e*fA)]):ce[~~(e*fA)]}}var Kt=1,Zt=new Float32Array(1e3);for(let t=0;t=e.loopEnd;)s-=o;let a=~~s,C=a+1;for(;C>=e.loopEnd;)C-=o;let B=s-a,d=n[C],Q=n[a];A[i]=Q+(d-Q)*B,s+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end){t.finished=!0;return}let C=s-i,B=n[a],d=n[i];A[o]=d+(B-d)*C,s+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=s}function In(t,A){let e=t.sample,s=e.cursor,n=e.loopEnd-e.loopStart,o=e.sampleData;if(t.sample.isLooping)for(let i=0;i=e.loopEnd;)s-=n;let a=~~s+1;for(;a>=e.loopEnd;)a-=n;A[i]=o[a],s+=e.playbackStep*t.currentTuningCalculated}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let i=0;i=e.end){t.finished=!0;return}A[i]=o[a],s+=e.playbackStep*t.currentTuningCalculated}}e.cursor=s}function En(t,A){let e=t.sample,s=e.cursor,n=e.sampleData;if(e.isLooping){let o=e.loopEnd-e.loopStart;for(let i=0;i=e.loopEnd;)s-=o;let a=~~s,C=a+1,B=C+1,d=B+1,Q=s-a;C>=e.loopEnd&&(C-=o),B>=e.loopEnd&&(B-=o),d>=e.loopEnd&&(d-=o);let l=n[a],c=n[C],f=n[B],y=n[d],S=.5*(f-l),w=l-2.5*c+2*f-.5*y,H=.5*(y-l)+1.5*(c-f);A[i]=((H*Q+w)*Q+S)*Q+c,s+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end||C>=e.end||B>=e.end){t.finished=!0;return}let Q=n[i],l=n[a],c=n[C],f=n[B],y=.5*(c-Q),S=Q-2.5*l+2*c-.5*f,w=.5*(f-Q)+1.5*(l-c);A[o]=((w*d+S)*d+y)*d+l,s+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=s}var Cn=.01,LA=100,Wt=90,hr=15e-6,qA=class t{currentSampleTime=0;sampleRate;currentAttenuationDb=LA;state=0;releaseStartDb=LA;releaseStartTimeSamples=0;currentReleaseGain=1;attackDuration=0;decayDuration=0;releaseDuration=0;attenuation=0;attenuationTargetGain=0;attenuationTarget=0;sustainDbRelative=0;delayEnd=0;attackEnd=0;holdEnd=0;decayEnd=0;constructor(A,e){this.sampleRate=A,this.canEndOnSilentSustain=e/10>=Wt}static startRelease(A){A.volumeEnvelope.releaseStartTimeSamples=A.volumeEnvelope.currentSampleTime,A.volumeEnvelope.currentReleaseGain=JA(A.volumeEnvelope.currentAttenuationDb),t.recalculate(A)}static recalculate(A){let e=A.volumeEnvelope,s=B=>Math.max(0,Math.floor(KA(B)*e.sampleRate));e.attenuationTarget=Math.max(0,Math.min(A.modulatedGenerators[r.initialAttenuation],1440))/10,e.attenuationTargetGain=JA(e.attenuationTarget),e.sustainDbRelative=Math.min(LA,A.modulatedGenerators[r.sustainVolEnv]/10);let n=Math.min(LA,e.sustainDbRelative);e.attackDuration=s(A.modulatedGenerators[r.attackVolEnv]);let o=A.modulatedGenerators[r.decayVolEnv],i=(60-A.targetKey)*A.modulatedGenerators[r.keyNumToVolEnvDecay],a=n/LA;e.decayDuration=s(o+i)*a,e.releaseDuration=s(A.modulatedGenerators[r.releaseVolEnv]),e.delayEnd=s(A.modulatedGenerators[r.delayVolEnv]),e.attackEnd=e.attackDuration+e.delayEnd;let C=(60-A.targetKey)*A.modulatedGenerators[r.keyNumToVolEnvHold];if(e.holdEnd=s(A.modulatedGenerators[r.holdVolEnv]+C)+e.attackEnd,e.decayEnd=e.decayDuration+e.holdEnd,e.state===0&&e.attackEnd===0&&(e.state=2),A.isInRelease){let B=Math.max(0,Math.min(LA,e.sustainDbRelative)),d=B/LA;switch(e.decayDuration=s(o+i)*d,e.state){case 0:e.releaseStartDb=LA;break;case 1:let l=1-(e.attackEnd-e.releaseStartTimeSamples)/e.attackDuration;e.releaseStartDb=20*Math.log10(l)*-1;break;case 2:e.releaseStartDb=0;break;case 3:e.releaseStartDb=(1-(e.decayEnd-e.releaseStartTimeSamples)/e.decayDuration)*B;break;case 4:e.releaseStartDb=B;break}e.releaseStartDb=Math.max(0,Math.min(e.releaseStartDb,LA)),e.releaseStartDb>=Wt&&(A.finished=!0),e.currentReleaseGain=JA(e.releaseStartDb);let Q=(LA-e.releaseStartDb)/LA;e.releaseDuration*=Q}}static apply(A,e,s,n){let o=A.volumeEnvelope,i=s/10,a=n;if(A.isInRelease){let B=o.currentSampleTime-o.releaseStartTimeSamples;if(B>=o.releaseDuration){for(let Q=0;Q=e.length)return;o.state++;case 1:for(;o.currentSampleTime=e.length)return}o.state++;case 2:for(;o.currentSampleTime=e.length)return;o.state++;case 3:for(;o.currentSampleTime=e.length)return;o.state++;case 4:for(o.canEndOnSilentSustain&&o.sustainDbRelative>=Wt&&(A.finished=!0);;)if(o.attenuation+=(o.attenuationTargetGain-o.attenuation)*a,e[C]*=o.attenuation*JA(o.sustainDbRelative+i),o.currentAttenuationDb=o.sustainDbRelative,o.currentSampleTime++,++C>=e.length)return}}};var we=class t{a0=0;a1=0;a2=0;a3=0;a4=0;x1=0;x2=0;y1=0;y2=0;reasonanceCb=0;reasonanceGain=1;cutoffCents=13501;cutoffHz=20001;static apply(A,e,s,n){if(n&&s>13499&&A.filter.reasonanceCb===0)return;let o=A.filter;(o.cutoffCents!==s||o.reasonanceCb!==A.modulatedGenerators[r.initialFilterQ])&&(o.cutoffCents=s,o.reasonanceCb=A.modulatedGenerators[r.initialFilterQ],t.calculateCoefficients(o));for(let i=0;i=A.releaseStartTime&&(A.isInRelease=!0,qA.startRelease(A),PA.startRelease(A),A.sample.loopingMode===3&&(A.sample.isLooping=!1)),A.modulatedGenerators[r.initialAttenuation]>2500){A.isInRelease&&(A.finished=!0);return}let i=A.targetKey,a=A.modulatedGenerators[r.fineTune]+t.customControllers[hA.channelTuning]+t.customControllers[hA.channelTransposeFine]+t.customControllers[hA.masterTuning]+t.channelOctaveTuning[A.midiNote%12]+t.keyCentTuning[A.midiNote],C=A.modulatedGenerators[r.coarseTune]+t.customControllers[hA.channelTuningSemitones],B=this.tunings[t.preset.program]?.[A.realKey];B?.midiNote>=0&&(i=B.midiNote,a+=B.centTuning),a+=(i-A.sample.rootKey)*A.modulatedGenerators[r.scaleTuning];let d=A.modulatedGenerators[r.vibLfoToPitch];if(d!==0){let I=A.startTime+KA(A.modulatedGenerators[r.delayVibLFO]),rA=Ue(A.modulatedGenerators[r.freqVibLFO]),Z=at(I,rA,currentTime);a+=Z*(d*t.customControllers[hA.modulationMultiplier])}let Q=A.modulatedGenerators[r.initialFilterFc],l=Q,c=A.modulatedGenerators[r.modLfoToPitch],f=A.modulatedGenerators[r.modLfoToVolume],y=A.modulatedGenerators[r.modLfoToFilterFc],S=0;if(c+y+f!==0){let I=A.startTime+KA(A.modulatedGenerators[r.delayModLFO]),rA=Ue(A.modulatedGenerators[r.freqModLFO]),Z=at(I,rA,currentTime);a+=Z*(c*t.customControllers[hA.modulationMultiplier]),S=-Z*f,l+=Z*y}if(t.channelVibrato.depth>0){let I=at(A.startTime+t.channelVibrato.delay,t.channelVibrato.rate,currentTime);I&&(a+=I*t.channelVibrato.depth)}let w=A.modulatedGenerators[r.modEnvToPitch],H=A.modulatedGenerators[r.modEnvToFilterFc],R=PA.getValue(A,currentTime);l+=R*H,a+=R*w;let x=~~(a+C*100);x!==A.currentTuningCents&&(A.currentTuningCents=x,A.currentTuningCalculated=Math.pow(2,x/1200));let G=new Float32Array(e.length);switch(this.interpolationType){case ke.linear:default:gn(A,G);break;case ke.nearestNeighbor:In(A,G);break;case ke.fourthOrder:En(A,G)}we.apply(A,G,l,Q>13499),qA.apply(A,G,S,this.volumeEnvelopeSmoothingFactor),this.panVoice(A,G,e,s,n,o)}function cr(t,A){let e=0;return t.drumChannel&&(e+=5),A.isInRelease&&(e-=5),e+=A.velocity/25,e-=A.volumeEnvelope.state,A.isInRelease&&(e-=5),e-=A.volumeEnvelope.currentAttenuationDb/50,e}function cn(t){let A=[];for(let s of this.workletProcessorChannels)for(let n of s.voices)if(!n.finished){let o=cr(s,n);A.push({channel:s,voice:n,priority:o})}A.sort((s,n)=>s.priority-n.priority);let e=A.slice(0,t);for(let{channel:s,voice:n}of e){let o=s.voices.indexOf(n);o>-1&&s.voices.splice(o,1)}}function ln(t,A=Qn){t.releaseStartTime=currentTime,t.releaseStartTime-t.startTimedn=t);var lr=function(t){var A,e,s,n,o,i,a,C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",B="",d=0;t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");do n=C.indexOf(t.charAt(d++)),o=C.indexOf(t.charAt(d++)),i=C.indexOf(t.charAt(d++)),a=C.indexOf(t.charAt(d++)),A=n<<2|o>>4,e=(15&o)<<4|i>>2,s=(3&i)<<6|a,B+=String.fromCharCode(A),i!==64&&(B+=String.fromCharCode(e)),a!==64&&(B+=String.fromCharCode(s));while(d1&&(I.thisProgram=process.argv[1].replace(/\\/g,"/")),I.arguments=process.argv.slice(2),typeof module<"u",process.on("uncaughtException",function(E){if(!(E instanceof Me))throw E}),process.on("unhandledRejection",function(E,h){process.exit(1)}),I.quit=function(E){process.exit(E)},I.inspect=function(){return"[Emscripten Module object]"}):IA?(typeof read<"u"&&(I.read=function(h){return read(h)}),I.readBinary=function(h){var u;return typeof readbuffer=="function"?new Uint8Array(readbuffer(h)):(te(typeof(u=read(h,"binary"))=="object"),u)},typeof scriptArgs<"u"?I.arguments=scriptArgs:typeof arguments<"u"&&(I.arguments=arguments),typeof quit=="function"&&(I.quit=function(E){quit(E)})):(Z||AA)&&(Z?document.currentScript&&(nA=document.currentScript.src):nA=self.location.href,nA=nA.indexOf("blob:")!==0?nA.split("/").slice(0,-1).join("/")+"/":"",I.read=function(h){var u=new XMLHttpRequest;return u.open("GET",h,!1),u.send(null),u.responseText},AA&&(I.readBinary=function(h){var u=new XMLHttpRequest;return u.open("GET",h,!1),u.responseType="arraybuffer",u.send(null),new Uint8Array(u.response)}),I.readAsync=function(h,u,m){var U=new XMLHttpRequest;U.open("GET",h,!0),U.responseType="arraybuffer",U.onload=function(){if(U.status==200||U.status==0&&U.response){u(U.response);return}m()},U.onerror=m,U.send(null)},I.setWindowTitle=function(E){document.title=E});var eA=I.print||(typeof console<"u"?console.log.bind(console):typeof print<"u"?print:null),lA=I.printErr||(typeof printErr<"u"?printErr:typeof console<"u"&&console.warn.bind(console)||eA);for(t in rA)rA.hasOwnProperty(t)&&(I[t]=rA[t]);function UA(E){var h=c;return c=c+E+15&-16,h}function os(E){var h=C[R>>2],u=h+E+15&-16;return C[R>>2]=u,u>=mA&&!cs()?(C[R>>2]=h,0):h}function rs(E,h){return h||(h=16),E=Math.ceil(E/h)*h}function _o(E){switch(E){case"i1":case"i8":return 1;case"i16":return 2;case"i32":case"float":return 4;case"i64":case"double":return 8;default:if(E[E.length-1]==="*")return 4;if(E[0]!=="i")return 0;var h=parseInt(E.substr(1));return te(h%8==0),h/8}}function Fe(E){Fe.shown||(Fe.shown={}),Fe.shown[E]||(Fe.shown[E]=1,lA(E))}rA=void 0;var zo={"f64-rem":function(E,h){return E%h},debugger:function(){}},pt=[];function Gr(E,h){for(var u=0,m=u;m>>0)+4294967296*+(h>>>0):+(E>>>0)+4294967296*+(0|h)}function St(E,h,u){return u&&u.length?I["dynCall_"+E].apply(null,[h].concat(u)):I["dynCall_"+E].call(null,h)}var Je=0,is=0;function te(E,h){E||jA("Assertion failed: "+h)}function as(E){var h=I["_"+E];return te(h,"Cannot call unknown function "+E+", make sure it is exported"),h}var gs={stackSave:function(){xt()},stackRestore:function(){Mt()},arrayToC:function(E){var h,u,m=Ze(E.length);return h=E,u=m,n.set(h,u),m},stringToC:function(E){var h=0;if(E!=null&&E!==0){var u=(E.length<<2)+1;h=Ze(u),Cs(E,h,u)}return h}},jo={string:gs.stringToC,array:gs.arrayToC};function Is(E,h,u,m,U){var X=as(E),j=[],Y=0;if(m)for(var pA=0;pA>0]=h;break;case"i16":i[E>>1]=h;break;case"i32":C[E>>2]=h;break;case"i64":tempI64=[h>>>0,+nr(tempDouble=h)>=1?tempDouble>0?(0|rr(+fs(tempDouble/4294967296),4294967295))>>>0:~~+or((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0],C[E>>2]=tempI64[0],C[E+4>>2]=tempI64[1];break;case"float":d[E>>2]=h;break;case"double":Q[E>>3]=h;break;default:jA("invalid type for setValue: "+u)}}function br(E,h,u){switch((h=h||"i8").charAt(h.length-1)==="*"&&(h="i32"),h){case"i1":case"i8":return n[E>>0];case"i16":return i[E>>1];case"i32":case"i64":return C[E>>2];case"float":return d[E>>2];case"double":return Q[E>>3];default:jA("invalid type for getValue: "+h)}return null}function Lr(E,h,u,m){typeof E=="number"?(X=!0,j=E):(X=!1,j=E.length);var U=typeof h=="string"?h:null;if(Y=u==4?m:[typeof Ke=="function"?Ke:UA,Ze,UA,os][u===void 0?2:u](Math.max(j,U?1:h.length)),X){for(m=Y,te((3&Y)==0),pA=Y+(-4&j);m>2]=0;for(pA=Y+j;m>0]=0;return Y}if(U==="i8")return E.subarray||E.slice?o.set(E,Y):o.set(new Uint8Array(E),Y),Y;for(var X,j,Y,pA,EA,CA,aA,W=0;W>0],(m!=0||h)&&(j++,!h||j!=h););h||(h=j);var Y="";if(X<128){for(;h>0;)U=String.fromCharCode.apply(String,o.subarray(E,E+Math.min(h,1024))),Y=Y?Y+U:U,E+=1024,h-=1024;return Y}return u=E,function(EA,CA){for(var aA=CA;EA[aA];)++aA;if(aA-CA>16&&EA.subarray&&Es)return Es.decode(EA.subarray(CA,aA));for(var W,RA,TA,vA,HA,Ee,YA="";;){if(!(W=EA[CA++]))return YA;if(!(128&W)){YA+=String.fromCharCode(W);continue}if(RA=63&EA[CA++],(224&W)==192){YA+=String.fromCharCode((31&W)<<6|RA);continue}if(TA=63&EA[CA++],(240&W)==224?W=(15&W)<<12|RA<<6|TA:(vA=63&EA[CA++],(248&W)==240?W=(7&W)<<18|RA<<12|TA<<6|vA:(HA=63&EA[CA++],W=(252&W)==248?(3&W)<<24|RA<<18|TA<<12|vA<<6|HA:(1&W)<<30|RA<<24|TA<<18|vA<<12|HA<<6|(Ee=63&EA[CA++]))),W<65536)YA+=String.fromCharCode(W);else{var xe=W-65536;YA+=String.fromCharCode(55296|xe>>10,56320|1023&xe)}}}(o,u)}function Tr(E){for(var h="";;){var u=n[E++>>0];if(!u)return h;h+=String.fromCharCode(u)}}function vr(E,h){return function(m,U,X){for(var j=0;j>0]=m.charCodeAt(j);X||(n[U>>0]=0)}(E,h,!1)}var Es=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function qe(E,h,u,m){if(!(m>0))return 0;for(var U=u,X=u+m-1,j=0;j=55296&&Y<=57343&&(Y=65536+((1023&Y)<<10)|1023&E.charCodeAt(++j)),Y<=127){if(u>=X)break;h[u++]=Y}else if(Y<=2047){if(u+1>=X)break;h[u++]=192|Y>>6,h[u++]=128|63&Y}else if(Y<=65535){if(u+2>=X)break;h[u++]=224|Y>>12,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}else if(Y<=2097151){if(u+3>=X)break;h[u++]=240|Y>>18,h[u++]=128|Y>>12&63,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}else if(Y<=67108863){if(u+4>=X)break;h[u++]=248|Y>>24,h[u++]=128|Y>>18&63,h[u++]=128|Y>>12&63,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}else{if(u+5>=X)break;h[u++]=252|Y>>30,h[u++]=128|Y>>24&63,h[u++]=128|Y>>18&63,h[u++]=128|Y>>12&63,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}}return h[u]=0,u-U}function Cs(E,h,u){return qe(E,o,h,u)}function Oe(E){for(var h=0,u=0;u=55296&&m<=57343&&(m=65536+((1023&m)<<10)|1023&E.charCodeAt(++u)),m<=127?++h:m<=2047?h+=2:m<=65535?h+=3:m<=2097151?h+=4:m<=67108863?h+=5:h+=6}return h}var Bs=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0;function Hr(E){for(var h=E,u=h>>1;i[u];)++u;if((h=u<<1)-E>32&&Bs)return Bs.decode(o.subarray(E,h));for(var m=0,U="";;){var X=i[E+2*m>>1];if(X==0)return U;++m,U+=String.fromCharCode(X)}}function Yr(E,h,u){if(u===void 0&&(u=2147483647),u<2)return 0;for(var m=h,U=(u-=2)<2*E.length?u/2:E.length,X=0;X>1]=j,h+=2}return i[h>>1]=0,h-m}function Jr(E){return 2*E.length}function Pr(E){for(var h=0,u="";;){var m=C[E+4*h>>2];if(m==0)return u;if(++h,m>=65536){var U=m-65536;u+=String.fromCharCode(55296|U>>10,56320|1023&U)}else u+=String.fromCharCode(m)}}function qr(E,h,u){if(u===void 0&&(u=2147483647),u<4)return 0;for(var m=h,U=m+u-4,X=0;X=55296&&j<=57343&&(j=65536+((1023&j)<<10)|1023&E.charCodeAt(++X)),C[h>>2]=j,(h+=4)+4>U)break}return C[h>>2]=0,h-m}function Or(E){for(var h=0,u=0;u=55296&&m<=57343&&++u,h+=4}return h}function Vr(E){var h=Oe(E)+1,u=Ke(h);return u&&qe(E,n,u,h),u}function Kr(E){var h=Oe(E)+1,u=Ze(h);return qe(E,n,u,h),u}function Zr(E){return E}function Wr(){var E,h=function(){var m=Error();if(!m.stack){try{throw Error(0)}catch(U){m=U}if(!m.stack)return"(no stack trace available)"}return m.stack.toString()}();return I.extraStackTrace&&(h+=` -`+I.extraStackTrace()),(E=h).replace(/__Z[\w\d_]+/g,function(u){var m,U=m=u;return u===U?u:u+" ["+U+"]"})}function Dt(E,h){return E%h>0&&(E+=h-E%h),E}function hs(E){I.buffer=s=E}function kt(){I.HEAP8=n=new Int8Array(s),I.HEAP16=i=new Int16Array(s),I.HEAP32=C=new Int32Array(s),I.HEAPU8=o=new Uint8Array(s),I.HEAPU16=a=new Uint16Array(s),I.HEAPU32=B=new Uint32Array(s),I.HEAPF32=d=new Float32Array(s),I.HEAPF64=Q=new Float64Array(s)}function cs(){var E=I.usingWasm?65536:16777216,h=2147483648-E;if(C[R>>2]>h)return!1;var u=mA;for(mA=Math.max(mA,16777216);mA>2];)mA=mA<=536870912?Dt(2*mA,E):Math.min(Dt((3*mA+2147483648)/4,E),h);var m=I.reallocBuffer(mA);return m&&m.byteLength==mA?(hs(m),kt(),!0):(mA=u,!1)}l=c=y=S=w=H=R=0,f=!1,I.reallocBuffer||(I.reallocBuffer=function(E){try{if(ArrayBuffer.transfer)h=ArrayBuffer.transfer(s,E);else{var h,u=n;h=new ArrayBuffer(E),new Int8Array(h).set(u)}}catch{return!1}return!!ir(h)&&h});try{(x=Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get))(new ArrayBuffer(4))}catch{x=function(h){return h.byteLength}}var wt=I.TOTAL_STACK||5242880,mA=I.TOTAL_MEMORY||16777216;function Ar(){return mA}function Re(E){for(;E.length>0;){var h=E.shift();if(typeof h=="function"){h();continue}var u=h.func;typeof u=="number"?h.arg===void 0?I.dynCall_v(u):I.dynCall_vi(u,h.arg):u(h.arg===void 0?null:h.arg)}}mA=0?E:h<=32?2*Math.abs(1<=m&&(h<=32||E>m)&&(E=-2*m+E),E}var nr=Math.abs,or=Math.ceil,fs=Math.floor,rr=Math.min,Ie=0,Gt=null,Ge=null;function ei(E){return E}I.preloadedImages={},I.preloadedAudios={};var ms="data:application/octet-stream;base64,";function Ve(E){return String.prototype.startsWith?E.startsWith(ms):E.indexOf(ms)===0}(function(){var h="main.wast",u="main.wasm",m="main.temp.asm.js";Ve(h)||(h=iA(h)),Ve(u)||(u=iA(u)),Ve(m)||(m=iA(m));var U={global:null,env:null,asm2wasm:zo,parent:I},X=null;function j(aA){return aA}function Y(){try{if(I.wasmBinary)return new Uint8Array(I.wasmBinary);if(I.readBinary)return I.readBinary(u);throw"both async and sync fetching of the wasm failed"}catch(aA){jA(aA)}}I.asmPreload=I.asm;var pA=I.reallocBuffer,EA=function(aA){aA=Dt(aA,I.usingWasm?65536:16777216);var W=I.buffer.byteLength;if(I.usingWasm)try{var RA=I.wasmMemory.grow((aA-W)/65536);return RA!==-1?I.buffer=I.wasmMemory.buffer:null}catch{return null}};I.reallocBuffer=function(aA){return CA==="asmjs"?pA(aA):EA(aA)};var CA="";I.asm=function(aA,W,RA){var TA;if(!(W=TA=W).table){var vA,HA=I.wasmTableSize;HA===void 0&&(HA=1024);var Ee=I.wasmMaxTableSize;typeof WebAssembly=="object"&&typeof WebAssembly.Table=="function"?Ee!==void 0?W.table=new WebAssembly.Table({initial:HA,maximum:Ee,element:"anyfunc"}):W.table=new WebAssembly.Table({initial:HA,element:"anyfunc"}):W.table=Array(HA),I.wasmTable=W.table}return W.memoryBase||(W.memoryBase=I.STATIC_BASE),W.tableBase||(W.tableBase=0),vA=function(xe,ue,bt){if(typeof WebAssembly!="object")return lA("no native wasm support detected"),!1;if(!(I.wasmMemory instanceof WebAssembly.Memory))return lA("no native wasm Memory in use"),!1;function We(ZA,WA){if((X=ZA.exports).memory){var Ne,Lt,Ss;Ne=X.memory,Lt=I.buffer,Ne.byteLength0?u:Oe(E)+1,U=Array(m),X=qe(E,U,0,U.length);return h&&(U.length=X),U}function oi(E){for(var h=[],u=0;u255&&(m&=255),h.push(String.fromCharCode(m))}return h.join("")}c+=16,R=UA(4),w=(y=S=rs(c))+wt,H=rs(w),C[R>>2]=H,f=!0,I.wasmTableSize=4,I.wasmMaxTableSize=4,I.asmGlobalArg={},I.asmLibraryArg={abort:jA,assert:te,enlargeMemory:cs,getTotalMemory:Ar,abortOnCannotGrowMemory:function(){jA("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+mA+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")},invoke_iii:function(h,u,m){var U=xt();try{return I.dynCall_iii(h,u,m)}catch(X){if(Mt(U),typeof X!="number"&&X!=="longjmp")throw X;I.setThrew(1,0)}},___assert_fail:function(h,u,m,U){jA("Assertion failed: "+Pe(h)+", at: "+[u?Pe(u):"unknown filename",m,U?Pe(U):"unknown function"])},___setErrNo:function(h){return I.___errno_location&&(C[I.___errno_location()>>2]=h),h},_abort:function(){I.abort()},_emscripten_memcpy_big:function(h,u,m){return o.set(o.subarray(u,u+m),h),h},_llvm_floor_f64:fs,DYNAMICTOP_PTR:R,tempDoublePtr:xA,ABORT:Je,STACKTOP:S,STACK_MAX:w};var ps=I.asm(I.asmGlobalArg,I.asmLibraryArg,s);I.asm=ps,I.___errno_location=function(){return I.asm.___errno_location.apply(null,arguments)};var ir=I._emscripten_replace_memory=function(){return I.asm._emscripten_replace_memory.apply(null,arguments)};I._free=function(){return I.asm._free.apply(null,arguments)};var Ke=I._malloc=function(){return I.asm._malloc.apply(null,arguments)};I._memcpy=function(){return I.asm._memcpy.apply(null,arguments)},I._memset=function(){return I.asm._memset.apply(null,arguments)},I._sbrk=function(){return I.asm._sbrk.apply(null,arguments)},I._stb_vorbis_js_channels=function(){return I.asm._stb_vorbis_js_channels.apply(null,arguments)},I._stb_vorbis_js_close=function(){return I.asm._stb_vorbis_js_close.apply(null,arguments)},I._stb_vorbis_js_decode=function(){return I.asm._stb_vorbis_js_decode.apply(null,arguments)},I._stb_vorbis_js_open=function(){return I.asm._stb_vorbis_js_open.apply(null,arguments)},I._stb_vorbis_js_sample_rate=function(){return I.asm._stb_vorbis_js_sample_rate.apply(null,arguments)},I.establishStackSpace=function(){return I.asm.establishStackSpace.apply(null,arguments)},I.getTempRet0=function(){return I.asm.getTempRet0.apply(null,arguments)},I.runPostSets=function(){return I.asm.runPostSets.apply(null,arguments)},I.setTempRet0=function(){return I.asm.setTempRet0.apply(null,arguments)},I.setThrew=function(){return I.asm.setThrew.apply(null,arguments)};var Ze=I.stackAlloc=function(){return I.asm.stackAlloc.apply(null,arguments)},Mt=I.stackRestore=function(){return I.asm.stackRestore.apply(null,arguments)},xt=I.stackSave=function(){return I.asm.stackSave.apply(null,arguments)};function Me(E){this.name="ExitStatus",this.message="Program terminated with exit("+E+")",this.status=E}function Nt(E){E=E||I.arguments,!(Ie>0)&&(function(){if(I.preRun)for(typeof I.preRun=="function"&&(I.preRun=[I.preRun]);I.preRun.length;)tr(I.preRun.shift());Re(ls)}(),!(Ie>0)&&(I.calledRun||(I.setStatus?(I.setStatus("Running..."),setTimeout(function(){setTimeout(function(){I.setStatus("")},1),h()},1)):h())));function h(){!I.calledRun&&(I.calledRun=!0,Je||(Rt||(Rt=!0,Re(Ft)),Re(Qs),I.onRuntimeInitialized&&I.onRuntimeInitialized(),function(){if(I.postRun)for(typeof I.postRun=="function"&&(I.postRun=[I.postRun]);I.postRun.length;)sr(I.postRun.shift());Re(ds)}()))}}function ri(E,h){(!h||!I.noExitRuntime||E!==0)&&(I.noExitRuntime||(Je=!0,is=E,S=G,Re(us),er=!0,I.onExit&&I.onExit(E)),I.quit(E,new Me(E)))}function jA(E){throw I.onAbort&&I.onAbort(E),E!==void 0?(eA(E),lA(E),E=JSON.stringify(E)):E="",Je=!0,is=1,"abort("+E+"). Build with -s ASSERTIONS=1 for more info."}if(I.dynCall_iii=function(){return I.asm.dynCall_iii.apply(null,arguments)},I.asm=ps,I.ccall=Is,I.cwrap=function(h,u,m,U){var X=(m=m||[]).every(function(j){return j==="number"});return u!=="string"&&X&&!U?as(h):function(){return Is(h,u,m,arguments,U)}},Me.prototype=Error(),Me.prototype.constructor=Me,Ge=function E(){I.calledRun||Nt(),I.calledRun||(Ge=E)},I.run=Nt,I.abort=jA,I.preInit)for(typeof I.preInit=="function"&&(I.preInit=[I.preInit]);I.preInit.length>0;)I.preInit.pop()();I.noExitRuntime=!0,Nt(),I.onRuntimeInitialized=()=>{un=!0,dn()},zA.decode=function(E){return function(u){if(!un)throw Error("Not initialized");var m={};function U(ue){return new Int32Array(I.HEAPU8.buffer,ue,1)[0]}function X(ue,bt){var We=new ArrayBuffer(bt*Float32Array.BYTES_PER_ELEMENT),de=new Float32Array(We);return de.set(new Float32Array(I.HEAPU8.buffer,ue,bt)),de}m.open=I.cwrap("stb_vorbis_js_open","number",[]),m.close=I.cwrap("stb_vorbis_js_close","void",["number"]),m.channels=I.cwrap("stb_vorbis_js_channels","number",["number"]),m.sampleRate=I.cwrap("stb_vorbis_js_sample_rate","number",["number"]),m.decode=I.cwrap("stb_vorbis_js_decode","number",["number","number","number","number","number"]);var j,Y,pA,EA,CA=m.open(),aA=(j=u,Y=u.byteLength,pA=I._malloc(Y),(EA=new Uint8Array(I.HEAPU8.buffer,pA,Y)).set(new Uint8Array(j,0,Y)),EA),W=I._malloc(4),RA=I._malloc(4),TA=m.decode(CA,aA.byteOffset,aA.byteLength,W,RA);if(I._free(aA.byteOffset),TA<0)throw m.close(CA),I._free(W),Error("stbvorbis decode failed: "+TA);for(var vA=m.channels(CA),HA=Array(vA),Ee=new Int32Array(I.HEAPU32.buffer,U(W),vA),YA=0;YA=0&&(s=this.workletProcessorChannels[e]),t.messageType){case sA.noteOn:this.noteOn(e,A[0],A[1],A[2]);break;case sA.noteOff:this.noteOff(e,A);break;case sA.pitchWheel:this.pitchWheel(e,A[0],A[1]);break;case sA.ccChange:this.controllerChange(e,A[0],A[1],A[2]);break;case sA.customcCcChange:s.customControllers[A[0]]=A[1];break;case sA.killNote:this.killNote(e,A);break;case sA.programChange:this.programChange(e,A[0],A[1]);break;case sA.channelPressure:this.channelPressure(e,A);break;case sA.polyPressure:this.polyPressure(e,A[0],A[1]);break;case sA.ccReset:e===OA?this.resetAllControllers():this.resetControllers(e);break;case sA.systemExclusive:this.systemExclusive(A);break;case sA.setChannelVibrato:if(e===OA)for(let i=0;i{let e=(A.midiControllers[dA+q.pitchWheelRange]>>7)+(A.midiControllers[dA+q.pitchWheelRange]&127)/127;return{voicesAmount:A.voices.length,pitchBend:A.midiControllers[dA+q.pitchWheel],pitchBendRangeSemitones:e,isMuted:A.isMuted,isDrum:A.drumChannel}});this.post({messageType:DA.channelProperties,messageData:t})}function Qr(t,A,e){let s=t,n=A<<7|e;return t===127&&A===127&&e===127?{midiNote:-1,centTuning:null}:{midiNote:s,centTuning:n*.0061}}function yn(t,A=0){let e=t[0];if(!(this.deviceID!==OA&&t[1]!==127&&this.deviceID!==t[1]))switch(e){default:T(`%cUnrecognized SysEx: %c${SA(t)}`,g.warn,g.unrecognized);break;case 126:case 127:switch(t[2]){case 4:let n;switch(t[3]){case 1:let o=t[5]<<7|t[4];this.setMIDIVolume(o/16384),p(`%cMaster Volume. Volume: %c${o}`,g.info,g.value);break;case 2:let a=((t[5]<<7|t[4])-8192)/8192;this.setMasterPan(a),p(`%cMaster Pan. Pan: %c${a}`,g.info,g.value);break;case 3:let C=(t[5]<<7|t[6])-8192;n=Math.floor(C/81.92),this.setMasterTuning(n),p(`%cMaster Fine Tuning. Cents: %c${n}`,g.info,g.value);break;case 4:n=(t[5]-64)*100,this.setMasterTuning(n),p(`%cMaster Coarse Tuning. Cents: %c${n}`,g.info,g.value);break;default:T(`%cUnrecognized MIDI Device Control Real-time message: %c${SA(t)}`,g.warn,g.unrecognized)}break;case 9:t[3]===1?(p("%cGM system on",g.info),this.system="gm"):t[3]===3?(p("%cGM2 system on",g.info),this.system="gm2"):(p("%cGM system off, defaulting to GS",g.info),this.system="gs");break;case 8:switch(t[3]){case 2:case 7:let o=4;t[3]===7&&o++;let i=t[o++],a=t[o++];for(let B=0;B>1&1)===1&&this.setOctaveTuning(15+A,C);for(let B=0;B<7;B++)(t[5]>>B&1)===1&&this.setOctaveTuning(7+B+A,C);for(let B=0;B<7;B++)(t[6]>>B&1)===1&&this.setOctaveTuning(B+A,C);p(`%cMIDI Octave Scale ${t[3]===8?"(1 byte)":"(2 bytes)"} tuning via Tuning: %c${C.join(" ")}`,g.info,g.value);break;default:T(`%cUnrecognized MIDI Tuning standard message: %c${SA(t)}`,g.warn,g.unrecognized);break}break;default:T(`%cUnrecognized MIDI Realtime/non realtime message: %c${SA(t)}`,g.warn,g.unrecognized)}break;case 65:let s=function(){T(`%cUnrecognized Roland %cGS %cSysEx: %c${SA(t)}`,g.warn,g.recognized,g.warn,g.unrecognized)};if(t[2]===66&&t[3]===18){let n=t[7];if(t[6]===127){n===0?(p("%cGS Reset received!",g.info),this.resetAllControllers(!1),this.system="gs"):n===127&&(p("%cGS system off, switching to GM2",g.info),this.resetAllControllers(!1),this.system="gm2");return}else if(t[4]===64){if((t[5]&16)>0){let o=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][t[5]&15]+A;switch(t[6]){default:s();break;case 21:let i=n>0&&t[5]>>4;this.setDrums(o,i),p(`%cChannel %c${o}%c ${i?"is now a drum channel":"now isn't a drum channel"}%c via: %c${SA(t)}`,g.info,g.value,g.recognized,g.info,g.value);return;case 22:let a=n-64;this.transposeChannel(o,a),p(`%cChannel %c${o}%c pitch shift. Semitones %c${a}%c, with %c${SA(t)}`,g.info,g.recognized,g.info,g.value,g.info,g.value);return;case 28:let C=n;C===0&&(C=Math.floor(Math.random()*128)),this.controllerChange(o,k.pan,C);break;case 33:this.controllerChange(o,k.chorusDepth,n);break;case 34:this.controllerChange(o,k.reverbDepth,n);break;case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:let B=t.length-9,d=new Int8Array(12);for(let l=0;l=this.workletProcessorChannels.length)return;let o=t[6];switch(t[5]){case 1:this.controllerChange(n,k.bankSelect,o);break;case 2:this.controllerChange(n,k.lsbForControl0BankSelect,o);break;case 3:this.programChange(n,o);break;case 8:let i=this.workletProcessorChannels[n];if(i.drumChannel)return;let a=o-64;i.channelTransposeKeyShift=a;break;case 11:this.controllerChange(n,k.mainVolume,o);break;case 14:let C=o;C===0&&(C=Math.floor(Math.random()*127)),this.controllerChange(n,k.pan,C);break;case 19:this.controllerChange(n,k.reverbDepth,o);break;case 18:this.controllerChange(n,k.chorusDepth,o);break;default:T(`%cUnrecognized Yamaha XG Part Setup: %c${t[5].toString(16).toUpperCase()}`,g.warn,g.unrecognized)}}else this.system==="xg"&&T(`%cUnrecognized Yamaha XG SysEx: %c${SA(t)}`,g.warn,g.unrecognized);else this.system==="xg"&&T(`%cUnrecognized Yamaha SysEx: %c${SA(t)}`,g.warn,g.unrecognized);break}}var ur=1e3/200;function Sn(t,A,e){if(A.transformAmount===0)return A.currentValue=0,0;let s;if(A.sourceUsesCC)s=t[A.sourceIndex];else{let B=A.sourceIndex+dA;switch(A.sourceIndex){case q.noController:s=16383;break;case q.noteOnKeyNum:s=e.midiNote<<7;break;case q.noteOnVelocity:s=e.velocity<<7;break;case q.polyPressure:s=e.pressure<<7;break;default:s=t[B];break}}let n=Qe[A.sourceCurveType][A.sourcePolarity][A.sourceDirection][s],o;if(A.secSrcUsesCC)o=t[A.secSrcIndex];else{let B=A.secSrcIndex+dA;switch(A.secSrcIndex){case q.noController:o=16383;break;case q.noteOnKeyNum:o=e.midiNote<<7;break;case q.noteOnVelocity:o=e.velocity<<7;break;case q.polyPressure:o=e.pressure<<7;break;default:o=t[B]}}let i=Qe[A.secSrcCurveType][A.secSrcPolarity][A.secSrcDirection][o],a=A.transformAmount;A.isEffectModulator&&a<=1e3&&(a*=ur,a=Math.min(a,1e3));let C=n*i*a;return A.transformType===2&&(C=Math.abs(C)),A.currentValue=C,C}function Ae(t,A,e=-1,s=0){let n=t.modulators,o=t.generators,i=t.modulatedGenerators;if(e===-1){i.set(o),n.forEach(B=>{let d=J[B.modulatorDestination],Q=i[B.modulatorDestination]+Sn(A,B,t);i[B.modulatorDestination]=Math.max(d.min,Math.min(Q,d.max))}),qA.recalculate(t),PA.recalculate(t);return}let a=new Set([r.initialAttenuation,r.delayVolEnv,r.attackVolEnv,r.holdVolEnv,r.decayVolEnv,r.sustainVolEnv,r.releaseVolEnv,r.keyNumToVolEnvHold,r.keyNumToVolEnvDecay]),C=new Set;n.forEach(B=>{if(B.sourceUsesCC===e&&B.sourceIndex===s||B.secSrcUsesCC===e&&B.secSrcIndex===s){let d=B.modulatorDestination;C.has(d)||(i[d]=o[d],Sn(A,B,t),n.forEach(Q=>{if(Q.modulatorDestination===d){let l=J[B.modulatorDestination],c=i[B.modulatorDestination]+Q.currentValue;i[B.modulatorDestination]=Math.max(l.min,Math.min(c,l.max))}}),C.add(d))}}),[...C].some(B=>a.has(B))&&qA.recalculate(t),PA.recalculate(t)}var Qe=[];for(let t=0;t<4;t++){Qe[t]=[[new Float32Array(fA),new Float32Array(fA)],[new Float32Array(fA),new Float32Array(fA)]];for(let A=0;A200&&e<40||this.highPerformanceMode&&e<10||i.isMuted)return;let a=A+i.channelTransposeKeyShift,C=a;if(A>127||A<0)return;let B=i.preset.program;this.tunings[B]?.[A]?.midiNote>=0&&(C=this.tunings[B]?.[A].midiNote),i.velocityOverride>0&&(e=i.velocityOverride);let d=this.keyModifierManager.getVelocity(t,A);d>-1&&(e=d);let Q=this.getWorkletVoices(t,C,e,i,o,a,s),l=i.voices;Q.forEach(c=>{let f=c.generators[r.exclusiveClass];f!==0&&l.forEach(G=>{G.generators[r.exclusiveClass]===f&&(this.releaseVoice(G,kn),G.modulatedGenerators[r.releaseVolEnv]=-7e3,G.modulatedGenerators[r.releaseModEnv]=-7e3,qA.recalculate(G),PA.recalculate(G))}),Ae(c,i.midiControllers);let y=c.modulatedGenerators[r.startAddrsOffset]+c.modulatedGenerators[r.startAddrsCoarseOffset]*32768,S=c.modulatedGenerators[r.endAddrOffset]+c.modulatedGenerators[r.endAddrsCoarseOffset]*32768,w=c.modulatedGenerators[r.startloopAddrsOffset]+c.modulatedGenerators[r.startloopAddrsCoarseOffset]*32768,H=c.modulatedGenerators[r.endloopAddrsOffset]+c.modulatedGenerators[r.endloopAddrsCoarseOffset]*32768,R=c.sample,x=G=>Math.max(0,Math.min(R.sampleData.length-1,G));if(R.cursor=x(R.cursor+y),R.end=x(R.end+S),R.loopStart=x(R.loopStart+w),R.loopEnd=x(R.loopEnd+H),R.loopEndthis.voiceCap&&this.voiceKilling(Q.length),l.push(...Q),n&&(this.sendChannelProperties(),this.callEvent("noteon",{midiNote:A,channel:t,velocity:e}))}function wn(t,A){if(A>127||A<0){T("Received a noteOn for note",A,"Ignoring.");return}let e=A+this.workletProcessorChannels[t].channelTransposeKeyShift;if(this.highPerformanceMode&&!this.workletProcessorChannels[t].drumChannel){this.killNote(t,e);return}this.workletProcessorChannels[t].voices.forEach(n=>{n.realKey!==e||n.isInRelease===!0||(this.workletProcessorChannels[t].holdPedal?this.workletProcessorChannels[t].sustainedVoices.push(n):this.releaseVoice(n))}),this.callEvent("noteoff",{midiNote:A,channel:t})}function Fn(t,A){this.workletProcessorChannels[t].voices.forEach(e=>{e.realKey===A&&(e.modulatedGenerators[r.releaseVolEnv]=-12e3,this.releaseVoice(e))})}function Rn(t,A=!1){let e=this.workletProcessorChannels[t].voices;A?(e.length=0,this.workletProcessorChannels[t].sustainedVoices.length=0,this.sendChannelProperties()):(e.forEach(s=>{s.isInRelease||this.releaseVoice(s)}),this.workletProcessorChannels[t].sustainedVoices.forEach(s=>{this.releaseVoice(s)}))}function Gn(t=!1){p("%cStop all received!",g.info);for(let A=0;AAe(n,this.workletProcessorChannels[t].midiControllers,0,q.pitchWheel)),this.sendChannelProperties()}function vn(t,A){let e=this.workletProcessorChannels[t];e.midiControllers[dA+q.channelPressure]=A<<7,this.workletProcessorChannels[t].voices.forEach(s=>Ae(s,e.midiControllers,0,q.channelPressure)),this.callEvent("channelpressure",{channel:t,pressure:A})}function Hn(t,A,e){this.workletProcessorChannels[t].voices.forEach(s=>{s.midiNote===A&&(s.pressure=e,Ae(s,this.workletProcessorChannels[t].midiControllers,0,q.polyPressure))}),this.callEvent("polypressure",{channel:t,midiNote:A,pressure:e})}function Yn(t,A){if(A.length!==12)throw new Error("Tuning is not the length of 12.");this.workletProcessorChannels[t].channelOctaveTuning=A}function Jn(t,A,e,s=!1){let n=this.workletProcessorChannels[t];if(n===void 0){T(`Trying to access channel ${t} which does not exist... ignoring!`);return}if(A>127){if(!s)return;switch(A){default:return;case Jt.velocityOverride:n.velocityOverride=e}}if(A>=k.lsbForControl1ModulationWheel&&A<=k.lsbForControl13EffectControl2&&A!==k.lsbForControl6DataEntry){let o=A-32;if(n.lockedControllers[o])return;n.midiControllers[o]=n.midiControllers[o]&16256|e&127,n.voices.forEach(i=>Ae(i,n.midiControllers,1,o))}switch(A){case k.allNotesOff:this.stopAll(t);break;case k.allSoundOff:this.stopAll(t,!0);break;case k.bankSelect:let o=e;if(!s){switch(this.system){case"gm":p(`%cIgnoring the Bank Select (${e}), as the synth is in GM mode.`,g.info);return;case"xg":o===120||o===126||o===127?this.setDrums(t,!0):t%16!==GA&&this.setDrums(t,!1);break;case"gm2":o===120&&this.setDrums(t,!0)}n.drumChannel&&(o=128),o===128&&!n.drumChannel&&(o=XA(n))}se(n,o);break;case k.lsbForControl0BankSelect:this.system==="xg"?n.drumChannel||e!==127&&se(n,e):this.system==="gm2"&&se(n,e);break;case k.RPNLsb:n.RPValue=n.RPValue<<7|e,n.dataEntryState=wA.RPFine;break;case k.RPNMsb:n.RPValue=e,n.dataEntryState=wA.RPCoarse;break;case k.NRPNMsb:n.NRPCoarse=e,n.dataEntryState=wA.NRPCoarse;break;case k.NRPNLsb:n.NRPFine=e,n.dataEntryState=wA.NRPFine;break;case k.dataEntryMsb:this.dataEntryCoarse(t,e);break;case k.lsbForControl6DataEntry:this.dataEntryFine(t,e);break;case k.resetAllControllers:this.resetControllers(t);break;case k.sustainPedal:e>=64?n.holdPedal=!0:(n.holdPedal=!1,n.sustainedVoices.forEach(i=>{this.releaseVoice(i)}),n.sustainedVoices=[]);break;default:if(n.lockedControllers[A])return;n.midiControllers[A]=e<<7,n.voices.forEach(i=>Ae(i,n.midiControllers,1,A));break}this.callEvent("controllerchange",{channel:t,controllerNumber:A,controllerValue:e})}function Pn(t){this.midiVolume=t,this.setMasterPan(this.pan)}function qn(t){this.masterGain=t*Xt,this.setMasterPan(this.pan)}function On(t){this.pan=t,t=t/2+.5,this.panLeft=1-t,this.panRight=t}function Vn(t,A){A&&this.stopAll(t,!0),this.workletProcessorChannels[t].isMuted=A,this.sendChannelProperties(),this.callEvent("mutechannel",{channel:t,isMuted:A})}function Kn(t){this.workletProcessorChannels[t].lockGSNRPNParams=!0,this.workletProcessorChannels[t].channelVibrato.rate=0,this.workletProcessorChannels[t].channelVibrato.delay=0,this.workletProcessorChannels[t].channelVibrato.depth=0}function Zn(t,A,e,s){this.workletProcessorChannels[t].lockGSNRPNParams||(this.workletProcessorChannels[t].channelVibrato.rate=e,this.workletProcessorChannels[t].channelVibrato.delay=s,this.workletProcessorChannels[t].channelVibrato.depth=A)}function Wn(t,A){let e=this.workletProcessorChannels[t],s=()=>{e.channelVibrato.delay===0&&e.channelVibrato.rate===0&&e.channelVibrato.depth===0&&(e.channelVibrato.depth=50,e.channelVibrato.rate=8,e.channelVibrato.delay=.6)};switch(e.dataEntryState){default:case wA.Idle:break;case wA.NRPFine:if(this.system!=="gs"||e.lockGSNRPNParams)return;switch(e.NRPCoarse){default:if(A===64)return;T(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16).toUpperCase()} 0x${e.NRPFine.toString(16).toUpperCase()})%c data value: %c${A}`,g.warn,g.recognized,g.warn,g.unrecognized,g.warn,g.value);break;case 1:switch(e.NRPFine){default:if(A===64)return;T(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16)} 0x${e.NRPFine.toString(16)})%c data value: %c${A}`,g.warn,g.recognized,g.warn,g.unrecognized,g.warn,g.value);break;case 8:if(A===64)return;s(),e.channelVibrato.rate=A/64*8,p(`%cVibrato rate for %c${t}%c is now set to %c${A} = ${e.channelVibrato.rate}%cHz.`,g.info,g.recognized,g.info,g.value,g.info);break;case 9:if(A===64)return;s(),e.channelVibrato.depth=A/2,p(`%cVibrato depth for %c${t}%c is now set to %c${A} = ${e.channelVibrato.depth}%c cents range of detune.`,g.info,g.recognized,g.info,g.value,g.info);break;case 10:if(A===64)return;s(),e.channelVibrato.delay=A/64/3,p(`%cVibrato delay for %c${t}%c is now set to %c${A} = ${e.channelVibrato.delay}%c seconds.`,g.info,g.recognized,g.info,g.value,g.info);break;case 32:let i=A;this.controllerChange(t,k.brightness,A),p(`%cFilter cutoff for %c${t}%c is now set to %c${i}`,g.info,g.recognized,g.info,g.value)}break;case 24:let n=A-64;e.keyCentTuning[e.NRPFine]=n*100,p(`%cGS drum key tuning. MIDI note: %c${e.NRPFine}%c semitones: %c${n}`,g.info,g.recognized,g.info,g.value);break;case 29:let o=A;this.controllerChange(t,k.reverbDepth,o),p(`%cGS Drum reverb for %c${t}%c: %c${o}`,g.info,g.recognized,g.info,g.value);break}break;case wA.RPCoarse:case wA.RPFine:switch(e.RPValue){default:T(`%cUnrecognized RPN for %c${t}%c: %c(0x${e.RPValue.toString(16)})%c data value: %c${A}`,g.warn,g.recognized,g.warn,g.unrecognized,g.warn,g.value);break;case 0:e.midiControllers[dA+q.pitchWheelRange]=A<<7,p(`%cChannel ${t} bend range. Semitones: %c${A}`,g.info,g.value);break;case 2:this.setChannelTuningSemitones(t,A-64);break;case 1:this.setChannelTuning(t,A-64,!1);break;case 5:this.setModulationDepth(t,A*100);break;case 16383:this.resetParameters(t);break}}}function Xn(t,A){let e=this.workletProcessorChannels[t];switch(e.dataEntryState){default:break;case wA.RPCoarse:case wA.RPFine:switch(e.RPValue){default:break;case 0:if(A===0)break;e.midiControllers[dA+q.pitchWheelRange]|=A;let s=(e.midiControllers[dA+q.pitchWheelRange]>>7)+A/127;p(`%cChannel ${t} bend range. Semitones: %c${s}`,g.info,g.value);break;case 1:let o=e.customControllers[hA.channelTuning]<<7|A;this.setChannelTuning(t,o*.01220703125);break;case 5:let a=e.customControllers[hA.modulationMultiplier]*50+A/128*100;this.setModulationDepth(t,a);break;case 16383:this.resetParameters(t);break}}}function _n(t=!0){t&&p("%cResetting all controllers!",g.info),this.callEvent("allcontrollerreset",void 0);for(let A=0;A>7});if(this.workletProcessorChannels[A].lockedControllers[dA+q.pitchWheel]===!1){let s=this.workletProcessorChannels[A].midiControllers[dA+q.pitchWheel],n=s>>7,o=s&127;this.callEvent("pitchwheel",{channel:A,MSB:n,LSB:o})}}this.tunings=[],this.tunings=[];for(let A=0;127>A;A++)this.tunings.push([]);this.setMIDIVolume(1),this.system=et}function zn(t){let A=this.workletProcessorChannels[t],e=A.lockedControllers.reduce((n,o,i)=>(o&&n.push(i),n),[]);A.channelOctaveTuning.fill(0),A.keyCentTuning.fill(0);for(let n=0;n>7}),A.midiControllers[n]=o}A.channelVibrato={rate:0,depth:0,delay:0},A.holdPedal=!1;let s=A.customControllers[hA.channelTransposeFine];A.customControllers.set(Yt),A.customControllers[hA.channelTransposeFine]=s,this.resetParameters(t)}function jn(t){let A=this.workletProcessorChannels[t];A.NRPCoarse=0,A.NRPFine=0,A.RPValue=0,A.dataEntryState=wA.Idle}function $n(){let t=4;for(let s of this.instruments)t+=s.instrumentZones.reduce((n,o)=>(o.generators=o.generators.filter(i=>i.generatorType!==r.sampleID&&i.generatorType!==r.keyRange&&i.generatorType!==r.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:r.velRange,generatorValue:o.velRange.max<<8|Math.max(o.velRange.min,0)}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:r.keyRange,generatorValue:o.keyRange.max<<8|Math.max(o.keyRange.min,0)}),o.isGlobal||o.generators.push({generatorType:r.sampleID,generatorValue:this.samples.indexOf(o.sample)}),o.generators.length*4+n),0);let A=new b(t),e=0;for(let s of this.instruments)for(let n of s.instrumentZones){n.generatorZoneStartIndex=e;for(let o of n.generators)L(A,o.generatorType),L(A,o.generatorValue),e++}return K(A,0),gA(new oA("igen",A.length,A))}function Ao(t,A,e,s,n){let o=this.samples.map((B,d)=>{e&&B.compressSample(s,n);let Q=B.getRawData();return p(`%cEncoded sample %c${d}. ${B.sampleName}%c of %c${this.samples.length}%c. Compressed: %c${B.isCompressed}%c.`,g.info,g.recognized,g.info,g.recognized,g.info,B.isCompressed?g.recognized:g.unrecognized,g.info),Q}),i=this.samples.reduce((B,d,Q)=>B+o[Q].length+46,0),a=new b(i);this.samples.forEach((B,d)=>{let Q=o[d],l,c,f=Q.length;B.isCompressed?(l=a.currentIndex,c=l+Q.length):(l=a.currentIndex/2,c=l+Q.length/2,f+=46),t.push(l),a.set(Q,a.currentIndex),a.currentIndex+=f,A.push(c)});let C=gA(new oA("smpl",a.length,a),new b([115,100,116,97]));return gA(new oA("LIST",C.length,C))}function eo(t,A){let s=new b(46*(this.samples.length+1));return this.samples.forEach((n,o)=>{yA(s,n.sampleName,20);let i=t[o];K(s,i);let a=A[o];K(s,a);let C=n.sampleLoopStartIndex+i,B=n.sampleLoopEndIndex+i;n.isCompressed&&(C-=i,B-=i),K(s,C),K(s,B),K(s,n.sampleRate),s[s.currentIndex++]=n.samplePitch,s[s.currentIndex++]=n.samplePitchCorrection,L(s,n.sampleLink),L(s,n.sampleType)}),yA(s,"EOS",46),gA(new oA("shdr",s.length,s))}function to(){let t=10;for(let s of this.instruments)t+=s.instrumentZones.reduce((n,o)=>o.modulators.length*10+n,0);let A=new b(t),e=0;for(let s of this.instruments)for(let n of s.instrumentZones){n.modulatorZoneStartIndex=e;for(let o of n.modulators)L(A,o.sourceEnum),L(A,o.modulatorDestination),L(A,o.transformAmount),L(A,o.secondarySourceEnum),L(A,o.transformType),e++}return De(A,0,10),gA(new oA("imod",A.length,A))}function so(){let t=this.instruments.reduce((o,i)=>i.instrumentZones.length*4+o,4),A=new b(t),e=0,s=0,n=0;for(let o of this.instruments){o.instrumentZoneIndex=e;for(let i of o.instrumentZones)i.zoneID=e,L(A,s),L(A,n),s+=i.generators.length,n+=i.modulators.length,e++}return L(A,s),L(A,n),gA(new oA("ibag",A.length,A))}function no(){let t=this.instruments.length*22+22,A=new b(t),e=0,s=0;for(let n of this.instruments)yA(A,n.instrumentName,20),L(A,e),e+=n.instrumentZones.length,n.instrumentID=s,s++;return yA(A,"EOI",20),L(A,e),gA(new oA("inst",A.length,A))}function oo(){let t=4;for(let s of this.presets)t+=s.presetZones.reduce((n,o)=>(o.generators=o.generators.filter(i=>i.generatorType!==r.instrument&&i.generatorType!==r.keyRange&&i.generatorType!==r.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:r.velRange,generatorValue:o.velRange.max<<8|Math.max(o.velRange.min,0)}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:r.keyRange,generatorValue:o.keyRange.max<<8|Math.max(o.keyRange.min,0)}),o.isGlobal||o.generators.push({generatorType:r.instrument,generatorValue:this.instruments.indexOf(o.instrument)}),o.generators.length*4+n),0);let A=new b(t),e=0;for(let s of this.presets)for(let n of s.presetZones){n.generatorZoneStartIndex=e;for(let o of n.generators)L(A,o.generatorType),L(A,o.generatorValue);e+=n.generators.length}return L(A,0),L(A,0),gA(new oA("pgen",A.length,A))}function ro(){let t=10;for(let s of this.presets)t+=s.presetZones.reduce((n,o)=>o.modulators.length*10+n,0);let A=new b(t),e=0;for(let s of this.presets)for(let n of s.presetZones){n.modulatorZoneStartIndex=e;for(let o of n.modulators)L(A,o.sourceEnum),L(A,o.modulatorDestination),L(A,o.transformAmount),L(A,o.secondarySourceEnum),L(A,o.transformType),e++}return De(A,0,10),gA(new oA("pmod",A.length,A))}function io(){let t=this.presets.reduce((o,i)=>i.presetZones.length*4+o,4),A=new b(t),e=0,s=0,n=0;for(let o of this.presets){o.presetZoneStartIndex=e;for(let i of o.presetZones)i.zoneID=e,L(A,s),L(A,n),s+=i.generators.length,n+=i.modulators.length,e++}return L(A,s),L(A,n),gA(new oA("pbag",A.length,A))}function ao(){let t=this.presets.length*38+38,A=new b(t),e=0;for(let s of this.presets)yA(A,s.presetName,20),L(A,s.program),L(A,s.bank),L(A,e),K(A,s.library),K(A,s.genre),K(A,s.morphology),e+=s.presetZones.length;return yA(A,"EOP",20),L(A,0),L(A,0),L(A,e),K(A,0),K(A,0),K(A,0),gA(new oA("phdr",A.length,A))}var dr={compress:!1,compressionQuality:.5,compressionFunction:void 0};function go(t=dr){if(t.compress&&typeof t.compressionFunction!="function")throw new TypeError("No compression function supplied but compression enabled.");QA("%cSaving soundfont...",g.info),p(`%cCompression: %c${t?.compress||"false"}%c quality: %c${t?.compressionQuality||"none"}`,g.info,g.recognized,g.info,g.recognized),p("%cWriting INFO...",g.info);let A=[];this.soundFontInfo.ISFT="SpessaSynth",t?.compress&&(this.soundFontInfo.ifil="3.0");for(let[x,G]of Object.entries(this.soundFontInfo))if(x==="ifil"||x==="iver"){let I=parseInt(G.split(".")[0]),rA=parseInt(G.split(".")[1]),Z=new b(4);L(Z,I),L(Z,rA),A.push(gA(new oA(x,4,Z)))}else if(x==="DMOD")A.push(gA(new oA(x,G.length,G)));else{let I=new b(G.length);yA(I,G),A.push(gA(new oA(x,G.length,I)))}let e=cA([new b([73,78,70,79]),...A]),s=gA(new oA("LIST",e.length,e));p("%cWriting SDTA...",g.info);let n=[],o=[],i=Ao.call(this,n,o,t?.compress,t?.compressionQuality??.5,t.compressionFunction);p("%cWriting PDTA...",g.info),p("%cWriting SHDR...",g.info);let a=eo.call(this,n,o);p("%cWriting IGEN...",g.info);let C=$n.call(this);p("%cWriting IMOD...",g.info);let B=to.call(this);p("%cWriting IBAG...",g.info);let d=so.call(this);p("%cWriting INST...",g.info);let Q=no.call(this),l=oo.call(this);p("%cWriting PMOD...",g.info);let c=ro.call(this);p("%cWriting PBAG...",g.info);let f=io.call(this);p("%cWriting PHDR...",g.info);let y=ao.call(this),S=cA([new b([112,100,116,97]),y,f,c,l,Q,d,B,C,a]),w=gA(new oA("LIST",S.length,S));p("%cWriting the output file...",g.info);let H=cA([new b([115,102,98,107]),s,i,w]),R=gA(new oA("RIFF",H.length,H));return p(`%cSaved succesfully! Final file size: %c${R.length}`,g.info,g.recognized),V(),R}var Te=class{velRange={min:-1,max:127};keyRange={min:-1,max:127};isGlobal=!1;generators=[];modulators=[];get hasKeyRange(){return this.keyRange.min!==-1}get hasVelRange(){return this.velRange.min!==-1}getGeneratorValue(A,e){return this.generators.find(s=>s.generatorType===A)?.generatorValue??e}};var FA=class extends Te{sample=void 0;useCount=0;deleteZone(){this.useCount--,!this.isGlobal&&this.sample.useCount--}},oe=class extends Te{instrument=void 0;deleteZone(){this.isGlobal||this.instrument.removeUseCount()}};var fr=new Set([r.velRange,r.keyRange,r.instrument,r.exclusiveClass,r.endOper,r.sampleModes,r.startloopAddrsOffset,r.startloopAddrsCoarseOffset,r.endloopAddrsOffset,r.endloopAddrsCoarseOffset,r.startAddrsOffset,r.startAddrsCoarseOffset,r.endAddrOffset,r.endAddrsCoarseOffset,r.initialAttenuation,r.fineTune,r.coarseTune,r.keyNumToVolEnvHold,r.keyNumToVolEnvDecay,r.keyNumToModEnvHold,r.keyNumToModEnvDecay]);function Io(t,A=!0){function e(Q,l){Q.push(...l.filter(c=>!Q.find(f=>f.generatorType===c.generatorType)))}function s(Q,l){return{min:Math.max(Q.min,l.min),max:Math.min(Q.max,l.max)}}function n(Q,l){Q.push(...l.filter(c=>!Q.find(f=>P.isIdentical(c,f))))}let o=[],i=[],a=[],C={min:0,max:127},B={min:0,max:127},d=t.presetZones.find(Q=>Q.isGlobal);d&&(i.push(...d.generators),a.push(...d.modulators),C=d.keyRange,B=d.velRange);for(let Q of t.presetZones){if(Q.isGlobal)continue;let l=Q.keyRange;Q.hasKeyRange||(l=C);let c=Q.velRange;Q.hasVelRange||(c=B);let f=Q.generators.map(I=>new N(I.generatorType,I.generatorValue));e(f,i);let y=[...Q.modulators];n(y,a);let S=Q.instrument.instrumentZones,w=[],H=[],R={min:0,max:127},x={min:0,max:127},G=S.find(I=>I.isGlobal);G&&(w.push(...G.generators),H.push(...G.modulators),R=G.keyRange,x=G.velRange);for(let I of S){if(I.isGlobal)continue;let rA=I.keyRange;I.hasKeyRange||(rA=R);let Z=I.velRange;if(I.hasVelRange||(Z=x),rA=s(rA,l),Z=s(Z,c),rA.maxnew N(eA.generatorType,eA.generatorValue));e(AA,w);let $=[...I.modulators];n($,H);let IA=[...$];for(let eA of y){let lA=IA.findIndex(UA=>P.isIdentical(eA,UA));lA!==-1?IA[lA]=IA[lA].sumTransform(eA):IA.push(eA)}let nA=AA.map(eA=>new N(eA.generatorType,eA.generatorValue));for(let eA of f){if(eA.generatorType===r.velRange||eA.generatorType===r.keyRange||eA.generatorType===r.instrument||eA.generatorType===r.endOper||eA.generatorType===r.sampleModes)continue;let lA=AA.findIndex(UA=>UA.generatorType===eA.generatorType);if(lA!==-1){let UA=nA[lA].generatorValue+eA.generatorValue;nA[lA]=new N(eA.generatorType,UA)}else{let UA=J[eA.generatorType].def+eA.generatorValue;nA.push(new N(eA.generatorType,UA))}}nA=nA.filter(eA=>eA.generatorType!==r.sampleID&&eA.generatorType!==r.keyRange&&eA.generatorType!==r.velRange&&eA.generatorType!==r.endOper&&eA.generatorType!==r.instrument&&eA.generatorValue!==J[eA.generatorType].def);let iA=new FA;iA.keyRange=rA,iA.velRange=Z,iA.keyRange.min===0&&iA.keyRange.max===127&&(iA.keyRange.min=-1),iA.velRange.min===0&&iA.velRange.max===127&&(iA.velRange.min=-1),iA.isGlobal=!1,iA.sample=I.sample,iA.generators=nA,iA.modulators=IA,o.push(iA)}}if(A){let Q=new FA;Q.isGlobal=!0;for(let f=0;f<58;f++){if(fr.has(f))continue;let y={},S=J[f]?.def||0;y[S]=0;for(let w of o){let H=w.generators.find(G=>G.generatorType===f);if(H){let G=H.generatorValue;y[G]===void 0?y[G]=1:y[G]++}else y[S]++;let R;switch(f){default:continue;case r.decayVolEnv:R=r.keyNumToVolEnvDecay;break;case r.holdVolEnv:R=r.keyNumToVolEnvHold;break;case r.decayModEnv:R=r.keyNumToModEnvDecay;break;case r.holdModEnv:R=r.keyNumToModEnvHold}if(w.generators.find(G=>G.generatorType===R)!==void 0){y={};break}}if(Object.keys(y).length>0){let w=Object.entries(y).reduce((R,x)=>R[1]{let x=R.generators.findIndex(G=>G.generatorType===f);x!==-1?R.generators[x].generatorValue===H&&R.generators.splice(x,1):H!==S&&R.generators.push(new N(f,S))})}}let c=o.find(f=>!f.isGlobal).modulators.map(f=>P.copy(f));for(let f of c){let y=!0;for(let S of o){if(S.isGlobal||!y)continue;S.modulators.find(H=>P.isIdentical(H,f))||(y=!1)}if(y===!0){Q.modulators.push(P.copy(f));for(let S of o){let w=S.modulators.find(H=>P.isIdentical(H,f));w.transformAmount===f.transformAmount&&S.modulators.splice(S.modulators.indexOf(w),1)}}}o.splice(0,0,Q)}return o}var Eo=20;function gt(t,A,e,s,n,o,i){let a=i===0?0:1,C=new b(Eo+a*16);K(C,Eo),L(C,A),L(C,e);let B=s*.4,d=Math.floor(B*-65536);K(C,d),K(C,2);let Q=o-n,l=0;switch(i){default:case 0:a=0;break;case 1:l=0,a=1;break;case 3:l=1,a=1}return K(C,a),a===1&&(K(C,16),K(C,l),K(C,n),K(C,Q)),tA("wsmp",C)}var v={none:0,modLfo:1,velocity:2,keyNum:3,volEnv:4,modEnv:5,pitchWheel:6,polyPressure:7,channelPressure:8,vibratoLfo:9,modulationWheel:129,volume:135,pan:138,expression:139,chorus:219,reverb:221,pitchWheelRange:256,fineTune:257,coarseTune:258},It=new P({srcEnum:219,dest:r.reverbEffectsSend,amt:1e3,secSrcEnum:0,transform:0}),Et=new P({srcEnum:221,dest:r.chorusEffectsSend,amt:1e3,secSrcEnum:0,transform:0}),Ct=new P({srcEnum:129,dest:r.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0}),Bt=new P({srcEnum:13,dest:r.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0});var D={none:0,gain:1,reserved:2,pitch:3,pan:4,keyNum:5,chorusSend:128,reverbSend:129,modLfoFreq:260,modLfoDelay:261,vibLfoFreq:276,vibLfoDelay:277,volEnvAttack:518,volEnvDecay:519,volEnvRelease:521,volEnvSustain:522,volEnvDelay:523,volEnvHold:524,modEnvAttack:778,modEnvDecay:779,modEnvRelease:781,modEnvSustain:782,modEnvDelay:783,modEnvHold:784,filterCutoff:1280,filterQ:1281};var ve=class{source;control;destination;scale;transform;constructor(A,e,s,n,o){this.source=A,this.control=e,this.destination=s,this.scale=n,this.transform=o}writeArticulator(){let A=new b(12);return L(A,this.source),L(A,this.control),L(A,this.destination),L(A,this.transform),K(A,this.scale<<16),A}};function Co(t,A){if(t)switch(A){default:return;case k.modulationWheel:return v.modulationWheel;case k.mainVolume:return v.volume;case k.pan:return v.pan;case k.expressionController:return v.expression;case k.chorusDepth:return v.chorus;case k.reverbDepth:return v.reverb}else switch(A){default:return;case q.noteOnKeyNum:return v.keyNum;case q.noteOnVelocity:return v.velocity;case q.noController:return v.none;case q.polyPressure:return v.polyPressure;case q.channelPressure:return v.channelPressure;case q.pitchWheel:return v.pitchWheel;case q.pitchWheelRange:return v.pitchWheelRange}}function Bo(t,A){switch(t){default:return;case r.initialAttenuation:return{dest:D.gain,amount:-A};case r.fineTune:return D.pitch;case r.pan:return D.pan;case r.keyNum:return D.keyNum;case r.reverbEffectsSend:return D.reverbSend;case r.chorusEffectsSend:return D.chorusSend;case r.freqModLFO:return D.modLfoFreq;case r.delayModLFO:return D.modLfoDelay;case r.delayVibLFO:return D.vibLfoDelay;case r.freqVibLFO:return D.vibLfoFreq;case r.delayVolEnv:return D.volEnvDelay;case r.attackVolEnv:return D.volEnvAttack;case r.holdVolEnv:return D.volEnvHold;case r.decayVolEnv:return D.volEnvDecay;case r.sustainVolEnv:return{dest:D.volEnvSustain,amount:1e3-A};case r.releaseVolEnv:return D.volEnvRelease;case r.delayModEnv:return D.modEnvDelay;case r.attackModEnv:return D.modEnvAttack;case r.holdModEnv:return D.modEnvHold;case r.decayModEnv:return D.modEnvDecay;case r.sustainModEnv:return{dest:D.modEnvSustain,amount:1e3-A};case r.releaseModEnv:return D.modEnvRelease;case r.initialFilterFc:return D.filterCutoff;case r.initialFilterQ:return D.filterQ}}function ho(t,A){switch(t){default:return;case r.modEnvToFilterFc:return{source:v.modEnv,dest:D.filterCutoff,amt:A,isBipolar:!1};case r.modEnvToPitch:return{source:v.modEnv,dest:D.pitch,amt:A,isBipolar:!1};case r.modLfoToFilterFc:return{source:v.modLfo,dest:D.filterCutoff,amt:A,isBipolar:!0};case r.modLfoToVolume:return{source:v.modLfo,dest:D.gain,amt:A,isBipolar:!0};case r.modLfoToPitch:return{source:v.modLfo,dest:D.pitch,amt:A,isBipolar:!0};case r.vibLfoToPitch:return{source:v.vibratoLfo,dest:D.pitch,amt:A,isBipolar:!0};case r.keyNumToVolEnvHold:return{source:v.keyNum,dest:D.volEnvHold,amt:A,isBipolar:!0};case r.keyNumToVolEnvDecay:return{source:v.keyNum,dest:D.volEnvDecay,amt:A,isBipolar:!0};case r.keyNumToModEnvHold:return{source:v.keyNum,dest:D.modEnvHold,amt:A,isBipolar:!0};case r.keyNumToModEnvDecay:return{source:v.keyNum,dest:D.modEnvDecay,amt:A,isBipolar:!0};case r.scaleTuning:return{source:v.keyNum,dest:D.pitch,amt:A*128,isBipolar:!1}}}function co(t){let A=Bo(t.generatorType,t.generatorValue),e=A,s=0,n=t.generatorValue;A?.amount!==void 0&&(n=A.amount,e=A.dest);let o=ho(t.generatorType,t.generatorValue);if(o!==void 0)n=o.amt,e=o.dest,s=o.source;else if(e===void 0){T(`Invalid generator type: ${t.generatorType}`);return}return new ve(s,0,e,n,0)}function lo(t){if(t.transformType!==0){T("Other transform types are not supported.");return}let A=Co(t.sourceUsesCC,t.sourceIndex),e=t.sourceCurveType,s=t.sourcePolarity,n=t.sourceDirection;if(A===void 0){T(`Invalid source: ${t.sourceIndex}, CC: ${t.sourceUsesCC}`);return}t.modulatorDestination===r.initialAttenuation&&(n=n===1?0:1);let o=Co(t.secSrcUsesCC,t.secSrcIndex),i=t.secSrcCurveType,a=t.secSrcPolarity,C=t.secSrcDirection;if(o===void 0){T(`Invalid secondary source: ${t.secSrcIndex}, CC: ${t.secSrcUsesCC}`);return}let B=Bo(t.modulatorDestination,t.transformAmount),d=B,Q=t.transformAmount;B?.dest!==void 0&&(d=B.dest,Q=B.amount);let l=ho(t.modulatorDestination,t.transformAmount);if(l!==void 0)Q=l.amt,o=A,i=e,a=s,C=n,e=uA.linear,s=l.isBipolar?1:0,n=0,A=l.source,d=l.dest;else if(d===void 0){T(`Invalid destination: ${t.modulatorDestination}`);return}let c=0;return c|=i<<4,c|=a<<8,c|=C<<9,c|=e,c|=s<<14,c|=n<<15,new ve(A,o,d,Q,c)}var mr=new Set([r.sampleModes,r.initialAttenuation,r.keyRange,r.velRange,r.sampleID,r.fineTune,r.coarseTune,r.startAddrsOffset,r.startAddrsCoarseOffset,r.endAddrOffset,r.endAddrsCoarseOffset,r.startloopAddrsOffset,r.startloopAddrsCoarseOffset,r.endloopAddrsOffset,r.endloopAddrsCoarseOffset,r.overridingRootKey,r.exclusiveClass]);function ht(t){for(let o=0;of.generatorType===a);if(C===void 0)continue;let B=i.generatorValue*-128,d=60/128*B,Q=C.generatorValue-d,l=t.generators.indexOf(i),c=t.generators.indexOf(C);t.generators[c]=new N(a,Q,!1),t.generators[l]=new N(i.generatorType,B,!1)}let A=t.generators.reduce((o,i)=>{if(mr.has(i.generatorType))return o;let a=co(i);return a!==void 0?(o.push(a),p("%cSucceeded converting to DLS Articulator!",g.recognized)):T("Failed converting to DLS Articulator!"),o},[]),e=t.modulators.reduce((o,i)=>{if(P.isIdentical(i,Et,!0)||P.isIdentical(i,It,!0)||P.isIdentical(i,Ct,!0)||P.isIdentical(i,Bt,!0))return o;let a=lo(i);return a!==void 0?(o.push(a),p("%cSucceeded converting to DLS Articulator!",g.recognized)):T("Failed converting to DLS Articulator!"),o},[]);A.push(...e);let s=new b(8);K(s,8),K(s,A.length);let n=A.map(o=>o.writeArticulator());return tA("art2",cA([s,...n]))}function Qo(t,A){let e=new b(12);L(e,Math.max(t.keyRange.min,0)),L(e,t.keyRange.max),L(e,Math.max(t.velRange.min,0)),L(e,t.velRange.max),L(e,0);let s=t.getGeneratorValue(r.exclusiveClass,0);L(e,s),L(e,0);let n=tA("rgnh",e),o=t.getGeneratorValue(r.overridingRootKey,t.sample.samplePitch);t.getGeneratorValue(r.scaleTuning,A.getGeneratorValue(r.scaleTuning,100))===0&&t.keyRange.max-t.keyRange.min===0&&(o=t.keyRange.min);let a=gt(t.sample,o,t.getGeneratorValue(r.fineTune,0)+t.getGeneratorValue(r.coarseTune,0)*100+t.sample.samplePitchCorrection,t.getGeneratorValue(r.initialAttenuation,0),t.sample.sampleLoopStartIndex+t.getGeneratorValue(r.startloopAddrsOffset,0)+t.getGeneratorValue(r.startloopAddrsCoarseOffset,0)*32768,t.sample.sampleLoopEndIndex+t.getGeneratorValue(r.endloopAddrsOffset,0)+t.getGeneratorValue(r.endloopAddrsCoarseOffset,0)*32768,t.getGeneratorValue(r.sampleModes,0)),C=new b(12);L(C,0),L(C,0),K(C,1),K(C,this.samples.indexOf(t.sample));let B=tA("wlnk",C),d=new b(0);if(t.modulators.length+t.generators.length>0){let Q=ht(t);d=tA("lar2",Q,!1,!0)}return tA("rgn2",cA([n,a,B,d]),!1,!0)}function uo(t){QA(`%cWriting %c${t.presetName}%c...`,g.info,g.recognized,g.info);let A=Io(t),e=A.reduce((l,c)=>c.isGlobal?l:l+1,0),s=new b(12);K(s,e);let n=(t.bank&127)<<8;t.bank===128&&(n|=1<<31),K(s,n),K(s,t.program&127);let o=tA("insh",s),i=new b(0),a=A.find(l=>l.isGlobal===!0);if(a){let l=ht(a);i=tA("lar2",l,!1,!0)}let C=cA(A.reduce((l,c)=>(c.isGlobal||l.push(Qo.apply(this,[c,a])),l),[])),B=tA("lrgn",C,!1,!0),d=tA("INAM",Be(t.presetName)),Q=tA("INFO",d,!1,!0);return V(),tA("ins ",cA([o,B,i,Q]),!1,!0)}function fo(){let t=cA(this.presets.map(A=>uo.apply(this,[A])));return tA("lins",t,!1,!0)}function mo(t){let A=new b(18);L(A,1),L(A,1),K(A,t.sampleRate),K(A,t.sampleRate*2),L(A,2),L(A,16);let e=tA("fmt ",A),s=1;t.sampleLoopStartIndex+Math.abs(t.getAudioData().length-t.sampleLoopEndIndex)<2&&(s=0);let n=gt(t,t.samplePitch,t.samplePitchCorrection,0,t.sampleLoopStartIndex,t.sampleLoopEndIndex,s),o=t.getAudioData(),i;if(t.isCompressed){let B=new Int16Array(o.length);for(let d=0;d{let n=mo(s);return A.push(t),t+=n.length,n});return{data:tA("wvpl",cA(e),!1,!0),indexes:A}}function yo(){QA("%cSaving DLS...",g.info);let t=new b(4);K(t,this.presets.length);let A=tA("colh",t);QA("%cWriting instruments...",g.info);let e=fo.apply(this);p("%cSuccess!",g.recognized),V(),QA("%cWriting WAVE samples...",g.info);let s=po.apply(this),n=s.data,o=s.indexes;p("%cSucceeded!",g.recognized),V();let i=new b(8+4*o.length);K(i,8),K(i,o.length);for(let Q of o)K(i,Q);let a=tA("ptbl",i);this.soundFontInfo.ICMT=(this.soundFontInfo.ICMT||"Soundfont")+` -Converted from SF2 to DLS using SpessaSynth`,this.soundFontInfo.ISFT="SpessaSynth";let C=[];for(let[Q,l]of Object.entries(this.soundFontInfo))Q!=="ICMT"&&Q!=="INAM"&&Q!=="ICRD"&&Q!=="IENG"&&Q!=="ICOP"&&Q!=="ISFT"&&Q!=="ISBJ"||C.push(tA(Q,Be(l),!0));let B=tA("INFO",cA(C),!1,!0),d=new b(A.length+e.length+a.length+n.length+B.length+4);return yA(d,"DLS "),d.set(cA([A,e,a,n,B]),4),p("%cSaved succesfully!",g.recognized),V(),tA("RIFF",d)}var pr=48e3,re=class{constructor(A,e,s,n,o,i,a,C){this.sampleName=A,this.sampleRate=e,this.samplePitch=s,this.samplePitchCorrection=n,this.sampleLink=o,this.sampleType=i,this.sampleLoopStartIndex=a,this.sampleLoopEndIndex=C,this.isCompressed=(i&16)>0,this.compressedData=void 0,this.useCount=0,this.sampleData=void 0}getRawData(){let A=new Uint8Array(this.sampleData.length*2);for(let e=0;e>8&255}return A}resampleData(A){let e=this.getAudioData(),s=A/this.sampleRate,n=new Float32Array(Math.floor(e.length*s));for(let o=0;o96e3)&&(this.resampleData(pr),s=this.getAudioData()),this.compressedData=e([s],1,this.sampleRate,A),this.sampleType|=16,this.isCompressed=!0}catch{T(`Failed to compress ${this.sampleName}. Leaving as uncompressed!`),this.isCompressed=!1,this.compressedData=void 0,this.sampleType&=239}}getAudioData(){return this.sampleData}};var ie=class{constructor(){this.instrumentName="",this.instrumentZones=[],this._useCount=0}get useCount(){return this._useCount}addUseCount(){this._useCount++,this.instrumentZones.forEach(A=>A.useCount++)}removeUseCount(){this._useCount--;for(let A=0;AA.deleteZone()),this.instrumentZones.length=0}safeDeleteZone(A){return this.instrumentZones[A].useCount--,this.instrumentZones[A].useCount<1?(this.deleteZone(A),!0):!1}deleteZone(A){this.instrumentZones[A].deleteZone(),this.instrumentZones.splice(A,1)}};var ae=class{constructor(A){this.presetName="",this.program=0,this.bank=0,this.presetZones=[],this.sampleIDOffset=0,this.foundSamplesAndGenerators=[];for(let e=0;e<128;e++)this.foundSamplesAndGenerators[e]=[];this.library=0,this.genre=0,this.morphology=0,this.defaultModulators=A}deletePreset(){this.presetZones.forEach(A=>A.deleteZone()),this.presetZones.length=0}deleteZone(A){this.presetZones[A].deleteZone(),this.presetZones.splice(A,1)}preload(A,e){for(let s=A;s{o.sample.isSampleLoaded||o.sample.getAudioData()})}preloadSpecific(A,e){this.getSamplesAndGenerators(A,e).forEach(s=>{s.sample.isSampleLoaded||s.sample.getAudioData()})}getSamplesAndGenerators(A,e){let s=this.foundSamplesAndGenerators[A][e];if(s)return s;if(this.presetZones.length<1)return[];function n(c,f){return f>=c.min&&f<=c.max}function o(c,f){c.push(...f.filter(y=>!c.find(S=>S.generatorType===y.generatorType)))}function i(c,f){c.push(...f.filter(y=>!c.find(S=>P.isIdentical(y,S))))}let a=[],C=this.presetZones[0].isGlobal?[...this.presetZones[0].generators]:[],B=this.presetZones[0].isGlobal?[...this.presetZones[0].modulators]:[],d=this.presetZones[0].isGlobal?this.presetZones[0].keyRange:{min:0,max:127},Q=this.presetZones[0].isGlobal?this.presetZones[0].velRange:{min:0,max:127};return this.presetZones.filter(c=>n(c.hasKeyRange?c.keyRange:d,A)&&n(c.hasVelRange?c.velRange:Q,e)&&!c.isGlobal).forEach(c=>{if(c.instrument.instrumentZones.length<1)return;let f=c.generators,y=c.modulators,S=c.instrument.instrumentZones[0],w=S.isGlobal?[...S.generators]:[],H=S.isGlobal?[...S.modulators]:[],R=S.isGlobal?S.keyRange:{min:0,max:127},x=S.isGlobal?S.velRange:{min:0,max:127};c.instrument.instrumentZones.filter(I=>n(I.hasKeyRange?I.keyRange:R,A)&&n(I.hasVelRange?I.velRange:x,e)&&!I.isGlobal).forEach(I=>{let rA=[...I.generators],Z=[...I.modulators];o(f,C),o(rA,w),i(y,B),i(Z,H),i(Z,this.defaultModulators);let AA=[...Z];for(let $=0;$P.isIdentical(IA,iA));nA!==-1?AA[nA]=AA[nA].sumTransform(IA):AA.push(IA)}a.push({instrumentGenerators:rA,presetGenerators:f,modulators:AA,sample:I.sample,sampleID:I.generators.find($=>$.generatorType===r.sampleID).generatorValue})})}),this.foundSamplesAndGenerators[A][e]=a,a}};var ge=class t{constructor(A=void 0){this.soundFontInfo={},this.presets=[],this.samples=[],this.instruments=[],this.defaultModulators=_e.map(e=>P.copy(e)),A?.presets&&(this.presets.push(...A.presets),this.soundFontInfo=A.info)}static mergeSoundfonts(...A){let e=A.shift(),s=e.presets;for(;A.length;)A.shift().presets.forEach(o=>{s.find(i=>i.bank===o.bank&&i.program===o.program)===void 0&&s.push(o)});return new t({presets:s,info:e.soundFontInfo})}static getDummySoundfontFile(){let A=new t,e=new re("Saw",44100,65,20,0,0,0,127);e.sampleData=new Float32Array(128);for(let B=0;B<128;B++)e.sampleData[B]=B/128*2-1;A.samples.push(e);let s=new FA;s.isGlobal=!0,s.generators.push(new N(r.initialAttenuation,375)),s.generators.push(new N(r.releaseVolEnv,-1e3)),s.generators.push(new N(r.sampleModes,1));let n=new FA;n.sample=e;let o=new FA;o.sample=e,o.generators.push(new N(r.fineTune,-9));let i=new ie;i.instrumentName="Saw Wave",i.instrumentZones.push(s),i.instrumentZones.push(n),i.instrumentZones.push(o),A.instruments.push(i);let a=new oe;a.instrument=i;let C=new ae(A.defaultModulators);return C.presetName="Saw Wave",C.presetZones.push(a),A.presets.push(C),A.soundFontInfo.ifil="2.1",A.soundFontInfo.isng="EMU8000",A.soundFontInfo.INAM="Dummy",A.write().buffer}removeUnusedElements(){this.instruments.forEach(A=>{A.useCount<1&&A.instrumentZones.forEach(e=>{e.isGlobal||e.sample.useCount--})}),this.instruments=this.instruments.filter(A=>A.useCount>0),this.samples=this.samples.filter(A=>A.useCount>0)}deleteInstrument(A){if(A.useCount>0)throw new Error(`Cannot delete an instrument that has ${A.useCount} usages.`);this.instruments.splice(this.instruments.indexOf(A),1),A.deleteInstrument(),this.removeUnusedElements()}deletePreset(A){A.deletePreset(),this.presets.splice(this.presets.indexOf(A),1),this.removeUnusedElements()}deleteSample(A){if(A.useCount>0)throw new Error(`Cannot delete sample that has ${A.useCount} usages.`);this.samples.splice(this.samples.indexOf(A),1),this.removeUnusedElements()}setSampleIDOffset(A){this.presets.forEach(e=>e.sampleIDOffset=A)}getPresetNoFallback(A,e,s=!1){let n=this.presets.find(o=>o.bank===A&&o.program===e);if(n)return n;if(s!==!1)return A===128?this.presets.find(o=>o.bank===128):this.presets.find(o=>o.program===e)}getPreset(A,e){let s=this.presets.find(n=>n.bank===A&&n.program===e);return s||(A===128?(s=this.presets.find(n=>n.bank===128&&n.program===e),s||(s=this.presets.find(n=>n.bank===128))):s=this.presets.find(n=>n.program===e&&n.bank!==128),s&&T(`%cPreset ${A}.${e} not found. Replaced with %c${s.presetName} (${s.bank}.${s.program})`,g.warn,g.recognized)),s||(T(`Preset ${e} not found. Defaulting to`,this.presets[0].presetName),s=this.presets[0]),s}getPresetByName(A){let e=this.presets.find(s=>s.presetName===A);return e||(T("Preset not found. Defaulting to:",this.presets[0].presetName),e=this.presets[0]),e}parsingError(A){throw new Error(`SF parsing error: ${A} The file may be corrupted.`)}destroySoundfont(){delete this.presets,delete this.instruments,delete this.samples}};ge.prototype.write=go;ge.prototype.writeDLS=yo;function So(t){QA("%cLoading instruments...",g.info);for(let A=0;A>8&127,A>>31&&(this.bank=128),this.DLSInstrument=new ie,this.DLSInstrument.addUseCount();let n=new oe;n.instrument=this.DLSInstrument,this.presetZones=[n]}};function Do(t){this.verifyHeader(t,"LIST"),this.verifyText(_(t.chunkData,4),"ins ");let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(z(t.chunkData));let e=A.find(c=>c.header==="insh");if(!e)throw V(),new Error("No instrument header!");let s=F(e.chunkData,4),n=F(e.chunkData,4),o=F(e.chunkData,4),i=new ct(n,o),a="unnamedPreset",C=MA(A,"INFO");if(C){let c=z(C.chunkData);for(;c.header!=="INAM";)c=z(C.chunkData);a=_(c.chunkData,c.chunkData.length).trim()}i.presetName=a,i.DLSInstrument.instrumentName=a,Ce(`%cParsing %c"${a}"%c...`,g.info,g.recognized,g.info);let B=MA(A,"lrgn");if(!B)throw V(),new Error("No region list!");let d=new FA;d.isGlobal=!0;let Q=MA(A,"lart"),l=MA(A,"lar2");(l!==void 0||Q!==void 0)&&this.readLart(Q,l,d),d.generators=d.generators.filter(c=>c.generatorValue!==J[c.generatorType].def),d.modulators.find(c=>c.modulatorDestination===r.reverbEffectsSend)===void 0&&d.modulators.push(P.copy(It)),d.modulators.find(c=>c.modulatorDestination===r.chorusEffectsSend)===void 0&&d.modulators.push(P.copy(Et)),i.DLSInstrument.instrumentZones.push(d);for(let c=0;c>10&15;H===uA.linear&&w!==uA.linear&&(H=w);let R=s>>14&1,x=s>>15&1;i===r.initialAttenuation&&n<0&&(x=1),l=VA(H,R,x,a.isCC,a.enum)}let c=s>>4&15,f=s>>8&1,y=s>>9&1,S=VA(c,f,y,Q.isCC,Q.enum);if(C){let w=S;S=l,l=w}return new P({srcEnum:l,secSrcEnum:S,dest:i,transform:0,amt:d})}function _t(t,A){let e=t.chunkData,s=[],n=[];F(e,4);let o=F(e,4);for(let i=0;i>16;if(a===0&&C===0&&d===0){let c;switch(B){case D.pan:c=new N(r.pan,l);break;case D.gain:c=new N(r.initialAttenuation,-l*10/.4);break;case D.filterCutoff:c=new N(r.initialFilterFc,l);break;case D.filterQ:c=new N(r.initialFilterQ,l);break;case D.modLfoFreq:c=new N(r.freqModLFO,l);break;case D.modLfoDelay:c=new N(r.delayModLFO,l);break;case D.vibLfoFreq:c=new N(r.freqVibLFO,l);break;case D.vibLfoDelay:c=new N(r.delayVibLFO,l);break;case D.volEnvDelay:c=new N(r.delayVolEnv,l);break;case D.volEnvAttack:c=new N(r.attackVolEnv,l);break;case D.volEnvHold:c=new N(r.holdVolEnv,l,!1);break;case D.volEnvDecay:c=new N(r.decayVolEnv,l,!1);break;case D.volEnvRelease:c=new N(r.releaseVolEnv,l);break;case D.volEnvSustain:let f=1e3-l;c=new N(r.sustainVolEnv,f);break;case D.modEnvDelay:c=new N(r.delayModEnv,l);break;case D.modEnvAttack:c=new N(r.attackModEnv,l);break;case D.modEnvHold:c=new N(r.holdModEnv,l,!1);break;case D.modEnvDecay:c=new N(r.decayModEnv,l,!1);break;case D.modEnvRelease:c=new N(r.releaseModEnv,l);break;case D.modEnvSustain:let y=1e3-l;c=new N(r.sustainModEnv,y);break;case D.reverbSend:c=new N(r.reverbEffectsSend,l);break;case D.chorusSend:c=new N(r.chorusEffectsSend,l);break;case D.pitch:let S=Math.floor(l/100),w=Math.floor(l-S*100);c=new N(r.fineTune,w),s.push(new N(r.coarseTune,S));break}c&&s.push(c)}else{let c=!0;if(C===v.none)if(a===v.modLfo&&B===D.pitch)s.push(new N(r.modLfoToPitch,l));else if(a===v.modLfo&&B===D.gain)s.push(new N(r.modLfoToVolume,l));else if(a===v.modLfo&&B===D.filterCutoff)s.push(new N(r.modLfoToFilterFc,l));else if(a===v.vibratoLfo&&B===D.pitch)s.push(new N(r.vibLfoToPitch,l));else if(a===v.modEnv&&B===D.pitch)s.push(new N(r.modEnvToPitch,l));else if(a===v.modEnv&&B===D.filterCutoff)s.push(new N(r.modEnvToFilterFc,l));else if(a===v.keyNum&&B===D.pitch)s.push(new N(r.scaleTuning,l/128));else if(a===v.keyNum&&B===D.volEnvHold){s.push(new N(r.keyNumToVolEnvHold,l/-128));let f=Math.round(60/128*l);s.forEach(y=>{y.generatorType===r.holdVolEnv&&(y.generatorValue+=f)})}else if(a===v.keyNum&&B===D.volEnvDecay){s.push(new N(r.keyNumToVolEnvDecay,l/-128));let f=Math.round(60/128*l);s.forEach(y=>{y.generatorType===r.decayVolEnv&&(y.generatorValue+=f)})}else if(a===v.keyNum&&B===D.modEnvHold){s.push(new N(r.keyNumToModEnvHold,l/-128));let f=Math.round(60/128*l);s.forEach(y=>{y.generatorType===r.holdModEnv&&(y.generatorValue+=f)})}else if(a===v.keyNum&&B===D.modEnvDecay){s.push(new N(r.keyNumToModEnvDecay,l/-128));let f=Math.round(60/128*l);s.forEach(y=>{y.generatorType===r.decayModEnv&&(y.generatorValue+=f)})}else c=!1;else c=!1;if(c===!1){let f=wo(a,C,B,d,l);f?(n.push(f),p("%cSucceeded converting to SF2 Modulator!",g.recognized)):T("Failed converting to SF2 Modulator!")}}}return A&&n.push(P.copy(Ct),P.copy(Bt)),{modulators:n,generators:s}}function Fo(t,A,e){if(t)for(;t.chunkData.currentIndext.chunkData.currentIndex;)A.push(z(t.chunkData));let e=A.find(Z=>Z.header==="rgnh"),s=F(e.chunkData,2),n=F(e.chunkData,2),o=F(e.chunkData,2),i=F(e.chunkData,2),a=new lt({min:s,max:n},{min:o,max:i});F(e.chunkData,2);let C=F(e.chunkData,2);C!==0&&a.generators.push(new N(r.exclusiveClass,C));let B=MA(A,"lart"),d=MA(A,"lar2");this.readLart(B,d,a),a.isGlobal=!1;let Q=A.find(Z=>Z.header==="wsmp");F(Q.chunkData,4);let l=F(Q.chunkData,2),c=ne(Q.chunkData[Q.chunkData.currentIndex++],Q.chunkData[Q.chunkData.currentIndex++]),y=(F(Q.chunkData,4)|0)/-655360;F(Q.chunkData,4);let S=F(Q.chunkData,4),w,H={start:0,end:0};if(S===0)w=0;else{F(Q.chunkData,4),F(Q.chunkData,4)===0?w=1:w=3,H.start=F(Q.chunkData,4);let AA=F(Q.chunkData,4);H.end=H.start+AA}let R=A.find(Z=>Z.header==="wlnk");if(R===void 0)return;F(R.chunkData,2),F(R.chunkData,2),F(R.chunkData,4);let x=F(R.chunkData,4),G=this.samples[x];if(G===void 0)throw new Error("Invalid sample ID!");let rA=(y||G.sampleDbAttenuation)*10/.4;return a.setWavesample(rA,w,H,l,G,x,c),a}var Qt=class extends re{sampleDbAttenuation;sampleData;constructor(A,e,s,n,o,i,a,C){super(A,e,s,n,0,1,o,i),this.sampleData=a,this.sampleDbAttenuation=C}getAudioData(){return this.sampleData}getRawData(){if(this.isCompressed){if(!this.compressedData)throw new Error("Compressed but no data?? This shouldn't happen!!");return this.compressedData}return super.getRawData()}};var Go={PCM:1,ALAW:6};function Dr(t,A){let e=Math.pow(2,A*8-1),s=Math.pow(2,A*8),n,o=!1;A===1?(n=255,o=!0):n=e;let i=t.size/A,a=new Float32Array(i);for(let C=0;C=e&&(B-=s),a[C]=B/n)}return a}function kr(t,A){let e=t.size/A,s=new Float32Array(e);for(let n=0;n>4,C=i&15;a>0&&(C+=16),C=(C<<4)+8,a>1&&(C=C<127?C:-C;s[n]=B/32678}return s}function Mo(t){QA("%cLoading Wave samples...",g.recognized);let A=0;for(;t.chunkData.currentIndexG.header==="fmt ");if(!n)throw new Error("No fmt chunk in the wave file!");let o=F(n.chunkData,2),i=F(n.chunkData,2);if(i!==1)throw new Error(`Only mono samples are supported. Fmt reports ${i} channels`);let a=F(n.chunkData,4);F(n.chunkData,4),F(n.chunkData,2);let B=F(n.chunkData,2)/8,d=!1,Q=s.find(G=>G.header==="data");Q||this.parsingError("No data chunk in the WAVE chunk!");let l;switch(o){default:d=!0,l=new Float32Array(Q.size/B);break;case Go.PCM:l=Dr(Q,B);break;case Go.ALAW:l=kr(Q,B);break}let c=MA(s,"INFO"),f=`Unnamed ${A}`;if(c){let G=z(c.chunkData);for(;G.header!=="INAM"&&c.chunkData.currentIndexG.header==="wsmp");if(x){F(x.chunkData,4),y=F(x.chunkData,2),S=ne(x.chunkData[x.chunkData.currentIndex++],x.chunkData[x.chunkData.currentIndex++]);let G=Math.trunc(S/100);if(y+=G,S-=G*100,R=(F(x.chunkData,4)|0)/-655360,F(x.chunkData,4),F(x.chunkData,4)===1){F(x.chunkData,8),w=F(x.chunkData,4);let Z=F(x.chunkData,4);H=w+Z}}else T("No wsmp chunk in wave... using sane defaults.");d&&console.error(`Failed to load '${f}': Unsupported format: (${o})`),this.samples.push(new Qt(f,a,y,S,w,H,l,R)),A++,p(`%cLoaded sample %c${f}`,g.info,g.recognized)}V()}var ee=class extends ge{constructor(A){super(),this.dataArray=new b(A),Ce("%cParsing DLS...",g.info),this.dataArray||(V(),this.parsingError("No data provided!"));let e=z(this.dataArray,!1);this.verifyHeader(e,"riff"),this.verifyText(_(this.dataArray,4).toLowerCase(),"dls ");let s=[];for(;this.dataArray.currentIndexye[t]=A<<7;kA(k.mainVolume,100);kA(k.balance,64);kA(k.expressionController,127);kA(k.pan,64);kA(k.timbreHarmonicContent,64);kA(k.releaseTime,64);kA(k.attackTime,64);kA(k.brightness,64);kA(k.soundController6,64);kA(k.soundController7,64);kA(k.soundController8,64);kA(k.soundController9,64);kA(k.generalPurposeController6,64);kA(k.generalPurposeController8,64);kA(dA+q.pitchWheel,64);kA(dA+q.pitchWheelRange,2);var hA={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4},Jt=Object.keys(hA).length,Pt=new Float32Array(Jt);Pt[hA.modulationMultiplier]=1;var wA={Idle:0,RPCoarse:1,RPFine:2,NRPCoarse:3,NRPFine:4,DataCoarse:5,DataFine:6};function vn(t=!1){let A={midiControllers:new Int16Array(ze),lockedControllers:Array(ze).fill(!1),customControllers:new Float32Array(Jt),NRPCoarse:0,NRPFine:0,RPValue:0,dataEntryState:wA.Idle,voices:[],sustainedVoices:[],cachedVoices:[],preset:this.defaultPreset,presetUsesOverride:!1,channelTransposeKeyShift:0,channelOctaveTuning:new Int8Array(12),keyCentTuning:new Int16Array(128),channelVibrato:{delay:0,depth:0,rate:0},velocityOverride:0,lockGSNRPNParams:!1,holdPedal:!1,isMuted:!1,drumChannel:!1,lockPreset:!1};for(let e=0;e<128;e++)A.cachedVoices.push([]);this.workletProcessorChannels.push(A),this.resetControllers(this.workletProcessorChannels.length-1),this.sendChannelProperties(),t&&this.callEvent("newchannel",void 0)}function ne(t,A){t.lockPreset||(t.bank=A)}function XA(t){return t.drumChannel?128:t.bank}var qt={velocityOverride:128};var je={addMapping:0,deleteMapping:1,clearMappings:2},$e=class{_keyMappings=[];handleMessage(A,e){switch(A){default:return;case je.addMapping:this.addMapping(...e);break;case je.clearMappings:this.clearMappings();break;case je.deleteMapping:this.deleteMapping(...e)}}addMapping(A,e,n){this._keyMappings[A]===void 0&&(this._keyMappings[A]=[]),this._keyMappings[A][e]=n}deleteMapping(A,e){this._keyMappings[A]?.[e]!==void 0&&(this._keyMappings[A][e]=void 0)}clearMappings(){this._keyMappings=[]}setMappings(A){this._keyMappings=A}getMappings(){return this._keyMappings}getVelocity(A,e){let n=this._keyMappings[A]?.[e];return n?n.velocity:-1}hasOverridePatch(A,e){let n=this._keyMappings[A]?.[e]?.patch?.bank;return n!==void 0&&n>=0}getPatch(A,e){let n=this._keyMappings[A]?.[e];if(n)return n.patch;throw new Error("No modifier.")}};var Hn="spessasynth-worklet-system",Yn=350,GA=9,At=16,et="gs";var NA={loadNewSongList:0,pause:1,stop:2,play:3,setTime:4,changeMIDIMessageSending:5,setPlaybackRate:6,setLoop:7,changeSong:8,getMIDI:9,setSkipToFirstNote:10,setPreservePlaybackState:11},bA={midiEvent:0,songChange:1,textEvent:2,timeChange:3,pause:4,getMIDI:5,midiError:6};function _A(t,A){let e=0;for(let n=8*(A-1);n>=0;n-=8)e|=t[t.currentIndex++]<>>0}function Jn(t,A){if(this.ignoreEvents)return;if(this.sendMIDIMessages&&t.messageStatusByte>=128){this.sendMIDIMessage([t.messageStatusByte,...t.messageData]);return}let e=be(t.messageStatusByte),n=this.midiPortChannelOffsets[this.midiPorts[A]]||0;switch(e.channel+=n,e.status){case M.noteOn:let s=t.messageData[1];if(s>0)this.synth.noteOn(e.channel,t.messageData[0],s),this.playingNotes.push({midiNote:t.messageData[0],channel:e.channel,velocity:s});else{this.synth.noteOff(e.channel,t.messageData[0]);let i=this.playingNotes.findIndex(a=>a.midiNote===t.messageData[0]&&a.channel===e.channel);i!==-1&&this.playingNotes.splice(i,1)}break;case M.noteOff:this.synth.noteOff(e.channel,t.messageData[0]);let o=this.playingNotes.findIndex(i=>i.midiNote===t.messageData[0]&&i.channel===e.channel);o!==-1&&this.playingNotes.splice(o,1);break;case M.pitchBend:this.synth.pitchWheel(e.channel,t.messageData[1],t.messageData[0]);break;case M.controllerChange:this.synth.controllerChange(e.channel,t.messageData[0],t.messageData[1]);break;case M.programChange:this.synth.programChange(e.channel,t.messageData[0]);break;case M.polyPressure:this.synth.polyPressure(e.channel,t.messageData[0],t.messageData[1]);break;case M.channelPressure:this.synth.channelPressure(e.channel,t.messageData[0]);break;case M.systemExclusive:this.synth.systemExclusive(t.messageData,n);break;case M.setTempo:this.oneTickToSeconds=60/(Br(t)*this.midiData.timeDivision),this.oneTickToSeconds===0&&(this.oneTickToSeconds=60/(120*this.midiData.timeDivision),T("invalid tempo! falling back to 120 BPM"));break;case M.timeSignature:case M.endOfTrack:case M.midiChannelPrefix:case M.songPosition:case M.activeSensing:case M.keySignature:case M.sequenceNumber:case M.sequenceSpecific:break;case M.text:case M.lyric:case M.copyright:case M.trackName:case M.marker:case M.cuePoint:case M.instrumentName:case M.programName:this.post(bA.textEvent,[t.messageData,e.status]);break;case M.midiPort:this.assignMIDIPort(A,t.messageData[0]);break;case M.reset:this.synth.stopAllChannels(),this.synth.resetAllControllers();break;default:T(`%cUnrecognized Event: %c${t.messageStatusByte}%c status byte: %c${Object.keys(M).find(i=>M[i]===e.status)}`,g.warn,g.unrecognized,g.warn,g.value);break}}function Pn(){for(let t=0;t<16;t++)this.synth.createWorkletChannel(!0),t===GA&&this.synth.setDrums(this.synth.workletProcessorChannels.length-1,!0)}function Br(t){return t.messageData.currentIndex=0,6e7/_A(t.messageData,3)}function qn(){let t=this.currentTime;for(;this.playedTime1&&this.nextSong();return}let n=this.tracks[A][this.eventIndex[A]];if(this.playedTime+=this.oneTickToSeconds*(n.ticks-e.ticks),this.midiData.loop.end<=e.ticks&&this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}else if(t>=this.duration){if(this.loop&&this.currentLoopCount>0){this.currentLoopCount--,this.setTimeTicks(this.midiData.loop.start);return}this.eventIndex[A]--,this.pause(!0),this.songs.length>1&&this.nextSong();return}}}function Vn(){let t=0,A=1/0;return this.tracks.forEach((e,n)=>{this.eventIndex[n]>=e.length||e[this.eventIndex[n]].ticks>>0}function De(t,A,e){for(let n=0;n>n*8&255}function L(t,A){t[t.currentIndex++]=A&255,t[t.currentIndex++]=A>>8}function K(t,A){De(t,A,4)}function se(t,A){let e=A<<8|t;return e>32767?e-65536:e}function On(t){return t>127?t-256:t}function _(t,A,e=void 0,n=!0){if(e){let s=t.slice(t.currentIndex,t.currentIndex+A);return t.currentIndex+=A,new TextDecoder(e.replace(/[^\x20-\x7E]/g,"")).decode(s.buffer)}else{let s=!1,o="";for(let i=0;i127)&&a!==10){if(n){s=!0;continue}else if(a===0){s=!0;continue}}o+=String.fromCharCode(a)}}return o}}function Kn(t,A=0){let e=t.length;A>0&&(e=A);let n=new b(e);return yA(n,t,A),n}function Be(t){return Kn(t,t.length+1)}function yA(t,A,e=0){e>0&&A.length>e&&(A=A.slice(0,e));for(let n=0;nA.length)for(let n=0;ne.header!=="LIST"?!1:(e.chunkData.currentIndex=0,_(e.chunkData,4)===A))}function nt(t){let A=0;for(;t;){let e=t[t.currentIndex++];if(A=A<<7|e&127,e>>7!==1)break}return A}var st={name:"INAM",album:"IPRD",album2:"IALB",artist:"IART",genre:"IGNR",picture:"IPIC",copyright:"ICOP",creationDate:"ICRD",comment:"ICMT",engineer:"IENG",software:"ISFT",encoding:"IENC",midiEncoding:"MENC",bankOffset:"DBNK"};var ot=class t extends Se{embeddedSoundFont=void 0;tracks=[];static copyFrom(A){let e=new t;return e.midiName=A.midiName,e.midiNameUsesFileName=A.midiNameUsesFileName,e.fileName=A.fileName,e.timeDivision=A.timeDivision,e.duration=A.duration,e.copyright=A.copyright,e.tracksAmount=A.tracksAmount,e.firstNoteOn=A.firstNoteOn,e.keyRange={...A.keyRange},e.lastVoiceEventTick=A.lastVoiceEventTick,e.loop={...A.loop},e.format=A.format,e.bankOffset=A.bankOffset,e.tempoChanges=[...A.tempoChanges],e.lyrics=A.lyrics.map(n=>new Uint8Array(n)),e.midiPorts=[...A.midiPorts],e.midiPortChannelOffsets=[...A.midiPortChannelOffsets],e.usedChannelsOnTrack=A.usedChannelsOnTrack.map(n=>new Set(n)),e.rawMidiName=A.rawMidiName?new Uint8Array(A.rawMidiName):void 0,e.embeddedSoundFont=A.embeddedSoundFont?A.embeddedSoundFont.slice():void 0,e.RMIDInfo={...A.RMIDInfo},e.tracks=A.tracks.map(n=>[...n]),e}flush(){let A=[];for(let s of this.tracks){s.sort((i,a)=>i.ticks-a.ticks);let o=s.find(i=>(i.messageStatusByte&240)===M.noteOn);o&&A.push(o.ticks)}this.firstNoteOn=Math.min(...A),this.lastVoiceEventTick=0,this.tempoChanges=[{ticks:0,tempo:120}],this.midiPorts=[],this.midiPortChannelOffsets=[];let e=0;this.usedChannelsOnTrack=this.tracks.map(()=>new Set),this.tracks.forEach((s,o)=>{this.midiPorts.push(-1),s.forEach(i=>{if(i.messageStatusByte>=128&&i.messageStatusByte<240&&i.ticks>this.lastVoiceEventTick&&(this.lastVoiceEventTick=i.ticks),i.messageStatusByte===M.setTempo)this.tempoChanges.push({ticks:i.ticks,tempo:6e7/_A(i.messageData,3)});else if((i.messageStatusByte&240)===M.noteOn)this.usedChannelsOnTrack[o].add(i.messageData[0]);else if(i.messageStatusByte===M.midiPort){let a=i.messageData[0];this.midiPorts[o]=a,this.midiPortChannelOffsets[a]===void 0&&(this.midiPortChannelOffsets[a]=e,e+=16)}})}),this.loop={start:this.firstNoteOn,end:this.lastVoiceEventTick},this.tempoChanges.reverse(),this.duration=he(this.lastVoiceEventTick,this);let n=0;for(let s of this.midiPorts)if(s!==-1){n=s;break}this.midiPorts=this.midiPorts.map(s=>s===-1?n:s),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0])}};function he(t,A){let e=0;for(;t>0;){let n=A.tempoChanges.find(o=>o.ticks0&&(x+=this.tracks[y-1][this.tracks[y-1].length-1].ticks);w.data.currentIndexthis.lastVoiceEventTick&&(this.lastVoiceEventTick=x),Z=Mn[I>>4],(I&240)===M.noteOn){H.add(rA);let sA=w.data[w.data.currentIndex];this.keyRange.min=Math.min(this.keyRange.min,sA),this.keyRange.max=Math.max(this.keyRange.max,sA)}R=I;break}let AA=new b(Z),$=w.data.slice(w.data.currentIndex,w.data.currentIndex+Z);w.data.currentIndex+=Z,AA.set($,0);let IA=new fe(x,I,AA);switch(S.push(IA),rA){case-2:switch(I){case M.setTempo:this.tempoChanges.push({ticks:x,tempo:6e7/_A($,3)});break;case M.marker:switch(_(AA,AA.length).trim().toLowerCase()){default:break;case"start":case"loopstart":d=x;break;case"loopend":Q=x}AA.currentIndex=0;break;case M.midiPort:let iA=AA[0];this.midiPorts[y]=iA,this.midiPortChannelOffsets[iA]===void 0&&(this.midiPortChannelOffsets[iA]=l,l+=16);break;case M.copyright:o||(this.copyright+=_(AA,AA.length,void 0,!1)+` +`);break;case M.lyric:this.lyrics.push(AA)}break;case-3:if(AA.slice(0,7).every((sA,iA)=>hr[iA]===sA)){let sA=AA.slice(7,$.length-3),iA=_(sA,sA.length)+` +`;this.copyright+=iA,p(`%cDecoded Roland SC message! %c${iA}`,g.recognized,g.value)}break;default:if((I&240)===M.controllerChange)switch(AA[0]){case 2:case 116:d=x;break;case 4:case 117:Q===null?Q=x:Q=0;break;case 0:a&&AA[1]!==0&&AA[1]!==127&&(p("%cDLS RMIDI with offset 1 detected!",g.recognized),this.bankOffset=1)}}}this.tracks.push(S),this.usedChannelsOnTrack.push(H),p(`%cParsed %c${this.tracks.length}%c / %c${this.tracksAmount}`,g.info,g.value,g.info,g.value)}p("%cAll tracks parsed correctly!",g.recognized),QA("%cCorrecting loops, ports and detecting notes...",g.info);let c=[];for(let y of this.tracks){let S=y.find(w=>(w.messageStatusByte&240)===M.noteOn);S&&c.push(S.ticks)}this.firstNoteOn=Math.min(...c),p(`%cFirst note-on detected at: %c${this.firstNoteOn}%c ticks!`,g.info,g.recognized,g.info),d!==null&&Q===null?(d=this.firstNoteOn,Q=this.lastVoiceEventTick):(d===null&&(d=this.firstNoteOn),(Q===null||Q===0)&&(Q=this.lastVoiceEventTick)),this.loop={start:d,end:Q},p(`%cLoop points: start: %c${this.loop.start}%c end: %c${this.loop.end}`,g.info,g.recognized,g.info,g.recognized);let f=0;for(let y of this.midiPorts)if(y!==-1){f=y;break}if(this.midiPorts=this.midiPorts.map(y=>y===-1?f:y),this.midiPortChannelOffsets.length===0&&(this.midiPortChannelOffsets=[0]),this.midiPortChannelOffsets.length<2?p("%cNo additional MIDI Ports detected.",g.info):p("%cMIDI Ports detected!",g.recognized),!i)if(this.tracks.length>1){if(this.tracks[0].find(y=>y.messageStatusByte>=M.noteOn&&y.messageStatusByteS.messageStatusByte===M.trackName);y&&(this.rawMidiName=y.messageData,this.midiName=_(y.messageData,y.messageData.length,void 0,!1))}}else{let y=this.tracks[0].find(S=>S.messageStatusByte===M.trackName);y&&(this.rawMidiName=y.messageData,this.midiName=_(y.messageData,y.messageData.length,void 0,!1))}if(this.fileName=e,this.midiName=this.midiName.trim(),this.midiNameUsesFileName=!1,this.midiName.length===0){p("%cNo name detected. Using the alt name!",g.info),this.midiName=Rn(e),this.midiNameUsesFileName=!0,this.rawMidiName=new Uint8Array(this.midiName.length);for(let y=0;yl>Q?l:Q),n=[];for(let Q=0;Q{i[f]>=c.length||c[i[f]].ticks0;){let Q=C(),l=t.tracks[Q];if(i[Q]>=l.length){a--;continue}let c=l[i[Q]];if(i[Q]++,c.messageStatusByte===M.midiPort){B[Q]=c.messageData[0];continue}let f=c.messageStatusByte&240;if(f!==M.noteOn&&f!==M.controllerChange&&f!==M.programChange&&f!==M.systemExclusive)continue;let y=(c.messageStatusByte&15)+t.midiPortChannelOffsets[B[Q]]||0,S=n[y];switch(f){case M.programChange:S.program=c.messageData[0],s(S);break;case M.controllerChange:if(c.messageData[0]!==k.bankSelect||d==="gs"&&S.drums)continue;let w=c.messageData[1],H=Math.max(0,w-t.bankOffset);if(d==="xg"){let G=w===120||w===126||w===127;G!==S.drums?(S.drums=G,S.bank=S.drums?128:H,s(S)):S.bank=S.drums?128:H;continue}n[y].bank=H;break;case M.noteOn:if(c.messageData[1]===0)continue;s(S),o[S.string].add(`${c.messageData[0]}-${c.messageData[1]}`);break;case M.systemExclusive:if(c.messageData[0]!==65||c.messageData[2]!==66||c.messageData[3]!==18||c.messageData[4]!==64||!(c.messageData[5]&16)||c.messageData[6]!==21){c.messageData[0]===67&&c.messageData[2]===76&&c.messageData[5]===126&&c.messageData[6]===0&&(d="xg");continue}let R=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][c.messageData[5]&15]+t.midiPortChannelOffsets[B[Q]],x=!!(c.messageData[7]>0&&c.messageData[5]>>4);S=n[R],S.drums=x,S.bank=x?128:0,s(S);break}}for(let Q of Object.keys(o))o[Q].size===0&&(p(`%cDetected change but no keys for %c${Q}`,g.info,g.value),delete o[Q]);return O(),o}function Wn(t,A){this.midiData.usedChannelsOnTrack[t].size!==0&&(this.midiPortChannelOffset===0&&(this.midiPortChannelOffset+=16,this.midiPortChannelOffsets[A]=0),this.midiPortChannelOffsets[A]===void 0&&(this.synth.workletProcessorChannels.length{this.assignMIDIPort(n,e)}),this.duration=this.midiData.duration,this.firstNoteTime=he(this.midiData.firstNoteOn,this.midiData),p(`%cTotal song time: ${vt(Math.ceil(this.duration)).time}`,g.recognized),this.post(bA.songChange,[new tt(this.midiData),this.songIndex,A]),this.duration<=1&&(T(`%cVery short song: (${vt(Math.round(this.duration)).time}). Disabling loop!`,g.warn),this.loop=!1),A)this.play(!0);else{let e=this._skipToFirstNoteOn?this.midiData.firstNoteOn-1:0;this.setTimeTicks(e),this.pause()}}function _n(t,A=!0){this.songs=t.reduce((e,n)=>{if(n.duration)return e.push(n),e;try{e.push(new rt(n.binary,n.altName||""))}catch(s){return this.post(bA.midiError,s.message),e}return e},[]),!(this.songs.length<1)&&(this.songIndex=0,this.songs.length>1&&(this.loop=!1),this.loadNewSequence(this.songs[this.songIndex],A))}function zn(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex++,this.songIndex%=this.songs.length,this.loadNewSequence(this.songs[this.songIndex])}function jn(){if(this.songs.length===1){this.currentTime=0;return}this.songIndex--,this.songIndex<0&&(this.songIndex=this.songs.length-1),this.loadNewSequence(this.songs[this.songIndex])}var Le=ye.slice(0,128);function $n(t,A=void 0){this.oneTickToSeconds=60/(120*this.midiData.timeDivision),this.synth.resetAllControllers(),this.sendMIDIReset(),this._resetTimers();let e=this.synth.workletProcessorChannels.length,n=Array(e).fill(8192),s=[];for(let a=0;aa===k.dataDecrement||a===k.dataIncrement||a===k.dataEntryMsb||a===k.dataDecrement||a===k.lsbForControl6DataEntry||a===k.RPNLsb||a===k.RPNMsb||a===k.NRPNLsb||a===k.NRPNMsb||a===k.bankSelect||a===k.lsbForControl0BankSelect||a===k.resetAllControllers,i=[];for(let a=0;a=A)break}else if(this.playedTime>=t)break;let B=be(C.messageStatusByte),d=B.channel+(this.midiPortChannelOffsets[this.midiPorts[a]]||0);switch(B.status){case M.noteOn:case M.noteOff:case M.keySignature:break;case M.pitchBend:n[d]=C.messageData[1]<<7|C.messageData[0];break;case M.programChange:let l=s[d];l.program=C.messageData[0],l.actualBank=l.bank;break;case M.controllerChange:let c=C.messageData[0];if(o(c)){let f=C.messageData[1];if(c===k.bankSelect){s[d].bank=f;break}else c===k.resetAllControllers&&(i[d]=Array.from(Le));this.sendMIDIMessages?this.sendMIDICC(d,c,f):this.synth.controllerChange(d,c,f)}else i[d]===void 0&&(i[d]=Array.from(Le)),i[d][c]=C.messageData[1];break;default:this._processEvent(C,a);break}this.eventIndex[a]++,a=this._findFirstEventIndex();let Q=this.tracks[a][this.eventIndex[a]];if(Q===void 0)return this.stop(),!1;this.playedTime+=this.oneTickToSeconds*(Q.ticks-C.ticks)}if(this.sendMIDIMessages){for(let a=0;a>7,n[a]&127),i[a]!==void 0&&i[a].forEach((C,B)=>{C!==Le[B]&&!o(B)&&this.sendMIDICC(a,B,C)}),s[a].program>=0&&s[a].actualBank>=0){let C=s[a].actualBank;this.sendMIDICC(a,k.bankSelect,C),this.sendMIDIProgramChange(a,s[a].program)}}else for(let a=0;a>7,n[a]&127),i[a]!==void 0&&i[a].forEach((C,B)=>{C!==Le[B]&&!o(B)&&this.synth.controllerChange(a,B,C)}),s[a].program>=0&&s[a].actualBank>=0){let C=s[a].actualBank;this.synth.controllerChange(a,k.bankSelect,C),this.synth.programChange(a,s[a].program)}return!0}function As(t=!1){if(this.midiData!==void 0){if(t){this.pausedTime=void 0,this.currentTime=0;return}if(this.currentTime>=this.duration){this.pausedTime=void 0,this.currentTime=0;return}this.paused&&(this._recalculateStartTime(this.pausedTime),this.pausedTime=void 0),this.sendMIDIMessages||this.playingNotes.forEach(A=>{this.synth.noteOn(A.channel,A.midiNote,A.velocity,!1,!0)}),this.setProcessHandler()}}function es(t){this.stop(),this.playingNotes=[],this.pausedTime=void 0,this.post(bA.timeChange,currentTime-he(t,this.midiData));let A=this._playTo(0,t);this._recalculateStartTime(this.playedTime),A&&this.play()}function ts(t){this.absoluteStartTime=currentTime-t/this._playbackRate}function ns(t,A){switch(t){default:break;case NA.loadNewSongList:this.loadNewSongList(A[0],A[1]);break;case NA.pause:this.pause();break;case NA.play:this.play(A);break;case NA.stop:this.stop();break;case NA.setTime:this.currentTime=A;break;case NA.changeMIDIMessageSending:this.sendMIDIMessages=A;break;case NA.setPlaybackRate:this.playbackRate=A;break;case NA.setLoop:this.loop=A;break;case NA.changeSong:A?this.nextSong():this.previousSong();break;case NA.getMIDI:this.post(bA.getMIDI,this.midiData);break;case NA.setSkipToFirstNote:this._skipToFirstNoteOn=A;break;case NA.setPreservePlaybackState:this.preservePlaybackState=A}}function ss(t,A=void 0){this.synth.enableEventSystem&&this.synth.post({messageType:DA.sequencerSpecific,messageData:{messageType:t,messageData:A}})}function os(t){this.post(bA.midiEvent,t)}function rs(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([M.controllerChange|t,A,e])}function is(t,A){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([M.programChange|t,A])}function as(t,A,e){t%=16,this.sendMIDIMessages&&this.sendMIDIMessage([M.pitchBend|t,e,A])}function gs(){if(this.sendMIDIMessages){this.sendMIDIMessage([M.reset]);for(let t=0;tthis.duration||A<0){this._skipToFirstNoteOn?this.setTimeTicks(this.midiData.firstNoteOn-1):this.setTimeTicks(0);return}if(this._skipToFirstNoteOn&&AIs?440*Math.pow(2,(t-6900)/1200):Ot[~~t-it]}var Zt=-1660,cr=1600,Kt=new Float32Array((cr-Zt)*100+1);for(let t=0;t.5?1:0,n?e*2-1:e;case uA.concave:return n?(e=e*2-1,e<0?-$A[~~(e*-fA)]:$A[~~(e*fA)]):$A[~~(e*fA)];case uA.convex:return n?(e=e*2-1,e<0?-ce[~~(e*-fA)]:ce[~~(e*fA)]):ce[~~(e*fA)]}}var Wt=1,Xt=new Float32Array(1e3);for(let t=0;t=e.loopEnd;)n-=o;let a=~~n,C=a+1;for(;C>=e.loopEnd;)C-=o;let B=n-a,d=s[C],Q=s[a];A[i]=Q+(d-Q)*B,n+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end){t.finished=!0;return}let C=n-i,B=s[a],d=s[i];A[o]=d+(B-d)*C,n+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=n}function Cs(t,A){let e=t.sample,n=e.cursor,s=e.loopEnd-e.loopStart,o=e.sampleData;if(t.sample.isLooping)for(let i=0;i=e.loopEnd;)n-=s;let a=~~n+1;for(;a>=e.loopEnd;)a-=s;A[i]=o[a],n+=e.playbackStep*t.currentTuningCalculated}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let i=0;i=e.end){t.finished=!0;return}A[i]=o[a],n+=e.playbackStep*t.currentTuningCalculated}}e.cursor=n}function Bs(t,A){let e=t.sample,n=e.cursor,s=e.sampleData;if(e.isLooping){let o=e.loopEnd-e.loopStart;for(let i=0;i=e.loopEnd;)n-=o;let a=~~n,C=a+1,B=C+1,d=B+1,Q=n-a;C>=e.loopEnd&&(C-=o),B>=e.loopEnd&&(B-=o),d>=e.loopEnd&&(d-=o);let l=s[a],c=s[C],f=s[B],y=s[d],S=.5*(f-l),w=l-2.5*c+2*f-.5*y,H=.5*(y-l)+1.5*(c-f);A[i]=((H*Q+w)*Q+S)*Q+c,n+=e.playbackStep*t.currentTuningCalculated}}else{if(e.loopingMode===2&&!t.isInRelease)return;for(let o=0;o=e.end||C>=e.end||B>=e.end){t.finished=!0;return}let Q=s[i],l=s[a],c=s[C],f=s[B],y=.5*(c-Q),S=Q-2.5*l+2*c-.5*f,w=.5*(f-Q)+1.5*(l-c);A[o]=((w*d+S)*d+y)*d+l,n+=e.playbackStep*t.currentTuningCalculated}}t.sample.cursor=n}var hs=.01,LA=100,_t=90,lr=15e-6,qA=class t{currentSampleTime=0;sampleRate;currentAttenuationDb=LA;state=0;releaseStartDb=LA;releaseStartTimeSamples=0;currentReleaseGain=1;attackDuration=0;decayDuration=0;releaseDuration=0;attenuation=0;attenuationTargetGain=0;attenuationTarget=0;sustainDbRelative=0;delayEnd=0;attackEnd=0;holdEnd=0;decayEnd=0;constructor(A,e){this.sampleRate=A,this.canEndOnSilentSustain=e/10>=_t}static startRelease(A){A.volumeEnvelope.releaseStartTimeSamples=A.volumeEnvelope.currentSampleTime,A.volumeEnvelope.currentReleaseGain=JA(A.volumeEnvelope.currentAttenuationDb),t.recalculate(A)}static recalculate(A){let e=A.volumeEnvelope,n=B=>Math.max(0,Math.floor(KA(B)*e.sampleRate));e.attenuationTarget=Math.max(0,Math.min(A.modulatedGenerators[r.initialAttenuation],1440))/10,e.attenuationTargetGain=JA(e.attenuationTarget),e.sustainDbRelative=Math.min(LA,A.modulatedGenerators[r.sustainVolEnv]/10);let s=Math.min(LA,e.sustainDbRelative);e.attackDuration=n(A.modulatedGenerators[r.attackVolEnv]);let o=A.modulatedGenerators[r.decayVolEnv],i=(60-A.targetKey)*A.modulatedGenerators[r.keyNumToVolEnvDecay],a=s/LA;e.decayDuration=n(o+i)*a,e.releaseDuration=n(A.modulatedGenerators[r.releaseVolEnv]),e.delayEnd=n(A.modulatedGenerators[r.delayVolEnv]),e.attackEnd=e.attackDuration+e.delayEnd;let C=(60-A.targetKey)*A.modulatedGenerators[r.keyNumToVolEnvHold];if(e.holdEnd=n(A.modulatedGenerators[r.holdVolEnv]+C)+e.attackEnd,e.decayEnd=e.decayDuration+e.holdEnd,e.state===0&&e.attackEnd===0&&(e.state=2),A.isInRelease){let B=Math.max(0,Math.min(LA,e.sustainDbRelative)),d=B/LA;switch(e.decayDuration=n(o+i)*d,e.state){case 0:e.releaseStartDb=LA;break;case 1:let l=1-(e.attackEnd-e.releaseStartTimeSamples)/e.attackDuration;e.releaseStartDb=20*Math.log10(l)*-1;break;case 2:e.releaseStartDb=0;break;case 3:e.releaseStartDb=(1-(e.decayEnd-e.releaseStartTimeSamples)/e.decayDuration)*B;break;case 4:e.releaseStartDb=B;break}e.releaseStartDb=Math.max(0,Math.min(e.releaseStartDb,LA)),e.releaseStartDb>=_t&&(A.finished=!0),e.currentReleaseGain=JA(e.releaseStartDb);let Q=(LA-e.releaseStartDb)/LA;e.releaseDuration*=Q}}static apply(A,e,n,s){let o=A.volumeEnvelope,i=n/10,a=s;if(A.isInRelease){let B=o.currentSampleTime-o.releaseStartTimeSamples;if(B>=o.releaseDuration){for(let Q=0;Q=e.length)return;o.state++;case 1:for(;o.currentSampleTime=e.length)return}o.state++;case 2:for(;o.currentSampleTime=e.length)return;o.state++;case 3:for(;o.currentSampleTime=e.length)return;o.state++;case 4:for(o.canEndOnSilentSustain&&o.sustainDbRelative>=_t&&(A.finished=!0);;)if(o.attenuation+=(o.attenuationTargetGain-o.attenuation)*a,e[C]*=o.attenuation*JA(o.sustainDbRelative+i),o.currentAttenuationDb=o.sustainDbRelative,o.currentSampleTime++,++C>=e.length)return}}};var we=class t{a0=0;a1=0;a2=0;a3=0;a4=0;x1=0;x2=0;y1=0;y2=0;reasonanceCb=0;reasonanceGain=1;cutoffCents=13501;cutoffHz=20001;static apply(A,e,n,s){if(s&&n>13499&&A.filter.reasonanceCb===0)return;let o=A.filter;(o.cutoffCents!==n||o.reasonanceCb!==A.modulatedGenerators[r.initialFilterQ])&&(o.cutoffCents=n,o.reasonanceCb=A.modulatedGenerators[r.initialFilterQ],t.calculateCoefficients(o));for(let i=0;i=A.releaseStartTime&&(A.isInRelease=!0,qA.startRelease(A),PA.startRelease(A),A.sample.loopingMode===3&&(A.sample.isLooping=!1)),A.modulatedGenerators[r.initialAttenuation]>2500){A.isInRelease&&(A.finished=!0);return}let i=A.targetKey,a=A.modulatedGenerators[r.fineTune]+t.customControllers[hA.channelTuning]+t.customControllers[hA.channelTransposeFine]+t.customControllers[hA.masterTuning]+t.channelOctaveTuning[A.midiNote%12]+t.keyCentTuning[A.midiNote],C=A.modulatedGenerators[r.coarseTune]+t.customControllers[hA.channelTuningSemitones],B=this.tunings[t.preset.program]?.[A.realKey];B?.midiNote>=0&&(i=B.midiNote,a+=B.centTuning),a+=(i-A.sample.rootKey)*A.modulatedGenerators[r.scaleTuning];let d=A.modulatedGenerators[r.vibLfoToPitch];if(d!==0){let I=A.startTime+KA(A.modulatedGenerators[r.delayVibLFO]),rA=Ue(A.modulatedGenerators[r.freqVibLFO]),Z=at(I,rA,currentTime);a+=Z*(d*t.customControllers[hA.modulationMultiplier])}let Q=A.modulatedGenerators[r.initialFilterFc],l=Q,c=A.modulatedGenerators[r.modLfoToPitch],f=A.modulatedGenerators[r.modLfoToVolume],y=A.modulatedGenerators[r.modLfoToFilterFc],S=0;if(c+y+f!==0){let I=A.startTime+KA(A.modulatedGenerators[r.delayModLFO]),rA=Ue(A.modulatedGenerators[r.freqModLFO]),Z=at(I,rA,currentTime);a+=Z*(c*t.customControllers[hA.modulationMultiplier]),S=-Z*f,l+=Z*y}if(t.channelVibrato.depth>0){let I=at(A.startTime+t.channelVibrato.delay,t.channelVibrato.rate,currentTime);I&&(a+=I*t.channelVibrato.depth)}let w=A.modulatedGenerators[r.modEnvToPitch],H=A.modulatedGenerators[r.modEnvToFilterFc],R=PA.getValue(A,currentTime);l+=R*H,a+=R*w;let x=~~(a+C*100);x!==A.currentTuningCents&&(A.currentTuningCents=x,A.currentTuningCalculated=Math.pow(2,x/1200));let G=new Float32Array(e.length);switch(this.interpolationType){case ke.linear:default:Es(A,G);break;case ke.nearestNeighbor:Cs(A,G);break;case ke.fourthOrder:Bs(A,G)}we.apply(A,G,l,Q>13499),qA.apply(A,G,S,this.volumeEnvelopeSmoothingFactor),this.panVoice(A,G,e,n,s,o)}function Qr(t,A){let e=0;return t.drumChannel&&(e+=5),A.isInRelease&&(e-=5),e+=A.velocity/25,e-=A.volumeEnvelope.state,A.isInRelease&&(e-=5),e-=A.volumeEnvelope.currentAttenuationDb/50,e}function Qs(t){let A=[];for(let n of this.workletProcessorChannels)for(let s of n.voices)if(!s.finished){let o=Qr(n,s);A.push({channel:n,voice:s,priority:o})}A.sort((n,s)=>n.priority-s.priority);let e=A.slice(0,t);for(let{channel:n,voice:s}of e){let o=n.voices.indexOf(s);o>-1&&n.voices.splice(o,1)}}function us(t,A=ds){t.releaseStartTime=currentTime,t.releaseStartTime-t.startTimems=t);var ur=function(t){var A,e,n,s,o,i,a,C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",B="",d=0;t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");do s=C.indexOf(t.charAt(d++)),o=C.indexOf(t.charAt(d++)),i=C.indexOf(t.charAt(d++)),a=C.indexOf(t.charAt(d++)),A=s<<2|o>>4,e=(15&o)<<4|i>>2,n=(3&i)<<6|a,B+=String.fromCharCode(A),i!==64&&(B+=String.fromCharCode(e)),a!==64&&(B+=String.fromCharCode(n));while(d1&&(I.thisProgram=process.argv[1].replace(/\\/g,"/")),I.arguments=process.argv.slice(2),typeof module<"u",process.on("uncaughtException",function(E){if(!(E instanceof Me))throw E}),process.on("unhandledRejection",function(E,h){process.exit(1)}),I.quit=function(E){process.exit(E)},I.inspect=function(){return"[Emscripten Module object]"}):IA?(typeof read<"u"&&(I.read=function(h){return read(h)}),I.readBinary=function(h){var u;return typeof readbuffer=="function"?new Uint8Array(readbuffer(h)):(te(typeof(u=read(h,"binary"))=="object"),u)},typeof scriptArgs<"u"?I.arguments=scriptArgs:typeof arguments<"u"&&(I.arguments=arguments),typeof quit=="function"&&(I.quit=function(E){quit(E)})):(Z||AA)&&(Z?document.currentScript&&(sA=document.currentScript.src):sA=self.location.href,sA=sA.indexOf("blob:")!==0?sA.split("/").slice(0,-1).join("/")+"/":"",I.read=function(h){var u=new XMLHttpRequest;return u.open("GET",h,!1),u.send(null),u.responseText},AA&&(I.readBinary=function(h){var u=new XMLHttpRequest;return u.open("GET",h,!1),u.responseType="arraybuffer",u.send(null),new Uint8Array(u.response)}),I.readAsync=function(h,u,m){var U=new XMLHttpRequest;U.open("GET",h,!0),U.responseType="arraybuffer",U.onload=function(){if(U.status==200||U.status==0&&U.response){u(U.response);return}m()},U.onerror=m,U.send(null)},I.setWindowTitle=function(E){document.title=E});var eA=I.print||(typeof console<"u"?console.log.bind(console):typeof print<"u"?print:null),lA=I.printErr||(typeof printErr<"u"?printErr:typeof console<"u"&&console.warn.bind(console)||eA);for(t in rA)rA.hasOwnProperty(t)&&(I[t]=rA[t]);function UA(E){var h=c;return c=c+E+15&-16,h}function an(E){var h=C[R>>2],u=h+E+15&-16;return C[R>>2]=u,u>=mA&&!un()?(C[R>>2]=h,0):h}function gn(E,h){return h||(h=16),E=Math.ceil(E/h)*h}function jo(E){switch(E){case"i1":case"i8":return 1;case"i16":return 2;case"i32":case"float":return 4;case"i64":case"double":return 8;default:if(E[E.length-1]==="*")return 4;if(E[0]!=="i")return 0;var h=parseInt(E.substr(1));return te(h%8==0),h/8}}function Fe(E){Fe.shown||(Fe.shown={}),Fe.shown[E]||(Fe.shown[E]=1,lA(E))}rA=void 0;var $o={"f64-rem":function(E,h){return E%h},debugger:function(){}},St=[];function xr(E,h){for(var u=0,m=u;m>>0)+4294967296*+(h>>>0):+(E>>>0)+4294967296*+(0|h)}function kt(E,h,u){return u&&u.length?I["dynCall_"+E].apply(null,[h].concat(u)):I["dynCall_"+E].call(null,h)}var Je=0,In=0;function te(E,h){E||jA("Assertion failed: "+h)}function En(E){var h=I["_"+E];return te(h,"Cannot call unknown function "+E+", make sure it is exported"),h}var Cn={stackSave:function(){bt()},stackRestore:function(){Nt()},arrayToC:function(E){var h,u,m=Ze(E.length);return h=E,u=m,s.set(h,u),m},stringToC:function(E){var h=0;if(E!=null&&E!==0){var u=(E.length<<2)+1;h=Ze(u),cn(E,h,u)}return h}},Ar={string:Cn.stringToC,array:Cn.arrayToC};function Bn(E,h,u,m,U){var X=En(E),j=[],Y=0;if(m)for(var pA=0;pA>0]=h;break;case"i16":i[E>>1]=h;break;case"i32":C[E>>2]=h;break;case"i64":tempI64=[h>>>0,+rr(tempDouble=h)>=1?tempDouble>0?(0|ar(+yn(tempDouble/4294967296),4294967295))>>>0:~~+ir((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0],C[E>>2]=tempI64[0],C[E+4>>2]=tempI64[1];break;case"float":d[E>>2]=h;break;case"double":Q[E>>3]=h;break;default:jA("invalid type for setValue: "+u)}}function Ur(E,h,u){switch((h=h||"i8").charAt(h.length-1)==="*"&&(h="i32"),h){case"i1":case"i8":return s[E>>0];case"i16":return i[E>>1];case"i32":case"i64":return C[E>>2];case"float":return d[E>>2];case"double":return Q[E>>3];default:jA("invalid type for getValue: "+h)}return null}function Tr(E,h,u,m){typeof E=="number"?(X=!0,j=E):(X=!1,j=E.length);var U=typeof h=="string"?h:null;if(Y=u==4?m:[typeof Ke=="function"?Ke:UA,Ze,UA,an][u===void 0?2:u](Math.max(j,U?1:h.length)),X){for(m=Y,te((3&Y)==0),pA=Y+(-4&j);m>2]=0;for(pA=Y+j;m>0]=0;return Y}if(U==="i8")return E.subarray||E.slice?o.set(E,Y):o.set(new Uint8Array(E),Y),Y;for(var X,j,Y,pA,EA,CA,aA,W=0;W>0],(m!=0||h)&&(j++,!h||j!=h););h||(h=j);var Y="";if(X<128){for(;h>0;)U=String.fromCharCode.apply(String,o.subarray(E,E+Math.min(h,1024))),Y=Y?Y+U:U,E+=1024,h-=1024;return Y}return u=E,function(EA,CA){for(var aA=CA;EA[aA];)++aA;if(aA-CA>16&&EA.subarray&&hn)return hn.decode(EA.subarray(CA,aA));for(var W,RA,TA,vA,HA,Ee,YA="";;){if(!(W=EA[CA++]))return YA;if(!(128&W)){YA+=String.fromCharCode(W);continue}if(RA=63&EA[CA++],(224&W)==192){YA+=String.fromCharCode((31&W)<<6|RA);continue}if(TA=63&EA[CA++],(240&W)==224?W=(15&W)<<12|RA<<6|TA:(vA=63&EA[CA++],(248&W)==240?W=(7&W)<<18|RA<<12|TA<<6|vA:(HA=63&EA[CA++],W=(252&W)==248?(3&W)<<24|RA<<18|TA<<12|vA<<6|HA:(1&W)<<30|RA<<24|TA<<18|vA<<12|HA<<6|(Ee=63&EA[CA++]))),W<65536)YA+=String.fromCharCode(W);else{var xe=W-65536;YA+=String.fromCharCode(55296|xe>>10,56320|1023&xe)}}}(o,u)}function Hr(E){for(var h="";;){var u=s[E++>>0];if(!u)return h;h+=String.fromCharCode(u)}}function Yr(E,h){return function(m,U,X){for(var j=0;j>0]=m.charCodeAt(j);X||(s[U>>0]=0)}(E,h,!1)}var hn=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0;function qe(E,h,u,m){if(!(m>0))return 0;for(var U=u,X=u+m-1,j=0;j=55296&&Y<=57343&&(Y=65536+((1023&Y)<<10)|1023&E.charCodeAt(++j)),Y<=127){if(u>=X)break;h[u++]=Y}else if(Y<=2047){if(u+1>=X)break;h[u++]=192|Y>>6,h[u++]=128|63&Y}else if(Y<=65535){if(u+2>=X)break;h[u++]=224|Y>>12,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}else if(Y<=2097151){if(u+3>=X)break;h[u++]=240|Y>>18,h[u++]=128|Y>>12&63,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}else if(Y<=67108863){if(u+4>=X)break;h[u++]=248|Y>>24,h[u++]=128|Y>>18&63,h[u++]=128|Y>>12&63,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}else{if(u+5>=X)break;h[u++]=252|Y>>30,h[u++]=128|Y>>24&63,h[u++]=128|Y>>18&63,h[u++]=128|Y>>12&63,h[u++]=128|Y>>6&63,h[u++]=128|63&Y}}return h[u]=0,u-U}function cn(E,h,u){return qe(E,o,h,u)}function Ve(E){for(var h=0,u=0;u=55296&&m<=57343&&(m=65536+((1023&m)<<10)|1023&E.charCodeAt(++u)),m<=127?++h:m<=2047?h+=2:m<=65535?h+=3:m<=2097151?h+=4:m<=67108863?h+=5:h+=6}return h}var ln=typeof TextDecoder<"u"?new TextDecoder("utf-16le"):void 0;function Jr(E){for(var h=E,u=h>>1;i[u];)++u;if((h=u<<1)-E>32&&ln)return ln.decode(o.subarray(E,h));for(var m=0,U="";;){var X=i[E+2*m>>1];if(X==0)return U;++m,U+=String.fromCharCode(X)}}function Pr(E,h,u){if(u===void 0&&(u=2147483647),u<2)return 0;for(var m=h,U=(u-=2)<2*E.length?u/2:E.length,X=0;X>1]=j,h+=2}return i[h>>1]=0,h-m}function qr(E){return 2*E.length}function Vr(E){for(var h=0,u="";;){var m=C[E+4*h>>2];if(m==0)return u;if(++h,m>=65536){var U=m-65536;u+=String.fromCharCode(55296|U>>10,56320|1023&U)}else u+=String.fromCharCode(m)}}function Or(E,h,u){if(u===void 0&&(u=2147483647),u<4)return 0;for(var m=h,U=m+u-4,X=0;X=55296&&j<=57343&&(j=65536+((1023&j)<<10)|1023&E.charCodeAt(++X)),C[h>>2]=j,(h+=4)+4>U)break}return C[h>>2]=0,h-m}function Kr(E){for(var h=0,u=0;u=55296&&m<=57343&&++u,h+=4}return h}function Zr(E){var h=Ve(E)+1,u=Ke(h);return u&&qe(E,s,u,h),u}function Wr(E){var h=Ve(E)+1,u=Ze(h);return qe(E,s,u,h),u}function Xr(E){return E}function _r(){var E,h=function(){var m=Error();if(!m.stack){try{throw Error(0)}catch(U){m=U}if(!m.stack)return"(no stack trace available)"}return m.stack.toString()}();return I.extraStackTrace&&(h+=` +`+I.extraStackTrace()),(E=h).replace(/__Z[\w\d_]+/g,function(u){var m,U=m=u;return u===U?u:u+" ["+U+"]"})}function wt(E,h){return E%h>0&&(E+=h-E%h),E}function Qn(E){I.buffer=n=E}function Ft(){I.HEAP8=s=new Int8Array(n),I.HEAP16=i=new Int16Array(n),I.HEAP32=C=new Int32Array(n),I.HEAPU8=o=new Uint8Array(n),I.HEAPU16=a=new Uint16Array(n),I.HEAPU32=B=new Uint32Array(n),I.HEAPF32=d=new Float32Array(n),I.HEAPF64=Q=new Float64Array(n)}function un(){var E=I.usingWasm?65536:16777216,h=2147483648-E;if(C[R>>2]>h)return!1;var u=mA;for(mA=Math.max(mA,16777216);mA>2];)mA=mA<=536870912?wt(2*mA,E):Math.min(wt((3*mA+2147483648)/4,E),h);var m=I.reallocBuffer(mA);return m&&m.byteLength==mA?(Qn(m),Ft(),!0):(mA=u,!1)}l=c=y=S=w=H=R=0,f=!1,I.reallocBuffer||(I.reallocBuffer=function(E){try{if(ArrayBuffer.transfer)h=ArrayBuffer.transfer(n,E);else{var h,u=s;h=new ArrayBuffer(E),new Int8Array(h).set(u)}}catch{return!1}return!!gr(h)&&h});try{(x=Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get))(new ArrayBuffer(4))}catch{x=function(h){return h.byteLength}}var Rt=I.TOTAL_STACK||5242880,mA=I.TOTAL_MEMORY||16777216;function tr(){return mA}function Re(E){for(;E.length>0;){var h=E.shift();if(typeof h=="function"){h();continue}var u=h.func;typeof u=="number"?h.arg===void 0?I.dynCall_v(u):I.dynCall_vi(u,h.arg):u(h.arg===void 0?null:h.arg)}}mA=0?E:h<=32?2*Math.abs(1<=m&&(h<=32||E>m)&&(E=-2*m+E),E}var rr=Math.abs,ir=Math.ceil,yn=Math.floor,ar=Math.min,Ie=0,xt=null,Ge=null;function ni(E){return E}I.preloadedImages={},I.preloadedAudios={};var Sn="data:application/octet-stream;base64,";function Oe(E){return String.prototype.startsWith?E.startsWith(Sn):E.indexOf(Sn)===0}(function(){var h="main.wast",u="main.wasm",m="main.temp.asm.js";Oe(h)||(h=iA(h)),Oe(u)||(u=iA(u)),Oe(m)||(m=iA(m));var U={global:null,env:null,asm2wasm:$o,parent:I},X=null;function j(aA){return aA}function Y(){try{if(I.wasmBinary)return new Uint8Array(I.wasmBinary);if(I.readBinary)return I.readBinary(u);throw"both async and sync fetching of the wasm failed"}catch(aA){jA(aA)}}I.asmPreload=I.asm;var pA=I.reallocBuffer,EA=function(aA){aA=wt(aA,I.usingWasm?65536:16777216);var W=I.buffer.byteLength;if(I.usingWasm)try{var RA=I.wasmMemory.grow((aA-W)/65536);return RA!==-1?I.buffer=I.wasmMemory.buffer:null}catch{return null}};I.reallocBuffer=function(aA){return CA==="asmjs"?pA(aA):EA(aA)};var CA="";I.asm=function(aA,W,RA){var TA;if(!(W=TA=W).table){var vA,HA=I.wasmTableSize;HA===void 0&&(HA=1024);var Ee=I.wasmMaxTableSize;typeof WebAssembly=="object"&&typeof WebAssembly.Table=="function"?Ee!==void 0?W.table=new WebAssembly.Table({initial:HA,maximum:Ee,element:"anyfunc"}):W.table=new WebAssembly.Table({initial:HA,element:"anyfunc"}):W.table=Array(HA),I.wasmTable=W.table}return W.memoryBase||(W.memoryBase=I.STATIC_BASE),W.tableBase||(W.tableBase=0),vA=function(xe,ue,Ut){if(typeof WebAssembly!="object")return lA("no native wasm support detected"),!1;if(!(I.wasmMemory instanceof WebAssembly.Memory))return lA("no native wasm Memory in use"),!1;function We(ZA,WA){if((X=ZA.exports).memory){var Ne,Tt,wn;Ne=X.memory,Tt=I.buffer,Ne.byteLength0?u:Ve(E)+1,U=Array(m),X=qe(E,U,0,U.length);return h&&(U.length=X),U}function ii(E){for(var h=[],u=0;u255&&(m&=255),h.push(String.fromCharCode(m))}return h.join("")}c+=16,R=UA(4),w=(y=S=gn(c))+Rt,H=gn(w),C[R>>2]=H,f=!0,I.wasmTableSize=4,I.wasmMaxTableSize=4,I.asmGlobalArg={},I.asmLibraryArg={abort:jA,assert:te,enlargeMemory:un,getTotalMemory:tr,abortOnCannotGrowMemory:function(){jA("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+mA+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")},invoke_iii:function(h,u,m){var U=bt();try{return I.dynCall_iii(h,u,m)}catch(X){if(Nt(U),typeof X!="number"&&X!=="longjmp")throw X;I.setThrew(1,0)}},___assert_fail:function(h,u,m,U){jA("Assertion failed: "+Pe(h)+", at: "+[u?Pe(u):"unknown filename",m,U?Pe(U):"unknown function"])},___setErrNo:function(h){return I.___errno_location&&(C[I.___errno_location()>>2]=h),h},_abort:function(){I.abort()},_emscripten_memcpy_big:function(h,u,m){return o.set(o.subarray(u,u+m),h),h},_llvm_floor_f64:yn,DYNAMICTOP_PTR:R,tempDoublePtr:xA,ABORT:Je,STACKTOP:S,STACK_MAX:w};var Dn=I.asm(I.asmGlobalArg,I.asmLibraryArg,n);I.asm=Dn,I.___errno_location=function(){return I.asm.___errno_location.apply(null,arguments)};var gr=I._emscripten_replace_memory=function(){return I.asm._emscripten_replace_memory.apply(null,arguments)};I._free=function(){return I.asm._free.apply(null,arguments)};var Ke=I._malloc=function(){return I.asm._malloc.apply(null,arguments)};I._memcpy=function(){return I.asm._memcpy.apply(null,arguments)},I._memset=function(){return I.asm._memset.apply(null,arguments)},I._sbrk=function(){return I.asm._sbrk.apply(null,arguments)},I._stb_vorbis_js_channels=function(){return I.asm._stb_vorbis_js_channels.apply(null,arguments)},I._stb_vorbis_js_close=function(){return I.asm._stb_vorbis_js_close.apply(null,arguments)},I._stb_vorbis_js_decode=function(){return I.asm._stb_vorbis_js_decode.apply(null,arguments)},I._stb_vorbis_js_open=function(){return I.asm._stb_vorbis_js_open.apply(null,arguments)},I._stb_vorbis_js_sample_rate=function(){return I.asm._stb_vorbis_js_sample_rate.apply(null,arguments)},I.establishStackSpace=function(){return I.asm.establishStackSpace.apply(null,arguments)},I.getTempRet0=function(){return I.asm.getTempRet0.apply(null,arguments)},I.runPostSets=function(){return I.asm.runPostSets.apply(null,arguments)},I.setTempRet0=function(){return I.asm.setTempRet0.apply(null,arguments)},I.setThrew=function(){return I.asm.setThrew.apply(null,arguments)};var Ze=I.stackAlloc=function(){return I.asm.stackAlloc.apply(null,arguments)},Nt=I.stackRestore=function(){return I.asm.stackRestore.apply(null,arguments)},bt=I.stackSave=function(){return I.asm.stackSave.apply(null,arguments)};function Me(E){this.name="ExitStatus",this.message="Program terminated with exit("+E+")",this.status=E}function Lt(E){E=E||I.arguments,!(Ie>0)&&(function(){if(I.preRun)for(typeof I.preRun=="function"&&(I.preRun=[I.preRun]);I.preRun.length;)sr(I.preRun.shift());Re(dn)}(),!(Ie>0)&&(I.calledRun||(I.setStatus?(I.setStatus("Running..."),setTimeout(function(){setTimeout(function(){I.setStatus("")},1),h()},1)):h())));function h(){!I.calledRun&&(I.calledRun=!0,Je||(Mt||(Mt=!0,Re(Gt)),Re(fn),I.onRuntimeInitialized&&I.onRuntimeInitialized(),function(){if(I.postRun)for(typeof I.postRun=="function"&&(I.postRun=[I.postRun]);I.postRun.length;)or(I.postRun.shift());Re(pn)}()))}}function ai(E,h){(!h||!I.noExitRuntime||E!==0)&&(I.noExitRuntime||(Je=!0,In=E,S=G,Re(mn),nr=!0,I.onExit&&I.onExit(E)),I.quit(E,new Me(E)))}function jA(E){throw I.onAbort&&I.onAbort(E),E!==void 0?(eA(E),lA(E),E=JSON.stringify(E)):E="",Je=!0,In=1,"abort("+E+"). Build with -s ASSERTIONS=1 for more info."}if(I.dynCall_iii=function(){return I.asm.dynCall_iii.apply(null,arguments)},I.asm=Dn,I.ccall=Bn,I.cwrap=function(h,u,m,U){var X=(m=m||[]).every(function(j){return j==="number"});return u!=="string"&&X&&!U?En(h):function(){return Bn(h,u,m,arguments,U)}},Me.prototype=Error(),Me.prototype.constructor=Me,Ge=function E(){I.calledRun||Lt(),I.calledRun||(Ge=E)},I.run=Lt,I.abort=jA,I.preInit)for(typeof I.preInit=="function"&&(I.preInit=[I.preInit]);I.preInit.length>0;)I.preInit.pop()();I.noExitRuntime=!0,Lt(),I.onRuntimeInitialized=()=>{fs=!0,ms()},zA.decode=function(E){return function(u){if(!fs)throw Error("Not initialized");var m={};function U(ue){return new Int32Array(I.HEAPU8.buffer,ue,1)[0]}function X(ue,Ut){var We=new ArrayBuffer(Ut*Float32Array.BYTES_PER_ELEMENT),de=new Float32Array(We);return de.set(new Float32Array(I.HEAPU8.buffer,ue,Ut)),de}m.open=I.cwrap("stb_vorbis_js_open","number",[]),m.close=I.cwrap("stb_vorbis_js_close","void",["number"]),m.channels=I.cwrap("stb_vorbis_js_channels","number",["number"]),m.sampleRate=I.cwrap("stb_vorbis_js_sample_rate","number",["number"]),m.decode=I.cwrap("stb_vorbis_js_decode","number",["number","number","number","number","number"]);var j,Y,pA,EA,CA=m.open(),aA=(j=u,Y=u.byteLength,pA=I._malloc(Y),(EA=new Uint8Array(I.HEAPU8.buffer,pA,Y)).set(new Uint8Array(j,0,Y)),EA),W=I._malloc(4),RA=I._malloc(4),TA=m.decode(CA,aA.byteOffset,aA.byteLength,W,RA);if(I._free(aA.byteOffset),TA<0)throw m.close(CA),I._free(W),Error("stbvorbis decode failed: "+TA);for(var vA=m.channels(CA),HA=Array(vA),Ee=new Int32Array(I.HEAPU32.buffer,U(W),vA),YA=0;YA=0&&(n=this.workletProcessorChannels[e]),t.messageType){case nA.noteOn:this.noteOn(e,A[0],A[1],A[2]);break;case nA.noteOff:this.noteOff(e,A);break;case nA.pitchWheel:this.pitchWheel(e,A[0],A[1]);break;case nA.ccChange:this.controllerChange(e,A[0],A[1],A[2]);break;case nA.customcCcChange:n.customControllers[A[0]]=A[1];break;case nA.killNote:this.killNote(e,A);break;case nA.programChange:this.programChange(e,A[0],A[1]);break;case nA.channelPressure:this.channelPressure(e,A);break;case nA.polyPressure:this.polyPressure(e,A[0],A[1]);break;case nA.ccReset:e===VA?this.resetAllControllers():this.resetControllers(e);break;case nA.systemExclusive:this.systemExclusive(A);break;case nA.setChannelVibrato:if(e===VA)for(let i=0;i{let e=(A.midiControllers[dA+q.pitchWheelRange]>>7)+(A.midiControllers[dA+q.pitchWheelRange]&127)/127;return{voicesAmount:A.voices.length,pitchBend:A.midiControllers[dA+q.pitchWheel],pitchBendRangeSemitones:e,isMuted:A.isMuted,isDrum:A.drumChannel}});this.post({messageType:DA.channelProperties,messageData:t})}function dr(t,A,e){let n=t,s=A<<7|e;return t===127&&A===127&&e===127?{midiNote:-1,centTuning:null}:{midiNote:n,centTuning:s*.0061}}function Ds(t,A=0){let e=t[0];if(!(this.deviceID!==VA&&t[1]!==127&&this.deviceID!==t[1]))switch(e){default:T(`%cUnrecognized SysEx: %c${SA(t)}`,g.warn,g.unrecognized);break;case 126:case 127:switch(t[2]){case 4:let s;switch(t[3]){case 1:let o=t[5]<<7|t[4];this.setMIDIVolume(o/16384),p(`%cMaster Volume. Volume: %c${o}`,g.info,g.value);break;case 2:let a=((t[5]<<7|t[4])-8192)/8192;this.setMasterPan(a),p(`%cMaster Pan. Pan: %c${a}`,g.info,g.value);break;case 3:let C=(t[5]<<7|t[6])-8192;s=Math.floor(C/81.92),this.setMasterTuning(s),p(`%cMaster Fine Tuning. Cents: %c${s}`,g.info,g.value);break;case 4:s=(t[5]-64)*100,this.setMasterTuning(s),p(`%cMaster Coarse Tuning. Cents: %c${s}`,g.info,g.value);break;default:T(`%cUnrecognized MIDI Device Control Real-time message: %c${SA(t)}`,g.warn,g.unrecognized)}break;case 9:t[3]===1?(p("%cGM system on",g.info),this.system="gm"):t[3]===3?(p("%cGM2 system on",g.info),this.system="gm2"):(p("%cGM system off, defaulting to GS",g.info),this.system="gs");break;case 8:switch(t[3]){case 2:case 7:let o=4;t[3]===7&&o++;let i=t[o++],a=t[o++];for(let B=0;B>1&1)===1&&this.setOctaveTuning(15+A,C);for(let B=0;B<7;B++)(t[5]>>B&1)===1&&this.setOctaveTuning(7+B+A,C);for(let B=0;B<7;B++)(t[6]>>B&1)===1&&this.setOctaveTuning(B+A,C);p(`%cMIDI Octave Scale ${t[3]===8?"(1 byte)":"(2 bytes)"} tuning via Tuning: %c${C.join(" ")}`,g.info,g.value);break;default:T(`%cUnrecognized MIDI Tuning standard message: %c${SA(t)}`,g.warn,g.unrecognized);break}break;default:T(`%cUnrecognized MIDI Realtime/non realtime message: %c${SA(t)}`,g.warn,g.unrecognized)}break;case 65:let n=function(){T(`%cUnrecognized Roland %cGS %cSysEx: %c${SA(t)}`,g.warn,g.recognized,g.warn,g.unrecognized)};if(t[2]===66&&t[3]===18){let s=t[7];if(t[6]===127){s===0?(p("%cGS Reset received!",g.info),this.resetAllControllers(!1),this.system="gs"):s===127&&(p("%cGS system off, switching to GM2",g.info),this.resetAllControllers(!1),this.system="gm2");return}else if(t[4]===64){if((t[5]&16)>0){let o=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][t[5]&15]+A;switch(t[6]){default:n();break;case 21:let i=s>0&&t[5]>>4;this.setDrums(o,i),p(`%cChannel %c${o}%c ${i?"is now a drum channel":"now isn't a drum channel"}%c via: %c${SA(t)}`,g.info,g.value,g.recognized,g.info,g.value);return;case 22:let a=s-64;this.transposeChannel(o,a),p(`%cChannel %c${o}%c pitch shift. Semitones %c${a}%c, with %c${SA(t)}`,g.info,g.recognized,g.info,g.value,g.info,g.value);return;case 28:let C=s;C===0&&(C=Math.floor(Math.random()*128)),this.controllerChange(o,k.pan,C);break;case 33:this.controllerChange(o,k.chorusDepth,s);break;case 34:this.controllerChange(o,k.reverbDepth,s);break;case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:let B=t.length-9,d=new Int8Array(12);for(let l=0;l=this.workletProcessorChannels.length)return;let o=t[6];switch(t[5]){case 1:this.controllerChange(s,k.bankSelect,o);break;case 2:this.controllerChange(s,k.lsbForControl0BankSelect,o);break;case 3:this.programChange(s,o);break;case 8:let i=this.workletProcessorChannels[s];if(i.drumChannel)return;let a=o-64;i.channelTransposeKeyShift=a;break;case 11:this.controllerChange(s,k.mainVolume,o);break;case 14:let C=o;C===0&&(C=Math.floor(Math.random()*127)),this.controllerChange(s,k.pan,C);break;case 19:this.controllerChange(s,k.reverbDepth,o);break;case 18:this.controllerChange(s,k.chorusDepth,o);break;default:T(`%cUnrecognized Yamaha XG Part Setup: %c${t[5].toString(16).toUpperCase()}`,g.warn,g.unrecognized)}}else this.system==="xg"&&T(`%cUnrecognized Yamaha XG SysEx: %c${SA(t)}`,g.warn,g.unrecognized);else this.system==="xg"&&T(`%cUnrecognized Yamaha SysEx: %c${SA(t)}`,g.warn,g.unrecognized);break}}var fr=1e3/200;function ks(t,A,e){if(A.transformAmount===0)return A.currentValue=0,0;let n;if(A.sourceUsesCC)n=t[A.sourceIndex];else{let B=A.sourceIndex+dA;switch(A.sourceIndex){case q.noController:n=16383;break;case q.noteOnKeyNum:n=e.midiNote<<7;break;case q.noteOnVelocity:n=e.velocity<<7;break;case q.polyPressure:n=e.pressure<<7;break;default:n=t[B];break}}let s=Qe[A.sourceCurveType][A.sourcePolarity][A.sourceDirection][n],o;if(A.secSrcUsesCC)o=t[A.secSrcIndex];else{let B=A.secSrcIndex+dA;switch(A.secSrcIndex){case q.noController:o=16383;break;case q.noteOnKeyNum:o=e.midiNote<<7;break;case q.noteOnVelocity:o=e.velocity<<7;break;case q.polyPressure:o=e.pressure<<7;break;default:o=t[B]}}let i=Qe[A.secSrcCurveType][A.secSrcPolarity][A.secSrcDirection][o],a=A.transformAmount;A.isEffectModulator&&a<=1e3&&(a*=fr,a=Math.min(a,1e3));let C=s*i*a;return A.transformType===2&&(C=Math.abs(C)),A.currentValue=C,C}function Ae(t,A,e=-1,n=0){let s=t.modulators,o=t.generators,i=t.modulatedGenerators;if(e===-1){i.set(o),s.forEach(B=>{let d=J[B.modulatorDestination],Q=i[B.modulatorDestination]+ks(A,B,t);i[B.modulatorDestination]=Math.max(d.min,Math.min(Q,d.max))}),qA.recalculate(t),PA.recalculate(t);return}let a=new Set([r.initialAttenuation,r.delayVolEnv,r.attackVolEnv,r.holdVolEnv,r.decayVolEnv,r.sustainVolEnv,r.releaseVolEnv,r.keyNumToVolEnvHold,r.keyNumToVolEnvDecay]),C=new Set;s.forEach(B=>{if(B.sourceUsesCC===e&&B.sourceIndex===n||B.secSrcUsesCC===e&&B.secSrcIndex===n){let d=B.modulatorDestination;C.has(d)||(i[d]=o[d],ks(A,B,t),s.forEach(Q=>{if(Q.modulatorDestination===d){let l=J[B.modulatorDestination],c=i[B.modulatorDestination]+Q.currentValue;i[B.modulatorDestination]=Math.max(l.min,Math.min(c,l.max))}}),C.add(d))}}),[...C].some(B=>a.has(B))&&qA.recalculate(t),PA.recalculate(t)}var Qe=[];for(let t=0;t<4;t++){Qe[t]=[[new Float32Array(fA),new Float32Array(fA)],[new Float32Array(fA),new Float32Array(fA)]];for(let A=0;A200&&e<40||this.highPerformanceMode&&e<10||i.isMuted)return;let a=A+i.channelTransposeKeyShift,C=a;if(A>127||A<0)return;let B=i.preset.program;this.tunings[B]?.[A]?.midiNote>=0&&(C=this.tunings[B]?.[A].midiNote),i.velocityOverride>0&&(e=i.velocityOverride);let d=this.keyModifierManager.getVelocity(t,A);d>-1&&(e=d);let Q=this.getWorkletVoices(t,C,e,i,o,a,n),l=i.voices;Q.forEach(c=>{let f=c.generators[r.exclusiveClass];f!==0&&l.forEach(G=>{G.generators[r.exclusiveClass]===f&&(this.releaseVoice(G,Fs),G.modulatedGenerators[r.releaseVolEnv]=-7e3,G.modulatedGenerators[r.releaseModEnv]=-7e3,qA.recalculate(G),PA.recalculate(G))}),Ae(c,i.midiControllers);let y=c.modulatedGenerators[r.startAddrsOffset]+c.modulatedGenerators[r.startAddrsCoarseOffset]*32768,S=c.modulatedGenerators[r.endAddrOffset]+c.modulatedGenerators[r.endAddrsCoarseOffset]*32768,w=c.modulatedGenerators[r.startloopAddrsOffset]+c.modulatedGenerators[r.startloopAddrsCoarseOffset]*32768,H=c.modulatedGenerators[r.endloopAddrsOffset]+c.modulatedGenerators[r.endloopAddrsCoarseOffset]*32768,R=c.sample,x=G=>Math.max(0,Math.min(R.sampleData.length-1,G));if(R.cursor=x(R.cursor+y),R.end=x(R.end+S),R.loopStart=x(R.loopStart+w),R.loopEnd=x(R.loopEnd+H),R.loopEndthis.voiceCap&&this.voiceKilling(Q.length),l.push(...Q),s&&(this.sendChannelProperties(),this.callEvent("noteon",{midiNote:A,channel:t,velocity:e}))}function Rs(t,A){if(A>127||A<0){T("Received a noteOn for note",A,"Ignoring.");return}let e=A+this.workletProcessorChannels[t].channelTransposeKeyShift;if(this.highPerformanceMode&&!this.workletProcessorChannels[t].drumChannel){this.killNote(t,e);return}this.workletProcessorChannels[t].voices.forEach(s=>{s.realKey!==e||s.isInRelease===!0||(this.workletProcessorChannels[t].holdPedal?this.workletProcessorChannels[t].sustainedVoices.push(s):this.releaseVoice(s))}),this.callEvent("noteoff",{midiNote:A,channel:t})}function Gs(t,A){this.workletProcessorChannels[t].voices.forEach(e=>{e.realKey===A&&(e.modulatedGenerators[r.releaseVolEnv]=-12e3,this.releaseVoice(e))})}function Ms(t,A=!1){let e=this.workletProcessorChannels[t].voices;A?(e.length=0,this.workletProcessorChannels[t].sustainedVoices.length=0,this.sendChannelProperties()):(e.forEach(n=>{n.isInRelease||this.releaseVoice(n)}),this.workletProcessorChannels[t].sustainedVoices.forEach(n=>{this.releaseVoice(n)}))}function xs(t=!1){p("%cStop all received!",g.info);for(let A=0;AAe(s,this.workletProcessorChannels[t].midiControllers,0,q.pitchWheel)),this.sendChannelProperties()}function Ys(t,A){let e=this.workletProcessorChannels[t];e.midiControllers[dA+q.channelPressure]=A<<7,this.workletProcessorChannels[t].voices.forEach(n=>Ae(n,e.midiControllers,0,q.channelPressure)),this.callEvent("channelpressure",{channel:t,pressure:A})}function Js(t,A,e){this.workletProcessorChannels[t].voices.forEach(n=>{n.midiNote===A&&(n.pressure=e,Ae(n,this.workletProcessorChannels[t].midiControllers,0,q.polyPressure))}),this.callEvent("polypressure",{channel:t,midiNote:A,pressure:e})}function Ps(t,A){if(A.length!==12)throw new Error("Tuning is not the length of 12.");this.workletProcessorChannels[t].channelOctaveTuning=A}function qs(t,A,e,n=!1){let s=this.workletProcessorChannels[t];if(s===void 0){T(`Trying to access channel ${t} which does not exist... ignoring!`);return}if(A>127){if(!n)return;switch(A){default:return;case qt.velocityOverride:s.velocityOverride=e}}if(A>=k.lsbForControl1ModulationWheel&&A<=k.lsbForControl13EffectControl2&&A!==k.lsbForControl6DataEntry){let o=A-32;if(s.lockedControllers[o])return;s.midiControllers[o]=s.midiControllers[o]&16256|e&127,s.voices.forEach(i=>Ae(i,s.midiControllers,1,o))}switch(A){case k.allNotesOff:this.stopAll(t);break;case k.allSoundOff:this.stopAll(t,!0);break;case k.bankSelect:let o=e;if(!n){switch(this.system){case"gm":p(`%cIgnoring the Bank Select (${e}), as the synth is in GM mode.`,g.info);return;case"xg":o===120||o===126||o===127?this.setDrums(t,!0):t%16!==GA&&this.setDrums(t,!1);break;case"gm2":o===120&&this.setDrums(t,!0)}s.drumChannel&&(o=128),o===128&&!s.drumChannel&&(o=XA(s))}ne(s,o);break;case k.lsbForControl0BankSelect:this.system==="xg"?s.drumChannel||e!==127&&ne(s,e):this.system==="gm2"&&ne(s,e);break;case k.RPNLsb:s.RPValue=s.RPValue<<7|e,s.dataEntryState=wA.RPFine;break;case k.RPNMsb:s.RPValue=e,s.dataEntryState=wA.RPCoarse;break;case k.NRPNMsb:s.NRPCoarse=e,s.dataEntryState=wA.NRPCoarse;break;case k.NRPNLsb:s.NRPFine=e,s.dataEntryState=wA.NRPFine;break;case k.dataEntryMsb:this.dataEntryCoarse(t,e);break;case k.lsbForControl6DataEntry:this.dataEntryFine(t,e);break;case k.resetAllControllers:this.resetControllers(t);break;case k.sustainPedal:e>=64?s.holdPedal=!0:(s.holdPedal=!1,s.sustainedVoices.forEach(i=>{this.releaseVoice(i)}),s.sustainedVoices=[]);break;default:if(s.lockedControllers[A])return;s.midiControllers[A]=e<<7,s.voices.forEach(i=>Ae(i,s.midiControllers,1,A));break}this.callEvent("controllerchange",{channel:t,controllerNumber:A,controllerValue:e})}function Vs(t){this.midiVolume=t,this.setMasterPan(this.pan)}function Os(t){this.masterGain=t*zt,this.setMasterPan(this.pan)}function Ks(t){this.pan=t,t=t/2+.5,this.panLeft=1-t,this.panRight=t}function Zs(t,A){A&&this.stopAll(t,!0),this.workletProcessorChannels[t].isMuted=A,this.sendChannelProperties(),this.callEvent("mutechannel",{channel:t,isMuted:A})}function Ws(t){this.workletProcessorChannels[t].lockGSNRPNParams=!0,this.workletProcessorChannels[t].channelVibrato.rate=0,this.workletProcessorChannels[t].channelVibrato.delay=0,this.workletProcessorChannels[t].channelVibrato.depth=0}function Xs(t,A,e,n){this.workletProcessorChannels[t].lockGSNRPNParams||(this.workletProcessorChannels[t].channelVibrato.rate=e,this.workletProcessorChannels[t].channelVibrato.delay=n,this.workletProcessorChannels[t].channelVibrato.depth=A)}function _s(t,A){let e=this.workletProcessorChannels[t],n=()=>{e.channelVibrato.delay===0&&e.channelVibrato.rate===0&&e.channelVibrato.depth===0&&(e.channelVibrato.depth=50,e.channelVibrato.rate=8,e.channelVibrato.delay=.6)};switch(e.dataEntryState){default:case wA.Idle:break;case wA.NRPFine:if(this.system!=="gs"||e.lockGSNRPNParams)return;switch(e.NRPCoarse){default:if(A===64)return;T(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16).toUpperCase()} 0x${e.NRPFine.toString(16).toUpperCase()})%c data value: %c${A}`,g.warn,g.recognized,g.warn,g.unrecognized,g.warn,g.value);break;case 1:switch(e.NRPFine){default:if(A===64)return;T(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16)} 0x${e.NRPFine.toString(16)})%c data value: %c${A}`,g.warn,g.recognized,g.warn,g.unrecognized,g.warn,g.value);break;case 8:if(A===64)return;n(),e.channelVibrato.rate=A/64*8,p(`%cVibrato rate for %c${t}%c is now set to %c${A} = ${e.channelVibrato.rate}%cHz.`,g.info,g.recognized,g.info,g.value,g.info);break;case 9:if(A===64)return;n(),e.channelVibrato.depth=A/2,p(`%cVibrato depth for %c${t}%c is now set to %c${A} = ${e.channelVibrato.depth}%c cents range of detune.`,g.info,g.recognized,g.info,g.value,g.info);break;case 10:if(A===64)return;n(),e.channelVibrato.delay=A/64/3,p(`%cVibrato delay for %c${t}%c is now set to %c${A} = ${e.channelVibrato.delay}%c seconds.`,g.info,g.recognized,g.info,g.value,g.info);break;case 32:let o=A;this.controllerChange(t,k.brightness,A),p(`%cFilter cutoff for %c${t}%c is now set to %c${o}`,g.info,g.recognized,g.info,g.value)}break;case 29:let s=A;this.controllerChange(t,k.reverbDepth,s),p(`%cGS Drum reverb for %c${t}%c: %c${s}`,g.info,g.recognized,g.info,g.value);break}break;case wA.RPCoarse:case wA.RPFine:switch(e.RPValue){default:T(`%cUnrecognized RPN for %c${t}%c: %c(0x${e.RPValue.toString(16)})%c data value: %c${A}`,g.warn,g.recognized,g.warn,g.unrecognized,g.warn,g.value);break;case 0:e.midiControllers[dA+q.pitchWheelRange]=A<<7,p(`%cChannel ${t} bend range. Semitones: %c${A}`,g.info,g.value);break;case 2:this.setChannelTuningSemitones(t,A-64);break;case 1:this.setChannelTuning(t,A-64,!1);break;case 5:this.setModulationDepth(t,A*100);break;case 16383:this.resetParameters(t);break}}}function zs(t,A){let e=this.workletProcessorChannels[t];switch(e.dataEntryState){default:break;case wA.RPCoarse:case wA.RPFine:switch(e.RPValue){default:break;case 0:if(A===0)break;e.midiControllers[dA+q.pitchWheelRange]|=A;let n=(e.midiControllers[dA+q.pitchWheelRange]>>7)+A/127;p(`%cChannel ${t} bend range. Semitones: %c${n}`,g.info,g.value);break;case 1:let o=e.customControllers[hA.channelTuning]<<7|A;this.setChannelTuning(t,o*.01220703125);break;case 5:let a=e.customControllers[hA.modulationMultiplier]*50+A/128*100;this.setModulationDepth(t,a);break;case 16383:this.resetParameters(t);break}}}function js(t=!0){t&&p("%cResetting all controllers!",g.info),this.callEvent("allcontrollerreset",void 0);for(let A=0;A>7});if(this.workletProcessorChannels[A].lockedControllers[dA+q.pitchWheel]===!1){let n=this.workletProcessorChannels[A].midiControllers[dA+q.pitchWheel],s=n>>7,o=n&127;this.callEvent("pitchwheel",{channel:A,MSB:s,LSB:o})}}this.tunings=[],this.tunings=[];for(let A=0;127>A;A++)this.tunings.push([]);this.setMIDIVolume(1),this.system=et}function $s(t){let A=this.workletProcessorChannels[t],e=A.lockedControllers.reduce((s,o,i)=>(o&&s.push(i),s),[]);A.channelOctaveTuning.fill(0),A.keyCentTuning.fill(0);for(let s=0;s>7}),A.midiControllers[s]=o}A.channelVibrato={rate:0,depth:0,delay:0},A.holdPedal=!1;let n=A.customControllers[hA.channelTransposeFine];A.customControllers.set(Pt),A.customControllers[hA.channelTransposeFine]=n,this.resetParameters(t)}function Ao(t){let A=this.workletProcessorChannels[t];A.NRPCoarse=0,A.NRPFine=0,A.RPValue=0,A.dataEntryState=wA.Idle}function eo(){let t=4;for(let n of this.instruments)t+=n.instrumentZones.reduce((s,o)=>(o.generators=o.generators.filter(i=>i.generatorType!==r.sampleID&&i.generatorType!==r.keyRange&&i.generatorType!==r.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:r.velRange,generatorValue:o.velRange.max<<8|Math.max(o.velRange.min,0)}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:r.keyRange,generatorValue:o.keyRange.max<<8|Math.max(o.keyRange.min,0)}),o.isGlobal||o.generators.push({generatorType:r.sampleID,generatorValue:this.samples.indexOf(o.sample)}),o.generators.length*4+s),0);let A=new b(t),e=0;for(let n of this.instruments)for(let s of n.instrumentZones){s.generatorZoneStartIndex=e;for(let o of s.generators)L(A,o.generatorType),L(A,o.generatorValue),e++}return K(A,0),gA(new oA("igen",A.length,A))}function to(t,A,e,n,s){let o=this.samples.map((B,d)=>{e&&B.compressSample(n,s);let Q=B.getRawData();return p(`%cEncoded sample %c${d}. ${B.sampleName}%c of %c${this.samples.length}%c. Compressed: %c${B.isCompressed}%c.`,g.info,g.recognized,g.info,g.recognized,g.info,B.isCompressed?g.recognized:g.unrecognized,g.info),Q}),i=this.samples.reduce((B,d,Q)=>B+o[Q].length+46,0),a=new b(i);this.samples.forEach((B,d)=>{let Q=o[d],l,c,f=Q.length;B.isCompressed?(l=a.currentIndex,c=l+Q.length):(l=a.currentIndex/2,c=l+Q.length/2,f+=46),t.push(l),a.set(Q,a.currentIndex),a.currentIndex+=f,A.push(c)});let C=gA(new oA("smpl",a.length,a),new b([115,100,116,97]));return gA(new oA("LIST",C.length,C))}function no(t,A){let n=new b(46*(this.samples.length+1));return this.samples.forEach((s,o)=>{yA(n,s.sampleName,20);let i=t[o];K(n,i);let a=A[o];K(n,a);let C=s.sampleLoopStartIndex+i,B=s.sampleLoopEndIndex+i;s.isCompressed&&(C-=i,B-=i),K(n,C),K(n,B),K(n,s.sampleRate),n[n.currentIndex++]=s.samplePitch,n[n.currentIndex++]=s.samplePitchCorrection,L(n,s.sampleLink),L(n,s.sampleType)}),yA(n,"EOS",46),gA(new oA("shdr",n.length,n))}function so(){let t=10;for(let n of this.instruments)t+=n.instrumentZones.reduce((s,o)=>o.modulators.length*10+s,0);let A=new b(t),e=0;for(let n of this.instruments)for(let s of n.instrumentZones){s.modulatorZoneStartIndex=e;for(let o of s.modulators)L(A,o.sourceEnum),L(A,o.modulatorDestination),L(A,o.transformAmount),L(A,o.secondarySourceEnum),L(A,o.transformType),e++}return De(A,0,10),gA(new oA("imod",A.length,A))}function oo(){let t=this.instruments.reduce((o,i)=>i.instrumentZones.length*4+o,4),A=new b(t),e=0,n=0,s=0;for(let o of this.instruments){o.instrumentZoneIndex=e;for(let i of o.instrumentZones)i.zoneID=e,L(A,n),L(A,s),n+=i.generators.length,s+=i.modulators.length,e++}return L(A,n),L(A,s),gA(new oA("ibag",A.length,A))}function ro(){let t=this.instruments.length*22+22,A=new b(t),e=0,n=0;for(let s of this.instruments)yA(A,s.instrumentName,20),L(A,e),e+=s.instrumentZones.length,s.instrumentID=n,n++;return yA(A,"EOI",20),L(A,e),gA(new oA("inst",A.length,A))}function io(){let t=4;for(let n of this.presets)t+=n.presetZones.reduce((s,o)=>(o.generators=o.generators.filter(i=>i.generatorType!==r.instrument&&i.generatorType!==r.keyRange&&i.generatorType!==r.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:r.velRange,generatorValue:o.velRange.max<<8|Math.max(o.velRange.min,0)}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:r.keyRange,generatorValue:o.keyRange.max<<8|Math.max(o.keyRange.min,0)}),o.isGlobal||o.generators.push({generatorType:r.instrument,generatorValue:this.instruments.indexOf(o.instrument)}),o.generators.length*4+s),0);let A=new b(t),e=0;for(let n of this.presets)for(let s of n.presetZones){s.generatorZoneStartIndex=e;for(let o of s.generators)L(A,o.generatorType),L(A,o.generatorValue);e+=s.generators.length}return L(A,0),L(A,0),gA(new oA("pgen",A.length,A))}function ao(){let t=10;for(let n of this.presets)t+=n.presetZones.reduce((s,o)=>o.modulators.length*10+s,0);let A=new b(t),e=0;for(let n of this.presets)for(let s of n.presetZones){s.modulatorZoneStartIndex=e;for(let o of s.modulators)L(A,o.sourceEnum),L(A,o.modulatorDestination),L(A,o.transformAmount),L(A,o.secondarySourceEnum),L(A,o.transformType),e++}return De(A,0,10),gA(new oA("pmod",A.length,A))}function go(){let t=this.presets.reduce((o,i)=>i.presetZones.length*4+o,4),A=new b(t),e=0,n=0,s=0;for(let o of this.presets){o.presetZoneStartIndex=e;for(let i of o.presetZones)i.zoneID=e,L(A,n),L(A,s),n+=i.generators.length,s+=i.modulators.length,e++}return L(A,n),L(A,s),gA(new oA("pbag",A.length,A))}function Io(){let t=this.presets.length*38+38,A=new b(t),e=0;for(let n of this.presets)yA(A,n.presetName,20),L(A,n.program),L(A,n.bank),L(A,e),K(A,n.library),K(A,n.genre),K(A,n.morphology),e+=n.presetZones.length;return yA(A,"EOP",20),L(A,0),L(A,0),L(A,e),K(A,0),K(A,0),K(A,0),gA(new oA("phdr",A.length,A))}var mr={compress:!1,compressionQuality:.5,compressionFunction:void 0};function Eo(t=mr){if(t.compress&&typeof t.compressionFunction!="function")throw new TypeError("No compression function supplied but compression enabled.");QA("%cSaving soundfont...",g.info),p(`%cCompression: %c${t?.compress||"false"}%c quality: %c${t?.compressionQuality||"none"}`,g.info,g.recognized,g.info,g.recognized),p("%cWriting INFO...",g.info);let A=[];this.soundFontInfo.ISFT="SpessaSynth",t?.compress&&(this.soundFontInfo.ifil="3.0");for(let[x,G]of Object.entries(this.soundFontInfo))if(x==="ifil"||x==="iver"){let I=parseInt(G.split(".")[0]),rA=parseInt(G.split(".")[1]),Z=new b(4);L(Z,I),L(Z,rA),A.push(gA(new oA(x,4,Z)))}else if(x==="DMOD")A.push(gA(new oA(x,G.length,G)));else{let I=new b(G.length);yA(I,G),A.push(gA(new oA(x,G.length,I)))}let e=cA([new b([73,78,70,79]),...A]),n=gA(new oA("LIST",e.length,e));p("%cWriting SDTA...",g.info);let s=[],o=[],i=to.call(this,s,o,t?.compress,t?.compressionQuality??.5,t.compressionFunction);p("%cWriting PDTA...",g.info),p("%cWriting SHDR...",g.info);let a=no.call(this,s,o);p("%cWriting IGEN...",g.info);let C=eo.call(this);p("%cWriting IMOD...",g.info);let B=so.call(this);p("%cWriting IBAG...",g.info);let d=oo.call(this);p("%cWriting INST...",g.info);let Q=ro.call(this),l=io.call(this);p("%cWriting PMOD...",g.info);let c=ao.call(this);p("%cWriting PBAG...",g.info);let f=go.call(this);p("%cWriting PHDR...",g.info);let y=Io.call(this),S=cA([new b([112,100,116,97]),y,f,c,l,Q,d,B,C,a]),w=gA(new oA("LIST",S.length,S));p("%cWriting the output file...",g.info);let H=cA([new b([115,102,98,107]),n,i,w]),R=gA(new oA("RIFF",H.length,H));return p(`%cSaved succesfully! Final file size: %c${R.length}`,g.info,g.recognized),O(),R}var Te=class{velRange={min:-1,max:127};keyRange={min:-1,max:127};isGlobal=!1;generators=[];modulators=[];get hasKeyRange(){return this.keyRange.min!==-1}get hasVelRange(){return this.velRange.min!==-1}getGeneratorValue(A,e){return this.generators.find(n=>n.generatorType===A)?.generatorValue??e}};var FA=class extends Te{sample=void 0;useCount=0;deleteZone(){this.useCount--,!this.isGlobal&&this.sample.useCount--}},oe=class extends Te{instrument=void 0;deleteZone(){this.isGlobal||this.instrument.removeUseCount()}};var pr=new Set([r.velRange,r.keyRange,r.instrument,r.exclusiveClass,r.endOper,r.sampleModes,r.startloopAddrsOffset,r.startloopAddrsCoarseOffset,r.endloopAddrsOffset,r.endloopAddrsCoarseOffset,r.startAddrsOffset,r.startAddrsCoarseOffset,r.endAddrOffset,r.endAddrsCoarseOffset,r.initialAttenuation,r.fineTune,r.coarseTune,r.keyNumToVolEnvHold,r.keyNumToVolEnvDecay,r.keyNumToModEnvHold,r.keyNumToModEnvDecay]);function Co(t,A=!0){function e(Q,l){Q.push(...l.filter(c=>!Q.find(f=>f.generatorType===c.generatorType)))}function n(Q,l){return{min:Math.max(Q.min,l.min),max:Math.min(Q.max,l.max)}}function s(Q,l){Q.push(...l.filter(c=>!Q.find(f=>P.isIdentical(c,f))))}let o=[],i=[],a=[],C={min:0,max:127},B={min:0,max:127},d=t.presetZones.find(Q=>Q.isGlobal);d&&(i.push(...d.generators),a.push(...d.modulators),C=d.keyRange,B=d.velRange);for(let Q of t.presetZones){if(Q.isGlobal)continue;let l=Q.keyRange;Q.hasKeyRange||(l=C);let c=Q.velRange;Q.hasVelRange||(c=B);let f=Q.generators.map(I=>new N(I.generatorType,I.generatorValue));e(f,i);let y=[...Q.modulators];s(y,a);let S=Q.instrument.instrumentZones,w=[],H=[],R={min:0,max:127},x={min:0,max:127},G=S.find(I=>I.isGlobal);G&&(w.push(...G.generators),H.push(...G.modulators),R=G.keyRange,x=G.velRange);for(let I of S){if(I.isGlobal)continue;let rA=I.keyRange;I.hasKeyRange||(rA=R);let Z=I.velRange;if(I.hasVelRange||(Z=x),rA=n(rA,l),Z=n(Z,c),rA.maxnew N(eA.generatorType,eA.generatorValue));e(AA,w);let $=[...I.modulators];s($,H);let IA=[...$];for(let eA of y){let lA=IA.findIndex(UA=>P.isIdentical(eA,UA));lA!==-1?IA[lA]=IA[lA].sumTransform(eA):IA.push(eA)}let sA=AA.map(eA=>new N(eA.generatorType,eA.generatorValue));for(let eA of f){if(eA.generatorType===r.velRange||eA.generatorType===r.keyRange||eA.generatorType===r.instrument||eA.generatorType===r.endOper||eA.generatorType===r.sampleModes)continue;let lA=AA.findIndex(UA=>UA.generatorType===eA.generatorType);if(lA!==-1){let UA=sA[lA].generatorValue+eA.generatorValue;sA[lA]=new N(eA.generatorType,UA)}else{let UA=J[eA.generatorType].def+eA.generatorValue;sA.push(new N(eA.generatorType,UA))}}sA=sA.filter(eA=>eA.generatorType!==r.sampleID&&eA.generatorType!==r.keyRange&&eA.generatorType!==r.velRange&&eA.generatorType!==r.endOper&&eA.generatorType!==r.instrument&&eA.generatorValue!==J[eA.generatorType].def);let iA=new FA;iA.keyRange=rA,iA.velRange=Z,iA.keyRange.min===0&&iA.keyRange.max===127&&(iA.keyRange.min=-1),iA.velRange.min===0&&iA.velRange.max===127&&(iA.velRange.min=-1),iA.isGlobal=!1,iA.sample=I.sample,iA.generators=sA,iA.modulators=IA,o.push(iA)}}if(A){let Q=new FA;Q.isGlobal=!0;for(let f=0;f<58;f++){if(pr.has(f))continue;let y={},S=J[f]?.def||0;y[S]=0;for(let w of o){let H=w.generators.find(G=>G.generatorType===f);if(H){let G=H.generatorValue;y[G]===void 0?y[G]=1:y[G]++}else y[S]++;let R;switch(f){default:continue;case r.decayVolEnv:R=r.keyNumToVolEnvDecay;break;case r.holdVolEnv:R=r.keyNumToVolEnvHold;break;case r.decayModEnv:R=r.keyNumToModEnvDecay;break;case r.holdModEnv:R=r.keyNumToModEnvHold}if(w.generators.find(G=>G.generatorType===R)!==void 0){y={};break}}if(Object.keys(y).length>0){let w=Object.entries(y).reduce((R,x)=>R[1]{let x=R.generators.findIndex(G=>G.generatorType===f);x!==-1?R.generators[x].generatorValue===H&&R.generators.splice(x,1):H!==S&&R.generators.push(new N(f,S))})}}let c=o.find(f=>!f.isGlobal).modulators.map(f=>P.copy(f));for(let f of c){let y=!0;for(let S of o){if(S.isGlobal||!y)continue;S.modulators.find(H=>P.isIdentical(H,f))||(y=!1)}if(y===!0){Q.modulators.push(P.copy(f));for(let S of o){let w=S.modulators.find(H=>P.isIdentical(H,f));w.transformAmount===f.transformAmount&&S.modulators.splice(S.modulators.indexOf(w),1)}}}o.splice(0,0,Q)}return o}var Bo=20;function gt(t,A,e,n,s,o,i){let a=i===0?0:1,C=new b(Bo+a*16);K(C,Bo),L(C,A),L(C,e);let B=n*.4,d=Math.floor(B*-65536);K(C,d),K(C,2);let Q=o-s,l=0;switch(i){default:case 0:a=0;break;case 1:l=0,a=1;break;case 3:l=1,a=1}return K(C,a),a===1&&(K(C,16),K(C,l),K(C,s),K(C,Q)),tA("wsmp",C)}var v={none:0,modLfo:1,velocity:2,keyNum:3,volEnv:4,modEnv:5,pitchWheel:6,polyPressure:7,channelPressure:8,vibratoLfo:9,modulationWheel:129,volume:135,pan:138,expression:139,chorus:219,reverb:221,pitchWheelRange:256,fineTune:257,coarseTune:258},It=new P({srcEnum:219,dest:r.reverbEffectsSend,amt:1e3,secSrcEnum:0,transform:0}),Et=new P({srcEnum:221,dest:r.chorusEffectsSend,amt:1e3,secSrcEnum:0,transform:0}),Ct=new P({srcEnum:129,dest:r.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0}),Bt=new P({srcEnum:13,dest:r.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0});var D={none:0,gain:1,reserved:2,pitch:3,pan:4,keyNum:5,chorusSend:128,reverbSend:129,modLfoFreq:260,modLfoDelay:261,vibLfoFreq:276,vibLfoDelay:277,volEnvAttack:518,volEnvDecay:519,volEnvRelease:521,volEnvSustain:522,volEnvDelay:523,volEnvHold:524,modEnvAttack:778,modEnvDecay:779,modEnvRelease:781,modEnvSustain:782,modEnvDelay:783,modEnvHold:784,filterCutoff:1280,filterQ:1281};var ve=class{source;control;destination;scale;transform;constructor(A,e,n,s,o){this.source=A,this.control=e,this.destination=n,this.scale=s,this.transform=o}writeArticulator(){let A=new b(12);return L(A,this.source),L(A,this.control),L(A,this.destination),L(A,this.transform),K(A,this.scale<<16),A}};function ho(t,A){if(t)switch(A){default:return;case k.modulationWheel:return v.modulationWheel;case k.mainVolume:return v.volume;case k.pan:return v.pan;case k.expressionController:return v.expression;case k.chorusDepth:return v.chorus;case k.reverbDepth:return v.reverb}else switch(A){default:return;case q.noteOnKeyNum:return v.keyNum;case q.noteOnVelocity:return v.velocity;case q.noController:return v.none;case q.polyPressure:return v.polyPressure;case q.channelPressure:return v.channelPressure;case q.pitchWheel:return v.pitchWheel;case q.pitchWheelRange:return v.pitchWheelRange}}function co(t,A){switch(t){default:return;case r.initialAttenuation:return{dest:D.gain,amount:-A};case r.fineTune:return D.pitch;case r.pan:return D.pan;case r.keyNum:return D.keyNum;case r.reverbEffectsSend:return D.reverbSend;case r.chorusEffectsSend:return D.chorusSend;case r.freqModLFO:return D.modLfoFreq;case r.delayModLFO:return D.modLfoDelay;case r.delayVibLFO:return D.vibLfoDelay;case r.freqVibLFO:return D.vibLfoFreq;case r.delayVolEnv:return D.volEnvDelay;case r.attackVolEnv:return D.volEnvAttack;case r.holdVolEnv:return D.volEnvHold;case r.decayVolEnv:return D.volEnvDecay;case r.sustainVolEnv:return{dest:D.volEnvSustain,amount:1e3-A};case r.releaseVolEnv:return D.volEnvRelease;case r.delayModEnv:return D.modEnvDelay;case r.attackModEnv:return D.modEnvAttack;case r.holdModEnv:return D.modEnvHold;case r.decayModEnv:return D.modEnvDecay;case r.sustainModEnv:return{dest:D.modEnvSustain,amount:1e3-A};case r.releaseModEnv:return D.modEnvRelease;case r.initialFilterFc:return D.filterCutoff;case r.initialFilterQ:return D.filterQ}}function lo(t,A){switch(t){default:return;case r.modEnvToFilterFc:return{source:v.modEnv,dest:D.filterCutoff,amt:A,isBipolar:!1};case r.modEnvToPitch:return{source:v.modEnv,dest:D.pitch,amt:A,isBipolar:!1};case r.modLfoToFilterFc:return{source:v.modLfo,dest:D.filterCutoff,amt:A,isBipolar:!0};case r.modLfoToVolume:return{source:v.modLfo,dest:D.gain,amt:A,isBipolar:!0};case r.modLfoToPitch:return{source:v.modLfo,dest:D.pitch,amt:A,isBipolar:!0};case r.vibLfoToPitch:return{source:v.vibratoLfo,dest:D.pitch,amt:A,isBipolar:!0};case r.keyNumToVolEnvHold:return{source:v.keyNum,dest:D.volEnvHold,amt:A,isBipolar:!0};case r.keyNumToVolEnvDecay:return{source:v.keyNum,dest:D.volEnvDecay,amt:A,isBipolar:!0};case r.keyNumToModEnvHold:return{source:v.keyNum,dest:D.modEnvHold,amt:A,isBipolar:!0};case r.keyNumToModEnvDecay:return{source:v.keyNum,dest:D.modEnvDecay,amt:A,isBipolar:!0};case r.scaleTuning:return{source:v.keyNum,dest:D.pitch,amt:A*128,isBipolar:!1}}}function Qo(t){let A=co(t.generatorType,t.generatorValue),e=A,n=0,s=t.generatorValue;A?.amount!==void 0&&(s=A.amount,e=A.dest);let o=lo(t.generatorType,t.generatorValue);if(o!==void 0)s=o.amt,e=o.dest,n=o.source;else if(e===void 0){T(`Invalid generator type: ${t.generatorType}`);return}return new ve(n,0,e,s,0)}function uo(t){if(t.transformType!==0){T("Other transform types are not supported.");return}let A=ho(t.sourceUsesCC,t.sourceIndex),e=t.sourceCurveType,n=t.sourcePolarity,s=t.sourceDirection;if(A===void 0){T(`Invalid source: ${t.sourceIndex}, CC: ${t.sourceUsesCC}`);return}t.modulatorDestination===r.initialAttenuation&&(s=s===1?0:1);let o=ho(t.secSrcUsesCC,t.secSrcIndex),i=t.secSrcCurveType,a=t.secSrcPolarity,C=t.secSrcDirection;if(o===void 0){T(`Invalid secondary source: ${t.secSrcIndex}, CC: ${t.secSrcUsesCC}`);return}let B=co(t.modulatorDestination,t.transformAmount),d=B,Q=t.transformAmount;B?.dest!==void 0&&(d=B.dest,Q=B.amount);let l=lo(t.modulatorDestination,t.transformAmount);if(l!==void 0)Q=l.amt,o=A,i=e,a=n,C=s,e=uA.linear,n=l.isBipolar?1:0,s=0,A=l.source,d=l.dest;else if(d===void 0){T(`Invalid destination: ${t.modulatorDestination}`);return}let c=0;return c|=i<<4,c|=a<<8,c|=C<<9,c|=e,c|=n<<14,c|=s<<15,new ve(A,o,d,Q,c)}var yr=new Set([r.sampleModes,r.initialAttenuation,r.keyRange,r.velRange,r.sampleID,r.fineTune,r.coarseTune,r.startAddrsOffset,r.startAddrsCoarseOffset,r.endAddrOffset,r.endAddrsCoarseOffset,r.startloopAddrsOffset,r.startloopAddrsCoarseOffset,r.endloopAddrsOffset,r.endloopAddrsCoarseOffset,r.overridingRootKey,r.exclusiveClass]);function ht(t){for(let o=0;of.generatorType===a);if(C===void 0)continue;let B=i.generatorValue*-128,d=60/128*B,Q=C.generatorValue-d,l=t.generators.indexOf(i),c=t.generators.indexOf(C);t.generators[c]=new N(a,Q,!1),t.generators[l]=new N(i.generatorType,B,!1)}let A=t.generators.reduce((o,i)=>{if(yr.has(i.generatorType))return o;let a=Qo(i);return a!==void 0?(o.push(a),p("%cSucceeded converting to DLS Articulator!",g.recognized)):T("Failed converting to DLS Articulator!"),o},[]),e=t.modulators.reduce((o,i)=>{if(P.isIdentical(i,Et,!0)||P.isIdentical(i,It,!0)||P.isIdentical(i,Ct,!0)||P.isIdentical(i,Bt,!0))return o;let a=uo(i);return a!==void 0?(o.push(a),p("%cSucceeded converting to DLS Articulator!",g.recognized)):T("Failed converting to DLS Articulator!"),o},[]);A.push(...e);let n=new b(8);K(n,8),K(n,A.length);let s=A.map(o=>o.writeArticulator());return tA("art2",cA([n,...s]))}function fo(t,A){let e=new b(12);L(e,Math.max(t.keyRange.min,0)),L(e,t.keyRange.max),L(e,Math.max(t.velRange.min,0)),L(e,t.velRange.max),L(e,0);let n=t.getGeneratorValue(r.exclusiveClass,0);L(e,n),L(e,0);let s=tA("rgnh",e),o=t.getGeneratorValue(r.overridingRootKey,t.sample.samplePitch);t.getGeneratorValue(r.scaleTuning,A.getGeneratorValue(r.scaleTuning,100))===0&&t.keyRange.max-t.keyRange.min===0&&(o=t.keyRange.min);let a=gt(t.sample,o,t.getGeneratorValue(r.fineTune,0)+t.getGeneratorValue(r.coarseTune,0)*100+t.sample.samplePitchCorrection,t.getGeneratorValue(r.initialAttenuation,0),t.sample.sampleLoopStartIndex+t.getGeneratorValue(r.startloopAddrsOffset,0)+t.getGeneratorValue(r.startloopAddrsCoarseOffset,0)*32768,t.sample.sampleLoopEndIndex+t.getGeneratorValue(r.endloopAddrsOffset,0)+t.getGeneratorValue(r.endloopAddrsCoarseOffset,0)*32768,t.getGeneratorValue(r.sampleModes,0)),C=new b(12);L(C,0),L(C,0),K(C,1),K(C,this.samples.indexOf(t.sample));let B=tA("wlnk",C),d=new b(0);if(t.modulators.length+t.generators.length>0){let Q=ht(t);d=tA("lar2",Q,!1,!0)}return tA("rgn2",cA([s,a,B,d]),!1,!0)}function mo(t){QA(`%cWriting %c${t.presetName}%c...`,g.info,g.recognized,g.info);let A=Co(t),e=A.reduce((l,c)=>c.isGlobal?l:l+1,0),n=new b(12);K(n,e);let s=(t.bank&127)<<8;t.bank===128&&(s|=1<<31),K(n,s),K(n,t.program&127);let o=tA("insh",n),i=new b(0),a=A.find(l=>l.isGlobal===!0);if(a){let l=ht(a);i=tA("lar2",l,!1,!0)}let C=cA(A.reduce((l,c)=>(c.isGlobal||l.push(fo.apply(this,[c,a])),l),[])),B=tA("lrgn",C,!1,!0),d=tA("INAM",Be(t.presetName)),Q=tA("INFO",d,!1,!0);return O(),tA("ins ",cA([o,B,i,Q]),!1,!0)}function po(){let t=cA(this.presets.map(A=>mo.apply(this,[A])));return tA("lins",t,!1,!0)}function yo(t){let A=new b(18);L(A,1),L(A,1),K(A,t.sampleRate),K(A,t.sampleRate*2),L(A,2),L(A,16);let e=tA("fmt ",A),n=1;t.sampleLoopStartIndex+Math.abs(t.getAudioData().length-t.sampleLoopEndIndex)<2&&(n=0);let s=gt(t,t.samplePitch,t.samplePitchCorrection,0,t.sampleLoopStartIndex,t.sampleLoopEndIndex,n),o=t.getAudioData(),i;if(t.isCompressed){let B=new Int16Array(o.length);for(let d=0;d{let s=yo(n);return A.push(t),t+=s.length,s});return{data:tA("wvpl",cA(e),!1,!0),indexes:A}}function Do(){QA("%cSaving DLS...",g.info);let t=new b(4);K(t,this.presets.length);let A=tA("colh",t);QA("%cWriting instruments...",g.info);let e=po.apply(this);p("%cSuccess!",g.recognized),O(),QA("%cWriting WAVE samples...",g.info);let n=So.apply(this),s=n.data,o=n.indexes;p("%cSucceeded!",g.recognized),O();let i=new b(8+4*o.length);K(i,8),K(i,o.length);for(let Q of o)K(i,Q);let a=tA("ptbl",i);this.soundFontInfo.ICMT=(this.soundFontInfo.ICMT||"Soundfont")+` +Converted from SF2 to DLS using SpessaSynth`,this.soundFontInfo.ISFT="SpessaSynth";let C=[];for(let[Q,l]of Object.entries(this.soundFontInfo))Q!=="ICMT"&&Q!=="INAM"&&Q!=="ICRD"&&Q!=="IENG"&&Q!=="ICOP"&&Q!=="ISFT"&&Q!=="ISBJ"||C.push(tA(Q,Be(l),!0));let B=tA("INFO",cA(C),!1,!0),d=new b(A.length+e.length+a.length+s.length+B.length+4);return yA(d,"DLS "),d.set(cA([A,e,a,s,B]),4),p("%cSaved succesfully!",g.recognized),O(),tA("RIFF",d)}var Sr=48e3,re=class{constructor(A,e,n,s,o,i,a,C){this.sampleName=A,this.sampleRate=e,this.samplePitch=n,this.samplePitchCorrection=s,this.sampleLink=o,this.sampleType=i,this.sampleLoopStartIndex=a,this.sampleLoopEndIndex=C,this.isCompressed=(i&16)>0,this.compressedData=void 0,this.useCount=0,this.sampleData=void 0}getRawData(){let A=new Uint8Array(this.sampleData.length*2);for(let e=0;e>8&255}return A}resampleData(A){let e=this.getAudioData(),n=A/this.sampleRate,s=new Float32Array(Math.floor(e.length*n));for(let o=0;o96e3)&&(this.resampleData(Sr),n=this.getAudioData()),this.compressedData=e([n],1,this.sampleRate,A),this.sampleType|=16,this.isCompressed=!0}catch{T(`Failed to compress ${this.sampleName}. Leaving as uncompressed!`),this.isCompressed=!1,this.compressedData=void 0,this.sampleType&=239}}getAudioData(){return this.sampleData}};var ie=class{constructor(){this.instrumentName="",this.instrumentZones=[],this._useCount=0}get useCount(){return this._useCount}addUseCount(){this._useCount++,this.instrumentZones.forEach(A=>A.useCount++)}removeUseCount(){this._useCount--;for(let A=0;AA.deleteZone()),this.instrumentZones.length=0}safeDeleteZone(A){return this.instrumentZones[A].useCount--,this.instrumentZones[A].useCount<1?(this.deleteZone(A),!0):!1}deleteZone(A){this.instrumentZones[A].deleteZone(),this.instrumentZones.splice(A,1)}};var ae=class{constructor(A){this.presetName="",this.program=0,this.bank=0,this.presetZones=[],this.sampleIDOffset=0,this.foundSamplesAndGenerators=[];for(let e=0;e<128;e++)this.foundSamplesAndGenerators[e]=[];this.library=0,this.genre=0,this.morphology=0,this.defaultModulators=A}deletePreset(){this.presetZones.forEach(A=>A.deleteZone()),this.presetZones.length=0}deleteZone(A){this.presetZones[A].deleteZone(),this.presetZones.splice(A,1)}preload(A,e){for(let n=A;n{o.sample.isSampleLoaded||o.sample.getAudioData()})}preloadSpecific(A,e){this.getSamplesAndGenerators(A,e).forEach(n=>{n.sample.isSampleLoaded||n.sample.getAudioData()})}getSamplesAndGenerators(A,e){let n=this.foundSamplesAndGenerators[A][e];if(n)return n;if(this.presetZones.length<1)return[];function s(c,f){return f>=c.min&&f<=c.max}function o(c,f){c.push(...f.filter(y=>!c.find(S=>S.generatorType===y.generatorType)))}function i(c,f){c.push(...f.filter(y=>!c.find(S=>P.isIdentical(y,S))))}let a=[],C=this.presetZones[0].isGlobal?[...this.presetZones[0].generators]:[],B=this.presetZones[0].isGlobal?[...this.presetZones[0].modulators]:[],d=this.presetZones[0].isGlobal?this.presetZones[0].keyRange:{min:0,max:127},Q=this.presetZones[0].isGlobal?this.presetZones[0].velRange:{min:0,max:127};return this.presetZones.filter(c=>s(c.hasKeyRange?c.keyRange:d,A)&&s(c.hasVelRange?c.velRange:Q,e)&&!c.isGlobal).forEach(c=>{if(c.instrument.instrumentZones.length<1)return;let f=c.generators,y=c.modulators,S=c.instrument.instrumentZones[0],w=S.isGlobal?[...S.generators]:[],H=S.isGlobal?[...S.modulators]:[],R=S.isGlobal?S.keyRange:{min:0,max:127},x=S.isGlobal?S.velRange:{min:0,max:127};c.instrument.instrumentZones.filter(I=>s(I.hasKeyRange?I.keyRange:R,A)&&s(I.hasVelRange?I.velRange:x,e)&&!I.isGlobal).forEach(I=>{let rA=[...I.generators],Z=[...I.modulators];o(f,C),o(rA,w),i(y,B),i(Z,H),i(Z,this.defaultModulators);let AA=[...Z];for(let $=0;$P.isIdentical(IA,iA));sA!==-1?AA[sA]=AA[sA].sumTransform(IA):AA.push(IA)}a.push({instrumentGenerators:rA,presetGenerators:f,modulators:AA,sample:I.sample,sampleID:I.generators.find($=>$.generatorType===r.sampleID).generatorValue})})}),this.foundSamplesAndGenerators[A][e]=a,a}};var ge=class t{constructor(A=void 0){this.soundFontInfo={},this.presets=[],this.samples=[],this.instruments=[],this.defaultModulators=_e.map(e=>P.copy(e)),A?.presets&&(this.presets.push(...A.presets),this.soundFontInfo=A.info)}static mergeSoundfonts(...A){let e=A.shift(),n=e.presets;for(;A.length;)A.shift().presets.forEach(o=>{n.find(i=>i.bank===o.bank&&i.program===o.program)===void 0&&n.push(o)});return new t({presets:n,info:e.soundFontInfo})}static getDummySoundfontFile(){let A=new t,e=new re("Saw",44100,65,20,0,0,0,127);e.sampleData=new Float32Array(128);for(let B=0;B<128;B++)e.sampleData[B]=B/128*2-1;A.samples.push(e);let n=new FA;n.isGlobal=!0,n.generators.push(new N(r.initialAttenuation,375)),n.generators.push(new N(r.releaseVolEnv,-1e3)),n.generators.push(new N(r.sampleModes,1));let s=new FA;s.sample=e;let o=new FA;o.sample=e,o.generators.push(new N(r.fineTune,-9));let i=new ie;i.instrumentName="Saw Wave",i.instrumentZones.push(n),i.instrumentZones.push(s),i.instrumentZones.push(o),A.instruments.push(i);let a=new oe;a.instrument=i;let C=new ae(A.defaultModulators);return C.presetName="Saw Wave",C.presetZones.push(a),A.presets.push(C),A.soundFontInfo.ifil="2.1",A.soundFontInfo.isng="EMU8000",A.soundFontInfo.INAM="Dummy",A.write().buffer}removeUnusedElements(){this.instruments.forEach(A=>{A.useCount<1&&A.instrumentZones.forEach(e=>{e.isGlobal||e.sample.useCount--})}),this.instruments=this.instruments.filter(A=>A.useCount>0),this.samples=this.samples.filter(A=>A.useCount>0)}deleteInstrument(A){if(A.useCount>0)throw new Error(`Cannot delete an instrument that has ${A.useCount} usages.`);this.instruments.splice(this.instruments.indexOf(A),1),A.deleteInstrument(),this.removeUnusedElements()}deletePreset(A){A.deletePreset(),this.presets.splice(this.presets.indexOf(A),1),this.removeUnusedElements()}deleteSample(A){if(A.useCount>0)throw new Error(`Cannot delete sample that has ${A.useCount} usages.`);this.samples.splice(this.samples.indexOf(A),1),this.removeUnusedElements()}setSampleIDOffset(A){this.presets.forEach(e=>e.sampleIDOffset=A)}getPresetNoFallback(A,e,n=!1){let s=this.presets.find(o=>o.bank===A&&o.program===e);if(s)return s;if(n!==!1)return A===128?this.presets.find(o=>o.bank===128):this.presets.find(o=>o.program===e)}getPreset(A,e){let n=this.presets.find(s=>s.bank===A&&s.program===e);return n||(A===128?(n=this.presets.find(s=>s.bank===128&&s.program===e),n||(n=this.presets.find(s=>s.bank===128))):n=this.presets.find(s=>s.program===e&&s.bank!==128),n&&T(`%cPreset ${A}.${e} not found. Replaced with %c${n.presetName} (${n.bank}.${n.program})`,g.warn,g.recognized)),n||(T(`Preset ${e} not found. Defaulting to`,this.presets[0].presetName),n=this.presets[0]),n}getPresetByName(A){let e=this.presets.find(n=>n.presetName===A);return e||(T("Preset not found. Defaulting to:",this.presets[0].presetName),e=this.presets[0]),e}parsingError(A){throw new Error(`SF parsing error: ${A} The file may be corrupted.`)}destroySoundfont(){delete this.presets,delete this.instruments,delete this.samples}};ge.prototype.write=Eo;ge.prototype.writeDLS=Do;function ko(t){QA("%cLoading instruments...",g.info);for(let A=0;A>8&127,A>>31&&(this.bank=128),this.DLSInstrument=new ie,this.DLSInstrument.addUseCount();let s=new oe;s.instrument=this.DLSInstrument,this.presetZones=[s]}};function wo(t){this.verifyHeader(t,"LIST"),this.verifyText(_(t.chunkData,4),"ins ");let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(z(t.chunkData));let e=A.find(c=>c.header==="insh");if(!e)throw O(),new Error("No instrument header!");let n=F(e.chunkData,4),s=F(e.chunkData,4),o=F(e.chunkData,4),i=new ct(s,o),a="unnamedPreset",C=MA(A,"INFO");if(C){let c=z(C.chunkData);for(;c.header!=="INAM";)c=z(C.chunkData);a=_(c.chunkData,c.chunkData.length).trim()}i.presetName=a,i.DLSInstrument.instrumentName=a,Ce(`%cParsing %c"${a}"%c...`,g.info,g.recognized,g.info);let B=MA(A,"lrgn");if(!B)throw O(),new Error("No region list!");let d=new FA;d.isGlobal=!0;let Q=MA(A,"lart"),l=MA(A,"lar2");(l!==void 0||Q!==void 0)&&this.readLart(Q,l,d),d.generators=d.generators.filter(c=>c.generatorValue!==J[c.generatorType].def),d.modulators.find(c=>c.modulatorDestination===r.reverbEffectsSend)===void 0&&d.modulators.push(P.copy(It)),d.modulators.find(c=>c.modulatorDestination===r.chorusEffectsSend)===void 0&&d.modulators.push(P.copy(Et)),i.DLSInstrument.instrumentZones.push(d);for(let c=0;c>10&15;H===uA.linear&&w!==uA.linear&&(H=w);let R=n>>14&1,x=n>>15&1;i===r.initialAttenuation&&s<0&&(x=1),l=OA(H,R,x,a.isCC,a.enum)}let c=n>>4&15,f=n>>8&1,y=n>>9&1,S=OA(c,f,y,Q.isCC,Q.enum);if(C){let w=S;S=l,l=w}return new P({srcEnum:l,secSrcEnum:S,dest:i,transform:0,amt:d})}function jt(t,A){let e=t.chunkData,n=[],s=[];F(e,4);let o=F(e,4);for(let i=0;i>16;if(a===0&&C===0&&d===0){let c;switch(B){case D.pan:c=new N(r.pan,l);break;case D.gain:c=new N(r.initialAttenuation,-l*10/.4);break;case D.filterCutoff:c=new N(r.initialFilterFc,l);break;case D.filterQ:c=new N(r.initialFilterQ,l);break;case D.modLfoFreq:c=new N(r.freqModLFO,l);break;case D.modLfoDelay:c=new N(r.delayModLFO,l);break;case D.vibLfoFreq:c=new N(r.freqVibLFO,l);break;case D.vibLfoDelay:c=new N(r.delayVibLFO,l);break;case D.volEnvDelay:c=new N(r.delayVolEnv,l);break;case D.volEnvAttack:c=new N(r.attackVolEnv,l);break;case D.volEnvHold:c=new N(r.holdVolEnv,l,!1);break;case D.volEnvDecay:c=new N(r.decayVolEnv,l,!1);break;case D.volEnvRelease:c=new N(r.releaseVolEnv,l);break;case D.volEnvSustain:let f=1e3-l;c=new N(r.sustainVolEnv,f);break;case D.modEnvDelay:c=new N(r.delayModEnv,l);break;case D.modEnvAttack:c=new N(r.attackModEnv,l);break;case D.modEnvHold:c=new N(r.holdModEnv,l,!1);break;case D.modEnvDecay:c=new N(r.decayModEnv,l,!1);break;case D.modEnvRelease:c=new N(r.releaseModEnv,l);break;case D.modEnvSustain:let y=1e3-l;c=new N(r.sustainModEnv,y);break;case D.reverbSend:c=new N(r.reverbEffectsSend,l);break;case D.chorusSend:c=new N(r.chorusEffectsSend,l);break;case D.pitch:let S=Math.floor(l/100),w=Math.floor(l-S*100);c=new N(r.fineTune,w),n.push(new N(r.coarseTune,S));break}c&&n.push(c)}else{let c=!0;if(C===v.none)if(a===v.modLfo&&B===D.pitch)n.push(new N(r.modLfoToPitch,l));else if(a===v.modLfo&&B===D.gain)n.push(new N(r.modLfoToVolume,l));else if(a===v.modLfo&&B===D.filterCutoff)n.push(new N(r.modLfoToFilterFc,l));else if(a===v.vibratoLfo&&B===D.pitch)n.push(new N(r.vibLfoToPitch,l));else if(a===v.modEnv&&B===D.pitch)n.push(new N(r.modEnvToPitch,l));else if(a===v.modEnv&&B===D.filterCutoff)n.push(new N(r.modEnvToFilterFc,l));else if(a===v.keyNum&&B===D.pitch)n.push(new N(r.scaleTuning,l/128));else if(a===v.keyNum&&B===D.volEnvHold){n.push(new N(r.keyNumToVolEnvHold,l/-128));let f=Math.round(60/128*l);n.forEach(y=>{y.generatorType===r.holdVolEnv&&(y.generatorValue+=f)})}else if(a===v.keyNum&&B===D.volEnvDecay){n.push(new N(r.keyNumToVolEnvDecay,l/-128));let f=Math.round(60/128*l);n.forEach(y=>{y.generatorType===r.decayVolEnv&&(y.generatorValue+=f)})}else if(a===v.keyNum&&B===D.modEnvHold){n.push(new N(r.keyNumToModEnvHold,l/-128));let f=Math.round(60/128*l);n.forEach(y=>{y.generatorType===r.holdModEnv&&(y.generatorValue+=f)})}else if(a===v.keyNum&&B===D.modEnvDecay){n.push(new N(r.keyNumToModEnvDecay,l/-128));let f=Math.round(60/128*l);n.forEach(y=>{y.generatorType===r.decayModEnv&&(y.generatorValue+=f)})}else c=!1;else c=!1;if(c===!1){let f=Ro(a,C,B,d,l);f?(s.push(f),p("%cSucceeded converting to SF2 Modulator!",g.recognized)):T("Failed converting to SF2 Modulator!")}}}return A&&s.push(P.copy(Ct),P.copy(Bt)),{modulators:s,generators:n}}function Go(t,A,e){if(t)for(;t.chunkData.currentIndext.chunkData.currentIndex;)A.push(z(t.chunkData));let e=A.find(Z=>Z.header==="rgnh"),n=F(e.chunkData,2),s=F(e.chunkData,2),o=F(e.chunkData,2),i=F(e.chunkData,2),a=new lt({min:n,max:s},{min:o,max:i});F(e.chunkData,2);let C=F(e.chunkData,2);C!==0&&a.generators.push(new N(r.exclusiveClass,C));let B=MA(A,"lart"),d=MA(A,"lar2");this.readLart(B,d,a),a.isGlobal=!1;let Q=A.find(Z=>Z.header==="wsmp");F(Q.chunkData,4);let l=F(Q.chunkData,2),c=se(Q.chunkData[Q.chunkData.currentIndex++],Q.chunkData[Q.chunkData.currentIndex++]),y=(F(Q.chunkData,4)|0)/-655360;F(Q.chunkData,4);let S=F(Q.chunkData,4),w,H={start:0,end:0};if(S===0)w=0;else{F(Q.chunkData,4),F(Q.chunkData,4)===0?w=1:w=3,H.start=F(Q.chunkData,4);let AA=F(Q.chunkData,4);H.end=H.start+AA}let R=A.find(Z=>Z.header==="wlnk");if(R===void 0)return;F(R.chunkData,2),F(R.chunkData,2),F(R.chunkData,4);let x=F(R.chunkData,4),G=this.samples[x];if(G===void 0)throw new Error("Invalid sample ID!");let rA=(y||G.sampleDbAttenuation)*10/.4;return a.setWavesample(rA,w,H,l,G,x,c),a}var Qt=class extends re{sampleDbAttenuation;sampleData;constructor(A,e,n,s,o,i,a,C){super(A,e,n,s,0,1,o,i),this.sampleData=a,this.sampleDbAttenuation=C}getAudioData(){return this.sampleData}getRawData(){if(this.isCompressed){if(!this.compressedData)throw new Error("Compressed but no data?? This shouldn't happen!!");return this.compressedData}return super.getRawData()}};var xo={PCM:1,ALAW:6};function wr(t,A){let e=Math.pow(2,A*8-1),n=Math.pow(2,A*8),s,o=!1;A===1?(s=255,o=!0):s=e;let i=t.size/A,a=new Float32Array(i);for(let C=0;C=e&&(B-=n),a[C]=B/s)}return a}function Fr(t,A){let e=t.size/A,n=new Float32Array(e);for(let s=0;s>4,C=i&15;a>0&&(C+=16),C=(C<<4)+8,a>1&&(C=C<127?C:-C;n[s]=B/32678}return n}function No(t){QA("%cLoading Wave samples...",g.recognized);let A=0;for(;t.chunkData.currentIndexG.header==="fmt ");if(!s)throw new Error("No fmt chunk in the wave file!");let o=F(s.chunkData,2),i=F(s.chunkData,2);if(i!==1)throw new Error(`Only mono samples are supported. Fmt reports ${i} channels`);let a=F(s.chunkData,4);F(s.chunkData,4),F(s.chunkData,2);let B=F(s.chunkData,2)/8,d=!1,Q=n.find(G=>G.header==="data");Q||this.parsingError("No data chunk in the WAVE chunk!");let l;switch(o){default:d=!0,l=new Float32Array(Q.size/B);break;case xo.PCM:l=wr(Q,B);break;case xo.ALAW:l=Fr(Q,B);break}let c=MA(n,"INFO"),f=`Unnamed ${A}`;if(c){let G=z(c.chunkData);for(;G.header!=="INAM"&&c.chunkData.currentIndexG.header==="wsmp");if(x){F(x.chunkData,4),y=F(x.chunkData,2),S=se(x.chunkData[x.chunkData.currentIndex++],x.chunkData[x.chunkData.currentIndex++]);let G=Math.trunc(S/100);if(y+=G,S-=G*100,R=(F(x.chunkData,4)|0)/-655360,F(x.chunkData,4),F(x.chunkData,4)===1){F(x.chunkData,8),w=F(x.chunkData,4);let Z=F(x.chunkData,4);H=w+Z}}else T("No wsmp chunk in wave... using sane defaults.");d&&console.error(`Failed to load '${f}': Unsupported format: (${o})`),this.samples.push(new Qt(f,a,y,S,w,H,l,R)),A++,p(`%cLoaded sample %c${f}`,g.info,g.recognized)}O()}var ee=class extends ge{constructor(A){super(),this.dataArray=new b(A),Ce("%cParsing DLS...",g.info),this.dataArray||(O(),this.parsingError("No data provided!"));let e=z(this.dataArray,!1);this.verifyHeader(e,"riff"),this.verifyText(_(this.dataArray,4).toLowerCase(),"dls ");let n=[];for(;this.dataArray.currentIndexC.header==="colh");o||(V(),this.parsingError("No colh chunk!")),this.instrumentAmount=F(o.chunkData,4),p(`%cInstruments amount: %c${this.instrumentAmount}`,g.info,g.recognized);let i=MA(s,"wvpl");i||(V(),this.parsingError("No wvpl chunk!")),this.readDLSSamples(i);let a=MA(s,"lins");a||(V(),this.parsingError("No lins chunk!")),this.readDLSInstrumentList(a),this.presets.sort((C,B)=>C.program-B.program+(C.bank-B.bank)),p(`%cParsing finished! %c"${this.soundFontInfo.INAM||"UNNAMED"}"%c has %c${this.presets.length} %cpresets, - %c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info),V()}verifyHeader(A,e){A.header.toLowerCase()!==e.toLowerCase()&&(V(),this.parsingError(`Invalid DLS chunk header! Expected "${e.toLowerCase()}" got "${A.header.toLowerCase()}"`))}verifyText(A,e){A.toLowerCase()!==e.toLowerCase()&&(V(),this.parsingError(`FourCC error: Expected "${e.toLowerCase()}" got "${A.toLowerCase()}"`))}parsingError(A){throw new Error(`DLS parse error: ${A} The file may be corrupted.`)}destroySoundfont(){super.destroySoundfont(),delete this.dataArray}};ee.prototype.readDLSInstrumentList=So;ee.prototype.readDLSInstrument=Do;ee.prototype.readRegion=Ro;ee.prototype.readLart=Fo;ee.prototype.readDLSSamples=Mo;var zt=class extends re{constructor(A,e,s,n,o,i,a,C,B,d,Q,l,c){super(A,i,a,C,B,d,n-e/2,o-e/2),this.sampleName=A,this.sampleStartIndex=e,this.sampleEndIndex=s,this.isSampleLoaded=!1,this.sampleID=l,this.sampleLength=this.sampleEndIndex-this.sampleStartIndex,this.sampleDataArray=Q,this.sampleData=new Float32Array(0),this.isCompressed&&(this.sampleLoopStartIndex+=this.sampleStartIndex/2,this.sampleLoopEndIndex+=this.sampleStartIndex/2,this.sampleLength=99999999),this.isDataRaw=c}getRawData(){let A=this.sampleDataArray;if(this.isCompressed){if(this.compressedData)return this.compressedData;let e=A.currentIndex;return A.slice(this.sampleStartIndex/2+e,this.sampleEndIndex/2+e)}else{this.isDataRaw||super.getRawData();let e=A.currentIndex;return A.slice(e+this.sampleStartIndex,e+this.sampleEndIndex)}}decodeVorbis(){if(this.sampleLength<1)return;let A=this.sampleDataArray,e=A.currentIndex,s=A.slice(this.sampleStartIndex/2+e,this.sampleEndIndex/2+e);this.sampleData=new Float32Array(0);try{let n=zA.decode(s.buffer);this.sampleData=n.data[0]}catch(n){T(`Error decoding sample ${this.sampleName}: ${n}`),this.sampleData=new Float32Array(this.sampleLoopEndIndex+1)}}getAudioData(){return this.isSampleLoaded?this.sampleData:this.sampleLength<1?new Float32Array(1):this.isCompressed?(this.decodeVorbis(),this.isSampleLoaded=!0,this.sampleData):this.isDataRaw?this.loadUncompressedData():this.getUncompressedReadyData()}loadUncompressedData(){if(this.isCompressed)return T("Trying to load a compressed sample via loadUncompressedData()... aborting!"),new Float32Array(0);let A=new Float32Array(this.sampleLength/2),e=this.sampleDataArray.currentIndex,s=new Int16Array(this.sampleDataArray.slice(e+this.sampleStartIndex,e+this.sampleEndIndex).buffer);for(let n=0;nt.chunkData.currentIndex;){let o=wr(n,t.chunkData,A,e);s.push(o),n++}return s.length>1&&s.pop(),s}function wr(t,A,e,s){let n=_(A,20),o=F(A,4)*2,i=F(A,4)*2,a=F(A,4),C=F(A,4),B=F(A,4),d=A[A.currentIndex++];d===255&&(d=60);let Q=Ps(A[A.currentIndex++]),l=F(A,2),c=F(A,2);return new zt(n,o,i,a,C,B,d,Q,l,c,e,t,s)}var jt=class extends N{constructor(A){super();let e=A.currentIndex;this.generatorType=A[e+1]<<8|A[e],this.generatorValue=ne(A[e+2],A[e+3]),A.currentIndex+=4}};function $t(t){let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(new jt(t.chunkData));return A.length>1&&A.pop(),A}var As=class extends ie{constructor(A){super(),this.instrumentName=_(A.chunkData,20).trim(),this.instrumentZoneIndex=F(A.chunkData,2),this.instrumentZonesAmount=0}getInstrumentZones(A,e){this.instrumentZonesAmount=A;for(let s=this.instrumentZoneIndex;st.chunkData.currentIndex;){let s=new As(t);if(e.length>0){let n=s.instrumentZoneIndex-e[e.length-1].instrumentZoneIndex;e[e.length-1].getInstrumentZones(n,A)}e.push(s)}return e.length>1&&e.pop(),e}var es=class extends FA{constructor(A){super(),this.generatorZoneStartIndex=F(A,2),this.modulatorZoneStartIndex=F(A,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(A,e){this.modulatorZoneSize=A,this.generatorZoneSize=e}getGenerators(A){for(let e=this.generatorZoneStartIndex;es.generatorType===r.sampleID);e&&(this.sample=A[e.generatorValue],this.isGlobal=!1,this.sample.useCount++)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===r.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===r.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function bo(t,A,e,s){let n=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new es(t.chunkData);if(n.length>0){let i=o.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,a=o.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(i,a),n[n.length-1].getGenerators(A),n[n.length-1].getModulators(e),n[n.length-1].getSample(s),n[n.length-1].getKeyRange(),n[n.length-1].getVelRange()}n.push(o)}return n.length>1&&n.pop(),n}var ts=class extends oe{constructor(A){super(),this.generatorZoneStartIndex=F(A,2),this.modulatorZoneStartIndex=F(A,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(A,e){this.modulatorZoneSize=A,this.generatorZoneSize=e}getGenerators(A){for(let e=this.generatorZoneStartIndex;es.generatorType===r.instrument);e&&(this.instrument=A[e.generatorValue],this.instrument.addUseCount(),this.isGlobal=!1)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===r.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===r.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function Lo(t,A,e,s){let n=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new ts(t.chunkData);if(n.length>0){let i=o.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,a=o.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(i,a),n[n.length-1].getGenerators(A),n[n.length-1].getModulators(e),n[n.length-1].getInstrument(s),n[n.length-1].getKeyRange(),n[n.length-1].getVelRange()}n.push(o)}return n.length>1&&n.pop(),n}var ss=class extends ae{constructor(A,e){super(e),this.presetName=_(A.chunkData,20).trim().replace(/\d{3}:\d{3}/,""),this.program=F(A.chunkData,2),this.bank=F(A.chunkData,2),this.presetZoneStartIndex=F(A.chunkData,2),this.library=F(A.chunkData,4),this.genre=F(A.chunkData,4),this.morphology=F(A.chunkData,4),this.presetZonesAmount=0}getPresetZones(A,e){this.presetZonesAmount=A;for(let s=this.presetZoneStartIndex;st.chunkData.currentIndex;){let n=new ss(t,e);if(s.length>0){let o=n.presetZoneStartIndex-s[s.length-1].presetZoneStartIndex;s[s.length-1].getPresetZones(o,A)}s.push(n)}return s.length>1&&s.pop(),s}var ns=class extends P{constructor(A){super({srcEnum:F(A,2),dest:F(A,2),amt:ne(A[A.currentIndex++],A[A.currentIndex++]),secSrcEnum:F(A,2),transform:F(A,2)})}};function ut(t){let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(new ns(t.chunkData));return A}var dt=class extends ge{constructor(A,e=!0){super(),e&&console.warn("Using the constructor directly is deprecated. Use loadSoundFont instead."),this.dataArray=new b(A),Ce("%cParsing SoundFont...",g.info),this.dataArray||(V(),this.parsingError("No data provided!"));let s=z(this.dataArray,!1);this.verifyHeader(s,"riff");let n=_(this.dataArray,4).toLowerCase();if(n!=="sfbk"&&n!=="sfpk")throw V(),new SyntaxError(`Invalid soundFont! Expected "sfbk" or "sfpk" got "${n}"`);let o=n==="sfpk",i=z(this.dataArray);for(this.verifyHeader(i,"list"),_(i.chunkData,4);i.chunkData.length>i.chunkData.currentIndex;){let $=z(i.chunkData),IA;switch($.header.toLowerCase()){case"ifil":case"iver":IA=`${F($.chunkData,2)}.${F($.chunkData,2)}`,this.soundFontInfo[$.header]=IA;break;case"icmt":IA=_($.chunkData,$.chunkData.length,void 0,!1),this.soundFontInfo[$.header]=IA;break;case"dmod":let nA=ut($);nA.pop(),IA=`Modulators: ${nA.length}`;let iA=this.defaultModulators;this.defaultModulators=nA,this.defaultModulators.push(...iA.filter(eA=>!this.defaultModulators.find(lA=>P.isIdentical(eA,lA)))),this.soundFontInfo[$.header]=$.chunkData;break;default:IA=_($.chunkData,$.chunkData.length),this.soundFontInfo[$.header]=IA}p(`%c"${$.header}": %c"${IA}"`,g.info,g.recognized)}let a=z(this.dataArray,!1);this.verifyHeader(a,"list"),this.verifyText(_(this.dataArray,4),"sdta"),p("%cVerifying smpl chunk...",g.warn);let C=z(this.dataArray,!1);this.verifyHeader(C,"smpl");let B;if(o){p("%cSF2Pack detected, attempting to decode the smpl chunk...",g.info);try{B=zA.decode(this.dataArray.buffer.slice(this.dataArray.currentIndex,this.dataArray.currentIndex+a.size-12)).data[0]}catch($){throw V(),new Error(`SF2Pack Ogg Vorbis decode error: ${$}`)}p(`%cDecoded the smpl chunk! Length: %c${B.length}`,g.info,g.value)}else B=this.dataArray,this.sampleDataStartIndex=this.dataArray.currentIndex;p(`%cSkipping sample chunk, length: %c${a.size-12}`,g.info,g.value),this.dataArray.currentIndex+=a.size-12,p("%cLoading preset data chunk...",g.warn);let d=z(this.dataArray);this.verifyHeader(d,"list"),_(d.chunkData,4);let Q=z(d.chunkData);this.verifyHeader(Q,"phdr");let l=z(d.chunkData);this.verifyHeader(l,"pbag");let c=z(d.chunkData);this.verifyHeader(c,"pmod");let f=z(d.chunkData);this.verifyHeader(f,"pgen");let y=z(d.chunkData);this.verifyHeader(y,"inst");let S=z(d.chunkData);this.verifyHeader(S,"ibag");let w=z(d.chunkData);this.verifyHeader(w,"imod");let H=z(d.chunkData);this.verifyHeader(H,"igen");let R=z(d.chunkData);this.verifyHeader(R,"shdr"),this.dataArray.currentIndex=this.sampleDataStartIndex,this.samples.push(...xo(R,B,!o));let x=$t(H),G=ut(w),I=bo(S,x,G,this.samples);this.instruments=No(y,I);let rA=$t(f),Z=ut(c),AA=Lo(l,rA,Z,this.instruments);this.presets.push(...Uo(Q,AA,this.defaultModulators)),this.presets.sort(($,IA)=>$.program-IA.program+($.bank-IA.bank)),p(`%cParsing finished! %c"${this.soundFontInfo.INAM}"%c has %c${this.presets.length} %cpresets, - %c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info),V(),o&&delete this.dataArray}verifyHeader(A,e){A.header.toLowerCase()!==e.toLowerCase()&&(V(),this.parsingError(`Invalid chunk header! Expected "${e.toLowerCase()}" got "${A.header.toLowerCase()}"`))}verifyText(A,e){A.toLowerCase()!==e.toLowerCase()&&(V(),this.parsingError(`Invalid FourCC: Expected "${e.toLowerCase()}" got "${A.toLowerCase()}"\``))}destroySoundfont(){super.destroySoundfont(),delete this.dataArray}};function He(t){let A=t.slice(8,12),e=new b(A);return _(e,4,void 0,!1).toLowerCase()==="dls "?new ee(t):new dt(t,!1)}function To(t,A,e=!1){let s=this.workletProcessorChannels[t];if(s===void 0){T(`Trying to access channel ${t} which does not exist... ignoring!`);return}if(s.lockPreset)return;let n=XA(s),o,i;if(this.overrideSoundfont){let a=n===128?128:n-this.soundfontBankOffset,C=this.overrideSoundfont.getPresetNoFallback(a,A);C?(o=n,i=C,s.presetUsesOverride=!0):(i=this.soundfontManager.getPreset(n,A),o=i.bank,s.presetUsesOverride=!1)}else i=this.soundfontManager.getPreset(n,A),o=i.bank,s.presetUsesOverride=!1;this.setPreset(t,i),this.callEvent("programchange",{channel:t,program:i.program,bank:o,userCalled:e})}function vo(t,A){if(this.overrideSoundfont){let e=t===128?128:t-this.soundfontBankOffset,s=this.overrideSoundfont.getPresetNoFallback(e,A);if(s)return s}return this.soundfontManager.getPreset(t,A)}function Ho(t,A){if(!this.workletProcessorChannels[t].lockPreset){delete this.workletProcessorChannels[t].preset,this.workletProcessorChannels[t].preset=A,this.workletProcessorChannels[t].cachedVoices=[];for(let e=0;e<128;e++)this.workletProcessorChannels[t].cachedVoices.push([])}}function Yo(t,A){let e=this.workletProcessorChannels[t];e.lockPreset||e.drumChannel!==A&&(A?(e.channelTransposeKeyShift=0,e.drumChannel=!0,this.setPreset(t,this.getPreset(XA(e),e.preset.program))):(e.drumChannel=!1,this.setPreset(t,this.getPreset(XA(e),e.preset.program))),e.presetUsesOverride=!1,this.callEvent("drumchange",{channel:t,isDrumChannel:e.drumChannel}),this.sendChannelProperties())}function Jo(){let t=this.soundfontManager.getPresetList();this.overrideSoundfont!==void 0&&this.overrideSoundfont.presets.forEach(A=>{let e=A.bank===128?128:A.bank+this.soundfontBankOffset,s=t.find(n=>n.bank===e&&n.program===A.program);s!==void 0?s.presetName=A.presetName:t.push({presetName:A.presetName,bank:e,program:A.program})}),this.callEvent("presetlistchange",t)}function Po(t=!0,A=!0){this.stopAllChannels(!0),A&&(delete this.overrideSoundfont,this.overrideSoundfont=void 0),this.defaultPreset=this.getPreset(0,0),this.drumPreset=this.getPreset(128,0);for(let e=0;e{this.programChange(s,e.preset.program)}),this.post({messageType:DA.ready,messageData:void 0}),this.sendPresetList(),p("%cSpessaSynth is ready!",g.recognized)}function Oo(t,A){this.soundfontBankOffset=A,this.reloadSoundFont(t,!0),this.overrideSoundfont.samples.forEach(e=>e.getAudioData()),this._snapshot!==void 0&&(this.applySynthesizerSnapshot(this._snapshot),this.resetAllControllers())}function Vo(){let A={channelSnapshots:this.workletProcessorChannels.map(e=>({program:e.preset.program,bank:XA(e),lockPreset:e.lockPreset,patchName:e.preset.presetName,midiControllers:e.midiControllers,lockedControllers:e.lockedControllers,customControllers:e.customControllers,channelVibrato:e.channelVibrato,lockVibrato:e.lockGSNRPNParams,channelTransposeKeyShift:e.channelTransposeKeyShift,channelOctaveTuning:e.channelOctaveTuning,keyCentTuning:e.keyCentTuning,velocityOverride:e.velocityOverride,isMuted:e.isMuted,drumChannel:e.drumChannel})),mainVolume:this.midiVolume,pan:this.pan,transposition:this.transposition,system:this.system,interpolation:this.interpolationType,keyMappings:this.keyModifierManager.getMappings()};this.post({messageType:DA.synthesizerSnapshot,messageData:A})}function Ko(t){for(this.system=t.system,this.setMasterGain(t.mainVolume),this.setMasterPan(t.pan),this.transposeAllChannels(t.transposition),this.interpolationType=t.interpolation,this.keyModifierManager.setMappings(t.keyMappings);this.workletProcessorChannels.length{let s=this.workletProcessorChannels[e];this.muteChannel(e,A.isMuted),this.setDrums(e,A.drumChannel),s.midiControllers=A.midiControllers,s.lockedControllers=A.lockedControllers,s.customControllers=A.customControllers,s.channelVibrato=A.channelVibrato,s.lockGSNRPNParams=A.lockVibrato,s.channelTransposeKeyShift=A.channelTransposeKeyShift,s.channelOctaveTuning=A.channelOctaveTuning,s.velocityOverride=A.velocityOverride,s.lockPreset=!1,se(s,A.bank),this.programChange(e,A.program),s.lockPreset=A.lockPreset}),p("%cFinished restoring controllers!",g.info)}var ft=class{constructor(A,e){this.ready=e,this.totalSoundfontOffset=0,this.reloadManager(A)}_assingSampleOffsets(){let A=0;this.soundfontList.forEach(e=>{e.soundfont.setSampleIDOffset(A),A+=e.soundfont.samples.length}),this.totalSoundfontOffset=A}generatePresetList(){this._assingSampleOffsets();let A={};for(let e=this.soundfontList.length-1;e>=0;e--){let s=this.soundfontList[e],n=new Set;for(let o of s.soundfont.presets){let i=`${o.bank+s.bankOffset}-${o.program}`;n.has(i)||(n.add(i),A[i]=o.presetName)}}this.presetList=[];for(let[e,s]of Object.entries(A)){let n=e.split("-");this.presetList.push({presetName:s,program:parseInt(n[1]),bank:parseInt(n[0])})}}handleMessage(A,e){switch(A){case pe.addNewSoundFont:this.addNewSoundFont(e[0],e[1],e[2]);break;case pe.reloadSoundFont:this.reloadManager(e);break;case pe.deleteSoundFont:this.deleteSoundFont(e);break;case pe.rearrangeSoundFonts:this.rearrangeSoundFonts(e)}}getPresetList(){return this.presetList.slice()}reloadManager(A){let e=He(A);this.soundfontList=[],this.soundfontList.push({id:"main",bankOffset:0,soundfont:e}),this.generatePresetList(),this.ready()}deleteSoundFont(A){if(this.soundfontList.length===0){T("1 soundfont left. Aborting!");return}let e=this.soundfontList.findIndex(s=>s.id===A);if(e===-1){T(`No soundfont with id of "${A}" found. Aborting!`);return}delete this.soundfontList[e].soundfont.presets,delete this.soundfontList[e].soundfont.instruments,delete this.soundfontList[e].soundfont.samples,this.soundfontList.splice(e,1),this.generatePresetList()}addNewSoundFont(A,e,s){if(this.soundfontList.find(n=>n.id===e)!==void 0)throw new Error("Cannot overwrite the existing soundfont. Use soundfontManager.delete(id) instead.");this.soundfontList.push({id:e,soundfont:He(A),bankOffset:s}),this.generatePresetList(),this.ready()}rearrangeSoundFonts(A){this.soundfontList.sort((e,s)=>A.indexOf(e.id)-A.indexOf(s.id)),this.generatePresetList()}getPreset(A,e){if(this.soundfontList.length<1)throw new Error("No soundfonts! This should never happen.");for(let s of this.soundfontList){let n=s.soundfont.getPresetNoFallback(A-s.bankOffset,e);if(n!==void 0)return n}if(A!==128){for(let s of this.soundfontList){let n=s.soundfont.presets.find(o=>o.program===e);if(n)return n}return this.soundfontList[0].soundfont.presets[0]}else{for(let s of this.soundfontList){let n=s.soundfont.presets.find(o=>o.bank===128);if(n)return n}return this.soundfontList[0].soundfont.presets[0]}}destroyManager(){this.soundfontList.forEach(A=>{A.soundfont.destroySoundfont()}),delete this.soundfontList}};var mt=class{sampleData;playbackStep=0;cursor=0;rootKey=0;loopStart=0;loopEnd=0;end=0;loopingMode=0;isLooping=!1;constructor(A,e,s,n,o,i,a,C){this.sampleData=A,this.playbackStep=e,this.cursor=s,this.rootKey=n,this.loopStart=o,this.loopEnd=i,this.end=a,this.loopingMode=C,this.isLooping=this.loopingMode===1||this.loopingMode===3}},Ye=class t{sample;filter=new we;generators;modulators=[];modulatedGenerators;finished=!1;isInRelease=!1;channelNumber=0;velocity=0;midiNote=0;pressure=0;targetKey=0;modulationEnvelope=new PA;volumeEnvelope;startTime=0;releaseStartTime=1/0;currentTuningCents=0;currentTuningCalculated=1;currentPan=.5;realKey;constructor(A,e,s,n,o,i,a,C,B,d){this.sample=e,this.generators=B,this.modulatedGenerators=new Int16Array(B),this.modulators=d,this.velocity=n,this.midiNote=s,this.channelNumber=o,this.startTime=i,this.targetKey=a,this.realKey=C,this.volumeEnvelope=new qA(A,B[r.sustainVolEnv])}static copy(A,e){let s=A.sample,n=new mt(s.sampleData,s.playbackStep,s.cursor,s.rootKey,s.loopStart,s.loopEnd,s.end,s.loopingMode);return new t(A.volumeEnvelope.sampleRate,n,A.midiNote,A.velocity,A.channelNumber,e,A.targetKey,A.realKey,A.generators,A.modulators.map(o=>P.copy(o)))}};function Zo(t,A,e,s,n,o,i=!1){let a,C=s.cachedVoices[A]?.[e],B=this.keyModifierManager.hasOverridePatch(t,A);if(C!==void 0&&!B)return C.map(l=>Ye.copy(l,n));let d=!0,Q=s.preset;if(B){d=!1;let l=this.keyModifierManager.getPatch(t,A);Q=this.soundfontManager.getPreset(l.bank,l.program)}return a=Q.getSamplesAndGenerators(A,e).reduce((l,c)=>{if(c.sample.sampleData===void 0)return T(`Discarding invalid sample: ${c.sample.sampleName}`),l;let f=new Int16Array(60);for(let G=0;G<60;G++)f[G]=bs(G,c.presetGenerators,c.instrumentGenerators);f[r.initialAttenuation]=Math.floor(f[r.initialAttenuation]*.4);let y=c.sample.samplePitch;f[r.overridingRootKey]>-1&&(y=f[r.overridingRootKey]);let S=A;f[r.keyNum]>-1&&(S=f[r.keyNum]);let w=c.sample.sampleLoopStartIndex,H=c.sample.sampleLoopEndIndex,R=f[r.sampleModes],x=new mt(c.sample.getAudioData(),c.sample.sampleRate/sampleRate*Math.pow(2,c.sample.samplePitchCorrection/1200),0,y,w,H,Math.floor(c.sample.sampleData.length)-1,R);return f[r.velocity]>-1&&(e=f[r.velocity]),i&&Ns([{Sample:c.sample.sampleName,Generators:f,Modulators:c.modulators.map(G=>G.debugString()),Velocity:e,TargetKey:S,MidiNote:A,WorkletSample:x}]),l.push(new Ye(sampleRate,x,A,e,t,n,S,o,f,c.modulators.map(G=>P.copy(G)))),l},[]),d&&(s.cachedVoices[A][e]=a.map(l=>Ye.copy(l,n))),a}var Fr=4600,Rr=2e3,Wo=Math.PI/2;function Xo(t,A,e,s,n,o){if(isNaN(A[0]))return;let i=(Math.max(-500,Math.min(500,t.modulatedGenerators[r.pan]))+500)/1e3;t.currentPan+=(i-t.currentPan)*this.panSmoothingFactor;let a=this.currentGain,C=Math.cos(Wo*t.currentPan)*a*this.panLeft,B=Math.sin(Wo*t.currentPan)*a*this.panRight,d=this.reverbGain*t.modulatedGenerators[r.reverbEffectsSend]/Fr*a,Q=this.chorusGain*t.modulatedGenerators[r.chorusEffectsSend]/Rr;if(d>0&&!this.oneOutputMode){let l=n[0],c=n[1];for(let f=0;f0&&!this.oneOutputMode){let l=o[0],c=o[1],f=C*Q,y=B*Q;for(let S=0;S0)for(let l=0;l0)for(let l=0;lthis.handleMessage(e.data),A.processorOptions.startRenderingData&&(this._snapshot!==void 0&&(this.applySynthesizerSnapshot(this._snapshot),this.resetAllControllers()),p("%cRendering enabled! Starting render.",g.info),A.processorOptions.startRenderingData.parsedMIDI&&(A.processorOptions.startRenderingData?.loopCount!==void 0?(this.sequencer.loopCount=A.processorOptions.startRenderingData?.loopCount,this.sequencer.loop=!0):this.sequencer.loop=!1,this.sequencer.loadNewSongList([A.processorOptions.startRenderingData.parsedMIDI]))),zA.isInitialized.then(()=>{this.postReady(),p("%cSpessaSynth is ready!",g.recognized)})}get currentGain(){return this.masterGain*this.midiVolume}post(A){this.enableEventSystem&&this.port.postMessage(A)}postReady(){this.enableEventSystem&&this.port.postMessage({messageType:DA.ready,messageData:void 0})}debugMessage(){p({channels:this.workletProcessorChannels,voicesAmount:this.totalVoicesAmount,outputAmount:this._outputsAmount,dumpedSamples:this.workletDumpedSamplesList})}process(A,e){if(!this.alive)return!1;this.processTickCallback&&this.processTickCallback();let s=0;return this.workletProcessorChannels.forEach((n,o)=>{if(n.voices.length<1||n.isMuted)return;let i,a,C,B,d;if(this.oneOutputMode){let l=e[0];i=o%16*2,a=l[i],C=l[i+1]}else i=o%this._outputsAmount+2,a=e[i][0],C=e[i][1],B=e[0],d=e[1];let Q=n.voices;n.voices=[],Q.forEach(l=>{this.renderVoice(n,l,a,C,B,d),l.finished||n.voices.push(l)}),s+=n.voices.length}),s!==this.totalVoicesAmount&&(this.totalVoicesAmount=s,this.sendChannelProperties()),!0}destroyWorkletProcessor(){this.alive=!1,this.workletProcessorChannels.forEach(A=>{delete A.midiControllers,delete A.voices,delete A.sustainedVoices,delete A.cachedVoices,delete A.lockedControllers,delete A.preset,delete A.customControllers}),delete this.workletProcessorChannels,delete this.sequencer.midiData,delete this.sequencer,this.soundfontManager.destroyManager(),delete this.soundfontManager}};O.prototype.renderVoice=hn;O.prototype.releaseVoice=ln;O.prototype.voiceKilling=cn;O.prototype.getWorkletVoices=Zo;O.prototype.handleMessage=fn;O.prototype.sendChannelProperties=pn;O.prototype.callEvent=mn;O.prototype.systemExclusive=yn;O.prototype.noteOn=Dn;O.prototype.noteOff=wn;O.prototype.polyPressure=Hn;O.prototype.killNote=Fn;O.prototype.stopAll=Rn;O.prototype.stopAllChannels=Gn;O.prototype.muteChannel=Vn;O.prototype.setVibrato=Zn;O.prototype.disableAndLockGSNRPN=Kn;O.prototype.dataEntryCoarse=Wn;O.prototype.dataEntryFine=Xn;O.prototype.createWorkletChannel=Ls;O.prototype.controllerChange=Jn;O.prototype.channelPressure=vn;O.prototype.resetAllControllers=_n;O.prototype.resetControllers=zn;O.prototype.resetParameters=jn;O.prototype.setMasterGain=qn;O.prototype.setMasterPan=On;O.prototype.setMIDIVolume=Pn;O.prototype.transposeAllChannels=Mn;O.prototype.transposeChannel=xn;O.prototype.setChannelTuning=Nn;O.prototype.setChannelTuningSemitones=bn;O.prototype.setMasterTuning=Ln;O.prototype.setModulationDepth=Un;O.prototype.pitchWheel=Tn;O.prototype.setOctaveTuning=Yn;O.prototype.programChange=To;O.prototype.getPreset=vo;O.prototype.setPreset=Ho;O.prototype.setDrums=Yo;O.prototype.reloadSoundFont=qo;O.prototype.clearSoundFont=Po;O.prototype.setEmbeddedSoundFont=Oo;O.prototype.sendPresetList=Jo;O.prototype.sendSynthesizerSnapshot=Vo;O.prototype.applySynthesizerSnapshot=Ko;O.prototype.panVoice=Xo;registerProcessor(Us,O);p("%cProcessor succesfully registered!",g.recognized); +Converted from DLS to SF2 with SpessaSynth`;for(let[C,B]of Object.entries(this.soundFontInfo))p(`%c"${C}": %c"${B}"`,g.info,g.recognized);let o=n.find(C=>C.header==="colh");o||(O(),this.parsingError("No colh chunk!")),this.instrumentAmount=F(o.chunkData,4),p(`%cInstruments amount: %c${this.instrumentAmount}`,g.info,g.recognized);let i=MA(n,"wvpl");i||(O(),this.parsingError("No wvpl chunk!")),this.readDLSSamples(i);let a=MA(n,"lins");a||(O(),this.parsingError("No lins chunk!")),this.readDLSInstrumentList(a),this.presets.sort((C,B)=>C.program-B.program+(C.bank-B.bank)),p(`%cParsing finished! %c"${this.soundFontInfo.INAM||"UNNAMED"}"%c has %c${this.presets.length} %cpresets, + %c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info),O()}verifyHeader(A,e){A.header.toLowerCase()!==e.toLowerCase()&&(O(),this.parsingError(`Invalid DLS chunk header! Expected "${e.toLowerCase()}" got "${A.header.toLowerCase()}"`))}verifyText(A,e){A.toLowerCase()!==e.toLowerCase()&&(O(),this.parsingError(`FourCC error: Expected "${e.toLowerCase()}" got "${A.toLowerCase()}"`))}parsingError(A){throw new Error(`DLS parse error: ${A} The file may be corrupted.`)}destroySoundfont(){super.destroySoundfont(),delete this.dataArray}};ee.prototype.readDLSInstrumentList=ko;ee.prototype.readDLSInstrument=wo;ee.prototype.readRegion=Mo;ee.prototype.readLart=Go;ee.prototype.readDLSSamples=No;var $t=class extends re{constructor(A,e,n,s,o,i,a,C,B,d,Q,l,c){super(A,i,a,C,B,d,s-e/2,o-e/2),this.sampleName=A,this.sampleStartIndex=e,this.sampleEndIndex=n,this.isSampleLoaded=!1,this.sampleID=l,this.sampleLength=this.sampleEndIndex-this.sampleStartIndex,this.sampleDataArray=Q,this.sampleData=new Float32Array(0),this.isCompressed&&(this.sampleLoopStartIndex+=this.sampleStartIndex/2,this.sampleLoopEndIndex+=this.sampleStartIndex/2,this.sampleLength=99999999),this.isDataRaw=c}getRawData(){let A=this.sampleDataArray;if(this.isCompressed){if(this.compressedData)return this.compressedData;let e=A.currentIndex;return A.slice(this.sampleStartIndex/2+e,this.sampleEndIndex/2+e)}else{this.isDataRaw||super.getRawData();let e=A.currentIndex;return A.slice(e+this.sampleStartIndex,e+this.sampleEndIndex)}}decodeVorbis(){if(this.sampleLength<1)return;let A=this.sampleDataArray,e=A.currentIndex,n=A.slice(this.sampleStartIndex/2+e,this.sampleEndIndex/2+e);this.sampleData=new Float32Array(0);try{let s=zA.decode(n.buffer);this.sampleData=s.data[0]}catch(s){T(`Error decoding sample ${this.sampleName}: ${s}`),this.sampleData=new Float32Array(this.sampleLoopEndIndex+1)}}getAudioData(){return this.isSampleLoaded?this.sampleData:this.sampleLength<1?new Float32Array(1):this.isCompressed?(this.decodeVorbis(),this.isSampleLoaded=!0,this.sampleData):this.isDataRaw?this.loadUncompressedData():this.getUncompressedReadyData()}loadUncompressedData(){if(this.isCompressed)return T("Trying to load a compressed sample via loadUncompressedData()... aborting!"),new Float32Array(0);let A=new Float32Array(this.sampleLength/2),e=this.sampleDataArray.currentIndex,n=new Int16Array(this.sampleDataArray.slice(e+this.sampleStartIndex,e+this.sampleEndIndex).buffer);for(let s=0;st.chunkData.currentIndex;){let o=Rr(s,t.chunkData,A,e);n.push(o),s++}return n.length>1&&n.pop(),n}function Rr(t,A,e,n){let s=_(A,20),o=F(A,4)*2,i=F(A,4)*2,a=F(A,4),C=F(A,4),B=F(A,4),d=A[A.currentIndex++];d===255&&(d=60);let Q=On(A[A.currentIndex++]),l=F(A,2),c=F(A,2);return new $t(s,o,i,a,C,B,d,Q,l,c,e,t,n)}var An=class extends N{constructor(A){super();let e=A.currentIndex;this.generatorType=A[e+1]<<8|A[e],this.generatorValue=se(A[e+2],A[e+3]),A.currentIndex+=4}};function en(t){let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(new An(t.chunkData));return A.length>1&&A.pop(),A}var tn=class extends ie{constructor(A){super(),this.instrumentName=_(A.chunkData,20).trim(),this.instrumentZoneIndex=F(A.chunkData,2),this.instrumentZonesAmount=0}getInstrumentZones(A,e){this.instrumentZonesAmount=A;for(let n=this.instrumentZoneIndex;nt.chunkData.currentIndex;){let n=new tn(t);if(e.length>0){let s=n.instrumentZoneIndex-e[e.length-1].instrumentZoneIndex;e[e.length-1].getInstrumentZones(s,A)}e.push(n)}return e.length>1&&e.pop(),e}var nn=class extends FA{constructor(A){super(),this.generatorZoneStartIndex=F(A,2),this.modulatorZoneStartIndex=F(A,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(A,e){this.modulatorZoneSize=A,this.generatorZoneSize=e}getGenerators(A){for(let e=this.generatorZoneStartIndex;en.generatorType===r.sampleID);e&&(this.sample=A[e.generatorValue],this.isGlobal=!1,this.sample.useCount++)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===r.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===r.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function Uo(t,A,e,n){let s=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new nn(t.chunkData);if(s.length>0){let i=o.modulatorZoneStartIndex-s[s.length-1].modulatorZoneStartIndex,a=o.generatorZoneStartIndex-s[s.length-1].generatorZoneStartIndex;s[s.length-1].setZoneSize(i,a),s[s.length-1].getGenerators(A),s[s.length-1].getModulators(e),s[s.length-1].getSample(n),s[s.length-1].getKeyRange(),s[s.length-1].getVelRange()}s.push(o)}return s.length>1&&s.pop(),s}var sn=class extends oe{constructor(A){super(),this.generatorZoneStartIndex=F(A,2),this.modulatorZoneStartIndex=F(A,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(A,e){this.modulatorZoneSize=A,this.generatorZoneSize=e}getGenerators(A){for(let e=this.generatorZoneStartIndex;en.generatorType===r.instrument);e&&(this.instrument=A[e.generatorValue],this.instrument.addUseCount(),this.isGlobal=!1)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===r.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===r.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function To(t,A,e,n){let s=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new sn(t.chunkData);if(s.length>0){let i=o.modulatorZoneStartIndex-s[s.length-1].modulatorZoneStartIndex,a=o.generatorZoneStartIndex-s[s.length-1].generatorZoneStartIndex;s[s.length-1].setZoneSize(i,a),s[s.length-1].getGenerators(A),s[s.length-1].getModulators(e),s[s.length-1].getInstrument(n),s[s.length-1].getKeyRange(),s[s.length-1].getVelRange()}s.push(o)}return s.length>1&&s.pop(),s}var on=class extends ae{constructor(A,e){super(e),this.presetName=_(A.chunkData,20).trim().replace(/\d{3}:\d{3}/,""),this.program=F(A.chunkData,2),this.bank=F(A.chunkData,2),this.presetZoneStartIndex=F(A.chunkData,2),this.library=F(A.chunkData,4),this.genre=F(A.chunkData,4),this.morphology=F(A.chunkData,4),this.presetZonesAmount=0}getPresetZones(A,e){this.presetZonesAmount=A;for(let n=this.presetZoneStartIndex;nt.chunkData.currentIndex;){let s=new on(t,e);if(n.length>0){let o=s.presetZoneStartIndex-n[n.length-1].presetZoneStartIndex;n[n.length-1].getPresetZones(o,A)}n.push(s)}return n.length>1&&n.pop(),n}var rn=class extends P{constructor(A){super({srcEnum:F(A,2),dest:F(A,2),amt:se(A[A.currentIndex++],A[A.currentIndex++]),secSrcEnum:F(A,2),transform:F(A,2)})}};function ut(t){let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(new rn(t.chunkData));return A}var dt=class extends ge{constructor(A,e=!0){super(),e&&console.warn("Using the constructor directly is deprecated. Use loadSoundFont instead."),this.dataArray=new b(A),Ce("%cParsing SoundFont...",g.info),this.dataArray||(O(),this.parsingError("No data provided!"));let n=z(this.dataArray,!1);this.verifyHeader(n,"riff");let s=_(this.dataArray,4).toLowerCase();if(s!=="sfbk"&&s!=="sfpk")throw O(),new SyntaxError(`Invalid soundFont! Expected "sfbk" or "sfpk" got "${s}"`);let o=s==="sfpk",i=z(this.dataArray);for(this.verifyHeader(i,"list"),_(i.chunkData,4);i.chunkData.length>i.chunkData.currentIndex;){let $=z(i.chunkData),IA;switch($.header.toLowerCase()){case"ifil":case"iver":IA=`${F($.chunkData,2)}.${F($.chunkData,2)}`,this.soundFontInfo[$.header]=IA;break;case"icmt":IA=_($.chunkData,$.chunkData.length,void 0,!1),this.soundFontInfo[$.header]=IA;break;case"dmod":let sA=ut($);sA.pop(),IA=`Modulators: ${sA.length}`;let iA=this.defaultModulators;this.defaultModulators=sA,this.defaultModulators.push(...iA.filter(eA=>!this.defaultModulators.find(lA=>P.isIdentical(eA,lA)))),this.soundFontInfo[$.header]=$.chunkData;break;default:IA=_($.chunkData,$.chunkData.length),this.soundFontInfo[$.header]=IA}p(`%c"${$.header}": %c"${IA}"`,g.info,g.recognized)}let a=z(this.dataArray,!1);this.verifyHeader(a,"list"),this.verifyText(_(this.dataArray,4),"sdta"),p("%cVerifying smpl chunk...",g.warn);let C=z(this.dataArray,!1);this.verifyHeader(C,"smpl");let B;if(o){p("%cSF2Pack detected, attempting to decode the smpl chunk...",g.info);try{B=zA.decode(this.dataArray.buffer.slice(this.dataArray.currentIndex,this.dataArray.currentIndex+a.size-12)).data[0]}catch($){throw O(),new Error(`SF2Pack Ogg Vorbis decode error: ${$}`)}p(`%cDecoded the smpl chunk! Length: %c${B.length}`,g.info,g.value)}else B=this.dataArray,this.sampleDataStartIndex=this.dataArray.currentIndex;p(`%cSkipping sample chunk, length: %c${a.size-12}`,g.info,g.value),this.dataArray.currentIndex+=a.size-12,p("%cLoading preset data chunk...",g.warn);let d=z(this.dataArray);this.verifyHeader(d,"list"),_(d.chunkData,4);let Q=z(d.chunkData);this.verifyHeader(Q,"phdr");let l=z(d.chunkData);this.verifyHeader(l,"pbag");let c=z(d.chunkData);this.verifyHeader(c,"pmod");let f=z(d.chunkData);this.verifyHeader(f,"pgen");let y=z(d.chunkData);this.verifyHeader(y,"inst");let S=z(d.chunkData);this.verifyHeader(S,"ibag");let w=z(d.chunkData);this.verifyHeader(w,"imod");let H=z(d.chunkData);this.verifyHeader(H,"igen");let R=z(d.chunkData);this.verifyHeader(R,"shdr"),this.dataArray.currentIndex=this.sampleDataStartIndex,this.samples.push(...bo(R,B,!o));let x=en(H),G=ut(w),I=Uo(S,x,G,this.samples);this.instruments=Lo(y,I);let rA=en(f),Z=ut(c),AA=To(l,rA,Z,this.instruments);this.presets.push(...vo(Q,AA,this.defaultModulators)),this.presets.sort(($,IA)=>$.program-IA.program+($.bank-IA.bank)),p(`%cParsing finished! %c"${this.soundFontInfo.INAM}"%c has %c${this.presets.length} %cpresets, + %c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info,g.recognized,g.info),O(),o&&delete this.dataArray}verifyHeader(A,e){A.header.toLowerCase()!==e.toLowerCase()&&(O(),this.parsingError(`Invalid chunk header! Expected "${e.toLowerCase()}" got "${A.header.toLowerCase()}"`))}verifyText(A,e){A.toLowerCase()!==e.toLowerCase()&&(O(),this.parsingError(`Invalid FourCC: Expected "${e.toLowerCase()}" got "${A.toLowerCase()}"\``))}destroySoundfont(){super.destroySoundfont(),delete this.dataArray}};function He(t){let A=t.slice(8,12),e=new b(A);return _(e,4,void 0,!1).toLowerCase()==="dls "?new ee(t):new dt(t,!1)}function Ho(t,A,e=!1){let n=this.workletProcessorChannels[t];if(n===void 0){T(`Trying to access channel ${t} which does not exist... ignoring!`);return}if(n.lockPreset)return;let s=XA(n),o,i;if(this.overrideSoundfont){let a=s===128?128:s-this.soundfontBankOffset,C=this.overrideSoundfont.getPresetNoFallback(a,A);C?(o=s,i=C,n.presetUsesOverride=!0):(i=this.soundfontManager.getPreset(s,A),o=i.bank,n.presetUsesOverride=!1)}else i=this.soundfontManager.getPreset(s,A),o=i.bank,n.presetUsesOverride=!1;this.setPreset(t,i),this.callEvent("programchange",{channel:t,program:i.program,bank:o,userCalled:e})}function Yo(t,A){if(this.overrideSoundfont){let e=t===128?128:t-this.soundfontBankOffset,n=this.overrideSoundfont.getPresetNoFallback(e,A);if(n)return n}return this.soundfontManager.getPreset(t,A)}function Jo(t,A){if(!this.workletProcessorChannels[t].lockPreset){delete this.workletProcessorChannels[t].preset,this.workletProcessorChannels[t].preset=A,this.workletProcessorChannels[t].cachedVoices=[];for(let e=0;e<128;e++)this.workletProcessorChannels[t].cachedVoices.push([])}}function Po(t,A){let e=this.workletProcessorChannels[t];e.lockPreset||e.drumChannel!==A&&(A?(e.channelTransposeKeyShift=0,e.drumChannel=!0,this.setPreset(t,this.getPreset(XA(e),e.preset.program))):(e.drumChannel=!1,this.setPreset(t,this.getPreset(XA(e),e.preset.program))),e.presetUsesOverride=!1,this.callEvent("drumchange",{channel:t,isDrumChannel:e.drumChannel}),this.sendChannelProperties())}function qo(){let t=this.soundfontManager.getPresetList();this.overrideSoundfont!==void 0&&this.overrideSoundfont.presets.forEach(A=>{let e=A.bank===128?128:A.bank+this.soundfontBankOffset,n=t.find(s=>s.bank===e&&s.program===A.program);n!==void 0?n.presetName=A.presetName:t.push({presetName:A.presetName,bank:e,program:A.program})}),this.callEvent("presetlistchange",t)}function Vo(t=!0,A=!0){this.stopAllChannels(!0),A&&(delete this.overrideSoundfont,this.overrideSoundfont=void 0),this.defaultPreset=this.getPreset(0,0),this.drumPreset=this.getPreset(128,0);for(let e=0;e{this.programChange(n,e.preset.program)}),this.post({messageType:DA.ready,messageData:void 0}),this.sendPresetList(),p("%cSpessaSynth is ready!",g.recognized)}function Ko(t,A){this.soundfontBankOffset=A,this.reloadSoundFont(t,!0),this.overrideSoundfont.samples.forEach(e=>e.getAudioData()),this._snapshot!==void 0&&(this.applySynthesizerSnapshot(this._snapshot),this.resetAllControllers())}var ft=class t{program;bank;patchName;lockPreset;midiControllers;lockedControllers;customControllers;lockVibrato;channelVibrato;channelTransposeKeyShift;channelOctaveTuning;keyCentTuning;isMuted;velocityOverride;drumChannel;static getChannelSnapshot(A,e){let n=A.workletProcessorChannels[e],s=new t;return s.program=n.preset.program,s.bank=XA(n),s.lockPreset=n.lockPreset,s.patchName=n.preset.presetName,s.midiControllers=n.midiControllers,s.lockedControllers=n.lockedControllers,s.customControllers=n.customControllers,s.channelVibrato=n.channelVibrato,s.lockVibrato=n.lockGSNRPNParams,s.channelTransposeKeyShift=n.channelTransposeKeyShift,s.channelOctaveTuning=n.channelOctaveTuning,s.keyCentTuning=n.keyCentTuning,s.isMuted=n.isMuted,s.velocityOverride=n.velocityOverride,s.drumChannel=n.drumChannel,s}static applyChannelSnapshot(A,e,n){let s=A.workletProcessorChannels[e];A.muteChannel(e,n.isMuted),A.setDrums(e,n.drumChannel),s.midiControllers=n.midiControllers,s.lockedControllers=n.lockedControllers,s.customControllers=n.customControllers,s.channelVibrato=n.channelVibrato,s.lockGSNRPNParams=n.lockVibrato,s.channelTransposeKeyShift=n.channelTransposeKeyShift,s.channelOctaveTuning=n.channelOctaveTuning,s.velocityOverride=n.velocityOverride,s.lockPreset=!1,ne(s,n.bank),A.programChange(e,n.program),s.lockPreset=n.lockPreset}},mt=class t{channelSnapshots;keyMappings;mainVolume;pan;interpolation;system;transposition;effectsConfig;static createSynthesizerSnapshot(A){let e=new t;return e.channelSnapshots=A.workletProcessorChannels.map((n,s)=>ft.getChannelSnapshot(A,s)),e.keyMappings=A.keyModifierManager.getMappings(),e.mainVolume=A.midiVolume,e.pan=A.pan,e.system=A.system,e.interpolation=A.interpolationType,e.transposition=A.transposition,e.effectsConfig={},e}static applySnapshot(A,e){for(A.system=e.system,A.setMasterGain(e.mainVolume),A.setMasterPan(e.pan),A.transposeAllChannels(e.transposition),A.interpolationType=e.interpolation,A.keyModifierManager.setMappings(e.keyMappings);A.workletProcessorChannels.length{ft.applyChannelSnapshot(A,s,n)}),p("%cFinished restoring controllers!",g.info)}};function Zo(){this.post({messageType:DA.synthesizerSnapshot,messageData:mt.createSynthesizerSnapshot(this)})}function Wo(t){mt.applySnapshot(this,t),p("%cFinished applying snapshot!",g.info)}var pt=class{constructor(A,e){this.ready=e,this.totalSoundfontOffset=0,this.reloadManager(A)}_assingSampleOffsets(){let A=0;this.soundfontList.forEach(e=>{e.soundfont.setSampleIDOffset(A),A+=e.soundfont.samples.length}),this.totalSoundfontOffset=A}generatePresetList(){this._assingSampleOffsets();let A={};for(let e=this.soundfontList.length-1;e>=0;e--){let n=this.soundfontList[e],s=new Set;for(let o of n.soundfont.presets){let i=`${o.bank+n.bankOffset}-${o.program}`;s.has(i)||(s.add(i),A[i]=o.presetName)}}this.presetList=[];for(let[e,n]of Object.entries(A)){let s=e.split("-");this.presetList.push({presetName:n,program:parseInt(s[1]),bank:parseInt(s[0])})}}handleMessage(A,e){switch(A){case pe.addNewSoundFont:this.addNewSoundFont(e[0],e[1],e[2]);break;case pe.reloadSoundFont:this.reloadManager(e);break;case pe.deleteSoundFont:this.deleteSoundFont(e);break;case pe.rearrangeSoundFonts:this.rearrangeSoundFonts(e)}}getPresetList(){return this.presetList.slice()}reloadManager(A){let e=He(A);this.soundfontList=[],this.soundfontList.push({id:"main",bankOffset:0,soundfont:e}),this.generatePresetList(),this.ready()}deleteSoundFont(A){if(this.soundfontList.length===0){T("1 soundfont left. Aborting!");return}let e=this.soundfontList.findIndex(n=>n.id===A);if(e===-1){T(`No soundfont with id of "${A}" found. Aborting!`);return}delete this.soundfontList[e].soundfont.presets,delete this.soundfontList[e].soundfont.instruments,delete this.soundfontList[e].soundfont.samples,this.soundfontList.splice(e,1),this.generatePresetList()}addNewSoundFont(A,e,n){if(this.soundfontList.find(s=>s.id===e)!==void 0)throw new Error("Cannot overwrite the existing soundfont. Use soundfontManager.delete(id) instead.");this.soundfontList.push({id:e,soundfont:He(A),bankOffset:n}),this.generatePresetList(),this.ready()}rearrangeSoundFonts(A){this.soundfontList.sort((e,n)=>A.indexOf(e.id)-A.indexOf(n.id)),this.generatePresetList()}getPreset(A,e){if(this.soundfontList.length<1)throw new Error("No soundfonts! This should never happen.");for(let n of this.soundfontList){let s=n.soundfont.getPresetNoFallback(A-n.bankOffset,e);if(s!==void 0)return s}if(A!==128){for(let n of this.soundfontList){let s=n.soundfont.presets.find(o=>o.program===e);if(s)return s}return this.soundfontList[0].soundfont.presets[0]}else{for(let n of this.soundfontList){let s=n.soundfont.presets.find(o=>o.bank===128);if(s)return s}return this.soundfontList[0].soundfont.presets[0]}}destroyManager(){this.soundfontList.forEach(A=>{A.soundfont.destroySoundfont()}),delete this.soundfontList}};var yt=class{sampleData;playbackStep=0;cursor=0;rootKey=0;loopStart=0;loopEnd=0;end=0;loopingMode=0;isLooping=!1;constructor(A,e,n,s,o,i,a,C){this.sampleData=A,this.playbackStep=e,this.cursor=n,this.rootKey=s,this.loopStart=o,this.loopEnd=i,this.end=a,this.loopingMode=C,this.isLooping=this.loopingMode===1||this.loopingMode===3}},Ye=class t{sample;filter=new we;generators;modulators=[];modulatedGenerators;finished=!1;isInRelease=!1;channelNumber=0;velocity=0;midiNote=0;pressure=0;targetKey=0;modulationEnvelope=new PA;volumeEnvelope;startTime=0;releaseStartTime=1/0;currentTuningCents=0;currentTuningCalculated=1;currentPan=.5;realKey;constructor(A,e,n,s,o,i,a,C,B,d){this.sample=e,this.generators=B,this.modulatedGenerators=new Int16Array(B),this.modulators=d,this.velocity=s,this.midiNote=n,this.channelNumber=o,this.startTime=i,this.targetKey=a,this.realKey=C,this.volumeEnvelope=new qA(A,B[r.sustainVolEnv])}static copy(A,e){let n=A.sample,s=new yt(n.sampleData,n.playbackStep,n.cursor,n.rootKey,n.loopStart,n.loopEnd,n.end,n.loopingMode);return new t(A.volumeEnvelope.sampleRate,s,A.midiNote,A.velocity,A.channelNumber,e,A.targetKey,A.realKey,A.generators,A.modulators.map(o=>P.copy(o)))}};function Xo(t,A,e,n,s,o,i=!1){let a,C=n.cachedVoices[A]?.[e],B=this.keyModifierManager.hasOverridePatch(t,A);if(C!==void 0&&!B)return C.map(l=>Ye.copy(l,s));let d=!0,Q=n.preset;if(B){d=!1;let l=this.keyModifierManager.getPatch(t,A);Q=this.soundfontManager.getPreset(l.bank,l.program)}return a=Q.getSamplesAndGenerators(A,e).reduce((l,c)=>{if(c.sample.sampleData===void 0)return T(`Discarding invalid sample: ${c.sample.sampleName}`),l;let f=new Int16Array(60);for(let G=0;G<60;G++)f[G]=Tn(G,c.presetGenerators,c.instrumentGenerators);f[r.initialAttenuation]=Math.floor(f[r.initialAttenuation]*.4);let y=c.sample.samplePitch;f[r.overridingRootKey]>-1&&(y=f[r.overridingRootKey]);let S=A;f[r.keyNum]>-1&&(S=f[r.keyNum]);let w=c.sample.sampleLoopStartIndex,H=c.sample.sampleLoopEndIndex,R=f[r.sampleModes],x=new yt(c.sample.getAudioData(),c.sample.sampleRate/sampleRate*Math.pow(2,c.sample.samplePitchCorrection/1200),0,y,w,H,Math.floor(c.sample.sampleData.length)-1,R);return f[r.velocity]>-1&&(e=f[r.velocity]),i&&Un([{Sample:c.sample.sampleName,Generators:f,Modulators:c.modulators.map(G=>G.debugString()),Velocity:e,TargetKey:S,MidiNote:A,WorkletSample:x}]),l.push(new Ye(sampleRate,x,A,e,t,s,S,o,f,c.modulators.map(G=>P.copy(G)))),l},[]),d&&(n.cachedVoices[A][e]=a.map(l=>Ye.copy(l,s))),a}var Gr=4600,Mr=2e3,_o=Math.PI/2;function zo(t,A,e,n,s,o){if(isNaN(A[0]))return;let i=(Math.max(-500,Math.min(500,t.modulatedGenerators[r.pan]))+500)/1e3;t.currentPan+=(i-t.currentPan)*this.panSmoothingFactor;let a=this.currentGain,C=Math.cos(_o*t.currentPan)*a*this.panLeft,B=Math.sin(_o*t.currentPan)*a*this.panRight,d=this.reverbGain*t.modulatedGenerators[r.reverbEffectsSend]/Gr*a,Q=this.chorusGain*t.modulatedGenerators[r.chorusEffectsSend]/Mr;if(d>0&&!this.oneOutputMode){let l=s[0],c=s[1];for(let f=0;f0&&!this.oneOutputMode){let l=o[0],c=o[1],f=C*Q,y=B*Q;for(let S=0;S0)for(let l=0;l0)for(let l=0;lthis.handleMessage(e.data),A.processorOptions.startRenderingData&&(this._snapshot!==void 0&&(this.applySynthesizerSnapshot(this._snapshot),this.resetAllControllers()),p("%cRendering enabled! Starting render.",g.info),A.processorOptions.startRenderingData.parsedMIDI&&(A.processorOptions.startRenderingData?.loopCount!==void 0?(this.sequencer.loopCount=A.processorOptions.startRenderingData?.loopCount,this.sequencer.loop=!0):this.sequencer.loop=!1,this.sequencer.loadNewSongList([A.processorOptions.startRenderingData.parsedMIDI]))),zA.isInitialized.then(()=>{this.postReady(),p("%cSpessaSynth is ready!",g.recognized)})}get currentGain(){return this.masterGain*this.midiVolume}post(A){this.enableEventSystem&&this.port.postMessage(A)}postReady(){this.enableEventSystem&&this.port.postMessage({messageType:DA.ready,messageData:void 0})}debugMessage(){p({channels:this.workletProcessorChannels,voicesAmount:this.totalVoicesAmount,outputAmount:this._outputsAmount,dumpedSamples:this.workletDumpedSamplesList})}process(A,e){if(!this.alive)return!1;this.processTickCallback&&this.processTickCallback();let n=0;return this.workletProcessorChannels.forEach((s,o)=>{if(s.voices.length<1||s.isMuted)return;let i,a,C,B,d;if(this.oneOutputMode){let l=e[0];i=o%16*2,a=l[i],C=l[i+1]}else i=o%this._outputsAmount+2,a=e[i][0],C=e[i][1],B=e[0],d=e[1];let Q=s.voices;s.voices=[],Q.forEach(l=>{this.renderVoice(s,l,a,C,B,d),l.finished||s.voices.push(l)}),n+=s.voices.length}),n!==this.totalVoicesAmount&&(this.totalVoicesAmount=n,this.sendChannelProperties()),!0}destroyWorkletProcessor(){this.alive=!1,this.workletProcessorChannels.forEach(A=>{delete A.midiControllers,delete A.voices,delete A.sustainedVoices,delete A.cachedVoices,delete A.lockedControllers,delete A.preset,delete A.customControllers}),delete this.workletProcessorChannels,delete this.sequencer.midiData,delete this.sequencer,this.soundfontManager.destroyManager(),delete this.soundfontManager}};V.prototype.renderVoice=ls;V.prototype.releaseVoice=us;V.prototype.voiceKilling=Qs;V.prototype.getWorkletVoices=Xo;V.prototype.handleMessage=ps;V.prototype.sendChannelProperties=Ss;V.prototype.callEvent=ys;V.prototype.systemExclusive=Ds;V.prototype.noteOn=ws;V.prototype.noteOff=Rs;V.prototype.polyPressure=Js;V.prototype.killNote=Gs;V.prototype.stopAll=Ms;V.prototype.stopAllChannels=xs;V.prototype.muteChannel=Zs;V.prototype.setVibrato=Xs;V.prototype.disableAndLockGSNRPN=Ws;V.prototype.dataEntryCoarse=_s;V.prototype.dataEntryFine=zs;V.prototype.createWorkletChannel=vn;V.prototype.controllerChange=qs;V.prototype.channelPressure=Ys;V.prototype.resetAllControllers=js;V.prototype.resetControllers=$s;V.prototype.resetParameters=Ao;V.prototype.setMasterGain=Os;V.prototype.setMasterPan=Ks;V.prototype.setMIDIVolume=Vs;V.prototype.transposeAllChannels=Ns;V.prototype.transposeChannel=bs;V.prototype.setChannelTuning=Ls;V.prototype.setChannelTuningSemitones=Us;V.prototype.setMasterTuning=Ts;V.prototype.setModulationDepth=vs;V.prototype.pitchWheel=Hs;V.prototype.setOctaveTuning=Ps;V.prototype.programChange=Ho;V.prototype.getPreset=Yo;V.prototype.setPreset=Jo;V.prototype.setDrums=Po;V.prototype.reloadSoundFont=Oo;V.prototype.clearSoundFont=Vo;V.prototype.setEmbeddedSoundFont=Ko;V.prototype.sendPresetList=qo;V.prototype.sendSynthesizerSnapshot=Zo;V.prototype.applySynthesizerSnapshot=Wo;V.prototype.panVoice=zo;registerProcessor(Hn,V);p("%cProcessor succesfully registered!",g.recognized); diff --git a/src/spessasynth_lib/synthetizer/worklet_system/main_processor.js b/src/spessasynth_lib/synthetizer/worklet_system/main_processor.js index 678c13b..848c9bb 100644 --- a/src/spessasynth_lib/synthetizer/worklet_system/main_processor.js +++ b/src/spessasynth_lib/synthetizer/worklet_system/main_processor.js @@ -46,7 +46,7 @@ import { setEmbeddedSoundFont, setPreset } from "./worklet_methods/program_control.js"; -import { applySynthesizerSnapshot, sendSynthesizerSnapshot } from "./worklet_methods/snapshot.js"; +import { applySynthesizerSnapshot, sendSynthesizerSnapshot } from "./snapshot/snapshot.js"; import { WorkletSoundfontManager } from "./worklet_methods/worklet_soundfont_manager/worklet_soundfont_manager.js"; import { interpolationTypes } from "./worklet_utilities/wavetable_oscillator.js"; import { WorkletKeyModifierManager } from "./worklet_methods/worklet_key_modifier.js";