@grame/faustwasm 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/assets/standalone/create-node.js +46 -9
  2. package/assets/standalone/faust-ui/index.js +2 -2
  3. package/assets/standalone/faust-ui/index.js.map +1 -1
  4. package/assets/standalone/faustwasm/index.d.ts +42 -2
  5. package/assets/standalone/faustwasm/index.js +117 -66
  6. package/assets/standalone/faustwasm/index.js.map +2 -2
  7. package/assets/standalone/index-pwa.js +125 -90
  8. package/assets/standalone/index-template.js +43 -22
  9. package/assets/standalone/index.js +36 -19
  10. package/assets/standalone/service-worker.js +58 -5
  11. package/dist/cjs/index.d.ts +42 -2
  12. package/dist/cjs/index.js +117 -66
  13. package/dist/cjs/index.js.map +2 -2
  14. package/dist/cjs-bundle/index.d.ts +42 -2
  15. package/dist/cjs-bundle/index.js +117 -66
  16. package/dist/cjs-bundle/index.js.map +2 -2
  17. package/dist/esm/index.d.ts +42 -2
  18. package/dist/esm/index.js +117 -66
  19. package/dist/esm/index.js.map +2 -2
  20. package/dist/esm-bundle/index.d.ts +42 -2
  21. package/dist/esm-bundle/index.js +117 -66
  22. package/dist/esm-bundle/index.js.map +2 -2
  23. package/package.json +2 -2
  24. package/src/FaustAudioWorkletNode.ts +14 -30
  25. package/src/FaustAudioWorkletProcessor.ts +16 -0
  26. package/src/FaustOfflineProcessor.ts +2 -0
  27. package/src/FaustScriptProcessorNode.ts +6 -30
  28. package/src/FaustWebAudioDsp.ts +88 -0
  29. package/src/copyWebStandaloneAssets.js +14 -0
  30. package/test/faustlive-wasm/faust-ui/index.js +2 -2
  31. package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
  32. package/test/faustlive-wasm/faustwasm/index.d.ts +42 -2
  33. package/test/faustlive-wasm/faustwasm/index.js +117 -66
  34. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  35. package/test/midi/create-node.js +177 -0
  36. package/test/midi/dsp-meta.json +133 -0
  37. package/test/midi/dsp-module.wasm +0 -0
  38. package/test/midi/faust-ui/index.css +442 -0
  39. package/test/midi/faust-ui/index.css.map +1 -0
  40. package/test/midi/faust-ui/index.d.ts +1 -0
  41. package/test/midi/faust-ui/index.js +3729 -0
  42. package/test/midi/faust-ui/index.js.map +1 -0
  43. package/test/midi/faustwasm/index.d.ts +1680 -0
  44. package/test/midi/faustwasm/index.js +4884 -0
  45. package/test/midi/faustwasm/index.js.map +7 -0
  46. package/test/midi/icon.png +0 -0
  47. package/test/midi/index.html +76 -0
  48. package/test/midi/index.js +183 -0
  49. package/test/midi/manifest.json +17 -0
  50. package/test/midi/service-worker.js +165 -0
  51. package/test/midi.dsp +8 -1
  52. package/test/organ1/create-node.js +177 -0
  53. package/test/organ1/dsp-meta.json +126 -0
  54. package/test/organ1/dsp-module.wasm +0 -0
  55. package/test/organ1/faust-ui/index.css +442 -0
  56. package/test/organ1/faust-ui/index.css.map +1 -0
  57. package/test/organ1/faust-ui/index.d.ts +1 -0
  58. package/test/organ1/faust-ui/index.js +3729 -0
  59. package/test/organ1/faust-ui/index.js.map +1 -0
  60. package/test/organ1/faustwasm/index.d.ts +1656 -0
  61. package/test/organ1/faustwasm/index.js +4783 -0
  62. package/test/organ1/faustwasm/index.js.map +7 -0
  63. package/test/organ1/icon.png +0 -0
  64. package/test/organ1/index.html +76 -0
  65. package/test/organ1/index.js +203 -0
  66. package/test/organ1/manifest.json +17 -0
  67. package/test/organ1/service-worker.js +181 -0
package/dist/cjs/index.js CHANGED
@@ -216,6 +216,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
216
216
  this.pitchWheel(msg.data[0], msg.data[1]);
217
217
  break;
218
218
  }
