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
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* @class Add a signal and a number or two signals. When no value is
|
2015-06-20 19:50:57 +00:00
|
|
|
* passed into the constructor, Tone.Add will sum <code>input[0]</code>
|
|
|
|
* and <code>input[1]</code>. If a value is passed into the constructor,
|
2015-06-19 04:52:04 +00:00
|
|
|
* the it will be added to the input.
|
|
|
|
*
|
2014-06-17 00:05:54 +00:00
|
|
|
* @constructor
|
2015-02-23 05:30:53 +00:00
|
|
|
* @extends {Tone.Signal}
|
2015-06-19 04:52:04 +00:00
|
|
|
* @param {number=} value If no value is provided, Tone.Add will sum the first
|
2014-10-23 01:19:04 +00:00
|
|
|
* and second inputs.
|
2015-02-27 18:40:35 +00:00
|
|
|
* @example
|
2015-06-14 05:17:09 +00:00
|
|
|
* var signal = new Tone.Signal(2);
|
|
|
|
* var add = new Tone.Add(2);
|
|
|
|
* signal.connect(add);
|
|
|
|
* //the output of add equals 4
|
|
|
|
* @example
|
|
|
|
* //if constructed with no arguments
|
|
|
|
* //it will add the first and second inputs
|
|
|
|
* var add = new Tone.Add();
|
|
|
|
* var sig0 = new Tone.Signal(3).connect(add, 0, 0);
|
|
|
|
* var sig1 = new Tone.Signal(4).connect(add, 0, 1);
|
|
|
|
* //the output of add equals 7.
|
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-11-04 06:21:42 +00:00
|
|
|
Tone.call(this, 2, 0);
|
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}
|
|
|
|
*/
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value = this.input[1] = new Tone.Signal(value);
|
2014-10-23 01:19:04 +00:00
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value.connect(this._sum);
|
2014-06-15 21:38:59 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
Tone.extend(Tone.Add, Tone.Signal);
|
|
|
|
|
2014-06-20 04:38:14 +00:00
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Add} this
|
2014-06-20 04:38:14 +00:00
|
|
|
*/
|
|
|
|
Tone.Add.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2015-02-23 05:30:53 +00:00
|
|
|
this._sum.disconnect();
|
2014-10-23 01:19:04 +00:00
|
|
|
this._sum = null;
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value.dispose();
|
|
|
|
this._value = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-06-20 04:38:14 +00:00
|
|
|
};
|
|
|
|
|
2014-04-05 22:05:42 +00:00
|
|
|
return Tone.Add;
|
|
|
|
});
|