2017-08-27 21:50:31 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/core/Param", "Tone/type/Type", "Tone/core/AudioNode"], function (Tone) {
|
2015-08-15 23:30:43 +00:00
|
|
|
|
2015-10-21 16:11:19 +00:00
|
|
|
"use strict";
|
|
|
|
|
2017-03-13 05:12:20 +00:00
|
|
|
/**
|
|
|
|
* createGain shim
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
if (window.GainNode && !AudioContext.prototype.createGain){
|
|
|
|
AudioContext.prototype.createGain = AudioContext.prototype.createGainNode;
|
|
|
|
}
|
|
|
|
|
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
|
2017-08-22 15:44:12 +00:00
|
|
|
* API and is useful for routing audio and adjusting gains.
|
2015-08-15 23:30:43 +00:00
|
|
|
* @extends {Tone}
|
2015-11-01 22:48:52 +00:00
|
|
|
* @param {Number=} gain The initial gain of the GainNode
|
2017-08-22 15:44:12 +00:00
|
|
|
* @param {Tone.Type=} units The units of the gain parameter.
|
2015-08-15 23:30:43 +00:00
|
|
|
*/
|
2015-10-21 14:02:23 +00:00
|
|
|
Tone.Gain = function(){
|
2015-08-15 23:30:43 +00:00
|
|
|
|
2017-04-26 02:23:22 +00:00
|
|
|
var options = Tone.defaults(arguments, ["gain", "units"], Tone.Gain);
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.AudioNode.call(this);
|
2015-08-16 18:23:01 +00:00
|
|
|
|
2015-08-15 23:30:43 +00:00
|
|
|
/**
|
|
|
|
* The GainNode
|
|
|
|
* @type {GainNode}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-11-01 22:48:52 +00:00
|
|
|
this.input = this.output = this._gainNode = this.context.createGain();
|
2015-08-15 23:30:43 +00:00
|
|
|
|
|
|
|
/**
|
2015-10-21 14:02:23 +00:00
|
|
|
* The gain parameter of the gain node.
|
2017-08-22 15:44:12 +00:00
|
|
|
* @type {Gain}
|
2015-08-15 23:30:43 +00:00
|
|
|
* @signal
|
|
|
|
*/
|
2015-11-01 22:48:52 +00:00
|
|
|
this.gain = new Tone.Param({
|
2017-08-22 15:44:12 +00:00
|
|
|
"param" : this._gainNode.gain,
|
2015-11-01 22:48:52 +00:00
|
|
|
"units" : options.units,
|
|
|
|
"value" : options.gain,
|
|
|
|
"convert" : options.convert
|
|
|
|
});
|
2015-08-15 23:30:43 +00:00
|
|
|
this._readOnly("gain");
|
|
|
|
};
|
|
|
|
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.extend(Tone.Gain, Tone.AudioNode);
|
2015-08-15 23:30:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The defaults
|
|
|
|
* @const
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
Tone.Gain.defaults = {
|
2015-11-01 22:48:52 +00:00
|
|
|
"gain" : 1,
|
|
|
|
"convert" : true,
|
2015-08-15 23:30:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up.
|
|
|
|
* @return {Tone.Gain} this
|
|
|
|
*/
|
|
|
|
Tone.Gain.prototype.dispose = function(){
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.AudioNode.prototype.dispose.call(this);
|
2015-08-15 23:30:43 +00:00
|
|
|
this._gainNode.disconnect();
|
|
|
|
this._gainNode = null;
|
|
|
|
this._writable("gain");
|
2015-11-01 22:48:52 +00:00
|
|
|
this.gain.dispose();
|
2015-08-15 23:30:43 +00:00
|
|
|
this.gain = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Gain;
|
2017-08-22 15:44:12 +00:00
|
|
|
});
|