renamed DryWet to CrossFade

This commit is contained in:
Yotam Mann 2015-02-02 12:48:04 -05:00
parent ee8c2cd43f
commit 11ef065861
7 changed files with 187 additions and 185 deletions

View file

@ -7,6 +7,8 @@
* Sampler accepts multiple samples as an object and can set using setSample
* deprecated MultiSampler - use Sampler with PolySynth instead
* added [cdn](cdn.tonejs.org/latest/Tone.min.js) - please don't use for production code
* Renamed DryWet to CrossFade
* functions return `this` to allow for chaining
### r3 - Expressive Signal

View file

@ -0,0 +1,99 @@
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Expr", "Tone/signal/EqualPowerGain"], function(Tone){
"use strict";
/**
* @class Equal power fading control values:
* 0 = 100% input 0
* 1 = 100% input 1
*
* @constructor
* @extends {Tone}
* @param {number} [initialFade=0.5]
*/
Tone.CrossFade = function(initialFade){
Tone.call(this, 2, 1);
/**
* the first input. input "a".
* @type {GainNode}
*/
this.a = this.input[0] = this.context.createGain();
/**
* the second input. input "b"
* @type {GainNode}
*/
this.b = this.input[1] = this.context.createGain();
/**
* controls the amount of wet signal
* which is mixed into the dry signal
*
* @type {Tone.Signal}
*/
this.fade = new Tone.Signal();
/**
* equal power gain cross fade
* @private
* @type {Tone.EqualPowerGain}
*/
this._equalPower = new Tone.EqualPowerGain();
/**
* invert the incoming signal
* @private
* @type {Tone}
*/
this._invert = new Tone.Expr("1 - $0");
//connections
this.a.connect(this.output);
this.b.connect(this.output);
this.fade.connect(this._equalPower);
this._equalPower.chain(this.b.gain);
this._equalPower.chain(this._invert, this.a.gain);
this.setFade(this.defaultArg(initialFade, 0.5));
};
Tone.extend(Tone.CrossFade);
/**
* Set the wet value
*
* @param {number} val
* @param {Tone.Time=} rampTime
* @returns {Tone.CrossFade} `this`
*/
Tone.CrossFade.prototype.setFade = function(val, rampTime){
if (rampTime){
this.fade.linearRampToValueNow(val, rampTime);
} else {
this.fade.setValue(val);
}
return this;
};
/**
* clean up
* @returns {Tone.CrossFade} `this`
*/
Tone.CrossFade.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._equalPower.dispose();
this._equalPower = null;
this.fade.dispose();
this.fade = null;
this._invert.dispose();
this._invert = null;
this.a.disconnect();
this.a = null;
this.b.disconnect();
this.b = null;
return this;
};
return Tone.CrossFade;
});

View file

@ -1,100 +0,0 @@
define(["Tone/core/Tone", "Tone/signal/Signal", "Tone/signal/Expr"], function(Tone){
"use strict";
/**
* @class dry/wet knob.
* equal power fading control values:
* 0 = 100% wet - 0% dry
* 1 = 0% wet - 100% dry
*
* @constructor
* @extends {Tone}
* @param {number} [initialDry=0.5]
*/
Tone.DryWet = function(initialDry){
Tone.call(this);
/**
* 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();
/**
* controls the amount of wet signal
* which is mixed into the dry signal
*
* @type {Tone.Signal}
*/
this.wetness = new Tone.Signal();
/**
* invert the incoming signal
* @private
* @type {Tone}
*/
this._invert = new Tone.Expr("1 - $0");
//connections
this.dry.connect(this.output);
this.wet.connect(this.output);
//wet control
this.wetness.connect(this.wet.gain);
//dry control is the inverse of the wet
this.wetness.chain(this._invert, this.dry.gain);
this.setDry(this.defaultArg(initialDry, 0.5));
};
Tone.extend(Tone.DryWet);
/**
* Set the dry value
*
* @param {number} val
* @param {Tone.Time=} rampTime
*/
Tone.DryWet.prototype.setDry = function(val, rampTime){
this.setWet(1-val, rampTime);
};
/**
* Set the wet value
*
* @param {number} val
* @param {Tone.Time=} rampTime
*/
Tone.DryWet.prototype.setWet = function(val, rampTime){
if (rampTime){
this.wetness.linearRampToValueNow(val, rampTime);
} else {
this.wetness.setValue(val);
}
};
/**
* clean up
*/
Tone.DryWet.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
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;
});

