@grame/faustwasm 0.12.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,10 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateGet = (obj, member, getter) => {
6
- __accessCheck(obj, member, "read from private field");
7
- return getter ? getter.call(obj) : member.get(obj);
8
- };
9
- var __privateAdd = (obj, member, value) => {
10
- if (member.has(obj))
11
- throw TypeError("Cannot add the same private member more than once");
12
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
- };
14
- var __privateSet = (obj, member, value, setter) => {
15
- __accessCheck(obj, member, "write to private field");
16
- setter ? setter.call(obj, value) : member.set(obj, value);
17
- return value;
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
18
3
  };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
+ 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);
7
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
19
8
 
20
9
  // src/instantiateFaustModuleFromFile.ts
21
10
  var instantiateFaustModuleFromFile = async (jsFile, dataFile = jsFile.replace(/c?js$/, "data"), wasmFile = jsFile.replace(/c?js$/, "wasm")) => {
@@ -67,8 +56,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
67
56
  const faustModule = await FaustModule({
68
57
  wasmBinary,
69
58
  getPreloadedPackage: (remotePackageName, remotePackageSize) => {
70
- if (remotePackageName === "libfaust-wasm.data")
71
- return dataBinary;
59
+ if (remotePackageName === "libfaust-wasm.data") return dataBinary;
72
60
  return new ArrayBuffer(0);
73
61
  }
74
62
  });
@@ -94,8 +82,7 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
94
82
  const analysePolyParameters = (item) => {
95
83
  const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
96
84
  const isPolyReserved = "address" in item && !!polyKeywords.find((k) => item.address.endsWith(k));
97
- if (poly && isPolyReserved)
98
- return null;
85
+ if (poly && isPolyReserved) return null;
99
86
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
100
87
  return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
101
88
  } else if (item.type === "button" || item.type === "checkbox") {
@@ -113,37 +100,30 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
113
100
  this.paramValuesCache[pd.name] = pd.defaultValue || 0;
114
101
  });
115
102
  const { moduleId, instanceId } = options.processorOptions;
116
- if (!moduleId || !instanceId)
117
- return;
103
+ if (!moduleId || !instanceId) return;
118
104
  this.wamInfo = { moduleId, instanceId };
119
105
  }
120
106
  static get parameterDescriptors() {
121
107
  const params = [];
122
108
  const callback = (item) => {
123
109
  const param = analysePolyParameters(item);
124
- if (param)
125
- params.push(param);
110
+ if (param) params.push(param);
126
111
  };
127
112
  FaustBaseWebAudioDsp2.parseUI(dspMeta.ui, callback);
128
- if (effectMeta)
129
- FaustBaseWebAudioDsp2.parseUI(effectMeta.ui, callback);
113
+ if (effectMeta) FaustBaseWebAudioDsp2.parseUI(effectMeta.ui, callback);
130
114
  return params;
131
115
  }
132
116
  setupWamEventHandler() {
133
117
  var _a;
134
- if (!this.wamInfo)
135
- return;
118
+ if (!this.wamInfo) return;
136
119
  const { moduleId, instanceId } = this.wamInfo;
137
120
  const { webAudioModules } = globalThis;
138
121
  const ModuleScope = webAudioModules.getModuleScope(moduleId);
139
122
  const paramMgrProcessor = (_a = ModuleScope == null ? void 0 : ModuleScope.paramMgrProcessors) == null ? void 0 : _a[instanceId];
140
- if (!paramMgrProcessor)
141
- return;
142
- if (paramMgrProcessor.handleEvent)
143
- return;
123
+ if (!paramMgrProcessor) return;
124
+ if (paramMgrProcessor.handleEvent) return;
144
125
  paramMgrProcessor.handleEvent = (event) => {
145
- if (event.type === "wam-midi")
146
- this.midiMessage(event.data.bytes);
126
+ if (event.type === "wam-midi") this.midiMessage(event.data.bytes);
147
127
  };
148
128
  }
