Tone.js/Tone/effect/Effect.js

108 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-02-02 17:48:04 +00:00
define(["Tone/core/Tone", "Tone/component/CrossFade"], function(Tone){
"use strict";
/**
2014-08-23 17:50:13 +00:00
* @class Effect is the base class for effects. connect the effect between
2014-09-05 15:32:33 +00:00
* the effectSend and effectReturn GainNodes. then control the amount of
* effect which goes to the output using the dry/wet control.
*
* @constructor
* @extends {Tone}
2015-02-02 17:48:04 +00:00
* @param {number} [initialWet=0] the starting wet value
* defaults to 100% wet
*/
Tone.Effect = function(){
Tone.call(this);
//get all of the defaults
2015-02-02 17:48:04 +00:00
var options = this.optionsObject(arguments, ["wet"], Tone.Effect.defaults);
/**
* the drywet knob to control the amount of effect
2015-02-02 17:48:04 +00:00
* @type {Tone.CrossFade}
* @private
2015-02-02 17:48:04 +00:00
*/
this._dryWet = new Tone.CrossFade(options.wet);
2015-02-02 17:48:04 +00:00
/**
2015-02-10 16:40:27 +00:00
* The wet control, i.e. how much of the effected
* will pass through to the output.
2015-02-02 17:48:04 +00:00
* @type {Tone.Signal}
*/
this.wet = this._dryWet.fade;
2014-08-21 00:46:57 +00:00
/**
* connect the effectSend to the input of hte effect
*
* @type {GainNode}
2015-02-27 21:53:10 +00:00
* @private
*/
this.effectSend = this.context.createGain();
2014-08-21 00:46:57 +00:00
/**
* connect the output of the effect to the effectReturn
*
* @type {GainNode}
2015-02-27 21:53:10 +00:00
* @private
*/
this.effectReturn = this.context.createGain();
//connections
this.input.connect(this._dryWet.a);
this.input.connect(this.effectSend);
this.effectReturn.connect(this._dryWet.b);
this._dryWet.connect(this.output);
2015-04-18 14:54:08 +00:00
this._readOnly(["wet"]);
};
Tone.extend(Tone.Effect);
/**
* @static
* @type {Object}
*/
Tone.Effect.defaults = {
2015-02-02 17:48:04 +00:00
"wet" : 1
};
/**
* bypass the effect
2015-02-02 17:48:04 +00:00
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.bypass = function(){
2015-02-23 05:32:33 +00:00
this.wet.value = 0;
2015-02-02 17:48:04 +00:00
return this;
};
/**
* chains the effect in between the effectSend and effectReturn
* @param {Tone} effect
* @private
2015-02-02 17:48:04 +00:00
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.connectEffect = function(effect){
2014-12-01 02:32:09 +00:00
this.effectSend.chain(effect, this.effectReturn);
2015-02-02 17:48:04 +00:00
return this;
};
/**
* tear down
2015-02-02 17:48:04 +00:00
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._dryWet.dispose();
this._dryWet = null;
this.effectSend.disconnect();
this.effectSend = null;
this.effectReturn.disconnect();
this.effectReturn = null;
2015-04-18 14:54:08 +00:00
this._writable(["wet"]);
2015-02-02 17:48:04 +00:00
this.wet = null;
return this;
};
return Tone.Effect;
});