219
+ case "keyOn": {
220
+ this.keyOn(msg.data[0], msg.data[1], msg.data[2]);
221
+ break;
222
+ }
223
+ case "keyOff": {
224
+ this.keyOff(msg.data[0], msg.data[1], msg.data[2]);
225
+ break;
226
+ }
219
227
  case "param": {
220
228
  this.setParamValue(msg.data.path, msg.data.value);
221
229
  break;
@@ -262,6 +270,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
262
270
  pitchWheel(channel, wheel) {
263
271
  this.fDSPCode.pitchWheel(channel, wheel);
264
272
  }
273
+ keyOn(channel, pitch, velocity) {
274
+ this.fDSPCode.keyOn(channel, pitch, velocity);
275
+ }
276
+ keyOff(channel, pitch, velocity) {
277
+ this.fDSPCode.keyOff(channel, pitch, velocity);
278
+ }
265
279
  propagateAcc(accelerationIncludingGravity, invert = false) {
266
280
  this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
267
281
  }
@@ -2142,6 +2156,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2142
2156
  // MIDI handling
2143
2157
  this.fPitchwheelLabel = [];
2144
2158
  this.fCtrlLabel = new Array(128).fill(null).map(() => []);
2159
+ // array of MIDI key handlers; array index is the MIDI note number
2160
+ this.fMidiKeyLabel = new Array(128).fill(null).map(() => []);
2161
+ this.fMidiKeyOnLabel = new Array(128).fill(null).map(() => []);
2162
+ this.fMidiKeyOffLabel = new Array(128).fill(null).map(() => []);
2145
2163
  this.fPathTable = {};
2146
2164
  this.fUICallback = (item) => {
2147
2165
  if (item.type === "hbargraph" || item.type === "vbargraph") {
@@ -2154,6 +2172,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2154
2172
  if (!item.meta)
2155
2173
  return;
2156
2174
  item.meta.forEach((meta) => {
2175
+ var _a, _b, _c, _d, _e, _f;
2157
2176
  const { midi, acc, gyr } = meta;
2158
2177
  if (midi) {
2159
2178
  const strMidi = midi.trim();
@@ -2167,10 +2186,25 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2167
2186
  } else {
2168
2187
  const matched2 = strMidi.match(/^ctrl\s(\d+)\s(\d+)/);
2169
2188
  const matched1 = strMidi.match(/^ctrl\s(\d+)/);
2189
+ const matchedKey = strMidi.match(/^key\s+(\d+)(?:\s+(\d+))?$/);
2190
+ const matchedKeyOn = strMidi.match(/^keyon\s+(\d+)(?:\s+(\d+))?$/);
2191
+ const matchedKeyOff = strMidi.match(/^keyoff\s+(\d+)(?:\s+(\d+))?$/);
2170
2192
  if (matched2) {
2171
2193
  this.fCtrlLabel[parseInt(matched2[1])].push({ path: item.address, chan: parseInt(matched2[2]), min: item.min, max: item.max });
2172
2194
  } else if (matched1) {
2173
2195
  this.fCtrlLabel[parseInt(matched1[1])].push({ path: item.address, chan: 0, min: item.min, max: item.max });
2196
+ } else if (matchedKey) {
2197
+ const note = parseInt(matchedKey[1]);
2198
+ const channel = matchedKey[2] ? parseInt(matchedKey[2]) : 0;
2199
+ this.fMidiKeyLabel[note].push({ path: item.address, chan: channel, min: (_a = item.min) != null ? _a : 0, max: (_b = item.max) != null ? _b : 1 });
2200
+ } else if (matchedKeyOn) {
2201
+ const note = parseInt(matchedKeyOn[1]);
2202
+ const channel = matchedKeyOn[2] ? parseInt(matchedKeyOn[2]) : 0;
2203
+ this.fMidiKeyOnLabel[note].push({ path: item.address, chan: channel, min: (_c = item.min) != null ? _c : 0, max: (_d = item.max) != null ? _d : 1 });
2204
+ } else if (matchedKeyOff) {
2205
+ const note = parseInt(matchedKeyOff[1]);
2206
+ const channel = matchedKeyOff[2] ? parseInt(matchedKeyOff[2]) : 0;
2207
+ this.fMidiKeyOffLabel[note].push({ path: item.address, chan: channel, min: (_e = item.min) != null ? _e : 0, max: (_f = item.max) != null ? _f : 1 });
2174
2208
  }
2175
2209
  }
2176
2210
  }
@@ -2432,6 +2466,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2432
2466
  return this.ctrlChange(channel, data1, data2);
2433
2467
  if (cmd === 14)
2434
2468
  return this.pitchWheel(channel, data2 * 128 + data1);
2469
+ if (cmd === 9) {
2470
+ if (data2 > 0)
2471
+ return this.keyOn(channel, data1, data2);
2472
+ else
2473
+ return this.keyOff(channel, data1, data2);
2474
+ }
2475
+ if (cmd === 8) {
2476
+ return this.keyOff(channel, data1, data2);
2477
+ }
2435
2478
  }
2436
2479
  ctrlChange(channel, ctrl, value) {
2437
2480
  if (this.fPlotHandler)
@@ -2447,6 +2490,46 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2447
2490
  });
2448
2491
  }
2449
2492
  }
