@grame/faustwasm 0.12.2 → 0.13.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 (81) hide show
  1. package/.prettierrc +5 -0
  2. package/README.md +21 -3
  3. package/assets/standalone/faustwasm/index.d.ts +38 -16
  4. package/assets/standalone/faustwasm/index.js +1574 -404
  5. package/assets/standalone/faustwasm/index.js.map +2 -2
  6. package/dist/cjs/index.d.ts +38 -16
  7. package/dist/cjs/index.js +1573 -404
  8. package/dist/cjs/index.js.map +2 -2
  9. package/dist/cjs-bundle/index.d.ts +38 -16
  10. package/dist/cjs-bundle/index.js +1576 -406
  11. package/dist/cjs-bundle/index.js.map +2 -2
  12. package/dist/esm/index.d.ts +38 -16
  13. package/dist/esm/index.js +1574 -404
  14. package/dist/esm/index.js.map +2 -2
  15. package/dist/esm-bundle/index.d.ts +38 -16
  16. package/dist/esm-bundle/index.js +1576 -406
  17. package/dist/esm-bundle/index.js.map +2 -2
  18. package/eslint.config.js +11 -0
  19. package/package.json +57 -51
  20. package/sound.cpp +163 -0
  21. package/sound.dsp +4 -0
  22. package/sound.json +1 -0
  23. package/sound.wasm +0 -0
  24. package/src/FaustAudioWorkletCommunicator.ts +150 -143
  25. package/src/FaustAudioWorkletNode.ts +173 -75
  26. package/src/FaustAudioWorkletProcessor.ts +218 -90
  27. package/src/FaustCmajor.ts +9 -3
  28. package/src/FaustCompiler.ts +112 -35
  29. package/src/FaustDspGenerator.ts +561 -117
  30. package/src/FaustDspInstance.ts +58 -24
  31. package/src/FaustFFTAudioWorkletProcessor.ts +822 -612
  32. package/src/FaustOfflineProcessor.ts +187 -56
  33. package/src/FaustScriptProcessorNode.ts +156 -49
  34. package/src/FaustSensors.ts +426 -96
  35. package/src/FaustSvgDiagrams.ts +18 -5
  36. package/src/FaustWasmInstantiator.ts +224 -70
  37. package/src/FaustWebAudioDsp.ts +1060 -349
  38. package/src/LibFaust.ts +13 -4
  39. package/src/SoundfileReader.ts +175 -131
  40. package/src/WavDecoder.ts +42 -20
  41. package/src/WavEncoder.ts +35 -21
  42. package/src/copyWebStandaloneAssets.d.ts +20 -5
  43. package/src/copyWebStandaloneAssets.js +203 -75
  44. package/src/exports-bundle.ts +5 -5
  45. package/src/exports.ts +24 -24
  46. package/src/faust2CmajorFiles.d.ts +7 -3
  47. package/src/faust2cmajorFiles.js +10 -8
  48. package/src/faust2svgFiles.d.ts +7 -3
  49. package/src/faust2svgFiles.js +9 -7
  50. package/src/faust2wasmFiles.d.ts +10 -5
  51. package/src/faust2wasmFiles.js +34 -17
  52. package/src/faust2wavFiles.d.ts +12 -3
  53. package/src/faust2wavFiles.js +25 -12
  54. package/src/index-bundle-iife.ts +2 -2
  55. package/src/index-bundle.ts +1 -1
  56. package/src/index.ts +1 -1
  57. package/src/instantiateFaustModule.ts +43 -36
  58. package/src/instantiateFaustModuleFromFile.ts +30 -14
  59. package/src/types.ts +101 -25
  60. package/test/faustlive-wasm/faustwasm/index.d.ts +38 -16
  61. package/test/faustlive-wasm/faustwasm/index.js +1574 -404
  62. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  63. package/test/web/create-faust-node.html +53 -0
  64. package/test/web/create-faust-node.js +186 -0
  65. package/test/organ/create-node.js +0 -252
  66. package/test/organ/dsp-meta.json +0 -131
  67. package/test/organ/dsp-module.wasm +0 -0
  68. package/test/organ/faust-pwa.js +0 -344
  69. package/test/organ/faust-ui/index.css +0 -442
  70. package/test/organ/faust-ui/index.css.map +0 -1
  71. package/test/organ/faust-ui/index.d.ts +0 -1
  72. package/test/organ/faust-ui/index.js +0 -3756
  73. package/test/organ/faust-ui/index.js.map +0 -1
  74. package/test/organ/faustwasm/index.d.ts +0 -1705
  75. package/test/organ/faustwasm/index.js +0 -4773
  76. package/test/organ/faustwasm/index.js.map +0 -7
  77. package/test/organ/icon.png +0 -0
  78. package/test/organ/index.html +0 -76
  79. package/test/organ/index.js +0 -69
  80. package/test/organ/manifest.json +0 -17
  81. package/test/organ/service-worker.js +0 -165
package/dist/cjs/index.js CHANGED
@@ -47,7 +47,9 @@
47
47
  jsCode = `${jsCode}
48
48
  export default ${(_a = jsCode.match(jsCodeHead)) == null ? void 0 : _a[1]};
49
49
  `;
50
- const jsFileMod = URL.createObjectURL(new Blob([jsCode], { type: "text/javascript" }));
50
+ const jsFileMod = URL.createObjectURL(
51
+ new Blob([jsCode], { type: "text/javascript" })
52
+ );
51
53
  FaustModule = (await import(
52
54
  /* webpackIgnore: true */
53
55
  jsFileMod
@@ -101,21 +103,32 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
101
103
  FaustWasmInstantiator: FaustWasmInstantiator2,
102
104
  FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
103
105
  } = dependencies;
104
- const {
105
- processorName,
106
- dspName,
107
- dspMeta,
108
- effectMeta,
109
- poly
110
- } = faustData;
106
+ const { processorName, dspName, dspMeta, effectMeta, poly } = faustData;
111
107
  const analysePolyParameters = (item) => {
112
- const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
108
+ const polyKeywords = [
109
+ "/gate",
110
+ "/freq",
111
+ "/gain",
112
+ "/key",
113
+ "/vel",
114
+ "/velocity"
115
+ ];
113
116
  const isPolyReserved = "address" in item && !!polyKeywords.find((k) => item.address.endsWith(k));
114
117
  if (poly && isPolyReserved) return null;
115
118
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
116
- return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
119
+ return {
120
+ name: item.address,
121
+ defaultValue: item.init || 0,
122
+ minValue: item.min || 0,
123
+ maxValue: item.max || 0
124
+ };
117
125
  } else if (item.type === "button" || item.type === "checkbox") {
118
- return { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
126
+ return {
127
+ name: item.address,
128
+ defaultValue: item.init || 0,
129
+ minValue: 0,
130
+ maxValue: 1
131
+ };
119
132
  }
120
133
  return null;
121
134
  };
@@ -123,7 +136,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
123
136
  constructor(options) {
124
137
  super(options);
125
138
  this.paramValuesCache = {};
126
- this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
139
+ this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(
140
+ this.port
141
+ );
127
142
  const { parameterDescriptors } = this.constructor;
128
143
  parameterDescriptors.forEach((pd) => {
129
144
  this.paramValuesCache[pd.name] = pd.defaultValue || 0;
@@ -139,7 +154,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
139
154
  if (param) params.push(param);
140
155
  };
141
156
  FaustBaseWebAudioDsp2.parseUI(dspMeta.ui, callback);
142
- if (effectMeta) FaustBaseWebAudioDsp2.parseUI(effectMeta.ui, callback);
157
+ if (effectMeta)
158
+ FaustBaseWebAudioDsp2.parseUI(effectMeta.ui, callback);
143
159
  return params;
144
160
  }
145
161
  setupWamEventHandler() {
@@ -147,12 +163,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
147
163
  if (!this.wamInfo) return;
148
164
  const { moduleId, instanceId } = this.wamInfo;
149
165
  const { webAudioModules } = globalThis;
150
- const ModuleScope = webAudioModules.getModuleScope(moduleId);
166
+ const ModuleScope = webAudioModules.getModuleScope(
167
+ moduleId
168
+ );
151
169
  const paramMgrProcessor = (_a = ModuleScope == null ? void 0 : ModuleScope.paramMgrProcessors) == null ? void 0 : _a[instanceId];
152
170
  if (!paramMgrProcessor) return;
153
171
  if (paramMgrProcessor.handleEvent) return;
154
172
  paramMgrProcessor.handleEvent = (event) => {
155
- if (event.type === "wam-midi") this.midiMessage(event.data.bytes);
173
+ if (event.type === "wam-midi")
174
+ this.midiMessage(event.data.bytes);
156
175
  };
157
176
  }
158
177
  process(inputs, outputs, parameters) {
@@ -212,7 +231,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
212
231
  // Plot handler set on demand
213
232
  case "setPlotHandler": {
214
233
  if (msg.data) {
215
- this.fDSPCode.setPlotHandler((output, index, events) => this.port.postMessage({ type: "plot", value: output, index, events }));
234
+ this.fDSPCode.setPlotHandler(
235
+ (output, index, events) => this.port.postMessage({
236
+ type: "plot",
237
+ value: output,
238
+ index,
239
+ events
240
+ })
241
+ );
216
242
  } else {
217
243
  this.fDSPCode.setPlotHandler(null);
218
244
  }
@@ -274,10 +300,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
274
300
  const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
275
301
  const { factory, sampleSize } = options.processorOptions;
276
302
  const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
277
- this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
303
+ this.fDSPCode = new FaustMonoWebAudioDsp2(
304
+ instance,
305
+ sampleRate,
306
+ sampleSize,
307
+ 128,
308
+ factory.soundfiles
309
+ );
278
310
  this.port.addEventListener("message", this.handleMessageAux);
279
311
  this.port.start();
280
- this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
312
+ this.fDSPCode.setOutputParamHandler(
313
+ (path, value) => this.port.postMessage({ path, value, type: "param" })
314
+ );
281
315
  this.fDSPCode.start();
282
316
  }
283
317
  }
@@ -299,13 +333,35 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
299
333
  }
300
334
  };
301
335
  const { FaustPolyWebAudioDsp: FaustPolyWebAudioDsp3 } = dependencies;
302
- const { voiceFactory, mixerModule, voices, effectFactory, sampleSize } = options.processorOptions;
303
- const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
304
- const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
305
- this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
336
+ const {
337
+ voiceFactory,
338
+ mixerModule,
339
+ voices,
340
+ effectFactory,
341
+ sampleSize
342
+ } = options.processorOptions;
343
+ const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(
344
+ voiceFactory,
345
+ mixerModule,
346
+ voices,
347
+ effectFactory
348
+ );
349
+ const soundfiles = {
350
+ ...effectFactory == null ? void 0 : effectFactory.soundfiles,
351
+ ...voiceFactory.soundfiles
352
+ };
353
+ this.fDSPCode = new FaustPolyWebAudioDsp3(
354
+ instance,
355
+ sampleRate,
356
+ sampleSize,
357
+ 128,
358
+ soundfiles
359
+ );
306
360
  this.port.addEventListener("message", this.handleMessageAux);
307
361
  this.port.start();
308
- this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
362
+ this.fDSPCode.setOutputParamHandler(
363
+ (path, value) => this.port.postMessage({ path, value, type: "param" })
364
+ );
309
365
  this.fDSPCode.start();
310
366
  }
311
367
  midiMessage(data) {
@@ -313,7 +369,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
313
369
  const channel = data[0] & 15;
314
370
  const data1 = data[1];
315
371
  const data2 = data[2];
316
- if (cmd === 8 || cmd === 9 && data2 === 0) this.keyOff(channel, data1, data2);
372
+ if (cmd === 8 || cmd === 9 && data2 === 0)
373
+ this.keyOff(channel, data1, data2);
317
374
  else if (cmd === 9) this.keyOn(channel, data1, data2);
318
375
  else super.midiMessage(data);
319
376
  }
@@ -331,7 +388,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
331
388
  const Processor = poly ? FaustPolyAudioWorkletProcessor : FaustMonoAudioWorkletProcessor;
332
389
  if (register) {
333
390
  try {
334
- registerProcessor(processorName || dspName || (poly ? "mydsp_poly" : "mydsp"), Processor);
391
+ registerProcessor(
392
+ processorName || dspName || (poly ? "mydsp_poly" : "mydsp"),
393
+ Processor
394
+ );
335
395
  } catch (error) {
336
396
  console.warn(error);
337
397
  }
@@ -350,19 +410,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
350
410
  FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
351
411
  FFTUtils
352
412
  } = dependencies;
353
- const {
354
- processorName,
355
- dspName,
356
- dspMeta,
357
- fftOptions
358
- } = faustData;
359
- const {
360
- windowFunctions,
361
- getFFT,
362
- fftToSignal,
363
- signalToFFT,
364
- signalToNoFFT
365
- } = FFTUtils;
413
+ const { processorName, dspName, dspMeta, fftOptions } = faustData;
414
+ const { windowFunctions, getFFT, fftToSignal, signalToFFT, signalToNoFFT } = FFTUtils;
366
415
  const ceil = (x, to) => Math.abs(to) < 1 ? Math.ceil(x * (1 / to)) / (1 / to) : Math.ceil(x / to) * to;
367
416
  const mod = (x, y) => (x % y + y) % y;
368
417
  const apply = (array, windowFunction) => {
@@ -370,7 +419,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
370
419
  array[i] *= windowFunction(i, array.length);
371
420
  }
372
421
  };
373
- const fftParamKeywords = ["/fftSize", "/fftHopSize", "/fftOverlap", "/windowFunction", "/noIFFT"];
422
+ const fftParamKeywords = [
423
+ "/fftSize",
424
+ "/fftHopSize",
425
+ "/fftOverlap",
426
+ "/windowFunction",
427
+ "/noIFFT"
428
+ ];
374
429
  const setTypedArray = (to, from, offsetTo = 0, offsetFrom = 0) => {
375
430
  const toLength = to.length;
376
431
  const fromLength = from.length;
@@ -379,7 +434,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
379
434
  let $to = mod(offsetTo, toLength) || 0;
380
435
  let $from = mod(offsetFrom, fromLength) || 0;
381
436
  while (spilled < spillLength) {
382
- const $spillLength = Math.min(spillLength - spilled, toLength - $to, fromLength - $from);
437
+ const $spillLength = Math.min(
438
+ spillLength - spilled,
439
+ toLength - $to,
440
+ fromLength - $from
441
+ );
383
442
  const $fromEnd = $from + $spillLength;
384
443
  if ($from === 0 && $fromEnd === fromLength) to.set(from, $to);
385
444
  else to.set(from.subarray($from, $fromEnd), $to);
@@ -393,9 +452,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
393
452
  const isFFTReserved = "address" in item && !!fftParamKeywords.find((k) => item.address.endsWith(k));
394
453
  if (isFFTReserved) return null;
395
454
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
396
- return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
455
+ return {
456
+ name: item.address,
457
+ defaultValue: item.init || 0,
458
+ minValue: item.min || 0,
459
+ maxValue: item.max || 0
460
+ };
397
461
  } else if (item.type === "button" || item.type === "checkbox") {
398
- return { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
462
+ return {
463
+ name: item.address,
464
+ defaultValue: item.init || 0,
465
+ minValue: 0,
466
+ maxValue: 1
467
+ };
399
468
  }
400
469
  return null;
401
470
  };
@@ -482,7 +551,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
482
551
  };
483
552
  this.port.addEventListener("message", this.handleMessageAux);
484
553
  this.port.start();
485
- this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
554
+ this.communicator = new FaustAudioWorkletProcessorCommunicator2(
555
+ this.port
556
+ );
486
557
  const { parameterDescriptors } = this.constructor;
