@grame/faustwasm 0.10.2 → 0.11.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.
@@ -432,6 +432,17 @@ export type SensorEventHandlers = {
432
432
  y: SensorEventHandler[];
433
433
  z: SensorEventHandler[];
434
434
  };
435
+ /**
436
+ * Interface for MIDI output handler, used in Faust WebAudio nodes
437
+ * to handle MIDI events like control changes, pitch wheel changes,
438
+ * key on and key off events.
439
+ */
440
+ export interface MidiOutputHandler {
441
+ ctrlChange(chan: number, ctrl: number, value: number): void;
442
+ pitchWheel(chan: number, value: number): void;
443
+ keyOn(channel: number, pitch: number, velocity: number): void;
444
+ keyOff(channel: number, pitch: number, velocity: number): void;
445
+ }
435
446
  /** Definition of the AudioBufferItem type */
436
447
  export interface AudioBufferItem {
437
448
  pathName: string;
@@ -555,6 +566,13 @@ export interface IFaustBaseWebAudioDsp {
555
566
  * @return the current output handler
556
567
  */
557
568
  getOutputParamHandler(): OutputParamHandler | null;
569
+ /**
570
+ * Call the output parameter handler with a path and value.
571
+ *
572
+ * @param path - the path to the wanted parameter (retrieved using 'getParams' method)
573
+ * @param value - the float value for the wanted control
574
+ */
575
+ callOutputParamHandler(path: string, value: number): void;
558
576
  /**
559
577
  * Set the compute handler, to be called in the 'compute' method with buffer size.
560
578
  *
@@ -567,6 +585,18 @@ export interface IFaustBaseWebAudioDsp {
567
585
  * @return the current output handler
568
586
  */
569
587
  getComputeHandler(): ComputeHandler | null;
588
+ /**
589
+ * Set the MIDI output handler, to be called in the 'compute' method with MIDI messages.
590
+ * @param handler - the MIDI output handler
591
+ * @return void
592
+ */
593
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
594
+ /**
595
+ * Get the MIDI output handler.
596
+ *
597
+ * @return the current MIDI output handler
598
+ */
599
+ getMidiOutputHandler(): MidiOutputHandler | null;
570
600
  /**
571
601
  * Set the plot handler, to be called in the 'compute' method with various info (see PlotHandler type).
572
602
  *
@@ -753,6 +783,7 @@ export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode
753
783
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
754
784
  protected fOutputHandler: OutputParamHandler | null;
755
785
  protected fComputeHandler: ComputeHandler | null;
786
+ protected fMidiOutputHandler: MidiOutputHandler | null;
756
787
  protected fPlotHandler: PlotHandler | null;
757
788
  protected fCachedEvents: {
758
789
  type: string;
@@ -848,7 +879,6 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
848
879
  * Init soundfiles memory.
849
880
  *
850
881
  * @param allocator : the wasm memory allocator
851
- * @param sfReader : the soundfile reader
852
882
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
853
883
  */
854
884
  protected initSoundfileMemory(allocator: WasmAllocator, baseDSP: number): void;
@@ -857,8 +887,11 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
857
887
  compute(input: Float32Array[], output: Float32Array[]): boolean;
858
888
  setOutputParamHandler(handler: OutputParamHandler | null): void;
859
889
  getOutputParamHandler(): OutputParamHandler | null;
890
+ callOutputParamHandler(path: string, value: number): void;
860
891
  setComputeHandler(handler: ComputeHandler | null): void;
861
892
  getComputeHandler(): ComputeHandler | null;
893
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
894
+ getMidiOutputHandler(): MidiOutputHandler | null;
862
895
  setPlotHandler(handler: PlotHandler | null): void;
863
896
  getPlotHandler(): PlotHandler | null;
864
897
  getNumInputs(): number;
@@ -1210,8 +1243,11 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1210
1243
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1211
1244
  setOutputParamHandler(handler: OutputParamHandler): void;
1212
1245
  getOutputParamHandler(): OutputParamHandler | null;
1246
+ callOutputParamHandler(path: string, value: number): void;
1213
1247
  setComputeHandler(handler: ComputeHandler): void;
1214
1248
  getComputeHandler(): ComputeHandler | null;
1249
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
1250
+ getMidiOutputHandler(): MidiOutputHandler | null;
1215
1251
  setPlotHandler(handler: PlotHandler): void;
1216
1252
  getPlotHandler(): PlotHandler | null;
1217
1253
  getNumInputs(): number;
@@ -1391,6 +1427,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1391
1427
  protected fInputsItems: string[];
1392
1428
  protected fOutputHandler: OutputParamHandler | null;
1393
1429
  protected fComputeHandler: ComputeHandler | null;
1430
+ protected fMidiOutputHandler: MidiOutputHandler | null;
1394
1431
  protected fPlotHandler: PlotHandler | null;
1395
1432
  protected fUICallback: UIHandler;
1396
1433
  protected fDescriptor: FaustUIInputItem[];
@@ -1404,8 +1441,11 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1404
1441
  stopSensors(): void;
1405
1442
  setOutputParamHandler(handler: OutputParamHandler | null): void;
1406
1443
  getOutputParamHandler(): OutputParamHandler | null;
1444
+ callOutputParamHandler(path: string, value: number): void;
1407
1445
  setComputeHandler(handler: ComputeHandler | null): void;
1408
1446
  getComputeHandler(): ComputeHandler | null;
1447
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
1448
+ getMidiOutputHandler(): MidiOutputHandler | null;
1409
1449
  setPlotHandler(handler: PlotHandler | null): void;
1410
1450
  getPlotHandler(): PlotHandler | null;
1411
1451
  setupWamEventHandler(): void;
@@ -1475,10 +1515,13 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1475
1515
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1476
1516
  setOutputParamHandler(handler: OutputParamHandler): void;
1477
1517
  getOutputParamHandler(): OutputParamHandler | null;
1518
+ callOutputParamHandler(path: string, value: number): void;
1478
1519
  setComputeHandler(handler: ComputeHandler): void;
1479
1520
  getComputeHandler(): ComputeHandler | null;
1480
1521
  setPlotHandler(handler: PlotHandler): void;
1481
1522
  getPlotHandler(): PlotHandler | null;
1523
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
1524
+ getMidiOutputHandler(): MidiOutputHandler | null;
1482
1525
  getNumInputs(): number;
1483
1526
  getNumOutputs(): number;
1484
1527
  metadata(handler: MetadataHandler): void;
@@ -8061,6 +8061,7 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8061
8061
  constructor(sampleSize, bufferSize, soundfiles) {
8062
8062
  this.fOutputHandler = null;
8063
8063
  this.fComputeHandler = null;
8064
+ this.fMidiOutputHandler = null;
8064
8065
  // To handle MIDI events plot
8065
8066
  this.fPlotHandler = null;
8066
8067
  this.fCachedEvents = [];
@@ -8326,7 +8327,6 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8326
8327
  * Init soundfiles memory.
8327
8328
  *
8328
8329
  * @param allocator : the wasm memory allocator
8329
- * @param sfReader : the soundfile reader
8330
8330
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
8331
8331
  */
8332
8332
  initSoundfileMemory(allocator, baseDSP) {
@@ -8359,12 +8359,25 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8359
8359
  getOutputParamHandler() {
8360
8360
  return this.fOutputHandler;
8361
8361
  }
8362
+ callOutputParamHandler(path, value) {
8363
+ if (this.fOutputHandler) {
8364
+ this.fOutputHandler(path, value);
8365
+ } else {
8366
+ console.warn("No OutputParamHandler set for this FaustAudioWorkletNode.");
8367
+ }
8368
+ }
8362
8369
  setComputeHandler(handler) {
8363
8370
  this.fComputeHandler = handler;
8364
8371
  }
8365
8372
  getComputeHandler() {
8366
8373
  return this.fComputeHandler;
8367
8374
  }
8375
+ setMidiOutputHandler(handler) {
8376
+ this.fMidiOutputHandler = handler;
8377
+ }
8378
+ getMidiOutputHandler() {
8379
+ return this.fMidiOutputHandler;
8380
+ }
8368
8381
  setPlotHandler(handler) {
8369
8382
  this.fPlotHandler = handler;
8370
8383
  }
@@ -8503,6 +8516,7 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8503
8516
  this.fDestroyed = true;
8504
8517
  this.fOutputHandler = null;
8505
8518
  this.fComputeHandler = null;
8519
+ this.fMidiOutputHandler = null;
8506
8520
  this.fPlotHandler = null;
8507
8521
  }
8508
8522
  };
@@ -9059,12 +9073,21 @@ var FaustOfflineProcessor = class {
9059
9073
  getOutputParamHandler() {
9060
9074
  return this.fDSPCode.getOutputParamHandler();
9061
9075
  }
9076
+ callOutputParamHandler(path, value) {
9077
+ this.fDSPCode.callOutputParamHandler(path, value);
9078
+ }
9062
9079
  setComputeHandler(handler) {
9063
9080
  this.fDSPCode.setComputeHandler(handler);
9064
9081
  }
9065
9082
  getComputeHandler() {
9066
9083
  return this.fDSPCode.getComputeHandler();
9067
9084
  }
9085
+ setMidiOutputHandler(handler) {
9086
+ this.fDSPCode.setMidiOutputHandler(handler);
9087
+ }
9088
+ getMidiOutputHandler() {
9089
+ return this.fDSPCode.getMidiOutputHandler();
9090
+ }
9068
9091
  setPlotHandler(handler) {
9069
9092
  this.fDSPCode.setPlotHandler(handler);
9070
9093
  }
@@ -9907,6 +9930,7 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
9907
9930
  processorOptions: options.processorOptions,
9908
9931
  ...options
9909
9932
  });
9933
+ this.fMidiOutputHandler = null;
9910
9934
  __privateAdd(this, _hasAccInput, false);
9911
9935
  __privateAdd(this, _hasGyrInput, false);
9912
9936
  this.handleMessageAux = (e) => {
@@ -9986,12 +10010,25 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
9986
10010
  getOutputParamHandler() {
9987
10011
  return this.fOutputHandler;
9988
10012
  }
10013
+ callOutputParamHandler(path, value) {
10014
+ if (this.fOutputHandler) {
10015
+ this.fOutputHandler(path, value);
10016
+ } else {
10017
+ console.warn("No OutputParamHandler set for this FaustAudioWorkletNode.");
10018
+ }
10019
+ }
9989
10020
  setComputeHandler(handler) {
9990
10021
  this.fComputeHandler = handler;
9991
10022
  }
9992
10023
  getComputeHandler() {
9993
10024
  return this.fComputeHandler;
9994
10025
  }
10026
+ setMidiOutputHandler(handler) {
10027
+ this.fMidiOutputHandler = handler;
10028
+ }
10029
+ getMidiOutputHandler() {
10030
+ return this.fMidiOutputHandler;
10031
+ }
9995
10032
  setPlotHandler(handler) {
9996
10033
  this.fPlotHandler = handler;
9997
10034
  if (this.fPlotHandler) {
@@ -10247,6 +10284,9 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
10247
10284
  getOutputParamHandler() {
10248
10285
  return this.fDSPCode.getOutputParamHandler();
10249
10286
  }
10287
+ callOutputParamHandler(path, value) {
10288
+ this.fDSPCode.callOutputParamHandler(path, value);
10289
+ }
10250
10290
  setComputeHandler(handler) {
10251
10291
  this.fDSPCode.setComputeHandler(handler);
10252
10292
  }
@@ -10259,6 +10299,12 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
10259
10299
  getPlotHandler() {
10260
10300
  return this.fDSPCode.getPlotHandler();
10261
10301
  }
10302
+ setMidiOutputHandler(handler) {
10303
+ this.fDSPCode.setMidiOutputHandler(handler);
10304
+ }
10305
+ getMidiOutputHandler() {
10306
+ return this.fDSPCode.getMidiOutputHandler();
10307
+ }
10262
10308
  getNumInputs() {
10263
10309
  return this.fDSPCode.getNumInputs();
10264
10310
  }