Tone.js/Tone/signal/Clip.js

62 lines
1.4 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
/**
2015-06-19 04:52:04 +00:00
* @class Clip the incoming signal so that the output is always between min and max.
2014-07-20 22:26:33 +00:00
*
* @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
2015-02-27 18:40:35 +00:00
* @example
2015-06-14 05:17:09 +00:00
* var clip = new Tone.Clip(0.5, 1);
* var osc = new Tone.Oscillator().connect(clip);
* //clips the output of the oscillator to between 0.5 and 1.
2014-07-20 22:26:33 +00:00
*/
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
/**
2015-02-23 05:30:53 +00:00
* The min clip value
2015-06-13 23:50:39 +00:00
* @type {Number}
* @signal
2014-07-20 22:26:33 +00:00
*/
2015-02-23 05:30:53 +00:00
this.min = this.input = new Tone.Min(max);
this._readOnly("min");
2014-07-20 22:26:33 +00:00
/**
2015-02-23 05:30:53 +00:00
* The max clip value
2015-06-13 23:50:39 +00:00
* @type {Number}
* @signal
2014-07-20 22:26:33 +00:00
*/
2015-02-23 05:30:53 +00:00
this.max = this.output = new Tone.Max(min);
this._readOnly("max");
2014-07-20 22:26:33 +00:00
2015-02-23 05:30:53 +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
/**
* clean up
* @returns {Tone.Clip} this
2014-07-22 15:31:14 +00:00
*/
Tone.Clip.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._writable("min");
2015-02-23 05:30:53 +00:00
this.min.dispose();
this.min = null;
this._writable("max");
2015-02-23 05:30:53 +00:00
this.max.dispose();
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;
});