Tone.js/Tone/signal/Add.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
"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
* 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
*/
Tone.Add = function(value){
Tone.call(this, 2, 0);
2014-07-02 21:26:27 +00:00
/**
* the summing node
2014-07-02 21:26:27 +00:00
* @type {GainNode}
* @private
2014-07-02 21:26:27 +00:00
*/
this._sum = this.input[0] = this.input[1] = this.output = this.context.createGain();
2014-07-02 21:26:27 +00:00
/**
* @private
* @type {Tone.Signal}
*/
2015-02-23 05:30:53 +00:00
this._value = this.input[1] = new Tone.Signal(value);
2015-02-23 05:30:53 +00:00
this._value.connect(this._sum);
2014-06-15 21:38:59 +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.
* @returns {Tone.Add} this
2014-06-20 04:38:14 +00:00
*/
Tone.Add.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2015-02-23 05:30:53 +00:00
this._sum.disconnect();
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
};
return Tone.Add;
});