UNPKG

1.84 kBJavaScriptView Raw
1import { Param } from "../context/Param.js";
2import { optionsFromArguments } from "../util/Defaults.js";
3import { readOnly } from "../util/Interface.js";
4import { ToneAudioNode } from "./ToneAudioNode.js";
5/**
6 * A thin wrapper around the Native Web Audio GainNode.
7 * The GainNode is a basic building block of the Web Audio
8 * API and is useful for routing audio and adjusting gains.
9 * @category Core
10 * @example
11 * return Tone.Offline(() => {
12 * const gainNode = new Tone.Gain(0).toDestination();
13 * const osc = new Tone.Oscillator(30).connect(gainNode).start();
14 * gainNode.gain.rampTo(1, 0.1);
15 * gainNode.gain.rampTo(0, 0.4, 0.2);
16 * }, 0.7, 1);
17 */
18export class Gain extends ToneAudioNode {
19 constructor() {
20 const options = optionsFromArguments(Gain.getDefaults(), arguments, [
21 "gain",
22 "units",
23 ]);
24 super(options);
25 this.name = "Gain";
26 /**
27 * The wrapped GainNode.
28 */
29 this._gainNode = this.context.createGain();
30 // input = output
31 this.input = this._gainNode;
32 this.output = this._gainNode;
33 this.gain = new Param({
34 context: this.context,
35 convert: options.convert,
36 param: this._gainNode.gain,
37 units: options.units,
38 value: options.gain,
39 minValue: options.minValue,
40 maxValue: options.maxValue,
41 });
42 readOnly(this, "gain");
43 }
44 static getDefaults() {
45 return Object.assign(ToneAudioNode.getDefaults(), {
46 convert: true,
47 gain: 1,
48 units: "gain",
49 });
50 }
51 /**
52 * Clean up.
53 */
54 dispose() {
55 super.dispose();
56 this._gainNode.disconnect();
57 this.gain.dispose();
58 return this;
59 }
60}
61//# sourceMappingURL=Gain.js.map
\No newline at end of file