mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
rewrote GreaterThan and LessThan in terms of GreaterThanZero
This commit is contained in:
parent
93eace9694
commit
f94034345d
2 changed files with 44 additions and 49 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue