UNPKG

5.26 kBTypeScriptView Raw
1import { AbstractParam } from "../context/AbstractParam.js";
2import { Positive, Time, UnitMap, UnitName } from "../type/Units.js";
3import { Timeline } from "../util/Timeline.js";
4import { ToneWithContext, ToneWithContextOptions } from "./ToneWithContext.js";
5export interface ParamOptions<TypeName extends UnitName> extends ToneWithContextOptions {
6 units: TypeName;
7 value?: UnitMap[TypeName];
8 param: AudioParam | Param<TypeName>;
9 convert: boolean;
10 minValue?: number;
11 maxValue?: number;
12 swappable?: boolean;
13}
14/**
15 * the possible automation types
16 */
17type AutomationType = "linearRampToValueAtTime" | "exponentialRampToValueAtTime" | "setValueAtTime" | "setTargetAtTime" | "cancelScheduledValues";
18interface TargetAutomationEvent {
19 type: "setTargetAtTime";
20 time: number;
21 value: number;
22 constant: number;
23}
24interface NormalAutomationEvent {
25 type: Exclude<AutomationType, "setTargetAtTime">;
26 time: number;
27 value: number;
28}
29/**
30 * The events on the automation
31 */
32export type AutomationEvent = NormalAutomationEvent | TargetAutomationEvent;
33/**
34 * Param wraps the native Web Audio's AudioParam to provide
35 * additional unit conversion functionality. It also
36 * serves as a base-class for classes which have a single,
37 * automatable parameter.
38 * @category Core
39 */
40export declare class Param<TypeName extends UnitName = "number"> extends ToneWithContext<ParamOptions<TypeName>> implements AbstractParam<TypeName> {
41 readonly name: string;
42 readonly input: GainNode | AudioParam;
43 readonly units: UnitName;
44 convert: boolean;
45 overridden: boolean;
46 /**
47 * The timeline which tracks all of the automations.
48 */
49 protected _events: Timeline<AutomationEvent>;
50 /**
51 * The native parameter to control
52 */
53 protected _param: AudioParam;
54 /**
55 * The default value before anything is assigned
56 */
57 protected _initialValue: number;
58 /**
59 * The minimum output value
60 */
61 private _minOutput;
62 /**
63 * Private reference to the min and max values if passed into the constructor
64 */
65 private readonly _minValue?;
66 private readonly _maxValue?;
67 /**
68 * If the underlying AudioParam can be swapped out
69 * using the setParam method.
70 */
71 protected readonly _swappable: boolean;
72 /**
73 * @param param The AudioParam to wrap
74 * @param units The unit name
75 * @param convert Whether or not to convert the value to the target units
76 */
77 constructor(param: AudioParam, units?: TypeName, convert?: boolean);
78 constructor(options: Partial<ParamOptions<TypeName>>);
79 static getDefaults(): ParamOptions<any>;
80 get value(): UnitMap[TypeName];
81 set value(value: UnitMap[TypeName]);
82 get minValue(): number;
83 get maxValue(): number;
84 /**
85 * Type guard based on the unit name
86 */
87 private _is;
88 /**
89 * Make sure the value is always in the defined range
90 */
91 private _assertRange;
92 /**
93 * Convert the given value from the type specified by Param.units
94 * into the destination value (such as Gain or Frequency).
95 */
96 protected _fromType(val: UnitMap[TypeName]): number;
97 /**
98 * Convert the parameters value into the units specified by Param.units.
99 */
100 protected _toType(val: number): UnitMap[TypeName];
101 setValueAtTime(value: UnitMap[TypeName], time: Time): this;
102 getValueAtTime(time: Time): UnitMap[TypeName];
103 setRampPoint(time: Time): this;
104 linearRampToValueAtTime(value: UnitMap[TypeName], endTime: Time): this;
105 exponentialRampToValueAtTime(value: UnitMap[TypeName], endTime: Time): this;
106 exponentialRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
107 linearRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
108 targetRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;
109 exponentialApproachValueAtTime(value: UnitMap[TypeName], time: Time, rampTime: Time): this;
110 setTargetAtTime(value: UnitMap[TypeName], startTime: Time, timeConstant: Positive): this;
111 setValueCurveAtTime(values: UnitMap[TypeName][], startTime: Time, duration: Time, scaling?: number): this;
112 cancelScheduledValues(time: Time): this;
113 cancelAndHoldAtTime(time: Time): this;
114 rampTo(value: UnitMap[TypeName], rampTime?: Time, startTime?: Time): this;
115 /**
116 * Apply all of the previously scheduled events to the passed in Param or AudioParam.
117 * The applied values will start at the context's current time and schedule
118 * all of the events which are scheduled on this Param onto the passed in param.
119 */
120 apply(param: Param | AudioParam): this;
121 /**
122 * Replace the Param's internal AudioParam. Will apply scheduled curves
123 * onto the parameter and replace the connections.
124 */
125 setParam(param: AudioParam): this;
126 dispose(): this;
127 get defaultValue(): UnitMap[TypeName];
128 protected _exponentialApproach(t0: number, v0: number, v1: number, timeConstant: number, t: number): number;
129 protected _linearInterpolate(t0: number, v0: number, t1: number, v1: number, t: number): number;
130 protected _exponentialInterpolate(t0: number, v0: number, t1: number, v1: number, t: number): number;
131}
132export {};