Tone.js/Tone/component/Gate.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-07-23 19:50:45 +00:00
define(["Tone/core/Tone", "Tone/component/Follower", "Tone/signal/GreaterThan"], function(Tone){
"use strict";
2014-07-23 19:50:45 +00:00
/**
* @class Only pass signal through when it's signal exceeds the
* specified threshold.
*
* @constructor
* @extends {Tone}
* @param {number=} [thresh = -40] the threshold in Decibels
2014-09-06 22:10:42 +00:00
* @param {number=} [attackTime = 0.1] the follower's attacktime
* @param {number=} [releaseTime = 0.1] the follower's release time
2014-07-23 19:50:45 +00:00
*/
2014-09-06 22:10:42 +00:00
Tone.Gate = function(thresh, attackTime, releaseTime){
2014-07-23 19:50:45 +00:00
Tone.call(this);
//default values
thresh = this.defaultArg(thresh, -40);
2014-09-06 22:10:42 +00:00
attackTime = this.defaultArg(attackTime, 0.1);
releaseTime = this.defaultArg(releaseTime, 0.2);
2014-07-23 19:50:45 +00:00
/**
* @type {Tone.Follower}
* @private
*/
2014-09-06 22:10:42 +00:00
this._follower = new Tone.Follower(attackTime, releaseTime);
2014-07-23 19:50:45 +00:00
/**
* @type {Tone.GreaterThan}
* @private
*/
this._gt = new Tone.GreaterThan(this.dbToGain(thresh));
//the connections
this.connectSeries(this.input, this.output);
2014-07-23 19:50:45 +00:00
//the control signal
this.connectSeries(this.input, this._gt, this._follower, this.output.gain);
2014-07-23 19:50:45 +00:00
};
Tone.extend(Tone.Gate);
/**
* set the gating threshold
* @param {number} thresh the gating threshold
*/
Tone.Gate.prototype.setThreshold = function(thresh){
this._gt.setValue(this.dbToGain(thresh));
};
/**
2014-09-06 22:10:42 +00:00
* set attack time of the follower
* @param {Tone.Time} attackTime
2014-07-23 19:50:45 +00:00
*/
2014-09-06 22:10:42 +00:00
Tone.Gate.prototype.setAttack = function(attackTime){
this._follower.setAttack(attackTime);
};
/**
* set attack time of the follower
* @param {Tone.Time} releaseTime
*/
Tone.Gate.prototype.setRelease = function(releaseTime){
this._follower.setRelease(releaseTime);
2014-07-23 19:50:45 +00:00
};
/**
* dispose
*/
Tone.Gate.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2014-07-23 19:50:45 +00:00
this._follower.dispose();
this._gt.dispose();
this._follower = null;
this._gt = null;
};
return Tone.Gate;
});