Tone.js/Tone/core/Gain.js

67 lines
1.4 KiB
JavaScript
Raw Normal View History

import Tone from "../core/Tone";
import "../core/Param";
import "../type/Type";
import "../core/AudioNode";
2015-08-15 23:30:43 +00:00
/**
* @class A thin wrapper around the Native Web Audio GainNode.
* The GainNode is a basic building block of the Web Audio
* API and is useful for routing audio and adjusting gains.
* @extends {Tone.AudioNode}
* @param {Number=} gain The initial gain of the GainNode
* @param {Tone.Type=} units The units of the gain parameter.
*/
Tone.Gain = function(){
var options = Tone.defaults(arguments, ["gain", "units"], Tone.Gain);
Tone.AudioNode.call(this, options);
2015-10-21 16:11:19 +00:00
2015-08-15 23:30:43 +00:00
/**
* The GainNode
* @type {GainNode}
* @private
2015-08-15 23:30:43 +00:00
*/
this.input = this.output = this._gainNode = this.context.createGain();
2015-08-16 18:23:01 +00:00
/**
* The gain parameter of the gain node.
* @type {Gain}
* @signal
*/
this.gain = new Tone.Param({
"param" : this._gainNode.gain,
"units" : options.units,
"value" : options.gain,
"convert" : options.convert
});
this._readOnly("gain");
};
2015-08-15 23:30:43 +00:00
Tone.extend(Tone.Gain, Tone.AudioNode);
2015-08-15 23:30:43 +00:00
/**
* The defaults
* @const
* @type {Object}
*/
Tone.Gain.defaults = {
"gain" : 1,
"convert" : true,
};
2015-08-15 23:30:43 +00:00
/**
* Clean up.
* @return {Tone.Gain} this
*/
Tone.Gain.prototype.dispose = function(){
Tone.AudioNode.prototype.dispose.call(this);
this._gainNode.disconnect();
this._gainNode = null;
this._writable("gain");
this.gain.dispose();
this.gain = null;
};
2015-08-15 23:30:43 +00:00
export default Tone.Gain;
2015-08-15 23:30:43 +00:00