@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;
@@ -9159,7 +9159,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9159
9159
  // src/SoundfileReader.ts
9160
9160
  var SoundfileReader = class {
9161
9161
  static get fallbackPaths() {
9162
- return [location.href, location.origin, "http://127.0.0.1:8000"];
9162
+ return [location.href, location.origin];
9163
9163
  }
9164
9164
  /**
9165
9165
  * Convert an audio buffer to audio data.
@@ -9592,6 +9592,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9592
9592
  return null;
9593
9593
  }
9594
9594
  }
9595
+ addSoundfiles(soundfileMap) {
9596
+ if (!this.factory)
9597
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9598
+ for (const id in soundfileMap) {
9599
+ this.factory.soundfiles[id] = soundfileMap[id];
9600
+ }
9601
+ }
9602
+ getSoundfileList() {
9603
+ if (!this.factory)
9604
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9605
+ const meta = JSON.parse(this.factory.json);
9606
+ const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
9607
+ return Object.keys(map);
9608
+ }
9595
9609
  async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
9596
9610
  var _a, _b;
9597
9611
  if (!factory)
@@ -9844,6 +9858,24 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
9844
9858
  return null;
9845
9859
  }
9846
9860
  }
9861
+ addSoundfiles(soundfileMap) {
9862
+ if (!this.voiceFactory)
9863
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9864
+ for (const id in soundfileMap) {
9865
+ this.voiceFactory.soundfiles[id] = soundfileMap[id];
9866
+ }
9867
+ }
9868
+ getSoundfileList() {
9869
+ if (!this.voiceFactory)
9870
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
9871
+ const meta = JSON.parse(this.voiceFactory.json);
9872
+ const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
9873
+ if (!this.effectFactory)
9874
+ return Object.keys(map);
9875
+ const effectMeta = JSON.parse(this.effectFactory.json);
9876
+ const effectMap = SoundfileReader_default.findSoundfilesFromMeta(effectMeta);
9877
+ return Object.keys({ ...effectMap, ...map });
9878
+ }
9847
9879
  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`) {
9848
9880
  var _a, _b;
9849
9881
  if (!voiceFactory)