@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.
@@ -425,6 +425,17 @@ export type SensorEventHandlers = {
425
425
  y: SensorEventHandler[];
426
426
  z: SensorEventHandler[];
427
427
  };
428
+ /**
429
+ * Interface for MIDI output handler, used in Faust WebAudio nodes
430
+ * to handle MIDI events like control changes, pitch wheel changes,
431
+ * key on and key off events.
432
+ */
433
+ export interface MidiOutputHandler {
434
+ ctrlChange(chan: number, ctrl: number, value: number): void;
435
+ pitchWheel(chan: number, value: number): void;
436
+ keyOn(channel: number, pitch: number, velocity: number): void;
437
+ keyOff(channel: number, pitch: number, velocity: number): void;
438
+ }
428
439
  /** Definition of the AudioBufferItem type */
429
440
  export interface AudioBufferItem {
430
441
  pathName: string;
@@ -548,6 +559,13 @@ export interface IFaustBaseWebAudioDsp {
548
559
  * @return the current output handler
549
560
  */
550
561
  getOutputParamHandler(): OutputParamHandler | null;
562
+ /**
563
+ * Call the output parameter handler with a path and value.
564
+ *
565
+ * @param path - the path to the wanted parameter (retrieved using 'getParams' method)
566
+ * @param value - the float value for the wanted control
567
+ */
568
+ callOutputParamHandler(path: string, value: number): void;
551
569
  /**
552
570
  * Set the compute handler, to be called in the 'compute' method with buffer size.
553
571
  *
@@ -560,6 +578,18 @@ export interface IFaustBaseWebAudioDsp {
560
578
  * @return the current output handler
561
579
  */
562
580
  getComputeHandler(): ComputeHandler | null;
581
+ /**
582
+ * Set the MIDI output handler, to be called in the 'compute' method with MIDI messages.
583
+ * @param handler - the MIDI output handler
584
+ * @return void
585
+ */
586
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
587
+ /**
588
+ * Get the MIDI output handler.
589
+ *
590
+ * @return the current MIDI output handler
591
+ */
592
+ getMidiOutputHandler(): MidiOutputHandler | null;
563
593
  /**
564
594
  * Set the plot handler, to be called in the 'compute' method with various info (see PlotHandler type).
565
595
  *
@@ -746,6 +776,7 @@ export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode
746
776
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
747
777
  protected fOutputHandler: OutputParamHandler | null;
748
778
  protected fComputeHandler: ComputeHandler | null;
779
+ protected fMidiOutputHandler: MidiOutputHandler | null;
749
780
  protected fPlotHandler: PlotHandler | null;
750
781
  protected fCachedEvents: {
751
782
  type: string;
@@ -841,7 +872,6 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
841
872
  * Init soundfiles memory.
842
873
  *
843
874
  * @param allocator : the wasm memory allocator
844
- * @param sfReader : the soundfile reader
845
875
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
846
876
  */
847
877
  protected initSoundfileMemory(allocator: WasmAllocator, baseDSP: number): void;
@@ -850,8 +880,11 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
850
880
  compute(input: Float32Array[], output: Float32Array[]): boolean;
851
881
  setOutputParamHandler(handler: OutputParamHandler | null): void;
852
882
  getOutputParamHandler(): OutputParamHandler | null;
883
+ callOutputParamHandler(path: string, value: number): void;
853
884
  setComputeHandler(handler: ComputeHandler | null): void;
854
885
  getComputeHandler(): ComputeHandler | null;
886
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
887
+ getMidiOutputHandler(): MidiOutputHandler | null;
855
888
  setPlotHandler(handler: PlotHandler | null): void;
856
889
  getPlotHandler(): PlotHandler | null;
857
890
  getNumInputs(): number;
@@ -1203,8 +1236,11 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1203
1236
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1204
1237
  setOutputParamHandler(handler: OutputParamHandler): void;
1205
1238
  getOutputParamHandler(): OutputParamHandler | null;
1239
+ callOutputParamHandler(path: string, value: number): void;
1206
1240
  setComputeHandler(handler: ComputeHandler): void;
1207
1241
  getComputeHandler(): ComputeHandler | null;
1242
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
1243
+ getMidiOutputHandler(): MidiOutputHandler | null;
1208
1244
  setPlotHandler(handler: PlotHandler): void;
1209
1245
  getPlotHandler(): PlotHandler | null;
1210
1246
  getNumInputs(): number;
@@ -1384,6 +1420,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1384
1420
  protected fInputsItems: string[];
1385
1421
  protected fOutputHandler: OutputParamHandler | null;
1386
1422
  protected fComputeHandler: ComputeHandler | null;
1423
+ protected fMidiOutputHandler: MidiOutputHandler | null;
1387
1424
  protected fPlotHandler: PlotHandler | null;
1388
1425
  protected fUICallback: UIHandler;
1389
1426
  protected fDescriptor: FaustUIInputItem[];
@@ -1397,8 +1434,11 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1397
1434
  stopSensors(): void;
1398
1435
  setOutputParamHandler(handler: OutputParamHandler | null): void;
1399
1436
  getOutputParamHandler(): OutputParamHandler | null;
1437
+ callOutputParamHandler(path: string, value: number): void;
1400
1438
  setComputeHandler(handler: ComputeHandler | null): void;
1401
1439
  getComputeHandler(): ComputeHandler | null;
1440
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
1441
+ getMidiOutputHandler(): MidiOutputHandler | null;
1402
1442
  setPlotHandler(handler: PlotHandler | null): void;
1403
1443
  getPlotHandler(): PlotHandler | null;
1404
1444
  setupWamEventHandler(): void;
@@ -1468,10 +1508,13 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1468
1508
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1469
1509
  setOutputParamHandler(handler: OutputParamHandler): void;
1470
1510
  getOutputParamHandler(): OutputParamHandler | null;
1511
+ callOutputParamHandler(path: string, value: number): void;
1471
1512
  setComputeHandler(handler: ComputeHandler): void;
1472
1513
  getComputeHandler(): ComputeHandler | null;
1473
1514
  setPlotHandler(handler: PlotHandler): void;
1474
1515
  getPlotHandler(): PlotHandler | null;
1516
+ setMidiOutputHandler(handler: MidiOutputHandler | null): void;
1517
+ getMidiOutputHandler(): MidiOutputHandler | null;
1475
1518
  getNumInputs(): number;
1476
1519
  getNumOutputs(): number;
1477
1520
  metadata(handler: MetadataHandler): void;
package/dist/cjs/index.js CHANGED
@@ -2137,6 +2137,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2137
2137
  constructor(sampleSize, bufferSize, soundfiles) {
2138
2138
  this.fOutputHandler = null;
2139
2139
  this.fComputeHandler = null;
2140
+ this.fMidiOutputHandler = null;
2140
2141
  // To handle MIDI events plot
2141
2142
  this.fPlotHandler = null;
2142
2143
  this.fCachedEvents = [];
@@ -2402,7 +2403,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2402
2403
  * Init soundfiles memory.
2403
2404
  *
2404
2405
  * @param allocator : the wasm memory allocator
2405
- * @param sfReader : the soundfile reader
2406
2406
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
2407
2407
  */
2408
2408
  initSoundfileMemory(allocator, baseDSP) {
@@ -2435,12 +2435,25 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2435
2435
  getOutputParamHandler() {
2436
2436
  return this.fOutputHandler;
2437
2437
  }
2438
+ callOutputParamHandler(path, value) {
2439
+ if (this.fOutputHandler) {
2440
+ this.fOutputHandler(path, value);
2441
+ } else {
2442
+ console.warn("No OutputParamHandler set for this FaustAudioWorkletNode.");
2443
+ }
2444
+ }
2438
2445
  setComputeHandler(handler) {
2439
2446
  this.fComputeHandler = handler;
2440
2447
  }
2441
2448
  getComputeHandler() {
2442
2449
  return this.fComputeHandler;
2443
2450
  }
2451
+ setMidiOutputHandler(handler) {
2452
+ this.fMidiOutputHandler = handler;
2453
+ }
2454
+ getMidiOutputHandler() {
2455
+ return this.fMidiOutputHandler;
2456
+ }
2444
2457
  setPlotHandler(handler) {
2445
2458
  this.fPlotHandler = handler;
2446
2459
  }
@@ -2579,6 +2592,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2579
2592
  this.fDestroyed = true;
2580
2593
  this.fOutputHandler = null;
2581
2594
  this.fComputeHandler = null;
2595
+ this.fMidiOutputHandler = null;
2582
2596
  this.fPlotHandler = null;
2583
2597
  }
2584
2598
  };
@@ -3135,12 +3149,21 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3135
3149
  getOutputParamHandler() {
3136
3150
  return this.fDSPCode.getOutputParamHandler();
3137
3151
  }
3152
+ callOutputParamHandler(path, value) {
3153
+ this.fDSPCode.callOutputParamHandler(path, value);
3154
+ }
3138
3155
  setComputeHandler(handler) {
3139
3156
  this.fDSPCode.setComputeHandler(handler);
3140
3157
  }
3141
3158
  getComputeHandler() {
3142
3159
  return this.fDSPCode.getComputeHandler();
3143
3160
  }
3161
+ setMidiOutputHandler(handler) {
3162
+ this.fDSPCode.setMidiOutputHandler(handler);
3163
+ }
3164
+ getMidiOutputHandler() {
3165
+ return this.fDSPCode.getMidiOutputHandler();
3166
+ }
3144
3167
  setPlotHandler(handler) {
3145
3168
  this.fDSPCode.setPlotHandler(handler);
3146
3169
  }
@@ -3983,6 +4006,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3983
4006
  processorOptions: options.processorOptions,
3984
4007
  ...options
3985
4008
  });
