faustwave 0.93.1 → 0.94.0

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.
Files changed (96) hide show
  1. package/README.md +48 -44
  2. package/dist/npm/faustwave.mjs +73 -18
  3. package/dist/npm/pagekit/pagekit.js +2347 -0
  4. package/dist/npm/pagekit/parts/device-button.glb +0 -0
  5. package/dist/npm/pagekit/parts/device-fader.glb +0 -0
  6. package/dist/npm/pagekit/parts/device-knob.glb +0 -0
  7. package/dist/npm/pagekit/parts/device-meter.glb +0 -0
  8. package/dist/npm/pagekit/parts/device-panel.glb +0 -0
  9. package/dist/npm/pagekit/parts/models-provenance.json +46 -0
  10. package/dist/npm/pagekit/player/THIRD-PARTY-NOTICES.md +12358 -0
  11. package/dist/npm/pagekit/player/assets/AppView-BV9Obknn.js +1 -0
  12. package/dist/npm/pagekit/player/assets/AppView-CdET0bgZ.css +1 -0
  13. package/dist/npm/pagekit/player/assets/FontLoader-C8xh6Irz.js +64 -0
  14. package/dist/npm/pagekit/player/assets/StageView-CSu--ASd.css +1 -0
  15. package/dist/npm/pagekit/player/assets/StageView-_SwGWnwx.js +1 -0
  16. package/dist/npm/pagekit/player/assets/actionRegistry-DrQhww6a.js +1 -0
  17. package/dist/npm/pagekit/player/assets/actionRegistry-hOkUYNvI.js +1 -0
  18. package/dist/npm/pagekit/player/assets/ahead-BNQHG1e8.js +1 -0
  19. package/dist/npm/pagekit/player/assets/api-BrGhAVvb.js +1 -0
  20. package/dist/npm/pagekit/player/assets/autoLayout-C5ue2K3x.js +1 -0
  21. package/dist/npm/pagekit/player/assets/bundledSources-2GoXdU5z.js +1 -0
  22. package/dist/npm/pagekit/player/assets/clapModule-CB6_36hc.js +1 -0
  23. package/dist/npm/pagekit/player/assets/client-DksDHYQL.js +1 -0
  24. package/dist/npm/pagekit/player/assets/codeEditorBridge-Bl202hrO.js +1 -0
  25. package/dist/npm/pagekit/player/assets/disclose-version-BvIhFN19.js +1 -0
  26. package/dist/npm/pagekit/player/assets/dist-BvRk9kiK.js +0 -0
  27. package/dist/npm/pagekit/player/assets/dist-DfaMbR-1.js +1 -0
  28. package/dist/npm/pagekit/player/assets/engine.worklet-BTB8yjdk.js +1865 -0
  29. package/dist/npm/pagekit/player/assets/engineCost.worker-Cv0PY3S-.js +2167 -0
  30. package/dist/npm/pagekit/player/assets/errors-BdUU2zPt.js +1 -0
  31. package/dist/npm/pagekit/player/assets/faust-analysis.nodepack-Bg1ixSAB.js +1 -0
  32. package/dist/npm/pagekit/player/assets/faust-physical-models.nodepack-DxbqTZII.js +1 -0
  33. package/dist/npm/pagekit/player/assets/faust-reverbs.nodepack-c-ZIKLrJ.js +1 -0
  34. package/dist/npm/pagekit/player/assets/faust-spatial.nodepack-C6GwVzOM.js +1 -0
  35. package/dist/npm/pagekit/player/assets/faust-vintage.nodepack-D8g5LX-U.js +1 -0
  36. package/dist/npm/pagekit/player/assets/faust.nodepack-Do7P1z0H.js +1 -0
  37. package/dist/npm/pagekit/player/assets/faustSource-Blr9zzKL.js +1 -0
  38. package/dist/npm/pagekit/player/assets/faustwasm-webclap-double-BX3OrOpF.js +1 -0
  39. package/dist/npm/pagekit/player/assets/faustwasm-webclap-double-Drn3DiHA.wasm +0 -0
  40. package/dist/npm/pagekit/player/assets/faustwasm.js +1 -0
  41. package/dist/npm/pagekit/player/assets/faustwave-conventions.nodepack-D2jA38Q6.js +1 -0
  42. package/dist/npm/pagekit/player/assets/fileMirror-CkgB9zNS.js +1 -0
  43. package/dist/npm/pagekit/player/assets/fileRef-BmnWhXuY.js +1 -0
  44. package/dist/npm/pagekit/player/assets/host-DPIuYxlL.js +1 -0
  45. package/dist/npm/pagekit/player/assets/instantiate-Dh0T46aH.js +1 -0
  46. package/dist/npm/pagekit/player/assets/inter-500.typeface-B6jxeZL_.js +21 -0
  47. package/dist/npm/pagekit/player/assets/inter-700.typeface-COCE0d_R.js +21 -0
  48. package/dist/npm/pagekit/player/assets/kernel-BErAMnKr.js +1 -0
  49. package/dist/npm/pagekit/player/assets/kernel-D6spGIFh.js +1 -0
  50. package/dist/npm/pagekit/player/assets/kernel-DKiI3Wqx.js +2 -0
  51. package/dist/npm/pagekit/player/assets/kit--nsV_OZy.js +1 -0
  52. package/dist/npm/pagekit/player/assets/kit-vVQ5cDnW.css +1 -0
  53. package/dist/npm/pagekit/player/assets/lazy-BkjipY-3.css +1 -0
  54. package/dist/npm/pagekit/player/assets/lazy-ClEpU-Ev.js +1 -0
  55. package/dist/npm/pagekit/player/assets/libraryFacts-B_z-Kv6i.js +1 -0
  56. package/dist/npm/pagekit/player/assets/mono-500.typeface-CuX9Pbhu.js +21 -0
  57. package/dist/npm/pagekit/player/assets/mono-700.typeface-BpIQdJao.js +21 -0
  58. package/dist/npm/pagekit/player/assets/newId-DuoSrkVn.js +1 -0
  59. package/dist/npm/pagekit/player/assets/notes-D-zF5qJ1.js +1 -0
  60. package/dist/npm/pagekit/player/assets/opfsStore-CXd1Yz_2.js +1 -0
  61. package/dist/npm/pagekit/player/assets/panic-ckha9YOX.js +1 -0
  62. package/dist/npm/pagekit/player/assets/patchSnippets-Dsccmpj6.js +1 -0
  63. package/dist/npm/pagekit/player/assets/paths-DFjX1bFA.js +1 -0
  64. package/dist/npm/pagekit/player/assets/player-CgcvekqS.js +2 -0
  65. package/dist/npm/pagekit/player/assets/playerApp-BmyTSXxw.js +2 -0
  66. package/dist/npm/pagekit/player/assets/playerApp-DO80EIpx.css +1 -0
  67. package/dist/npm/pagekit/player/assets/preArm-ifXM2Buj.js +1 -0
  68. package/dist/npm/pagekit/player/assets/preload-helper-9MKZsTCd.js +1 -0
  69. package/dist/npm/pagekit/player/assets/projectFiles-BEdLy3nE.js +1 -0
  70. package/dist/npm/pagekit/player/assets/projectPicker-mteZ2tiI.js +1 -0
  71. package/dist/npm/pagekit/player/assets/rocket-CgRnlVoE.js +1 -0
  72. package/dist/npm/pagekit/player/assets/runtime-36oA_YiG.js +1 -0
  73. package/dist/npm/pagekit/player/assets/runtime-7lvdeERt.js +1 -0
  74. package/dist/npm/pagekit/player/assets/runtime-BNLxaYPi.js +2 -0
  75. package/dist/npm/pagekit/player/assets/runtime-CL1M0Epi.js +1 -0
  76. package/dist/npm/pagekit/player/assets/runtime-bQsuRbRM.js +2 -0
  77. package/dist/npm/pagekit/player/assets/runtime-vj8wKnnG.js +1 -0
  78. package/dist/npm/pagekit/player/assets/runtime-wuc1seO8.js +1 -0
  79. package/dist/npm/pagekit/player/assets/scale-D2nqiPek.js +1 -0
  80. package/dist/npm/pagekit/player/assets/sha256-B9lHpAF4.js +1 -0
  81. package/dist/npm/pagekit/player/assets/soundfiles-DMZ8HKDZ.js +1 -0
  82. package/dist/npm/pagekit/player/assets/src-BvHr5YSH.js +2 -0
  83. package/dist/npm/pagekit/player/assets/src-Co7ihhBK.js +1 -0
  84. package/dist/npm/pagekit/player/assets/src-DyDfRe65.js +1 -0
  85. package/dist/npm/pagekit/player/assets/src-LMfGAjlj.js +1 -0
  86. package/dist/npm/pagekit/player/assets/stageWorker-ggqqFf5m.js +20869 -0
  87. package/dist/npm/pagekit/player/assets/store-CJdayqZa.js +1 -0
  88. package/dist/npm/pagekit/player/assets/sun-Bi-OgPry.js +1 -0
  89. package/dist/npm/pagekit/player/assets/time-aboh42pX.js +1 -0
  90. package/dist/npm/pagekit/player/assets/toasts-BCcM1yGS.js +1 -0
  91. package/dist/npm/pagekit/player/assets/toasts-ChPacqdd.js +1 -0
  92. package/dist/npm/pagekit/player/assets/transportFollow-Ox91SKLF.js +1 -0
  93. package/dist/npm/pagekit/player/favicon.svg +77 -0
  94. package/dist/npm/pagekit/player/files.json +1 -0
  95. package/dist/npm/pagekit/player/player.html +35 -0
  96. package/package.json +58 -43
