rewrote GreaterThan and LessThan in terms of GreaterThanZero

This commit is contained in:
Yotam Mann 2014-10-03 13:07:26 -04:00
parent 93eace9694
commit f94034345d
2 changed files with 44 additions and 49 deletions

View file

@ -1,4 +1,4 @@
define(["Tone/core/Tone", "Tone/signal/LessThan", "Tone/signal/Negate", "Tone/signal/Signal"], function(Tone){ define(["Tone/core/Tone", "Tone/signal/GreaterThanZero", "Tone/signal/Add"], function(Tone){
"use strict"; "use strict";
@ -10,32 +10,35 @@ define(["Tone/core/Tone", "Tone/signal/LessThan", "Tone/signal/Negate", "Tone/si
* @param {number=} [value=0] the value to compare to the incoming signal * @param {number=} [value=0] the value to compare to the incoming signal
*/ */
Tone.GreaterThan = function(value){ Tone.GreaterThan = function(value){
/**
* @type {Tone.LessThan}
* @private
*/
this._lt = new Tone.LessThan(-value);
/** /**
* @type {Tone.Negate} * subtract the amount from the incoming signal
* @private
*/
this._neg = new Tone.Negate();
/**
* alias for the adder
* @type {Tone.Add} * @type {Tone.Add}
* @private
*/ */
this.input = this._neg; this._adder = new Tone.Add(-value);
/** /**
* alias for the thresh * compare that amount to zero
* @type {Tone.Threshold} * @type {Tone.GreaterThanZero}
* @private
*/ */
this.output = this._lt; this._gtz = new Tone.GreaterThanZero();
/**
* alias for the negate
* @type {Tone.Negate}
*/
this.input = this._adder;
/**
* alias for the less than
* @type {Tone.LessThan}
*/
this.output = this._gtz;
//connect //connect
this._neg.connect(this._lt); this._adder.connect(this._gtz);
}; };
Tone.extend(Tone.GreaterThan); Tone.extend(Tone.GreaterThan);
@ -46,7 +49,7 @@ define(["Tone/core/Tone", "Tone/signal/LessThan", "Tone/signal/Negate", "Tone/si
* @param {number} value * @param {number} value
*/ */
Tone.GreaterThan.prototype.setValue = function(value){ Tone.GreaterThan.prototype.setValue = function(value){
this._lt.setValue(-value); this._adder.setValue(-value);
}; };
/** /**
@ -61,10 +64,10 @@ define(["Tone/core/Tone", "Tone/signal/LessThan", "Tone/signal/Negate", "Tone/si
*/ */
Tone.GreaterThan.prototype.dispose = function(){ Tone.GreaterThan.prototype.dispose = function(){
Tone.prototype.dispose.call(this); Tone.prototype.dispose.call(this);
this._lt.disconnect(); this._adder.dispose();
this._neg.disconnect(); this._gtz.dispose();
this._lt = null; this._adder = null;
this._neg = null; this._gtz = null;
}; };
return Tone.GreaterThan; return Tone.GreaterThan;

View file

@ -1,4 +1,4 @@
define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Add", "Tone/signal/Signal", "Tone/signal/NOT"], function(Tone){ define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/Negate"], function(Tone){
"use strict"; "use strict";
@ -12,39 +12,33 @@ define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Add", "Tone/sign
Tone.LessThan = function(value){ Tone.LessThan = function(value){
/** /**
* subtract the value from the incoming signal * negate the incoming signal
* * @type {Tone.Negate}
* @type {Tone.Add}
* @private * @private
*/ */
this._adder = new Tone.Add(this.defaultArg(-value, 0)); this._neg = new Tone.Negate();
/** /**
* @type {Tone.Threshold} * input < value === -input > -value
* @type {Tone.GreaterThan}
* @private * @private
*/ */
this._thresh = new Tone.Threshold(0); this._gt = new Tone.GreaterThan(-value);
/**
* @type {Tone.NOT}
* @private
*/
this._not = new Tone.NOT();
/** /**
* alias for the adder * alias for the adder
* @type {Tone.Add} * @type {Tone.Negate}
*/ */
this.input = this._adder; this.input = this._neg;
/** /**
* alias for the thresh * alias for the thresh
* @type {Tone.Threshold} * @type {Tone.GreatThan}
*/ */
this.output = this._not; this.output = this._gt;
//connect //connect
this.chain(this._adder, this._thresh, this._not); this._neg.connect(this._gt);
}; };
Tone.extend(Tone.LessThan); Tone.extend(Tone.LessThan);
@ -55,7 +49,7 @@ define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Add", "Tone/sign
* @param {number} value * @param {number} value
*/ */
Tone.LessThan.prototype.setValue = function(value){ Tone.LessThan.prototype.setValue = function(value){
this._adder.setValue(-value); this._gt.setValue(-value);
}; };
/** /**
@ -70,12 +64,10 @@ define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Add", "Tone/sign
*/ */
Tone.LessThan.prototype.dispose = function(){ Tone.LessThan.prototype.dispose = function(){
Tone.prototype.dispose.call(this); Tone.prototype.dispose.call(this);
this._adder.disconnect(); this._neg.dispose();
this._thresh.dispose(); this._gt.dispose();
this._not.dispose(); this._neg = null;
this._adder = null; this._gt = null;
this._thresh = null;
this._not = null;
}; };
return Tone.LessThan; return Tone.LessThan;