spessasynth_lib 3.26.24 → 3.26.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spessasynth_lib",
|
|
3
|
-
"version": "3.26.
|
|
3
|
+
"version": "3.26.25",
|
|
4
4
|
"description": "MIDI and SoundFont2/DLS library for the browsers with no compromises",
|
|
5
5
|
"browser": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -31,7 +31,8 @@
|
|
|
31
31
|
"web-midi-api",
|
|
32
32
|
"player",
|
|
33
33
|
"soundfont2",
|
|
34
|
-
"soundfont3"
|
|
34
|
+
"soundfont3",
|
|
35
|
+
"audio-buffer-to-wav"
|
|
35
36
|
],
|
|
36
37
|
"author": {
|
|
37
38
|
"name": "spessasus",
|
|
@@ -10,8 +10,8 @@ import { audioToWav } from "spessasynth_core";
|
|
|
10
10
|
|
|
11
11
|
// noinspection JSUnusedGlobalSymbols
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param audioBuffer {AudioBuffer}
|
|
13
|
+
* Converts an audio buffer into a wave file
|
|
14
|
+
* @param audioBuffer {AudioBuffer} variable channels
|
|
15
15
|
* @param normalizeAudio {boolean} find the max sample point and set it to 1, and scale others with it
|
|
16
16
|
* @param channelOffset {number} channel offset and channel offset + 1 get saved
|
|
17
17
|
* @param metadata {WaveMetadata}
|
|
@@ -20,9 +20,16 @@ import { audioToWav } from "spessasynth_core";
|
|
|
20
20
|
*/
|
|
21
21
|
export function audioBufferToWav(audioBuffer, normalizeAudio = true, channelOffset = 0, metadata = {}, loop = undefined)
|
|
22
22
|
{
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
/**
|
|
24
|
+
* @type {Float32Array[]}
|
|
25
|
+
*/
|
|
26
|
+
const channels = [];
|
|
27
|
+
for (let i = 0; i < audioBuffer.numberOfChannels; i++)
|
|
28
|
+
{
|
|
29
|
+
channels.push(audioBuffer.getChannelData(channelOffset + i));
|
|
30
|
+
}
|
|
31
|
+
return new Blob(
|
|
32
|
+
[audioToWav(channels, audioBuffer.sampleRate, normalizeAudio, metadata, loop)],
|
|
33
|
+
{ type: "audio/wav" }
|
|
34
|
+
);
|
|
28
35
|
}
|
|
@@ -8,7 +8,7 @@ var Js=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(A,t)=>(
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
`}getSourceEnum(){return XA(this.sourceCurveType,this.sourcePolarity,this.sourceDirection,this.sourceUsesCC,this.sourceIndex)}getSecSrcEnum(){return XA(this.secSrcCurveType,this.secSrcPolarity,this.secSrcDirection,this.secSrcUsesCC,this.secSrcIndex)}sumTransform(A){return new e(this.sourceIndex,this.sourceCurveType,this.sourceUsesCC,this.sourcePolarity,this.sourceDirection,this.secSrcIndex,this.secSrcCurveType,this.secSrcUsesCC,this.secSrcPolarity,this.secSrcDirection,this.modulatorDestination,this.transformAmount+A.transformAmount,this.transformType,this.isEffectModulator)}},mA=class extends CA{constructor(A,t,n,s,o){let r=A>>9&1,g=A>>8&1,i=A>>7&1,E=A&127,B=A>>10&3,l=t>>9&1,c=t>>8&1,h=t>>7&1,u=t&127,f=t>>10&3;super(E,B,i,r,g,u,f,h,l,c,n,s,o),this.isEffectModulator=(A===219||A===221)&&t===0&&(this.modulatorDestination===a.reverbEffectsSend||this.modulatorDestination===a.chorusEffectsSend)}},gs=960,Is=DA.concave;function XA(e,A,t,n,s){return e<<10|A<<9|t<<8|n<<7|s}var Gi=[new mA(XA(Is,0,1,0,X.noteOnVelocity),0,a.initialAttenuation,gs,0),new mA(129,0,a.vibLfoToPitch,50,0),new mA(XA(Is,0,1,1,p.mainVolume),0,a.initialAttenuation,gs,0),new mA(13,0,a.vibLfoToPitch,50,0),new mA(526,16,a.fineTune,12700,0),new mA(650,0,a.pan,500,0),new mA(XA(Is,0,1,1,p.expressionController),0,a.initialAttenuation,gs,0),new mA(219,0,a.reverbEffectsSend,200,0),new mA(221,0,a.chorusEffectsSend,200,0)],Mi=[new mA(XA(DA.linear,0,0,0,X.polyPressure),0,a.vibLfoToPitch,50,0),new mA(XA(DA.linear,0,0,1,p.tremoloDepth),0,a.modLfoToVolume,24,0),new mA(XA(DA.convex,1,0,1,p.attackTime),0,a.attackVolEnv,6e3,0),new mA(XA(DA.linear,1,0,1,p.releaseTime),0,a.releaseVolEnv,3600,0),new mA(XA(DA.linear,1,0,1,p.brightness),0,a.initialFilterFc,6e3,0),new mA(XA(DA.linear,1,0,1,p.filterResonance),0,a.initialFilterQ,250,0)],so=Gi.concat(Mi);var cA=128,Cn=147,Oe=new Int16Array(Cn).fill(0),MA=(e,A)=>Oe[e]=A<<7;MA(p.mainVolume,100);MA(p.balance,64);MA(p.expressionController,127);MA(p.pan,64);MA(p.portamentoOnOff,127);MA(p.filterResonance,64);MA(p.releaseTime,64);MA(p.attackTime,64);MA(p.brightness,64);MA(p.decayTime,64);MA(p.vibratoRate,64);MA(p.vibratoDepth,64);MA(p.vibratoDelay,64);MA(p.generalPurposeController6,64);MA(p.generalPurposeController8,64);MA(p.RPNLsb,127);MA(p.RPNMsb,127);MA(p.NRPNLsb,127);MA(p.NRPNMsb,127);var cn=1;Oe[p.portamentoControl]=cn;MA(cA+X.pitchWheel,64);MA(cA+X.pitchWheelRange,2);var tA={channelTuning:0,channelTransposeFine:1,modulationMultiplier:2,masterTuning:3,channelTuningSemitones:4,channelKeyShift:5,sf2NPRNGeneratorLSB:6},Es=Object.keys(tA).length,Cs=new Float32Array(Es);Cs[tA.modulationMultiplier]=1;var vA={Idle:0,RPCoarse:1,RPFine:2,NRPCoarse:3,NRPFine:4,DataCoarse:5,DataFine:6},cs={velocityOverride:128};function oo(e,A,t){let n=e,s=A<<7|t;return e===127&&A===127&&t===127?{midiNote:-1,centTuning:null}:{midiNote:n,centTuning:s*.0061}}function ro(e,A=0){let t=e[0];if(this.deviceID!==-1&&e[1]!==127&&this.deviceID!==e[1])return;function n(o,r,g,i){y(`%cChannel %c${o}%c ${g}. %c${r} ${i}%c, with %c${YA(e)}`,I.info,I.recognized,I.info,I.value,I.info,I.value)}function s(){Y(`%cUnrecognized Roland %cGS %cSysEx: %c${YA(e)}`,I.warn,I.recognized,I.warn,I.unrecognized)}switch(t){default:Y(`%cUnrecognized SysEx: %c${YA(e)}`,I.warn,I.unrecognized);break;case 126:case 127:switch(e[2]){case 4:let o;switch(e[3]){case 1:let g=e[5]<<7|e[4];this.setMIDIVolume(g/16384),y(`%cMaster Volume. Volume: %c${g}`,I.info,I.value);break;case 2:let E=((e[5]<<7|e[4])-8192)/8192;this.setMasterParameter(JA.masterPan,E),y(`%cMaster Pan. Pan: %c${E}`,I.info,I.value);break;case 3:let B=(e[5]<<7|e[6])-8192;o=Math.floor(B/81.92),this.setMasterTuning(o),y(`%cMaster Fine Tuning. Cents: %c${o}`,I.info,I.value);break;case 4:o=(e[5]-64)*100,this.setMasterTuning(o),y(`%cMaster Coarse Tuning. Cents: %c${o}`,I.info,I.value);break;default:Y(`%cUnrecognized MIDI Device Control Real-time message: %c${YA(e)}`,I.warn,I.unrecognized)}break;case 9:e[3]===1?(y("%cGM1 system on",I.info),this.setSystem("gm")):e[3]===3?(y("%cGM2 system on",I.info),this.setSystem("gm2")):(y("%cGM system off, defaulting to GS",I.info),this.setSystem("gs"));break;case 8:let r=4;switch(e[3]){case 1:let g=e[r++];e.currentIndex=r;let i=AA(e,16);if(r+=16,e.length<384){Y(`The Bulk Tuning Dump is too short! (${e.length} bytes, at least 384 are expected)`);return}for(let c=0;c<128;c++)this.tunings[g][c]=oo(e[r++],e[r++],e[r++]);y(`%cBulk Tuning Dump %c${i}%c Program: %c${g}`,I.info,I.value,I.info,I.recognized);break;case 2:case 7:e[3]===7&&r++;let E=e[r++],B=e[r++];for(let c=0;c<B;c++)this.tunings[E][e[r++]]=oo(e[r++],e[r++],e[r++]);y(`%cSingle Note Tuning. Program: %c${E}%c Keys affected: %c${B}`,I.info,I.recognized,I.info,I.recognized);break;case 9:case 8:let l=new Int8Array(12);if(e[3]===8)for(let c=0;c<12;c++)l[c]=e[7+c]-64;else for(let c=0;c<24;c+=2){let h=(e[7+c]<<7|e[8+c])-8192;l[c/2]=Math.floor(h/81.92)}(e[4]&1)===1&&this.midiAudioChannels[14+A].setOctaveTuning(l),(e[4]>>1&1)===1&&this.midiAudioChannels[15+A].setOctaveTuning(l);for(let c=0;c<7;c++)(e[5]>>c&1)===1&&this.midiAudioChannels[7+c+A].setOctaveTuning(l);for(let c=0;c<7;c++)(e[6]>>c&1)===1&&this.midiAudioChannels[c+A].setOctaveTuning(l);y(`%cMIDI Octave Scale ${e[3]===8?"(1 byte)":"(2 bytes)"} tuning via Tuning: %c${l.join(" ")}`,I.info,I.value);break;default:Y(`%cUnrecognized MIDI Tuning standard message: %c${YA(e)}`,I.warn,I.unrecognized);break}break;default:Y(`%cUnrecognized MIDI Realtime/non realtime message: %c${YA(e)}`,I.warn,I.unrecognized)}break;case 65:if(e[2]===66&&e[3]===18){let o=e[7];if(e[4]===64||e[4]===0&&e[6]===127){if((e[5]&16)>0){let r=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][e[5]&15]+A,g=this.midiAudioChannels[r];switch(e[6]){default:s();break;case 21:let i=o>0&&e[5]>>4;g.setDrums(i),y(`%cChannel %c${r}%c ${i?"is now a drum channel":"now isn't a drum channel"}%c via: %c${YA(e)}`,I.info,I.value,I.recognized,I.info,I.value);return;case 22:let E=o-64;g.setCustomController(tA.channelKeyShift,E),n(r,E,"key shift","keys");return;case 28:let B=o;B===0?(g.randomPan=!0,y(`%cRandom pan is set to %cON%c for %c${r}`,I.info,I.recognized,I.info,I.value)):(g.randomPan=!1,g.controllerChange(p.pan,B));break;case 33:g.controllerChange(p.chorusDepth,o);break;case 34:g.controllerChange(p.reverbDepth,o);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 l=e.length-9,c=new Int8Array(12);for(let u=0;u<l;u++)c[u]=e[u+7]-64;g.setOctaveTuning(c);let h=o-64;n(r,c.join(" "),"octave scale tuning","cents"),g.setTuning(h);break}return}else if((e[5]&32)>0){let r=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][e[5]&15]+A,g=this.midiAudioChannels[r],i=o-64,E=i/64,B=o/128,l=(c,h,u=!1)=>{switch(e[6]&15){case 0:c===cA+X.pitchWheel?(g.controllerChange(p.RPNMsb,0),g.controllerChange(p.RPNLsb,0),g.controllerChange(p.dataEntryMsb,Math.floor(i))):(g.sysExModulators.setModulator(c,a.fineTune,i*100,u),n(r,i,`${h} pitch control`,"semitones"));break;case 1:g.sysExModulators.setModulator(c,a.initialFilterFc,E*9600,u),n(r,E*9600,`${h} pitch control`,"cents");break;case 2:g.sysExModulators.setModulator(c,a.initialAttenuation,E*960,u),n(r,E*960,`${h} amplitude`,"cB");break;case 4:g.sysExModulators.setModulator(c,a.vibLfoToPitch,B*600,u),n(r,B*600,`${h} LFO1 pitch depth`,"cents");break;case 5:g.sysExModulators.setModulator(c,a.vibLfoToFilterFc,B*2400,u),n(r,B*2400,`${h} LFO1 filter depth`,"cents");break;case 6:g.sysExModulators.setModulator(c,a.vibLfoToVolume,E*960,u),n(r,E*960,`${h} LFO1 amplitude depth`,"cB");break;case 8:g.sysExModulators.setModulator(c,a.modLfoToPitch,B*600,u),n(r,B*600,`${h} LFO2 pitch depth`,"cents");break;case 9:g.sysExModulators.setModulator(c,a.modLfoToFilterFc,B*2400,u),n(r,B*2400,`${h} LFO2 filter depth`,"cents");break;case 10:g.sysExModulators.setModulator(c,a.modLfoToVolume,E*960,u),n(r,E*960,`${h} LFO2 amplitude depth`,"cB");break}};switch(e[6]&240){default:s();break;case 0:l(p.modulationWheel,"mod wheel");break;case 16:l(cA+X.pitchWheel,"pitch bend",!0);break;case 32:l(cA+X.channelPressure,"channel pressure");break;case 48:l(cA+X.polyPressure,"poly pressure");break}return}else if(e[5]===0){switch(e[6]){default:s();break;case 127:o===0?(y("%cGS Reset received!",I.info),this.resetAllControllers(!1),this.setSystem("gs")):o===127&&(y("%cGS system off, switching to GM2",I.info),this.resetAllControllers(!1),this.setSystem("gm2"));break;case 6:y(`%cRoland GS Master Pan set to: %c${o}%c with: %c${YA(e)}`,I.info,I.value,I.info,I.value),this.setMasterParameter(JA.masterPan,(o-64)/64);break;case 4:y(`%cRoland GS Master Volume set to: %c${o}%c with: %c${YA(e)}`,I.info,I.value,I.info,I.value),this.setMIDIVolume(o/127);break;case 5:let r=o-64;y(`%cRoland GS Master Key-Shift set to: %c${r}%c with: %c${YA(e)}`,I.info,I.value,I.info,I.value),this.setMasterTuning(r*100);break}return}else if(e[5]===1)switch(e[6]){default:s();break;case 0:e.currentIndex=7;let r=AA(e,16);y(`%cGS Patch name: %c${r}`,I.info,I.value);break;case 51:y(`%cGS Reverb level: %c${o}`,I.info,I.value),this.reverbSend=o/64;break;case 48:case 49:case 50:case 52:case 53:case 55:y(`%cUnsupported GS Reverb Parameter: %c${e[6].toString(16)}`,I.warn,I.unrecognized);break;case 58:y(`%cGS Chorus level: %c${o}`,I.info,I.value),this.chorusSend=o/64;break;case 56:case 57:case 59:case 60:case 61:case 62:case 63:case 64:y(`%cUnsupported GS Chorus Parameter: %c${e[6].toString(16)}`,I.warn,I.unrecognized);break}}else s();return}else if(e[2]===69&&e[3]===18){if(e[4]===16&&e[6]===0)if(e[5]===0){let o=new Uint8Array(e.slice(7,e.length-2));this.callEvent("synthdisplay",{displayData:o,displayType:Pt.SoundCanvasText})}else if(e[5]===1){let o=new Uint8Array(e.slice(7,e.length-3));this.callEvent("synthdisplay",{displayData:o,displayType:Pt.SoundCanvasDotDisplay}),y(`%cRoland SC Display Dot Matrix via: %c${YA(e)}`,I.info,I.value)}else s()}else if(e[2]===22&&e[3]===18&&e[4]===16){this.setMIDIVolume(e[7]/100),y(`%cRoland Master Volume control set to: %c${e[7]}%c via: %c${YA(e)}`,I.info,I.value,I.info,I.value);return}else{Y(`%cUnrecognized Roland SysEx: %c${YA(e)}`,I.warn,I.unrecognized);return}break;case 67:if(e[2]===76)if(e[3]===0&&e[4]===0)switch(e[5]){case 4:let o=e[6];this.setMIDIVolume(o/127),y(`%cXG master volume. Volume: %c${o}`,I.info,I.recognized);break;case 6:let r=e[6]-64;this.transposeAllChannels(r),y(`%cXG master transpose. Volume: %c${r}`,I.info,I.recognized);break;case 126:y("%cXG system on",I.info),this.resetAllControllers(!1),this.setSystem("xg");break}else if(e[3]===8){if(!GA(this.system))return;let o=e[4]+A;if(o>=this.midiAudioChannels.length)return;let r=this.midiAudioChannels[o],g=e[6];switch(e[5]){case 1:r.controllerChange(p.bankSelect,g);break;case 2:r.controllerChange(p.lsbForControl0BankSelect,g);break;case 3:r.programChange(g);break;case 8:if(r.drumChannel)return;let i=g-64;r.channelTransposeKeyShift=i;break;case 11:r.controllerChange(p.mainVolume,g);break;case 14:let E=g;E===0?(r.randomPan=!0,y(`%cRandom pan is set to %cON%c for %c${o}`,I.info,I.recognized,I.info,I.value)):r.controllerChange(p.pan,E);break;case 19:r.controllerChange(p.reverbDepth,g);break;case 18:r.controllerChange(p.chorusDepth,g);break;default:Y(`%cUnrecognized Yamaha XG Part Setup: %c${e[5].toString(16).toUpperCase()}`,I.warn,I.unrecognized)}}else if(e[3]===6&&e[4]===0){let o=new Uint8Array(e.slice(5,e.length-1));this.callEvent("synthdisplay",{displayData:o,displayType:Pt.XGText})}else GA(this.system)&&Y(`%cUnrecognized Yamaha XG SysEx: %c${YA(e)}`,I.warn,I.unrecognized);else GA(this.system)&&Y(`%cUnrecognized Yamaha SysEx: %c${YA(e)}`,I.warn,I.unrecognized);break}}function io(e=!0){e&&y("%cResetting all controllers!",I.info),this.callEvent("allcontrollerreset",void 0),this.setSystem(Yt);for(let A=0;A<this.midiAudioChannels.length;A++){this.midiAudioChannels[A].resetControllers();let t=this.midiAudioChannels[A];t.lockPreset?this.callEvent("drumchange",{channel:A,isDrumChannel:t.drumChannel}):(t.setBankSelect(to(this.system)),A%16===9?(t.setPreset(this.drumPreset),t.drumChannel=!0,this.callEvent("drumchange",{channel:A,isDrumChannel:!0})):(t.drumChannel=!1,t.setPreset(this.defaultPreset),this.callEvent("drumchange",{channel:A,isDrumChannel:!1})));let n=t.preset.bank;this.callEvent("programchange",{channel:A,program:t.preset.program,bank:n});for(let s=0;s<128;s++)this.midiAudioChannels[A].lockedControllers[s]&&this.callEvent("controllerchange",{channel:A,controllerNumber:s,controllerValue:this.midiAudioChannels[A].midiControllers[s]>>7});if(this.midiAudioChannels[A].lockedControllers[cA+X.pitchWheel]===!1){let s=this.midiAudioChannels[A].midiControllers[cA+X.pitchWheel],o=s>>7,r=s&127;this.callEvent("pitchwheel",{channel:A,MSB:o,LSB:r})}}this.tunings=[],this.tunings=[];for(let A=0;A<128;A++)this.tunings.push([]);this.setMIDIVolume(1)}function ao(){this.channelOctaveTuning.fill(0);for(let A=0;A<Oe.length;A++){if(this.lockedControllers[A])continue;let t=Oe[A];this.midiControllers[A]!==t&&A<127?A===p.portamentoControl?this.midiControllers[A]=cn:this.controllerChange(A,t>>7):this.midiControllers[A]=t}this.channelVibrato={rate:0,depth:0,delay:0},this.holdPedal=!1,this.randomPan=!1,this.sysExModulators.resetModulators();let e=this.customControllers[tA.channelTransposeFine];this.customControllers.set(Cs),this.setCustomController(tA.channelTransposeFine,e),this.resetParameters()}var hs=new Set([p.bankSelect,p.lsbForControl0BankSelect,p.mainVolume,p.lsbForControl7MainVolume,p.pan,p.lsbForControl10Pan,p.reverbDepth,p.tremoloDepth,p.chorusDepth,p.detuneDepth,p.phaserDepth,p.soundVariation,p.filterResonance,p.releaseTime,p.attackTime,p.brightness,p.decayTime,p.vibratoRate,p.vibratoDepth,p.vibratoDelay,p.soundController10]);function go(){this.channelOctaveTuning.fill(0),this.pitchWheel(64,0),this.channelVibrato={rate:0,depth:0,delay:0};for(let e=0;e<128;e++){let A=Oe[e];!hs.has(e)&&A!==this.midiControllers[e]&&(e===p.portamentoControl?this.midiControllers[e]=cn:this.controllerChange(e,A>>7))}this.resetGeneratorOverrides(),this.resetGeneratorOffsets()}function Io(){this.dataEntryState=vA.Idle,this.midiControllers[p.NRPNLsb]=16256,this.midiControllers[p.NRPNMsb]=16256,this.midiControllers[p.RPNLsb]=16256,this.midiControllers[p.RPNMsb]=16256,this.resetGeneratorOverrides(),this.resetGeneratorOffsets()}var mt=class{soundfontList=[];presetList=[];constructor(A){this.presetListChangeCallback=A}generatePresetList(){let A={};for(let t=this.soundfontList.length-1;t>=0;t--){let n=this.soundfontList[t],s=new Set;for(let o of n.soundfont.presets){let g=`${Math.min(128,o.bank+n.bankOffset)}-${o.program}`;s.has(g)||(s.add(g),A[g]=o.presetName)}}this.presetList=[];for(let[t,n]of Object.entries(A)){let s=t.split("-");this.presetList.push({presetName:n,program:parseInt(s[1]),bank:parseInt(s[0])})}this.presetListChangeCallback()}getPresetList(){return this.presetList.slice()}reloadManager(A){this.soundfontList=this.soundfontList.filter(t=>t.id===$e),this.soundfontList.push({id:"main",bankOffset:0,soundfont:A}),this.generatePresetList()}deleteSoundFont(A){if(this.soundfontList.length===0){Y("1 soundfont left. Aborting!");return}let t=this.soundfontList.findIndex(n=>n.id===A);if(t===-1){y(`No soundfont with id of "${A}" found. Aborting!`);return}delete this.soundfontList[t].soundfont.presets,delete this.soundfontList[t].soundfont.instruments,delete this.soundfontList[t].soundfont.samples,this.soundfontList.splice(t,1),this.generatePresetList()}addNewSoundFont(A,t,n){if(this.soundfontList.find(s=>s.id===t)!==void 0){let s=this.soundfontList.find(o=>o.id===t);s.soundfont=A,s.bankOffset=n}else this.soundfontList.push({id:t,soundfont:A,bankOffset:n});this.generatePresetList()}getCurrentSoundFontOrder(){return this.soundfontList.map(A=>A.id)}rearrangeSoundFonts(A){this.soundfontList.sort((t,n)=>A.indexOf(t.id)-A.indexOf(n.id)),this.generatePresetList()}getPreset(A,t,n=!1){if(this.soundfontList.length<1)throw new Error("No soundfonts! Did you forget to add one?");let s=A===128||n&&te(A);for(let o of this.soundfontList){let r=o.soundfont.getPresetNoFallback(A===128?128:A-o.bankOffset,t,n);if(r!==void 0)return{preset:r,bankOffset:o.bankOffset}}if(s){for(let r of this.soundfontList){let g=r.soundfont.presets.find(E=>E.isDrumPreset(n)&&E.program===t);if(g)return{preset:g,bankOffset:r.bankOffset};let i=r.soundfont.presets.find(E=>E.isDrumPreset(n));if(i)return{preset:i,bankOffset:r.bankOffset}}let o=this.soundfontList[0];return{preset:o.soundfont.presets[0],bankOffset:o.bankOffset}}else{for(let r of this.soundfontList){let g=r.soundfont.presets.find(i=>i.program===t&&!i.isDrumPreset(n));if(g)return{preset:g,bankOffset:r.bankOffset}}let o=this.soundfontList[0];return{preset:o.soundfont.presets[0],bankOffset:o.bankOffset}}}destroyManager(){this.soundfontList.forEach(A=>{A.soundfont.destroySoundBank()}),delete this.soundfontList}};var hn=class{_keyMappings=[];addMapping(A,t,n){this._keyMappings[A]===void 0&&(this._keyMappings[A]=[]),this._keyMappings[A][t]=n}deleteMapping(A,t){this._keyMappings[A]?.[t]!==void 0&&(this._keyMappings[A][t]=void 0)}clearMappings(){this._keyMappings=[]}setMappings(A){this._keyMappings=A}getMappings(){return this._keyMappings}getVelocity(A,t){return this._keyMappings[A]?.[t]?.velocity??-1}getGain(A,t){return this._keyMappings[A]?.[t]?.gain??1}hasOverridePatch(A,t){let n=this._keyMappings[A]?.[t]?.patch?.bank;return n!==void 0&&n>=0}getPatch(A,t){let n=this._keyMappings[A]?.[t];if(n)return n.patch;throw new Error("No modifier.")}};var Eo=.1,Je=class e{static cachedCoefficients=[];a0=0;a1=0;a2=0;a3=0;a4=0;x1=0;x2=0;y1=0;y2=0;resonanceCb=0;currentInitialFc=13500;lastTargetCutoff=1/0;initialized=!1;sampleRate;constructor(A){this.sampleRate=A,this.maxCutoff=A*.45}static apply(A,t,n,s){let o=A.modulatedGenerators[a.initialFilterFc],r=A.filter;r.initialized?r.currentInitialFc+=(o-r.currentInitialFc)*s:(r.initialized=!0,r.currentInitialFc=o);let g=r.currentInitialFc+n,i=A.modulatedGenerators[a.initialFilterQ];if(r.currentInitialFc>13499&&g>13499&&i===0){r.currentInitialFc=13500;return}(Math.abs(r.lastTargetCutoff-g)>1||r.resonanceCb!==i)&&(r.lastTargetCutoff=g,r.resonanceCb=i,e.calculateCoefficients(r,g));for(let E=0;E<t.length;E++){let B=t[E],l=r.a0*B+r.a1*r.x1+r.a2*r.x2-r.a3*r.y1-r.a4*r.y2;r.x2=r.x1,r.x1=B,r.y2=r.y1,r.y1=l,t[E]=l}}static calculateCoefficients(A,t){t=~~t;let n=A.resonanceCb,s=e.cachedCoefficients?.[n]?.[t];if(s!==void 0){A.a0=s.a0,A.a1=s.a1,A.a2=s.a2,A.a3=s.a3,A.a4=s.a4;return}let o=Ot(t);o=Math.min(o,A.maxCutoff);let r=n/10,g=Ee(-(r-3.01)),i=1/Math.sqrt(Ee(-r)),E=2*Math.PI*o/A.sampleRate,B=Math.cos(E),l=Math.sin(E)/(2*g),c=(1-B)*i,h=c/2,u=h,f=1+l,S=-2*B,w=1-l,D={};D.a0=h/f,D.a1=c/f,D.a2=u/f,D.a3=S/f,D.a4=w/f,A.a0=D.a0,A.a1=D.a1,A.a2=D.a2,A.a3=D.a3,A.a4=D.a4,e.cachedCoefficients[n]===void 0&&(e.cachedCoefficients[n]=[]),e.cachedCoefficients[n][t]=D}},ls=new Je(44100);ls.resonanceCb=0;for(let e=1500;e<13500;e++)ls.currentInitialFc=e,Je.calculateCoefficients(ls,e);var LA=16384,Ge=new Float32Array(LA+1),et=new Float32Array(LA+1);Ge[0]=0;Ge[Ge.length-1]=1;et[0]=0;et[et.length-1]=1;for(let e=1;e<LA-1;e++){let A=-.4166666666666667*Math.log(e/(Ge.length-1))/Math.LN10;et[e]=1-A,Ge[Ge.length-1-e]=A}function tt(e,A,t,n){switch(e&&(t=1-t),A){case DA.linear:return n?t*2-1:t;case DA.switch:return t=t>.5?1:0,n?t*2-1:t;case DA.concave:return n?(t=t*2-1,t<0?-Ge[~~(t*-LA)]:Ge[~~(t*LA)]):Ge[~~(t*LA)];case DA.convex:return n?(t=t*2-1,t<0?-et[~~(t*-LA)]:et[~~(t*LA)]):et[~~(t*LA)]}}var Bs=1,Qs=new Float32Array(1e3);for(let e=0;e<Qs.length;e++)Qs[e]=tt(0,DA.convex,e/1e3,0);var le=class e{attackDuration=0;decayDuration=0;holdDuration=0;releaseDuration=0;sustainLevel=0;delayEnd=0;attackEnd=0;holdEnd=0;decayEnd=0;releaseStartLevel=0;currentValue=0;static startRelease(A){e.recalculate(A)}static recalculate(A){let t=A.modulationEnvelope;A.isInRelease&&(t.releaseStartLevel=e.getValue(A,A.releaseStartTime,!0)),t.sustainLevel=1-A.modulatedGenerators[a.sustainModEnv]/1e3,t.attackDuration=ce(A.modulatedGenerators[a.attackModEnv]);let n=(60-A.midiNote)*A.modulatedGenerators[a.keyNumToModEnvDecay],s=ce(A.modulatedGenerators[a.decayModEnv]+n);t.decayDuration=s*(1-t.sustainLevel);let o=(60-A.midiNote)*A.modulatedGenerators[a.keyNumToModEnvHold];t.holdDuration=ce(o+A.modulatedGenerators[a.holdModEnv]);let r=ce(A.modulatedGenerators[a.releaseModEnv]);t.releaseDuration=r*t.releaseStartLevel,t.delayEnd=A.startTime+ce(A.modulatedGenerators[a.delayModEnv]),t.attackEnd=t.delayEnd+t.attackDuration,t.holdEnd=t.attackEnd+t.holdDuration,t.decayEnd=t.holdEnd+t.decayDuration}static getValue(A,t,n=!1){let s=A.modulationEnvelope;return A.isInRelease&&!n?s.releaseStartLevel===0?0:Math.max(0,(1-(t-A.releaseStartTime)/s.releaseDuration)*s.releaseStartLevel):(t<s.delayEnd?s.currentValue=0:t<s.attackEnd?s.currentValue=Qs[~~((1-(s.attackEnd-t)/s.attackDuration)*1e3)]:t<s.holdEnd?s.currentValue=Bs:t<s.decayEnd?s.currentValue=(1-(s.decayEnd-t)/s.decayDuration)*(s.sustainLevel-Bs)+Bs:s.currentValue=s.sustainLevel,s.currentValue)}};var Pe=4,U=class{generatorType=a.INVALID;generatorValue=0;constructor(A=a.INVALID,t=0,n=!0){if(this.generatorType=A,t===void 0)throw new Error("No value provided.");if(this.generatorValue=Math.round(t),n){let s=K[A];s!==void 0&&(this.generatorValue=Math.max(s.min,Math.min(s.max,this.generatorValue)))}}};function Co(e,A,t){let n=K[e]||{min:0,max:32768,def:0},s=A.find(i=>i.generatorType===e),o=0;s&&(o=s.generatorValue);let r=t.find(i=>i.generatorType===e),g=n.def;return r&&(g=r.generatorValue),g+o}var xi=-2320,Ni=-1130,ln=class{sampleData;playbackStep=0;cursor=0;rootKey=0;loopStart=0;loopEnd=0;end=0;loopingMode=0;isLooping=!1;constructor(A,t,n,s,o,r,g,i){this.sampleData=A,this.playbackStep=t,this.cursor=n,this.rootKey=s,this.loopStart=o,this.loopEnd=r,this.end=g,this.loopingMode=i,this.isLooping=this.loopingMode===1||this.loopingMode===3}},Kt=class e{sample;filter;gain=1;generators;modulators=[];modulatedGenerators;finished=!1;isInRelease=!1;velocity=0;midiNote=0;pressure=0;targetKey=0;modulationEnvelope=new le;volumeEnvelope;startTime=0;releaseStartTime=1/0;currentTuningCents=0;currentTuningCalculated=1;currentPan=0;realKey;portamentoFromKey=-1;portamentoDuration=0;overridePan=0;exclusiveClass=0;constructor(A,t,n,s,o,r,g,i,E){this.sample=t,this.generators=i,this.exclusiveClass=this.generators[a.exclusiveClass],this.modulatedGenerators=new Int16Array(i),this.modulators=E,this.filter=new Je(A),this.velocity=s,this.midiNote=n,this.startTime=o,this.targetKey=r,this.realKey=g,this.volumeEnvelope=new he(A,i[a.sustainVolEnv])}static copy(A,t,n){let s=A.sample,o=new ln(s.sampleData,s.playbackStep,s.cursor,s.rootKey,s.loopStart,s.loopEnd,s.end,s.loopingMode);return new e(A.volumeEnvelope.sampleRate,o,A.midiNote,A.velocity,t,A.targetKey,n,new Int16Array(A.generators),A.modulators.map(r=>CA.copy(r)))}exclusiveRelease(A){this.release(A,Bo),this.modulatedGenerators[a.releaseVolEnv]=xi,this.modulatedGenerators[a.releaseModEnv]=Ni,he.recalculate(this),le.recalculate(this)}release(A,t=lo){this.releaseStartTime=A,this.releaseStartTime-this.startTime<t&&(this.releaseStartTime=this.startTime+t)}};function co(e,A,t,n,s,o){let r=e.getSamplesAndGenerators(n,s).reduce((g,i)=>{if(i.sample.getAudioData()===void 0)return Y(`Discarding invalid sample: ${i.sample.sampleName}`),g;let E=new Int16Array(Jt);for(let S=0;S<60;S++)E[S]=Co(S,i.presetGenerators,i.instrumentGenerators);E[a.initialAttenuation]=Math.floor(E[a.initialAttenuation]*.4);let B=i.sample.samplePitch;E[a.overridingRootKey]>-1&&(B=E[a.overridingRootKey]);let l=n;E[a.keyNum]>-1&&(l=E[a.keyNum]);let c=i.sample.sampleLoopStartIndex,h=i.sample.sampleLoopEndIndex,u=E[a.sampleModes],f=new ln(i.sample.sampleData,i.sample.sampleRate/this.sampleRate*Math.pow(2,i.sample.samplePitchCorrection/1200),0,B,c,h,Math.floor(i.sample.sampleData.length)-1,u);return E[a.velocity]>-1&&(s=E[a.velocity]),g.push(new Kt(this.sampleRate,f,n,s,this.currentSynthTime,l,o,E,i.modulators.map(S=>CA.copy(S)))),g},[]);return this.setCachedVoice(A,t,n,s,r),r.map(g=>Kt.copy(g,this.currentSynthTime,o))}function ho(e,A,t,n){let s=this.midiAudioChannels[e],o=this.keyModifierManager.hasOverridePatch(e,A),r=s.getBankSelect(),g=s.preset.program;if(o){let B=this.keyModifierManager.getPatch(e,A);r=B.bank,g=B.program}let i=this.getCachedVoice(r,g,A,t);if(i!==void 0)return i.map(B=>Kt.copy(B,this.currentSynthTime,n));let E=s.preset;return o&&(E=this.getPreset(r,g)),this.getVoicesForPreset(E,r,g,A,t,n)}var fo=.05,bi=3070,Li=2e3,Qo=Math.PI/2,Bn=-500,uo=500,ds=uo-Bn,mo=new Float32Array(ds+1),po=new Float32Array(ds+1);for(let e=Bn;e<=uo;e++){let A=(e-Bn)/ds,t=e-Bn;mo[t]=Math.cos(Qo*A),po[t]=Math.sin(Qo*A)}function yo(e,A,t,n,s,o,r,g){if(isNaN(A[0]))return;let i;e.overridePan?i=e.overridePan:(e.currentPan+=(e.modulatedGenerators[a.pan]-e.currentPan)*this.synth.panSmoothingFactor,i=e.currentPan);let E=this.synth.currentGain*e.gain,B=~~(i+500),l=mo[B]*E*this.synth.panLeft,c=po[B]*E*this.synth.panRight;if(this.synth.effectsEnabled){let h=e.modulatedGenerators[a.reverbEffectsSend];if(h>0){let f=this.synth.reverbGain*this.synth.reverbSend*E*(h/bi);for(let S=0;S<A.length;S++)s[S]+=f*A[S];o.set(s)}let u=e.modulatedGenerators[a.chorusEffectsSend];if(u>0){let f=this.synth.chorusGain*this.synth.chorusSend*(u/Li),S=l*f,w=c*f;for(let D=0;D<A.length;D++)r[D]+=S*A[D],g[D]+=w*A[D]}}if(l>0)for(let h=0;h<A.length;h++)t[h]+=l*A[h];if(c>0)for(let h=0;h<A.length;h++)n[h]+=c*A[h]}function So(e=!1){y("%cStop all received!",I.info);for(let A=0;A<this.midiAudioChannels.length;A++)this.midiAudioChannels[A].stopAllNotes(e);this.callEvent("stopall",void 0)}function b(e,A){let t=0;for(let n=0;n<A;n++)t|=e[e.currentIndex++]<<n*8;return t>>>0}function Se(e,A,t){for(let n=0;n<t;n++)e[e.currentIndex++]=A>>n*8&255}function O(e,A){e[e.currentIndex++]=A&255,e[e.currentIndex++]=A>>8}function eA(e,A){Se(e,A,4)}function Ke(e,A){let t=A<<8|e;return t>32767?t-65536:t}function Do(e){return e>127?e-256:e}var hA=class{constructor(A,t,n){this.header=A,this.size=t,this.chunkData=n}};function gA(e,A=!0,t=!1){let n=AA(e,4),s=b(e,4),o;return A&&(o=new L(e.buffer.slice(e.currentIndex,e.currentIndex+s))),(A||t)&&(e.currentIndex+=s),s%2!==0&&e[e.currentIndex]===0&&e.currentIndex++,new hA(n,s,o)}function dA(e,A=void 0){let t=8+e.size;e.size%2!==0&&t++,A&&(t+=A.length);let n=new L(t);return A&&(n.set(A,n.currentIndex),n.currentIndex+=A.length),bA(n,e.header),eA(n,t-8-(A?.length||0)),n.set(e.chunkData,n.currentIndex),n}function z(e,A,t=!1,n=!1){if(t){let E=new Uint8Array(A.length+1);E.set(A),A=E}let s=8,o=s+A.length,r=A.length;o%2!==0&&o++;let g=e;n&&(o+=4,r+=4,s+=4,g="LIST");let i=new L(o);return bA(i,g),eA(i,r),n&&bA(i,e),i.set(A,s),i}function _A(e,A){return e.find(t=>t.header!=="LIST"?!1:(t.chunkData.currentIndex=0,AA(t.chunkData,4)===A))}function ko(){let e=Pe;for(let n of this.instruments)e+=n.globalZone.generators.length*Pe,e+=n.instrumentZones.reduce((s,o)=>(o.generators=o.generators.filter(r=>r.generatorType!==a.sampleID&&r.generatorType!==a.keyRange&&r.generatorType!==a.velRange),o.hasVelRange&&o.prependGenerator(new U(a.velRange,o.velRange.max<<8|Math.max(o.velRange.min,0),!1)),o.hasKeyRange&&o.prependGenerator(new U(a.keyRange,o.keyRange.max<<8|Math.max(o.keyRange.min,0),!1)),o.addGenerators(new U(a.sampleID,this.samples.indexOf(o.sample),!1)),o.generators.length*Pe+s),0);let A=new L(e),t=n=>{for(let s of n.generators)O(A,s.generatorType),O(A,s.generatorValue)};for(let n of this.instruments){t(n.globalZone);for(let s of n.instrumentZones)t(s)}return eA(A,0),dA(new hA("igen",A.length,A))}function Fo(e,A,t,n,s){let o=this.samples.map((E,B)=>{t&&E.compressSample(n,s);let l=E.getRawData();return y(`%cEncoded sample %c${B}. ${E.sampleName}%c of %c${this.samples.length}%c. Compressed: %c${E.isCompressed}%c.`,I.info,I.recognized,I.info,I.recognized,I.info,E.isCompressed?I.recognized:I.unrecognized,I.info),l}),r=this.samples.reduce((E,B,l)=>E+o[l].length+46,0),g=new L(r);this.samples.forEach((E,B)=>{let l=o[B],c,h,u=l.length;E.isCompressed?(c=g.currentIndex,h=c+l.length):(c=g.currentIndex/2,h=c+l.length/2,u+=46),e.push(c),g.set(l,g.currentIndex),g.currentIndex+=u,A.push(h)});let i=dA(new hA("smpl",g.length,g),new L([115,100,116,97]));return dA(new hA("LIST",i.length,i))}function wo(e,A){let n=new L(46*(this.samples.length+1));return this.samples.forEach((s,o)=>{bA(n,s.sampleName,20);let r=e[o];eA(n,r);let g=A[o];eA(n,g);let i=s.sampleLoopStartIndex+r,E=s.sampleLoopEndIndex+r;s.isCompressed&&(i-=r,E-=r),eA(n,i),eA(n,E),eA(n,s.sampleRate),n[n.currentIndex++]=s.samplePitch,n[n.currentIndex++]=s.samplePitchCorrection,O(n,s.sampleLink),O(n,s.sampleType)}),bA(n,"EOS",46),dA(new hA("shdr",n.length,n))}function Ro(){let e=WA;for(let n of this.instruments)e+=n.globalZone.modulators.length*WA,e+=n.instrumentZones.reduce((s,o)=>o.modulators.length*WA+s,0);let A=new L(e),t=n=>{for(let s of n.modulators)O(A,s.getSourceEnum()),O(A,s.modulatorDestination),O(A,s.transformAmount),O(A,s.getSecSrcEnum()),O(A,s.transformType)};for(let n of this.instruments){t(n.globalZone);for(let s of n.instrumentZones)t(s)}return Se(A,0,WA),dA(new hA("imod",A.length,A))}var Go=4;function Mo(){let e=this.instruments.reduce((o,r)=>(r.instrumentZones.length+1)*Go+o,Go),A=new L(e),t=0,n=0,s=o=>{O(A,t),O(A,n),t+=o.generators.length,n+=o.modulators.length};for(let o of this.instruments){s(o.globalZone);for(let r of o.instrumentZones)s(r)}return O(A,t),O(A,n),dA(new hA("ibag",A.length,A))}var xo=22;function No(){let e=this.instruments.length*xo+xo,A=new L(e),t=0;for(let n of this.instruments)bA(A,n.instrumentName,20),O(A,t),t+=n.instrumentZones.length+1;return bA(A,"EOI",20),O(A,t),dA(new hA("inst",A.length,A))}function bo(){let e=Pe;for(let n of this.presets)e+=n.globalZone.generators.length*Pe,e+=n.presetZones.reduce((s,o)=>(o.generators=o.generators.filter(r=>r.generatorType!==a.instrument&&r.generatorType!==a.keyRange&&r.generatorType!==a.velRange),o.hasVelRange&&o.prependGenerator(new U(a.velRange,o.velRange.max<<8|Math.max(o.velRange.min,0),!1)),o.hasKeyRange&&o.prependGenerator(new U(a.keyRange,o.keyRange.max<<8|Math.max(o.keyRange.min,0),!1)),o.addGenerators(new U(a.instrument,this.instruments.indexOf(o.instrument),!1)),o.generators.length*Pe+s),0);let A=new L(e),t=n=>{for(let s of n.generators)O(A,s.generatorType),O(A,s.generatorValue)};for(let n of this.presets){t(n.globalZone);for(let s of n.presetZones)t(s)}return eA(A,0),dA(new hA("pgen",A.length,A))}function Lo(){let e=WA;for(let n of this.presets)e+=n.globalZone.modulators.length*WA,e+=n.presetZones.reduce((s,o)=>o.modulators.length*WA+s,0);let A=new L(e),t=n=>{for(let s of n.modulators)O(A,s.getSourceEnum()),O(A,s.modulatorDestination),O(A,s.transformAmount),O(A,s.getSecSrcEnum()),O(A,s.transformType)};for(let n of this.presets){t(n.globalZone);for(let s of n.presetZones)t(s)}return Se(A,0,WA),dA(new hA("pmod",A.length,A))}var To=4;function Uo(){let e=this.presets.reduce((o,r)=>(r.presetZones.length+1)*To+o,To),A=new L(e),t=0,n=0,s=o=>{O(A,t),O(A,n),t+=o.generators.length,n+=o.modulators.length};for(let o of this.presets){s(o.globalZone);for(let r of o.presetZones)s(r)}return O(A,t),O(A,n),dA(new hA("pbag",A.length,A))}var vo=38;function Ho(){let e=this.presets.length*vo+vo,A=new L(e),t=0;for(let n of this.presets)bA(A,n.presetName,20),O(A,n.program),O(A,n.bank),O(A,t),eA(A,n.library),eA(A,n.genre),eA(A,n.morphology),t+=n.presetZones.length+1;return bA(A,"EOP",20),O(A,0),O(A,0),O(A,t),eA(A,0),eA(A,0),eA(A,0),dA(new hA("phdr",A.length,A))}function Qn(e,A){e===void 0&&(e={});for(let t in A)A.hasOwnProperty(t)&&!(t in e)&&(e[t]=A[t]);return e}var Yo={compress:!1,compressionQuality:.5,compressionFunction:void 0,writeDefaultModulators:!0};function Oo(e=Yo){if(e=Qn(e,Yo),e.compress&&typeof e.compressionFunction!="function")throw new TypeError("No compression function supplied but compression enabled.");QA("%cSaving soundfont...",I.info),y(`%cCompression: %c${e?.compress||"false"}%c quality: %c${e?.compressionQuality||"none"}`,I.info,I.recognized,I.info,I.recognized),y("%cWriting INFO...",I.info);let A=[];this.soundFontInfo.ISFT="SpessaSynth",e?.compress&&(this.soundFontInfo.ifil="3.0"),e?.writeDefaultModulators?(this.soundFontInfo.DMOD=`${this.defaultModulators.length} Modulators`,this.customDefaultModulators=!0):delete this.soundFontInfo.DMOD;for(let[x,v]of Object.entries(this.soundFontInfo))if(x==="ifil"||x==="iver"){let G=parseInt(v.split(".")[0]),C=parseInt(v.split(".")[1]),N=new L(4);O(N,G),O(N,C),A.push(dA(new hA(x,4,N)))}else if(x==="DMOD"){let G=this.defaultModulators;y(`%cWriting %c${G.length}%c default modulators...`,I.info,I.recognized,I.info);let C=WA+G.length*WA,N=new L(C);for(let M of G)O(N,M.getSourceEnum()),O(N,M.modulatorDestination),O(N,M.transformAmount),O(N,M.getSecSrcEnum()),O(N,M.transformType);Se(N,0,WA),A.push(dA(new hA(x,N.length,N)))}else{let G=new L(v.length+1);bA(G,v),A.push(dA(new hA(x,G.length,G)))}let t=z("INFO",kA(A),!1,!0);y("%cWriting SDTA...",I.info);let n=[],s=[],o=Fo.call(this,n,s,e?.compress,e?.compressionQuality??.5,e.compressionFunction);y("%cWriting PDTA...",I.info),y("%cWriting SHDR...",I.info);let r=wo.call(this,n,s);y("%cWriting IGEN...",I.info);let g=ko.call(this);y("%cWriting IMOD...",I.info);let i=Ro.call(this);y("%cWriting IBAG...",I.info);let E=Mo.call(this);y("%cWriting INST...",I.info);let B=No.call(this),l=bo.call(this);y("%cWriting PMOD...",I.info);let c=Lo.call(this);y("%cWriting PBAG...",I.info);let h=Uo.call(this);y("%cWriting PHDR...",I.info);let u=Ho.call(this),f=kA([new L([112,100,116,97]),u,h,c,l,B,E,i,g,r]),S=dA(new hA("LIST",f.length,f));y("%cWriting the output file...",I.info);let w=kA([new L([115,102,98,107]),t,o,S]),D=dA(new hA("RIFF",w.length,w));return y(`%cSaved succesfully! Final file size: %c${D.length}`,I.info,I.recognized),P(),D}var qe=class{velRange={min:-1,max:127};keyRange={min:-1,max:127};generators=[];modulators=[];get hasKeyRange(){return this.keyRange.min!==-1}get hasVelRange(){return this.velRange.min!==-1}prependGenerator(A){this.generators.unshift(A)}setGenerator(A,t){switch(A){case a.sampleID:throw new Error("Use setSample()");case a.instrument:throw new Error("Use setInstrument()");case a.velRange:case a.keyRange:throw new Error("Set the range manually")}let n=this.generators.find(s=>s.generatorType===A);n?n.generatorValue=t:this.addGenerators(new U(A,t))}addGenerators(...A){A.forEach(t=>{switch(t.generatorType){default:this.generators.push(t);break;case a.velRange:this.velRange.min=t.generatorValue&127,this.velRange.max=t.generatorValue>>8&127;break;case a.keyRange:this.keyRange.min=t.generatorValue&127,this.keyRange.max=t.generatorValue>>8&127}})}addModulators(...A){this.modulators.push(...A)}getGeneratorValue(A,t){return this.generators.find(n=>n.generatorType===A)?.generatorValue??t}copyFrom(A){this.generators=[...A.generators],this.modulators=[...A.modulators],this.velRange={...A.velRange},this.keyRange={...A.keyRange}}};var Ve=class extends qe{};var Me=class e extends qe{parentInstrument;sample;useCount;constructor(A){super(),this.parentInstrument=A,this.useCount=A.linkedPresets.length}setSample(A){this.sample=A,A.linkTo(this.parentInstrument)}deleteZone(){this.sample.unlinkFrom(this.parentInstrument)}copyFrom(A){super.copyFrom(A),A instanceof e&&(this.sample=A.sample)}};var Be=class{instrumentName="";instrumentZones=[];globalZone=new Ve;linkedPresets=[];get useCount(){return this.linkedPresets.length}createZone(){let A=new Me(this);return this.instrumentZones.push(A),A}linkTo(A){this.linkedPresets.push(A),this.instrumentZones.forEach(t=>t.useCount=this.linkedPresets.length)}unlinkFrom(A){let t=this.linkedPresets.indexOf(A);if(t<0)throw new Error(`Cannot unlink ${A.presetName} from ${this.instrumentName}: not linked.`);this.linkedPresets.splice(t,1)}deleteAllZones(){this.instrumentZones.forEach(A=>A.deleteZone()),this.instrumentZones.length=0}deleteZone(A){let t=this.instrumentZones[A];return t.useCount<1?(t.deleteZone(),this.instrumentZones.splice(A,1),!0):!1}};var Ti=new Set([a.velRange,a.keyRange,a.instrument,a.exclusiveClass,a.endOper,a.sampleModes,a.startloopAddrsOffset,a.startloopAddrsCoarseOffset,a.endloopAddrsOffset,a.endloopAddrsCoarseOffset,a.startAddrsOffset,a.startAddrsCoarseOffset,a.endAddrOffset,a.endAddrsCoarseOffset,a.initialAttenuation,a.fineTune,a.coarseTune,a.keyNumToVolEnvHold,a.keyNumToVolEnvDecay,a.keyNumToModEnvHold,a.keyNumToModEnvDecay]);function Jo(e,A=!0){function t(c,h){c.push(...h.filter(u=>!c.find(f=>f.generatorType===u.generatorType)))}function n(c,h){return{min:Math.max(c.min,h.min),max:Math.min(c.max,h.max)}}function s(c,h){c.push(...h.filter(u=>!c.find(f=>CA.isIdentical(u,f))))}let o=new Be,r=[],g=[],i=e.globalZone;r.push(...i.generators),g.push(...i.modulators);let E=i.keyRange,B=i.velRange;for(let c of e.presetZones){let h=c.keyRange;c.hasKeyRange||(h=E);let u=c.velRange;c.hasVelRange||(u=B);let f=c.generators.map(M=>new U(M.generatorType,M.generatorValue));t(f,r);let S=[...c.modulators];s(S,g);let w=c.instrument,D=w.instrumentZones,x=[],v=[],G=w.globalZone;x.push(...G.generators),v.push(...G.modulators);let C=G.keyRange,N=G.velRange;for(let M of D){let $=M.keyRange;M.hasKeyRange||($=C);let iA=M.velRange;if(M.hasVelRange||(iA=N),$=n($,h),iA=n(iA,u),$.max<$.min||iA.max<iA.min)continue;let Z=M.generators.map(_=>new U(_.generatorType,_.generatorValue));t(Z,x);let IA=[...M.modulators];s(IA,v);let RA=[...IA];for(let _ of S){let T=RA.findIndex(H=>CA.isIdentical(_,H));T!==-1?RA[T]=RA[T].sumTransform(_):RA.push(_)}let NA=Z.map(_=>new U(_.generatorType,_.generatorValue));for(let _ of f){if(_.generatorType===a.velRange||_.generatorType===a.keyRange||_.generatorType===a.instrument||_.generatorType===a.endOper||_.generatorType===a.sampleModes)continue;let T=Z.findIndex(H=>H.generatorType===_.generatorType);if(T!==-1){let H=NA[T].generatorValue+_.generatorValue;NA[T]=new U(_.generatorType,H)}else{let H=K[_.generatorType].def+_.generatorValue;NA.push(new U(_.generatorType,H))}}NA=NA.filter(_=>_.generatorType!==a.sampleID&&_.generatorType!==a.keyRange&&_.generatorType!==a.velRange&&_.generatorType!==a.endOper&&_.generatorType!==a.instrument&&_.generatorValue!==K[_.generatorType].def);let nA=o.createZone();nA.keyRange=$,nA.velRange=iA,nA.keyRange.min===0&&nA.keyRange.max===127&&(nA.keyRange.min=-1),nA.velRange.min===0&&nA.velRange.max===127&&(nA.velRange.min=-1),nA.setSample(M.sample),nA.addGenerators(...NA),nA.addModulators(...RA)}}let l=o.globalZone;if(A){for(let u=0;u<58;u++){if(Ti.has(u))continue;let f={},S=K[u]?.def||0;f[S]=0;for(let w of o.instrumentZones){let D=w.generators.find(G=>G.generatorType===u);if(D){let G=D.generatorValue;f[G]===void 0?f[G]=1:f[G]++}else f[S]++;let x;switch(u){default:continue;case a.decayVolEnv:x=a.keyNumToVolEnvDecay;break;case a.holdVolEnv:x=a.keyNumToVolEnvHold;break;case a.decayModEnv:x=a.keyNumToModEnvDecay;break;case a.holdModEnv:x=a.keyNumToModEnvHold}if(w.generators.find(G=>G.generatorType===x)!==void 0){f={};break}}if(Object.keys(f).length>0){let w=Object.entries(f).reduce((x,v)=>x[1]<v[1]?v:x,[0,0]),D=parseInt(w[0]);D!==S&&l.addGenerators(new U(u,D)),o.instrumentZones.forEach(x=>{let v=x.generators.findIndex(G=>G.generatorType===u);v!==-1?x.generators[v].generatorValue===D&&x.generators.splice(v,1):D!==S&&x.addGenerators(new U(u,S))})}}let h=o.instrumentZones[0].modulators.map(u=>CA.copy(u));for(let u of h){let f=!0;for(let S of o.instrumentZones){if(!f)continue;S.modulators.find(D=>CA.isIdentical(D,u))||(f=!1)}if(f===!0){l.addModulators(CA.copy(u));for(let S of o.instrumentZones){let w=S.modulators.find(D=>CA.isIdentical(D,u));w.transformAmount===u.transformAmount&&S.modulators.splice(S.modulators.indexOf(w),1)}}}}return o}var Po=20;function dn(e,A,t,n,s,o,r){let g=r===0?0:1,i=new L(Po+g*16);eA(i,Po),O(i,A),O(i,t);let E=n*.4,B=Math.floor(E*-65536);eA(i,B),eA(i,2);let l=o-s,c=0;switch(r){default:case 0:g=0;break;case 1:c=0,g=1;break;case 3:c=1,g=1}return eA(i,g),g===1&&(eA(i,16),eA(i,c),eA(i,s),eA(i,l)),z("wsmp",i)}var q={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:221,reverb:219,pitchWheelRange:256,fineTune:257,coarseTune:258},fn=new mA(219,0,a.reverbEffectsSend,1e3,0),un=new mA(221,0,a.chorusEffectsSend,1e3,0),mn=new mA(129,0,a.vibLfoToPitch,0,0),pn=new mA(13,0,a.vibLfoToPitch,0,0);var R={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 qt=class{source;control;destination;scale;transform;constructor(A,t,n,s,o){this.source=A,this.control=t,this.destination=n,this.scale=s,this.transform=o}writeArticulator(){let A=new L(12);return O(A,this.source),O(A,this.control),O(A,this.destination),O(A,this.transform),eA(A,this.scale<<16),A}};function Ko(e,A){if(e)switch(A){default:return;case p.modulationWheel:return q.modulationWheel;case p.mainVolume:return q.volume;case p.pan:return q.pan;case p.expressionController:return q.expression;case p.chorusDepth:return q.chorus;case p.reverbDepth:return q.reverb}else switch(A){default:return;case X.noteOnKeyNum:return q.keyNum;case X.noteOnVelocity:return q.velocity;case X.noController:return q.none;case X.polyPressure:return q.polyPressure;case X.channelPressure:return q.channelPressure;case X.pitchWheel:return q.pitchWheel;case X.pitchWheelRange:return q.pitchWheelRange}}function qo(e,A){switch(e){default:return;case a.initialAttenuation:return{dest:R.gain,amount:-A};case a.fineTune:return R.pitch;case a.pan:return R.pan;case a.keyNum:return R.keyNum;case a.reverbEffectsSend:return R.reverbSend;case a.chorusEffectsSend:return R.chorusSend;case a.freqModLFO:return R.modLfoFreq;case a.delayModLFO:return R.modLfoDelay;case a.delayVibLFO:return R.vibLfoDelay;case a.freqVibLFO:return R.vibLfoFreq;case a.delayVolEnv:return R.volEnvDelay;case a.attackVolEnv:return R.volEnvAttack;case a.holdVolEnv:return R.volEnvHold;case a.decayVolEnv:return R.volEnvDecay;case a.sustainVolEnv:return{dest:R.volEnvSustain,amount:1e3-A};case a.releaseVolEnv:return R.volEnvRelease;case a.delayModEnv:return R.modEnvDelay;case a.attackModEnv:return R.modEnvAttack;case a.holdModEnv:return R.modEnvHold;case a.decayModEnv:return R.modEnvDecay;case a.sustainModEnv:return{dest:R.modEnvSustain,amount:1e3-A};case a.releaseModEnv:return R.modEnvRelease;case a.initialFilterFc:return R.filterCutoff;case a.initialFilterQ:return R.filterQ}}function Vo(e,A){switch(e){default:return;case a.modEnvToFilterFc:return{source:q.modEnv,dest:R.filterCutoff,amt:A,isBipolar:!1};case a.modEnvToPitch:return{source:q.modEnv,dest:R.pitch,amt:A,isBipolar:!1};case a.modLfoToFilterFc:return{source:q.modLfo,dest:R.filterCutoff,amt:A,isBipolar:!0};case a.modLfoToVolume:return{source:q.modLfo,dest:R.gain,amt:A,isBipolar:!0};case a.modLfoToPitch:return{source:q.modLfo,dest:R.pitch,amt:A,isBipolar:!0};case a.vibLfoToPitch:return{source:q.vibratoLfo,dest:R.pitch,amt:A,isBipolar:!0};case a.keyNumToVolEnvHold:return{source:q.keyNum,dest:R.volEnvHold,amt:A,isBipolar:!0};case a.keyNumToVolEnvDecay:return{source:q.keyNum,dest:R.volEnvDecay,amt:A,isBipolar:!0};case a.keyNumToModEnvHold:return{source:q.keyNum,dest:R.modEnvHold,amt:A,isBipolar:!0};case a.keyNumToModEnvDecay:return{source:q.keyNum,dest:R.modEnvDecay,amt:A,isBipolar:!0};case a.scaleTuning:return{source:q.keyNum,dest:R.pitch,amt:A*128,isBipolar:!1}}}function Zo(e){let A=qo(e.generatorType,e.generatorValue),t=A,n=0,s=e.generatorValue;A?.amount!==void 0&&(s=A.amount,t=A.dest);let o=Vo(e.generatorType,e.generatorValue);if(o!==void 0)s=o.amt,t=o.dest,n=o.source;else if(t===void 0){Y(`Invalid generator type: ${e.generatorType}`);return}return new qt(n,0,t,s,0)}function Xo(e){if(e.transformType!==0){Y("Other transform types are not supported.");return}let A=Ko(e.sourceUsesCC,e.sourceIndex),t=e.sourceCurveType,n=e.sourcePolarity,s=e.sourceDirection;if(A===void 0){Y(`Invalid source: ${e.sourceIndex}, CC: ${e.sourceUsesCC}`);return}e.modulatorDestination===a.initialAttenuation&&(s=s===1?0:1);let o=Ko(e.secSrcUsesCC,e.secSrcIndex),r=e.secSrcCurveType,g=e.secSrcPolarity,i=e.secSrcDirection;if(o===void 0){Y(`Invalid secondary source: ${e.secSrcIndex}, CC: ${e.secSrcUsesCC}`);return}let E=qo(e.modulatorDestination,e.transformAmount),B=E,l=e.transformAmount;E?.dest!==void 0&&(B=E.dest,l=E.amount);let c=Vo(e.modulatorDestination,e.transformAmount);if(c!==void 0)l=c.amt,o=A,r=t,g=n,i=s,t=DA.linear,n=c.isBipolar?1:0,s=0,A=c.source,B=c.dest;else if(B===void 0){Y(`Invalid destination: ${e.modulatorDestination}`);return}let h=0;return h|=r<<4,h|=g<<8,h|=i<<9,h|=t,h|=n<<14,h|=s<<15,new qt(A,o,B,l,h)}var Ui=new Set([a.sampleModes,a.initialAttenuation,a.keyRange,a.velRange,a.sampleID,a.fineTune,a.coarseTune,a.startAddrsOffset,a.startAddrsCoarseOffset,a.endAddrOffset,a.endAddrsCoarseOffset,a.startloopAddrsOffset,a.startloopAddrsCoarseOffset,a.endloopAddrsOffset,a.endloopAddrsCoarseOffset,a.overridingRootKey,a.exclusiveClass]);function yn(e){for(let o=0;o<e.generators.length;o++){let r=e.generators[o];(r.generatorType===a.delayVolEnv||r.generatorType===a.attackVolEnv||r.generatorType===a.holdVolEnv||r.generatorType===a.decayVolEnv||r.generatorType===a.releaseVolEnv||r.generatorType===a.delayModEnv||r.generatorType===a.attackModEnv||r.generatorType===a.holdModEnv||r.generatorType===a.decayModEnv)&&(e.generators[o]=new U(r.generatorType,Math.min(r.generatorValue,6386),!1))}for(let o=0;o<e.generators.length;o++){let r=e.generators[o],g;switch(r.generatorType){default:continue;case a.keyNumToVolEnvDecay:g=a.decayVolEnv;break;case a.keyNumToVolEnvHold:g=a.holdVolEnv;break;case a.keyNumToModEnvDecay:g=a.decayModEnv;break;case a.keyNumToModEnvHold:g=a.holdModEnv}let i=e.generators.find(u=>u.generatorType===g);if(i===void 0)continue;let E=r.generatorValue*-128,B=60/128*E,l=i.generatorValue-B,c=e.generators.indexOf(r),h=e.generators.indexOf(i);e.generators[h]=new U(g,l,!1),e.generators[c]=new U(r.generatorType,E,!1)}let A=e.generators.reduce((o,r)=>{if(Ui.has(r.generatorType))return o;let g=Zo(r);return g!==void 0?(o.push(g),y("%cSucceeded converting to DLS Articulator!",I.recognized)):Y("Failed converting to DLS Articulator!"),o},[]),t=e.modulators.reduce((o,r)=>{if(CA.isIdentical(r,un,!0)||CA.isIdentical(r,fn,!0)||CA.isIdentical(r,mn,!0)||CA.isIdentical(r,pn,!0))return o;let g=Xo(r);return g!==void 0?(o.push(g),y("%cSucceeded converting to DLS Articulator!",I.recognized)):Y("Failed converting to DLS Articulator!"),o},[]);A.push(...t);let n=new L(8);eA(n,8),eA(n,A.length);let s=A.map(o=>o.writeArticulator());return z("art2",kA([n,...s]))}function Wo(e,A){let t=new L(12);O(t,Math.max(e.keyRange.min,0)),O(t,e.keyRange.max),O(t,Math.max(e.velRange.min,0)),O(t,e.velRange.max),O(t,0);let n=e.getGeneratorValue(a.exclusiveClass,0);O(t,n),O(t,0);let s=z("rgnh",t),o=e.getGeneratorValue(a.overridingRootKey,e.sample.samplePitch);e.getGeneratorValue(a.scaleTuning,A.getGeneratorValue(a.scaleTuning,100))===0&&e.keyRange.max-e.keyRange.min===0&&(o=e.keyRange.min);let g=dn(e.sample,o,e.getGeneratorValue(a.fineTune,0)+e.getGeneratorValue(a.coarseTune,0)*100+e.sample.samplePitchCorrection,e.getGeneratorValue(a.initialAttenuation,0),e.sample.sampleLoopStartIndex+e.getGeneratorValue(a.startloopAddrsOffset,0)+e.getGeneratorValue(a.startloopAddrsCoarseOffset,0)*32768,e.sample.sampleLoopEndIndex+e.getGeneratorValue(a.endloopAddrsOffset,0)+e.getGeneratorValue(a.endloopAddrsCoarseOffset,0)*32768,e.getGeneratorValue(a.sampleModes,0)),i=new L(12);O(i,0),O(i,0),eA(i,1),eA(i,this.samples.indexOf(e.sample));let E=z("wlnk",i),B=new L(0);if(e.modulators.length+e.generators.length>0){let l=yn(e);B=z("lar2",l,!1,!0)}return z("rgn2",kA([s,g,E,B]),!1,!0)}function _o(e){QA(`%cWriting %c${e.presetName}%c...`,I.info,I.recognized,I.info);let A=Jo(e),t=A.globalZone,n=A.instrumentZones,s=new L(12);eA(s,n.length);let o=(e.bank&127)<<8;e.bank===128&&(o|=1<<31),eA(s,o),eA(s,e.program&127);let r=z("insh",s),g=yn(t),i=z("lar2",g,!1,!0),E=kA(n.reduce((h,u)=>(h.push(Wo.apply(this,[u,t])),h),[])),B=z("lrgn",E,!1,!0),l=z("INAM",VA(e.presetName,!0)),c=z("INFO",l,!1,!0);return P(),z("ins ",kA([r,B,i,c]),!1,!0)}function zo(){let e=kA(this.presets.map(A=>_o.apply(this,[A])));return z("lins",e,!1,!0)}function jo(e){let A=new L(18);O(A,1),O(A,1),eA(A,e.sampleRate),eA(A,e.sampleRate*2),O(A,2),O(A,16);let t=z("fmt ",A),n=1;e.sampleLoopStartIndex+Math.abs(e.getAudioData().length-e.sampleLoopEndIndex)<2&&(n=0);let s=dn(e,e.samplePitch,e.samplePitchCorrection,0,e.sampleLoopStartIndex,e.sampleLoopEndIndex,n),o=e.getAudioData(),r;if(e.isCompressed){let E=new Int16Array(o.length);for(let B=0;B<o.length;B++)E[B]=o[B]*32767;r=z("data",new L(E.buffer))}else r=z("data",e.getRawData());let g=z("INAM",VA(e.sampleName,!0)),i=z("INFO",g,!1,!0);return y(`%cSaved %c${e.sampleName}%c succesfully!`,I.recognized,I.value,I.recognized),z("wave",kA([t,s,r,i]),!1,!0)}function $o(){let e=0,A=[],t=this.samples.map(n=>{let s=jo(n);return A.push(e),e+=s.length,s});return{data:z("wvpl",kA(t),!1,!0),indexes:A}}function Ar(){QA("%cSaving DLS...",I.info);let e=new L(4);eA(e,this.presets.length);let A=z("colh",e);QA("%cWriting instruments...",I.info);let t=zo.apply(this);y("%cSuccess!",I.recognized),P(),QA("%cWriting WAVE samples...",I.info);let n=$o.apply(this),s=n.data,o=n.indexes;y("%cSucceeded!",I.recognized),P();let r=new L(8+4*o.length);eA(r,8),eA(r,o.length);for(let l of o)eA(r,l);let g=z("ptbl",r);this.soundFontInfo.ICMT=(this.soundFontInfo.ICMT||"Soundfont")+`
|
|
11
|
-
Converted from SF2 to DLS using SpessaSynth`,this.soundFontInfo.ISFT="SpessaSynth";let i=[];for(let[l,c]of Object.entries(this.soundFontInfo))l!=="ICMT"&&l!=="INAM"&&l!=="ICRD"&&l!=="IENG"&&l!=="ICOP"&&l!=="ISFT"&&l!=="ISBJ"||i.push(z(l,VA(c,!0),!0));let E=z("INFO",kA(i),!1,!0),B=new L(A.length+t.length+g.length+s.length+E.length+4);return bA(B,"DLS "),B.set(kA([A,t,g,s,E]),4),y("%cSaved succesfully!",I.recognized),P(),z("RIFF",B)}var vi=48e3,xe=class{sampleName;sampleRate;samplePitch;samplePitchCorrection;sampleLink;sampleType;sampleLoopStartIndex;sampleLoopEndIndex;isCompressed;compressedData=void 0;linkedInstruments=[];sampleData=void 0;constructor(A,t,n,s,o,r,g,i){this.sampleName=A,this.sampleRate=t,this.samplePitch=n,this.samplePitchCorrection=s,this.sampleLink=o,this.sampleType=r,this.sampleLoopStartIndex=g,this.sampleLoopEndIndex=i,this.isCompressed=(r&16)>0}get useCount(){return this.linkedInstruments.length}getRawData(){let A=new Uint8Array(this.sampleData.length*2);for(let t=0;t<this.sampleData.length;t++){let n=Math.floor(this.sampleData[t]*32768);A[t*2]=n&255,A[t*2+1]=n>>8&255}return A}resampleData(A){let t=this.getAudioData(),n=A/this.sampleRate,s=new Float32Array(Math.floor(t.length*n));for(let o=0;o<s.length;o++)s[o]=t[Math.floor(o*(1/n))];t=s,this.sampleRate=A,this.sampleLoopStartIndex=Math.floor(this.sampleLoopStartIndex*n),this.sampleLoopEndIndex=Math.floor(this.sampleLoopEndIndex*n),this.sampleData=t}compressSample(A,t){if(!this.isCompressed)try{let n=this.getAudioData();(this.sampleRate<8e3||this.sampleRate>96e3)&&(this.resampleData(vi),n=this.getAudioData()),this.compressedData=t([n],1,this.sampleRate,A),this.sampleType|=16,this.isCompressed=!0}catch{Y(`Failed to compress ${this.sampleName}. Leaving as uncompressed!`),this.isCompressed=!1,this.compressedData=void 0,this.sampleType&=239}}linkTo(A){this.linkedInstruments.push(A)}unlinkFrom(A){let t=this.linkedInstruments.indexOf(A);if(t<0)throw new Error(`Cannot unlink ${A.instrumentName} from ${this.sampleName}: not linked.`);this.linkedInstruments.splice(t,1)}getAudioData(){return this.sampleData}};var nt=class e extends qe{parentPreset;instrument;constructor(A){super(),this.parentPreset=A}deleteZone(){this.instrument.unlinkFrom(this.parentPreset)}setInstrument(A){this.instrument=A,this.instrument.linkTo(this.parentPreset)}copyFrom(A){super.copyFrom(A),A instanceof e&&(this.instrument=A.instrument)}};var Ne=class{parentSoundBank;presetName="";program=0;bank=0;presetZones=[];globalZone=new Ve;library=0;genre=0;morphology=0;constructor(A){this.parentSoundBank=A}isDrumPreset(A,t=!1){let n=A&&this.parentSoundBank.isXGBank;return this.bank===128||n&&te(this.bank)&&(this.bank!==126||t)}deletePreset(){this.presetZones.forEach(A=>A.deleteZone()),this.presetZones.length=0}deleteZone(A){this.presetZones[A].deleteZone(),this.presetZones.splice(A,1)}createZone(){let A=new nt(this);return this.presetZones.push(A),A}preload(A,t){for(let n=A;n<t+1;n++)for(let s=0;s<128;s++)this.getSamplesAndGenerators(n,s).forEach(o=>{o.sample.isSampleLoaded||o.sample.getAudioData()})}getSamplesAndGenerators(A,t){if(this.presetZones.length<1)return[];function n(c,h){return h>=c.min&&h<=c.max}function s(c,h){c.push(...h.filter(u=>!c.find(f=>f.generatorType===u.generatorType)))}function o(c,h){c.push(...h.filter(u=>!c.find(f=>CA.isIdentical(u,f))))}let r=[],g=[...this.globalZone.generators],i=[...this.globalZone.modulators],E=this.globalZone.keyRange,B=this.globalZone.velRange;return this.presetZones.filter(c=>n(c.hasKeyRange?c.keyRange:E,A)&&n(c.hasVelRange?c.velRange:B,t)).forEach(c=>{let h=c.instrument;if(h.instrumentZones.length<1)return;let u=c.generators,f=c.modulators,S=[...h.globalZone.generators],w=[...h.globalZone.modulators],D=h.globalZone.keyRange,x=h.globalZone.velRange;h.instrumentZones.filter(G=>n(G.hasKeyRange?G.keyRange:D,A)&&n(G.hasVelRange?G.velRange:x,t)).forEach(G=>{let C=[...G.generators],N=[...G.modulators];s(u,g),s(C,S),o(f,i),o(N,w),o(N,this.parentSoundBank.defaultModulators);let M=[...N];for(let $=0;$<f.length;$++){let iA=f[$],Z=M.findIndex(IA=>CA.isIdentical(iA,IA));Z!==-1?M[Z]=M[Z].sumTransform(iA):M.push(iA)}r.push({instrumentGenerators:C,presetGenerators:u,modulators:M,sample:G.sample})})}),r}};var be=class e{soundFontInfo={};presets=[];samples=[];instruments=[];defaultModulators=so.map(A=>CA.copy(A));customDefaultModulators=!1;isXGBank=!1;constructor(A=void 0){if(A?.presets){this.soundFontInfo=A.info,this.addPresets(...A.presets);let t=[];for(let s of A.presets)for(let o of s.presetZones)t.includes(o.instrument)||t.push(o.instrument);this.addInstruments(...t);let n=[];for(let s of t)for(let o of s.instrumentZones)n.includes(o.sample)||n.push(o.sample);this.addSamples(...n)}}static mergeSoundBanks(...A){let t=A.shift(),n=t.presets;for(;A.length;)A.shift().presets.forEach(o=>{n.find(r=>r.bank===o.bank&&r.program===o.program)===void 0&&n.push(o)});return new e({presets:n,info:t.soundFontInfo})}static getDummySoundfontFile(){let A=new e,t=new xe("Saw",44100,65,20,0,0,0,127);t.sampleData=new Float32Array(128);for(let E=0;E<128;E++)t.sampleData[E]=E/128*2-1;A.addSamples(t);let n=new Ve;n.addGenerators(new U(a.initialAttenuation,375),new U(a.releaseVolEnv,-1e3),new U(a.sampleModes,1));let s=new Be;s.instrumentName="Saw Wave",s.globalZone=n,s.createZone().setSample(t);let r=s.createZone();r.setSample(t),r.addGenerators(new U(a.fineTune,-9)),A.addInstruments(s);let g=new Ne(A);return g.presetName="Saw Wave",g.createZone().setInstrument(s),A.addPresets(g),A.soundFontInfo.ifil="2.1",A.soundFontInfo.isng="EMU8000",A.soundFontInfo.INAM="Dummy",A.flush(),A.write().buffer}addPresets(...A){this.presets.push(...A)}flush(){this.presets.sort((A,t)=>A.bank!==t.bank?A.bank-t.bank:A.program-t.program),this._parseInternal()}addInstruments(...A){this.instruments.push(...A)}addSamples(...A){this.samples.push(...A)}_parseInternal(){this.isXGBank=!1;let A=new Set([0,1,2,3,4,5,6,7,8,9,16,17,24,25,27,28,29,30,31,32,33,40,41,48,56,57,58,64,65,66,126,127]);for(let t of this.presets)if(te(t.bank)&&(this.isXGBank=!0,!A.has(t.program))){this.isXGBank=!1,y(`%cThis bank is not valid XG. Preset %c${t.bank}:${t.program}%c is not a valid XG drum. XG mode will use presets on bank 128.`,I.info,I.value,I.info);break}}trimSoundBank(A){let t=this;function n(o,r){let g=0;for(let i=0;i<o.instrumentZones.length;i++){let E=o.instrumentZones[i],B=E.keyRange,l=E.velRange,c=!1;for(let h of r)if(h.key>=B.min&&h.key<=B.max&&h.velocity>=l.min&&h.velocity<=l.max){c=!0;break}c||(y(`%c${E.sample.sampleName} %cremoved from %c${o.instrumentName}%c.`,I.recognized,I.info,I.recognized,I.info),o.deleteZone(i)&&(g++,i--,y(`%c${E.sample.sampleName} %cdeleted`,I.recognized,I.info)),E.sample.useCount<1&&t.deleteSample(E.sample))}return g}Ie("%cTrimming soundfont...",I.info);let s=A.getUsedProgramsAndKeys(t);QA("%cModifying soundfont...",I.info),y("Detected keys for midi:",s);for(let o=0;o<t.presets.length;o++){let r=t.presets[o],g=r.bank+":"+r.program,i=s[g];if(i===void 0)y(`%cDeleting preset %c${r.presetName}%c and its zones`,I.info,I.recognized,I.info),t.deletePreset(r),t.removeUnusedElements(),o--;else{let E=[...i].map(l=>{let c=l.split("-");return{key:parseInt(c[0]),velocity:parseInt(c[1])}});QA(`%cTrimming %c${r.presetName}`,I.info,I.recognized),y(`Keys for ${r.presetName}:`,E);let B=0;for(let l=0;l<r.presetZones.length;l++){let c=r.presetZones[l],h=c.keyRange,u=c.velRange,f=!1;for(let S of E)if(S.key>=h.min&&S.key<=h.max&&S.velocity>=u.min&&S.velocity<=u.max){f=!0;let w=n(c.instrument,E);y(`%cTrimmed off %c${w}%c zones from %c${c.instrument.instrumentName}`,I.info,I.recognized,I.info,I.recognized);break}f||(B++,r.deleteZone(l),c.instrument.useCount<1&&t.deleteInstrument(c.instrument),l--)}y(`%cTrimmed off %c${B}%c zones from %c${r.presetName}`,I.info,I.recognized,I.info,I.recognized),P()}}t.removeUnusedElements(),t.soundFontInfo.ICMT=`NOTE: This soundfont was trimmed by SpessaSynth to only contain presets used in "${A.midiName}"
|
|
11
|
+
Converted from SF2 to DLS using SpessaSynth`,this.soundFontInfo.ISFT="SpessaSynth";let i=[];for(let[l,c]of Object.entries(this.soundFontInfo))l!=="ICMT"&&l!=="INAM"&&l!=="ICRD"&&l!=="IENG"&&l!=="ICOP"&&l!=="ISFT"&&l!=="ISBJ"||i.push(z(l,VA(c,!0),!0));let E=z("INFO",kA(i),!1,!0),B=new L(A.length+t.length+g.length+s.length+E.length+4);return bA(B,"DLS "),B.set(kA([A,t,g,s,E]),4),y("%cSaved succesfully!",I.recognized),P(),z("RIFF",B)}var vi=48e3,xe=class{sampleName;sampleRate;samplePitch;samplePitchCorrection;sampleLink;sampleType;sampleLoopStartIndex;sampleLoopEndIndex;isCompressed;compressedData=void 0;linkedInstruments=[];sampleData=void 0;constructor(A,t,n,s,o,r,g,i){this.sampleName=A,this.sampleRate=t,this.samplePitch=n,this.samplePitchCorrection=s,this.sampleLink=o,this.sampleType=r,this.sampleLoopStartIndex=g,this.sampleLoopEndIndex=i,this.isCompressed=(r&16)>0}get useCount(){return this.linkedInstruments.length}getRawData(){let A=new Uint8Array(this.sampleData.length*2);for(let t=0;t<this.sampleData.length;t++){let n=Math.floor(this.sampleData[t]*32768);A[t*2]=n&255,A[t*2+1]=n>>8&255}return A}resampleData(A){let t=this.getAudioData(),n=A/this.sampleRate,s=new Float32Array(Math.floor(t.length*n));for(let o=0;o<s.length;o++)s[o]=t[Math.floor(o*(1/n))];t=s,this.sampleRate=A,this.sampleLoopStartIndex=Math.floor(this.sampleLoopStartIndex*n),this.sampleLoopEndIndex=Math.floor(this.sampleLoopEndIndex*n),this.sampleData=t}compressSample(A,t){if(!this.isCompressed)try{let n=this.getAudioData();(this.sampleRate<8e3||this.sampleRate>96e3)&&(this.resampleData(vi),n=this.getAudioData()),this.compressedData=t([n],1,this.sampleRate,A),this.sampleType|=16,this.isCompressed=!0}catch{Y(`Failed to compress ${this.sampleName}. Leaving as uncompressed!`),this.isCompressed=!1,this.compressedData=void 0,this.sampleType&=239}}linkTo(A){this.linkedInstruments.push(A)}unlinkFrom(A){let t=this.linkedInstruments.indexOf(A);if(t<0)throw new Error(`Cannot unlink ${A.instrumentName} from ${this.sampleName}: not linked.`);this.linkedInstruments.splice(t,1)}getAudioData(){if(!this.sampleData)throw new Error("Error! Sample data is undefined. Is the method overriden properly?");return this.sampleData}setAudioData(A){this.isCompressed=!1,delete this.compressedData,this.sampleData=A}};var nt=class e extends qe{parentPreset;instrument;constructor(A){super(),this.parentPreset=A}deleteZone(){this.instrument.unlinkFrom(this.parentPreset)}setInstrument(A){this.instrument=A,this.instrument.linkTo(this.parentPreset)}copyFrom(A){super.copyFrom(A),A instanceof e&&(this.instrument=A.instrument)}};var Ne=class{parentSoundBank;presetName="";program=0;bank=0;presetZones=[];globalZone=new Ve;library=0;genre=0;morphology=0;constructor(A){this.parentSoundBank=A}isDrumPreset(A,t=!1){let n=A&&this.parentSoundBank.isXGBank;return this.bank===128||n&&te(this.bank)&&(this.bank!==126||t)}deletePreset(){this.presetZones.forEach(A=>A.deleteZone()),this.presetZones.length=0}deleteZone(A){this.presetZones[A].deleteZone(),this.presetZones.splice(A,1)}createZone(){let A=new nt(this);return this.presetZones.push(A),A}preload(A,t){for(let n=A;n<t+1;n++)for(let s=0;s<128;s++)this.getSamplesAndGenerators(n,s).forEach(o=>{o.sample.isSampleLoaded||o.sample.getAudioData()})}getSamplesAndGenerators(A,t){if(this.presetZones.length<1)return[];function n(c,h){return h>=c.min&&h<=c.max}function s(c,h){c.push(...h.filter(u=>!c.find(f=>f.generatorType===u.generatorType)))}function o(c,h){c.push(...h.filter(u=>!c.find(f=>CA.isIdentical(u,f))))}let r=[],g=[...this.globalZone.generators],i=[...this.globalZone.modulators],E=this.globalZone.keyRange,B=this.globalZone.velRange;return this.presetZones.filter(c=>n(c.hasKeyRange?c.keyRange:E,A)&&n(c.hasVelRange?c.velRange:B,t)).forEach(c=>{let h=c.instrument;if(h.instrumentZones.length<1)return;let u=c.generators,f=c.modulators,S=[...h.globalZone.generators],w=[...h.globalZone.modulators],D=h.globalZone.keyRange,x=h.globalZone.velRange;h.instrumentZones.filter(G=>n(G.hasKeyRange?G.keyRange:D,A)&&n(G.hasVelRange?G.velRange:x,t)).forEach(G=>{let C=[...G.generators],N=[...G.modulators];s(u,g),s(C,S),o(f,i),o(N,w),o(N,this.parentSoundBank.defaultModulators);let M=[...N];for(let $=0;$<f.length;$++){let iA=f[$],Z=M.findIndex(IA=>CA.isIdentical(iA,IA));Z!==-1?M[Z]=M[Z].sumTransform(iA):M.push(iA)}r.push({instrumentGenerators:C,presetGenerators:u,modulators:M,sample:G.sample})})}),r}};var be=class e{soundFontInfo={};presets=[];samples=[];instruments=[];defaultModulators=so.map(A=>CA.copy(A));customDefaultModulators=!1;isXGBank=!1;constructor(A=void 0){if(A?.presets){this.soundFontInfo=A.info,this.addPresets(...A.presets);let t=[];for(let s of A.presets)for(let o of s.presetZones)t.includes(o.instrument)||t.push(o.instrument);this.addInstruments(...t);let n=[];for(let s of t)for(let o of s.instrumentZones)n.includes(o.sample)||n.push(o.sample);this.addSamples(...n)}}static mergeSoundBanks(...A){let t=A.shift(),n=t.presets;for(;A.length;)A.shift().presets.forEach(o=>{n.find(r=>r.bank===o.bank&&r.program===o.program)===void 0&&n.push(o)});return new e({presets:n,info:t.soundFontInfo})}static getDummySoundfontFile(){let A=new e,t=new xe("Saw",44100,65,20,0,0,0,127);t.sampleData=new Float32Array(128);for(let E=0;E<128;E++)t.sampleData[E]=E/128*2-1;A.addSamples(t);let n=new Ve;n.addGenerators(new U(a.initialAttenuation,375),new U(a.releaseVolEnv,-1e3),new U(a.sampleModes,1));let s=new Be;s.instrumentName="Saw Wave",s.globalZone=n,s.createZone().setSample(t);let r=s.createZone();r.setSample(t),r.addGenerators(new U(a.fineTune,-9)),A.addInstruments(s);let g=new Ne(A);return g.presetName="Saw Wave",g.createZone().setInstrument(s),A.addPresets(g),A.soundFontInfo.ifil="2.1",A.soundFontInfo.isng="EMU8000",A.soundFontInfo.INAM="Dummy",A.flush(),A.write().buffer}addPresets(...A){this.presets.push(...A)}flush(){this.presets.sort((A,t)=>A.bank!==t.bank?A.bank-t.bank:A.program-t.program),this._parseInternal()}addInstruments(...A){this.instruments.push(...A)}addSamples(...A){this.samples.push(...A)}_parseInternal(){this.isXGBank=!1;let A=new Set([0,1,2,3,4,5,6,7,8,9,16,17,24,25,27,28,29,30,31,32,33,40,41,48,56,57,58,64,65,66,126,127]);for(let t of this.presets)if(te(t.bank)&&(this.isXGBank=!0,!A.has(t.program))){this.isXGBank=!1,y(`%cThis bank is not valid XG. Preset %c${t.bank}:${t.program}%c is not a valid XG drum. XG mode will use presets on bank 128.`,I.info,I.value,I.info);break}}trimSoundBank(A){let t=this;function n(o,r){let g=0;for(let i=0;i<o.instrumentZones.length;i++){let E=o.instrumentZones[i],B=E.keyRange,l=E.velRange,c=!1;for(let h of r)if(h.key>=B.min&&h.key<=B.max&&h.velocity>=l.min&&h.velocity<=l.max){c=!0;break}c||(y(`%c${E.sample.sampleName} %cremoved from %c${o.instrumentName}%c.`,I.recognized,I.info,I.recognized,I.info),o.deleteZone(i)&&(g++,i--,y(`%c${E.sample.sampleName} %cdeleted`,I.recognized,I.info)),E.sample.useCount<1&&t.deleteSample(E.sample))}return g}Ie("%cTrimming soundfont...",I.info);let s=A.getUsedProgramsAndKeys(t);QA("%cModifying soundfont...",I.info),y("Detected keys for midi:",s);for(let o=0;o<t.presets.length;o++){let r=t.presets[o],g=r.bank+":"+r.program,i=s[g];if(i===void 0)y(`%cDeleting preset %c${r.presetName}%c and its zones`,I.info,I.recognized,I.info),t.deletePreset(r),t.removeUnusedElements(),o--;else{let E=[...i].map(l=>{let c=l.split("-");return{key:parseInt(c[0]),velocity:parseInt(c[1])}});QA(`%cTrimming %c${r.presetName}`,I.info,I.recognized),y(`Keys for ${r.presetName}:`,E);let B=0;for(let l=0;l<r.presetZones.length;l++){let c=r.presetZones[l],h=c.keyRange,u=c.velRange,f=!1;for(let S of E)if(S.key>=h.min&&S.key<=h.max&&S.velocity>=u.min&&S.velocity<=u.max){f=!0;let w=n(c.instrument,E);y(`%cTrimmed off %c${w}%c zones from %c${c.instrument.instrumentName}`,I.info,I.recognized,I.info,I.recognized);break}f||(B++,r.deleteZone(l),c.instrument.useCount<1&&t.deleteInstrument(c.instrument),l--)}y(`%cTrimmed off %c${B}%c zones from %c${r.presetName}`,I.info,I.recognized,I.info,I.recognized),P()}}t.removeUnusedElements(),t.soundFontInfo.ICMT=`NOTE: This soundfont was trimmed by SpessaSynth to only contain presets used in "${A.midiName}"
|
|
12
12
|
|
|
13
13
|
`+t.soundFontInfo.ICMT,y("%cSoundfont modified!",I.recognized),P(),P()}removeUnusedElements(){this.instruments.forEach(A=>{A.useCount<1&&A.deleteAllZones()}),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.deleteAllZones()}deletePreset(A){A.deletePreset(),this.presets.splice(this.presets.indexOf(A),1)}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)}getPresetNoFallback(A,t,n=!1){let s=A===128||n&&te(A),o;if(s?o=this.presets.find(r=>r.bank===A&&r.isDrumPreset(n)&&r.program===t):o=this.presets.find(r=>r.bank===A&&r.program===t),o)return o;if(s&&n){let r=this.presets.find(g=>g.isDrumPreset(n)&&g.program===t);if(r)return r}}getPreset(A,t,n=!1){let s=A===128||n&&te(A),o;return s?o=this.presets.find(r=>r.bank===A&&r.isDrumPreset(n)&&r.program===t):o=this.presets.find(r=>r.bank===A&&r.program===t),o||(s?(o=this.presets.find(r=>r.isDrumPreset(n)&&r.program===t),o||(o=this.presets.find(r=>r.isDrumPreset(n)))):o=this.presets.find(r=>r.program===t&&!r.isDrumPreset(n)),o&&Y(`%cPreset ${A}.${t} not found. Replaced with %c${o.presetName} (${o.bank}.${o.program})`,I.warn,I.recognized),o||(Y(`Preset ${t} not found. Defaulting to`,this.presets[0].presetName),o=this.presets[0]),o)}getPresetByName(A){let t=this.presets.find(n=>n.presetName===A);return t||(Y("Preset not found. Defaulting to:",this.presets[0].presetName),t=this.presets[0]),t}parsingError(A){throw new Error(`SF parsing error: ${A} The file may be corrupted.`)}destroySoundBank(){delete this.presets,delete this.instruments,delete this.samples}};be.prototype.write=Oo;be.prototype.writeDLS=Ar;function er(e){QA("%cLoading instruments...",I.info);for(let A=0;A<this.instrumentAmount;A++)this.readDLSInstrument(gA(e.chunkData));P()}var Sn=class extends Me{constructor(A){super(A)}setWavesample(A,t,n,s,o,r,g){t!==0&&this.addGenerators(new U(a.sampleModes,t)),this.addGenerators(new U(a.initialAttenuation,A)),g-=o.samplePitchCorrection;let i=Math.trunc(g/100);i!==0&&this.addGenerators(new U(a.coarseTune,i));let E=g-i*100;if(E!==0&&this.addGenerators(new U(a.fineTune,E)),t!==0){let B=n.start-o.sampleLoopStartIndex,l=n.end-o.sampleLoopEndIndex;if(B!==0){let c=B%32768;this.addGenerators(new U(a.startloopAddrsOffset,c));let h=Math.trunc(B/32768);h!==0&&this.addGenerators(new U(a.startloopAddrsCoarseOffset,h))}if(l!==0){let c=l%32768;this.addGenerators(new U(a.endloopAddrsOffset,c));let h=Math.trunc(l/32768);h!==0&&this.addGenerators(new U(a.endloopAddrsCoarseOffset,h))}}s!==o.samplePitch&&this.addGenerators(new U(a.overridingRootKey,s)),this.setSample(o)}};var Dn=class extends Be{constructor(){super()}createZone(){let A=new Sn(this);return this.instrumentZones.push(A),A}};var kn=class extends Ne{dlsInstrument=new Dn;constructor(A,t,n){super(A),this.program=n&127;let s=t>>8&127,o=t&127;s>0?this.bank=s:this.bank=o,t>>31&&(this.bank=128),this.createZone().setInstrument(this.dlsInstrument)}};function tr(e){this.verifyHeader(e,"LIST"),this.verifyText(AA(e.chunkData,4),"ins ");let A=[];for(;e.chunkData.length>e.chunkData.currentIndex;)A.push(gA(e.chunkData));let t=A.find(h=>h.header==="insh");if(!t)throw P(),new Error("No instrument header!");let n=b(t.chunkData,4),s=b(t.chunkData,4),o=b(t.chunkData,4),r=new kn(this,s,o),g="unnamedPreset",i=_A(A,"INFO");if(i){let h=gA(i.chunkData);for(;h.header!=="INAM";)h=gA(i.chunkData);g=AA(h.chunkData,h.chunkData.length).trim()}r.presetName=g,r.dlsInstrument.instrumentName=g,QA(`%cParsing %c"${g}"%c...`,I.info,I.recognized,I.info);let E=_A(A,"lrgn");if(!E)throw P(),new Error("No region list!");let B=r.dlsInstrument.globalZone,l=_A(A,"lart"),c=_A(A,"lar2");(c!==void 0||l!==void 0)&&this.readLart(l,c,B),B.generators=B.generators.filter(h=>h.generatorValue!==K[h.generatorType].def),B.modulators.find(h=>h.modulatorDestination===a.reverbEffectsSend)===void 0&&B.addModulators(CA.copy(fn)),B.modulators.find(h=>h.modulatorDestination===a.chorusEffectsSend)===void 0&&B.addModulators(CA.copy(un));for(let h=0;h<n;h++){let u=gA(E.chunkData);this.verifyHeader(u,"LIST");let f=AA(u.chunkData,4);f!=="rgn "&&f!=="rgn2"&&(P(),this.parsingError(`Invalid DLS region! Expected "rgn " or "rgn2" got "${f}"`));let S=r.dlsInstrument.createZone();this.readRegion(u,S)}this.addPresets(r),this.addInstruments(r.dlsInstrument),P()}function nr(e){let A,t=!1;switch(e){default:case q.modLfo:case q.vibratoLfo:case q.coarseTune:case q.fineTune:case q.modEnv:return;case q.keyNum:A=X.noteOnKeyNum;break;case q.none:A=X.noController;break;case q.modulationWheel:A=p.modulationWheel,t=!0;break;case q.pan:A=p.pan,t=!0;break;case q.reverb:A=p.reverbDepth,t=!0;break;case q.chorus:A=p.chorusDepth,t=!0;break;case q.expression:A=p.expressionController,t=!0;break;case q.volume:A=p.mainVolume,t=!0;break;case q.velocity:A=X.noteOnVelocity;break;case q.polyPressure:A=X.polyPressure;break;case q.channelPressure:A=X.channelPressure;break;case q.pitchWheel:A=X.pitchWheel;break;case q.pitchWheelRange:A=X.pitchWheelRange;break}if(A===void 0)throw new Error(`Unknown DLS Source: ${e}`);return{enum:A,isCC:t}}function Hi(e,A){switch(e){default:case R.none:return;case R.pan:return a.pan;case R.gain:return{gen:a.initialAttenuation,newAmount:A*-1};case R.pitch:return a.fineTune;case R.keyNum:return a.overridingRootKey;case R.volEnvDelay:return a.delayVolEnv;case R.volEnvAttack:return a.attackVolEnv;case R.volEnvHold:return a.holdVolEnv;case R.volEnvDecay:return a.decayVolEnv;case R.volEnvSustain:return{gen:a.sustainVolEnv,newAmount:1e3-A};case R.volEnvRelease:return a.releaseVolEnv;case R.modEnvDelay:return a.delayModEnv;case R.modEnvAttack:return a.attackModEnv;case R.modEnvHold:return a.holdModEnv;case R.modEnvDecay:return a.decayModEnv;case R.modEnvSustain:return{gen:a.sustainModEnv,newAmount:(1e3-A)/10};case R.modEnvRelease:return a.releaseModEnv;case R.filterCutoff:return a.initialFilterFc;case R.filterQ:return a.initialFilterQ;case R.chorusSend:return a.chorusEffectsSend;case R.reverbSend:return a.reverbEffectsSend;case R.modLfoFreq:return a.freqModLFO;case R.modLfoDelay:return a.delayModLFO;case R.vibLfoFreq:return a.freqVibLFO;case R.vibLfoDelay:return a.delayVibLFO}}function Yi(e,A){return e===q.vibratoLfo&&A===R.pitch?a.vibLfoToPitch:e===q.modLfo&&A===R.pitch?a.modLfoToPitch:e===q.modLfo&&A===R.filterCutoff?a.modLfoToFilterFc:e===q.modLfo&&A===R.gain?a.modLfoToVolume:e===q.modEnv&&A===R.filterCutoff?a.modEnvToFilterFc:e===q.modEnv&&A===R.pitch?a.modEnvToPitch:void 0}function sr(e,A,t,n,s){let o=Yi(e,t),r,g,i=!1,E=!1,B=s;if(o===void 0){let w=Hi(t,s);if(w===void 0){Y(`Invalid destination: ${t}`);return}if(r=w,w.newAmount!==void 0&&(B=w.newAmount,r=w.gen),g=nr(e),g===void 0){Y(`Invalid source: ${e}`);return}}else r=o,i=!0,g={enum:X.noController,isCC:!1},E=!0;let l=nr(A);if(l===void 0){Y(`Invalid control: ${A}`);return}let c;if(E)c=0;else{let w=n&15,D=n>>10&15;D===DA.linear&&w!==DA.linear&&(D=w);let x=n>>14&1,v=n>>15&1;r===a.initialAttenuation&&s<0&&(v=1),c=XA(D,x,v,g.isCC,g.enum)}r===a.initialAttenuation&&(B=Math.max(960,Math.min(0,B)));let h=n>>4&15,u=n>>8&1,f=n>>9&1,S=XA(h,u,f,l.isCC,l.enum);if(i){let w=S;S=c,c=w}return new mA(c,S,r,B,0)}function fs(e,A){let t=e.chunkData,n=[],s=[];b(t,4);let o=b(t,4);for(let r=0;r<o;r++){let g=b(t,2),i=b(t,2),E=b(t,2),B=b(t,2),c=(b(t,4)|0)>>16;if(g===0&&i===0&&B===0){let h;switch(E){case R.pan:h=new U(a.pan,c);break;case R.gain:h=new U(a.initialAttenuation,-c*10/.4);break;case R.filterCutoff:h=new U(a.initialFilterFc,c);break;case R.filterQ:h=new U(a.initialFilterQ,c);break;case R.modLfoFreq:h=new U(a.freqModLFO,c);break;case R.modLfoDelay:h=new U(a.delayModLFO,c);break;case R.vibLfoFreq:h=new U(a.freqVibLFO,c);break;case R.vibLfoDelay:h=new U(a.delayVibLFO,c);break;case R.volEnvDelay:h=new U(a.delayVolEnv,c);break;case R.volEnvAttack:h=new U(a.attackVolEnv,c);break;case R.volEnvHold:h=new U(a.holdVolEnv,c,!1);break;case R.volEnvDecay:h=new U(a.decayVolEnv,c,!1);break;case R.volEnvRelease:h=new U(a.releaseVolEnv,c);break;case R.volEnvSustain:let u=1e3-c;h=new U(a.sustainVolEnv,u);break;case R.modEnvDelay:h=new U(a.delayModEnv,c);break;case R.modEnvAttack:h=new U(a.attackModEnv,c);break;case R.modEnvHold:h=new U(a.holdModEnv,c,!1);break;case R.modEnvDecay:h=new U(a.decayModEnv,c,!1);break;case R.modEnvRelease:h=new U(a.releaseModEnv,c);break;case R.modEnvSustain:let f=1e3-c;h=new U(a.sustainModEnv,f);break;case R.reverbSend:h=new U(a.reverbEffectsSend,c);break;case R.chorusSend:h=new U(a.chorusEffectsSend,c);break;case R.pitch:let S=Math.floor(c/100),w=Math.floor(c-S*100);h=new U(a.fineTune,w),n.push(new U(a.coarseTune,S));break}h&&n.push(h)}else{let h=!0,u=(f,S,w)=>{let D=f/-128;if(n.push(new U(S,D)),D<=120){let x=Math.round(.46875*f);n.forEach(v=>{v.generatorType===w&&(v.generatorValue+=x)})}};if(i===q.none?g===q.modLfo&&E===R.pitch?n.push(new U(a.modLfoToPitch,c)):g===q.modLfo&&E===R.gain?n.push(new U(a.modLfoToVolume,c)):g===q.modLfo&&E===R.filterCutoff?n.push(new U(a.modLfoToFilterFc,c)):g===q.vibratoLfo&&E===R.pitch?n.push(new U(a.vibLfoToPitch,c)):g===q.modEnv&&E===R.pitch?n.push(new U(a.modEnvToPitch,c)):g===q.modEnv&&E===R.filterCutoff?n.push(new U(a.modEnvToFilterFc,c)):g===q.keyNum&&E===R.pitch?n.push(new U(a.scaleTuning,c/128)):g===q.keyNum&&E===R.volEnvHold?u(c,a.keyNumToVolEnvHold,a.holdVolEnv):g===q.keyNum&&E===R.volEnvDecay?u(c,a.keyNumToVolEnvDecay,a.decayVolEnv):g===q.keyNum&&E===R.modEnvHold?u(c,a.keyNumToModEnvHold,a.holdModEnv):g===q.keyNum&&E===R.modEnvDecay?u(c,a.keyNumToModEnvDecay,a.decayModEnv):h=!1:h=!1,h===!1){let f=sr(g,i,E,B,c);f?(s.push(f),y("%cSucceeded converting to SF2 Modulator!",I.recognized)):Y("Failed converting to SF2 Modulator!")}}}return A&&s.push(CA.copy(mn),CA.copy(pn)),{modulators:s,generators:n}}function or(e,A,t){if(e)for(;e.chunkData.currentIndex<e.chunkData.length;){let n=gA(e.chunkData);this.verifyHeader(n,"art1","art2");let s=fs(n,!0);t.addGenerators(...s.generators),t.addModulators(...s.modulators)}if(A)for(;A.chunkData.currentIndex<A.chunkData.length;){let n=gA(A.chunkData);this.verifyHeader(n,"art2","art1");let s=fs(n,!1);t.addGenerators(...s.generators),t.addModulators(...s.modulators)}}function rr(e,A){let t=[];for(;e.chunkData.length>e.chunkData.currentIndex;)t.push(gA(e.chunkData));let n=t.find(M=>M.header==="rgnh"),s=b(n.chunkData,2),o=b(n.chunkData,2),r=b(n.chunkData,2),g=b(n.chunkData,2);r===0&&g===0&&(g=127,r=0),A.keyRange={min:s,max:o},A.velRange={min:r,max:g},b(n.chunkData,2);let i=b(n.chunkData,2);i!==0&&A.addGenerators(new U(a.exclusiveClass,i));let E=_A(t,"lart"),B=_A(t,"lar2");this.readLart(E,B,A);let l=t.find(M=>M.header==="wsmp");b(l.chunkData,4);let c=b(l.chunkData,2),h=Ke(l.chunkData[l.chunkData.currentIndex++],l.chunkData[l.chunkData.currentIndex++]),f=(b(l.chunkData,4)|0)/-655360;b(l.chunkData,4);let S=b(l.chunkData,4),w,D={start:0,end:0};if(S===0)w=0;else{b(l.chunkData,4),b(l.chunkData,4)===0?w=1:w=3,D.start=b(l.chunkData,4);let $=b(l.chunkData,4);D.end=D.start+$}let x=t.find(M=>M.header==="wlnk");if(x===void 0)return;b(x.chunkData,2),b(x.chunkData,2),b(x.chunkData,4);let v=b(x.chunkData,4),G=this.samples[v];if(G===void 0)throw new Error("Invalid sample ID!");let N=(f||G.sampleDbAttenuation)*10/.4;A.setWavesample(N,w,D,c,G,v,h)}var Fn=class extends xe{sampleDbAttenuation;sampleData;constructor(A,t,n,s,o,r,g,i){super(A,t,n,s,0,1,o,r),this.sampleData=g,this.sampleDbAttenuation=i}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 ir={PCM:1,ALAW:6};function Oi(e,A){let t=Math.pow(2,A*8-1),n=Math.pow(2,A*8),s,o=!1;A===1?(s=255,o=!0):s=t;let r=e.size/A,g=new Float32Array(r);for(let i=0;i<g.length;i++){let E=b(e.chunkData,A);o?g[i]=E/s-.5:(E>=t&&(E-=n),g[i]=E/s)}return g}function Ji(e,A){let t=e.size/A,n=new Float32Array(t);for(let s=0;s<n.length;s++){let o=b(e.chunkData,A),r=o^85;r&=127;let g=r>>4,i=r&15;g>0&&(i+=16),i=(i<<4)+8,g>1&&(i=i<<g-1);let E=o>127?i:-i;n[s]=E/32678}return n}function ar(e){QA("%cLoading Wave samples...",I.recognized);let A=0;for(;e.chunkData.currentIndex<e.chunkData.length;){let t=gA(e.chunkData);this.verifyHeader(t,"LIST"),this.verifyText(AA(t.chunkData,4),"wave");let n=[];for(;t.chunkData.currentIndex<t.chunkData.length;)n.push(gA(t.chunkData));let s=n.find(G=>G.header==="fmt ");if(!s)throw new Error("No fmt chunk in the wave file!");let o=b(s.chunkData,2),r=b(s.chunkData,2);if(r!==1)throw new Error(`Only mono samples are supported. Fmt reports ${r} channels`);let g=b(s.chunkData,4);b(s.chunkData,4),b(s.chunkData,2);let E=b(s.chunkData,2)/8,B=!1,l=n.find(G=>G.header==="data");l||this.parsingError("No data chunk in the WAVE chunk!");let c;switch(o){default:B=!0,c=new Float32Array(l.size/E);break;case ir.PCM:c=Oi(l,E);break;case ir.ALAW:c=Ji(l,E);break}let h=_A(n,"INFO"),u=`Unnamed ${A}`;if(h){let G=gA(h.chunkData);for(;G.header!=="INAM"&&h.chunkData.currentIndex<h.chunkData.length;)G=gA(h.chunkData);G.header==="INAM"&&(u=AA(G.chunkData,G.size).trim())}let f=60,S=0,w=0,D=c.length-1,x=0,v=n.find(G=>G.header==="wsmp");if(v){b(v.chunkData,4),f=b(v.chunkData,2),S=Ke(v.chunkData[v.chunkData.currentIndex++],v.chunkData[v.chunkData.currentIndex++]);let G=Math.trunc(S/100);if(f+=G,S-=G*100,x=(b(v.chunkData,4)|0)/-655360,b(v.chunkData,4),b(v.chunkData,4)===1){b(v.chunkData,8),w=b(v.chunkData,4);let M=b(v.chunkData,4);D=w+M}}else Y("No wsmp chunk in wave... using sane defaults.");B&&console.error(`Failed to load '${u}': Unsupported format: (${o})`),this.samples.push(new Fn(u,g,f,S,w,D,c,x)),A++,y(`%cLoaded sample %c${u}`,I.info,I.recognized)}P()}var Le=class extends be{constructor(A){super(),this.dataArray=new L(A),Ie("%cParsing DLS...",I.info),this.dataArray||(P(),this.parsingError("No data provided!"));let t=gA(this.dataArray,!1);this.verifyHeader(t,"riff"),this.verifyText(AA(this.dataArray,4).toLowerCase(),"dls ");let n=[];for(;this.dataArray.currentIndex<this.dataArray.length;)n.push(gA(this.dataArray));this.soundFontInfo.ifil="2.1",this.soundFontInfo.isng="EMU8000",this.soundFontInfo.INAM="Unnamed DLS",this.soundFontInfo.IENG="Unknown",this.soundFontInfo.IPRD="SpessaSynth DLS",this.soundFontInfo.ICRD=new Date().toDateString();let s=_A(n,"INFO");if(s)for(;s.chunkData.currentIndex<s.chunkData.length;){let i=gA(s.chunkData);this.soundFontInfo[i.header]=AA(i.chunkData,i.size)}this.soundFontInfo.ICMT=this.soundFontInfo.ICMT||"(No description)",this.soundFontInfo.ISBJ&&(this.soundFontInfo.ICMT+=`
|
|
14
14
|
`+this.soundFontInfo.ISBJ,delete this.soundFontInfo.ISBJ),this.soundFontInfo.ICMT+=`
|