@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;
@@ -2107,6 +2107,7 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2107
2107
  constructor(sampleSize, bufferSize, soundfiles) {
2108
2108
  this.fOutputHandler = null;
2109
2109
  this.fComputeHandler = null;
2110
+ this.fMidiOutputHandler = null;
2110
2111
  // To handle MIDI events plot
2111
2112
  this.fPlotHandler = null;
2112
2113
  this.fCachedEvents = [];
@@ -2372,7 +2373,6 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2372
2373
  * Init soundfiles memory.
2373
2374
  *
2374
2375
  * @param allocator : the wasm memory allocator
2375
- * @param sfReader : the soundfile reader
2376
2376
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
2377
2377
  */
2378
2378
  initSoundfileMemory(allocator, baseDSP) {
@@ -2405,12 +2405,25 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2405
2405
  getOutputParamHandler() {
2406
2406
  return this.fOutputHandler;
2407
2407
  }
2408
+ callOutputParamHandler(path, value) {
2409
+ if (this.fOutputHandler) {
2410
+ this.fOutputHandler(path, value);
2411
+ } else {
2412
+ console.warn("No OutputParamHandler set for this FaustAudioWorkletNode.");
2413
+ }
2414
+ }
2408
2415
  setComputeHandler(handler) {
2409
2416
  this.fComputeHandler = handler;
2410
2417
  }
2411
2418
  getComputeHandler() {
2412
2419
  return this.fComputeHandler;
2413
2420
  }
2421
+ setMidiOutputHandler(handler) {
2422
+ this.fMidiOutputHandler = handler;
2423
+ }
2424
+ getMidiOutputHandler() {
2425
+ return this.fMidiOutputHandler;
2426
+ }
2414
2427
  setPlotHandler(handler) {
2415
2428
  this.fPlotHandler = handler;
2416
2429
  }
@@ -2549,6 +2562,7 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2549
2562
  this.fDestroyed = true;
2550
2563
  this.fOutputHandler = null;
2551
2564
  this.fComputeHandler = null;
2565
+ this.fMidiOutputHandler = null;
2552
2566
  this.fPlotHandler = null;
2553
2567
  }
2554
2568
  };
@@ -3105,12 +3119,21 @@ var FaustOfflineProcessor = class {
3105
3119
  getOutputParamHandler() {
3106
3120
  return this.fDSPCode.getOutputParamHandler();
3107
3121
  }
3122
+ callOutputParamHandler(path, value) {
3123
+ this.fDSPCode.callOutputParamHandler(path, value);
3124
+ }
3108
3125
  setComputeHandler(handler) {
3109
3126
  this.fDSPCode.setComputeHandler(handler);
3110
3127
  }
3111
3128
  getComputeHandler() {
3112
3129
  return this.fDSPCode.getComputeHandler();
3113
3130
  }
3131
+ setMidiOutputHandler(handler) {
3132
+ this.fDSPCode.setMidiOutputHandler(handler);
3133
+ }
3134
+ getMidiOutputHandler() {
3135
+ return this.fDSPCode.getMidiOutputHandler();
3136
+ }
3114
3137
  setPlotHandler(handler) {
3115
3138
  this.fDSPCode.setPlotHandler(handler);
3116
3139
  }
@@ -3953,6 +3976,7 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3953
3976
  processorOptions: options.processorOptions,
3954
3977
  ...options
3955
3978
  });
3979
+ this.fMidiOutputHandler = null;
3956
3980
  __privateAdd(this, _hasAccInput, false);
3957
3981
  __privateAdd(this, _hasGyrInput, false);
3958
3982
  this.handleMessageAux = (e) => {
@@ -4032,12 +4056,25 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
4032
4056
  getOutputParamHandler() {
4033
4057
  return this.fOutputHandler;
4034
4058
  }
4059
+ callOutputParamHandler(path, value) {
4060
+ if (this.fOutputHandler) {
4061
+ this.fOutputHandler(path, value);
4062
+ } else {
4063
+ console.warn("No OutputParamHandler set for this FaustAudioWorkletNode.");
4064
+ }
4065
+ }
4035
4066
  setComputeHandler(handler) {
4036
4067
  this.fComputeHandler = handler;
4037
4068
  }
4038
4069
  getComputeHandler() {
4039
4070
  return this.fComputeHandler;
4040
4071
  }
4072
+ setMidiOutputHandler(handler) {
4073
+ this.fMidiOutputHandler = handler;
4074
+ }
4075
+ getMidiOutputHandler() {
4076
+ return this.fMidiOutputHandler;
4077
+ }
4041
4078
  setPlotHandler(handler) {
4042
4079
  this.fPlotHandler = handler;
4043
4080
  if (this.fPlotHandler) {
@@ -4293,6 +4330,9 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
4293
4330
  getOutputParamHandler() {
4294
4331
  return this.fDSPCode.getOutputParamHandler();
4295
4332
  }
4333
+ callOutputParamHandler(path, value) {
4334
+ this.fDSPCode.callOutputParamHandler(path, value);
4335
+ }
4296
4336
  setComputeHandler(handler) {
4297
4337
  this.fDSPCode.setComputeHandler(handler);
4298
4338
  }
@@ -4305,6 +4345,12 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
4305
4345
  getPlotHandler() {
4306
4346
  return this.fDSPCode.getPlotHandler();
4307
4347
  }
4348
+ setMidiOutputHandler(handler) {
4349
+ this.fDSPCode.setMidiOutputHandler(handler);
4350
+ }
4351
+ getMidiOutputHandler() {
4352
+ return this.fDSPCode.getMidiOutputHandler();
4353
+ }
4308
4354
  getNumInputs() {
4309
4355
  return this.fDSPCode.getNumInputs();
4310
4356
  }