@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
@@ -41,7 +41,7 @@
41
41
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
42
42
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
43
43
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
44
- var __toBinary = /* @__PURE__ */ (() => {
44
+ var __toBinary = Uint8Array.fromBase64 || /* @__PURE__ */ (() => {
45
45
  var table = new Uint8Array(128);
46
46
  for (var i = 0; i < 64; i++) table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;
47
47
  return (base64) => {
@@ -5768,6 +5768,7 @@
5768
5768
  FaustBaseWebAudioDsp: () => FaustBaseWebAudioDsp,
5769
5769
  FaustCmajor: () => FaustCmajor_default,
5770
5770
  FaustCompiler: () => FaustCompiler_default,
5771
+ FaustDspGenerator: () => FaustDspGenerator,
5771
5772
  FaustDspInstance: () => FaustDspInstance,
5772
5773
  FaustModuleFactoryData: () => FaustModuleFactoryData,
5773
5774
  FaustModuleFactoryFn: () => FaustModuleFactoryFn,
@@ -5851,7 +5852,9 @@
5851
5852
  jsCode = `${jsCode}
5852
5853
  export default ${(_a = jsCode.match(jsCodeHead)) == null ? void 0 : _a[1]};
5853
5854
  `;
5854
- const jsFileMod = URL.createObjectURL(new Blob([jsCode], { type: "text/javascript" }));
5855
+ const jsFileMod = URL.createObjectURL(
5856
+ new Blob([jsCode], { type: "text/javascript" })
5857
+ );
5855
5858
  FaustModule = (await import(
5856
5859
  /* webpackIgnore: true */
5857
5860
  jsFileMod
@@ -5905,21 +5908,32 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
5905
5908
  FaustWasmInstantiator: FaustWasmInstantiator2,
5906
5909
  FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
5907
5910
  } = dependencies;
5908
- const {
5909
- processorName,
5910
- dspName,
5911
- dspMeta,
5912
- effectMeta,
5913
- poly
5914
- } = faustData;
5911
+ const { processorName, dspName, dspMeta, effectMeta, poly } = faustData;
5915
5912
  const analysePolyParameters = (item) => {
5916
- const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
5913
+ const polyKeywords = [
5914
+ "/gate",
5915
+ "/freq",
5916
+ "/gain",
5917
+ "/key",
5918
+ "/vel",
5919
+ "/velocity"
5920
+ ];
5917
5921
  const isPolyReserved = "address" in item && !!polyKeywords.find((k) => item.address.endsWith(k));
5918
5922
  if (poly && isPolyReserved) return null;
5919
5923
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
5920
- return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
5924
+ return {
5925
+ name: item.address,
5926
+ defaultValue: item.init || 0,
5927
+ minValue: item.min || 0,
5928
+ maxValue: item.max || 0
5929
+ };
5921
5930
  } else if (item.type === "button" || item.type === "checkbox") {
5922
- return { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
5931
+ return {
5932
+ name: item.address,
5933
+ defaultValue: item.init || 0,
5934
+ minValue: 0,
5935
+ maxValue: 1
5936
+ };
5923
5937
  }
5924
5938
  return null;
5925
5939
  };
@@ -5927,7 +5941,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
5927
5941
  constructor(options) {
5928
5942
  super(options);
5929
5943
  this.paramValuesCache = {};
5930
- this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
5944
+ this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(
5945
+ this.port
5946
+ );
5931
5947
  const { parameterDescriptors } = this.constructor;
5932
5948
  parameterDescriptors.forEach((pd) => {
5933
5949
  this.paramValuesCache[pd.name] = pd.defaultValue || 0;
@@ -5943,7 +5959,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
5943
5959
  if (param) params.push(param);
5944
5960
  };
5945
5961
  FaustBaseWebAudioDsp2.parseUI(dspMeta.ui, callback);
5946
- if (effectMeta) FaustBaseWebAudioDsp2.parseUI(effectMeta.ui, callback);
5962
+ if (effectMeta)
5963
+ FaustBaseWebAudioDsp2.parseUI(effectMeta.ui, callback);
5947
5964
  return params;
5948
5965
  }
5949
5966
  setupWamEventHandler() {
@@ -5951,12 +5968,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
5951
5968
  if (!this.wamInfo) return;
5952
5969
  const { moduleId, instanceId } = this.wamInfo;
5953
5970
  const { webAudioModules } = globalThis;
5954
- const ModuleScope = webAudioModules.getModuleScope(moduleId);
5971
+ const ModuleScope = webAudioModules.getModuleScope(
5972
+ moduleId
5973
+ );
5955
5974
  const paramMgrProcessor = (_a = ModuleScope == null ? void 0 : ModuleScope.paramMgrProcessors) == null ? void 0 : _a[instanceId];
5956
5975
  if (!paramMgrProcessor) return;
5957
5976
  if (paramMgrProcessor.handleEvent) return;
5958
5977
  paramMgrProcessor.handleEvent = (event) => {
5959
- if (event.type === "wam-midi") this.midiMessage(event.data.bytes);
5978
+ if (event.type === "wam-midi")
5979
+ this.midiMessage(event.data.bytes);
5960
5980
  };
5961
5981
  }
5962
5982
  process(inputs, outputs, parameters) {
@@ -6016,7 +6036,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6016
6036
  // Plot handler set on demand
6017
6037
  case "setPlotHandler": {
6018
6038
  if (msg.data) {
6019
- this.fDSPCode.setPlotHandler((output, index, events) => this.port.postMessage({ type: "plot", value: output, index, events }));
6039
+ this.fDSPCode.setPlotHandler(
6040
+ (output, index, events) => this.port.postMessage({
6041
+ type: "plot",
6042
+ value: output,
6043
+ index,
6044
+ events
6045
+ })
6046
+ );
6020
6047
  } else {
6021
6048
  this.fDSPCode.setPlotHandler(null);
6022
6049
  }
@@ -6078,10 +6105,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6078
6105
  const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
6079
6106
  const { factory, sampleSize } = options.processorOptions;
6080
6107
  const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
6081
- this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
6108
+ this.fDSPCode = new FaustMonoWebAudioDsp2(
6109
+ instance,
6110
+ sampleRate,
6111
+ sampleSize,
6112
+ 128,
6113
+ factory.soundfiles
6114
+ );
6082
6115
  this.port.addEventListener("message", this.handleMessageAux);
6083
6116
  this.port.start();
6084
- this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
6117
+ this.fDSPCode.setOutputParamHandler(
6118
+ (path, value) => this.port.postMessage({ path, value, type: "param" })
6119
+ );
6085
6120
  this.fDSPCode.start();
6086
6121
  }
6087
6122
  }
@@ -6103,13 +6138,35 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6103
6138
  }
6104
6139
  };
6105
6140
  const { FaustPolyWebAudioDsp: FaustPolyWebAudioDsp3 } = dependencies;
6106
- const { voiceFactory, mixerModule, voices, effectFactory, sampleSize } = options.processorOptions;
6107
- const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
6108
- const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
6109
- this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
6141
+ const {
6142
+ voiceFactory,
6143
+ mixerModule,
6144
+ voices,
6145
+ effectFactory,
6146
+ sampleSize
6147
+ } = options.processorOptions;
6148
+ const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(
6149
+ voiceFactory,
6150
+ mixerModule,
6151
+ voices,
6152
+ effectFactory
6153
+ );
6154
+ const soundfiles = {
6155
+ ...effectFactory == null ? void 0 : effectFactory.soundfiles,
6156
+ ...voiceFactory.soundfiles
6157
+ };
6158
+ this.fDSPCode = new FaustPolyWebAudioDsp3(
6159
+ instance,
6160
+ sampleRate,
6161
+ sampleSize,
6162
+ 128,
6163
+ soundfiles
6164
+ );
6110
6165
  this.port.addEventListener("message", this.handleMessageAux);
6111
6166
  this.port.start();
6112
- this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
6167
+ this.fDSPCode.setOutputParamHandler(
6168
+ (path, value) => this.port.postMessage({ path, value, type: "param" })
6169
+ );
6113
6170
  this.fDSPCode.start();
6114
6171
  }
6115
6172
  midiMessage(data) {
@@ -6117,7 +6174,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6117
6174
  const channel = data[0] & 15;
6118
6175
  const data1 = data[1];
6119
6176
  const data2 = data[2];
6120
- if (cmd === 8 || cmd === 9 && data2 === 0) this.keyOff(channel, data1, data2);
6177
+ if (cmd === 8 || cmd === 9 && data2 === 0)
6178
+ this.keyOff(channel, data1, data2);
6121
6179
  else if (cmd === 9) this.keyOn(channel, data1, data2);
6122
6180
  else super.midiMessage(data);
6123
6181
  }
@@ -6135,7 +6193,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6135
6193
  const Processor = poly ? FaustPolyAudioWorkletProcessor : FaustMonoAudioWorkletProcessor;
6136
6194
  if (register) {
6137
6195
  try {
6138
- registerProcessor(processorName || dspName || (poly ? "mydsp_poly" : "mydsp"), Processor);
6196
+ registerProcessor(
6197
+ processorName || dspName || (poly ? "mydsp_poly" : "mydsp"),
6198
+ Processor
6199
+ );
6139
6200
  } catch (error) {
6140
6201
  console.warn(error);
6141
6202
  }
@@ -6154,19 +6215,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6154
6215
  FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
6155
6216
  FFTUtils
6156
6217
  } = dependencies;
6157
- const {
6158
- processorName,
6159
- dspName,
6160
- dspMeta,
6161
- fftOptions
6162
- } = faustData;
6163
- const {
6164
- windowFunctions,
6165
- getFFT,
6166
- fftToSignal,
6167
- signalToFFT,
6168
- signalToNoFFT
6169
- } = FFTUtils;
6218
+ const { processorName, dspName, dspMeta, fftOptions } = faustData;
6219
+ const { windowFunctions, getFFT, fftToSignal, signalToFFT, signalToNoFFT } = FFTUtils;
6170
6220
  const ceil = (x, to) => Math.abs(to) < 1 ? Math.ceil(x * (1 / to)) / (1 / to) : Math.ceil(x / to) * to;
6171
6221
  const mod = (x, y) => (x % y + y) % y;
6172
6222
  const apply = (array, windowFunction) => {
@@ -6174,7 +6224,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6174
6224
  array[i] *= windowFunction(i, array.length);
6175
6225
  }
6176
6226
  };
6177
- const fftParamKeywords = ["/fftSize", "/fftHopSize", "/fftOverlap", "/windowFunction", "/noIFFT"];
6227
+ const fftParamKeywords = [
6228
+ "/fftSize",
6229
+ "/fftHopSize",
6230
+ "/fftOverlap",
6231
+ "/windowFunction",
6232
+ "/noIFFT"
6233
+ ];
6178
6234
  const setTypedArray = (to, from, offsetTo = 0, offsetFrom = 0) => {
6179
6235
  const toLength = to.length;
6180
6236
  const fromLength = from.length;
@@ -6183,7 +6239,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6183
6239
  let $to = mod(offsetTo, toLength) || 0;
6184
6240
  let $from = mod(offsetFrom, fromLength) || 0;
6185
6241
  while (spilled < spillLength) {
6186
- const $spillLength = Math.min(spillLength - spilled, toLength - $to, fromLength - $from);
6242
+ const $spillLength = Math.min(
6243
+ spillLength - spilled,
6244
+ toLength - $to,
6245
+ fromLength - $from
6246
+ );
6187
6247
  const $fromEnd = $from + $spillLength;
6188
6248
  if ($from === 0 && $fromEnd === fromLength) to.set(from, $to);
6189
6249
  else to.set(from.subarray($from, $fromEnd), $to);
@@ -6197,9 +6257,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6197
6257
  const isFFTReserved = "address" in item && !!fftParamKeywords.find((k) => item.address.endsWith(k));
6198
6258
  if (isFFTReserved) return null;
6199
6259
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
6200
- return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
6260
+ return {
6261
+ name: item.address,
6262
+ defaultValue: item.init || 0,
6263
+ minValue: item.min || 0,
6264
+ maxValue: item.max || 0
6265
+ };
6201
6266
  } else if (item.type === "button" || item.type === "checkbox") {
6202
- return { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
6267
+ return {
6268
+ name: item.address,
6269
+ defaultValue: item.init || 0,
6270
+ minValue: 0,
6271
+ maxValue: 1
6272
+ };
6203
6273
  }
6204
6274
  return null;
6205
6275
  };
@@ -6286,7 +6356,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6286
6356
  };
6287
6357
  this.port.addEventListener("message", this.handleMessageAux);
6288
6358
  this.port.start();
6289
- this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
6359
+ this.communicator = new FaustAudioWorkletProcessorCommunicator2(
6360
+ this.port
6361
+ );
6290
6362
  const { parameterDescriptors } = this.constructor;
6291
6363
  parameterDescriptors.forEach((pd) => {
6292
6364
  this.paramValuesCache[pd.name] = pd.defaultValue || 0;
@@ -6348,35 +6420,55 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6348
6420
  if (!this.wamInfo) return;
6349
6421
  const { moduleId, instanceId } = this.wamInfo;
6350
6422
  const { webAudioModules } = globalThis;
6351
- const ModuleScope = webAudioModules.getModuleScope(moduleId);
6423
+ const ModuleScope = webAudioModules.getModuleScope(
6424
+ moduleId
6425
+ );
6352
6426
  const paramMgrProcessor = (_a = ModuleScope == null ? void 0 : ModuleScope.paramMgrProcessors) == null ? void 0 : _a[instanceId];
6353
6427
  if (!paramMgrProcessor) return;
6354
6428
  if (paramMgrProcessor.handleEvent) return;
6355
6429
  paramMgrProcessor.handleEvent = (event) => {
6356
- if (event.type === "wam-midi") this.midiMessage(event.data.bytes);
6430
+ if (event.type === "wam-midi")
6431
+ this.midiMessage(event.data.bytes);
6357
6432
  };
6358
6433
  }
6359
6434
  processFFT() {
6360
6435
  let samplesForFFT = mod(this.$inputWrite - this.$inputRead, this.fftBufferSize) || this.fftBufferSize;
6361
6436
  while (samplesForFFT >= this.fftSize) {
6362
6437
  let fftProcessorOutputs = [];
6363
- this.fDSPCode.compute((inputs) => {
6364
- for (let i = 0; i < Math.min(this.fftInput.length, Math.ceil(inputs.length / 3)); i++) {
6365
- const ffted = this.rfft.forward((fftBuffer) => {
6366
- setTypedArray(fftBuffer, this.fftInput[i], 0, this.$inputRead);
6367
- for (let j = 0; j < fftBuffer.length; j++) {
6368
- fftBuffer[j] *= this.window[j];
6369
- }
6370
- });
6371
- fftToSignal(ffted, inputs[i * 3], inputs[i * 3 + 1], inputs[i * 3 + 2]);
6372
- }
6373
- for (let i = this.fftInput.length * 3; i < inputs.length; i++) {
6374
- if (i % 3 === 2) inputs[i].forEach((v, j) => inputs[i][j] = j);
6375
- else inputs[i].fill(0);
6376
- }
6377
- }, (outputs) => {
6378
- fftProcessorOutputs = outputs;
6379
- });
6438
+ this.fDSPCode.compute(
6439
+ (inputs) => {
6440
+ for (let i = 0; i < Math.min(
6441
+ this.fftInput.length,
6442
+ Math.ceil(inputs.length / 3)
6443
+ ); i++) {
6444
+ const ffted = this.rfft.forward((fftBuffer) => {
6445
+ setTypedArray(
6446
+ fftBuffer,
6447
+ this.fftInput[i],
6448
+ 0,
6449
+ this.$inputRead
6450
+ );
6451
+ for (let j = 0; j < fftBuffer.length; j++) {
6452
+ fftBuffer[j] *= this.window[j];
6453
+ }
6454
+ });
6455
+ fftToSignal(
6456
+ ffted,
6457
+ inputs[i * 3],
6458
+ inputs[i * 3 + 1],
6459
+ inputs[i * 3 + 2]
6460
+ );
6461
+ }
6462
+ for (let i = this.fftInput.length * 3; i < inputs.length; i++) {
6463
+ if (i % 3 === 2)
6464
+ inputs[i].forEach((v, j) => inputs[i][j] = j);
6465
+ else inputs[i].fill(0);
6466
+ }
6467
+ },
6468
+ (outputs) => {
6469
+ fftProcessorOutputs = outputs;
6470
+ }
6471
+ );
6380
6472
  this.$inputRead += this.fftHopSize;
6381
6473
  this.$inputRead %= this.fftBufferSize;
6382
6474
  samplesForFFT -= this.fftHopSize;
@@ -6384,10 +6476,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6384
6476
  let iffted;
6385
6477
  if (this.noIFFT) {
6386
6478
  iffted = this.noIFFTBuffer;
6387
- signalToNoFFT(fftProcessorOutputs[i * 2] || this.fftProcessorZeros, fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros, iffted);
6479
+ signalToNoFFT(
6480
+ fftProcessorOutputs[i * 2] || this.fftProcessorZeros,
6481
+ fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros,
6482
+ iffted
6483
+ );
6388
6484
  } else {
6389
6485
  iffted = this.rfft.inverse((ifftBuffer) => {
6390
- signalToFFT(fftProcessorOutputs[i * 2] || this.fftProcessorZeros, fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros, ifftBuffer);
6486
+ signalToFFT(
6487
+ fftProcessorOutputs[i * 2] || this.fftProcessorZeros,
6488
+ fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros,
6489
+ ifftBuffer
6490
+ );
6391
6491
  });
6392
6492
  }
6393
6493
  for (let j = 0; j < iffted.length; j++) {
@@ -6397,12 +6497,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6397
6497
  for (let j = 0; j < iffted.length - this.fftHopSize; j++) {
6398
6498
  $ = mod(this.$outputWrite + j, this.fftBufferSize);
6399
6499
  this.fftOutput[i][$] += iffted[j];
6400
- if (i === 0) this.windowSumSquare[$] += this.noIFFT ? this.window[j] : this.window[j] ** 2;
6500
+ if (i === 0)
6501
+ this.windowSumSquare[$] += this.noIFFT ? this.window[j] : this.window[j] ** 2;
6401
6502
  }
6402
6503
  for (let j = iffted.length - this.fftHopSize; j < iffted.length; j++) {
6403
6504
  $ = mod(this.$outputWrite + j, this.fftBufferSize);
6404
6505
  this.fftOutput[i][$] = iffted[j];
6405
- if (i === 0) this.windowSumSquare[$] = this.noIFFT ? this.window[j] : this.window[j] ** 2;
6506
+ if (i === 0)
6507
+ this.windowSumSquare[$] = this.noIFFT ? this.window[j] : this.window[j] ** 2;
6406
6508
  }
6407
6509
  }
6408
6510
  this.$outputWrite += this.fftHopSize;
@@ -6418,10 +6520,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6418
6520
  const outputChannels = (output == null ? void 0 : output.length) || 0;
6419
6521
  const bufferSize = (input == null ? void 0 : input.length) ? Math.max(...input.map((c) => c.length)) || 128 : 128;
6420
6522
  this.noIFFT = !!parameters.noIFFT[0];
6421
- this.resetFFT(~~parameters.fftSize[0], ~~parameters.fftOverlap[0], ~~parameters.windowFunction[0], inputChannels, outputChannels, bufferSize);
6523
+ this.resetFFT(
6524
+ ~~parameters.fftSize[0],
6525
+ ~~parameters.fftOverlap[0],
6526
+ ~~parameters.windowFunction[0],
6527
+ inputChannels,
6528
+ outputChannels,
6529
+ bufferSize
6530
+ );
6422
6531
  if (!this.fDSPCode) return true;
6423
6532
  for (const path in parameters) {
6424
- if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k))) continue;
6533
+ if (fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
6534
+ continue;
6425
6535
  const [paramValue] = parameters[path];
6426
6536
  if (paramValue !== this.paramValuesCache[path]) {
6427
6537
  this.setParamValue(path, paramValue);
@@ -6447,7 +6557,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6447
6557
  for (let i = 0; i < input.length; i++) {
6448
6558
  const inputWindow = this.fftInput[i];
6449
6559
  const channel = input[i].length ? input[i] : new Float32Array(bufferSize);
6450
- $inputWrite = setTypedArray(inputWindow, channel, this.$inputWrite);
6560
+ $inputWrite = setTypedArray(
6561
+ inputWindow,
6562
+ channel,
6563
+ this.$inputWrite
6564
+ );
6451
6565
  }
6452
6566
  this.$inputWrite = $inputWrite;
6453
6567
  } else {
@@ -6456,7 +6570,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6456
6570
  }
6457
6571
  this.processFFT();
6458
6572
  for (let i = 0; i < output.length; i++) {
6459
- setTypedArray(output[i], this.fftOutput[i], 0, this.$outputRead);
6573
+ setTypedArray(
6574
+ output[i],
6575
+ this.fftOutput[i],
6576
+ 0,
6577
+ this.$outputRead
6578
+ );
6460
6579
  let div = 0;
6461
6580
  for (let j = 0; j < bufferSize; j++) {
6462
6581
  div = this.windowSumSquare[mod(this.$outputRead + j, this.fftBufferSize)];
@@ -6466,7 +6585,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6466
6585
  this.$outputRead += bufferSize;
6467
6586
  this.$outputRead %= this.fftBufferSize;
6468
6587
  if (this.fPlotHandler) {
6469
- this.port.postMessage({ type: "plot", value: output, index: this.fBufferNum++, events: this.fCachedEvents });
6588
+ this.port.postMessage({
6589
+ type: "plot",
6590
+ value: output,
6591
+ index: this.fBufferNum++,
6592
+ events: this.fCachedEvents
6593
+ });
6470
6594
  this.fCachedEvents = [];
6471
6595
  }
6472
6596
  return true;
@@ -6514,8 +6638,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6514
6638
  this.$inputRead = 0;
6515
6639
  this.$outputWrite = 0;
6516
6640
  this.$outputRead = -latency;
6517
- this.fftBufferSize = Math.max(fftSize * 2 - this.fftHopSize, bufferSize * 2);
6518
- if (!fftSizeChanged && this.fftHopSizeParam) (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(this.fftHopSizeParam, this.fftHopSize);
6641
+ this.fftBufferSize = Math.max(
6642
+ fftSize * 2 - this.fftHopSize,
6643
+ bufferSize * 2
6644
+ );
6645
+ if (!fftSizeChanged && this.fftHopSizeParam)
6646
+ (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(
6647
+ this.fftHopSizeParam,
6648
+ this.fftHopSize
6649
+ );
6519
6650
  }
6520
6651
  if (fftSizeChanged) {
6521
6652
  (_b = this.rfft) == null ? void 0 : _b.dispose();
@@ -6551,7 +6682,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6551
6682
  }
6552
6683
  if (this.fftOutput.length < outputChannels) {
6553
6684
  for (let i = this.fftOutput.length; i < outputChannels; i++) {
6554
- this.fftOutput[i] = new Float32Array(this.fftBufferSize);
6685
+ this.fftOutput[i] = new Float32Array(
6686
+ this.fftBufferSize
6687
+ );
6555
6688
  }
6556
6689
  }
6557
6690
  }
@@ -6560,20 +6693,38 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6560
6693
  var _a, _b;
6561
6694
  (_a = this.fDSPCode) == null ? void 0 : _a.stop();
6562
6695
  (_b = this.fDSPCode) == null ? void 0 : _b.destroy();
6563
- this.fDSPCode = new FaustMonoWebAudioDsp2(this.dspInstance, sampleRate, this.sampleSize, this.fftProcessorBufferSize, this.soundfiles);
6564
- this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
6696
+ this.fDSPCode = new FaustMonoWebAudioDsp2(
6697
+ this.dspInstance,
6698
+ sampleRate,
6699
+ this.sampleSize,
6700
+ this.fftProcessorBufferSize,
6701
+ this.soundfiles
6702
+ );
6703
+ this.fDSPCode.setOutputParamHandler(
6704
+ (path, value) => this.port.postMessage({ path, value, type: "param" })
6705
+ );
6565
6706
  this.fDSPCode.setPlotHandler(this.fPlotHandler);
6566
6707
  const params = this.fDSPCode.getParams();
6567
6708
  this.fDSPCode.start();
6568
6709
  for (const path in this.paramValuesCache) {
6569
- if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k))) continue;
6710
+ if (fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
6711
+ continue;
6570
6712
  this.fDSPCode.setParamValue(path, this.paramValuesCache[path]);
6571
6713
  }
6572
6714
  const fftSizeParam = params.find((s) => s.endsWith("/fftSize"));
6573
- if (fftSizeParam) this.fDSPCode.setParamValue(fftSizeParam, this.fftSize);
6574
- this.fftHopSizeParam = params.find((s) => s.endsWith("/fftHopSize"));
6575
- if (this.fftHopSizeParam) this.fDSPCode.setParamValue(this.fftHopSizeParam, this.fftHopSize);
6576
- this.fftProcessorZeros = new Float32Array(this.fftProcessorBufferSize);
6715
+ if (fftSizeParam)
6716
+ this.fDSPCode.setParamValue(fftSizeParam, this.fftSize);
6717
+ this.fftHopSizeParam = params.find(
6718
+ (s) => s.endsWith("/fftHopSize")
6719
+ );
6720
+ if (this.fftHopSizeParam)
6721
+ this.fDSPCode.setParamValue(
6722
+ this.fftHopSizeParam,
6723
+ this.fftHopSize
6724
+ );
6725
+ this.fftProcessorZeros = new Float32Array(
6726
+ this.fftProcessorBufferSize
6727
+ );
6577
6728
  }
6578
6729
  destroy() {
6579
6730
  var _a, _b, _c;
@@ -6586,7 +6737,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6586
6737
  const Processor = FaustFFTAudioWorkletProcessor;
6587
6738
  if (register) {
6588
6739
  try {
6589
- registerProcessor(processorName || dspName || "myfftdsp", Processor);
6740
+ registerProcessor(
6741
+ processorName || dspName || "myfftdsp",
6742
+ Processor
6743
+ );
6590
6744
  } catch (error) {
6591
6745
  console.warn(error);
6592
6746
  }
@@ -6995,7 +7149,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6995
7149
  const table = {};
6996
7150
  this.gFactories.forEach((factory, shaKey) => {
6997
7151
  const { code, json, poly } = factory;
6998
- table[shaKey] = { code: btoa(ab2str(code)), json: JSON.parse(json), poly };
7152
+ table[shaKey] = {
7153
+ code: btoa(ab2str(code)),
7154
+ json: JSON.parse(json),
7155
+ poly
7156
+ };
6999
7157
  });
7000
7158
  return table;
7001
7159
  }
@@ -7014,7 +7172,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7014
7172
  const factory = table[shaKey];
7015
7173
  const { code, json, poly } = factory;
7016
7174
  const ab = str2ab(atob(code));
7017
- awaited.push(WebAssembly.compile(ab).then((module) => this.gFactories.set(shaKey, { shaKey, cfactory: 0, code: ab, module, json: JSON.stringify(json), poly, soundfiles: {} })));
7175
+ awaited.push(
7176
+ WebAssembly.compile(ab).then(
7177
+ (module) => this.gFactories.set(shaKey, {
7178
+ shaKey,
7179
+ cfactory: 0,
7180
+ code: ab,
7181
+ module,
7182
+ json: JSON.stringify(json),
7183
+ poly,
7184
+ soundfiles: {}
7185
+ })
7186
+ )
7187
+ );
7018
7188
  }
7019
7189
  return Promise.all(awaited);
7020
7190
  }
@@ -7041,16 +7211,31 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7041
7211
  if (_FaustCompiler.gFactories.size > 10) {
7042
7212
  _FaustCompiler.gFactories.clear();
7043
7213
  }
7044
- let shaKey = await sha256(name + code + args + (poly ? "poly" : "mono"));
7214
+ const shaKey = await sha256(
7215
+ name + code + args + (poly ? "poly" : "mono")
7216
+ );
7045
7217
  if (_FaustCompiler.gFactories.has(shaKey)) {
7046
7218
  return _FaustCompiler.gFactories.get(shaKey) || null;
7047
7219
  } else {
7048
7220
  try {
7049
- const faustDspWasm = this.fLibFaust.createDSPFactory(name, code, args, !poly);
7221
+ const faustDspWasm = this.fLibFaust.createDSPFactory(
7222
+ name,
7223
+ code,
7224
+ args,
7225
+ !poly
7226
+ );
7050
7227
  const ui8Code = this.intVec2intArray(faustDspWasm.data);
7051
7228
  faustDspWasm.data.delete();
7052
7229
  const module = await WebAssembly.compile(ui8Code);
7053
- const factory = { shaKey, cfactory: faustDspWasm.cfactory, code: ui8Code, module, json: faustDspWasm.json, poly, soundfiles: {} };
7230
+ const factory = {
7231
+ shaKey,
7232
+ cfactory: faustDspWasm.cfactory,
7233
+ code: ui8Code,
7234
+ module,
7235
+ json: faustDspWasm.json,
7236
+ poly,
7237
+ soundfiles: {}
7238
+ };
7054
7239
  this.deleteDSPFactory(factory);
7055
7240
  _FaustCompiler.gFactories.set(shaKey, factory);
7056
7241
  return factory;
@@ -7104,18 +7289,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7104
7289
  async getAsyncInternalMixerModule(isDouble = false) {
7105
7290
  const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
7106
7291
  const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
7107
- if (this[moduleKey]) return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
7292
+ if (this[moduleKey])
7293
+ return {
7294
+ mixerBuffer: this[bufferKey],
7295
+ mixerModule: this[moduleKey]
7296
+ };
7108
7297
  const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
7109
7298
  const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
7110
7299
  this[bufferKey] = mixerBuffer;
7111
- const mixerModule = await WebAssembly.compile(new Uint8Array(mixerBuffer));
7300
+ const mixerModule = await WebAssembly.compile(
7301
+ new Uint8Array(mixerBuffer)
7302
+ );
7112
7303
  this[moduleKey] = mixerModule;
7113
7304
  return { mixerBuffer, mixerModule };
7114
7305
  }
7115
7306
  getSyncInternalMixerModule(isDouble = false) {
7116
7307
  const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
7117
7308
  const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
7118
- if (this[moduleKey]) return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
7309
+ if (this[moduleKey])
7310
+ return {
7311
+ mixerBuffer: this[bufferKey],
7312
+ mixerModule: this[moduleKey]
7313
+ };
7119
7314
  const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
7120
7315
  const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
7121
7316
  this[bufferKey] = mixerBuffer;
@@ -7252,7 +7447,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7252
7447
  };
7253
7448
  const effectSize = effectMeta ? effectMeta.size : 0;
7254
7449
  let memorySize = pow2limit(
7255
- effectSize + dspMeta.size * voices + (dspMeta.inputs + dspMeta.outputs * 2) * (ptrSize + bufferSize * sampleSize)
7450
+ effectSize + dspMeta.size * voices + (dspMeta.inputs + dspMeta.outputs * 2) * // + 2 for effect
7451
+ (ptrSize + bufferSize * sampleSize)
7256
7452
  ) / 65536;
7257
7453
  memorySize = Math.max(2, memorySize);
7258
7454
  return new WebAssembly.Memory({ initial: memorySize });
@@ -7277,14 +7473,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7277
7473
  const voiceMeta = JSON.parse(voiceFactory.json);
7278
7474
  const effectMeta = effectFactory && effectFactory.json ? JSON.parse(effectFactory.json) : null;
7279
7475
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
7280
- return this.createWasmMemoryPoly(voices, sampleSize, voiceMeta, effectMeta, 8192);
7476
+ return this.createWasmMemoryPoly(
7477
+ voices,
7478
+ sampleSize,
7479
+ voiceMeta,
7480
+ effectMeta,
7481
+ 8192
7482
+ );
7281
7483
  }
7282
7484
  static createMixerAux(mixerModule, memory) {
7283
7485
  const mixerImport = {
7284
7486
  imports: { print: console.log },
7285
7487
  memory: { memory }
7286
7488
  };
7287
- const mixerInstance = new WebAssembly.Instance(mixerModule, mixerImport);
7489
+ const mixerInstance = new WebAssembly.Instance(
7490
+ mixerModule,
7491
+ mixerImport
7492
+ );
7288
7493
  const mixerFunctions = mixerInstance.exports;
7289
7494
  return mixerFunctions;
7290
7495
  }
@@ -7292,7 +7497,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7292
7497
  static async loadDSPFactory(wasmPath, jsonPath) {
7293
7498
  const wasmFile = await fetch(wasmPath);
7294
7499
  if (!wasmFile.ok) {
7295
- throw new Error(`=> exception raised while running loadDSPFactory, file not found: ${wasmPath}`);
7500
+ throw new Error(
7501
+ `=> exception raised while running loadDSPFactory, file not found: ${wasmPath}`
7502
+ );
7296
7503
  }
7297
7504
  try {
7298
7505
  const wasmBuffer = await wasmFile.arrayBuffer();
@@ -7302,7 +7509,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7302
7509
  const meta = JSON.parse(json);
7303
7510
  const cOptions = meta.compile_options;
7304
7511
  const poly = cOptions.indexOf("wasm-e") !== -1;
7305
- return { cfactory: 0, code: new Uint8Array(wasmBuffer), module, json, poly };
7512
+ return {
7513
+ cfactory: 0,
7514
+ code: new Uint8Array(wasmBuffer),
7515
+ module,
7516
+ json,
7517
+ poly
7518
+ };
7306
7519
  } catch (e) {
7307
7520
  throw e;
7308
7521
  }
@@ -7311,7 +7524,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7311
7524
  try {
7312
7525
  let mixerBuffer = null;
7313
7526
  if (fs) {
7314
- mixerBuffer = new Uint8Array(fs.readFile(mixerPath, { encoding: "binary" }));
7527
+ mixerBuffer = new Uint8Array(
7528
+ fs.readFile(mixerPath, { encoding: "binary" })
7529
+ );
7315
7530
  } else {
7316
7531
  const mixerFile = await fetch(mixerPath);
7317
7532
  mixerBuffer = await mixerFile.arrayBuffer();
@@ -7326,10 +7541,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7326
7541
  const isDetected = pattern.test(factory.json);
7327
7542
  if (isDetected) {
7328
7543
  const memory = this.createMemoryMono(factory);
7329
- const instance = await WebAssembly.instantiate(factory.module, this.createWasmImport(memory));
7330
- return this.createMonoDSPInstanceAux(instance, factory.json, memory);
7544
+ const instance = await WebAssembly.instantiate(
7545
+ factory.module,
7546
+ this.createWasmImport(memory)
7547
+ );
7548
+ return this.createMonoDSPInstanceAux(
7549
+ instance,
7550
+ factory.json,
7551
+ memory
7552
+ );
7331
7553
  } else {
7332
- const instance = await WebAssembly.instantiate(factory.module, this.createWasmImport());
7554
+ const instance = await WebAssembly.instantiate(
7555
+ factory.module,
7556
+ this.createWasmImport()
7557
+ );
7333
7558
  return this.createMonoDSPInstanceAux(instance, factory.json);
7334
7559
  }
7335
7560
  }
@@ -7338,21 +7563,41 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7338
7563
  const isDetected = pattern.test(factory.json);
7339
7564
  if (isDetected) {
7340
7565
  const memory = this.createMemoryMono(factory);
7341
- const instance = new WebAssembly.Instance(factory.module, this.createWasmImport(memory));
7342
- return this.createMonoDSPInstanceAux(instance, factory.json, memory);
7566
+ const instance = new WebAssembly.Instance(
7567
+ factory.module,
7568
+ this.createWasmImport(memory)
7569
+ );
7570
+ return this.createMonoDSPInstanceAux(
7571
+ instance,
7572
+ factory.json,
7573
+ memory
7574
+ );
7343
7575
  } else {
7344
- const instance = new WebAssembly.Instance(factory.module, this.createWasmImport());
7576
+ const instance = new WebAssembly.Instance(
7577
+ factory.module,
7578
+ this.createWasmImport()
7579
+ );
7345
7580
  return this.createMonoDSPInstanceAux(instance, factory.json);
7346
7581
  }
7347
7582
  }
7348
7583
  static async createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory) {
7349
- const memory = this.createMemoryPoly(voices, voiceFactory, effectFactory);
7350
- const voiceInstance = await WebAssembly.instantiate(voiceFactory.module, this.createWasmImport(memory));
7584
+ const memory = this.createMemoryPoly(
7585
+ voices,
7586
+ voiceFactory,
7587
+ effectFactory
7588
+ );
7589
+ const voiceInstance = await WebAssembly.instantiate(
7590
+ voiceFactory.module,
7591
+ this.createWasmImport(memory)
7592
+ );
7351
7593
  const voiceFunctions = voiceInstance.exports;
7352
7594
  const voiceAPI = new FaustDspInstance(voiceFunctions);
7353
7595
  const mixerAPI = this.createMixerAux(mixerModule, memory);
7354
7596
  if (effectFactory) {
7355
- const effectInstance = await WebAssembly.instantiate(effectFactory.module, this.createWasmImport(memory));
7597
+ const effectInstance = await WebAssembly.instantiate(
7598
+ effectFactory.module,
7599
+ this.createWasmImport(memory)
7600
+ );
7356
7601
  const effectFunctions = effectInstance.exports;
7357
7602
  const effectAPI = new FaustDspInstance(effectFunctions);
7358
7603
  return {
@@ -7375,13 +7620,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7375
7620
  }
7376
7621
  }
7377
7622
  static createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory) {
7378
- const memory = this.createMemoryPoly(voices, voiceFactory, effectFactory);
7379
- const voiceInstance = new WebAssembly.Instance(voiceFactory.module, this.createWasmImport(memory));
7623
+ const memory = this.createMemoryPoly(
7624
+ voices,
7625
+ voiceFactory,
7626
+ effectFactory
7627
+ );
7628
+ const voiceInstance = new WebAssembly.Instance(
7629
+ voiceFactory.module,
7630
+ this.createWasmImport(memory)
7631
+ );
7380
7632
  const voiceFunctions = voiceInstance.exports;
7381
7633
  const voiceAPI = new FaustDspInstance(voiceFunctions);
7382
7634
  const mixerAPI = this.createMixerAux(mixerModule, memory);
7383
7635
  if (effectFactory) {
7384
- const effectInstance = new WebAssembly.Instance(effectFactory.module, this.createWasmImport(memory));
7636
+ const effectInstance = new WebAssembly.Instance(
7637
+ effectFactory.module,
7638
+ this.createWasmImport(memory)
7639
+ );
7385
7640
  const effectFunctions = effectInstance.exports;
7386
7641
  const effectAPI = new FaustDspInstance(effectFunctions);
7387
7642
  return {
@@ -7410,7 +7665,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7410
7665
  var FaustSensors = class _FaustSensors {
7411
7666
  /**
7412
7667
  * Function to convert a number to an axis type
7413
- *
7668
+ *
7414
7669
  * @param value number
7415
7670
  * @returns axis type
7416
7671
  */
@@ -7429,7 +7684,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7429
7684
  }
7430
7685
  /**
7431
7686
  * Function to convert a number to a curve type
7432
- *
7687
+ *
7433
7688
  * @param value number
7434
7689
  * @returns curve type
7435
7690
  */
@@ -7481,7 +7736,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7481
7736
  }
7482
7737
  }
7483
7738
  returnMappedValue(v) {
7484
- var x = this.fRange.clip(v);
7739
+ const x = this.fRange.clip(v);
7485
7740
  return this.fOffset + x * this.fCoef;
7486
7741
  }
7487
7742
  getLowHigh(amin, amax) {
@@ -7498,17 +7753,37 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7498
7753
  if (!this._Interpolator3pt) {
7499
7754
  this._Interpolator3pt = class {
7500
7755
  constructor(lo, mid, hi, v1, vMid, v2) {
7501
- this.fSegment1 = new _FaustSensors.Interpolator(lo, mid, v1, vMid);
7502
- this.fSegment2 = new _FaustSensors.Interpolator(mid, hi, vMid, v2);
7756
+ this.fSegment1 = new _FaustSensors.Interpolator(
7757
+ lo,
7758
+ mid,
7759
+ v1,
7760
+ vMid
7761
+ );
7762
+ this.fSegment2 = new _FaustSensors.Interpolator(
7763
+ mid,
7764
+ hi,
7765
+ vMid,
7766
+ v2
7767
+ );
7503
7768
  this.fMid = mid;
7504
7769
  }
7505
7770
  returnMappedValue(x) {
7506
7771
  return x < this.fMid ? this.fSegment1.returnMappedValue(x) : this.fSegment2.returnMappedValue(x);
7507
7772
  }
7508
7773
  getMappingValues(amin, amid, amax) {
7509
- var lowHighSegment1 = this.fSegment1.getLowHigh(amin, amid);
7510
- var lowHighSegment2 = this.fSegment2.getLowHigh(amid, amax);
7511
- return { amin: lowHighSegment1.amin, amid: lowHighSegment2.amin, amax: lowHighSegment2.amax };
7774
+ const lowHighSegment1 = this.fSegment1.getLowHigh(
7775
+ amin,
7776
+ amid
7777
+ );
7778
+ const lowHighSegment2 = this.fSegment2.getLowHigh(
7779
+ amid,
7780
+ amax
7781
+ );
7782
+ return {
7783
+ amin: lowHighSegment1.amin,
7784
+ amid: lowHighSegment2.amin,
7785
+ amax: lowHighSegment2.amax
7786
+ };
7512
7787
  }
7513
7788
  };
7514
7789
  }
@@ -7522,8 +7797,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7522
7797
  this._UpConverter = class {
7523
7798
  constructor(amin, amid, amax, fmin, fmid, fmax) {
7524
7799
  this.fActive = true;
7525
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmin, fmid, fmax);
7526
- this.fF2A = new _FaustSensors.Interpolator3pt(fmin, fmid, fmax, amin, amid, amax);
7800
+ this.fA2F = new _FaustSensors.Interpolator3pt(
7801
+ amin,
7802
+ amid,
7803
+ amax,
7804
+ fmin,
7805
+ fmid,
7806
+ fmax
7807
+ );
7808
+ this.fF2A = new _FaustSensors.Interpolator3pt(
7809
+ fmin,
7810
+ fmid,
7811
+ fmax,
7812
+ amin,
7813
+ amid,
7814
+ amax
7815
+ );
7527
7816
  }
7528
7817
  uiToFaust(x) {
7529
7818
  return this.fA2F.returnMappedValue(x);
@@ -7532,8 +7821,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7532
7821
  return this.fF2A.returnMappedValue(x);
7533
7822
  }
7534
7823
  setMappingValues(amin, amid, amax, min, init, max) {
7535
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, min, init, max);
7536
- this.fF2A = new _FaustSensors.Interpolator3pt(min, init, max, amin, amid, amax);
7824
+ this.fA2F = new _FaustSensors.Interpolator3pt(
7825
+ amin,
7826
+ amid,
7827
+ amax,
7828
+ min,
7829
+ init,
7830
+ max
7831
+ );
7832
+ this.fF2A = new _FaustSensors.Interpolator3pt(
7833
+ min,
7834
+ init,
7835
+ max,
7836
+ amin,
7837
+ amid,
7838
+ amax
7839
+ );
7537
7840
  }
7538
7841
  getMappingValues(amin, amid, amax) {
7539
7842
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -7556,8 +7859,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7556
7859
  this._DownConverter = class {
7557
7860
  constructor(amin, amid, amax, fmin, fmid, fmax) {
7558
7861
  this.fActive = true;
7559
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmax, fmid, fmin);
7560
- this.fF2A = new _FaustSensors.Interpolator3pt(fmin, fmid, fmax, amax, amid, amin);
7862
+ this.fA2F = new _FaustSensors.Interpolator3pt(
7863
+ amin,
7864
+ amid,
7865
+ amax,
7866
+ fmax,
7867
+ fmid,
7868
+ fmin
7869
+ );
7870
+ this.fF2A = new _FaustSensors.Interpolator3pt(
7871
+ fmin,
7872
+ fmid,
7873
+ fmax,
7874
+ amax,
7875
+ amid,
7876
+ amin
7877
+ );
7561
7878
  }
7562
7879
  uiToFaust(x) {
7563
7880
  return this.fA2F.returnMappedValue(x);
@@ -7566,8 +7883,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7566
7883
  return this.fF2A.returnMappedValue(x);
7567
7884
  }
7568
7885
  setMappingValues(amin, amid, amax, min, init, max) {
7569
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, max, init, min);
7570
- this.fF2A = new _FaustSensors.Interpolator3pt(min, init, max, amax, amid, amin);
7886
+ this.fA2F = new _FaustSensors.Interpolator3pt(
7887
+ amin,
7888
+ amid,
7889
+ amax,
7890
+ max,
7891
+ init,
7892
+ min
7893
+ );
7894
+ this.fF2A = new _FaustSensors.Interpolator3pt(
7895
+ min,
7896
+ init,
7897
+ max,
7898
+ amax,
7899
+ amid,
7900
+ amin
7901
+ );
7571
7902
  }
7572
7903
  getMappingValues(amin, amid, amax) {
7573
7904
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -7590,8 +7921,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7590
7921
  this._UpDownConverter = class {
7591
7922
  constructor(amin, amid, amax, fmin, fmid, fmax) {
7592
7923
  this.fActive = true;
7593
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmin, fmax, fmin);
7594
- this.fF2A = new _FaustSensors.Interpolator(fmin, fmax, amin, amax);
7924
+ this.fA2F = new _FaustSensors.Interpolator3pt(
7925
+ amin,
7926
+ amid,
7927
+ amax,
7928
+ fmin,
7929
+ fmax,
7930
+ fmin
7931
+ );
7932
+ this.fF2A = new _FaustSensors.Interpolator(
7933
+ fmin,
7934
+ fmax,
7935
+ amin,
7936
+ amax
7937
+ );
7595
7938
  }
7596
7939
  uiToFaust(x) {
7597
7940
  return this.fA2F.returnMappedValue(x);
@@ -7600,8 +7943,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7600
7943
  return this.fF2A.returnMappedValue(x);
7601
7944
  }
7602
7945
  setMappingValues(amin, amid, amax, min, init, max) {
7603
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, min, max, min);
7604
- this.fF2A = new _FaustSensors.Interpolator(min, max, amin, amax);
7946
+ this.fA2F = new _FaustSensors.Interpolator3pt(
7947
+ amin,
7948
+ amid,
7949
+ amax,
7950
+ min,
7951
+ max,
7952
+ min
7953
+ );
7954
+ this.fF2A = new _FaustSensors.Interpolator(
7955
+ min,
7956
+ max,
7957
+ amin,
7958
+ amax
7959
+ );
7605
7960
  }
7606
7961
  getMappingValues(amin, amid, amax) {
7607
7962
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -7621,8 +7976,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7621
7976
  this._DownUpConverter = class {
7622
7977
  constructor(amin, amid, amax, fmin, fmid, fmax) {
7623
7978
  this.fActive = true;
7624
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, fmax, fmin, fmax);
7625
- this.fF2A = new _FaustSensors.Interpolator(fmin, fmax, amin, amax);
7979
+ this.fA2F = new _FaustSensors.Interpolator3pt(
7980
+ amin,
7981
+ amid,
7982
+ amax,
7983
+ fmax,
7984
+ fmin,
7985
+ fmax
7986
+ );
7987
+ this.fF2A = new _FaustSensors.Interpolator(
7988
+ fmin,
7989
+ fmax,
7990
+ amin,
7991
+ amax
7992
+ );
7626
7993
  }
7627
7994
  uiToFaust(x) {
7628
7995
  return this.fA2F.returnMappedValue(x);
@@ -7631,8 +7998,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7631
7998
  return this.fF2A.returnMappedValue(x);
7632
7999
  }
7633
8000
  setMappingValues(amin, amid, amax, min, init, max) {
7634
- this.fA2F = new _FaustSensors.Interpolator3pt(amin, amid, amax, max, min, max);
7635
- this.fF2A = new _FaustSensors.Interpolator(min, max, amin, amax);
8001
+ this.fA2F = new _FaustSensors.Interpolator3pt(
8002
+ amin,
8003
+ amid,
8004
+ amax,
8005
+ max,
8006
+ min,
8007
+ max
8008
+ );
8009
+ this.fF2A = new _FaustSensors.Interpolator(
8010
+ min,
8011
+ max,
8012
+ amin,
8013
+ amax
8014
+ );
7636
8015
  }
7637
8016
  getMappingValues(amin, amid, amax) {
7638
8017
  return this.fA2F.getMappingValues(amin, amid, amax);
@@ -7655,15 +8034,50 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7655
8034
  static buildHandler(curve, amin, amid, amax, min, init, max) {
7656
8035
  switch (curve) {
7657
8036
  case 0 /* Up */:
7658
- return new _FaustSensors.UpConverter(amin, amid, amax, min, init, max);
8037
+ return new _FaustSensors.UpConverter(
8038
+ amin,
8039
+ amid,
8040
+ amax,
8041
+ min,
8042
+ init,
8043
+ max
8044
+ );
7659
8045
  case 1 /* Down */:
7660
- return new _FaustSensors.DownConverter(amin, amid, amax, min, init, max);
8046
+ return new _FaustSensors.DownConverter(
8047
+ amin,
8048
+ amid,
8049
+ amax,
8050
+ min,
8051
+ init,
8052
+ max
8053
+ );
7661
8054
  case 2 /* UpDown */:
7662
- return new _FaustSensors.UpDownConverter(amin, amid, amax, min, init, max);
8055
+ return new _FaustSensors.UpDownConverter(
8056
+ amin,
8057
+ amid,
8058
+ amax,
8059
+ min,
8060
+ init,
8061
+ max
8062
+ );
7663
8063
  case 3 /* DownUp */:
7664
- return new _FaustSensors.DownUpConverter(amin, amid, amax, min, init, max);
8064
+ return new _FaustSensors.DownUpConverter(
8065
+ amin,
8066
+ amid,
8067
+ amax,
8068
+ min,
8069
+ init,
8070
+ max
8071
+ );
7665
8072
  default:
7666
- return new _FaustSensors.UpConverter(amin, amid, amax, min, init, max);
8073
+ return new _FaustSensors.UpConverter(
8074
+ amin,
8075
+ amid,
8076
+ amax,
8077
+ min,
8078
+ init,
8079
+ max
8080
+ );
7667
8081
  }
7668
8082
  }
7669
8083
  };
@@ -7678,7 +8092,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7678
8092
  * Allocates a block of memory of the specified size, returning the pointer to the
7679
8093
  * beginning of the block. The block is allocated at the current offset and the
7680
8094
  * offset is incremented by the size of the block.
7681
- *
8095
+ *
7682
8096
  * @param sizeInBytes The size of the block to allocate in bytes.
7683
8097
  * @returns The offset (pointer) to the beginning of the allocated block.
7684
8098
  */
@@ -7687,7 +8101,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7687
8101
  const newOffset = currentOffset + sizeInBytes;
7688
8102
  const totalMemoryBytes = this.memory.buffer.byteLength;
7689
8103
  if (newOffset > totalMemoryBytes) {
7690
- const neededPages = Math.ceil((newOffset - totalMemoryBytes) / 65536);
8104
+ const neededPages = Math.ceil(
8105
+ (newOffset - totalMemoryBytes) / 65536
8106
+ );
7691
8107
  console.log(`GROW: ${neededPages} pages`);
7692
8108
  this.memory.grow(neededPages);
7693
8109
  }
@@ -7696,7 +8112,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7696
8112
  }
7697
8113
  /**
7698
8114
  * Returns the underlying buffer object.
7699
- *
8115
+ *
7700
8116
  * @returns The buffer object.
7701
8117
  */
7702
8118
  getBuffer() {
@@ -7704,7 +8120,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7704
8120
  }
7705
8121
  /**
7706
8122
  * Returns the Int32 view of the underlying buffer object.
7707
- *
8123
+ *
7708
8124
  * @returns The view of the memory buffer as Int32Array.
7709
8125
  */
7710
8126
  getInt32Array() {
@@ -7712,7 +8128,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7712
8128
  }
7713
8129
  /**
7714
8130
  * Returns the Int64 view of the underlying buffer object.
7715
- *
8131
+ *
7716
8132
  * @returns The view of the memory buffer as BigInt64Array.
7717
8133
  */
7718
8134
  getInt64Array() {
@@ -7720,7 +8136,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7720
8136
  }
7721
8137
  /**
7722
8138
  * Returns the Float32 view of the underlying buffer object.
7723
- *
8139
+ *
7724
8140
  * @returns The view of the memory buffer as Float32Array.
7725
8141
  */
7726
8142
  getFloat32Array() {
@@ -7728,7 +8144,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7728
8144
  }
7729
8145
  /**
7730
8146
  * Returns the Float64 view of the underlying buffer object..
7731
- *
8147
+ *
7732
8148
  * @returns The view of the memory buffer as Float64Array.
7733
8149
  */
7734
8150
  getFloat64Array() {
@@ -7757,11 +8173,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7757
8173
  this.fIntSize = this.fSampleSize;
7758
8174
  this.fPtrSize = 4;
7759
8175
  this.fAllocator = allocator;
7760
- console.log(`Soundfile constructor: curChan: ${curChan}, length: ${length}, maxChan: ${maxChan}, totalParts: ${totalParts}`);
8176
+ console.log(
8177
+ `Soundfile constructor: curChan: ${curChan}, length: ${length}, maxChan: ${maxChan}, totalParts: ${totalParts}`
8178
+ );
7761
8179
  this.fPtr = allocator.alloc(4 * this.fPtrSize);
7762
- this.fLength = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
7763
- this.fSR = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
7764
- this.fOffset = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
8180
+ this.fLength = allocator.alloc(
8181
+ _Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize
8182
+ );
8183
+ this.fSR = allocator.alloc(
8184
+ _Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize
8185
+ );
8186
+ this.fOffset = allocator.alloc(
8187
+ _Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize
8188
+ );
7765
8189
  this.fBuffers = this.allocBuffers(curChan, length, maxChan);
7766
8190
  const HEAP32 = this.fAllocator.getInt32Array();
7767
8191
  HEAP32[this.fPtr >> 2] = this.fBuffers;
@@ -7777,7 +8201,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7777
8201
  const buffers = this.fAllocator.alloc(maxChan * this.fPtrSize);
7778
8202
  console.log(`allocBuffers buffers: ${buffers}`);
7779
8203
  for (let chan = 0; chan < curChan; chan++) {
7780
- const buffer = this.fAllocator.alloc(length * this.fSampleSize);
8204
+ const buffer = this.fAllocator.alloc(
8205
+ length * this.fSampleSize
8206
+ );
7781
8207
  const HEAP32 = this.fAllocator.getInt32Array();
7782
8208
  HEAP32[(buffers >> 2) + chan] = buffer;
7783
8209
  }
@@ -7797,11 +8223,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7797
8223
  HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
7798
8224
  } else {
7799
8225
  const HEAP64 = this.fAllocator.getInt64Array();
7800
- HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(audioData.audioBuffer[0].length);
7801
- HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(audioData.sampleRate);
8226
+ HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(
8227
+ audioData.audioBuffer[0].length
8228
+ );
8229
+ HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(
8230
+ audioData.sampleRate
8231
+ );
7802
8232
  HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
7803
8233
  }
7804
- console.log(`copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${audioData}`);
8234
+ console.log(
8235
+ `copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${audioData}`
8236
+ );
7805
8237
  if (this.fSampleSize === 8) {
7806
8238
  this.copyToOutReal64(maxChannels, offset, audioData);
7807
8239
  } else {
@@ -7816,7 +8248,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7816
8248
  const output = HEAP32[(this.fBuffers >> 2) + chan];
7817
8249
  const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
7818
8250
  const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
7819
- console.log(`copyToOutReal32 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
8251
+ console.log(
8252
+ `copyToOutReal32 begin: ${begin}, end: ${end}, delta: ${end - begin}`
8253
+ );
7820
8254
  const outputReal = HEAPF.subarray(
7821
8255
  output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
7822
8256
  output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
@@ -7834,7 +8268,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7834
8268
  const output = HEAP32[(this.fBuffers >> 2) + chan];
7835
8269
  const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
7836
8270
  const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
7837
- console.log(`copyToOutReal64 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
8271
+ console.log(
8272
+ `copyToOutReal64 begin: ${begin}, end: ${end}, delta: ${end - begin}`
8273
+ );
7838
8274
  const outputReal = HEAPF.subarray(
7839
8275
  output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
7840
8276
  output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
@@ -7852,8 +8288,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7852
8288
  HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
7853
8289
  } else {
7854
8290
  const HEAP64 = this.fAllocator.getInt64Array();
7855
- HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(_Soundfile.BUFFER_SIZE);
7856
- HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(_Soundfile.SAMPLE_RATE);
8291
+ HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(
8292
+ _Soundfile.BUFFER_SIZE
8293
+ );
8294
+ HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(
8295
+ _Soundfile.SAMPLE_RATE
8296
+ );
7857
8297
  HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
7858
8298
  }
7859
8299
  return offset + _Soundfile.BUFFER_SIZE;
@@ -7868,9 +8308,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7868
8308
  const HEAP32 = this.fAllocator.getInt32Array();
7869
8309
  if (mem) console.log(`HEAP32: ${HEAP32}`);
7870
8310
  console.log(`HEAP32[this.fPtr >> 2]: ${HEAP32[this.fPtr >> 2]}`);
7871
- console.log(`HEAP32[(this.fPtr + ptrSize) >> 2]: ${HEAP32[this.fPtr + this.fPtrSize >> 2]}`);
7872
- console.log(`HEAP32[(this.fPtr + 2 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 2 * this.fPtrSize >> 2]}`);
7873
- console.log(`HEAP32[(this.fPtr + 3 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 3 * this.fPtrSize >> 2]}`);
8311
+ console.log(
8312
+ `HEAP32[(this.fPtr + ptrSize) >> 2]: ${HEAP32[this.fPtr + this.fPtrSize >> 2]}`
8313
+ );
8314
+ console.log(
8315
+ `HEAP32[(this.fPtr + 2 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 2 * this.fPtrSize >> 2]}`
8316
+ );
8317
+ console.log(
8318
+ `HEAP32[(this.fPtr + 3 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 3 * this.fPtrSize >> 2]}`
8319
+ );
7874
8320
  }
7875
8321
  // Return the pointer to the soundfile structure in wasm memory
7876
8322
  getPtr() {
@@ -7929,46 +8375,112 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
7929
8375
  if (strMidi === "pitchwheel") {
7930
8376
  const matched = strMidi.match(/^pitchwheel\s(\d+)/);
7931
8377
  if (matched) {
7932
- this.fPitchwheelLabel.push({ path: item.address, chan: parseInt(matched[1]), min: item.min, max: item.max });
8378
+ this.fPitchwheelLabel.push({
8379
+ path: item.address,
8380
+ chan: parseInt(matched[1]),
8381
+ min: item.min,
8382
+ max: item.max
8383
+ });
7933
8384
  } else {
7934
- this.fPitchwheelLabel.push({ path: item.address, chan: 0, min: item.min, max: item.max });
8385
+ this.fPitchwheelLabel.push({
8386
+ path: item.address,
8387
+ chan: 0,
8388
+ min: item.min,
8389
+ max: item.max
8390
+ });
7935
8391
  }
7936
8392
  } else {
7937
8393
  const matched2 = strMidi.match(/^ctrl\s(\d+)\s(\d+)/);
7938
8394
  const matched1 = strMidi.match(/^ctrl\s(\d+)/);
7939
- const matchedKey = strMidi.match(/^key\s+(\d+)(?:\s+(\d+))?$/);
7940
- const matchedKeyOn = strMidi.match(/^keyon\s+(\d+)(?:\s+(\d+))?$/);
7941
- const matchedKeyOff = strMidi.match(/^keyoff\s+(\d+)(?:\s+(\d+))?$/);
8395
+ const matchedKey = strMidi.match(
8396
+ /^key\s+(\d+)(?:\s+(\d+))?$/
8397
+ );
8398
+ const matchedKeyOn = strMidi.match(
8399
+ /^keyon\s+(\d+)(?:\s+(\d+))?$/
8400
+ );
8401
+ const matchedKeyOff = strMidi.match(
8402
+ /^keyoff\s+(\d+)(?:\s+(\d+))?$/
8403
+ );
7942
8404
  if (matched2) {
7943
- this.fCtrlLabel[parseInt(matched2[1])].push({ path: item.address, chan: parseInt(matched2[2]), min: item.min, max: item.max });
8405
+ this.fCtrlLabel[parseInt(matched2[1])].push({
8406
+ path: item.address,
8407
+ chan: parseInt(matched2[2]),
8408
+ min: item.min,
8409
+ max: item.max
8410
+ });
7944
8411
  } else if (matched1) {
7945
- this.fCtrlLabel[parseInt(matched1[1])].push({ path: item.address, chan: 0, min: item.min, max: item.max });
8412
+ this.fCtrlLabel[parseInt(matched1[1])].push({
8413
+ path: item.address,
8414
+ chan: 0,
8415
+ min: item.min,
8416
+ max: item.max
8417
+ });
7946
8418
  } else if (matchedKey) {
7947
8419
  const note = parseInt(matchedKey[1]);
7948
8420
  const channel = matchedKey[2] ? parseInt(matchedKey[2]) : 0;
7949
- this.fMidiKeyLabel[note].push({ path: item.address, chan: channel, min: (_a = item.min) != null ? _a : 0, max: (_b = item.max) != null ? _b : 1 });
8421
+ this.fMidiKeyLabel[note].push({
8422
+ path: item.address,
8423
+ chan: channel,
8424
+ min: (_a = item.min) != null ? _a : 0,
8425
+ max: (_b = item.max) != null ? _b : 1
8426
+ });
7950
8427
  } else if (matchedKeyOn) {
7951
8428
  const note = parseInt(matchedKeyOn[1]);
7952
8429
  const channel = matchedKeyOn[2] ? parseInt(matchedKeyOn[2]) : 0;
7953
- this.fMidiKeyOnLabel[note].push({ path: item.address, chan: channel, min: (_c = item.min) != null ? _c : 0, max: (_d = item.max) != null ? _d : 1 });
8430
+ this.fMidiKeyOnLabel[note].push({
8431
+ path: item.address,
8432
+ chan: channel,
8433
+ min: (_c = item.min) != null ? _c : 0,
8434
+ max: (_d = item.max) != null ? _d : 1
8435
+ });
7954
8436
  } else if (matchedKeyOff) {
7955
8437
  const note = parseInt(matchedKeyOff[1]);
7956
8438
  const channel = matchedKeyOff[2] ? parseInt(matchedKeyOff[2]) : 0;
7957
- this.fMidiKeyOffLabel[note].push({ path: item.address, chan: channel, min: (_e = item.min) != null ? _e : 0, max: (_f = item.max) != null ? _f : 1 });
8439
+ this.fMidiKeyOffLabel[note].push({
8440
+ path: item.address,
8441
+ chan: channel,
8442
+ min: (_e = item.min) != null ? _e : 0,
8443
+ max: (_f = item.max) != null ? _f : 1
8444
+ });
7958
8445
  }
7959
8446
  }
7960
8447
  }
7961
8448
  if (acc) {
7962
8449
  const numAcc = acc.trim().split(" ").map(Number);
7963
- this.setupAccHandler(item.address, FaustSensors.convertToAxis(numAcc[0]), FaustSensors.convertToCurve(numAcc[1]), numAcc[2], numAcc[3], numAcc[4], item.min, item.init, item.max);
8450
+ this.setupAccHandler(
8451
+ item.address,
8452
+ FaustSensors.convertToAxis(numAcc[0]),
8453
+ FaustSensors.convertToCurve(numAcc[1]),
8454
+ numAcc[2],
8455
+ numAcc[3],
8456
+ numAcc[4],
8457
+ item.min,
8458
+ item.init,
8459
+ item.max
8460
+ );
7964
8461
  }
7965
8462
  if (gyr) {
7966
8463
  const numAcc = gyr.trim().split(" ").map(Number);
7967
- this.setupGyrHandler(item.address, FaustSensors.convertToAxis(numAcc[0]), FaustSensors.convertToCurve(numAcc[1]), numAcc[2], numAcc[3], numAcc[4], item.min, item.init, item.max);
8464
+ this.setupGyrHandler(
8465
+ item.address,
8466
+ FaustSensors.convertToAxis(numAcc[0]),
8467
+ FaustSensors.convertToCurve(numAcc[1]),
8468
+ numAcc[2],
8469
+ numAcc[3],
8470
+ numAcc[4],
8471
+ item.min,
8472
+ item.init,
8473
+ item.max
8474
+ );
7968
8475
  }
7969
8476
  });
7970
8477
  } else if (item.type === "soundfile") {
7971
- this.fSoundfiles.push({ name: item.label, url: item.url, index: item.index, basePtr: -1 });
8478
+ this.fSoundfiles.push({
8479
+ name: item.label,
8480
+ url: item.url,
8481
+ index: item.index,
8482
+ basePtr: -1
8483
+ });
7972
8484
  }
7973
8485
  };
7974
8486
  // Audio callback
@@ -8007,8 +8519,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8007
8519
  }
8008
8520
  /** Split the soundfile names and return an array of names */
8009
8521
  static splitSoundfileNames(input) {
8010
- let trimmed = input.replace(/^\{|\}$/g, "");
8011
- return trimmed.split(";").map((str) => str.length <= 2 ? "" : str.substring(1, str.length - 1));
8522
+ const trimmed = input.replace(/^\{|\}$/g, "");
8523
+ return trimmed.split(";").map(
8524
+ (str) => str.length <= 2 ? "" : str.substring(1, str.length - 1)
8525
+ );
8012
8526
  }
8013
8527
  get hasAccInput() {
8014
8528
  return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
@@ -8036,36 +8550,66 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8036
8550
  }
8037
8551
  /** Build the accelerometer handler */
8038
8552
  setupAccHandler(path, axis, curve, amin, amid, amax, min, init, max) {
8039
- const handler = FaustSensors.buildHandler(curve, amin, amid, amax, min, init, max);
8553
+ const handler = FaustSensors.buildHandler(
8554
+ curve,
8555
+ amin,
8556
+ amid,
8557
+ amax,
8558
+ min,
8559
+ init,
8560
+ max
8561
+ );
8040
8562
  switch (axis) {
8041
8563
  case 0 /* x */:
8042
- this.fAcc.x.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
8564
+ this.fAcc.x.push(
8565
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
8566
+ );
8043
8567
  break;
8044
8568
  case 1 /* y */:
8045
- this.fAcc.y.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
8569
+ this.fAcc.y.push(
8570
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
8571
+ );
8046
8572
  break;
8047
8573
  case 2 /* z */:
8048
- this.fAcc.z.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
8574
+ this.fAcc.z.push(
8575
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
8576
+ );
8049
8577
  break;
8050
8578
  }
8051
8579
  }
8052
8580
  /** Build the gyroscope handler */
8053
8581
  setupGyrHandler(path, axis, curve, amin, amid, amax, min, init, max) {
8054
- const handler = FaustSensors.buildHandler(curve, amin, amid, amax, min, init, max);
8582
+ const handler = FaustSensors.buildHandler(
8583
+ curve,
8584
+ amin,
8585
+ amid,
8586
+ amax,
8587
+ min,
8588
+ init,
8589
+ max
8590
+ );
8055
8591
  switch (axis) {
8056
8592
  case 0 /* x */:
8057
- this.fGyr.x.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
8593
+ this.fGyr.x.push(
8594
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
8595
+ );
8058
8596
  break;
8059
8597
  case 1 /* y */:
8060
- this.fGyr.y.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
8598
+ this.fGyr.y.push(
8599
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
8600
+ );
8061
8601
  break;
8062
8602
  case 2 /* z */:
8063
- this.fGyr.z.push((val) => this.setParamValue(path, handler.uiToFaust(val)));
8603
+ this.fGyr.z.push(
8604
+ (val) => this.setParamValue(path, handler.uiToFaust(val))
8605
+ );
8064
8606
  break;
8065
8607
  }
8066
8608
  }
8067
8609
  static extractUrlsFromMeta(dspMeta) {
8068
- const soundfilesEntry = dspMeta.meta.find((entry) => entry.soundfiles !== void 0);
8610
+ const soundfilesEntry = dspMeta.meta.find(
8611
+ (entry) => entry.soundfiles !== void 0
8612
+ );
8069
8613
  if (soundfilesEntry) {
8070
8614
  return soundfilesEntry.soundfiles.split(";").filter((url) => url !== "");
8071
8615
  } else {
@@ -8075,9 +8619,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8075
8619
  /**
8076
8620
  * Load a soundfile possibly containing several parts in the DSP struct.
8077
8621
  * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
8078
- * The DSP struct is located at baseDSP in the wasm memory,
8622
+ * The DSP struct is located at baseDSP in the wasm memory,
8079
8623
  * either a monophonic DSP, or a voice in a polyphonic context.
8080
- *
8624
+ *
8081
8625
  * @param allocator : the wasm memory allocator
8082
8626
  * @param baseDSP : the base DSP in the wasm memory
8083
8627
  * @param name : the name of the soundfile
@@ -8090,17 +8634,27 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8090
8634
  if (!item) throw new Error(`Soundfile with ${url} cannot be found !}`);
8091
8635
  if (item.basePtr !== -1) {
8092
8636
  const HEAP32 = allocator.getInt32Array();
8093
- console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
8637
+ console.log(
8638
+ `Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`
8639
+ );
8094
8640
  HEAP32[baseDSP + item.index >> 2] = item.basePtr;
8095
8641
  } else {
8096
- const soundfile = this.createSoundfile(allocator, soundfileIds, this.fSoundfileBuffers);
8642
+ const soundfile = this.createSoundfile(
8643
+ allocator,
8644
+ soundfileIds,
8645
+ this.fSoundfileBuffers
8646
+ );
8097
8647
  if (soundfile) {
8098
8648
  const HEAP32 = soundfile.getHEAP32();
8099
8649
  item.basePtr = soundfile.getPtr();
8100
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
8650
+ console.log(
8651
+ `Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`
8652
+ );
8101
8653
  HEAP32[baseDSP + item.index >> 2] = item.basePtr;
8102
8654
  } else {
8103
- console.log(`Soundfile ${name} for ${url} cannot be created !}`);
8655
+ console.log(
8656
+ `Soundfile ${name} for ${url} cannot be created !}`
8657
+ );
8104
8658
  }
8105
8659
  }
8106
8660
  }
@@ -8122,7 +8676,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8122
8676
  totalLength += len;
8123
8677
  }
8124
8678
  totalLength += (Soundfile.MAX_SOUNDFILE_PARTS - soundfileIdList.length) * Soundfile.BUFFER_SIZE;
8125
- const soundfile = new Soundfile(allocator, this.fSampleSize, curChan, totalLength, maxChan, soundfileIdList.length);
8679
+ const soundfile = new Soundfile(
8680
+ allocator,
8681
+ this.fSampleSize,
8682
+ curChan,
8683
+ totalLength,
8684
+ maxChan,
8685
+ soundfileIdList.length
8686
+ );
8126
8687
  let offset = 0;
8127
8688
  for (let part = 0; part < soundfileIdList.length; part++) {
8128
8689
  const soundfileId = soundfileIdList[part];
@@ -8140,31 +8701,34 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8140
8701
  soundfile.shareBuffers(curChan, maxChan);
8141
8702
  return soundfile;
8142
8703
  }
8143
- /**
8704
+ /**
8144
8705
  * Init soundfiles memory.
8145
- *
8706
+ *
8146
8707
  * @param allocator : the wasm memory allocator
8147
8708
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
8148
- */
8709
+ */
8149
8710
  initSoundfileMemory(allocator, baseDSP) {
8150
8711
  for (const { name, url } of this.fSoundfiles) {
8151
8712
  this.loadSoundfile(allocator, baseDSP, name, url);
8152
8713
  }
8153
- ;
8154
8714
  }
8155
8715
  updateOutputs() {
8156
8716
  if (this.fOutputsItems.length > 0 && this.fOutputHandler && this.fOutputsTimer-- === 0) {
8157
8717
  this.fOutputsTimer = 5;
8158
- this.fOutputsItems.forEach((item) => {
8159
- var _a;
8160
- return (_a = this.fOutputHandler) == null ? void 0 : _a.call(this, item, this.getParamValue(item));
8161
- });
8718
+ this.fOutputsItems.forEach(
8719
+ (item) => {
8720
+ var _a;
8721
+ return (_a = this.fOutputHandler) == null ? void 0 : _a.call(this, item, this.getParamValue(item));
8722
+ }
8723
+ );
8162
8724
  }
8163
8725
  }
8164
8726
  // Public API
8165
8727
  metadata(handler) {
8166
8728
  if (this.fJSONDsp.meta) {
8167
- this.fJSONDsp.meta.forEach((meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]]));
8729
+ this.fJSONDsp.meta.forEach(
8730
+ (meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]])
8731
+ );
8168
8732
  }
