2015-03-24 20:29:48 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/CrossFade", "Tone/component/Merge",
|
2015-04-05 16:13:19 +00:00
|
|
|
"Tone/component/Split", "Tone/signal/Signal", "Tone/signal/GainToAudio"],
|
2014-04-05 22:05:42 +00:00
|
|
|
function(Tone){
|
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-21 17:06:27 +00:00
|
|
|
/**
|
|
|
|
* Panner.
|
|
|
|
*
|
2014-09-05 15:32:33 +00:00
|
|
|
* @class Equal Power Gain L/R Panner. Not 3D.
|
|
|
|
* 0 = 100% Left
|
|
|
|
* 1 = 100% Right
|
2014-06-21 17:06:27 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
2014-12-02 06:42:08 +00:00
|
|
|
* @param {number} [initialPan=0.5] the initail panner value (defaults to 0.5 = center)
|
2015-02-27 21:53:10 +00:00
|
|
|
* @example
|
|
|
|
* var panner = new Tone.Panner(1);
|
|
|
|
* // ^ pan the input signal hard right.
|
2014-06-21 17:06:27 +00:00
|
|
|
*/
|
|
|
|
Tone.Panner = function(initialPan){
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2015-03-24 20:29:48 +00:00
|
|
|
Tone.call(this);
|
|
|
|
|
2014-06-21 17:06:27 +00:00
|
|
|
/**
|
2015-03-24 20:29:48 +00:00
|
|
|
* indicates if the panner is using the new StereoPannerNode internally
|
|
|
|
* @type {boolean}
|
2014-06-21 17:06:27 +00:00
|
|
|
* @private
|
|
|
|
*/
|
2015-03-24 20:29:48 +00:00
|
|
|
this._hasStereoPanner = this.isFunction(this.context.createStereoPanner);
|
|
|
|
|
|
|
|
if (this._hasStereoPanner){
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the panner node
|
|
|
|
* @type {StereoPannerNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._panner = this.input = this.output = this.context.createStereoPanner();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the pan control
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
2015-05-23 22:57:05 +00:00
|
|
|
this.pan = new Tone.Signal(0, Tone.Type.Normal);
|
2015-03-24 20:29:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* scale the pan signal to between -1 and 1
|
|
|
|
* @type {Tone.WaveShaper}
|
|
|
|
* @private
|
|
|
|
*/
|
2015-04-05 16:13:19 +00:00
|
|
|
this._scalePan = new Tone.GainToAudio();
|
2015-03-24 20:29:48 +00:00
|
|
|
|
|
|
|
//connections
|
|
|
|
this.pan.chain(this._scalePan, this._panner.pan);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the dry/wet knob
|
|
|
|
* @type {Tone.CrossFade}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._crossFade = new Tone.CrossFade();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Tone.Merge}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._merger = this.output = new Tone.Merge();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {Tone.Split}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._splitter = this.input = new Tone.Split();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the pan control
|
|
|
|
* @type {Tone.Signal}
|
|
|
|
*/
|
|
|
|
this.pan = this._crossFade.fade;
|
2014-06-21 17:06:27 +00:00
|
|
|
|
2015-03-24 20:29:48 +00:00
|
|
|
//CONNECTIONS:
|
|
|
|
//left channel is a, right channel is b
|
|
|
|
this._splitter.connect(this._crossFade, 0, 0);
|
|
|
|
this._splitter.connect(this._crossFade, 1, 1);
|
|
|
|
//merge it back together
|
|
|
|
this._crossFade.a.connect(this._merger, 0, 0);
|
|
|
|
this._crossFade.b.connect(this._merger, 0, 1);
|
|
|
|
}
|
2014-06-21 17:06:27 +00:00
|
|
|
|
|
|
|
//initial value
|
2015-02-06 22:49:04 +00:00
|
|
|
this.pan.value = this.defaultArg(initialPan, 0.5);
|
2015-04-05 19:13:15 +00:00
|
|
|
this._readOnly("pan");
|
2014-06-18 21:01:31 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
|
|
|
Tone.extend(Tone.Panner);
|
|
|
|
|
2014-06-21 17:06:27 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 17:48:04 +00:00
|
|
|
* @returns {Tone.Panner} `this`
|
2014-06-21 17:06:27 +00:00
|
|
|
*/
|
|
|
|
Tone.Panner.prototype.dispose = function(){
|
2014-08-24 20:24:16 +00:00
|
|
|
Tone.prototype.dispose.call(this);
|
2015-04-05 19:13:15 +00:00
|
|
|
this._writable("pan");
|
2015-03-24 20:29:48 +00:00
|
|
|
if (this._hasStereoPanner){
|
|
|
|
this._panner.disconnect();
|
|
|
|
this._panner = null;
|
|
|
|
this.pan.dispose();
|
|
|
|
this.pan = null;
|
|
|
|
this._scalePan.dispose();
|
|
|
|
this._scalePan = null;
|
|
|
|
} else {
|
|
|
|
this._crossFade.dispose();
|
|
|
|
this._crossFade = null;
|
|
|
|
this._splitter.dispose();
|
|
|
|
this._splitter = null;
|
|
|
|
this._merger.dispose();
|
|
|
|
this._merger = null;
|
|
|
|
this.pan = null;
|
|
|
|
}
|
2015-02-02 17:48:04 +00:00
|
|
|
return this;
|
2014-06-18 21:01:31 +00:00
|
|
|
};
|
2014-04-05 22:05:42 +00:00
|
|
|
|
|
|
|
return Tone.Panner;
|
2014-06-21 17:06:27 +00:00
|
|
|
});
|