Tone.js/Tone/signal/Clip.js

84 lines
1.7 KiB
JavaScript
Raw Normal View History

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
"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
* @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
* @type {Tone.Min}
2014-07-20 22:26:33 +00:00
* @private
*/
this._min = this.input = new Tone.Min(max);
2014-07-20 22:26:33 +00:00
/**
* the max clipper
* @type {Tone.Max}
2014-07-20 22:26:33 +00:00
* @private
*/
this._max = this.output = new Tone.Max(min);
2014-07-20 22:26:33 +00:00
this._min.connect(this._max);
2014-07-20 22:26:33 +00:00
};
Tone.extend(Tone.Clip, Tone.SignalBase);
2014-07-20 22:26:33 +00:00
2014-07-22 15:31:14 +00:00
/**
* The minimum value which Clip will output.
* @memberOf Tone.Clip#
* @type {number}
* @name min
2014-07-22 15:31:14 +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
/**
* The maximum value which Clip will output.
* @memberOf Tone.Clip#
* @type {number}
* @name max
2014-07-22 15:31:14 +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(){
Tone.prototype.dispose.call(this);
2014-07-22 15:31:14 +00:00
this._min.dispose();
this._min = null;
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;
});