487
558
  parameterDescriptors.forEach((pd) => {
488
559
  this.paramValuesCache[pd.name] = pd.defaultValue || 0;
@@ -544,35 +615,55 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
544
615
  if (!this.wamInfo) return;
545
616
  const { moduleId, instanceId } = this.wamInfo;
546
617
  const { webAudioModules } = globalThis;
547
- const ModuleScope = webAudioModules.getModuleScope(moduleId);
618
+ const ModuleScope = webAudioModules.getModuleScope(
619
+ moduleId
620
+ );
548
621
  const paramMgrProcessor = (_a = ModuleScope == null ? void 0 : ModuleScope.paramMgrProcessors) == null ? void 0 : _a[instanceId];
549
622
  if (!paramMgrProcessor) return;
550
623
  if (paramMgrProcessor.handleEvent) return;
551
624
  paramMgrProcessor.handleEvent = (event) => {
552
- if (event.type === "wam-midi") this.midiMessage(event.data.bytes);
625
+ if (event.type === "wam-midi")
626
+ this.midiMessage(event.data.bytes);
553
627
  };
554
628
  }
555
629
  processFFT() {
556
630
  let samplesForFFT = mod(this.$inputWrite - this.$inputRead, this.fftBufferSize) || this.fftBufferSize;
557
631
  while (samplesForFFT >= this.fftSize) {
558
632
  let fftProcessorOutputs = [];
559
- this.fDSPCode.compute((inputs) => {
560
- for (let i = 0; i < Math.min(this.fftInput.length, Math.ceil(inputs.length / 3)); i++) {
561
- const ffted = this.rfft.forward((fftBuffer) => {
562
- setTypedArray(fftBuffer, this.fftInput[i], 0, this.$inputRead);
563
- for (let j = 0; j < fftBuffer.length; j++) {
564
- fftBuffer[j] *= this.window[j];
565
- }
566
- });
567
- fftToSignal(ffted, inputs[i * 3], inputs[i * 3 + 1], inputs[i * 3 + 2]);
568
- }
569
- for (let i = this.fftInput.length * 3; i < inputs.length; i++) {
570
- if (i % 3 === 2) inputs[i].forEach((v, j) => inputs[i][j] = j);
571
- else inputs[i].fill(0);
633
+ this.fDSPCode.compute(
634
+ (inputs) => {
635
+ for (let i = 0; i < Math.min(
636
+ this.fftInput.length,
637
+ Math.ceil(inputs.length / 3)
638
+ ); i++) {
639
+ const ffted = this.rfft.forward((fftBuffer) => {
640
+ setTypedArray(
641
+ fftBuffer,
642
+ this.fftInput[i],
643
+ 0,
644
+ this.$inputRead
645
+ );
646
+ for (let j = 0; j < fftBuffer.length; j++) {
647
+ fftBuffer[j] *= this.window[j];
648
+ }
649
+ });
650
+ fftToSignal(
651
+ ffted,
652
+ inputs[i * 3],
653
+ inputs[i * 3 + 1],
654
+ inputs[i * 3 + 2]
655
+ );
656
+ }
657
+ for (let i = this.fftInput.length * 3; i < inputs.length; i++) {
658
+ if (i % 3 === 2)
659
+ inputs[i].forEach((v, j) => inputs[i][j] = j);
660
+ else inputs[i].fill(0);
661
+ }
662
+ },
663
+ (outputs) => {
664
+ fftProcessorOutputs = outputs;
572
665
  }
573
- }, (outputs) => {
574
- fftProcessorOutputs = outputs;
575
- });
666
+ );
576
667
  this.$inputRead += this.fftHopSize;
577
668
  this.$inputRead %= this.fftBufferSize;
578
669
  samplesForFFT -= this.fftHopSize;
@@ -580,10 +671,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
580
671
  let iffted;
581
672
  if (this.noIFFT) {
582
673
  iffted = this.noIFFTBuffer;
583
- signalToNoFFT(fftProcessorOutputs[i * 2] || this.fftProcessorZeros, fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros, iffted);
674
+ signalToNoFFT(
675
+ fftProcessorOutputs[i * 2] || this.fftProcessorZeros,
676
+ fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros,
677
+ iffted
678
+ );
584
679
  } else {
585
680
  iffted = this.rfft.inverse((ifftBuffer) => {
586
- signalToFFT(fftProcessorOutputs[i * 2] || this.fftProcessorZeros, fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros, ifftBuffer);
681
+ signalToFFT(
682
+ fftProcessorOutputs[i * 2] || this.fftProcessorZeros,
683
+ fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros,
684
+ ifftBuffer
685
+ );
587
686
  });
588
687
  }
589
688
  for (let j = 0; j < iffted.length; j++) {
@@ -593,12 +692,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
593
692
  for (let j = 0; j < iffted.length - this.fftHopSize; j++) {
594
693
  $ = mod(this.$outputWrite + j, this.fftBufferSize);
595
694
  this.fftOutput[i][$] += iffted[j];
596
- if (i === 0) this.windowSumSquare[$] += this.noIFFT ? this.window[j] : this.window[j] ** 2;
695
+ if (i === 0)
696
+ this.windowSumSquare[$] += this.noIFFT ? this.window[j] : this.window[j] ** 2;
597
697
  }
598
698
  for (let j = iffted.length - this.fftHopSize; j < iffted.length; j++) {
599
699
  $ = mod(this.$outputWrite + j, this.fftBufferSize);
600
700
  this.fftOutput[i][$] = iffted[j];
601
- if (i === 0) this.windowSumSquare[$] = this.noIFFT ? this.window[j] : this.window[j] ** 2;
701
+ if (i === 0)
702
+ this.windowSumSquare[$] = this.noIFFT ? this.window[j] : this.window[j] ** 2;
602
703
  }
603
704
  }
604
705
  this.$outputWrite += this.fftHopSize;
@@ -614,10 +715,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
614
715
  const outputChannels = (output == null ? void 0 : output.length) || 0;
615
716
  const bufferSize = (input == null ? void 0 : input.length) ? Math.max(...input.map((c) => c.length)) || 128 : 128;
616
717
  this.noIFFT = !!parameters.noIFFT[0];
617
- this.resetFFT(~~parameters.fftSize[0], ~~parameters.fftOverlap[0], ~~parameters.windowFunction[0], inputChannels, outputChannels, bufferSize);
718
+ this.resetFFT(
719
+ ~~parameters.fftSize[0],
720
+ ~~parameters.fftOverlap[0],
721
+ ~~parameters.windowFunction[0],
722
+ inputChannels,
723
+ outputChannels,
724
+ bufferSize
725
+ );
618
726
  if (!this.fDSPCode) return true;
619
727
  for (const path in parameters) {
620
- if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k))) continue;
728
+ if (fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
729
+ continue;
621
730
  const [paramValue] = parameters[path];
622
731
  if (paramValue !== this.paramValuesCache[path]) {
623
732
  this.setParamValue(path, paramValue);
@@ -643,7 +752,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
643
752
  for (let i = 0; i < input.length; i++) {
644
753
  const inputWindow = this.fftInput[i];
645
754
  const channel = input[i].length ? input[i] : new Float32Array(bufferSize);
646
- $inputWrite = setTypedArray(inputWindow, channel, this.$inputWrite);
755
+ $inputWrite = setTypedArray(
756
+ inputWindow,
757
+ channel,
758
+ this.$inputWrite
759
+ );
647
760
  }
648
761
  this.$inputWrite = $inputWrite;
649
762
  } else {
@@ -652,7 +765,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
652
765
  }
653
766
  this.processFFT();
654
767
  for (let i = 0; i < output.length; i++) {
655
- setTypedArray(output[i], this.fftOutput[i], 0, this.$outputRead);
768
+ setTypedArray(
769
+ output[i],
770
+ this.fftOutput[i],
771
+ 0,
772
+ this.$outputRead
773
+ );
656
774
  let div = 0;
657
775
  for (let j = 0; j < bufferSize; j++) {
658
776
  div = this.windowSumSquare[mod(this.$outputRead + j, this.fftBufferSize)];
@@ -662,7 +780,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
662
780
  this.$outputRead += bufferSize;
663
781
  this.$outputRead %= this.fftBufferSize;
664
782
  if (this.fPlotHandler) {
665
- this.port.postMessage({ type: "plot", value: output, index: this.fBufferNum++, events: this.fCachedEvents });
783
+ this.port.postMessage({
784
+ type: "plot",
785
+ value: output,
786
+ index: this.fBufferNum++,
787
+ events: this.fCachedEvents
788
+ });
666
789
  this.fCachedEvents = [];
667
790
  }
668
791
  return true;
@@ -710,8 +833,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
710
833
  this.$inputRead = 0;
711
834
  this.$outputWrite = 0;
712
835
  this.$outputRead = -latency;
713
- this.fftBufferSize = Math.max(fftSize * 2 - this.fftHopSize, bufferSize * 2);
714
- if (!fftSizeChanged && this.fftHopSizeParam) (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(this.fftHopSizeParam, this.fftHopSize);
836
+ this.fftBufferSize = Math.max(
837
+ fftSize * 2 - this.fftHopSize,
838
+ bufferSize * 2
839
+ );
840
+ if (!fftSizeChanged && this.fftHopSizeParam)
841
+ (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(
842
+ this.fftHopSizeParam,
843
+ this.fftHopSize
844
+ );
715
845
  }
716
846
  if (fftSizeChanged) {
717
847
  (_b = this.rfft) == null ? void 0 : _b.dispose();
@@ -747,7 +877,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
747
877
  }
748
878
  if (this.fftOutput.length < outputChannels) {
749
879
  for (let i = this.fftOutput.length; i < outputChannels; i++) {
750
- this.fftOutput[i] = new Float32Array(this.fftBufferSize);
880
+ this.fftOutput[i] = new Float32Array(
881
+ this.fftBufferSize
882
+ );
751
883
  }
752
884
  }
753
885
  }
@@ -756,20 +888,38 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
756
888
  var _a, _b;
757
889
  (_a = this.fDSPCode) == null ? void 0 : _a.stop();
758
890
  (_b = this.fDSPCode) == null ? void 0 : _b.destroy();
759
- this.fDSPCode = new FaustMonoWebAudioDsp2(this.dspInstance, sampleRate, this.sampleSize, this.fftProcessorBufferSize, this.soundfiles);
760
- this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
891
+ this.fDSPCode = new FaustMonoWebAudioDsp2(
892
+ this.dspInstance,
893
+ sampleRate,
894
+ this.sampleSize,
895
+ this.fftProcessorBufferSize,
896
+ this.soundfiles
897
+ );
898
+ this.fDSPCode.setOutputParamHandler(
899
+ (path, value) => this.port.postMessage({ path, value, type: "param" })
900
+ );
761
901
  this.fDSPCode.setPlotHandler(this.fPlotHandler);
762
902
  const params = this.fDSPCode.getParams();
763
903
  this.fDSPCode.start();
764
904
  for (const path in this.paramValuesCache) {
765
- if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k))) continue;
905
+ if (fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
906
+ continue;
766
907
  this.fDSPCode.setParamValue(path, this.paramValuesCache[path]);
767
908
  }
768
909
  const fftSizeParam = params.find((s) => s.endsWith("/fftSize"));
769
- if (fftSizeParam) this.fDSPCode.setParamValue(fftSizeParam, this.fftSize);
770
- this.fftHopSizeParam = params.find((s) => s.endsWith("/fftHopSize"));
771
- if (this.fftHopSizeParam) this.fDSPCode.setParamValue(this.fftHopSizeParam, this.fftHopSize);
772
- this.fftProcessorZeros = new Float32Array(this.fftProcessorBufferSize);
910
+ if (fftSizeParam)
911
+ this.fDSPCode.setParamValue(fftSizeParam, this.fftSize);
912
+ this.fftHopSizeParam = params.find(
913
+ (s) => s.endsWith("/fftHopSize")
914
+ );
915
+ if (this.fftHopSizeParam)
916
+ this.fDSPCode.setParamValue(
917
+ this.fftHopSizeParam,
918
+ this.fftHopSize
919
+ );
920
+ this.fftProcessorZeros = new Float32Array(
921
+ this.fftProcessorBufferSize
922
+ );
773
923
  }
774
924
  destroy() {
775
925
  var _a, _b, _c;
@@ -782,7 +932,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
782
932
  const Processor = FaustFFTAudioWorkletProcessor;
783
933
  if (register) {
784
934
  try {
785
- registerProcessor(processorName || dspName || "myfftdsp", Processor);
935
+ registerProcessor(
936
+ processorName || dspName || "myfftdsp",
937
+ Processor
938
+ );
786
939
  } catch (error) {
787
940
  console.warn(error);
788
941
  }
@@ -1191,7 +1344,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1191
1344
  const table = {};
1192
1345
  this.gFactories.forEach((factory, shaKey) => {
1193
1346
  const { code, json, poly } = factory;
1194
- table[shaKey] = { code: btoa(ab2str(code)), json: JSON.parse(json), poly };
1347
+ table[shaKey] = {
1348
+ code: btoa(ab2str(code)),
1349
+ json: JSON.parse(json),
1350
+ poly
1351
+ };
1195
1352
  });
1196
1353
  return table;
1197
1354
  }
@@ -1210,7 +1367,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1210
1367
  const factory = table[shaKey];
1211
1368
  const { code, json, poly } = factory;
1212
1369
  const ab = str2ab(atob(code));
1213
- awaited.push(WebAssembly.compile(ab).then((module) => this.gFactories.set(shaKey, { shaKey, cfactory: 0, code: ab, module, json: JSON.stringify(json), poly, soundfiles: {} })));
1370
+ awaited.push(
1371
+ WebAssembly.compile(ab).then(
1372
+ (module) => this.gFactories.set(shaKey, {
1373
+ shaKey,
1374
+ cfactory: 0,
1375
+ code: ab,
1376
+ module,
1377
+ json: JSON.stringify(json),
1378
+ poly,
1379
+ soundfiles: {}
1380
+ })
1381
+ )
1382
+ );
1214
1383
  }
1215
1384
  return Promise.all(awaited);
1216
1385
  }
@@ -1237,16 +1406,31 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1237
1406
  if (_FaustCompiler.gFactories.size > 10) {
1238
1407
  _FaustCompiler.gFactories.clear();
1239
1408
  }
1240
- let shaKey = await sha256(name + code + args + (poly ? "poly" : "mono"));
1409
+ const shaKey = await sha256(
1410
+ name + code + args + (poly ? "poly" : "mono")
1411
+ );
1241
1412
  if (_FaustCompiler.gFactories.has(shaKey)) {
1242
1413
  return _FaustCompiler.gFactories.get(shaKey) || null;
1243
1414
  } else {
1244
1415
  try {
1245
- const faustDspWasm = this.fLibFaust.createDSPFactory(name, code, args, !poly);
1416
+ const faustDspWasm = this.fLibFaust.createDSPFactory(
1417
+ name,
1418
+ code,
1419
+ args,
1420
+ !poly
1421
+ );
1246
1422
  const ui8Code = this.intVec2intArray(faustDspWasm.data);
1247
1423
  faustDspWasm.data.delete();
1248
1424
  const module = await WebAssembly.compile(ui8Code);
1249
- const factory = { shaKey, cfactory: faustDspWasm.cfactory, code: ui8Code, module, json: faustDspWasm.json, poly, soundfiles: {} };
1425
+ const factory = {
1426
+ shaKey,
1427
+ cfactory: faustDspWasm.cfactory,
1428
+ code: ui8Code,
1429
+ module,
1430
+ json: faustDspWasm.json,
1431
+ poly,
1432
+ soundfiles: {}
1433
+ };
1250
1434
  this.deleteDSPFactory(factory);
1251
1435
  _FaustCompiler.gFactories.set(shaKey, factory);
1252
1436
  return factory;
@@ -1300,18 +1484,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1300
1484
  async getAsyncInternalMixerModule(isDouble = false) {
1301
1485
  const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
1302
1486
  const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
1303
- if (this[moduleKey]) return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1487
+ if (this[moduleKey])
1488
+ return {
1489
+ mixerBuffer: this[bufferKey],
1490
+ mixerModule: this[moduleKey]
1491
+ };
1304
1492
  const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
1305
1493
  const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
1306
1494
  this[bufferKey] = mixerBuffer;
1307
- const mixerModule = await WebAssembly.compile(new Uint8Array(mixerBuffer));
1495
+ const mixerModule = await WebAssembly.compile(
1496
+ new Uint8Array(mixerBuffer)
1497
+ );
1308
1498
  this[moduleKey] = mixerModule;
1309
1499
  return { mixerBuffer, mixerModule };
1310
1500
  }
1311
1501
  getSyncInternalMixerModule(isDouble = false) {
1312
1502
  const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
1313
1503
  const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
1314
- if (this[moduleKey]) return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1504
+ if (this[moduleKey])
1505
+ return {
1506
+ mixerBuffer: this[bufferKey],
1507
+ mixerModule: this[moduleKey]
1508
+ };
1315
1509
  const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
1316
1510
  const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
1317
1511
  this[bufferKey] = mixerBuffer;
@@ -1448,7 +1642,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1448
1642
  };
1449
1643
  const effectSize = effectMeta ? effectMeta.size : 0;
1450
1644
  let memorySize = pow2limit(
1451
- effectSize + dspMeta.size * voices + (dspMeta.inputs + dspMeta.outputs * 2) * (ptrSize + bufferSize * sampleSize)
1645
+ effectSize + dspMeta.size * voices + (dspMeta.inputs + dspMeta.outputs * 2) * // + 2 for effect
1646
+ (ptrSize + bufferSize * sampleSize)
1452
1647
  ) / 65536;
1453
1648
  memorySize = Math.max(2, memorySize);
1454
1649
  return new WebAssembly.Memory({ initial: memorySize });
@@ -1473,14 +1668,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1473
1668
  const voiceMeta = JSON.parse(voiceFactory.json);
1474
1669
  const effectMeta = effectFactory && effectFactory.json ? JSON.parse(effectFactory.json) : null;
1475
1670
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
1476
- return this.createWasmMemoryPoly(voices, sampleSize, voiceMeta, effectMeta, 8192);
1671
+ return this.createWasmMemoryPoly(
1672
+ voices,
1673
+ sampleSize,
1674
+ voiceMeta,
1675
+ effectMeta,
1676
+ 8192
1677
+ );
1477
1678
  }
1478
1679
  static createMixerAux(mixerModule, memory) {
1479
1680
  const mixerImport = {
1480
1681
  imports: { print: console.log },
1481
1682
  memory: { memory }
1482
1683
  };
1483
- const mixerInstance = new WebAssembly.Instance(mixerModule, mixerImport);
1684
+ const mixerInstance = new WebAssembly.Instance(
1685
+ mixerModule,
1686
+ mixerImport
1687
+ );
1484
1688
  const mixerFunctions = mixerInstance.exports;
1485
1689
  return mixerFunctions;
1486
1690
  }
@@ -1488,7 +1692,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1488
1692
  static async loadDSPFactory(wasmPath, jsonPath) {
1489
1693
  const wasmFile = await fetch(wasmPath);
1490
1694
  if (!wasmFile.ok) {
1491
- throw new Error(`=> exception raised while running loadDSPFactory, file not found: ${wasmPath}`);
1695
+ throw new Error(
1696
+ `=> exception raised while running loadDSPFactory, file not found: ${wasmPath}`
1697
+ );
1492
1698
  }
1493
1699
  try {
1494
1700
  const wasmBuffer = await wasmFile.arrayBuffer();
@@ -1498,7 +1704,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1498
1704
  const meta = JSON.parse(json);
1499
1705
  const cOptions = meta.compile_options;
1500
1706
  const poly = cOptions.indexOf("wasm-e") !== -1;
1501
- return { cfactory: 0, code: new Uint8Array(wasmBuffer), module, json, poly };
1707
+ return {
1708
+ cfactory: 0,
1709
+ code: new Uint8Array(wasmBuffer),
1710
+ module,
1711
+ json,
1712
+ poly
1713
+ };
1502
1714
  } catch (e) {
1503
1715
  throw e;
1504
1716
  }
@@ -1507,7 +1719,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1507
1719
  try {
1508
1720
  let mixerBuffer = null;
1509
1721
  if (fs) {
1510
- mixerBuffer = new Uint8Array(fs.readFile(mixerPath, { encoding: "binary" }));
1722
+ mixerBuffer = new Uint8Array(
1723
+ fs.readFile(mixerPath, { encoding: "binary" })
1724
+ );
1511
1725
  } else {
1512
1726
  const mixerFile = await fetch(mixerPath);
1513
1727
  mixerBuffer = await mixerFile.arrayBuffer();
@@ -1522,10 +1736,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1522
1736
  const isDetected = pattern.test(factory.json);
1523
1737
  if (isDetected) {
1524
1738
  const memory = this.createMemoryMono(factory);
1525
- const instance = await WebAssembly.instantiate(factory.module, this.createWasmImport(memory));
1526
- return this.createMonoDSPInstanceAux(instance, factory.json, memory);
1739
+ const instance = await WebAssembly.instantiate(
1740
+ factory.module,
1741
+ this.createWasmImport(memory)
1742
+ );
1743
+ return this.createMonoDSPInstanceAux(
1744
+ instance,
1745
+ factory.json,
1746
+ memory
1747
+ );
1527
1748
  } else {
1528
- const instance = await WebAssembly.instantiate(factory.module, this.createWasmImport());
1749
+ const instance = await WebAssembly.instantiate(
1750
+ factory.module,
1751
+ this.createWasmImport()
1752
+ );
1529
1753
  return this.createMonoDSPInstanceAux(instance, factory.json);
1530
1754
  }
1531
1755
  }
@@ -1534,21 +1758,41 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1534
1758
  const isDetected = pattern.test(factory.json);
1535
1759
  if (isDetected) {
1536
1760
  const memory = this.createMemoryMono(factory);
1537
- const instance = new WebAssembly.Instance(factory.module, this.createWasmImport(memory));
1538
- return this.createMonoDSPInstanceAux(instance, factory.json, memory);
1761
+ const instance = new WebAssembly.Instance(
1762
+ factory.module,
1763
+ this.createWasmImport(memory)
1764
+ );
1765
+ return this.createMonoDSPInstanceAux(
1766
+ instance,
1767
+ factory.json,
1768
+ memory
1769
+ );
1539
1770
  } else {
1540
- const instance = new WebAssembly.Instance(factory.module, this.createWasmImport());
1771
+ const instance = new WebAssembly.Instance(
1772
+ factory.module,
1773
+ this.createWasmImport()
1774
+ );
1541
1775
  return this.createMonoDSPInstanceAux(instance, factory.json);
1542
1776
  }
1543
1777
  }
1544
1778
  static async createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory) {
1545
- const memory = this.createMemoryPoly(voices, voiceFactory, effectFactory);
1546
- const voiceInstance = await WebAssembly.instantiate(voiceFactory.module, this.createWasmImport(memory));
1779
+ const memory = this.createMemoryPoly(
1780
+ voices,
1781
+ voiceFactory,
1782
+ effectFactory
1783
+ );
1784
+ const voiceInstance = await WebAssembly.instantiate(
1785
+ voiceFactory.module,
1786
+ this.createWasmImport(memory)
1787
+ );
1547
1788
  const voiceFunctions = voiceInstance.exports;
1548
1789
  const voiceAPI = new FaustDspInstance(voiceFunctions);
1549
1790
  const mixerAPI = this.createMixerAux(mixerModule, memory);
1550
1791
  if (effectFactory) {
1551
- const effectInstance = await WebAssembly.instantiate(effectFactory.module, this.createWasmImport(memory));
1792
+ const effectInstance = await WebAssembly.instantiate(
1793
+ effectFactory.module,
1794
+ this.createWasmImport(memory)
1795
+ );
1552
1796
  const effectFunctions = effectInstance.exports;
1553
1797
  const effectAPI = new FaustDspInstance(effectFunctions);
1554
1798
  return {
@@ -1571,13 +1815,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1571
1815
  }
1572
1816
  }
1573
1817
  static createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory) {
1574
- const memory = this.createMemoryPoly(voices, voiceFactory, effectFactory);
1575
- const voiceInstance = new WebAssembly.Instance(voiceFactory.module, this.createWasmImport(memory));
1818
+ const memory = this.createMemoryPoly(
1819
+ voices,
1820
+ voiceFactory,
1821
+ effectFactory
1822
+ );
1823
+ const voiceInstance = new WebAssembly.Instance(
1824
+ voiceFactory.module,
1825
+ this.createWasmImport(memory)
1826
+ );
1576
1827
  const voiceFunctions = voiceInstance.exports;
1577
1828
  const voiceAPI = new FaustDspInstance(voiceFunctions);
1578
1829
  const mixerAPI = this.createMixerAux(mixerModule, memory);
1579
1830
  if (effectFactory) {
1580
- const effectInstance = new WebAssembly.Instance(effectFactory.module, this.createWasmImport(memory));
1831
+ const effectInstance = new WebAssembly.Instance(
1832
+ effectFactory.module,
1833
+ this.createWasmImport(memory)
1834
+ );
1581
1835
  const effectFunctions = effectInstance.exports;
1582
1836
  const effectAPI = new FaustDspInstance(effectFunctions);
1583
1837
  return {
@@ -1606,7 +1860,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1606
1860
  var FaustSensors = class _FaustSensors {
1607
1861
  /**
1608
1862
  * Function to convert a number to an axis type
1609
- *
1863
+ *
1610
1864
  * @param value number
1611
1865
  * @returns axis type
1612
1866
  */
@@ -1625,7 +1879,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1625
1879
  }
1626
1880
  /**
1627
1881
  * Function to convert a number to a curve type
1628
- *
1882
+ *
1629
1883
  * @param value number
1630
1884
  * @returns curve type
1631
1885
  */
@@ -1677,7 +1931,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1677
1931
  }
1678
1932
  }
1679
1933
  returnMappedValue(v) {
1680
- var x = this.fRange.clip(v);
1934
+ const x = this.fRange.clip(v);
1681
1935
  return this.fOffset + x * this.fCoef;
1682
1936
  }
1683
1937
  getLowHigh(amin, amax) {
@@ -1694,17 +1948,37 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1694
1948
  if (!this._Interpolator3pt) {
1695
1949
  this._Interpolator3pt = class {
1696
1950
  constructor(lo, mid, hi, v1, vMid, v2) {
1697
- this.fSegment1 = new _FaustSensors.Interpolator(lo, mid, v1, vMid);
1698
- this.fSegment2 = new _FaustSensors.Interpolator(mid, hi, vMid, v2);
1951
+ this.fSegment1 = new _FaustSensors.Interpolator(
1952
+ lo,
1953
+ mid,
1954
+ v1,
1955
+ vMid
1956
+ );
1957
+ this.fSegment2 = new _FaustSensors.Interpolator(
1958
+ mid,
1959
+ hi,
1960
+ vMid,
1961
+ v2
1962
+ );
1699
1963
  this.fMid = mid;
1700
1964
  }
1701
1965
  returnMappedValue(x) {
1702
1966
  return x < this.fMid ? this.fSegment1.returnMappedValue(x) : this.fSegment2.returnMappedValue(x);
1703
1967
  }
1704
1968
  getMappingValues(amin, amid, amax) {
1705
- var lowHighSegment1 = this.fSegment1.getLowHigh(amin, amid);
1706
- var lowHighSegment2 = this.fSegment2.getLowHigh(amid, amax);
1707
- return { amin: lowHighSegment1.amin, amid: lowHighSegment2.amin, amax: lowHighSegment2.amax };
1969
+ const lowHighSegment1 = this.fSegment1.getLowHigh(
1970
+ amin,
1971
+ amid
1972
+ );
1973
+ const lowHighSegment2 = this.fSegment2.getLowHigh(
1974
+ amid,
1975
+ amax
1976
+ );
1977
+ return {
1978
+ amin: lowHighSegment1.amin,
1979
+ amid: lowHighSegment2.amin,
1980
+ amax: lowHighSegment2.amax
1981
+ };
1708
1982
  }
1709
1983
  };
1710
1984
  }
@@ -1718,8 +1992,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1718
1992
  this._UpConverter = class {
1719
1993
  constructor(amin, amid, amax, fmin, fmid, fmax) {
1720
1994
  this.fActive = true;
1721
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmin, fmid, fmax);
1722
- this.fF2A = new _FaustSensors.Interpolator3pt(fmin, fmid, fmax, amin, amid, amax);
1995
+ this.fA2F = new _FaustSensors.Interpolator3pt(
1996
+ amin,
1997
+ amid,
1998
+ amax,
1999
+ fmin,
2000
+ fmid,
2001
+ fmax
2002
+ );
2003
+ this.fF2A = new _FaustSensors.Interpolator3pt(
2004
+ fmin,
2005
+ fmid,
2006
+ fmax,
2007
+ amin,
2008
+ amid,
2009
+ amax
2010
+ );
1723
2011
  }
1724
2012
  uiToFaust(x) {
1725
2013
  return this.fA2F.returnMappedValue(x);
@@ -1728,8 +2016,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1728
2016
  return this.fF2A.returnMappedValue(x);
1729
2017
  }
1730
2018
  setMappingValues(amin, amid, amax, min, init, max) {
1731
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, min, init, max);
1732
- this.fF2A = new _FaustSensors.Interpolator3pt(min, init, max, amin, amid, amax);
2019
+ this.fA2F = new _FaustSensors.Interpolator3pt(
2020
+ amin,
2021
+ amid,
2022
+ amax,
2023
+ min,
2024
+ init,
2025
+ max
2026
+ );
2027
+ this.fF2A = new _FaustSensors.Interpolator3pt(
2028
+ min,
2029
+ init,
2030
+ max,
2031
+ amin,
2032
+ amid,
2033
+ amax
2034
+ );
1733
2035
  }
1734
2036
  getMappingValues(amin, amid, amax) {
1735
2037
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -1752,8 +2054,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1752
2054
  this._DownConverter = class {
1753
2055
  constructor(amin, amid, amax, fmin, fmid, fmax) {
1754
2056
  this.fActive = true;
1755
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmax, fmid, fmin);
1756
- this.fF2A = new _FaustSensors.Interpolator3pt(fmin, fmid, fmax, amax, amid, amin);
2057
+ this.fA2F = new _FaustSensors.Interpolator3pt(
2058
+ amin,
2059
+ amid,
2060
+ amax,
2061
+ fmax,
2062
+ fmid,
2063
+ fmin
2064
+ );
2065
+ this.fF2A = new _FaustSensors.Interpolator3pt(
2066
+ fmin,
2067
+ fmid,
2068
+ fmax,
2069
+ amax,
2070
+ amid,
2071
+ amin
2072
+ );
1757
2073
  }
1758
2074
  uiToFaust(x) {
1759
2075
  return this.fA2F.returnMappedValue(x);
@@ -1762,8 +2078,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1762
2078
  return this.fF2A.returnMappedValue(x);
1763
2079
  }
1764
2080
  setMappingValues(amin, amid, amax, min, init, max) {
1765
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, max, init, min);
1766
- this.fF2A = new _FaustSensors.Interpolator3pt(min, init, max, amax, amid, amin);
2081
+ this.fA2F = new _FaustSensors.Interpolator3pt(
2082
+ amin,
2083
+ amid,
2084
+ amax,
2085
+ max,
2086
+ init,
2087
+ min
2088
+ );
2089
+ this.fF2A = new _FaustSensors.Interpolator3pt(
2090
+ min,
2091
+ init,
2092
+ max,
2093
+ amax,
2094
+ amid,
2095
+ amin
2096
+ );
1767
2097
  }
1768
2098
  getMappingValues(amin, amid, amax) {
1769
2099
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -1786,8 +2116,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1786
2116
  this._UpDownConverter = class {
1787
2117
  constructor(amin, amid, amax, fmin, fmid, fmax) {
1788
2118
  this.fActive = true;
1789
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmin, fmax, fmin);
1790
- this.fF2A = new _FaustSensors.Interpolator(fmin, fmax, amin, amax);
2119
+ this.fA2F = new _FaustSensors.Interpolator3pt(
2120
+ amin,
2121
+ amid,
2122
+ amax,
2123
+ fmin,
2124
+ fmax,
2125
+ fmin
2126
+ );
2127
+ this.fF2A = new _FaustSensors.Interpolator(
2128
+ fmin,
2129
+ fmax,
2130
+ amin,
2131
+ amax
2132
+ );
1791
2133
  }
1792
2134
  uiToFaust(x) {
1793
2135
  return this.fA2F.returnMappedValue(x);
@@ -1796,8 +2138,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1796
2138
  return this.fF2A.returnMappedValue(x);
1797
2139
  }
1798
2140
  setMappingValues(amin, amid, amax, min, init, max) {
1799
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, min, max, min);
1800
- this.fF2A = new _FaustSensors.Interpolator(min, max, amin, amax);
2141
+ this.fA2F = new _FaustSensors.Interpolator3pt(
2142
+ amin,
2143
+ amid,
2144
+ amax,
2145
+ min,
2146
+ max,
2147
+ min
2148
+ );
2149
+ this.fF2A = new _FaustSensors.Interpolator(
2150
+ min,
2151
+ max,
2152
+ amin,
2153
+ amax
2154
+ );
1801
2155
  }
1802
2156
  getMappingValues(amin, amid, amax) {
1803
2157
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -1817,8 +2171,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1817
2171
  this._DownUpConverter = class {
1818
2172
  constructor(amin, amid, amax, fmin, fmid, fmax) {
1819
2173
  this.fActive = true;
1820
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmax, fmin, fmax);
1821
- this.fF2A = new _FaustSensors.Interpolator(fmin, fmax, amin, amax);
2174
+ this.fA2F = new _FaustSensors.Interpolator3pt(
2175
+ amin,
2176
+ amid,
2177
+ amax,
2178
+ fmax,
2179
+ fmin,
2180
+ fmax
2181
+ );
2182
+ this.fF2A = new _FaustSensors.Interpolator(
2183
+ fmin,
2184
+ fmax,
2185
+ amin,
2186
+ amax
2187
+ );
1822
2188
  }
1823
2189
  uiToFaust(x) {
1824
2190
  return this.fA2F.returnMappedValue(x);
@@ -1827,8 +2193,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1827
2193
  return this.fF2A.returnMappedValue(x);
1828
2194
  }
1829
2195
  setMappingValues(amin, amid, amax, min, init, max) {
1830
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, max, min, max);
1831
- this.fF2A = new _FaustSensors.Interpolator(min, max, amin, amax);
2196
+ this.fA2F = new _FaustSensors.Interpolator3pt(
2197
+ amin,
2198
+ amid,
2199
+ amax,
2200
+ max,
2201
+ min,
2202
+ max
2203
+ );
2204
+ this.fF2A = new _FaustSensors.Interpolator(
2205
+ min,
2206
+ max,
2207
+ amin,
2208
+ amax
2209
+ );
1832
2210
  }
1833
2211
  getMappingValues(amin, amid, amax) {
1834
2212
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -1851,15 +2229,50 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1851
2229
  static buildHandler(curve, amin, amid, amax, min, init, max) {
1852
2230
  switch (curve) {
1853
2231
  case 0 /* Up */:
1854
- return new _FaustSensors.UpConverter(amin, amid, amax, min, init, max);
2232
+ return new _FaustSensors.UpConverter(
2233
+ amin,
2234
+ amid,
2235
+ amax,
2236
+ min,
2237
+ init,
2238
+ max
2239
+ );
1855
2240
  case 1 /* Down */:
1856
- return new _FaustSensors.DownConverter(amin, amid, amax, min, init, max);
2241
+ return new _FaustSensors.DownConverter(
2242
+ amin,
2243
+ amid,
2244
+ amax,
2245
+ min,
2246
+ init,
2247
+ max
2248
+ );
1857
2249
  case 2 /* UpDown */:
1858
- return new _FaustSensors.UpDownConverter(amin, amid, amax, min, init, max);
2250
+ return new _FaustSensors.UpDownConverter(
2251
+ amin,
2252
+ amid,
2253
+ amax,
2254
+ min,
2255
+ init,
2256
+ max
2257
+ );
1859
2258
  case 3 /* DownUp */:
1860
- return new _FaustSensors.DownUpConverter(amin, amid, amax, min, init, max);
2259
+ return new _FaustSensors.DownUpConverter(
2260
+ amin,
2261
+ amid,
2262
+ amax,
2263
+ min,
2264
+ init,
2265
+ max
2266
+ );
1861
2267
  default:
1862
- return new _FaustSensors.UpConverter(amin, amid, amax, min, init, max);
2268
+ return new _FaustSensors.UpConverter(
2269
+ amin,
2270
+ amid,
2271
+ amax,
2272
+ min,
2273
+ init,
2274
+ max
2275
+ );
1863
2276
  }
1864
2277
  }
1865
2278
  };
@@ -1874,7 +2287,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1874
2287
  * Allocates a block of memory of the specified size, returning the pointer to the
1875
2288
  * beginning of the block. The block is allocated at the current offset and the
1876
2289
  * offset is incremented by the size of the block.
1877
- *
2290
+ *
1878
2291
  * @param sizeInBytes The size of the block to allocate in bytes.
1879
2292
  * @returns The offset (pointer) to the beginning of the allocated block.
1880
2293
  */
@@ -1883,7 +2296,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1883
2296
  const newOffset = currentOffset + sizeInBytes;
1884
2297
  const totalMemoryBytes = this.memory.buffer.byteLength;
1885
2298
  if (newOffset > totalMemoryBytes) {
1886
- const neededPages = Math.ceil((newOffset - totalMemoryBytes) / 65536);
2299
+ const neededPages = Math.ceil(
2300
+ (newOffset - totalMemoryBytes) / 65536
2301
+ );
1887
2302
  console.log(`GROW: ${neededPages} pages`);
1888
2303
  this.memory.grow(neededPages);
1889
2304
  }
@@ -1892,7 +2307,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1892
2307
  }
1893
2308
  /**
1894
2309
  * Returns the underlying buffer object.
1895
- *
2310
+ *
1896
2311
  * @returns The buffer object.
1897
2312
  */
1898
2313
  getBuffer() {
@@ -1900,7 +2315,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1900
2315
  }
1901
2316
  /**
1902
2317
  * Returns the Int32 view of the underlying buffer object.
1903
- *
2318
+ *
1904
2319
  * @returns The view of the memory buffer as Int32Array.
1905
2320
  */
1906
2321
  getInt32Array() {
@@ -1908,7 +2323,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1908
2323
  }
1909
2324
  /**
1910
2325
  * Returns the Int64 view of the underlying buffer object.
1911
- *
2326
+ *
1912
2327
  * @returns The view of the memory buffer as BigInt64Array.
1913
2328
  */
1914
2329
  getInt64Array() {
@@ -1916,7 +2331,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1916
2331
  }
1917
2332
  /**
1918
2333
  * Returns the Float32 view of the underlying buffer object.
1919
- *
2334
+ *
1920
2335
  * @returns The view of the memory buffer as Float32Array.
1921
2336
  */
1922
2337
  getFloat32Array() {
@@ -1924,7 +2339,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1924
2339
  }
1925
2340
  /**
1926
2341
  * Returns the Float64 view of the underlying buffer object..
1927
- *
2342
+ *
1928
2343
  * @returns The view of the memory buffer as Float64Array.
1929
2344
  */
1930
2345
  getFloat64Array() {
@@ -1953,11 +2368,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1953
2368
  this.fIntSize = this.fSampleSize;
1954
2369
  this.fPtrSize = 4;
1955
2370
  this.fAllocator = allocator;
1956
- console.log(`Soundfile constructor: curChan: ${curChan}, length: ${length}, maxChan: ${maxChan}, totalParts: ${totalParts}`);
2371
+ console.log(
2372
+ `Soundfile constructor: curChan: ${curChan}, length: ${length}, maxChan: ${maxChan}, totalParts: ${totalParts}`
2373
+ );
1957
2374
  this.fPtr = allocator.alloc(4 * this.fPtrSize);
1958
- this.fLength = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
1959
- this.fSR = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
1960
- this.fOffset = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
2375
+ this.fLength = allocator.alloc(
2376
+ _Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize
2377
+ );
2378
+ this.fSR = allocator.alloc(
2379
+ _Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize
2380
+ );
2381
+ this.fOffset = allocator.alloc(
2382
+ _Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize
2383
+ );
1961
2384
  this.fBuffers = this.allocBuffers(curChan, length, maxChan);
1962
2385
  const HEAP32 = this.fAllocator.getInt32Array();
1963
2386
  HEAP32[this.fPtr >> 2] = this.fBuffers;
@@ -1973,7 +2396,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1973
2396
  const buffers = this.fAllocator.alloc(maxChan * this.fPtrSize);
1974
2397
  console.log(`allocBuffers buffers: ${buffers}`);
1975
2398
  for (let chan = 0; chan < curChan; chan++) {
1976
- const buffer = this.fAllocator.alloc(length * this.fSampleSize);
2399
+ const buffer = this.fAllocator.alloc(
2400
+ length * this.fSampleSize
2401
+ );
1977
2402
  const HEAP32 = this.fAllocator.getInt32Array();
1978
2403
  HEAP32[(buffers >> 2) + chan] = buffer;
1979
2404
  }
@@ -1993,11 +2418,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1993
2418
  HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
1994
2419
  } else {
1995
2420
  const HEAP64 = this.fAllocator.getInt64Array();
1996
- HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(audioData.audioBuffer[0].length);
1997
- HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(audioData.sampleRate);
2421
+ HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(
2422
+ audioData.audioBuffer[0].length
2423
+ );
2424
+ HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(
2425
+ audioData.sampleRate
2426
+ );
1998
2427
  HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
1999
2428
  }
2000
- console.log(`copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${audioData}`);
2429
+ console.log(
2430
+ `copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${audioData}`
2431
+ );
2001
2432
  if (this.fSampleSize === 8) {
2002
2433
  this.copyToOutReal64(maxChannels, offset, audioData);
2003
2434
  } else {
@@ -2012,7 +2443,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2012
2443
  const output = HEAP32[(this.fBuffers >> 2) + chan];
2013
2444
  const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
2014
2445
  const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
2015
- console.log(`copyToOutReal32 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
2446
+ console.log(
2447
+ `copyToOutReal32 begin: ${begin}, end: ${end}, delta: ${end - begin}`
2448
+ );
2016
2449
  const outputReal = HEAPF.subarray(
2017
2450
  output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
2018
2451
  output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
@@ -2030,7 +2463,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2030
2463
  const output = HEAP32[(this.fBuffers >> 2) + chan];
2031
2464
  const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
2032
2465
  const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
2033
- console.log(`copyToOutReal64 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
2466
+ console.log(
2467
+ `copyToOutReal64 begin: ${begin}, end: ${end}, delta: ${end - begin}`
2468
+ );
2034
2469
  const outputReal = HEAPF.subarray(
2035
2470
  output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
2036
2471
  output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
@@ -2048,8 +2483,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2048
2483
  HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
2049
2484
  } else {
2050
2485
  const HEAP64 = this.fAllocator.getInt64Array();
2051
- HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(_Soundfile.BUFFER_SIZE);
2052
- HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(_Soundfile.SAMPLE_RATE);
2486
+ HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(
2487
+ _Soundfile.BUFFER_SIZE
2488
+ );
2489
+ HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(
2490
+ _Soundfile.SAMPLE_RATE
2491
+ );
2053
2492
  HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
2054
2493
  }
2055
2494
  return offset + _Soundfile.BUFFER_SIZE;
@@ -2064,9 +2503,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2064
2503
  const HEAP32 = this.fAllocator.getInt32Array();
2065
2504
  if (mem) console.log(`HEAP32: ${HEAP32}`);
2066
2505
  console.log(`HEAP32[this.fPtr >> 2]: ${HEAP32[this.fPtr >> 2]}`);
2067
- console.log(`HEAP32[(this.fPtr + ptrSize) >> 2]: ${HEAP32[this.fPtr + this.fPtrSize >> 2]}`);
2068
- console.log(`HEAP32[(this.fPtr + 2 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 2 * this.fPtrSize >> 2]}`);
2069
- console.log(`HEAP32[(this.fPtr + 3 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 3 * this.fPtrSize >> 2]}`);
2506
+ console.log(
2507
+ `HEAP32[(this.fPtr + ptrSize) >> 2]: ${HEAP32[this.fPtr + this.fPtrSize >> 2]}`
2508
+ );
2509
+ console.log(
2510
+ `HEAP32[(this.fPtr + 2 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 2 * this.fPtrSize >> 2]}`
2511
+ );
2512
+ console.log(
2513
+ `HEAP32[(this.fPtr + 3 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 3 * this.fPtrSize >> 2]}`
2514
+ );
2070
2515
  }
2071
2516
  // Return the pointer to the soundfile structure in wasm memory
2072
2517
  getPtr() {
@@ -2125,46 +2570,112 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2125
2570
  if (strMidi === "pitchwheel") {
2126
2571
  const matched = strMidi.match(/^pitchwheel\s(\d+)/);
2127
2572
  if (matched) {
2128
- this.fPitchwheelLabel.push({ path: item.address, chan: parseInt(matched[1]), min: item.min, max: item.max });
2573
+ this.fPitchwheelLabel.push({
2574
+ path: item.address,
2575
+ chan: parseInt(matched[1]),
2576
+ min: item.min,
2577
+ max: item.max
2578
+ });
2129
2579
  } else {
2130
- this.fPitchwheelLabel.push({ path: item.address, chan: 0, min: item.min, max: item.max });
2580
+ this.fPitchwheelLabel.push({
2581
+ path: item.address,
2582
+ chan: 0,
2583
+ min: item.min,
2584
+ max: item.max
2585
+ });
2131
2586
  }
2132
2587
  } else {
2133
2588
  const matched2 = strMidi.match(/^ctrl\s(\d+)\s(\d+)/);
2134
2589
  const matched1 = strMidi.match(/^ctrl\s(\d+)/);
2135
- const matchedKey = strMidi.match(/^key\s+(\d+)(?:\s+(\d+))?$/);
2136
- const matchedKeyOn = strMidi.match(/^keyon\s+(\d+)(?:\s+(\d+))?$/);
2137
- const matchedKeyOff = strMidi.match(/^keyoff\s+(\d+)(?:\s+(\d+))?$/);
2590
+ const matchedKey = strMidi.match(
2591
+ /^key\s+(\d+)(?:\s+(\d+))?$/
2592
+ );
2593
+ const matchedKeyOn = strMidi.match(
2594
+ /^keyon\s+(\d+)(?:\s+(\d+))?$/
2595
+ );
2596
+ const matchedKeyOff = strMidi.match(
2597
+ /^keyoff\s+(\d+)(?:\s+(\d+))?$/
2598
+ );
2138
2599
  if (matched2) {
2139
- this.fCtrlLabel[parseInt(matched2[1])].push({ path: item.address, chan: parseInt(matched2[2]), min: item.min, max: item.max });
2600
+ this.fCtrlLabel[parseInt(matched2[1])].push({
2601
+ path: item.address,
2602
+ chan: parseInt(matched2[2]),
2603
+ min: item.min,
2604
+ max: item.max
2605
+ });
2140
2606
  } else if (matched1) {
2141
- this.fCtrlLabel[parseInt(matched1[1])].push({ path: item.address, chan: 0, min: item.min, max: item.max });
2607
+ this.fCtrlLabel[parseInt(matched1[1])].push({
2608
+ path: item.address,
2609
+ chan: 0,
2610
+ min: item.min,
2611
+ max: item.max
2612
+ });
2142
2613
  } else if (matchedKey) {
2143
2614
  const note = parseInt(matchedKey[1]);
2144
2615
  const channel = matchedKey[2] ? parseInt(matchedKey[2]) : 0;
2145
- this.fMidiKeyLabel[note].push({ path: item.address, chan: channel, min: (_a = item.min) != null ? _a : 0, max: (_b = item.max) != null ? _b : 1 });
2616
+ this.fMidiKeyLabel[note].push({
2617
+ path: item.address,
2618
+ chan: channel,
2619
+ min: (_a = item.min) != null ? _a : 0,
2620
+ max: (_b = item.max) != null ? _b : 1
2621
+ });
2146
2622
  } else if (matchedKeyOn) {
2147
2623
  const note = parseInt(matchedKeyOn[1]);
2148
2624
  const channel = matchedKeyOn[2] ? parseInt(matchedKeyOn[2]) : 0;
2149
- this.fMidiKeyOnLabel[note].push({ path: item.address, chan: channel, min: (_c = item.min) != null ? _c : 0, max: (_d = item.max) != null ? _d : 1 });
2625
+ this.fMidiKeyOnLabel[note].push({
2626
+ path: item.address,
2627
+ chan: channel,
2628
+ min: (_c = item.min) != null ? _c : 0,
2629
+ max: (_d = item.max) != null ? _d : 1
2630
+ });
2150
2631
  } else if (matchedKeyOff) {
2151
2632
  const note = parseInt(matchedKeyOff[1]);
2152
2633
  const channel = matchedKeyOff[2] ? parseInt(matchedKeyOff[2]) : 0;
2153
- this.fMidiKeyOffLabel[note].push({ path: item.address, chan: channel, min: (_e = item.min) != null ? _e : 0, max: (_f = item.max) != null ? _f : 1 });
2634
+ this.fMidiKeyOffLabel[note].push({
2635
+ path: item.address,
2636
+ chan: channel,
2637
+ min: (_e = item.min) != null ? _e : 0,
2638
+ max: (_f = item.max) != null ? _f : 1
2639
+ });
2154
2640
  }
2155
2641
  }
2156
2642
  }
2157
2643
  if (acc) {
2158
2644
  const numAcc = acc.trim().split(" ").map(Number);
2159
- this.setupAccHandler(item.address, FaustSensors.convertToAxis(numAcc[0]), FaustSensors.convertToCurve(numAcc[1]), numAcc[2], numAcc[3], numAcc[4], item.min, item.init, item.max);
2645
+ this.setupAccHandler(
2646
+ item.address,
2647
+ FaustSensors.convertToAxis(numAcc[0]),
2648
+ FaustSensors.convertToCurve(numAcc[1]),
2649
+ numAcc[2],
2650
+ numAcc[3],
2651
+ numAcc[4],
2652
+ item.min,
2653
+ item.init,
2654
+ item.max
2655
+ );
2160
2656
  }
2161
2657
  if (gyr) {
2162
2658
  const numAcc = gyr.trim().split(" ").map(Number);
2163
- this.setupGyrHandler(item.address, FaustSensors.convertToAxis(numAcc[0]), FaustSensors.convertToCurve(numAcc[1]), numAcc[2], numAcc[3], numAcc[4], item.min, item.init, item.max);
2659
+ this.setupGyrHandler(
2660
+ item.address,
2661
+ FaustSensors.convertToAxis(numAcc[0]),
2662
+ FaustSensors.convertToCurve(numAcc[1]),
2663
+ numAcc[2],
2664
+ numAcc[3],
2665
+ numAcc[4],
2666
+ item.min,
2667
+ item.init,
2668
+ item.max
2669
+ );
2164
2670
  }
2165
2671
  });
2166
2672
  } else if (item.type === "soundfile") {
2167
- this.fSoundfiles.push({ name: item.label, url: item.url, index: item.index, basePtr: -1 });
2673
+ this.fSoundfiles.push({
2674
+ name: item.label,
2675
+ url: item.url,
2676
+ index: item.index,
2677
+ basePtr: -1
2678
+ });
2168
2679
  }