2493
+ keyOn(channel, pitch, velocity) {
2494
+ if (this.fPlotHandler)
2495
+ this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
2496
+ this.fMidiKeyOnLabel[pitch].forEach((key) => {
2497
+ const { path, chan } = key;
2498
+ if (chan === 0 || channel === chan - 1) {
2499
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2500
+ if (this.fOutputHandler)
2501
+ this.fOutputHandler(path, this.getParamValue(path));
2502
+ }
2503
+ });
2504
+ this.fMidiKeyLabel[pitch].forEach((key) => {
2505
+ const { path, chan } = key;
2506
+ if (chan === 0 || channel === chan - 1) {
2507
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2508
+ if (this.fOutputHandler)
2509
+ this.fOutputHandler(path, this.getParamValue(path));
2510
+ }
2511
+ });
2512
+ }
2513
+ keyOff(channel, pitch, velocity) {
2514
+ if (this.fPlotHandler)
2515
+ this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
2516
+ this.fMidiKeyOffLabel[pitch].forEach((key) => {
2517
+ const { path, chan } = key;
2518
+ if (chan === 0 || channel === chan - 1) {
2519
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
2520
+ if (this.fOutputHandler)
2521
+ this.fOutputHandler(path, this.getParamValue(path));
2522
+ }
2523
+ });
2524
+ this.fMidiKeyLabel[pitch].forEach((key) => {
2525
+ const { path, chan } = key;
2526
+ if (chan === 0 || channel === chan - 1) {
2527
+ this.setParamValue(path, 0);
2528
+ if (this.fOutputHandler)
2529
+ this.fOutputHandler(path, this.getParamValue(path));
2530
+ }
2531
+ });
2532
+ }
2450
2533
  pitchWheel(channel, wheel) {
2451
2534
  if (this.fPlotHandler)
2452
2535
  this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
@@ -2482,6 +2565,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2482
2565
  hasSoundfiles() {
2483
2566
  return this.fSoundfiles.length > 0;
2484
2567
  }
2568
+ startSensors() {
2569
+ this.startSensors();
2570
+ }
2571
+ stopSensors() {
2572
+ this.stopSensors();
2573
+ }
2485
2574
  start() {
2486
2575
  this.fProcessing = true;
2487
2576
  }
@@ -2494,12 +2583,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2494
2583
  this.fComputeHandler = null;
2495
2584
  this.fPlotHandler = null;
2496
2585
  }
2497
- startSensors() {
2498
- this.startSensors();
2499
- }
2500
- stopSensors() {
2501
- this.stopSensors();
2502
- }
2503
2586
  };
2504
2587
  var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