149
129
  process(inputs, outputs, parameters) {
@@ -173,10 +153,12 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
173
153
  handleMessageAux(e) {
174
154
  const msg = e.data;
175
155
  switch (msg.type) {
156
+ // Generic MIDI message
176
157
  case "midi": {
177
158
  this.midiMessage(msg.data);
178
159
  break;
179
160
  }
161
+ // Typed MIDI message
180
162
  case "ctrlChange": {
181
163
  this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
182
164
  break;
@@ -193,10 +175,12 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
193
175
  this.keyOff(msg.data[0], msg.data[1], msg.data[2]);
194
176
  break;
195
177
  }
178
+ // Generic data message
196
179
  case "param": {
197
180
  this.setParamValue(msg.data.path, msg.data.value);
198
181
  break;
199
182
  }
183
+ // Plot handler set on demand
200
184
  case "setPlotHandler": {
201
185
  if (msg.data) {
202
186
  this.fDSPCode.setPlotHandler((output, index, events) => this.port.postMessage({ type: "plot", value: output, index, events }));
@@ -300,12 +284,9 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
300
284
  const channel = data[0] & 15;
301
285
  const data1 = data[1];
302
286
  const data2 = data[2];
303
- if (cmd === 8 || cmd === 9 && data2 === 0)
304
- this.keyOff(channel, data1, data2);
305
- else if (cmd === 9)
306
- this.keyOn(channel, data1, data2);
307
- else
308
- super.midiMessage(data);
287
+ if (cmd === 8 || cmd === 9 && data2 === 0) this.keyOff(channel, data1, data2);
288
+ else if (cmd === 9) this.keyOn(channel, data1, data2);
289
+ else super.midiMessage(data);
309
290
  }
310
291
  // Public API
311
292
  keyOn(channel, pitch, velocity) {
@@ -371,10 +352,8 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
371
352
  while (spilled < spillLength) {
372
353
  const $spillLength = Math.min(spillLength - spilled, toLength - $to, fromLength - $from);
373
354
  const $fromEnd = $from + $spillLength;
374
- if ($from === 0 && $fromEnd === fromLength)
375
- to.set(from, $to);
376
- else
377
- to.set(from.subarray($from, $fromEnd), $to);
355
+ if ($from === 0 && $fromEnd === fromLength) to.set(from, $to);
356
+ else to.set(from.subarray($from, $fromEnd), $to);
378
357
  $to = ($to + $spillLength) % toLength;
379
358
  $from = $fromEnd % fromLength;
380
359
  spilled += $spillLength;
@@ -383,8 +362,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
383
362
  };
384
363
  const analyseParameters = (item) => {
385
364
  const isFFTReserved = "address" in item && !!fftParamKeywords.find((k) => item.address.endsWith(k));
386
- if (isFFTReserved)
387
- return null;
365
+ if (isFFTReserved) return null;
388
366
  if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
389
367
  return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
390
368
  } else if (item.type === "button" || item.type === "checkbox") {
@@ -425,23 +403,26 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
425
403
  var _a, _b, _c;
426
404
  const msg = e.data;
427
405
  switch (msg.type) {
406
+ // Generic MIDI message
428
407
  case "midi":
429
408
  this.midiMessage(msg.data);
430
409
  break;
410
+ // Typed MIDI message
431
411
  case "ctrlChange":
432
412
  this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
433
413
  break;
434
414
  case "pitchWheel":
435
415
  this.pitchWheel(msg.data[0], msg.data[1]);
436
416
  break;
417
+ // Generic data message
437
418
  case "param":
438
419
  this.setParamValue(msg.data.path, msg.data.value);
439
420
  break;
421
+ // Plot handler set on demand
440
422
  case "setPlotHandler": {
441
423
  if (msg.data) {
442
424
  this.fPlotHandler = (output, index, events) => {
443
- if (events)
444
- this.fCachedEvents.push(...events);
425
+ if (events) this.fCachedEvents.push(...events);
445
426
  };
446
427
  } else {
447
428
  this.fPlotHandler = null;
@@ -483,8 +464,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
483
464
  this.soundfiles = factory.soundfiles;
484
465
  this.initFFT();
485
466
  const { moduleId, instanceId } = options.processorOptions;
486
- if (!moduleId || !instanceId)
487
- return;
467
+ if (!moduleId || !instanceId) return;
488
468
  this.wamInfo = { moduleId, instanceId };
489
469
  }
490
470
  get fftProcessorBufferSize() {
@@ -499,8 +479,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
499
479
  const params = [];
500
480
  const callback = (item) => {
501
481
  const param = analyseParameters(item);
502
- if (param)
503
- params.push(param);
482
+ if (param) params.push(param);
504
483
  };
505
484
  FaustBaseWebAudioDsp2.parseUI(dspMeta.ui, callback);
506
485
  return [
@@ -533,19 +512,15 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
533
512
  }
534
513
  setupWamEventHandler() {
535
514
  var _a;
536
- if (!this.wamInfo)
537
- return;
515
+ if (!this.wamInfo) return;
538
516
  const { moduleId, instanceId } = this.wamInfo;
539
517
  const { webAudioModules } = globalThis;
540
518
  const ModuleScope = webAudioModules.getModuleScope(moduleId);
541
519
  const paramMgrProcessor = (_a = ModuleScope == null ? void 0 : ModuleScope.paramMgrProcessors) == null ? void 0 : _a[instanceId];
542
- if (!paramMgrProcessor)
543
- return;
544
- if (paramMgrProcessor.handleEvent)
545
- return;
520
+ if (!paramMgrProcessor) return;
521
+ if (paramMgrProcessor.handleEvent) return;
546
522
  paramMgrProcessor.handleEvent = (event) => {
547
- if (event.type === "wam-midi")
548
- this.midiMessage(event.data.bytes);
523
+ if (event.type === "wam-midi") this.midiMessage(event.data.bytes);
549
524
  };
550
525
  }
551
526
  processFFT() {
@@ -563,10 +538,8 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
563
538
  fftToSignal(ffted, inputs[i * 3], inputs[i * 3 + 1], inputs[i * 3 + 2]);
564
539
  }
565
540
  for (let i = this.fftInput.length * 3; i < inputs.length; i++) {
566
- if (i % 3 === 2)
567
- inputs[i].forEach((v, j) => inputs[i][j] = j);
568
- else
569
- inputs[i].fill(0);
541
+ if (i % 3 === 2) inputs[i].forEach((v, j) => inputs[i][j] = j);
542
+ else inputs[i].fill(0);
570
543
  }
571
544
  }, (outputs) => {
572
545
  fftProcessorOutputs = outputs;
@@ -591,14 +564,12 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
591
564
  for (let j = 0; j < iffted.length - this.fftHopSize; j++) {
592
565
  $ = mod(this.$outputWrite + j, this.fftBufferSize);
593
566
  this.fftOutput[i][$] += iffted[j];
594
- if (i === 0)
595
- this.windowSumSquare[$] += this.noIFFT ? this.window[j] : this.window[j] ** 2;
567
+ if (i === 0) this.windowSumSquare[$] += this.noIFFT ? this.window[j] : this.window[j] ** 2;
596
568
  }
597
569
  for (let j = iffted.length - this.fftHopSize; j < iffted.length; j++) {
598
570
  $ = mod(this.$outputWrite + j, this.fftBufferSize);
599
571
  this.fftOutput[i][$] = iffted[j];
600
- if (i === 0)
601
- this.windowSumSquare[$] = this.noIFFT ? this.window[j] : this.window[j] ** 2;
572
+ if (i === 0) this.windowSumSquare[$] = this.noIFFT ? this.window[j] : this.window[j] ** 2;
602
573
  }
603
574
  }
604
575
  this.$outputWrite += this.fftHopSize;
@@ -606,10 +577,8 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
606
577
  }
607
578
  }
608
579
  process(inputs, outputs, parameters) {
609
- if (this.destroyed)
610
- return false;
611
- if (!this.FFT)
612
- return true;
580
+ if (this.destroyed) return false;
581
+ if (!this.FFT) return true;
613
582
  const input = inputs[0];
614
583
  const output = outputs[0];
615
584
  const inputChannels = (input == null ? void 0 : input.length) || 0;
@@ -617,11 +586,9 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
617
586
  const bufferSize = (input == null ? void 0 : input.length) ? Math.max(...input.map((c) => c.length)) || 128 : 128;
618
587
  this.noIFFT = !!parameters.noIFFT[0];
619
588
  this.resetFFT(~~parameters.fftSize[0], ~~parameters.fftOverlap[0], ~~parameters.windowFunction[0], inputChannels, outputChannels, bufferSize);
620
- if (!this.fDSPCode)
621
- return true;
589
+ if (!this.fDSPCode) return true;
622
590
  for (const path in parameters) {
623
- if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
624
- continue;
591
+ if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k))) continue;
625
592
  const [paramValue] = parameters[path];
626
593
  if (paramValue !== this.paramValuesCache[path]) {
627
594
  this.setParamValue(path, paramValue);
@@ -715,8 +682,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
715
682
  this.$outputWrite = 0;
716
683
  this.$outputRead = -latency;
717
684
  this.fftBufferSize = Math.max(fftSize * 2 - this.fftHopSize, bufferSize * 2);
718
- if (!fftSizeChanged && this.fftHopSizeParam)
719
- (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(this.fftHopSizeParam, this.fftHopSize);
685
+ if (!fftSizeChanged && this.fftHopSizeParam) (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(this.fftHopSizeParam, this.fftHopSize);
720
686
  }
721
687
  if (fftSizeChanged) {
722
688
  (_b = this.rfft) == null ? void 0 : _b.dispose();
@@ -728,8 +694,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
728
694
  this.windowFunction = windowFunction;
729
695
  this.window = new Float32Array(fftSize);
730
696
  this.window.fill(1);
731
- if (windowFunction)
732
- apply(this.window, windowFunction);
697
+ if (windowFunction) apply(this.window, windowFunction);
733
698
  this.windowSumSquare = new Float32Array(this.fftBufferSize);
734
699
  }
735
700
  if (this.fftInput.length > inputChannels) {
@@ -768,16 +733,13 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
768
733
  const params = this.fDSPCode.getParams();
769
734
  this.fDSPCode.start();
770
735
  for (const path in this.paramValuesCache) {
771
- if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
772
- continue;
736
+ if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k))) continue;
773
737
  this.fDSPCode.setParamValue(path, this.paramValuesCache[path]);
774
738
  }
775
739
  const fftSizeParam = params.find((s) => s.endsWith("/fftSize"));
776
- if (fftSizeParam)
777
- this.fDSPCode.setParamValue(fftSizeParam, this.fftSize);
740
+ if (fftSizeParam) this.fDSPCode.setParamValue(fftSizeParam, this.fftSize);
778
741
  this.fftHopSizeParam = params.find((s) => s.endsWith("/fftHopSize"));
779
- if (this.fftHopSizeParam)
780
- this.fDSPCode.setParamValue(this.fftHopSizeParam, this.fftHopSize);
742
+ if (this.fftHopSizeParam) this.fDSPCode.setParamValue(this.fftHopSizeParam, this.fftHopSize);
781
743
  this.fftProcessorZeros = new Float32Array(this.fftProcessorBufferSize);
782
744
  }
783
745
  destroy() {
@@ -830,8 +792,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
830
792
  }
831
793
  function __generator(thisArg, body) {
832
794
  var _ = { label: 0, sent: function() {
833
- if (t[0] & 1)
834
- throw t[1];
795
+ if (t[0] & 1) throw t[1];
835
796
  return t[1];
836
797
  }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
837
798
  return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
@@ -843,64 +804,58 @@ function __generator(thisArg, body) {
843
804
  };
844
805
  }
845
806
  function step(op) {
846
- if (f)
847
- throw new TypeError("Generator is already executing.");
848
- while (g && (g = 0, op[0] && (_ = 0)), _)
849
- try {
850
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
851
- return t;
852
- if (y = 0, t)
853
- op = [op[0] & 2, t.value];
854
- switch (op[0]) {
855
- case 0:
856
- case 1:
807
+ if (f) throw new TypeError("Generator is already executing.");
808
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
809
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
810
+ if (y = 0, t) op = [op[0] & 2, t.value];
811
+ switch (op[0]) {
812
+ case 0:
813
+ case 1:
814
+ t = op;
815
+ break;
816
+ case 4:
817
+ _.label++;
818
+ return { value: op[1], done: false };
819
+ case 5:
820
+ _.label++;
821
+ y = op[1];
822
+ op = [0];
823
+ continue;
824
+ case 7:
825
+ op = _.ops.pop();
826
+ _.trys.pop();
827
+ continue;
828
+ default:
829
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
830
+ _ = 0;
831
+ continue;
832
+ }
833
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
834
+ _.label = op[1];
835
+ break;
836
+ }
837
+ if (op[0] === 6 && _.label < t[1]) {
838
+ _.label = t[1];
857
839
  t = op;
858
840
  break;
859
- case 4:
860
- _.label++;
861
- return { value: op[1], done: false };
862
- case 5:
863
- _.label++;
864
- y = op[1];
865
- op = [0];
866
- continue;
867
- case 7:
868
- op = _.ops.pop();
869
- _.trys.pop();
870
- continue;
871
- default:
872
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
873
- _ = 0;
874
- continue;
875
- }
876
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
877
- _.label = op[1];
878
- break;
879
- }
880
- if (op[0] === 6 && _.label < t[1]) {
881
- _.label = t[1];
882
- t = op;
883
- break;
884
- }
885
- if (t && _.label < t[2]) {
886
- _.label = t[2];
887
- _.ops.push(op);
888
- break;
889
- }
890
- if (t[2])
891
- _.ops.pop();
892
- _.trys.pop();
893
- continue;
894
- }
895
- op = body.call(thisArg, _);
896
- } catch (e) {
897
- op = [6, e];
898
- y = 0;
899
- } finally {
900
- f = t = 0;
841
+ }
842
+ if (t && _.label < t[2]) {
843
+ _.label = t[2];
844
+ _.ops.push(op);
845
+ break;
846
+ }
847
+ if (t[2]) _.ops.pop();
848
+ _.trys.pop();
849
+ continue;
901
850
  }
902
- if (op[0] & 5)
903
- throw op[1];
851
+ op = body.call(thisArg, _);
852
+ } catch (e) {
853
+ op = [6, e];
854
+ y = 0;
855
+ } finally {
856
+ f = t = 0;
857
+ }
858
+ if (op[0] & 5) throw op[1];
904
859
  return { value: op[0] ? op[1] : void 0, done: true };
905
860
  }
906
861
  }
