UNPKG

@azgaar/tone

Version:

A fork of Web Audio framework for making interactive music in the browser.

86 lines (85 loc) 2.94 kB
import { Tone } from "../Tone"; import { ToneMediaElement } from "./ToneMediaElement"; export interface ToneMediaElementsUrlMap { [name: string]: string; [name: number]: string; } interface ToneMediaElementsOptions { urls: ToneMediaElementsUrlMap; onload: () => void; onerror?: (error: Error) => void; baseUrl: string; } /** * A data structure for holding multiple MediaElements in a Map-like datastructure. * * @example * const pianoMediaElementSamples = new Tone.ToneMediaElements({ * A1: "https://tonejs.github.io/audio/casio/A1.mp3", * A2: "https://tonejs.github.io/audio/casio/A2.mp3", * }, () => { * const player = new Tone.Player().toDestination(); * // play one of the samples when they all load * player.element = pianoSamples.get("A2"); * player.start(); * }); * @example * // To pass in additional parameters in the second parameter * const elements = new Tone.ToneMediaElements({ * urls: { * A1: "A1.mp3", * A2: "A2.mp3", * }, * onload: () => console.log("loaded"), * baseUrl: "https://tonejs.github.io/audio/casio/" * }); * @category Core */ export declare class ToneMediaElements extends Tone { readonly name: string; /** * All of the elements */ private _elements; /** * A path which is prefixed before every url. */ baseUrl: string; /** * Keep track of the number of loaded elements */ private _loadingCount; /** * @param urls An object literal or array of urls to load. * @param onload The callback to invoke when the elements are loaded. * @param baseUrl A prefix url to add before all the urls */ constructor(urls?: ToneMediaElementsUrlMap, onload?: () => void, baseUrl?: string); constructor(options?: Partial<ToneMediaElementsOptions>); static getDefaults(): ToneMediaElementsOptions; /** * True if the elements object has a element by that name. * @param name The key or index of the element. */ has(name: string | number): boolean; /** * Get a element by name. If an array was loaded, * then use the array index. * @param name The key or index of the element. */ get(name: string | number): ToneMediaElement; /** * A element was loaded. decrement the counter. */ private _elementLoaded; /** * Add a element by name and url to the elements * @param name A unique name to give the element * @param url Either the url of the bufer, or a element which will be added with the given name. * @param callback The callback to invoke when the url is loaded. * @param onerror Invoked if the element can't be loaded */ add(name: string | number, url: string, callback?: () => void, onerror?: (e: Error) => void): this; dispose(): this; } export {};