View file

@ -1,4 +1,4 @@
define(["Tone/core/Tone", "Tone/component/DryWet", "Tone/component/Merge", "Tone/component/Split"],
define(["Tone/core/Tone", "Tone/component/CrossFade", "Tone/component/Merge", "Tone/component/Split"],
function(Tone){
"use strict";
@ -20,10 +20,10 @@ function(Tone){
/**
* the dry/wet knob
* @type {Tone.DryWet}
* @type {Tone.CrossFade}
* @private
*/
this._dryWet = new Tone.DryWet();
this._crossFade = new Tone.CrossFade();
/**
* @type {Tone.Merge}
* @private
@ -38,17 +38,17 @@ function(Tone){
* the pan control
* @type {Tone.Signal}
*/
this.pan = this._dryWet.wetness;
this.pan = this._crossFade.fade;
//CONNECTIONS:
this.input.connect(this._splitter.left);
this.input.connect(this._splitter.right);
//left channel is dry, right channel is wet
this._splitter.left.connect(this._dryWet.dry);
this._splitter.right.connect(this._dryWet.wet);
this._splitter.connect(this._crossFade, 0, 0);
this._splitter.connect(this._crossFade, 1, 1);
//merge it back together
this._dryWet.dry.connect(this._merger.left);
this._dryWet.wet.connect(this._merger.right);
this._crossFade.a.connect(this._merger.left);
this._crossFade.b.connect(this._merger.right);
//initial value
this.setPan(this.defaultArg(initialPan, 0.5));
@ -64,23 +64,27 @@ function(Tone){
*
* @param {number} pan 0-1
* @param {Tone.Time=} rampTime ramp to the pan position
* @returns {Tone.Panner} `this`
*/
Tone.Panner.prototype.setPan = function(pan, rampTime){
this._dryWet.setWet(pan, rampTime);
this._crossFade.setFade(pan, rampTime);
return this;
};
/**
* clean up
* @returns {Tone.Panner} `this`
*/
Tone.Panner.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
this._dryWet.dispose();
this._crossFade.dispose();
this._crossFade = null;
this._splitter.dispose();
this._merger.dispose();
this._dryWet = null;
this._splitter = null;
this._merger.dispose();
this._merger = null;
this.pan = null;
return this;
};
return Tone.Panner;

View file

@ -1,4 +1,4 @@
define(["Tone/core/Tone", "Tone/component/DryWet"], function(Tone){
define(["Tone/core/Tone", "Tone/component/CrossFade"], function(Tone){
"use strict";
@ -9,22 +9,27 @@ define(["Tone/core/Tone", "Tone/component/DryWet"], function(Tone){
*
* @constructor
* @extends {Tone}
* @param {number} [initalDry=0] the starting dry value
* defaults to 100% wet
* @param {number} [initialWet=0] the starting wet value
* defaults to 100% wet
*/
Tone.Effect = function(){
Tone.call(this);
//get all of the defaults
var options = this.optionsObject(arguments, ["dry"], Tone.Effect.defaults);
var options = this.optionsObject(arguments, ["wet"], Tone.Effect.defaults);
/**
* the drywet knob to control the amount of effect
*
* @type {Tone.DryWet}
* @type {Tone.CrossFade}
*/
this.dryWet = new Tone.DryWet();
this.dryWet = new Tone.CrossFade();
/**
* the wet control
* @type {Tone.Signal}
*/
this.wet = this.dryWet.fade;
/**
* connect the effectSend to the input of hte effect
@ -41,12 +46,12 @@ define(["Tone/core/Tone", "Tone/component/DryWet"], function(Tone){
this.effectReturn = this.context.createGain();
//connections
this.input.connect(this.dryWet.dry);
this.input.connect(this.dryWet.a);
this.input.connect(this.effectSend);
this.effectReturn.connect(this.dryWet.wet);
this.effectReturn.connect(this.dryWet.b);
this.dryWet.connect(this.output);
//setup values
this.setDry(options.dry);
this.setWet(options.wet);
};
Tone.extend(Tone.Effect);
@ -56,18 +61,7 @@ define(["Tone/core/Tone", "Tone/component/DryWet"], function(Tone){
* @type {Object}
*/
Tone.Effect.defaults = {
"dry" : 0
};
/**
* setDry adjusts the dry / wet balance
* dryness is 0 (100% wet) to 1 (100% dry)
*
* @param {number} dryness
* @param {Tone.Time=} rampTime
*/
Tone.Effect.prototype.setDry = function(dryness, rampTime){
this.dryWet.setDry(dryness, rampTime);
"wet" : 1
};
/**
@ -76,48 +70,48 @@ define(["Tone/core/Tone", "Tone/component/DryWet"], function(Tone){
*
* @param {number} wetness
* @param {Tone.Time=} rampTime
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.setWet = function(wetVal, rampTime){
this.dryWet.setWet(wetVal, rampTime);
};
/**
* set in bulk
* @param {Object} param
*/
Tone.Effect.prototype.set = function(params){
if (!this.isUndef(params.dry)) this.setDry(params.dry);
if (!this.isUndef(params.wet)) this.setWet(params.wet);
this.dryWet.setFade(wetVal, rampTime);
return this;
};
/**
* bypass the effect
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.bypass = function(){
this.setDry(1);
this.setWet(0);
return this;
};
/**
* chains the effect in between the effectSend and effectReturn
* @param {Tone} effect
* @internal
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.connectEffect = function(effect){
this.effectSend.chain(effect, this.effectReturn);
return this;
};
/**
* set the preset if it exists
* @param {string} presetName the name of the preset
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.setPreset = function(presetName){
if (!this.isUndef(this.preset) && this.preset.hasOwnProperty(presetName)){
this.set(this.preset[presetName]);
}
return this;
};
/**
* tear down
* @returns {Tone.Effect} `this`
*/
Tone.Effect.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
@ -127,6 +121,8 @@ define(["Tone/core/Tone", "Tone/component/DryWet"], function(Tone){
this.effectSend = null;
this.effectReturn.disconnect();
this.effectReturn = null;
this.wet = null;
return this;
};
return Tone.Effect;

View file

@ -1,4 +1,5 @@
define(["Tone/core/Tone", "Tone/effect/Effect", "Tone/component/Split", "Tone/component/Merge"],
define(["Tone/core/Tone", "Tone/effect/Effect", "Tone/component/Split",
"Tone/component/Merge", "Tone/component/CrossFade"],
function(Tone){
"use strict";
@ -13,14 +14,14 @@ function(Tone){
Tone.call(this);
//get the defaults
var options = this.optionsObject(arguments, ["dry"], Tone.Effect.defaults);
var options = this.optionsObject(arguments, ["wet"], Tone.Effect.defaults);
/**
* the drywet knob to control the amount of effect
*
* @type {Tone.DryWet}
* @type {Tone.CrossFade}
*/
this.dryWet = new Tone.DryWet();
this.dryWet = new Tone.CrossFade();
/**
* then split it
@ -63,11 +64,11 @@ function(Tone){
//connections
this.input.connect(this._split);
//dry wet connections
this.input.connect(this.dryWet.dry);
this._merge.connect(this.dryWet.wet);
this.input.connect(this.dryWet, 0, 0);
this._merge.connect(this.dryWet, 0, 1);
this.dryWet.connect(this.output);
//setup values
this.setDry(options.dry);
this.setWet(options.wet);
};
Tone.extend(Tone.StereoEffect, Tone.Effect);

View file

@ -1,53 +1,53 @@
/* global it, describe, maxTimeout*/
define(["tests/Core", "chai", "Tone/component/DryWet", "Tone/core/Master", "Tone/signal/Signal",
define(["tests/Core", "chai", "Tone/component/CrossFade", "Tone/core/Master", "Tone/signal/Signal",
"Tone/component/Recorder", "Tone/component/Panner", "Tone/component/LFO", "Tone/component/Gate",
"Tone/component/Follower", "Tone/component/Envelope", "Tone/component/Filter", "Tone/component/EQ",
"Tone/component/Merge", "Tone/component/Split", "tests/Common", "Tone/component/AmplitudeEnvelope",
"Tone/component/LowpassCombFilter", "Tone/component/FeedbackCombFilter", "Tone/component/Mono",
"Tone/component/MultibandSplit", "Tone/component/Compressor", "Tone/component/PanVol",
"Tone/component/MultibandCompressor", "Tone/component/ScaledEnvelope", "Tone/component/Limiter"],
function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Follower, Envelope,
function(coreTest, chai, CrossFade, Master, Signal, Recorder, Panner, LFO, Gate, Follower, Envelope,
Filter, EQ, Merge, Split, Test, AmplitudeEnvelope, LowpassCombFilter, FeedbackCombFilter,
Mono, MultibandSplit, Compressor, PanVol, MultibandCompressor, ScaledEnvelope, Limiter){
var expect = chai.expect;
Master.mute();
describe("Tone.DryWet", function(){
describe("Tone.CrossFade", function(){
this.timeout(maxTimeout);
var dryWet, drySignal, wetSignal, recorder;
var crossFade, drySignal, wetSignal, recorder;
it("can be created and disposed", function(){
var dw = new DryWet();
var dw = new CrossFade();
dw.dispose();
Test.wasDisposed(dw);
});
it("handles input and output connections", function(){
Test.onlineContext();
var dryWet = new DryWet();
Test.acceptsInput(dryWet.dry);
Test.acceptsInput(dryWet.wet);
Test.acceptsOutput(dryWet);
dryWet.dispose();
var crossFade = new CrossFade();
Test.acceptsInput(crossFade, 0);
Test.acceptsInput(crossFade, 1);
Test.acceptsOutput(crossFade);
crossFade.dispose();
});
it("pass 100% dry signal", function(done){
Test.offlineTest(0.1, function(dest){
dryWet = new DryWet();
crossFade = new CrossFade();
drySignal = new Signal(10);
wetSignal = new Signal(20);
drySignal.connect(dryWet.dry);
wetSignal.connect(dryWet.wet);
drySignal.connect(crossFade, 0, 0);
wetSignal.connect(crossFade, 0, 1);
recorder = new Recorder();
dryWet.setDry(1);
dryWet.connect(dest);
crossFade.setFade(0);
crossFade.connect(dest);
}, function(sample){
expect(sample).to.equal(10);
expect(sample).to.closeTo(10, 0.01);
}, function(){
dryWet.dispose();
crossFade.dispose();
drySignal.dispose();
wetSignal.dispose();
done();
@ -56,18 +56,18 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
it("pass 100% wet signal", function(done){
Test.offlineTest(0.1, function(dest){
dryWet = new DryWet();
crossFade = new CrossFade();
drySignal = new Signal(10);
wetSignal = new Signal(20);
drySignal.connect(dryWet.dry);
wetSignal.connect(dryWet.wet);
drySignal.connect(crossFade, 0, 0);
wetSignal.connect(crossFade, 0, 1);
recorder = new Recorder();
dryWet.setWet(1);
dryWet.connect(dest);
crossFade.setFade(1);
crossFade.connect(dest);
}, function(sample){
expect(sample).to.equal(20);
expect(sample).to.closeTo(20, 0.01);
}, function(){
dryWet.dispose();
crossFade.dispose();
drySignal.dispose();
wetSignal.dispose();
done();
@ -76,18 +76,18 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
it("can mix two signals", function(done){
Test.offlineTest(0.1, function(dest){
dryWet = new DryWet();
crossFade = new CrossFade();
drySignal = new Signal(10);
wetSignal = new Signal(20);
drySignal.connect(dryWet.dry);
wetSignal.connect(dryWet.wet);
drySignal.connect(crossFade, 0, 0);
wetSignal.connect(crossFade, 0, 1);
recorder = new Recorder();
dryWet.setWet(0.5);
dryWet.connect(dest);
crossFade.setFade(0.5);
crossFade.connect(dest);
}, function(sample){
expect(sample).to.equal(15);
expect(sample).to.closeTo(17.06, 0.01);
}, function(){
dryWet.dispose();
crossFade.dispose();
drySignal.dispose();
wetSignal.dispose();
done();
@ -163,8 +163,8 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
panner.setPan(1);
panner.connect(dest);
}, function(L, R){
expect(L).to.equal(0);
expect(R).to.equal(1);
expect(L).to.be.closeTo(0, 0.01);
expect(R).to.be.closeTo(1, 0.01);
}, function(){
panner.dispose();
signal.dispose();