@@ -989,7 +944,7 @@ var MAX_HASHABLE_LENGTH = Math.pow(2, 53) - 1;
989
944
  // node_modules/@aws-crypto/sha256-js/build/module/RawSha256.js
990
945
  var RawSha256 = (
991
946
  /** @class */
992
- function() {
947
+ (function() {
993
948
  function RawSha2562() {
994
949
  this.state = Int32Array.from(INIT);
995
950
  this.temp = new Int32Array(64);
@@ -1081,7 +1036,7 @@ var RawSha256 = (
1081
1036
  state[7] += state7;
1082
1037
  };
1083
1038
  return RawSha2562;
1084
- }()
1039
+ })()
1085
1040
  );
1086
1041
 
1087
1042
  // node_modules/@smithy/util-utf8/dist-es/fromUtf8.browser.js
@@ -1114,7 +1069,7 @@ function isEmptyData(data) {
1114
1069
  // node_modules/@aws-crypto/sha256-js/build/module/jsSha256.js
1115
1070
  var Sha256 = (
1116
1071
  /** @class */
1117
- function() {
1072
+ (function() {
1118
1073
  function Sha2562(secret) {
1119
1074
  this.secret = secret;
1120
1075
  this.hash = new RawSha256();
@@ -1168,7 +1123,7 @@ var Sha256 = (
1168
1123
  }
1169
1124
  };
1170
1125
  return Sha2562;
1171
- }()
1126
+ })()
1172
1127
  );
1173
1128
  function bufferFromSecret(secret) {
1174
1129
  var input = convertToBuffer(secret);
@@ -1316,8 +1271,7 @@ var _FaustCompiler = class _FaustCompiler {
1316
1271
  async getAsyncInternalMixerModule(isDouble = false) {
1317
1272
  const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
1318
1273
  const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
1319
- if (this[moduleKey])
1320
- return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1274
+ if (this[moduleKey]) return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1321
1275
  const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
1322
1276
  const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
1323
1277
  this[bufferKey] = mixerBuffer;
@@ -1328,8 +1282,7 @@ var _FaustCompiler = class _FaustCompiler {
1328
1282
  getSyncInternalMixerModule(isDouble = false) {
1329
1283
  const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
1330
1284
  const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
1331
- if (this[moduleKey])
1332
- return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1285
+ if (this[moduleKey]) return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1333
1286
  const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
1334
1287
  const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
1335
1288
  this[bufferKey] = mixerBuffer;
@@ -1670,10 +1623,8 @@ var FaustSensors = class _FaustSensors {
1670
1623
  this.fHi = Math.max(x, y);
1671
1624
  }
1672
1625
  clip(x) {
1673
- if (x < this.fLo)
1674
- return this.fLo;
1675
- if (x > this.fHi)
1676
- return this.fHi;
1626
+ if (x < this.fLo) return this.fLo;
1627
+ if (x > this.fHi) return this.fHi;
1677
1628
  return x;
1678
1629
  }
1679
1630
  };
@@ -2082,8 +2033,7 @@ var Soundfile = class _Soundfile {
2082
2033
  console.log(`fSR: ${this.fSR}`);
2083
2034
  console.log(`fOffset: ${this.fOffset}`);
2084
2035
  const HEAP32 = this.fAllocator.getInt32Array();
2085
- if (mem)
2086
- console.log(`HEAP32: ${HEAP32}`);
2036
+ if (mem) console.log(`HEAP32: ${HEAP32}`);
2087
2037
  console.log(`HEAP32[this.fPtr >> 2]: ${HEAP32[this.fPtr >> 2]}`);
2088
2038
  console.log(`HEAP32[(this.fPtr + ptrSize) >> 2]: ${HEAP32[this.fPtr + this.fPtrSize >> 2]}`);
2089
2039
  console.log(`HEAP32[(this.fPtr + 2 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 2 * this.fPtrSize >> 2]}`);
@@ -2137,8 +2087,7 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2137
2087
  this.fInputsItems.push(item.address);
2138
2088
  this.fPathTable[item.address] = item.index;
2139
2089
  this.fDescriptor.push(item);
2140
- if (!item.meta)
2141
- return;
2090
+ if (!item.meta) return;
2142
2091
  item.meta.forEach((meta) => {
2143
2092
  var _a, _b, _c, _d, _e, _f;
2144
2093
  const { midi, acc, gyr } = meta;
@@ -2234,19 +2183,13 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2234
2183
  propagateAcc(accelerationIncludingGravity, invert = false) {
2235
2184
  const { x, y, z } = accelerationIncludingGravity;
2236
2185
  if (invert) {
2237
- if (x !== null)
2238
- this.fAcc.x.forEach((handler) => handler(-x));
2239
- if (y !== null)
2240
- this.fAcc.y.forEach((handler) => handler(-y));
2241
- if (z !== null)
2242
- this.fAcc.z.forEach((handler) => handler(-z));
2186
+ if (x !== null) this.fAcc.x.forEach((handler) => handler(-x));
2187
+ if (y !== null) this.fAcc.y.forEach((handler) => handler(-y));
2188
+ if (z !== null) this.fAcc.z.forEach((handler) => handler(-z));
2243
2189
  } else {
2244
- if (x !== null)
2245
- this.fAcc.x.forEach((handler) => handler(x));
2246
- if (y !== null)
2247
- this.fAcc.y.forEach((handler) => handler(y));
2248
- if (z !== null)
2249
- this.fAcc.z.forEach((handler) => handler(z));
2190
+ if (x !== null) this.fAcc.x.forEach((handler) => handler(x));
2191
+ if (y !== null) this.fAcc.y.forEach((handler) => handler(y));
2192
+ if (z !== null) this.fAcc.z.forEach((handler) => handler(z));
2250
2193
  }
2251
2194
  }
2252
2195
  get hasGyrInput() {
@@ -2254,12 +2197,9 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2254
2197
  }
2255
2198
  propagateGyr(event) {
2256
2199
  const { alpha, beta, gamma } = event;
2257
- if (alpha !== null)
2258
- this.fGyr.x.forEach((handler) => handler(alpha));
2259
- if (beta !== null)
2260
- this.fGyr.y.forEach((handler) => handler(beta));
2261
- if (gamma !== null)
2262
- this.fGyr.z.forEach((handler) => handler(gamma));
2200
+ if (alpha !== null) this.fGyr.x.forEach((handler) => handler(alpha));
2201
+ if (beta !== null) this.fGyr.y.forEach((handler) => handler(beta));
2202
+ if (gamma !== null) this.fGyr.z.forEach((handler) => handler(gamma));
2263
2203
  }
2264
2204
  /** Build the accelerometer handler */
2265
2205
  setupAccHandler(path, axis, curve, amin, amid, amax, min, init, max) {
@@ -2314,8 +2254,7 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2314
2254
  console.log(`Soundfile ${name} paths: ${url}`);
2315
2255
  const soundfileIds = _FaustBaseWebAudioDsp.splitSoundfileNames(url);
2316
2256
  const item = this.fSoundfiles.find((item2) => item2.url === url);
2317
- if (!item)
2318
- throw new Error(`Soundfile with ${url} cannot be found !}`);
2257
+ if (!item) throw new Error(`Soundfile with ${url} cannot be found !}`);
2319
2258
  if (item.basePtr !== -1) {
2320
2259
  const HEAP32 = allocator.getInt32Array();
2321
2260
  console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
@@ -2430,16 +2369,13 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2430
2369
  return -1;
2431
2370
  }
2432
2371
  midiMessage(data) {
2433
- if (this.fPlotHandler)
2434
- this.fCachedEvents.push({ data, type: "midi" });
2372
+ if (this.fPlotHandler) this.fCachedEvents.push({ data, type: "midi" });
2435
2373
  const cmd = data[0] >> 4;
2436
2374
  const channel = data[0] & 15;
2437
2375
  const data1 = data[1];
2438
2376
  const data2 = data[2];
2439
- if (cmd === 11)
2440
- return this.ctrlChange(channel, data1, data2);
2441
- if (cmd === 14)
2442
- return this.pitchWheel(channel, data2 * 128 + data1);
2377
+ if (cmd === 11) return this.ctrlChange(channel, data1, data2);
2378
+ if (cmd === 14) return this.pitchWheel(channel, data2 * 128 + data1);
2443
2379
  if (cmd === 9) {
2444
2380
  if (data2 > 0)
2445
2381
  return this.keyOn(channel, data1, data2);
@@ -2451,68 +2387,58 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2451
2387
  }
2452
2388
  }
2453
2389
  ctrlChange(channel, ctrl, value) {
2454
- if (this.fPlotHandler)
2455
- this.fCachedEvents.push({ type: "ctrlChange", data: [channel, ctrl, value] });
2390
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "ctrlChange", data: [channel, ctrl, value] });
2456
2391
  if (this.fCtrlLabel[ctrl].length) {
2457
2392
  this.fCtrlLabel[ctrl].forEach((ctrl2) => {
2458
2393
  const { path, chan } = ctrl2;
2459
2394
  if (chan === 0 || channel === chan - 1) {
2460
2395
  this.setParamValue(path, _FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
2461
- if (this.fOutputHandler)
2462
- this.fOutputHandler(path, this.getParamValue(path));
2396
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
2463
2397
  }
2464
2398
  });
2465
2399
  }
2466
2400
  }
2467
2401
  keyOn(channel, pitch, velocity) {
2468
- if (this.fPlotHandler)
2469
- this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
2402
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
2470
2403
  this.fMidiKeyOnLabel[pitch].forEach((key) => {
2471
2404
  const { path, chan } = key;
2472
2405
  if (chan === 0 || channel === chan - 1) {
2473
2406
  this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2474
- if (this.fOutputHandler)
2475
- this.fOutputHandler(path, this.getParamValue(path));
2407
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
2476
2408
  }
2477
2409
  });
2478
2410
  this.fMidiKeyLabel[pitch].forEach((key) => {
2479
2411
  const { path, chan } = key;
2480
2412
  if (chan === 0 || channel === chan - 1) {
2481
2413
  this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2482
- if (this.fOutputHandler)
2483
- this.fOutputHandler(path, this.getParamValue(path));
2414
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
2484
2415
  }
2485
2416
  });
2486
2417
  }
2487
2418
  keyOff(channel, pitch, velocity) {
2488
- if (this.fPlotHandler)
2489
- this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
2419
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
2490
2420
  this.fMidiKeyOffLabel[pitch].forEach((key) => {
2491
2421
  const { path, chan } = key;
2492
2422
  if (chan === 0 || channel === chan - 1) {
2493
2423
  this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2494
- if (this.fOutputHandler)
2495
- this.fOutputHandler(path, this.getParamValue(path));
2424
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
2496
2425
  }
2497
2426
  });
2498
2427
  this.fMidiKeyLabel[pitch].forEach((key) => {
2499
2428
  const { path, chan } = key;
2500
2429
  if (chan === 0 || channel === chan - 1) {
2501
2430
  this.setParamValue(path, 0);
2502
- if (this.fOutputHandler)
2503
- this.fOutputHandler(path, this.getParamValue(path));
2431
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
2504
2432
  }
2505
2433
  });
2506
2434
  }
2507
2435
  pitchWheel(channel, wheel) {
2508
- if (this.fPlotHandler)
2509
- this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
2436
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
2510
2437
  this.fPitchwheelLabel.forEach((pw) => {
2511
2438
  const { path, chan } = pw;
2512
2439
  if (chan === 0 || channel === chan - 1) {
2513
2440
  this.setParamValue(path, _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
2514
- if (this.fOutputHandler)
2515
- this.fOutputHandler(path, this.getParamValue(path));
2441
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
2516
2442
  }
2517
2443
  });
2518
2444
  }
@@ -2613,10 +2539,8 @@ var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
2613
2539
  }
2614
2540
  // Public API
2615
2541
  compute(input, output) {
2616
- if (this.fDestroyed)
2617
- return false;
2618
- if (!this.fProcessing)
2619
- return true;
2542
+ if (this.fDestroyed) return false;
2543
+ if (!this.fProcessing) return true;
2620
2544
  if (this.fFirstCall) {
2621
2545
  this.initMemory();
2622
2546
  this.fFirstCall = false;
@@ -2637,8 +2561,7 @@ var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
2637
2561
  }
2638
2562
  }
2639
2563
  }
2640
- if (this.fComputeHandler)
2641
- this.fComputeHandler(this.fBufferSize);
2564
+ if (this.fComputeHandler) this.fComputeHandler(this.fBufferSize);
2642
2565
  this.fInstance.api.compute(this.fDSP, this.fBufferSize, this.fAudioInputs, this.fAudioOutputs);
2643
2566
  this.updateOutputs();
2644
2567
  let forPlot = this.fOutChannels;
@@ -2667,8 +2590,7 @@ var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
2667
2590
  return this.fInstance.api.getNumOutputs(this.fDSP);
2668
2591
  }
2669
2592
  setParamValue(path, value) {
2670
- if (this.fPlotHandler)
2671
- this.fCachedEvents.push({ type: "param", data: { path, value } });
2593
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "param", data: { path, value } });
2672
2594
  this.fInstance.api.setParamValue(this.fDSP, this.fPathTable[path], value);
2673
2595
  }
2674
2596
  getParamValue(path) {
@@ -2794,8 +2716,7 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
2794
2716
  this.fJSONDsp = JSON.parse(this.fInstance.voiceJSON);
2795
2717
  this.fJSONEffect = this.fInstance.effectAPI && this.fInstance.effectJSON ? JSON.parse(this.fInstance.effectJSON) : null;
2796
2718
  FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
2797
- if (this.fJSONEffect)
2798
- FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
2719
+ if (this.fJSONEffect) FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
2799
2720
  this.fEndMemory = this.initMemory();
2800
2721
  this.fVoiceTable = [];
2801
2722
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
@@ -2807,8 +2728,7 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
2807
2728
  sampleRate
2808
2729
  ));
2809
2730
  }
2810
- if (this.fInstance.effectAPI)
2811
- this.fInstance.effectAPI.init(this.fEffect, sampleRate);
2731
+ if (this.fInstance.effectAPI) this.fInstance.effectAPI.init(this.fEffect, sampleRate);
2812
2732
  if (this.fSoundfiles.length > 0) {
2813
2733
  const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
2814
2734
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
@@ -2914,14 +2834,12 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
2914
2834
  }
2915
2835
  // Public API
2916
2836
  compute(input, output) {
2917
- if (this.fDestroyed)
2918
- return false;
2837
+ if (this.fDestroyed) return false;
2919
2838
  if (this.fFirstCall) {
2920
2839
  this.initMemory();
2921
2840
  this.fFirstCall = false;
2922
2841
  }
2923
- if (!this.fProcessing)
2924
- return true;
2842
+ if (!this.fProcessing) return true;
2925
2843
  if (this.getNumInputs() > 0 && (!input || !input[0] || input[0].length === 0)) {
2926
2844
  return true;
2927
2845
  }
@@ -2934,8 +2852,7 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
2934
2852
  dspInput.set(input[chan]);
2935
2853
  }
2936
2854
  }
2937
- if (this.fComputeHandler)
2938
- this.fComputeHandler(this.fBufferSize);
2855
+ if (this.fComputeHandler) this.fComputeHandler(this.fBufferSize);
2939
2856
  this.fInstance.mixerAPI.clearOutput(this.fBufferSize, this.getNumOutputs(), this.fAudioOutputs);
2940
2857
  this.fVoiceTable.forEach((voice) => {
2941
2858
  if (voice.fCurNote === FaustWebAudioDspVoice.kLegatoVoice) {
@@ -2950,8 +2867,7 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
2950
2867
  }
2951
2868
  }
2952
2869
  });
2953
- if (this.fInstance.effectAPI)
2954
- this.fInstance.effectAPI.compute(this.fEffect, this.fBufferSize, this.fAudioOutputs, this.fAudioOutputs);
2870
+ if (this.fInstance.effectAPI) this.fInstance.effectAPI.compute(this.fEffect, this.fBufferSize, this.fAudioOutputs, this.fAudioOutputs);
2955
2871
  this.updateOutputs();
2956
2872
  if (output !== void 0) {
2957
2873
  for (let chan = 0; chan < Math.min(this.getNumOutputs(), output.length); chan++) {
@@ -2978,15 +2894,13 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
2978
2894
  return o.address === p;
2979
2895
  } else {
2980
2896
  for (const k in o) {
2981
- if (_FaustPolyWebAudioDsp.findPath(o[k], p))
2982
- return true;
2897
+ if (_FaustPolyWebAudioDsp.findPath(o[k], p)) return true;
2983
2898
  }
2984
2899
  return false;
2985
2900
  }
2986
2901
  }
2987
2902
  setParamValue(path, value) {
2988
- if (this.fPlotHandler)
2989
- this.fCachedEvents.push({ type: "param", data: { path, value } });
2903
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "param", data: { path, value } });
2990
2904
  if (this.fJSONEffect && _FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2991
2905
  this.fInstance.effectAPI.setParamValue(this.fEffect, this.fPathTable[path], value);
2992
2906
  } else {
@@ -3038,12 +2952,9 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
3038
2952
  const channel = data[0] & 15;
3039
2953
  const data1 = data[1];
3040
2954
  const data2 = data[2];
3041
- if (cmd === 8 || cmd === 9 && data2 === 0)
3042
- return this.keyOff(channel, data1, data2);
3043
- else if (cmd === 9)
3044
- return this.keyOn(channel, data1, data2);
3045
- else
3046
- super.midiMessage(data);
2955
+ if (cmd === 8 || cmd === 9 && data2 === 0) return this.keyOff(channel, data1, data2);
2956
+ else if (cmd === 9) return this.keyOn(channel, data1, data2);
2957
+ else super.midiMessage(data);
3047
2958
  }
