Spaces:
Running
Running
Upload demo_main.min.js
Browse files- demo_main.min.js +1 -1
demo_main.min.js
CHANGED
|
@@ -360,7 +360,7 @@ Converted from DLS to SF2 with SpessaSynth`;for(let[r,a]of Object.entries(this.s
|
|
| 360 |
`+c.extraStackTrace()),(p=E).replace(/__Z[\w\d_]+/g,function(Q){var R,W=R=Q;return Q===W?Q:Q+" ["+W+"]"})}function Ft(p,E){return p%E>0&&(p+=E-p%E),p}function mi(p){c.buffer=o=p}function ei(){c.HEAP8=n=new Int8Array(o),c.HEAP16=A=new Int16Array(o),c.HEAP32=r=new Int32Array(o),c.HEAPU8=s=new Uint8Array(o),c.HEAPU16=l=new Uint16Array(o),c.HEAPU32=a=new Uint32Array(o),c.HEAPF32=d=new Float32Array(o),c.HEAPF64=g=new Float64Array(o)}function Gi(){var p=c.usingWasm?65536:16777216,E=2147483648-p;if(r[D>>2]>E)return!1;var Q=ve;for(ve=Math.max(ve,16777216);ve<r[D>>2];)ve=ve<=536870912?Ft(2*ve,p):Math.min(Ft((3*ve+2147483648)/4,p),E);var R=c.reallocBuffer(ve);return R&&R.byteLength==ve?(mi(R),ei(),!0):(ve=Q,!1)}I=h=C=f=y=S=D=0,m=!1,c.reallocBuffer||(c.reallocBuffer=function(p){try{if(ArrayBuffer.transfer)E=ArrayBuffer.transfer(o,p);else{var E,Q=n;E=new ArrayBuffer(p),new Int8Array(E).set(Q)}}catch{return!1}return!!rl(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 Ci=c.TOTAL_STACK||5242880,ve=c.TOTAL_MEMORY||16777216;function co(){return ve}function Nt(p){for(;p.length>0;){var E=p.shift();if(typeof E=="function"){E();continue}var Q=E.func;typeof Q=="number"?E.arg===void 0?c.dynCall_v(Q):c.dynCall_vi(Q,E.arg):Q(E.arg===void 0?null:E.arg)}}ve<Ci&&Y("TOTAL_MEMORY should be larger than TOTAL_STACK, was "+ve+"! (TOTAL_STACK="+Ci+")"),c.buffer?o=c.buffer:(typeof WebAssembly=="object"&&typeof WebAssembly.Memory=="function"?(c.wasmMemory=new WebAssembly.Memory({initial:ve/65536}),o=c.wasmMemory.buffer):o=new ArrayBuffer(ve),c.buffer=o),ei();var Ti=[],pn=[],ts=[],is=[],os=[],mn=!1,tl=!1;function il(p){Ti.unshift(p)}function nc(p){pn.unshift(p)}function sc(p){ts.unshift(p)}function Ac(p){is.unshift(p)}function ol(p){os.unshift(p)}function rc(p,E,Q){var R,W;P("writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!"),Q&&(R=n[W=E+Ye(p)]),xi(p,E,1/0),Q&&(n[W]=R)}function ac(p,E,Q){return p>=0?p:E<=32?2*Math.abs(1<<E-1)+p:Math.pow(2,E)+p}function lc(p,E,Q){if(p<=0)return p;var R=E<=32?Math.abs(1<<E-1):Math.pow(2,E-1);return p>=R&&(E<=32||p>R)&&(p=-2*R+p),p}var nl=Math.abs,sl=Math.ceil,ns=Math.floor,Al=Math.min,ti=0,Cn=null,Ui=null;function cc(p){return p}c.preloadedImages={},c.preloadedAudios={};var ss="data:application/octet-stream;base64,";function go(p){return String.prototype.startsWith?p.startsWith(ss):p.indexOf(ss)===0}(function(){var E="main.wast",Q="main.wasm",R="main.temp.asm.js";go(E)||(E=$(E)),go(Q)||(Q=$(Q)),go(R)||(R=$(R));var W={global:null,env:null,asm2wasm:Ae,parent:c},ae=null;function de(Be){return Be}function _(){try{if(c.wasmBinary)return new Uint8Array(c.wasmBinary);if(c.readBinary)return c.readBinary(Q);throw"both async and sync fetching of the wasm failed"}catch(Be){Mt(Be)}}c.asmPreload=c.asm;var Ge=c.reallocBuffer,ye=function(Be){Be=Ft(Be,c.usingWasm?65536:16777216);var re=c.buffer.byteLength;if(c.usingWasm)try{var Oe=c.wasmMemory.grow((Be-re)/65536);return Oe!==-1?c.buffer=c.wasmMemory.buffer:null}catch{return null}};c.reallocBuffer=function(Be){return Se==="asmjs"?Ge(Be):ye(Be)};var Se="";c.asm=function(Be,re,Oe){var At;if(!(re=At=re).table){var rt,at=c.wasmTableSize;at===void 0&&(at=1024);var ii=c.wasmMaxTableSize;typeof WebAssembly=="object"&&typeof WebAssembly.Table=="function"?ii!==void 0?re.table=new WebAssembly.Table({initial:at,maximum:ii,element:"anyfunc"}):re.table=new WebAssembly.Table({initial:at,element:"anyfunc"}):re.table=Array(at),c.wasmTable=re.table}return re.memoryBase||(re.memoryBase=c.STATIC_BASE),re.tableBase||(re.tableBase=0),rt=function(Ji,Ei,Qn){if(typeof WebAssembly!="object")return Y("no native wasm support detected"),!1;if(!(c.wasmMemory instanceof WebAssembly.Memory))return Y("no native wasm Memory in use"),!1;function uo(Bt,ft){if((ae=Bt.exports).memory){var qi,yn,as;qi=ae.memory,yn=c.buffer,qi.byteLength<yn.byteLength&&Y("the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here"),as=new Int8Array(yn),new Int8Array(qi).set(as),mi(qi),ei()}c.asm=ae,c.usingWasm=!0,function(mc){if(ti--,c.monitorRunDependencies&&c.monitorRunDependencies(ti),ti==0&&(Cn!==null&&(clearInterval(Cn),Cn=null),Ui)){var al=Ui;Ui=null,al()}}("wasm-instantiate")}if(Ei.memory=c.wasmMemory,W.global={NaN:NaN,Infinity:1/0},W["global.Math"]=Math,W.env=Ei,ti++,c.monitorRunDependencies&&c.monitorRunDependencies(ti),c.instantiateWasm)try{return c.instantiateWasm(W,uo)}catch(Bt){return Y("Module.instantiateWasm callback failed with error: "+Bt),!1}function Bi(Bt){uo(Bt.instance,Bt.module)}function rs(Bt){(!c.wasmBinary&&(b||q)&&typeof fetch=="function"?fetch(Q,{credentials:"same-origin"}).then(function(ft){if(!ft.ok)throw"failed to load wasm binary file at '"+Q+"'";return ft.arrayBuffer()}).catch(function(){return _()}):new Promise(function(ft,qi){ft(_())})).then(function(ft){return WebAssembly.instantiate(ft,W)}).then(Bt).catch(function(ft){Y("failed to asynchronously prepare wasm: "+ft),Mt(ft)})}return c.wasmBinary||typeof WebAssembly.instantiateStreaming!="function"||go(Q)||typeof fetch!="function"?rs(Bi):WebAssembly.instantiateStreaming(fetch(Q,{credentials:"same-origin"}),W).then(Bi).catch(function(Bt){Y("wasm streaming compile failed: "+Bt),Y("falling back to ArrayBuffer instantiation"),rs(Bi)}),{}}(Be,re,Oe),$e(rt,"no binaryen method succeeded."),rt},c.asm})(),h=(I=1024)+4816,pn.push(),c.STATIC_BASE=I,c.STATIC_BUMP=4816;var tt=h;function gc(p){n[tt]=n[p],n[tt+1]=n[p+1],n[tt+2]=n[p+2],n[tt+3]=n[p+3]}function dc(p){n[tt]=n[p],n[tt+1]=n[p+1],n[tt+2]=n[p+2],n[tt+3]=n[p+3],n[tt+4]=n[p+4],n[tt+5]=n[p+5],n[tt+6]=n[p+6],n[tt+7]=n[p+7]}function hc(p,E,Q){var R=Q>0?Q:Ye(p)+1,W=Array(R),ae=pi(p,W,0,W.length);return E&&(W.length=ae),W}function Ic(p){for(var E=[],Q=0;Q<p.length;Q++){var R=p[Q];R>255&&(R&=255),E.push(String.fromCharCode(R))}return E.join("")}h+=16,D=te(4),y=(C=f=K(h))+Ci,S=K(y),r[D>>2]=S,m=!0,c.wasmTableSize=4,c.wasmMaxTableSize=4,c.asmGlobalArg={},c.asmLibraryArg={abort:Mt,assert:$e,enlargeMemory:Gi,getTotalMemory:co,abortOnCannotGrowMemory:function(){Mt("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+ve+", (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,R){var W=Bn();try{return c.dynCall_iii(E,Q,R)}catch(ae){if(En(W),typeof ae!="number"&&ae!=="longjmp")throw ae;c.setThrew(1,0)}},___assert_fail:function(E,Q,R,W){Mt("Assertion failed: "+Ut(E)+", at: "+[Q?Ut(Q):"unknown filename",R,W?Ut(W):"unknown function"])},___setErrNo:function(E){return c.___errno_location&&(r[c.___errno_location()>>2]=E),E},_abort:function(){c.abort()},_emscripten_memcpy_big:function(E,Q,R){return s.set(s.subarray(Q,Q+R),E),E},_llvm_floor_f64:ns,DYNAMICTOP_PTR:D,tempDoublePtr:tt,ABORT:Ee,STACKTOP:f,STACK_MAX:y};var As=c.asm(c.asmGlobalArg,c.asmLibraryArg,o);c.asm=As,c.___errno_location=function(){return c.asm.___errno_location.apply(null,arguments)};var rl=c._emscripten_replace_memory=function(){return c.asm._emscripten_replace_memory.apply(null,arguments)};c._free=function(){return c.asm._free.apply(null,arguments)};var ho=c._malloc=function(){return c.asm._malloc.apply(null,arguments)};c._memcpy=function(){return c.asm._memcpy.apply(null,arguments)},c._memset=function(){return c.asm._memset.apply(null,arguments)},c._sbrk=function(){return c.asm._sbrk.apply(null,arguments)},c._stb_vorbis_js_channels=function(){return c.asm._stb_vorbis_js_channels.apply(null,arguments)},c._stb_vorbis_js_close=function(){return c.asm._stb_vorbis_js_close.apply(null,arguments)},c._stb_vorbis_js_decode=function(){return c.asm._stb_vorbis_js_decode.apply(null,arguments)},c._stb_vorbis_js_open=function(){return c.asm._stb_vorbis_js_open.apply(null,arguments)},c._stb_vorbis_js_sample_rate=function(){return c.asm._stb_vorbis_js_sample_rate.apply(null,arguments)},c.establishStackSpace=function(){return c.asm.establishStackSpace.apply(null,arguments)},c.getTempRet0=function(){return c.asm.getTempRet0.apply(null,arguments)},c.runPostSets=function(){return c.asm.runPostSets.apply(null,arguments)},c.setTempRet0=function(){return c.asm.setTempRet0.apply(null,arguments)},c.setThrew=function(){return c.asm.setThrew.apply(null,arguments)};var Io=c.stackAlloc=function(){return c.asm.stackAlloc.apply(null,arguments)},En=c.stackRestore=function(){return c.asm.stackRestore.apply(null,arguments)},Bn=c.stackSave=function(){return c.asm.stackSave.apply(null,arguments)};function Ni(p){this.name="ExitStatus",this.message="Program terminated with exit("+p+")",this.status=p}function fn(p){p=p||c.arguments,!(ti>0)&&(function(){if(c.preRun)for(typeof c.preRun=="function"&&(c.preRun=[c.preRun]);c.preRun.length;)il(c.preRun.shift());Nt(Ti)}(),!(ti>0)&&(c.calledRun||(c.setStatus?(c.setStatus("Running..."),setTimeout(function(){setTimeout(function(){c.setStatus("")},1),E()},1)):E())));function E(){!c.calledRun&&(c.calledRun=!0,Ee||(mn||(mn=!0,Nt(pn)),Nt(ts),c.onRuntimeInitialized&&c.onRuntimeInitialized(),function(){if(c.postRun)for(typeof c.postRun=="function"&&(c.postRun=[c.postRun]);c.postRun.length;)ol(c.postRun.shift());Nt(os)}()))}}function uc(p,E){(!E||!c.noExitRuntime||p!==0)&&(c.noExitRuntime||(Ee=!0,Et=p,f=w,Nt(is),tl=!0,c.onExit&&c.onExit(p)),c.quit(p,new Ni(p)))}function Mt(p){throw c.onAbort&&c.onAbort(p),p!==void 0?(j(p),Y(p),p=JSON.stringify(p)):p="",Ee=!0,Et=1,"abort("+p+"). Build with -s ASSERTIONS=1 for more info."}if(c.dynCall_iii=function(){return c.asm.dynCall_iii.apply(null,arguments)},c.asm=As,c.ccall=Ii,c.cwrap=function(E,Q,R,W){var ae=(R=R||[]).every(function(de){return de==="number"});return Q!=="string"&&ae&&!W?Gt(E):function(){return Ii(E,Q,R,arguments,W)}},Ni.prototype=Error(),Ni.prototype.constructor=Ni,Ui=function p(){c.calledRun||fn(),c.calledRun||(Ui=p)},c.run=fn,c.abort=Mt,c.preInit)for(typeof c.preInit=="function"&&(c.preInit=[c.preInit]);c.preInit.length>0;)c.preInit.pop()();c.noExitRuntime=!0,fn(),c.onRuntimeInitialized=()=>{Ja=!0,qa()},Xt.decode=function(p){return function(Q){if(!Ja)throw Error("SF3 decoder has not been initialized yet. Did you await synth.isReady?");var R={};function W(Ei){return new Int32Array(c.HEAPU8.buffer,Ei,1)[0]}function ae(Ei,Qn){var uo=new ArrayBuffer(Qn*Float32Array.BYTES_PER_ELEMENT),Bi=new Float32Array(uo);return Bi.set(new Float32Array(c.HEAPU8.buffer,Ei,Qn)),Bi}R.open=c.cwrap("stb_vorbis_js_open","number",[]),R.close=c.cwrap("stb_vorbis_js_close","void",["number"]),R.channels=c.cwrap("stb_vorbis_js_channels","number",["number"]),R.sampleRate=c.cwrap("stb_vorbis_js_sample_rate","number",["number"]),R.decode=c.cwrap("stb_vorbis_js_decode","number",["number","number","number","number","number"]);var de,_,Ge,ye,Se=R.open(),Be=(de=Q,_=Q.byteLength,Ge=c._malloc(_),(ye=new Uint8Array(c.HEAPU8.buffer,Ge,_)).set(new Uint8Array(de,0,_)),ye),re=c._malloc(4),Oe=c._malloc(4),At=R.decode(Se,Be.byteOffset,Be.byteLength,re,Oe);if(c._free(Be.byteOffset),At<0)throw R.close(Se),c._free(re),Error("stbvorbis decode failed: "+At);for(var rt=R.channels(Se),at=Array(rt),ii=new Int32Array(c.HEAPU32.buffer,W(re),rt),lt=0;lt<rt;lt++)at[lt]=ae(ii[lt],At),c._free(ii[lt]);var Ji=R.sampleRate(Se);return R.close(Se),c._free(W(re)),c._free(re),{data:at,sampleRate:Ji,eof:!0,error:null}}(p)}})();var Kn=class extends Wt{constructor(e,t,o,n,s,A,l,r,a,d,g,I,h){super(e,A,l,r,a,d,n-t/2,s-t/2),this.sampleName=e,this.sampleStartIndex=t,this.sampleEndIndex=o,this.isSampleLoaded=!1,this.sampleID=I,this.sampleLength=this.sampleEndIndex-this.sampleStartIndex,this.sampleDataArray=g,this.sampleData=new Float32Array(0),this.isCompressed&&(this.sampleLoopStartIndex+=this.sampleStartIndex/2,this.sampleLoopEndIndex+=this.sampleStartIndex/2,this.sampleLength=99999999),this.isDataRaw=h}getRawData(){let e=this.sampleDataArray;if(this.isCompressed){if(this.compressedData)return this.compressedData;let t=e.currentIndex;return e.slice(this.sampleStartIndex/2+t,this.sampleEndIndex/2+t)}else{this.isDataRaw||super.getRawData();let t=e.currentIndex;return e.slice(t+this.sampleStartIndex,t+this.sampleEndIndex)}}decodeVorbis(){if(this.sampleLength<1)return;let e=this.sampleDataArray,t=e.currentIndex,o=e.slice(this.sampleStartIndex/2+t,this.sampleEndIndex/2+t);this.sampleData=new Float32Array(0);try{let n=Xt.decode(o.buffer);this.sampleData=n.data[0],this.sampleData===void 0&&ie(`Error decoding sample ${this.sampleName}: Vorbis decode returned undefined.`)}catch(n){ie(`Error decoding sample ${this.sampleName}: ${n}`),this.sampleData=new Float32Array(this.sampleLoopEndIndex+1)}}getAudioData(){return this.isSampleLoaded?this.sampleData:this.sampleLength<1?(ie(`Invalid sample ${this.sampleName}! Invalid length: ${this.sampleLength}`),new Float32Array(1)):this.isCompressed?(this.decodeVorbis(),this.isSampleLoaded=!0,this.sampleData):this.isDataRaw?this.loadUncompressedData():this.getUncompressedReadyData()}loadUncompressedData(){if(this.isCompressed)return ie("Trying to load a compressed sample via loadUncompressedData()... aborting!"),new Float32Array(0);let e=new Float32Array(this.sampleLength/2),t=this.sampleDataArray.currentIndex,o=new Int16Array(this.sampleDataArray.slice(t+this.sampleStartIndex,t+this.sampleEndIndex).buffer);for(let n=0;n<o.length;n++)e[n]=o[n]/32768;return this.sampleData=e,this.isSampleLoaded=!0,e}getUncompressedReadyData(){let e=this.sampleDataArray.slice(this.sampleStartIndex/2,this.sampleEndIndex/2);return this.sampleData=e,this.isSampleLoaded=!0,e}};function Ka(i,e,t=!0){let o=[],n=0;for(;i.chunkData.length>i.chunkData.currentIndex;){let s=Hl(n,i.chunkData,e,t);o.push(s),n++}return o.length>1&&o.pop(),o}function Hl(i,e,t,o){let n=Ie(e,20),s=N(e,4)*2,A=N(e,4)*2,l=N(e,4),r=N(e,4),a=N(e,4),d=e[e.currentIndex++];d===255&&(d=60);let g=Ss(e[e.currentIndex++]),I=N(e,2),h=N(e,2);return new Kn(n,s,A,l,r,a,d,g,I,h,t,i,o)}var Vn=class extends J{constructor(e){super();let t=e.currentIndex;this.generatorType=e[t+1]<<8|e[t],this.generatorValue=Kt(e[t+2],e[t+3]),e.currentIndex+=4}};function Yn(i){let e=[];for(;i.chunkData.length>i.chunkData.currentIndex;)e.push(new Vn(i.chunkData));return e.length>1&&e.pop(),e}var Pn=class extends Pe{constructor(e){super(),this.generatorZoneStartIndex=N(e,2),this.modulatorZoneStartIndex=N(e,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(e,t){this.modulatorZoneSize=e,this.generatorZoneSize=t}getGenerators(e){for(let t=this.generatorZoneStartIndex;t<this.generatorZoneStartIndex+this.generatorZoneSize;t++)this.generators.push(e[t])}getModulators(e){for(let t=this.modulatorZoneStartIndex;t<this.modulatorZoneStartIndex+this.modulatorZoneSize;t++)this.modulators.push(e[t])}getSample(e){let t=this.generators.find(o=>o.generatorType===u.sampleID);t&&(this.sample=e[t.generatorValue],this.isGlobal=!1,this.sample.useCount++)}getKeyRange(){let e=this.generators.find(t=>t.generatorType===u.keyRange);e&&(this.keyRange.min=e.generatorValue&127,this.keyRange.max=e.generatorValue>>8&127)}getVelRange(){let e=this.generators.find(t=>t.generatorType===u.velRange);e&&(this.velRange.min=e.generatorValue&127,this.velRange.max=e.generatorValue>>8&127)}};function Va(i,e,t,o){let n=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let s=new Pn(i.chunkData);if(n.length>0){let A=s.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,l=s.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(A,l),n[n.length-1].getGenerators(e),n[n.length-1].getModulators(t),n[n.length-1].getSample(o),n[n.length-1].getKeyRange(),n[n.length-1].getVelRange()}n.push(s)}return n.length>1&&n.pop(),n}var On=class extends Ht{constructor(e){super(),this.generatorZoneStartIndex=N(e,2),this.modulatorZoneStartIndex=N(e,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(e,t){this.modulatorZoneSize=e,this.generatorZoneSize=t}getGenerators(e){for(let t=this.generatorZoneStartIndex;t<this.generatorZoneStartIndex+this.generatorZoneSize;t++)this.generators.push(e[t])}getModulators(e){for(let t=this.modulatorZoneStartIndex;t<this.modulatorZoneStartIndex+this.modulatorZoneSize;t++)this.modulators.push(e[t])}getInstrument(e){let t=this.generators.find(o=>o.generatorType===u.instrument);t&&(this.instrument=e[t.generatorValue],this.instrument.addUseCount(),this.isGlobal=!1)}getKeyRange(){let e=this.generators.find(t=>t.generatorType===u.keyRange);e&&(this.keyRange.min=e.generatorValue&127,this.keyRange.max=e.generatorValue>>8&127)}getVelRange(){let e=this.generators.find(t=>t.generatorType===u.velRange);e&&(this.velRange.min=e.generatorValue&127,this.velRange.max=e.generatorValue>>8&127)}};function Ya(i,e,t,o){let n=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let s=new On(i.chunkData);if(n.length>0){let A=s.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,l=s.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(A,l),n[n.length-1].getGenerators(e),n[n.length-1].getModulators(t),n[n.length-1].getInstrument(o),n[n.length-1].getKeyRange(),n[n.length-1].getVelRange()}n.push(s)}return n.length>1&&n.pop(),n}var Hn=class extends Zt{constructor(e,t){super(t),this.presetName=Ie(e.chunkData,20).trim().replace(/\d{3}:\d{3}/,""),this.program=N(e.chunkData,2),this.bank=N(e.chunkData,2),this.presetZoneStartIndex=N(e.chunkData,2),this.library=N(e.chunkData,4),this.genre=N(e.chunkData,4),this.morphology=N(e.chunkData,4),this.presetZonesAmount=0}getPresetZones(e,t){this.presetZonesAmount=e;for(let o=this.presetZoneStartIndex;o<this.presetZonesAmount+this.presetZoneStartIndex;o++)this.presetZones.push(t[o])}};function Pa(i,e,t){let o=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let n=new Hn(i,t);if(o.length>0){let s=n.presetZoneStartIndex-o[o.length-1].presetZoneStartIndex;o[o.length-1].getPresetZones(s,e)}o.push(n)}return o.length>1&&o.pop(),o}var Wn=class extends zt{constructor(e){super(),this.instrumentName=Ie(e.chunkData,20).trim(),this.instrumentZoneIndex=N(e.chunkData,2),this.instrumentZonesAmount=0}getInstrumentZones(e,t){this.instrumentZonesAmount=e;for(let o=this.instrumentZoneIndex;o<this.instrumentZonesAmount+this.instrumentZoneIndex;o++)this.instrumentZones.push(t[o])}};function Oa(i,e){let t=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let o=new Wn(i);if(t.length>0){let n=o.instrumentZoneIndex-t[t.length-1].instrumentZoneIndex;t[t.length-1].getInstrumentZones(n,e)}t.push(o)}return t.length>1&&t.pop(),t}var zn=class extends oe{constructor(e){let t=N(e,2),o=N(e,2),n=Kt(e[e.currentIndex++],e[e.currentIndex++]),s=N(e,2),A=N(e,2);super(t,s,o,n,A)}};function rn(i){let e=[];for(;i.chunkData.length>i.chunkData.currentIndex;)e.push(new zn(i.chunkData));return e}var an=class extends jt{constructor(e,t=!0){super(),t&&console.warn("Using the constructor directly is deprecated. Use loadSoundFont instead."),this.dataArray=new U(e),He("%cParsing SoundFont...",B.info),this.dataArray||(ne(),this.parsingError("No data provided!"));let o=he(this.dataArray,!1);this.verifyHeader(o,"riff");let n=Ie(this.dataArray,4).toLowerCase();if(n!=="sfbk"&&n!=="sfpk")throw ne(),new SyntaxError(`Invalid soundFont! Expected "sfbk" or "sfpk" got "${n}"`);let s=n==="sfpk",A=he(this.dataArray);for(this.verifyHeader(A,"list"),Ie(A.chunkData,4);A.chunkData.length>A.chunkData.currentIndex;){let O=he(A.chunkData),T;switch(O.header.toLowerCase()){case"ifil":case"iver":T=`${N(O.chunkData,2)}.${N(O.chunkData,2)}`,this.soundFontInfo[O.header]=T;break;case"icmt":T=Ie(O.chunkData,O.chunkData.length,void 0,!1),this.soundFontInfo[O.header]=T;break;case"dmod":let H=rn(O);H.pop(),T=`Modulators: ${H.length}`;let $=this.defaultModulators;this.defaultModulators=H,this.defaultModulators.push(...$.filter(j=>!this.defaultModulators.find(Y=>oe.isIdentical(j,Y)))),this.soundFontInfo[O.header]=O.chunkData;break;default:T=Ie(O.chunkData,O.chunkData.length),this.soundFontInfo[O.header]=T}F(`%c"${O.header}": %c"${T}"`,B.info,B.recognized)}let l=he(this.dataArray,!1);this.verifyHeader(l,"list"),this.verifyText(Ie(this.dataArray,4),"sdta"),F("%cVerifying smpl chunk...",B.warn);let r=he(this.dataArray,!1);this.verifyHeader(r,"smpl");let a;if(s){F("%cSF2Pack detected, attempting to decode the smpl chunk...",B.info);try{a=Xt.decode(this.dataArray.buffer.slice(this.dataArray.currentIndex,this.dataArray.currentIndex+l.size-12)).data[0]}catch(O){throw ne(),new Error(`SF2Pack Ogg Vorbis decode error: ${O}`)}F(`%cDecoded the smpl chunk! Length: %c${a.length}`,B.info,B.value)}else a=this.dataArray,this.sampleDataStartIndex=this.dataArray.currentIndex;F(`%cSkipping sample chunk, length: %c${l.size-12}`,B.info,B.value),this.dataArray.currentIndex+=l.size-12,F("%cLoading preset data chunk...",B.warn);let d=he(this.dataArray);this.verifyHeader(d,"list"),Ie(d.chunkData,4);let g=he(d.chunkData);this.verifyHeader(g,"phdr");let I=he(d.chunkData);this.verifyHeader(I,"pbag");let h=he(d.chunkData);this.verifyHeader(h,"pmod");let m=he(d.chunkData);this.verifyHeader(m,"pgen");let C=he(d.chunkData);this.verifyHeader(C,"inst");let f=he(d.chunkData);this.verifyHeader(f,"ibag");let y=he(d.chunkData);this.verifyHeader(y,"imod");let S=he(d.chunkData);this.verifyHeader(S,"igen");let D=he(d.chunkData);this.verifyHeader(D,"shdr"),this.dataArray.currentIndex=this.sampleDataStartIndex,this.samples.push(...Ka(D,a,!s));let k=Yn(S),w=rn(y),c=Va(f,k,w,this.samples);this.instruments=Oa(C,c);let M=Yn(m),b=rn(h),q=Ya(I,M,b,this.instruments);this.presets.push(...Pa(g,q,this)),this.presets.sort((O,T)=>O.program-T.program+(O.bank-T.bank)),this._parseInternal(),F(`%cParsing finished! %c"${this.soundFontInfo.INAM}"%c has %c${this.presets.length} %cpresets,
|
| 361 |
%c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,B.info,B.recognized,B.info,B.recognized,B.info,B.recognized,B.info,B.recognized,B.info),ne(),s&&delete this.dataArray}verifyHeader(e,t){e.header.toLowerCase()!==t.toLowerCase()&&(ne(),this.parsingError(`Invalid chunk header! Expected "${t.toLowerCase()}" got "${e.header.toLowerCase()}"`))}verifyText(e,t){e.toLowerCase()!==t.toLowerCase()&&(ne(),this.parsingError(`Invalid FourCC: Expected "${t.toLowerCase()}" got "${e.toLowerCase()}"\``))}destroySoundBank(){super.destroySoundBank(),delete this.dataArray}};function Lt(i){let e=i.slice(8,12),t=new U(e);return Ie(t,4,void 0,!1).toLowerCase()==="dls "?new xt(i):new an(i,!1)}async function Ha(){let i="locale.exportAudio.formats.formats.soundfont.options.";ue(this.localeManager.getLocaleString(i+"title"),[{type:"toggle",translatePathTitle:i+"trim",attributes:{"trim-toggle":"1",checked:"checked"}},{type:"toggle",translatePathTitle:i+"compress",attributes:{"compress-toggle":"1"}},{type:"range",translatePathTitle:i+"quality",attributes:{min:"0",max:"10",value:"5"}},{type:"button",textContent:this.localeManager.getLocaleString(i+"confirm"),onClick:async e=>{let t=e.div.querySelector("input[trim-toggle='1']").checked,o=e.div.querySelector("input[compress-toggle='1']").checked,n=parseInt(e.div.querySelector("input[type='range']").value)/10;le(e.id),He("%cExporting minified soundfont...",B.info);let s=await this.seq.getMIDI(),A=Lt(s.embeddedSoundFont||this.soundFont);s.applySnapshotToMIDI(await this.synth.getSynthesizerSnapshot()),t&&A.trimSoundBank(s);let l=A.write({compress:o,compressionQuality:n,compressionFunction:await this.getVorbisEncodeFunction()}),r=new Blob([l.buffer],{type:"audio/soundfont"}),a=A.soundFontInfo.ifil.split(".")[0]==="3"?"sf3":"sf2";this.saveBlob(r,`${A.soundFontInfo.INAM||"unnamed"}.${a}`),ne()}}],99999999,!0,this.localeManager)}async function Wa(){let i="locale.exportAudio.formats.";ue(this.localeManager.getLocaleString(i+"title"),[{type:"button",translatePathTitle:i+"formats.wav.button",onClick:e=>{le(e.id),this._exportAudioData()}},{type:"button",translatePathTitle:i+"formats.midi.button",onClick:e=>{le(e.id),this.exportMidi()}},{type:"button",translatePathTitle:i+"formats.soundfont.button",onClick:e=>{le(e.id);try{this._exportSoundfont()}catch{ue("Warning",[{type:"text",textContent:this.localeManager.getLocaleString("locale.warnings.outOfMemory")}])}}},{type:"button",translatePathTitle:i+"formats.dls.button",onClick:e=>{le(e.id);try{this._exportDLS()}catch{ue("Warning",[{type:"text",textContent:this.localeManager.getLocaleString("locale.warnings.outOfMemory")}])}}},{type:"button",translatePathTitle:i+"formats.rmidi.button",onClick:e=>{le(e.id);try{this._exportRMIDI()}catch{ue("Warning",[{type:"text",textContent:this.localeManager.getLocaleString("locale.warnings.outOfMemory")}])}}}],999999,!0,this.localeManager,{display:"flex",flexWrap:"wrap",justifyContent:"center"})}async function za(){let i=(g,I,h)=>this.seq.midiData.RMIDInfo?.[g]===void 0?I:h.decode(this.seq.midiData.RMIDInfo?.[g]).replace(/\0$/,""),e=i("IENC","ascii",new TextDecoder),t=new TextDecoder(e),o=i("IPRD","",t),n=i("IART","",t),s=i("IGNR","",t),A=i("ICMT","Created using SpessaSynth: https://spessasus.github.io/SpessaSynth",t),l="locale.exportAudio.formats.formats.rmidi.options.",r="locale.exportAudio.formats.metadata.",d=ue(this.localeManager.getLocaleString(l+"title"),[{type:"text",textContent:this.localeManager.getLocaleString(l+"description"),attributes:{style:"max-width: 30ch; font-style: italic"}},{type:"toggle",translatePathTitle:l+"compress",attributes:{"compress-toggle":"1",checked:"true"}},{type:"range",translatePathTitle:l+"quality",attributes:{min:"0",max:"10",value:"5"}},{type:"input",translatePathTitle:r+"songTitle",attributes:{name:"song_title",type:"text",value:this.seqUI.currentSongTitle}},{type:"input",translatePathTitle:r+"album",attributes:{value:o,name:"album",type:"text"}},{type:"input",translatePathTitle:r+"artist",attributes:{value:n,name:"artist",type:"text"}},{type:"input",translatePathTitle:r+"genre",attributes:{value:s,name:"genre",type:"text"}},{type:"input",translatePathTitle:r+"comment",attributes:{value:A,name:"comment",type:"text"}},{type:"file",translatePathTitle:r+"albumCover",attributes:{value:this.seq.midiData.RMIDInfo?.IPIC!==void 0?this.seq.midiData.RMIDInfo.IPIC:"",name:"cover",accept:"image/*"}},{type:"input",translatePathTitle:l+"bankOffset",attributes:{value:this.seq.midiData.bankOffset,name:"bank_offset",type:"number"}},{type:"toggle",translatePathTitle:l+"adjust",attributes:{name:"adjust",checked:"checked"}},{type:"button",textContent:this.localeManager.getLocaleString(l+"confirm"),onClick:async g=>{let I=g.div.querySelector("input[compress-toggle='1']").checked,h=parseInt(g.div.querySelector("input[type='range']").value)/10,m=g.div.querySelector("input[name='album']").value,C=g.div.querySelector("input[name='artist']").value,f=g.div.querySelector("input[name='song_title']").value,y=g.div.querySelector("input[name='comment']").value,S=g.div.querySelector("input[name='genre']").value,D=parseInt(g.div.querySelector("input[name='bank_offset']").value),k=g.div.querySelector("input[name='adjust']").checked,w=g.div.querySelector("input[type='file']")?.files[0];le(g.id),we("%cExporting RMIDI...",B.info);let c="locale.exportAudio.formats.formats.rmidi.progress.",M=ue(this.localeManager.getLocaleString(c+"title"),[{type:"text",textContent:this.localeManager.getLocaleString(c+"loading"),attributes:{class:"export_rmidi_message"}}],9999999,!1);await new Promise(Y=>setTimeout(Y,500));let b=M.div.getElementsByClassName("export_rmidi_message")[0],q=await this.seq.getMIDI(),O=Lt(q.embeddedSoundFont||this.soundFont);b.textContent=this.localeManager.getLocaleString(c+"modifyingMIDI"),await new Promise(Y=>setTimeout(Y,75));try{q.applySnapshotToMIDI(await this.synth.getSynthesizerSnapshot())}catch(Y){ie("Failed to modify MIDI:",Y)}b.textContent=this.localeManager.getLocaleString(c+"modifyingSoundfont"),await new Promise(Y=>setTimeout(Y,75)),O.trimSoundBank(q);let T=O.write({compress:I,compressionQuality:h,compressionFunction:await this.getVorbisEncodeFunction()});b.textContent=this.localeManager.getLocaleString(c+"saving"),await new Promise(Y=>setTimeout(Y,75));let H;w?.type.split("/")[0]==="image"?H=await w.arrayBuffer():q.RMIDInfo?.IPIC!==void 0&&(H=q.RMIDInfo.IPIC.buffer);let $=q.writeRMIDI(T,O,D,this.seqUI.encoding,{name:f,comment:y,engineer:O.soundFontInfo.IENG,picture:H,album:m.length>0?m:void 0,artist:C.length>0?C:void 0,genre:S.length>0?S:void 0,midiEncoding:this.seqUI.encoding},k),j=new Blob([$.buffer],{type:"audio/rmid"});this.saveBlob(j,`${f||"unnamed_song"}.rmi`),b.textContent=this.localeManager.getLocaleString(c+"done"),le(M.id),ne()}}],9999999,!0,this.localeManager).div.querySelector("input[type='file']");d.oninput=()=>{d.files[0]&&(d.parentElement.firstChild.textContent=d.files[0].name)}}var Za="worklet_processor.min.js";var ln=class{constructor(e,t){let o=document.getElementsByClassName("drop_prompt")[0];document.body.addEventListener("dragover",n=>{n.preventDefault(),o.classList.remove("hidden")}),document.body.addEventListener("dragend",()=>{o.classList.add("hidden")}),document.body.addEventListener("drop",async n=>{if(n.preventDefault(),o.classList.add("hidden"),!n.dataTransfer.files[0])return;let s=[];for(let A of n.dataTransfer.files){let l=A.name,r=await A.arrayBuffer(),a=r.slice(0,4),d=new TextDecoder;if(d.decode(a)==="RIFF"){let g=r.slice(8,12);if(d.decode(g)==="RMID"){s.push({binary:r,altName:l});continue}t(r);continue}s.push({binary:r,altName:l})}e(s)})}};async function ja(){let i="locale.exportAudio.formats.formats.dls.warning.";ue(this.localeManager.getLocaleString(i+"title"),[{type:"text",textContent:this.localeManager.getLocaleString(i+"message"),attributes:{style:"font-weight: bold"}},{type:"toggle",translatePathTitle:"locale.exportAudio.formats.formats.soundfont.options.trim",attributes:{"trim-toggle":"1"}},{type:"button",textContent:this.localeManager.getLocaleString(i+"details"),onClick:()=>{window.open("https://github.com/spessasus/SpessaSynth/wiki/DLS-Conversion-Problem")}},{type:"button",textContent:this.localeManager.getLocaleString(i+"confirm"),onClick:async e=>{let t=e.div.querySelector("input[trim-toggle='1']").checked;le(e.id),He("%cExporting DLS...",B.info);let o=await this.seq.getMIDI(),n=Lt(o.embeddedSoundFont||this.soundFont);o.applySnapshotToMIDI(await this.synth.getSynthesizerSnapshot()),t&&n.trimSoundBank(o);try{let s=n.writeDLS(),A=new Blob([s.buffer],{type:"audio/dls"});this.saveBlob(A,`${n.soundFontInfo.INAM||"unnamed"}.dls`)}catch(s){ie("Failed to export DLS: ",s),ue(this.localeManager.getLocaleString("locale.error"),[{type:"text",textContent:s,attributes:{style:"font-weight: bold; color: red"}}])}ne()}}],99999999,!0,this.localeManager)}document.body.classList.add("load");var Wl=!1,mt=class{channelColors=["rgba(255, 99, 71, 1)","rgba(255, 165, 0, 1)","rgba(255, 215, 0, 1)","rgba(50, 205, 50, 1)","rgba(60, 179, 113, 1)","rgba(0, 128, 0, 1)","rgba(0, 191, 255, 1)","rgba(65, 105, 225, 1)","rgba(138, 43, 226, 1)","rgba(50, 120, 125, 1)","rgba(255, 0, 255, 1)","rgba(255, 20, 147, 1)","rgba(218, 112, 214, 1)","rgba(240, 128, 128, 1)","rgba(255, 192, 203, 1)","rgba(255, 255, 0, 1)"];sfError;compressionFunction=void 0;constructor(e,t,o,n=Wl){this.localeManager=o,this.context=e,this.enableDebug=n,this.isExporting=!1;let s;this.ready=new Promise(A=>s=A),this.initializeContext(e,t).then(()=>{s()})}async getVorbisEncodeFunction(){return this.compressionFunction!==void 0?this.compressionFunction:(this.compressionFunction=(await import("../externals/libvorbis/encode_vorbis.js")).encodeVorbis,this.compressionFunction)}saveBlob(e,t){let o=URL.createObjectURL(e),n=document.createElement("a");n.href=o,n.download=t,n.click(),F(n)}async initializeContext(e,t){if(!e.audioWorklet)throw alert("Audio worklet is not supported on your browser. Sorry!"),new Error("Audio worklet is not supported");for(let a of document.querySelectorAll("*[translate-path]"))this.localeManager.bindObjectProperty(a,"innerText",a.getAttribute("translate-path"));for(let a of document.querySelectorAll("*[translate-path-title]"))this.localeManager.bindObjectProperty(a,"innerText",a.getAttribute("translate-path-title")+".title"),this.localeManager.bindObjectProperty(a,"title",a.getAttribute("translate-path-title")+".description");this.soundFont=t;let n=this.enableDebug?"worklet_processor.js":Za;this.enableDebug&&console.warn("DEBUG ENABLED! DEBUGGING ENABLED!!");let s=window.isLocalEdition?"../../../":"../../";this.workletPath=s+n,e.audioWorklet&&await e.audioWorklet.addModule(new URL(this.workletPath,import.meta.url)),this.audioDelay=new DelayNode(e,{delayTime:0}),this.audioDelay.connect(e.destination),this.synth=new ki(this.audioDelay,this.soundFont,void 0,void 0,{chorusEnabled:!0,chorusConfig:void 0,reverbEnabled:!0,audioNodeCreators:void 0}),this.synth.eventHandler.addEvent("soundfonterror","manager-sf-error",a=>{this.sfError&&this.sfError(a.message)}),await this.synth.isReady,this.midHandler=new Yo,new Po(this.synth),this.keyboard=new zi(this.channelColors,this.synth);let A=document.getElementById("note_canvas");A.width=window.innerWidth*window.devicePixelRatio,A.height=window.innerHeight*window.devicePixelRatio,this.renderer=new Je(this.channelColors,this.synth,A,this.localeManager,window.SPESSASYNTH_VERSION),this.renderer.render(!0);let l=!1,r=()=>{if(this.renderer.updateSize(),je){if(window.innerWidth/window.innerHeight>1){if(!l){let a=document.getElementById("title_wrapper"),d=document.getElementById("settings_div");l=!0,a.parentElement.insertBefore(d,a)}}else if(l){let a=document.getElementById("title_wrapper"),d=document.getElementById("settings_div");l=!1,a.parentElement.insertBefore(a,d)}}this.renderer.render(!1,!0)};r(),window.addEventListener("resize",r.bind(this)),window.addEventListener("orientationchange",r.bind(this)),je&&(this.renderer.keyRange={min:48,max:72},this.keyboard.setKeyRange({min:48,max:72},!1)),this.synthUI=new ut(this.channelColors,document.getElementById("synthetizer_controls"),this.localeManager),this.synthUI.connectSynth(this.synth),this.synthUI.connectKeyboard(this.keyboard),this.musicModeUI=new Zo(document.getElementById("player_info"),this.localeManager),this.seqUI=new Rt(document.getElementById("sequencer_controls"),this.localeManager,this.musicModeUI,this.renderer),this.settingsUI=new Ve(document.getElementById("settings_div"),this.synthUI,this.seqUI,this.renderer,this.keyboard,this.midHandler,this.musicModeUI,this.localeManager,this.audioDelay),new ln(async a=>{if(a.length===0)return;await this.context.resume(),this.play(a);let d=a[0].altName;d>20&&(d=d.substring(0,21)+"..."),document.getElementById("file_upload").textContent=d;let g=document.getElementById("export_button");g.style.display="flex",g.onclick=this.exportSong.bind(this),window.isLocalEdition||(document.getElementById("demo_song").style.display="none")},a=>{this.reloadSf(a)}),document.addEventListener("keydown",a=>{if(!a.ctrlKey)switch(a.key.toLowerCase()){case be.videoMode:this.seq&&this.seq.pause();let d=window.prompt(`Video mode!
|
| 362 |
Paste the link to the video source (leave blank to disable)
|
| 363 |
-
Note: the video will be available in console as 'video'`,"");if(d===null)return;let g=document.createElement("video");g.src=d,g.classList.add("secret_video"),A.parentElement.appendChild(g),g.play(),window.video=g,this.seq&&(g.currentTime=parseFloat(window.prompt("Video offset to sync to midi, in seconds.","0")),g.play(),this.seq.currentTime=0),document.addEventListener("keydown",I=>{I.key===" "&&(g.paused?g.play():g.pause())});break;case be.sustainPedal:this.renderer.showHoldPedal=!0,this.renderer.render(!1),this.keyboard.setHoldPedal(!0)}}),document.addEventListener("keyup",a=>{if(!a.ctrlKey)switch(a.key.toLowerCase()){case be.sustainPedal:this.renderer.showHoldPedal=!1,this.renderer.render(!1),this.keyboard.setHoldPedal(!1);break;default:break}}),this.renderer.render(!1,!0)}doDLSCheck(){if(window.isLocalEdition!==!0){let e=this.soundFont.slice(8,12);Ie(new U(e),4).toLowerCase()==="dls "&&ue(this.localeManager.getLocaleString("locale.convertDls.title"),[{type:"text",textContent:this.localeManager.getLocaleString("locale.convertDls.message")},{type:"button",textContent:this.localeManager.getLocaleString("locale.yes"),onClick:o=>{le(o.id),this.downloadDesfont()}},{type:"button",textContent:this.localeManager.getLocaleString("locale.no"),onClick:o=>{le(o.id)}}],99999999)}}async reloadSf(e){await this.synth.soundfontManager.reloadManager(e),this.soundFont=e,setTimeout(()=>{this.doDLSCheck()},3e3)}play(e){if(this.synth){if(this.seq){this.seq.loadNewSongList(e),this.seq.play(!0);return}this.seq=new To(e,this.synth),this.seq.onError=t=>{console.error(t),document.getElementById("title").textContent=t.message},this.seqUI.connectSequencer(this.seq),this.musicModeUI.connectSequencer(this.seq),this.renderer.connectSequencer(this.seq),this.settingsUI.addSequencer(this.seq),this.synthUI.connectSequencer(this.seq),this.seq.play(!0)}}async downloadDLSRMI(){let e=await this.seq.getMIDI(),t=Lt(this.soundFont),o=e.writeRMIDI(t.writeDLS(),t),n=new Blob([o.buffer],{type:"audio/rmid"});this.saveBlob(n,`${e.midiName}.rmi`)}downloadDesfont(){let e=Lt(this.soundFont),t=e.write(),o=new Blob([t.buffer],{type:"audio/soundfont"});this.saveBlob(o,`${e.soundFontInfo.INAM}.sf2`)}};mt.prototype.exportSong=Wa;mt.prototype._exportAudioData=sa;mt.prototype._doExportAudioData=na;mt.prototype.exportMidi=Aa;mt.prototype._exportSoundfont=Ha;mt.prototype._exportDLS=ja;mt.prototype._exportRMIDI=za;var zl=44100,Zl="violin.sf2",cn=document.getElementById("title"),_t=document.getElementById("midi_file_input"),jl=document.getElementById("sf_file_input"),_a=document.getElementById("demo_song"),Zn=document.getElementById("export_button"),ci=document.getElementsByClassName("loading")[0],Xe=document.getElementById("loading_message"),Xl=await(await fetch("package.json")).json();window.SPESSASYNTH_VERSION=Xl.version;var _l="spessasynth-db",di="soundFontStore";function _n(i){let e=indexedDB.open(_l,1);e.onsuccess=()=>{let t=e.result;i(t)},e.onupgradeneeded=t=>{t.target.result.createObjectStore(di,{keyPath:"id"})}}async function $l(){return await new Promise(i=>{_n(e=>{let n=e.transaction([di],"readonly").objectStore(di).get("buffer");n.onerror=s=>{console.error("Database error"),console.error(s),i(void 0)},n.onsuccess=async()=>{let s=n.result;if(!s){i(void 0);return}i(s.data)}})})}function gi(i,e=!0){let t=ci.getElementsByClassName("loading_icon")[0];t.innerHTML=i,t.style.animation=e?"none":""}async function $a(i){_n(e=>{let o=e.transaction([di],"readwrite").objectStore(di);try{let n=o.put({id:"buffer",data:i});n.onsuccess=()=>{F("SoundFont stored successfully")},n.onerror=s=>{console.error("Error saving soundfont",s)}}catch(n){ie("Failed saving soundfont:",n)}})}async function ec(i){let e=new jo(i);try{let n=window.AudioContext||window.webkitAudioContext;window.audioContextMain=new n({sampleRate:zl})}catch(n){throw gi($i(256)),Xe.textContent=e.getLocaleString("locale.synthInit.noWebAudio"),n}Xe.textContent=e.getLocaleString("locale.synthInit.loadingSoundfont");let t=await $l(),o=!0;if(t===void 0){ie("Failed to load from db, fetching online instead"),o=!1;let n=document.getElementById("progress_bar"),s=e.getLocaleString("locale.synthInit.loadingBundledSoundfont");Xe.textContent=s,t=await tc(`${Zl}`,A=>{Xe.textContent=`${s} ${A}%`}),n.style.width="0"}else F("Loaded the soundfont from the database succesfully");window.soundFontParser=t,o||(Xe.textContent=e.getLocaleString("locale.synthInit.savingSoundfont"),await $a(t)),window.audioContextMain.state!=="running"&&document.addEventListener("mousedown",()=>{window.audioContextMain.state!=="running"&&window.audioContextMain.resume().then()}),Xe.textContent=e.getLocaleString("locale.synthInit.startingSynthesizer"),window.manager=new mt(audioContextMain,soundFontParser,e),window.manager.sfError=n=>{gi($i(256)),o?(ie("Invalid soundfont in the database. Resetting."),_n(s=>{let r=s.transaction([di],"readwrite").objectStore(di).delete("buffer");r.onsuccess=()=>{location.reload()}})):cn.innerHTML=`Error parsing soundfont: <pre style='font-family: monospace; font-weight: bold;'>${n}</pre>`,Xe.innerHTML=`Error parsing soundfont: <pre style='font-family: monospace; font-weight: bold;'>${n}</pre>`},await manager.ready,manager.synth.voiceCap=el,_t.files[0]?await jn(_t.files):(_t.onclick=void 0,_t.onchange=()=>{_t.files[0]&&jn(_t.files).then()}),gi(xn(256)),Xe.textContent=e.getLocaleString("locale.synthInit.done")}async function tc(i,e){let t=await fetch(i);if(!t.ok)throw cn.innerText="Error downloading soundfont!",t;let o=t.headers.get("content-length"),n=await(await t.body).getReader(),s=!1,A=new Uint8Array(parseInt(o)),l=0;do{let r=await n.read();r.value&&(A.set(r.value,l),l+=r.value.length),s=r.done;let a=Math.round(l/o*100);e(a)}while(!s);return A.buffer}async function jn(i){_a.style.display="none";let e;i[0].name.length>20?e=i[0].name.substring(0,21)+"...":e=i[0].name,i.length>1&&(e+=` and ${i.length-1} others`),document.getElementById("file_upload").innerText=e,document.getElementById("file_upload").title=i[0].name;let t=[];for(let o of i)t.push({binary:await o.arrayBuffer(),altName:o.name});manager.synth.setLogLevel(!1,!1,!1,!1),manager.seq?manager.seq.loadNewSongList(t):manager.play(t),Zn.style.display="flex",Zn.onclick=window.manager.exportSong.bind(window.manager)}function ic(i){localStorage.setItem("spessasynth-settings",JSON.stringify(i)),F("saved as",i)}var el=350,Xa=localStorage.getItem("spessasynth-voice-cap");Xa&&(el=parseInt(Xa));window.rememberVoiceCap=i=>{localStorage.setItem("spessasynth-voice-cap",i.toString()),window.location.reload()};window.saveSettings=ic;var so=JSON.parse(localStorage.getItem("spessasynth-settings"));so!==null&&(window.savedSettings=new Promise(i=>{i(so)}));var Xn;so&&so.interface&&so.interface.language?Xn=(await savedSettings).interface.language||navigator.language.split("-")[0].toLowerCase():Xn=navigator.language.split("-")[0].toLowerCase();_t.value="";_t.focus();Zn.style.display="none";document.getElementById("sf_upload").style.display="none";document.getElementById("file_upload").style.display="none";async function oc(i){cn.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.genericLoading");let e=await fetch("https://spessasus.github.io/spessasynth-demo-songs/demo_songs/"+i);e.name=i,await jn([e])}ec(Xn).then(()=>{document.getElementById("sf_upload").style.display="flex",document.getElementById("file_upload").style.display="flex",ci.classList.add("done"),document.documentElement.classList.add("no_scroll"),document.body.classList.add("no_scroll"),setTimeout(()=>{ci.style.display="none",document.body.classList.remove("no_scroll"),document.documentElement.classList.remove("no_scroll"),je&&window.chrome&&ue(window.manager.localeManager.getLocaleString("locale.warnings.warning"),[{type:"text",textContent:window.manager.localeManager.getLocaleString("locale.warnings.chromeMobile")}],7)},1e3),jl.onchange=i=>{if(!i.target.files[0])return;let e=i.target.files[0];window.manager.seq&&window.manager.seq.pause(),document.getElementById("sf_upload").firstElementChild.innerText=e.name,ci.style.display="",setTimeout(async()=>{ci.classList.remove("done"),gi(AA(256),!1),Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.loadingSoundfont");let t=performance.now()/1e3,o;try{o=await e.arrayBuffer(),window.soundFontParser=o}catch(s){throw Xe.textContent=window.manager.localeManager.getLocaleString("locale.warnings.outOfMemory"),gi($i(256)),ue(manager.localeManager.getLocaleString("locale.warnings.warning"),[{type:"text",textContent:window.manager.localeManager.getLocaleString("locale.warnings.outOfMemory")}]),s}window.manager.sfError=s=>{Xe.innerHTML=`Error parsing soundfont: <pre style='font-family: monospace; font-weight: bold;'>${s}</pre>`,gi($i(256)),console.error(s)},Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.startingSynthesizer"),await window.manager.reloadSf(o),window.manager.seq&&(window.manager.seq.currentTime-=.1),Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.savingSoundfont"),await $a(o);let n=performance.now()/1e3-t;await new Promise(s=>setTimeout(s,1e3-n)),gi(xn(256)),Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.done"),ci.classList.add("done"),document.documentElement.classList.add("no_scroll"),document.body.classList.add("no_scroll"),setTimeout(()=>{ci.style.display="none",document.body.classList.remove("no_scroll"),document.documentElement.classList.remove("no_scroll")},1e3)},75)},_a.onclick=async()=>{let i=[{type:"button",textContent:"Bundled SoundFont Credits",onClick:()=>{window.open("https://schristiancollins.com/generaluser.php")}}];cn.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.genericLoading");let e=await(await fetch("https://spessasus.github.io/spessasynth-demo-songs/demo_song_list.json")).text(),t=JSON.parse(e);for(let o of t)i.push({type:"button",textContent:o.name,onClick:n=>{le(n.id),ue(window.manager.localeManager.getLocaleString("locale.credits"),[{type:"text",textContent:o.credits.replace(`
|
| 364 |
`,`\r
|
| 365 |
\r
|
| 366 |
`),attributes:{style:"white-space: pre-line;"}},{type:"button",textContent:"Ok",onClick:s=>{le(s.id)}}],999999,!0,void 0,void 0,async()=>{await oc(o.fileName)})}});ue(window.manager.localeManager.getLocaleString("locale.demoSongButton"),i,999999,!0,void 0)}});
|
|
|
|
| 360 |
`+c.extraStackTrace()),(p=E).replace(/__Z[\w\d_]+/g,function(Q){var R,W=R=Q;return Q===W?Q:Q+" ["+W+"]"})}function Ft(p,E){return p%E>0&&(p+=E-p%E),p}function mi(p){c.buffer=o=p}function ei(){c.HEAP8=n=new Int8Array(o),c.HEAP16=A=new Int16Array(o),c.HEAP32=r=new Int32Array(o),c.HEAPU8=s=new Uint8Array(o),c.HEAPU16=l=new Uint16Array(o),c.HEAPU32=a=new Uint32Array(o),c.HEAPF32=d=new Float32Array(o),c.HEAPF64=g=new Float64Array(o)}function Gi(){var p=c.usingWasm?65536:16777216,E=2147483648-p;if(r[D>>2]>E)return!1;var Q=ve;for(ve=Math.max(ve,16777216);ve<r[D>>2];)ve=ve<=536870912?Ft(2*ve,p):Math.min(Ft((3*ve+2147483648)/4,p),E);var R=c.reallocBuffer(ve);return R&&R.byteLength==ve?(mi(R),ei(),!0):(ve=Q,!1)}I=h=C=f=y=S=D=0,m=!1,c.reallocBuffer||(c.reallocBuffer=function(p){try{if(ArrayBuffer.transfer)E=ArrayBuffer.transfer(o,p);else{var E,Q=n;E=new ArrayBuffer(p),new Int8Array(E).set(Q)}}catch{return!1}return!!rl(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 Ci=c.TOTAL_STACK||5242880,ve=c.TOTAL_MEMORY||16777216;function co(){return ve}function Nt(p){for(;p.length>0;){var E=p.shift();if(typeof E=="function"){E();continue}var Q=E.func;typeof Q=="number"?E.arg===void 0?c.dynCall_v(Q):c.dynCall_vi(Q,E.arg):Q(E.arg===void 0?null:E.arg)}}ve<Ci&&Y("TOTAL_MEMORY should be larger than TOTAL_STACK, was "+ve+"! (TOTAL_STACK="+Ci+")"),c.buffer?o=c.buffer:(typeof WebAssembly=="object"&&typeof WebAssembly.Memory=="function"?(c.wasmMemory=new WebAssembly.Memory({initial:ve/65536}),o=c.wasmMemory.buffer):o=new ArrayBuffer(ve),c.buffer=o),ei();var Ti=[],pn=[],ts=[],is=[],os=[],mn=!1,tl=!1;function il(p){Ti.unshift(p)}function nc(p){pn.unshift(p)}function sc(p){ts.unshift(p)}function Ac(p){is.unshift(p)}function ol(p){os.unshift(p)}function rc(p,E,Q){var R,W;P("writeStringToMemory is deprecated and should not be called! Use stringToUTF8() instead!"),Q&&(R=n[W=E+Ye(p)]),xi(p,E,1/0),Q&&(n[W]=R)}function ac(p,E,Q){return p>=0?p:E<=32?2*Math.abs(1<<E-1)+p:Math.pow(2,E)+p}function lc(p,E,Q){if(p<=0)return p;var R=E<=32?Math.abs(1<<E-1):Math.pow(2,E-1);return p>=R&&(E<=32||p>R)&&(p=-2*R+p),p}var nl=Math.abs,sl=Math.ceil,ns=Math.floor,Al=Math.min,ti=0,Cn=null,Ui=null;function cc(p){return p}c.preloadedImages={},c.preloadedAudios={};var ss="data:application/octet-stream;base64,";function go(p){return String.prototype.startsWith?p.startsWith(ss):p.indexOf(ss)===0}(function(){var E="main.wast",Q="main.wasm",R="main.temp.asm.js";go(E)||(E=$(E)),go(Q)||(Q=$(Q)),go(R)||(R=$(R));var W={global:null,env:null,asm2wasm:Ae,parent:c},ae=null;function de(Be){return Be}function _(){try{if(c.wasmBinary)return new Uint8Array(c.wasmBinary);if(c.readBinary)return c.readBinary(Q);throw"both async and sync fetching of the wasm failed"}catch(Be){Mt(Be)}}c.asmPreload=c.asm;var Ge=c.reallocBuffer,ye=function(Be){Be=Ft(Be,c.usingWasm?65536:16777216);var re=c.buffer.byteLength;if(c.usingWasm)try{var Oe=c.wasmMemory.grow((Be-re)/65536);return Oe!==-1?c.buffer=c.wasmMemory.buffer:null}catch{return null}};c.reallocBuffer=function(Be){return Se==="asmjs"?Ge(Be):ye(Be)};var Se="";c.asm=function(Be,re,Oe){var At;if(!(re=At=re).table){var rt,at=c.wasmTableSize;at===void 0&&(at=1024);var ii=c.wasmMaxTableSize;typeof WebAssembly=="object"&&typeof WebAssembly.Table=="function"?ii!==void 0?re.table=new WebAssembly.Table({initial:at,maximum:ii,element:"anyfunc"}):re.table=new WebAssembly.Table({initial:at,element:"anyfunc"}):re.table=Array(at),c.wasmTable=re.table}return re.memoryBase||(re.memoryBase=c.STATIC_BASE),re.tableBase||(re.tableBase=0),rt=function(Ji,Ei,Qn){if(typeof WebAssembly!="object")return Y("no native wasm support detected"),!1;if(!(c.wasmMemory instanceof WebAssembly.Memory))return Y("no native wasm Memory in use"),!1;function uo(Bt,ft){if((ae=Bt.exports).memory){var qi,yn,as;qi=ae.memory,yn=c.buffer,qi.byteLength<yn.byteLength&&Y("the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here"),as=new Int8Array(yn),new Int8Array(qi).set(as),mi(qi),ei()}c.asm=ae,c.usingWasm=!0,function(mc){if(ti--,c.monitorRunDependencies&&c.monitorRunDependencies(ti),ti==0&&(Cn!==null&&(clearInterval(Cn),Cn=null),Ui)){var al=Ui;Ui=null,al()}}("wasm-instantiate")}if(Ei.memory=c.wasmMemory,W.global={NaN:NaN,Infinity:1/0},W["global.Math"]=Math,W.env=Ei,ti++,c.monitorRunDependencies&&c.monitorRunDependencies(ti),c.instantiateWasm)try{return c.instantiateWasm(W,uo)}catch(Bt){return Y("Module.instantiateWasm callback failed with error: "+Bt),!1}function Bi(Bt){uo(Bt.instance,Bt.module)}function rs(Bt){(!c.wasmBinary&&(b||q)&&typeof fetch=="function"?fetch(Q,{credentials:"same-origin"}).then(function(ft){if(!ft.ok)throw"failed to load wasm binary file at '"+Q+"'";return ft.arrayBuffer()}).catch(function(){return _()}):new Promise(function(ft,qi){ft(_())})).then(function(ft){return WebAssembly.instantiate(ft,W)}).then(Bt).catch(function(ft){Y("failed to asynchronously prepare wasm: "+ft),Mt(ft)})}return c.wasmBinary||typeof WebAssembly.instantiateStreaming!="function"||go(Q)||typeof fetch!="function"?rs(Bi):WebAssembly.instantiateStreaming(fetch(Q,{credentials:"same-origin"}),W).then(Bi).catch(function(Bt){Y("wasm streaming compile failed: "+Bt),Y("falling back to ArrayBuffer instantiation"),rs(Bi)}),{}}(Be,re,Oe),$e(rt,"no binaryen method succeeded."),rt},c.asm})(),h=(I=1024)+4816,pn.push(),c.STATIC_BASE=I,c.STATIC_BUMP=4816;var tt=h;function gc(p){n[tt]=n[p],n[tt+1]=n[p+1],n[tt+2]=n[p+2],n[tt+3]=n[p+3]}function dc(p){n[tt]=n[p],n[tt+1]=n[p+1],n[tt+2]=n[p+2],n[tt+3]=n[p+3],n[tt+4]=n[p+4],n[tt+5]=n[p+5],n[tt+6]=n[p+6],n[tt+7]=n[p+7]}function hc(p,E,Q){var R=Q>0?Q:Ye(p)+1,W=Array(R),ae=pi(p,W,0,W.length);return E&&(W.length=ae),W}function Ic(p){for(var E=[],Q=0;Q<p.length;Q++){var R=p[Q];R>255&&(R&=255),E.push(String.fromCharCode(R))}return E.join("")}h+=16,D=te(4),y=(C=f=K(h))+Ci,S=K(y),r[D>>2]=S,m=!0,c.wasmTableSize=4,c.wasmMaxTableSize=4,c.asmGlobalArg={},c.asmLibraryArg={abort:Mt,assert:$e,enlargeMemory:Gi,getTotalMemory:co,abortOnCannotGrowMemory:function(){Mt("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+ve+", (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,R){var W=Bn();try{return c.dynCall_iii(E,Q,R)}catch(ae){if(En(W),typeof ae!="number"&&ae!=="longjmp")throw ae;c.setThrew(1,0)}},___assert_fail:function(E,Q,R,W){Mt("Assertion failed: "+Ut(E)+", at: "+[Q?Ut(Q):"unknown filename",R,W?Ut(W):"unknown function"])},___setErrNo:function(E){return c.___errno_location&&(r[c.___errno_location()>>2]=E),E},_abort:function(){c.abort()},_emscripten_memcpy_big:function(E,Q,R){return s.set(s.subarray(Q,Q+R),E),E},_llvm_floor_f64:ns,DYNAMICTOP_PTR:D,tempDoublePtr:tt,ABORT:Ee,STACKTOP:f,STACK_MAX:y};var As=c.asm(c.asmGlobalArg,c.asmLibraryArg,o);c.asm=As,c.___errno_location=function(){return c.asm.___errno_location.apply(null,arguments)};var rl=c._emscripten_replace_memory=function(){return c.asm._emscripten_replace_memory.apply(null,arguments)};c._free=function(){return c.asm._free.apply(null,arguments)};var ho=c._malloc=function(){return c.asm._malloc.apply(null,arguments)};c._memcpy=function(){return c.asm._memcpy.apply(null,arguments)},c._memset=function(){return c.asm._memset.apply(null,arguments)},c._sbrk=function(){return c.asm._sbrk.apply(null,arguments)},c._stb_vorbis_js_channels=function(){return c.asm._stb_vorbis_js_channels.apply(null,arguments)},c._stb_vorbis_js_close=function(){return c.asm._stb_vorbis_js_close.apply(null,arguments)},c._stb_vorbis_js_decode=function(){return c.asm._stb_vorbis_js_decode.apply(null,arguments)},c._stb_vorbis_js_open=function(){return c.asm._stb_vorbis_js_open.apply(null,arguments)},c._stb_vorbis_js_sample_rate=function(){return c.asm._stb_vorbis_js_sample_rate.apply(null,arguments)},c.establishStackSpace=function(){return c.asm.establishStackSpace.apply(null,arguments)},c.getTempRet0=function(){return c.asm.getTempRet0.apply(null,arguments)},c.runPostSets=function(){return c.asm.runPostSets.apply(null,arguments)},c.setTempRet0=function(){return c.asm.setTempRet0.apply(null,arguments)},c.setThrew=function(){return c.asm.setThrew.apply(null,arguments)};var Io=c.stackAlloc=function(){return c.asm.stackAlloc.apply(null,arguments)},En=c.stackRestore=function(){return c.asm.stackRestore.apply(null,arguments)},Bn=c.stackSave=function(){return c.asm.stackSave.apply(null,arguments)};function Ni(p){this.name="ExitStatus",this.message="Program terminated with exit("+p+")",this.status=p}function fn(p){p=p||c.arguments,!(ti>0)&&(function(){if(c.preRun)for(typeof c.preRun=="function"&&(c.preRun=[c.preRun]);c.preRun.length;)il(c.preRun.shift());Nt(Ti)}(),!(ti>0)&&(c.calledRun||(c.setStatus?(c.setStatus("Running..."),setTimeout(function(){setTimeout(function(){c.setStatus("")},1),E()},1)):E())));function E(){!c.calledRun&&(c.calledRun=!0,Ee||(mn||(mn=!0,Nt(pn)),Nt(ts),c.onRuntimeInitialized&&c.onRuntimeInitialized(),function(){if(c.postRun)for(typeof c.postRun=="function"&&(c.postRun=[c.postRun]);c.postRun.length;)ol(c.postRun.shift());Nt(os)}()))}}function uc(p,E){(!E||!c.noExitRuntime||p!==0)&&(c.noExitRuntime||(Ee=!0,Et=p,f=w,Nt(is),tl=!0,c.onExit&&c.onExit(p)),c.quit(p,new Ni(p)))}function Mt(p){throw c.onAbort&&c.onAbort(p),p!==void 0?(j(p),Y(p),p=JSON.stringify(p)):p="",Ee=!0,Et=1,"abort("+p+"). Build with -s ASSERTIONS=1 for more info."}if(c.dynCall_iii=function(){return c.asm.dynCall_iii.apply(null,arguments)},c.asm=As,c.ccall=Ii,c.cwrap=function(E,Q,R,W){var ae=(R=R||[]).every(function(de){return de==="number"});return Q!=="string"&&ae&&!W?Gt(E):function(){return Ii(E,Q,R,arguments,W)}},Ni.prototype=Error(),Ni.prototype.constructor=Ni,Ui=function p(){c.calledRun||fn(),c.calledRun||(Ui=p)},c.run=fn,c.abort=Mt,c.preInit)for(typeof c.preInit=="function"&&(c.preInit=[c.preInit]);c.preInit.length>0;)c.preInit.pop()();c.noExitRuntime=!0,fn(),c.onRuntimeInitialized=()=>{Ja=!0,qa()},Xt.decode=function(p){return function(Q){if(!Ja)throw Error("SF3 decoder has not been initialized yet. Did you await synth.isReady?");var R={};function W(Ei){return new Int32Array(c.HEAPU8.buffer,Ei,1)[0]}function ae(Ei,Qn){var uo=new ArrayBuffer(Qn*Float32Array.BYTES_PER_ELEMENT),Bi=new Float32Array(uo);return Bi.set(new Float32Array(c.HEAPU8.buffer,Ei,Qn)),Bi}R.open=c.cwrap("stb_vorbis_js_open","number",[]),R.close=c.cwrap("stb_vorbis_js_close","void",["number"]),R.channels=c.cwrap("stb_vorbis_js_channels","number",["number"]),R.sampleRate=c.cwrap("stb_vorbis_js_sample_rate","number",["number"]),R.decode=c.cwrap("stb_vorbis_js_decode","number",["number","number","number","number","number"]);var de,_,Ge,ye,Se=R.open(),Be=(de=Q,_=Q.byteLength,Ge=c._malloc(_),(ye=new Uint8Array(c.HEAPU8.buffer,Ge,_)).set(new Uint8Array(de,0,_)),ye),re=c._malloc(4),Oe=c._malloc(4),At=R.decode(Se,Be.byteOffset,Be.byteLength,re,Oe);if(c._free(Be.byteOffset),At<0)throw R.close(Se),c._free(re),Error("stbvorbis decode failed: "+At);for(var rt=R.channels(Se),at=Array(rt),ii=new Int32Array(c.HEAPU32.buffer,W(re),rt),lt=0;lt<rt;lt++)at[lt]=ae(ii[lt],At),c._free(ii[lt]);var Ji=R.sampleRate(Se);return R.close(Se),c._free(W(re)),c._free(re),{data:at,sampleRate:Ji,eof:!0,error:null}}(p)}})();var Kn=class extends Wt{constructor(e,t,o,n,s,A,l,r,a,d,g,I,h){super(e,A,l,r,a,d,n-t/2,s-t/2),this.sampleName=e,this.sampleStartIndex=t,this.sampleEndIndex=o,this.isSampleLoaded=!1,this.sampleID=I,this.sampleLength=this.sampleEndIndex-this.sampleStartIndex,this.sampleDataArray=g,this.sampleData=new Float32Array(0),this.isCompressed&&(this.sampleLoopStartIndex+=this.sampleStartIndex/2,this.sampleLoopEndIndex+=this.sampleStartIndex/2,this.sampleLength=99999999),this.isDataRaw=h}getRawData(){let e=this.sampleDataArray;if(this.isCompressed){if(this.compressedData)return this.compressedData;let t=e.currentIndex;return e.slice(this.sampleStartIndex/2+t,this.sampleEndIndex/2+t)}else{this.isDataRaw||super.getRawData();let t=e.currentIndex;return e.slice(t+this.sampleStartIndex,t+this.sampleEndIndex)}}decodeVorbis(){if(this.sampleLength<1)return;let e=this.sampleDataArray,t=e.currentIndex,o=e.slice(this.sampleStartIndex/2+t,this.sampleEndIndex/2+t);this.sampleData=new Float32Array(0);try{let n=Xt.decode(o.buffer);this.sampleData=n.data[0],this.sampleData===void 0&&ie(`Error decoding sample ${this.sampleName}: Vorbis decode returned undefined.`)}catch(n){ie(`Error decoding sample ${this.sampleName}: ${n}`),this.sampleData=new Float32Array(this.sampleLoopEndIndex+1)}}getAudioData(){return this.isSampleLoaded?this.sampleData:this.sampleLength<1?(ie(`Invalid sample ${this.sampleName}! Invalid length: ${this.sampleLength}`),new Float32Array(1)):this.isCompressed?(this.decodeVorbis(),this.isSampleLoaded=!0,this.sampleData):this.isDataRaw?this.loadUncompressedData():this.getUncompressedReadyData()}loadUncompressedData(){if(this.isCompressed)return ie("Trying to load a compressed sample via loadUncompressedData()... aborting!"),new Float32Array(0);let e=new Float32Array(this.sampleLength/2),t=this.sampleDataArray.currentIndex,o=new Int16Array(this.sampleDataArray.slice(t+this.sampleStartIndex,t+this.sampleEndIndex).buffer);for(let n=0;n<o.length;n++)e[n]=o[n]/32768;return this.sampleData=e,this.isSampleLoaded=!0,e}getUncompressedReadyData(){let e=this.sampleDataArray.slice(this.sampleStartIndex/2,this.sampleEndIndex/2);return this.sampleData=e,this.isSampleLoaded=!0,e}};function Ka(i,e,t=!0){let o=[],n=0;for(;i.chunkData.length>i.chunkData.currentIndex;){let s=Hl(n,i.chunkData,e,t);o.push(s),n++}return o.length>1&&o.pop(),o}function Hl(i,e,t,o){let n=Ie(e,20),s=N(e,4)*2,A=N(e,4)*2,l=N(e,4),r=N(e,4),a=N(e,4),d=e[e.currentIndex++];d===255&&(d=60);let g=Ss(e[e.currentIndex++]),I=N(e,2),h=N(e,2);return new Kn(n,s,A,l,r,a,d,g,I,h,t,i,o)}var Vn=class extends J{constructor(e){super();let t=e.currentIndex;this.generatorType=e[t+1]<<8|e[t],this.generatorValue=Kt(e[t+2],e[t+3]),e.currentIndex+=4}};function Yn(i){let e=[];for(;i.chunkData.length>i.chunkData.currentIndex;)e.push(new Vn(i.chunkData));return e.length>1&&e.pop(),e}var Pn=class extends Pe{constructor(e){super(),this.generatorZoneStartIndex=N(e,2),this.modulatorZoneStartIndex=N(e,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(e,t){this.modulatorZoneSize=e,this.generatorZoneSize=t}getGenerators(e){for(let t=this.generatorZoneStartIndex;t<this.generatorZoneStartIndex+this.generatorZoneSize;t++)this.generators.push(e[t])}getModulators(e){for(let t=this.modulatorZoneStartIndex;t<this.modulatorZoneStartIndex+this.modulatorZoneSize;t++)this.modulators.push(e[t])}getSample(e){let t=this.generators.find(o=>o.generatorType===u.sampleID);t&&(this.sample=e[t.generatorValue],this.isGlobal=!1,this.sample.useCount++)}getKeyRange(){let e=this.generators.find(t=>t.generatorType===u.keyRange);e&&(this.keyRange.min=e.generatorValue&127,this.keyRange.max=e.generatorValue>>8&127)}getVelRange(){let e=this.generators.find(t=>t.generatorType===u.velRange);e&&(this.velRange.min=e.generatorValue&127,this.velRange.max=e.generatorValue>>8&127)}};function Va(i,e,t,o){let n=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let s=new Pn(i.chunkData);if(n.length>0){let A=s.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,l=s.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(A,l),n[n.length-1].getGenerators(e),n[n.length-1].getModulators(t),n[n.length-1].getSample(o),n[n.length-1].getKeyRange(),n[n.length-1].getVelRange()}n.push(s)}return n.length>1&&n.pop(),n}var On=class extends Ht{constructor(e){super(),this.generatorZoneStartIndex=N(e,2),this.modulatorZoneStartIndex=N(e,2),this.modulatorZoneSize=0,this.generatorZoneSize=0,this.isGlobal=!0}setZoneSize(e,t){this.modulatorZoneSize=e,this.generatorZoneSize=t}getGenerators(e){for(let t=this.generatorZoneStartIndex;t<this.generatorZoneStartIndex+this.generatorZoneSize;t++)this.generators.push(e[t])}getModulators(e){for(let t=this.modulatorZoneStartIndex;t<this.modulatorZoneStartIndex+this.modulatorZoneSize;t++)this.modulators.push(e[t])}getInstrument(e){let t=this.generators.find(o=>o.generatorType===u.instrument);t&&(this.instrument=e[t.generatorValue],this.instrument.addUseCount(),this.isGlobal=!1)}getKeyRange(){let e=this.generators.find(t=>t.generatorType===u.keyRange);e&&(this.keyRange.min=e.generatorValue&127,this.keyRange.max=e.generatorValue>>8&127)}getVelRange(){let e=this.generators.find(t=>t.generatorType===u.velRange);e&&(this.velRange.min=e.generatorValue&127,this.velRange.max=e.generatorValue>>8&127)}};function Ya(i,e,t,o){let n=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let s=new On(i.chunkData);if(n.length>0){let A=s.modulatorZoneStartIndex-n[n.length-1].modulatorZoneStartIndex,l=s.generatorZoneStartIndex-n[n.length-1].generatorZoneStartIndex;n[n.length-1].setZoneSize(A,l),n[n.length-1].getGenerators(e),n[n.length-1].getModulators(t),n[n.length-1].getInstrument(o),n[n.length-1].getKeyRange(),n[n.length-1].getVelRange()}n.push(s)}return n.length>1&&n.pop(),n}var Hn=class extends Zt{constructor(e,t){super(t),this.presetName=Ie(e.chunkData,20).trim().replace(/\d{3}:\d{3}/,""),this.program=N(e.chunkData,2),this.bank=N(e.chunkData,2),this.presetZoneStartIndex=N(e.chunkData,2),this.library=N(e.chunkData,4),this.genre=N(e.chunkData,4),this.morphology=N(e.chunkData,4),this.presetZonesAmount=0}getPresetZones(e,t){this.presetZonesAmount=e;for(let o=this.presetZoneStartIndex;o<this.presetZonesAmount+this.presetZoneStartIndex;o++)this.presetZones.push(t[o])}};function Pa(i,e,t){let o=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let n=new Hn(i,t);if(o.length>0){let s=n.presetZoneStartIndex-o[o.length-1].presetZoneStartIndex;o[o.length-1].getPresetZones(s,e)}o.push(n)}return o.length>1&&o.pop(),o}var Wn=class extends zt{constructor(e){super(),this.instrumentName=Ie(e.chunkData,20).trim(),this.instrumentZoneIndex=N(e.chunkData,2),this.instrumentZonesAmount=0}getInstrumentZones(e,t){this.instrumentZonesAmount=e;for(let o=this.instrumentZoneIndex;o<this.instrumentZonesAmount+this.instrumentZoneIndex;o++)this.instrumentZones.push(t[o])}};function Oa(i,e){let t=[];for(;i.chunkData.length>i.chunkData.currentIndex;){let o=new Wn(i);if(t.length>0){let n=o.instrumentZoneIndex-t[t.length-1].instrumentZoneIndex;t[t.length-1].getInstrumentZones(n,e)}t.push(o)}return t.length>1&&t.pop(),t}var zn=class extends oe{constructor(e){let t=N(e,2),o=N(e,2),n=Kt(e[e.currentIndex++],e[e.currentIndex++]),s=N(e,2),A=N(e,2);super(t,s,o,n,A)}};function rn(i){let e=[];for(;i.chunkData.length>i.chunkData.currentIndex;)e.push(new zn(i.chunkData));return e}var an=class extends jt{constructor(e,t=!0){super(),t&&console.warn("Using the constructor directly is deprecated. Use loadSoundFont instead."),this.dataArray=new U(e),He("%cParsing SoundFont...",B.info),this.dataArray||(ne(),this.parsingError("No data provided!"));let o=he(this.dataArray,!1);this.verifyHeader(o,"riff");let n=Ie(this.dataArray,4).toLowerCase();if(n!=="sfbk"&&n!=="sfpk")throw ne(),new SyntaxError(`Invalid soundFont! Expected "sfbk" or "sfpk" got "${n}"`);let s=n==="sfpk",A=he(this.dataArray);for(this.verifyHeader(A,"list"),Ie(A.chunkData,4);A.chunkData.length>A.chunkData.currentIndex;){let O=he(A.chunkData),T;switch(O.header.toLowerCase()){case"ifil":case"iver":T=`${N(O.chunkData,2)}.${N(O.chunkData,2)}`,this.soundFontInfo[O.header]=T;break;case"icmt":T=Ie(O.chunkData,O.chunkData.length,void 0,!1),this.soundFontInfo[O.header]=T;break;case"dmod":let H=rn(O);H.pop(),T=`Modulators: ${H.length}`;let $=this.defaultModulators;this.defaultModulators=H,this.defaultModulators.push(...$.filter(j=>!this.defaultModulators.find(Y=>oe.isIdentical(j,Y)))),this.soundFontInfo[O.header]=O.chunkData;break;default:T=Ie(O.chunkData,O.chunkData.length),this.soundFontInfo[O.header]=T}F(`%c"${O.header}": %c"${T}"`,B.info,B.recognized)}let l=he(this.dataArray,!1);this.verifyHeader(l,"list"),this.verifyText(Ie(this.dataArray,4),"sdta"),F("%cVerifying smpl chunk...",B.warn);let r=he(this.dataArray,!1);this.verifyHeader(r,"smpl");let a;if(s){F("%cSF2Pack detected, attempting to decode the smpl chunk...",B.info);try{a=Xt.decode(this.dataArray.buffer.slice(this.dataArray.currentIndex,this.dataArray.currentIndex+l.size-12)).data[0]}catch(O){throw ne(),new Error(`SF2Pack Ogg Vorbis decode error: ${O}`)}F(`%cDecoded the smpl chunk! Length: %c${a.length}`,B.info,B.value)}else a=this.dataArray,this.sampleDataStartIndex=this.dataArray.currentIndex;F(`%cSkipping sample chunk, length: %c${l.size-12}`,B.info,B.value),this.dataArray.currentIndex+=l.size-12,F("%cLoading preset data chunk...",B.warn);let d=he(this.dataArray);this.verifyHeader(d,"list"),Ie(d.chunkData,4);let g=he(d.chunkData);this.verifyHeader(g,"phdr");let I=he(d.chunkData);this.verifyHeader(I,"pbag");let h=he(d.chunkData);this.verifyHeader(h,"pmod");let m=he(d.chunkData);this.verifyHeader(m,"pgen");let C=he(d.chunkData);this.verifyHeader(C,"inst");let f=he(d.chunkData);this.verifyHeader(f,"ibag");let y=he(d.chunkData);this.verifyHeader(y,"imod");let S=he(d.chunkData);this.verifyHeader(S,"igen");let D=he(d.chunkData);this.verifyHeader(D,"shdr"),this.dataArray.currentIndex=this.sampleDataStartIndex,this.samples.push(...Ka(D,a,!s));let k=Yn(S),w=rn(y),c=Va(f,k,w,this.samples);this.instruments=Oa(C,c);let M=Yn(m),b=rn(h),q=Ya(I,M,b,this.instruments);this.presets.push(...Pa(g,q,this)),this.presets.sort((O,T)=>O.program-T.program+(O.bank-T.bank)),this._parseInternal(),F(`%cParsing finished! %c"${this.soundFontInfo.INAM}"%c has %c${this.presets.length} %cpresets,
|
| 361 |
%c${this.instruments.length}%c instruments and %c${this.samples.length}%c samples.`,B.info,B.recognized,B.info,B.recognized,B.info,B.recognized,B.info,B.recognized,B.info),ne(),s&&delete this.dataArray}verifyHeader(e,t){e.header.toLowerCase()!==t.toLowerCase()&&(ne(),this.parsingError(`Invalid chunk header! Expected "${t.toLowerCase()}" got "${e.header.toLowerCase()}"`))}verifyText(e,t){e.toLowerCase()!==t.toLowerCase()&&(ne(),this.parsingError(`Invalid FourCC: Expected "${t.toLowerCase()}" got "${e.toLowerCase()}"\``))}destroySoundBank(){super.destroySoundBank(),delete this.dataArray}};function Lt(i){let e=i.slice(8,12),t=new U(e);return Ie(t,4,void 0,!1).toLowerCase()==="dls "?new xt(i):new an(i,!1)}async function Ha(){let i="locale.exportAudio.formats.formats.soundfont.options.";ue(this.localeManager.getLocaleString(i+"title"),[{type:"toggle",translatePathTitle:i+"trim",attributes:{"trim-toggle":"1",checked:"checked"}},{type:"toggle",translatePathTitle:i+"compress",attributes:{"compress-toggle":"1"}},{type:"range",translatePathTitle:i+"quality",attributes:{min:"0",max:"10",value:"5"}},{type:"button",textContent:this.localeManager.getLocaleString(i+"confirm"),onClick:async e=>{let t=e.div.querySelector("input[trim-toggle='1']").checked,o=e.div.querySelector("input[compress-toggle='1']").checked,n=parseInt(e.div.querySelector("input[type='range']").value)/10;le(e.id),He("%cExporting minified soundfont...",B.info);let s=await this.seq.getMIDI(),A=Lt(s.embeddedSoundFont||this.soundFont);s.applySnapshotToMIDI(await this.synth.getSynthesizerSnapshot()),t&&A.trimSoundBank(s);let l=A.write({compress:o,compressionQuality:n,compressionFunction:await this.getVorbisEncodeFunction()}),r=new Blob([l.buffer],{type:"audio/soundfont"}),a=A.soundFontInfo.ifil.split(".")[0]==="3"?"sf3":"sf2";this.saveBlob(r,`${A.soundFontInfo.INAM||"unnamed"}.${a}`),ne()}}],99999999,!0,this.localeManager)}async function Wa(){let i="locale.exportAudio.formats.";ue(this.localeManager.getLocaleString(i+"title"),[{type:"button",translatePathTitle:i+"formats.wav.button",onClick:e=>{le(e.id),this._exportAudioData()}},{type:"button",translatePathTitle:i+"formats.midi.button",onClick:e=>{le(e.id),this.exportMidi()}},{type:"button",translatePathTitle:i+"formats.soundfont.button",onClick:e=>{le(e.id);try{this._exportSoundfont()}catch{ue("Warning",[{type:"text",textContent:this.localeManager.getLocaleString("locale.warnings.outOfMemory")}])}}},{type:"button",translatePathTitle:i+"formats.dls.button",onClick:e=>{le(e.id);try{this._exportDLS()}catch{ue("Warning",[{type:"text",textContent:this.localeManager.getLocaleString("locale.warnings.outOfMemory")}])}}},{type:"button",translatePathTitle:i+"formats.rmidi.button",onClick:e=>{le(e.id);try{this._exportRMIDI()}catch{ue("Warning",[{type:"text",textContent:this.localeManager.getLocaleString("locale.warnings.outOfMemory")}])}}}],999999,!0,this.localeManager,{display:"flex",flexWrap:"wrap",justifyContent:"center"})}async function za(){let i=(g,I,h)=>this.seq.midiData.RMIDInfo?.[g]===void 0?I:h.decode(this.seq.midiData.RMIDInfo?.[g]).replace(/\0$/,""),e=i("IENC","ascii",new TextDecoder),t=new TextDecoder(e),o=i("IPRD","",t),n=i("IART","",t),s=i("IGNR","",t),A=i("ICMT","Created using SpessaSynth: https://spessasus.github.io/SpessaSynth",t),l="locale.exportAudio.formats.formats.rmidi.options.",r="locale.exportAudio.formats.metadata.",d=ue(this.localeManager.getLocaleString(l+"title"),[{type:"text",textContent:this.localeManager.getLocaleString(l+"description"),attributes:{style:"max-width: 30ch; font-style: italic"}},{type:"toggle",translatePathTitle:l+"compress",attributes:{"compress-toggle":"1",checked:"true"}},{type:"range",translatePathTitle:l+"quality",attributes:{min:"0",max:"10",value:"5"}},{type:"input",translatePathTitle:r+"songTitle",attributes:{name:"song_title",type:"text",value:this.seqUI.currentSongTitle}},{type:"input",translatePathTitle:r+"album",attributes:{value:o,name:"album",type:"text"}},{type:"input",translatePathTitle:r+"artist",attributes:{value:n,name:"artist",type:"text"}},{type:"input",translatePathTitle:r+"genre",attributes:{value:s,name:"genre",type:"text"}},{type:"input",translatePathTitle:r+"comment",attributes:{value:A,name:"comment",type:"text"}},{type:"file",translatePathTitle:r+"albumCover",attributes:{value:this.seq.midiData.RMIDInfo?.IPIC!==void 0?this.seq.midiData.RMIDInfo.IPIC:"",name:"cover",accept:"image/*"}},{type:"input",translatePathTitle:l+"bankOffset",attributes:{value:this.seq.midiData.bankOffset,name:"bank_offset",type:"number"}},{type:"toggle",translatePathTitle:l+"adjust",attributes:{name:"adjust",checked:"checked"}},{type:"button",textContent:this.localeManager.getLocaleString(l+"confirm"),onClick:async g=>{let I=g.div.querySelector("input[compress-toggle='1']").checked,h=parseInt(g.div.querySelector("input[type='range']").value)/10,m=g.div.querySelector("input[name='album']").value,C=g.div.querySelector("input[name='artist']").value,f=g.div.querySelector("input[name='song_title']").value,y=g.div.querySelector("input[name='comment']").value,S=g.div.querySelector("input[name='genre']").value,D=parseInt(g.div.querySelector("input[name='bank_offset']").value),k=g.div.querySelector("input[name='adjust']").checked,w=g.div.querySelector("input[type='file']")?.files[0];le(g.id),we("%cExporting RMIDI...",B.info);let c="locale.exportAudio.formats.formats.rmidi.progress.",M=ue(this.localeManager.getLocaleString(c+"title"),[{type:"text",textContent:this.localeManager.getLocaleString(c+"loading"),attributes:{class:"export_rmidi_message"}}],9999999,!1);await new Promise(Y=>setTimeout(Y,500));let b=M.div.getElementsByClassName("export_rmidi_message")[0],q=await this.seq.getMIDI(),O=Lt(q.embeddedSoundFont||this.soundFont);b.textContent=this.localeManager.getLocaleString(c+"modifyingMIDI"),await new Promise(Y=>setTimeout(Y,75));try{q.applySnapshotToMIDI(await this.synth.getSynthesizerSnapshot())}catch(Y){ie("Failed to modify MIDI:",Y)}b.textContent=this.localeManager.getLocaleString(c+"modifyingSoundfont"),await new Promise(Y=>setTimeout(Y,75)),O.trimSoundBank(q);let T=O.write({compress:I,compressionQuality:h,compressionFunction:await this.getVorbisEncodeFunction()});b.textContent=this.localeManager.getLocaleString(c+"saving"),await new Promise(Y=>setTimeout(Y,75));let H;w?.type.split("/")[0]==="image"?H=await w.arrayBuffer():q.RMIDInfo?.IPIC!==void 0&&(H=q.RMIDInfo.IPIC.buffer);let $=q.writeRMIDI(T,O,D,this.seqUI.encoding,{name:f,comment:y,engineer:O.soundFontInfo.IENG,picture:H,album:m.length>0?m:void 0,artist:C.length>0?C:void 0,genre:S.length>0?S:void 0,midiEncoding:this.seqUI.encoding},k),j=new Blob([$.buffer],{type:"audio/rmid"});this.saveBlob(j,`${f||"unnamed_song"}.rmi`),b.textContent=this.localeManager.getLocaleString(c+"done"),le(M.id),ne()}}],9999999,!0,this.localeManager).div.querySelector("input[type='file']");d.oninput=()=>{d.files[0]&&(d.parentElement.firstChild.textContent=d.files[0].name)}}var Za="worklet_processor.min.js";var ln=class{constructor(e,t){let o=document.getElementsByClassName("drop_prompt")[0];document.body.addEventListener("dragover",n=>{n.preventDefault(),o.classList.remove("hidden")}),document.body.addEventListener("dragend",()=>{o.classList.add("hidden")}),document.body.addEventListener("drop",async n=>{if(n.preventDefault(),o.classList.add("hidden"),!n.dataTransfer.files[0])return;let s=[];for(let A of n.dataTransfer.files){let l=A.name,r=await A.arrayBuffer(),a=r.slice(0,4),d=new TextDecoder;if(d.decode(a)==="RIFF"){let g=r.slice(8,12);if(d.decode(g)==="RMID"){s.push({binary:r,altName:l});continue}t(r);continue}s.push({binary:r,altName:l})}e(s)})}};async function ja(){let i="locale.exportAudio.formats.formats.dls.warning.";ue(this.localeManager.getLocaleString(i+"title"),[{type:"text",textContent:this.localeManager.getLocaleString(i+"message"),attributes:{style:"font-weight: bold"}},{type:"toggle",translatePathTitle:"locale.exportAudio.formats.formats.soundfont.options.trim",attributes:{"trim-toggle":"1"}},{type:"button",textContent:this.localeManager.getLocaleString(i+"details"),onClick:()=>{window.open("https://github.com/spessasus/SpessaSynth/wiki/DLS-Conversion-Problem")}},{type:"button",textContent:this.localeManager.getLocaleString(i+"confirm"),onClick:async e=>{let t=e.div.querySelector("input[trim-toggle='1']").checked;le(e.id),He("%cExporting DLS...",B.info);let o=await this.seq.getMIDI(),n=Lt(o.embeddedSoundFont||this.soundFont);o.applySnapshotToMIDI(await this.synth.getSynthesizerSnapshot()),t&&n.trimSoundBank(o);try{let s=n.writeDLS(),A=new Blob([s.buffer],{type:"audio/dls"});this.saveBlob(A,`${n.soundFontInfo.INAM||"unnamed"}.dls`)}catch(s){ie("Failed to export DLS: ",s),ue(this.localeManager.getLocaleString("locale.error"),[{type:"text",textContent:s,attributes:{style:"font-weight: bold; color: red"}}])}ne()}}],99999999,!0,this.localeManager)}document.body.classList.add("load");var Wl=!1,mt=class{channelColors=["rgba(255, 99, 71, 1)","rgba(255, 165, 0, 1)","rgba(255, 215, 0, 1)","rgba(50, 205, 50, 1)","rgba(60, 179, 113, 1)","rgba(0, 128, 0, 1)","rgba(0, 191, 255, 1)","rgba(65, 105, 225, 1)","rgba(138, 43, 226, 1)","rgba(50, 120, 125, 1)","rgba(255, 0, 255, 1)","rgba(255, 20, 147, 1)","rgba(218, 112, 214, 1)","rgba(240, 128, 128, 1)","rgba(255, 192, 203, 1)","rgba(255, 255, 0, 1)"];sfError;compressionFunction=void 0;constructor(e,t,o,n=Wl){this.localeManager=o,this.context=e,this.enableDebug=n,this.isExporting=!1;let s;this.ready=new Promise(A=>s=A),this.initializeContext(e,t).then(()=>{s()})}async getVorbisEncodeFunction(){return this.compressionFunction!==void 0?this.compressionFunction:(this.compressionFunction=(await import("../externals/libvorbis/encode_vorbis.js")).encodeVorbis,this.compressionFunction)}saveBlob(e,t){let o=URL.createObjectURL(e),n=document.createElement("a");n.href=o,n.download=t,n.click(),F(n)}async initializeContext(e,t){if(!e.audioWorklet)throw alert("Audio worklet is not supported on your browser. Sorry!"),new Error("Audio worklet is not supported");for(let a of document.querySelectorAll("*[translate-path]"))this.localeManager.bindObjectProperty(a,"innerText",a.getAttribute("translate-path"));for(let a of document.querySelectorAll("*[translate-path-title]"))this.localeManager.bindObjectProperty(a,"innerText",a.getAttribute("translate-path-title")+".title"),this.localeManager.bindObjectProperty(a,"title",a.getAttribute("translate-path-title")+".description");this.soundFont=t;let n=this.enableDebug?"worklet_processor.js":Za;this.enableDebug&&console.warn("DEBUG ENABLED! DEBUGGING ENABLED!!");let s=window.isLocalEdition?"../../../":"../../";this.workletPath=s+n,e.audioWorklet&&await e.audioWorklet.addModule(new URL(this.workletPath,import.meta.url)),this.audioDelay=new DelayNode(e,{delayTime:0}),this.audioDelay.connect(e.destination),this.synth=new ki(this.audioDelay,this.soundFont,void 0,void 0,{chorusEnabled:!0,chorusConfig:void 0,reverbEnabled:!0,audioNodeCreators:void 0}),this.synth.eventHandler.addEvent("soundfonterror","manager-sf-error",a=>{this.sfError&&this.sfError(a.message)}),await this.synth.isReady,this.midHandler=new Yo,new Po(this.synth),this.keyboard=new zi(this.channelColors,this.synth);let A=document.getElementById("note_canvas");A.width=window.innerWidth*window.devicePixelRatio,A.height=window.innerHeight*window.devicePixelRatio,this.renderer=new Je(this.channelColors,this.synth,A,this.localeManager,window.SPESSASYNTH_VERSION),this.renderer.render(!0);let l=!1,r=()=>{if(this.renderer.updateSize(),je){if(window.innerWidth/window.innerHeight>1){if(!l){let a=document.getElementById("title_wrapper"),d=document.getElementById("settings_div");l=!0,a.parentElement.insertBefore(d,a)}}else if(l){let a=document.getElementById("title_wrapper"),d=document.getElementById("settings_div");l=!1,a.parentElement.insertBefore(a,d)}}this.renderer.render(!1,!0)};r(),window.addEventListener("resize",r.bind(this)),window.addEventListener("orientationchange",r.bind(this)),je&&(this.renderer.keyRange={min:48,max:72},this.keyboard.setKeyRange({min:48,max:72},!1)),this.synthUI=new ut(this.channelColors,document.getElementById("synthetizer_controls"),this.localeManager),this.synthUI.connectSynth(this.synth),this.synthUI.connectKeyboard(this.keyboard),this.musicModeUI=new Zo(document.getElementById("player_info"),this.localeManager),this.seqUI=new Rt(document.getElementById("sequencer_controls"),this.localeManager,this.musicModeUI,this.renderer),this.settingsUI=new Ve(document.getElementById("settings_div"),this.synthUI,this.seqUI,this.renderer,this.keyboard,this.midHandler,this.musicModeUI,this.localeManager,this.audioDelay),new ln(async a=>{if(a.length===0)return;await this.context.resume(),this.play(a);let d=a[0].altName;d>20&&(d=d.substring(0,21)+"..."),document.getElementById("file_upload").textContent=d;let g=document.getElementById("export_button");g.style.display="flex",g.onclick=this.exportSong.bind(this),window.isLocalEdition||(document.getElementById("demo_song").style.display="none")},a=>{this.reloadSf(a)}),document.addEventListener("keydown",a=>{if(!a.ctrlKey)switch(a.key.toLowerCase()){case be.videoMode:this.seq&&this.seq.pause();let d=window.prompt(`Video mode!
|
| 362 |
Paste the link to the video source (leave blank to disable)
|
| 363 |
+
Note: the video will be available in console as 'video'`,"");if(d===null)return;let g=document.createElement("video");g.src=d,g.classList.add("secret_video"),A.parentElement.appendChild(g),g.play(),window.video=g,this.seq&&(g.currentTime=parseFloat(window.prompt("Video offset to sync to midi, in seconds.","0")),g.play(),this.seq.currentTime=0),document.addEventListener("keydown",I=>{I.key===" "&&(g.paused?g.play():g.pause())});break;case be.sustainPedal:this.renderer.showHoldPedal=!0,this.renderer.render(!1),this.keyboard.setHoldPedal(!0)}}),document.addEventListener("keyup",a=>{if(!a.ctrlKey)switch(a.key.toLowerCase()){case be.sustainPedal:this.renderer.showHoldPedal=!1,this.renderer.render(!1),this.keyboard.setHoldPedal(!1);break;default:break}}),this.renderer.render(!1,!0)}doDLSCheck(){if(window.isLocalEdition!==!0){let e=this.soundFont.slice(8,12);Ie(new U(e),4).toLowerCase()==="dls "&&ue(this.localeManager.getLocaleString("locale.convertDls.title"),[{type:"text",textContent:this.localeManager.getLocaleString("locale.convertDls.message")},{type:"button",textContent:this.localeManager.getLocaleString("locale.yes"),onClick:o=>{le(o.id),this.downloadDesfont()}},{type:"button",textContent:this.localeManager.getLocaleString("locale.no"),onClick:o=>{le(o.id)}}],99999999)}}async reloadSf(e){await this.synth.soundfontManager.reloadManager(e),this.soundFont=e,setTimeout(()=>{this.doDLSCheck()},3e3)}play(e){if(this.synth){if(this.seq){this.seq.loadNewSongList(e),this.seq.play(!0);return}this.seq=new To(e,this.synth),this.seq.onError=t=>{console.error(t),document.getElementById("title").textContent=t.message},this.seqUI.connectSequencer(this.seq),this.musicModeUI.connectSequencer(this.seq),this.renderer.connectSequencer(this.seq),this.settingsUI.addSequencer(this.seq),this.synthUI.connectSequencer(this.seq),this.seq.play(!0)}}async downloadDLSRMI(){let e=await this.seq.getMIDI(),t=Lt(this.soundFont),o=e.writeRMIDI(t.writeDLS(),t),n=new Blob([o.buffer],{type:"audio/rmid"});this.saveBlob(n,`${e.midiName}.rmi`)}downloadDesfont(){let e=Lt(this.soundFont),t=e.write(),o=new Blob([t.buffer],{type:"audio/soundfont"});this.saveBlob(o,`${e.soundFontInfo.INAM}.sf2`)}};mt.prototype.exportSong=Wa;mt.prototype._exportAudioData=sa;mt.prototype._doExportAudioData=na;mt.prototype.exportMidi=Aa;mt.prototype._exportSoundfont=Ha;mt.prototype._exportDLS=ja;mt.prototype._exportRMIDI=za;var zl=44100,Zl="piano.sf3",cn=document.getElementById("title"),_t=document.getElementById("midi_file_input"),jl=document.getElementById("sf_file_input"),_a=document.getElementById("demo_song"),Zn=document.getElementById("export_button"),ci=document.getElementsByClassName("loading")[0],Xe=document.getElementById("loading_message"),Xl=await(await fetch("package.json")).json();window.SPESSASYNTH_VERSION=Xl.version;var _l="spessasynth-db",di="soundFontStore";function _n(i){let e=indexedDB.open(_l,1);e.onsuccess=()=>{let t=e.result;i(t)},e.onupgradeneeded=t=>{t.target.result.createObjectStore(di,{keyPath:"id"})}}async function $l(){return await new Promise(i=>{_n(e=>{let n=e.transaction([di],"readonly").objectStore(di).get("buffer");n.onerror=s=>{console.error("Database error"),console.error(s),i(void 0)},n.onsuccess=async()=>{let s=n.result;if(!s){i(void 0);return}i(s.data)}})})}function gi(i,e=!0){let t=ci.getElementsByClassName("loading_icon")[0];t.innerHTML=i,t.style.animation=e?"none":""}async function $a(i){_n(e=>{let o=e.transaction([di],"readwrite").objectStore(di);try{let n=o.put({id:"buffer",data:i});n.onsuccess=()=>{F("SoundFont stored successfully")},n.onerror=s=>{console.error("Error saving soundfont",s)}}catch(n){ie("Failed saving soundfont:",n)}})}async function ec(i){let e=new jo(i);try{let n=window.AudioContext||window.webkitAudioContext;window.audioContextMain=new n({sampleRate:zl})}catch(n){throw gi($i(256)),Xe.textContent=e.getLocaleString("locale.synthInit.noWebAudio"),n}Xe.textContent=e.getLocaleString("locale.synthInit.loadingSoundfont");let t=await $l(),o=!0;if(t===void 0){ie("Failed to load from db, fetching online instead"),o=!1;let n=document.getElementById("progress_bar"),s=e.getLocaleString("locale.synthInit.loadingBundledSoundfont");Xe.textContent=s,t=await tc(`${Zl}`,A=>{Xe.textContent=`${s} ${A}%`}),n.style.width="0"}else F("Loaded the soundfont from the database succesfully");window.soundFontParser=t,o||(Xe.textContent=e.getLocaleString("locale.synthInit.savingSoundfont"),await $a(t)),window.audioContextMain.state!=="running"&&document.addEventListener("mousedown",()=>{window.audioContextMain.state!=="running"&&window.audioContextMain.resume().then()}),Xe.textContent=e.getLocaleString("locale.synthInit.startingSynthesizer"),window.manager=new mt(audioContextMain,soundFontParser,e),window.manager.sfError=n=>{gi($i(256)),o?(ie("Invalid soundfont in the database. Resetting."),_n(s=>{let r=s.transaction([di],"readwrite").objectStore(di).delete("buffer");r.onsuccess=()=>{location.reload()}})):cn.innerHTML=`Error parsing soundfont: <pre style='font-family: monospace; font-weight: bold;'>${n}</pre>`,Xe.innerHTML=`Error parsing soundfont: <pre style='font-family: monospace; font-weight: bold;'>${n}</pre>`},await manager.ready,manager.synth.voiceCap=el,_t.files[0]?await jn(_t.files):(_t.onclick=void 0,_t.onchange=()=>{_t.files[0]&&jn(_t.files).then()}),gi(xn(256)),Xe.textContent=e.getLocaleString("locale.synthInit.done")}async function tc(i,e){let t=await fetch(i);if(!t.ok)throw cn.innerText="Error downloading soundfont!",t;let o=t.headers.get("content-length"),n=await(await t.body).getReader(),s=!1,A=new Uint8Array(parseInt(o)),l=0;do{let r=await n.read();r.value&&(A.set(r.value,l),l+=r.value.length),s=r.done;let a=Math.round(l/o*100);e(a)}while(!s);return A.buffer}async function jn(i){_a.style.display="none";let e;i[0].name.length>20?e=i[0].name.substring(0,21)+"...":e=i[0].name,i.length>1&&(e+=` and ${i.length-1} others`),document.getElementById("file_upload").innerText=e,document.getElementById("file_upload").title=i[0].name;let t=[];for(let o of i)t.push({binary:await o.arrayBuffer(),altName:o.name});manager.synth.setLogLevel(!1,!1,!1,!1),manager.seq?manager.seq.loadNewSongList(t):manager.play(t),Zn.style.display="flex",Zn.onclick=window.manager.exportSong.bind(window.manager)}function ic(i){localStorage.setItem("spessasynth-settings",JSON.stringify(i)),F("saved as",i)}var el=350,Xa=localStorage.getItem("spessasynth-voice-cap");Xa&&(el=parseInt(Xa));window.rememberVoiceCap=i=>{localStorage.setItem("spessasynth-voice-cap",i.toString()),window.location.reload()};window.saveSettings=ic;var so=JSON.parse(localStorage.getItem("spessasynth-settings"));so!==null&&(window.savedSettings=new Promise(i=>{i(so)}));var Xn;so&&so.interface&&so.interface.language?Xn=(await savedSettings).interface.language||navigator.language.split("-")[0].toLowerCase():Xn=navigator.language.split("-")[0].toLowerCase();_t.value="";_t.focus();Zn.style.display="none";document.getElementById("sf_upload").style.display="none";document.getElementById("file_upload").style.display="none";async function oc(i){cn.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.genericLoading");let e=await fetch("https://spessasus.github.io/spessasynth-demo-songs/demo_songs/"+i);e.name=i,await jn([e])}ec(Xn).then(()=>{document.getElementById("sf_upload").style.display="flex",document.getElementById("file_upload").style.display="flex",ci.classList.add("done"),document.documentElement.classList.add("no_scroll"),document.body.classList.add("no_scroll"),setTimeout(()=>{ci.style.display="none",document.body.classList.remove("no_scroll"),document.documentElement.classList.remove("no_scroll"),je&&window.chrome&&ue(window.manager.localeManager.getLocaleString("locale.warnings.warning"),[{type:"text",textContent:window.manager.localeManager.getLocaleString("locale.warnings.chromeMobile")}],7)},1e3),jl.onchange=i=>{if(!i.target.files[0])return;let e=i.target.files[0];window.manager.seq&&window.manager.seq.pause(),document.getElementById("sf_upload").firstElementChild.innerText=e.name,ci.style.display="",setTimeout(async()=>{ci.classList.remove("done"),gi(AA(256),!1),Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.loadingSoundfont");let t=performance.now()/1e3,o;try{o=await e.arrayBuffer(),window.soundFontParser=o}catch(s){throw Xe.textContent=window.manager.localeManager.getLocaleString("locale.warnings.outOfMemory"),gi($i(256)),ue(manager.localeManager.getLocaleString("locale.warnings.warning"),[{type:"text",textContent:window.manager.localeManager.getLocaleString("locale.warnings.outOfMemory")}]),s}window.manager.sfError=s=>{Xe.innerHTML=`Error parsing soundfont: <pre style='font-family: monospace; font-weight: bold;'>${s}</pre>`,gi($i(256)),console.error(s)},Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.startingSynthesizer"),await window.manager.reloadSf(o),window.manager.seq&&(window.manager.seq.currentTime-=.1),Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.savingSoundfont"),await $a(o);let n=performance.now()/1e3-t;await new Promise(s=>setTimeout(s,1e3-n)),gi(xn(256)),Xe.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.done"),ci.classList.add("done"),document.documentElement.classList.add("no_scroll"),document.body.classList.add("no_scroll"),setTimeout(()=>{ci.style.display="none",document.body.classList.remove("no_scroll"),document.documentElement.classList.remove("no_scroll")},1e3)},75)},_a.onclick=async()=>{let i=[{type:"button",textContent:"Bundled SoundFont Credits",onClick:()=>{window.open("https://schristiancollins.com/generaluser.php")}}];cn.textContent=window.manager.localeManager.getLocaleString("locale.synthInit.genericLoading");let e=await(await fetch("https://spessasus.github.io/spessasynth-demo-songs/demo_song_list.json")).text(),t=JSON.parse(e);for(let o of t)i.push({type:"button",textContent:o.name,onClick:n=>{le(n.id),ue(window.manager.localeManager.getLocaleString("locale.credits"),[{type:"text",textContent:o.credits.replace(`
|
| 364 |
`,`\r
|
| 365 |
\r
|
| 366 |
`),attributes:{style:"white-space: pre-line;"}},{type:"button",textContent:"Ok",onClick:s=>{le(s.id)}}],999999,!0,void 0,void 0,async()=>{await oc(o.fileName)})}});ue(window.manager.localeManager.getLocaleString("locale.demoSongButton"),i,999999,!0,void 0)}});
|