8169
8733
  }
8170
8734
  compute(input, output) {
@@ -8210,68 +8774,127 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8210
8774
  if (cmd === 11) return this.ctrlChange(channel, data1, data2);
8211
8775
  if (cmd === 14) return this.pitchWheel(channel, data2 * 128 + data1);
8212
8776
  if (cmd === 9) {
8213
- if (data2 > 0)
8214
- return this.keyOn(channel, data1, data2);
8215
- else
8216
- return this.keyOff(channel, data1, data2);
8777
+ if (data2 > 0) return this.keyOn(channel, data1, data2);
8778
+ else return this.keyOff(channel, data1, data2);
8217
8779
  }
8218
8780
  if (cmd === 8) {
8219
8781
  return this.keyOff(channel, data1, data2);
8220
8782
  }
8221
8783
  }
8222
8784
  ctrlChange(channel, ctrl, value) {
8223
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "ctrlChange", data: [channel, ctrl, value] });
8785
+ if (this.fPlotHandler)
8786
+ this.fCachedEvents.push({
8787
+ type: "ctrlChange",
8788
+ data: [channel, ctrl, value]
8789
+ });
8224
8790
  if (this.fCtrlLabel[ctrl].length) {
8225
8791
  this.fCtrlLabel[ctrl].forEach((ctrl2) => {
8226
8792
  const { path, chan } = ctrl2;
8227
8793
  if (chan === 0 || channel === chan - 1) {
8228
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
8229
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
8794
+ this.setParamValue(
8795
+ path,
8796
+ _FaustBaseWebAudioDsp.remap(
8797
+ value,
8798
+ 0,
8799
+ 127,
8800
+ ctrl2.min,
8801
+ ctrl2.max
8802
+ )
8803
+ );
8804
+ if (this.fOutputHandler)
8805
+ this.fOutputHandler(path, this.getParamValue(path));
8230
8806
  }
8231
8807
  });
8232
8808
  }
