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";
|
|
|
|
|
|
|
|
/**
|
2015-02-27 18:40:35 +00:00
|
|
|
* @class Outputs the lesser of two signals. If a number is given
|
2014-10-23 01:23:47 +00:00
|
|
|
* in the constructor, it will use a signal and a number.
|
2014-09-08 01:43:24 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2015-02-23 05:30:53 +00:00
|
|
|
* @extends {Tone.Signal}
|
2015-06-20 19:50:57 +00:00
|
|
|
* @param {number} min The minimum to compare to the incoming signal
|
2015-02-27 18:40:35 +00:00
|
|
|
* @example
|
2015-06-14 05:17:09 +00:00
|
|
|
* var min = new Tone.Min(2);
|
|
|
|
* var sig = new Tone.Signal(3).connect(min);
|
|
|
|
* //min outputs 2
|
|
|
|
* sig.value = 1;
|
|
|
|
* //min outputs 1
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* var min = new Tone.Min();
|
|
|
|
* var sigA = new Tone.Signal(3);
|
|
|
|
* var sigB = new Tone.Signal(4);
|
|
|
|
* sigA.connect(min, 0, 0);
|
|
|
|
* sigB.connect(min, 0, 1);
|
|
|
|
* //output of min is 3.
|
2014-09-08 01:43:24 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
2015-10-21 14:34:37 +00:00
|
|
|
this._param = 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);
|
2015-10-21 14:34:37 +00:00
|
|
|
this._param.connect(this._ifThenElse.else);
|
|
|
|
this._param.connect(this._lt, 0, 1);
|
2014-09-08 01:43:24 +00:00
|
|
|
};
|
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
Tone.extend(Tone.Min, Tone.Signal);
|
2014-09-08 01:43:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Min} this
|
2014-09-08 01:43:24 +00:00
|
|
|
*/
|
|
|
|
Tone.Min.prototype.dispose = function(){
|
|
|
|
Tone.prototype.dispose.call(this);
|
2015-10-21 14:34:37 +00:00
|
|
|
this._param.dispose();
|
2014-10-13 23:22:11 +00:00
|
|
|
this._ifThenElse.dispose();
|
2014-09-08 01:43:24 +00:00
|
|
|
this._lt.dispose();
|
2015-10-21 14:34:37 +00:00
|
|
|
this._param = 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;
|
|
|
|
});
|