2169
2680
  };
2170
2681
  // Audio callback
@@ -2203,8 +2714,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2203
2714
  }
2204
2715
  /** Split the soundfile names and return an array of names */
2205
2716
  static splitSoundfileNames(input) {
2206
- let trimmed = input.replace(/^\{|\}$/g, "");
2207
- return trimmed.split(";").map((str) => str.length <= 2 ? "" : str.substring(1, str.length - 1));
2717
+ const trimmed = input.replace(/^\{|\}$/g, "");
2718
+ return trimmed.split(";").map(
2719
+ (str) => str.length <= 2 ? "" : str.substring(1, str.length - 1)
2720
+ );
2208
2721
  }
2209
2722
  get hasAccInput() {
2210
2723
  return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
@@ -2232,36 +2745,66 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2232
2745
  }
2233
2746
  /** Build the accelerometer handler */
2234
2747
  setupAccHandler(path, axis, curve, amin, amid, amax, min, init, max) {
2235
- const handler = FaustSensors.buildHandler(curve, amin, amid, amax, min, init, max);
2748
+ const handler = FaustSensors.buildHandler(
2749
+ curve,
2750
+ amin,
2751
+ amid,
2752
+ amax,
2753
+ min,
2754
+ init,
2755
+ max
2756
+ );
2236
2757
  switch (axis) {
2237
2758
  case 0 /* x */:
2238
- this.fAcc.x.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
2759
+ this.fAcc.x.push(
2760
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
2761
+ );
2239
2762
  break;
2240
2763
  case 1 /* y */:
2241
- this.fAcc.y.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
2764
+ this.fAcc.y.push(
2765
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
2766
+ );
2242
2767
  break;
2243
2768
  case 2 /* z */:
2244
- this.fAcc.z.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
2769
+ this.fAcc.z.push(
2770
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
2771
+ );
2245
2772
  break;
2246
2773
  }
2247
2774
  }
