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,2167 @@
1
+ const t = {
2
+ noteOn: 0,
3
+ noteOff: 1,
4
+ choke: 2,
5
+ end: 3,
6
+ expression: 4,
7
+ paramValue: 5,
8
+ paramMod: 6,
9
+ transport: 9,
10
+ midi: 10
11
+ };
12
+ function e(t, e, s, i, n, r = 0, o = 0) {
13
+ 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);
14
+ }
15
+ function s(t, s, i, n, r, o, a = 0) {
16
+ e(t, s, 40, i, n, a), t.setInt32(s + 16, r.noteId, !0), t.setInt16(s + 20, r.port, !0), t.setInt16(s + 22, r.channel, !0), t.setInt16(s + 24, r.key, !0), t.setFloat64(s + 32, o, !0);
17
+ }
18
+ function i(s, i, n, r, o, a, h = 0) {
19
+ e(s, i, 40, n, t.expression, h), s.setInt32(i + 16, o, !0), s.setInt32(i + 20, r.noteId, !0), s.setInt16(i + 24, r.port, !0), s.setInt16(i + 26, r.channel, !0), s.setInt16(i + 28, r.key, !0), s.setFloat64(i + 32, a, !0);
20
+ }
21
+ function n(s, i, n, r, o, a = {}) {
22
+ e(s, i, 48, n, t.paramValue, a.flags ?? 0, a.space ?? 0), s.setUint32(i + 16, r, !0), s.setUint32(i + 20, 0, !0), s.setInt32(i + 24, a.noteId ?? -1, !0), s.setInt16(i + 28, a.port ?? -1, !0), s.setInt16(i + 30, a.channel ?? -1, !0), s.setInt16(i + 32, a.key ?? -1, !0), s.setFloat64(i + 40, o, !0);
23
+ }
24
+ function r(t, e, s) {
25
+ 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);
26
+ }
27
+ function o(s, i, n, r, o, a = 0) {
28
+ e(s, i, 24, n, t.midi, a), s.setUint16(i + 16, r, !0);
29
+ for (let t = 0; t < 3; t++) s.setUint8(i + 18 + t, o[t]);
30
+ }
31
+ const a = {
32
+ volume: 0,
33
+ pan: 1,
34
+ tuning: 2,
35
+ vibrato: 3,
36
+ expression: 4,
37
+ brightness: 5,
38
+ pressure: 6
39
+ };
40
+ function h(t) {
41
+ const e = [];
42
+ for (const s of t) {
43
+ const t = s.codePointAt(0);
44
+ 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);
45
+ }
46
+ return Uint8Array.from(e);
47
+ }
48
+ function l(t) {
49
+ let e = "";
50
+ for (let s = 0; s < t.length;) {
51
+ const i = t[s++];
52
+ let n = i;
53
+ 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);
54
+ }
55
+ return e;
56
+ }
57
+ const c = 0, u = 8, p = 28, d = 52, f = 70, m = 2, g = 3, w = {
58
+ FD_READ: 2n,
59
+ FD_WRITE: 64n
60
+ }, v = 0, y = 1, b = 1, x = 3;
61
+ function k(t) {
62
+ let e = 8;
63
+ const s = () => {
64
+ let s, i = 0, n = 0;
65
+ do
66
+ s = t[e++], i += (127 & s) * 2 ** n, n += 7;
67
+ while (128 & s);
68
+ return i;
69
+ }, i = () => {
70
+ const i = s(), n = String.fromCharCode(...t.subarray(e, e + i));
71
+ return e += i, n;
72
+ }, n = () => {
73
+ const i = t[e++];
74
+ return {
75
+ initial: s(),
76
+ maximum: 1 & i ? s() : void 0,
77
+ shared: !!(2 & i)
78
+ };
79
+ };
80
+ for (; e < t.length;) {
81
+ const r = t[e++], o = s(), a = e + o;
82
+ if (2 === r) {
83
+ for (let r = s(); r > 0; r--) {
84
+ const r = i(), o = i(), a = t[e++];
85
+ if (0 === a) s();
86
+ else if (1 === a) e++, n();
87
+ else {
88
+ if (2 === a) return {
89
+ module: r,
90
+ name: o,
91
+ ...n()
92
+ };
93
+ if (3 !== a) return null;
94
+ e += 2;
95
+ }
96
+ }
97
+ return null;
98
+ }
99
+ e = a;
100
+ }
101
+ return null;
102
+ }
103
+ const E = 512;
104
+ async function A(t) {
105
+ const e = function(t) {
106
+ const e = /* @__PURE__ */ new Map(), s = (e, s) => l(t.subarray(e, e + s)).replace(/\0.*$/s, "");
107
+ for (let r = 0; r + E <= t.length && !t.subarray(r, r + E).every((t) => 0 === t);) {
108
+ 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];
109
+ r += E, 48 !== a && 0 !== a || e.set(n, new Uint8Array(t.subarray(r, r + o))), r += Math.ceil(o / E) * E;
110
+ }
111
+ const i = new Set([...e.keys()].map((t) => t.split("/")[0]));
112
+ if (1 !== i.size || [...e.keys()].some((t) => !t.includes("/"))) return e;
113
+ const [n] = i;
114
+ return new Map([...e].map(([t, e]) => [t.slice(n.length + 1), e]));
115
+ }(await async function(t) {
116
+ const e = new Blob([t]).stream().pipeThrough(new DecompressionStream("gzip"));
117
+ return new Uint8Array(await new Response(e).arrayBuffer());
118
+ }(t)), s = e.get("module.wasm");
119
+ if (!s) throw new Error(`the bundle has no module.wasm at its top (it has ${[...e.keys()].slice(0, 8).join(", ")})`);
120
+ return {
121
+ module: s,
122
+ files: e
123
+ };
124
+ }
125
+ const $ = {
126
+ "clap.state": ["dirty"],
127
+ "clap.latency": ["latencyChanged"],
128
+ "clap.tail": ["tailChanged"],
129
+ "clap.audio-ports": ["portsFlag", "portsRescan"],
130
+ "clap.note-ports": ["dialects", "notesRescan"],
131
+ "clap.thread-check": ["isMain", "isAudio"],
132
+ "clap.gui": [
133
+ "hints",
134
+ "resize",
135
+ "show",
136
+ "hide",
137
+ "closed"
138
+ ],
139
+ "clap.preset-load/2": ["presetError", "presetLoaded"]
140
+ }, _ = [
141
+ "size",
142
+ "get",
143
+ "write",
144
+ "read",
145
+ "push",
146
+ "ext",
147
+ "send",
148
+ "flush",
149
+ "rescan",
150
+ "log",
151
+ "restart",
152
+ "request",
153
+ "callback",
154
+ "clear",
155
+ "dirty",
156
+ "latencyChanged",
157
+ "tailChanged",
158
+ "portsFlag",
159
+ "portsRescan",
160
+ "dialects",
161
+ "notesRescan",
162
+ "isMain",
163
+ "isAudio",
164
+ "hints",
165
+ "resize",
166
+ "show",
167
+ "hide",
168
+ "closed",
169
+ "idxFiletype",
170
+ "idxLocation",
171
+ "idxSoundpack",
172
+ "idxExt",
173
+ "recError",
174
+ "recBegin",
175
+ "recPluginId",
176
+ "recSoundpack",
177
+ "recFlags",
178
+ "recCreator",
179
+ "recDescription",
180
+ "recTimestamps",
181
+ "recFeature",
182
+ "recExtra",
183
+ "presetError",
184
+ "presetLoaded"
185
+ ], U = 0, I = 8, P = 12, T = 16, M = 20, S = 24, C = 28, O = 32, F = 36, R = 40, D = 44, B = [
186
+ 1,
187
+ 2,
188
+ 10
189
+ ], N = 0, L = 1, z = 12, V = 16, W = 20, j = 24, H = 28, q = 32, J = 36, G = 40, Y = 44, Q = 0, K = 4, X = 12, Z = 268, tt = 1296, et = 1304, st = 1312, it = 1320, nt = 112;
190
+ function rt(t, e, s) {
191
+ const i = {}, n = [];
192
+ let r = null;
193
+ for (const h of WebAssembly.Module.imports(t)) if ("wasi_snapshot_preview1" === h.module && "function" === h.kind) n.push(h.name);
194
+ else {
195
+ if ("memory" !== h.kind) throw "wasi" === h.module && "thread-spawn" === h.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 ${h.module}.${h.name} (${h.kind}), which this host does not offer (a WCLAP may import WASI and its memory)`);
196
+ {
197
+ const t = e;
198
+ if (!t || t.module !== h.module || t.name !== h.name) throw new Error(`the plugin imports a memory (${h.module}.${h.name}) whose limits are read from its bytes: load it from them (ClapHost.load)`);
199
+ 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)");
200
+ r = new WebAssembly.Memory({
201
+ initial: t.initial,
202
+ maximum: t.maximum,
203
+ shared: t.shared
204
+ }), (i[h.module] ??= {})[h.name] = r;
205
+ }
206
+ }
207
+ const o = {
208
+ log: (t, e) => {},
209
+ inited: !1,
210
+ live: 0
211
+ };
212
+ n.length && (i.wasi_snapshot_preview1 = function(t, e) {
213
+ const s = () => new DataView(e.memory().buffer), i = () => new Uint8Array(e.memory().buffer), n = h(e.bundle), r = {
214
+ 1: [],
215
+ 2: []
216
+ }, o = (t) => {
217
+ const s = r[t];
218
+ r[t] = [], e.log(1 === t ? b : x, l(Uint8Array.from(s)));
219
+ }, a = {
220
+ environ_sizes_get: (t, e) => (s().setUint32(t, 0, !0), s().setUint32(e, 0, !0), c),
221
+ environ_get: () => c,
222
+ clock_time_get: (t, e, i) => {
223
+ const n = t === v ? Date.now() : t === y ? globalThis.performance?.now() ?? Date.now() : NaN;
224
+ return Number.isNaN(n) ? p : (s().setBigUint64(i, BigInt(Math.round(1e6 * n)), !0), c);
225
+ },
226
+ random_get: (t, e) => {
227
+ const s = i().subarray(t, t + e), n = new Uint8Array(Math.min(e, 65536));
228
+ for (let i = 0; i < e; i += n.length) {
229
+ const t = n.subarray(0, Math.min(n.length, e - i));
230
+ if (globalThis.crypto?.getRandomValues) globalThis.crypto.getRandomValues(t);
231
+ else for (let e = 0; e < t.length; e++) t[e] = 256 * Math.random() | 0;
232
+ s.set(t, i);
233
+ }
234
+ return c;
235
+ },
236
+ fd_write: (t, e, n, a) => {
237
+ if (1 !== t && 2 !== t) return u;
238
+ const h = s(), l = i();
239
+ let p = 0;
240
+ for (let s = 0; s < n; s++) {
241
+ const i = h.getUint32(e + 8 * s, !0), n = h.getUint32(e + 8 * s + 4, !0);
242
+ for (let e = 0; e < n; e++) {
243
+ const s = l[i + e];
244
+ 10 === s ? o(t) : r[t].push(s);
245
+ }
246
+ p += n;
247
+ }
248
+ return h.setUint32(a, p, !0), c;
249
+ },
250
+ fd_read: (t, e, i, n) => 0 !== t ? u : (s().setUint32(n, 0, !0), c),
251
+ fd_seek: (t) => t <= 2 ? f : u,
252
+ fd_close: (t) => t <= 3 ? c : u,
253
+ fd_fdstat_get: (t, i) => {
254
+ if (t > 3) return u;
255
+ const n = s();
256
+ return new Uint8Array(e.memory().buffer, i, 24).fill(0), n.setUint8(i, 3 === t ? g : m), n.setBigUint64(i + 8, 0 === t ? w.FD_READ : 3 === t ? 0n : w.FD_WRITE, !0), c;
257
+ },
258
+ fd_prestat_get: (t, e) => {
259
+ if (3 !== t) return u;
260
+ const i = s();
261
+ return i.setUint8(e, 0), i.setUint32(e + 4, n.length, !0), c;
262
+ },
263
+ fd_prestat_dir_name: (t, e, s) => 3 !== t ? u : s < n.length ? p : (i().set(n, e), c),
264
+ sched_yield: () => c,
265
+ proc_exit: (t) => {
266
+ throw new Error(`the plugin called proc_exit(${t})`);
267
+ }
268
+ };
269
+ return Object.fromEntries(t.map((t) => [t, a[t] ?? (() => d)]));
270
+ }(n, {
271
+ memory: () => o.memory,
272
+ bundle: s,
273
+ log: (t, e) => o.log(t, e)
274
+ }));
275
+ const a = new WebAssembly.Instance(t, i).exports, k = Object.values(a).filter((t) => t instanceof WebAssembly.Table);
276
+ if (1 !== k.length) throw new Error(`a WCLAP exports exactly one function table (WebCLAP README); this one exports ${k.length}`);
277
+ const E = r ?? a.memory;
278
+ if (!(E instanceof WebAssembly.Memory)) throw new Error("the module has no memory: neither imported nor exported");
279
+ if (!(a.clap_entry instanceof WebAssembly.Global)) throw new Error("the module exports no clap_entry");
280
+ const A = a.clap_entry.value;
281
+ if ("number" != typeof A) throw new Error("a wasm64 WCLAP: this host plays wasm32 ones (the WebCLAP README: \"you should probably build your WCLAPs as wasm32\")");
282
+ const $ = (t) => "function" == typeof a[t] ? a[t] : null, _ = $("malloc"), U = $("cabi_realloc");
283
+ if (!_ && !U) throw new Error("the module exports no malloc or cabi_realloc (WebCLAP README)");
284
+ const I = /* @__PURE__ */ new Map(), P = _ ? (t) => _(t) : (t) => {
285
+ const e = U(0, 0, 8, t);
286
+ return I.set(e, t), e;
287
+ }, T = $("free"), M = T ? (t) => {
288
+ T(t);
289
+ } : U && !_ ? (t) => {
290
+ U(t, I.get(t) ?? 0, 8, 0), I.delete(t);
291
+ } : () => {};
292
+ return Object.assign(o, {
293
+ memory: E,
294
+ table: k[0],
295
+ malloc: P,
296
+ free: M,
297
+ entry: A
298
+ }), $("_initialize")?.(), o;
299
+ }
300
+ var ot = class e {
301
+ static BUNDLE = "/plugin.wclap";
302
+ static NAME = "webclap-host";
303
+ static VENDOR = "webclap-host";
304
+ static URL = "https://github.com/crafics/webclap-host";
305
+ static VERSION = "0.1.0";
306
+ get toldHost() {
307
+ return this.told_;
308
+ }
309
+ onResize = null;
310
+ told_ = {
311
+ stateDirty: 0,
312
+ latencyChanged: 0,
313
+ tailChanged: 0,
314
+ portsRescan: 0,
315
+ notesRescan: 0,
316
+ resizeHints: 0,
317
+ resizeAsked: null,
318
+ guiClosed: 0,
319
+ presetsLoaded: 0,
320
+ presetErrors: []
321
+ };
322
+ restartAsked = 0;
323
+ processAsked = 0;
324
+ callbackDue = !1;
325
+ active = !1;
326
+ processing = !1;
327
+ steady = 0n;
328
+ descriptor;
329
+ plugins = [];
330
+ params = [];
331
+ audioIn;
332
+ audioOut;
333
+ inPorts = [];
334
+ outPorts = [];
335
+ notes;
336
+ notePorts = [];
337
+ get hasState() {
338
+ return !!this.stateExt;
339
+ }
340
+ page;
341
+ toPage = [];
342
+ flushesAsked = 0;
343
+ rescansAsked = 0;
344
+ logs = [];
345
+ x;
346
+ owned = /* @__PURE__ */ new Set();
347
+ host = 0;
348
+ hostWebview = 0;
349
+ hostParams = 0;
350
+ hostLog = 0;
351
+ hostExts = /* @__PURE__ */ new Map();
352
+ inAudio = !1;
353
+ guiMade = !1;
354
+ outEvents = [];
355
+ tell(t) {
356
+ this.outEvents.push(t), this.outEvents.length > 1024 && this.outEvents.splice(0, this.outEvents.length - 1024);
357
+ }
358
+ outputValues = /* @__PURE__ */ new Map();
359
+ readonlyIds = /* @__PURE__ */ new Set();
360
+ outRaw = [];
361
+ streamChunk = 0;
362
+ outList = 0;
363
+ plugin = 0;
364
+ paramsExt = 0;
365
+ entryAt = 0;
366
+ factoryAt = 0;
367
+ descAt = 0;
368
+ stateExt = 0;
369
+ events = [];
370
+ stream = [];
371
+ readAt = 0;
372
+ base = 0;
373
+ pool = 0;
374
+ poolRoom = 0;
375
+ list = 0;
376
+ transport = 0;
377
+ proc = 0;
378
+ activation = [];
379
+ ins = [];
380
+ outs = [];
381
+ scratch = 0;
382
+ frames = 0;
383
+ constructor(t, s) {
384
+ this.x = t, t.log = (t, e) => this.logs.push({
385
+ severity: t,
386
+ message: e
387
+ });
388
+ const i = t.table, n = new WebAssembly.Instance(new WebAssembly.Module(function() {
389
+ 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) => [
390
+ t,
391
+ ...e(s.length),
392
+ ...s
393
+ ], i = _, n = [
394
+ 0,
395
+ 1,
396
+ 2,
397
+ 2,
398
+ 1,
399
+ 1,
400
+ 3,
401
+ 4,
402
+ 5,
403
+ 6,
404
+ 4,
405
+ 4,
406
+ 4,
407
+ 6,
408
+ 4,
409
+ 4,
410
+ 4,
411
+ 1,
412
+ 5,
413
+ 0,
414
+ 5,
415
+ 0,
416
+ 0,
417
+ 4,
418
+ 3,
419
+ 0,
420
+ 0,
421
+ 5,
422
+ 1,
423
+ 1,
424
+ 1,
425
+ 1,
426
+ 6,
427
+ 3,
428
+ 5,
429
+ 5,
430
+ 5,
431
+ 5,
432
+ 5,
433
+ 7,
434
+ 5,
435
+ 6,
436
+ 9,
437
+ 8
438
+ ], r = [
439
+ 1,
440
+ 2,
441
+ 3,
442
+ 3,
443
+ 2,
444
+ 2,
445
+ 3,
446
+ 1,
447
+ 2,
448
+ 3,
449
+ 1,
450
+ 1,
451
+ 1,
452
+ 3,
453
+ 1,
454
+ 1,
455
+ 1,
456
+ 2,
457
+ 2,
458
+ 1,
459
+ 2,
460
+ 1,
461
+ 1,
462
+ 1,
463
+ 3,
464
+ 1,
465
+ 1,
466
+ 2,
467
+ 2,
468
+ 2,
469
+ 2,
470
+ 2,
471
+ 3,
472
+ 3,
473
+ 2,
474
+ 2,
475
+ 2,
476
+ 2,
477
+ 2,
478
+ 3,
479
+ 2,
480
+ 3,
481
+ 6,
482
+ 4
483
+ ], o = i.map((t, e) => {
484
+ const s = [
485
+ 0,
486
+ ...Array.from({ length: r[e] }, (t, e) => [32, e]).flat(),
487
+ 16,
488
+ e,
489
+ 11
490
+ ];
491
+ return [s.length, ...s];
492
+ });
493
+ return new Uint8Array([
494
+ 0,
495
+ 97,
496
+ 115,
497
+ 109,
498
+ 1,
499
+ 0,
500
+ 0,
501
+ 0,
502
+ ...s(1, [
503
+ 10,
504
+ 96,
505
+ 1,
506
+ 127,
507
+ 1,
508
+ 127,
509
+ 96,
510
+ 2,
511
+ 127,
512
+ 127,
513
+ 1,
514
+ 127,
515
+ 96,
516
+ 3,
517
+ 127,
518
+ 127,
519
+ 126,
520
+ 1,
521
+ 126,
522
+ 96,
523
+ 3,
524
+ 127,
525
+ 127,
526
+ 127,
527
+ 1,
528
+ 127,
529
+ 96,
530
+ 1,
531
+ 127,
532
+ 0,
533
+ 96,
534
+ 2,
535
+ 127,
536
+ 127,
537
+ 0,
538
+ 96,
539
+ 3,
540
+ 127,
541
+ 127,
542
+ 127,
543
+ 0,
544
+ 96,
545
+ 3,
546
+ 127,
547
+ 126,
548
+ 126,
549
+ 0,
550
+ 96,
551
+ 4,
552
+ 127,
553
+ 127,
554
+ 127,
555
+ 127,
556
+ 0,
557
+ 96,
558
+ 6,
559
+ 127,
560
+ 127,
561
+ 127,
562
+ 127,
563
+ 127,
564
+ 127,
565
+ 0
566
+ ]),
567
+ ...s(2, [i.length, ...i.flatMap((e, s) => [
568
+ ...t("h"),
569
+ ...t(e),
570
+ 0,
571
+ n[s]
572
+ ])]),
573
+ ...s(3, [i.length, ...n]),
574
+ ...s(7, [i.length, ...i.flatMap((e, s) => [
575
+ ...t(e),
576
+ 0,
577
+ i.length + s
578
+ ])]),
579
+ ...s(10, [i.length, ...o.flat()])
580
+ ]);
581
+ }()), { h: {
582
+ size: () => this.events.length,
583
+ get: (t, e) => this.events[e],
584
+ write: (t, e, s) => {
585
+ const i = this.streamChunk ? Math.min(Number(s), this.streamChunk) : Number(s);
586
+ for (const n of new Uint8Array(this.x.memory.buffer, e, i)) this.stream.push(n);
587
+ return BigInt(i);
588
+ },
589
+ read: (t, e, s) => {
590
+ const i = Math.min(Number(s), this.stream.length - this.readAt, this.streamChunk || 1 / 0);
591
+ return new Uint8Array(this.x.memory.buffer).set(this.stream.slice(this.readAt, this.readAt + i), e), this.readAt += i, BigInt(i);
592
+ },
593
+ push: (t, e) => {
594
+ const s = this.view(), i = s.getUint16(e + 10, !0), n = s.getUint32(e + 16, !0);
595
+ return this.outRaw.push({
596
+ time: s.getUint32(e + 4, !0),
597
+ type: i,
598
+ space: s.getUint16(e + 8, !0)
599
+ }), 5 === i && this.readonlyIds.has(n) ? this.outputValues.set(n, s.getFloat64(e + 40, !0)) : 5 === i ? this.tell({
600
+ type: "value",
601
+ id: n,
602
+ value: s.getFloat64(e + 40, !0)
603
+ }) : 7 !== i && 8 !== i || this.tell({
604
+ type: 7 === i ? "begin" : "end",
605
+ id: n
606
+ }), 1;
607
+ },
608
+ ext: (t, e) => {
609
+ const s = this.cstr(e);
610
+ return "clap.webview/3" === s ? this.hostWebview : "clap.params" === s ? this.hostParams : "clap.log" === s ? this.hostLog : this.hostExts.get(s) ?? 0;
611
+ },
612
+ log: (t, e, s) => {
613
+ this.logs.push({
614
+ severity: e,
615
+ message: this.cstr(s)
616
+ });
617
+ },
618
+ flush: () => {
619
+ this.flushesAsked++;
620
+ },
621
+ rescan: (t, e) => {
622
+ 1 & e && this.rescansAsked++;
623
+ },
624
+ send: (t, e, s) => (this.toPage.push(new Uint8Array(this.x.memory.buffer.slice(e, e + s))), 1),
625
+ restart: () => {
626
+ this.restartAsked++;
627
+ },
628
+ request: () => {
629
+ this.processAsked++;
630
+ },
631
+ callback: () => {
632
+ this.callbackDue = !0;
633
+ },
634
+ clear: () => {},
635
+ dirty: () => {
636
+ this.told_.stateDirty++;
637
+ },
638
+ latencyChanged: () => {
639
+ this.told_.latencyChanged++;
640
+ },
641
+ tailChanged: () => {
642
+ this.told_.tailChanged++;
643
+ },
644
+ portsFlag: () => 0,
645
+ portsRescan: () => {
646
+ this.told_.portsRescan++;
647
+ },
648
+ dialects: () => 3,
649
+ notesRescan: () => {
650
+ this.told_.notesRescan++;
651
+ },
652
+ isMain: () => this.inAudio ? 0 : 1,
653
+ isAudio: () => this.inAudio ? 1 : 0,
654
+ hints: () => {
655
+ this.told_.resizeHints++;
656
+ },
657
+ resize: (t, e, s) => (this.told_.resizeAsked = {
658
+ width: e,
659
+ height: s
660
+ }, this.onResize?.(e, s) ? 1 : 0),
661
+ show: () => 0,
662
+ hide: () => 0,
663
+ closed: () => {
664
+ this.told_.guiClosed++;
665
+ },
666
+ idxFiletype: () => this.declared("declare_filetype"),
667
+ idxSoundpack: () => this.declared("declare_soundpack"),
668
+ idxLocation: (t, e) => {
669
+ if (!this.declared("declare_location")) return 0;
670
+ const s = this.view(), [i, n, r, o] = [
671
+ 0,
672
+ 4,
673
+ 8,
674
+ 12
675
+ ].map((t) => s.getUint32(e + t, !0)), a = o ? this.cstr(o) : null;
676
+ return r === N && null === a ? this.crawl.errors.push("The location may not be a null pointer with CLAP_PRESET_DISCOVERY_LOCATION_FILE.") : r !== N || a.startsWith("/") ? r === L && null !== a ? this.crawl.errors.push("The location must be a null pointer with CLAP_PRESET_DISCOVERY_LOCATION_PLUGIN.") : r !== N && r !== L ? this.crawl.errors.push(`Unknown location kind ${r}.`) : this.crawl.locations.push({
677
+ flags: i,
678
+ name: n ? this.cstr(n) : "",
679
+ kind: r,
680
+ path: a
681
+ }) : this.crawl.errors.push(`'${a}' should be an absolute path, i.e. '/${a}'.`), 1;
682
+ },
683
+ idxExt: () => 0,
684
+ recError: (t, e, s) => {
685
+ this.crawl?.errors.push(`Load error occurred: OS error code ${e} with the following error message: ${s ? this.cstr(s) : ""}`);
686
+ },
687
+ recBegin: (t, e, s) => {
688
+ const i = this.crawl;
689
+ if (!i?.at) return i?.errors.push("'begin_preset()' outside 'get_metadata()'."), 0;
690
+ const n = e ? this.cstr(e) : null, r = s ? this.cstr(s) : null;
691
+ 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 = {
692
+ provider: i.provider,
693
+ name: n ?? (i.at.path ?? "").replace(/^.*\//, ""),
694
+ key: r,
695
+ location: {
696
+ kind: i.at.kind,
697
+ path: i.at.path
698
+ },
699
+ pluginIds: [],
700
+ flags: null
701
+ }, null === r ? i.single = !0 : i.keyed = !0, 1);
702
+ },
703
+ recPluginId: (t, e) => {
704
+ const s = this.presetOpen("add_plugin_id");
705
+ if (!s) return;
706
+ const i = this.cstr(this.u32(e));
707
+ "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({
708
+ abi: i,
709
+ id: this.cstr(this.u32(e + 4))
710
+ });
711
+ },
712
+ recFlags: (t, e) => {
713
+ const s = this.presetOpen("set_flags");
714
+ s && (s.flags = e);
715
+ },
716
+ recSoundpack: () => {
717
+ this.presetOpen("set_soundpack_id");
718
+ },
719
+ recCreator: () => {
720
+ this.presetOpen("add_creator");
721
+ },
722
+ recDescription: () => {
723
+ this.presetOpen("set_description");
724
+ },
725
+ recTimestamps: () => {
726
+ this.presetOpen("set_timestamps");
727
+ },
728
+ recFeature: () => {
729
+ this.presetOpen("add_feature");
730
+ },
731
+ recExtra: () => {
732
+ this.presetOpen("add_extra_info");
733
+ },
734
+ presetError: (t, e, s, i, n, r) => {
735
+ this.told_.presetErrors.push(`OS error code ${n}: ${r ? this.cstr(r) : ""}`);
736
+ },
737
+ presetLoaded: () => {
738
+ this.told_.presetsLoaded++;
739
+ }
740
+ } }).exports;
741
+ this.base = i.length, i.grow(_.length), _.forEach((t, e) => i.set(this.base + e, n[t])), this.host = this.take(48);
742
+ {
743
+ const t = [
744
+ e.NAME,
745
+ e.VENDOR,
746
+ e.URL,
747
+ e.VERSION
748
+ ].map((t) => this.text(t)), s = this.view();
749
+ B.forEach((t, e) => s.setUint32(this.host + 4 * e, t, !0)), s.setUint32(this.host + 12, 0, !0), t.forEach((t, e) => s.setUint32(this.host + 16 + 4 * e, t, !0)), s.setUint32(this.host + 32, this.base + 5, !0), s.setUint32(this.host + 36, this.base + 10, !0), s.setUint32(this.host + 40, this.base + 11, !0), s.setUint32(this.host + 44, this.base + 12, !0);
750
+ }
751
+ 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);
752
+ for (const [e, f] of Object.entries($)) {
753
+ const t = this.take(4 * f.length);
754
+ f.forEach((e, s) => this.view().setUint32(t + 4 * s, this.base + _.indexOf(e), !0)), this.hostExts.set(e, t);
755
+ }
756
+ const r = t.entry;
757
+ if (!t.inited) {
758
+ if (!this.fn(this.u32(r + 12))(this.text(e.BUNDLE))) throw new Error("clap_entry.init failed");
759
+ t.inited = !0;
760
+ }
761
+ const o = this.fn(this.u32(r + 20))(this.text("clap.plugin-factory"));
762
+ if (!o) throw new Error("no plugin factory");
763
+ const a = this.fn(this.u32(o))(o), h = [];
764
+ for (let e = 0; e < a; e++) h.push(this.fn(this.u32(o + 4))(o, e));
765
+ if (this.plugins = h.map((t) => this.cstr(this.u32(t + z))), !h.length) throw new Error("the plugin factory offers no plugin");
766
+ const l = void 0 === s ? h[0] : h[this.plugins.indexOf(s)];
767
+ if (!l) throw new Error(`no plugin ${s} in this module (it has ${this.plugins.join(", ")})`);
768
+ [this.entryAt, this.factoryAt, this.descAt] = [
769
+ r,
770
+ o,
771
+ l
772
+ ];
773
+ const c = [];
774
+ for (let e = this.u32(l + Y); e && this.u32(e); e += 4) c.push(this.cstr(this.u32(e)));
775
+ if (this.descriptor = {
776
+ id: this.cstr(this.u32(l + z)),
777
+ name: this.cstr(this.u32(l + V)),
778
+ vendor: this.cstr(this.u32(l + W)),
779
+ version: this.cstr(this.u32(l + J)),
780
+ features: c
781
+ }, this.plugin = this.fn(this.u32(o + 8))(o, this.host, this.u32(l + z)), !this.plugin) throw new Error("the factory made no plugin");
782
+ if (!this.fn(this.u32(this.plugin + I))(this.plugin)) throw this.pluginDestroy(), /* @__PURE__ */ new Error("the plugin did not start (init returned false)");
783
+ t.live++;
784
+ const u = this.extension("clap.audio-ports"), p = (t) => {
785
+ if (!u) return [];
786
+ const e = this.fn(this.u32(u))(this.plugin, t), s = this.take(296), i = [];
787
+ 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);
788
+ return this.give(s), i;
789
+ };
790
+ this.inPorts = p(!0), this.outPorts = p(!1), this.audioIn = this.inPorts[0] ?? 0, this.audioOut = this.outPorts[0] ?? 0;
791
+ const d = this.extension("clap.note-ports");
792
+ if (d) {
793
+ const t = this.fn(this.u32(d))(this.plugin, !0), e = this.take(268);
794
+ for (let s = 0; s < t; s++) this.fn(this.u32(d + 4))(this.plugin, s, !0, e) && this.notePorts.push({
795
+ supported: this.u32(e + 4),
796
+ preferred: this.u32(e + 8)
797
+ });
798
+ this.give(e);
799
+ }
800
+ 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(nt * 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(it), this.paramsExt) {
801
+ const t = this.fn(this.u32(this.paramsExt))(this.plugin);
802
+ for (let e = 0; e < t; e++) {
803
+ this.fn(this.u32(this.paramsExt + 4))(this.plugin, e, this.scratch);
804
+ const t = this.view();
805
+ this.params.push({
806
+ id: this.u32(this.scratch + Q),
807
+ name: this.cstr(this.scratch + X),
808
+ min: t.getFloat64(this.scratch + tt, !0),
809
+ max: t.getFloat64(this.scratch + et, !0),
810
+ init: t.getFloat64(this.scratch + st, !0),
811
+ stepped: !!(1 & this.u32(this.scratch + K)),
812
+ automatable: !!(32 & this.u32(this.scratch + K)),
813
+ named: !!(65536 & this.u32(this.scratch + K)),
814
+ readonly: !!(8 & this.u32(this.scratch + K)),
815
+ hidden: !!(4 & this.u32(this.scratch + K)),
816
+ module: this.cstr(this.scratch + Z)
817
+ });
818
+ }
819
+ for (const e of this.params) e.readonly && this.readonlyIds.add(e.id);
820
+ }
821
+ }
822
+ static async load(t, s) {
823
+ return e.of(await WebAssembly.compile(t), s, k(t));
824
+ }
825
+ static async loadBundle(t, s) {
826
+ return e.load((await A(t)).module, s);
827
+ }
828
+ static of(t, s, i = null) {
829
+ return new e(rt(t, i, e.BUNDLE), s);
830
+ }
831
+ another(t) {
832
+ return new e(this.x, t);
833
+ }
834
+ activate(t, e, s = 120) {
835
+ if (!(t > 0)) throw new Error(`a sample rate of ${t}`);
836
+ if (!(e >= 1 && e <= 2147483647)) throw new Error(`a block of ${e} frames`);
837
+ if (this.active && this.deactivate(), this.frames = e, !this.pluginActivate(t, e)) throw new Error("activate failed");
838
+ this.active = !0, this.steady = 0n, this.runCallback();
839
+ for (const h of this.activation) this.give(h);
840
+ this.activation = [], this.ins = [], this.outs = [];
841
+ const i = (t) => {
842
+ const e = this.take(t);
843
+ return this.activation.push(e), e;
844
+ }, n = (t, s) => {
845
+ const n = i(24 * Math.max(t.length, 1));
846
+ return t.forEach((t, r) => {
847
+ const o = i(4 * Math.max(t, 1));
848
+ for (let n = 0; n < t; n++) {
849
+ const t = i(4 * e);
850
+ new Float32Array(this.x.memory.buffer, t, e).fill(0), 0 === r && s.push(t), this.view().setUint32(o + 4 * n, t, !0);
851
+ }
852
+ const a = this.view(), h = n + 24 * r;
853
+ 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);
854
+ }), n;
855
+ }, r = n(this.inPorts, this.ins), o = n(this.outPorts, this.outs);
856
+ this.transport = i(104), this.proc = i(40);
857
+ const a = this.view();
858
+ 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);
859
+ }
860
+ process(t = [], e = []) {
861
+ this.events = this.inPool(t);
862
+ const s = new Float32Array(this.x.memory.buffer);
863
+ 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 = [];
864
+ const i = new Float32Array(this.x.memory.buffer);
865
+ return this.outs.map((t) => i.slice(t / 4, t / 4 + this.frames));
866
+ }
867
+ play(t) {
868
+ this.view().setUint32(this.transport + 16, 1 | (t ? 16 : 0), !0);
869
+ }
870
+ setTransport(t, e, s) {
871
+ const i = this.view();
872
+ 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);
873
+ }
874
+ render(t, e, s, i = [], n = []) {
875
+ if (s < 1 || s > this.frames) throw new Error(`a block of 1..${this.frames} frames`);
876
+ if (this.events = this.inPool(i), this.view().setUint32(this.proc + 8, s, !0), this.ins.length) {
877
+ const t = new Float32Array(this.x.memory.buffer);
878
+ 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));
879
+ }
880
+ this.startIfStopped(), this.lastStatus = this.callProcess(), this.events = [], this.view().setUint32(this.proc + 8, this.frames, !0);
881
+ const r = new Float32Array(this.x.memory.buffer);
882
+ 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);
883
+ }
884
+ pluginActivate(t, e) {
885
+ return !!this.fn(this.u32(this.plugin + T))(this.plugin, t, 1, e);
886
+ }
887
+ pluginDeactivate() {
888
+ this.fn(this.u32(this.plugin + M))(this.plugin);
889
+ }
890
+ pluginStart() {
891
+ return this.audio(() => !!this.fn(this.u32(this.plugin + S))(this.plugin));
892
+ }
893
+ pluginStop() {
894
+ this.audio(() => this.fn(this.u32(this.plugin + C))(this.plugin));
895
+ }
896
+ pluginReset() {
897
+ this.audio(() => this.fn(this.u32(this.plugin + O))(this.plugin));
898
+ }
899
+ audio(t) {
900
+ this.inAudio = !0;
901
+ try {
902
+ return t();
903
+ } finally {
904
+ this.inAudio = !1;
905
+ }
906
+ }
907
+ pluginDestroy() {
908
+ this.fn(this.u32(this.plugin + P))(this.plugin);
909
+ }
910
+ startIfStopped() {
911
+ if (!this.active) throw new Error("process before activate");
912
+ if (!this.processing && !this.startProcessing()) throw new Error("start_processing failed");
913
+ }
914
+ callProcess() {
915
+ if (!this.processing) throw new Error("process while not processing");
916
+ this.outRaw = [], this.view().setBigInt64(this.proc, this.steady, !0);
917
+ const t = this.audio(() => this.fn(this.u32(this.plugin + F))(this.plugin, this.proc));
918
+ return this.steady += BigInt(this.view().getUint32(this.proc + 8, !0)), this.runCallback(), t;
919
+ }
920
+ runCallback() {
921
+ if (!this.callbackDue) return;
922
+ this.callbackDue = !1;
923
+ const t = this.u32(this.plugin + D);
924
+ t && this.fn(t)(this.plugin);
925
+ }
926
+ lastStatus = 1;
927
+ deactivate() {
928
+ this.active && (this.processing && this.stopProcessing(), this.pluginDeactivate(), this.active = !1, this.runCallback());
929
+ }
930
+ startProcessing() {
931
+ if (!this.active) throw new Error("start_processing before activate");
932
+ return !!this.processing || (this.processing = this.pluginStart(), this.processing);
933
+ }
934
+ stopProcessing() {
935
+ this.processing && (this.pluginStop(), this.processing = !1);
936
+ }
937
+ reset() {
938
+ this.active && this.pluginReset();
939
+ }
940
+ destroy() {
941
+ this.active && this.deactivate(), this.guiMade && this.fn(this.u32(this.need(this.extension("clap.gui"), "clap.gui") + 12))(this.plugin), this.pluginDestroy();
942
+ for (const t of this.owned) this.x.free(t);
943
+ this.owned.clear(), 0 === --this.x.live && this.x.inited && (this.fn(this.u32(this.x.entry + 16))(), this.x.inited = !1);
944
+ }
945
+ memoryBytes() {
946
+ return this.x.memory.buffer.byteLength;
947
+ }
948
+ instanceDescriptorId() {
949
+ return this.cstr(this.u32(this.u32(this.plugin + U) + z));
950
+ }
951
+ descriptorFields(t) {
952
+ const e = "factory" === t ? this.descAt : this.u32(this.plugin + U), s = (t) => this.u32(e + t) ? this.cstr(this.u32(e + t)) : null, i = [];
953
+ for (let n = this.u32(e + Y); n && this.u32(n); n += 4) i.push(this.cstr(this.u32(n)));
954
+ return {
955
+ id: s(z),
956
+ name: s(V),
957
+ vendor: s(W),
958
+ url: s(j),
959
+ manual_url: s(H),
960
+ support_url: s(q),
961
+ version: s(J),
962
+ description: s(G),
963
+ features: i
964
+ };
965
+ }
966
+ hasExtension(t) {
967
+ return 0 !== this.extension(t);
968
+ }
969
+ hasFactory(t) {
970
+ const e = this.text(t), s = this.fn(this.u32(this.entryAt + 20))(e);
971
+ return this.give(e), 0 !== s;
972
+ }
973
+ creates(t) {
974
+ const e = this.text(t), s = this.fn(this.u32(this.factoryAt + 8))(this.factoryAt, this.host, e);
975
+ return this.give(e), s && this.fn(this.u32(s + P))(s), 0 !== s;
976
+ }
977
+ pushed() {
978
+ const t = this.outRaw;
979
+ return this.outRaw = [], t;
980
+ }
981
+ setTransportFull(t) {
982
+ this.view().setUint32(this.proc + 12, t ? this.transport : 0, !0), t && r(this.view(), this.transport, t);
983
+ }
984
+ processChecked(t, e, s, i) {
985
+ if (t < 1 || t > this.frames) throw new Error(`a block of 1..${this.frames} frames`);
986
+ this.events = this.inPool(e);
987
+ const n = new Float32Array(this.x.memory.buffer);
988
+ this.ins.forEach((t, e) => n.set(s[e]?.subarray(0, this.frames) ?? new Float32Array(this.frames), t / 4));
989
+ const r = new Uint32Array(this.x.memory.buffer);
990
+ for (const c of this.outs) r.fill(i >>> 0, c / 4, c / 4 + this.frames);
991
+ const o = this.view(), a = o.getUint32(this.proc + 20, !0);
992
+ o.setBigUint64(a + 16, 0n, !0), o.setUint32(this.proc + 8, t, !0), this.startIfStopped();
993
+ const h = this.callProcess();
994
+ this.lastStatus = h, this.events = [], this.view().setUint32(this.proc + 8, this.frames, !0);
995
+ const l = new Float32Array(this.x.memory.buffer);
996
+ return {
997
+ status: h,
998
+ inputs: this.ins.map((t) => l.slice(t / 4, t / 4 + this.frames)),
999
+ outputs: this.outs.map((t) => l.slice(t / 4, t / 4 + this.frames)),
1000
+ constantMask: this.view().getBigUint64(a + 16, !0)
1001
+ };
1002
+ }
1003
+ value(t) {
1004
+ 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);
1005
+ }
1006
+ valueToText(t, e) {
1007
+ 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;
1008
+ }
1009
+ textToValue(t, e) {
1010
+ this.need(this.paramsExt, "clap.params");
1011
+ const s = this.text(e), i = this.fn(this.u32(this.paramsExt + 16))(this.plugin, t, s, this.scratch);
1012
+ return this.give(s), i ? this.view().getFloat64(this.scratch, !0) : null;
1013
+ }
1014
+ flush(t = []) {
1015
+ this.need(this.paramsExt, "clap.params"), this.events = this.inPool(t);
1016
+ const e = () => this.fn(this.u32(this.paramsExt + 20))(this.plugin, this.list, this.outList);
1017
+ this.active ? this.audio(e) : e(), this.events = [];
1018
+ }
1019
+ output(t) {
1020
+ return this.outputValues.get(t);
1021
+ }
1022
+ told() {
1023
+ const t = this.outEvents;
1024
+ return this.outEvents = [], t;
1025
+ }
1026
+ latency() {
1027
+ if (!this.active) throw new Error("latency before activate");
1028
+ const t = this.extension("clap.latency");
1029
+ return t ? this.fn(this.u32(t))(this.plugin) >>> 0 : null;
1030
+ }
1031
+ tail() {
1032
+ if (!this.active) throw new Error("tail before activate");
1033
+ const t = this.extension("clap.tail");
1034
+ return t ? this.fn(this.u32(t))(this.plugin) >>> 0 : null;
1035
+ }
1036
+ remotePages() {
1037
+ const t = this.extension("clap.remote-controls/2");
1038
+ if (!t) return null;
1039
+ const e = [], s = this.fn(this.u32(t))(this.plugin) >>> 0, i = this.take(552);
1040
+ for (let n = 0; n < s; n++) {
1041
+ if (!this.fn(this.u32(t + 4))(this.plugin, n, i)) throw new Error(`clap.remote-controls get ${n} failed`);
1042
+ e.push({
1043
+ section: this.cstr(i),
1044
+ id: this.u32(i + 256),
1045
+ name: this.cstr(i + 260),
1046
+ params: Array.from({ length: 8 }, (t, e) => this.u32(i + 516 + 4 * e)),
1047
+ forPreset: 0 !== this.view().getUint8(i + 548)
1048
+ });
1049
+ }
1050
+ return this.give(i), e;
1051
+ }
1052
+ noteNames() {
1053
+ const t = this.extension("clap.note-name");
1054
+ if (!t) return null;
1055
+ const e = [], s = this.fn(this.u32(t))(this.plugin) >>> 0, i = this.take(262);
1056
+ for (let n = 0; n < s; n++) {
1057
+ if (!this.fn(this.u32(t + 4))(this.plugin, n, i)) throw new Error(`clap.note-name get ${n} failed`);
1058
+ const s = this.view();
1059
+ e.push({
1060
+ name: this.cstr(i),
1061
+ port: s.getInt16(i + 256, !0),
1062
+ key: s.getInt16(i + 258, !0),
1063
+ channel: s.getInt16(i + 260, !0)
1064
+ });
1065
+ }
1066
+ return this.give(i), e;
1067
+ }
1068
+ voiceInfo() {
1069
+ const t = this.extension("clap.voice-info");
1070
+ if (!t) return null;
1071
+ const e = this.take(16);
1072
+ if (!this.fn(this.u32(t))(this.plugin, e)) throw new Error("clap.voice-info get failed");
1073
+ const s = this.view(), i = {
1074
+ count: s.getUint32(e, !0),
1075
+ capacity: s.getUint32(e + 4, !0),
1076
+ flags: Number(s.getBigUint64(e + 8, !0))
1077
+ };
1078
+ return this.give(e), i;
1079
+ }
1080
+ pageUri() {
1081
+ 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);
1082
+ this.fn(this.u32(t))(this.plugin, s, e);
1083
+ const i = this.cstr(s);
1084
+ return this.give(s), i;
1085
+ }
1086
+ pageSize() {
1087
+ const t = this.need(this.extension("clap.gui"), "clap.gui");
1088
+ if (!this.guiMade) {
1089
+ const e = this.text("webview"), s = !!this.fn(this.u32(t + 8))(this.plugin, e, !1);
1090
+ if (this.give(e), !s) throw new Error("the plugin made no webview gui (clap.gui create)");
1091
+ this.guiMade = !0;
1092
+ }
1093
+ const e = this.take(8), s = this.fn(this.u32(t + 20))(this.plugin, e, e + 4), i = {
1094
+ width: this.u32(e),
1095
+ height: this.u32(e + 4)
1096
+ };
1097
+ if (this.give(e), !s) throw new Error("no size");
1098
+ return i;
1099
+ }
1100
+ presets() {
1101
+ const t = ["clap.preset-discovery-factory/2", "clap.preset-discovery-factory/draft-2"].map((t) => {
1102
+ const e = this.text(t), s = this.fn(this.u32(this.entryAt + 20))(e);
1103
+ return this.give(e), s;
1104
+ }).find((t) => 0 !== t);
1105
+ if (!t) return null;
1106
+ const s = [], i = [], n = [], r = [
1107
+ e.NAME,
1108
+ e.VENDOR,
1109
+ e.URL,
1110
+ e.VERSION
1111
+ ].map((t) => this.text(t)), o = this.take(48), a = this.take(44);
1112
+ {
1113
+ const t = this.view();
1114
+ B.forEach((e, s) => t.setUint32(o + 4 * s, e, !0)), r.forEach((e, s) => t.setUint32(o + 12 + 4 * s, e, !0)), t.setUint32(o + 28, 0, !0), [
1115
+ "idxFiletype",
1116
+ "idxLocation",
1117
+ "idxSoundpack",
1118
+ "idxExt"
1119
+ ].forEach((e, s) => t.setUint32(o + 32 + 4 * s, this.base + _.indexOf(e), !0)), t.setUint32(a, 0, !0), [
1120
+ "recError",
1121
+ "recBegin",
1122
+ "recPluginId",
1123
+ "recSoundpack",
1124
+ "recFlags",
1125
+ "recCreator",
1126
+ "recDescription",
1127
+ "recTimestamps",
1128
+ "recFeature",
1129
+ "recExtra"
1130
+ ].forEach((e, s) => t.setUint32(a + 4 + 4 * s, this.base + _.indexOf(e), !0));
1131
+ }
1132
+ const h = (t) => {
1133
+ const e = (e) => this.u32(t + e) ? this.cstr(this.u32(t + e)) : null;
1134
+ return {
1135
+ id: e(12),
1136
+ name: e(16),
1137
+ vendor: e(20)
1138
+ };
1139
+ }, l = this.fn(this.u32(t))(t);
1140
+ for (let e = 0; e < l; e++) {
1141
+ const r = this.fn(this.u32(t + 4))(t, e);
1142
+ if (!r) {
1143
+ s.push(`'clap_preset_discovery_factory::get_descriptor()' returned a null pointer for index ${e}.`);
1144
+ continue;
1145
+ }
1146
+ const l = h(r);
1147
+ if (!l.id || !l.name) {
1148
+ s.push(`The provider descriptor at index ${e} has no ${l.id ? "name" : "id"}.`);
1149
+ continue;
1150
+ }
1151
+ const c = this.text(l.id);
1152
+ this.crawl = {
1153
+ provider: l.id,
1154
+ errors: s,
1155
+ locations: [],
1156
+ init: !0,
1157
+ at: null,
1158
+ single: !1,
1159
+ keyed: !1,
1160
+ current: null,
1161
+ presets: n
1162
+ };
1163
+ const u = this.fn(this.u32(t + 8))(t, o, c);
1164
+ if (this.give(c), !u) {
1165
+ s.push(`'clap_preset_discovery_factory::create()' returned a null pointer for the provider with ID '${l.id}'.`);
1166
+ continue;
1167
+ }
1168
+ const p = this.u32(u) ? h(this.u32(u)) : null;
1169
+ p || s.push("The 'desc' field on the 'clap_preset_provider' struct is a null pointer."), i.push({
1170
+ id: l.id,
1171
+ name: l.name,
1172
+ vendor: l.vendor ?? "",
1173
+ sameDescriptor: !!p && p.id === l.id && p.name === l.name && p.vendor === l.vendor
1174
+ });
1175
+ const d = !!this.fn(this.u32(u + 8))(u);
1176
+ if (this.crawl.init = !1, d) for (const t of this.crawl.locations) {
1177
+ Object.assign(this.crawl, {
1178
+ at: t,
1179
+ single: !1,
1180
+ keyed: !1,
1181
+ current: null
1182
+ });
1183
+ const e = null === t.path ? 0 : this.text(t.path), i = this.fn(this.u32(u + 16))(u, t.kind, e, a);
1184
+ e && this.give(e), this.presetDone(), i || s.push(`The preset provider returned false when fetching metadata for ${t.path ?? "<plugin>"}.`);
1185
+ }
1186
+ else s.push(`'clap_preset_discovery_provider::init()' returned false for the provider with ID '${l.id}'.`);
1187
+ this.fn(this.u32(u + 12))(u), this.crawl = null;
1188
+ }
1189
+ for (const e of [
1190
+ o,
1191
+ a,
1192
+ ...r
1193
+ ]) this.give(e);
1194
+ if (s.length) throw new Error(s.join("\n"));
1195
+ return {
1196
+ providers: i,
1197
+ presets: n
1198
+ };
1199
+ }
1200
+ loadPreset(t) {
1201
+ 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);
1202
+ return s && this.give(s), i && this.give(i), n;
1203
+ }
1204
+ declared(t) {
1205
+ 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);
1206
+ }
1207
+ presetOpen(t) {
1208
+ return this.crawl?.current ? this.crawl.current : (this.crawl?.errors.push(`No preceding 'begin_preset()' call. This is not valid. (${t})`), null);
1209
+ }
1210
+ presetDone() {
1211
+ const t = this.crawl;
1212
+ 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);
1213
+ }
1214
+ crawl = null;
1215
+ fromPage(t) {
1216
+ const e = this.need(this.extension("clap.webview/3"), "clap.webview/3"), s = this.take(Math.max(t.length, 1));
1217
+ new Uint8Array(this.x.memory.buffer).set(t, s);
1218
+ const i = !!this.fn(this.u32(e + 8))(this.plugin, s, t.length);
1219
+ return this.give(s), i;
1220
+ }
1221
+ saveState() {
1222
+ if (!this.stateExt) return null;
1223
+ const t = this.stateStream(2);
1224
+ this.stream = [];
1225
+ const e = this.fn(this.u32(this.stateExt))(this.plugin, t);
1226
+ return this.give(t), e ? new Uint8Array(this.stream) : null;
1227
+ }
1228
+ loadState(t) {
1229
+ if (!this.stateExt) return !1;
1230
+ const e = this.stateStream(3);
1231
+ this.stream = [...t], this.readAt = 0;
1232
+ const s = !!this.fn(this.u32(this.stateExt + 4))(this.plugin, e);
1233
+ return this.give(e), s;
1234
+ }
1235
+ view() {
1236
+ return new DataView(this.x.memory.buffer);
1237
+ }
1238
+ u32(t) {
1239
+ return this.view().getUint32(t, !0);
1240
+ }
1241
+ fn(t) {
1242
+ return this.x.table.get(t);
1243
+ }
1244
+ cstr(t) {
1245
+ const e = new Uint8Array(this.x.memory.buffer);
1246
+ let s = t;
1247
+ for (; e[s];) s++;
1248
+ return l(e.subarray(t, s));
1249
+ }
1250
+ text(t) {
1251
+ const e = h(t), s = this.take(e.length + 1), i = new Uint8Array(this.x.memory.buffer);
1252
+ return i.set(e, s), i[s + e.length] = 0, s;
1253
+ }
1254
+ extension(t) {
1255
+ const e = this.text(t), s = this.fn(this.u32(this.plugin + R))(this.plugin, e);
1256
+ return this.give(e), s;
1257
+ }
1258
+ need(t, e) {
1259
+ if (!t) throw new Error(`the plugin has no ${e}`);
1260
+ return t;
1261
+ }
1262
+ inPool(t) {
1263
+ return t.length > this.poolRoom && (this.give(this.pool), this.poolRoom = Math.max(t.length, 2 * this.poolRoom), this.pool = this.take(nt * this.poolRoom)), t.map((t, e) => this.event(t, this.pool + e * nt));
1264
+ }
1265
+ take(t) {
1266
+ const e = this.x.malloc(t);
1267
+ return this.owned.add(e), e;
1268
+ }
1269
+ give(t) {
1270
+ this.owned.delete(t), this.x.free(t);
1271
+ }
1272
+ stateStream(t) {
1273
+ const e = this.take(8);
1274
+ return this.view().setUint32(e, 0, !0), this.view().setUint32(e + 4, this.base + t, !0), e;
1275
+ }
1276
+ event(e, r) {
1277
+ const h = this.view();
1278
+ if (new Uint8Array(this.x.memory.buffer, r, nt).fill(0), "raw" === e.type) {
1279
+ if (e.bytes.length > nt) throw new Error("an event of at most 112 bytes");
1280
+ return new Uint8Array(this.x.memory.buffer).set(e.bytes, r), r;
1281
+ }
1282
+ if ("param" === e.type) n(h, r, e.time, e.id, e.value);
1283
+ else if ("midi" === e.type) o(h, r, e.time, 0, e.data);
1284
+ else if ("expression" === e.type) i(h, r, e.time, {
1285
+ noteId: e.noteId ?? -1,
1286
+ port: e.port ?? -1,
1287
+ channel: e.channel ?? -1,
1288
+ key: e.key ?? -1
1289
+ }, a[e.expression], e.value);
1290
+ else {
1291
+ const i = "on" === e.type ? t.noteOn : "off" === e.type ? t.noteOff : t.choke;
1292
+ s(h, r, e.time, i, {
1293
+ noteId: e.noteId ?? -1,
1294
+ port: e.port ?? 0,
1295
+ channel: e.channel ?? 0,
1296
+ key: e.key
1297
+ }, e.velocity ?? 0);
1298
+ }
1299
+ return r;
1300
+ }
1301
+ }, at = class {
1302
+ s;
1303
+ constructor(t = 322398055) {
1304
+ this.s = /* @__PURE__ */ new Uint32Array(4);
1305
+ let e = t >>> 0;
1306
+ for (let s = 0; s < 4; s++) {
1307
+ e = e + 2654435769 >>> 0;
1308
+ let t = e;
1309
+ t = Math.imul(t ^ t >>> 16, 2246822507) >>> 0, t = Math.imul(t ^ t >>> 13, 3266489909) >>> 0, this.s[s] = (t ^ t >>> 16) >>> 0;
1310
+ }
1311
+ }
1312
+ u32() {
1313
+ const t = this.s, e = (t, e) => (t << e | t >>> 32 - e) >>> 0, s = e(t[0] + t[3] >>> 0, 7) + t[0] >>> 0, i = t[1] << 9 >>> 0;
1314
+ return t[2] ^= t[0], t[3] ^= t[1], t[1] ^= t[2], t[0] ^= t[3], t[2] ^= i, t[3] = e(t[3], 11), s;
1315
+ }
1316
+ unit() {
1317
+ return (this.u32() * 2 ** 21 + (this.u32() >>> 11)) / 2 ** 53;
1318
+ }
1319
+ int(t, e) {
1320
+ return t + Math.floor(this.unit() * (e - t + 1));
1321
+ }
1322
+ float(t, e) {
1323
+ return t + this.unit() * (e - t);
1324
+ }
1325
+ bool(t) {
1326
+ return this.unit() < t;
1327
+ }
1328
+ choose(t) {
1329
+ return t.length ? t[Math.floor(this.unit() * t.length)] : void 0;
1330
+ }
1331
+ noise(t) {
1332
+ return Float32Array.from({ length: t }, () => this.float(-1, 1));
1333
+ }
1334
+ };
1335
+ const ht = t;
1336
+ function lt(t, e, s) {
1337
+ const i = new Uint8Array(e);
1338
+ return s(new DataView(i.buffer)), {
1339
+ time: t,
1340
+ type: "raw",
1341
+ bytes: i
1342
+ };
1343
+ }
1344
+ function ct(t, e, i, n, r = 0) {
1345
+ return lt(t, 40, (o) => s(o, 0, t, e, i, n, r));
1346
+ }
1347
+ function ut(t, e, s, n, r = 0) {
1348
+ return lt(t, 40, (o) => i(o, 0, t, e, s, n, r));
1349
+ }
1350
+ function pt(t, e, s, i = {}) {
1351
+ return lt(t, 48, (r) => n(r, 0, t, e, s, i));
1352
+ }
1353
+ function dt(t, e, s, i = 0) {
1354
+ return lt(t, 24, (n) => o(n, 0, t, e, s, i));
1355
+ }
1356
+ var ft = class {
1357
+ ports;
1358
+ range;
1359
+ active = [];
1360
+ nextId = 0;
1361
+ consistent = !0;
1362
+ overlapping = !1;
1363
+ wildcards = !1;
1364
+ constructor(t, e = [-6, 5]) {
1365
+ this.ports = t, this.range = e;
1366
+ }
1367
+ reset() {
1368
+ this.active = [], this.nextId = 0;
1369
+ }
1370
+ randomNote(t) {
1371
+ return {
1372
+ port: t.int(0, 9),
1373
+ key: t.int(0, 127),
1374
+ channel: t.int(0, 15),
1375
+ noteId: t.int(0, 99),
1376
+ live: t.bool(.1),
1377
+ choked: !1
1378
+ };
1379
+ }
1380
+ filter(t, e) {
1381
+ const s = (e) => this.wildcards && t.bool(.1) ? -1 : e;
1382
+ return {
1383
+ port: s(e.port),
1384
+ channel: s(e.channel),
1385
+ key: s(e.key),
1386
+ noteId: s(e.noteId)
1387
+ };
1388
+ }
1389
+ matches(t, e) {
1390
+ return (t.port < 0 || t.port === e.port) && (t.channel < 0 || t.channel === e.channel) && (t.key < 0 || t.key === e.key) && (t.noteId < 0 || t.noteId === e.noteId);
1391
+ }
1392
+ events(t, e) {
1393
+ const s = [];
1394
+ let i = Math.max(0, t.int(...this.range));
1395
+ for (; i < e;) {
1396
+ const e = this.event(t, i);
1397
+ if (!e) break;
1398
+ s.push(e), i += Math.max(0, t.int(...this.range));
1399
+ }
1400
+ return s;
1401
+ }
1402
+ event(t, e) {
1403
+ if (!this.ports.length) return null;
1404
+ const s = t.int(0, this.ports.length - 1), i = this.ports[s], n = [...i.clap ? [
1405
+ "clapOn",
1406
+ "clapOff",
1407
+ "clapChoke",
1408
+ "clapExpression"
1409
+ ] : [], ...i.midi ? [
1410
+ "midiOn",
1411
+ "midiOff",
1412
+ "midiChannelPressure",
1413
+ "midiPolyPressure",
1414
+ "midiPitchBend",
1415
+ "midiCc",
1416
+ "midiProgram"
1417
+ ] : []];
1418
+ if (!n.length) return null;
1419
+ for (let r = 0; r < 1024; r++) {
1420
+ const i = t.choose(n), r = (t) => t.live ? 1 : 0;
1421
+ if ("clapOn" === i || "midiOn" === i) {
1422
+ let n;
1423
+ if (this.consistent) {
1424
+ if (n = {
1425
+ ...this.randomNote(t),
1426
+ noteId: this.nextId,
1427
+ port: s
1428
+ }, !this.overlapping && this.active.some((t) => t.port === n.port && t.channel === n.channel && t.key === n.key)) continue;
1429
+ this.active.push(n), this.nextId = this.nextId + 1 | 0;
1430
+ } else n = this.randomNote(t);
1431
+ if ("clapOn" === i) return ct(e, ht.noteOn, n, t.float(0, 1), r(n));
1432
+ const o = Math.min(127, Math.max(0, Math.round(127 * t.float(0, 1))));
1433
+ return dt(e, s, [
1434
+ 144 | n.channel,
1435
+ n.key,
1436
+ o
1437
+ ], r(n));
1438
+ }
1439
+ if ("clapOff" === i || "clapChoke" === i || "clapExpression" === i || "midiOff" === i || "midiPolyPressure" === i) {
1440
+ let n;
1441
+ if (this.consistent) {
1442
+ if (n = t.choose("clapChoke" === i ? this.active.filter((t) => !t.choked) : this.active), !n) continue;
1443
+ } else n = this.randomNote(t);
1444
+ if ("midiOff" === i) {
1445
+ const i = n;
1446
+ this.active = this.active.filter((t) => !(t.port === i.port && t.channel === i.channel && t.key === i.key));
1447
+ const o = Math.min(127, Math.max(0, Math.round(127 * t.float(0, 1))));
1448
+ return dt(e, s, [
1449
+ 128 | i.channel,
1450
+ i.key,
1451
+ o
1452
+ ], r(i));
1453
+ }
1454
+ if ("midiPolyPressure" === i) return dt(e, s, [
1455
+ 160 | n.channel,
1456
+ n.key,
1457
+ t.int(0, 127)
1458
+ ], r(n));
1459
+ const o = this.filter(t, n);
1460
+ if ("clapOff" === i) return this.active = this.active.filter((t) => !this.matches(o, t)), ct(e, ht.noteOff, o, t.float(0, 1), r(n));
1461
+ if ("clapChoke" === i) {
1462
+ for (const t of this.active) this.matches(o, t) && (t.choked = !0);
1463
+ return ct(e, ht.choke, o, NaN, r(n));
1464
+ }
1465
+ const a = t.int(0, 6);
1466
+ return ut(e, o, a, 0 === a ? t.float(0, 4) : 2 === a ? t.float(-128, 128) : t.float(0, 1), r(n));
1467
+ }
1468
+ const o = t.int(0, 15);
1469
+ if ("midiChannelPressure" === i) return dt(e, s, [
1470
+ 208 | o,
1471
+ t.int(0, 127),
1472
+ 0
1473
+ ]);
1474
+ if ("midiPitchBend" === i) {
1475
+ const i = Math.min(16383, Math.max(0, Math.round(8191.5 * (t.float(-1, 1) + 1))));
1476
+ return dt(e, s, [
1477
+ 224 | o,
1478
+ 127 & i,
1479
+ i >> 7
1480
+ ]);
1481
+ }
1482
+ return dt(e, s, "midiCc" === i ? [
1483
+ 176 | o,
1484
+ t.int(0, 127),
1485
+ t.int(0, 127)
1486
+ ] : [
1487
+ 192 | o,
1488
+ t.int(0, 127),
1489
+ 0
1490
+ ]);
1491
+ }
1492
+ throw new Error("Unable to generate a random note event after 1024 tries");
1493
+ }
1494
+ stopAll(t) {
1495
+ const e = this.active.map((e) => this.ports[e.port]?.clap ? ct(t, ht.noteOff, e, 0) : dt(t, e.port, [
1496
+ 128 | e.channel,
1497
+ e.key,
1498
+ 0
1499
+ ]));
1500
+ return this.active = [], e;
1501
+ }
1502
+ };
1503
+ function mt(t, e) {
1504
+ const s = t.float(e.min, e.max);
1505
+ return e.stepped ? Math.round(s) : s;
1506
+ }
1507
+ const gt = (t) => t.filter((t) => !t.readonly);
1508
+ function wt(t, e, s, i = !1) {
1509
+ return gt(e).map((e) => pt(s, e.id, i ? t.bool(.5) ? e.min : e.max : mt(t, e), { flags: e.automatable ? 0 : 1 }));
1510
+ }
1511
+ function vt(t, e, s) {
1512
+ const i = gt(e), n = [];
1513
+ let r = Math.max(0, t.int(-10, 20));
1514
+ for (; r < s && i.length;) {
1515
+ const e = t.choose(i);
1516
+ n.push(pt(0, e.id, mt(t, e), { flags: e.automatable ? 0 : 1 })), r += Math.max(0, t.int(-10, 20));
1517
+ }
1518
+ return n;
1519
+ }
1520
+ const yt = () => ({
1521
+ playing: !1,
1522
+ recording: !1,
1523
+ tsig: [4, 4],
1524
+ tempo: [120, 0],
1525
+ seconds: 0,
1526
+ beats: 0,
1527
+ samplePos: 0,
1528
+ freerun: !1
1529
+ });
1530
+ function bt(t, e) {
1531
+ t.bool(.2) && (e.playing = !e.playing), t.bool(.2) && (e.recording = !e.recording), t.bool(.2) && (e.tsig = t.bool(.5) ? null : [t.int(1, 16), t.int(1, 4)]), t.bool(.2) && (e.tempo = t.bool(.5) ? null : [t.float(40, 480), 0]), e.tempo && t.bool(.2) && (e.tempo = [Math.max(e.tempo[0], 20), t.float(-.01, .01)]), t.bool(.2) && (e.seconds = t.bool(.5) ? null : t.float(0, 60), e.beats = t.bool(.5) ? null : t.float(0, 240), e.samplePos = t.bool(.5) ? null : (e.samplePos ?? 0) + t.int(0, 1e5)), e.tempo || (e.beats = null), !e.playing && e.tempo && (e.tempo = [e.tempo[0], 0]);
1532
+ }
1533
+ function xt(t, e, s) {
1534
+ if (!t.playing) return;
1535
+ const i = e / s;
1536
+ null !== t.seconds && (t.seconds += i), null !== t.beats && t.tempo && (t.beats += i * t.tempo[0] / 60), null !== t.samplePos && (t.samplePos += e), t.tempo && (t.tempo = [Math.min(Math.max(t.tempo[0] + t.tempo[1] * e, 1), 1e4), t.tempo[1]]);
1537
+ }
1538
+ const kt = (t) => BigInt(Math.round(2147483648 * t));
1539
+ function Et(t) {
1540
+ return {
1541
+ flags: (t.tempo ? 1 : 0) | (null !== t.beats ? 2 : 0) | (null !== t.seconds ? 4 : 0) | (t.tsig ? 8 : 0) | (t.playing ? 16 : 0) | (t.recording ? 32 : 0),
1542
+ songPosBeats: kt(t.beats ?? 0),
1543
+ songPosSeconds: kt(t.seconds ?? 0),
1544
+ tempo: t.tempo?.[0] ?? 0,
1545
+ tempoInc: t.tempo?.[1] ?? 0,
1546
+ loopStartBeats: 0n,
1547
+ loopEndBeats: 0n,
1548
+ loopStartSeconds: 0n,
1549
+ loopEndSeconds: 0n,
1550
+ barStart: 0n,
1551
+ barNumber: 0,
1552
+ tsigNum: t.tsig?.[0] ?? 0,
1553
+ tsigDenom: t.tsig?.[1] ?? 0
1554
+ };
1555
+ }
1556
+ function At(t, s) {
1557
+ const i = Et(s), n = /* @__PURE__ */ new Uint8Array(104), o = new DataView(n.buffer);
1558
+ return e(o, 0, 104, t, ht.transport), r(o, 0, i), {
1559
+ time: t,
1560
+ type: "raw",
1561
+ bytes: n
1562
+ };
1563
+ }
1564
+ const $t = 2143294004, _t = 117549435e-46;
1565
+ var Ut = class extends Error {};
1566
+ const It = (t) => {
1567
+ throw new Ut(t);
1568
+ };
1569
+ var Pt = class {
1570
+ host;
1571
+ frames;
1572
+ sampleRate;
1573
+ transport = {
1574
+ playing: !1,
1575
+ recording: !1,
1576
+ tsig: [4, 4],
1577
+ tempo: [120, 0],
1578
+ seconds: 0,
1579
+ beats: 0,
1580
+ samplePos: 0,
1581
+ freerun: !1
1582
+ };
1583
+ checkDenormals = !0;
1584
+ outputs = [];
1585
+ state = "deactivated";
1586
+ inputs;
1587
+ constructor(t, e, s = 44100) {
1588
+ this.host = t, this.frames = e, this.sampleRate = s, this.inputs = Array.from({ length: t.audioIn }, () => new Float32Array(e));
1589
+ }
1590
+ noise(t) {
1591
+ for (const e of this.inputs) e.set(t.noise(this.frames));
1592
+ }
1593
+ silence() {
1594
+ for (const t of this.inputs) t.fill(0);
1595
+ }
1596
+ fillInputs(t) {
1597
+ for (const e of this.inputs) for (let s = 0; s < e.length; s++) e[s] = t();
1598
+ }
1599
+ activate() {
1600
+ "deactivated" === this.state && (this.host.activate(this.sampleRate, this.frames), this.state = "activated"), "activated" === this.state && (this.host.startProcessing() || It("'clap_plugin::start_processing()' returned false"), this.state = "processing");
1601
+ }
1602
+ run(t = [], e = this.frames) {
1603
+ if (e < 1 || e > this.frames) throw new Error("a block of 1..frames");
1604
+ if (t.some((t) => t.time >= e)) throw new Error("The input event queue contains events beyond the current processing block size");
1605
+ this.activate(), this.host.setTransportFull(this.transport.freerun ? null : Et(this.transport)), this.host.pushed();
1606
+ const s = this.inputs.map((t) => t.slice()), i = this.host.processChecked(e, [...t].sort((t, e) => t.time - e.time), this.inputs, $t);
1607
+ 0 === i.status && It("The plugin returned CLAP_PROCESS_ERROR"), this.outputs = i.outputs.map((t) => t.slice(0, e)), xt(this.transport, e, this.sampleRate), i.inputs.forEach((t, e) => {
1608
+ for (let i = 0; i < t.length; i++) Object.is(t[i], s[e][i]) || Number.isNaN(t[i]) && Number.isNaN(s[e][i]) || It(`The plugin has overwritten an input buffer (index 0) during out-of-place processing, at channel ${e} and sample index ${i}.`);
1609
+ });
1610
+ i.outputs.forEach((t, s) => {
1611
+ const n = new Uint32Array(t.buffer, t.byteOffset, t.length);
1612
+ if (i.constantMask >> BigInt(s) & 1n) {
1613
+ let [e, i] = [1 / 0, -1 / 0];
1614
+ for (let s = 0; s < t.length; s++) {
1615
+ const n = Math.abs(t[s]);
1616
+ n < e && (e = n), n > i && (i = n);
1617
+ }
1618
+ const n = .5 * (i - e);
1619
+ n < .001 || It(`The output channel ${s} of port 0 is not constant despite the constant flag being set (${(20 * Math.log10(n)).toFixed(2)} dBFS).`);
1620
+ }
1621
+ for (let i = 0; i < e; i++) {
1622
+ const e = t[i], r = 0 !== e && Math.abs(e) < _t;
1623
+ (!Number.isFinite(e) || r && this.checkDenormals) && (r && It(`The sample written to output port 0, channel ${s}, and sample index ${i} is subnormal (${e}).`), n[i] === $t && It(`The sample at output port 0, channel ${s}, and sample index ${i} was left unwritten.`), It(`The sample written to output port 0, channel ${s}, and sample index ${i} is ${e}.`));
1624
+ }
1625
+ for (let i = e; i < t.length; i++) n[i] !== $t && It(`The plugin has overwritten a sample beyond the current processing block size at channel ${s} and sample index ${i}. The block size is ${e}.`);
1626
+ });
1627
+ let n = 0;
1628
+ for (const r of this.host.pushed()) r.time < n && It(`The plugin output an event for sample ${r.time} after it had previously output an event for sample ${n}.`), r.time >= e && It(`The plugin output an event for sample ${r.time} but the audio buffer only contains ${e} samples.`), 0 === r.space && r.type === ht.transport && It("The plugin emitted a transport event during processing, which is not allowed."), n = r.time;
1629
+ return i.status;
1630
+ }
1631
+ reset() {
1632
+ "deactivated" !== this.state && this.host.reset();
1633
+ }
1634
+ deactivate() {
1635
+ "processing" === this.state && this.host.stopProcessing(), "deactivated" !== this.state && this.host.deactivate(), this.state = "deactivated";
1636
+ }
1637
+ };
1638
+ const Tt = 512, Mt = (t) => ({
1639
+ status: "skipped",
1640
+ details: t
1641
+ }), St = (t) => t.notes ? [{
1642
+ clap: !0,
1643
+ midi: !0
1644
+ }] : [];
1645
+ function Ct(t, e, s) {
1646
+ return t.stepped ? Math.round(e) === Math.round(s) : Math.abs((e - t.min) / (t.max - t.min) - (s - t.min) / (t.max - t.min)) <= 1e-4;
1647
+ }
1648
+ function Ot(t) {
1649
+ return new Map(t.params.map((e) => [e.id, t.value(e.id)]));
1650
+ }
1651
+ function Ft(t, e, s) {
1652
+ const i = [], n = (e, s) => {
1653
+ if (void 0 === s) return "missing";
1654
+ const i = t.valueToText(e.id, s);
1655
+ return null !== i ? `${i} (${s.toFixed(4)})` : s.toFixed(4);
1656
+ };
1657
+ for (const r of t.params) {
1658
+ const [o, a] = [e.get(r.id), s.get(r.id)], h = void 0 === o ? null : t.valueToText(r.id, o), l = void 0 === a ? null : t.valueToText(r.id, a);
1659
+ null !== h && null !== l && h === l || void 0 !== o && void 0 !== a && Ct(r, o, a) || i.push(` - ${r.name} (${r.id}) - ${n(r, o)} vs ${n(r, a)}`);
1660
+ }
1661
+ return i.length ? i.length > 5 ? `${i.slice(0, 5).join("\n")}\n...and ${i.length - 5} more` : i.join("\n") : null;
1662
+ }
1663
+ const Rt = {
1664
+ "query-nonexistent-factory": (t, e) => {
1665
+ const s = t();
1666
+ for (let i = 0; i < 10; i++) {
1667
+ const t = `foo-factory-${e.u32()}${e.u32()}`;
1668
+ s.hasFactory(t) && It(`Querying a factory with the non-existent factory ID '${t}' should return a null pointer, but the plugin returned a non-null pointer instead. The plugin may be unconditionally returning the plugin factory.`);
1669
+ }
1670
+ },
1671
+ "create-id-with-trailing-garbage": (t) => {
1672
+ const e = t(), s = `${e.descriptor.id}x1`;
1673
+ e.creates(s) && It(`Creating a plugin instance with a non-existent plugin ID '${s}' should return a null pointer, but it did not.`);
1674
+ },
1675
+ "scan-rtld-now": () => Mt("This test is only relevant to Unix-like platforms (a native library; a WebCLAP has none)"),
1676
+ "preset-discovery-crawl": (t) => Bt(t()) ? void 0 : Dt,
1677
+ "preset-discovery-descriptor-consistency": (t) => {
1678
+ const e = Bt(t());
1679
+ if (!e) return Dt;
1680
+ const s = e.providers.find((t) => !t.sameDescriptor);
1681
+ s && It(`The 'clap_preset_discovery_provider_descriptor' stored on '${s.id}'s 'clap_preset_discovery_provider' object contains different values than the one returned by the factory.`);
1682
+ },
1683
+ "preset-discovery-load": (t) => {
1684
+ const e = t(), s = Bt(e);
1685
+ if (!s) return Dt;
1686
+ const i = /* @__PURE__ */ new Map();
1687
+ for (const n of s.presets) for (const { abi: t, id: e } of n.pluginIds) "clap" === t && i.set(e, [...i.get(e) ?? [], n]);
1688
+ for (const [n, r] of i) {
1689
+ const t = e.another(n);
1690
+ if (!t.hasExtension("clap.preset-load/2")) return Mt(`'${n}' does not implement the 'preset-load' extension.`);
1691
+ for (const e of r) {
1692
+ const s = t.toldHost.presetErrors.length, i = t.loadPreset(e), r = t.toldHost.presetErrors.slice(s);
1693
+ r.length && It(`An error occurred while loading the preset '${e.name}' for plugin '${n}': ${r.join("; ")}`), i || It(`Could not load the preset '${e.name}' for plugin '${n}'`), t.activate(44100, 512), t.startProcessing(), t.process([]), t.stopProcessing(), t.deactivate();
1694
+ }
1695
+ t.destroy();
1696
+ }
1697
+ },
1698
+ "descriptor-consistency": (t) => {
1699
+ const e = t();
1700
+ if (JSON.stringify(e.descriptorFields("factory")) !== JSON.stringify(e.descriptorFields("instance"))) return {
1701
+ status: "failed",
1702
+ details: `The 'clap_plugin_descriptor' stored on '${e.descriptor.id}'s 'clap_plugin' object contains different values than the one returned by the factory.`
1703
+ };
1704
+ },
1705
+ "features-categories": (t) => {
1706
+ t().descriptor.features.some((t) => [
1707
+ "instrument",
1708
+ "audio-effect",
1709
+ "note-detector",
1710
+ "note-effect",
1711
+ "analyzer"
1712
+ ].includes(t)) || It("The plugin needs to have at least one of the following plugin category features: \"instrument\", \"audio-effect\", \"note-effect\", or \"analyzer\".");
1713
+ },
1714
+ "features-duplicates": (t) => {
1715
+ const e = t().descriptor.features;
1716
+ new Set(e).size !== e.length && It(`The plugin has duplicate features: ${JSON.stringify([...e].sort())}`);
1717
+ },
1718
+ "process-audio-basic-out-of-place": (t, e) => {
1719
+ const s = new Pt(t(), Tt);
1720
+ for (let i = 0; i < 5; i++) s.noise(e), s.run();
1721
+ s.deactivate();
1722
+ },
1723
+ "process-audio-basic-in-place": (t, e) => {
1724
+ const s = new Pt(t(), Tt);
1725
+ for (let i = 0; i < 5; i++) s.noise(e), s.run();
1726
+ s.deactivate();
1727
+ },
1728
+ "process-audio-double-out-of-place": () => Mt("The plugin does not support 64-bit floating point audio."),
1729
+ "process-audio-double-in-place": () => Mt("The plugin does not support 64-bit floating point audio."),
1730
+ "process-audio-denormals": (t, e) => {
1731
+ const s = t();
1732
+ if (!s.audioIn) return Mt("The plugin implements the 'audio-ports' extension but it does not have any input audio ports.");
1733
+ const i = new ft(St(s), [-4, 64]), n = (t) => {
1734
+ const n = new Pt(s, Tt);
1735
+ n.checkDenormals = !1;
1736
+ const r = performance.now();
1737
+ for (let s = 0; s < 50; s++) {
1738
+ const s = i.events(e, Tt);
1739
+ t ? n.fillInputs(() => e.float(-117549435e-46, _t)) : n.noise(e), n.run(s);
1740
+ }
1741
+ return n.deactivate(), performance.now() - r;
1742
+ }, r = n(!0) / n(!1);
1743
+ return r > 2 ? {
1744
+ status: "warning",
1745
+ details: `The plugin took ${r.toFixed(2)}x longer to process denormals, you should set flush-to-zero flags or avoid denormals in some other way.`
1746
+ } : r > 1.2 ? {
1747
+ status: "passed",
1748
+ details: `The plugin took ${r.toFixed(2)}x longer to process denormals`
1749
+ } : void 0;
1750
+ },
1751
+ "process-sleep-constant-mask": (t, e) => {
1752
+ const s = t(), i = new Pt(s, Tt), n = new ft(St(s), [-4, 64]);
1753
+ i.silence(), i.run(), i.noise(e), i.run(n.events(e, Tt)), i.silence(), i.run(n.stopAll(0));
1754
+ for (let r = 1; r < 38; r++) i.run();
1755
+ return i.deactivate(), {
1756
+ status: "passed",
1757
+ details: "Every output channel flagged constant was constant"
1758
+ };
1759
+ },
1760
+ "process-sleep-process-status": (t, e) => {
1761
+ const s = t(), i = new Pt(s, Tt), n = new ft(St(s), [-4, 64]);
1762
+ let r = !1, o = !1, a = 0;
1763
+ for (const h of [
1764
+ !0,
1765
+ !1,
1766
+ !0,
1767
+ !1,
1768
+ !0,
1769
+ !0
1770
+ ]) for (let t = 0; t < 10; t++) {
1771
+ let t;
1772
+ h ? (t = n.stopAll(0), i.silence()) : (t = n.events(e, Tt), i.noise(e));
1773
+ const l = i.run(t);
1774
+ if (o ||= r, 1 === l) r = !1;
1775
+ else if (4 === l) r = !0;
1776
+ else if (3 === l) {
1777
+ const t = s.tail();
1778
+ null === t && It("Plugin returned `CLAP_PROCESS_TAIL` process status but does not implement the 'tail' extension."), r = t < a, a = h ? a + Tt : 0;
1779
+ }
1780
+ }
1781
+ if (i.deactivate(), !o) return {
1782
+ status: "passed",
1783
+ details: "The plugin never went to sleep during the test."
1784
+ };
1785
+ },
1786
+ "process-note-out-of-place-basic": (t, e) => Nt(t, e, !1, !1),
1787
+ "process-note-inconsistent": (t, e) => Nt(t, e, !0, !1),
1788
+ "process-note-wildcard": (t, e) => Nt(t, e, !1, !0),
1789
+ "process-varying-sample-rates": (t, e) => {
1790
+ const s = t();
1791
+ for (const n of [
1792
+ 8e3,
1793
+ 22050,
1794
+ 44100,
1795
+ 48e3,
1796
+ 88200,
1797
+ 96e3,
1798
+ 192e3,
1799
+ 384e3,
1800
+ 768e3,
1801
+ 1234.5678,
1802
+ 12345.678,
1803
+ 45678.901,
1804
+ 123456.78
1805
+ ]) {
1806
+ const t = new ft(St(s), [-4, 64]), r = new Pt(s, Tt, n);
1807
+ try {
1808
+ for (let s = 0; s < 5; s++) r.noise(e), r.run(t.events(e, Tt));
1809
+ } catch (i) {
1810
+ throw i instanceof Ut ? new Ut(`Error while processing with ${n.toFixed(2)}hz sample rate: ${i.message}`) : i;
1811
+ }
1812
+ r.deactivate();
1813
+ }
1814
+ },
1815
+ "process-varying-block-sizes": (t, e) => {
1816
+ for (const i of [
1817
+ 1,
1818
+ 256,
1819
+ 1024,
1820
+ 4096,
1821
+ 16384,
1822
+ 1536,
1823
+ 10,
1824
+ 17,
1825
+ 2027
1826
+ ]) {
1827
+ const n = t(), r = new ft(St(n), [-4, 64]), o = new Pt(n, i);
1828
+ try {
1829
+ for (let t = 0; t < Math.min(Math.floor(16384 / i), 5); t++) o.noise(e), o.run(r.events(e, i));
1830
+ } catch (s) {
1831
+ throw s instanceof Ut ? new Ut(`Error while processing with buffer size of ${i}: ${s.message}`) : s;
1832
+ }
1833
+ o.deactivate();
1834
+ }
1835
+ },
1836
+ "process-random-block-sizes": (t, e) => {
1837
+ const s = t(), i = new Pt(s, 2048), n = new ft(St(s), [-4, 64]);
1838
+ for (let o = 0; o < 20; o++) {
1839
+ const t = e.bool(.8) ? e.int(2, 2048) : 1;
1840
+ i.noise(e);
1841
+ try {
1842
+ i.run(n.events(e, t), t);
1843
+ } catch (r) {
1844
+ throw r instanceof Ut ? new Ut(`Error while processing with buffer size of ${t}: ${r.message}`) : r;
1845
+ }
1846
+ }
1847
+ i.deactivate();
1848
+ },
1849
+ "process-reset-reactivate": (t, e) => {
1850
+ const s = t(), i = new Pt(s, Tt), n = new ft(St(s), [-4, 64]);
1851
+ i.noise(e), i.run(n.events(e, Tt)), i.deactivate(), n.reset(), i.noise(e), i.run(n.events(e, Tt)), i.reset(), n.reset(), i.noise(new at()), i.run(n.events(new at(), Tt)), i.deactivate();
1852
+ },
1853
+ "layout-audio-ports-activation": () => Mt("The plugin does not implement the 'audio-ports-activation' extension."),
1854
+ "layout-audio-ports-config": () => Mt("The plugin does not implement the 'audio-ports-config' extension."),
1855
+ "layout-configurable-audio-ports": () => Mt("The plugin does not implement the 'configurable-audio-ports' extension."),
1856
+ "param-conversions": (t) => {
1857
+ const e = t(), s = e.params.length;
1858
+ if (!s) return Mt("The plugin implements the 'params' extension, but does not have any parameters.");
1859
+ const i = Math.min(Math.max(Math.ceil(4e3 / s), 5), 100), n = s * i;
1860
+ let [r, o] = [0, 0];
1861
+ const a = [], h = [];
1862
+ for (const l of e.params) for (let t = 0; t < i; t++) {
1863
+ const s = l.min + (l.max - l.min) * t / (i - 1), n = e.valueToText(l.id, s);
1864
+ if (null === n) {
1865
+ a.push(`\n - ${l.name}: ${s.toFixed(4)}`);
1866
+ break;
1867
+ }
1868
+ r++;
1869
+ const c = e.textToValue(l.id, n);
1870
+ if (null === c) {
1871
+ h.push(`\n - ${l.name}: '${n}'`);
1872
+ continue;
1873
+ }
1874
+ o++;
1875
+ const u = e.valueToText(l.id, c);
1876
+ null === u && It(`Failure in repeated value to text conversion for parameter ${l.id} ('${l.name}')`), n !== u && It(`Converting ${s} to a string, back to a value, and then back to a string again for parameter '${l.name}' (${l.id}) results in '${n}' -> ${c} -> '${u}', which is not consistent.`);
1877
+ const p = e.textToValue(l.id, u);
1878
+ null === p && It(`Failure in repeated text to value conversion for parameter ${l.id} ('${l.name}')`), p !== c && It(`Converting ${s} to a string, back to a value, back to a string, and then back to a value again for parameter '${l.name}' (${l.id}) results in '${n}' -> ${c} -> '${u}' -> ${p}, which is not consistent.`);
1879
+ }
1880
+ if (0 === r || 0 === o) return {
1881
+ status: "passed",
1882
+ details: "The plugin does not support text-to-value and value-to-text parameter conversions"
1883
+ };
1884
+ r !== n && It(`'clap_plugin_params::value_to_text()' returned true for ${r} out of ${n} calls. This function is expected to be supported for either none of the parameters or for all of them. Examples of failing conversions were: ${a.slice(0, 10).join("")}`), o !== n && It(`'clap_plugin_params::text_to_value()' returned true for ${o} out of ${n} calls. This function is expected to be supported for either none of the parameters or for all of them. Examples of failing conversions were: ${h.slice(0, 10).join("")}`);
1885
+ },
1886
+ "param-set-events": (t) => Lt(t),
1887
+ "param-set-no-cookies": (t) => Lt(t),
1888
+ "param-set-wrong-namespace": (t, e) => {
1889
+ const s = t(), i = Ot(s), n = wt(e, s.params, 0).map((t) => {
1890
+ const e = t.bytes;
1891
+ return new DataView(e.buffer).setUint16(8, 45887, !0), t;
1892
+ }), r = new Pt(s, Tt);
1893
+ r.noise(e), r.run(n), r.deactivate();
1894
+ const o = Ot(s);
1895
+ if ([...i].some(([t, e]) => o.get(t) !== e)) return {
1896
+ status: "failed",
1897
+ details: "Sending events with type ID 5 (CLAP_EVENT_PARAM_VALUE) and namespace ID 0xb33f to the plugin caused its parameter values to change. This should not happen. The plugin may not be checking the event's namespace ID."
1898
+ };
1899
+ },
1900
+ "param-fuzz-basic": (t, e) => zt(t, e, !1),
1901
+ "param-fuzz-bounds": (t, e) => zt(t, e, !0),
1902
+ "param-fuzz-sample-accurate": (t, e) => {
1903
+ const s = t(), i = new ft(St(s), [-1, 128]);
1904
+ for (const n of [
1905
+ 1e3,
1906
+ 100,
1907
+ 10
1908
+ ]) {
1909
+ const t = new Pt(s, Tt);
1910
+ let r = 0;
1911
+ for (let o = 0; o < Math.ceil(4 * n / Tt); o++) {
1912
+ const o = [];
1913
+ for (; r < Tt;) o.push(...wt(e, s.params, r)), r += n;
1914
+ r -= Tt, t.noise(e), t.run([...o, ...i.events(e, Tt)]);
1915
+ }
1916
+ t.deactivate();
1917
+ }
1918
+ },
1919
+ "param-fuzz-modulation": (t, e) => {
1920
+ const s = t();
1921
+ if (!s.params.length) return;
1922
+ const i = new ft(St(s)), n = new Pt(s, Tt);
1923
+ n.noise(e), n.run([...vt(e, s.params, Tt), ...i.events(e, Tt)]), n.deactivate();
1924
+ },
1925
+ "param-default-values": (t) => {
1926
+ const e = t();
1927
+ for (const s of e.params) {
1928
+ const t = e.value(s.id);
1929
+ Ct(s, t, s.init) || It(`The default value for parameter ${s.id} ('${s.name}') is ${s.init}, but the actual parameter value after initialization is ${t}.`);
1930
+ }
1931
+ },
1932
+ "state-invalid-empty": (t) => {
1933
+ if (t().loadState(/* @__PURE__ */ new Uint8Array(0))) return {
1934
+ status: "warning",
1935
+ details: "The plugin returned true when 'clap_plugin_state::load()' was called when an empty state, this is likely a bug."
1936
+ };
1937
+ },
1938
+ "state-invalid-random": (t, e) => {
1939
+ const s = t();
1940
+ let i = !1;
1941
+ for (let n = 0; n < 3; n++) {
1942
+ const t = new Uint8Array(1 << 20);
1943
+ for (let s = 0; s < t.length; s += 4) new DataView(t.buffer).setUint32(s, e.u32(), !0);
1944
+ i ||= s.loadState(t);
1945
+ }
1946
+ if (i) return {
1947
+ status: "warning",
1948
+ details: "The plugin loaded random bytes successfully, which is unexpected, but the plugin did not crash."
1949
+ };
1950
+ },
1951
+ "state-reproducibility-basic": (t, e) => Vt(t, e, !1, !1),
1952
+ "state-reproducibility-buffered": (t, e) => Vt(t, e, !0, !1),
1953
+ "state-reproducibility-binary": (t, e) => Vt(t, e, !1, !0),
1954
+ "transport-null": (t, e) => {
1955
+ const s = t(), i = new ft(St(s), [-1, 128]), n = new Pt(s, 128);
1956
+ for (let r = 0; r < 5; r++) {
1957
+ n.transport.freerun = !0;
1958
+ const t = i.events(e, 128);
1959
+ n.noise(e), n.run(t);
1960
+ }
1961
+ n.deactivate();
1962
+ },
1963
+ "transport-fuzz": (t, e) => {
1964
+ const s = t(), i = new ft(St(s), [-1, 128]), n = new Pt(s, 128);
1965
+ for (let r = 0; r < 80; r++) {
1966
+ bt(e, n.transport);
1967
+ const t = i.events(e, 128);
1968
+ n.noise(e), n.run(t);
1969
+ }
1970
+ n.deactivate();
1971
+ },
1972
+ "transport-fuzz-sample-accurate": (t, e) => {
1973
+ for (const i of [
1974
+ 1e3,
1975
+ 100,
1976
+ 1
1977
+ ]) {
1978
+ const n = t(), r = new ft(St(n), [-1, 128]), o = new Pt(n, 128), a = yt();
1979
+ let h = yt(), l = 0;
1980
+ try {
1981
+ for (let t = 0; t < 20; t++) {
1982
+ o.transport = { ...h };
1983
+ const t = [];
1984
+ for (; l < 128;) l + i >= 128 && (h = { ...a }, xt(h, 128 - l, o.sampleRate)), xt(a, i, o.sampleRate), bt(e, a), t.push(At(l, a)), l += i;
1985
+ l -= 128, o.noise(e), o.run([...t, ...r.events(e, 128)]);
1986
+ }
1987
+ } catch (s) {
1988
+ throw s instanceof Ut ? new Ut(`Error during sample-accurate transport test with interval of ${i} samples: ${s.message}`) : s;
1989
+ }
1990
+ o.deactivate();
1991
+ }
1992
+ },
1993
+ "fw-two-instances": (t, e) => {
1994
+ const s = t(), i = s.another();
1995
+ if (!s.params.length) return Mt("The plugin has no parameters to tell two instances apart by.");
1996
+ const n = wt(e, s.params, 0), [r, o] = [t(), t()];
1997
+ s.flush(n), r.flush(n), gt(s.params).some((t) => i.value(t.id) !== o.value(t.id)) && It("A value set on one plugin of the module changed another plugin of the same module.");
1998
+ const a = [
1999
+ s,
2000
+ i,
2001
+ r,
2002
+ o
2003
+ ].map((t) => new Pt(t, Tt)), h = new ft(St(s), [-4, 64]);
2004
+ for (let l = 0; l < 4; l++) {
2005
+ const t = h.events(e, Tt);
2006
+ for (const [e, i] of a.entries()) i.fillInputs(() => 0), i.noise(new at(l + 1)), i.run(e % 2 == 0 ? t : []);
2007
+ const s = (t, e) => t.every((t, s) => t.every((t, i) => Object.is(t, e[s][i])));
2008
+ s(a[0].outputs, a[2].outputs) || It(`Block ${l}: a plugin sounded otherwise beside another plugin of the same module than alone.`), s(a[1].outputs, a[3].outputs) || It(`Block ${l}: the second plugin of the module sounded otherwise than a plugin of its own (it heard the first one's values or notes).`);
2009
+ }
2010
+ for (const l of a) l.deactivate();
2011
+ },
2012
+ "fw-memory-after-destroy": (t) => {
2013
+ const e = t(), s = () => {
2014
+ const t = e.another();
2015
+ t.activate(44100, Tt), t.startProcessing(), t.process([]), t.stopProcessing(), t.deactivate(), t.destroy();
2016
+ };
2017
+ s();
2018
+ const i = e.memoryBytes();
2019
+ for (let r = 0; r < 20; r++) s();
2020
+ const n = e.memoryBytes() - i;
2021
+ n > 0 && It(`20 plugins made and destroyed grew the module's memory by ${n} bytes: a destroyed plugin's memory is not given back.`);
2022
+ }
2023
+ }, Dt = Mt("The plugin does not implement the 'clap.preset-discovery-factory/2' factory.");
2024
+ function Bt(t) {
2025
+ try {
2026
+ return t.presets();
2027
+ } catch (e) {
2028
+ return It(`Error occurred while crawling presets: ${e instanceof Error ? e.message : String(e)}`);
2029
+ }
2030
+ }
2031
+ function Nt(t, e, s, i) {
2032
+ const n = t();
2033
+ if (!n.notes) return Mt("The plugin does not implement the 'note-ports' extension.");
2034
+ const r = new ft(St(n));
2035
+ r.consistent = !s, r.wildcards = i;
2036
+ const o = new Pt(n, Tt);
2037
+ o.activate();
2038
+ for (let a = 0; a < 5; a++) o.noise(e), o.run(r.events(e, Tt));
2039
+ o.deactivate();
2040
+ }
2041
+ function Lt(t) {
2042
+ const e = t(), s = Ot(e);
2043
+ let i = [];
2044
+ const n = new at();
2045
+ for (let u = 0; u < 100 && !i.length; u++) {
2046
+ const t = wt(n, e.params, 0);
2047
+ t.some((t) => new DataView(t.bytes.buffer).getFloat64(40, !0) !== s.get(new DataView(t.bytes.buffer).getUint32(16, !0))) && (i = t);
2048
+ }
2049
+ if (!i.length) return Mt("The plugin does not have any automatable parameters");
2050
+ e.flush(i);
2051
+ const r = Ot(e);
2052
+ [...s].every(([t, e]) => r.get(t) === e) && It("After calling 'clap_plugin_params::flush()', the parameter values did not change");
2053
+ const o = e.another(), a = Ot(o), h = new Pt(o, Tt);
2054
+ h.run(i), h.deactivate();
2055
+ const l = Ot(o);
2056
+ [...a].every(([t, e]) => l.get(t) === e) && It("After sending parameter changes via 'clap_plugin::process()', the parameter values did not change");
2057
+ const c = Ft(o, r, l);
2058
+ c && It(`The resulting parameter values after calling 'clap_plugin_params::flush()' were different from the resulting parameter values after sending the same parameter changes via 'clap_plugin::process()': \n${c}`);
2059
+ }
2060
+ function zt(t, e, s) {
2061
+ const i = t(), n = new ft(St(i), [-1, 128]);
2062
+ for (let o = 0; o < 50; o++) {
2063
+ const t = wt(e, i.params, 0, s), a = new Pt(i, Tt);
2064
+ try {
2065
+ for (let s = 0; s < 5; s++) a.noise(e), a.run([...0 === s ? t : [], ...n.events(e, Tt)]);
2066
+ } catch (r) {
2067
+ throw r instanceof Ut ? new Ut(`Invalid output detected in parameter value permutation ${o} of 50: ${r.message}`) : r;
2068
+ }
2069
+ a.deactivate();
2070
+ }
2071
+ }
2072
+ function Vt(t, e, s, i) {
2073
+ const n = t();
2074
+ n.flush(wt(e, n.params, 0));
2075
+ const r = Ot(n);
2076
+ n.streamChunk = s ? 23 : 0;
2077
+ const o = n.saveState();
2078
+ o || It("'clap_plugin_state::save()' returned false"), n.destroy();
2079
+ const a = t(), h = Ot(a), l = a.rescansAsked;
2080
+ a.streamChunk = s ? 17 : 0, a.loadState(o) || It("'clap_plugin_state::load()' returned false"), a.streamChunk = 0;
2081
+ const c = Ot(a), u = a.rescansAsked > l;
2082
+ let p = Ft(a, h, c);
2083
+ !u && p && It(`After reloading the state, these parameter values changed without a rescan request: \n${p}`), p = Ft(a, c, r), p && It(`After reloading the state, these parameter values do not match the previously saved values: \n${p}`);
2084
+ const d = a.saveState();
2085
+ if (i && (d.length !== o.length || d.some((t, e) => t !== o[e]))) return {
2086
+ status: "failed",
2087
+ details: "The saved state after loading differs from the original saved state."
2088
+ };
2089
+ }
2090
+ const Wt = 128, jt = [
2091
+ 57,
2092
+ 60,
2093
+ 64,
2094
+ 69
2095
+ ];
2096
+ function Ht(t, e) {
2097
+ try {
2098
+ const s = ot.of(t);
2099
+ s.activate(e, Wt);
2100
+ const i = s.notes && !s.audioIn ? jt.map((t) => ({
2101
+ time: 0,
2102
+ type: "on",
2103
+ key: t,
2104
+ velocity: 100 / 127
2105
+ })) : [], n = Array.from({ length: s.audioOut }, () => new Float32Array(Wt));
2106
+ s.render(n, 0, Wt, i);
2107
+ for (let t = 0; t < 20; t++) s.render(n, 0, Wt);
2108
+ const r = Math.round(e / 2 / Wt), o = performance.now();
2109
+ for (let t = 0; t < r; t++) s.render(n, 0, Wt);
2110
+ const a = (performance.now() - o) / r;
2111
+ return {
2112
+ msPerBlock: Math.round(1e3 * a) / 1e3,
2113
+ share: Math.round(a / (Wt / e * 1e3) * 1e3) / 1e3,
2114
+ notes: i.length,
2115
+ memoryBytes: s.memoryBytes()
2116
+ };
2117
+ } catch {
2118
+ return null;
2119
+ }
2120
+ }
2121
+ self.onmessage = (t) => {
2122
+ const e = t.data, s = (t) => self.postMessage(t);
2123
+ "check" === e.kind ? async function(e, s = {}) {
2124
+ const i = performance.now(), n = e instanceof WebAssembly.Module ? e : await WebAssembly.compile(e), r = e instanceof WebAssembly.Module ? null : k(e);
2125
+ ot.of(n, void 0, r);
2126
+ const o = Math.round(performance.now() - i), a = [], h = (t) => !s.only || s.only.includes(t);
2127
+ h("scan-time") && a.push(o <= 100 ? {
2128
+ test: "scan-time",
2129
+ status: "passed",
2130
+ details: `The plugin can be scanned in ${o} milliseconds.`
2131
+ } : {
2132
+ test: "scan-time",
2133
+ status: "warning",
2134
+ details: `The plugin took ${o} milliseconds to scan`
2135
+ });
2136
+ for (const [l, c] of Object.entries(Rt)) if (h(l)) try {
2137
+ const t = c(() => ot.of(n, void 0, r), new at());
2138
+ t ? "string" == typeof t ? a.push({
2139
+ test: l,
2140
+ status: t
2141
+ }) : a.push({
2142
+ test: l,
2143
+ ...t
2144
+ }) : a.push({
2145
+ test: l,
2146
+ status: "passed"
2147
+ });
2148
+ } catch (t) {
2149
+ a.push({
2150
+ test: l,
2151
+ status: "failed",
2152
+ details: t instanceof Ut ? t.message : `${t instanceof Error ? `${t.name}: ${t.message}` : String(t)}`
2153
+ });
2154
+ }
2155
+ return a;
2156
+ }(e.module).then((t) => s({
2157
+ id: e.id,
2158
+ results: t
2159
+ }), (t) => s({
2160
+ id: e.id,
2161
+ results: null,
2162
+ error: t instanceof Error ? t.message : String(t)
2163
+ })) : s({
2164
+ id: e.id,
2165
+ cost: Ht(e.module, e.sampleRate)
2166
+ });
2167
+ };