@grame/faustwasm 0.2.0 → 0.2.1

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.
@@ -1203,7 +1203,7 @@ export declare class SoundfileReader {
1203
1203
  * @param dspMeta : the metadata
1204
1204
  * @returns : the URLs
1205
1205
  */
1206
- private static findSoundfilesFromMeta;
1206
+ static findSoundfilesFromMeta(dspMeta: FaustDspMeta): LooseFaustDspFactory["soundfiles"];
1207
1207
  /**
1208
1208
  * Check if the file exists.
1209
1209
  *
@@ -1343,7 +1343,19 @@ export declare class FaustPolyScriptProcessorNode extends FaustScriptProcessorNo
1343
1343
  keyOff(channel: number, pitch: number, velocity: number): void;
1344
1344
  allNotesOff(hard: boolean): void;
1345
1345
  }
1346
- export interface IFaustMonoDspGenerator {
1346
+ export interface GeneratorSupportingSoundfiles {
1347
+ /**
1348
+ * Attach a map of id - audio data, call after `compile()` before `createNode()`
1349
+ *
1350
+ * @param soundfileMap a map of id - `AudioData` as an object where `AudioData` contains channel data as `audioBuffer: Float32Array[]` and `sampleRate: number`
1351
+ */
1352
+ addSoundfiles(soundfileMap: Record<string, AudioData>): void;
1353
+ /**
1354
+ * Get a list of soundfiles needed, call after `compile()`
1355
+ */
1356
+ getSoundfileList(): string[];
1357
+ }
1358
+ export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
1347
1359
  /**
1348
1360
  * Compile a monophonic DSP factory from given code.
1349
1361
  *
@@ -1410,7 +1422,7 @@ export interface IFaustMonoDspGenerator {
1410
1422
  */
1411
1423
  getUI(): FaustUIDescriptor;
1412
1424
  }
1413
- export interface IFaustPolyDspGenerator {
1425
+ export interface IFaustPolyDspGenerator extends GeneratorSupportingSoundfiles {
1414
1426
  /**
1415
1427
  * Compile a monophonic DSP factory from given code.
1416
1428
  *
@@ -1475,6 +1487,8 @@ export declare class FaustMonoDspGenerator implements IFaustMonoDspGenerator {
1475
1487
  factory: FaustDspFactory | null;
1476
1488
  constructor();
1477
1489
  compile(compiler: IFaustCompiler, name: string, code: string, args: string): Promise<this | null>;
1490
+ addSoundfiles(soundfileMap: Record<string, AudioData>): void;
1491
+ getSoundfileList(): string[];
1478
1492
  createNode<SP extends boolean = false>(context: BaseAudioContext, name?: string, factory?: LooseFaustDspFactory, sp?: SP, bufferSize?: number, processorName?: string): Promise<SP extends true ? FaustMonoScriptProcessorNode | null : FaustMonoAudioWorkletNode | null>;
1479
1493
  createFFTNode(context: BaseAudioContext, fftUtils: typeof FFTUtils, name?: string, factory?: LooseFaustDspFactory, fftOptions?: Partial<FaustFFTOptionsData>, processorName?: string): Promise<FaustMonoAudioWorkletNode | null>;
1480
1494
  createAudioWorkletProcessor(name?: string, factory?: LooseFaustDspFactory, processorName?: string): Promise<{
@@ -1496,6 +1510,8 @@ export declare class FaustPolyDspGenerator implements IFaustPolyDspGenerator {
1496
1510
  mixerModule: WebAssembly.Module;
1497
1511
  constructor();
1498
1512
  compile(compiler: IFaustCompiler, name: string, dspCodeAux: string, args: string, effectCodeAux?: string): Promise<this | null>;
1513
+ addSoundfiles(soundfileMap: Record<string, AudioData>): void;
1514
+ getSoundfileList(): string[];
1499
1515
  createNode<SP extends boolean = false>(context: BaseAudioContext, voices: number, name?: string, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, sp?: SP, bufferSize?: number, processorName?: string): Promise<SP extends true ? FaustPolyScriptProcessorNode | null : FaustPolyAudioWorkletNode | null>;
1500
1516
  createAudioWorkletProcessor(name?: string, voiceFactory?: LooseFaustDspFactory, effectFactory?: LooseFaustDspFactory | null, processorName?: string): Promise<{
1501
1517
  new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
@@ -9114,7 +9114,7 @@ var WavDecoder_default = WavDecoder;
9114
9114
  // src/SoundfileReader.ts
9115
9115
  var SoundfileReader = class {
9116
9116
  static get fallbackPaths() {
9117
- return [location.href, location.origin, "http://127.0.0.1:8000"];
9117
+ return [location.href, location.origin];
9118
9118
  }
9119
9119
  /**
9120
9120
  * Convert an audio buffer to audio data.
@@ -9547,6 +9547,20 @@ var _FaustMonoDspGenerator = class _FaustMonoDspGenerator {
9547
9547
  return null;
9548
9548
  }
9549
9549
  }
9550
+ addSoundfiles(soundfileMap) {
9551
+ if (!this.factory)
9552
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9553
+ for (const id in soundfileMap) {
9554
+ this.factory.soundfiles[id] = soundfileMap[id];
9555
+ }
9556
+ }
9557
+ getSoundfileList() {
9558
+ if (!this.factory)
9559
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9560
+ const meta = JSON.parse(this.factory.json);
9561
+ const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
9562
+ return Object.keys(map);
9563
+ }
9550
9564
  async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
9551
9565
  var _a, _b;
9552
9566
  if (!factory)
@@ -9799,6 +9813,24 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
9799
9813
  return null;
9800
9814
  }
9801
9815
  }
9816
+ addSoundfiles(soundfileMap) {
9817
+ if (!this.voiceFactory)
9818
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9819
+ for (const id in soundfileMap) {
9820
+ this.voiceFactory.soundfiles[id] = soundfileMap[id];
9821
+ }
9822
+ }
9823
+ getSoundfileList() {
9824
+ if (!this.voiceFactory)
9825
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9826
+ const meta = JSON.parse(this.voiceFactory.json);
9827
+ const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
9828
+ if (!this.effectFactory)
9829
+ return Object.keys(map);
9830
+ const effectMeta = JSON.parse(this.effectFactory.json);
9831
+ const effectMap = SoundfileReader_default.findSoundfilesFromMeta(effectMeta);
9832
+ return Object.keys({ ...effectMap, ...map });
9833
+ }
9802
9834
  async createNode(context, voices, name = this.name, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, sp = false, bufferSize = 1024, processorName = ((voiceFactory == null ? void 0 : voiceFactory.shaKey) || "") + ((effectFactory == null ? void 0 : effectFactory.shaKey) || "") || `${name}_poly`) {
9803
9835
  var _a, _b;
9804
9836
  if (!voiceFactory)