@ilusiv/fyug-js 2026.11.7 → 2026.11.9

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/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # @ilusiv/fyug-js
2
2
 
3
- A limited preview of Fyug for the browser: the engine compiled to WebAssembly,
4
- for surfaces where the desktop app can't run. It has a reduced feature set,
5
- and its audio may drop out, especially when it runs on a page's main thread;
6
- for the full app, install Fyug on your desktop:
3
+ Fyug's engine for the browser, compiled to WebAssembly, for surfaces where the
4
+ desktop app can't run, such as the in-chat player. It builds the module types
5
+ its release lists, and its audio may drop out, especially when it runs on a
6
+ page's main thread. The desktop app is at
7
7
  https://github.com/Ilusiv-media/fyug
8
8
 
9
9
  The browser engine builds the module types listed in each engine release's
@@ -196,6 +196,43 @@ Each is licensed for redistribution (the 808 kit is CC0-1.0). Samples given to
196
196
  same WebAssembly instance (an AudioWorklet's engine has an instance of its
197
197
  own). WAV is decoded; FLAC is not, in the browser engine.
198
198
 
199
+ ## Reading What Plays
200
+
201
+ A page that drives the worklet's message protocol itself (posting
202
+ `{ type: "request", id, method, args }` and reading `{ type: "response", id,
203
+ result | error }`) can ask it for what a meter and a playhead show with the
204
+ `views` request. `args` is `[clock]`, the id of the clock whose beats the
205
+ playhead follows, or `[]`. The answer covers everything rendered since the
206
+ last `views` request, which starts the next reading over:
207
+
208
+ - `levels`: the engine's `takeLevels()` JSON, with each channel's peak
209
+ (before the output clamp) and RMS (after it, of what the device plays), the
210
+ count of samples over full scale, the count of non-finite samples, and
211
+ `frames`.
212
+ - `squares`: `[left, right]`, the sums of squares of the samples the worklet
213
+ sent the device, after the clamp, over `frames` frames: the level that is
214
+ heard. RMS is `Math.sqrt(squares[i] / frames)`. `levels.frames` and `frames`
215
+ count the same frames; a load or reset starts both over.
216
+ - `beats`: the clock's `elapsed` control (a JSON number as a string), or
217
+ `null` when no clock was named or the piece has none by that id.
218
+ - `time`: the worklet's `currentTime`, where the rendered audio, and `beats`,
219
+ end. A page maps it to what is heard with `AudioContext.getOutputTimestamp()`.
220
+
221
+ Nothing counts while the piece is stopped. The request adds two multiply-adds
222
+ per frame to `process()`, into numbers the worklet already holds, and nothing
223
+ else there. Like every request, the answer is built on the render thread
224
+ between renders; it allocates the `levels` and `beats` strings (in the wasm
225
+ memory and as JS strings), the answer object and its two-element `squares`
226
+ array, besides the response message every request posts. A clock the piece
227
+ lacks is looked up once, not on each request, until the next load or edit.
228
+ Ask at most once per animation frame and not while an answer is still on its
229
+ way.
230
+
231
+ Before a piece is loaded the request fails like the others do. A worklet older
232
+ than this request answers it with the error
233
+ `Unknown Fugue player method: views`: a page that gets that error can stop
234
+ asking, show no views and play on.
235
+
199
236
  ## Single-File Player
200
237
 
201
238
  Each engine release also carries `fyug-player.html`, one self-contained page for
