UNPKG

4.39 kBTypeScriptView Raw
1import { AbstractParam } from "../core/context/AbstractParam.js";
2import { Param } from "../core/context/Param.js";
3import { InputNode, OutputNode, ToneAudioNode, ToneAudioNodeOptions } from "../core/context/ToneAudioNode.js";
4import { Time, UnitMap, UnitName } from "../core/type/Units.js";
5import { ToneConstantSource } from "./ToneConstantSource.js";
6export interface SignalOptions<TypeName extends UnitName> extends ToneAudioNodeOptions {
7 value: UnitMap[TypeName];
8 units: TypeName;
9 convert: boolean;
10 minValue?: number;
11 maxValue?: number;
12}
13/**
14 * A signal is an audio-rate value. Tone.Signal is a core component of the library.
15 * Unlike a number, Signals can be scheduled with sample-level accuracy. Tone.Signal
16 * has all of the methods available to native Web Audio
17 * [AudioParam](http://webaudio.github.io/web-audio-api/#the-audioparam-interface)
18 * as well as additional conveniences. Read more about working with signals
19 * [here](https://github.com/Tonejs/Tone.js/wiki/Signals).
20 *
21 * @example
22 * const osc = new Tone.Oscillator().toDestination().start();
23 * // a scheduleable signal which can be connected to control an AudioParam or another Signal
24 * const signal = new Tone.Signal({
25 * value: "C4",
26 * units: "frequency"
27 * }).connect(osc.frequency);
28 * // the scheduled ramp controls the connected signal
29 * signal.rampTo("C2", 4, "+0.5");
30 * @category Signal
31 */
32export declare class Signal<TypeName extends UnitName = "number"> extends ToneAudioNode<SignalOptions<any>> implements AbstractParam<TypeName> {
33 readonly name: string;
34 /**
35 * Indicates if the value should be overridden on connection.
36 */
37 readonly override: boolean;
38 /**
39 * The constant source node which generates the signal
40 */
41 protected _constantSource: ToneConstantSource<TypeName>;
42 readonly output: OutputNode;
43 protected _param: Param<TypeName>;
44 readonly input: InputNode;
45 /**
46 * @param value Initial value of the signal
47 * @param units The unit name, e.g. "frequency"
48 */
49 constructor(value?: UnitMap[TypeName], units?: TypeName);
50 constructor(options?: Partial<SignalOptions<TypeName>>);
51 static getDefaults(): SignalOptions<any>;
52 connect(destination: InputNode, outputNum?: number, inputNum?: number): this;
53 dispose(): this;
54 setValueAtTime(value: UnitMap[TypeName], time: Time): this;
55 getValueAtTime(time: Time): UnitMap[TypeName];
56 setRampPoint(time: Time): this;
57 linearRampToValueAtTime(value: UnitMap[TypeName], time: Time): this;
58 exponentialRampToValueAtTime(value: UnitMap[TypeName], time: Time): this;
59 exponentialRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
60 linearRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
61 targetRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
62 exponentialApproachValueAtTime(value: UnitMap[TypeName], time: Time, rampTime: Time): this;
63 setTargetAtTime(value: UnitMap[TypeName], startTime: Time, timeConstant: number): this;
64 setValueCurveAtTime(values: UnitMap[TypeName][], startTime: Time, duration: Time, scaling?: number): this;
65 cancelScheduledValues(time: Time): this;
66 cancelAndHoldAtTime(time: Time): this;
67 rampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
68 get value(): UnitMap[TypeName];
69 set value(value: UnitMap[TypeName]);
70 get convert(): boolean;
71 set convert(convert: boolean);
72 get units(): UnitName;
73 get overridden(): boolean;
74 set overridden(overridden: boolean);
75 get maxValue(): number;
76 get minValue(): number;
77 /**
78 * @see {@link Param.apply}.
79 */
80 apply(param: Param | AudioParam): this;
81}
82/**
83 * When connecting from a signal, it's necessary to zero out the node destination
84 * node if that node is also a signal. If the destination is not 0, then the values
85 * will be summed. This method insures that the output of the destination signal will
86 * be the same as the source signal, making the destination signal a pass through node.
87 * @param signal The output signal to connect from
88 * @param destination the destination to connect to
89 * @param outputNum the optional output number
90 * @param inputNum the input number
91 */
92export declare function connectSignal(signal: OutputNode, destination: InputNode, outputNum?: number, inputNum?: number): void;