2505
2588
  constructor(instance, sampleRate, sampleSize, bufferSize, soundfiles) {
@@ -3083,6 +3166,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3083
3166
  pitchWheel(chan, value) {
3084
3167
  this.fDSPCode.pitchWheel(chan, value);
3085
3168
  }
3169
+ keyOn(channel, pitch, velocity) {
3170
+ this.fDSPCode.keyOn(channel, pitch, velocity);
3171
+ }
3172
+ keyOff(channel, pitch, velocity) {
3173
+ this.fDSPCode.keyOff(channel, pitch, velocity);
3174
+ }
3086
3175
  setParamValue(path, value) {
3087
3176
  this.fDSPCode.setParamValue(path, value);
3088
3177
  }
@@ -3948,42 +4037,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3948
4037
  async startSensors() {
3949
4038
  if (this.hasAccInput) {
3950
4039
  if (window.DeviceMotionEvent) {
3951
- if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3952
- try {
3953
- const response = await window.DeviceMotionEvent.requestPermission();
3954
- if (response === "granted") {
3955
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
3956
- } else if (response === "denied") {
3957
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
3958
- throw new Error("Unable to access the accelerometer.");
3959
- }
3960
- } catch (error) {
3961
- console.error(error);
3962
- }
3963
- } else {
3964
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
3965
- }
4040
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
3966
4041
  } else {
3967
4042
  console.log("Cannot set the accelerometer handler.");
3968
4043
  }
3969
4044
  }
3970
4045
  if (this.hasGyrInput) {
3971
4046
  if (window.DeviceMotionEvent) {
3972
- if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
3973
- try {
3974
- const response = await window.DeviceOrientationEvent.requestPermission();
3975
- if (response === "granted") {
3976
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
3977
- } else if (response === "denied") {
3978
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
3979
- throw new Error("Unable to access the gyroscope.");
3980
- }
3981
- } catch (error) {
3982
- console.error(error);
3983
- }
3984
- } else {
3985
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
3986
- }
4047
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
3987
4048
  } else {
3988
4049
  console.log("Cannot set the gyroscope handler.");
3989
4050
  }
@@ -4047,6 +4108,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4047
4108
  this.ctrlChange(channel, data1, data2);
4048
4109
  else if (cmd === 14)
4049
4110
  this.pitchWheel(channel, data2 * 128 + data1);
4111
+ if (cmd === 8 || cmd === 9 && data2 === 0)
4112
+ this.keyOff(channel, data1, data2);
4113
+ else if (cmd === 9)
4114
+ this.keyOn(channel, data1, data2);
4050
4115
  else
4051
4116
  this.port.postMessage({ type: "midi", data });
4052
4117
  }
@@ -4058,6 +4123,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4058
4123
  const e = { type: "pitchWheel", data: [channel, wheel] };
4059
4124
  this.port.postMessage(e);
4060
4125
  }
4126
+ keyOn(channel, pitch, velocity) {
4127
+ const e = { type: "keyOn", data: [channel, pitch, velocity] };
4128
+ this.port.postMessage(e);
4129
+ }
4130
+ keyOff(channel, pitch, velocity) {
4131
+ const e = { type: "keyOff", data: [channel, pitch, velocity] };
4132
+ this.port.postMessage(e);
4133
+ }
4061
4134
  get hasAccInput() {
4062
4135
  return __privateGet(this, _hasAccInput);
4063
4136
  }
@@ -4221,42 +4294,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4221
4294
  async startSensors() {
4222
4295
  if (this.hasAccInput) {
4223
4296
  if (window.DeviceMotionEvent) {
4224
- if (typeof window.DeviceMotionEvent.requestPermission === "function") {
4225
- try {
4226
- const response = await window.DeviceMotionEvent.requestPermission();
4227
- if (response === "granted") {
4228
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4229
- } else if (response === "denied") {
4230
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
4231
- throw new Error("Unable to access the accelerometer.");
4232
- }
4233
- } catch (error) {
4234
- console.error(error);
4235
- }
4236
- } else {
4237
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4238
- }
4297
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
4239
4298
  } else {
4240
4299
  console.log("Cannot set the accelerometer handler.");
4241
4300
  }
4242
4301
  }
4243
4302
  if (this.hasGyrInput) {
4244
4303
  if (window.DeviceMotionEvent) {
4245
- if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
4246
- try {
4247
- const response = await window.DeviceOrientationEvent.requestPermission();
4248
- if (response === "granted") {
4249
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4250
- } else if (response === "denied") {
4251
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
4252
- throw new Error("Unable to access the gyroscope.");
4253
- }
4254
- } catch (error) {
4255
- console.error(error);
4256
- }
4257
- } else {
4258
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4259
- }
4304
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
4260
4305
  } else {
4261
4306
  console.log("Cannot set the gyroscope handler.");
4262
4307
  }
@@ -4309,6 +4354,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4309
4354
  pitchWheel(chan, value) {
4310
4355
  this.fDSPCode.pitchWheel(chan, value);
4311
4356
  }
4357
+ keyOn(channel, pitch, velocity) {
4358
+ this.fDSPCode.keyOn(channel, pitch, velocity);
4359
+ }
4360
+ keyOff(channel, pitch, velocity) {
4361
+ this.fDSPCode.keyOff(channel, pitch, velocity);
4362
+ }
4312
4363
  setParamValue(path, value) {
4313
4364
  this.fDSPCode.setParamValue(path, value);
4314
4365
  }