2014-10-13 23:22:11 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/LessThan", "Tone/signal/IfThenElse", "Tone/signal/Signal"], function(Tone){
|
2014-09-08 01:43:24 +00:00
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/**
|
2014-10-23 01:23:47 +00:00
|
|
|
* @class outputs the lesser of two signals. If a number is given
|
|
|
|
* in the constructor, it will use a signal and a number.
|
2014-09-08 01:43:24 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2014-09-08 01:43:24 +00:00
|
|
|
* @param {number} min the minimum to compare to the incoming signal
|
|
|
|
*/
|
|
|
|
Tone.Min = function(min){
|
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
Tone.call(this, 2, 0);
|
2014-10-23 01:23:47 +00:00
|
|
|
this.input[0] = this.context.createGain();
|
2014-09-08 01:43:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Tone.Select}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-10-23 01:23:47 +00:00
|
|
|
this._ifThenElse = this.output = new Tone.IfThenElse();
|
2014-10-13 23:22:11 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-23 01:23:47 +00:00
|
|
|
* @type {Tone.Select}
|
|
|
|
* @private
|
2014-10-13 23:22:11 +00:00
|
|
|
*/
|
2014-10-23 01:23:47 +00:00
|
|
|
this._lt = new Tone.LessThan();
|
2014-09-08 01:43:24 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-23 01:23:47 +00:00
|
|
|
* the min signal
|
|
|
|
* @type {Tone.Signal}
|
2014-09-08 01:43:24 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-23 01:23:47 +00:00
|
|
|
this._minSignal = this.input[1] = new Tone.Signal(min);
|
2014-09-08 01:43:24 +00:00
|
|
|
|
|
|
|
//connections
|
2014-12-01 02:32:09 +00:00
|
|
|
this.input[0].chain(this._lt, this._ifThenElse.if);
|
2014-10-23 01:23:47 +00:00
|
|
|
this.input[0].connect(this._ifThenElse.then);
|
2014-10-13 23:22:11 +00:00
|
|
|
this._minSignal.connect(this._ifThenElse.else);
|
2014-10-23 01:23:47 +00:00
|
|
|
this._minSignal.connect(this._lt, 0, 1);
|
2014-09-08 01:43:24 +00:00
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.Min, Tone.SignalBase);
|
2014-09-08 01:43:24 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-06 22:47:26 +00:00
|
|
|
* Will output the minimum between the incoming signal
|
|
|
|
* and `value`.
|
|
|
|
* @memberOf Tone.Min#
|
|
|
|
* @type {number}
|
|
|
|
* @name value
|
2014-09-08 01:43:24 +00:00
|
|
|
*/
|
2015-02-06 22:47:26 +00:00
|
|
|
Object.defineProperty(Tone.Min.prototype, "value", {
|
|
|
|
get : function(){
|
|
|
|
return this._minSignal.value;
|
|
|
|
},
|
|
|
|
set : function(max){
|
|
|
|
this._minSignal.value = max;
|
|
|
|
}
|
|
|
|
});
|
2014-09-08 01:43:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Min} `this`
|
2014-09-08 01:43:24 +00:00
|
|
|
*/
|
|
|
|
Tone.Min.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
|
|
|
this._minSignal.dispose();
|
2014-10-13 23:22:11 +00:00
|
|
|
this._ifThenElse.dispose();
|
2014-09-08 01:43:24 +00:00
|
|
|
this._lt.dispose();
|
|
|
|
this._minSignal = null;
|
2014-10-13 23:22:11 +00:00
|
|
|
this._ifThenElse = null;
|
2014-09-08 01:43:24 +00:00
|
|
|
this._lt = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-09-08 01:43:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Min;
|
|
|
|
});
|