@@ -0,0 +1,1865 @@
1
+ const t = 0, e = 1, s = 2, i = 4, n = 5, r = 10;
2
+ function o(t, e, s, i, n, r = 0, o = 0) {
3
+ t.setUint32(e, s, !0), t.setUint32(e + 4, i, !0), t.setUint16(e + 8, o, !0), t.setUint16(e + 10, n, !0), t.setUint32(e + 12, r, !0);
4
+ }
5
+ const a = {
6
+ volume: 0,
7
+ pan: 1,
8
+ tuning: 2,
9
+ vibrato: 3,
10
+ expression: 4,
11
+ brightness: 5,
12
+ pressure: 6
13
+ }, h = 1, l = 2, c = (t) => Math.min(127, Math.max(0, Math.round(127 * t)));
14
+ function u(t, e = 0) {
15
+ if (t.length < 1 || t.length > 3) return null;
16
+ const s = t[0];
17
+ if (s < 128 || 240 === s || 247 === s) return null;
18
+ const i = t[1] ?? 0, n = t[2] ?? 0, r = 15 & s;
19
+ switch (240 & s) {
20
+ case 144: return n > 0 ? {
21
+ time: e,
22
+ type: "on",
23
+ key: i,
24
+ channel: r,
25
+ velocity: n / 127
26
+ } : {
27
+ time: e,
28
+ type: "off",
29
+ key: i,
30
+ channel: r,
31
+ velocity: 0
32
+ };
33
+ case 128: return {
34
+ time: e,
35
+ type: "off",
36
+ key: i,
37
+ channel: r,
38
+ velocity: n / 127
39
+ };
40
+ case 160: return {
41
+ time: e,
42
+ type: "expression",
43
+ expression: "pressure",
44
+ key: i,
45
+ channel: r,
46
+ value: n / 127
47
+ };
48
+ case 208: return {
49
+ time: e,
50
+ type: "expression",
51
+ expression: "pressure",
52
+ key: -1,
53
+ channel: r,
54
+ value: i / 127
55
+ };
56
+ case 224: return {
57
+ time: e,
58
+ type: "expression",
59
+ expression: "tuning",
60
+ key: -1,
61
+ channel: r,
62
+ value: ((n << 7 | i) - 8192) / 8192 * 2
63
+ };
64
+ case 176: return 123 === i ? {
65
+ time: e,
66
+ type: "off",
67
+ key: -1,
68
+ channel: r,
69
+ velocity: 0
70
+ } : 120 === i ? {
71
+ time: e,
72
+ type: "choke",
73
+ key: -1,
74
+ channel: r
75
+ } : {
76
+ time: e,
77
+ type: "midi",
78
+ data: [
79
+ s,
80
+ i,
81
+ n
82
+ ]
83
+ };
84
+ default: return {
85
+ time: e,
86
+ type: "midi",
87
+ data: [
88
+ s,
89
+ i,
90
+ n
91
+ ]
92
+ };
93
+ }
94
+ }
95
+ function p(t) {
96
+ if ("midi" === t.type) return [[
97
+ t.data[0],
98
+ t.data[1],
99
+ t.data[2]
100
+ ]];
101
+ if ("on" !== t.type && "off" !== t.type && "choke" !== t.type && "expression" !== t.type) return [];
102
+ const e = (t.channel ?? 0) < 0 ? Array.from({ length: 16 }, (t, e) => e) : [t.channel ?? 0], s = t.key ?? -1;
103
+ return e.map((e) => {
104
+ switch (t.type) {
105
+ case "on": return s < 0 ? null : [
106
+ 144 | e,
107
+ s,
108
+ Math.max(1, c(t.velocity ?? 0))
109
+ ];
110
+ case "off": return s < 0 ? [
111
+ 176 | e,
112
+ 123,
113
+ 0
114
+ ] : [
115
+ 128 | e,
116
+ s,
117
+ c(t.velocity ?? 0)
118
+ ];
119
+ case "choke": return s < 0 ? [
120
+ 176 | e,
121
+ 120,
122
+ 0
123
+ ] : [
124
+ 128 | e,
125
+ s,
126
+ 0
127
+ ];
128
+ case "expression":
129
+ if ("pressure" === t.expression) return s < 0 ? [
130
+ 208 | e,
131
+ c(t.value),
132
+ 0
133
+ ] : [
134
+ 160 | e,
135
+ s,
136
+ c(t.value)
137
+ ];
138
+ if ("tuning" === t.expression && s < 0) {
139
+ const s = Math.min(16383, Math.max(0, Math.round(t.value / 2 * 8192 + 8192)));
140
+ return [
141
+ 224 | e,
142
+ 127 & s,
143
+ s >> 7
144
+ ];
145
+ }
146
+ return null;
147
+ }
148
+ }).filter((t) => null !== t);
149
+ }
150
+ function d(t, e) {
151
+ const s = [];
152
+ for (const i of t) if ("midi" !== e || "on" !== i.type && "off" !== i.type && "choke" !== i.type && "expression" !== i.type) if ("clap" === e && "midi" === i.type) {
153
+ const t = u(i.data, i.time);
154
+ t && s.push(t);
155
+ } else s.push(i);
156
+ else for (const t of p(i)) s.push({
157
+ time: i.time,
158
+ type: "midi",
159
+ data: t
160
+ });
161
+ return s;
162
+ }
163
+ function f(t) {
164
+ const e = [];
165
+ for (const s of t) {
166
+ const t = s.codePointAt(0);
167
+ t < 128 ? e.push(t) : t < 2048 ? e.push(192 | t >> 6, 128 | 63 & t) : t < 65536 ? e.push(224 | t >> 12, 128 | t >> 6 & 63, 128 | 63 & t) : e.push(240 | t >> 18, 128 | t >> 12 & 63, 128 | t >> 6 & 63, 128 | 63 & t);
168
+ }
169
+ return Uint8Array.from(e);
170
+ }
171
+ function g(t) {
172
+ let e = "";
173
+ for (let s = 0; s < t.length;) {
174
+ const i = t[s++];
175
+ let n = i;
176
+ i >= 240 ? n = (7 & i) << 18 | (63 & t[s++]) << 12 | (63 & t[s++]) << 6 | 63 & t[s++] : i >= 224 ? n = (15 & i) << 12 | (63 & t[s++]) << 6 | 63 & t[s++] : i >= 192 && (n = (31 & i) << 6 | 63 & t[s++]), e += String.fromCodePoint(n);
177
+ }
178
+ return e;
179
+ }
180
+ const m = 0, y = 8, w = 28, v = 52, b = 70, k = 2, x = 3, E = {
181
+ FD_READ: 2n,
182
+ FD_WRITE: 64n
183
+ }, U = 0, A = 1, _ = 1, I = 3;
184
+ const P = 512;
185
+ async function M(t) {
186
+ const e = function(t) {
187
+ const e = /* @__PURE__ */ new Map(), s = (e, s) => g(t.subarray(e, e + s)).replace(/\0.*$/s, "");
188
+ for (let r = 0; r + P <= t.length && !t.subarray(r, r + P).every((t) => 0 === t);) {
189
+ const i = s(r + 345, 155), n = (i ? `${i}/` : "") + s(r, 100), o = parseInt(s(r + 124, 12).trim() || "0", 8), a = t[r + 156];
190
+ r += P, 48 !== a && 0 !== a || e.set(n, new Uint8Array(t.subarray(r, r + o))), r += Math.ceil(o / P) * P;
191
+ }
192
+ const i = new Set([...e.keys()].map((t) => t.split("/")[0]));
193
+ if (1 !== i.size || [...e.keys()].some((t) => !t.includes("/"))) return e;
194
+ const [n] = i;
195
+ return new Map([...e].map(([t, e]) => [t.slice(n.length + 1), e]));
196
+ }(await async function(t) {
197
+ const e = new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"));
198
+ return new Uint8Array(await new Response(e).arrayBuffer());
199
+ }(t)), s = e.get("module.wasm");
200
+ if (!s) throw new Error(`the bundle has no module.wasm at its top (it has ${[...e.keys()].slice(0, 8).join(", ")})`);
201
+ return {
202
+ module: s,
203
+ files: e
204
+ };
205
+ }
206
+ const F = {
207
+ "clap.state": ["dirty"],
208
+ "clap.latency": ["latencyChanged"],
209
+ "clap.tail": ["tailChanged"],
210
+ "clap.audio-ports": ["portsFlag", "portsRescan"],
211
+ "clap.note-ports": ["dialects", "notesRescan"],
212
+ "clap.thread-check": ["isMain", "isAudio"],
213
+ "clap.gui": [
214
+ "hints",
215
+ "resize",
216
+ "show",
217
+ "hide",
218
+ "closed"
219
+ ],
220
+ "clap.preset-load/2": ["presetError", "presetLoaded"]
221
+ }, R = [
222
+ "size",
223
+ "get",
224
+ "write",
225
+ "read",
226
+ "push",
227
+ "ext",
228
+ "send",
229
+ "flush",
230
+ "rescan",
231
+ "log",
232
+ "restart",
233
+ "request",
234
+ "callback",
235
+ "clear",
236
+ "dirty",
237
+ "latencyChanged",
238
+ "tailChanged",
239
+ "portsFlag",
240
+ "portsRescan",
241
+ "dialects",
242
+ "notesRescan",
243
+ "isMain",
244
+ "isAudio",
245
+ "hints",
246
+ "resize",
247
+ "show",
248
+ "hide",
249
+ "closed",
250
+ "idxFiletype",
251
+ "idxLocation",
252
+ "idxSoundpack",
253
+ "idxExt",
254
+ "recError",
255
+ "recBegin",
256
+ "recPluginId",
257
+ "recSoundpack",
258
+ "recFlags",
259
+ "recCreator",
260
+ "recDescription",
261
+ "recTimestamps",
262
+ "recFeature",
263
+ "recExtra",
264
+ "presetError",
265
+ "presetLoaded"
266
+ ], S = 0, D = 8, C = 12, L = 16, $ = 20, O = 24, B = 28, N = 32, T = 36, W = 40, V = 44, z = [
267
+ 1,
268
+ 2,
269
+ 10
270
+ ], j = 0, H = 1, q = 12, G = 16, Y = 20, J = 24, K = 28, Q = 32, X = 36, Z = 40, tt = 44, et = 0, st = 4, it = 12, nt = 268, rt = 1296, ot = 1304, at = 1312, ht = 1320, lt = 112;
271
+ function ct(t, e, s) {
272
+ const i = {}, n = [];
273
+ let r = null;
274
+ for (const f of WebAssembly.Module.imports(t)) if ("wasi_snapshot_preview1" === f.module && "function" === f.kind) n.push(f.name);
275
+ else {
276
+ if ("memory" !== f.kind) throw "wasi" === f.module && "thread-spawn" === f.name ? /* @__PURE__ */ new Error("the plugin starts threads of its own (wasi thread-spawn): this host plays on one thread") : /* @__PURE__ */ new Error(`the plugin imports ${f.module}.${f.name} (${f.kind}), which this host does not offer (a WCLAP may import WASI and its memory)`);
277
+ {
278
+ const t = e;
279
+ if (!t || t.module !== f.module || t.name !== f.name) throw new Error(`the plugin imports a memory (${f.module}.${f.name}) whose limits are read from its bytes: load it from them (ClapHost.load)`);
280
+ if (t.shared && "undefined" == typeof SharedArrayBuffer) throw new Error("the plugin imports shared memory: it needs SharedArrayBuffer (in a browser, a cross-origin isolated page)");
281
+ r = new WebAssembly.Memory({
282
+ initial: t.initial,
283
+ maximum: t.maximum,
284
+ shared: t.shared
285
+ }), (i[f.module] ??= {})[f.name] = r;
286
+ }
287
+ }
288
+ const o = {
289
+ log: (t, e) => {},
290
+ inited: !1,
291
+ live: 0
292
+ };
293
+ n.length && (i.wasi_snapshot_preview1 = function(t, e) {
294
+ const s = () => new DataView(e.memory().buffer), i = () => new Uint8Array(e.memory().buffer), n = f(e.bundle), r = {
295
+ 1: [],
296
+ 2: []
297
+ }, o = (t) => {
298
+ const s = r[t];
299
+ r[t] = [], e.log(1 === t ? _ : I, g(Uint8Array.from(s)));
300
+ }, a = {
301
+ environ_sizes_get: (t, e) => (s().setUint32(t, 0, !0), s().setUint32(e, 0, !0), m),
302
+ environ_get: () => m,
303
+ clock_time_get: (t, e, i) => {
304
+ const n = t === U ? Date.now() : t === A ? globalThis.performance?.now() ?? Date.now() : NaN;
305
+ return Number.isNaN(n) ? w : (s().setBigUint64(i, BigInt(Math.round(1e6 * n)), !0), m);
306
+ },
307
+ random_get: (t, e) => {
308
+ const s = i().subarray(t, t + e), n = new Uint8Array(Math.min(e, 65536));
309
+ for (let i = 0; i < e; i += n.length) {
310
+ const t = n.subarray(0, Math.min(n.length, e - i));
311
+ if (globalThis.crypto?.getRandomValues) globalThis.crypto.getRandomValues(t);
312
+ else for (let e = 0; e < t.length; e++) t[e] = 256 * Math.random() | 0;
313
+ s.set(t, i);
314
+ }
315
+ return m;
316
+ },
317
+ fd_write: (t, e, n, a) => {
318
+ if (1 !== t && 2 !== t) return y;
319
+ const h = s(), l = i();
320
+ let c = 0;
321
+ for (let s = 0; s < n; s++) {
322
+ const i = h.getUint32(e + 8 * s, !0), n = h.getUint32(e + 8 * s + 4, !0);
323
+ for (let e = 0; e < n; e++) {
324
+ const s = l[i + e];
325
+ 10 === s ? o(t) : r[t].push(s);
326
+ }
327
+ c += n;
328
+ }
329
+ return h.setUint32(a, c, !0), m;
330
+ },
331
+ fd_read: (t, e, i, n) => 0 !== t ? y : (s().setUint32(n, 0, !0), m),
332
+ fd_seek: (t) => t <= 2 ? b : y,
333
+ fd_close: (t) => t <= 3 ? m : y,
334
+ fd_fdstat_get: (t, i) => {
335
+ if (t > 3) return y;
336
+ const n = s();
337
+ return new Uint8Array(e.memory().buffer, i, 24).fill(0), n.setUint8(i, 3 === t ? x : k), n.setBigUint64(i + 8, 0 === t ? E.FD_READ : 3 === t ? 0n : E.FD_WRITE, !0), m;
338
+ },
339
+ fd_prestat_get: (t, e) => {
340
+ if (3 !== t) return y;
341
+ const i = s();
342
+ return i.setUint8(e, 0), i.setUint32(e + 4, n.length, !0), m;
343
+ },
344
+ fd_prestat_dir_name: (t, e, s) => 3 !== t ? y : s < n.length ? w : (i().set(n, e), m),
345
+ sched_yield: () => m,
346
+ proc_exit: (t) => {
347
+ throw new Error(`the plugin called proc_exit(${t})`);
348
+ }
349
+ };
350
+ return Object.fromEntries(t.map((t) => [t, a[t] ?? (() => v)]));
351
+ }(n, {
352
+ memory: () => o.memory,
353
+ bundle: s,
354
+ log: (t, e) => o.log(t, e)
355
+ }));
356
+ const a = new WebAssembly.Instance(t, i).exports, h = Object.values(a).filter((t) => t instanceof WebAssembly.Table);
357
+ if (1 !== h.length) throw new Error(`a WCLAP exports exactly one function table (WebCLAP README); this one exports ${h.length}`);
358
+ const l = r ?? a.memory;
359
+ if (!(l instanceof WebAssembly.Memory)) throw new Error("the module has no memory: neither imported nor exported");
360
+ if (!(a.clap_entry instanceof WebAssembly.Global)) throw new Error("the module exports no clap_entry");
361
+ const c = a.clap_entry.value;
362
+ if ("number" != typeof c) throw new Error("a wasm64 WCLAP: this host plays wasm32 ones (the WebCLAP README: \"you should probably build your WCLAPs as wasm32\")");
363
+ const u = (t) => "function" == typeof a[t] ? a[t] : null, p = u("malloc"), d = u("cabi_realloc");
364
+ if (!p && !d) throw new Error("the module exports no malloc or cabi_realloc (WebCLAP README)");
365
+ const P = /* @__PURE__ */ new Map(), M = p ? (t) => p(t) : (t) => {
366
+ const e = d(0, 0, 8, t);
367
+ return P.set(e, t), e;
368
+ }, F = u("free"), R = F ? (t) => {
369
+ F(t);
370
+ } : d && !p ? (t) => {
371
+ d(t, P.get(t) ?? 0, 8, 0), P.delete(t);
372
+ } : () => {};
373
+ return Object.assign(o, {
374
+ memory: l,
375
+ table: h[0],
376
+ malloc: M,
377
+ free: R,
378
+ entry: c
379
+ }), u("_initialize")?.(), o;
380
+ }
381
+ var ut = class h {
382
+ static BUNDLE = "/plugin.wclap";
383
+ static NAME = "webclap-host";
384
+ static VENDOR = "webclap-host";
385
+ static URL = "https://github.com/crafics/webclap-host";
386
+ static VERSION = "0.1.0";
387
+ get toldHost() {
388
+ return this.told_;
389
+ }
390
+ onResize = null;
391
+ told_ = {
392
+ stateDirty: 0,
393
+ latencyChanged: 0,
394
+ tailChanged: 0,
395
+ portsRescan: 0,
396
+ notesRescan: 0,
397
+ resizeHints: 0,
398
+ resizeAsked: null,
399
+ guiClosed: 0,
400
+ presetsLoaded: 0,
401
+ presetErrors: []
402
+ };
403
+ restartAsked = 0;
404
+ processAsked = 0;
405
+ callbackDue = !1;
406
+ active = !1;
407
+ processing = !1;
408
+ steady = 0n;
409
+ descriptor;
410
+ plugins = [];
411
+ params = [];
412
+ audioIn;
413
+ audioOut;
414
+ inPorts = [];
415
+ outPorts = [];
416
+ notes;
417
+ notePorts = [];
418
+ get hasState() {
419
+ return !!this.stateExt;
420
+ }
421
+ page;
422
+ toPage = [];
423
+ flushesAsked = 0;
424
+ rescansAsked = 0;
425
+ logs = [];
426
+ x;
427
+ owned = /* @__PURE__ */ new Set();
428
+ host = 0;
429
+ hostWebview = 0;
430
+ hostParams = 0;
431
+ hostLog = 0;
432
+ hostExts = /* @__PURE__ */ new Map();
433
+ inAudio = !1;
434
+ guiMade = !1;
435
+ outEvents = [];
436
+ tell(t) {
437
+ this.outEvents.push(t), this.outEvents.length > 1024 && this.outEvents.splice(0, this.outEvents.length - 1024);
438
+ }
439
+ outputValues = /* @__PURE__ */ new Map();
440
+ readonlyIds = /* @__PURE__ */ new Set();
441
+ outRaw = [];
442
+ streamChunk = 0;
443
+ outList = 0;
444
+ plugin = 0;
445
+ paramsExt = 0;
446
+ entryAt = 0;
447
+ factoryAt = 0;
448
+ descAt = 0;
449
+ stateExt = 0;
450
+ events = [];
451
+ stream = [];
452
+ readAt = 0;
453
+ base = 0;
454
+ pool = 0;
455
+ poolRoom = 0;
456
+ list = 0;
457
+ transport = 0;
458
+ proc = 0;
459
+ activation = [];
460
+ ins = [];
461
+ outs = [];
462
+ scratch = 0;
463
+ frames = 0;
464
+ constructor(t, e) {
465
+ this.x = t, t.log = (t, e) => this.logs.push({
466
+ severity: t,
467
+ message: e
468
+ });
469
+ const s = t.table, i = new WebAssembly.Instance(new WebAssembly.Module(function() {
470
+ const t = (t) => [t.length, ...[...t].map((t) => t.charCodeAt(0))], e = (t) => t < 128 ? [t] : [127 & t | 128, ...e(t >>> 7)], s = (t, s) => [
471
+ t,
472
+ ...e(s.length),
473
+ ...s
474
+ ], i = R, n = [
475
+ 0,
476
+ 1,
477
+ 2,
478
+ 2,
479
+ 1,
480
+ 1,
481
+ 3,
482
+ 4,
483
+ 5,
484
+ 6,
485
+ 4,
486
+ 4,
487
+ 4,
488
+ 6,
489
+ 4,
490
+ 4,
491
+ 4,
492
+ 1,
493
+ 5,
494
+ 0,
495
+ 5,
496
+ 0,
497
+ 0,
498
+ 4,
499
+ 3,
500
+ 0,
501
+ 0,
502
+ 5,
503
+ 1,
504
+ 1,
505
+ 1,
506
+ 1,
507
+ 6,
508
+ 3,
509
+ 5,
510
+ 5,
511
+ 5,
512
+ 5,
513
+ 5,
514
+ 7,
515
+ 5,
516
+ 6,
517
+ 9,
518
+ 8
519
+ ], r = [
520
+ 1,
521
+ 2,
522
+ 3,
523
+ 3,
524
+ 2,
525
+ 2,
526
+ 3,
527
+ 1,
528
+ 2,
529
+ 3,
530
+ 1,
531
+ 1,
532
+ 1,
533
+ 3,
534
+ 1,
535
+ 1,
536
+ 1,
537
+ 2,
538
+ 2,
539
+ 1,
540
+ 2,
541
+ 1,
542
+ 1,
543
+ 1,
544
+ 3,
545
+ 1,
546
+ 1,
547
+ 2,
548
+ 2,
549
+ 2,
550
+ 2,
551
+ 2,
552
+ 3,
553
+ 3,
554
+ 2,
555
+ 2,
556
+ 2,
557
+ 2,
558
+ 2,
559
+ 3,
560
+ 2,
561
+ 3,
562
+ 6,
563
+ 4
564
+ ], o = i.map((t, e) => {
565
+ const s = [
566
+ 0,
567
+ ...Array.from({ length: r[e] }, (t, e) => [32, e]).flat(),
568
+ 16,
569
+ e,
570
+ 11
571
+ ];
572
+ return [s.length, ...s];
573
+ });
574
+ return new Uint8Array([
575
+ 0,
576
+ 97,
577
+ 115,
578
+ 109,
579
+ 1,
580
+ 0,
581
+ 0,
582
+ 0,
583
+ ...s(1, [
584
+ 10,
585
+ 96,
586
+ 1,
587
+ 127,
588
+ 1,
589
+ 127,
590
+ 96,
591
+ 2,
592
+ 127,
593
+ 127,
594
+ 1,
595
+ 127,
596
+ 96,
597
+ 3,
598
+ 127,
599
+ 127,
600
+ 126,
601
+ 1,
602
+ 126,
603
+ 96,
604
+ 3,
605
+ 127,
606
+ 127,
607
+ 127,
608
+ 1,
609
+ 127,
610
+ 96,
611
+ 1,
612
+ 127,
613
+ 0,
614
+ 96,
615
+ 2,
616
+ 127,
617
+ 127,
618
+ 0,
619
+ 96,
620
+ 3,
621
+ 127,
622
+ 127,
623
+ 127,
624
+ 0,
625
+ 96,
626
+ 3,
627
+ 127,
628
+ 126,
629
+ 126,
630
+ 0,
631
+ 96,
632
+ 4,
633
+ 127,
634
+ 127,
635
+ 127,
636
+ 127,
637
+ 0,
638
+ 96,
639
+ 6,
640
+ 127,
641
+ 127,
642
+ 127,
643
+ 127,
644
+ 127,
645
+ 127,
646
+ 0
647
+ ]),
648
+ ...s(2, [i.length, ...i.flatMap((e, s) => [
649
+ ...t("h"),
650
+ ...t(e),
651
+ 0,
652
+ n[s]
653
+ ])]),
654
+ ...s(3, [i.length, ...n]),
655
+ ...s(7, [i.length, ...i.flatMap((e, s) => [
656
+ ...t(e),
657
+ 0,
658
+ i.length + s
659
+ ])]),
660
+ ...s(10, [i.length, ...o.flat()])
661
+ ]);
662
+ }()), { h: {
663
+ size: () => this.events.length,
664
+ get: (t, e) => this.events[e],
665
+ write: (t, e, s) => {
666
+ const i = this.streamChunk ? Math.min(Number(s), this.streamChunk) : Number(s);
667
+ for (const n of new Uint8Array(this.x.memory.buffer, e, i)) this.stream.push(n);
668
+ return BigInt(i);
669
+ },
670
+ read: (t, e, s) => {
671
+ const i = Math.min(Number(s), this.stream.length - this.readAt, this.streamChunk || 1 / 0);
672
+ return new Uint8Array(this.x.memory.buffer).set(this.stream.slice(this.readAt, this.readAt + i), e), this.readAt += i, BigInt(i);
673
+ },
674
+ push: (t, e) => {
675
+ const s = this.view(), i = s.getUint16(e + 10, !0), n = s.getUint32(e + 16, !0);
676
+ return this.outRaw.push({
677
+ time: s.getUint32(e + 4, !0),
678
+ type: i,
679
+ space: s.getUint16(e + 8, !0)
680
+ }), 5 === i && this.readonlyIds.has(n) ? this.outputValues.set(n, s.getFloat64(e + 40, !0)) : 5 === i ? this.tell({
681
+ type: "value",
682
+ id: n,
683
+ value: s.getFloat64(e + 40, !0)
684
+ }) : 7 !== i && 8 !== i || this.tell({
685
+ type: 7 === i ? "begin" : "end",
686
+ id: n
687
+ }), 1;
688
+ },
689
+ ext: (t, e) => {
690
+ const s = this.cstr(e);
691
+ return "clap.webview/3" === s ? this.hostWebview : "clap.params" === s ? this.hostParams : "clap.log" === s ? this.hostLog : this.hostExts.get(s) ?? 0;
692
+ },
693
+ log: (t, e, s) => {
694
+ this.logs.push({
695
+ severity: e,
696
+ message: this.cstr(s)
697
+ });
698
+ },
699
+ flush: () => {
700
+ this.flushesAsked++;
701
+ },
702
+ rescan: (t, e) => {
703
+ 1 & e && this.rescansAsked++;
704
+ },
705
+ send: (t, e, s) => (this.toPage.push(new Uint8Array(this.x.memory.buffer.slice(e, e + s))), 1),
706
+ restart: () => {
707
+ this.restartAsked++;
708
+ },
709
+ request: () => {
710
+ this.processAsked++;
711
+ },
712
+ callback: () => {
713
+ this.callbackDue = !0;
714
+ },
715
+ clear: () => {},
716
+ dirty: () => {
717
+ this.told_.stateDirty++;
718
+ },
719
+ latencyChanged: () => {
720
+ this.told_.latencyChanged++;
721
+ },
722
+ tailChanged: () => {
723
+ this.told_.tailChanged++;
724
+ },
725
+ portsFlag: () => 0,
726
+ portsRescan: () => {
727
+ this.told_.portsRescan++;
728
+ },
729
+ dialects: () => 3,
730
+ notesRescan: () => {
731
+ this.told_.notesRescan++;
732
+ },
733
+ isMain: () => this.inAudio ? 0 : 1,
734
+ isAudio: () => this.inAudio ? 1 : 0,
735
+ hints: () => {
736
+ this.told_.resizeHints++;
737
+ },
738
+ resize: (t, e, s) => (this.told_.resizeAsked = {
739
+ width: e,
740
+ height: s
741
+ }, this.onResize?.(e, s) ? 1 : 0),
742
+ show: () => 0,
743
+ hide: () => 0,
744
+ closed: () => {
745
+ this.told_.guiClosed++;
746
+ },
747
+ idxFiletype: () => this.declared("declare_filetype"),
748
+ idxSoundpack: () => this.declared("declare_soundpack"),
749
+ idxLocation: (t, e) => {
750
+ if (!this.declared("declare_location")) return 0;
751
+ const s = this.view(), [i, n, r, o] = [
752
+ 0,
753
+ 4,
754
+ 8,
755
+ 12
756
+ ].map((t) => s.getUint32(e + t, !0)), a = o ? this.cstr(o) : null;
757
+ return r === j && null === a ? this.crawl.errors.push("The location may not be a null pointer with CLAP_PRESET_DISCOVERY_LOCATION_FILE.") : r !== j || a.startsWith("/") ? r === H && null !== a ? this.crawl.errors.push("The location must be a null pointer with CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN.") : r !== j && r !== H ? this.crawl.errors.push(`Unknown location kind ${r}.`) : this.crawl.locations.push({
758
+ flags: i,
759
+ name: n ? this.cstr(n) : "",
760
+ kind: r,
761
+ path: a
762
+ }) : this.crawl.errors.push(`'${a}' should be an absolute path, i.e. '/${a}'.`), 1;
763
+ },
764
+ idxExt: () => 0,
765
+ recError: (t, e, s) => {
766
+ this.crawl?.errors.push(`Load error occurred: OS error code ${e} with the following error message: ${s ? this.cstr(s) : ""}`);
767
+ },
768
+ recBegin: (t, e, s) => {
769
+ const i = this.crawl;
770
+ if (!i?.at) return i?.errors.push("'begin_preset()' outside 'get_metadata()'."), 0;
771
+ const n = e ? this.cstr(e) : null, r = s ? this.cstr(s) : null;
772
+ return i.single ? (i.errors.push("Calling 'begin_preset()' a second time for a non-container (no load key) preset file is not allowed"), 0) : i.keyed && null === r ? (i.errors.push("'begin_preset()' was called with a load key for the first time, and without a load key the second time. This is invalid behavior"), 0) : null === n && null !== r ? (i.errors.push("Container presets must specify a preset name"), 0) : (this.presetDone(), i.current = {
773
+ provider: i.provider,
774
+ name: n ?? (i.at.path ?? "").replace(/^.*\//, ""),
775
+ key: r,
776
+ location: {
777
+ kind: i.at.kind,
778
+ path: i.at.path
779
+ },
780
+ pluginIds: [],
781
+ flags: null
782
+ }, null === r ? i.single = !0 : i.keyed = !0, 1);
783
+ },
784
+ recPluginId: (t, e) => {
785
+ const s = this.presetOpen("add_plugin_id");
786
+ if (!s) return;
787
+ const i = this.cstr(this.u32(e));
788
+ "clap" !== i && "clap" === i.trim().toLowerCase() ? this.crawl.errors.push(`'${i}' was provided as an ABI argument. This is probably a typo. The expected value is 'clap' in all lowercase.`) : s.pluginIds.push({
789
+ abi: i,
790
+ id: this.cstr(this.u32(e + 4))
791
+ });
792
+ },
793
+ recFlags: (t, e) => {
794
+ const s = this.presetOpen("set_flags");
795
+ s && (s.flags = e);
796
+ },
797
+ recSoundpack: () => {
798
+ this.presetOpen("set_soundpack_id");
799
+ },
800
+ recCreator: () => {
801
+ this.presetOpen("add_creator");
802
+ },
803
+ recDescription: () => {
804
+ this.presetOpen("set_description");
805
+ },
806
+ recTimestamps: () => {
807
+ this.presetOpen("set_timestamps");
808
+ },
809
+ recFeature: () => {
810
+ this.presetOpen("add_feature");
811
+ },
812
+ recExtra: () => {
813
+ this.presetOpen("add_extra_info");
814
+ },
815
+ presetError: (t, e, s, i, n, r) => {
816
+ this.told_.presetErrors.push(`OS error code ${n}: ${r ? this.cstr(r) : ""}`);
817
+ },
818
+ presetLoaded: () => {
819
+ this.told_.presetsLoaded++;
820
+ }
821
+ } }).exports;
822
+ this.base = s.length, s.grow(R.length), R.forEach((t, e) => s.set(this.base + e, i[t])), this.host = this.take(48);
823
+ {
824
+ const t = [
825
+ h.NAME,
826
+ h.VENDOR,
827
+ h.URL,
828
+ h.VERSION
829
+ ].map((t) => this.text(t)), e = this.view();
830
+ z.forEach((t, s) => e.setUint32(this.host + 4 * s, t, !0)), e.setUint32(this.host + 12, 0, !0), t.forEach((t, s) => e.setUint32(this.host + 16 + 4 * s, t, !0)), e.setUint32(this.host + 32, this.base + 5, !0), e.setUint32(this.host + 36, this.base + 10, !0), e.setUint32(this.host + 40, this.base + 11, !0), e.setUint32(this.host + 44, this.base + 12, !0);
831
+ }
832
+ this.hostWebview = this.take(4), this.view().setUint32(this.hostWebview, this.base + 6, !0), this.hostParams = this.take(12), this.view().setUint32(this.hostParams, this.base + 8, !0), this.view().setUint32(this.hostParams + 4, this.base + 13, !0), this.view().setUint32(this.hostParams + 8, this.base + 7, !0), this.hostLog = this.take(4), this.view().setUint32(this.hostLog, this.base + 9, !0);
833
+ for (const [h, f] of Object.entries(F)) {
834
+ const t = this.take(4 * f.length);
835
+ f.forEach((e, s) => this.view().setUint32(t + 4 * s, this.base + R.indexOf(e), !0)), this.hostExts.set(h, t);
836
+ }
837
+ const n = t.entry;
838
+ if (!t.inited) {
839
+ if (!this.fn(this.u32(n + 12))(this.text(h.BUNDLE))) throw new Error("clap_entry.init failed");
840
+ t.inited = !0;
841
+ }
842
+ const r = this.fn(this.u32(n + 20))(this.text("clap.plugin-factory"));
843
+ if (!r) throw new Error("no plugin factory");
844
+ const o = this.fn(this.u32(r))(r), a = [];
845
+ for (let h = 0; h < o; h++) a.push(this.fn(this.u32(r + 4))(r, h));
846
+ if (this.plugins = a.map((t) => this.cstr(this.u32(t + q))), !a.length) throw new Error("the plugin factory offers no plugin");
847
+ const l = void 0 === e ? a[0] : a[this.plugins.indexOf(e)];
848
+ if (!l) throw new Error(`no plugin ${e} in this module (it has ${this.plugins.join(", ")})`);
849
+ [this.entryAt, this.factoryAt, this.descAt] = [
850
+ n,
851
+ r,
852
+ l
853
+ ];
854
+ const c = [];
855
+ for (let h = this.u32(l + tt); h && this.u32(h); h += 4) c.push(this.cstr(this.u32(h)));
856
+ if (this.descriptor = {
857
+ id: this.cstr(this.u32(l + q)),
858
+ name: this.cstr(this.u32(l + G)),
859
+ vendor: this.cstr(this.u32(l + Y)),
860
+ version: this.cstr(this.u32(l + X)),
861
+ features: c
862
+ }, this.plugin = this.fn(this.u32(r + 8))(r, this.host, this.u32(l + q)), !this.plugin) throw new Error("the factory made no plugin");
863
+ if (!this.fn(this.u32(this.plugin + D))(this.plugin)) throw this.pluginDestroy(), /* @__PURE__ */ new Error("the plugin did not start (init returned false)");
864
+ t.live++;
865
+ const u = this.extension("clap.audio-ports"), p = (t) => {
866
+ if (!u) return [];
867
+ const e = this.fn(this.u32(u))(this.plugin, t), s = this.take(296), i = [];
868
+ for (let n = 0; n < e; n++) i.push(this.fn(this.u32(u + 4))(this.plugin, n, t, s) ? this.u32(s + 264) : 0);
869
+ return this.give(s), i;
870
+ };
871
+ this.inPorts = p(!0), this.outPorts = p(!1), this.audioIn = this.inPorts[0] ?? 0, this.audioOut = this.outPorts[0] ?? 0;
872
+ const d = this.extension("clap.note-ports");
873
+ if (d) {
874
+ const t = this.fn(this.u32(d))(this.plugin, !0), e = this.take(268);
875
+ for (let s = 0; s < t; s++) this.fn(this.u32(d + 4))(this.plugin, s, !0, e) && this.notePorts.push({
876
+ supported: this.u32(e + 4),
877
+ preferred: this.u32(e + 8)
878
+ });
879
+ this.give(e);
880
+ }
881
+ if (this.notes = this.notePorts.length > 0, this.paramsExt = this.extension("clap.params"), this.stateExt = this.extension("clap.state"), this.page = !!this.extension("clap.gui") && !!this.extension("clap.webview/3"), this.poolRoom = 1024, this.pool = this.take(lt * this.poolRoom), this.list = this.take(12), this.view().setUint32(this.list, 0, !0), this.view().setUint32(this.list + 4, this.base, !0), this.view().setUint32(this.list + 8, this.base + 1, !0), this.outList = this.take(8), this.view().setUint32(this.outList, 0, !0), this.view().setUint32(this.outList + 4, this.base + 4, !0), this.scratch = this.take(ht), this.paramsExt) {
882
+ const t = this.fn(this.u32(this.paramsExt))(this.plugin);
883
+ for (let e = 0; e < t; e++) {
884
+ this.fn(this.u32(this.paramsExt + 4))(this.plugin, e, this.scratch);
885
+ const t = this.view();
886
+ this.params.push({
887
+ id: this.u32(this.scratch + et),
888
+ name: this.cstr(this.scratch + it),
889
+ min: t.getFloat64(this.scratch + rt, !0),
890
+ max: t.getFloat64(this.scratch + ot, !0),
891
+ init: t.getFloat64(this.scratch + at, !0),
892
+ stepped: !!(1 & this.u32(this.scratch + st)),
893
+ automatable: !!(32 & this.u32(this.scratch + st)),
894
+ named: !!(65536 & this.u32(this.scratch + st)),
895
+ readonly: !!(8 & this.u32(this.scratch + st)),
896
+ hidden: !!(4 & this.u32(this.scratch + st)),
897
+ module: this.cstr(this.scratch + nt)
898
+ });
899
+ }
900
+ for (const e of this.params) e.readonly && this.readonlyIds.add(e.id);
901
+ }
902
+ }
903
+ static async load(t, e) {
904
+ return h.of(await WebAssembly.compile(t), e, function(t) {
905
+ let e = 8;
906
+ const s = () => {
907
+ let s, i = 0, n = 0;
908
+ do
909
+ s = t[e++], i += (127 & s) * 2 ** n, n += 7;
910
+ while (128 & s);
911
+ return i;
912
+ }, i = () => {
913
+ const i = s(), n = String.fromCharCode(...t.subarray(e, e + i));
914
+ return e += i, n;
915
+ }, n = () => {
916
+ const i = t[e++];
917
+ return {
918
+ initial: s(),
919
+ maximum: 1 & i ? s() : void 0,
920
+ shared: !!(2 & i)
921
+ };
922
+ };
923
+ for (; e < t.length;) {
924
+ const r = t[e++], o = s(), a = e + o;
925
+ if (2 === r) {
926
+ for (let r = s(); r > 0; r--) {
927
+ const r = i(), o = i(), a = t[e++];
928
+ if (0 === a) s();
929
+ else if (1 === a) e++, n();
930
+ else {
931
+ if (2 === a) return {
932
+ module: r,
933
+ name: o,
934
+ ...n()
935
+ };
936
+ if (3 !== a) return null;
937
+ e += 2;
938
+ }
939
+ }
940
+ return null;
941
+ }
942
+ e = a;
943
+ }
944
+ return null;
945
+ }(t));
946
+ }
947
+ static async loadBundle(t, e) {
948
+ return h.load((await M(t)).module, e);
949
+ }
950
+ static of(t, e, s = null) {
951
+ return new h(ct(t, s, h.BUNDLE), e);
952
+ }
953
+ another(t) {
954
+ return new h(this.x, t);
955
+ }
956
+ activate(t, e, s = 120) {
957
+ if (!(t > 0)) throw new Error(`a sample rate of ${t}`);
958
+ if (!(e >= 1 && e <= 2147483647)) throw new Error(`a block of ${e} frames`);
959
+ if (this.active && this.deactivate(), this.frames = e, !this.pluginActivate(t, e)) throw new Error("activate failed");
960
+ this.active = !0, this.steady = 0n, this.runCallback();
961
+ for (const h of this.activation) this.give(h);
962
+ this.activation = [], this.ins = [], this.outs = [];
963
+ const i = (t) => {
964
+ const e = this.take(t);
965
+ return this.activation.push(e), e;
966
+ }, n = (t, s) => {
967
+ const n = i(24 * Math.max(t.length, 1));
968
+ return t.forEach((t, r) => {
969
+ const o = i(4 * Math.max(t, 1));
970
+ for (let n = 0; n < t; n++) {
971
+ const t = i(4 * e);
972
+ new Float32Array(this.x.memory.buffer, t, e).fill(0), 0 === r && s.push(t), this.view().setUint32(o + 4 * n, t, !0);
973
+ }
974
+ const a = this.view(), h = n + 24 * r;
975
+ a.setUint32(h, o, !0), a.setUint32(h + 4, 0, !0), a.setUint32(h + 8, t, !0), a.setUint32(h + 12, 0, !0), a.setBigUint64(h + 16, 0n, !0);
976
+ }), n;
977
+ }, r = n(this.inPorts, this.ins), o = n(this.outPorts, this.outs);
978
+ this.transport = i(104), this.proc = i(40);
979
+ const a = this.view();
980
+ new Uint8Array(this.x.memory.buffer, this.transport, 104).fill(0), a.setUint32(this.transport, 104, !0), a.setUint16(this.transport + 10, 9, !0), a.setUint32(this.transport + 16, 1, !0), a.setFloat64(this.transport + 40, s, !0), a.setUint32(this.proc + 8, e, !0), a.setUint32(this.proc + 12, this.transport, !0), a.setUint32(this.proc + 16, this.inPorts.length ? r : 0, !0), a.setUint32(this.proc + 20, this.outPorts.length ? o : 0, !0), a.setUint32(this.proc + 24, this.inPorts.length, !0), a.setUint32(this.proc + 28, this.outPorts.length, !0), a.setUint32(this.proc + 32, this.list, !0), a.setUint32(this.proc + 36, this.outList, !0);
981
+ }
982
+ process(t = [], e = []) {
983
+ this.events = this.inPool(t);
984
+ const s = new Float32Array(this.x.memory.buffer);
985
+ this.ins.forEach((t, i) => s.set(e[i]?.subarray(0, this.frames) ?? new Float32Array(this.frames), t / 4)), this.startIfStopped(), this.lastStatus = this.callProcess(), this.events = [];
986
+ const i = new Float32Array(this.x.memory.buffer);
987
+ return this.outs.map((t) => i.slice(t / 4, t / 4 + this.frames));
988
+ }
989
+ play(t) {
990
+ this.view().setUint32(this.transport + 16, 1 | (t ? 16 : 0), !0);
991
+ }
992
+ setTransport(t, e, s) {
993
+ const i = this.view();
994
+ i.setUint32(this.transport + 16, 3 | (t ? 16 : 0), !0), i.setBigInt64(this.transport + 24, BigInt(Math.round(2147483648 * s)), !0), i.setFloat64(this.transport + 40, e, !0);
995
+ }
996
+ render(t, e, s, i = [], n = []) {
997
+ if (s < 1 || s > this.frames) throw new Error(`a block of 1..${this.frames} frames`);
998
+ if (this.events = this.inPool(i), this.view().setUint32(this.proc + 8, s, !0), this.ins.length) {
999
+ const t = new Float32Array(this.x.memory.buffer);
1000
+ this.ins.forEach((i, r) => n[r] ? t.set(n[r].subarray(e, e + s), i / 4) : t.fill(0, i / 4, i / 4 + s));
1001
+ }
1002
+ this.startIfStopped(), this.lastStatus = this.callProcess(), this.events = [], this.view().setUint32(this.proc + 8, this.frames, !0);
1003
+ const r = new Float32Array(this.x.memory.buffer);
1004
+ for (let o = 0; o < t.length && o < this.outs.length; o++) t[o].set(r.subarray(this.outs[o] / 4, this.outs[o] / 4 + s), e);
1005
+ }
1006
+ pluginActivate(t, e) {
1007
+ return !!this.fn(this.u32(this.plugin + L))(this.plugin, t, 1, e);
1008
+ }
1009
+ pluginDeactivate() {
1010
+ this.fn(this.u32(this.plugin + $))(this.plugin);
1011
+ }
1012
+ pluginStart() {
1013
+ return this.audio(() => !!this.fn(this.u32(this.plugin + O))(this.plugin));
1014
+ }
1015
+ pluginStop() {
1016
+ this.audio(() => this.fn(this.u32(this.plugin + B))(this.plugin));
1017
+ }
1018
+ pluginReset() {
1019
+ this.audio(() => this.fn(this.u32(this.plugin + N))(this.plugin));
1020
+ }
1021
+ audio(t) {
1022
+ this.inAudio = !0;
1023
+ try {
1024
+ return t();
1025
+ } finally {
1026
+ this.inAudio = !1;
1027
+ }
1028
+ }
1029
+ pluginDestroy() {
1030
+ this.fn(this.u32(this.plugin + C))(this.plugin);
1031
+ }
1032
+ startIfStopped() {
1033
+ if (!this.active) throw new Error("process before activate");
1034
+ if (!this.processing && !this.startProcessing()) throw new Error("start_processing failed");
1035
+ }
1036
+ callProcess() {
1037
+ if (!this.processing) throw new Error("process while not processing");
1038
+ this.outRaw = [], this.view().setBigInt64(this.proc, this.steady, !0);
1039
+ const t = this.audio(() => this.fn(this.u32(this.plugin + T))(this.plugin, this.proc));
1040
+ return this.steady += BigInt(this.view().getUint32(this.proc + 8, !0)), this.runCallback(), t;
1041
+ }
1042
+ runCallback() {
1043
+ if (!this.callbackDue) return;
1044
+ this.callbackDue = !1;
1045
+ const t = this.u32(this.plugin + V);
1046
+ t && this.fn(t)(this.plugin);
1047
+ }
1048
+ lastStatus = 1;
1049
+ deactivate() {
1050
+ this.active && (this.processing && this.stopProcessing(), this.pluginDeactivate(), this.active = !1, this.runCallback());
1051
+ }
1052
+ startProcessing() {
1053
+ if (!this.active) throw new Error("start_processing before activate");
1054
+ return !!this.processing || (this.processing = this.pluginStart(), this.processing);
1055
+ }
1056
+ stopProcessing() {
1057
+ this.processing && (this.pluginStop(), this.processing = !1);
1058
+ }
1059
+ reset() {
1060
+ this.active && this.pluginReset();
1061
+ }
1062
+ destroy() {
1063
+ this.active && this.deactivate(), this.guiMade && this.fn(this.u32(this.need(this.extension("clap.gui"), "clap.gui") + 12))(this.plugin), this.pluginDestroy();
1064
+ for (const t of this.owned) this.x.free(t);
1065
+ this.owned.clear(), 0 === --this.x.live && this.x.inited && (this.fn(this.u32(this.x.entry + 16))(), this.x.inited = !1);
1066
+ }
1067
+ memoryBytes() {
1068
+ return this.x.memory.buffer.byteLength;
1069
+ }
1070
+ instanceDescriptorId() {
1071
+ return this.cstr(this.u32(this.u32(this.plugin + S) + q));
1072
+ }
1073
+ descriptorFields(t) {
1074
+ const e = "factory" === t ? this.descAt : this.u32(this.plugin + S), s = (t) => this.u32(e + t) ? this.cstr(this.u32(e + t)) : null, i = [];
1075
+ for (let n = this.u32(e + tt); n && this.u32(n); n += 4) i.push(this.cstr(this.u32(n)));
1076
+ return {
1077
+ id: s(q),
1078
+ name: s(G),
1079
+ vendor: s(Y),
1080
+ url: s(J),
1081
+ manual_url: s(K),
1082
+ support_url: s(Q),
1083
+ version: s(X),
1084
+ description: s(Z),
1085
+ features: i
1086
+ };
1087
+ }
1088
+ hasExtension(t) {
1089
+ return 0 !== this.extension(t);
1090
+ }
1091
+ hasFactory(t) {
1092
+ const e = this.text(t), s = this.fn(this.u32(this.entryAt + 20))(e);
1093
+ return this.give(e), 0 !== s;
1094
+ }
1095
+ creates(t) {
1096
+ const e = this.text(t), s = this.fn(this.u32(this.factoryAt + 8))(this.factoryAt, this.host, e);
1097
+ return this.give(e), s && this.fn(this.u32(s + C))(s), 0 !== s;
1098
+ }
1099
+ pushed() {
1100
+ const t = this.outRaw;
1101
+ return this.outRaw = [], t;
1102
+ }
1103
+ setTransportFull(t) {
1104
+ this.view().setUint32(this.proc + 12, t ? this.transport : 0, !0), t && function(t, e, s) {
1105
+ t.setUint32(e + 16, s.flags, !0), t.setBigInt64(e + 24, s.songPosBeats, !0), t.setBigInt64(e + 32, s.songPosSeconds, !0), t.setFloat64(e + 40, s.tempo, !0), t.setFloat64(e + 48, s.tempoInc, !0), t.setBigInt64(e + 56, s.loopStartBeats, !0), t.setBigInt64(e + 64, s.loopEndBeats, !0), t.setBigInt64(e + 72, s.loopStartSeconds, !0), t.setBigInt64(e + 80, s.loopEndSeconds, !0), t.setBigInt64(e + 88, s.barStart, !0), t.setInt32(e + 96, s.barNumber, !0), t.setUint16(e + 100, s.tsigNum, !0), t.setUint16(e + 102, s.tsigDenom, !0);
1106
+ }(this.view(), this.transport, t);
1107
+ }
1108
+ processChecked(t, e, s, i) {
1109
+ if (t < 1 || t > this.frames) throw new Error(`a block of 1..${this.frames} frames`);
1110
+ this.events = this.inPool(e);
1111
+ const n = new Float32Array(this.x.memory.buffer);
1112
+ this.ins.forEach((t, e) => n.set(s[e]?.subarray(0, this.frames) ?? new Float32Array(this.frames), t / 4));
1113
+ const r = new Uint32Array(this.x.memory.buffer);
1114
+ for (const c of this.outs) r.fill(i >>> 0, c / 4, c / 4 + this.frames);
1115
+ const o = this.view(), a = o.getUint32(this.proc + 20, !0);
1116
+ o.setBigUint64(a + 16, 0n, !0), o.setUint32(this.proc + 8, t, !0), this.startIfStopped();
1117
+ const h = this.callProcess();
1118
+ this.lastStatus = h, this.events = [], this.view().setUint32(this.proc + 8, this.frames, !0);
1119
+ const l = new Float32Array(this.x.memory.buffer);
1120
+ return {
1121
+ status: h,
1122
+ inputs: this.ins.map((t) => l.slice(t / 4, t / 4 + this.frames)),
1123
+ outputs: this.outs.map((t) => l.slice(t / 4, t / 4 + this.frames)),
1124
+ constantMask: this.view().getBigUint64(a + 16, !0)
1125
+ };
1126
+ }
1127
+ value(t) {
1128
+ return this.need(this.paramsExt, "clap.params"), this.fn(this.u32(this.paramsExt + 8))(this.plugin, t, this.scratch), this.view().getFloat64(this.scratch, !0);
1129
+ }
1130
+ valueToText(t, e) {
1131
+ return this.need(this.paramsExt, "clap.params"), this.fn(this.u32(this.paramsExt + 12))(this.plugin, t, e, this.scratch, 256) ? this.cstr(this.scratch) : null;
1132
+ }
1133
+ textToValue(t, e) {
1134
+ this.need(this.paramsExt, "clap.params");
1135
+ const s = this.text(e), i = this.fn(this.u32(this.paramsExt + 16))(this.plugin, t, s, this.scratch);
1136
+ return this.give(s), i ? this.view().getFloat64(this.scratch, !0) : null;
1137
+ }
1138
+ flush(t = []) {
1139
+ this.need(this.paramsExt, "clap.params"), this.events = this.inPool(t);
1140
+ const e = () => this.fn(this.u32(this.paramsExt + 20))(this.plugin, this.list, this.outList);
1141
+ this.active ? this.audio(e) : e(), this.events = [];
1142
+ }
1143
+ output(t) {
1144
+ return this.outputValues.get(t);
1145
+ }
1146
+ told() {
1147
+ const t = this.outEvents;
1148
+ return this.outEvents = [], t;
1149
+ }
1150
+ latency() {
1151
+ if (!this.active) throw new Error("latency before activate");
1152
+ const t = this.extension("clap.latency");
1153
+ return t ? this.fn(this.u32(t))(this.plugin) >>> 0 : null;
1154
+ }
1155
+ tail() {
1156
+ if (!this.active) throw new Error("tail before activate");
1157
+ const t = this.extension("clap.tail");
1158
+ return t ? this.fn(this.u32(t))(this.plugin) >>> 0 : null;
1159
+ }
1160
+ remotePages() {
1161
+ const t = this.extension("clap.remote-controls/2");
1162
+ if (!t) return null;
1163
+ const e = [], s = this.fn(this.u32(t))(this.plugin) >>> 0, i = this.take(552);
1164
+ for (let n = 0; n < s; n++) {
1165
+ if (!this.fn(this.u32(t + 4))(this.plugin, n, i)) throw new Error(`clap.remote-controls get ${n} failed`);
1166
+ e.push({
1167
+ section: this.cstr(i),
1168
+ id: this.u32(i + 256),
1169
+ name: this.cstr(i + 260),
1170
+ params: Array.from({ length: 8 }, (t, e) => this.u32(i + 516 + 4 * e)),
1171
+ forPreset: 0 !== this.view().getUint8(i + 548)
1172
+ });
1173
+ }
1174
+ return this.give(i), e;
1175
+ }
1176
+ noteNames() {
1177
+ const t = this.extension("clap.note-name");
1178
+ if (!t) return null;
1179
+ const e = [], s = this.fn(this.u32(t))(this.plugin) >>> 0, i = this.take(262);
1180
+ for (let n = 0; n < s; n++) {
1181
+ if (!this.fn(this.u32(t + 4))(this.plugin, n, i)) throw new Error(`clap.note-name get ${n} failed`);
1182
+ const s = this.view();
1183
+ e.push({
1184
+ name: this.cstr(i),
1185
+ port: s.getInt16(i + 256, !0),
1186
+ key: s.getInt16(i + 258, !0),
1187
+ channel: s.getInt16(i + 260, !0)
1188
+ });
1189
+ }
1190
+ return this.give(i), e;
1191
+ }
1192
+ voiceInfo() {
1193
+ const t = this.extension("clap.voice-info");
1194
+ if (!t) return null;
1195
+ const e = this.take(16);
1196
+ if (!this.fn(this.u32(t))(this.plugin, e)) throw new Error("clap.voice-info get failed");
1197
+ const s = this.view(), i = {
1198
+ count: s.getUint32(e, !0),
1199
+ capacity: s.getUint32(e + 4, !0),
1200
+ flags: Number(s.getBigUint64(e + 8, !0))
1201
+ };
1202
+ return this.give(e), i;
1203
+ }
1204
+ pageUri() {
1205
+ const t = this.need(this.extension("clap.webview/3"), "clap.webview/3"), e = this.fn(this.u32(t))(this.plugin, 0, 0), s = this.take(e);
1206
+ this.fn(this.u32(t))(this.plugin, s, e);
1207
+ const i = this.cstr(s);
1208
+ return this.give(s), i;
1209
+ }
1210
+ pageSize() {
1211
+ const t = this.need(this.extension("clap.gui"), "clap.gui");
1212
+ if (!this.guiMade) {
1213
+ const e = this.text("webview"), s = !!this.fn(this.u32(t + 8))(this.plugin, e, !1);
1214
+ if (this.give(e), !s) throw new Error("the plugin made no webview gui (clap.gui create)");
1215
+ this.guiMade = !0;
1216
+ }
1217
+ const e = this.take(8), s = this.fn(this.u32(t + 20))(this.plugin, e, e + 4), i = {
1218
+ width: this.u32(e),
1219
+ height: this.u32(e + 4)
1220
+ };
1221
+ if (this.give(e), !s) throw new Error("no size");
1222
+ return i;
1223
+ }
1224
+ presets() {
1225
+ const t = ["clap.preset-discovery-factory/2", "clap.preset-discovery-factory/draft-2"].map((t) => {
1226
+ const e = this.text(t), s = this.fn(this.u32(this.entryAt + 20))(e);
1227
+ return this.give(e), s;
1228
+ }).find((t) => 0 !== t);
1229
+ if (!t) return null;
1230
+ const e = [], s = [], i = [], n = [
1231
+ h.NAME,
1232
+ h.VENDOR,
1233
+ h.URL,
1234
+ h.VERSION
1235
+ ].map((t) => this.text(t)), r = this.take(48), o = this.take(44);
1236
+ {
1237
+ const t = this.view();
1238
+ z.forEach((e, s) => t.setUint32(r + 4 * s, e, !0)), n.forEach((e, s) => t.setUint32(r + 12 + 4 * s, e, !0)), t.setUint32(r + 28, 0, !0), [
1239
+ "idxFiletype",
1240
+ "idxLocation",
1241
+ "idxSoundpack",
1242
+ "idxExt"
1243
+ ].forEach((e, s) => t.setUint32(r + 32 + 4 * s, this.base + R.indexOf(e), !0)), t.setUint32(o, 0, !0), [
1244
+ "recError",
1245
+ "recBegin",
1246
+ "recPluginId",
1247
+ "recSoundpack",
1248
+ "recFlags",
1249
+ "recCreator",
1250
+ "recDescription",
1251
+ "recTimestamps",
1252
+ "recFeature",
1253
+ "recExtra"
1254
+ ].forEach((e, s) => t.setUint32(o + 4 + 4 * s, this.base + R.indexOf(e), !0));
1255
+ }
1256
+ const a = (t) => {
1257
+ const e = (e) => this.u32(t + e) ? this.cstr(this.u32(t + e)) : null;
1258
+ return {
1259
+ id: e(12),
1260
+ name: e(16),
1261
+ vendor: e(20)
1262
+ };
1263
+ }, l = this.fn(this.u32(t))(t);
1264
+ for (let h = 0; h < l; h++) {
1265
+ const n = this.fn(this.u32(t + 4))(t, h);
1266
+ if (!n) {
1267
+ e.push(`'clap_preset_discovery_factory::get_descriptor()' returned a null pointer for index ${h}.`);
1268
+ continue;
1269
+ }
1270
+ const l = a(n);
1271
+ if (!l.id || !l.name) {
1272
+ e.push(`The provider descriptor at index ${h} has no ${l.id ? "name" : "id"}.`);
1273
+ continue;
1274
+ }
1275
+ const c = this.text(l.id);
1276
+ this.crawl = {
1277
+ provider: l.id,
1278
+ errors: e,
1279
+ locations: [],
1280
+ init: !0,
1281
+ at: null,
1282
+ single: !1,
1283
+ keyed: !1,
1284
+ current: null,
1285
+ presets: i
1286
+ };
1287
+ const u = this.fn(this.u32(t + 8))(t, r, c);
1288
+ if (this.give(c), !u) {
1289
+ e.push(`'clap_preset_discovery_factory::create()' returned a null pointer for the provider with ID '${l.id}'.`);
1290
+ continue;
1291
+ }
1292
+ const p = this.u32(u) ? a(this.u32(u)) : null;
1293
+ p || e.push("The 'desc' field on the 'clap_preset_provider' struct is a null pointer."), s.push({
1294
+ id: l.id,
1295
+ name: l.name,
1296
+ vendor: l.vendor ?? "",
1297
+ sameDescriptor: !!p && p.id === l.id && p.name === l.name && p.vendor === l.vendor
1298
+ });
1299
+ const d = !!this.fn(this.u32(u + 8))(u);
1300
+ if (this.crawl.init = !1, d) for (const t of this.crawl.locations) {
1301
+ Object.assign(this.crawl, {
1302
+ at: t,
1303
+ single: !1,
1304
+ keyed: !1,
1305
+ current: null
1306
+ });
1307
+ const s = null === t.path ? 0 : this.text(t.path), i = this.fn(this.u32(u + 16))(u, t.kind, s, o);
1308
+ s && this.give(s), this.presetDone(), i || e.push(`The preset provider returned false when fetching metadata for ${t.path ?? "<plugin>"}.`);
1309
+ }
1310
+ else e.push(`'clap_preset_discovery_provider::init()' returned false for the provider with ID '${l.id}'.`);
1311
+ this.fn(this.u32(u + 12))(u), this.crawl = null;
1312
+ }
1313
+ for (const h of [
1314
+ r,
1315
+ o,
1316
+ ...n
1317
+ ]) this.give(h);
1318
+ if (e.length) throw new Error(e.join("\n"));
1319
+ return {
1320
+ providers: s,
1321
+ presets: i
1322
+ };
1323
+ }
1324
+ loadPreset(t) {
1325
+ const e = this.need(this.extension("clap.preset-load/2"), "clap.preset-load/2"), s = null === t.location.path ? 0 : this.text(t.location.path), i = null === t.key ? 0 : this.text(t.key), n = !!this.fn(this.u32(e))(this.plugin, t.location.kind, s, i);
1326
+ return s && this.give(s), i && this.give(i), n;
1327
+ }
1328
+ declared(t) {
1329
+ return this.crawl?.init ? 1 : (this.crawl?.errors.push(`Attempt to add to the indexer after the 'clap_preset_discovery_factory::init' call (${t})`), 0);
1330
+ }
1331
+ presetOpen(t) {
1332
+ return this.crawl?.current ? this.crawl.current : (this.crawl?.errors.push(`No preceding 'begin_preset()' call. This is not valid. (${t})`), null);
1333
+ }
1334
+ presetDone() {
1335
+ const t = this.crawl;
1336
+ t?.current && (t.current.pluginIds.length ? t.presets.push(t.current) : t.errors.push(`The preset '${t.current.name}' was defined without setting a plugin ID.`), t.current = null);
1337
+ }
1338
+ crawl = null;
1339
+ fromPage(t) {
1340
+ const e = this.need(this.extension("clap.webview/3"), "clap.webview/3"), s = this.take(Math.max(t.length, 1));
1341
+ new Uint8Array(this.x.memory.buffer).set(t, s);
1342
+ const i = !!this.fn(this.u32(e + 8))(this.plugin, s, t.length);
1343
+ return this.give(s), i;
1344
+ }
1345
+ saveState() {
1346
+ if (!this.stateExt) return null;
1347
+ const t = this.stateStream(2);
1348
+ this.stream = [];
1349
+ const e = this.fn(this.u32(this.stateExt))(this.plugin, t);
1350
+ return this.give(t), e ? new Uint8Array(this.stream) : null;
1351
+ }
1352
+ loadState(t) {
1353
+ if (!this.stateExt) return !1;
1354
+ const e = this.stateStream(3);
1355
+ this.stream = [...t], this.readAt = 0;
1356
+ const s = !!this.fn(this.u32(this.stateExt + 4))(this.plugin, e);
1357
+ return this.give(e), s;
1358
+ }
1359
+ view() {
1360
+ return new DataView(this.x.memory.buffer);
1361
+ }
1362
+ u32(t) {
1363
+ return this.view().getUint32(t, !0);
1364
+ }
1365
+ fn(t) {
1366
+ return this.x.table.get(t);
1367
+ }
1368
+ cstr(t) {
1369
+ const e = new Uint8Array(this.x.memory.buffer);
1370
+ let s = t;
1371
+ for (; e[s];) s++;
1372
+ return g(e.subarray(t, s));
1373
+ }
1374
+ text(t) {
1375
+ const e = f(t), s = this.take(e.length + 1), i = new Uint8Array(this.x.memory.buffer);
1376
+ return i.set(e, s), i[s + e.length] = 0, s;
1377
+ }
1378
+ extension(t) {
1379
+ const e = this.text(t), s = this.fn(this.u32(this.plugin + W))(this.plugin, e);
1380
+ return this.give(e), s;
1381
+ }
1382
+ need(t, e) {
1383
+ if (!t) throw new Error(`the plugin has no ${e}`);
1384
+ return t;
1385
+ }
1386
+ inPool(t) {
1387
+ return t.length > this.poolRoom && (this.give(this.pool), this.poolRoom = Math.max(t.length, 2 * this.poolRoom), this.pool = this.take(lt * this.poolRoom)), t.map((t, e) => this.event(t, this.pool + e * lt));
1388
+ }
1389
+ take(t) {
1390
+ const e = this.x.malloc(t);
1391
+ return this.owned.add(e), e;
1392
+ }
1393
+ give(t) {
1394
+ this.owned.delete(t), this.x.free(t);
1395
+ }
1396
+ stateStream(t) {
1397
+ const e = this.take(8);
1398
+ return this.view().setUint32(e, 0, !0), this.view().setUint32(e + 4, this.base + t, !0), e;
1399
+ }
1400
+ event(h, l) {
1401
+ const c = this.view();
1402
+ if (new Uint8Array(this.x.memory.buffer, l, lt).fill(0), "raw" === h.type) {
1403
+ if (h.bytes.length > lt) throw new Error("an event of at most 112 bytes");
1404
+ return new Uint8Array(this.x.memory.buffer).set(h.bytes, l), l;
1405
+ }
1406
+ if ("param" === h.type) (function(t, e, s, i, r, a = {}) {
1407
+ o(t, e, 48, s, n, a.flags ?? 0, a.space ?? 0), t.setUint32(e + 16, i, !0), t.setUint32(e + 20, 0, !0), t.setInt32(e + 24, a.noteId ?? -1, !0), t.setInt16(e + 28, a.port ?? -1, !0), t.setInt16(e + 30, a.channel ?? -1, !0), t.setInt16(e + 32, a.key ?? -1, !0), t.setFloat64(e + 40, r, !0);
1408
+ })(c, l, h.time, h.id, h.value);
1409
+ else if ("midi" === h.type) (function(t, e, s, i, n, a = 0) {
1410
+ o(t, e, 24, s, r, a), t.setUint16(e + 16, i, !0);
1411
+ for (let r = 0; r < 3; r++) t.setUint8(e + 18 + r, n[r]);
1412
+ })(c, l, h.time, 0, h.data);
1413
+ else if ("expression" === h.type) (function(t, e, s, n, r, a, h = 0) {
1414
+ o(t, e, 40, s, i, h), t.setInt32(e + 16, r, !0), t.setInt32(e + 20, n.noteId, !0), t.setInt16(e + 24, n.port, !0), t.setInt16(e + 26, n.channel, !0), t.setInt16(e + 28, n.key, !0), t.setFloat64(e + 32, a, !0);
1415
+ })(c, l, h.time, {
1416
+ noteId: h.noteId ?? -1,
1417
+ port: h.port ?? -1,
1418
+ channel: h.channel ?? -1,
1419
+ key: h.key ?? -1
1420
+ }, a[h.expression], h.value);
1421
+ else {
1422
+ const i = "on" === h.type ? t : "off" === h.type ? e : s;
1423
+ (function(t, e, s, i, n, r, a = 0) {
1424
+ o(t, e, 40, s, i, a), t.setInt32(e + 16, n.noteId, !0), t.setInt16(e + 20, n.port, !0), t.setInt16(e + 22, n.channel, !0), t.setInt16(e + 24, n.key, !0), t.setFloat64(e + 32, r, !0);
1425
+ })(c, l, h.time, i, {
1426
+ noteId: h.noteId ?? -1,
1427
+ port: h.port ?? 0,
1428
+ channel: h.channel ?? 0,
1429
+ key: h.key
1430
+ }, h.velocity ?? 0);
1431
+ }
1432
+ return l;
1433
+ }
1434
+ };
1435
+ function pt(t, e, s) {
1436
+ return t.playing ? t.beat + (e - t.frame) / s * (t.bpm / 60) : t.beat;
1437
+ }
1438
+ const dt = () => ({
1439
+ ms: 0,
1440
+ peak: [0, 0],
1441
+ notes: 0,
1442
+ params: 0
1443
+ });
1444
+ var ft = class {
1445
+ sampleRate;
1446
+ block;
1447
+ clock;
1448
+ nodes = /* @__PURE__ */ new Map();
1449
+ order = null;
1450
+ timeline = [{
1451
+ frame: 0,
1452
+ playing: !1,
1453
+ bpm: 120,
1454
+ beat: 0
1455
+ }];
1456
+ step;
1457
+ blocks = 0;
1458
+ renderMs = 0;
1459
+ statsFrom;
1460
+ constructor(t, e = 128, s = Date.now) {
1461
+ this.sampleRate = t, this.block = e, this.clock = s, this.step = 1 - Math.exp(-1 / (.005 * t)), this.statsFrom = s();
1462
+ }
1463
+ takeStats() {
1464
+ const t = this.clock(), e = {};
1465
+ for (const [i, n] of this.nodes) n.host && (e[i] = n.stats, n.stats = dt());
1466
+ const s = {
1467
+ blocks: this.blocks,
1468
+ ms: this.renderMs,
1469
+ wallMs: t - this.statsFrom,
1470
+ plugins: e
1471
+ };
1472
+ return this.blocks = 0, this.renderMs = 0, this.statsFrom = t, s;
1473
+ }
1474
+ node(t, e, s, i = 1) {
1475
+ const n = (t) => Array.from({ length: t }, () => new Float32Array(this.block)), r = (t) => ({
1476
+ target: t,
1477
+ now: t
1478
+ });
1479
+ return {
1480
+ host: t,
1481
+ curve: null,
1482
+ out: n(e),
1483
+ in: n(s),
1484
+ sources: /* @__PURE__ */ new Map(),
1485
+ fader: [r(i), r(i)],
1486
+ peak: [0, 0],
1487
+ due: [],
1488
+ dialect: null,
1489
+ fault: 0,
1490
+ active: !0,
1491
+ stats: {
1492
+ ms: 0,
1493
+ peak: [0, 0],
1494
+ notes: 0,
1495
+ params: 0
1496
+ }
1497
+ };
1498
+ }
1499
+ active(t, e) {
1500
+ const s = this.nodes.get(t);
1501
+ if (s?.host && (s.active = e, !e)) {
1502
+ s.host.stopProcessing(), s.due.length = 0;
1503
+ for (const t of s.out) t.fill(0);
1504
+ }
1505
+ }
1506
+ reset(t) {
1507
+ const e = this.nodes.get(t);
1508
+ if (e?.host) {
1509
+ e.host.reset(), e.due.length = 0;
1510
+ for (const t of e.out) t.fill(0);
1511
+ }
1512
+ }
1513
+ add(t, e, s = {}) {
1514
+ this.remove(t);
1515
+ const i = ut.of(e, s.id, s.memory ?? null);
1516
+ i.activate(this.sampleRate, this.block, this.timeline[0].bpm);
1517
+ const n = this.node(i, i.audioOut, i.audioIn);
1518
+ return n.dialect = i.notePorts[0] ? function(t) {
1519
+ const e = t.preferred & t.supported;
1520
+ return e === h ? "clap" : e === l ? "midi" : t.supported & h ? "clap" : t.supported & l ? "midi" : null;
1521
+ }(i.notePorts[0]) : null, this.nodes.set(t, n), this.order = null, i;
1522
+ }
1523
+ bus(t) {
1524
+ this.nodes.has(t) || (this.nodes.set(t, this.node(null, 2, 2)), this.order = null);
1525
+ }
1526
+ shaper(t, e) {
1527
+ this.nodes.has(t) || (this.nodes.set(t, this.node(null, 2, 2)), this.order = null), this.nodes.get(t).curve = e;
1528
+ }
1529
+ remove(t) {
1530
+ const e = this.nodes.get(t);
1531
+ if (e) {
1532
+ this.nodes.delete(t), e.host?.destroy();
1533
+ for (const e of this.nodes.values()) e.sources.delete(t);
1534
+ this.order = null;
1535
+ }
1536
+ }
1537
+ has(t) {
1538
+ return this.nodes.has(t);
1539
+ }
1540
+ host(t) {
1541
+ return this.nodes.get(t)?.host ?? null;
1542
+ }
1543
+ isActive(t) {
1544
+ return this.nodes.get(t)?.active ?? !1;
1545
+ }
1546
+ cable(t, e, s) {
1547
+ const i = this.nodes.get(e);
1548
+ if (null === s) return void (i?.sources.delete(t) && (this.order = null));
1549
+ if (!i) throw new Error(`a cable into "${e}", which the engine does not hold`);
1550
+ if (!this.nodes.has(t)) throw new Error(`a cable from "${t}", which the engine does not hold`);
1551
+ const n = i.sources.get(t);
1552
+ n ? n.target = s : (i.sources.set(t, {
1553
+ target: s,
1554
+ now: s
1555
+ }), this.order = null);
1556
+ }
1557
+ fader(t, e, s) {
1558
+ const i = this.nodes.get(t);
1559
+ i && !i.host && (i.fader[0].target = e, i.fader[1].target = s);
1560
+ }
1561
+ takePeak(t) {
1562
+ const e = this.nodes.get(t);
1563
+ if (!e) return [0, 0];
1564
+ const s = [e.peak[0], e.peak[1]];
1565
+ return e.peak[0] = e.peak[1] = 0, s;
1566
+ }
1567
+ takeFault(t) {
1568
+ const e = this.nodes.get(t);
1569
+ return 1 === e?.fault && (e.fault = 2, !0);
1570
+ }
1571
+ event(t, e, s) {
1572
+ const i = this.nodes.get(t);
1573
+ if (!i?.host) return;
1574
+ if (!i.active) {
1575
+ if ("param" !== s.type) return;
1576
+ const t = i.due.findIndex((t) => "param" === t.event.type && t.event.id === s.id);
1577
+ t >= 0 && i.due.splice(t, 1);
1578
+ }
1579
+ if ("midi" === s.type && 176 == (240 & s.data[0]) && (120 === s.data[1] || 123 === s.data[1])) {
1580
+ const t = 15 & s.data[0];
1581
+ i.due = i.due.filter((e) => !("midi" === e.event.type && (15 & e.event.data[0]) === t || ("on" === e.event.type || "off" === e.event.type) && (e.event.channel ?? 0) === t));
1582
+ }
1583
+ let n = i.due.length;
1584
+ for (; n > 0 && i.due[n - 1].frame > e;) n--;
1585
+ i.due.splice(n, 0, {
1586
+ frame: e,
1587
+ event: s
1588
+ });
1589
+ }
1590
+ transport(t) {
1591
+ const e = this.timeline.at(-1);
1592
+ if (t.playing && e && !e.playing && e.frame >= t.frame) {
1593
+ const s = e.frame + 1;
1594
+ t = {
1595
+ ...t,
1596
+ frame: s,
1597
+ beat: pt(t, s, this.sampleRate)
1598
+ };
1599
+ }
1600
+ this.timeline = this.timeline.filter((e) => e.frame < t.frame), this.timeline.push(t);
1601
+ }
1602
+ transportAt(t) {
1603
+ let e = this.timeline[0];
1604
+ for (const s of this.timeline) s.frame <= t && (e = s);
1605
+ return {
1606
+ playing: e.playing,
1607
+ bpm: e.bpm,
1608
+ beat: pt(e, t, this.sampleRate)
1609
+ };
1610
+ }
1611
+ ordered() {
1612
+ if (this.order) return this.order;
1613
+ const t = /* @__PURE__ */ new Set(), e = /* @__PURE__ */ new Set(), s = [], i = (n) => {
1614
+ if (!t.has(n) && !e.has(n) && this.nodes.has(n)) {
1615
+ e.add(n);
1616
+ for (const t of this.nodes.get(n).sources.keys()) i(t);
1617
+ e.delete(n), t.add(n), s.push(n);
1618
+ }
1619
+ };
1620
+ for (const n of this.nodes.keys()) i(n);
1621
+ return this.order = s;
1622
+ }
1623
+ addInto(t, e, s) {
1624
+ const i = this.step;
1625
+ let n = s.now;
1626
+ const r = s.target, o = n === r;
1627
+ for (let a = 0; a < this.block; a++) {
1628
+ o || (n += (r - n) * i);
1629
+ for (let s = 0; s < t.length; s++) {
1630
+ const i = e.length === t.length ? e[s][a] : 1 === e.length ? e[0][a] : 1 === t.length ? .5 * (e[0][a] + e[1][a]) : e[s]?.[a] ?? 0;
1631
+ t[s][a] += i * n;
1632
+ }
1633
+ }
1634
+ s.now = Math.abs(r - n) < 1e-7 ? r : n;
1635
+ }
1636
+ render(t, e, s) {
1637
+ const i = t + this.block, n = this.clock(), r = [
1638
+ t,
1639
+ ...this.timeline.filter((e) => e.frame > t && e.frame < i).map((t) => t.frame),
1640
+ i
1641
+ ], o = {
1642
+ target: 1,
1643
+ now: 1
1644
+ };
1645
+ for (const h of this.ordered()) {
1646
+ const i = this.nodes.get(h);
1647
+ for (const t of i.in) t.fill(0);
1648
+ const n = s?.get(h);
1649
+ n && n.length && i.in.length && this.addInto(i.in, n, o);
1650
+ for (const [t, e] of i.sources) {
1651
+ const s = this.nodes.get(t);
1652
+ s && i.in.length && this.addInto(i.in, s.out, e);
1653
+ }
1654
+ if (i.host && !i.active);
1655
+ else if (i.host) {
1656
+ const e = this.clock();
1657
+ for (let n = 0; n + 1 < r.length; n++) {
1658
+ const [e, s] = [r[n], r[n + 1]], o = this.transportAt(e);
1659
+ i.host.setTransport(o.playing, o.bpm, o.beat);
1660
+ let a = 0;
1661
+ for (; a < i.due.length && i.due[a].frame < s;) a++;
1662
+ const h = i.due.splice(0, a).map(({ frame: t, event: s }) => ({
1663
+ ...s,
1664
+ time: Math.max(0, t - e)
1665
+ })), l = i.dialect ? d(h, i.dialect) : h;
1666
+ for (const t of l) "param" === t.type ? i.stats.params++ : ("on" === t.type || "midi" === t.type && 144 == (240 & t.data[0]) && t.data[2] > 0) && i.stats.notes++;
1667
+ i.host.render(i.out, e - t, s - e, l, i.in);
1668
+ }
1669
+ i.stats.ms += this.clock() - e;
1670
+ let s = !1;
1671
+ for (let t = 0; t < i.out.length && !s; t++) {
1672
+ const e = i.out[t];
1673
+ let n = i.stats.peak[t > 0 ? 1 : 0];
1674
+ for (let t = 0; t < e.length; t++) {
1675
+ const i = e[t];
1676
+ Number.isFinite(i) ? (i < 0 ? -i : i) > n && (n = i < 0 ? -i : i) : s = !0;
1677
+ }
1678
+ i.stats.peak[t > 0 ? 1 : 0] = n;
1679
+ }
1680
+ if (s) {
1681
+ for (const t of i.out) t.fill(0);
1682
+ 0 === i.fault && (i.fault = 1);
1683
+ }
1684
+ 1 === i.out.length && (i.stats.peak[1] = i.stats.peak[0]);
1685
+ } else if (i.curve) {
1686
+ const t = i.curve, e = t.length - 1;
1687
+ for (let s = 0; s < 2; s++) {
1688
+ const [n, r] = [i.in[s], i.out[s]];
1689
+ for (let s = 0; s < this.block; s++) {
1690
+ const i = e / 2 * (n[s] + 1);
1691
+ if (i <= 0) r[s] = t[0];
1692
+ else if (i >= e) r[s] = t[e];
1693
+ else {
1694
+ const e = Math.floor(i), n = i - e;
1695
+ r[s] = (1 - n) * t[e] + n * t[e + 1];
1696
+ }
1697
+ }
1698
+ }
1699
+ } else for (let t = 0; t < 2; t++) {
1700
+ const e = i.fader[t], [s, n] = [i.in[t], i.out[t]];
1701
+ let r = e.now, o = i.peak[t];
1702
+ for (let t = 0; t < this.block; t++) {
1703
+ r !== e.target && (r += (e.target - r) * this.step);
1704
+ const i = s[t] * r;
1705
+ n[t] = i;
1706
+ const a = i < 0 ? -i : i;
1707
+ a > o && (o = a);
1708
+ }
1709
+ e.now = Math.abs(e.target - r) < 1e-7 ? e.target : r, i.peak[t] = o;
1710
+ }
1711
+ const a = e.get(h);
1712
+ if (a) for (let t = 0; t < a.length; t++) a[t].set(i.out[t] ?? (1 === i.out.length ? i.out[0] : new Float32Array(this.block)));
1713
+ }
1714
+ const a = this.timeline.filter((t) => t.frame < i);
1715
+ this.timeline = [...a.slice(-1), ...this.timeline.filter((t) => t.frame >= i)], this.blocks++, this.renderMs += this.clock() - n;
1716
+ }
1717
+ };
1718
+ function gt(t, e) {
1719
+ const s = ArrayBuffer.isView(t) ? new DataView(t.buffer, t.byteOffset, t.byteLength) : new DataView(t);
1720
+ if (s.byteLength < 24 || 1 !== s.getUint8(0)) return null;
1721
+ const i = s.getUint16(2, !0);
1722
+ if (s.byteLength < 24 + 12 * i) return null;
1723
+ const n = /* @__PURE__ */ new Map();
1724
+ for (let o = 0; o < i; o++) n.set(s.getUint32(24 + 12 * o, !0), s.getFloat64(28 + 12 * o, !0));
1725
+ const r = (e?.bargraphs ?? []).map((t) => n.get(t.id) ?? t.min);
1726
+ for (const o of e?.bargraphs ?? []) n.delete(o.id);
1727
+ return {
1728
+ playing: 1 === s.getUint8(1),
1729
+ tempo: s.getFloat64(8, !0),
1730
+ beat: s.getFloat64(16, !0),
1731
+ values: n,
1732
+ bargraphs: r
1733
+ };
1734
+ }
1735
+ function mt(t) {
1736
+ return {
1737
+ params: t.params.map((t) => ({ ...t })),
1738
+ remotePages: t.remotePages(),
1739
+ noteNames: t.noteNames(),
1740
+ voiceInfo: t.voiceInfo()
1741
+ };
1742
+ }
1743
+ const yt = new Uint8Array([0]);
1744
+ var wt = class extends AudioWorkletProcessor {
1745
+ core = new ft(sampleRate, 128);
1746
+ held = /* @__PURE__ */ new Map();
1747
+ block = 0;
1748
+ outs = /* @__PURE__ */ new Map();
1749
+ ins = /* @__PURE__ */ new Map();
1750
+ constructor() {
1751
+ super(), this.port.onmessage = (t) => {
1752
+ try {
1753
+ this.take(t.data);
1754
+ } catch (e) {
1755
+ const s = t.data, i = "cable" === s.type ? `${s.from}->${s.to}` : "id" in s ? s.id : s.type;
1756
+ this.port.postMessage({
1757
+ type: "error",
1758
+ what: s.type,
1759
+ key: i,
1760
+ error: e instanceof Error ? e.message : String(e)
1761
+ });
1762
+ }
1763
+ };
1764
+ }
1765
+ take(t) {
1766
+ if ("add" === t.type) try {
1767
+ const e = this.core.add(t.id, t.module, t.plugin), s = t.modouts;
1768
+ this.held.set(t.id, {
1769
+ port: -1,
1770
+ kind: "plugin",
1771
+ modouts: Array(s.length).fill(0),
1772
+ ids: s
1773
+ }), this.port.postMessage({
1774
+ type: "added",
1775
+ id: t.id,
1776
+ audioIn: e.audioIn,
1777
+ audioOut: e.audioOut,
1778
+ report: mt(e)
1779
+ });
1780
+ } catch (e) {
1781
+ this.port.postMessage({
1782
+ type: "failed",
1783
+ id: t.id,
1784
+ error: e instanceof Error ? e.message : String(e)
1785
+ });
1786
+ }
1787
+ else if ("bus" === t.type) this.core.bus(t.id), this.held.has(t.id) || this.held.set(t.id, {
1788
+ port: -1,
1789
+ kind: "bus",
1790
+ modouts: [],
1791
+ ids: []
1792
+ });
1793
+ else if ("shaper" === t.type) this.core.shaper(t.id, t.curve), this.held.has(t.id) || this.held.set(t.id, {
1794
+ port: -1,
1795
+ kind: "shaper",
1796
+ modouts: [],
1797
+ ids: []
1798
+ });
1799
+ else if ("port" === t.type) {
1800
+ const e = this.held.get(t.id);
1801
+ e && (e.port = t.port);
1802
+ } else if ("remove" === t.type) this.core.remove(t.id), this.held.delete(t.id);
1803
+ else if ("active" === t.type) this.core.active(t.id, t.on);
1804
+ else if ("reset" === t.type) this.core.reset(t.id);
1805
+ else if ("cable" === t.type) this.core.cable(t.from, t.to, t.gain);
1806
+ else if ("fader" === t.type) this.core.fader(t.id, t.left, t.right);
1807
+ else if ("events" === t.type) for (const s of t.events) this.core.event(t.id, s.frame, s.event);
1808
+ else this.core.transport(t.at);
1809
+ }
1810
+ process(t, e) {
1811
+ this.outs.clear(), this.ins.clear();
1812
+ for (const [o, a] of this.held) a.port < 0 || (this.outs.set(o, e[a.port]), this.ins.set(o, t[a.port]));
1813
+ this.core.render(currentFrame, this.outs, this.ins);
1814
+ const s = ++this.block, i = s % 6 == 0, n = s % 8 == 0;
1815
+ let r = null;
1816
+ for (const [o, a] of this.held) {
1817
+ if ("bus" === a.kind) {
1818
+ n && ((r ??= {})[o] = this.core.takePeak(o));
1819
+ continue;
1820
+ }
1821
+ if ("plugin" !== a.kind) continue;
1822
+ this.core.takeFault(o) && this.port.postMessage({
1823
+ type: "nonfinite",
1824
+ id: o
1825
+ });
1826
+ const t = this.core.host(o);
1827
+ t.logs.length && this.port.postMessage({
1828
+ type: "logs",
1829
+ id: o,
1830
+ logs: t.logs.splice(0)
1831
+ });
1832
+ const e = i && this.core.isActive(o);
1833
+ if (e) {
1834
+ const e = /* @__PURE__ */ new Map();
1835
+ for (const s of t.told()) "value" === s.type && e.set(s.id, s.value);
1836
+ e.size && this.port.postMessage({
1837
+ type: "told",
1838
+ id: o,
1839
+ values: [...e]
1840
+ });
1841
+ }
1842
+ if (e && a.modouts.length) {
1843
+ const t = this.core.host(o);
1844
+ t.fromPage(yt);
1845
+ const e = t.toPage.at(-1);
1846
+ t.toPage.length = 0;
1847
+ const s = e ? gt(e)?.values : void 0;
1848
+ for (let i = 0; i < a.modouts.length; i++) a.modouts[i] = s?.get(a.ids[i]) ?? a.modouts[i];
1849
+ this.port.postMessage({
1850
+ type: "modout",
1851
+ id: o,
1852
+ values: a.modouts
1853
+ });
1854
+ }
1855
+ }
1856
+ return r && this.port.postMessage({
1857
+ type: "peaks",
1858
+ peaks: r
1859
+ }), s % 94 == 0 && this.port.postMessage({
1860
+ type: "stats",
1861
+ stats: this.core.takeStats()
1862
+ }), !0;
1863
+ }
1864
+ };
1865
+ registerProcessor("fw-engine", wt);