Tone.js/Tone/signal/Max.js

76 lines
1.7 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/signal/GreaterThan", "Tone/signal/IfThenElse", "Tone/signal/Signal"], function(Tone){
2014-07-20 22:18:29 +00:00
"use strict";
2014-07-20 22:18:29 +00:00
/**
2014-10-23 01:23:47 +00:00
* @class outputs the greater of two signals. If a number is provided in the constructor
* it will use that instead of the signal.
2014-07-20 22:18:29 +00:00
*
* @constructor
* @extends {Tone}
2014-10-23 01:23:47 +00:00
* @param {number=} max max value if provided. if not provided, it will use the
* signal value from input 1.
2014-07-20 22:18:29 +00:00
*/
Tone.Max = function(max){
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
*/
2014-10-23 01:23:47 +00:00
this._maxSignal = 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-10-23 01:23:47 +00:00
this.chain(this.input[0], this._gt, this._ifThenElse.if);
this.input[0].connect(this._ifThenElse.then);
this._maxSignal.connect(this._ifThenElse.else);
2014-10-23 01:23:47 +00:00
this._maxSignal.connect(this._gt, 0, 1);
2014-07-20 22:18:29 +00:00
};
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);
};
/**
* 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(){
Tone.prototype.dispose.call(this);
2014-07-20 22:18:29 +00:00
this._maxSignal.dispose();
this._ifThenElse.dispose();
2014-07-20 22:18:29 +00:00
this._gt.dispose();
this._maxSignal = null;
this._ifThenElse = null;
2014-07-20 22:18:29 +00:00
this._gt = null;
};
return Tone.Max;
});