Tone.js/Tone/signal/OR.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-10-03 21:20:00 +00:00
define(["Tone/core/Tone", "Tone/signal/GreaterThanZero"], function(Tone){
"use strict";
/**
* @class OR the inputs together. True if at least one of the inputs is true.
*
* @extends {Tone.SignalBase}
2014-10-03 21:20:00 +00:00
* @constructor
* @param {number} inputCount the input count
2015-02-27 18:40:35 +00:00
* @example
* var or = new Tone.OR(2);
* var sigA = new Tone.Signal(0)connect(or, 0, 0);
* var sigB = new Tone.Signal(1)connect(or, 0, 1);
* //output of or is 1 because at least
* //one of the inputs is equal to 1.
2014-10-03 21:20:00 +00:00
*/
2014-10-30 05:05:17 +00:00
Tone.OR = function(inputCount){
inputCount = this.defaultArg(inputCount, 2);
Tone.call(this, inputCount, 0);
2014-10-30 05:05:17 +00:00
/**
* a private summing node
* @type {GainNode}
* @private
*/
this._sum = this.context.createGain();
/**
* @type {Tone.Equal}
* @private
*/
2015-04-05 18:01:05 +00:00
this._gtz = this.output = new Tone.GreaterThanZero();
2014-10-30 05:05:17 +00:00
//make each of the inputs an alias
for (var i = 0; i < inputCount; i++){
this.input[i] = this._sum;
}
this._sum.connect(this._gtz);
};
Tone.extend(Tone.OR, Tone.SignalBase);
2014-10-30 05:05:17 +00:00
/**
* clean up
2015-02-02 03:56:33 +00:00
* @returns {Tone.OR} `this`
2014-10-30 05:05:17 +00:00
*/
Tone.OR.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._gtz.dispose();
this._gtz = null;
this._sum.disconnect();
this._sum = null;
2015-02-02 03:56:33 +00:00
return this;
2014-10-30 05:05:17 +00:00
};
2014-10-03 21:20:00 +00:00
return Tone.OR;
});