8233
8809
  }
8234
8810
  keyOn(channel, pitch, velocity) {
8235
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
8811
+ if (this.fPlotHandler)
8812
+ this.fCachedEvents.push({
8813
+ type: "keyOn",
8814
+ data: [channel, pitch, velocity]
8815
+ });
8236
8816
  this.fMidiKeyOnLabel[pitch].forEach((key) => {
8237
8817
  const { path, chan } = key;
8238
8818
  if (chan === 0 || channel === chan - 1) {
8239
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8240
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
8819
+ this.setParamValue(
8820
+ path,
8821
+ _FaustBaseWebAudioDsp.remap(
8822
+ velocity,
8823
+ 0,
8824
+ 127,
8825
+ key.min,
8826
+ key.max
8827
+ )
8828
+ );
8829
+ if (this.fOutputHandler)
8830
+ this.fOutputHandler(path, this.getParamValue(path));
8241
8831
  }
8242
8832
  });
8243
8833
  this.fMidiKeyLabel[pitch].forEach((key) => {
8244
8834
  const { path, chan } = key;
8245
8835
  if (chan === 0 || channel === chan - 1) {
8246
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8247
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
8836
+ this.setParamValue(
8837
+ path,
8838
+ _FaustBaseWebAudioDsp.remap(
8839
+ velocity,
8840
+ 0,
8841
+ 127,
8842
+ key.min,
8843
+ key.max
8844
+ )
8845
+ );
8846
+ if (this.fOutputHandler)
8847
+ this.fOutputHandler(path, this.getParamValue(path));
8248
8848
  }
8249
8849
  });
8250
8850
  }
