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
|
|
|
|
|
|
|
/**
|
|
|
|
* set the min value
|
|
|
|
* @param {number} min the minimum to compare to the incoming signal
|
|
|
|
*/
|
|
|
|
Tone.Min.prototype.setMin = function(min){
|
|
|
|
this._minSignal.setValue(min);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Min;
|
|
|
|
});
|