2248
2775
  /** Build the gyroscope handler */
2249
2776
  setupGyrHandler(path, axis, curve, amin, amid, amax, min, init, max) {
2250
- const handler = FaustSensors.buildHandler(curve, amin, amid, amax, min, init, max);
2777
+ const handler = FaustSensors.buildHandler(
2778
+ curve,
2779
+ amin,
2780
+ amid,
2781
+ amax,
2782
+ min,
2783
+ init,
2784
+ max
2785
+ );
2251
2786
  switch (axis) {
2252
2787
  case 0 /* x */:
2253
- this.fGyr.x.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
2788
+ this.fGyr.x.push(
2789
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
2790
+ );
2254
2791
  break;
2255
2792
  case 1 /* y */:
2256
- this.fGyr.y.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
2793
+ this.fGyr.y.push(
2794
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
2795
+ );
2257
2796
  break;
2258
2797
  case 2 /* z */:
2259
- this.fGyr.z.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
2798
+ this.fGyr.z.push(
2799
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
2800
+ );
2260
2801
  break;
2261
2802
  }
2262
2803
  }
2263
2804
  static extractUrlsFromMeta(dspMeta) {
2264
- const soundfilesEntry = dspMeta.meta.find((entry) => entry.soundfiles !== void 0);
2805
+ const soundfilesEntry = dspMeta.meta.find(
2806
+ (entry) => entry.soundfiles !== void 0
2807
+ );
2265
2808
  if (soundfilesEntry) {
2266
2809
  return soundfilesEntry.soundfiles.split(";").filter((url) => url !== "");
2267
2810
  } else {
@@ -2271,9 +2814,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2271
2814
  /**
2272
2815
  * Load a soundfile possibly containing several parts in the DSP struct.
2273
2816
  * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
2274
- * The DSP struct is located at baseDSP in the wasm memory,
2817
+ * The DSP struct is located at baseDSP in the wasm memory,
2275
2818
  * either a monophonic DSP, or a voice in a polyphonic context.
2276
- *
2819
+ *
2277
2820
  * @param allocator : the wasm memory allocator
2278
2821
  * @param baseDSP : the base DSP in the wasm memory
2279
2822
  * @param name : the name of the soundfile
@@ -2286,17 +2829,27 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2286
2829
  if (!item) throw new Error(`Soundfile with ${url} cannot be found !}`);
2287
2830
  if (item.basePtr !== -1) {
2288
2831
  const HEAP32 = allocator.getInt32Array();
2289
- console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
2832
+ console.log(
2833
+ `Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`
2834
+ );
2290
2835
  HEAP32[baseDSP + item.index >> 2] = item.basePtr;
2291
2836
  } else {
2292
- const soundfile = this.createSoundfile(allocator, soundfileIds, this.fSoundfileBuffers);
2837
+ const soundfile = this.createSoundfile(
2838
+ allocator,
2839
+ soundfileIds,
2840
+ this.fSoundfileBuffers
2841
+ );
2293
2842
  if (soundfile) {
2294
2843
  const HEAP32 = soundfile.getHEAP32();
2295
2844
  item.basePtr = soundfile.getPtr();
2296
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
2845
+ console.log(
2846
+ `Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`
2847
+ );
2297
2848
  HEAP32[baseDSP + item.index >> 2] = item.basePtr;
2298
2849
  } else {
2299
- console.log(`Soundfile ${name} for ${url} cannot be created !}`);
2850
+ console.log(
2851
+ `Soundfile ${name} for ${url} cannot be created !}`
2852
+ );
2300
2853
  }
2301
2854
  }
2302
2855
  }
@@ -2318,7 +2871,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2318
2871
  totalLength += len;
2319
2872
  }
2320
2873
  totalLength += (Soundfile.MAX_SOUNDFILE_PARTS - soundfileIdList.length) * Soundfile.BUFFER_SIZE;
2321
- const soundfile = new Soundfile(allocator, this.fSampleSize, curChan, totalLength, maxChan, soundfileIdList.length);
2874
+ const soundfile = new Soundfile(
2875
+ allocator,
2876
+ this.fSampleSize,
2877
+ curChan,
2878
+ totalLength,
2879
+ maxChan,
2880
+ soundfileIdList.length
2881
+ );
2322
2882
  let offset = 0;
2323
2883
  for (let part = 0; part < soundfileIdList.length; part++) {
2324
2884
  const soundfileId = soundfileIdList[part];
@@ -2336,31 +2896,34 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2336
2896
  soundfile.shareBuffers(curChan, maxChan);
2337
2897
  return soundfile;
2338
2898
  }
2339
- /**
2899
+ /**
2340
2900
  * Init soundfiles memory.
2341
- *
2901
+ *
2342
2902
  * @param allocator : the wasm memory allocator
2343
2903
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
2344
- */
2904
+ */
2345
2905
  initSoundfileMemory(allocator, baseDSP) {
2346
2906
  for (const { name, url } of this.fSoundfiles) {
2347
2907
  this.loadSoundfile(allocator, baseDSP, name, url);
2348
2908
  }
2349
- ;
2350
2909
  }
2351
2910
  updateOutputs() {
2352
2911
  if (this.fOutputsItems.length > 0 && this.fOutputHandler && this.fOutputsTimer-- === 0) {
2353
2912
  this.fOutputsTimer = 5;
2354
- this.fOutputsItems.forEach((item) => {
2355
- var _a;
2356
- return (_a = this.fOutputHandler) == null ? void 0 : _a.call(this, item, this.getParamValue(item));
2357
- });
2913
+ this.fOutputsItems.forEach(
2914
+ (item) => {
2915
+ var _a;
2916
+ return (_a = this.fOutputHandler) == null ? void 0 : _a.call(this, item, this.getParamValue(item));
2917
+ }
2918
+ );
2358
2919
  }
2359
2920
  }
2360
2921
  // Public API
2361
2922
  metadata(handler) {
2362
2923
  if (this.fJSONDsp.meta) {
2363
- this.fJSONDsp.meta.forEach((meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]]));
2924
+ this.fJSONDsp.meta.forEach(
2925
+ (meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]])
2926
+ );
2364
2927
  }