8251
8851
  keyOff(channel, pitch, velocity) {
8252
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
8852
+ if (this.fPlotHandler)
8853
+ this.fCachedEvents.push({
8854
+ type: "keyOff",
8855
+ data: [channel, pitch, velocity]
8856
+ });
8253
8857
  this.fMidiKeyOffLabel[pitch].forEach((key) => {
8254
8858
  const { path, chan } = key;
8255
8859
  if (chan === 0 || channel === chan - 1) {
8256
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8257
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
8860
+ this.setParamValue(
8861
+ path,
8862
+ _FaustBaseWebAudioDsp.remap(
8863
+ velocity,
8864
+ 0,
8865
+ 127,
8866
+ key.min,
8867
+ key.max
8868
+ )
8869
+ );
8870
+ if (this.fOutputHandler)
8871
+ this.fOutputHandler(path, this.getParamValue(path));
8258
8872
  }
8259
8873
  });
8260
8874
  this.fMidiKeyLabel[pitch].forEach((key) => {
8261
8875
  const { path, chan } = key;
8262
8876
  if (chan === 0 || channel === chan - 1) {
8263
8877
  this.setParamValue(path, 0);
8264
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
8878
+ if (this.fOutputHandler)
8879
+ this.fOutputHandler(path, this.getParamValue(path));
8265
8880
  }
8266
8881
  });
8267
8882
  }
