Tone.js/Tone/signal/OR.js

60 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";
/**
2015-07-04 19:25:37 +00:00
* @class [OR](https://en.wikipedia.org/wiki/OR_gate)
2015-06-19 04:52:04 +00:00
* the inputs together. True if at least one of the inputs is true.
2014-10-03 21:20:00 +00:00
*
* @extends {Tone.SignalBase}
2014-10-03 21:20:00 +00:00
* @constructor
2015-06-19 04:52:04 +00:00
* @param {number} [inputCount=2] the input count
2015-02-27 18:40:35 +00:00
* @example
2015-06-14 05:17:09 +00:00
* 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
* @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;
});