2365
2928
  }
2366
2929
  compute(input, output) {
@@ -2406,68 +2969,127 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2406
2969
  if (cmd === 11) return this.ctrlChange(channel, data1, data2);
2407
2970
  if (cmd === 14) return this.pitchWheel(channel, data2 * 128 + data1);
2408
2971
  if (cmd === 9) {
2409
- if (data2 > 0)
2410
- return this.keyOn(channel, data1, data2);
2411
- else
2412
- return this.keyOff(channel, data1, data2);
2972
+ if (data2 > 0) return this.keyOn(channel, data1, data2);
2973
+ else return this.keyOff(channel, data1, data2);
2413
2974
  }
2414
2975
  if (cmd === 8) {
2415
2976
  return this.keyOff(channel, data1, data2);
2416
2977
  }
2417
2978
  }
2418
2979
  ctrlChange(channel, ctrl, value) {
2419
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "ctrlChange", data: [channel, ctrl, value] });
2980
+ if (this.fPlotHandler)
2981
+ this.fCachedEvents.push({
2982
+ type: "ctrlChange",
2983
+ data: [channel, ctrl, value]
2984
+ });
2420
2985
  if (this.fCtrlLabel[ctrl].length) {
2421
2986
  this.fCtrlLabel[ctrl].forEach((ctrl2) => {
2422
2987
  const { path, chan } = ctrl2;
2423
2988
  if (chan === 0 || channel === chan - 1) {
2424
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
2425
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
2989
+ this.setParamValue(
2990
+ path,
2991
+ _FaustBaseWebAudioDsp.remap(
2992
+ value,
2993
+ 0,
2994
+ 127,
2995
+ ctrl2.min,
2996
+ ctrl2.max
2997
+ )
2998
+ );
2999
+ if (this.fOutputHandler)
3000
+ this.fOutputHandler(path, this.getParamValue(path));
2426
3001
  }
2427
3002
  });
2428
3003
  }
2429
3004
  }
2430
3005
  keyOn(channel, pitch, velocity) {
2431
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
3006
+ if (this.fPlotHandler)
3007
+ this.fCachedEvents.push({
3008
+ type: "keyOn",
3009
+ data: [channel, pitch, velocity]
3010
+ });
2432
3011
  this.fMidiKeyOnLabel[pitch].forEach((key) => {
2433
3012
  const { path, chan } = key;
2434
3013
  if (chan === 0 || channel === chan - 1) {
2435
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2436
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
3014
+ this.setParamValue(
3015
+ path,
3016
+ _FaustBaseWebAudioDsp.remap(
3017
+ velocity,
3018
+ 0,
3019
+ 127,
3020
+ key.min,
3021
+ key.max
3022
+ )
3023
+ );
3024
+ if (this.fOutputHandler)
3025
+ this.fOutputHandler(path, this.getParamValue(path));
2437
3026
  }
2438
3027
  });
2439
3028
  this.fMidiKeyLabel[pitch].forEach((key) => {
2440
3029
  const { path, chan } = key;
2441
3030
  if (chan === 0 || channel === chan - 1) {
2442
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2443
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
3031
+ this.setParamValue(
3032
+ path,
3033
+ _FaustBaseWebAudioDsp.remap(
3034
+ velocity,
3035
+ 0,
3036
+ 127,
3037
+ key.min,
3038
+ key.max
3039
+ )
3040
+ );
3041
+ if (this.fOutputHandler)
3042
+ this.fOutputHandler(path, this.getParamValue(path));
2444
3043
  }
2445
3044
  });
2446
3045
  }
2447
3046
  keyOff(channel, pitch, velocity) {
2448
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
3047
+ if (this.fPlotHandler)
3048
+ this.fCachedEvents.push({
3049
+ type: "keyOff",
3050
+ data: [channel, pitch, velocity]
3051
+ });
2449
3052
  this.fMidiKeyOffLabel[pitch].forEach((key) => {
2450
3053
  const { path, chan } = key;
2451
3054
  if (chan === 0 || channel === chan - 1) {
2452
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2453
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
3055
+ this.setParamValue(
3056
+ path,
3057
+ _FaustBaseWebAudioDsp.remap(
3058
+ velocity,
3059
+ 0,
3060
+ 127,
3061
+ key.min,
3062
+ key.max
3063
+ )
3064
+ );
3065
+ if (this.fOutputHandler)
3066
+ this.fOutputHandler(path, this.getParamValue(path));
2454
3067
  }
2455
3068
  });
2456
3069
  this.fMidiKeyLabel[pitch].forEach((key) => {
2457
3070
  const { path, chan } = key;
2458
3071
  if (chan === 0 || channel === chan - 1) {
2459
3072
  this.setParamValue(path, 0);
2460
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
3073
+ if (this.fOutputHandler)
3074
+ this.fOutputHandler(path, this.getParamValue(path));
2461
3075
  }
2462
3076
  });
2463
3077
  }
2464
3078
  pitchWheel(channel, wheel) {
2465
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
3079
+ if (this.fPlotHandler)
3080
+ this.fCachedEvents.push({
3081
+ type: "pitchWheel",
3082
+ data: [channel, wheel]
3083
+ });
2466
3084
  this.fPitchwheelLabel.forEach((pw) => {
2467
3085
  const { path, chan } = pw;
2468
3086
  if (chan === 0 || channel === chan - 1) {
2469
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
2470
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
3087
+ this.setParamValue(
3088
+ path,
3089
+ _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max)
3090
+ );
3091
+ if (this.fOutputHandler)
3092
+ this.fOutputHandler(path, this.getParamValue(path));
2471
3093
  }
2472
3094
  });
2473
3095
  }
@@ -2523,7 +3145,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2523
3145
  this.fEndMemory = this.initMemory();
2524
3146
  this.fInstance.api.init(this.fDSP, sampleRate);
2525
3147
  if (this.fSoundfiles.length > 0) {
2526
- const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
3148
+ const allocator = new WasmAllocator(
3149
+ this.fInstance.memory,
3150
+ this.fEndMemory
3151
+ );
2527
3152
  this.initSoundfileMemory(allocator, this.fDSP);
2528
3153
  }
2529
3154
  }
@@ -2542,18 +3167,30 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2542
3167
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
2543
3168
  HEAP32[(this.fAudioInputs >> 2) + chan] = $audioInputs + this.fBufferSize * this.fSampleSize * chan;
2544
3169
  }
2545
- const dspInChans = HEAP32.subarray(this.fAudioInputs >> 2, this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2);
3170
+ const dspInChans = HEAP32.subarray(
3171
+ this.fAudioInputs >> 2,
3172
+ this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2
3173
+ );
2546
3174
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
2547
- this.fInChannels[chan] = HEAPF.subarray(dspInChans[chan] >> Math.log2(this.fSampleSize), dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
3175
+ this.fInChannels[chan] = HEAPF.subarray(
3176
+ dspInChans[chan] >> Math.log2(this.fSampleSize),
3177
+ dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
3178
+ );
2548
3179
  }
2549
3180
  }
2550
3181
  if (this.getNumOutputs() > 0) {
2551
3182
  for (let chan = 0; chan < this.getNumOutputs(); chan++) {
2552
3183
  HEAP32[(this.fAudioOutputs >> 2) + chan] = $audioOutputs + this.fBufferSize * this.fSampleSize * chan;
2553
3184
  }
2554
- const dspOutChans = HEAP32.subarray(this.fAudioOutputs >> 2, this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2);
3185
+ const dspOutChans = HEAP32.subarray(
3186
+ this.fAudioOutputs >> 2,
3187
+ this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2
3188
+ );
2555
3189
  for (let chan = 0; chan < this.getNumOutputs(); chan++) {
2556
- this.fOutChannels[chan] = HEAPF.subarray(dspOutChans[chan] >> Math.log2(this.fSampleSize), dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
3190
+ this.fOutChannels[chan] = HEAPF.subarray(
3191
+ dspOutChans[chan] >> Math.log2(this.fSampleSize),
3192
+ dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
3193
+ );
2557
3194
  }
2558
3195
  }
2559
3196
  return endMemory;
@@ -2591,7 +3228,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2591
3228
  }
2592
3229
  }
2593
3230
  if (this.fComputeHandler) this.fComputeHandler(this.fBufferSize);
2594
- this.fInstance.api.compute(this.fDSP, this.fBufferSize, this.fAudioInputs, this.fAudioOutputs);
3231
+ this.fInstance.api.compute(
3232
+ this.fDSP,
3233
+ this.fBufferSize,
3234
+ this.fAudioInputs,
3235
+ this.fAudioOutputs
3236
+ );
2595
3237
  this.updateOutputs();
2596
3238
  let forPlot = this.fOutChannels;
2597
3239
  if (typeof output === "function") {
@@ -2604,7 +3246,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2604
3246
  forPlot = output;
2605
3247
  }
2606
3248
  if (this.fPlotHandler) {
2607
- this.fPlotHandler(forPlot, this.fBufferNum++, this.fCachedEvents.length ? this.fCachedEvents : void 0);
3249
+ this.fPlotHandler(
3250
+ forPlot,
3251
+ this.fBufferNum++,
3252
+ this.fCachedEvents.length ? this.fCachedEvents : void 0
3253
+ );
2608
3254
  this.fCachedEvents = [];
2609
3255
  }
2610
3256
  return true;
@@ -2619,11 +3265,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2619
3265
  return this.fInstance.api.getNumOutputs(this.fDSP);
2620
3266
  }
2621
3267
  setParamValue(path, value) {
2622
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "param", data: { path, value } });
2623
- this.fInstance.api.setParamValue(this.fDSP, this.fPathTable[path], value);
3268
+ if (this.fPlotHandler)
3269
+ this.fCachedEvents.push({ type: "param", data: { path, value } });
3270
+ this.fInstance.api.setParamValue(
3271
+ this.fDSP,
3272
+ this.fPathTable[path],
3273
+ value
3274
+ );
2624
3275
  }
2625
3276
  getParamValue(path) {
2626
- return this.fInstance.api.getParamValue(this.fDSP, this.fPathTable[path]);
3277
+ return this.fInstance.api.getParamValue(
3278
+ this.fDSP,
3279
+ this.fPathTable[path]
3280
+ );
2627
3281
  }
2628
3282
  getMeta() {
2629
3283
  return this.fJSONDsp;
@@ -2704,16 +3358,36 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2704
3358
  this.fNextNote = pitch;
2705
3359
  this.fNextVel = velocity;
2706
3360
  } else {
2707
- this.fFreqLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, _FaustWebAudioDspVoice.midiToFreq(pitch)));
2708
- this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 1));
2709
- this.fGainLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, _FaustWebAudioDspVoice.normalizeVelocity(velocity)));
2710
- this.fKeyLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, pitch));
2711
- this.fVelLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, velocity));
3361
+ this.fFreqLabel.forEach(
3362
+ (index) => this.fAPI.setParamValue(
3363
+ this.fDSP,
3364
+ index,
3365
+ _FaustWebAudioDspVoice.midiToFreq(pitch)
3366
+ )
3367
+ );
3368
+ this.fGateLabel.forEach(
3369
+ (index) => this.fAPI.setParamValue(this.fDSP, index, 1)
3370
+ );
3371
+ this.fGainLabel.forEach(
3372
+ (index) => this.fAPI.setParamValue(
3373
+ this.fDSP,
3374
+ index,
3375
+ _FaustWebAudioDspVoice.normalizeVelocity(velocity)
3376
+ )
3377
+ );
3378
+ this.fKeyLabel.forEach(
3379
+ (index) => this.fAPI.setParamValue(this.fDSP, index, pitch)
3380
+ );
3381
+ this.fVelLabel.forEach(
3382
+ (index) => this.fAPI.setParamValue(this.fDSP, index, velocity)
3383
+ );
2712
3384
  this.fCurNote = pitch;
2713
3385
  }
2714
3386
  }
2715
3387
  keyOff(hard = false) {
2716
- this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 0));
3388
+ this.fGateLabel.forEach(
3389
+ (index) => this.fAPI.setParamValue(this.fDSP, index, 0)
3390
+ );
2717
3391
  if (hard) {
2718
3392
  this.fCurNote = _FaustWebAudioDspVoice.kFreeVoice;
2719
3393
  } else {
@@ -2721,8 +3395,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2721
3395
  }
2722
3396
  }
2723
3397
  computeLegato(bufferSize, $inputs, $outputZero, $outputsHalf) {
2724
- let size = bufferSize / 2;
2725
- this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 0));
3398
+ const size = bufferSize / 2;
3399
+ this.fGateLabel.forEach(
3400
+ (index) => this.fAPI.setParamValue(this.fDSP, index, 0)
3401
+ );
2726
3402
  this.fAPI.compute(this.fDSP, size, $inputs, $outputZero);
2727
3403
  this.keyOn(this.fNextNote, this.fNextVel);
2728
3404
  this.fAPI.compute(this.fDSP, size, $inputs, $outputsHalf);
@@ -2745,21 +3421,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2745
3421
  this.fJSONDsp = JSON.parse(this.fInstance.voiceJSON);
2746
3422
  this.fJSONEffect = this.fInstance.effectAPI && this.fInstance.effectJSON ? JSON.parse(this.fInstance.effectJSON) : null;
2747
3423
  FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
2748
- if (this.fJSONEffect) FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
3424
+ if (this.fJSONEffect)
3425
+ FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
2749
3426
  this.fEndMemory = this.initMemory();
2750
3427
  this.fVoiceTable = [];
2751
3428
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
2752
- this.fVoiceTable.push(new FaustWebAudioDspVoice(
2753
- this.fJSONDsp.size * voice,
2754
- this.fInstance.voiceAPI,
2755
- this.fInputsItems,
2756
- this.fPathTable,
2757
- sampleRate
2758
- ));
2759
- }
2760
- if (this.fInstance.effectAPI) this.fInstance.effectAPI.init(this.fEffect, sampleRate);
3429
+ this.fVoiceTable.push(
3430
+ new FaustWebAudioDspVoice(
3431
+ this.fJSONDsp.size * voice,
3432
+ this.fInstance.voiceAPI,
3433
+ this.fInputsItems,
3434
+ this.fPathTable,
3435
+ sampleRate
3436
+ )
3437
+ );
3438
+ }
3439
+ if (this.fInstance.effectAPI)
3440
+ this.fInstance.effectAPI.init(this.fEffect, sampleRate);
2761
3441
  if (this.fSoundfiles.length > 0) {
2762
- const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
3442
+ const allocator = new WasmAllocator(
3443
+ this.fInstance.memory,
3444
+ this.fEndMemory
3445
+ );
2763
3446
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
2764
3447
  this.initSoundfileMemory(allocator, this.fJSONDsp.size * voice);
2765
3448
  }
@@ -2783,9 +3466,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2783
3466
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
2784
3467
  HEAP32[(this.fAudioInputs >> 2) + chan] = $audioInputs + this.fBufferSize * this.fSampleSize * chan;
2785
3468
  }
2786
- const dspInChans = HEAP32.subarray(this.fAudioInputs >> 2, this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2);
3469
+ const dspInChans = HEAP32.subarray(
3470
+ this.fAudioInputs >> 2,
3471
+ this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2
3472
+ );
2787
3473
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
2788
- this.fInChannels[chan] = HEAPF.subarray(dspInChans[chan] >> Math.log2(this.fSampleSize), dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
3474
+ this.fInChannels[chan] = HEAPF.subarray(
3475
+ dspInChans[chan] >> Math.log2(this.fSampleSize),
3476
+ dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
3477
+ );
2789
3478
  }
2790
3479
  }
