Tone.js/Tone/effect/Effect.js

98 lines
2.2 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";
/**
* @class Tone.Effect is the base class for effects. Connect the effect between
* the effectSend and effectReturn GainNodes, then control the amount of
2015-06-22 05:20:57 +00:00
* effect which goes to the output using the wet control.
*
* @constructor
* @extends {Tone}
2015-06-22 05:20:57 +00:00
* @param {NormalRange|Object} [wet] The starting wet value.
*/
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-06-22 05:20:57 +00:00
* The wet control is how much of the effected
* will pass through to the output. 1 = 100% effected
* signal, 0 = 100% dry signal.
2015-06-13 23:50:39 +00:00
* @type {NormalRange}
* @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
};
/**
* chains the effect in between the effectSend and effectReturn
* @param {Tone} effect
* @private
* @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;
};
/**
2015-06-22 05:20:57 +00:00
* Clean up.
* @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;
});