3048
2959
  ctrlChange(channel, ctrl, value) {
3049
2960
  if (ctrl === 123 || ctrl === 120) {
@@ -3053,14 +2964,12 @@ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudio
3053
2964
  }
3054
2965
  }
3055
2966
  keyOn(channel, pitch, velocity) {
3056
- if (this.fPlotHandler)
3057
- this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
2967
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
3058
2968
  const voice = this.getFreeVoice();
3059
2969
  this.fVoiceTable[voice].keyOn(pitch, velocity, this.fVoiceTable[voice].fCurNote == FaustWebAudioDspVoice.kLegatoVoice);
3060
2970
  }
3061
2971
  keyOff(channel, pitch, velocity) {
3062
- if (this.fPlotHandler)
3063
- this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
2972
+ if (this.fPlotHandler) this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
3064
2973
  const voice = this.getPlayingVoice(pitch);
3065
2974
  if (voice !== FaustWebAudioDspVoice.kNoVoice) {
3066
2975
  this.fVoiceTable[voice].keyOff();
@@ -3096,8 +3005,7 @@ var FaustOfflineProcessor = class {
3096
3005
  param = { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
3097
3006
  }
3098
3007
  }
3099
- if (param)
3100
- params.push(param);
3008
+ if (param) params.push(param);
3101
3009
  };
3102
3010
  FaustBaseWebAudioDsp.parseUI(this.fDSPCode.getUI(), callback);
3103
3011
  return params;
@@ -3268,8 +3176,7 @@ var FaustSvgDiagrams = class {
3268
3176
  } catch {
3269
3177
  }
3270
3178
  const success = this.compiler.generateAuxFiles(name, code, `-lang wasm -o binary -svg ${args}`);
3271
- if (!success)
3272
- throw new Error(this.compiler.getErrorMessage());
3179
+ if (!success) throw new Error(this.compiler.getErrorMessage());
3273
3180
  const svgs = {};
3274
3181
  const files = fs.readdir(`/${name}-svg/`);
3275
3182
  files.filter((file) => file !== "." && file !== "..").forEach((file) => svgs[file] = fs.readFile(`/${name}-svg/${file}`, { encoding: "utf8" }));
@@ -3772,8 +3679,7 @@ var SoundfileReader = class {
3772
3679
  static async fetchSoundfile(url, audioCtx) {
3773
3680
  console.log(`Loading sound file from ${url}`);
3774
3681
  const response = await fetch(url);
3775
- if (!response.ok)
3776
- throw new Error(`Failed to load sound file from ${url}: ${response.statusText}`);
3682
+ if (!response.ok) throw new Error(`Failed to load sound file from ${url}: ${response.statusText}`);
3777
3683
  const arrayBuffer = await response.arrayBuffer();
3778
3684
  const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
3779
3685
  return this.toAudioData(audioBuffer);
@@ -3787,13 +3693,11 @@ var SoundfileReader = class {
3787
3693
  * @param audioCtx : the audio context
3788
3694
  */
3789
3695
  static async loadSoundfile(filename, metaUrls, soundfiles, audioCtx) {
3790
- if (soundfiles[filename])
3791
- return;
3696
+ if (soundfiles[filename]) return;
3792
3697
  const urlsToCheck = [filename, ...[...metaUrls, ...this.fallbackPaths].map((path) => new URL(filename, path.endsWith("/") ? path : `${path}/`).href)];
3793
3698
  const checkResults = await Promise.all(urlsToCheck.map((url) => this.checkFileExists(url)));
3794
3699
  const successIndex = checkResults.findIndex((r) => !!r);
3795
- if (successIndex === -1)
3796
- throw new Error(`Failed to load sound file ${filename}, all check failed.`);
3700
+ if (successIndex === -1) throw new Error(`Failed to load sound file ${filename}, all check failed.`);
3797
3701
  soundfiles[filename] = await this.fetchSoundfile(urlsToCheck[successIndex], audioCtx);
3798
3702
  }
3799
3703
  /**
@@ -3846,8 +3750,7 @@ var FaustAudioWorkletCommunicator = class {
3846
3750
  ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
3847
3751
  }
3848
3752
  setNewAccDataAvailable(value) {
3849
- if (!this.uin8NewAccData)
3850
- return;
3753
+ if (!this.uin8NewAccData) return;
3851
3754
  this.uin8NewAccData[0] = +value;
3852
3755
  }
3853
3756
  getNewAccDataAvailable() {
@@ -3855,8 +3758,7 @@ var FaustAudioWorkletCommunicator = class {
3855
3758
  return !!((_a = this.uin8NewAccData) == null ? void 0 : _a[0]);
3856
3759
  }
3857
3760
  setNewGyrDataAvailable(value) {
3858
- if (!this.uin8NewGyrData)
3859
- return;
3761
+ if (!this.uin8NewGyrData) return;
3860
3762
  this.uin8NewGyrData[0] = +value;
3861
3763
  }
3862
3764
  getNewGyrDataAvailable() {
@@ -3868,8 +3770,7 @@ var FaustAudioWorkletCommunicator = class {
3868
3770
  const e = { type: "acc", data: { x, y, z }, invert };
3869
3771
  this.port.postMessage(e);
3870
3772
  }
3871
- if (!this.uin8NewAccData)
3872
- return;
3773
+ if (!this.uin8NewAccData) return;
3873
3774
  this.uin8Invert[0] = +invert;
3874
3775
  this.f32Acc[0] = x;
3875
3776
  this.f32Acc[1] = y;
@@ -3877,8 +3778,7 @@ var FaustAudioWorkletCommunicator = class {
3877
3778
  this.uin8NewAccData[0] = 1;
3878
3779
  }
3879
3780
  getAcc() {
3880
- if (!this.uin8NewAccData)
3881
- return;
3781
+ if (!this.uin8NewAccData) return;
3882
3782
  const invert = !!this.uin8Invert[0];
3883
3783
  const [x, y, z] = this.f32Acc;
3884
3784
  return { x, y, z, invert };
@@ -3888,16 +3788,14 @@ var FaustAudioWorkletCommunicator = class {
3888
3788
  const e = { type: "gyr", data: { alpha, beta, gamma } };
3889
3789
  this.port.postMessage(e);
3890
3790
  }
3891
- if (!this.uin8NewGyrData)
3892
- return;
3791
+ if (!this.uin8NewGyrData) return;
3893
3792
  this.f32Gyr[0] = alpha;
3894
3793
  this.f32Gyr[1] = beta;
3895
3794
  this.f32Gyr[2] = gamma;
3896
3795
  this.uin8NewGyrData[0] = 1;
3897
3796
  }
3898
3797
  getGyr() {
3899
- if (!this.uin8NewGyrData)
3900
- return;
3798
+ if (!this.uin8NewGyrData) return;
3901
3799
  const [alpha, beta, gamma] = this.f32Gyr;
3902
3800
  return { alpha, beta, gamma };
3903
3801
  }
@@ -3931,6 +3829,7 @@ var FaustAudioWorkletProcessorCommunicator = class extends FaustAudioWorkletComm
3931
3829
  this.port.addEventListener("message", (event) => {
3932
3830
  const msg = event.data;
3933
3831
  switch (msg.type) {
3832
+ // Sensors messages
3934
3833
  case "acc": {
3935
3834
  this.setAcc(msg.data, msg.invert);
3936
3835
  break;
@@ -3974,8 +3873,7 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3974
3873
  // Accelerometer and gyroscope handlers
3975
3874
  this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3976
3875
  const isAndroid = /Android/i.test(navigator.userAgent);
3977
- if (!accelerationIncludingGravity)
3978
- return;
3876
+ if (!accelerationIncludingGravity) return;
3979
3877
  const { x, y, z } = accelerationIncludingGravity;
3980
3878
  this.propagateAcc({ x, y, z }, isAndroid);
3981
3879
  };
@@ -3993,14 +3891,11 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3993
3891
  if (item.type === "vslider" || item.type === "hslider" || item.type === "button" || item.type === "checkbox" || item.type === "nentry") {
3994
3892
  this.fInputsItems.push(item.address);
3995
3893
  this.fDescriptor.push(item);
3996
- if (!item.meta)
3997
- return;
3894
+ if (!item.meta) return;
3998
3895
  item.meta.forEach((meta) => {
3999
3896
  const { midi, acc, gyr } = meta;
4000
- if (acc)
4001
- __privateSet(this, _hasAccInput, true);
4002
- if (gyr)
4003
- __privateSet(this, _hasGyrInput, true);
3897
+ if (acc) __privateSet(this, _hasAccInput, true);
3898
+ if (gyr) __privateSet(this, _hasGyrInput, true);
4004
3899
  });
4005
3900
  }
4006
3901
  };
@@ -4088,16 +3983,11 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
4088
3983
  const channel = data[0] & 15;
4089
3984
  const data1 = data[1];
4090
3985
  const data2 = data[2];
4091
- if (cmd === 11)
4092
- this.ctrlChange(channel, data1, data2);
4093
- else if (cmd === 14)
4094
- this.pitchWheel(channel, data2 * 128 + data1);
4095
- if (cmd === 8 || cmd === 9 && data2 === 0)
4096
- this.keyOff(channel, data1, data2);
4097
- else if (cmd === 9)
4098
- this.keyOn(channel, data1, data2);
4099
- else
4100
- this.port.postMessage({ type: "midi", data });
3986
+ if (cmd === 11) this.ctrlChange(channel, data1, data2);
3987
+ else if (cmd === 14) this.pitchWheel(channel, data2 * 128 + data1);
3988
+ if (cmd === 8 || cmd === 9 && data2 === 0) this.keyOff(channel, data1, data2);
3989
+ else if (cmd === 9) this.keyOn(channel, data1, data2);
3990
+ else this.port.postMessage({ type: "midi", data });
4101
3991
  }
4102
3992
  ctrlChange(channel, ctrl, value) {
4103
3993
  const e = { type: "ctrlChange", data: [channel, ctrl, value] };
@@ -4119,8 +4009,7 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
4119
4009
  return __privateGet(this, _hasAccInput);
4120
4010
  }
4121
4011
  propagateAcc(accelerationIncludingGravity, invert = false) {
4122
- if (!accelerationIncludingGravity)
4123
- return;
4012
+ if (!accelerationIncludingGravity) return;
4124
4013
  const { x, y, z } = accelerationIncludingGravity;
4125
4014
  this.fCommunicator.setAcc({ x, y, z }, invert);
4126
4015
  }
@@ -4128,8 +4017,7 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
4128
4017
  return __privateGet(this, _hasGyrInput);
4129
4018
  }
4130
4019
  propagateGyr(event) {
4131
- if (!event)
4132
- return;
4020
+ if (!event) return;
4133
4021
  const { alpha, beta, gamma } = event;
4134
4022
  this.fCommunicator.setGyr({ alpha, beta, gamma });
4135
4023
  }
@@ -4137,8 +4025,7 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
4137
4025
  const e = { type: "param", data: { path, value } };
4138
4026
  this.port.postMessage(e);
4139
4027
  const param = this.parameters.get(path);
4140
- if (param)
4141
- param.setValueAtTime(value, this.context.currentTime);
4028
+ if (param) param.setValueAtTime(value, this.context.currentTime);
4142
4029
  }
4143
4030
  getParamValue(path) {
4144
4031
  const param = this.parameters.get(path);
@@ -4254,8 +4141,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
4254
4141
  this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
4255
4142
  this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
4256
4143
  const isAndroid = /Android/i.test(navigator.userAgent);
4257
- if (!accelerationIncludingGravity)
4258
- return;
4144
+ if (!accelerationIncludingGravity) return;
4259
4145
  const { x, y, z } = accelerationIncludingGravity;
4260
4146
  this.propagateAcc({ x, y, z }, isAndroid);
4261
4147
  };
@@ -4419,23 +4305,20 @@ var _FaustMonoDspGenerator = class _FaustMonoDspGenerator {
4419
4305
  }
4420
4306
  }
4421
4307
  addSoundfiles(soundfileMap) {
4422
- if (!this.factory)
4423
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4308
+ if (!this.factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4424
4309
  for (const id in soundfileMap) {
4425
4310
  this.factory.soundfiles[id] = soundfileMap[id];
4426
4311
  }
4427
4312
  }
4428
4313
  getSoundfileList() {
4429
- if (!this.factory)
4430
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4314
+ if (!this.factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4431
4315
  const meta = JSON.parse(this.factory.json);
4432
4316
  const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
4433
4317
  return Object.keys(map);
4434
4318
  }
4435
4319
  async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name, processorOptions = {}) {
4436
4320
  var _a, _b;
4437
- if (!factory)
4438
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4321
+ if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4439
4322
  const meta = JSON.parse(factory.json);
4440
4323
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
4441
4324
  factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
@@ -4447,8 +4330,7 @@ var _FaustMonoDspGenerator = class _FaustMonoDspGenerator {
4447
4330
  sp2.init(monoDsp);
4448
4331
  return sp2;
4449
4332
  } else {
4450
- if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
4451
- _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
4333
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context)) _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
4452
4334
  if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
4453
4335
  try {
4454
4336
  const processorCode = `
@@ -4501,13 +4383,11 @@ const dependencies = {
4501
4383
  }
4502
4384
  async createFFTNode(context, fftUtils, name = this.name, factory = this.factory, fftOptions = {}, processorName = (factory == null ? void 0 : factory.shaKey) ? `${factory.shaKey}_fft` : name, processorOptions = {}) {
4503
4385
  var _a, _b;
4504
- if (!factory)
4505
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4386
+ if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4506
4387
  const meta = JSON.parse(factory.json);
4507
4388
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
4508
4389
  factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
4509
- if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
4510
- _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
4390
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context)) _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
4511
4391
  if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
4512
4392
  try {
4513
4393
  const processorCode = `
@@ -4559,29 +4439,24 @@ const dependencies = {
4559
4439
  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 } });
4560
4440
  if (fftOptions.fftSize) {
4561
4441
  const param = node.parameters.get("fftSize");
4562
- if (param)
4563
- param.value = fftOptions.fftSize;
4442
+ if (param) param.value = fftOptions.fftSize;
4564
4443
  }
4565
4444
  if (fftOptions.fftOverlap) {
4566
4445
  const param = node.parameters.get("fftOverlap");
4567
- if (param)
4568
- param.value = fftOptions.fftOverlap;
4446
+ if (param) param.value = fftOptions.fftOverlap;
4569
4447
  }
4570
4448
  if (typeof fftOptions.defaultWindowFunction === "number") {
4571
4449
  const param = node.parameters.get("windowFunction");
4572
- if (param)
4573
- param.value = fftOptions.defaultWindowFunction + 1;
4450
+ if (param) param.value = fftOptions.defaultWindowFunction + 1;
4574
4451
  }
4575
4452
  if (typeof fftOptions.noIFFT === "boolean") {
4576
4453
  const param = node.parameters.get("noIFFT");
4577
- if (param)
4578
- param.value = +fftOptions.noIFFT;
4454
+ if (param) param.value = +fftOptions.noIFFT;
4579
4455
  }
4580
4456
  return node;
4581
4457
  }
4582
4458
  async createAudioWorkletProcessor(name = this.name, factory = this.factory, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
4583
- if (!factory)
4584
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4459
+ if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4585
4460
  const meta = JSON.parse(factory.json);
4586
4461
  const dependencies = {
4587
4462
  FaustBaseWebAudioDsp,
@@ -4605,13 +4480,11 @@ const dependencies = {
4605
4480
  }
4606
4481
  }
4607
4482
  async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory, context) {
4608
- if (!factory)
4609
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4483
+ if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4610
4484
  const meta = JSON.parse(factory.json);
4611
4485
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
4612
4486
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
4613
- if (context)
4614
- factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
4487
+ if (context) factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
4615
4488
  const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
4616
4489
  return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
4617
4490
  }
@@ -4702,33 +4575,28 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
4702
4575
  }
4703
4576
  }
4704
4577
  addSoundfiles(soundfileMap) {
4705
- if (!this.voiceFactory)
4706
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4578
+ if (!this.voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4707
4579
  for (const id in soundfileMap) {
4708
4580
  this.voiceFactory.soundfiles[id] = soundfileMap[id];
4709
4581
  }
4710
4582
  }
4711
4583
  getSoundfileList() {
4712
- if (!this.voiceFactory)
4713
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4584
+ if (!this.voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4714
4585
  const meta = JSON.parse(this.voiceFactory.json);
4715
4586
  const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
4716
- if (!this.effectFactory)
4717
- return Object.keys(map);
4587
+ if (!this.effectFactory) return Object.keys(map);
4718
4588
  const effectMeta = JSON.parse(this.effectFactory.json);
4719
4589
  const effectMap = SoundfileReader_default.findSoundfilesFromMeta(effectMeta);
4720
4590
  return Object.keys({ ...effectMap, ...map });
4721
4591
  }
4722
4592
  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 = {}) {
4723
4593
  var _a, _b;
4724
- if (!voiceFactory)
4725
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4594
+ if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4726
4595
  const voiceMeta = JSON.parse(voiceFactory.json);
4727
4596
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4728
4597
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
4729
4598
  voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
4730
- if (effectFactory)
4731
- effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
4599
+ if (effectFactory) effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
4732
4600
  if (sp) {
4733
4601
  const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
4734
4602
  const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
@@ -4738,8 +4606,7 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
4738
4606
  sp2.init(polyDsp);
4739
4607
  return sp2;
4740
4608
  } else {
4741
- if (!_FaustPolyDspGenerator.gWorkletProcessors.has(context))
4742
- _FaustPolyDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
4609
+ if (!_FaustPolyDspGenerator.gWorkletProcessors.has(context)) _FaustPolyDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
4743
4610
  if (!((_a = _FaustPolyDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
4744
4611
  try {
4745
4612
  const processorCode = `
@@ -4794,8 +4661,7 @@ const dependencies = {
4794
4661
  }
4795
4662
  }
4796
4663
  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`) {
4797
- if (!voiceFactory)
4798
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4664
+ if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4799
4665
  const voiceMeta = JSON.parse(voiceFactory.json);
4800
4666
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4801
4667
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
@@ -4822,16 +4688,14 @@ const dependencies = {
4822
4688
  }
4823
4689
  }
4824
4690
  async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, context) {
4825
- if (!voiceFactory)
4826
- throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4691
+ if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
4827
4692
  const voiceMeta = JSON.parse(voiceFactory.json);
4828
4693
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4829
4694
  const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
4830
4695
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
4831
4696
  if (context) {
4832
4697
  voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
4833
- if (effectFactory)
4834
- effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
4698
+ if (effectFactory) effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
4835
4699
  }
4836
4700
  const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
4837
4701
  const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);