UNPKG

3.72 kBTypeScriptView Raw
1import { Param } from "../core/context/Param.js";
2import { OutputNode, ToneAudioNode, ToneAudioNodeOptions } from "../core/context/ToneAudioNode.js";
3import { Decibels, Frequency, NormalRange, Time } from "../core/type/Units.js";
4export interface InstrumentOptions extends ToneAudioNodeOptions {
5 volume: Decibels;
6}
7/**
8 * Base-class for all instruments
9 */
10export declare abstract class Instrument<Options extends InstrumentOptions> extends ToneAudioNode<Options> {
11 /**
12 * The output and volume triming node
13 */
14 private _volume;
15 output: OutputNode;
16 /**
17 * The instrument only has an output
18 */
19 input: undefined;
20 /**
21 * The volume of the output in decibels.
22 * @example
23 * const amSynth = new Tone.AMSynth().toDestination();
24 * amSynth.volume.value = -6;
25 * amSynth.triggerAttackRelease("G#3", 0.2);
26 */
27 volume: Param<"decibels">;
28 /**
29 * Keep track of all events scheduled to the transport
30 * when the instrument is 'synced'
31 */
32 private _scheduledEvents;
33 /**
34 * If the instrument is currently synced
35 */
36 private _synced;
37 constructor(options?: Partial<InstrumentOptions>);
38 static getDefaults(): InstrumentOptions;
39 /**
40 * Sync the instrument to the Transport. All subsequent calls of
41 * {@link triggerAttack} and {@link triggerRelease} will be scheduled along the transport.
42 * @example
43 * const fmSynth = new Tone.FMSynth().toDestination();
44 * fmSynth.volume.value = -6;
45 * fmSynth.sync();
46 * // schedule 3 notes when the transport first starts
47 * fmSynth.triggerAttackRelease("C4", "8n", 0);
48 * fmSynth.triggerAttackRelease("E4", "8n", "8n");
49 * fmSynth.triggerAttackRelease("G4", "8n", "4n");
50 * // start the transport to hear the notes
51 * Tone.Transport.start();
52 */
53 sync(): this;
54 /**
55 * set _sync
56 */
57 protected _syncState(): boolean;
58 /**
59 * Wrap the given method so that it can be synchronized
60 * @param method Which method to wrap and sync
61 * @param timePosition What position the time argument appears in
62 */
63 protected _syncMethod(method: string, timePosition: number): void;
64 /**
65 * Unsync the instrument from the Transport
66 */
67 unsync(): this;
68 /**
69 * Trigger the attack and then the release after the duration.
70 * @param note The note to trigger.
71 * @param duration How long the note should be held for before
72 * triggering the release. This value must be greater than 0.
73 * @param time When the note should be triggered.
74 * @param velocity The velocity the note should be triggered at.
75 * @example
76 * const synth = new Tone.Synth().toDestination();
77 * // trigger "C4" for the duration of an 8th note
78 * synth.triggerAttackRelease("C4", "8n");
79 */
80 triggerAttackRelease(note: Frequency, duration: Time, time?: Time, velocity?: NormalRange): this;
81 /**
82 * Start the instrument's note.
83 * @param note the note to trigger
84 * @param time the time to trigger the note
85 * @param velocity the velocity to trigger the note (between 0-1)
86 */
87 abstract triggerAttack(note: Frequency, time?: Time, velocity?: NormalRange): this;
88 private _original_triggerAttack;
89 /**
90 * Trigger the release phase of the current note.
91 * @param time when to trigger the release
92 */
93 abstract triggerRelease(...args: any[]): this;
94 private _original_triggerRelease;
95 /**
96 * The release which is scheduled to the timeline.
97 */
98 protected _syncedRelease: (time: number) => this;
99 /**
100 * clean up
101 * @returns {Instrument} this
102 */
103 dispose(): this;
104}