2791
3480
  if (this.getNumOutputs() > 0) {
@@ -2794,9 +3483,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2794
3483
  HEAP32[(this.fAudioMixing >> 2) + chan] = $audioMixing + this.fBufferSize * this.fSampleSize * chan;
2795
3484
  HEAP32[(this.fAudioMixingHalf >> 2) + chan] = $audioMixing + this.fBufferSize * this.fSampleSize * chan + this.fBufferSize / 2 * this.fSampleSize;
2796
3485
  }
2797
- const dspOutChans = HEAP32.subarray(this.fAudioOutputs >> 2, this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2);
3486
+ const dspOutChans = HEAP32.subarray(
3487
+ this.fAudioOutputs >> 2,
3488
+ this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2
3489
+ );
2798
3490
  for (let chan = 0; chan < this.getNumOutputs(); chan++) {
2799
- this.fOutChannels[chan] = HEAPF.subarray(dspOutChans[chan] >> Math.log2(this.fSampleSize), dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
3491
+ this.fOutChannels[chan] = HEAPF.subarray(
3492
+ dspOutChans[chan] >> Math.log2(this.fSampleSize),
3493
+ dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
3494
+ );
2800
3495
  }
2801
3496
  }
2802
3497
  return endMemory;
@@ -2819,8 +3514,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2819
3514
  let voicePlaying = FaustWebAudioDspVoice.kNoVoice;
2820
3515
  let oldestDatePlaying = Number.MAX_VALUE;
2821
3516
  for (let i = 0; i < this.fInstance.voices; i++) {
2822
- let curNote = this.fVoiceTable[i].fCurNote;
2823
- let nextNote = this.fVoiceTable[i].fNextNote;
3517
+ const curNote = this.fVoiceTable[i].fCurNote;
3518
+ const nextNote = this.fVoiceTable[i].fNextNote;
2824
3519
  if (curNote === pitch || curNote === FaustWebAudioDspVoice.kLegatoVoice && nextNote === pitch) {
2825
3520
  if (this.fVoiceTable[i].fDate < oldestDatePlaying) {
2826
3521
  oldestDatePlaying = this.fVoiceTable[i].fDate;
@@ -2833,7 +3528,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2833
3528
  getFreeVoice() {
2834
3529
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
2835
3530
  if (this.fVoiceTable[voice].fCurNote === FaustWebAudioDspVoice.kFreeVoice) {
2836
- return this.allocVoice(voice, FaustWebAudioDspVoice.kActiveVoice);
3531
+ return this.allocVoice(
3532
+ voice,
3533
+ FaustWebAudioDspVoice.kActiveVoice
3534
+ );
2837
3535
  }
2838
3536
  }
2839
3537
  let voiceRelease = FaustWebAudioDspVoice.kNoVoice;
@@ -2852,12 +3550,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2852
3550
  }
2853
3551
  }
2854
3552
  if (oldestDateRelease !== Number.MAX_VALUE) {
2855
- console.log(`Steal release voice : voice_date = ${this.fVoiceTable[voiceRelease].fDate} voice = ${voiceRelease}`);
2856
- return this.allocVoice(voiceRelease, FaustWebAudioDspVoice.kLegatoVoice);
3553
+ console.log(
3554
+ `Steal release voice : voice_date = ${this.fVoiceTable[voiceRelease].fDate} voice = ${voiceRelease}`
3555
+ );
3556
+ return this.allocVoice(
3557
+ voiceRelease,
3558
+ FaustWebAudioDspVoice.kLegatoVoice
3559
+ );
2857
3560
  }
2858
3561
  if (oldestDatePlaying !== Number.MAX_VALUE) {
2859
- console.log(`Steal playing voice : voice_date = ${this.fVoiceTable[voicePlaying].fDate} voice = ${voicePlaying}`);
2860
- return this.allocVoice(voicePlaying, FaustWebAudioDspVoice.kLegatoVoice);
3562
+ console.log(
3563
+ `Steal playing voice : voice_date = ${this.fVoiceTable[voicePlaying].fDate} voice = ${voicePlaying}`
3564
+ );
3565
+ return this.allocVoice(
3566
+ voicePlaying,
3567
+ FaustWebAudioDspVoice.kLegatoVoice
3568
+ );
2861
3569
  }
2862
3570
  return FaustWebAudioDspVoice.kNoVoice;
2863
3571
  }
@@ -2882,21 +3590,54 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2882
3590
  }
2883
3591
  }
2884
3592
  if (this.fComputeHandler) this.fComputeHandler(this.fBufferSize);
2885
- this.fInstance.mixerAPI.clearOutput(this.fBufferSize, this.getNumOutputs(), this.fAudioOutputs);
3593
+ this.fInstance.mixerAPI.clearOutput(
3594
+ this.fBufferSize,
3595
+ this.getNumOutputs(),
3596
+ this.fAudioOutputs
3597
+ );
2886
3598
  this.fVoiceTable.forEach((voice) => {
2887
3599
  if (voice.fCurNote === FaustWebAudioDspVoice.kLegatoVoice) {
2888
- voice.computeLegato(this.fBufferSize, this.fAudioInputs, this.fAudioMixing, this.fAudioMixingHalf);
2889
- this.fInstance.mixerAPI.fadeOut(this.fBufferSize / 2, this.getNumOutputs(), this.fAudioMixing);
2890
- voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(this.fBufferSize, this.getNumOutputs(), this.fAudioMixing, this.fAudioOutputs);
3600
+ voice.computeLegato(
3601
+ this.fBufferSize,
3602
+ this.fAudioInputs,
3603
+ this.fAudioMixing,
3604
+ this.fAudioMixingHalf
3605
+ );
3606
+ this.fInstance.mixerAPI.fadeOut(
3607
+ this.fBufferSize / 2,
3608
+ this.getNumOutputs(),
3609
+ this.fAudioMixing
3610
+ );
3611
+ voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(
3612
+ this.fBufferSize,
3613
+ this.getNumOutputs(),
3614
+ this.fAudioMixing,
3615
+ this.fAudioOutputs
3616
+ );
2891
3617
  } else if (voice.fCurNote !== FaustWebAudioDspVoice.kFreeVoice) {
2892
- voice.compute(this.fBufferSize, this.fAudioInputs, this.fAudioMixing);
2893
- voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(this.fBufferSize, this.getNumOutputs(), this.fAudioMixing, this.fAudioOutputs);
3618
+ voice.compute(
3619
+ this.fBufferSize,
3620
+ this.fAudioInputs,
3621
+ this.fAudioMixing
3622
+ );
3623
+ voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(
3624
+ this.fBufferSize,
3625
+ this.getNumOutputs(),
3626
+ this.fAudioMixing,
3627
+ this.fAudioOutputs
3628
+ );
2894
3629
  if (voice.fCurNote == FaustWebAudioDspVoice.kReleaseVoice && voice.fLevel < FaustWebAudioDspVoice.VOICE_STOP_LEVEL) {
2895
3630
  voice.fCurNote = FaustWebAudioDspVoice.kFreeVoice;
2896
3631
  }
2897
3632
  }
2898
3633
  });
2899
- if (this.fInstance.effectAPI) this.fInstance.effectAPI.compute(this.fEffect, this.fBufferSize, this.fAudioOutputs, this.fAudioOutputs);
3634
+ if (this.fInstance.effectAPI)
3635
+ this.fInstance.effectAPI.compute(
3636
+ this.fEffect,
3637
+ this.fBufferSize,
3638
+ this.fAudioOutputs,
3639
+ this.fAudioOutputs
3640
+ );
2900
3641
  this.updateOutputs();
2901
3642
  if (output !== void 0) {
2902
3643
  for (let chan = 0; chan < Math.min(this.getNumOutputs(), output.length); chan++) {
@@ -2904,7 +3645,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2904
3645
  output[chan].set(dspOutput);
2905
3646
  }
2906
3647
  if (this.fPlotHandler) {
2907
- this.fPlotHandler(output, this.fBufferNum++, this.fCachedEvents.length ? this.fCachedEvents : void 0);
3648
+ this.fPlotHandler(
3649
+ output,
3650
+ this.fBufferNum++,
3651
+ this.fCachedEvents.length ? this.fCachedEvents : void 0
3652
+ );
2908
3653
  this.fCachedEvents = [];
2909
3654
  }
2910
3655
  }
@@ -2929,16 +3674,26 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2929
3674
  }
2930
3675
  }
2931
3676
  setParamValue(path, value) {
2932
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "param", data: { path, value } });
3677
+ if (this.fPlotHandler)
3678
+ this.fCachedEvents.push({ type: "param", data: { path, value } });
2933
3679
  if (this.fJSONEffect && _FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2934
- this.fInstance.effectAPI.setParamValue(this.fEffect, this.fPathTable[path], value);
3680
+ this.fInstance.effectAPI.setParamValue(
3681
+ this.fEffect,
3682
+ this.fPathTable[path],
3683
+ value
3684
+ );
2935
3685
  } else {
2936
- this.fVoiceTable.forEach((voice) => voice.setParamValue(this.fPathTable[path], value));
3686
+ this.fVoiceTable.forEach(
3687
+ (voice) => voice.setParamValue(this.fPathTable[path], value)
3688
+ );
2937
3689
  }
2938
3690
  }
2939
3691
  getParamValue(path) {
2940
3692
  if (this.fJSONEffect && _FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2941
- return this.fInstance.effectAPI.getParamValue(this.fEffect, this.fPathTable[path]);
3693
+ return this.fInstance.effectAPI.getParamValue(
3694
+ this.fEffect,
3695
+ this.fPathTable[path]
3696
+ );
2942
3697
  } else {
2943
3698
  return this.fVoiceTable[0].getParamValue(this.fPathTable[path]);
2944
3699
  }
@@ -2948,22 +3703,24 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2948
3703
  const e = this.fJSONEffect;
2949
3704
  const r = { ...o };
2950
3705
  if (e) {
2951
- r.ui = [{
2952
- type: "tgroup",
2953
- label: "Sequencer",
2954
- items: [
2955
- { type: "vgroup", label: "Instrument", items: o.ui },
2956
- { type: "vgroup", label: "Effect", items: e.ui }
2957
- ]
2958
- }];
3706
+ r.ui = [
3707
+ {
3708
+ type: "tgroup",
3709
+ label: "Sequencer",
3710
+ items: [
3711
+ { type: "vgroup", label: "Instrument", items: o.ui },
3712
+ { type: "vgroup", label: "Effect", items: e.ui }
3713
+ ]
3714
+ }
3715
+ ];
2959
3716
  } else {
2960
- r.ui = [{
2961
- type: "tgroup",
2962
- label: "Polyphonic",
2963
- items: [
2964
- { type: "vgroup", label: "Voices", items: o.ui }
2965
- ]
2966
- }];
3717
+ r.ui = [
3718
+ {
3719
+ type: "tgroup",
3720
+ label: "Polyphonic",
3721
+ items: [{ type: "vgroup", label: "Voices", items: o.ui }]
3722
+ }
3723
+ ];
2967
3724
  }
2968
3725
  return r;
2969
3726
  }
@@ -2981,7 +3738,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2981
3738
  const channel = data[0] & 15;
2982
3739
  const data1 = data[1];
2983
3740
  const data2 = data[2];
2984
- if (cmd === 8 || cmd === 9 && data2 === 0) return this.keyOff(channel, data1, data2);
3741
+ if (cmd === 8 || cmd === 9 && data2 === 0)
3742
+ return this.keyOff(channel, data1, data2);
2985
3743
  else if (cmd === 9) return this.keyOn(channel, data1, data2);
2986
3744
  else super.midiMessage(data);
2987
3745
  }
@@ -2993,12 +3751,24 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2993
3751
  }
2994
3752
  }
2995
3753
  keyOn(channel, pitch, velocity) {
2996
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
3754
+ if (this.fPlotHandler)
3755
+ this.fCachedEvents.push({
3756
+ type: "keyOn",
3757
+ data: [channel, pitch, velocity]
3758
+ });
2997
3759
  const voice = this.getFreeVoice();
2998
- this.fVoiceTable[voice].keyOn(pitch, velocity, this.fVoiceTable[voice].fCurNote == FaustWebAudioDspVoice.kLegatoVoice);
3760
+ this.fVoiceTable[voice].keyOn(
3761
+ pitch,
3762
+ velocity,
3763
+ this.fVoiceTable[voice].fCurNote == FaustWebAudioDspVoice.kLegatoVoice
3764
+ );
2999
3765
  }
3000
3766
  keyOff(channel, pitch, velocity) {
3001
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
3767
+ if (this.fPlotHandler)
3768
+ this.fCachedEvents.push({
3769
+ type: "keyOff",
3770
+ data: [channel, pitch, velocity]
3771
+ });
3002
3772
  const voice = this.getPlayingVoice(pitch);
3003
3773
  if (voice !== FaustWebAudioDspVoice.kNoVoice) {
3004
3774
  this.fVoiceTable[voice].keyOff();
@@ -3025,13 +3795,30 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3025
3795
  const params = [];
3026
3796
  const callback = (item) => {
3027
3797
  let param = null;
3028
- const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
3798
+ const polyKeywords = [
3799
+ "/gate",
3800
+ "/freq",
3801
+ "/gain",
3802
+ "/key",
3803
+ "/vel",
3804
+ "/velocity"
3805
+ ];
3029
3806
  const isPolyReserved = "address" in item && !!polyKeywords.find((k) => item.address.endsWith(k));
3030
3807
  if (this.fDSPCode instanceof FaustMonoWebAudioDsp || !isPolyReserved) {
3031
3808
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
3032
- param = { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
3809
+ param = {
3810
+ name: item.address,
3811
+ defaultValue: item.init || 0,
3812
+ minValue: item.min || 0,
3813
+ maxValue: item.max || 0
3814
+ };
3033
3815
  } else if (item.type === "button" || item.type === "checkbox") {
3034
- param = { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
3816
+ param = {
3817
+ name: item.address,
3818
+ defaultValue: item.init || 0,
3819
+ minValue: 0,
3820
+ maxValue: 1
3821
+ };
3035
3822
  }
3036
3823
  }
3037
3824
  if (param) params.push(param);
@@ -3204,11 +3991,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3204
3991
  files2.filter((file) => file !== "." && file !== "..").forEach((file) => fs.unlink(`/${name}-svg/${file}`));
3205
3992
  } catch {
3206
3993
  }
3207
- const success = this.compiler.generateAuxFiles(name, code, `-lang wasm -o binary -svg ${args}`);
3994
+ const success = this.compiler.generateAuxFiles(
3995
+ name,
3996
+ code,
3997
+ `-lang wasm -o binary -svg ${args}`
3998
+ );
3208
3999
  if (!success) throw new Error(this.compiler.getErrorMessage());
3209
4000
  const svgs = {};
3210
4001
  const files = fs.readdir(`/${name}-svg/`);
3211
- files.filter((file) => file !== "." && file !== "..").forEach((file) => svgs[file] = fs.readFile(`/${name}-svg/${file}`, { encoding: "utf8" }));
4002
+ files.filter((file) => file !== "." && file !== "..").forEach(
4003
+ (file) => svgs[file] = fs.readFile(`/${name}-svg/${file}`, {
4004
+ encoding: "utf8"
4005
+ })
4006
+ );
3212
4007
  return svgs;
3213
4008
  }
3214
4009
  };
@@ -3221,7 +4016,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3221
4016
  }
3222
4017
  compile(name, code, args) {
3223
4018
  const fs = this.fCompiler.fs();
3224
- const success = this.fCompiler.generateAuxFiles(name, code, `-lang cmajor-hybrid -cn ${name} -o ${name}.cmajor`);
4019
+ const success = this.fCompiler.generateAuxFiles(
4020
+ name,
4021
+ code,
4022
+ `-lang cmajor-hybrid -cn ${name} -o ${name}.cmajor`
4023
+ );
3225
4024
  return success ? fs.readFile(`${name}.cmajor`, { encoding: "utf8" }) : "";
3226
4025
  }
3227
4026
  };
@@ -3244,7 +4043,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3244
4043
  return this.fCompiler.version();
3245
4044
  }
3246
4045
  createDSPFactory(name, code, args, useInternalMemory) {
3247
- return this.fCompiler.createDSPFactory(name, code, args, useInternalMemory);
4046
+ return this.fCompiler.createDSPFactory(
4047
+ name,
4048
+ code,
4049
+ args,
4050
+ useInternalMemory
4051
+ );
3248
4052
  }
3249
4053
  deleteDSPFactory(cFactory) {
3250
4054
  return this.fCompiler.deleteDSPFactory(cFactory);
@@ -3301,7 +4105,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3301
4105
  return ab;
3302
4106
  }
