@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.
- package/.prettierrc +5 -0
- package/README.md +21 -3
- package/assets/standalone/faustwasm/index.d.ts +38 -16
- package/assets/standalone/faustwasm/index.js +1593 -404
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.d.ts +38 -16
- package/dist/cjs/index.js +1592 -404
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +38 -16
- package/dist/cjs-bundle/index.js +1595 -406
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +38 -16
- package/dist/esm/index.js +1593 -404
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +38 -16
- package/dist/esm-bundle/index.js +1595 -406
- package/dist/esm-bundle/index.js.map +2 -2
- package/eslint.config.js +11 -0
- package/package.json +57 -51
- package/sound.cpp +163 -0
- package/sound.dsp +4 -0
- package/sound.json +1 -0
- package/sound.wasm +0 -0
- package/src/FaustAudioWorkletCommunicator.ts +150 -143
- package/src/FaustAudioWorkletNode.ts +173 -75
- package/src/FaustAudioWorkletProcessor.ts +218 -90
- package/src/FaustCmajor.ts +9 -3
- package/src/FaustCompiler.ts +112 -35
- package/src/FaustDspGenerator.ts +589 -117
- package/src/FaustDspInstance.ts +58 -24
- package/src/FaustFFTAudioWorkletProcessor.ts +822 -612
- package/src/FaustOfflineProcessor.ts +187 -56
- package/src/FaustScriptProcessorNode.ts +156 -49
- package/src/FaustSensors.ts +426 -96
- package/src/FaustSvgDiagrams.ts +18 -5
- package/src/FaustWasmInstantiator.ts +224 -70
- package/src/FaustWebAudioDsp.ts +1060 -349
- package/src/LibFaust.ts +13 -4
- package/src/SoundfileReader.ts +175 -131
- package/src/WavDecoder.ts +42 -20
- package/src/WavEncoder.ts +35 -21
- package/src/copyWebStandaloneAssets.d.ts +20 -5
- package/src/copyWebStandaloneAssets.js +203 -75
- package/src/exports-bundle.ts +5 -5
- package/src/exports.ts +24 -24
- package/src/faust2CmajorFiles.d.ts +7 -3
- package/src/faust2cmajorFiles.js +10 -8
- package/src/faust2svgFiles.d.ts +7 -3
- package/src/faust2svgFiles.js +9 -7
- package/src/faust2wasmFiles.d.ts +10 -5
- package/src/faust2wasmFiles.js +34 -17
- package/src/faust2wavFiles.d.ts +12 -3
- package/src/faust2wavFiles.js +25 -12
- package/src/index-bundle-iife.ts +2 -2
- package/src/index-bundle.ts +1 -1
- package/src/index.ts +1 -1
- package/src/instantiateFaustModule.ts +43 -36
- package/src/instantiateFaustModuleFromFile.ts +30 -14
- package/src/types.ts +101 -25
- package/test/faustlive-wasm/faustwasm/index.d.ts +38 -16
- package/test/faustlive-wasm/faustwasm/index.js +1593 -404
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
- package/test/web/create-faust-node.html +53 -0
- package/test/web/create-faust-node.js +181 -0
- package/test/organ/create-node.js +0 -252
- package/test/organ/dsp-meta.json +0 -131
- package/test/organ/dsp-module.wasm +0 -0
- package/test/organ/faust-pwa.js +0 -344
- package/test/organ/faust-ui/index.css +0 -442
- package/test/organ/faust-ui/index.css.map +0 -1
- package/test/organ/faust-ui/index.d.ts +0 -1
- package/test/organ/faust-ui/index.js +0 -3756
- package/test/organ/faust-ui/index.js.map +0 -1
- package/test/organ/faustwasm/index.d.ts +0 -1705
- package/test/organ/faustwasm/index.js +0 -4773
- package/test/organ/faustwasm/index.js.map +0 -7
- package/test/organ/icon.png +0 -0
- package/test/organ/index.html +0 -76
- package/test/organ/index.js +0 -69
- package/test/organ/manifest.json +0 -17
- package/test/organ/service-worker.js +0 -165
|
@@ -1,28 +1,58 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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(
|
|
19
|
+
render(
|
|
20
|
+
inputs?: Float32Array[],
|
|
21
|
+
length?: number,
|
|
22
|
+
onUpdate?: (sample: number) => any
|
|
23
|
+
): Float32Array[];
|
|
9
24
|
}
|
|
10
25
|
|
|
11
|
-
export interface IFaustMonoOfflineProcessor
|
|
12
|
-
|
|
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
|
|
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(
|
|
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())
|
|
25
|
-
|
|
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 = [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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[]) {
|
|
105
|
+
compute(input: Float32Array[], output: Float32Array[]) {
|
|
106
|
+
return this.fDSPCode.compute(input, output);
|
|
107
|
+
}
|
|
50
108
|
|
|
51
|
-
setOutputParamHandler(handler: OutputParamHandler) {
|
|
52
|
-
|
|
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) {
|
|
58
|
-
|
|
119
|
+
setComputeHandler(handler: ComputeHandler) {
|
|
120
|
+
this.fDSPCode.setComputeHandler(handler);
|
|
121
|
+
}
|
|
122
|
+
getComputeHandler() {
|
|
123
|
+
return this.fDSPCode.getComputeHandler();
|
|
124
|
+
}
|
|
59
125
|
|
|
60
|
-
setPlotHandler(handler: PlotHandler) {
|
|
61
|
-
|
|
126
|
+
setPlotHandler(handler: PlotHandler) {
|
|
127
|
+
this.fDSPCode.setPlotHandler(handler);
|
|
128
|
+
}
|
|
129
|
+
getPlotHandler() {
|
|
130
|
+
return this.fDSPCode.getPlotHandler();
|
|
131
|
+
}
|
|
62
132
|
|
|
63
|
-
getNumInputs() {
|
|
64
|
-
|
|
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) {
|
|
142
|
+
midiMessage(data: number[] | Uint8Array) {
|
|
143
|
+
this.fDSPCode.midiMessage(data);
|
|
144
|
+
}
|
|
69
145
|
|
|
70
|
-
ctrlChange(chan: number, ctrl: number, value: number) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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) {
|
|
76
|
-
|
|
77
|
-
|
|
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() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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() {
|
|
85
|
-
|
|
182
|
+
start() {
|
|
183
|
+
this.fDSPCode.start();
|
|
184
|
+
}
|
|
185
|
+
stop() {
|
|
186
|
+
this.fDSPCode.stop();
|
|
187
|
+
}
|
|
86
188
|
|
|
87
|
-
destroy() {
|
|
189
|
+
destroy() {
|
|
190
|
+
this.fDSPCode.destroy();
|
|
191
|
+
}
|
|
88
192
|
|
|
89
|
-
get hasAccInput() {
|
|
193
|
+
get hasAccInput() {
|
|
194
|
+
return this.fDSPCode.hasAccInput;
|
|
195
|
+
}
|
|
90
196
|
|
|
91
|
-
propagateAcc(
|
|
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() {
|
|
206
|
+
get hasGyrInput() {
|
|
207
|
+
return this.fDSPCode.hasGyrInput;
|
|
208
|
+
}
|
|
96
209
|
|
|
97
|
-
propagateGyr(
|
|
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(
|
|
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())
|
|
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
|
|
154
|
-
|
|
274
|
+
export class FaustMonoOfflineProcessor
|
|
275
|
+
extends FaustOfflineProcessor<false>
|
|
276
|
+
implements IFaustMonoWebAudioDsp {}
|
|
155
277
|
|
|
156
|
-
export class FaustPolyOfflineProcessor
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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 {
|
|
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<
|
|
7
|
-
|
|
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(
|
|
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 = ({
|
|
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 = ({
|
|
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(
|
|
80
|
+
window.addEventListener(
|
|
81
|
+
'devicemotion',
|
|
82
|
+
this.handleDeviceMotion,
|
|
83
|
+
true
|
|
84
|
+
);
|
|
59
85
|
} else {
|
|
60
86
|
// Browser doesn't support DeviceMotionEvent
|
|
61
|
-
console.log(
|
|
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(
|
|
93
|
+
window.addEventListener(
|
|
94
|
+
'deviceorientation',
|
|
95
|
+
this.handleDeviceOrientation,
|
|
96
|
+
true
|
|
97
|
+
);
|
|
68
98
|
} else {
|
|
69
99
|
// Browser doesn't support DeviceMotionEvent
|
|
70
|
-
console.log(
|
|
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(
|
|
108
|
+
window.removeEventListener(
|
|
109
|
+
'devicemotion',
|
|
110
|
+
this.handleDeviceMotion,
|
|
111
|
+
true
|
|
112
|
+
);
|
|
79
113
|
}
|
|
80
114
|
if (this.hasGyrInput) {
|
|
81
|
-
window.removeEventListener(
|
|
115
|
+
window.removeEventListener(
|
|
116
|
+
'deviceorientation',
|
|
117
|
+
this.handleDeviceOrientation,
|
|
118
|
+
true
|
|
119
|
+
);
|
|
82
120
|
}
|
|
83
121
|
}
|
|
84
122
|
|
|
85
|
-
compute(input: Float32Array[], output: Float32Array[]) {
|
|
123
|
+
compute(input: Float32Array[], output: Float32Array[]) {
|
|
124
|
+
return this.fDSPCode.compute(input, output);
|
|
125
|
+
}
|
|
86
126
|
|
|
87
|
-
setOutputParamHandler(handler: OutputParamHandler) {
|
|
88
|
-
|
|
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) {
|
|
94
|
-
|
|
137
|
+
setComputeHandler(handler: ComputeHandler) {
|
|
138
|
+
this.fDSPCode.setComputeHandler(handler);
|
|
139
|
+
}
|
|
140
|
+
getComputeHandler() {
|
|
141
|
+
return this.fDSPCode.getComputeHandler();
|
|
142
|
+
}
|
|
95
143
|
|
|
96
|
-
setPlotHandler(handler: PlotHandler) {
|
|
97
|
-
|
|
144
|
+
setPlotHandler(handler: PlotHandler) {
|
|
145
|
+
this.fDSPCode.setPlotHandler(handler);
|
|
146
|
+
}
|
|
147
|
+
getPlotHandler() {
|
|
148
|
+
return this.fDSPCode.getPlotHandler();
|
|
149
|
+
}
|
|
98
150
|
|
|
99
|
-
getNumInputs() {
|
|
100
|
-
|
|
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) {
|
|
160
|
+
midiMessage(data: number[] | Uint8Array) {
|
|
161
|
+
this.fDSPCode.midiMessage(data);
|
|
162
|
+
}
|
|
105
163
|
|
|
106
|
-
ctrlChange(chan: number, ctrl: number, value: number) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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) {
|
|
112
|
-
|
|
113
|
-
|
|
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() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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() {
|
|
121
|
-
|
|
200
|
+
start() {
|
|
201
|
+
this.fDSPCode.start();
|
|
202
|
+
}
|
|
203
|
+
stop() {
|
|
204
|
+
this.fDSPCode.stop();
|
|
205
|
+
}
|
|
122
206
|
|
|
123
|
-
destroy() {
|
|
207
|
+
destroy() {
|
|
208
|
+
this.fDSPCode.destroy();
|
|
209
|
+
}
|
|
124
210
|
|
|
125
|
-
get hasAccInput() {
|
|
211
|
+
get hasAccInput() {
|
|
212
|
+
return this.fDSPCode.hasAccInput;
|
|
213
|
+
}
|
|
126
214
|
|
|
127
|
-
propagateAcc(
|
|
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() {
|
|
224
|
+
get hasGyrInput() {
|
|
225
|
+
return this.fDSPCode.hasGyrInput;
|
|
226
|
+
}
|
|
132
227
|
|
|
133
|
-
propagateGyr(
|
|
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
|
|
139
|
-
|
|
235
|
+
export class FaustMonoScriptProcessorNode
|
|
236
|
+
extends FaustScriptProcessorNode<false>
|
|
237
|
+
implements IFaustMonoWebAudioDsp {}
|
|
140
238
|
|
|
141
|
-
export class FaustPolyScriptProcessorNode
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
}
|