@grame/faustwasm 0.12.2 → 0.13.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.
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 +1593 -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 +1592 -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 +1595 -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 +1593 -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 +1595 -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 +589 -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 +1593 -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 +181 -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
@@ -1,28 +1,58 @@
1
- import { ComputeHandler, FaustBaseWebAudioDsp, FaustMonoWebAudioDsp, FaustPolyWebAudioDsp, IFaustBaseWebAudioDsp, IFaustMonoWebAudioDsp, IFaustPolyWebAudioDsp, MetadataHandler, OutputParamHandler, PlotHandler } from "./FaustWebAudioDsp";
2
- import { AudioParamDescriptor, FaustUIItem } from "./types";
1
+ import {
2
+ ComputeHandler,
3
+ FaustBaseWebAudioDsp,
4
+ FaustMonoWebAudioDsp,
5
+ FaustPolyWebAudioDsp,
6
+ IFaustBaseWebAudioDsp,
7
+ IFaustMonoWebAudioDsp,
8
+ IFaustPolyWebAudioDsp,
9
+ MetadataHandler,
10
+ OutputParamHandler,
11
+ PlotHandler
12
+ } from './FaustWebAudioDsp';
13
+ import { AudioParamDescriptor, FaustUIItem } from './types';
3
14
 
4
15
  /**
5
16
  * For offline rendering.
6
17
  */
7
18
  export interface IFaustOfflineProcessor extends IFaustBaseWebAudioDsp {
8
- render(inputs?: Float32Array[], length?: number, onUpdate?: (sample: number) => any): Float32Array[];
19
+ render(
20
+ inputs?: Float32Array[],
21
+ length?: number,
22
+ onUpdate?: (sample: number) => any
23
+ ): Float32Array[];
9
24
  }
10
25
 
11
- export interface IFaustMonoOfflineProcessor extends IFaustOfflineProcessor, IFaustMonoWebAudioDsp { }
12
- export interface IFaustPolyOfflineProcessor extends IFaustOfflineProcessor, IFaustPolyWebAudioDsp { }
26
+ export interface IFaustMonoOfflineProcessor
27
+ extends IFaustOfflineProcessor,
28
+ IFaustMonoWebAudioDsp {}
29
+ export interface IFaustPolyOfflineProcessor
30
+ extends IFaustOfflineProcessor,
31
+ IFaustPolyWebAudioDsp {}
13
32
 
