@grame/faustwasm 0.5.5 → 0.6.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -591,8 +591,8 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
591
591
  protected fSampleSize: number;
592
592
 
593
593
  // MIDI handling
594
- protected fPitchwheelLabel: { path: string; min: number; max: number }[] = [];
595
- protected fCtrlLabel: { path: string; min: number; max: number }[][] = new Array(128).fill(null).map(() => []);
594
+ protected fPitchwheelLabel: { path: string; chan: number; min: number; max: number }[] = [];
595
+ protected fCtrlLabel: { path: string; chan: number; min: number; max: number }[][] = new Array(128).fill(null).map(() => []);
596
596
  protected fPathTable: { [address: string]: number } = {};
597
597
  protected fUICallback: UIHandler = (item: FaustUIItem) => {
598
598
  if (item.type === "hbargraph" || item.type === "vbargraph") {
@@ -611,14 +611,27 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
611
611
  if (midi) {
612
612
  const strMidi = midi.trim();
613
613
  if (strMidi === "pitchwheel") {
614
- this.fPitchwheelLabel.push({ path: item.address, min: item.min as number, max: item.max as number });
615
- } else {
616
- const matched = strMidi.match(/^ctrl\s(\d+)/);
614
+ const matched = strMidi.match(/^pitchwheel\s(\d+)/);
615
+ // "pitchwheel chan"
617
616
  if (matched) {
618
- this.fCtrlLabel[parseInt(matched[1])].push({ path: item.address, min: item.min as number, max: item.max as number });
617
+ this.fPitchwheelLabel.push({ path: item.address, chan: parseInt(matched[1]), min: item.min as number, max: item.max as number });
618
+ // "pitchwheel"
619
+ } else {
620
+ this.fPitchwheelLabel.push({ path: item.address, chan: 0, min: item.min as number, max: item.max as number });
621
+ }
622
+ } else {
623
+ // "ctrl num chan"
624
+ const matched2 = strMidi.match(/^ctrl\s(\d+)\s(\d+)/);
625
+ // "ctrl num"
626
+ const matched1 = strMidi.match(/^ctrl\s(\d+)/);
627
+ if (matched2) {
628
+ this.fCtrlLabel[parseInt(matched2[1])].push({ path: item.address, chan: parseInt(matched2[2]), min: item.min as number, max: item.max as number });
629
+ } else if (matched1) {
630
+ this.fCtrlLabel[parseInt(matched1[1])].push({ path: item.address, chan: 0, min: item.min as number, max: item.max as number });
619
631
  }
620
632
  }
621
633
  }
634
+
622
635
  // Parse 'acc' metadata
623
636
  if (acc) {
624
637
  const numAcc: number[] = acc.trim().split(" ").map(Number);
@@ -939,10 +952,12 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
939
952
  if (this.fPlotHandler) this.fCachedEvents.push({ type: "ctrlChange", data: [channel, ctrl, value] });
940
953
  if (this.fCtrlLabel[ctrl].length) {
941
954
  this.fCtrlLabel[ctrl].forEach((ctrl) => {
942
- const { path } = ctrl;
943
- this.setParamValue(path, FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl.min, ctrl.max));
944
- // Typically used to reflect parameter change on GUI
945
- if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
955
+ const { path, chan } = ctrl;
956
+ if (chan === 0 || channel === chan - 1) {
957
+ this.setParamValue(path, FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl.min, ctrl.max));
958
+ // Typically used to reflect parameter change on GUI
959
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
960
+ }
946
961
  });
947
962
  }
948
963
  }
