1 | import { Param } from "../core/context/Param.js";
|
2 | import { ToneAudioNode, } from "../core/context/ToneAudioNode.js";
|
3 | import { connect } from "../core/context/ToneAudioNode.js";
|
4 | import { isAudioParam } from "../core/util/AdvancedTypeCheck.js";
|
5 | import { optionsFromArguments } from "../core/util/Defaults.js";
|
6 | import { ToneConstantSource } from "./ToneConstantSource.js";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export class Signal extends ToneAudioNode {
|
27 | constructor() {
|
28 | const options = optionsFromArguments(Signal.getDefaults(), arguments, [
|
29 | "value",
|
30 | "units",
|
31 | ]);
|
32 | super(options);
|
33 | this.name = "Signal";
|
34 | |
35 |
|
36 |
|
37 | this.override = true;
|
38 | this.output = this._constantSource = new ToneConstantSource({
|
39 | context: this.context,
|
40 | convert: options.convert,
|
41 | offset: options.value,
|
42 | units: options.units,
|
43 | minValue: options.minValue,
|
44 | maxValue: options.maxValue,
|
45 | });
|
46 | this._constantSource.start(0);
|
47 | this.input = this._param = this._constantSource.offset;
|
48 | }
|
49 | static getDefaults() {
|
50 | return Object.assign(ToneAudioNode.getDefaults(), {
|
51 | convert: true,
|
52 | units: "number",
|
53 | value: 0,
|
54 | });
|
55 | }
|
56 | connect(destination, outputNum = 0, inputNum = 0) {
|
57 |
|
58 | connectSignal(this, destination, outputNum, inputNum);
|
59 | return this;
|
60 | }
|
61 | dispose() {
|
62 | super.dispose();
|
63 | this._param.dispose();
|
64 | this._constantSource.dispose();
|
65 | return this;
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | setValueAtTime(value, time) {
|
73 | this._param.setValueAtTime(value, time);
|
74 | return this;
|
75 | }
|
76 | getValueAtTime(time) {
|
77 | return this._param.getValueAtTime(time);
|
78 | }
|
79 | setRampPoint(time) {
|
80 | this._param.setRampPoint(time);
|
81 | return this;
|
82 | }
|
83 | linearRampToValueAtTime(value, time) {
|
84 | this._param.linearRampToValueAtTime(value, time);
|
85 | return this;
|
86 | }
|
87 | exponentialRampToValueAtTime(value, time) {
|
88 | this._param.exponentialRampToValueAtTime(value, time);
|
89 | return this;
|
90 | }
|
91 | exponentialRampTo(value, rampTime, startTime) {
|
92 | this._param.exponentialRampTo(value, rampTime, startTime);
|
93 | return this;
|
94 | }
|
95 | linearRampTo(value, rampTime, startTime) {
|
96 | this._param.linearRampTo(value, rampTime, startTime);
|
97 | return this;
|
98 | }
|
99 | targetRampTo(value, rampTime, startTime) {
|
100 | this._param.targetRampTo(value, rampTime, startTime);
|
101 | return this;
|
102 | }
|
103 | exponentialApproachValueAtTime(value, time, rampTime) {
|
104 | this._param.exponentialApproachValueAtTime(value, time, rampTime);
|
105 | return this;
|
106 | }
|
107 | setTargetAtTime(value, startTime, timeConstant) {
|
108 | this._param.setTargetAtTime(value, startTime, timeConstant);
|
109 | return this;
|
110 | }
|
111 | setValueCurveAtTime(values, startTime, duration, scaling) {
|
112 | this._param.setValueCurveAtTime(values, startTime, duration, scaling);
|
113 | return this;
|
114 | }
|
115 | cancelScheduledValues(time) {
|
116 | this._param.cancelScheduledValues(time);
|
117 | return this;
|
118 | }
|
119 | cancelAndHoldAtTime(time) {
|
120 | this._param.cancelAndHoldAtTime(time);
|
121 | return this;
|
122 | }
|
123 | rampTo(value, rampTime, startTime) {
|
124 | this._param.rampTo(value, rampTime, startTime);
|
125 | return this;
|
126 | }
|
127 | get value() {
|
128 | return this._param.value;
|
129 | }
|
130 | set value(value) {
|
131 | this._param.value = value;
|
132 | }
|
133 | get convert() {
|
134 | return this._param.convert;
|
135 | }
|
136 | set convert(convert) {
|
137 | this._param.convert = convert;
|
138 | }
|
139 | get units() {
|
140 | return this._param.units;
|
141 | }
|
142 | get overridden() {
|
143 | return this._param.overridden;
|
144 | }
|
145 | set overridden(overridden) {
|
146 | this._param.overridden = overridden;
|
147 | }
|
148 | get maxValue() {
|
149 | return this._param.maxValue;
|
150 | }
|
151 | get minValue() {
|
152 | return this._param.minValue;
|
153 | }
|
154 | |
155 |
|
156 |
|
157 | apply(param) {
|
158 | this._param.apply(param);
|
159 | return this;
|
160 | }
|
161 | }
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | export function connectSignal(signal, destination, outputNum, inputNum) {
|
173 | if (destination instanceof Param ||
|
174 | isAudioParam(destination) ||
|
175 | (destination instanceof Signal && destination.override)) {
|
176 |
|
177 | destination.cancelScheduledValues(0);
|
178 |
|
179 | destination.setValueAtTime(0, 0);
|
180 |
|
181 | if (destination instanceof Signal) {
|
182 | destination.overridden = true;
|
183 | }
|
184 | }
|
185 | connect(signal, destination, outputNum, inputNum);
|
186 | }
|
187 |
|
\ | No newline at end of file |