2014-10-13 23:22:11 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/IfThenElse", "Tone/signal/Signal"], function(Tone){
|
2014-07-20 22:18:29 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-07-20 22:18:29 +00:00
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* @class Outputs the greater of two signals. If a number is provided in the constructor
|
2014-10-23 01:23:47 +00:00
|
|
|
* it will use that instead of the signal.
|
2014-07-20 22:18:29 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2015-02-23 05:30:53 +00:00
|
|
|
* @extends {Tone.Signal}
|
2015-06-20 19:50:57 +00:00
|
|
|
* @param {number=} max Max value if provided. if not provided, it will use the
|
2014-10-23 01:23:47 +00:00
|
|
|
* signal value from input 1.
|
2015-02-27 18:40:35 +00:00
|
|
|
* @example
|
2015-06-14 05:17:09 +00:00
|
|
|
* var max = new Tone.Max(2);
|
|
|
|
* var sig = new Tone.Signal(3).connect(max);
|
|
|
|
* //max outputs 3
|
|
|
|
* sig.value = 1;
|
|
|
|
* //max outputs 2
|
2015-06-20 19:50:57 +00:00
|
|
|
* @example
|
|
|
|
* var max = new Tone.Max();
|
|
|
|
* var sigA = new Tone.Signal(3);
|
|
|
|
* var sigB = new Tone.Signal(4);
|
|
|
|
* sigA.connect(max, 0, 0);
|
|
|
|
* sigB.connect(max, 0, 1);
|
|
|
|
* //output of max is 4.
|
2014-07-20 22:18:29 +00:00
|
|
|
*/
|
|
|
|
Tone.Max = function(max){
|
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-07-20 22:18:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the max signal
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value = this.input[1] = new Tone.Signal(max);
|
2014-07-20 22:18:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-08 01:42:31 +00:00
|
|
|
* @type {Tone.Select}
|
2014-07-20 22:18:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-23 01:23:47 +00:00
|
|
|
this._ifThenElse = this.output = new Tone.IfThenElse();
|
2014-07-20 22:18:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-08 01:42:31 +00:00
|
|
|
* @type {Tone.Select}
|
2014-07-20 22:18:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-10-23 01:23:47 +00:00
|
|
|
this._gt = new Tone.GreaterThan();
|
2014-07-20 22:18:29 +00:00
|
|
|
|
|
|
|
//connections
|
2014-12-01 02:32:09 +00:00
|
|
|
this.input[0].chain(this._gt, this._ifThenElse.if);
|
2014-10-23 01:23:47 +00:00
|
|
|
this.input[0].connect(this._ifThenElse.then);
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value.connect(this._ifThenElse.else);
|
|
|
|
this._value.connect(this._gt, 0, 1);
|
2014-07-20 22:18:29 +00:00
|
|
|
};
|
|
|
|
|
2015-02-23 05:30:53 +00:00
|
|
|
Tone.extend(Tone.Max, Tone.Signal);
|
2014-07-20 22:18:29 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-19 04:52:04 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Max} this
|
2014-07-20 22:18:29 +00:00
|
|
|
*/
|
|
|
|
Tone.Max.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value.dispose();
|
2014-10-13 23:22:11 +00:00
|
|
|
this._ifThenElse.dispose();
|
2014-07-20 22:18:29 +00:00
|
|
|
this._gt.dispose();
|
2015-02-23 05:30:53 +00:00
|
|
|
this._value = null;
|
2014-10-13 23:22:11 +00:00
|
|
|
this._ifThenElse = null;
|
2014-07-20 22:18:29 +00:00
|
|
|
this._gt = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-07-20 22:18:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Max;
|
|
|
|
});
|