2014-07-23 19:47:00 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/Selector"], function(Tone){
|
2014-07-20 22:18:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @class the output signal is the greater of the incoming signal and max
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
* @param {number} max the
|
|
|
|
*/
|
|
|
|
Tone.Max = function(max){
|
|
|
|
Tone.call(this);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the max signal
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._maxSignal = new Tone.Signal(max);
|
|
|
|
|
|
|
|
/**
|
2014-07-23 19:47:00 +00:00
|
|
|
* @type {Tone.Selector}
|
2014-07-20 22:18:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-07-23 19:47:00 +00:00
|
|
|
this._switch = new Tone.Selector(2);
|
2014-07-20 22:18:29 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-23 19:47:00 +00:00
|
|
|
* @type {Tone.Selector}
|
2014-07-20 22:18:29 +00:00
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._gt = new Tone.GreaterThan(max);
|
|
|
|
|
|
|
|
//connections
|
2014-07-22 16:48:37 +00:00
|
|
|
this._maxSignal.connect(this._switch, 0, 0);
|
|
|
|
this.input.connect(this._switch, 0, 1);
|
2014-07-20 22:18:29 +00:00
|
|
|
this.input.connect(this._gt);
|
|
|
|
this._gt.connect(this._switch.gate);
|
|
|
|
this._switch.connect(this.output);
|
|
|
|
};
|
|
|
|
|
|
|
|
Tone.extend(Tone.Max);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set the max value
|
|
|
|
* @param {number} max the maximum to compare to the incoming signal
|
|
|
|
*/
|
|
|
|
Tone.Max.prototype.setMax = function(max){
|
|
|
|
this._maxSignal.setValue(max);
|
|
|
|
};
|
|
|
|
|
2014-08-24 17:19:49 +00:00
|
|
|
/**
|
|
|
|
* borrows the method from {@link Tone.Signal}
|
|
|
|
*
|
|
|
|
* @function
|
|
|
|
*/
|
|
|
|
Tone.Max.prototype.connect = Tone.Signal.prototype.connect;
|
|
|
|
|
2014-07-20 22:18:29 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
|
|
|
*/
|
|
|
|
Tone.Max.prototype.dispose = function(){
|
|
|
|
this.input.disconnect();
|
|
|
|
this.output.disconnect();
|
|
|
|
this._maxSignal.dispose();
|
|
|
|
this._switch.dispose();
|
|
|
|
this._gt.dispose();
|
|
|
|
this.input = null;
|
|
|
|
this.output = null;
|
|
|
|
this._maxSignal = null;
|
|
|
|
this._switch = null;
|
|
|
|
this._gt = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.Max;
|
|
|
|
});
|