Tone.js/Tone/signal/Max.js

79 lines
1.8 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.SignalBase}
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-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);
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, Tone.SignalBase);
2014-07-20 22:18:29 +00:00
/**
* Will output the maximum between the incoming signal
* and `value`.
* @memberOf Tone.Max#
* @type {number}
* @name value
2014-07-20 22:18:29 +00:00
*/
Object.defineProperty(Tone.Max.prototype, "value", {
get : function(){
return this._maxSignal.value;
},
set : function(max){
this._maxSignal.value = max;
}
});
2014-07-20 22:18:29 +00:00
/**
* clean up
2015-02-02 03:56:33 +00:00
* @returns {Tone.Max} `this`
2014-07-20 22:18:29 +00:00
*/
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;
2015-02-02 03:56:33 +00:00
return this;
2014-07-20 22:18:29 +00:00
};
return Tone.Max;
});