8268
8883
  pitchWheel(channel, wheel) {
8269
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
8884
+ if (this.fPlotHandler)
8885
+ this.fCachedEvents.push({
8886
+ type: "pitchWheel",
8887
+ data: [channel, wheel]
8888
+ });
8270
8889
  this.fPitchwheelLabel.forEach((pw) => {
8271
8890
  const { path, chan } = pw;
8272
8891
  if (chan === 0 || channel === chan - 1) {
8273
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
8274
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
8892
+ this.setParamValue(
8893
+ path,
8894
+ _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max)
8895
+ );
8896
+ if (this.fOutputHandler)
8897
+ this.fOutputHandler(path, this.getParamValue(path));
8275
8898
  }
8276
8899
  });
8277
8900
  }
@@ -8327,7 +8950,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8327
8950
  this.fEndMemory = this.initMemory();
8328
8951
  this.fInstance.api.init(this.fDSP, sampleRate);
8329
8952
  if (this.fSoundfiles.length > 0) {
8330
- const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
8953
+ const allocator = new WasmAllocator(
8954
+ this.fInstance.memory,
8955
+ this.fEndMemory
8956
+ );
8331
8957
  this.initSoundfileMemory(allocator, this.fDSP);
8332
8958
  }
8333
8959
  }
@@ -8346,18 +8972,30 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8346
8972
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
8347
8973
  HEAP32[(this.fAudioInputs >> 2) + chan] = $audioInputs + this.fBufferSize * this.fSampleSize * chan;
8348
8974
  }
8349
- const dspInChans = HEAP32.subarray(this.fAudioInputs >> 2, this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2);
8975
+ const dspInChans = HEAP32.subarray(
8976
+ this.fAudioInputs >> 2,
8977
+ this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2
8978
+ );
8350
8979
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
8351
- this.fInChannels[chan] = HEAPF.subarray(dspInChans[chan] >> Math.log2(this.fSampleSize), dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
8980
+ this.fInChannels[chan] = HEAPF.subarray(
8981
+ dspInChans[chan] >> Math.log2(this.fSampleSize),
8982
+ dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
8983
+ );
8352
8984
  }
8353
8985
  }
8354
8986
  if (this.getNumOutputs() > 0) {
8355
8987
  for (let chan = 0; chan < this.getNumOutputs(); chan++) {
8356
8988
  HEAP32[(this.fAudioOutputs >> 2) + chan] = $audioOutputs + this.fBufferSize * this.fSampleSize * chan;
8357
8989
  }
8358
- const dspOutChans = HEAP32.subarray(this.fAudioOutputs >> 2, this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2);
8990
+ const dspOutChans = HEAP32.subarray(
8991
+ this.fAudioOutputs >> 2,
8992
+ this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2
8993
+ );
8359
8994
  for (let chan = 0; chan < this.getNumOutputs(); chan++) {
8360
- this.fOutChannels[chan] = HEAPF.subarray(dspOutChans[chan] >> Math.log2(this.fSampleSize), dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
8995
+ this.fOutChannels[chan] = HEAPF.subarray(
8996
+ dspOutChans[chan] >> Math.log2(this.fSampleSize),
8997
+ dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
8998
+ );
8361
8999
  }
8362
9000
  }
8363
9001
  return endMemory;
@@ -8395,7 +9033,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8395
9033
  }
8396
9034
  }
8397
9035
  if (this.fComputeHandler) this.fComputeHandler(this.fBufferSize);
8398
- this.fInstance.api.compute(this.fDSP, this.fBufferSize, this.fAudioInputs, this.fAudioOutputs);
9036
+ this.fInstance.api.compute(
9037
+ this.fDSP,
9038
+ this.fBufferSize,
9039
+ this.fAudioInputs,
9040
+ this.fAudioOutputs
9041
+ );
8399
9042
  this.updateOutputs();
8400
9043
  let forPlot = this.fOutChannels;
8401
9044
  if (typeof output === "function") {
@@ -8408,7 +9051,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8408
9051
  forPlot = output;
8409
9052
  }
8410
9053
  if (this.fPlotHandler) {
8411
- this.fPlotHandler(forPlot, this.fBufferNum++, this.fCachedEvents.length ? this.fCachedEvents : void 0);
9054
+ this.fPlotHandler(
9055
+ forPlot,
9056
+ this.fBufferNum++,
9057
+ this.fCachedEvents.length ? this.fCachedEvents : void 0
9058
+ );
8412
9059
  this.fCachedEvents = [];
8413
9060
  }
8414
9061
  return true;
@@ -8423,11 +9070,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8423
9070
  return this.fInstance.api.getNumOutputs(this.fDSP);
8424
9071
  }
8425
9072
  setParamValue(path, value) {
8426
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "param", data: { path, value } });
8427
- this.fInstance.api.setParamValue(this.fDSP, this.fPathTable[path], value);
9073
+ if (this.fPlotHandler)
9074
+ this.fCachedEvents.push({ type: "param", data: { path, value } });
9075
+ this.fInstance.api.setParamValue(
9076
+ this.fDSP,
9077
+ this.fPathTable[path],
9078
+ value
9079
+ );
8428
9080
  }
8429
9081
  getParamValue(path) {
8430
- return this.fInstance.api.getParamValue(this.fDSP, this.fPathTable[path]);
9082
+ return this.fInstance.api.getParamValue(
9083
+ this.fDSP,
9084
+ this.fPathTable[path]
9085
+ );
8431
9086
  }
8432
9087
  getMeta() {
8433
9088
  return this.fJSONDsp;
@@ -8508,16 +9163,36 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8508
9163
  this.fNextNote = pitch;
8509
9164
  this.fNextVel = velocity;
8510
9165
  } else {
8511
- this.fFreqLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, _FaustWebAudioDspVoice.midiToFreq(pitch)));
8512
- this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 1));
8513
- this.fGainLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, _FaustWebAudioDspVoice.normalizeVelocity(velocity)));
8514
- this.fKeyLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, pitch));
8515
- this.fVelLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, velocity));
9166
+ this.fFreqLabel.forEach(
9167
+ (index) => this.fAPI.setParamValue(
9168
+ this.fDSP,
9169
+ index,
9170
+ _FaustWebAudioDspVoice.midiToFreq(pitch)
9171
+ )
9172
+ );
9173
+ this.fGateLabel.forEach(
9174
+ (index) => this.fAPI.setParamValue(this.fDSP, index, 1)
9175
+ );
9176
+ this.fGainLabel.forEach(
9177
+ (index) => this.fAPI.setParamValue(
9178
+ this.fDSP,
9179
+ index,
9180
+ _FaustWebAudioDspVoice.normalizeVelocity(velocity)
9181
+ )
9182
+ );
9183
+ this.fKeyLabel.forEach(
9184
+ (index) => this.fAPI.setParamValue(this.fDSP, index, pitch)
9185
+ );
9186
+ this.fVelLabel.forEach(
9187
+ (index) => this.fAPI.setParamValue(this.fDSP, index, velocity)
9188
+ );
8516
9189
  this.fCurNote = pitch;
8517
9190
  }
8518
9191
  }
8519
9192
  keyOff(hard = false) {
8520
- this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 0));
9193
+ this.fGateLabel.forEach(
9194
+ (index) => this.fAPI.setParamValue(this.fDSP, index, 0)
9195
+ );
8521
9196
  if (hard) {
8522
9197
  this.fCurNote = _FaustWebAudioDspVoice.kFreeVoice;
8523
9198
  } else {
@@ -8525,8 +9200,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8525
9200
  }
8526
9201
  }
8527
9202
  computeLegato(bufferSize, $inputs, $outputZero, $outputsHalf) {
8528
- let size = bufferSize / 2;
8529
- this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 0));
9203
+ const size = bufferSize / 2;
9204
+ this.fGateLabel.forEach(
9205
+ (index) => this.fAPI.setParamValue(this.fDSP, index, 0)
9206
+ );
8530
9207
  this.fAPI.compute(this.fDSP, size, $inputs, $outputZero);
8531
9208
  this.keyOn(this.fNextNote, this.fNextVel);
8532
9209
  this.fAPI.compute(this.fDSP, size, $inputs, $outputsHalf);
@@ -8549,21 +9226,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8549
9226
  this.fJSONDsp = JSON.parse(this.fInstance.voiceJSON);
8550
9227
  this.fJSONEffect = this.fInstance.effectAPI && this.fInstance.effectJSON ? JSON.parse(this.fInstance.effectJSON) : null;
8551
9228
  FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
8552
- if (this.fJSONEffect) FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
9229
+ if (this.fJSONEffect)
9230
+ FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
8553
9231
  this.fEndMemory = this.initMemory();
8554
9232
  this.fVoiceTable = [];
8555
9233
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
8556
- this.fVoiceTable.push(new FaustWebAudioDspVoice(
8557
- this.fJSONDsp.size * voice,
8558
- this.fInstance.voiceAPI,
8559
- this.fInputsItems,
8560
- this.fPathTable,
8561
- sampleRate
8562
- ));
8563
- }
8564
- if (this.fInstance.effectAPI) this.fInstance.effectAPI.init(this.fEffect, sampleRate);
9234
+ this.fVoiceTable.push(
9235
+ new FaustWebAudioDspVoice(
9236
+ this.fJSONDsp.size * voice,
9237
+ this.fInstance.voiceAPI,
9238
+ this.fInputsItems,
9239
+ this.fPathTable,
9240
+ sampleRate
9241
+ )
9242
+ );
9243
+ }
9244
+ if (this.fInstance.effectAPI)
9245
+ this.fInstance.effectAPI.init(this.fEffect, sampleRate);
8565
9246
  if (this.fSoundfiles.length > 0) {
8566
- const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
9247
+ const allocator = new WasmAllocator(
9248
+ this.fInstance.memory,
9249
+ this.fEndMemory
9250
+ );
8567
9251
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
8568
9252
  this.initSoundfileMemory(allocator, this.fJSONDsp.size * voice);
8569
9253
  }
@@ -8587,9 +9271,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8587
9271
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
8588
9272
  HEAP32[(this.fAudioInputs >> 2) + chan] = $audioInputs + this.fBufferSize * this.fSampleSize * chan;
8589
9273
  }
8590
- const dspInChans = HEAP32.subarray(this.fAudioInputs >> 2, this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2);
9274
+ const dspInChans = HEAP32.subarray(
9275
+ this.fAudioInputs >> 2,
9276
+ this.fAudioInputs + this.getNumInputs() * this.fPtrSize >> 2
9277
+ );
8591
9278
  for (let chan = 0; chan < this.getNumInputs(); chan++) {
8592
- this.fInChannels[chan] = HEAPF.subarray(dspInChans[chan] >> Math.log2(this.fSampleSize), dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
9279
+ this.fInChannels[chan] = HEAPF.subarray(
9280
+ dspInChans[chan] >> Math.log2(this.fSampleSize),
9281
+ dspInChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
9282
+ );
8593
9283
  }
8594
9284
  }
8595
9285
  if (this.getNumOutputs() > 0) {
@@ -8598,9 +9288,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8598
9288
  HEAP32[(this.fAudioMixing >> 2) + chan] = $audioMixing + this.fBufferSize * this.fSampleSize * chan;
8599
9289
  HEAP32[(this.fAudioMixingHalf >> 2) + chan] = $audioMixing + this.fBufferSize * this.fSampleSize * chan + this.fBufferSize / 2 * this.fSampleSize;
8600
9290
  }
