UNPKG

2.99 kBTypeScriptView Raw
1import { Tone } from "../Tone.js";
2import { ToneAudioBuffer } from "./ToneAudioBuffer.js";
3export interface ToneAudioBuffersUrlMap {
4 [name: string]: string | AudioBuffer | ToneAudioBuffer;
5 [name: number]: string | AudioBuffer | ToneAudioBuffer;
6}
7interface ToneAudioBuffersOptions {
8 urls: ToneAudioBuffersUrlMap;
9 onload: () => void;
10 onerror?: (error: Error) => void;
11 baseUrl: string;
12}
13/**
14 * A data structure for holding multiple buffers in a Map-like datastructure.
15 *
16 * @example
17 * const pianoSamples = new Tone.ToneAudioBuffers({
18 * A1: "https://tonejs.github.io/audio/casio/A1.mp3",
19 * A2: "https://tonejs.github.io/audio/casio/A2.mp3",
20 * }, () => {
21 * const player = new Tone.Player().toDestination();
22 * // play one of the samples when they all load
23 * player.buffer = pianoSamples.get("A2");
24 * player.start();
25 * });
26 * @example
27 * // To pass in additional parameters in the second parameter
28 * const buffers = new Tone.ToneAudioBuffers({
29 * urls: {
30 * A1: "A1.mp3",
31 * A2: "A2.mp3",
32 * },
33 * onload: () => console.log("loaded"),
34 * baseUrl: "https://tonejs.github.io/audio/casio/"
35 * });
36 * @category Core
37 */
38export declare class ToneAudioBuffers extends Tone {
39 readonly name: string;
40 /**
41 * All of the buffers
42 */
43 private _buffers;
44 /**
45 * A path which is prefixed before every url.
46 */
47 baseUrl: string;
48 /**
49 * Keep track of the number of loaded buffers
50 */
51 private _loadingCount;
52 /**
53 * @param urls An object literal or array of urls to load.
54 * @param onload The callback to invoke when the buffers are loaded.
55 * @param baseUrl A prefix url to add before all the urls
56 */
57 constructor(urls?: ToneAudioBuffersUrlMap, onload?: () => void, baseUrl?: string);
58 constructor(options?: Partial<ToneAudioBuffersOptions>);
59 static getDefaults(): ToneAudioBuffersOptions;
60 /**
61 * True if the buffers object has a buffer by that name.
62 * @param name The key or index of the buffer.
63 */
64 has(name: string | number): boolean;
65 /**
66 * Get a buffer by name. If an array was loaded,
67 * then use the array index.
68 * @param name The key or index of the buffer.
69 */
70 get(name: string | number): ToneAudioBuffer;
71 /**
72 * A buffer was loaded. decrement the counter.
73 */
74 private _bufferLoaded;
75 /**
76 * If the buffers are loaded or not
77 */
78 get loaded(): boolean;
79 /**
80 * Add a buffer by name and url to the Buffers
81 * @param name A unique name to give the buffer
82 * @param url Either the url of the bufer, or a buffer which will be added with the given name.
83 * @param callback The callback to invoke when the url is loaded.
84 * @param onerror Invoked if the buffer can't be loaded
85 */
86 add(name: string | number, url: string | AudioBuffer | ToneAudioBuffer, callback?: () => void, onerror?: (e: Error) => void): this;
87 dispose(): this;
88}
89export {};