@@ -950,9 +965,12 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
950
965
  pitchWheel(channel: number, wheel: number) {
951
966
  if (this.fPlotHandler) this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
952
967
  this.fPitchwheelLabel.forEach((pw) => {
953
- this.setParamValue(pw.path, FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
954
- // Typically used to reflect parameter change on GUI
955
- if (this.fOutputHandler) this.fOutputHandler(pw.path, this.getParamValue(pw.path));
968
+ const { path, chan } = pw;
969
+ if (chan === 0 || channel === chan - 1) {
970
+ this.setParamValue(path, FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
971
+ // Typically used to reflect parameter change on GUI
972
+ if (this.fOutputHandler) this.fOutputHandler(path, this.getParamValue(path));
973
+ }
956
974
  });
957
975
  }
958
976
 
@@ -699,11 +699,13 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
699
699
  protected fSampleSize: number;
700
700
  protected fPitchwheelLabel: {
701
701
  path: string;
702
+ chan: number;
702
703
  min: number;
703
704
  max: number;
704
705
  }[];
705
706
  protected fCtrlLabel: {
706
707
  path: string;
708
+ chan: number;
707
709
  min: number;
708
710
  max: number;
709
711
  }[][];
@@ -2090,11 +2090,24 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2090
2090
  if (midi) {
2091
2091
  const strMidi = midi.trim();
2092
2092
  if (strMidi === "pitchwheel") {
2093
- this.fPitchwheelLabel.push({ path: item.address, min: item.min, max: item.max });
2094
- } else {
2095
- const matched = strMidi.match(/^ctrl\s(\d+)/);
2093
+ const matched = strMidi.match(/^pitchwheel\s(\d+)/);
2096
2094
  if (matched) {
2097
- this.fCtrlLabel[parseInt(matched[1])].push({ path: item.address, min: item.min, max: item.max });
2095
+ this.fPitchwheelLabel.push({ path: item.address, chan: parseInt(matched[1]), min: item.min, max: item.max });
2096
+ } else {
2097
+ this.fPitchwheelLabel.push({ path: item.address, chan: 0, min: item.min, max: item.max });
2098
+ }
2099
+ } else {
2100
+ const matched2 = strMidi.match(/^ctrl\s(\d+)\s(\d+)/);
2101
+ const matched1 = strMidi.match(/^ctrl\s(\d+)/);
2102
+ if (matched2) {
2103
+ console.log("matched2", matched2);
2104
+ console.log("matched2[1]", matched2[1]);
2105
+ console.log("matched2[2]", matched2[2]);
2106
+ this.fCtrlLabel[parseInt(matched2[1])].push({ path: item.address, chan: parseInt(matched2[2]), min: item.min, max: item.max });
2107
+ } else if (matched1) {
2108
+ console.log("matched1", matched1);
2109
+ console.log("matched1[1]", matched1[1]);
2110
+ this.fCtrlLabel[parseInt(matched1[1])].push({ path: item.address, chan: 0, min: item.min, max: item.max });
2098
2111
  }
2099
2112
  }
2100
2113
  }
@@ -2362,10 +2375,13 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2362
2375
  this.fCachedEvents.push({ type: "ctrlChange", data: [channel, ctrl, value] });
2363
2376
  if (this.fCtrlLabel[ctrl].length) {
2364
2377
  this.fCtrlLabel[ctrl].forEach((ctrl2) => {
2365
- const { path } = ctrl2;
2366
- this.setParamValue(path, _FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
2367
- if (this.fOutputHandler)
2368
- this.fOutputHandler(path, this.getParamValue(path));
2378
+ const { path, chan } = ctrl2;
2379
+ console.log("ctrlChange", path, chan, channel);
2380
+ if (chan === 0 || channel === chan - 1) {
2381
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
2382
+ if (this.fOutputHandler)
2383
+ this.fOutputHandler(path, this.getParamValue(path));
2384
+ }
2369
2385
  });
2370
2386
  }
2371
2387
  }
@@ -2373,9 +2389,12 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2373
2389
  if (this.fPlotHandler)
2374
2390
  this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
2375
2391
  this.fPitchwheelLabel.forEach((pw) => {
2376
- this.setParamValue(pw.path, _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
2377
- if (this.fOutputHandler)
2378
- this.fOutputHandler(pw.path, this.getParamValue(pw.path));
2392
+ const { path, chan } = pw;
2393
+ if (chan === 0 || channel === chan - 1) {
2394
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
2395
+ if (this.fOutputHandler)
2396
+ this.fOutputHandler(path, this.getParamValue(path));
2397
+ }
2379
2398
  });
2380
2399
  }
2381
2400
  setParamValue(path, value) {