8601
- const dspOutChans = HEAP32.subarray(this.fAudioOutputs >> 2, this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2);
9291
+ const dspOutChans = HEAP32.subarray(
9292
+ this.fAudioOutputs >> 2,
9293
+ this.fAudioOutputs + this.getNumOutputs() * this.fPtrSize >> 2
9294
+ );
8602
9295
  for (let chan = 0; chan < this.getNumOutputs(); chan++) {
8603
- this.fOutChannels[chan] = HEAPF.subarray(dspOutChans[chan] >> Math.log2(this.fSampleSize), dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize));
9296
+ this.fOutChannels[chan] = HEAPF.subarray(
9297
+ dspOutChans[chan] >> Math.log2(this.fSampleSize),
9298
+ dspOutChans[chan] + this.fBufferSize * this.fSampleSize >> Math.log2(this.fSampleSize)
9299
+ );
8604
9300
  }
8605
9301
  }
8606
9302
  return endMemory;
@@ -8623,8 +9319,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8623
9319
  let voicePlaying = FaustWebAudioDspVoice.kNoVoice;
8624
9320
  let oldestDatePlaying = Number.MAX_VALUE;
8625
9321
  for (let i = 0; i < this.fInstance.voices; i++) {
8626
- let curNote = this.fVoiceTable[i].fCurNote;
8627
- let nextNote = this.fVoiceTable[i].fNextNote;
9322
+ const curNote = this.fVoiceTable[i].fCurNote;
9323
+ const nextNote = this.fVoiceTable[i].fNextNote;
8628
9324
  if (curNote === pitch || curNote === FaustWebAudioDspVoice.kLegatoVoice && nextNote === pitch) {
8629
9325
  if (this.fVoiceTable[i].fDate < oldestDatePlaying) {
8630
9326
  oldestDatePlaying = this.fVoiceTable[i].fDate;
@@ -8637,7 +9333,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8637
9333
  getFreeVoice() {
8638
9334
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
8639
9335
  if (this.fVoiceTable[voice].fCurNote === FaustWebAudioDspVoice.kFreeVoice) {
8640
- return this.allocVoice(voice, FaustWebAudioDspVoice.kActiveVoice);
9336
+ return this.allocVoice(
9337
+ voice,
9338
+ FaustWebAudioDspVoice.kActiveVoice
9339
+ );
8641
9340
  }
8642
9341
  }
8643
9342
  let voiceRelease = FaustWebAudioDspVoice.kNoVoice;
@@ -8656,12 +9355,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8656
9355
  }
8657
9356
  }
8658
9357
  if (oldestDateRelease !== Number.MAX_VALUE) {
8659
- console.log(`Steal release voice : voice_date = ${this.fVoiceTable[voiceRelease].fDate} voice = ${voiceRelease}`);
8660
- return this.allocVoice(voiceRelease, FaustWebAudioDspVoice.kLegatoVoice);
9358
+ console.log(
9359
+ `Steal release voice : voice_date = ${this.fVoiceTable[voiceRelease].fDate} voice = ${voiceRelease}`
9360
+ );
9361
+ return this.allocVoice(
9362
+ voiceRelease,
9363
+ FaustWebAudioDspVoice.kLegatoVoice
9364
+ );
8661
9365
  }
8662
9366
  if (oldestDatePlaying !== Number.MAX_VALUE) {
8663
- console.log(`Steal playing voice : voice_date = ${this.fVoiceTable[voicePlaying].fDate} voice = ${voicePlaying}`);
8664
- return this.allocVoice(voicePlaying, FaustWebAudioDspVoice.kLegatoVoice);
9367
+ console.log(
9368
+ `Steal playing voice : voice_date = ${this.fVoiceTable[voicePlaying].fDate} voice = ${voicePlaying}`
9369
+ );
9370
+ return this.allocVoice(
9371
+ voicePlaying,
9372
+ FaustWebAudioDspVoice.kLegatoVoice
9373
+ );
8665
9374
  }
8666
9375
  return FaustWebAudioDspVoice.kNoVoice;
8667
9376
  }
@@ -8686,21 +9395,54 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8686
9395
  }
8687
9396
  }
8688
9397
  if (this.fComputeHandler) this.fComputeHandler(this.fBufferSize);
8689
- this.fInstance.mixerAPI.clearOutput(this.fBufferSize, this.getNumOutputs(), this.fAudioOutputs);
9398
+ this.fInstance.mixerAPI.clearOutput(
9399
+ this.fBufferSize,
9400
+ this.getNumOutputs(),
9401
+ this.fAudioOutputs
9402
+ );
8690
9403
  this.fVoiceTable.forEach((voice) => {
8691
9404
  if (voice.fCurNote === FaustWebAudioDspVoice.kLegatoVoice) {
8692
- voice.computeLegato(this.fBufferSize, this.fAudioInputs, this.fAudioMixing, this.fAudioMixingHalf);
8693
- this.fInstance.mixerAPI.fadeOut(this.fBufferSize / 2, this.getNumOutputs(), this.fAudioMixing);
8694
- voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(this.fBufferSize, this.getNumOutputs(), this.fAudioMixing, this.fAudioOutputs);
9405
+ voice.computeLegato(
9406
+ this.fBufferSize,
9407
+ this.fAudioInputs,
9408
+ this.fAudioMixing,
9409
+ this.fAudioMixingHalf
9410
+ );
9411
+ this.fInstance.mixerAPI.fadeOut(
9412
+ this.fBufferSize / 2,
9413
+ this.getNumOutputs(),
9414
+ this.fAudioMixing
9415
+ );
9416
+ voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(
9417
+ this.fBufferSize,
9418
+ this.getNumOutputs(),
9419
+ this.fAudioMixing,
9420
+ this.fAudioOutputs
9421
+ );
8695
9422
  } else if (voice.fCurNote !== FaustWebAudioDspVoice.kFreeVoice) {
8696
- voice.compute(this.fBufferSize, this.fAudioInputs, this.fAudioMixing);
8697
- voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(this.fBufferSize, this.getNumOutputs(), this.fAudioMixing, this.fAudioOutputs);
9423
+ voice.compute(
9424
+ this.fBufferSize,
9425
+ this.fAudioInputs,
9426
+ this.fAudioMixing
9427
+ );
9428
+ voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(
9429
+ this.fBufferSize,
9430
+ this.getNumOutputs(),
9431
+ this.fAudioMixing,
9432
+ this.fAudioOutputs
9433
+ );
8698
9434
  if (voice.fCurNote == FaustWebAudioDspVoice.kReleaseVoice && voice.fLevel < FaustWebAudioDspVoice.VOICE_STOP_LEVEL) {
8699
9435
  voice.fCurNote = FaustWebAudioDspVoice.kFreeVoice;
8700
9436
  }
8701
9437
  }
8702
9438
  });
8703
- if (this.fInstance.effectAPI) this.fInstance.effectAPI.compute(this.fEffect, this.fBufferSize, this.fAudioOutputs, this.fAudioOutputs);
9439
+ if (this.fInstance.effectAPI)
9440
+ this.fInstance.effectAPI.compute(
9441
+ this.fEffect,
9442
+ this.fBufferSize,
9443
+ this.fAudioOutputs,
9444
+ this.fAudioOutputs
9445
+ );
8704
9446
  this.updateOutputs();
8705
9447
  if (output !== void 0) {
8706
9448
  for (let chan = 0; chan < Math.min(this.getNumOutputs(), output.length); chan++) {
@@ -8708,7 +9450,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8708
9450
  output[chan].set(dspOutput);
8709
9451
  }
8710
9452
  if (this.fPlotHandler) {
8711
- this.fPlotHandler(output, this.fBufferNum++, this.fCachedEvents.length ? this.fCachedEvents : void 0);
9453
+ this.fPlotHandler(
9454
+ output,
9455
+ this.fBufferNum++,
9456
+ this.fCachedEvents.length ? this.fCachedEvents : void 0
9457
+ );
8712
9458
  this.fCachedEvents = [];
8713
9459
  }
8714
9460
  }
@@ -8733,16 +9479,26 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8733
9479
  }
8734
9480
  }
8735
9481
  setParamValue(path, value) {
8736
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "param", data: { path, value } });
9482
+ if (this.fPlotHandler)
9483
+ this.fCachedEvents.push({ type: "param", data: { path, value } });
8737
9484
  if (this.fJSONEffect && _FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
8738
- this.fInstance.effectAPI.setParamValue(this.fEffect, this.fPathTable[path], value);
9485
+ this.fInstance.effectAPI.setParamValue(
9486
+ this.fEffect,
9487
+ this.fPathTable[path],
9488
+ value
9489
+ );
8739
9490
  } else {
8740
- this.fVoiceTable.forEach((voice) => voice.setParamValue(this.fPathTable[path], value));
9491
+ this.fVoiceTable.forEach(
9492
+ (voice) => voice.setParamValue(this.fPathTable[path], value)
9493
+ );
8741
9494
  }
8742
9495
  }
8743
9496
  getParamValue(path) {
8744
9497
  if (this.fJSONEffect && _FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
8745
- return this.fInstance.effectAPI.getParamValue(this.fEffect, this.fPathTable[path]);
9498
+ return this.fInstance.effectAPI.getParamValue(
9499
+ this.fEffect,
9500
+ this.fPathTable[path]
9501
+ );
8746
9502
  } else {
8747
9503
  return this.fVoiceTable[0].getParamValue(this.fPathTable[path]);
8748
9504
  }
@@ -8752,22 +9508,24 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8752
9508
  const e = this.fJSONEffect;
8753
9509
  const r = { ...o };
8754
9510
  if (e) {
8755
- r.ui = [{
8756
- type: "tgroup",
8757
- label: "Sequencer",
8758
- items: [
8759
- { type: "vgroup", label: "Instrument", items: o.ui },
8760
- { type: "vgroup", label: "Effect", items: e.ui }
8761
- ]
8762
- }];
9511
+ r.ui = [
9512
+ {
9513
+ type: "tgroup",
9514
+ label: "Sequencer",
9515
+ items: [
9516
+ { type: "vgroup", label: "Instrument", items: o.ui },
9517
+ { type: "vgroup", label: "Effect", items: e.ui }
9518
+ ]
9519
+ }
9520
+ ];
8763
9521
  } else {
8764
- r.ui = [{
8765
- type: "tgroup",
8766
- label: "Polyphonic",
8767
- items: [
8768
- { type: "vgroup", label: "Voices", items: o.ui }
8769
- ]
8770
- }];
9522
+ r.ui = [
9523
+ {
9524
+ type: "tgroup",
9525
+ label: "Polyphonic",
9526
+ items: [{ type: "vgroup", label: "Voices", items: o.ui }]
9527
+ }
9528
+ ];
8771
9529
  }
8772
9530
  return r;
8773
9531
  }
@@ -8785,7 +9543,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8785
9543
  const channel = data[0] & 15;
8786
9544
  const data1 = data[1];
8787
9545
  const data2 = data[2];
8788
- if (cmd === 8 || cmd === 9 && data2 === 0) return this.keyOff(channel, data1, data2);
9546
+ if (cmd === 8 || cmd === 9 && data2 === 0)
9547
+ return this.keyOff(channel, data1, data2);
8789
9548
  else if (cmd === 9) return this.keyOn(channel, data1, data2);
8790
9549
  else super.midiMessage(data);
8791
9550
  }
@@ -8797,12 +9556,24 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8797
9556
  }
8798
9557
  }
8799
9558
  keyOn(channel, pitch, velocity) {
8800
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
9559
+ if (this.fPlotHandler)
9560
+ this.fCachedEvents.push({
9561
+ type: "keyOn",
9562
+ data: [channel, pitch, velocity]
9563
+ });
8801
9564
  const voice = this.getFreeVoice();
8802
- this.fVoiceTable[voice].keyOn(pitch, velocity, this.fVoiceTable[voice].fCurNote == FaustWebAudioDspVoice.kLegatoVoice);
9565
+ this.fVoiceTable[voice].keyOn(
9566
+ pitch,
9567
+ velocity,
9568
+ this.fVoiceTable[voice].fCurNote == FaustWebAudioDspVoice.kLegatoVoice
9569
+ );
8803
9570
  }
8804
9571
  keyOff(channel, pitch, velocity) {
8805
- if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
9572
+ if (this.fPlotHandler)
9573
+ this.fCachedEvents.push({
9574
+ type: "keyOff",
9575
+ data: [channel, pitch, velocity]
9576
+ });
8806
9577
  const voice = this.getPlayingVoice(pitch);
8807
9578
  if (voice !== FaustWebAudioDspVoice.kNoVoice) {
8808
9579
  this.fVoiceTable[voice].keyOff();
@@ -8829,13 +9600,30 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8829
9600
  const params = [];
8830
9601
  const callback = (item) => {
8831
9602
  let param = null;
8832
- const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
9603
+ const polyKeywords = [
9604
+ "/gate",
9605
+ "/freq",
9606
+ "/gain",
9607
+ "/key",
9608
+ "/vel",
9609
+ "/velocity"
9610
+ ];
8833
9611
  const isPolyReserved = "address" in item && !!polyKeywords.find((k) => item.address.endsWith(k));
8834
9612
  if (this.fDSPCode instanceof FaustMonoWebAudioDsp || !isPolyReserved) {
8835
9613
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
8836
- param = { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
9614
+ param = {
9615
+ name: item.address,
9616
+ defaultValue: item.init || 0,
9617
+ minValue: item.min || 0,
9618
+ maxValue: item.max || 0
9619
+ };
8837
9620
  } else if (item.type === "button" || item.type === "checkbox") {
8838
- param = { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
9621
+ param = {
9622
+ name: item.address,
9623
+ defaultValue: item.init || 0,
9624
+ minValue: 0,
9625
+ maxValue: 1
9626
+ };
8839
9627
  }
8840
9628
  }
8841
9629
  if (param) params.push(param);
@@ -9008,11 +9796,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9008
9796
  files2.filter((file) => file !== "." && file !== "..").forEach((file) => fs.unlink(`/${name}-svg/${file}`));
9009
9797
  } catch {
9010
9798
  }
9011
- const success = this.compiler.generateAuxFiles(name, code, `-lang wasm -o binary -svg ${args}`);
9799
+ const success = this.compiler.generateAuxFiles(
9800
+ name,
9801
+ code,
9802
+ `-lang wasm -o binary -svg ${args}`
9803
+ );
9012
9804
  if (!success) throw new Error(this.compiler.getErrorMessage());
9013
9805
  const svgs = {};
9014
9806
  const files = fs.readdir(`/${name}-svg/`);
9015
- files.filter((file) => file !== "." && file !== "..").forEach((file) => svgs[file] = fs.readFile(`/${name}-svg/${file}`, { encoding: "utf8" }));
9807
+ files.filter((file) => file !== "." && file !== "..").forEach(
9808
+ (file) => svgs[file] = fs.readFile(`/${name}-svg/${file}`, {
9809
+ encoding: "utf8"
9810
+ })
9811
+ );
9016
9812
  return svgs;
9017
9813
  }
9018
9814
  };
@@ -9025,7 +9821,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9025
9821
  }
9026
9822
  compile(name, code, args) {
9027
9823
  const fs = this.fCompiler.fs();
9028
- const success = this.fCompiler.generateAuxFiles(name, code, `-lang cmajor-hybrid -cn ${name} -o ${name}.cmajor`);
9824
+ const success = this.fCompiler.generateAuxFiles(
9825
+ name,
9826
+ code,
9827
+ `-lang cmajor-hybrid -cn ${name} -o ${name}.cmajor`
9828
+ );
9029
9829
  return success ? fs.readFile(`${name}.cmajor`, { encoding: "utf8" }) : "";
9030
9830
  }
9031
9831
  };
@@ -9048,7 +9848,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9048
9848
  return this.fCompiler.version();
9049
9849
  }
9050
9850
  createDSPFactory(name, code, args, useInternalMemory) {
9051
- return this.fCompiler.createDSPFactory(name, code, args, useInternalMemory);
9851
+ return this.fCompiler.createDSPFactory(
9852
+ name,
9853
+ code,
9854
+ args,
9855
+ useInternalMemory
9856
+ );
9052
9857
  }
9053
9858
  deleteDSPFactory(cFactory) {
9054
9859
  return this.fCompiler.deleteDSPFactory(cFactory);
@@ -9105,7 +9910,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9105
9910
  return ab;
9106
9911
  }
