@ilusiv/fyug-js 2026.5.2 → 2026.11.1

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,6 +1,15 @@
1
1
  # @ilusiv/fyug-js
2
2
 
3
- Browser JavaScript bindings for the Fugue runtime.
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:
7
+ https://github.com/Ilusiv-media/fyug
8
+
9
+ The browser engine builds the module types listed in each release's
10
+ `fyug-player-modules.json`. Check a piece before loading it with
11
+ `unsupportedModuleTypes(invention, list)`, which names every type the list
12
+ lacks.
4
13
 
5
14
  ## Install
6
15
 
@@ -39,6 +48,32 @@ const player = await FuguePlayer.create({
39
48
  });
40
49
  ```
41
50
 
51
+ Each release's engine files are also served at stable, exact-version URLs from
52
+ the npm package, with `Access-Control-Allow-Origin: *`:
53
+
54
+ ```ts
55
+ const base = "https://cdn.jsdelivr.net/npm/@ilusiv/fyug-js@<version>/dist";
56
+ const player = await FuguePlayer.create({
57
+ wasmUrl: `${base}/generated/fugue_bg.wasm`,
58
+ workletUrl: `${base}/fugue-audio-worklet.js`,
59
+ });
60
+ ```
61
+
62
+ The worklet script is standalone (it imports nothing), and its bytes and the
63
+ wasm's match `fyug-player-worklet.js` and `fyug-player.wasm` in the release's
64
+ `SHA256SUMS.txt`. npm never changes a published version, so the bytes at a
65
+ version's URL never change.
66
+
67
+ ## Single-File Player
68
+
69
+ Each release also carries `fyug-player.html`, one self-contained page for
70
+ hosts that can show a page but not install anything (such as a chat
71
+ artifact). Put an invention's JSON as the text of its
72
+ `<script type="application/json" id="fyug-invention">` element, writing every
73
+ `<` as `\u003c`, then open it and press Play. It needs no network. It shows a
74
+ preview notice and refuses a piece that uses an unsupported module type,
75
+ naming the type.
76
+
42
77
  ## Custom Audio Routing
43
78
 
44
79
  Pass an existing `AudioContext` and destination node when an app needs to route
@@ -70,24 +105,22 @@ pnpm --filter @ilusiv/fyug-js test
70
105
  The package is published to npm as part of a product release, never from an
71
106
  ordinary push:
72
107
 
73
- 1. `Release` type-checks, tests and builds the package from the pinned core, runs
74
- `npm pack` and checks the tarball. If this `package.json` version is not on npm
75
- yet, it stages the tarball in the draft release with its checksum and
76
- provenance. Otherwise it stages nothing, so a product release never forces a
77
- player version bump.
108
+ 1. `Release` type-checks, tests and builds the package from the pinned core,
109
+ then `packaging/scripts/stage-browser-preview.sh` packs it at the product
110
+ release's version (the `version` in this `package.json` is not used) and
111
+ stages the tarball, its provenance and the preview files in the draft.
78
112
  2. `Promote Release` publishes that exact tarball with npm trusted publishing
79
113
  (OIDC). No npm token exists anywhere.
80
114
 
81
- To release a new player version, bump `version` here and run a product release.
115
+ So every product release `V` publishes `@ilusiv/fyug-js@V`.
82
116
 
83
- `@ilusiv/fyug-js` replaces `@ilusiv/fugue-js`, which stays on npm at 2026.5.2.
84
- npm offers trusted publishing settings only for a package that already exists,
85
- so publish the first `@ilusiv/fyug-js` version by hand. Run
86
- `pnpm --filter @ilusiv/fyug-js build`, then `npm publish --access public` in
87
- `packages/fugue-js`, from an npm account that owns the `@ilusiv` scope. Then
88
- configure trusted publishing and deprecate the old name:
117
+ `@ilusiv/fyug-js` replaces `@ilusiv/fugue-js`, which stays on npm at 2026.5.2
118
+ and is deprecated there. npm offers trusted publishing settings only for a
119
+ package that already exists; `@ilusiv/fyug-js` does (2026.5.2 was published by
120
+ hand on 2026-09-15), so trusted publishing can be configured now and no further
121
+ hand publish is needed. To make the old name point at the new one, run
89
122
  `npm deprecate @ilusiv/fugue-js "Renamed to @ilusiv/fyug-js"`.
90
123
 
91
124
  Trusted publishing is configured on npmjs.com under the package's settings:
92
- publisher GitHub Actions, repository `gdamron/fyug-product`, workflow
125
+ publisher GitHub Actions, repository `Ilusiv-media/fyug-product`, workflow
93
126
  `promote.yml`, environment `public-release`.
@@ -1,138 +1 @@
1
- import "./fugue-worklet-utf8.js";
2
- import init, { FugueEngine } from "./generated/fugue.js";
3
- class FugueAudioWorkletProcessor extends AudioWorkletProcessor {
4
- engine = null;
5
- ready = false;
6
- playing = false;
7
- renderBuffer = new Float32Array(0);
8
- constructor(options) {
9
- super();
10
- this.port.onmessage = (event) => {
11
- this.handleMessage(event.data);
12
- };
13
- void this.initialize(options?.processorOptions ?? {});
14
- }
15
- async initialize(options) {
16
- try {
17
- await init({
18
- module_or_path: options.wasmBytes,
19
- });
20
- this.engine = new FugueEngine(options.sampleRate ?? sampleRate);
21
- this.ready = true;
22
- this.port.postMessage({ type: "ready" });
23
- }
24
- catch (error) {
25
- this.postError(error);
26
- }
27
- }
28
- handleMessage(message) {
29
- if (!message || typeof message !== "object") {
30
- return;
31
- }
32
- if (message.type === "play") {
33
- this.playing = true;
34
- this.port.postMessage({ type: "state", state: "playing" });
35
- return;
36
- }
37
- if (message.type === "stop") {
38
- this.playing = false;
39
- this.port.postMessage({ type: "state", state: "stopped" });
40
- return;
41
- }
42
- if (message.type !== "request") {
43
- return;
44
- }
45
- try {
46
- const result = this.handleRequest(message.method, message.args ?? []);
47
- this.port.postMessage({ type: "response", id: message.id, result });
48
- }
49
- catch (error) {
50
- this.port.postMessage({
51
- type: "response",
52
- id: message.id,
53
- error: error instanceof Error ? error.message : String(error),
54
- });
55
- }
56
- }
57
- handleRequest(method, args) {
58
- if (!this.ready || !this.engine) {
59
- throw new Error("Fugue engine is not ready");
60
- }
61
- switch (method) {
62
- case "loadInvention":
63
- this.engine.loadInvention(args[0]);
64
- return null;
65
- case "reset":
66
- this.engine.reset();
67
- return null;
68
- case "status":
69
- return this.engine.status();
70
- case "listModules":
71
- return this.engine.listModules();
72
- case "listConnections":
73
- return this.engine.listConnections();
74
- case "listControls":
75
- return this.engine.listControls(args[0]);
76
- case "getControl":
77
- return this.engine.getControl(args[0], args[1]);
78
- case "setControl":
79
- this.setControl(args[0], args[1], args[2]);
80
- return null;
81
- default:
82
- throw new Error(`Unknown Fugue player method: ${method}`);
83
- }
84
- }
85
- setControl(moduleId, key, value) {
86
- switch (typeof value) {
87
- case "number":
88
- this.engine?.setControlNumber(moduleId, key, value);
89
- return;
90
- case "boolean":
91
- this.engine?.setControlBool(moduleId, key, value);
92
- return;
93
- case "string":
94
- this.engine?.setControlString(moduleId, key, value);
95
- return;
96
- }
97
- }
98
- process(_inputs, outputs) {
99
- const output = outputs[0];
100
- const left = output?.[0];
101
- const right = output?.[1];
102
- if (!left || !right) {
103
- return true;
104
- }
105
- if (!this.playing || !this.ready || !this.engine) {
106
- left.fill(0);
107
- right.fill(0);
108
- return true;
109
- }
110
- const frames = left.length;
111
- const sampleCount = frames * 2;
112
- if (this.renderBuffer.length !== sampleCount) {
113
- this.renderBuffer = new Float32Array(sampleCount);
114
- }
115
- try {
116
- this.engine.renderInterleavedInto(this.renderBuffer);
117
- for (let frame = 0, sample = 0; frame < frames; frame += 1, sample += 2) {
118
- left[frame] = this.renderBuffer[sample] ?? 0;
119
- right[frame] = this.renderBuffer[sample + 1] ?? 0;
120
- }
121
- }
122
- catch (error) {
123
- this.playing = false;
124
- left.fill(0);
125
- right.fill(0);
126
- this.postError(error);
127
- }
128
- return true;
129
- }
130
- postError(error) {
131
- this.port.postMessage({
132
- type: "error",
133
- error: error instanceof Error ? error.message : String(error),
134
- });
135
- }
136
- }
137
- registerProcessor("fugue-audio-worklet", FugueAudioWorkletProcessor);
138
- //# sourceMappingURL=fugue-audio-worklet.js.map
1
+ "use strict";(()=>{var W=Object.defineProperty;var O=(i,t,e)=>t in i?W(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var y=(i,t,e)=>O(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 l=(s&31)<<6|(e[++r]??0)&63;n+=String.fromCharCode(l)}else if((s&240)===224&&r+2<e.length){let l=(s&15)<<12|((e[++r]??0)&63)<<6|(e[++r]??0)&63;n+=String.fromCharCode(l)}else if((s&248)===240&&r+3<e.length){let l=(s&7)<<18|((e[++r]??0)&63)<<12|((e[++r]??0)&63)<<6|(e[++r]??0)&63;l-=65536,n+=String.fromCharCode(55296+(l>>10),56320+(l&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 $={},h=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,l=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),_=c;var a=S(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])}connect(t,e,n,r){let s=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c,_=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),a=c,g=f(n,o.__wbindgen_malloc,o.__wbindgen_realloc),u=c,b=f(r,o.__wbindgen_malloc,o.__wbindgen_realloc),M=c,p=o.fugueengine_connect(this.__wbg_ptr,s,l,_,a,g,u,b,M);if(p[1])throw d(p[0])}disconnect(t,e,n,r){let s=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),l=c,_=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),a=c,g=f(n,o.__wbindgen_malloc,o.__wbindgen_realloc),u=c,b=f(r,o.__wbindgen_malloc,o.__wbindgen_realloc),M=c,p=o.fugueengine_disconnect(this.__wbg_ptr,s,l,_,a,g,u,b,M);if(p[1])throw d(p[0])}finishAudioFileSink(t){let e,n;try{let l=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),_=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,w(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=B(r[0],r[1]).slice();return o.__wbindgen_free(r[0],r[1]*1,1),s}getCodeModuleConfig(t){let e,n;try{let l=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),_=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,w(r,s)}finally{o.__wbindgen_free(e,n,1)}}getControl(t,e){let n,r;try{let _=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),a=c,g=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),u=c,b=o.fugueengine_getControl(this.__wbg_ptr,_,a,g,u);var s=b[0],l=b[1];if(b[3])throw s=0,l=0,d(b[2]);return n=s,r=l,w(s,l)}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,w(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,w(n,r)}finally{o.__wbindgen_free(t,e,1)}}listControls(t){let e,n;try{var r=S(t)?0:f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),s=c;let a=o.fugueengine_listControls(this.__wbg_ptr,r,s);var l=a[0],_=a[1];if(a[3])throw l=0,_=0,d(a[2]);return e=l,n=_,w(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,w(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}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=F(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),l=c,_=o.fugueengine_setCodeModuleError(this.__wbg_ptr,n,r,s,l);if(_[1])throw d(_[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),l=c,_=o.fugueengine_setCodeModuleStatus(this.__wbg_ptr,n,r,s,l);if(_[1])throw d(_[0])}setControlBool(t,e,n){let r=f(t,o.__wbindgen_malloc,o.__wbindgen_realloc),s=c,l=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),_=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,l=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),_=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,l=f(e,o.__wbindgen_malloc,o.__wbindgen_realloc),_=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,w(n,r)}finally{o.__wbindgen_free(t,e,1)}}};Symbol.dispose&&(h.prototype[Symbol.dispose]=h.prototype.free);function k(){return{__proto__:null,"./fugue_bg.js":{__proto__:null,__wbg___wbindgen_throw_41e9ee4f547fc59a:function(t,e){throw new Error(w(t,e))},__wbg_getRandomValues_436a51d0629d84e1:function(){return D(function(t,e){globalThis.crypto.getRandomValues(B(t,e))},arguments)},__wbg_length_58572db4c38f3c3e:function(t){return t.length},__wbg_set_070bd465f1c195a4:function(t,e,n){t.set(F(e,n))},__wbindgen_generic_0000000000000001:function(t,e){return w(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)}}}}var R=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(i=>o.__wbg_fugueengine_free(i,1));function U(i){let t=o.__externref_table_alloc();return o.__wbindgen_externrefs.set(t,i),t}function F(i,t){return i=i>>>0,V().subarray(i/4,i/4+t)}function B(i,t){return i=i>>>0,v().subarray(i/1,i/1+t)}var m=null;function V(){return(m===null||m.byteLength===0)&&(m=new Float32Array(o.memory.buffer)),m}function w(i,t){return j(i>>>0,t)}var x=null;function v(){return(x===null||x.byteLength===0)&&(x=new Uint8Array(o.memory.buffer)),x}function D(i,t){try{return i.apply(this,t)}catch(e){let n=U(e);o.__wbindgen_exn_store(n)}}function S(i){return i==null}function f(i,t,e){if(e===void 0){let _=C.encode(i),a=t(_.length,1)>>>0;return v().subarray(a,a+_.length).set(_),c=_.length,a}let n=i.length,r=t(n,1)>>>0,s=v(),l=0;for(;l<n;l++){let _=i.charCodeAt(l);if(_>127)break;s[r+l]=_}if(l!==n){l!==0&&(i=i.slice(l)),r=e(r,n,n=l+i.length*3,1)>>>0;let _=v().subarray(r+l,r+n),a=C.encodeInto(i,_);l+=a.written,r=e(r,n,l,1)>>>0}return c=l,r}function d(i){let t=o.__wbindgen_externrefs.get(i);return o.__externref_table_dealloc(i),t}var A=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});A.decode();var P=2146435072,T=0;function j(i,t){return T+=t,T>=P&&(A=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),A.decode(),T=t),A.decode(v().subarray(i,i+t))}var C=new TextEncoder;"encodeInto"in C||(C.encodeInto=function(i,t){let e=C.encode(i);return t.set(e),{read:i.length,written:e.length}});var c=0,q,L,o;function z(i,t){return L=i,o=i.exports,q=t,m=null,x=null,o.__wbindgen_start(),o}async function N(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 I(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",$.url));let t=k();(typeof i=="string"||typeof Request=="function"&&i instanceof Request||typeof URL=="function"&&i instanceof URL)&&(i=fetch(i));let{instance:e,module:n}=await N(await i,t);return z(e,n)}var E=class extends AudioWorkletProcessor{constructor(e){super();y(this,"engine",null);y(this,"ready",!1);y(this,"playing",!1);y(this,"renderBuffer",new Float32Array(0));this.port.onmessage=n=>{this.handleMessage(n.data)},this.initialize(e?.processorOptions??{})}async initialize(e){try{await I({module_or_path:e.wasmBytes}),this.engine=new h(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"status":return this.engine.status();case"listModules":return this.engine.listModules();case"listConnections":return this.engine.listConnections();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],l=r?.[1];if(!s||!l)return!0;if(!this.playing||!this.ready||!this.engine)return s.fill(0),l.fill(0),!0;let _=s.length,a=_*2;this.renderBuffer.length!==a&&(this.renderBuffer=new Float32Array(a));try{this.engine.renderInterleavedInto(this.renderBuffer);for(let g=0,u=0;g<_;g+=1,u+=2)s[g]=this.renderBuffer[u]??0,l[g]=this.renderBuffer[u+1]??0}catch(g){this.playing=!1,s.fill(0),l.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",E);})();