2014-04-16 23:56:18 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-17 00:05:54 +00:00
|
|
|
/**
|
2014-10-23 01:19:04 +00:00
|
|
|
* @class Add a signal and a number or two signals.
|
2014-06-17 00:05:54 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
2014-10-23 01:19:04 +00:00
|
|
|
* @param {number=} value if no value is provided, Tone.Add will sum the first
|
|
|
|
* and second inputs.
|
2014-06-17 00:05:54 +00:00
|
|
|
*/
|
2014-04-16 23:56:18 +00:00
|
|
|
Tone.Add = function(value){
|
2014-10-23 01:19:04 +00:00
|
|
|
|
2014-06-17 00:05:54 +00:00
|
|
|
/**
|
2014-10-23 01:19:04 +00:00
|
|
|
* the inputs
|
|
|
|
* input 0: augend
|
|
|
|
* input 1: addend
|
|
|
|
* @type {Array.<GainNode>}
|
2014-06-17 00:05:54 +00:00
|
|
|
*/
|
2014-10-23 01:19:04 +00:00
|
|
|
this.input = new Array(2);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-07-02 21:26:27 +00:00
|
|
|
/**
|
2014-10-23 01:19:04 +00:00
|
|
|
* the summing node
|
2014-07-02 21:26:27 +00:00
|
|
|
* @type {GainNode}
|
2014-10-23 01:19:04 +00:00
|
|
|
* @private
|
2014-07-02 21:26:27 +00:00
|
|
|
*/
|
2014-10-23 01:19:04 +00:00
|
|
|
this._sum = this.input[0] = this.input[1] = this.output = this.context.createGain();
|
2014-07-02 21:26:27 +00:00
|
|
|
|
2014-10-23 01:19:04 +00:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
|
|
|
this._value = null;
|
|
|
|
|
|
|
|
if (isFinite(value)){
|
|
|
|
this._value = new Tone.Signal(value);
|
|
|
|
this._value.connect(this._sum);
|
|
|
|
}
|
2014-06-15 21:38:59 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
|
|
|
Tone.extend(Tone.Add);
|
2014-04-04 17:07:16 +00:00
|
|
|
|
2014-06-17 00:05:54 +00:00
|
|
|
/**
|
|
|
|
* set the constant
|
|
|
|
*
|
|
|
|
* @param {number} value
|
|
|
|
*/
|
2014-04-16 23:56:18 +00:00
|
|
|
Tone.Add.prototype.setValue = function(value){
|
2014-10-23 01:19:04 +00:00
|
|
|
if (this._value !== null){
|
|
|
|
this._value.setValue(value);
|
|
|
|
} else {
|
|
|
|
throw new Error("cannot switch from signal to number");
|
|
|
|
}
|
2014-06-15 22:19:05 +00:00
|
|
|
};
|
2014-04-16 20:47:25 +00:00
|
|
|
|
2014-08-24 17:19:49 +00:00
|
|
|
/**
|
|
|
|
* borrows the method from {@link Tone.Signal}
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
Tone.Add.prototype.connect = Tone.Signal.prototype.connect;
|
|
|
|
|
2014-06-20 04:38:14 +00:00
|
|
|
/**
|
|
|
|
* dispose method
|
|
|
|
*/
|
|
|
|
Tone.Add.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-10-23 01:19:04 +00:00
|
|
|
this._sum = null;
|
|
|
|
if (this._value){
|
|
|
|
this._value.dispose();
|
|
|
|
this._value = null;
|
|
|
|
}
|
2014-06-20 04:38:14 +00:00
|
|
|
};
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Add;
|
|
|
|
});
|