9107
9912
  static writeHeader(writer, format) {
9108
- const { formatId, sampleRate, bitDepth, numberOfChannels, length, byteDepth } = format;
9913
+ const {
9914
+ formatId,
9915
+ sampleRate,
9916
+ bitDepth,
9917
+ numberOfChannels,
9918
+ length,
9919
+ byteDepth
9920
+ } = format;
9109
9921
  writer.string("RIFF");
9110
9922
  writer.uint32(writer.dataView.byteLength - 8);
9111
9923
  writer.string("WAVE");
@@ -9144,7 +9956,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9144
9956
  if (!writer[methodName]) {
9145
9957
  throw new TypeError("Not supported bit depth: " + bitDepth);
9146
9958
  }
9147
- const write = writer[methodName].bind(writer);
9959
+ const write = writer[methodName].bind(
9960
+ writer
9961
+ );
9148
9962
  for (let i = 0; i < length; i++) {
9149
9963
  for (let j = 0; j < numberOfChannels; j++) {
9150
9964
  write(audioBuffer[j][i]);
@@ -9279,7 +10093,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9279
10093
  if (chunkType === "fmt ") {
9280
10094
  format = this.decodeFormat(reader, chunkSize);
9281
10095
  } else if (chunkType === "data") {
9282
- audioData = this.decodeData(reader, chunkSize, format, options || {});
10096
+ audioData = this.decodeData(
10097
+ reader,
10098
+ chunkSize,
10099
+ format,
10100
+ options || {}
10101
+ );
9283
10102
  } else {
9284
10103
  reader.skip(chunkSize);
9285
10104
  }
@@ -9292,8 +10111,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9292
10111
  3: "lpcm"
9293
10112
  };
9294
10113
  const formatId = reader.uint16();
9295
- if (!formats.hasOwnProperty(formatId)) {
9296
- throw new TypeError("Unsupported format in WAV file: 0x" + formatId.toString(16));
10114
+ if (!Object.prototype.hasOwnProperty.call(formats, formatId)) {
10115
+ throw new TypeError(
10116
+ "Unsupported format in WAV file: 0x" + formatId.toString(16)
10117
+ );
9297
10118
  }
9298
10119
  const format = {
9299
10120
  formatId,
@@ -9445,7 +10266,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9445
10266
  var SoundfileReader = class {
9446
10267
  // Set the fallback paths
9447
10268
  static get fallbackPaths() {
9448
- return [location.href, this.getParentUrl(location.href), location.origin];
10269
+ return [
10270
+ location.href,
10271
+ this.getParentUrl(location.href),
10272
+ location.origin
10273
+ ];
9449
10274
  }
9450
10275
  /**
9451
10276
  * Extract the parent URL from an URL.
@@ -9457,7 +10282,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9457
10282
  }
9458
10283
  /**
9459
10284
  * Convert an audio buffer to audio data.
9460
- *
10285
+ *
9461
10286
  * @param audioBuffer : the audio buffer to convert
9462
10287
  * @returns : the audio data
9463
10288
  */
@@ -9470,7 +10295,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9470
10295
  }
9471
10296
  /**
9472
10297
  * Extract the URLs from the metadata.
9473
- *
10298
+ *
9474
10299
  * @param dspMeta : the metadata
9475
10300
  * @returns : the URLs
9476
10301
  */
@@ -9487,7 +10312,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9487
10312
  }
9488
10313
  /**
9489
10314
  * Check if the file exists.
9490
- *
10315
+ *
9491
10316
  * @param url : the url of the file to check
9492
10317
  * @returns : true if the file exists, otherwise false
9493
10318
  */
@@ -9504,7 +10329,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9504
10329
  }
9505
10330
  /**
9506
10331
  * Fetch the soundfile.
9507
- *
10332
+ *
9508
10333
  * @param url : the url of the soundfile
9509
10334
  * @param audioCtx : the audio context
9510
10335
  * @returns : the audio data
@@ -9512,14 +10337,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9512
10337
  static async fetchSoundfile(url, audioCtx) {
9513
10338
  console.log(`Loading sound file from ${url}`);
9514
10339
  const response = await fetch(url);
9515
- if (!response.ok) throw new Error(`Failed to load sound file from ${url}: ${response.statusText}`);
10340
+ if (!response.ok)
10341
+ throw new Error(
10342
+ `Failed to load sound file from ${url}: ${response.statusText}`
10343
+ );
9516
10344
  const arrayBuffer = await response.arrayBuffer();
9517
10345
  const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
9518
10346
  return this.toAudioData(audioBuffer);
9519
10347
  }
9520
10348
  /**
9521
10349
  * Load the soundfile.
9522
- *
10350
+ *
9523
10351
  * @param filename : the filename
9524
10352
  * @param metaUrls : the metadata URLs
9525
10353
  * @param soundfiles : the soundfiles
@@ -9527,15 +10355,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9527
10355
  */
9528
10356
  static async loadSoundfile(filename, metaUrls, soundfiles, audioCtx) {
9529
10357
  if (soundfiles == null ? void 0 : soundfiles[filename]) return;
9530
- const urlsToCheck = [filename, ...[...metaUrls, ...this.fallbackPaths].map((path) => new URL(filename, path.endsWith("/") ? path : `${path}/`).href)];
9531
- const checkResults = await Promise.all(urlsToCheck.map((url) => this.checkFileExists(url)));
10358
+ const urlsToCheck = [
10359
+ filename,
10360
+ ...[...metaUrls, ...this.fallbackPaths].map(
10361
+ (path) => new URL(filename, path.endsWith("/") ? path : `${path}/`).href
10362
+ )
10363
+ ];
10364
+ const checkResults = await Promise.all(
10365
+ urlsToCheck.map((url) => this.checkFileExists(url))
10366
+ );
9532
10367
  const successIndex = checkResults.findIndex((r) => !!r);
9533
- if (successIndex === -1) throw new Error(`Failed to load sound file ${filename}, all check failed.`);
9534
- soundfiles[filename] = await this.fetchSoundfile(urlsToCheck[successIndex], audioCtx);
10368
+ if (successIndex === -1)
10369
+ throw new Error(
10370
+ `Failed to load sound file ${filename}, all check failed.`
10371
+ );
10372
+ soundfiles[filename] = await this.fetchSoundfile(
10373
+ urlsToCheck[successIndex],
10374
+ audioCtx
10375
+ );
9535
10376
  }
9536
10377
  /**
9537
10378
  * Load the soundfiles, public API.
9538
- *
10379
+ *
9539
10380
  * @param dspMeta : the metadata
9540
10381
  * @param soundfilesIn : the soundfiles
9541
10382
  * @param audioCtx : the audio context
@@ -9576,7 +10417,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9576
10417
  this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
9577
10418
  ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
9578
10419
  ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
9579
- ;
9580
10420
  this.f32Acc = new Float32Array(ab, ptr, 3);
9581
10421
  ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
9582
10422
  this.f32Gyr = new Float32Array(ab, ptr, 3);
@@ -9616,7 +10456,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9616
10456
  const [x, y, z] = this.f32Acc;
9617
10457
  return { x, y, z, invert };
9618
10458
  }
9619
- setGyr({ alpha, beta, gamma }) {
10459
+ setGyr({
10460
+ alpha,
10461
+ beta,
10462
+ gamma
10463
+ }) {
9620
10464
  if (!this.supportSharedArrayBuffer) {
9621
10465
  const e = { type: "gyr", data: { alpha, beta, gamma } };
9622
10466
  this.port.postMessage(e);
@@ -9704,13 +10548,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9704
10548
  }
9705
10549
  };
9706
10550
  // Accelerometer and gyroscope handlers
9707
- this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
10551
+ this.handleDeviceMotion = ({
10552
+ accelerationIncludingGravity
10553
+ }) => {
9708
10554
  const isAndroid = /Android/i.test(navigator.userAgent);
9709
10555
  if (!accelerationIncludingGravity) return;
9710
10556
  const { x, y, z } = accelerationIncludingGravity;
9711
10557
  this.propagateAcc({ x, y, z }, isAndroid);
9712
10558
  };
9713
- this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
10559
+ this.handleDeviceOrientation = ({
10560
+ alpha,
10561
+ beta,
10562
+ gamma
10563
+ }) => {
9714
10564
  this.propagateGyr({ alpha, beta, gamma });
9715
10565
  };
9716
10566
  this.fJSONDsp = JSONObj;
@@ -9742,14 +10592,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9742
10592
  async startSensors() {
9743
10593
  if (this.hasAccInput) {
9744
10594
  if (window.DeviceMotionEvent) {
9745
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10595
+ window.addEventListener(
10596
+ "devicemotion",
10597
+ this.handleDeviceMotion,
10598
+ true
10599
+ );
9746
10600
  } else {
9747
10601
  console.log("Cannot set the accelerometer handler.");
9748
10602
  }
9749
10603
  }
9750
10604
  if (this.hasGyrInput) {
9751
10605
  if (window.DeviceMotionEvent) {
9752
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10606
+ window.addEventListener(
10607
+ "deviceorientation",
10608
+ this.handleDeviceOrientation,
10609
+ true
10610
+ );
9753
10611
  } else {
9754
10612
  console.log("Cannot set the gyroscope handler.");
9755
10613
  }
@@ -9757,10 +10615,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9757
10615
  }
9758
10616
  stopSensors() {
9759
10617
  if (this.hasAccInput) {
9760
- window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
10618
+ window.removeEventListener(
10619
+ "devicemotion",
10620
+ this.handleDeviceMotion,
10621
+ true
10622
+ );
9761
10623
  }
9762
10624
  if (this.hasGyrInput) {
9763
- window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
10625
+ window.removeEventListener(
10626
+ "deviceorientation",
10627
+ this.handleDeviceOrientation,
10628
+ true
10629
+ );
9764
10630
  }
9765
10631
  }
9766
10632
  setOutputParamHandler(handler) {
@@ -9808,7 +10674,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9808
10674
  }
9809
10675
  metadata(handler) {
9810
10676
  if (this.fJSONDsp.meta) {
9811
- this.fJSONDsp.meta.forEach((meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]]));
10677
+ this.fJSONDsp.meta.forEach(
10678
+ (meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]])
10679
+ );
9812
10680
  }
9813
10681
  }
9814
10682
  midiMessage(data) {
@@ -9818,7 +10686,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9818
10686
  const data2 = data[2];
9819
10687
  if (cmd === 11) this.ctrlChange(channel, data1, data2);
9820
10688
  else if (cmd === 14) this.pitchWheel(channel, data2 * 128 + data1);
9821
- if (cmd === 8 || cmd === 9 && data2 === 0) this.keyOff(channel, data1, data2);
10689
+ if (cmd === 8 || cmd === 9 && data2 === 0)
10690
+ this.keyOff(channel, data1, data2);
9822
10691
  else if (cmd === 9) this.keyOn(channel, data1, data2);
9823
10692
  else this.port.postMessage({ type: "midi", data });
9824
10693
  }
@@ -9852,7 +10721,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9852
10721
  propagateGyr(event) {
9853
10722
  if (!event) return;
9854
10723
  const { alpha, beta, gamma } = event;
9855
- this.fCommunicator.setGyr({ alpha, beta, gamma });
10724
+ this.fCommunicator.setGyr({
10725
+ alpha,
10726
+ beta,
10727
+ gamma
10728
+ });
9856
10729
  }
9857
10730
  setParamValue(path, value) {
9858
10731
  const e = { type: "param", data: { path, value } };
@@ -9894,7 +10767,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9894
10767
  _hasGyrInput = new WeakMap();
9895
10768
  var FaustMonoAudioWorkletNode = class extends FaustAudioWorkletNode {
9896
10769
  constructor(context, options) {
9897
- super(context, options.processorOptions.name, options.processorOptions.factory, options);
10770
+ super(
10771
+ context,
10772
+ options.processorOptions.name,
10773
+ options.processorOptions.factory,
10774
+ options
10775
+ );
9898
10776
  this.onprocessorerror = (e) => {
9899
10777
  throw e;
9900
10778
  };
@@ -9934,22 +10812,24 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9934
10812
  const e = this.fJSONEffect;
9935
10813
  const r = { ...o };
9936
10814
  if (e) {
9937
- r.ui = [{
9938
- type: "tgroup",
9939
- label: "Sequencer",
9940
- items: [
9941
- { type: "vgroup", label: "Instrument", items: o.ui },
9942
- { type: "vgroup", label: "Effect", items: e.ui }
9943
- ]
9944
- }];
10815
+ r.ui = [
10816
+ {
10817
+ type: "tgroup",
10818
+ label: "Sequencer",
10819
+ items: [
10820
+ { type: "vgroup", label: "Instrument", items: o.ui },
10821
+ { type: "vgroup", label: "Effect", items: e.ui }
10822
+ ]
10823
+ }
10824
+ ];
9945
10825
  } else {
9946
- r.ui = [{
9947
- type: "tgroup",
9948
- label: "Polyphonic",
9949
- items: [
9950
- { type: "vgroup", label: "Voices", items: o.ui }
9951
- ]
9952
- }];
10826
+ r.ui = [
10827
+ {
10828
+ type: "tgroup",
10829
+ label: "Polyphonic",
10830
+ items: [{ type: "vgroup", label: "Voices", items: o.ui }]
10831
+ }
10832
+ ];
9953
10833
  }
9954
10834
  return r;
9955
10835
  }
@@ -9972,13 +10852,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9972
10852
  this.fDSPCode = instance;
9973
10853
  this.fInputs = new Array(this.fDSPCode.getNumInputs());
9974
10854
  this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
9975
- this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
10855
+ this.handleDeviceMotion = ({
10856
+ accelerationIncludingGravity
10857
+ }) => {
9976
10858
  const isAndroid = /Android/i.test(navigator.userAgent);
9977
10859
  if (!accelerationIncludingGravity) return;
9978
10860
  const { x, y, z } = accelerationIncludingGravity;
9979
10861
  this.propagateAcc({ x, y, z }, isAndroid);
9980
10862
  };
9981
- this.handleDeviceOrientation = ({ alpha, beta, gamma }) => {
10863
+ this.handleDeviceOrientation = ({
10864
+ alpha,
10865
+ beta,
10866
+ gamma
10867
+ }) => {
9982
10868
  this.propagateGyr({ alpha, beta, gamma });
9983
10869
  };
9984
10870
  this.onaudioprocess = (e) => {
@@ -9997,14 +10883,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9997
10883
  async startSensors() {
9998
10884
  if (this.hasAccInput) {
9999
10885
  if (window.DeviceMotionEvent) {
10000
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10886
+ window.addEventListener(
10887
+ "devicemotion",
10888
+ this.handleDeviceMotion,
10889
+ true
10890
+ );
10001
10891
  } else {
10002
10892
  console.log("Cannot set the accelerometer handler.");
10003
10893
  }
10004
10894
  }
10005
10895
  if (this.hasGyrInput) {
10006
10896
  if (window.DeviceMotionEvent) {
10007
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10897
+ window.addEventListener(
10898
+ "deviceorientation",
10899
+ this.handleDeviceOrientation,
10900
+ true
10901
+ );
10008
10902
  } else {
10009
10903
  console.log("Cannot set the gyroscope handler.");
10010
10904
  }
@@ -10013,10 +10907,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10013
10907
  /** Stop accelerometer and gyroscope handlers */
10014
10908
  stopSensors() {
10015
10909
  if (this.hasAccInput) {
10016
- window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
10910
+ window.removeEventListener(
10911
+ "devicemotion",
10912
+ this.handleDeviceMotion,
10913
+ true
10914
+ );
10017
10915
  }
10018
10916
  if (this.hasGyrInput) {
10019
- window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
10917
+ window.removeEventListener(
10918
+ "deviceorientation",
10919
+ this.handleDeviceOrientation,
10920
+ true
10921
+ );
10020
10922
  }
10021
10923
  }
10022
10924
  compute(input, output) {
@@ -10138,13 +11040,19 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10138
11040
  }
10139
11041
  }
10140
11042
  addSoundfiles(soundfileMap) {
10141
- if (!this.factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11043
+ if (!this.factory)
11044
+ throw new Error(
11045
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11046
+ );
10142
11047
  for (const id in soundfileMap) {
10143
11048
  this.factory.soundfiles[id] = soundfileMap[id];
10144
11049
  }
10145
11050
  }
10146
11051
  getSoundfileList() {
10147
- if (!this.factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11052
+ if (!this.factory)
11053
+ throw new Error(
11054
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11055
+ );
10148
11056
  const meta = JSON.parse(this.factory.json);
10149
11057
  const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
10150
11058
  if (!map) return [];
@@ -10152,19 +11060,40 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10152
11060
  }
10153
11061
  async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name, processorOptions = {}) {
10154
11062
  var _a, _b;
10155
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11063
+ if (!factory)
11064
+ throw new Error(
11065
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11066
+ );
10156
11067
  const meta = JSON.parse(factory.json);
10157
11068
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
10158
- factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
11069
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(
11070
+ meta,
11071
+ factory.soundfiles || {},
11072
+ context
11073
+ );
10159
11074
  if (sp) {
10160
11075
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
10161
- const monoDsp = new FaustMonoWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize, factory.soundfiles);
10162
- const sp2 = context.createScriptProcessor(bufferSize, monoDsp.getNumInputs(), monoDsp.getNumOutputs());
11076
+ const monoDsp = new FaustMonoWebAudioDsp(
11077
+ instance,
11078
+ context.sampleRate,
11079
+ sampleSize,
11080
+ bufferSize,
11081
+ factory.soundfiles
11082
+ );
11083
+ const sp2 = context.createScriptProcessor(
11084
+ bufferSize,
11085
+ monoDsp.getNumInputs(),
11086
+ monoDsp.getNumOutputs()
11087
+ );
10163
11088
  Object.setPrototypeOf(sp2, FaustMonoScriptProcessorNode.prototype);
10164
11089
  sp2.init(monoDsp);
10165
11090
  return sp2;
10166
11091
  } else {
10167
- if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context)) _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
11092
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
11093
+ _FaustMonoDspGenerator.gWorkletProcessors.set(
11094
+ context,
11095
+ /* @__PURE__ */ new Set()
11096
+ );
10168
11097
  if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
10169
11098
  try {
10170
11099
  const processorCode = `
@@ -10204,24 +11133,41 @@ const dependencies = {
10204
11133
  // Generate the actual AudioWorkletProcessor code
10205
11134
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
10206
11135
  `;
10207
- const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
11136
+ const url = URL.createObjectURL(
11137
+ new Blob([processorCode], { type: "text/javascript" })
11138
+ );
10208
11139
  await context.audioWorklet.addModule(url);
10209
11140
  (_b = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
10210
11141
  } catch (e) {
10211
11142
  throw e;
10212
11143
  }
10213
11144
  }
10214
- const node = new FaustMonoAudioWorkletNode(context, { processorOptions: { name: processorName, factory, sampleSize, ...processorOptions } });
11145
+ const node = new FaustMonoAudioWorkletNode(context, {
11146
+ processorOptions: {
11147
+ name: processorName,
11148
+ factory,
11149
+ sampleSize,
11150
+ ...processorOptions
11151
+ }
11152
+ });
10215
11153
  return node;
10216
11154
  }
10217
11155
  }
10218
11156
  async createFFTNode(context, fftUtils, name = this.name, factory = this.factory, fftOptions = {}, processorName = (factory == null ? void 0 : factory.shaKey) ? `${factory.shaKey}_fft` : name, processorOptions = {}) {
10219
11157
  var _a, _b;
10220
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11158
+ if (!factory)
11159
+ throw new Error(
11160
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11161
+ );
10221
11162
  const meta = JSON.parse(factory.json);
10222
11163
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
10223
- factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
10224
- if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context)) _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
11164
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(
11165
+ meta,
11166
+ factory.soundfiles || {},
11167
+ context
11168
+ );
11169
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
11170
+ _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
10225
11171
  if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
