@grame/faustwasm 0.8.2 → 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 (61) hide show
  1. package/assets/standalone/create-node.js +15 -8
  2. package/assets/standalone/faustwasm/index.d.ts +40 -0
  3. package/assets/standalone/faustwasm/index.js +109 -30
  4. package/assets/standalone/faustwasm/index.js.map +2 -2
  5. package/assets/standalone/index-pwa.js +1 -1
  6. package/assets/standalone/service-worker.js +58 -5
  7. package/dist/cjs/index.d.ts +40 -0
  8. package/dist/cjs/index.js +109 -30
  9. package/dist/cjs/index.js.map +2 -2
  10. package/dist/cjs-bundle/index.d.ts +40 -0
  11. package/dist/cjs-bundle/index.js +109 -30
  12. package/dist/cjs-bundle/index.js.map +2 -2
  13. package/dist/esm/index.d.ts +40 -0
  14. package/dist/esm/index.js +109 -30
  15. package/dist/esm/index.js.map +2 -2
  16. package/dist/esm-bundle/index.d.ts +40 -0
  17. package/dist/esm-bundle/index.js +109 -30
  18. package/dist/esm-bundle/index.js.map +2 -2
  19. package/package.json +1 -1
  20. package/src/FaustAudioWorkletNode.ts +10 -0
  21. package/src/FaustAudioWorkletProcessor.ts +16 -0
  22. package/src/FaustOfflineProcessor.ts +2 -0
  23. package/src/FaustScriptProcessorNode.ts +2 -0
  24. package/src/FaustWebAudioDsp.ts +88 -0
  25. package/src/copyWebStandaloneAssets.js +14 -0
  26. package/test/faustlive-wasm/faustwasm/index.d.ts +40 -0
  27. package/test/faustlive-wasm/faustwasm/index.js +109 -30
  28. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  29. package/test/midi/create-node.js +177 -0
  30. package/test/midi/dsp-meta.json +133 -0
  31. package/test/midi/dsp-module.wasm +0 -0
  32. package/test/midi/faust-ui/index.css +442 -0
  33. package/test/midi/faust-ui/index.css.map +1 -0
  34. package/test/midi/faust-ui/index.d.ts +1 -0
  35. package/test/midi/faust-ui/index.js +3729 -0
  36. package/test/midi/faust-ui/index.js.map +1 -0
  37. package/test/midi/faustwasm/index.d.ts +1680 -0
  38. package/test/midi/faustwasm/index.js +4884 -0
  39. package/test/midi/faustwasm/index.js.map +7 -0
  40. package/test/midi/icon.png +0 -0
  41. package/test/midi/index.html +76 -0
  42. package/test/midi/index.js +183 -0
  43. package/test/midi/manifest.json +17 -0
  44. package/test/midi/service-worker.js +165 -0
  45. package/test/midi.dsp +8 -1
  46. package/test/organ1/create-node.js +177 -0
  47. package/test/organ1/dsp-meta.json +126 -0
  48. package/test/organ1/dsp-module.wasm +0 -0
  49. package/test/organ1/faust-ui/index.css +442 -0
  50. package/test/organ1/faust-ui/index.css.map +1 -0
  51. package/test/organ1/faust-ui/index.d.ts +1 -0
  52. package/test/organ1/faust-ui/index.js +3729 -0
  53. package/test/organ1/faust-ui/index.js.map +1 -0
  54. package/test/organ1/faustwasm/index.d.ts +1656 -0
  55. package/test/organ1/faustwasm/index.js +4783 -0
  56. package/test/organ1/faustwasm/index.js.map +7 -0
  57. package/test/organ1/icon.png +0 -0
  58. package/test/organ1/index.html +76 -0
  59. package/test/organ1/index.js +203 -0
  60. package/test/organ1/manifest.json +17 -0
  61. package/test/organ1/service-worker.js +181 -0