14
33
  export class FaustOfflineProcessor<Poly extends boolean = false> {
15
- protected fDSPCode!: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp;
34
+ protected fDSPCode!: Poly extends true
35
+ ? FaustPolyWebAudioDsp
36
+ : FaustMonoWebAudioDsp;
16
37
 
17
38
  protected fBufferSize: number;
18
39
  protected fInputs: Float32Array[];
19
40
  protected fOutputs: Float32Array[];
20
41
 
21
- constructor(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp, bufferSize: number) {
42
+ constructor(
43
+ instance: Poly extends true
44
+ ? FaustPolyWebAudioDsp
45
+ : FaustMonoWebAudioDsp,
46
+ bufferSize: number
47
+ ) {
22
48
  this.fDSPCode = instance;
23
49
  this.fBufferSize = bufferSize;
24
- this.fInputs = new Array(this.fDSPCode.getNumInputs()).fill(null).map(() => new Float32Array(bufferSize));
25
- this.fOutputs = new Array(this.fDSPCode.getNumOutputs()).fill(null).map(() => new Float32Array(bufferSize));
50
+ this.fInputs = new Array(this.fDSPCode.getNumInputs())
51
+ .fill(null)
52
+ .map(() => new Float32Array(bufferSize));
53
+ this.fOutputs = new Array(this.fDSPCode.getNumOutputs())
54
+ .fill(null)
55
+ .map(() => new Float32Array(bufferSize));
26
56
  }
27
57
 
28
58
  // Public API
@@ -32,75 +62,160 @@ export class FaustOfflineProcessor<Poly extends boolean = false> {
32
62
  // Analyse voice JSON to generate AudioParam parameters
33
63
  const callback = (item: FaustUIItem) => {
34
64
  let param: AudioParamDescriptor | null = null;
35
- const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
36
- const isPolyReserved = "address" in item && !!polyKeywords.find(k => item.address.endsWith(k));
37
- if (this.fDSPCode instanceof FaustMonoWebAudioDsp || !isPolyReserved) {
38
- if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
39
- param = { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
40
- } else if (item.type === "button" || item.type === "checkbox") {
41
- param = { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
65
+ const polyKeywords = [
66
+ '/gate',
67
+ '/freq',
68
+ '/gain',
69
+ '/key',
70
+ '/vel',
71
+ '/velocity'
72
+ ];
73
+ const isPolyReserved =
74
+ 'address' in item &&
75
+ !!polyKeywords.find((k) => item.address.endsWith(k));
76
+ if (
77
+ this.fDSPCode instanceof FaustMonoWebAudioDsp ||
78
+ !isPolyReserved
79
+ ) {
80
+ if (
81
+ item.type === 'vslider' ||
82
+ item.type === 'hslider' ||
83
+ item.type === 'nentry'
84
+ ) {
85
+ param = {
86
+ name: item.address,
87
+ defaultValue: item.init || 0,
88
+ minValue: item.min || 0,
89
+ maxValue: item.max || 0
90
+ };
91
+ } else if (item.type === 'button' || item.type === 'checkbox') {
92
+ param = {
93
+ name: item.address,
94
+ defaultValue: item.init || 0,
95
+ minValue: 0,
96
+ maxValue: 1
97
+ };
42
98
  }
43
99
  }
44
100
  if (param) params.push(param);
45
- }
101
+ };
46
102
  FaustBaseWebAudioDsp.parseUI(this.fDSPCode.getUI(), callback);
47
103
  return params;
48
104
  }
49
- compute(input: Float32Array[], output: Float32Array[]) { return this.fDSPCode.compute(input, output); }
105
+ compute(input: Float32Array[], output: Float32Array[]) {
106
+ return this.fDSPCode.compute(input, output);
107
+ }
50
108
 
51
- setOutputParamHandler(handler: OutputParamHandler) { this.fDSPCode.setOutputParamHandler(handler); }
52
- getOutputParamHandler() { return this.fDSPCode.getOutputParamHandler(); }
109
+ setOutputParamHandler(handler: OutputParamHandler) {
110
+ this.fDSPCode.setOutputParamHandler(handler);
111
+ }
112
+ getOutputParamHandler() {
113
+ return this.fDSPCode.getOutputParamHandler();
114
+ }
53
115
  callOutputParamHandler(path: string, value: number) {
54
116
  this.fDSPCode.callOutputParamHandler(path, value);
55
117
  }
56
118
 
57
- setComputeHandler(handler: ComputeHandler) { this.fDSPCode.setComputeHandler(handler); }
58
- getComputeHandler() { return this.fDSPCode.getComputeHandler(); }
119
+ setComputeHandler(handler: ComputeHandler) {
120
+ this.fDSPCode.setComputeHandler(handler);
121
+ }
122
+ getComputeHandler() {
123
+ return this.fDSPCode.getComputeHandler();
124
+ }
59
125
 
60
- setPlotHandler(handler: PlotHandler) { this.fDSPCode.setPlotHandler(handler); }
61
- getPlotHandler() { return this.fDSPCode.getPlotHandler(); }
126
+ setPlotHandler(handler: PlotHandler) {
127
+ this.fDSPCode.setPlotHandler(handler);
128
+ }
129
+ getPlotHandler() {
130
+ return this.fDSPCode.getPlotHandler();
131
+ }
62
132
 
63
- getNumInputs() { return this.fDSPCode.getNumInputs(); }
64
- getNumOutputs() { return this.fDSPCode.getNumOutputs(); }
133
+ getNumInputs() {
134
+ return this.fDSPCode.getNumInputs();
135
+ }
136
+ getNumOutputs() {
137
+ return this.fDSPCode.getNumOutputs();
138
+ }
65
139
 
66
- metadata(handler: MetadataHandler) { }
140
+ metadata(handler: MetadataHandler) {}
67
141
 
68
- midiMessage(data: number[] | Uint8Array) { this.fDSPCode.midiMessage(data); }
142
+ midiMessage(data: number[] | Uint8Array) {
143
+ this.fDSPCode.midiMessage(data);
144
+ }
69
145
 
70
- ctrlChange(chan: number, ctrl: number, value: number) { this.fDSPCode.ctrlChange(chan, ctrl, value); }
71
- pitchWheel(chan: number, value: number) { this.fDSPCode.pitchWheel(chan, value); }
72
- keyOn(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOn(channel, pitch, velocity); }
73
- keyOff(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOff(channel, pitch, velocity); }
146
+ ctrlChange(chan: number, ctrl: number, value: number) {
147
+ this.fDSPCode.ctrlChange(chan, ctrl, value);
148
+ }
149
+ pitchWheel(chan: number, value: number) {
150
+ this.fDSPCode.pitchWheel(chan, value);
151
+ }
152
+ keyOn(channel: number, pitch: number, velocity: number) {
153
+ this.fDSPCode.keyOn(channel, pitch, velocity);
154
+ }
155
+ keyOff(channel: number, pitch: number, velocity: number) {
156
+ this.fDSPCode.keyOff(channel, pitch, velocity);
157
+ }
74
158
 
75
- setParamValue(path: string, value: number) { this.fDSPCode.setParamValue(path, value); }
76
- getParamValue(path: string) { return this.fDSPCode.getParamValue(path); }
77
- getParams() { return this.fDSPCode.getParams(); }
159
+ setParamValue(path: string, value: number) {
160
+ this.fDSPCode.setParamValue(path, value);
161
+ }
162
+ getParamValue(path: string) {
163
+ return this.fDSPCode.getParamValue(path);
164
+ }
165
+ getParams() {
166
+ return this.fDSPCode.getParams();
167
+ }
78
168
 
79
- getMeta() { return this.fDSPCode.getMeta(); }
80
- getJSON() { return this.fDSPCode.getJSON(); }
81
- getDescriptors() { return this.fDSPCode.getDescriptors(); }
82
- getUI() { return this.fDSPCode.getUI(); }
169
+ getMeta() {
170
+ return this.fDSPCode.getMeta();
171
+ }
172
+ getJSON() {
173
+ return this.fDSPCode.getJSON();
174
+ }
175
+ getDescriptors() {
176
+ return this.fDSPCode.getDescriptors();
177
+ }
178
+ getUI() {
179
+ return this.fDSPCode.getUI();
180
+ }
83
181
 
84
- start() { this.fDSPCode.start(); }
85
- stop() { this.fDSPCode.stop(); }
182
+ start() {
183
+ this.fDSPCode.start();
184
+ }
185
+ stop() {
186
+ this.fDSPCode.stop();
187
+ }
86
188
 
87
- destroy() { this.fDSPCode.destroy(); }
189
+ destroy() {
190
+ this.fDSPCode.destroy();
191
+ }
88
192
 
89
- get hasAccInput() { return this.fDSPCode.hasAccInput; }
193
+ get hasAccInput() {
194
+ return this.fDSPCode.hasAccInput;
195
+ }
90
196
 
91
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
197
+ propagateAcc(
198
+ accelerationIncludingGravity: NonNullable<
199
+ DeviceMotionEvent['accelerationIncludingGravity']
200
+ >,
201
+ invert: boolean = false
202
+ ) {
92
203
  this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
93
204
  }
94
205
 
95
- get hasGyrInput() { return this.fDSPCode.hasGyrInput; }
206
+ get hasGyrInput() {
207
+ return this.fDSPCode.hasGyrInput;
208
+ }
96
209
 
97
- propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">) {
210
+ propagateGyr(
211
+ event: Pick<DeviceOrientationEvent, 'alpha' | 'beta' | 'gamma'>
212
+ ) {
98
213
  this.fDSPCode.propagateGyr(event);
99
214
  }
100
215
 
101
- startSensors(): void { }
216
+ startSensors(): void {}
102
217
 
103
- stopSensors(): void { }
218
+ stopSensors(): void {}
104
219
 
105
220
  /**
106
221
  * Render frames in an array.
@@ -110,9 +225,15 @@ export class FaustOfflineProcessor<Poly extends boolean = false> {
110
225
  * @param onUpdate - a callback after each buffer calculated, with an argument "current sample"
111
226
  * @return an array of Float32Array with the rendered frames
112
227
  */
113
- render(inputs: Float32Array[] = [], length = this.fBufferSize, onUpdate?: (sample: number) => any): Float32Array[] {
228
+ render(
229
+ inputs: Float32Array[] = [],
230
+ length = this.fBufferSize,
231
+ onUpdate?: (sample: number) => any
232
+ ): Float32Array[] {
114
233
  let l = 0;
115
- const outputs = new Array(this.fDSPCode.getNumOutputs()).fill(null).map(() => new Float32Array(length));
234
+ const outputs = new Array(this.fDSPCode.getNumOutputs())
235
+ .fill(null)
236
+ .map(() => new Float32Array(length));
116
237
  // The node has to be started before rendering
117
238
  this.fDSPCode.start();
118
239
  while (l < length) {
@@ -150,13 +271,23 @@ export class FaustOfflineProcessor<Poly extends boolean = false> {
150
271
  }
151
272
  }
152
273
 
153
- export class FaustMonoOfflineProcessor extends FaustOfflineProcessor<false> implements IFaustMonoWebAudioDsp {
154
- }
274
+ export class FaustMonoOfflineProcessor
275
+ extends FaustOfflineProcessor<false>
276
+ implements IFaustMonoWebAudioDsp {}
155
277
 
156
- export class FaustPolyOfflineProcessor extends FaustOfflineProcessor<true> implements IFaustPolyWebAudioDsp {
157
- keyOn(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOn(channel, pitch, velocity); }
158
- keyOff(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOff(channel, pitch, velocity); }
159
- allNotesOff(hard: boolean) { this.fDSPCode.allNotesOff(hard); }
278
+ export class FaustPolyOfflineProcessor
279
+ extends FaustOfflineProcessor<true>
280
+ implements IFaustPolyWebAudioDsp
281
+ {
282
+ keyOn(channel: number, pitch: number, velocity: number) {
283
+ this.fDSPCode.keyOn(channel, pitch, velocity);
284
+ }
285
+ keyOff(channel: number, pitch: number, velocity: number) {
286
+ this.fDSPCode.keyOff(channel, pitch, velocity);
287
+ }
288
+ allNotesOff(hard: boolean) {
289
+ this.fDSPCode.allNotesOff(hard);
290
+ }
160
291
  }
161
292
 
162
293
  export default FaustOfflineProcessor;
@@ -1,10 +1,23 @@
1
- import type { ComputeHandler, FaustMonoWebAudioDsp, FaustPolyWebAudioDsp, IFaustMonoWebAudioDsp, IFaustPolyWebAudioDsp, MetadataHandler, OutputParamHandler, PlotHandler } from "./FaustWebAudioDsp";
1
+ import type {
2
+ ComputeHandler,
3
+ FaustMonoWebAudioDsp,
4
+ FaustPolyWebAudioDsp,
5
+ IFaustMonoWebAudioDsp,
6
+ IFaustPolyWebAudioDsp,
7
+ MetadataHandler,
8
+ OutputParamHandler,
9
+ PlotHandler
10
+ } from './FaustWebAudioDsp';
2
11
 
3
12
  /**
4
13
  * Base class for Monophonic and Polyphonic ScriptProcessorNode
5
14
  */
6
- export class FaustScriptProcessorNode<Poly extends boolean = false> extends (globalThis.ScriptProcessorNode || null) {
7
- protected fDSPCode!: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp;
15
+ export class FaustScriptProcessorNode<
16
+ Poly extends boolean = false
17
+ > extends (globalThis.ScriptProcessorNode || null) {
18
+ protected fDSPCode!: Poly extends true
19
+ ? FaustPolyWebAudioDsp
20
+ : FaustMonoWebAudioDsp;
8
21
 
9
22
  // Needed for ScriptProcessorNode
10
23
  protected fInputs!: Float32Array[];
@@ -12,26 +25,35 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
12
25
  protected handleDeviceMotion = undefined as any;
13
26
  protected handleDeviceOrientation = undefined as any;
14
27
 
15
- init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp) {
28
+ init(
29
+ instance: Poly extends true
30
+ ? FaustPolyWebAudioDsp
31
+ : FaustMonoWebAudioDsp
32
+ ) {
16
33
  this.fDSPCode = instance;
17
34
 
18
35
  this.fInputs = new Array(this.fDSPCode.getNumInputs());
19
36
  this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
20
37
 
21
38
  // Accelerometer and gyroscope handlers
22
- this.handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
39
+ this.handleDeviceMotion = ({
40
+ accelerationIncludingGravity
41
+ }: DeviceMotionEvent) => {
23
42
  const isAndroid: boolean = /Android/i.test(navigator.userAgent);
24
43
  if (!accelerationIncludingGravity) return;
25
44
  const { x, y, z } = accelerationIncludingGravity;
26
45
  this.propagateAcc({ x, y, z }, isAndroid);
27
46
  };
28
47
 
29
- this.handleDeviceOrientation = ({ alpha, beta, gamma }: DeviceOrientationEvent) => {
48
+ this.handleDeviceOrientation = ({
49
+ alpha,
50
+ beta,
51
+ gamma
52
+ }: DeviceOrientationEvent) => {
30
53
  this.propagateGyr({ alpha, beta, gamma });
31
54
  };
32
55
 
33
56
  this.onaudioprocess = (e) => {
34
-
35
57
  // Read inputs
36
58
  for (let chan = 0; chan < this.fDSPCode.getNumInputs(); chan++) {
37
59
  this.fInputs[chan] = e.inputBuffer.getChannelData(chan);
@@ -43,7 +65,7 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
43
65
  }
44
66
 
45
67
  return this.fDSPCode.compute(this.fInputs, this.fOutputs);
46
- }
68
+ };
47
69
 
48
70
  this.start();
49
71
  }
@@ -55,19 +77,27 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
55
77
  if (this.hasAccInput) {
56
78
  if (window.DeviceMotionEvent) {
57
79
  // iOS 13+ requires a user gesture to enable DeviceMotionEvent, to be done in the main thread
58
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
80
+ window.addEventListener(
81
+ 'devicemotion',
82
+ this.handleDeviceMotion,
83
+ true
84
+ );
59
85
  } else {
60
86
  // Browser doesn't support DeviceMotionEvent
61
- console.log("Cannot set the accelerometer handler.");
87
+ console.log('Cannot set the accelerometer handler.');
62
88
  }
63
89
  }
64
90
  if (this.hasGyrInput) {
65
91
  if (window.DeviceMotionEvent) {
66
92
  // iOS 13+ requires a user gesture to enable DeviceMotionEvent, to be done in the main thread
67
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
93
+ window.addEventListener(
94
+ 'deviceorientation',
95
+ this.handleDeviceOrientation,
96
+ true
97
+ );
68
98
  } else {
69
99
  // Browser doesn't support DeviceMotionEvent
70
- console.log("Cannot set the gyroscope handler.");
100
+ console.log('Cannot set the gyroscope handler.');
71
101
  }
72
102
  }
73
103
  }
@@ -75,71 +105,148 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
75
105
  /** Stop accelerometer and gyroscope handlers */
76
106
  stopSensors() {
77
107
  if (this.hasAccInput) {
78
- window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
108
+ window.removeEventListener(
109
+ 'devicemotion',
110
+ this.handleDeviceMotion,
111
+ true
112
+ );
79
113
  }
80
114
  if (this.hasGyrInput) {
81
- window.removeEventListener("deviceorientation", this.handleDeviceOrientation, true);
115
+ window.removeEventListener(
116
+ 'deviceorientation',
117
+ this.handleDeviceOrientation,
118
+ true
119
+ );
82
120
  }
83
121
  }
84
122
 
85
- compute(input: Float32Array[], output: Float32Array[]) { return this.fDSPCode.compute(input, output); }
123
+ compute(input: Float32Array[], output: Float32Array[]) {
124
+ return this.fDSPCode.compute(input, output);
125
+ }
86
126
 
87
- setOutputParamHandler(handler: OutputParamHandler) { this.fDSPCode.setOutputParamHandler(handler); }
88
- getOutputParamHandler() { return this.fDSPCode.getOutputParamHandler(); }
127
+ setOutputParamHandler(handler: OutputParamHandler) {
128
+ this.fDSPCode.setOutputParamHandler(handler);
129
+ }
130
+ getOutputParamHandler() {
131
+ return this.fDSPCode.getOutputParamHandler();
132
+ }
89
133
  callOutputParamHandler(path: string, value: number) {
90
134
  this.fDSPCode.callOutputParamHandler(path, value);
91
135
  }
92
136
 
93
- setComputeHandler(handler: ComputeHandler) { this.fDSPCode.setComputeHandler(handler); }
94
- getComputeHandler() { return this.fDSPCode.getComputeHandler(); }
137
+ setComputeHandler(handler: ComputeHandler) {
138
+ this.fDSPCode.setComputeHandler(handler);
139
+ }
140
+ getComputeHandler() {
141
+ return this.fDSPCode.getComputeHandler();
142
+ }
95
143
 
96
- setPlotHandler(handler: PlotHandler) { this.fDSPCode.setPlotHandler(handler); }
97
- getPlotHandler() { return this.fDSPCode.getPlotHandler(); }
144
+ setPlotHandler(handler: PlotHandler) {
145
+ this.fDSPCode.setPlotHandler(handler);
146
+ }
147
+ getPlotHandler() {
148
+ return this.fDSPCode.getPlotHandler();
149
+ }
98
150
 
99
- getNumInputs() { return this.fDSPCode.getNumInputs(); }
100
- getNumOutputs() { return this.fDSPCode.getNumOutputs(); }
151
+ getNumInputs() {
152
+ return this.fDSPCode.getNumInputs();
153
+ }
154
+ getNumOutputs() {
155
+ return this.fDSPCode.getNumOutputs();
156
+ }
101
157
 
102
- metadata(handler: MetadataHandler) { }
158
+ metadata(handler: MetadataHandler) {}
103
159
 
104
- midiMessage(data: number[] | Uint8Array) { this.fDSPCode.midiMessage(data); }
160
+ midiMessage(data: number[] | Uint8Array) {
161
+ this.fDSPCode.midiMessage(data);
162
+ }
105
163
 
106
- ctrlChange(chan: number, ctrl: number, value: number) { this.fDSPCode.ctrlChange(chan, ctrl, value); }
107
- pitchWheel(chan: number, value: number) { this.fDSPCode.pitchWheel(chan, value); }
108
- keyOn(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOn(channel, pitch, velocity); }
109
- keyOff(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOff(channel, pitch, velocity); }
164
+ ctrlChange(chan: number, ctrl: number, value: number) {
165
+ this.fDSPCode.ctrlChange(chan, ctrl, value);
166
+ }
167
+ pitchWheel(chan: number, value: number) {
168
+ this.fDSPCode.pitchWheel(chan, value);
169
+ }
170
+ keyOn(channel: number, pitch: number, velocity: number) {
171
+ this.fDSPCode.keyOn(channel, pitch, velocity);
172
+ }
173
+ keyOff(channel: number, pitch: number, velocity: number) {
174
+ this.fDSPCode.keyOff(channel, pitch, velocity);
175
+ }
110
176
 
111
- setParamValue(path: string, value: number) { this.fDSPCode.setParamValue(path, value); }
112
- getParamValue(path: string) { return this.fDSPCode.getParamValue(path); }
113
- getParams() { return this.fDSPCode.getParams(); }
177
+ setParamValue(path: string, value: number) {
178
+ this.fDSPCode.setParamValue(path, value);
179
+ }
180
+ getParamValue(path: string) {
181
+ return this.fDSPCode.getParamValue(path);
182
+ }
183
+ getParams() {
184
+ return this.fDSPCode.getParams();
185
+ }
114
186
 
115
- getMeta() { return this.fDSPCode.getMeta(); }
116
- getJSON() { return this.fDSPCode.getJSON(); }
117
- getDescriptors() { return this.fDSPCode.getDescriptors(); }
118
- getUI() { return this.fDSPCode.getUI(); }
187
+ getMeta() {
188
+ return this.fDSPCode.getMeta();
189
+ }
190
+ getJSON() {
191
+ return this.fDSPCode.getJSON();
192
+ }
193
+ getDescriptors() {
194
+ return this.fDSPCode.getDescriptors();
195
+ }
196
+ getUI() {
197
+ return this.fDSPCode.getUI();
198
+ }
119
199
 
120
- start() { this.fDSPCode.start(); }
121
- stop() { this.fDSPCode.stop(); }
200
+ start() {
201
+ this.fDSPCode.start();
202
+ }
203
+ stop() {
204
+ this.fDSPCode.stop();
205
+ }
122
206
 
123
- destroy() { this.fDSPCode.destroy(); }
207
+ destroy() {
208
+ this.fDSPCode.destroy();
209
+ }
124
210
 
125
- get hasAccInput() { return this.fDSPCode.hasAccInput; }
211
+ get hasAccInput() {
212
+ return this.fDSPCode.hasAccInput;
213
+ }
126
214
 
127
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
215
+ propagateAcc(
216
+ accelerationIncludingGravity: NonNullable<
217
+ DeviceMotionEvent['accelerationIncludingGravity']
218
+ >,
219
+ invert: boolean = false
220
+ ) {
128
221
  this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
129
222
  }
130
223
 
131
- get hasGyrInput() { return this.fDSPCode.hasGyrInput; }
224
+ get hasGyrInput() {
225
+ return this.fDSPCode.hasGyrInput;
226
+ }
132
227
 
133
- propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">) {
228
+ propagateGyr(
229
+ event: Pick<DeviceOrientationEvent, 'alpha' | 'beta' | 'gamma'>
230
+ ) {
134
231
  this.fDSPCode.propagateGyr(event);
135
232
  }
136
233
  }
137
234
 
138
- export class FaustMonoScriptProcessorNode extends FaustScriptProcessorNode<false> implements IFaustMonoWebAudioDsp {
139
- }
235
+ export class FaustMonoScriptProcessorNode
236
+ extends FaustScriptProcessorNode<false>
237
+ implements IFaustMonoWebAudioDsp {}
140
238
 
141
- export class FaustPolyScriptProcessorNode extends FaustScriptProcessorNode<true> implements IFaustPolyWebAudioDsp {
142
- keyOn(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOn(channel, pitch, velocity); }
143
- keyOff(channel: number, pitch: number, velocity: number) { this.fDSPCode.keyOff(channel, pitch, velocity); }
144
- allNotesOff(hard: boolean) { this.fDSPCode.allNotesOff(hard); }
239
+ export class FaustPolyScriptProcessorNode
240
+ extends FaustScriptProcessorNode<true>
241
+ implements IFaustPolyWebAudioDsp
242
+ {
243
+ keyOn(channel: number, pitch: number, velocity: number) {
244
+ this.fDSPCode.keyOn(channel, pitch, velocity);
245
+ }
246
+ keyOff(channel: number, pitch: number, velocity: number) {
247
+ this.fDSPCode.keyOff(channel, pitch, velocity);
248
+ }
249
+ allNotesOff(hard: boolean) {
250
+ this.fDSPCode.allNotesOff(hard);
251
+ }
145
252
  }