2014-08-24 19:47:59 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/signal/Max", "Tone/signal/Min", "Tone/signal/Signal"], function(Tone){
|
2014-07-20 22:26:33 +00:00
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-07-20 22:26:33 +00:00
|
|
|
/**
|
|
|
|
* @class Clip the incoming signal so that the output is always between min and max
|
|
|
|
*
|
|
|
|
* @constructor
|
2014-12-01 04:26:06 +00:00
|
|
|
* @extends {Tone.SignalBase}
|
2014-07-20 22:26:33 +00:00
|
|
|
* @param {number} min the minimum value of the outgoing signal
|
|
|
|
* @param {number} max the maximum value of the outgoing signal
|
|
|
|
*/
|
|
|
|
Tone.Clip = function(min, max){
|
2014-07-22 15:31:14 +00:00
|
|
|
//make sure the args are in the right order
|
|
|
|
if (min > max){
|
|
|
|
var tmp = min;
|
|
|
|
min = max;
|
|
|
|
max = tmp;
|
|
|
|
}
|
2014-07-20 22:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the min clipper
|
2014-08-24 17:19:49 +00:00
|
|
|
* @type {Tone.Min}
|
2014-07-20 22:26:33 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-04 06:21:42 +00:00
|
|
|
this._min = this.input = new Tone.Min(max);
|
2014-07-20 22:26:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the max clipper
|
2014-08-24 17:19:49 +00:00
|
|
|
* @type {Tone.Max}
|
2014-07-20 22:26:33 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2014-11-04 06:21:42 +00:00
|
|
|
this._max = this.output = new Tone.Max(min);
|
2014-07-20 22:26:33 +00:00
|
|
|
|
2014-11-04 06:21:42 +00:00
|
|
|
this._min.connect(this._max);
|
2014-07-20 22:26:33 +00:00
|
|
|
};
|
|
|
|
|
2014-12-01 04:26:06 +00:00
|
|
|
Tone.extend(Tone.Clip, Tone.SignalBase);
|
2014-07-20 22:26:33 +00:00
|
|
|
|
2014-07-22 15:31:14 +00:00
|
|
|
/**
|
2015-02-06 22:47:26 +00:00
|
|
|
* The minimum value which Clip will output.
|
|
|
|
* @memberOf Tone.Clip#
|
|
|
|
* @type {number}
|
|
|
|
* @name min
|
2014-07-22 15:31:14 +00:00
|
|
|
*/
|
2015-02-06 22:47:26 +00:00
|
|
|
Object.defineProperty(Tone.Clip.prototype, "min", {
|
|
|
|
get : function(){
|
|
|
|
return this._min.value;
|
|
|
|
},
|
|
|
|
set : function(min){
|
|
|
|
this._min.value = min;
|
|
|
|
}
|
|
|
|
});
|
2014-07-22 15:31:14 +00:00
|
|
|
|
|
|
|
/**
|
2015-02-06 22:47:26 +00:00
|
|
|
* The maximum value which Clip will output.
|
|
|
|
* @memberOf Tone.Clip#
|
|
|
|
* @type {number}
|
|
|
|
* @name max
|
2014-07-22 15:31:14 +00:00
|
|
|
*/
|
2015-02-06 22:47:26 +00:00
|
|
|
Object.defineProperty(Tone.Clip.prototype, "max", {
|
|
|
|
get : function(){
|
|
|
|
return this._max.value;
|
|
|
|
},
|
|
|
|
set : function(max){
|
|
|
|
this._max.value = max;
|
|
|
|
}
|
|
|
|
});
|
2014-07-22 15:31:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 03:56:33 +00:00
|
|
|
* @returns {Tone.Clip} `this`
|
2014-07-22 15:31:14 +00:00
|
|
|
*/
|
|
|
|
Tone.Clip.prototype.dispose = function(){
|
2014-09-06 22:55:11 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2014-07-22 15:31:14 +00:00
|
|
|
this._min.dispose();
|
|
|
|
this._min = null;
|
2014-11-04 06:21:42 +00:00
|
|
|
this._max.dispose();
|
2014-07-22 15:31:14 +00:00
|
|
|
this._max = null;
|
2015-02-02 03:56:33 +00:00
|
|
|
return this;
|
2014-07-22 15:31:14 +00:00
|
|
|
};
|
|
|
|
|
2014-07-20 22:26:33 +00:00
|
|
|
return Tone.Clip;
|
|
|
|
});
|