4009
+ this.fMidiOutputHandler = null;
3986
4010
  __privateAdd(this, _hasAccInput, false);
3987
4011
  __privateAdd(this, _hasGyrInput, false);
3988
4012
  this.handleMessageAux = (e) => {
@@ -4062,12 +4086,25 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4062
4086
  getOutputParamHandler() {
4063
4087
  return this.fOutputHandler;
4064
4088
  }
4089
+ callOutputParamHandler(path, value) {
4090
+ if (this.fOutputHandler) {
4091
+ this.fOutputHandler(path, value);
4092
+ } else {
4093
+ console.warn("No OutputParamHandler set for this FaustAudioWorkletNode.");
4094
+ }
4095
+ }
4065
4096
  setComputeHandler(handler) {
4066
4097
  this.fComputeHandler = handler;
4067
4098
  }
4068
4099
  getComputeHandler() {
4069
4100
  return this.fComputeHandler;
4070
4101
  }
4102
+ setMidiOutputHandler(handler) {
4103
+ this.fMidiOutputHandler = handler;
4104
+ }
4105
+ getMidiOutputHandler() {
4106
+ return this.fMidiOutputHandler;
4107
+ }
4071
4108
  setPlotHandler(handler) {
4072
4109
  this.fPlotHandler = handler;
4073
4110
  if (this.fPlotHandler) {
@@ -4323,6 +4360,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4323
4360
  getOutputParamHandler() {
4324
4361
  return this.fDSPCode.getOutputParamHandler();
4325
4362
  }
4363
+ callOutputParamHandler(path, value) {
4364
+ this.fDSPCode.callOutputParamHandler(path, value);
4365
+ }
4326
4366
  setComputeHandler(handler) {
4327
4367
  this.fDSPCode.setComputeHandler(handler);
4328
4368
  }
@@ -4335,6 +4375,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4335
4375
  getPlotHandler() {
4336
4376
  return this.fDSPCode.getPlotHandler();
4337
4377
  }
4378
+ setMidiOutputHandler(handler) {
4379
+ this.fDSPCode.setMidiOutputHandler(handler);
4380
+ }
4381
+ getMidiOutputHandler() {
4382
+ return this.fDSPCode.getMidiOutputHandler();
4383
+ }
4338
4384
  getNumInputs() {
4339
4385
  return this.fDSPCode.getNumInputs();
4340
4386
  }