spessasynth_lib 3.20.42 → 3.20.43
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
|
@@ -63,8 +63,8 @@ export class LoadedSample extends BasicSample
|
|
|
63
63
|
if(this.isCompressed)
|
|
64
64
|
{
|
|
65
65
|
// correct loop points
|
|
66
|
-
this.sampleLoopStartIndex += this.sampleStartIndex;
|
|
67
|
-
this.sampleLoopEndIndex += this.sampleStartIndex;
|
|
66
|
+
this.sampleLoopStartIndex += this.sampleStartIndex / 2;
|
|
67
|
+
this.sampleLoopEndIndex += this.sampleStartIndex / 2;
|
|
68
68
|
this.sampleLength = 99999999; // set to 999999 before we decode it
|
|
69
69
|
}
|
|
70
70
|
this.isDataRaw = isDataRaw;
|
|
@@ -14,5 +14,5 @@ var Is=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(A,e)=>(
|
|
|
14
14
|
`+I.extraStackTrace()),(a=E).replace(/__Z[\w\d_]+/g,function(Q){var f,R=f=Q;return Q===R?Q:Q+" ["+R+"]"})}function It(a,E){return a%E>0&&(a+=E-a%E),a}function jt(a){I.buffer=s=a}function gt(){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=C=new Uint16Array(s),I.HEAPU32=B=new Uint32Array(s),I.HEAPF32=d=new Float32Array(s),I.HEAPF64=h=new Float64Array(s)}function $t(){var a=I.usingWasm?65536:16777216,E=2147483648-a;if(c[G>>2]>E)return!1;var Q=BA;for(BA=Math.max(BA,16777216);BA<c[G>>2];)BA=BA<=536870912?It(2*BA,a):Math.min(It((3*BA+2147483648)/4,a),E);var f=I.reallocBuffer(BA);return f&&f.byteLength==BA?(jt(f),gt(),!0):(BA=Q,!1)}u=l=S=w=y=N=G=0,D=!1,I.reallocBuffer||(I.reallocBuffer=function(a){try{if(ArrayBuffer.transfer)E=ArrayBuffer.transfer(s,a);else{var E,Q=n;E=new ArrayBuffer(a),new Int8Array(E).set(Q)}}catch{return!1}return!!Ro(E)&&E});try{(K=Function.prototype.call.bind(Object.getOwnPropertyDescriptor(ArrayBuffer.prototype,"byteLength").get))(new ArrayBuffer(4))}catch{K=function(E){return E.byteLength}}var Ct=I.TOTAL_STACK||5242880,BA=I.TOTAL_MEMORY||16777216;function po(){return BA}function me(a){for(;a.length>0;){var E=a.shift();if(typeof E=="function"){E();continue}var Q=E.func;typeof Q=="number"?E.arg===void 0?I.dynCall_v(Q):I.dynCall_vi(Q,E.arg):Q(E.arg===void 0?null:E.arg)}}BA<Ct&&RA("TOTAL_MEMORY should be larger than TOTAL_STACK, was "+BA+"! (TOTAL_STACK="+Ct+")"),I.buffer?s=I.buffer:(typeof WebAssembly=="object"&&typeof WebAssembly.Memory=="function"?(I.wasmMemory=new WebAssembly.Memory({initial:BA/65536}),s=I.wasmMemory.buffer):s=new ArrayBuffer(BA),I.buffer=s),gt();var As=[],Et=[],es=[],ts=[],ss=[],Bt=!1,yo=!1;function So(a){As.unshift(a)}function ar(a){Et.unshift(a)}function Ir(a){es.unshift(a)}function gr(a){ts.unshift(a)}function Do(a){ss.unshift(a)}function Cr(a,E,Q){var f,R;fe("writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!"),Q&&(f=n[R=E+Te(a)]),_t(a,E,1/0),Q&&(n[R]=f)}function Er(a,E,Q){return a>=0?a:E<=32?2*Math.abs(1<<E-1)+a:Math.pow(2,E)+a}function Br(a,E,Q){if(a<=0)return a;var f=E<=32?Math.abs(1<<E-1):Math.pow(2,E-1);return a>=f&&(E<=32||a>f)&&(a=-2*f+a),a}var ko=Math.abs,wo=Math.ceil,ns=Math.floor,Fo=Math.min,Ae=0,ht=null,pe=null;function hr(a){return a}I.preloadedImages={},I.preloadedAudios={};var os="data:application/octet-stream;base64,";function He(a){return String.prototype.startsWith?a.startsWith(os):a.indexOf(os)===0}(function(){var E="main.wast",Q="main.wasm",f="main.temp.asm.js";He(E)||(E=fA(E)),He(Q)||(Q=fA(Q)),He(f)||(f=fA(f));var R={global:null,env:null,asm2wasm:uo,parent:I},q=null;function _(tA){return tA}function M(){try{if(I.wasmBinary)return new Uint8Array(I.wasmBinary);if(I.readBinary)return I.readBinary(Q);throw"both async and sync fetching of the wasm failed"}catch(tA){ZA(tA)}}I.asmPreload=I.asm;var hA=I.reallocBuffer,rA=function(tA){tA=It(tA,I.usingWasm?65536:16777216);var v=I.buffer.byteLength;if(I.usingWasm)try{var mA=I.wasmMemory.grow((tA-v)/65536);return mA!==-1?I.buffer=I.wasmMemory.buffer:null}catch{return null}};I.reallocBuffer=function(tA){return iA==="asmjs"?hA(tA):rA(tA)};var iA="";I.asm=function(tA,v,mA){var GA;if(!(v=GA=v).table){var xA,MA=I.wasmTableSize;MA===void 0&&(MA=1024);var ee=I.wasmMaxTableSize;typeof WebAssembly=="object"&&typeof WebAssembly.Table=="function"?ee!==void 0?v.table=new WebAssembly.Table({initial:MA,maximum:ee,element:"anyfunc"}):v.table=new WebAssembly.Table({initial:MA,element:"anyfunc"}):v.table=Array(MA),I.wasmTable=v.table}return v.memoryBase||(v.memoryBase=I.STATIC_BASE),v.tableBase||(v.tableBase=0),xA=function(Se,oe,ut){if(typeof WebAssembly!="object")return RA("no native wasm support detected"),!1;if(!(I.wasmMemory instanceof WebAssembly.Memory))return RA("no native wasm Memory in use"),!1;function ve(vA,qA){if((q=vA.exports).memory){var De,dt,as;De=q.memory,dt=I.buffer,De.byteLength<dt.byteLength&&RA("the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here"),as=new Int8Array(dt),new Int8Array(De).set(as),jt(De),gt()}I.asm=q,I.usingWasm=!0,function(mr){if(Ae--,I.monitorRunDependencies&&I.monitorRunDependencies(Ae),Ae==0&&(ht!==null&&(clearInterval(ht),ht=null),pe)){var Go=pe;pe=null,Go()}}("wasm-instantiate")}if(oe.memory=I.wasmMemory,R.global={NaN:NaN,Infinity:1/0},R["global.Math"]=Math,R.env=oe,Ae++,I.monitorRunDependencies&&I.monitorRunDependencies(Ae),I.instantiateWasm)try{return I.instantiateWasm(R,ve)}catch(vA){return RA("Module.instantiateWasm callback failed with error: "+vA),!1}function re(vA){ve(vA.instance,vA.module)}function is(vA){(!I.wasmBinary&&(j||J)&&typeof fetch=="function"?fetch(Q,{credentials:"same-origin"}).then(function(qA){if(!qA.ok)throw"failed to load wasm binary file at '"+Q+"'";return qA.arrayBuffer()}).catch(function(){return M()}):new Promise(function(qA,De){qA(M())})).then(function(qA){return WebAssembly.instantiate(qA,R)}).then(vA).catch(function(qA){RA("failed to asynchronously prepare wasm: "+qA),ZA(qA)})}return I.wasmBinary||typeof WebAssembly.instantiateStreaming!="function"||He(Q)||typeof fetch!="function"?is(re):WebAssembly.instantiateStreaming(fetch(Q,{credentials:"same-origin"}),R).then(re).catch(function(vA){RA("wasm streaming compile failed: "+vA),RA("falling back to ArrayBuffer instantiation"),is(re)}),{}}(tA,v,mA),_A(xA,"no binaryen method succeeded."),xA},I.asm})(),l=(u=1024)+4816,Et.push(),I.STATIC_BASE=u,I.STATIC_BUMP=4816;var kA=l;function Qr(a){n[kA]=n[a],n[kA+1]=n[a+1],n[kA+2]=n[a+2],n[kA+3]=n[a+3]}function cr(a){n[kA]=n[a],n[kA+1]=n[a+1],n[kA+2]=n[a+2],n[kA+3]=n[a+3],n[kA+4]=n[a+4],n[kA+5]=n[a+5],n[kA+6]=n[a+6],n[kA+7]=n[a+7]}function lr(a,E,Q){var f=Q>0?Q:Te(a)+1,R=Array(f),q=Ue(a,R,0,R.length);return E&&(R.length=q),R}function ur(a){for(var E=[],Q=0;Q<a.length;Q++){var f=a[Q];f>255&&(f&=255),E.push(String.fromCharCode(f))}return E.join("")}l+=16,G=Ne(4),y=(S=w=Kt(l))+Ct,N=Kt(y),c[G>>2]=N,D=!0,I.wasmTableSize=4,I.wasmMaxTableSize=4,I.asmGlobalArg={},I.asmLibraryArg={abort:ZA,assert:_A,enlargeMemory:$t,getTotalMemory:po,abortOnCannotGrowMemory:function(){ZA("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+BA+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")},invoke_iii:function(E,Q,f){var R=ct();try{return I.dynCall_iii(E,Q,f)}catch(q){if(Qt(R),typeof q!="number"&&q!=="longjmp")throw q;I.setThrew(1,0)}},___assert_fail:function(E,Q,f,R){ZA("Assertion failed: "+Le(E)+", at: "+[Q?Le(Q):"unknown filename",f,R?Le(R):"unknown function"])},___setErrNo:function(E){return I.___errno_location&&(c[I.___errno_location()>>2]=E),E},_abort:function(){I.abort()},_emscripten_memcpy_big:function(E,Q,f){return o.set(o.subarray(Q,Q+f),E),E},_llvm_floor_f64:ns,DYNAMICTOP_PTR:G,tempDoublePtr:kA,ABORT:be,STACKTOP:w,STACK_MAX:y};var rs=I.asm(I.asmGlobalArg,I.asmLibraryArg,s);I.asm=rs,I.___errno_location=function(){return I.asm.___errno_location.apply(null,arguments)};var Ro=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 Ye=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 Je=I.stackAlloc=function(){return I.asm.stackAlloc.apply(null,arguments)},Qt=I.stackRestore=function(){return I.asm.stackRestore.apply(null,arguments)},ct=I.stackSave=function(){return I.asm.stackSave.apply(null,arguments)};function ye(a){this.name="ExitStatus",this.message="Program terminated with exit("+a+")",this.status=a}function lt(a){a=a||I.arguments,!(Ae>0)&&(function(){if(I.preRun)for(typeof I.preRun=="function"&&(I.preRun=[I.preRun]);I.preRun.length;)So(I.preRun.shift());me(As)}(),!(Ae>0)&&(I.calledRun||(I.setStatus?(I.setStatus("Running..."),setTimeout(function(){setTimeout(function(){I.setStatus("")},1),E()},1)):E())));function E(){!I.calledRun&&(I.calledRun=!0,be||(Bt||(Bt=!0,me(Et)),me(es),I.onRuntimeInitialized&&I.onRuntimeInitialized(),function(){if(I.postRun)for(typeof I.postRun=="function"&&(I.postRun=[I.postRun]);I.postRun.length;)Do(I.postRun.shift());me(ss)}()))}}function dr(a,E){(!E||!I.noExitRuntime||a!==0)&&(I.noExitRuntime||(be=!0,Vt=a,w=W,me(ts),yo=!0,I.onExit&&I.onExit(a)),I.quit(a,new ye(a)))}function ZA(a){throw I.onAbort&&I.onAbort(a),a!==void 0?(Me(a),RA(a),a=JSON.stringify(a)):a="",be=!0,Vt=1,"abort("+a+"). Build with -s ASSERTIONS=1 for more info."}if(I.dynCall_iii=function(){return I.asm.dynCall_iii.apply(null,arguments)},I.asm=rs,I.ccall=Xt,I.cwrap=function(E,Q,f,R){var q=(f=f||[]).every(function(_){return _==="number"});return Q!=="string"&&q&&!R?Ot(E):function(){return Xt(E,Q,f,arguments,R)}},ye.prototype=Error(),ye.prototype.constructor=ye,pe=function a(){I.calledRun||lt(),I.calledRun||(pe=a)},I.run=lt,I.abort=ZA,I.preInit)for(typeof I.preInit=="function"&&(I.preInit=[I.preInit]);I.preInit.length>0;)I.preInit.pop()();I.noExitRuntime=!0,lt(),I.onRuntimeInitialized=()=>{tn=!0,sn()},OA.decode=function(a){return function(Q){if(!tn)throw Error("Not initialized");var f={};function R(oe){return new Int32Array(I.HEAPU8.buffer,oe,1)[0]}function q(oe,ut){var ve=new ArrayBuffer(ut*Float32Array.BYTES_PER_ELEMENT),re=new Float32Array(ve);return re.set(new Float32Array(I.HEAPU8.buffer,oe,ut)),re}f.open=I.cwrap("stb_vorbis_js_open","number",[]),f.close=I.cwrap("stb_vorbis_js_close","void",["number"]),f.channels=I.cwrap("stb_vorbis_js_channels","number",["number"]),f.sampleRate=I.cwrap("stb_vorbis_js_sample_rate","number",["number"]),f.decode=I.cwrap("stb_vorbis_js_decode","number",["number","number","number","number","number"]);var _,M,hA,rA,iA=f.open(),tA=(_=Q,M=Q.byteLength,hA=I._malloc(M),(rA=new Uint8Array(I.HEAPU8.buffer,hA,M)).set(new Uint8Array(_,0,M)),rA),v=I._malloc(4),mA=I._malloc(4),GA=f.decode(iA,tA.byteOffset,tA.byteLength,v,mA);if(I._free(tA.byteOffset),GA<0)throw f.close(iA),I._free(v),Error("stbvorbis decode failed: "+GA);for(var xA=f.channels(iA),MA=Array(xA),ee=new Int32Array(I.HEAPU32.buffer,R(v),xA),NA=0;NA<xA;NA++)MA[NA]=q(ee[NA],GA),I._free(ee[NA]);var Se=f.sampleRate(iA);return f.close(iA),I._free(R(v)),I._free(v),{data:MA,sampleRate:Se,eof:!0,error:null}}(a)}})();function nn(t){let A=t.messageData,e=t.channelNumber,s={};switch(e>=0&&(s=this.workletProcessorChannels[e]),t.messageType){case eA.noteOn:this.noteOn(e,A[0],A[1],A[2]);break;case eA.noteOff:this.noteOff(e,A);break;case eA.pitchWheel:this.pitchWheel(e,A[0],A[1]);break;case eA.ccChange:this.controllerChange(e,A[0],A[1],A[2]);break;case eA.customcCcChange:s.customControllers[A[0]]=A[1];break;case eA.killNote:this.killNote(e,A);break;case eA.programChange:this.programChange(e,A[0],A[1]);break;case eA.channelPressure:this.channelPressure(e,A);break;case eA.polyPressure:this.polyPressure(e,A[0],A[1]);break;case eA.ccReset:e===UA?this.resetAllControllers():this.resetControllers(e);break;case eA.systemExclusive:this.systemExclusive(A);break;case eA.setChannelVibrato:if(e===UA)for(let i=0;i<this.workletProcessorChannels.length;i++)A.rate===-1?this.disableAndLockGSNRPN(i):this.setVibrato(i,A.depth,A.rate,A.delay);else A.rate===-1?this.disableAndLockGSNRPN(e):this.setVibrato(e,A.depth,A.rate,A.delay);break;case eA.stopAll:e===UA?this.stopAllChannels(A===1):this.stopAll(e,A===1);break;case eA.killNotes:this.voiceKilling(A);break;case eA.muteChannel:this.muteChannel(e,A);break;case eA.addNewChannel:this.createWorkletChannel(!0);break;case eA.debugMessage:this.debugMessage();break;case eA.setMasterParameter:let n=A[0],o=A[1];switch(n){case ae.masterPan:this.setMasterPan(o);break;case ae.mainVolume:this.setMasterGain(o);break;case ae.voicesCap:this.voiceCap=o;break;case ae.interpolationType:this.interpolationType=o;break}break;case eA.setDrums:this.setDrums(e,A);break;case eA.transpose:e===UA?this.transposeAllChannels(A[0],A[1]):this.transposeChannel(e,A[0],A[1]);break;case eA.highPerformanceMode:this.highPerformanceMode=A;break;case eA.lockController:A[0]===UA?s.lockPreset=A[1]:s.lockedControllers[A[0]]=A[1];break;case eA.sequencerSpecific:this.sequencer.processMessage(A.messageType,A.messageData);break;case eA.soundFontManager:this.soundfontManager.handleMessage(A[0],A[1]),this.clearSoundFont(!0,!1);break;case eA.requestSynthesizerSnapshot:this.sendSynthesizerSnapshot();break;case eA.setLogLevel:cs(A[0],A[1],A[2],A[3]);break;default:L("Unrecognized event:",A);break}}function on(t,A){this.enableEventSystem&&this.post({messageType:pA.eventCall,messageData:{eventName:t,eventData:A}})}function rn(){if(!this.enableEventSystem)return;let t=this.workletProcessorChannels.map(A=>{let e=(A.midiControllers[EA+P.pitchWheelRange]>>7)+(A.midiControllers[EA+P.pitchWheelRange]&127)/127;return{voicesAmount:A.voices.length,pitchBend:A.midiControllers[EA+P.pitchWheel],pitchBendRangeSemitones:e,isMuted:A.isMuted,isDrum:A.drumChannel}});this.post({messageType:pA.channelProperties,messageData:t})}function Ho(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 an(t,A=0){let e=t[0];if(!(this.deviceID!==UA&&t[1]!==127&&this.deviceID!==t[1]))switch(e){default:L(`%cUnrecognized SysEx: %c${lA(t)}`,r.warn,r.unrecognized);break;case 126:case 127:switch(t[2]){case 4:let n;switch(t[3]){case 1:let o=t[5]<<7|t[4];this.setMIDIVolume(o/16384),m(`%cMaster Volume. Volume: %c${o}`,r.info,r.value);break;case 2:let C=((t[5]<<7|t[4])-8192)/8192;this.setMasterPan(C),m(`%cMaster Pan. Pan: %c${C}`,r.info,r.value);break;case 3:let c=(t[5]<<7|t[6])-8192;n=Math.floor(c/81.92),this.setMasterTuning(n),m(`%cMaster Fine Tuning. Cents: %c${n}`,r.info,r.value);break;case 4:n=(t[5]-64)*100,this.setMasterTuning(n),m(`%cMaster Coarse Tuning. Cents: %c${n}`,r.info,r.value);break;default:L(`%cUnrecognized MIDI Device Control Real-time message: %c${lA(t)}`,r.warn,r.unrecognized)}break;case 9:t[3]===1?(m("%cGM system on",r.info),this.system="gm"):t[3]===3?(m("%cGM2 system on",r.info),this.system="gm2"):(m("%cGM system off, defaulting to GS",r.info),this.system="gs");break;case 8:switch(t[3]){case 2:case 7:let o=4;t[3]===7&&o++;let i=t[o++],C=t[o++];for(let B=0;B<C;B++)this.tunings[i][t[o++]]=Ho(t[o++],t[o++],t[o++]);m(`%cSingle Note Tuning. Program: %c${i}%c Keys affected: ${C}`,r.info,r.recognized,r.info,r.recognized);break;case 9:case 8:let c=new Int8Array(12);if(t[3]===8)for(let B=0;B<12;B++)c[B]=t[7+B]-64;else for(let B=0;B<24;B+=2){let d=(t[7+B]<<7|t[8+B])-8192;c[B/2]=Math.floor(d/81.92)}(t[4]&1)===1&&this.setOctaveTuning(14+A,c),(t[4]>>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);m(`%cMIDI Octave Scale ${t[3]===8?"(1 byte)":"(2 bytes)"} tuning via Tuning: %c${c.join(" ")}`,r.info,r.value);break;default:L(`%cUnrecognized MIDI Tuning standard message: %c${lA(t)}`,r.warn,r.unrecognized);break}break;default:L(`%cUnrecognized MIDI Realtime/non realtime message: %c${lA(t)}`,r.warn,r.unrecognized)}break;case 65:let s=function(){L(`%cUnrecognized Roland %cGS %cSysEx: %c${lA(t)}`,r.warn,r.recognized,r.warn,r.unrecognized)};if(t[2]===66&&t[3]===18){let n=t[7];if(t[6]===127){n===0?(m("%cGS Reset received!",r.info),this.resetAllControllers(!1),this.system="gs"):n===127&&(m("%cGS system off, switching to GM2",r.info),this.resetAllControllers(!1),this.system="gm2");return}else if(t[4]===64){if((t[5]&16)>0){let o=[9,0,1,2,3,4,5,6,7,8,10,11,12,13,14,15][t[5]&15]+A;switch(t[6]){default:s();break;case 21:let i=n>0&&t[5]>>4;this.setDrums(o,i),m(`%cChannel %c${o}%c ${i?"is now a drum channel":"now isn't a drum channel"}%c via: %c${lA(t)}`,r.info,r.value,r.recognized,r.info,r.value);return;case 22:let C=n-64;this.transposeChannel(o,C),m(`%cChannel %c${o}%c pitch shift. Semitones %c${C}%c, with %c${lA(t)}`,r.info,r.recognized,r.info,r.value,r.info,r.value);return;case 28:let c=n;c===0&&(c=Math.floor(Math.random()*128)),this.controllerChange(o,p.pan,c);break;case 33:this.controllerChange(o,p.effects3Depth,n);break;case 34:this.controllerChange(o,p.effects1Depth,n);break;case 64:case 65:case 66:case 67:case 68:case 69:case 70:case 71:case 72:case 73:case 74:case 75:let B=t.length-9,d=new Int8Array(12);for(let u=0;u<B;u++)d[u]=t[u+7]-64;this.setOctaveTuning(o,d);let h=n-64;m(`%cChannel %c${o}%c octave scale tuning. Cents %c${d.join(" ")}%c, with %c${lA(t)}`,r.info,r.recognized,r.info,r.value,r.info,r.value),this.setChannelTuning(o,h);break}return}else if(t[5]===0&&t[6]===6){m(`%cRoland GS Master Pan set to: %c${n}%c with: %c${lA(t)}`,r.info,r.value,r.info,r.value),this.setMasterPan((n-64)/64);return}else if(t[5]===0&&t[6]===5){let o=n-64;m(`%cRoland GS Master Key-Shift set to: %c${o}%c with: %c${lA(t)}`,r.info,r.value,r.info,r.value),this.setMasterTuning(o*100);return}else if(t[5]===0&&t[6]===4){m(`%cRoland GS Master Volume set to: %c${n}%c with: %c${lA(t)}`,r.info,r.value,r.info,r.value),this.setMIDIVolume(n/127);return}}s();return}else if(t[2]===22&&t[3]===18&&t[4]===16){this.setMIDIVolume(t[7]/100),m(`%cRoland Master Volume control set to: %c${t[7]}%c via: %c${lA(t)}`,r.info,r.value,r.info,r.value);return}else{L(`%cUnrecognized Roland SysEx: %c${lA(t)}`,r.warn,r.unrecognized);return}case 67:if(t[2]===76)if(t[3]===0&&t[4]===0)switch(t[5]){case 4:let n=t[6];this.setMIDIVolume(n/127),m(`%cXG master volume. Volume: %c${n}`,r.info,r.recognized);break;case 6:let o=t[6]-64;this.transposeAllChannels(o),m(`%cXG master transpose. Volume: %c${o}`,r.info,r.recognized);break;case 126:m("%cXG system on",r.info),this.resetAllControllers(!1),this.system="xg";break}else if(t[3]===8){if(this.system!=="xg")return;let n=t[4]+A;if(n>=this.workletProcessorChannels.length)return;let o=t[6];switch(t[5]){case 1:this.controllerChange(n,p.bankSelect,o);break;case 2:this.controllerChange(n,p.lsbForControl0BankSelect,o);break;case 3:this.programChange(n,o);break;case 8:let i=this.workletProcessorChannels[n];if(i.drumChannel)return;let C=o-64;i.channelTransposeKeyShift=C;break;case 11:this.controllerChange(n,p.mainVolume,o);break;case 14:let c=o;c===0&&(c=Math.floor(Math.random()*127)),this.controllerChange(n,p.pan,c);break;case 19:this.controllerChange(n,p.effects1Depth,o);break;case 18:this.controllerChange(n,p.effects3Depth,o);break;default:L(`%cUnrecognized Yamaha XG Part Setup: %c${t[5].toString(16).toUpperCase()}`,r.warn,r.unrecognized)}}else this.system==="xg"&&L(`%cUnrecognized Yamaha XG SysEx: %c${lA(t)}`,r.warn,r.unrecognized);else this.system==="xg"&&L(`%cUnrecognized Yamaha SysEx: %c${lA(t)}`,r.warn,r.unrecognized);break}}function In(t,A,e){if(A.transformAmount===0)return A.currentValue=0,0;let s;if(A.sourceUsesCC)s=t[A.sourceIndex];else{let c=A.sourceIndex+EA;switch(A.sourceIndex){case P.noController:s=16383;break;case P.noteOnKeyNum:s=e.midiNote<<7;break;case P.noteOnVelocity:s=e.velocity<<7;break;case P.polyPressure:s=e.pressure<<7;break;default:s=t[c];break}}let n=dA[A.sourceCurveType][A.sourcePolarity][A.sourceDirection][s],o;if(A.secSrcUsesCC)o=t[A.secSrcIndex];else{let c=A.secSrcIndex+EA;switch(A.secSrcIndex){case P.noController:o=16383;break;case P.noteOnKeyNum:o=e.midiNote<<7;break;case P.noteOnVelocity:o=e.velocity<<7;break;case P.polyPressure:o=e.pressure<<7;break;default:o=t[c]}}let i=dA[A.secSrcCurveType][A.secSrcPolarity][A.secSrcDirection][o],C=n*i*A.transformAmount;return A.transformType===2&&(C=Math.abs(C)),A.currentValue=C,C}function XA(t,A,e=-1,s=0){let n=t.modulators,o=t.generators,i=t.modulatedGenerators;if(YA.recalculate(t),e===-1){i.set(o),n.forEach(B=>{let d=b[B.modulatorDestination],h=i[B.modulatorDestination]+In(A,B,t);i[B.modulatorDestination]=Math.max(d.min,Math.min(h,d.max))}),LA.recalculate(t);return}let C=new Set([g.initialAttenuation,g.delayVolEnv,g.attackVolEnv,g.holdVolEnv,g.decayVolEnv,g.sustainVolEnv,g.releaseVolEnv,g.keyNumToVolEnvHold,g.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],In(A,B,t),n.forEach(h=>{if(h.modulatorDestination===d){let u=b[B.modulatorDestination],l=i[B.modulatorDestination]+h.currentValue;i[B.modulatorDestination]=Math.max(u.min,Math.min(l,u.max))}}),c.add(d))}}),[...c].some(B=>C.has(B))&&LA.recalculate(t)}var dA=[];for(let t=0;t<4;t++){dA[t]=[[new Float32Array(gA),new Float32Array(gA)],[new Float32Array(gA),new Float32Array(gA)]];for(let A=0;A<gA;A++)dA[t][0][0][A]=se(0,t,A/gA,0),isNaN(dA[t][0][0][A])&&(dA[t][0][0][A]=1),dA[t][1][0][A]=se(0,t,A/gA,1),isNaN(dA[t][1][0][A])&&(dA[t][1][0][A]=1),dA[t][0][1][A]=se(1,t,A/gA,0),isNaN(dA[t][0][1][A])&&(dA[t][0][1][A]=1),dA[t][1][1][A]=se(1,t,A/gA,1),isNaN(dA[t][1][1][A])&&(dA[t][1][1][A]=1)}function gn(t,A,e,s=!1,n=!0,o=currentTime){if(e===0){this.noteOff(t,A);return}let i=this.workletProcessorChannels[t];if(this.highPerformanceMode&&this.totalVoicesAmount>200&&e<40||this.highPerformanceMode&&e<10||i.isMuted)return;let C=A+i.channelTransposeKeyShift;if(A>127||A<0)return;let c=i.preset.program;this.tunings[c]?.[A]?.midiNote>=0&&(C=this.tunings[c]?.[A].midiNote),i.velocityOverride>0&&(e=i.velocityOverride);let B=this.getWorkletVoices(t,C,e,i,o,s),d=i.voices;B.forEach(h=>{let u=h.generators[g.exclusiveClass];u!==0&&d.forEach(G=>{G.generators[g.exclusiveClass]===u&&(this.releaseVoice(G),G.modulatedGenerators[g.releaseVolEnv]=-7e3,G.modulatedGenerators[g.releaseModEnv]=-7e3,LA.recalculate(G),YA.recalculate(G))}),XA(h,i.midiControllers);let l=h.modulatedGenerators[g.startAddrsOffset]+h.modulatedGenerators[g.startAddrsCoarseOffset]*32768,D=h.modulatedGenerators[g.endAddrOffset]+h.modulatedGenerators[g.endAddrsCoarseOffset]*32768,S=h.modulatedGenerators[g.startloopAddrsOffset]+h.modulatedGenerators[g.startloopAddrsCoarseOffset]*32768,w=h.modulatedGenerators[g.endloopAddrsOffset]+h.modulatedGenerators[g.endloopAddrsCoarseOffset]*32768,y=h.sample,N=G=>Math.max(0,Math.min(y.sampleData.length-1,G));if(y.cursor=N(y.cursor+l),y.end=N(y.end+D),y.loopStart=N(y.loopStart+S),y.loopEnd=N(y.loopEnd+w),y.loopEnd<y.loopStart){let G=y.loopStart;y.loopStart=y.loopEnd,y.loopEnd=G}y.loopEnd-y.loopStart<1&&(y.loopingMode=0,y.isLooping=!1),h.volumeEnvelope.attenuation=h.volumeEnvelope.attenuationTarget,h.currentPan=(Math.max(-500,Math.min(500,h.modulatedGenerators[g.pan]))+500)/1e3}),this.totalVoicesAmount+=B.length,this.totalVoicesAmount>this.voiceCap&&this.voiceKilling(B.length),d.push(...B),n&&(this.sendChannelProperties(),this.callEvent("noteon",{midiNote:A,channel:t,velocity:e}))}function Cn(t,A){if(A>127||A<0){L("Received a noteOn for note",A,"Ignoring.");return}let e=A+this.workletProcessorChannels[t].channelTransposeKeyShift,s=this.workletProcessorChannels[t].preset.program;if(this.tunings[s]?.[A]?.midiNote>=0&&(e=this.tunings[s]?.[A].midiNote),this.highPerformanceMode&&!this.workletProcessorChannels[t].drumChannel){this.killNote(t,e);return}this.workletProcessorChannels[t].voices.forEach(o=>{o.midiNote!==e||o.isInRelease===!0||(this.workletProcessorChannels[t].holdPedal?this.workletProcessorChannels[t].sustainedVoices.push(o):this.releaseVoice(o))}),this.callEvent("noteoff",{midiNote:A,channel:t})}function En(t,A){this.workletProcessorChannels[t].voices.forEach(e=>{e.midiNote===A&&(e.modulatedGenerators[g.releaseVolEnv]=-12e3,this.releaseVoice(e))})}function Bn(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 hn(t=!1){m("%cStop all received!",r.info);for(let A=0;A<this.workletProcessorChannels.length;A++)this.stopAll(A,t);this.callEvent("stopall",void 0)}function Qn(t,A=!1){this.transposition=0;for(let e=0;e<this.workletProcessorChannels.length;e++)this.transposeChannel(e,t,A);this.transposition=t}function cn(t,A,e=!1){let s=this.workletProcessorChannels[t];s.drumChannel||(A+=this.transposition);let n=Math.trunc(A),o=s.channelTransposeKeyShift+s.customControllers[IA.channelTransposeFine]/100;s.drumChannel&&!e||A===o||(n!==s.channelTransposeKeyShift&&this.stopAll(t,!1),s.channelTransposeKeyShift=n,s.customControllers[IA.channelTransposeFine]=(A-n)*100)}function ln(t,A,e=!0){let s=this.workletProcessorChannels[t];A=Math.round(A),s.customControllers[IA.channelTuning]=A,e&&m(`%cChannel ${t} fine tuning. Cents: %c${A}`,r.info,r.value)}function un(t,A){let e=this.workletProcessorChannels[t];A=Math.round(A),e.customControllers[IA.channelTuningSemitones]=A,m(`%cChannel ${t} coarse tuning. Semitones: %c${A}`,r.info,r.value)}function dn(t){t=Math.round(t);for(let A=0;A<this.workletProcessorChannels.length;A++)this.workletProcessorChannels[A].customControllers[IA.masterTuning]=t}function fn(t,A){let e=this.workletProcessorChannels[t];A=Math.round(A),m(`%cChannel ${t} modulation depth. Cents: %c${A}`,r.info,r.value),e.customControllers[IA.modulationMultiplier]=A/50}function mn(t,A,e){if(this.workletProcessorChannels[t].lockedControllers[EA+P.pitchWheel])return;let s=e|A<<7;this.callEvent("pitchwheel",{channel:t,MSB:A,LSB:e}),this.workletProcessorChannels[t].midiControllers[EA+P.pitchWheel]=s,this.workletProcessorChannels[t].voices.forEach(n=>XA(n,this.workletProcessorChannels[t].midiControllers,0,P.pitchWheel)),this.sendChannelProperties()}function pn(t,A){let e=this.workletProcessorChannels[t];e.midiControllers[EA+P.channelPressure]=A<<7,this.workletProcessorChannels[t].voices.forEach(s=>XA(s,e.midiControllers,0,P.channelPressure)),this.callEvent("channelpressure",{channel:t,pressure:A})}function yn(t,A,e){this.workletProcessorChannels[t].voices.forEach(s=>{s.midiNote===A&&(s.pressure=e,XA(s,this.workletProcessorChannels[t].midiControllers,0,P.polyPressure))}),this.callEvent("polypressure",{channel:t,midiNote:A,pressure:e})}function Sn(t,A){if(A.length!==12)throw new Error("Tuning is not the length of 12.");this.workletProcessorChannels[t].channelOctaveTuning=A}function Dn(t,A,e,s=!1){let n=this.workletProcessorChannels[t];if(n===void 0){L(`Trying to access channel ${t} which does not exist... ignoring!`);return}if(A>127){if(!s)return;switch(A){default:return;case wt.velocityOverride:n.velocityOverride=e}}if(A>=p.lsbForControl1ModulationWheel&&A<=p.lsbForControl13EffectControl2&&A!==p.lsbForControl6DataEntry){let o=A-32;if(n.lockedControllers[o])return;n.midiControllers[o]=n.midiControllers[o]&16256|e&127,n.voices.forEach(i=>XA(i,n.midiControllers,1,o))}switch(A){case p.allNotesOff:this.stopAll(t);break;case p.allSoundOff:this.stopAll(t,!0);break;case p.bankSelect:let o=e;if(!s){switch(this.system){case"gm":m(`%cIgnoring the Bank Select (${e}), as the synth is in GM mode.`,r.info);return;case"xg":o===120||o===126||o===127?this.setDrums(t,!0):t%16!==DA&&this.setDrums(t,!1);break;case"gm2":o===120&&(n.drumChannel=!0,this.callEvent("drumchange",{channel:t,isDrumChannel:!0}))}n.drumChannel&&(o=128),o===128&&!n.drumChannel&&(o=n.midiControllers[p.bankSelect])}n.midiControllers[p.bankSelect]=o;break;case p.lsbForControl0BankSelect:this.system==="xg"?n.drumChannel||e!==127&&(n.midiControllers[p.bankSelect]=e):this.system==="gm2"&&(n.midiControllers[p.bankSelect]=e);break;case p.RPNLsb:n.RPValue=n.RPValue<<7|e,n.dataEntryState=uA.RPFine;break;case p.RPNMsb:n.RPValue=e,n.dataEntryState=uA.RPCoarse;break;case p.NRPNMsb:n.NRPCoarse=e,n.dataEntryState=uA.NRPCoarse;break;case p.NRPNLsb:n.NRPFine=e,n.dataEntryState=uA.NRPFine;break;case p.dataEntryMsb:this.dataEntryCoarse(t,e);break;case p.lsbForControl6DataEntry:this.dataEntryFine(t,e);break;case p.resetAllControllers:this.resetControllers(t);break;case p.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=>XA(i,n.midiControllers,1,A)),this.callEvent("controllerchange",{channel:t,controllerNumber:A,controllerValue:e});break}}function kn(t){this.midiVolume=t,this.setMasterPan(this.pan)}function wn(t){this.masterGain=t*Ut,this.setMasterPan(this.pan)}function Fn(t){this.pan=t,t=t/2+.5,this.panLeft=(1-t)*this.currentGain,this.panRight=t*this.currentGain}function Rn(t,A){A&&this.stopAll(t,!0),this.workletProcessorChannels[t].isMuted=A,this.sendChannelProperties(),this.callEvent("mutechannel",{channel:t,isMuted:A})}function Gn(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 xn(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 Mn(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 uA.Idle:break;case uA.NRPFine:if(this.system!=="gs"||e.lockGSNRPNParams)return;switch(e.NRPCoarse){default:if(A===64)return;L(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16).toUpperCase()} 0x${e.NRPFine.toString(16).toUpperCase()})%c data value: %c${A}`,r.warn,r.recognized,r.warn,r.unrecognized,r.warn,r.value);break;case 1:switch(e.NRPFine){default:if(A===64)return;L(`%cUnrecognized NRPN for %c${t}%c: %c(0x${e.NRPCoarse.toString(16)} 0x${e.NRPFine.toString(16)})%c data value: %c${A}`,r.warn,r.recognized,r.warn,r.unrecognized,r.warn,r.value);break;case 8:if(A===64)return;s(),e.channelVibrato.rate=A/64*8,m(`%cVibrato rate for %c${t}%c is now set to %c${A} = ${e.channelVibrato.rate}%cHz.`,r.info,r.recognized,r.info,r.value,r.info);break;case 9:if(A===64)return;s(),e.channelVibrato.depth=A/2,m(`%cVibrato depth for %c${t}%c is now set to %c${A} = ${e.channelVibrato.depth}%c cents range of detune.`,r.info,r.recognized,r.info,r.value,r.info);break;case 10:if(A===64)return;s(),e.channelVibrato.delay=A/64/3,m(`%cVibrato delay for %c${t}%c is now set to %c${A} = ${e.channelVibrato.delay}%c seconds.`,r.info,r.recognized,r.info,r.value,r.info);break;case 32:let i=A;this.controllerChange(t,p.brightness,A),m(`%cFilter cutoff for %c${t}%c is now set to %c${i}`,r.info,r.recognized,r.info,r.value)}break;case 24:let n=A-64;e.keyCentTuning[e.NRPFine]=n*100,m(`%cGS drum key tuning. MIDI note: %c${e.NRPFine}%c semitones: %c${n}`,r.info,r.recognized,r.info,r.value);break;case 29:let o=A;this.controllerChange(t,p.effects1Depth,o),m(`%cGS Drum reverb for %c${t}%c: %c${o}`,r.info,r.recognized,r.info,r.value);break}break;case uA.RPCoarse:case uA.RPFine:switch(e.RPValue){default:L(`%cUnrecognized RPN for %c${t}%c: %c(0x${e.RPValue.toString(16)})%c data value: %c${A}`,r.warn,r.recognized,r.warn,r.unrecognized,r.warn,r.value);break;case 0:e.midiControllers[EA+P.pitchWheelRange]=A<<7,m(`%cChannel ${t} bend range. Semitones: %c${A}`,r.info,r.value);break;case 2:this.setChannelTuningSemitones(t,A-64);break;case 1:this.setChannelTuning(t,A-64,!1);break;case 5:this.setModulationDepth(t,A*100);break;case 16383:this.resetParameters(t);break}}}function Nn(t,A){let e=this.workletProcessorChannels[t];switch(e.dataEntryState){default:break;case uA.RPCoarse:case uA.RPFine:switch(e.RPValue){default:break;case 0:if(A===0)break;e.midiControllers[EA+P.pitchWheelRange]|=A;let s=(e.midiControllers[EA+P.pitchWheelRange]>>7)+A/127;m(`%cChannel ${t} bend range. Semitones: %c${s}`,r.info,r.value);break;case 1:let o=e.customControllers[IA.channelTuning]<<7|A;this.setChannelTuning(t,o*.01220703125);break;case 5:let C=e.customControllers[IA.modulationMultiplier]*50+A/128*100;this.setModulationDepth(t,C);break;case 16383:this.resetParameters(t);break}}}function bn(t=!0){t&&m("%cResetting all controllers!",r.info),this.callEvent("allcontrollerreset",void 0);for(let A=0;A<this.workletProcessorChannels.length;A++){this.resetControllers(A);let e=this.workletProcessorChannels[A];e.lockPreset?this.callEvent("drumchange",{channel:A,isDrumChannel:e.drumChannel}):(e.presetUsesOverride=!0,e.midiControllers[p.bankSelect]=0,A%16===DA?(this.setPreset(A,this.drumPreset),e.drumChannel=!0,this.callEvent("drumchange",{channel:A,isDrumChannel:!0})):(e.drumChannel=!1,this.setPreset(A,this.defaultPreset),this.callEvent("drumchange",{channel:A,isDrumChannel:!1}))),this.callEvent("programchange",{channel:A,program:e.preset.program,bank:e.preset.bank,userCalled:!1});let s=n=>{this.workletProcessorChannels[A].lockedControllers[n]&&this.callEvent("controllerchange",{channel:A,controllerNumber:n,controllerValue:this.workletProcessorChannels[A].midiControllers[n]>>7})};if(s(p.mainVolume),s(p.pan),s(p.expressionController),s(p.modulationWheel),s(p.effects3Depth),s(p.effects1Depth),s(p.brightness),this.workletProcessorChannels[A].lockedControllers[EA+P.pitchWheel]){let n=this.workletProcessorChannels[A].midiControllers[EA+P.pitchWheel],o=n>>7,i=n&127;this.callEvent("pitchwheel",{channel:A,MSB:o,LSB:i})}}this.tunings=[],this.tunings=[];for(let A=0;A<127;A++)this.tunings.push([]);this.setMIDIVolume(1),this.system=Oe}function Ln(t){let A=this.workletProcessorChannels[t],s=A.lockedControllers.reduce((o,i,C)=>(i&&o.push(C),o),[]).map(o=>({ccNum:o,ccVal:A.midiControllers[o]}));A.channelOctaveTuning.fill(0),A.keyCentTuning.fill(0),A.midiControllers.set(PA),A.channelVibrato={rate:0,depth:0,delay:0},A.holdPedal=!1,s.forEach(o=>{A.midiControllers[o.ccNum]=o.ccVal});let n=A.customControllers[IA.channelTransposeFine];A.customControllers.set(kt),A.customControllers[IA.channelTransposeFine]=n,this.resetParameters(t)}function Un(t){let A=this.workletProcessorChannels[t];A.NRPCoarse=0,A.NRPFine=0,A.RPValue=0,A.dataEntryState=uA.Idle}function Tn(){let t=4;for(let s of this.instruments)t+=s.instrumentZones.reduce((n,o)=>(o.generators=o.generators.filter(i=>i.generatorType!==g.sampleID&&i.generatorType!==g.keyRange&&i.generatorType!==g.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:g.velRange,generatorValue:o.velRange.max<<8|o.velRange.min}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:g.keyRange,generatorValue:o.keyRange.max<<8|o.keyRange.min}),o.isGlobal||o.generators.push({generatorType:g.sampleID,generatorValue:this.samples.indexOf(o.sample)}),o.generators.length*4+n),0);let A=new H(t),e=0;for(let s of this.instruments)for(let n of s.instrumentZones){n.generatorZoneStartIndex=e;for(let o of n.generators)Y(A,o.generatorType),Y(A,o.generatorValue),e++}return cA(A,0),sA(new AA("igen",A.length,A))}function Hn(t,A,e,s,n){let o=this.samples.map((B,d)=>{e&&B.compressSample(s,n);let h=B.getRawData();return m(`%cEncoded sample %c${d}. ${B.sampleName}%c of %c${this.samples.length}`,r.info,r.recognized,r.info,r.recognized),h}),i=this.samples.reduce((B,d,h)=>B+o[h].length+46,0),C=new H(i);this.samples.forEach((B,d)=>{let h=o[d],u,l,D=h.length;B.isCompressed?(u=C.currentIndex,l=u+h.length):(u=C.currentIndex/2,l=u+h.length/2,D+=46),t.push(u),C.set(h,C.currentIndex),C.currentIndex+=D,A.push(l)});let c=sA(new AA("smpl",C.length,C),new H([115,100,116,97]));return sA(new AA("LIST",c.length,c))}function Yn(t,A){let s=new H(46*(this.samples.length+1));return this.samples.forEach((n,o)=>{wA(s,n.sampleName,20);let i=t[o];cA(s,i);let C=A[o];cA(s,C);let c=n.sampleLoopStartIndex+i,B=n.sampleLoopEndIndex+i;n.isCompressed&&(c-=i,B-=i),cA(s,c),cA(s,B),cA(s,n.sampleRate),s[s.currentIndex++]=n.samplePitch,s[s.currentIndex++]=n.samplePitchCorrection,Y(s,n.sampleLink),Y(s,n.sampleType)}),wA(s,"EOS",46),sA(new AA("shdr",s.length,s))}function Jn(){let t=10;for(let s of this.instruments)t+=s.instrumentZones.reduce((n,o)=>o.modulators.length*10+n,0);let A=new H(t),e=0;for(let s of this.instruments)for(let n of s.instrumentZones){n.modulatorZoneStartIndex=e;for(let o of n.modulators)Y(A,o.sourceEnum),Y(A,o.modulatorDestination),Y(A,o.transformAmount),Y(A,o.secondarySourceEnum),Y(A,o.transformType),e++}return ge(A,0,10),sA(new AA("imod",A.length,A))}function vn(){let t=this.instruments.reduce((o,i)=>i.instrumentZones.length*4+o,4),A=new H(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,Y(A,s),Y(A,n),s+=i.generators.length,n+=i.modulators.length,e++}return Y(A,s),Y(A,n),sA(new AA("ibag",A.length,A))}function qn(){let t=this.instruments.length*22+22,A=new H(t),e=0,s=0;for(let n of this.instruments)wA(A,n.instrumentName,20),Y(A,e),e+=n.instrumentZones.length,n.instrumentID=s,s++;return wA(A,"EOI",20),Y(A,e),sA(new AA("inst",A.length,A))}function Pn(){let t=4;for(let s of this.presets)t+=s.presetZones.reduce((n,o)=>(o.generators=o.generators.filter(i=>i.generatorType!==g.instrument&&i.generatorType!==g.keyRange&&i.generatorType!==g.velRange),(o.velRange.max!==127||o.velRange.min!==0)&&o.generators.unshift({generatorType:g.velRange,generatorValue:o.velRange.max<<8|o.velRange.min}),(o.keyRange.max!==127||o.keyRange.min!==0)&&o.generators.unshift({generatorType:g.keyRange,generatorValue:o.keyRange.max<<8|o.keyRange.min}),o.isGlobal||o.generators.push({generatorType:g.instrument,generatorValue:this.instruments.indexOf(o.instrument)}),o.generators.length*4+n),0);let A=new H(t),e=0;for(let s of this.presets)for(let n of s.presetZones){n.generatorZoneStartIndex=e;for(let o of n.generators)Y(A,o.generatorType),Y(A,o.generatorValue);e+=n.generators.length}return Y(A,0),Y(A,0),sA(new AA("pgen",A.length,A))}function Kn(){let t=10;for(let s of this.presets)t+=s.presetZones.reduce((n,o)=>o.modulators.length*10+n,0);let A=new H(t),e=0;for(let s of this.presets)for(let n of s.presetZones){n.modulatorZoneStartIndex=e;for(let o of n.modulators)Y(A,o.sourceEnum),Y(A,o.modulatorDestination),Y(A,o.transformAmount),Y(A,o.secondarySourceEnum),Y(A,o.transformType),e++}return ge(A,0,10),sA(new AA("pmod",A.length,A))}function Vn(){let t=this.presets.reduce((o,i)=>i.presetZones.length*4+o,4),A=new H(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,Y(A,s),Y(A,n),s+=i.generators.length,n+=i.modulators.length,e++}return Y(A,s),Y(A,n),sA(new AA("pbag",A.length,A))}function On(){let t=this.presets.length*38+38,A=new H(t),e=0;for(let s of this.presets)wA(A,s.presetName,20),Y(A,s.program),Y(A,s.bank),Y(A,e),cA(A,s.library),cA(A,s.genre),cA(A,s.morphology),e+=s.presetZones.length;return wA(A,"EOP",20),Y(A,0),Y(A,0),Y(A,e),cA(A,0),cA(A,0),cA(A,0),sA(new AA("phdr",A.length,A))}var Yo={compress:!1,compressionQuality:.5,compressionFunction:void 0};function Zn(t=Yo){if(t.compress&&typeof t.compressionFunction!="function")throw new TypeError("No compression function supplied but compression enabled.");yA("%cSaving soundfont...",r.info),m(`%cCompression: %c${t?.compress||"false"}%c quality: %c${t?.compressionQuality||"none"}`,r.info,r.recognized,r.info,r.recognized),m("%cWriting INFO...",r.info);let A=[];this.soundFontInfo.ISFT="SpessaSynth",t?.compress&&(this.soundFontInfo.ifil="3.0");for(let[K,W]of Object.entries(this.soundFontInfo))if(K==="ifil"||K==="iver"){let I=parseInt(W.split(".")[0]),nA=parseInt(W.split(".")[1]),j=new H(4);Y(j,I),Y(j,nA),A.push(sA(new AA(K,4,j)))}else if(K==="DMOD")A.push(sA(new AA(K,W.length,W)));else{let I=new H(W.length);wA(I,W),A.push(sA(new AA(K,W.length,I)))}let e=ke([new H([73,78,70,79]),...A]),s=sA(new AA("LIST",e.length,e));m("%cWriting SDTA...",r.info);let n=[],o=[],i=Hn.call(this,n,o,t?.compress,t?.compressionQuality||.5,t.compressionFunction);m("%cWriting PDTA...",r.info),m("%cWriting SHDR...",r.info);let C=Yn.call(this,n,o);m("%cWriting IGEN...",r.info);let c=Tn.call(this);m("%cWriting IMOD...",r.info);let B=Jn.call(this);m("%cWriting IBAG...",r.info);let d=vn.call(this);m("%cWriting INST...",r.info);let h=qn.call(this),u=Pn.call(this);m("%cWriting PMOD...",r.info);let l=Kn.call(this);m("%cWriting PBAG...",r.info);let D=Vn.call(this);m("%cWriting PHDR...",r.info);let S=On.call(this),w=ke([new H([112,100,116,97]),S,D,l,u,h,d,B,c,C]),y=sA(new AA("LIST",w.length,w));m("%cWriting the output file...",r.info);let N=ke([new H([115,102,98,107]),s,i,y]),G=sA(new AA("RIFF",N.length,N));return m(`%cSaved succesfully! Final file size: %c${G.length}`,r.info,r.recognized),X(),G}var ne=class t{constructor(A=void 0){this.soundFontInfo={},this.presets=[],this.samples=[],this.instruments=[],this.defaultModulators=Pe.map(e=>$.copy(e)),A?.presets&&(this.presets.push(...A.presets),this.soundFontInfo=A.info)}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()}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()}deletePreset(A){A.deletePreset(),this.presets.splice(this.presets.indexOf(A),1),this.removeUnusedElements()}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)}setSampleIDOffset(A){this.presets.forEach(e=>e.sampleIDOffset=A)}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&&L(`%cPreset ${A}.${e} not found. Replaced with %c${s.presetName} (${s.bank}.${s.program})`,r.warn,r.recognized)),s||(L(`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||(L("Preset not found. Defaulting to:",this.presets[0].presetName),e=this.presets[0]),e}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})}};ne.prototype.write=Zn;function Xn(t){yA("%cLoading instruments...",r.info);for(let A=0;A<this.instrumentAmount;A++)this.readDLSInstrument(O(t.chunkData));X()}var ce=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<e+1;s++)for(let n=0;n<128;n++)this.getSamplesAndGenerators(s,n).forEach(o=>{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(h,u,l){return l>=h&&l<=u}function o(h,u){h.push(...u.filter(l=>!h.find(D=>D.generatorType===l.generatorType)))}function i(h,u){h.push(...u.filter(l=>!h.find(D=>$.isIdentical(l,D))))}let C=[],c=this.presetZones[0].isGlobal?[...this.presetZones[0].generators]:[],B=this.presetZones[0].isGlobal?[...this.presetZones[0].modulators]:[];return this.presetZones.filter(h=>n(h.keyRange.min,h.keyRange.max,A)&&n(h.velRange.min,h.velRange.max,e)&&!h.isGlobal).forEach(h=>{if(h.instrument.instrumentZones.length<1)return;let u=h.generators,l=h.modulators,D=h.instrument.instrumentZones[0].isGlobal?[...h.instrument.instrumentZones[0].generators]:[],S=h.instrument.instrumentZones[0].isGlobal?[...h.instrument.instrumentZones[0].modulators]:[];h.instrument.instrumentZones.filter(y=>n(y.keyRange.min,y.keyRange.max,A)&&n(y.velRange.min,y.velRange.max,e)&&!y.isGlobal).forEach(y=>{let N=[...y.generators],G=[...y.modulators];o(u,c),o(N,D),i(l,B),i(G,S),i(G,this.defaultModulators);let K=[...G];for(let W=0;W<l.length;W++){let I=l[W],nA=K.findIndex(j=>$.isIdentical(I,j));nA!==-1?K[nA]=K[nA].sumTransform(I):K.push(I)}C.push({instrumentGenerators:N,presetGenerators:u,modulators:K,sample:y.sample,sampleID:y.generators.find(W=>W.generatorType===g.sampleID).generatorValue})})}),this.foundSamplesAndGenerators[A][e]=C,C}};var Re=class{velRange={min:0,max:127};keyRange={min:0,max:127};isGlobal=!1;generators=[];modulators=[]};var $A=class extends Re{sample=void 0;useCount=0;deleteZone(){this.useCount--,!this.isGlobal&&this.sample.useCount--}},le=class extends Re{instrument=void 0;deleteZone(){this.isGlobal||this.instrument.removeUseCount()}};var ue=class{constructor(){this.instrumentName="",this.instrumentZones=[],this._useCount=0}addUseCount(){this._useCount++,this.instrumentZones.forEach(A=>A.useCount++)}removeUseCount(){this._useCount--;for(let A=0;A<this.instrumentZones.length;A++)this.safeDeleteZone(A)&&A--}get useCount(){return this._useCount}deleteInstrument(){this.instrumentZones.forEach(A=>A.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 At=class extends ce{constructor(A,e){super(Pe),this.program=e&127,this.bank=A>>8&127,A>>31&&(this.bank=128),this.DLSInstrument=new ue,this.DLSInstrument.addUseCount();let n=new le;n.instrument=this.DLSInstrument,this.presetZones=[n]}};function Wn(t){this.verifyHeader(t,"LIST"),this.verifyText(V(t.chunkData,4),"ins ");let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(O(t.chunkData));let e=A.find(l=>l.header==="insh");if(!e)throw X(),new Error("No instrument header!");let s=k(e.chunkData,4),n=k(e.chunkData,4),o=k(e.chunkData,4),i=new At(n,o),C="unnamedPreset",c=SA(A,"INFO");if(c){let l=O(c.chunkData);for(;l.header!=="INAM";)l=O(c.chunkData);C=V(l.chunkData,l.chunkData.length).trim()}i.presetName=C,i.DLSInstrument.instrumentName=C,te(`%cParsing %c"${C}"%c...`,r.info,r.recognized,r.info);let B=SA(A,"lrgn");if(!B)throw X(),new Error("No region list!");let d=new $A;d.isGlobal=!0;let h=SA(A,"lart"),u=SA(A,"lar2");this.readLart(h,u,d),i.DLSInstrument.instrumentZones.push(d);for(let l=0;l<s;l++){let D=O(B.chunkData);this.verifyHeader(D,"LIST");let S=V(D.chunkData,4);if(S!=="rgn "&&S!=="rgn2")throw X(),new SyntaxError(`Invalid DLS region! Expected "rgn " or "rgn2" got "${S}"`);let w=this.readRegion(D);w&&i.DLSInstrument.instrumentZones.push(w)}this.presets.push(i),this.instruments.push(i.DLSInstrument),X()}var x={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 z={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};function _n(t){let A,e=!1;switch(t){default:case z.modLfo:case z.vibratoLfo:case z.coarseTune:case z.fineTune:case z.modEnv:return;case z.keyNum:A=P.noteOnKeyNum;break;case z.none:A=P.noController;break;case z.modulationWheel:A=p.modulationWheel,e=!0;break;case z.pan:A=p.pan,e=!0;break;case z.reverb:A=p.effects1Depth,e=!0;break;case z.chorus:A=p.effects3Depth,e=!0;break;case z.expression:A=p.expressionController,e=!0;break;case z.volume:A=p.mainVolume,e=!0;break;case z.velocity:A=P.noteOnVelocity;break;case z.polyPressure:A=P.polyPressure;break;case z.channelPressure:A=P.channelPressure;break;case z.pitchWheel:A=P.pitchWheel;break;case z.pitchWheelRange:A=P.pitchWheelRange;break}if(A===void 0)throw`not known?? ${t}`;return{enum:A,isCC:e}}function Jo(t,A){switch(t){default:case x.none:return;case x.pan:return g.pan;case x.gain:return{gen:g.initialAttenuation,newAmount:A*-1};case x.pitch:return g.fineTune;case x.keyNum:return g.overridingRootKey;case x.volEnvDelay:return g.delayVolEnv;case x.volEnvAttack:return g.attackVolEnv;case x.volEnvHold:return g.holdVolEnv;case x.volEnvDecay:return g.decayVolEnv;case x.volEnvSustain:return{gen:g.sustainVolEnv,newAmount:1e3-A};case x.volEnvRelease:return g.releaseVolEnv;case x.modEnvDelay:return g.delayModEnv;case x.modEnvAttack:return g.attackModEnv;case x.modEnvHold:return g.holdModEnv;case x.modEnvDecay:return g.decayModEnv;case x.modEnvSustain:return{gen:g.sustainModEnv,newAmount:(1e3-A)/10};case x.modEnvRelease:return g.releaseModEnv;case x.filterCutoff:return g.initialFilterFc;case x.filterQ:return g.initialFilterQ;case x.chorusSend:return g.chorusEffectsSend;case x.reverbSend:return g.reverbEffectsSend}}function vo(t,A){return t===z.vibratoLfo&&A===x.pitch?g.vibLfoToPitch:t===z.modLfo&&A===x.pitch?g.modLfoToPitch:t===z.modLfo&&A===x.filterCutoff?g.modLfoToFilterFc:t===z.modLfo&&A===x.gain?g.modLfoToVolume:t===z.modEnv&&A===x.filterCutoff?g.modEnvToFilterFc:t===z.modEnv&&A===x.pitch?g.modEnvToPitch:void 0}function zn(t,A,e,s,n){let o=vo(t,e),i,C,c=!1,B=!1;if(o===void 0){let w=Jo(e,n);if(w===void 0||(i=w,w.newAmount!==void 0&&(n=w.newAmount,i=w.gen),C=_n(t),C===void 0))return}else i=o,c=!0,C={enum:P.noController,isCC:!1},B=!0;let d=_n(A);if(d===void 0)return;let h;if(B)h=0;else{let w=s&15,y=s>>10&15;y===QA.linear&&w!==QA.linear&&(y=w);let N=s>>14&1,G=s>>15&1;i===g.initialAttenuation&&(G=!G),h=TA(y,N,G,C.isCC,C.enum)}let u=s>>4&15,l=s>>8&1,D=s>>9&1,S=TA(u,l,D,d.isCC,d.enum);if(c){let w=S;S=h,h=w}return new $({srcEnum:h,secSrcEnum:S,dest:i,transform:0,amt:n})}function Tt(t,A){let e=t.chunkData,s=[],n=[];k(e,4);let o=k(e,4);for(let i=0;i<o;i++){let C=k(e,2),c=k(e,2),B=k(e,2),d=k(e,2),u=(k(e,4)|0)>>16;if(C===0&&c===0&&d===0){let l;switch(B){case x.pan:l=new U(g.pan,u);break;case x.gain:l=new U(g.initialAttenuation,-u*10/.4);break;case x.filterCutoff:l=new U(g.initialFilterFc,u);break;case x.filterQ:l=new U(g.initialFilterQ,u);break;case x.modLfoFreq:l=new U(g.freqModLFO,u);break;case x.modLfoDelay:l=new U(g.delayModLFO,u);break;case x.vibLfoFreq:l=new U(g.freqVibLFO,u);break;case x.vibLfoDelay:l=new U(g.delayVibLFO,u);break;case x.volEnvDelay:l=new U(g.delayVolEnv,u);break;case x.volEnvAttack:l=new U(g.attackVolEnv,u);break;case x.volEnvHold:l=new U(g.holdVolEnv,u);break;case x.volEnvDecay:l=new U(g.decayVolEnv,u);break;case x.volEnvRelease:l=new U(g.releaseVolEnv,u);break;case x.volEnvSustain:let D=(1e3-u)/10;l=new U(g.sustainVolEnv,D*10);break;case x.modEnvDelay:l=new U(g.delayModEnv,u);break;case x.modEnvAttack:l=new U(g.attackModEnv,u);break;case x.modEnvHold:l=new U(g.holdModEnv,u);break;case x.modEnvDecay:l=new U(g.decayModEnv,u);break;case x.modEnvRelease:l=new U(g.releaseModEnv,u);break;case x.modEnvSustain:let S=1e3-u;l=new U(g.sustainModEnv,S);break;case x.reverbSend:l=new U(g.reverbEffectsSend,u);break;case x.chorusSend:l=new U(g.chorusEffectsSend,u);break;case x.pitch:let w=Math.floor(u/100),y=Math.floor(u-w*100);l=new U(g.fineTune,y),s.push(new U(g.coarseTune,w));break}l&&s.push(l)}else{let l=!0;if(c===z.none)if(C===z.modLfo&&B===x.pitch)s.push(new U(g.modLfoToPitch,u));else if(C===z.modLfo&&B===x.gain)s.push(new U(g.modLfoToVolume,u));else if(C===z.modLfo&&B===x.filterCutoff)s.push(new U(g.modLfoToFilterFc,u));else if(C===z.vibratoLfo&&B===x.pitch)s.push(new U(g.vibLfoToPitch,u));else if(C===z.modEnv&&B===x.pitch)s.push(new U(g.modEnvToPitch,u));else if(C===z.modEnv&&B===x.filterCutoff)s.push(new U(g.modEnvToFilterFc,u));else if(C===z.keyNum&&B===x.volEnvHold){s.push(new U(g.keyNumToVolEnvHold,u/-128));let D=Math.round(60/128*u);s.forEach(S=>{S.generatorType===g.holdVolEnv&&(S.generatorValue+=D)})}else if(C===z.keyNum&&B===x.volEnvDecay){s.push(new U(g.keyNumToVolEnvDecay,u/-128));let D=Math.round(60/128*u);s.forEach(S=>{S.generatorType===g.decayVolEnv&&(S.generatorValue+=D)})}else if(C===z.keyNum&&B===x.modEnvHold){s.push(new U(g.keyNumToModEnvHold,u/-128));let D=Math.round(60/128*u);s.forEach(S=>{S.generatorType===g.holdModEnv&&(S.generatorValue+=D)})}else if(C===z.keyNum&&B===x.modEnvDecay){s.push(new U(g.keyNumToModEnvDecay,u/-128));let D=Math.round(60/128*u);s.forEach(S=>{S.generatorType===g.decayModEnv&&(S.generatorValue+=D)})}else l=!1;else l=!1;if(l===!1){let D=zn(C,c,B,d,u);D?(n.push(D),m("%cSucceeded converting to SF2 Modulator!",r.recognized)):L("Failed converting to SF2 Modulator!")}}}return n.find(i=>i.modulatorDestination===g.reverbEffectsSend)===void 0&&n.push(new $({srcEnum:219,dest:g.reverbEffectsSend,amt:1e3,secSrcEnum:0,transform:0})),n.find(i=>i.modulatorDestination===g.chorusEffectsSend)===void 0&&n.push(new $({srcEnum:221,dest:g.chorusEffectsSend,amt:1e3,secSrcEnum:0,transform:0})),A&&n.push(new $({srcEnum:129,dest:g.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0}),new $({srcEnum:13,dest:g.vibLfoToPitch,amt:0,secSrcEnum:0,transform:0})),{modulators:n,generators:s}}function jn(t,A,e){if(t)for(;t.chunkData.currentIndex<t.chunkData.length;){let s=O(t.chunkData);this.verifyHeader(s,"art1");let n=Tt(s,!0);e.generators.push(...n.generators),e.modulators.push(...n.modulators)}if(A)for(;A.chunkData.currentIndex<A.chunkData.length;){let s=O(A.chunkData);this.verifyHeader(s,"art2");let n=Tt(s,!1);e.generators.push(...n.generators),e.modulators.push(...n.modulators)}}var et=class extends $A{constructor(A,e){super(),this.keyRange=A,this.velRange=e,this.isGlobal=!0}setWavesample(A,e,s,n,o,i,C){e!==0&&this.generators.push(new U(g.sampleModes,e)),this.generators.push(new U(g.initialAttenuation,A)),this.isGlobal=!1,C-=o.samplePitchCorrection;let c=Math.trunc(C/100);c!==0&&this.generators.push(new U(g.coarseTune,c));let B=C-c*100;B!==0&&this.generators.push(new U(g.fineTune,B));let d=s.start-o.sampleLoopStartIndex,h=s.end-o.sampleLoopEndIndex;if(d!==0){let u=d%32768;this.generators.push(new U(g.startloopAddrsOffset,u));let l=Math.trunc(d/32768);l!==0&&this.generators.push(new U(g.startloopAddrsCoarseOffset,l))}if(h!==0){let u=h%32768;this.generators.push(new U(g.endloopAddrsOffset,u));let l=Math.trunc(h/32768);l!==0&&this.generators.push(new U(g.endloopAddrsCoarseOffset,l))}n!==o.samplePitch&&this.generators.push(new U(g.overridingRootKey,n)),this.generators.push(new U(g.sampleID,i)),this.sample=o,o.useCount++}};function $n(t){let A=[];for(;t.chunkData.length>t.chunkData.currentIndex;)A.push(O(t.chunkData));let e=A.find(j=>j.header==="rgnh"),s=k(e.chunkData,2),n=k(e.chunkData,2),o=k(e.chunkData,2),i=k(e.chunkData,2),C=new et({min:s,max:n},{min:o,max:i});k(e.chunkData,2);let c=k(e.chunkData,2);c!==0&&C.generators.push(new U(g.exclusiveClass,c));let B=SA(A,"lart"),d=SA(A,"lar2");this.readLart(B,d,C),C.isGlobal=!1;let h=A.find(j=>j.header==="wsmp");k(h.chunkData,4);let u=k(h.chunkData,2),l=zA(h.chunkData[h.chunkData.currentIndex++],h.chunkData[h.chunkData.currentIndex++]),S=(k(h.chunkData,4)|0)/-655360;k(h.chunkData,4);let w=k(h.chunkData,4),y,N={start:0,end:0};if(w===0)y=0;else{k(h.chunkData,4),k(h.chunkData,4)===0?y=1:y=3,N.start=k(h.chunkData,4);let J=k(h.chunkData,4);N.end=N.start+J}let G=A.find(j=>j.header==="wlnk");if(G===void 0)return;k(G.chunkData,2),k(G.chunkData,2),k(G.chunkData,4);let K=k(G.chunkData,4),W=this.samples[K];if(W===void 0)throw new Error("Invalid sample ID!");let nA=(S||W.sampleDbAttenuation)*10/.4;return C.setWavesample(nA,y,N,u,W,K,l),C}var de=class{constructor(A,e,s,n,o,i,C,c){this.sampleName=A,this.sampleRate=e,this.samplePitch=s,this.samplePitchCorrection=n,this.sampleLink=o,this.sampleType=i,this.sampleLoopStartIndex=C,this.sampleLoopEndIndex=c,this.isCompressed=(i&16)>0,this.compressedData=void 0,this.useCount=0}getRawData(){let A=new Error("Not implemented");throw A.name="NotImplementedError",A}compressSample(A,e){if(!this.isCompressed)try{this.compressedData=e([this.getAudioData()],1,this.sampleRate,A),this.sampleType|=16,this.isCompressed=!0}catch{L(`Failed to compress ${this.sampleName}. Leaving as uncompressed!`),this.isCompressed=!1,this.compressedData=void 0,this.sampleType&=-17}}getAudioData(){let A=new Error("Not implemented");throw A.name="NotImplementedError",A}};var tt=class extends de{constructor(A,e,s,n,o,i,C,c){super(A,e,s,n,0,1,o,i-1),this.sampleData=C,this.sampleDbAttenuation=c}getAudioData(){return this.sampleData}sampleDbAttenuation;sampleData;getRawData(){if(this.isCompressed){if(!this.compressedData)throw new Error("Compressed but no data??");return this.compressedData}let A=new Uint8Array(this.sampleData.length*2);for(let e=0;e<this.sampleData.length;e++){let s=Math.floor(this.sampleData[e]*32767);A[e*2]=s&255,A[e*2+1]=s>>8&255}return A}};function Ao(t){yA("%cLoading Wave samples...",r.recognized);let A=0;for(;t.chunkData.currentIndex<t.chunkData.length;){let e=O(t.chunkData);this.verifyHeader(e,"LIST"),this.verifyText(V(e.chunkData,4),"wave");let s=[];for(;e.chunkData.currentIndex<e.chunkData.length;)s.push(O(e.chunkData));let n=s.find(J=>J.header==="fmt ");if(!n)throw new Error("No fmt chunk in the wave file!");if(k(n.chunkData,2)!==1)throw new Error("Only PCM format in WAVE is supported.");if(k(n.chunkData,2)!==1)throw new Error("Only mono samples are supported.");let C=k(n.chunkData,4);k(n.chunkData,4),k(n.chunkData,2);let c=k(n.chunkData,2),B=c/8,d=Math.pow(2,B*8-1),h=Math.pow(2,B*8),u,l=!1;c===8?(u=255,l=!0):u=d;let D=s.find(J=>J.header==="data");if(!D)throw new Error("No data chunk in the wave chunk!");let S=D.size/B,w=new Float32Array(S);for(let J=0;J<w.length;J++){let Z=k(D.chunkData,B);l?w[J]=Z/u-.5:(Z>=d&&(Z-=h),w[J]=Z/u)}let y=60,N=0,G=0,K=w.length-1,W=0,I=s.find(J=>J.header==="wsmp");if(I){if(k(I.chunkData,4),y=k(I.chunkData,2),N=zA(I.chunkData[I.chunkData.currentIndex++],I.chunkData[I.chunkData.currentIndex++]),W=(k(I.chunkData,4)|0)/-655360,k(I.chunkData,4),k(I.chunkData,4)===1){k(I.chunkData,8),G=k(I.chunkData,4);let CA=k(I.chunkData,4);K=G+CA}}else L("No wsmp chunk in wave... using sane defaults.");let nA=SA(s,"INFO"),j=`Unnamed ${A}`;if(nA){let J=O(nA.chunkData);for(;J.header!=="INAM"&&nA.chunkData.currentIndex<nA.chunkData.length;)J=O(nA.chunkData);J.header==="INAM"&&(j=V(J.chunkData,J.size).trim())}this.samples.push(new tt(j,C,y,N,G,S,w,W)),A++,m(`%cLoaded sample %c${j}`,r.info,r.recognized)}X()}var WA=class extends ne{constructor(A){if(super(),this.dataArray=new H(A),te("%cParsing DLS...",r.info),!this.dataArray)throw X(),new TypeError("No data!");let e=O(this.dataArray,!1);this.verifyHeader(e,"riff"),this.verifyText(V(this.dataArray,4).toLowerCase(),"dls ");let s=[];for(;this.dataArray.currentIndex<this.dataArray.length;)s.push(O(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 n=SA(s,"INFO");if(n)for(;n.chunkData.currentIndex<n.chunkData.length;){let c=O(n.chunkData);this.soundFontInfo[c.header]=V(c.chunkData,c.size)}this.soundFontInfo.ICMT=(this.soundFontInfo.ICMT||"(No description)")+`
|
|
15
15
|
Converted from DLS to SF2 with SpessaSynth`,this.soundFontInfo.ISBJ&&(this.soundFontInfo.ICMT+=`
|
|
16
16
|
`+this.soundFontInfo.ISBJ,delete this.soundFontInfo.ISBJ);for(let[c,B]of Object.entries(this.soundFontInfo))m(`%c"${c}": %c"${B}"`,r.info,r.recognized);let o=s.find(c=>c.header==="colh");if(!o)throw X(),new Error("No colh chunk!");this.instrumentAmount=k(o.chunkData,4),m(`%cInstruments amount: %c${this.instrumentAmount}`,r.info,r.recognized);let i=SA(s,"wvpl");this.readDLSSamples(i);let C=SA(s,"lins");if(!C)throw X(),new Error("No lins chunk!");this.readDLSInstrumentList(C),this.presets.sort((c,B)=>c.program-B.program+(c.bank-B.bank)),m(`%cParsing finished! %c"${this.soundFontInfo.INAM||"UNNAMED"}"%c has %c${this.presets.length} %cpresets,
|
|
17
|
-
%c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,r.info,r.recognized,r.info,r.recognized,r.info,r.recognized,r.info,r.recognized,r.info),X()}verifyHeader(A,e){if(A.header.toLowerCase()!==e.toLowerCase())throw X(),new SyntaxError(`Invalid DLS chunk header! Expected "${e.toLowerCase()}" got "${A.header.toLowerCase()}"`)}verifyText(A,e){if(A.toLowerCase()!==e.toLowerCase())throw X(),new SyntaxError(`Invalid DLS soundfont! Expected "${e.toLowerCase()}" got "${A.toLowerCase()}"`)}};WA.prototype.readDLSInstrumentList=Xn;WA.prototype.readDLSInstrument=Wn;WA.prototype.readRegion=$n;WA.prototype.readLart=jn;WA.prototype.readDLSSamples=Ao;var Ht=class extends de{constructor(A,e,s,n,o,i,C,c,B,d,h,u,l){super(A,i,C,c,B,d,n-e/2,o-e/2),this.sampleName=A,this.sampleStartIndex=e,this.sampleEndIndex=s,this.isSampleLoaded=!1,this.sampleID=u,this.sampleLength=this.sampleEndIndex-this.sampleStartIndex,this.sampleDataArray=h,this.sampleData=new Float32Array(0),this.isCompressed&&(this.sampleLoopStartIndex+=this.sampleStartIndex,this.sampleLoopEndIndex+=this.sampleStartIndex,this.sampleLength=99999999),this.isDataRaw=l}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{if(!this.isDataRaw)throw new Error("Writing SF2Pack samples is not supported.");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);let n=OA.decode(s.buffer);this.sampleData=n.data[0]}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 L("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;n<s.length;n++)A[n]=s[n]/32768;return this.sampleData=A,this.isSampleLoaded=!0,A}getUncompressedReadyData(){let A=this.sampleDataArray.slice(this.sampleStartIndex/2,this.sampleEndIndex/2);return this.sampleData=A,this.isSampleLoaded=!0,A}};function eo(t,A,e=!0){let s=[],n=0;for(;t.chunkData.length>t.chunkData.currentIndex;){let o=qo(n,t.chunkData,A,e);s.push(o),n++}return s.length>1&&s.pop(),s}function qo(t,A,e,s){let n=V(A,20),o=k(A,4)*2,i=k(A,4)*2,C=k(A,4),c=k(A,4),B=k(A,4),d=A[A.currentIndex++];d===255&&(d=60);let h=us(A[A.currentIndex++]),u=k(A,2),l=k(A,2);return new Ht(n,o,i,C,c,B,d,h,u,l,e,t,s)}var Yt=class extends ue{constructor(A){super(),this.instrumentName=V(A.chunkData,20).trim(),this.instrumentZoneIndex=k(A.chunkData,2),this.instrumentZonesAmount=0}getInstrumentZones(A,e){this.instrumentZonesAmount=A;for(let s=this.instrumentZoneIndex;s<this.instrumentZonesAmount+this.instrumentZoneIndex;s++)this.instrumentZones.push(e[s])}};function to(t,A){let e=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let s=new Yt(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 Jt=class extends $A{constructor(A){super(),this.generatorZoneStartIndex=k(A,2),this.modulatorZoneStartIndex=k(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;e<this.generatorZoneStartIndex+this.generatorZoneSize;e++)this.generators.push(A[e])}getModulators(A){for(let e=this.modulatorZoneStartIndex;e<this.modulatorZoneStartIndex+this.modulatorZoneSize;e++)this.modulators.push(A[e])}getSample(A){let e=this.generators.find(s=>s.generatorType===g.sampleID);e&&(this.sample=A[e.generatorValue],this.isGlobal=!1,this.sample.useCount++)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===g.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===g.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function so(t,A,e,s){let n=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new Jt(t.chunkData);if(n.length>0){let i=o.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,C=o.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(i,C),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 vt=class extends le{constructor(A){super(),this.generatorZoneStartIndex=k(A,2),this.modulatorZoneStartIndex=k(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;e<this.generatorZoneStartIndex+this.generatorZoneSize;e++)this.generators.push(A[e])}getModulators(A){for(let e=this.modulatorZoneStartIndex;e<this.modulatorZoneStartIndex+this.modulatorZoneSize;e++)this.modulators.push(A[e])}getInstrument(A){let e=this.generators.find(s=>s.generatorType===g.instrument);e&&(this.instrument=A[e.generatorValue],this.instrument.addUseCount(),this.isGlobal=!1)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===g.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===g.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function no(t,A,e,s){let n=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new vt(t.chunkData);if(n.length>0){let i=o.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,C=o.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(i,C),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 qt=class extends ce{constructor(A,e){super(e),this.presetName=V(A.chunkData,20).trim().replace(/\d{3}:\d{3}/,""),this.program=k(A.chunkData,2),this.bank=k(A.chunkData,2),this.presetZoneStartIndex=k(A.chunkData,2),this.library=k(A.chunkData,4),this.genre=k(A.chunkData,4),this.morphology=k(A.chunkData,4),this.presetZonesAmount=0}getPresetZones(A,e){this.presetZonesAmount=A;for(let s=this.presetZoneStartIndex;s<this.presetZonesAmount+this.presetZoneStartIndex;s++)this.presetZones.push(e[s])}};function oo(t,A,e){let s=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let n=new qt(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 st=class extends ne{constructor(A,e=!0){if(super(),e&&console.warn("Using the constructor directly is deprecated. Use loadSoundFont instead."),this.dataArray=new H(A),te("%cParsing SoundFont...",r.info),!this.dataArray)throw X(),new TypeError("No data!");let s=O(this.dataArray,!1);this.verifyHeader(s,"riff");let n=V(this.dataArray,4).toLowerCase();if(n!=="sfbk"&&n!=="sfpk")throw X(),new SyntaxError(`Invalid soundFont! Expected "sfbk" or "sfpk" got "${n}"`);let o=n==="sfpk",i=O(this.dataArray);for(this.verifyHeader(i,"list"),V(i.chunkData,4);i.chunkData.length>i.chunkData.currentIndex;){let Z=O(i.chunkData),CA;switch(Z.header.toLowerCase()){case"ifil":case"iver":CA=`${k(Z.chunkData,2)}.${k(Z.chunkData,2)}`,this.soundFontInfo[Z.header]=CA;break;case"icmt":CA=V(Z.chunkData,Z.chunkData.length,void 0,!1),this.soundFontInfo[Z.header]=CA;break;case"dmod":let oA=Ke(Z);oA.pop(),CA=`Modulators: ${oA.length}`;let fA=this.defaultModulators;this.defaultModulators=oA,this.defaultModulators.push(...fA.filter(Me=>!this.defaultModulators.find(RA=>$.isIdentical(Me,RA)))),this.soundFontInfo[Z.header]=Z.chunkData;break;default:CA=V(Z.chunkData,Z.chunkData.length),this.soundFontInfo[Z.header]=CA}m(`%c"${Z.header}": %c"${CA}"`,r.info,r.recognized)}let C=O(this.dataArray,!1);this.verifyHeader(C,"list"),this.verifyText(V(this.dataArray,4),"sdta"),m("%cVerifying smpl chunk...",r.warn);let c=O(this.dataArray,!1);this.verifyHeader(c,"smpl");let B;if(o){m("%cSF2Pack detected, attempting to decode the smpl chunk...",r.info);try{B=OA.decode(this.dataArray.buffer.slice(this.dataArray.currentIndex,this.dataArray.currentIndex+C.size-12)).data[0]}catch(Z){throw X(),new Error(`SF2Pack Ogg Vorbis decode error: ${Z}`)}m(`%cDecoded the smpl chunk! Length: %c${B.length}`,r.info,r.value)}else B=this.dataArray,this.sampleDataStartIndex=this.dataArray.currentIndex;m(`%cSkipping sample chunk, length: %c${C.size-12}`,r.info,r.value),this.dataArray.currentIndex+=C.size-12,m("%cLoading preset data chunk...",r.warn);let d=O(this.dataArray);this.verifyHeader(d,"list"),V(d.chunkData,4);let h=O(d.chunkData);this.verifyHeader(h,"phdr");let u=O(d.chunkData);this.verifyHeader(u,"pbag");let l=O(d.chunkData);this.verifyHeader(l,"pmod");let D=O(d.chunkData);this.verifyHeader(D,"pgen");let S=O(d.chunkData);this.verifyHeader(S,"inst");let w=O(d.chunkData);this.verifyHeader(w,"ibag");let y=O(d.chunkData);this.verifyHeader(y,"imod");let N=O(d.chunkData);this.verifyHeader(N,"igen");let G=O(d.chunkData);this.verifyHeader(G,"shdr"),this.dataArray.currentIndex=this.sampleDataStartIndex,this.samples.push(...eo(G,B,!o));let K=pt(N),W=Ke(y),I=so(w,K,W,this.samples);this.instruments=to(S,I);let nA=pt(D),j=Ke(l),J=no(u,nA,j,this.instruments);this.presets.push(...oo(h,J,this.defaultModulators)),this.presets.sort((Z,CA)=>Z.program-CA.program+(Z.bank-CA.bank)),m(`%cParsing finished! %c"${this.soundFontInfo.INAM}"%c has %c${this.presets.length} %cpresets,
|
|
17
|
+
%c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,r.info,r.recognized,r.info,r.recognized,r.info,r.recognized,r.info,r.recognized,r.info),X()}verifyHeader(A,e){if(A.header.toLowerCase()!==e.toLowerCase())throw X(),new SyntaxError(`Invalid DLS chunk header! Expected "${e.toLowerCase()}" got "${A.header.toLowerCase()}"`)}verifyText(A,e){if(A.toLowerCase()!==e.toLowerCase())throw X(),new SyntaxError(`Invalid DLS soundfont! Expected "${e.toLowerCase()}" got "${A.toLowerCase()}"`)}};WA.prototype.readDLSInstrumentList=Xn;WA.prototype.readDLSInstrument=Wn;WA.prototype.readRegion=$n;WA.prototype.readLart=jn;WA.prototype.readDLSSamples=Ao;var Ht=class extends de{constructor(A,e,s,n,o,i,C,c,B,d,h,u,l){super(A,i,C,c,B,d,n-e/2,o-e/2),this.sampleName=A,this.sampleStartIndex=e,this.sampleEndIndex=s,this.isSampleLoaded=!1,this.sampleID=u,this.sampleLength=this.sampleEndIndex-this.sampleStartIndex,this.sampleDataArray=h,this.sampleData=new Float32Array(0),this.isCompressed&&(this.sampleLoopStartIndex+=this.sampleStartIndex/2,this.sampleLoopEndIndex+=this.sampleStartIndex/2,this.sampleLength=99999999),this.isDataRaw=l}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{if(!this.isDataRaw)throw new Error("Writing SF2Pack samples is not supported.");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);let n=OA.decode(s.buffer);this.sampleData=n.data[0]}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 L("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;n<s.length;n++)A[n]=s[n]/32768;return this.sampleData=A,this.isSampleLoaded=!0,A}getUncompressedReadyData(){let A=this.sampleDataArray.slice(this.sampleStartIndex/2,this.sampleEndIndex/2);return this.sampleData=A,this.isSampleLoaded=!0,A}};function eo(t,A,e=!0){let s=[],n=0;for(;t.chunkData.length>t.chunkData.currentIndex;){let o=qo(n,t.chunkData,A,e);s.push(o),n++}return s.length>1&&s.pop(),s}function qo(t,A,e,s){let n=V(A,20),o=k(A,4)*2,i=k(A,4)*2,C=k(A,4),c=k(A,4),B=k(A,4),d=A[A.currentIndex++];d===255&&(d=60);let h=us(A[A.currentIndex++]),u=k(A,2),l=k(A,2);return new Ht(n,o,i,C,c,B,d,h,u,l,e,t,s)}var Yt=class extends ue{constructor(A){super(),this.instrumentName=V(A.chunkData,20).trim(),this.instrumentZoneIndex=k(A.chunkData,2),this.instrumentZonesAmount=0}getInstrumentZones(A,e){this.instrumentZonesAmount=A;for(let s=this.instrumentZoneIndex;s<this.instrumentZonesAmount+this.instrumentZoneIndex;s++)this.instrumentZones.push(e[s])}};function to(t,A){let e=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let s=new Yt(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 Jt=class extends $A{constructor(A){super(),this.generatorZoneStartIndex=k(A,2),this.modulatorZoneStartIndex=k(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;e<this.generatorZoneStartIndex+this.generatorZoneSize;e++)this.generators.push(A[e])}getModulators(A){for(let e=this.modulatorZoneStartIndex;e<this.modulatorZoneStartIndex+this.modulatorZoneSize;e++)this.modulators.push(A[e])}getSample(A){let e=this.generators.find(s=>s.generatorType===g.sampleID);e&&(this.sample=A[e.generatorValue],this.isGlobal=!1,this.sample.useCount++)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===g.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===g.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function so(t,A,e,s){let n=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new Jt(t.chunkData);if(n.length>0){let i=o.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,C=o.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(i,C),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 vt=class extends le{constructor(A){super(),this.generatorZoneStartIndex=k(A,2),this.modulatorZoneStartIndex=k(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;e<this.generatorZoneStartIndex+this.generatorZoneSize;e++)this.generators.push(A[e])}getModulators(A){for(let e=this.modulatorZoneStartIndex;e<this.modulatorZoneStartIndex+this.modulatorZoneSize;e++)this.modulators.push(A[e])}getInstrument(A){let e=this.generators.find(s=>s.generatorType===g.instrument);e&&(this.instrument=A[e.generatorValue],this.instrument.addUseCount(),this.isGlobal=!1)}getKeyRange(){let A=this.generators.find(e=>e.generatorType===g.keyRange);A&&(this.keyRange.min=A.generatorValue&127,this.keyRange.max=A.generatorValue>>8&127)}getVelRange(){let A=this.generators.find(e=>e.generatorType===g.velRange);A&&(this.velRange.min=A.generatorValue&127,this.velRange.max=A.generatorValue>>8&127)}};function no(t,A,e,s){let n=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let o=new vt(t.chunkData);if(n.length>0){let i=o.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,C=o.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(i,C),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 qt=class extends ce{constructor(A,e){super(e),this.presetName=V(A.chunkData,20).trim().replace(/\d{3}:\d{3}/,""),this.program=k(A.chunkData,2),this.bank=k(A.chunkData,2),this.presetZoneStartIndex=k(A.chunkData,2),this.library=k(A.chunkData,4),this.genre=k(A.chunkData,4),this.morphology=k(A.chunkData,4),this.presetZonesAmount=0}getPresetZones(A,e){this.presetZonesAmount=A;for(let s=this.presetZoneStartIndex;s<this.presetZonesAmount+this.presetZoneStartIndex;s++)this.presetZones.push(e[s])}};function oo(t,A,e){let s=[];for(;t.chunkData.length>t.chunkData.currentIndex;){let n=new qt(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 st=class extends ne{constructor(A,e=!0){if(super(),e&&console.warn("Using the constructor directly is deprecated. Use loadSoundFont instead."),this.dataArray=new H(A),te("%cParsing SoundFont...",r.info),!this.dataArray)throw X(),new TypeError("No data!");let s=O(this.dataArray,!1);this.verifyHeader(s,"riff");let n=V(this.dataArray,4).toLowerCase();if(n!=="sfbk"&&n!=="sfpk")throw X(),new SyntaxError(`Invalid soundFont! Expected "sfbk" or "sfpk" got "${n}"`);let o=n==="sfpk",i=O(this.dataArray);for(this.verifyHeader(i,"list"),V(i.chunkData,4);i.chunkData.length>i.chunkData.currentIndex;){let Z=O(i.chunkData),CA;switch(Z.header.toLowerCase()){case"ifil":case"iver":CA=`${k(Z.chunkData,2)}.${k(Z.chunkData,2)}`,this.soundFontInfo[Z.header]=CA;break;case"icmt":CA=V(Z.chunkData,Z.chunkData.length,void 0,!1),this.soundFontInfo[Z.header]=CA;break;case"dmod":let oA=Ke(Z);oA.pop(),CA=`Modulators: ${oA.length}`;let fA=this.defaultModulators;this.defaultModulators=oA,this.defaultModulators.push(...fA.filter(Me=>!this.defaultModulators.find(RA=>$.isIdentical(Me,RA)))),this.soundFontInfo[Z.header]=Z.chunkData;break;default:CA=V(Z.chunkData,Z.chunkData.length),this.soundFontInfo[Z.header]=CA}m(`%c"${Z.header}": %c"${CA}"`,r.info,r.recognized)}let C=O(this.dataArray,!1);this.verifyHeader(C,"list"),this.verifyText(V(this.dataArray,4),"sdta"),m("%cVerifying smpl chunk...",r.warn);let c=O(this.dataArray,!1);this.verifyHeader(c,"smpl");let B;if(o){m("%cSF2Pack detected, attempting to decode the smpl chunk...",r.info);try{B=OA.decode(this.dataArray.buffer.slice(this.dataArray.currentIndex,this.dataArray.currentIndex+C.size-12)).data[0]}catch(Z){throw X(),new Error(`SF2Pack Ogg Vorbis decode error: ${Z}`)}m(`%cDecoded the smpl chunk! Length: %c${B.length}`,r.info,r.value)}else B=this.dataArray,this.sampleDataStartIndex=this.dataArray.currentIndex;m(`%cSkipping sample chunk, length: %c${C.size-12}`,r.info,r.value),this.dataArray.currentIndex+=C.size-12,m("%cLoading preset data chunk...",r.warn);let d=O(this.dataArray);this.verifyHeader(d,"list"),V(d.chunkData,4);let h=O(d.chunkData);this.verifyHeader(h,"phdr");let u=O(d.chunkData);this.verifyHeader(u,"pbag");let l=O(d.chunkData);this.verifyHeader(l,"pmod");let D=O(d.chunkData);this.verifyHeader(D,"pgen");let S=O(d.chunkData);this.verifyHeader(S,"inst");let w=O(d.chunkData);this.verifyHeader(w,"ibag");let y=O(d.chunkData);this.verifyHeader(y,"imod");let N=O(d.chunkData);this.verifyHeader(N,"igen");let G=O(d.chunkData);this.verifyHeader(G,"shdr"),this.dataArray.currentIndex=this.sampleDataStartIndex,this.samples.push(...eo(G,B,!o));let K=pt(N),W=Ke(y),I=so(w,K,W,this.samples);this.instruments=to(S,I);let nA=pt(D),j=Ke(l),J=no(u,nA,j,this.instruments);this.presets.push(...oo(h,J,this.defaultModulators)),this.presets.sort((Z,CA)=>Z.program-CA.program+(Z.bank-CA.bank)),m(`%cParsing finished! %c"${this.soundFontInfo.INAM}"%c has %c${this.presets.length} %cpresets,
|
|
18
18
|
%c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,r.info,r.recognized,r.info,r.recognized,r.info,r.recognized,r.info,r.recognized,r.info),X(),o&&delete this.dataArray}verifyHeader(A,e){if(A.header.toLowerCase()!==e.toLowerCase())throw X(),new SyntaxError(`Invalid chunk header! Expected "${e.toLowerCase()}" got "${A.header.toLowerCase()}"`)}verifyText(A,e){if(A.toLowerCase()!==e.toLowerCase())throw X(),new SyntaxError(`Invalid soundFont! Expected "${e.toLowerCase()}" got "${A.toLowerCase()}"`)}};function Ge(t){let A=t.slice(8,12),e=new H(A);return V(e,4,void 0,!1).toLowerCase()==="dls "?new WA(t):new st(t,!1)}function ro(t,A,e=!1){let s=this.workletProcessorChannels[t];if(s===void 0){L(`Trying to access channel ${t} which does not exist... ignoring!`);return}if(s.lockPreset)return;let n=s.drumChannel?128:s.midiControllers[p.bankSelect],o,i;if(this.overrideSoundfont){let C=n===128?128:n-this.soundfontBankOffset,c=this.overrideSoundfont.getPresetNoFallback(C,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 io(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 ao(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 Io(t,A){let e=this.workletProcessorChannels[t];e.lockPreset||e.drumChannel!==A&&(A?(e.channelTransposeKeyShift=0,e.drumChannel=!0,this.setPreset(t,this.getPreset(128,e.preset.program))):(e.drumChannel=!1,this.setPreset(t,this.getPreset(e.midiControllers[p.bankSelect],e.preset.program))),e.presetUsesOverride=!1,this.callEvent("drumchange",{channel:t,isDrumChannel:e.drumChannel}),this.sendChannelProperties())}function go(){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 Co(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.workletProcessorChannels.length;e++){let s=this.workletProcessorChannels[e];s.cachedVoices=[];for(let n=0;n<128;n++)s.cachedVoices.push([]);A||(s.lockPreset=!1),this.programChange(e,s.preset.program)}t&&this.sendPresetList()}function Eo(t,A=!1){this.clearSoundFont(!1,A);try{A?(this.overrideSoundfont=Ge(t),this.overrideSoundfont.setSampleIDOffset(this.soundfontManager.totalSoundfontOffset)):this.soundfontManager.reloadManager(t)}catch(e){this.post({messageType:pA.soundfontError,messageData:e});return}this.defaultPreset=this.getPreset(0,0),this.drumPreset=this.getPreset(128,0),this.workletProcessorChannels.forEach((e,s)=>{this.programChange(s,e.preset.program)}),this.post({messageType:pA.ready,messageData:void 0}),this.sendPresetList(),m("%cSpessaSynth is ready!",r.recognized)}function Bo(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 ho(){let A={channelSnapshots:this.workletProcessorChannels.map(e=>({program:e.preset.program,bank:e.preset.bank,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};this.post({messageType:pA.synthesizerSnapshot,messageData:A})}function Qo(t){for(this.system=t.system,this.setMasterGain(t.mainVolume),this.setMasterPan(t.pan),this.transposeAllChannels(t.transposition),this.interpolationType=t.interpolation;this.workletProcessorChannels.length<t.channelSnapshots.length;)this.createWorkletChannel();t.channelSnapshots.forEach((A,e)=>{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,s.midiControllers[p.bankSelect]=A.bank,this.programChange(e,A.program),s.lockPreset=A.lockPreset}),m("%cFinished restoring controllers!",r.info)}var nt=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 Ie.addNewSoundFont:this.addNewSoundFont(e[0],e[1],e[2]);break;case Ie.reloadSoundFont:this.reloadManager(e);break;case Ie.deleteSoundFont:this.deleteSoundFont(e);break;case Ie.rearrangeSoundFonts:this.rearrangeSoundFonts(e)}}getPresetList(){return this.presetList.slice()}reloadManager(A){let e=Ge(A);this.soundfontList=[],this.soundfontList.push({id:"main",bankOffset:0,soundfont:e}),this.generatePresetList(),this.ready()}deleteSoundFont(A){if(this.soundfontList.length===0){L("1 soundfont left. Aborting!");return}let e=this.soundfontList.findIndex(s=>s.id===A);if(e===-1){L(`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:Ge(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]}}};var ot=class{constructor(A,e,s,n,o,i,C,c){this.sampleData=A,this.playbackStep=e,this.cursor=s,this.rootKey=n,this.loopStart=o,this.loopEnd=i,this.end=C,this.loopingMode=c,this.isLooping=this.loopingMode===1||this.loopingMode===3}sampleData;playbackStep=0;cursor=0;rootKey=0;loopStart=0;loopEnd=0;end=0;loopingMode=0;isLooping=!1},xe=class t{constructor(A,e,s,n,o,i,C,c,B){this.sample=e,this.generators=c,this.modulatedGenerators=new Int16Array(c),this.modulators=B,this.velocity=n,this.midiNote=s,this.channelNumber=o,this.startTime=i,this.targetKey=C,this.volumeEnvelope=new LA(A,c[g.sustainVolEnv])}sample;filter=new Qe;generators;modulators=[];modulatedGenerators;finished=!1;isInRelease=!1;channelNumber=0;velocity=0;midiNote=0;pressure=0;targetKey=0;modulationEnvelope=new YA;volumeEnvelope;startTime=0;releaseStartTime=1/0;currentTuningCents=0;currentTuningCalculated=1;currentPan=.5;static copy(A,e){let s=A.sample,n=new ot(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.generators,A.modulators.map(o=>$.copy(o)))}};function co(t,A,e,s,n,o=!1){let i,C=s.cachedVoices[A][e];return C!==void 0?C.map(c=>xe.copy(c,n)):(i=s.preset.getSamplesAndGenerators(A,e).reduce((B,d)=>{if(d.sample.sampleData===void 0)return L(`Discarding invalid sample: ${d.sample.sampleName}`),B;let h=new Int16Array(60);for(let N=0;N<60;N++)h[N]=ds(N,d.presetGenerators,d.instrumentGenerators);h[g.initialAttenuation]=Math.floor(h[g.initialAttenuation]*.4);let u=d.sample.samplePitch;h[g.overridingRootKey]>-1&&(u=h[g.overridingRootKey]);let l=A;h[g.keyNum]>-1&&(l=h[g.keyNum]);let D=d.sample.sampleLoopStartIndex,S=d.sample.sampleLoopEndIndex,w=h[g.sampleModes],y=new ot(d.sample.getAudioData(),d.sample.sampleRate/sampleRate*Math.pow(2,d.sample.samplePitchCorrection/1200),0,u,D,S,Math.floor(d.sample.sampleData.length)-1,w);return h[g.velocity]>-1&&(e=h[g.velocity]),o&&ls([{Sample:d.sample.sampleName,Generators:h,Modulators:d.modulators.map(N=>N.debugString()),Velocity:e,TargetKey:l,MidiNote:A,WorkletSample:y}]),B.push(new xe(sampleRate,y,A,e,t,n,l,h,d.modulators.map(N=>$.copy(N)))),B},[]),s.cachedVoices[A][e]=i.map(B=>xe.copy(B,n)),i)}var Lt=.03,Ut=1,T=class extends AudioWorkletProcessor{constructor(A){super(),this.oneOutputMode=A.processorOptions?.startRenderingData?.oneOutput===!0,this._outputsAmount=this.oneOutputMode?1:A.processorOptions.midiChannels,this.enableEventSystem=A.processorOptions.enableEventSystem,this.deviceID=UA,this.interpolationType=he.fourthOrder,this.processTickCallback=void 0,this.sequencer=new aA(this),this.transposition=0,this.tunings=[];for(let e=0;e<127;e++)this.tunings.push([]);this.soundfontBankOffset=0,this.masterGain=Ut,this.midiVolume=1,this.voiceCap=ys,this.pan=0,this.panLeft=.5*this.currentGain,this.highPerformanceMode=!1,this.overrideSoundfont=void 0,this.panRight=.5*this.currentGain;try{this.soundfontManager=new nt(A.processorOptions.soundfont,this.postReady.bind(this))}catch(e){throw this.post({messageType:pA.soundfontError,messageData:e}),e}this.sendPresetList(),this.defaultPreset=this.getPreset(0,0),this.drumPreset=this.getPreset(128,0),this.workletProcessorChannels=[];for(let e=0;e<A.processorOptions.midiChannels;e++)this.createWorkletChannel(!1);this.workletProcessorChannels[DA].preset=this.drumPreset,this.workletProcessorChannels[DA].drumChannel=!0,this.volumeEnvelopeSmoothingFactor=_s*(sampleRate/44100),this.panSmoothingFactor=js*(sampleRate/44100),this.system=Oe,this.totalVoicesAmount=0,this._snapshot=A.processorOptions?.startRenderingData?.snapshot,this.port.onmessage=e=>this.handleMessage(e.data),A.processorOptions.startRenderingData&&(this._snapshot!==void 0&&(this.applySynthesizerSnapshot(this._snapshot),this.resetAllControllers()),m("%cRendering enabled! Starting render.",r.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]))),OA.isInitialized.then(()=>{this.postReady(),m("%cSpessaSynth is ready!",r.recognized)})}post(A){this.enableEventSystem&&this.port.postMessage(A)}postReady(){this.enableEventSystem&&this.port.postMessage({messageType:pA.ready,messageData:void 0})}get currentGain(){return this.masterGain*this.midiVolume}debugMessage(){m({channels:this.workletProcessorChannels,voicesAmount:this.totalVoicesAmount,outputAmount:this._outputsAmount,dumpedSamples:this.workletDumpedSamplesList})}process(A,e){this.processTickCallback&&this.processTickCallback();let s=0;return this.workletProcessorChannels.forEach((n,o)=>{if(n.voices.length<1||n.isMuted)return;let i,C,c,B,d;if(this.oneOutputMode){let u=e[0];i=o%16*2,C=u[i],c=u[i+1]}else i=o%this._outputsAmount+2,C=e[i][0],c=e[i][1],B=e[0],d=e[1];let h=n.voices;n.voices=[],h.forEach(u=>{this.renderVoice(n,u,C,c,B,d),u.finished||n.voices.push(u)}),s+=n.voices.length}),s!==this.totalVoicesAmount&&(this.totalVoicesAmount=s,this.sendChannelProperties()),!0}};T.prototype.renderVoice=$s;T.prototype.releaseVoice=en;T.prototype.voiceKilling=An;T.prototype.getWorkletVoices=co;T.prototype.handleMessage=nn;T.prototype.sendChannelProperties=rn;T.prototype.callEvent=on;T.prototype.systemExclusive=an;T.prototype.noteOn=gn;T.prototype.noteOff=Cn;T.prototype.polyPressure=yn;T.prototype.killNote=En;T.prototype.stopAll=Bn;T.prototype.stopAllChannels=hn;T.prototype.muteChannel=Rn;T.prototype.setVibrato=xn;T.prototype.disableAndLockGSNRPN=Gn;T.prototype.dataEntryCoarse=Mn;T.prototype.dataEntryFine=Nn;T.prototype.createWorkletChannel=fs;T.prototype.controllerChange=Dn;T.prototype.channelPressure=pn;T.prototype.resetAllControllers=bn;T.prototype.resetControllers=Ln;T.prototype.resetParameters=Un;T.prototype.setMasterGain=wn;T.prototype.setMasterPan=Fn;T.prototype.setMIDIVolume=kn;T.prototype.transposeAllChannels=Qn;T.prototype.transposeChannel=cn;T.prototype.setChannelTuning=ln;T.prototype.setChannelTuningSemitones=un;T.prototype.setMasterTuning=dn;T.prototype.setModulationDepth=fn;T.prototype.pitchWheel=mn;T.prototype.setOctaveTuning=Sn;T.prototype.programChange=ro;T.prototype.getPreset=io;T.prototype.setPreset=ao;T.prototype.setDrums=Io;T.prototype.reloadSoundFont=Eo;T.prototype.clearSoundFont=Co;T.prototype.setEmbeddedSoundFont=Bo;T.prototype.sendPresetList=go;T.prototype.sendSynthesizerSnapshot=ho;T.prototype.applySynthesizerSnapshot=Qo;registerProcessor(ps,T);m("%cProcessor succesfully registered!",r.recognized);
|