@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[];
@@ -6188,6 +6188,14 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
6188
6188
  this.pitchWheel(msg.data[0], msg.data[1]);
6189
6189
  break;
6190
6190
  }
6191
+ case "keyOn": {
6192
+ this.keyOn(msg.data[0], msg.data[1], msg.data[2]);
6193
+ break;
6194
+ }
6195
+ case "keyOff": {
6196
+ this.keyOff(msg.data[0], msg.data[1], msg.data[2]);
6197
+ break;
6198
+ }
6191
6199
  case "param": {
6192
6200
  this.setParamValue(msg.data.path, msg.data.value);
6193
6201
  break;
@@ -6234,6 +6242,12 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
6234
6242
  pitchWheel(channel, wheel) {
6235
6243
  this.fDSPCode.pitchWheel(channel, wheel);
6236
6244
  }
6245
+ keyOn(channel, pitch, velocity) {
6246
+ this.fDSPCode.keyOn(channel, pitch, velocity);
6247
+ }
6248
+ keyOff(channel, pitch, velocity) {
6249
+ this.fDSPCode.keyOff(channel, pitch, velocity);
6250
+ }
6237
6251
  propagateAcc(accelerationIncludingGravity, invert = false) {
6238
6252
  this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
6239
6253
  }
@@ -8114,6 +8128,10 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8114
8128
  // MIDI handling
8115
8129
  this.fPitchwheelLabel = [];
8116
8130
  this.fCtrlLabel = new Array(128).fill(null).map(() => []);
8131
+ // array of MIDI key handlers; array index is the MIDI note number
8132
+ this.fMidiKeyLabel = new Array(128).fill(null).map(() => []);
8133
+ this.fMidiKeyOnLabel = new Array(128).fill(null).map(() => []);
8134
+ this.fMidiKeyOffLabel = new Array(128).fill(null).map(() => []);
8117
8135
  this.fPathTable = {};
8118
8136
  this.fUICallback = (item) => {
8119
8137
  if (item.type === "hbargraph" || item.type === "vbargraph") {
@@ -8126,6 +8144,7 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8126
8144
  if (!item.meta)
8127
8145
  return;
8128
8146
  item.meta.forEach((meta) => {
8147
+ var _a, _b, _c, _d, _e, _f;
8129
8148
  const { midi, acc, gyr } = meta;
8130
8149
  if (midi) {
8131
8150
  const strMidi = midi.trim();
@@ -8139,10 +8158,25 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8139
8158
  } else {
8140
8159
  const matched2 = strMidi.match(/^ctrl\s(\d+)\s(\d+)/);
8141
8160
  const matched1 = strMidi.match(/^ctrl\s(\d+)/);
8161
+ const matchedKey = strMidi.match(/^key\s+(\d+)(?:\s+(\d+))?$/);
8162
+ const matchedKeyOn = strMidi.match(/^keyon\s+(\d+)(?:\s+(\d+))?$/);
8163
+ const matchedKeyOff = strMidi.match(/^keyoff\s+(\d+)(?:\s+(\d+))?$/);
8142
8164
  if (matched2) {
8143
8165
  this.fCtrlLabel[parseInt(matched2[1])].push({ path: item.address, chan: parseInt(matched2[2]), min: item.min, max: item.max });
8144
8166
  } else if (matched1) {
8145
8167
  this.fCtrlLabel[parseInt(matched1[1])].push({ path: item.address, chan: 0, min: item.min, max: item.max });
8168
+ } else if (matchedKey) {
8169
+ const note = parseInt(matchedKey[1]);
8170
+ const channel = matchedKey[2] ? parseInt(matchedKey[2]) : 0;
8171
+ this.fMidiKeyLabel[note].push({ path: item.address, chan: channel, min: (_a = item.min) != null ? _a : 0, max: (_b = item.max) != null ? _b : 1 });
8172
+ } else if (matchedKeyOn) {
8173
+ const note = parseInt(matchedKeyOn[1]);
8174
+ const channel = matchedKeyOn[2] ? parseInt(matchedKeyOn[2]) : 0;
8175
+ this.fMidiKeyOnLabel[note].push({ path: item.address, chan: channel, min: (_c = item.min) != null ? _c : 0, max: (_d = item.max) != null ? _d : 1 });
8176
+ } else if (matchedKeyOff) {
8177
+ const note = parseInt(matchedKeyOff[1]);
8178
+ const channel = matchedKeyOff[2] ? parseInt(matchedKeyOff[2]) : 0;
8179
+ this.fMidiKeyOffLabel[note].push({ path: item.address, chan: channel, min: (_e = item.min) != null ? _e : 0, max: (_f = item.max) != null ? _f : 1 });
8146
8180
  }
8147
8181
  }
8148
8182
  }
@@ -8404,6 +8438,15 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8404
8438
  return this.ctrlChange(channel, data1, data2);
8405
8439
  if (cmd === 14)
8406
8440
  return this.pitchWheel(channel, data2 * 128 + data1);
8441
+ if (cmd === 9) {
8442
+ if (data2 > 0)
8443
+ return this.keyOn(channel, data1, data2);
8444
+ else
8445
+ return this.keyOff(channel, data1, data2);
8446
+ }
8447
+ if (cmd === 8) {
8448
+ return this.keyOff(channel, data1, data2);
8449
+ }
8407
8450
  }
8408
8451
  ctrlChange(channel, ctrl, value) {
8409
8452
  if (this.fPlotHandler)
@@ -8419,6 +8462,46 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8419
8462
  });
8420
8463
  }
8421
8464
  }