10226
11172
  try {
10227
11173
  const processorCode = `
@@ -10263,14 +11209,25 @@ const dependencies = {
10263
11209
  // Generate the actual AudioWorkletProcessor code
10264
11210
  (${FaustFFTAudioWorkletProcessor_default.toString()})(dependencies, faustData);
10265
11211
  `;
10266
- const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
11212
+ const url = URL.createObjectURL(
11213
+ new Blob([processorCode], { type: "text/javascript" })
11214
+ );
10267
11215
  await context.audioWorklet.addModule(url);
10268
11216
  (_b = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
10269
11217
  } catch (e) {
10270
11218
  throw e;
10271
11219
  }
10272
11220
  }
10273
- 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 } });
11221
+ const node = new FaustMonoAudioWorkletNode(context, {
11222
+ channelCount: Math.max(1, Math.ceil(meta.inputs / 3)),
11223
+ outputChannelCount: [Math.ceil(meta.outputs / 2)],
11224
+ processorOptions: {
11225
+ name: processorName,
11226
+ factory,
11227
+ sampleSize,
11228
+ ...processorOptions
11229
+ }
11230
+ });
10274
11231
  if (fftOptions.fftSize) {
10275
11232
  const param = node.parameters.get("fftSize");
10276
11233
  if (param) param.value = fftOptions.fftSize;
@@ -10290,7 +11247,10 @@ const dependencies = {
10290
11247
  return node;
10291
11248
  }
10292
11249
  async createAudioWorkletProcessor(name = this.name, factory = this.factory, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
10293
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11250
+ if (!factory)
11251
+ throw new Error(
11252
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11253
+ );
10294
11254
  const meta = JSON.parse(factory.json);
10295
11255
  const dependencies = {
10296
11256
  FaustBaseWebAudioDsp,
@@ -10307,19 +11267,36 @@ const dependencies = {
10307
11267
  dspMeta: meta,
10308
11268
  poly: false
10309
11269
  };
10310
- const Processor = FaustAudioWorkletProcessor_default(dependencies, faustData);
11270
+ const Processor = FaustAudioWorkletProcessor_default(
11271
+ dependencies,
11272
+ faustData
11273
+ );
10311
11274
  return Processor;
10312
11275
  } catch (e) {
10313
11276
  throw e;
10314
11277
  }
10315
11278
  }
10316
11279
  async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory, context) {
10317
- if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11280
+ if (!factory)
11281
+ throw new Error(
11282
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11283
+ );
10318
11284
  const meta = JSON.parse(factory.json);
10319
11285
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
10320
11286
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
10321
- if (context) factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
10322
- const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
11287
+ if (context)
11288
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(
11289
+ meta,
11290
+ factory.soundfiles || {},
11291
+ context
11292
+ );
11293
+ const monoDsp = new FaustMonoWebAudioDsp(
11294
+ instance,
11295
+ sampleRate,
11296
+ sampleSize,
11297
+ bufferSize,
11298
+ factory.soundfiles
11299
+ );
10323
11300
  return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
10324
11301
  }
10325
11302
  getMeta() {
@@ -10345,7 +11322,11 @@ const dependencies = {
10345
11322
  };
10346
11323
  process = dsp_code.effect;`) {
10347
11324
  try {
10348
- this.effectFactory = await compiler.createPolyDSPFactory(name, effectCodeAux, args);
11325
+ this.effectFactory = await compiler.createPolyDSPFactory(
11326
+ name,
11327
+ effectCodeAux,
11328
+ args
11329
+ );
10349
11330
  if (this.effectFactory) {
10350
11331
  const effectJSON = JSON.parse(this.effectFactory.json);
10351
11332
  const dspCode = `// Voice output is forced to 2, when DSP is stereo or effect has 2 ins or 2 outs,
@@ -10385,16 +11366,28 @@ dsp_code = environment{
10385
11366
  };
10386
11367
  process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
10387
11368
  `;
10388
- this.voiceFactory = await compiler.createPolyDSPFactory(name, dspCode, args);
11369
+ this.voiceFactory = await compiler.createPolyDSPFactory(
11370
+ name,
11371
+ dspCode,
11372
+ args
11373
+ );
10389
11374
  try {
10390
- this.effectFactory = await compiler.createPolyDSPFactory(name, effectCode, args + " -inpl");
11375
+ this.effectFactory = await compiler.createPolyDSPFactory(
11376
+ name,
11377
+ effectCode,
11378
+ args + " -inpl"
11379
+ );
10391
11380
  } catch (e) {
10392
11381
  console.warn(e);
10393
11382
  }
10394
11383
  }
10395
11384
  } catch (e) {
10396
11385
  console.warn(e);
10397
- this.voiceFactory = await compiler.createPolyDSPFactory(name, dspCodeAux, args);
11386
+ this.voiceFactory = await compiler.createPolyDSPFactory(
11387
+ name,
11388
+ dspCodeAux,
11389
+ args
11390
+ );
10398
11391
  }
10399
11392
  if (this.voiceFactory) {
10400
11393
  this.name = name;
@@ -10409,13 +11402,19 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
10409
11402
  }
10410
11403
  }
10411
11404
  addSoundfiles(soundfileMap) {
10412
- if (!this.voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11405
+ if (!this.voiceFactory)
11406
+ throw new Error(
11407
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11408
+ );
10413
11409
  for (const id in soundfileMap) {
10414
11410
  this.voiceFactory.soundfiles[id] = soundfileMap[id];
10415
11411
  }
10416
11412
  }
10417
11413
  getSoundfileList() {
10418
- if (!this.voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11414
+ if (!this.voiceFactory)
11415
+ throw new Error(
11416
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11417
+ );
10419
11418
  const meta = JSON.parse(this.voiceFactory.json);
10420
11419
  const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
10421
11420
  if (!map) return [];
@@ -10426,22 +11425,56 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
10426
11425
  }
10427
11426
  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 = {}) {
10428
11427
  var _a, _b;
10429
- if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11428
+ if (!voiceFactory)
11429
+ throw new Error(
11430
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11431
+ );
10430
11432
  const voiceMeta = JSON.parse(voiceFactory.json);
10431
11433
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
10432
11434
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
10433
- voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
10434
- if (effectFactory) effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
11435
+ voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
11436
+ voiceMeta,
11437
+ voiceFactory.soundfiles || {},
11438
+ context
11439
+ );
11440
+ if (effectFactory)
11441
+ effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
11442
+ effectMeta,
11443
+ effectFactory.soundfiles || {},
11444
+ context
11445
+ );
10435
11446
  if (sp) {
10436
- const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
10437
- const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
10438
- const polyDsp = new FaustPolyWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize, soundfiles);
10439
- const sp2 = context.createScriptProcessor(bufferSize, polyDsp.getNumInputs(), polyDsp.getNumOutputs());
11447
+ const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(
11448
+ voiceFactory,
11449
+ mixerModule,
11450
+ voices,
11451
+ effectFactory || void 0
11452
+ );
11453
+ const soundfiles = {
11454
+ ...effectFactory == null ? void 0 : effectFactory.soundfiles,
11455
+ ...voiceFactory.soundfiles
11456
+ };
11457
+ const polyDsp = new FaustPolyWebAudioDsp(
11458
+ instance,
11459
+ context.sampleRate,
11460
+ sampleSize,
11461
+ bufferSize,
11462
+ soundfiles
11463
+ );
11464
+ const sp2 = context.createScriptProcessor(
11465
+ bufferSize,
11466
+ polyDsp.getNumInputs(),
11467
+ polyDsp.getNumOutputs()
11468
+ );
10440
11469
  Object.setPrototypeOf(sp2, FaustPolyScriptProcessorNode.prototype);
10441
11470
  sp2.init(polyDsp);
10442
11471
  return sp2;
10443
11472
  } else {
10444
- if (!_FaustPolyDspGenerator.gWorkletProcessors.has(context)) _FaustPolyDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
11473
+ if (!_FaustPolyDspGenerator.gWorkletProcessors.has(context))
11474
+ _FaustPolyDspGenerator.gWorkletProcessors.set(
11475
+ context,
11476
+ /* @__PURE__ */ new Set()
11477
+ );
10445
11478
  if (!((_a = _FaustPolyDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
10446
11479
  try {
10447
11480
  const processorCode = `
@@ -10484,19 +11517,34 @@ const dependencies = {
10484
11517
  // Generate the actual AudioWorkletProcessor code
10485
11518
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
10486
11519
  `;
10487
- const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
11520
+ const url = URL.createObjectURL(
11521
+ new Blob([processorCode], { type: "text/javascript" })
11522
+ );
10488
11523
  await context.audioWorklet.addModule(url);
10489
11524
  (_b = _FaustPolyDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
10490
11525
  } catch (e) {
10491
11526
  throw e;
10492
11527
  }
10493
11528
  }
10494
- const node = new FaustPolyAudioWorkletNode(context, { processorOptions: { name: processorName, voiceFactory, mixerModule, voices, sampleSize, effectFactory: effectFactory || void 0, ...processorOptions } });
11529
+ const node = new FaustPolyAudioWorkletNode(context, {
11530
+ processorOptions: {
11531
+ name: processorName,
11532
+ voiceFactory,
11533
+ mixerModule,
11534
+ voices,
11535
+ sampleSize,
11536
+ effectFactory: effectFactory || void 0,
11537
+ ...processorOptions
11538
+ }
11539
+ });
10495
11540
  return node;
10496
11541
  }
10497
11542
  }
10498
11543
  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`) {
10499
- if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11544
+ if (!voiceFactory)
11545
+ throw new Error(
11546
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11547
+ );
10500
11548
  const voiceMeta = JSON.parse(voiceFactory.json);
10501
11549
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
10502
11550
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
@@ -10516,24 +11564,53 @@ const dependencies = {
10516
11564
  poly: true,
10517
11565
  effectMeta
10518
11566
  };
10519
- const Processor = FaustAudioWorkletProcessor_default(dependencies, faustData);
11567
+ const Processor = FaustAudioWorkletProcessor_default(
11568
+ dependencies,
11569
+ faustData
11570
+ );
10520
11571
  return Processor;
10521
11572
  } catch (e) {
10522
11573
  throw e;
10523
11574
  }
10524
11575
  }
10525
11576
  async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, context) {
10526
- if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
11577
+ if (!voiceFactory)
11578
+ throw new Error(
11579
+ "Code is not compiled, please define the factory or call `await this.compile()` first."
11580
+ );
10527
11581
  const voiceMeta = JSON.parse(voiceFactory.json);
10528
11582
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
10529
- const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
11583
+ const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(
11584
+ voiceFactory,
11585
+ mixerModule,
11586
+ voices,
11587
+ effectFactory || void 0
11588
+ );
10530
11589
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
10531
11590
  if (context) {
10532
- voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
10533
- if (effectFactory) effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
10534
- }
10535
- const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
10536
- const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
11591
+ voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
11592
+ voiceMeta,
11593
+ voiceFactory.soundfiles || {},
11594
+ context
11595
+ );
11596
+ if (effectFactory)
11597
+ effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(
11598
+ effectMeta,
11599
+ effectFactory.soundfiles || {},
11600
+ context
11601
+ );
11602
+ }
11603
+ const soundfiles = {
11604
+ ...effectFactory == null ? void 0 : effectFactory.soundfiles,
11605
+ ...voiceFactory.soundfiles
11606
+ };
11607
+ const polyDsp = new FaustPolyWebAudioDsp(
11608
+ instance,
11609
+ sampleRate,
11610
+ sampleSize,
11611
+ bufferSize,
11612
+ soundfiles
11613
+ );
10537
11614
  return new FaustPolyOfflineProcessor(polyDsp, bufferSize);
10538
11615
  }
10539
11616
  getMeta() {
@@ -10541,22 +11618,24 @@ const dependencies = {
10541
11618
  const e = this.effectFactory ? JSON.parse(this.effectFactory.json) : null;
10542
11619
  const r = { ...o };
10543
11620
  if (e) {
10544
- r.ui = [{
10545
- type: "tgroup",
10546
- label: "Sequencer",
10547
- items: [
10548
- { type: "vgroup", label: "Instrument", items: o.ui },
10549
- { type: "vgroup", label: "Effect", items: e.ui }
10550
- ]
10551
- }];
11621
+ r.ui = [
11622
+ {
11623
+ type: "tgroup",
11624
+ label: "Sequencer",
11625
+ items: [
11626
+ { type: "vgroup", label: "Instrument", items: o.ui },
11627
+ { type: "vgroup", label: "Effect", items: e.ui }
11628
+ ]
11629
+ }
11630
+ ];
10552
11631
  } else {
10553
- r.ui = [{
10554
- type: "tgroup",
10555
- label: "Polyphonic",
10556
- items: [
10557
- { type: "vgroup", label: "Voices", items: o.ui }
10558
- ]
10559
- }];
11632
+ r.ui = [
11633
+ {
11634
+ type: "tgroup",
11635
+ label: "Polyphonic",
11636
+ items: [{ type: "vgroup", label: "Voices", items: o.ui }]
11637
+ }
11638
+ ];
10560
11639
  }
10561
11640
  return r;
10562
11641
  }
@@ -10570,6 +11649,97 @@ const dependencies = {
10570
11649
  // Set of all created WorkletProcessors, each of them has to be unique
10571
11650
  _FaustPolyDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
10572
11651
  var FaustPolyDspGenerator = _FaustPolyDspGenerator;
11652
+ var _FaustDspGenerator = class _FaustDspGenerator {
11653
+ // Analyze the metadata of a Faust JSON file and extract the [midi:on] and [nvoices:n] options
11654
+ extractMidiAndNvoices(jsonData) {
11655
+ const optionsMetadata = jsonData.meta.find((meta) => meta.options);
11656
+ if (optionsMetadata && optionsMetadata.options) {
11657
+ const options = optionsMetadata.options;
11658
+ const midiRegex = /\[midi:(on|off)\]/;
11659
+ const nvoicesRegex = /\[nvoices:(\d+)\]/;
11660
+ const midiMatch = options.match(midiRegex);
11661
+ const nvoicesMatch = options.match(nvoicesRegex);
11662
+ const midi = midiMatch ? midiMatch[1] === "on" : false;
11663
+ const nvoices = nvoicesMatch ? parseInt(nvoicesMatch[1], 10) : -1;
11664
+ return { midi, nvoices };
11665
+ } else {
11666
+ return { midi: false, nvoices: -1 };
11667
+ }
11668
+ }
11669
+ /**
11670
+ * Compile DSP code, inspect metadata for [nvoices:] (and optionally [midi:on]), and build either a mono
11671
+ * or poly WebAudio node (ScriptProcessor or AudioWorklet depending on `sp`). Compilation uses a shared,
11672
+ * lazily-created libfaust instance to avoid repeatedly instantiating the WASM compiler.
11673
+ */
11674
+ async createFaustNode(context, name, code, sp, bufferSize) {
11675
+ const getCompiler = async () => {
11676
+ if (!_FaustDspGenerator.compilerPromise) {
11677
+ const baseURL = (typeof document !== "undefined" ? "src" in (document.currentScript || {}) ? document.currentScript.src : document.baseURI : void 0) || (typeof window !== "undefined" ? window.location.href : void 0);
11678
+ if (!baseURL)
11679
+ throw new Error("Cannot resolve libfaust-wasm location.");
11680
+ const jsURL = new URL(
11681
+ "../libfaust-wasm/libfaust-wasm.js",
11682
+ baseURL
11683
+ ).href;
11684
+ const dataURL = jsURL.replace(/c?js$/, "data");
11685
+ const wasmURL = jsURL.replace(/c?js$/, "wasm");
11686
+ _FaustDspGenerator.compilerPromise = instantiateFaustModuleFromFile_default(
11687
+ jsURL,
11688
+ dataURL,
11689
+ wasmURL
11690
+ ).then((module) => new FaustCompiler_default(new LibFaust_default(module)));
11691
+ }
11692
+ return _FaustDspGenerator.compilerPromise;
11693
+ };
11694
+ const args = "-ftz 2";
11695
+ try {
11696
+ const compiler = await getCompiler();
11697
+ const monoGenerator = new FaustMonoDspGenerator();
11698
+ const compiledMono = await monoGenerator.compile(
11699
+ compiler,
11700
+ name,
11701
+ code,
11702
+ args
11703
+ );
11704
+ if (!compiledMono) return null;
11705
+ const { nvoices } = this.extractMidiAndNvoices(
11706
+ monoGenerator.getMeta()
11707
+ );
11708
+ if (nvoices > 0) {
11709
+ const polyGenerator = new FaustPolyDspGenerator();
11710
+ const compiledPoly = await polyGenerator.compile(
11711
+ compiler,
11712
+ name,
11713
+ code,
11714
+ args
11715
+ );
11716
+ if (!compiledPoly) return null;
11717
+ return await polyGenerator.createNode(
11718
+ context,
11719
+ nvoices,
11720
+ name,
11721
+ void 0,
11722
+ void 0,
11723
+ void 0,
11724
+ sp,
11725
+ bufferSize
11726
+ );
11727
+ }
11728
+ return await monoGenerator.createNode(
11729
+ context,
11730
+ name,
11731
+ void 0,
11732
+ sp,
11733
+ bufferSize
11734
+ );
11735
+ } catch (e) {
11736
+ console.error(e);
11737
+ return null;
11738
+ }
11739
+ }
11740
+ };
11741
+ _FaustDspGenerator.compilerPromise = null;
11742
+ var FaustDspGenerator = _FaustDspGenerator;
10573
11743
 
10574
11744
  // src/index-bundle-iife.ts
10575
11745
  globalThis.faustwasm = exports_bundle_exports;