3303
4107
  static writeHeader(writer, format) {
3304
- const { formatId, sampleRate, bitDepth, numberOfChannels, length, byteDepth } = format;
4108
+ const {
4109
+ formatId,
4110
+ sampleRate,
4111
+ bitDepth,
4112
+ numberOfChannels,
4113
+ length,
4114
+ byteDepth
4115
+ } = format;
3305
4116
  writer.string("RIFF");
3306
4117
  writer.uint32(writer.dataView.byteLength - 8);
3307
4118
  writer.string("WAVE");
@@ -3340,7 +4151,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3340
4151
  if (!writer[methodName]) {
3341
4152
  throw new TypeError("Not supported bit depth: " + bitDepth);
3342
4153
  }
3343
- const write = writer[methodName].bind(writer);
4154
+ const write = writer[methodName].bind(
4155
+ writer
4156
+ );
3344
4157
  for (let i = 0; i < length; i++) {
3345
4158
  for (let j = 0; j < numberOfChannels; j++) {
3346
4159
  write(audioBuffer[j][i]);
@@ -3475,7 +4288,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3475
4288
  if (chunkType === "fmt ") {
3476
4289
  format = this.decodeFormat(reader, chunkSize);
3477
4290
  } else if (chunkType === "data") {
3478
- audioData = this.decodeData(reader, chunkSize, format, options || {});
4291
+ audioData = this.decodeData(
4292
+ reader,
4293
+ chunkSize,
4294
+ format,
4295
+ options || {}
4296
+ );
3479
4297
  } else {
3480
4298
  reader.skip(chunkSize);
3481
4299
  }
@@ -3488,8 +4306,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3488
4306
  3: "lpcm"
3489
4307
  };
3490
4308
  const formatId = reader.uint16();
3491
- if (!formats.hasOwnProperty(formatId)) {
3492
- throw new TypeError("Unsupported format in WAV file: 0x" + formatId.toString(16));
4309
+ if (!Object.prototype.hasOwnProperty.call(formats, formatId)) {
4310
+ throw new TypeError(
4311
+ "Unsupported format in WAV file: 0x" + formatId.toString(16)
4312
+ );
3493
4313
  }
3494
4314
  const format = {
3495
4315
  formatId,
@@ -3641,7 +4461,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3641
4461
  var SoundfileReader = class {
3642
4462
  // Set the fallback paths
3643
4463
  static get fallbackPaths() {
3644
- return [location.href, this.getParentUrl(location.href), location.origin];
4464
+ return [
4465
+ location.href,
4466
+ this.getParentUrl(location.href),
4467
+ location.origin
4468
+ ];
3645
4469
  }
3646
4470
  /**
3647
4471
  * Extract the parent URL from an URL.
@@ -3653,7 +4477,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3653
4477
  }
3654
4478
  /**
3655
4479
  * Convert an audio buffer to audio data.
3656
- *
4480
+ *
3657
4481
  * @param audioBuffer : the audio buffer to convert
3658
4482
  * @returns : the audio data
3659
4483
  */
@@ -3666,7 +4490,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3666
4490
  }
3667
4491
  /**
3668
4492
  * Extract the URLs from the metadata.
3669
- *
4493
+ *
3670
4494
  * @param dspMeta : the metadata
3671
4495
  * @returns : the URLs
3672
4496
  */
@@ -3683,7 +4507,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3683
4507
  }
3684
4508
  /**
3685
4509
  * Check if the file exists.
3686
- *
4510
+ *
3687
4511
  * @param url : the url of the file to check
3688
4512
  * @returns : true if the file exists, otherwise false
3689
4513
  */
@@ -3700,7 +4524,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3700
4524
  }
3701
4525
  /**
3702
4526
  * Fetch the soundfile.
3703
- *
4527
+ *
3704
4528
  * @param url : the url of the soundfile
3705
4529
  * @param audioCtx : the audio context
3706
4530
  * @returns : the audio data
@@ -3708,14 +4532,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3708
4532
  static async fetchSoundfile(url, audioCtx) {
3709
4533
  console.log(`Loading sound file from ${url}`);
3710
4534
  const response = await fetch(url);
3711
- if (!response.ok) throw new Error(`Failed to load sound file from ${url}: ${response.statusText}`);
4535
+ if (!response.ok)
4536
+ throw new Error(
4537
+ `Failed to load sound file from ${url}: ${response.statusText}`
4538
+ );
3712
4539
  const arrayBuffer = await response.arrayBuffer();
3713
4540
  const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
3714
4541
  return this.toAudioData(audioBuffer);
3715
4542
  }
3716
4543
  /**
3717
4544
  * Load the soundfile.
3718
- *
4545
+ *
3719
4546
  * @param filename : the filename
3720
4547
  * @param metaUrls : the metadata URLs
3721
4548
  * @param soundfiles : the soundfiles
@@ -3723,15 +4550,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3723
4550
  */
3724
4551
  static async loadSoundfile(filename, metaUrls, soundfiles, audioCtx) {
3725
4552
  if (soundfiles == null ? void 0 : soundfiles[filename]) return;
3726
- const urlsToCheck = [filename, ...[...metaUrls, ...this.fallbackPaths].map((path) => new URL(filename, path.endsWith("/") ? path : `${path}/`).href)];
3727
- const checkResults = await Promise.all(urlsToCheck.map((url) => this.checkFileExists(url)));
4553
+ const urlsToCheck = [
4554
+ filename,
4555
+ ...[...metaUrls, ...this.fallbackPaths].map(
4556
+ (path) => new URL(filename, path.endsWith("/") ? path : `${path}/`).href
4557
+ )
4558
+ ];
4559
+ const checkResults = await Promise.all(
4560
+ urlsToCheck.map((url) => this.checkFileExists(url))
4561
+ );
3728
4562
  const successIndex = checkResults.findIndex((r) => !!r);
3729
- if (successIndex === -1) throw new Error(`Failed to load sound file ${filename}, all check failed.`);
3730
- soundfiles[filename] = await this.fetchSoundfile(urlsToCheck[successIndex], audioCtx);
4563
+ if (successIndex === -1)
4564
+ throw new Error(
4565
+ `Failed to load sound file ${filename}, all check failed.`
4566
+ );
4567
+ soundfiles[filename] = await this.fetchSoundfile(
4568
+ urlsToCheck[successIndex],
4569
+ audioCtx
4570
+ );
3731
4571
  }
3732
4572
  /**
3733
4573
  * Load the soundfiles, public API.
3734
- *
4574
+ *
3735
4575
  * @param dspMeta : the metadata
3736
4576
  * @param soundfilesIn : the soundfiles
3737
4577
  * @param audioCtx : the audio context
@@ -3772,7 +4612,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3772
4612
  this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
3773
4613
  ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
3774
4614
  ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
3775
- ;
3776
4615
  this.f32Acc = new Float32Array(ab, ptr, 3);
3777
4616
  ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
3778
4617
  this.f32Gyr = new Float32Array(ab, ptr, 3);
@@ -3812,7 +4651,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3812
4651
  const [x, y, z] = this.f32Acc;
3813
4652
  return { x, y, z, invert };
3814
4653
  }
3815
- setGyr({ alpha, beta, gamma }) {
4654
+ setGyr({
4655
+ alpha,
4656
+ beta,
4657
+ gamma
4658
+ }) {
3816
4659
  if (!this.supportSharedArrayBuffer) {
3817
4660
  const e = { type: "gyr", data: { alpha, beta, gamma } };
3818
4661
  this.port.postMessage(e);
@@ -3900,13 +4743,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3900
4743
  }
3901
4744
  };
3902
4745
  // Accelerometer and gyroscope handlers
3903
- this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
4746
+ this.handleDeviceMotion = ({
4747
+ accelerationIncludingGravity
4748
+ }) => {
3904
4749
  const isAndroid = /Android/i.test(navigator.userAgent);
3905
4750
  if (!accelerationIncludingGravity) return;
3906
4751
  const { x, y, z } = accelerationIncludingGravity;
3907
4752
  this.propagateAcc({ x, y, z }, isAndroid);
3908
4753
  };
3909
- this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
4754
+ this.handleDeviceOrientation = ({
4755
+ alpha,
4756
+ beta,
4757
+ gamma
4758
+ }) => {
3910
4759
  this.propagateGyr({ alpha, beta, gamma });
3911
4760
  };
3912
4761
  this.fJSONDsp = JSONObj;
@@ -3938,14 +4787,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3938
4787
  async startSensors() {
3939
4788
  if (this.hasAccInput) {
3940
4789
  if (window.DeviceMotionEvent) {
3941
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4790
+ window.addEventListener(
4791
+ "devicemotion",
4792
+ this.handleDeviceMotion,
4793
+ true
4794
+ );
3942
4795
  } else {
3943
4796
  console.log("Cannot set the accelerometer handler.");
3944
4797
  }
3945
4798
  }
3946
4799
  if (this.hasGyrInput) {
3947
4800
  if (window.DeviceMotionEvent) {
3948
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4801
+ window.addEventListener(
4802
+ "deviceorientation",
4803
+ this.handleDeviceOrientation,
4804
+ true
4805
+ );
3949
4806
  } else {
3950
4807
  console.log("Cannot set the gyroscope handler.");
3951
4808
  }
@@ -3953,10 +4810,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3953
4810
  }
3954
4811
  stopSensors() {
3955
4812
  if (this.hasAccInput) {
3956
- window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
4813
+ window.removeEventListener(
4814
+ "devicemotion",
4815
+ this.handleDeviceMotion,
4816
+ true
4817
+ );
3957
4818
  }
3958
4819
  if (this.hasGyrInput) {
3959
- window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
4820
+ window.removeEventListener(
4821
+ "deviceorientation",
4822
+ this.handleDeviceOrientation,
4823
+ true
4824
+ );
3960
4825
  }
3961
4826
  }
3962
4827
  setOutputParamHandler(handler) {
@@ -4004,7 +4869,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4004
4869
  }
4005
4870
  metadata(handler) {
4006
4871
  if (this.fJSONDsp.meta) {
4007
- this.fJSONDsp.meta.forEach((meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]]));
4872
+ this.fJSONDsp.meta.forEach(
4873
+ (meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]])
4874
+ );
4008
4875
  }
4009
4876
  }
4010
4877
  midiMessage(data) {
@@ -4014,7 +4881,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4014
4881
  const data2 = data[2];
4015
4882
  if (cmd === 11) this.ctrlChange(channel, data1, data2);
4016
4883
  else if (cmd === 14) this.pitchWheel(channel, data2 * 128 + data1);
4017
- if (cmd === 8 || cmd === 9 && data2 === 0) this.keyOff(channel, data1, data2);
4884
+ if (cmd === 8 || cmd === 9 && data2 === 0)
4885
+ this.keyOff(channel, data1, data2);
4018
4886
  else if (cmd === 9) this.keyOn(channel, data1, data2);
4019
4887
  else this.port.postMessage({ type: "midi", data });
4020
4888
  }
@@ -4048,7 +4916,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4048
4916
  propagateGyr(event) {
4049
4917
  if (!event) return;
4050
4918
  const { alpha, beta, gamma } = event;
4051
- this.fCommunicator.setGyr({ alpha, beta, gamma });
4919
+ this.fCommunicator.setGyr({
4920
+ alpha,
4921
+ beta,
4922
+ gamma
4923
+ });
4052
4924
  }
4053
4925
  setParamValue(path, value) {
4054
4926
  const e = { type: "param", data: { path, value } };
@@ -4090,7 +4962,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4090
4962
  _hasGyrInput = new WeakMap();
4091
4963
  var FaustMonoAudioWorkletNode = class extends FaustAudioWorkletNode {
4092
4964
  constructor(context, options) {
4093
- super(context, options.processorOptions.name, options.processorOptions.factory, options);
4965
+ super(
4966
+ context,
4967
+ options.processorOptions.name,
4968
+ options.processorOptions.factory,
4969
+ options
4970
+ );
4094
4971
  this.onprocessorerror = (e) => {
4095
4972
  throw e;
4096
4973
  };
@@ -4130,22 +5007,24 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4130
5007
  const e = this.fJSONEffect;
4131
5008
  const r = { ...o };
4132
5009
  if (e) {
4133
- r.ui = [{
4134
- type: "tgroup",
4135
- label: "Sequencer",
4136
- items: [
4137
- { type: "vgroup", label: "Instrument", items: o.ui },
4138
- { type: "vgroup", label: "Effect", items: e.ui }
4139
- ]
4140
- }];
5010
+ r.ui = [
5011
+ {
5012
+ type: "tgroup",
5013
+ label: "Sequencer",
5014
+ items: [
5015
+ { type: "vgroup", label: "Instrument", items: o.ui },
5016
+ { type: "vgroup", label: "Effect", items: e.ui }
5017
+ ]
5018
+ }
5019
+ ];
4141
5020
  } else {
4142
- r.ui = [{
4143
- type: "tgroup",
4144
- label: "Polyphonic",
4145
- items: [
4146
- { type: "vgroup", label: "Voices", items: o.ui }
4147
- ]
4148
- }];
5021
+ r.ui = [
5022
+ {
5023
+ type: "tgroup",
5024
+ label: "Polyphonic",
5025
+ items: [{ type: "vgroup", label: "Voices", items: o.ui }]
5026
+ }
5027
+ ];
4149
5028
  }
4150
5029
  return r;
4151
5030
  }
@@ -4168,13 +5047,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4168
5047
  this.fDSPCode = instance;
4169
5048
  this.fInputs = new Array(this.fDSPCode.getNumInputs());
4170
5049
  this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
4171
- this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
5050
+ this.handleDeviceMotion = ({
5051
+ accelerationIncludingGravity
5052
+ }) => {
4172
5053
  const isAndroid = /Android/i.test(navigator.userAgent);
4173
5054
  if (!accelerationIncludingGravity) return;
4174
5055
  const { x, y, z } = accelerationIncludingGravity;
4175
5056
  this.propagateAcc({ x, y, z }, isAndroid);
4176
5057
  };
4177
- this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
5058
+ this.handleDeviceOrientation = ({
5059
+ alpha,
5060
+ beta,
5061
+ gamma
5062
+ }) => {
4178
5063
  this.propagateGyr({ alpha, beta, gamma });
4179
5064
  };
4180
5065
  this.onaudioprocess = (e) => {
@@ -4193,14 +5078,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4193
5078
  async startSensors() {
4194
5079
  if (this.hasAccInput) {
4195
5080
  if (window.DeviceMotionEvent) {
4196
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
5081
+ window.addEventListener(
5082
+ "devicemotion",
5083
+ this.handleDeviceMotion,
5084
+ true
5085
+ );
4197
5086
  } else {
4198
5087
  console.log("Cannot set the accelerometer handler.");
4199
5088
  }
4200
5089
  }
4201
5090
  if (this.hasGyrInput) {
4202
5091
  if (window.DeviceMotionEvent) {
4203
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
5092
+ window.addEventListener(
5093
+ "deviceorientation",
5094
+ this.handleDeviceOrientation,
5095
+ true
5096
+ );
4204
5097
  } else {
4205
5098
  console.log("Cannot set the gyroscope handler.");
4206
5099
  }
@@ -4209,10 +5102,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4209
5102
  /** Stop accelerometer and gyroscope handlers */
4210
5103
  stopSensors() {
4211
5104
  if (this.hasAccInput) {
4212
- window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
5105
+ window.removeEventListener(
5106
+ "devicemotion",
5107
+ this.handleDeviceMotion,
5108
+ true
5109
+ );
4213
5110
  }
4214
5111
  if (this.hasGyrInput) {
4215
- window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
5112
+ window.removeEventListener(
5113
+ "deviceorientation",
5114
+ this.handleDeviceOrientation,
5115
+ true
5116
+ );
4216
5117
  }
4217
5118
  }
4218
5119
  compute(input, output) {
@@ -4334,13 +5235,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4334
5235
  }
4335
5236
  }
4336
5237
  addSoundfiles(soundfileMap) {
4337
- if (!this.factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5238
+ if (!this.factory)
5239
+ throw new Error(
5240
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5241
+ );
4338
5242
  for (const id in soundfileMap) {
4339
5243
  this.factory.soundfiles[id] = soundfileMap[id];
4340
5244
  }
4341
5245
  }
4342
5246
  getSoundfileList() {
4343
- if (!this.factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5247
+ if (!this.factory)
5248
+ throw new Error(
5249
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5250
+ );
4344
5251
  const meta = JSON.parse(this.factory.json);
4345
5252
  const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
4346
5253
  if (!map) return [];
@@ -4348,19 +5255,40 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4348
5255
  }
4349
5256
  async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name, processorOptions = {}) {
4350
5257
  var _a, _b;
4351
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5258
+ if (!factory)
5259
+ throw new Error(
5260
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5261
+ );
4352
5262
  const meta = JSON.parse(factory.json);
4353
5263
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
4354
- factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
5264
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(
5265
+ meta,
5266
+ factory.soundfiles || {},
5267
+ context
5268
+ );
4355
5269
  if (sp) {
4356
5270
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
4357
- const monoDsp = new FaustMonoWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize, factory.soundfiles);
4358
- const sp2 = context.createScriptProcessor(bufferSize, monoDsp.getNumInputs(), monoDsp.getNumOutputs());
5271
+ const monoDsp = new FaustMonoWebAudioDsp(
5272
+ instance,
5273
+ context.sampleRate,
5274
+ sampleSize,
5275
+ bufferSize,
5276
+ factory.soundfiles
5277
+ );
5278
+ const sp2 = context.createScriptProcessor(
5279
+ bufferSize,
5280
+ monoDsp.getNumInputs(),
5281
+ monoDsp.getNumOutputs()
5282
+ );
4359
5283
  Object.setPrototypeOf(sp2, FaustMonoScriptProcessorNode.prototype);
4360
5284
  sp2.init(monoDsp);
4361
5285
  return sp2;
4362
5286
  } else {
4363
- if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context)) _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
5287
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
5288
+ _FaustMonoDspGenerator.gWorkletProcessors.set(
5289
+ context,
5290
+ /* @__PURE__ */ new Set()
5291
+ );
4364
5292
  if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
4365
5293
  try {
4366
5294
  const processorCode = `
@@ -4400,24 +5328,41 @@ const dependencies = {
4400
5328
  // Generate the actual AudioWorkletProcessor code
4401
5329
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
4402
5330
  `;
4403
- const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
5331
+ const url = URL.createObjectURL(
5332
+ new Blob([processorCode], { type: "text/javascript" })
5333
+ );
4404
5334
  await context.audioWorklet.addModule(url);
4405
5335
  (_b = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
4406
5336
  } catch (e) {
4407
5337
  throw e;
4408
5338
  }
4409
5339
  }
4410
- const node = new FaustMonoAudioWorkletNode(context, { processorOptions: { name: processorName, factory, sampleSize, ...processorOptions } });
5340
+ const node = new FaustMonoAudioWorkletNode(context, {
5341
+ processorOptions: {
5342
+ name: processorName,
5343
+ factory,
5344
+ sampleSize,
5345
+ ...processorOptions
5346
+ }
5347
+ });
4411
5348
  return node;
4412
5349
  }
4413
5350
  }
4414
5351
  async createFFTNode(context, fftUtils, name = this.name, factory = this.factory, fftOptions = {}, processorName = (factory == null ? void 0 : factory.shaKey) ? `${factory.shaKey}_fft` : name, processorOptions = {}) {
4415
5352
  var _a, _b;
4416
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5353
+ if (!factory)
5354
+ throw new Error(
5355
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5356
+ );
4417
5357
  const meta = JSON.parse(factory.json);
4418
5358
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
4419
- factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
4420
- if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context)) _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
5359
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(
5360
+ meta,
5361
+ factory.soundfiles || {},
5362
+ context
5363
+ );
5364
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
5365
+ _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
4421
5366
  if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
