From f94034345dbaff21edfdc7777e2cd1f19e5e507e Mon Sep 17 00:00:00 2001 From: Yotam Mann Date: Fri, 3 Oct 2014 13:07:26 -0400 Subject: [PATCH] rewrote GreaterThan and LessThan in terms of GreaterThanZero --- Tone/signal/GreaterThan.js | 51 ++++++++++++++++++++------------------ Tone/signal/LessThan.js | 42 +++++++++++++------------------ 2 files changed, 44 insertions(+), 49 deletions(-) diff --git a/Tone/signal/GreaterThan.js b/Tone/signal/GreaterThan.js index cbaa4a79..2ee4eb14 100644 --- a/Tone/signal/GreaterThan.js +++ b/Tone/signal/GreaterThan.js @@ -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"; @@ -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 */ Tone.GreaterThan = function(value){ + /** - * @type {Tone.LessThan} - * @private - */ - this._lt = new Tone.LessThan(-value); - - /** - * @type {Tone.Negate} - * @private - */ - this._neg = new Tone.Negate(); - - /** - * alias for the adder + * subtract the amount from the incoming signal * @type {Tone.Add} + * @private */ - this.input = this._neg; + this._adder = new Tone.Add(-value); /** - * alias for the thresh - * @type {Tone.Threshold} + * compare that amount to zero + * @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 - this._neg.connect(this._lt); + this._adder.connect(this._gtz); }; Tone.extend(Tone.GreaterThan); @@ -46,7 +49,7 @@ define(["Tone/core/Tone", "Tone/signal/LessThan", "Tone/signal/Negate", "Tone/si * @param {number} 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.prototype.dispose.call(this); - this._lt.disconnect(); - this._neg.disconnect(); - this._lt = null; - this._neg = null; + this._adder.dispose(); + this._gtz.dispose(); + this._adder = null; + this._gtz = null; }; return Tone.GreaterThan; diff --git a/Tone/signal/LessThan.js b/Tone/signal/LessThan.js index 0b74bd1b..cbe7983b 100644 --- a/Tone/signal/LessThan.js +++ b/Tone/signal/LessThan.js @@ -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"; @@ -12,39 +12,33 @@ define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Add", "Tone/sign Tone.LessThan = function(value){ /** - * subtract the value from the incoming signal - * - * @type {Tone.Add} + * negate the incoming signal + * @type {Tone.Negate} * @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 */ - this._thresh = new Tone.Threshold(0); - - /** - * @type {Tone.NOT} - * @private - */ - this._not = new Tone.NOT(); + this._gt = new Tone.GreaterThan(-value); /** * alias for the adder - * @type {Tone.Add} + * @type {Tone.Negate} */ - this.input = this._adder; + this.input = this._neg; /** * alias for the thresh - * @type {Tone.Threshold} + * @type {Tone.GreatThan} */ - this.output = this._not; + this.output = this._gt; //connect - this.chain(this._adder, this._thresh, this._not); + this._neg.connect(this._gt); }; Tone.extend(Tone.LessThan); @@ -55,7 +49,7 @@ define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Add", "Tone/sign * @param {number} 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.prototype.dispose.call(this); - this._adder.disconnect(); - this._thresh.dispose(); - this._not.dispose(); - this._adder = null; - this._thresh = null; - this._not = null; + this._neg.dispose(); + this._gt.dispose(); + this._neg = null; + this._gt = null; }; return Tone.LessThan;