UNPKG

3.15 kBTypeScriptView Raw
1import { FrequencyClass } from "../core/type/Frequency.js";
2import { Cents, Frequency, NormalRange, Seconds, Time } from "../core/type/Units.js";
3import { Instrument, InstrumentOptions } from "../instrument/Instrument.js";
4import { Signal } from "../signal/Signal.js";
5type onSilenceCallback = (instrument: Monophonic<any>) => void;
6export interface MonophonicOptions extends InstrumentOptions {
7 portamento: Seconds;
8 onsilence: onSilenceCallback;
9 detune: Cents;
10}
11/**
12 * Abstract base class for other monophonic instruments to extend.
13 */
14export declare abstract class Monophonic<Options extends MonophonicOptions> extends Instrument<Options> {
15 /**
16 * The glide time between notes.
17 */
18 portamento: Seconds;
19 /**
20 * Invoked when the release has finished and the output is silent.
21 */
22 onsilence: onSilenceCallback;
23 /**
24 * The instrument's frequency signal.
25 */
26 abstract readonly frequency: Signal<"frequency">;
27 /**
28 * The instrument's detune control signal.
29 */
30 abstract readonly detune: Signal<"cents">;
31 constructor(options?: Partial<MonophonicOptions>);
32 static getDefaults(): MonophonicOptions;
33 /**
34 * Trigger the attack of the note optionally with a given velocity.
35 * @param note The note to trigger.
36 * @param time When the note should start.
37 * @param velocity The velocity determines how "loud" the note will be.
38 * @example
39 * const synth = new Tone.Synth().toDestination();
40 * // trigger the note a half second from now at half velocity
41 * synth.triggerAttack("C4", "+0.5", 0.5);
42 */
43 triggerAttack(note: Frequency | FrequencyClass, time?: Time, velocity?: NormalRange): this;
44 /**
45 * Trigger the release portion of the envelope.
46 * @param time If no time is given, the release happens immediately.
47 * @example
48 * const synth = new Tone.Synth().toDestination();
49 * synth.triggerAttack("C4");
50 * // trigger the release a second from now
51 * synth.triggerRelease("+1");
52 */
53 triggerRelease(time?: Time): this;
54 /**
55 * Internal method which starts the envelope attack
56 */
57 protected abstract _triggerEnvelopeAttack(time: Seconds, velocity: NormalRange): void;
58 /**
59 * Internal method which starts the envelope release
60 */
61 protected abstract _triggerEnvelopeRelease(time: Seconds): void;
62 /**
63 * Get the level of the output at the given time. Measures
64 * the envelope(s) value at the time.
65 * @param time The time to query the envelope value
66 * @return The output level between 0-1
67 */
68 abstract getLevelAtTime(time: Time): NormalRange;
69 /**
70 * Set the note at the given time. If no time is given, the note
71 * will set immediately.
72 * @param note The note to change to.
73 * @param time The time when the note should be set.
74 * @example
75 * const synth = new Tone.Synth().toDestination();
76 * synth.triggerAttack("C4");
77 * // change to F#6 in one quarter note from now.
78 * synth.setNote("F#6", "+4n");
79 */
80 setNote(note: Frequency | FrequencyClass, time?: Time): this;
81}
82export {};