UNPKG

3.85 kBTypeScriptView Raw
1import { Param } from "../../core/context/Param.js";
2import { ToneAudioBuffer } from "../../core/context/ToneAudioBuffer.js";
3import { ToneAudioBuffersUrlMap } from "../../core/context/ToneAudioBuffers.js";
4import { OutputNode, ToneAudioNode } from "../../core/context/ToneAudioNode.js";
5import { Decibels, Time } from "../../core/type/Units.js";
6import { BasicPlaybackState } from "../../core/util/StateTimeline.js";
7import { SourceOptions } from "../Source.js";
8import { Player } from "./Player.js";
9export interface PlayersOptions extends SourceOptions {
10 urls: ToneAudioBuffersUrlMap;
11 volume: Decibels;
12 mute: boolean;
13 onload: () => void;
14 onerror: (error: Error) => void;
15 baseUrl: string;
16 fadeIn: Time;
17 fadeOut: Time;
18}
19/**
20 * Players combines multiple {@link Player} objects.
21 * @category Source
22 */
23export declare class Players extends ToneAudioNode<PlayersOptions> {
24 readonly name: string;
25 /**
26 * The output volume node
27 */
28 private _volume;
29 /**
30 * The volume of the output in decibels.
31 */
32 readonly volume: Param<"decibels">;
33 /**
34 * The combined output of all of the players
35 */
36 readonly output: OutputNode;
37 /**
38 * Players has no input.
39 */
40 readonly input: undefined;
41 /**
42 * The container of all of the players
43 */
44 private _players;
45 /**
46 * The container of all the buffers
47 */
48 private _buffers;
49 /**
50 * private holder of the fadeIn time
51 */
52 private _fadeIn;
53 /**
54 * private holder of the fadeOut time
55 */
56 private _fadeOut;
57 /**
58 * @param urls An object mapping a name to a url.
59 * @param onload The function to invoke when all buffers are loaded.
60 */
61 constructor(urls?: ToneAudioBuffersUrlMap, onload?: () => void);
62 /**
63 * @param urls An object mapping a name to a url.
64 * @param options The remaining options associated with the players
65 */
66 constructor(urls?: ToneAudioBuffersUrlMap, options?: Partial<Omit<PlayersOptions, "urls">>);
67 constructor(options?: Partial<PlayersOptions>);
68 static getDefaults(): PlayersOptions;
69 /**
70 * Mute the output.
71 */
72 get mute(): boolean;
73 set mute(mute: boolean);
74 /**
75 * The fadeIn time of the envelope applied to the source.
76 */
77 get fadeIn(): Time;
78 set fadeIn(fadeIn: Time);
79 /**
80 * The fadeOut time of the each of the sources.
81 */
82 get fadeOut(): Time;
83 set fadeOut(fadeOut: Time);
84 /**
85 * The state of the players object. Returns "started" if any of the players are playing.
86 */
87 get state(): BasicPlaybackState;
88 /**
89 * True if the buffers object has a buffer by that name.
90 * @param name The key or index of the buffer.
91 */
92 has(name: string): boolean;
93 /**
94 * Get a player by name.
95 * @param name The players name as defined in the constructor object or `add` method.
96 */
97 player(name: string): Player;
98 /**
99 * If all the buffers are loaded or not
100 */
101 get loaded(): boolean;
102 /**
103 * Add a player by name and url to the Players
104 * @param name A unique name to give the player
105 * @param url Either the url of the bufer or a buffer which will be added with the given name.
106 * @param callback The callback to invoke when the url is loaded.
107 * @example
108 * const players = new Tone.Players();
109 * players.add("gong", "https://tonejs.github.io/audio/berklee/gong_1.mp3", () => {
110 * console.log("gong loaded");
111 * players.player("gong").start();
112 * });
113 */
114 add(name: string, url: string | ToneAudioBuffer | AudioBuffer, callback?: () => void): this;
115 /**
116 * Stop all of the players at the given time
117 * @param time The time to stop all of the players.
118 */
119 stopAll(time?: Time): this;
120 dispose(): this;
121}