8465
+ keyOn(channel, pitch, velocity) {
8466
+ if (this.fPlotHandler)
8467
+ this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
8468
+ this.fMidiKeyOnLabel[pitch].forEach((key) => {
8469
+ const { path, chan } = key;
8470
+ if (chan === 0 || channel === chan - 1) {
8471
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8472
+ if (this.fOutputHandler)
8473
+ this.fOutputHandler(path, this.getParamValue(path));
8474
+ }
8475
+ });
8476
+ this.fMidiKeyLabel[pitch].forEach((key) => {
8477
+ const { path, chan } = key;
8478
+ if (chan === 0 || channel === chan - 1) {
8479
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8480
+ if (this.fOutputHandler)
8481
+ this.fOutputHandler(path, this.getParamValue(path));
8482
+ }
8483
+ });
8484
+ }
8485
+ keyOff(channel, pitch, velocity) {
8486
+ if (this.fPlotHandler)
8487
+ this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
8488
+ this.fMidiKeyOffLabel[pitch].forEach((key) => {
8489
+ const { path, chan } = key;
8490
+ if (chan === 0 || channel === chan - 1) {
8491
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(velocity, 0, 127, key.min, key.max));
8492
+ if (this.fOutputHandler)
8493
+ this.fOutputHandler(path, this.getParamValue(path));
8494
+ }
8495
+ });
8496
+ this.fMidiKeyLabel[pitch].forEach((key) => {
8497
+ const { path, chan } = key;
8498
+ if (chan === 0 || channel === chan - 1) {
8499
+ this.setParamValue(path, 0);
8500
+ if (this.fOutputHandler)
8501
+ this.fOutputHandler(path, this.getParamValue(path));
8502
+ }
8503
+ });
8504
+ }
8422
8505
  pitchWheel(channel, wheel) {
8423
8506
  if (this.fPlotHandler)
8424
8507
  this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
@@ -9055,6 +9138,12 @@ var FaustOfflineProcessor = class {
9055
9138
  pitchWheel(chan, value) {
9056
9139
  this.fDSPCode.pitchWheel(chan, value);
9057
9140
  }
9141
+ keyOn(channel, pitch, velocity) {
9142
+ this.fDSPCode.keyOn(channel, pitch, velocity);
9143
+ }
9144
+ keyOff(channel, pitch, velocity) {
9145
+ this.fDSPCode.keyOff(channel, pitch, velocity);
9146
+ }
9058
9147
  setParamValue(path, value) {
9059
9148
  this.fDSPCode.setParamValue(path, value);
9060
9149
  }
@@ -9991,6 +10080,10 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
9991
10080
  this.ctrlChange(channel, data1, data2);
9992
10081
  else if (cmd === 14)
9993
10082
  this.pitchWheel(channel, data2 * 128 + data1);
10083
+ if (cmd === 8 || cmd === 9 && data2 === 0)
10084
+ this.keyOff(channel, data1, data2);
10085
+ else if (cmd === 9)
10086
+ this.keyOn(channel, data1, data2);
9994
10087
  else
9995
10088
  this.port.postMessage({ type: "midi", data });
9996
10089
  }
@@ -10002,6 +10095,14 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
10002
10095
  const e = { type: "pitchWheel", data: [channel, wheel] };
10003
10096
  this.port.postMessage(e);
10004
10097
  }
10098
+ keyOn(channel, pitch, velocity) {
10099
+ const e = { type: "keyOn", data: [channel, pitch, velocity] };
10100
+ this.port.postMessage(e);
10101
+ }
10102
+ keyOff(channel, pitch, velocity) {
10103
+ const e = { type: "keyOff", data: [channel, pitch, velocity] };
10104
+ this.port.postMessage(e);
10105
+ }
10005
10106
  get hasAccInput() {
10006
10107
  return __privateGet(this, _hasAccInput);
10007
10108
  }
@@ -10165,42 +10266,14 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
10165
10266
  async startSensors() {
10166
10267
  if (this.hasAccInput) {
10167
10268
  if (window.DeviceMotionEvent) {
10168
- if (typeof window.DeviceMotionEvent.requestPermission === "function") {
10169
- try {
10170
- const response = await window.DeviceMotionEvent.requestPermission();
10171
- if (response === "granted") {
10172
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10173
- } else if (response === "denied") {
10174
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
10175
- throw new Error("Unable to access the accelerometer.");
10176
- }
10177
- } catch (error) {
10178
- console.error(error);
10179
- }
10180
- } else {
10181
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10182
- }
10269
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
10183
10270
  } else {
10184
10271
  console.log("Cannot set the accelerometer handler.");
10185
10272
  }
10186
10273
  }
10187
10274
  if (this.hasGyrInput) {
10188
10275
  if (window.DeviceMotionEvent) {
10189
- if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
10190
- try {
10191
- const response = await window.DeviceOrientationEvent.requestPermission();
10192
- if (response === "granted") {
10193
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10194
- } else if (response === "denied") {
10195
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
10196
- throw new Error("Unable to access the gyroscope.");
10197
- }
10198
- } catch (error) {
10199
- console.error(error);
10200
- }
10201
- } else {
10202
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10203
- }
10276
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
10204
10277
  } else {
10205
10278
  console.log("Cannot set the gyroscope handler.");
10206
10279
  }
@@ -10253,6 +10326,12 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
10253
10326
  pitchWheel(chan, value) {
10254
10327
  this.fDSPCode.pitchWheel(chan, value);
10255
10328
  }
10329
+ keyOn(channel, pitch, velocity) {
10330
+ this.fDSPCode.keyOn(channel, pitch, velocity);
10331
+ }
10332
+ keyOff(channel, pitch, velocity) {
10333
+ this.fDSPCode.keyOff(channel, pitch, velocity);
10334
+ }
10256
10335
  setParamValue(path, value) {
10257
10336
  this.fDSPCode.setParamValue(path, value);
10258
10337
  }