@@ -1 +1 @@
1
- "use strict";(()=>{var L=Object.defineProperty;var P=(i,t,e)=>t in i?L(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var x=(i,t,e)=>P(i,typeof t!="symbol"?t+"":t,e);typeof globalThis.TextEncoder>"u"&&(globalThis.TextEncoder=class{encode(t=""){let e=[];for(let n=0;n<t.length;n+=1){let r=t.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<t.length){let s=t.charCodeAt(n+1);s>=56320&&s<=57343&&(r=65536+(r-55296<<10)+(s-56320),n+=1)}r<=127?e.push(r):r<=2047?e.push(192|r>>6,128|r&63):r<=65535?e.push(224|r>>12,128|r>>6&63,128|r&63):e.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|r&63)}return new Uint8Array(e)}encodeInto(t,e){let n=this.encode(t),r=Math.min(n.length,e.length);return e.set(n.subarray(0,r)),{read:t.length,written:r}}});typeof globalThis.TextDecoder>"u"&&(globalThis.TextDecoder=class{decode(t=new Uint8Array){let e=t instanceof Uint8Array?t:new Uint8Array(t),n="";for(let r=0;r<e.length;r+=1){let s=e[r]??0;if(s<128)n+=String.fromCharCode(s);else if((s&224)===192&&r+1<e.length){let _=(s&31)<<6|(e[++r]??0)&63;n+=String.fromCharCode(_)}else if((s&240)===224&&r+2<e.length){let _=(s&15)<<12|((e[++r]??0)&63)<<6|(e[++r]??0)&63;n+=String.fromCharCode(_)}else if((s&248)===240&&r+3<e.length){let _=(s&7)<<18|((e[++r]??0)&63)<<12|((e[++r]??0)&63)<<6|(e[++r]??0)&63;_-=65536,n+=String.fromCharCode(55296+(_>>10),56320+(_&1023))}else n+="\uFFFD"}return n}});if(typeof globalThis.crypto>"u"||typeof globalThis.crypto.getRandomValues!="function"){let i=(Date.now()&4294967295^(typeof currentTime=="number"?currentTime*4294967295:0)>>>0)>>>0,t=()=>(i^=i<<13,i^=i>>>17,i^=i<<5,i&255),e={getRandomValues(n){if(!n||!ArrayBuffer.isView(n))throw new TypeError("Expected an integer typed array");let r=new Uint8Array(n.buffer,n.byteOffset,n.byteLength);for(let s=0;s<r.length;s+=1)r[s]=t();return n}};typeof globalThis.crypto>"u"?Object.defineProperty(globalThis,"crypto",{configurable:!0,value:e}):Object.defineProperty(globalThis.crypto,"getRandomValues",{configurable:!0,value:e.getRandomValues})}var ee={},y=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,R.unregister(this),t}free(){let t=this.__destroy_into_raw();o.__wbg_fugueengine_free(t,0)}addModule(t,e,n){let r=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),s=c,_=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c;var a=B(n)?0:f(n,o.__wbindgen_malloc,o.__wbindgen_realloc),g=c;let u=o.fugueengine_addModule(this.__wbg_ptr,r,s,_,l,a,g);if(u[1])throw d(u[0])}applyEdits(t){let e=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),n=c,r=o.fugueengine_applyEdits(this.__wbg_ptr,e,n);if(r[1])throw d(r[0])}connect(t,e,n,r){let s=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),_=c,l=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),a=c,g=f(n,o.__wbindgen_malloc,o.__wbindgen_realloc),u=c,w=f(r,o.__wbindgen_malloc,o.__wbindgen_realloc),m=c,p=o.fugueengine_connect(this.__wbg_ptr,s,_,l,a,g,u,w,m);if(p[1])throw d(p[0])}disconnect(t,e,n,r){let s=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),_=c,l=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),a=c,g=f(n,o.__wbindgen_malloc,o.__wbindgen_realloc),u=c,w=f(r,o.__wbindgen_malloc,o.__wbindgen_realloc),m=c,p=o.fugueengine_disconnect(this.__wbg_ptr,s,_,l,a,g,u,w,m);if(p[1])throw d(p[0])}finishAudioFileSink(t){let e,n;try{let _=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c,a=o.fugueengine_finishAudioFileSink(this.__wbg_ptr,_,l);var r=a[0],s=a[1];if(a[3])throw r=0,s=0,d(a[2]);return e=r,n=s,b(r,s)}finally{o.__wbindgen_free(e,n,1)}}getAudioFileSinkWav(t){let e=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),n=c,r=o.fugueengine_getAudioFileSinkWav(this.__wbg_ptr,e,n);if(r[3])throw d(r[2]);var s=I(r[0],r[1]).slice();return o.__wbindgen_free(r[0],r[1]*1,1),s}getCodeModuleConfig(t){let e,n;try{let _=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c,a=o.fugueengine_getCodeModuleConfig(this.__wbg_ptr,_,l);var r=a[0],s=a[1];if(a[3])throw r=0,s=0,d(a[2]);return e=r,n=s,b(r,s)}finally{o.__wbindgen_free(e,n,1)}}getControl(t,e){let n,r;try{let l=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),a=c,g=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),u=c,w=o.fugueengine_getControl(this.__wbg_ptr,l,a,g,u);var s=w[0],_=w[1];if(w[3])throw s=0,_=0,d(w[2]);return n=s,r=_,b(s,_)}finally{o.__wbindgen_free(n,r,1)}}listCodeModules(){let t,e;try{let s=o.fugueengine_listCodeModules(this.__wbg_ptr);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,d(s[2]);return t=n,e=r,b(n,r)}finally{o.__wbindgen_free(t,e,1)}}listConnections(){let t,e;try{let s=o.fugueengine_listConnections(this.__wbg_ptr);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,d(s[2]);return t=n,e=r,b(n,r)}finally{o.__wbindgen_free(t,e,1)}}listControls(t){let e,n;try{var r=B(t)?0:f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),s=c;let a=o.fugueengine_listControls(this.__wbg_ptr,r,s);var _=a[0],l=a[1];if(a[3])throw _=0,l=0,d(a[2]);return e=_,n=l,b(_,l)}finally{o.__wbindgen_free(e,n,1)}}listModules(){let t,e;try{let s=o.fugueengine_listModules(this.__wbg_ptr);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,d(s[2]);return t=n,e=r,b(n,r)}finally{o.__wbindgen_free(t,e,1)}}loadInvention(t){let e=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),n=c,r=o.fugueengine_loadInvention(this.__wbg_ptr,e,n);if(r[1])throw d(r[0])}constructor(t){let e=o.fugueengine_new(t);return this.__wbg_ptr=e,R.register(this,this.__wbg_ptr,this),this}previewNotes(t,e){let n=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),r=c,s=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),_=c;return o.fugueengine_previewNotes(this.__wbg_ptr,n,r,s,_)}provideSample(t,e,n,r){let s,_;try{let g=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),u=c,w=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),m=c,p=f(n,o.__wbindgen_malloc,o.__wbindgen_realloc),U=c,D=Y(r,o.__wbindgen_malloc),V=c,T=o.fugueengine_provideSample(this.__wbg_ptr,g,u,w,m,p,U,D,V);var l=T[0],a=T[1];if(T[3])throw l=0,a=0,d(T[2]);return s=l,_=a,b(l,a)}finally{o.__wbindgen_free(s,_,1)}}removeModule(t){let e=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),n=c,r=o.fugueengine_removeModule(this.__wbg_ptr,e,n);if(r[1])throw d(r[0])}renderInterleavedInto(t){let e=o.fugueengine_renderInterleavedInto(this.__wbg_ptr,t);if(e[2])throw d(e[1]);return e[0]>>>0}renderInterleaved(t){let e=o.fugueengine_renderInterleaved(this.__wbg_ptr,t);if(e[3])throw d(e[2]);var n=W(e[0],e[1]).slice();return o.__wbindgen_free(e[0],e[1]*4,4),n}reset(){let t=o.fugueengine_reset(this.__wbg_ptr);if(t[1])throw d(t[0])}sampleRate(){return o.fugueengine_sampleRate(this.__wbg_ptr)>>>0}setCodeModuleError(t,e){let n=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),r=c,s=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),_=c,l=o.fugueengine_setCodeModuleError(this.__wbg_ptr,n,r,s,_);if(l[1])throw d(l[0])}setCodeModuleStatus(t,e){let n=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),r=c,s=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),_=c,l=o.fugueengine_setCodeModuleStatus(this.__wbg_ptr,n,r,s,_);if(l[1])throw d(l[0])}setControlBool(t,e,n){let r=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),s=c,_=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c,a=o.fugueengine_setControlBool(this.__wbg_ptr,r,s,_,l,n);if(a[1])throw d(a[0])}setControlNumber(t,e,n){let r=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),s=c,_=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c,a=o.fugueengine_setControlNumber(this.__wbg_ptr,r,s,_,l,n);if(a[1])throw d(a[0])}setControlString(t,e,n){let r=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),s=c,_=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c,a=f(n,o.__wbindgen_malloc,o.__wbindgen_realloc),g=c,u=o.fugueengine_setControlString(this.__wbg_ptr,r,s,_,l,a,g);if(u[1])throw d(u[0])}status(){let t,e;try{let s=o.fugueengine_status(this.__wbg_ptr);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,d(s[2]);return t=n,e=r,b(n,r)}finally{o.__wbindgen_free(t,e,1)}}takeLevels(){let t,e;try{let s=o.fugueengine_takeLevels(this.__wbg_ptr);var n=s[0],r=s[1];if(s[3])throw n=0,r=0,d(s[2]);return t=n,e=r,b(n,r)}finally{o.__wbindgen_free(t,e,1)}}};Symbol.dispose&&(y.prototype[Symbol.dispose]=y.prototype.free);function j(){return{__proto__:null,"./fugue_bg.js":{__proto__:null,__wbg___wbindgen_throw_41e9ee4f547fc59a:function(t,e){throw new Error(b(t,e))},__wbg__wbg_cb_unref_dcc1a90847f04c41:function(t){t._wbg_cb_unref()},__wbg_call_187d372bd5fdd4aa:function(){return k(function(t,e,n){return t.call(e,n)},arguments)},__wbg_getRandomValues_436a51d0629d84e1:function(){return k(function(t,e){globalThis.crypto.getRandomValues(I(t,e))},arguments)},__wbg_length_58572db4c38f3c3e:function(t){return t.length},__wbg_new_5502aad30c185fc8:function(t,e){try{var n={a:t,b:e},r=(_,l)=>{let a=n.a;n.a=0;try{return z(a,n.b,_,l)}finally{n.a=a}};return new Promise(r)}finally{n.a=0}},__wbg_now_aa4ccb83129e9e55:function(){return Date.now()},__wbg_setTimeout_4bf75e1eaccfc9e2:function(t,e){return setTimeout(t,e)},__wbg_set_070bd465f1c195a4:function(t,e,n){t.set(W(e,n))},__wbindgen_generic_0000000000000001:function(t,e){return X(t,e,q)},__wbindgen_generic_0000000000000002:function(t,e){return b(t,e)},__wbindgen_init_externref_table:function(){let t=o.__wbindgen_externrefs,e=t.grow(4);t.set(0,void 0),t.set(e+0,void 0),t.set(e+1,null),t.set(e+2,!0),t.set(e+3,!1)}}}}function q(i,t){o.wasm_bindgen__convert__closures_____invoke__hd2d6d321acd2ef74(i,t)}function z(i,t,e,n){o.wasm_bindgen__convert__closures_____invoke__h1b9b7a832ddda534(i,t,e,n)}var R=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>o.__wbg_fugueengine_free(i,1));function N(i){let t=o.__externref_table_alloc();return o.__wbindgen_externrefs.set(t,i),t}var F=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>o.__wbindgen_destroy_closure(i.a,i.b));function W(i,t){return i=i>>>0,$().subarray(i/4,i/4+t)}function I(i,t){return i=i>>>0,h().subarray(i/1,i/1+t)}var v=null;function $(){return(v===null||v.byteLength===0)&&(v=new Float32Array(o.memory.buffer)),v}function b(i,t){return H(i>>>0,t)}var C=null;function h(){return(C===null||C.byteLength===0)&&(C=new Uint8Array(o.memory.buffer)),C}function k(i,t){try{return i.apply(this,t)}catch(e){let n=N(e);o.__wbindgen_exn_store(n)}}function B(i){return i==null}function X(i,t,e){let n={a:i,b:t,cnt:1},r=(...s)=>{n.cnt++;let _=n.a;n.a=0;try{return e(_,n.b,...s)}finally{n.a=_,r._wbg_cb_unref()}};return r._wbg_cb_unref=()=>{--n.cnt===0&&(o.__wbindgen_destroy_closure(n.a,n.b),n.a=0,F.unregister(n))},F.register(r,n,n),r}function Y(i,t){let e=t(i.length*1,1)>>>0;return h().set(i,e/1),c=i.length,e}function f(i,t,e){if(e===void 0){let l=A.encode(i),a=t(l.length,1)>>>0;return h().subarray(a,a+l.length).set(l),c=l.length,a}let n=i.length,r=t(n,1)>>>0,s=h(),_=0;for(;_<n;_++){let l=i.charCodeAt(_);if(l>127)break;s[r+_]=l}if(_!==n){_!==0&&(i=i.slice(_)),r=e(r,n,n=_+i.length*3,1)>>>0;let l=h().subarray(r+_,r+n),a=A.encodeInto(i,l);_+=a.written,r=e(r,n,_,1)>>>0}return c=_,r}function d(i){let t=o.__wbindgen_externrefs.get(i);return o.__externref_table_dealloc(i),t}var M=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});M.decode();var G=2146435072,E=0;function H(i,t){return E+=t,E>=G&&(M=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),M.decode(),E=t),M.decode(h().subarray(i,i+t))}var A=new TextEncoder;"encodeInto"in A||(A.encodeInto=function(i,t){let e=A.encode(i);return t.set(e),{read:i.length,written:e.length}});var c=0,J,K,o;function Q(i,t){return K=i,o=i.exports,J=t,v=null,C=null,o.__wbindgen_start(),o}async function Z(i,t){if(typeof Response=="function"&&i instanceof Response){if(!i.ok)throw new Error(`failed to fetch Wasm: ${i.status} ${i.statusText} fetching '${i.url}'`);if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(i,t)}catch(r){if(e(i.type)&&i.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",r);else throw r}let n=await i.arrayBuffer();return await WebAssembly.instantiate(n,t)}else{let n=await WebAssembly.instantiate(i,t);return n instanceof WebAssembly.Instance?{instance:n,module:i}:n}function e(n){switch(n){case"basic":case"cors":case"default":return!0}return!1}}async function O(i){if(o!==void 0)return o;i!==void 0&&(Object.getPrototypeOf(i)===Object.prototype?{module_or_path:i}=i:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),i===void 0&&(i=new URL("fugue_bg.wasm",ee.url));let t=j();(typeof i=="string"||typeof Request=="function"&&i instanceof Request||typeof URL=="function"&&i instanceof URL)&&(i=fetch(i));let{instance:e,module:n}=await Z(await i,t);return Q(e,n)}var S=class extends AudioWorkletProcessor{constructor(e){super();x(this,"engine",null);x(this,"ready",!1);x(this,"playing",!1);x(this,"renderBuffer",new Float32Array(0));this.port.onmessage=n=>{this.handleMessage(n.data)},this.initialize(e?.processorOptions??{})}async initialize(e){try{await O({module_or_path:e.wasmBytes}),this.engine=new y(e.sampleRate??sampleRate),this.ready=!0,this.port.postMessage({type:"ready"})}catch(n){this.postError(n)}}handleMessage(e){if(!(!e||typeof e!="object")){if(e.type==="play"){this.playing=!0,this.port.postMessage({type:"state",state:"playing"});return}if(e.type==="stop"){this.playing=!1,this.port.postMessage({type:"state",state:"stopped"});return}if(e.type==="request")try{let n=this.handleRequest(e.method,e.args??[]);this.port.postMessage({type:"response",id:e.id,result:n})}catch(n){this.port.postMessage({type:"response",id:e.id,error:n instanceof Error?n.message:String(n)})}}}handleRequest(e,n){if(!this.ready||!this.engine)throw new Error("Fugue engine is not ready");switch(e){case"loadInvention":return this.engine.loadInvention(n[0]),null;case"reset":return this.engine.reset(),null;case"provideSample":return this.engine.provideSample(n[0],n[1],n[2],n[3]),null;case"status":return this.engine.status();case"listModules":return this.engine.listModules();case"listConnections":return this.engine.listConnections();case"applyEdits":return this.engine.applyEdits(n[0]);case"listControls":return this.engine.listControls(n[0]);case"getControl":return this.engine.getControl(n[0],n[1]);case"setControl":return this.setControl(n[0],n[1],n[2]),null;default:throw new Error(`Unknown Fugue player method: ${e}`)}}setControl(e,n,r){switch(typeof r){case"number":this.engine?.setControlNumber(e,n,r);return;case"boolean":this.engine?.setControlBool(e,n,r);return;case"string":this.engine?.setControlString(e,n,r);return}}process(e,n){let r=n[0],s=r?.[0],_=r?.[1];if(!s||!_)return!0;if(!this.playing||!this.ready||!this.engine)return s.fill(0),_.fill(0),!0;let l=s.length,a=l*2;this.renderBuffer.length!==a&&(this.renderBuffer=new Float32Array(a));try{this.engine.renderInterleavedInto(this.renderBuffer);for(let g=0,u=0;g<l;g+=1,u+=2)s[g]=this.renderBuffer[u]??0,_[g]=this.renderBuffer[u+1]??0}catch(g){this.playing=!1,s.fill(0),_.fill(0),this.postError(g)}return!0}postError(e){this.port.postMessage({type:"error",error:e instanceof Error?e.message:String(e)})}};registerProcessor("fugue-audio-worklet",S);})();
1
+ "use strict";(()=>{var D=Object.defineProperty;var P=(i,t,e)=>t in i?D(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var p=(i,t,e)=>P(i,typeof t!="symbol"?t+"":t,e);typeof globalThis.TextEncoder>"u"&&(globalThis.TextEncoder=class{encode(t=""){let e=[];for(let n=0;n<t.length;n+=1){let s=t.charCodeAt(n);if(s>=55296&&s<=56319&&n+1<t.length){let o=t.charCodeAt(n+1);o>=56320&&o<=57343&&(s=65536+(s-55296<<10)+(o-56320),n+=1)}s<=127?e.push(s):s<=2047?e.push(192|s>>6,128|s&63):s<=65535?e.push(224|s>>12,128|s>>6&63,128|s&63):e.push(240|s>>18,128|s>>12&63,128|s>>6&63,128|s&63)}return new Uint8Array(e)}encodeInto(t,e){let n=this.encode(t),s=Math.min(n.length,e.length);return e.set(n.subarray(0,s)),{read:t.length,written:s}}});typeof globalThis.TextDecoder>"u"&&(globalThis.TextDecoder=class{decode(t=new Uint8Array){let e=t instanceof Uint8Array?t:new Uint8Array(t),n="";for(let s=0;s<e.length;s+=1){let o=e[s]??0;if(o<128)n+=String.fromCharCode(o);else if((o&224)===192&&s+1<e.length){let _=(o&31)<<6|(e[++s]??0)&63;n+=String.fromCharCode(_)}else if((o&240)===224&&s+2<e.length){let _=(o&15)<<12|((e[++s]??0)&63)<<6|(e[++s]??0)&63;n+=String.fromCharCode(_)}else if((o&248)===240&&s+3<e.length){let _=(o&7)<<18|((e[++s]??0)&63)<<12|((e[++s]??0)&63)<<6|(e[++s]??0)&63;_-=65536,n+=String.fromCharCode(55296+(_>>10),56320+(_&1023))}else n+="\uFFFD"}return n}});if(typeof globalThis.crypto>"u"||typeof globalThis.crypto.getRandomValues!="function"){let i=(Date.now()&4294967295^(typeof currentTime=="number"?currentTime*4294967295:0)>>>0)>>>0,t=()=>(i^=i<<13,i^=i>>>17,i^=i<<5,i&255),e={getRandomValues(n){if(!n||!ArrayBuffer.isView(n))throw new TypeError("Expected an integer typed array");let s=new Uint8Array(n.buffer,n.byteOffset,n.byteLength);for(let o=0;o<s.length;o+=1)s[o]=t();return n}};typeof globalThis.crypto>"u"?Object.defineProperty(globalThis,"crypto",{configurable:!0,value:e}):Object.defineProperty(globalThis.crypto,"getRandomValues",{configurable:!0,value:e.getRandomValues})}var re={},v=class{__destroy_into_raw(){let t=this.__wbg_ptr;return this.__wbg_ptr=0,q.unregister(this),t}free(){let t=this.__destroy_into_raw();r.__wbg_fugueengine_free(t,0)}addModule(t,e,n){let s=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),o=c,_=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c;var l=F(n)?0:f(n,r.__wbindgen_malloc,r.__wbindgen_realloc),g=c;let d=r.fugueengine_addModule(this.__wbg_ptr,s,o,_,a,l,g);if(d[1])throw u(d[0])}applyEdits(t){let e,n;try{let _=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c,l=r.fugueengine_applyEdits(this.__wbg_ptr,_,a);var s=l[0],o=l[1];if(l[3])throw s=0,o=0,u(l[2]);return e=s,n=o,w(s,o)}finally{r.__wbindgen_free(e,n,1)}}connect(t,e,n,s){let o=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),_=c,a=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),l=c,g=f(n,r.__wbindgen_malloc,r.__wbindgen_realloc),d=c,b=f(s,r.__wbindgen_malloc,r.__wbindgen_realloc),y=c,h=r.fugueengine_connect(this.__wbg_ptr,o,_,a,l,g,d,b,y);if(h[1])throw u(h[0])}disconnect(t,e,n,s){let o=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),_=c,a=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),l=c,g=f(n,r.__wbindgen_malloc,r.__wbindgen_realloc),d=c,b=f(s,r.__wbindgen_malloc,r.__wbindgen_realloc),y=c,h=r.fugueengine_disconnect(this.__wbg_ptr,o,_,a,l,g,d,b,y);if(h[1])throw u(h[0])}finishAudioFileSink(t){let e,n;try{let _=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c,l=r.fugueengine_finishAudioFileSink(this.__wbg_ptr,_,a);var s=l[0],o=l[1];if(l[3])throw s=0,o=0,u(l[2]);return e=s,n=o,w(s,o)}finally{r.__wbindgen_free(e,n,1)}}getAudioFileSinkWav(t){let e=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),n=c,s=r.fugueengine_getAudioFileSinkWav(this.__wbg_ptr,e,n);if(s[3])throw u(s[2]);var o=V(s[0],s[1]).slice();return r.__wbindgen_free(s[0],s[1]*1,1),o}getCodeModuleConfig(t){let e,n;try{let _=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c,l=r.fugueengine_getCodeModuleConfig(this.__wbg_ptr,_,a);var s=l[0],o=l[1];if(l[3])throw s=0,o=0,u(l[2]);return e=s,n=o,w(s,o)}finally{r.__wbindgen_free(e,n,1)}}getControl(t,e){let n,s;try{let a=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),l=c,g=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),d=c,b=r.fugueengine_getControl(this.__wbg_ptr,a,l,g,d);var o=b[0],_=b[1];if(b[3])throw o=0,_=0,u(b[2]);return n=o,s=_,w(o,_)}finally{r.__wbindgen_free(n,s,1)}}listCodeModules(){let t,e;try{let o=r.fugueengine_listCodeModules(this.__wbg_ptr);var n=o[0],s=o[1];if(o[3])throw n=0,s=0,u(o[2]);return t=n,e=s,w(n,s)}finally{r.__wbindgen_free(t,e,1)}}listConnections(){let t,e;try{let o=r.fugueengine_listConnections(this.__wbg_ptr);var n=o[0],s=o[1];if(o[3])throw n=0,s=0,u(o[2]);return t=n,e=s,w(n,s)}finally{r.__wbindgen_free(t,e,1)}}listControls(t){let e,n;try{var s=F(t)?0:f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),o=c;let l=r.fugueengine_listControls(this.__wbg_ptr,s,o);var _=l[0],a=l[1];if(l[3])throw _=0,a=0,u(l[2]);return e=_,n=a,w(_,a)}finally{r.__wbindgen_free(e,n,1)}}listModules(){let t,e;try{let o=r.fugueengine_listModules(this.__wbg_ptr);var n=o[0],s=o[1];if(o[3])throw n=0,s=0,u(o[2]);return t=n,e=s,w(n,s)}finally{r.__wbindgen_free(t,e,1)}}loadInvention(t){let e=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),n=c,s=r.fugueengine_loadInvention(this.__wbg_ptr,e,n);if(s[1])throw u(s[0])}constructor(t){let e=r.fugueengine_new(t);return this.__wbg_ptr=e,q.register(this,this.__wbg_ptr,this),this}previewNotes(t,e){let n=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),s=c,o=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),_=c;return r.fugueengine_previewNotes(this.__wbg_ptr,n,s,o,_)}provideSample(t,e,n,s){let o,_;try{let g=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),d=c,b=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),y=c,h=f(n,r.__wbindgen_malloc,r.__wbindgen_realloc),x=c,U=J(s,r.__wbindgen_malloc),L=c,R=r.fugueengine_provideSample(this.__wbg_ptr,g,d,b,y,h,x,U,L);var a=R[0],l=R[1];if(R[3])throw a=0,l=0,u(R[2]);return o=a,_=l,w(a,l)}finally{r.__wbindgen_free(o,_,1)}}removeModule(t){let e=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),n=c,s=r.fugueengine_removeModule(this.__wbg_ptr,e,n);if(s[1])throw u(s[0])}renderInterleavedInto(t){let e=r.fugueengine_renderInterleavedInto(this.__wbg_ptr,t);if(e[2])throw u(e[1]);return e[0]>>>0}renderInterleaved(t){let e=r.fugueengine_renderInterleaved(this.__wbg_ptr,t);if(e[3])throw u(e[2]);var n=B(e[0],e[1]).slice();return r.__wbindgen_free(e[0],e[1]*4,4),n}reset(){let t=r.fugueengine_reset(this.__wbg_ptr);if(t[1])throw u(t[0])}sampleRate(){return r.fugueengine_sampleRate(this.__wbg_ptr)>>>0}setCodeModuleError(t,e){let n=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),s=c,o=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),_=c,a=r.fugueengine_setCodeModuleError(this.__wbg_ptr,n,s,o,_);if(a[1])throw u(a[0])}setCodeModuleStatus(t,e){let n=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),s=c,o=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),_=c,a=r.fugueengine_setCodeModuleStatus(this.__wbg_ptr,n,s,o,_);if(a[1])throw u(a[0])}setControlBool(t,e,n){let s=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),o=c,_=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c,l=r.fugueengine_setControlBool(this.__wbg_ptr,s,o,_,a,n);if(l[1])throw u(l[0])}setControlNumber(t,e,n){let s=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),o=c,_=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c,l=r.fugueengine_setControlNumber(this.__wbg_ptr,s,o,_,a,n);if(l[1])throw u(l[0])}setControlString(t,e,n){let s=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),o=c,_=f(e,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c,l=f(n,r.__wbindgen_malloc,r.__wbindgen_realloc),g=c,d=r.fugueengine_setControlString(this.__wbg_ptr,s,o,_,a,l,g);if(d[1])throw u(d[0])}setControls(t){let e,n;try{let _=f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),a=c,l=r.fugueengine_setControls(this.__wbg_ptr,_,a);var s=l[0],o=l[1];if(l[3])throw s=0,o=0,u(l[2]);return e=s,n=o,w(s,o)}finally{r.__wbindgen_free(e,n,1)}}setViewsClock(t){var e=F(t)?0:f(t,r.__wbindgen_malloc,r.__wbindgen_realloc),n=c;r.fugueengine_setViewsClock(this.__wbg_ptr,e,n)}status(){let t,e;try{let o=r.fugueengine_status(this.__wbg_ptr);var n=o[0],s=o[1];if(o[3])throw n=0,s=0,u(o[2]);return t=n,e=s,w(n,s)}finally{r.__wbindgen_free(t,e,1)}}takeLevels(){let t,e;try{let o=r.fugueengine_takeLevels(this.__wbg_ptr);var n=o[0],s=o[1];if(o[3])throw n=0,s=0,u(o[2]);return t=n,e=s,w(n,s)}finally{r.__wbindgen_free(t,e,1)}}takeViewsInto(t){let e=r.fugueengine_takeViewsInto(this.__wbg_ptr,t);if(e[2])throw u(e[1]);return e[0]!==0}static viewsLength(){return r.fugueengine_viewsLength()>>>0}};Symbol.dispose&&(v.prototype[Symbol.dispose]=v.prototype.free);function j(){return{__proto__:null,"./fugue_bg.js":{__proto__:null,__wbg___wbindgen_throw_41e9ee4f547fc59a:function(t,e){throw new Error(w(t,e))},__wbg__wbg_cb_unref_dcc1a90847f04c41:function(t){t._wbg_cb_unref()},__wbg_call_187d372bd5fdd4aa:function(){return W(function(t,e,n){return t.call(e,n)},arguments)},__wbg_getRandomValues_436a51d0629d84e1:function(){return W(function(t,e){globalThis.crypto.getRandomValues(V(t,e))},arguments)},__wbg_length_58572db4c38f3c3e:function(t){return t.length},__wbg_length_b5f0008bbf60cf59:function(t){return t.length},__wbg_new_5502aad30c185fc8:function(t,e){try{var n={a:t,b:e},s=(_,a)=>{let l=n.a;n.a=0;try{return N(l,n.b,_,a)}finally{n.a=l}};return new Promise(s)}finally{n.a=0}},__wbg_now_aa4ccb83129e9e55:function(){return Date.now()},__wbg_setTimeout_4bf75e1eaccfc9e2:function(t,e){return setTimeout(t,e)},__wbg_set_070bd465f1c195a4:function(t,e,n){t.set(B(e,n))},__wbg_set_8b5ae6cfd49dec9f:function(t,e,n){t.set(X(e,n))},__wbindgen_generic_0000000000000001:function(t,e){return H(t,e,z)},__wbindgen_generic_0000000000000002:function(t,e){return w(t,e)},__wbindgen_init_externref_table:function(){let t=r.__wbindgen_externrefs,e=t.grow(4);t.set(0,void 0),t.set(e+0,void 0),t.set(e+1,null),t.set(e+2,!0),t.set(e+3,!1)}}}}function z(i,t){r.wasm_bindgen__convert__closures_____invoke__hd2d6d321acd2ef74(i,t)}function N(i,t,e,n){r.wasm_bindgen__convert__closures_____invoke__h1b9b7a832ddda534(i,t,e,n)}var q=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>r.__wbg_fugueengine_free(i,1));function $(i){let t=r.__externref_table_alloc();return r.__wbindgen_externrefs.set(t,i),t}var I=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>r.__wbindgen_destroy_closure(i.a,i.b));function B(i,t){return i=i>>>0,Y().subarray(i/4,i/4+t)}function X(i,t){return i=i>>>0,G().subarray(i/8,i/8+t)}function V(i,t){return i=i>>>0,m().subarray(i/1,i/1+t)}var C=null;function Y(){return(C===null||C.byteLength===0)&&(C=new Float32Array(r.memory.buffer)),C}var A=null;function G(){return(A===null||A.byteLength===0)&&(A=new Float64Array(r.memory.buffer)),A}function w(i,t){return Q(i>>>0,t)}var M=null;function m(){return(M===null||M.byteLength===0)&&(M=new Uint8Array(r.memory.buffer)),M}function W(i,t){try{return i.apply(this,t)}catch(e){let n=$(e);r.__wbindgen_exn_store(n)}}function F(i){return i==null}function H(i,t,e){let n={a:i,b:t,cnt:1},s=(...o)=>{n.cnt++;let _=n.a;n.a=0;try{return e(_,n.b,...o)}finally{n.a=_,s._wbg_cb_unref()}};return s._wbg_cb_unref=()=>{--n.cnt===0&&(r.__wbindgen_destroy_closure(n.a,n.b),n.a=0,I.unregister(n))},I.register(s,n,n),s}function J(i,t){let e=t(i.length*1,1)>>>0;return m().set(i,e/1),c=i.length,e}function f(i,t,e){if(e===void 0){let a=T.encode(i),l=t(a.length,1)>>>0;return m().subarray(l,l+a.length).set(a),c=a.length,l}let n=i.length,s=t(n,1)>>>0,o=m(),_=0;for(;_<n;_++){let a=i.charCodeAt(_);if(a>127)break;o[s+_]=a}if(_!==n){_!==0&&(i=i.slice(_)),s=e(s,n,n=_+i.length*3,1)>>>0;let a=m().subarray(s+_,s+n),l=T.encodeInto(i,a);_+=l.written,s=e(s,n,_,1)>>>0}return c=_,s}function u(i){let t=r.__wbindgen_externrefs.get(i);return r.__externref_table_dealloc(i),t}var E=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});E.decode();var K=2146435072,S=0;function Q(i,t){return S+=t,S>=K&&(E=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),E.decode(),S=t),E.decode(m().subarray(i,i+t))}var T=new TextEncoder;"encodeInto"in T||(T.encodeInto=function(i,t){let e=T.encode(i);return t.set(e),{read:i.length,written:e.length}});var c=0,Z,ee,r;function ne(i,t){return ee=i,r=i.exports,Z=t,C=null,A=null,M=null,r.__wbindgen_start(),r}async function te(i,t){if(typeof Response=="function"&&i instanceof Response){if(!i.ok)throw new Error(`failed to fetch Wasm: ${i.status} ${i.statusText} fetching '${i.url}'`);if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(i,t)}catch(s){if(e(i.type)&&i.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",s);else throw s}let n=await i.arrayBuffer();return await WebAssembly.instantiate(n,t)}else{let n=await WebAssembly.instantiate(i,t);return n instanceof WebAssembly.Instance?{instance:n,module:i}:n}function e(n){switch(n){case"basic":case"cors":case"default":return!0}return!1}}async function O(i){if(r!==void 0)return r;i!==void 0&&(Object.getPrototypeOf(i)===Object.prototype?{module_or_path:i}=i:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),i===void 0&&(i=new URL("fugue_bg.wasm",re.url));let t=j();(typeof i=="string"||typeof Request=="function"&&i instanceof Request||typeof URL=="function"&&i instanceof URL)&&(i=fetch(i));let{instance:e,module:n}=await te(await i,t);return ne(e,n)}var k=class extends AudioWorkletProcessor{constructor(e){super();p(this,"engine",null);p(this,"ready",!1);p(this,"playing",!1);p(this,"renderBuffer",new Float32Array(0));p(this,"squares",new Float64Array(2));p(this,"squaredFrames",0);p(this,"missingClock",null);this.port.onmessage=n=>{this.handleMessage(n.data)},this.initialize(e?.processorOptions??{})}async initialize(e){try{await O({module_or_path:e.wasmBytes}),this.engine=new v(e.sampleRate??sampleRate),this.ready=!0,this.port.postMessage({type:"ready"})}catch(n){this.postError(n)}}handleMessage(e){if(!(!e||typeof e!="object")){if(e.type==="play"){this.playing=!0,this.port.postMessage({type:"state",state:"playing"});return}if(e.type==="stop"){this.playing=!1,this.port.postMessage({type:"state",state:"stopped"});return}if(e.type==="request")try{let n=this.handleRequest(e.method,e.args??[]);this.port.postMessage({type:"response",id:e.id,result:n})}catch(n){this.port.postMessage({type:"response",id:e.id,error:n instanceof Error?n.message:String(n)})}}}handleRequest(e,n){if(!this.ready||!this.engine)throw new Error("Fugue engine is not ready");switch(e){case"loadInvention":return this.engine.loadInvention(n[0]),this.restartReading(),null;case"reset":return this.engine.reset(),this.restartReading(),null;case"provideSample":return this.engine.provideSample(n[0],n[1],n[2],n[3]),null;case"status":return this.engine.status();case"listModules":return this.engine.listModules();case"listConnections":return this.engine.listConnections();case"applyEdits":return this.missingClock=null,this.engine.applyEdits(n[0]);case"listControls":return this.engine.listControls(n[0]);case"getControl":return this.engine.getControl(n[0],n[1]);case"views":return this.views(n[0]);case"setControl":return this.setControl(n[0],n[1],n[2]),null;default:throw new Error(`Unknown Fugue player method: ${e}`)}}views(e){let n=this.engine,s=n.takeLevels(),o=null;if(typeof e=="string"&&e!==this.missingClock)try{o=n.getControl(e,"elapsed")}catch{this.missingClock=e}let _={levels:s,beats:o,squares:[this.squares[0],this.squares[1]],frames:this.squaredFrames,time:currentTime};return this.squares[0]=0,this.squares[1]=0,this.squaredFrames=0,_}restartReading(){this.squares[0]=0,this.squares[1]=0,this.squaredFrames=0,this.missingClock=null}setControl(e,n,s){switch(typeof s){case"number":this.engine?.setControlNumber(e,n,s);return;case"boolean":this.engine?.setControlBool(e,n,s);return;case"string":this.engine?.setControlString(e,n,s);return}}process(e,n){let s=n[0],o=s?.[0],_=s?.[1];if(!o||!_)return!0;if(!this.playing||!this.ready||!this.engine)return o.fill(0),_.fill(0),!0;let a=o.length,l=a*2;this.renderBuffer.length!==l&&(this.renderBuffer=new Float32Array(l));try{this.engine.renderInterleavedInto(this.renderBuffer);let g=0,d=0;for(let b=0,y=0;b<a;b+=1,y+=2){let h=this.renderBuffer[y]??0,x=this.renderBuffer[y+1]??0;o[b]=h,_[b]=x,g+=h*h,d+=x*x}this.squares[0]+=g,this.squares[1]+=d,this.squaredFrames+=a}catch(g){this.playing=!1,o.fill(0),_.fill(0);try{this.engine.takeLevels()}catch{}this.restartReading(),this.postError(g)}return!0}postError(e){this.port.postMessage({type:"error",error:e instanceof Error?e.message:String(e)})}};registerProcessor("fugue-audio-worklet",k);})();
@@ -1 +1 @@
1
- {"version":3,"file":"embedded-assets.d.ts","sourceRoot":"","sources":["../../src/generated/embedded-assets.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,EAAE,MAAq6d,CAAC;AAE18d,eAAO,MAAM,kBAAkB,EAAE,MAAm8qhI,CAAC"}
1
+ {"version":3,"file":"embedded-assets.d.ts","sourceRoot":"","sources":["../../src/generated/embedded-assets.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,EAAE,MAAykhB,CAAC;AAE9mhB,eAAO,MAAM,kBAAkB,EAAE,MAAum/1I,CAAC"}