@@ -625,6 +625,20 @@ export interface IFaustBaseWebAudioDsp {
625
625
  * @param value - the MIDI controller value (0..16383)
626
626
  */
627
627
  pitchWheel(chan: number, value: number): void;
628
+ /**
629
+ * Handle MIDI keyOn messages.
630
+ * @param channel
631
+ * @param pitch
632
+ * @param velocity
633
+ */
634
+ keyOn(channel: number, pitch: number, velocity: number): void;
635
+ /**
636
+ * Handle MIDI keyOn messages.
637
+ * @param channel
638
+ * @param pitch
639
+ * @param velocity
640
+ */
641
+ keyOff(channel: number, pitch: number, velocity: number): void;
628
642
  /**
629
643
  * Set parameter value.
630
644
  *
@@ -774,6 +788,24 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
774
788
  min: number;
775
789
  max: number;
776
790
  }[][];
791
+ protected fMidiKeyLabel: {
792
+ path: string;
793
+ chan: number;
794
+ min: number;
795
+ max: number;
796
+ }[][];
797
+ protected fMidiKeyOnLabel: {
798
+ path: string;
799
+ chan: number;
800
+ min: number;
801
+ max: number;
802
+ }[][];
803
+ protected fMidiKeyOffLabel: {
804
+ path: string;
805
+ chan: number;
806
+ min: number;
807
+ max: number;
808
+ }[][];
777
809
  protected fPathTable: {
778
810
  [address: string]: number;
779
811
  };
@@ -833,6 +865,8 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
833
865
  getNumOutputs(): number;
834
866
  midiMessage(data: number[] | Uint8Array): void;
835
867
  ctrlChange(channel: number, ctrl: number, value: number): void;
868
+ keyOn(channel: number, pitch: number, velocity: number): void;
869
+ keyOff(channel: number, pitch: number, velocity: number): void;
836
870
  pitchWheel(channel: number, wheel: number): void;
837
871
  setParamValue(path: string, value: number): void;
838
872
  getParamValue(path: string): number;
@@ -1187,6 +1221,8 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1187
1221
  midiMessage(data: number[] | Uint8Array): void;
1188
1222
  ctrlChange(chan: number, ctrl: number, value: number): void;
1189
1223
  pitchWheel(chan: number, value: number): void;
1224
+ keyOn(channel: number, pitch: number, velocity: number): void;
1225
+ keyOff(channel: number, pitch: number, velocity: number): void;
1190
1226
  setParamValue(path: string, value: number): void;
1191
1227
  getParamValue(path: string): number;
1192
1228
  getParams(): string[];
@@ -1381,6 +1417,8 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1381
1417
  midiMessage(data: number[] | Uint8Array): void;
1382
1418
  ctrlChange(channel: number, ctrl: number, value: number): void;
1383
1419
  pitchWheel(channel: number, wheel: number): void;
1420
+ keyOn(channel: number, pitch: number, velocity: number): void;
1421
+ keyOff(channel: number, pitch: number, velocity: number): void;
1384
1422
  get hasAccInput(): boolean;
1385
1423
  propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1386
1424
  get hasGyrInput(): boolean;
@@ -1448,6 +1486,8 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1448
1486
  midiMessage(data: number[] | Uint8Array): void;
1449
1487
  ctrlChange(chan: number, ctrl: number, value: number): void;
1450
1488
  pitchWheel(chan: number, value: number): void;
1489
+ keyOn(channel: number, pitch: number, velocity: number): void;
1490
+ keyOff(channel: number, pitch: number, velocity: number): void;
1451
1491
  setParamValue(path: string, value: number): void;
1452
1492
  getParamValue(path: string): number;
1453
1493
  getParams(): string[];
@@ -6233,6 +6233,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6233
6233
  this.pitchWheel(msg.data[0], msg.data[1]);
6234
6234
  break;
6235
6235
  }
6236
+ case "keyOn": {
6237
+ this.keyOn(msg.data[0], msg.data[1], msg.data[2]);
6238
+ break;
6239
+ }
6240
+ case "keyOff": {
6241
+ this.keyOff(msg.data[0], msg.data[1], msg.data[2]);
6242
+ break;
6243
+ }
6236
6244
  case "param": {
6237
6245
  this.setParamValue(msg.data.path, msg.data.value);
6238
6246
  break;
@@ -6279,6 +6287,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6279
6287
  pitchWheel(channel, wheel) {
6280
6288
  this.fDSPCode.pitchWheel(channel, wheel);
6281
6289
  }
6290
+ keyOn(channel, pitch, velocity) {
6291
+ this.fDSPCode.keyOn(channel, pitch, velocity);
6292
+ }
6293
+ keyOff(channel, pitch, velocity) {
6294
+ this.fDSPCode.keyOff(channel, pitch, velocity);
6295
+ }
6282
6296
  propagateAcc(accelerationIncludingGravity, invert = false) {
6283
6297
  this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
6284
6298
  }
@@ -8159,6 +8173,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8159
8173
  // MIDI handling
8160
8174
  this.fPitchwheelLabel = [];
8161
8175
  this.fCtrlLabel = new Array(128).fill(null).map(() => []);
8176
+ // array of MIDI key handlers; array index is the MIDI note number
8177
+ this.fMidiKeyLabel = new Array(128).fill(null).map(() => []);
8178
+ this.fMidiKeyOnLabel = new Array(128).fill(null).map(() => []);
8179
+ this.fMidiKeyOffLabel = new Array(128).fill(null).map(() => []);
8162
8180
  this.fPathTable = {};
8163
8181
  this.fUICallback = (item) => {
8164
8182
  if (item.type === "hbargraph" || item.type === "vbargraph") {
@@ -8171,6 +8189,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8171
8189
  if (!item.meta)
8172
8190
  return;
8173
8191
  item.meta.forEach((meta) => {
8192
+ var _a, _b, _c, _d, _e, _f;
8174
8193
  const { midi, acc, gyr } = meta;
8175
8194
  if (midi) {
8176
8195
  const strMidi = midi.trim();
@@ -8184,10 +8203,25 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8184
8203
  } else {
8185
8204
  const matched2 = strMidi.match(/^ctrl\s(\d+)\s(\d+)/);
8186
8205
  const matched1 = strMidi.match(/^ctrl\s(\d+)/);
8206
+ const matchedKey = strMidi.match(/^key\s+(\d+)(?:\s+(\d+))?$/);
8207
+ const matchedKeyOn = strMidi.match(/^keyon\s+(\d+)(?:\s+(\d+))?$/);
8208
+ const matchedKeyOff = strMidi.match(/^keyoff\s+(\d+)(?:\s+(\d+))?$/);
8187
8209
  if (matched2) {
8188
8210
  this.fCtrlLabel[parseInt(matched2[1])].push({ path: item.address, chan: parseInt(matched2[2]), min: item.min, max: item.max });
8189
8211
  } else if (matched1) {
8190
8212
  this.fCtrlLabel[parseInt(matched1[1])].push({ path: item.address, chan: 0, min: item.min, max: item.max });
8213
+ } else if (matchedKey) {
8214
+ const note = parseInt(matchedKey[1]);
8215
+ const channel = matchedKey[2] ? parseInt(matchedKey[2]) : 0;
8216
+ this.fMidiKeyLabel[note].push({ path: item.address, chan: channel, min: (_a = item.min) != null ? _a : 0, max: (_b = item.max) != null ? _b : 1 });
8217
+ } else if (matchedKeyOn) {
8218
+ const note = parseInt(matchedKeyOn[1]);
8219
+ const channel = matchedKeyOn[2] ? parseInt(matchedKeyOn[2]) : 0;
8220
+ this.fMidiKeyOnLabel[note].push({ path: item.address, chan: channel, min: (_c = item.min) != null ? _c : 0, max: (_d = item.max) != null ? _d : 1 });
8221
+ } else if (matchedKeyOff) {
8222
+ const note = parseInt(matchedKeyOff[1]);
8223
+ const channel = matchedKeyOff[2] ? parseInt(matchedKeyOff[2]) : 0;
8224
+ this.fMidiKeyOffLabel[note].push({ path: item.address, chan: channel, min: (_e = item.min) != null ? _e : 0, max: (_f = item.max) != null ? _f : 1 });
8191
8225
  }
8192
8226
  }
8193
8227
  }
@@ -8449,6 +8483,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8449
8483
  return this.ctrlChange(channel, data1, data2);
8450
8484
  if (cmd === 14)
8451
8485
  return this.pitchWheel(channel, data2 * 128 + data1);
8486
+ if (cmd === 9) {
8487
+ if (data2 > 0)
8488
+ return this.keyOn(channel, data1, data2);
8489
+ else
8490
+ return this.keyOff(channel, data1, data2);
8491
+ }
8492
+ if (cmd === 8) {
8493
+ return this.keyOff(channel, data1, data2);
8494
+ }
8452
8495
  }
8453
8496
  ctrlChange(channel, ctrl, value) {
8454
8497
  if (this.fPlotHandler)
@@ -8464,6 +8507,46 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8464
8507
  });
8465
8508
  }
8466
8509
  }
8510
+ keyOn(channel, pitch, velocity) {
8511
+ if (this.fPlotHandler)
8512
+ this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
8513
+ this.fMidiKeyOnLabel[pitch].forEach((key) => {
8514
+ const { path, chan } = key;
8515
+ if (chan === 0 || channel === chan - 1) {
8516
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8517
+ if (this.fOutputHandler)
8518
+ this.fOutputHandler(path, this.getParamValue(path));
8519
+ }
8520
+ });
8521
+ this.fMidiKeyLabel[pitch].forEach((key) => {
8522
+ const { path, chan } = key;
8523
+ if (chan === 0 || channel === chan - 1) {
8524
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8525
+ if (this.fOutputHandler)
8526
+ this.fOutputHandler(path, this.getParamValue(path));
8527
+ }
8528
+ });
8529
+ }
8530
+ keyOff(channel, pitch, velocity) {
8531
+ if (this.fPlotHandler)
8532
+ this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
8533
+ this.fMidiKeyOffLabel[pitch].forEach((key) => {
8534
+ const { path, chan } = key;
8535
+ if (chan === 0 || channel === chan - 1) {
8536
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8537
+ if (this.fOutputHandler)
8538
+ this.fOutputHandler(path, this.getParamValue(path));
8539
+ }
8540
+ });
8541
+ this.fMidiKeyLabel[pitch].forEach((key) => {
8542
+ const { path, chan } = key;
8543
+ if (chan === 0 || channel === chan - 1) {
8544
+ this.setParamValue(path, 0);
8545
+ if (this.fOutputHandler)
8546
+ this.fOutputHandler(path, this.getParamValue(path));
8547
+ }
8548
+ });
8549
+ }
8467
8550
  pitchWheel(channel, wheel) {
8468
8551
  if (this.fPlotHandler)
8469
8552
  this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
@@ -9100,6 +9183,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9100
9183
  pitchWheel(chan, value) {
9101
9184
  this.fDSPCode.pitchWheel(chan, value);
9102
9185
  }
9186
+ keyOn(channel, pitch, velocity) {
9187
+ this.fDSPCode.keyOn(channel, pitch, velocity);
9188
+ }
9189
+ keyOff(channel, pitch, velocity) {
9190
+ this.fDSPCode.keyOff(channel, pitch, velocity);
9191
+ }
9103
9192
  setParamValue(path, value) {
9104
9193
  this.fDSPCode.setParamValue(path, value);
9105
9194
  }
@@ -10036,6 +10125,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10036
10125
  this.ctrlChange(channel, data1, data2);
10037
10126
  else if (cmd === 14)
10038
10127
  this.pitchWheel(channel, data2 * 128 + data1);
10128
+ if (cmd === 8 || cmd === 9 && data2 === 0)
10129
+ this.keyOff(channel, data1, data2);
10130
+ else if (cmd === 9)
10131
+ this.keyOn(channel, data1, data2);
10039
10132
  else
10040
10133
  this.port.postMessage({ type: "midi", data });
10041
10134
  }
@@ -10047,6 +10140,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10047
10140
  const e = { type: "pitchWheel", data: [channel, wheel] };
10048
10141
  this.port.postMessage(e);
10049
10142
  }
10143
+ keyOn(channel, pitch, velocity) {
10144
+ const e = { type: "keyOn", data: [channel, pitch, velocity] };
10145
+ this.port.postMessage(e);
10146
+ }
10147
+ keyOff(channel, pitch, velocity) {
10148
+ const e = { type: "keyOff", data: [channel, pitch, velocity] };
10149
+ this.port.postMessage(e);
10150
+ }
10050
10151
  get hasAccInput() {
10051
10152
  return __privateGet(this, _hasAccInput);
10052
10153
  }
@@ -10210,42 +10311,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10210
10311
  async startSensors() {
10211
10312
  if (this.hasAccInput) {
10212
10313
  if (window.DeviceMotionEvent) {
10213
- if (typeof window.DeviceMotionEvent.requestPermission === "function") {
10214
- try {
10215
- const response = await window.DeviceMotionEvent.requestPermission();
10216
- if (response === "granted") {
10217
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10218
- } else if (response === "denied") {
10219
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
10220
- throw new Error("Unable to access the accelerometer.");
10221
- }
10222
- } catch (error) {
10223
- console.error(error);
10224
- }
10225
- } else {
10226
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10227
- }
10314
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10228
10315
  } else {
10229
10316
  console.log("Cannot set the accelerometer handler.");
10230
10317
  }
10231
10318
  }
10232
10319
  if (this.hasGyrInput) {
10233
10320
  if (window.DeviceMotionEvent) {
10234
- if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
10235
- try {
10236
- const response = await window.DeviceOrientationEvent.requestPermission();
10237
- if (response === "granted") {
10238
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10239
- } else if (response === "denied") {
10240
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
10241
- throw new Error("Unable to access the gyroscope.");
10242
- }
10243
- } catch (error) {
10244
- console.error(error);
10245
- }
10246
- } else {
10247
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10248
- }
10321
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10249
10322
  } else {
10250
10323
  console.log("Cannot set the gyroscope handler.");
10251
10324
  }
@@ -10298,6 +10371,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10298
10371
  pitchWheel(chan, value) {
10299
10372
  this.fDSPCode.pitchWheel(chan, value);
10300
10373
  }
10374
+ keyOn(channel, pitch, velocity) {
10375
+ this.fDSPCode.keyOn(channel, pitch, velocity);
10376
+ }
10377
+ keyOff(channel, pitch, velocity) {
10378
+ this.fDSPCode.keyOff(channel, pitch, velocity);
10379
+ }
10301
10380
  setParamValue(path, value) {
10302
10381
  this.fDSPCode.setParamValue(path, value);
10303
10382
  }