Tone.js/Tone/component/DryWet.js

101 lines
2 KiB
JavaScript
Raw Normal View History

2014-11-01 20:17:27 +00:00
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Expr"], function(Tone){
"use strict";
2014-06-15 23:08:32 +00:00
/**
2014-08-21 00:46:10 +00:00
* @class dry/wet knob.
* equal power fading control values:
* 0 = 100% wet - 0% dry
* 1 = 0% wet - 100% dry
2014-06-15 23:08:32 +00:00
*
* @constructor
2014-08-21 00:46:10 +00:00
* @extends {Tone}
2014-12-02 06:42:08 +00:00
* @param {number} [initialDry=0.5]
2014-06-15 23:08:32 +00:00
*/
Tone.DryWet = function(initialDry){
Tone.call(this);
2014-06-20 05:12:15 +00:00
/**
* connect this input to the dry signal
* the dry signal is also the default input
*
* @type {GainNode}
*/
this.dry = this.input;
/**
* connect this input to the wet signal
*
* @type {GainNode}
*/
this.wet = this.context.createGain();
2014-08-23 18:24:06 +00:00
2014-06-20 05:12:15 +00:00
/**
* controls the amount of wet signal
* which is mixed into the dry signal
*
2014-06-20 15:16:09 +00:00
* @type {Tone.Signal}
2014-06-20 05:12:15 +00:00
*/
2014-06-20 15:16:09 +00:00
this.wetness = new Tone.Signal();
2014-08-23 18:24:06 +00:00
2014-06-20 05:12:15 +00:00
/**
* invert the incoming signal
* @private
* @type {Tone}
*/
2014-11-01 20:17:27 +00:00
this._invert = new Tone.Expr("1 - $0");
2014-04-04 18:36:01 +00:00
//connections
this.dry.connect(this.output);
this.wet.connect(this.output);
2014-04-06 00:47:59 +00:00
//wet control
2014-12-01 02:32:09 +00:00
this.wetness.connect(this.wet.gain);
2014-06-21 17:05:41 +00:00
//dry control is the inverse of the wet
2014-12-01 02:32:09 +00:00
this.wetness.chain(this._invert, this.dry.gain);
2014-12-02 06:42:08 +00:00
this.setDry(this.defaultArg(initialDry, 0.5));
2014-06-15 23:08:32 +00:00
};
Tone.extend(Tone.DryWet);
2014-06-15 23:08:32 +00:00
/**
2014-06-20 05:12:15 +00:00
* Set the dry value
2014-06-15 23:08:32 +00:00
*
* @param {number} val
2014-06-20 15:16:09 +00:00
* @param {Tone.Time=} rampTime
2014-06-15 23:08:32 +00:00
*/
Tone.DryWet.prototype.setDry = function(val, rampTime){
2014-06-21 17:05:41 +00:00
this.setWet(1-val, rampTime);
2014-06-15 23:08:32 +00:00
};
/**
2014-06-20 05:12:15 +00:00
* Set the wet value
2014-06-15 23:08:32 +00:00
*
* @param {number} val
2014-06-20 15:16:09 +00:00
* @param {Tone.Time=} rampTime
2014-06-15 23:08:32 +00:00
*/
Tone.DryWet.prototype.setWet = function(val, rampTime){
2014-06-21 17:05:41 +00:00
if (rampTime){
this.wetness.linearRampToValueNow(val, rampTime);
} else {
this.wetness.setValue(val);
}
2014-06-15 23:08:32 +00:00
};
2014-06-20 05:12:15 +00:00
/**
* clean up
*/
Tone.DryWet.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2014-06-20 05:12:15 +00:00
this.dry.disconnect();
this.wet.disconnect();
this.wetness.dispose();
this._invert.dispose();
this.dry = null;
this.wet = null;
this.wetness = null;
this._invert = null;
};
return Tone.DryWet;
});