4422
5367
  try {
4423
5368
  const processorCode = `
@@ -4459,14 +5404,25 @@ const dependencies = {
4459
5404
  // Generate the actual AudioWorkletProcessor code
4460
5405
  (${FaustFFTAudioWorkletProcessor_default.toString()})(dependencies, faustData);
4461
5406
  `;
4462
- const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
5407
+ const url = URL.createObjectURL(
5408
+ new Blob([processorCode], { type: "text/javascript" })
5409
+ );
4463
5410
  await context.audioWorklet.addModule(url);
4464
5411
  (_b = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
4465
5412
  } catch (e) {
4466
5413
  throw e;
4467
5414
  }
4468
5415
  }
4469
- const node = new FaustMonoAudioWorkletNode(context, { channelCount: Math.max(1, Math.ceil(meta.inputs / 3)), outputChannelCount: [Math.ceil(meta.outputs / 2)], processorOptions: { name: processorName, factory, sampleSize, ...processorOptions } });
5416
+ const node = new FaustMonoAudioWorkletNode(context, {
5417
+ channelCount: Math.max(1, Math.ceil(meta.inputs / 3)),
5418
+ outputChannelCount: [Math.ceil(meta.outputs / 2)],
5419
+ processorOptions: {
5420
+ name: processorName,
5421
+ factory,
5422
+ sampleSize,
5423
+ ...processorOptions
5424
+ }
5425
+ });
4470
5426
  if (fftOptions.fftSize) {
4471
5427
  const param = node.parameters.get("fftSize");
4472
5428
  if (param) param.value = fftOptions.fftSize;
@@ -4486,7 +5442,10 @@ const dependencies = {
4486
5442
  return node;
4487
5443
  }
4488
5444
  async createAudioWorkletProcessor(name = this.name, factory = this.factory, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
4489
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5445
+ if (!factory)
5446
+ throw new Error(
5447
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5448
+ );
4490
5449
  const meta = JSON.parse(factory.json);
4491
5450
  const dependencies = {
4492
5451
  FaustBaseWebAudioDsp,
@@ -4503,19 +5462,36 @@ const dependencies = {
4503
5462
  dspMeta: meta,
4504
5463
  poly: false
4505
5464
  };
4506
- const Processor = FaustAudioWorkletProcessor_default(dependencies, faustData);
5465
+ const Processor = FaustAudioWorkletProcessor_default(
5466
+ dependencies,
5467
+ faustData
5468
+ );
4507
5469
  return Processor;
4508
5470
  } catch (e) {
4509
5471
  throw e;
4510
5472
  }
4511
5473
  }
4512
5474
  async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory, context) {
4513
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5475
+ if (!factory)
5476
+ throw new Error(
5477
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5478
+ );
4514
5479
  const meta = JSON.parse(factory.json);
4515
5480
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
4516
5481
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
4517
- if (context) factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
4518
- const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
5482
+ if (context)
5483
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(
5484
+ meta,
5485
+ factory.soundfiles || {},
5486
+ context
5487
+ );
5488
+ const monoDsp = new FaustMonoWebAudioDsp(
5489
+ instance,
5490
+ sampleRate,
5491
+ sampleSize,
5492
+ bufferSize,
5493
+ factory.soundfiles
5494
+ );
4519
5495
  return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
4520
5496
  }
4521
5497
  getMeta() {
@@ -4541,7 +5517,11 @@ const dependencies = {
4541
5517
  };
4542
5518
  process = dsp_code.effect;`) {
4543
5519
  try {
4544
- this.effectFactory = await compiler.createPolyDSPFactory(name, effectCodeAux, args);
5520
+ this.effectFactory = await compiler.createPolyDSPFactory(
5521
+ name,
5522
+ effectCodeAux,
5523
+ args
5524
+ );
4545
5525
  if (this.effectFactory) {
4546
5526
  const effectJSON = JSON.parse(this.effectFactory.json);
4547
5527
  const dspCode = `// Voice output is forced to 2, when DSP is stereo or effect has 2 ins or 2 outs,
@@ -4581,16 +5561,28 @@ dsp_code = environment{
4581
5561
  };
4582
5562
  process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
4583
5563
  `;
4584
- this.voiceFactory = await compiler.createPolyDSPFactory(name, dspCode, args);
5564
+ this.voiceFactory = await compiler.createPolyDSPFactory(
5565
+ name,
5566
+ dspCode,
5567
+ args
5568
+ );
4585
5569
  try {
4586
- this.effectFactory = await compiler.createPolyDSPFactory(name, effectCode, args + " -inpl");
5570
+ this.effectFactory = await compiler.createPolyDSPFactory(
5571
+ name,
5572
+ effectCode,
5573
+ args + " -inpl"
5574
+ );
4587
5575
  } catch (e) {
4588
5576
  console.warn(e);
4589
5577
  }
4590
5578
  }
4591
5579
  } catch (e) {
4592
5580
  console.warn(e);
4593
- this.voiceFactory = await compiler.createPolyDSPFactory(name, dspCodeAux, args);
5581
+ this.voiceFactory = await compiler.createPolyDSPFactory(
5582
+ name,
5583
+ dspCodeAux,
5584
+ args
5585
+ );
4594
5586
  }
4595
5587
  if (this.voiceFactory) {
4596
5588
  this.name = name;
@@ -4605,13 +5597,19 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
4605
5597
  }
4606
5598
  }
4607
5599
  addSoundfiles(soundfileMap) {
4608
- if (!this.voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5600
+ if (!this.voiceFactory)
5601
+ throw new Error(
5602
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5603
+ );
4609
5604
  for (const id in soundfileMap) {
4610
5605
  this.voiceFactory.soundfiles[id] = soundfileMap[id];
4611
5606
  }
4612
5607
  }
4613
5608
  getSoundfileList() {
4614
- if (!this.voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5609
+ if (!this.voiceFactory)
5610
+ throw new Error(
5611
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5612
+ );
4615
5613
  const meta = JSON.parse(this.voiceFactory.json);
4616
5614
  const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
4617
5615
  if (!map) return [];
@@ -4622,22 +5620,56 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
4622
5620
  }
4623
5621
  async createNode(context, voices, name = this.name, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, sp = false, bufferSize = 1024, processorName = ((voiceFactory == null ? void 0 : voiceFactory.shaKey) || "") + ((effectFactory == null ? void 0 : effectFactory.shaKey) || "") || `${name}_poly`, processorOptions = {}) {
4624
5622
  var _a, _b;
4625
- if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5623
+ if (!voiceFactory)
5624
+ throw new Error(
5625
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5626
+ );
4626
5627
  const voiceMeta = JSON.parse(voiceFactory.json);
4627
5628
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4628
5629
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
4629
- voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
4630
- if (effectFactory) effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
5630
+ voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
5631
+ voiceMeta,
5632
+ voiceFactory.soundfiles || {},
5633
+ context
5634
+ );
5635
+ if (effectFactory)
5636
+ effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
5637
+ effectMeta,
5638
+ effectFactory.soundfiles || {},
5639
+ context
5640
+ );
4631
5641
  if (sp) {
4632
- const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
4633
- const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
4634
- const polyDsp = new FaustPolyWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize, soundfiles);
4635
- const sp2 = context.createScriptProcessor(bufferSize, polyDsp.getNumInputs(), polyDsp.getNumOutputs());
5642
+ const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(
5643
+ voiceFactory,
5644
+ mixerModule,
5645
+ voices,
5646
+ effectFactory || void 0
5647
+ );
5648
+ const soundfiles = {
5649
+ ...effectFactory == null ? void 0 : effectFactory.soundfiles,
5650
+ ...voiceFactory.soundfiles
5651
+ };
5652
+ const polyDsp = new FaustPolyWebAudioDsp(
5653
+ instance,
5654
+ context.sampleRate,
5655
+ sampleSize,
5656
+ bufferSize,
5657
+ soundfiles
5658
+ );
5659
+ const sp2 = context.createScriptProcessor(
5660
+ bufferSize,
5661
+ polyDsp.getNumInputs(),
5662
+ polyDsp.getNumOutputs()
5663
+ );
4636
5664
  Object.setPrototypeOf(sp2, FaustPolyScriptProcessorNode.prototype);
4637
5665
  sp2.init(polyDsp);
4638
5666
  return sp2;
4639
5667
  } else {
4640
- if (!_FaustPolyDspGenerator.gWorkletProcessors.has(context)) _FaustPolyDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
5668
+ if (!_FaustPolyDspGenerator.gWorkletProcessors.has(context))
5669
+ _FaustPolyDspGenerator.gWorkletProcessors.set(
5670
+ context,
5671
+ /* @__PURE__ */ new Set()
5672
+ );
4641
5673
  if (!((_a = _FaustPolyDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
4642
5674
  try {
4643
5675
  const processorCode = `
@@ -4680,19 +5712,34 @@ const dependencies = {
4680
5712
  // Generate the actual AudioWorkletProcessor code
4681
5713
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
4682
5714
  `;
4683
- const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
5715
+ const url = URL.createObjectURL(
5716
+ new Blob([processorCode], { type: "text/javascript" })
5717
+ );
4684
5718
  await context.audioWorklet.addModule(url);
4685
5719
  (_b = _FaustPolyDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
4686
5720
  } catch (e) {
4687
5721
  throw e;
4688
5722
  }
4689
5723
  }
4690
- const node = new FaustPolyAudioWorkletNode(context, { processorOptions: { name: processorName, voiceFactory, mixerModule, voices, sampleSize, effectFactory: effectFactory || void 0, ...processorOptions } });
5724
+ const node = new FaustPolyAudioWorkletNode(context, {
5725
+ processorOptions: {
5726
+ name: processorName,
5727
+ voiceFactory,
5728
+ mixerModule,
5729
+ voices,
5730
+ sampleSize,
5731
+ effectFactory: effectFactory || void 0,
5732
+ ...processorOptions
5733
+ }
5734
+ });
4691
5735
  return node;
4692
5736
  }
4693
5737
  }
4694
5738
  async createAudioWorkletProcessor(name = this.name, voiceFactory = this.voiceFactory, effectFactory = this.effectFactory, processorName = ((voiceFactory == null ? void 0 : voiceFactory.shaKey) || "") + ((effectFactory == null ? void 0 : effectFactory.shaKey) || "") || `${name}_poly`) {
4695
- if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5739
+ if (!voiceFactory)
5740
+ throw new Error(
5741
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5742
+ );
4696
5743
  const voiceMeta = JSON.parse(voiceFactory.json);
4697
5744
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4698
5745
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
@@ -4712,24 +5759,53 @@ const dependencies = {
4712
5759
  poly: true,
4713
5760
  effectMeta
4714
5761
  };
4715
- const Processor = FaustAudioWorkletProcessor_default(dependencies, faustData);
5762
+ const Processor = FaustAudioWorkletProcessor_default(
5763
+ dependencies,
5764
+ faustData
5765
+ );
4716
5766
  return Processor;
4717
5767
  } catch (e) {
4718
5768
  throw e;
4719
5769
  }
4720
5770
  }
4721
5771
  async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, context) {
4722
- if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
5772
+ if (!voiceFactory)
5773
+ throw new Error(
5774
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
5775
+ );
4723
5776
  const voiceMeta = JSON.parse(voiceFactory.json);
4724
5777
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4725
- const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
5778
+ const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(
5779
+ voiceFactory,
5780
+ mixerModule,
5781
+ voices,
5782
+ effectFactory || void 0
5783
+ );
4726
5784
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
4727
5785
  if (context) {
4728
- voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
4729
- if (effectFactory) effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
4730
- }
4731
- const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
4732
- const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
5786
+ voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
5787
+ voiceMeta,
5788
+ voiceFactory.soundfiles || {},
5789
+ context
5790
+ );
5791
+ if (effectFactory)
5792
+ effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
5793
+ effectMeta,
5794
+ effectFactory.soundfiles || {},
5795
+ context
5796
+ );
5797
+ }
5798
+ const soundfiles = {
5799
+ ...effectFactory == null ? void 0 : effectFactory.soundfiles,
5800
+ ...voiceFactory.soundfiles
5801
+ };
5802
+ const polyDsp = new FaustPolyWebAudioDsp(
5803
+ instance,
5804
+ sampleRate,
5805
+ sampleSize,
5806
+ bufferSize,
5807
+ soundfiles
5808
+ );
4733
5809
  return new FaustPolyOfflineProcessor(polyDsp, bufferSize);
4734
5810
  }
4735
5811
  getMeta() {
@@ -4737,22 +5813,24 @@ const dependencies = {
4737
5813
  const e = this.effectFactory ? JSON.parse(this.effectFactory.json) : null;
4738
5814
  const r = { ...o };
4739
5815
  if (e) {
4740
- r.ui = [{
4741
- type: "tgroup",
4742
- label: "Sequencer",
4743
- items: [
4744
- { type: "vgroup", label: "Instrument", items: o.ui },
4745
- { type: "vgroup", label: "Effect", items: e.ui }
4746
- ]
4747
- }];
5816
+ r.ui = [
5817
+ {
5818
+ type: "tgroup",
5819
+ label: "Sequencer",
5820
+ items: [
5821
+ { type: "vgroup", label: "Instrument", items: o.ui },
5822
+ { type: "vgroup", label: "Effect", items: e.ui }
5823
+ ]
5824
+ }
5825
+ ];
4748
5826
  } else {
4749
- r.ui = [{
4750
- type: "tgroup",
4751
- label: "Polyphonic",
4752
- items: [
4753
- { type: "vgroup", label: "Voices", items: o.ui }
4754
- ]
4755
- }];
5827
+ r.ui = [
5828
+ {
5829
+ type: "tgroup",
5830
+ label: "Polyphonic",
5831
+ items: [{ type: "vgroup", label: "Voices", items: o.ui }]
5832
+ }
5833
+ ];
4756
5834
  }
4757
5835
  return r;
4758
5836
  }
@@ -4766,5 +5844,96 @@ const dependencies = {
4766
5844
  // Set of all created WorkletProcessors, each of them has to be unique
4767
5845
  _FaustPolyDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
4768
5846
  var FaustPolyDspGenerator = _FaustPolyDspGenerator;
5847
+ var _FaustDspGenerator = class _FaustDspGenerator {
5848
+ // Analyze the metadata of a Faust JSON file and extract the [midi:on] and [nvoices:n] options
5849
+ extractMidiAndNvoices(jsonData) {
5850
+ const optionsMetadata = jsonData.meta.find((meta) => meta.options);
5851
+ if (optionsMetadata && optionsMetadata.options) {
5852
+ const options = optionsMetadata.options;
5853
+ const midiRegex = /\[midi:(on|off)\]/;
5854
+ const nvoicesRegex = /\[nvoices:(\d+)\]/;
5855
+ const midiMatch = options.match(midiRegex);
5856
+ const nvoicesMatch = options.match(nvoicesRegex);
5857
+ const midi = midiMatch ? midiMatch[1] === "on" : false;
5858
+ const nvoices = nvoicesMatch ? parseInt(nvoicesMatch[1], 10) : -1;
5859
+ return { midi, nvoices };
5860
+ } else {
5861
+ return { midi: false, nvoices: -1 };
5862
+ }
5863
+ }
5864
+ /**
5865
+ * Compile DSP code, inspect metadata for [nvoices:] (and optionally [midi:on]), and build either a mono
5866
+ * or poly WebAudio node (ScriptProcessor or AudioWorklet depending on `sp`). Compilation uses a shared,
5867
+ * lazily-created libfaust instance to avoid repeatedly instantiating the WASM compiler.
5868
+ */
5869
+ async createFaustNode(context, name, code, sp, bufferSize) {
5870
+ const getCompiler = async () => {
5871
+ if (!_FaustDspGenerator.compilerPromise) {
5872
+ const baseURL = (typeof document !== "undefined" ? "src" in (document.currentScript || {}) ? document.currentScript.src : document.baseURI : void 0) || (typeof window !== "undefined" ? window.location.href : void 0);
5873
+ if (!baseURL)
5874
+ throw new Error("Cannot resolve libfaust-wasm location.");
5875
+ const jsURL = new URL(
5876
+ "../libfaust-wasm/libfaust-wasm.js",
5877
+ baseURL
5878
+ ).href;
5879
+ const dataURL = jsURL.replace(/c?js$/, "data");
5880
+ const wasmURL = jsURL.replace(/c?js$/, "wasm");
5881
+ _FaustDspGenerator.compilerPromise = instantiateFaustModuleFromFile_default(
5882
+ jsURL,
5883
+ dataURL,
5884
+ wasmURL
5885
+ ).then((module) => new FaustCompiler_default(new LibFaust_default(module)));
5886
+ }
5887
+ return _FaustDspGenerator.compilerPromise;
5888
+ };
5889
+ const args = "-ftz 2";
5890
+ try {
5891
+ const compiler = await getCompiler();
5892
+ const monoGenerator = new FaustMonoDspGenerator();
5893
+ const compiledMono = await monoGenerator.compile(
5894
+ compiler,
5895
+ name,
5896
+ code,
5897
+ args
5898
+ );
5899
+ if (!compiledMono) return null;
5900
+ const { nvoices } = this.extractMidiAndNvoices(
5901
+ monoGenerator.getMeta()
5902
+ );
5903
+ if (nvoices > 0) {
5904
+ const polyGenerator = new FaustPolyDspGenerator();
5905
+ const compiledPoly = await polyGenerator.compile(
5906
+ compiler,
5907
+ name,
5908
+ code,
5909
+ args
5910
+ );
5911
+ if (!compiledPoly) return null;
5912
+ return await polyGenerator.createNode(
5913
+ context,
5914
+ nvoices,
5915
+ name,
5916
+ void 0,
5917
+ void 0,
5918
+ void 0,
5919
+ sp,
5920
+ bufferSize
5921
+ );
5922
+ }
5923
+ return await monoGenerator.createNode(
5924
+ context,
5925
+ name,
5926
+ void 0,
5927
+ sp,
5928
+ bufferSize
5929
+ );
5930
+ } catch (e) {
5931
+ console.error(e);
5932
+ return null;
5933
+ }
5934
+ }
5935
+ };
5936
+ _FaustDspGenerator.compilerPromise = null;
5937
+ var FaustDspGenerator = _FaustDspGenerator;
4769
5938
  })();
4770
5939
  //# sourceMappingURL=index.js.map