2017-08-27 21:50:31 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/component/CrossFade", "Tone/component/Merge", "Tone/component/Split",
|
|
|
|
"Tone/signal/Signal", "Tone/signal/AudioToGain", "Tone/signal/Zero", "Tone/core/AudioNode"],
|
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
|
|
|
/**
|
2015-07-02 00:19:58 +00:00
|
|
|
* @class Tone.Panner is an equal power Left/Right Panner and does not
|
2017-08-27 21:50:31 +00:00
|
|
|
* support 3D. Panner uses the StereoPannerNode when available.
|
|
|
|
*
|
2014-06-21 17:06:27 +00:00
|
|
|
* @constructor
|
2017-08-27 21:50:31 +00:00
|
|
|
* @extends {Tone.AudioNode}
|
2017-04-30 18:11:44 +00:00
|
|
|
* @param {NormalRange} [initialPan=0] The initail panner value (center).
|
2015-02-27 21:53:10 +00:00
|
|
|
* @example
|
2017-08-27 21:50:31 +00:00
|
|
|
* //pan the input signal hard right.
|
2015-02-27 21:53:10 +00:00
|
|
|
* var panner = new Tone.Panner(1);
|
2014-06-21 17:06:27 +00:00
|
|
|
*/
|
|
|
|
Tone.Panner = function(initialPan){
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.AudioNode.call(this);
|
2017-04-30 18:11:44 +00:00
|
|
|
if (Tone.Panner.hasStereoPanner){
|
2015-03-24 20:29:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the panner node
|
|
|
|
* @type {StereoPannerNode}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._panner = this.input = this.output = this.context.createStereoPanner();
|
|
|
|
|
|
|
|
/**
|
2017-08-27 21:50:31 +00:00
|
|
|
* The pan control. -1 = hard left, 1 = hard right.
|
2015-06-13 23:50:39 +00:00
|
|
|
* @type {NormalRange}
|
|
|
|
* @signal
|
2017-08-27 21:50:31 +00:00
|
|
|
*/
|
2016-02-27 16:31:15 +00:00
|
|
|
this.pan = this._panner.pan;
|
2017-08-27 21:50:31 +00:00
|
|
|
|
2015-03-24 20:29:48 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the dry/wet knob
|
|
|
|
* @type {Tone.CrossFade}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._crossFade = new Tone.CrossFade();
|
2017-08-27 21:50:31 +00:00
|
|
|
|
2015-03-24 20:29:48 +00:00
|
|
|
/**
|
|
|
|
* @type {Tone.Merge}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._merger = this.output = new Tone.Merge();
|
2017-08-27 21:50:31 +00:00
|
|
|
|
2015-03-24 20:29:48 +00:00
|
|
|
/**
|
|
|
|
* @type {Tone.Split}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._splitter = this.input = new Tone.Split();
|
2017-08-27 21:50:31 +00:00
|
|
|
|
2015-03-24 20:29:48 +00:00
|
|
|
/**
|
2017-08-27 21:50:31 +00:00
|
|
|
* The pan control. -1 = hard left, 1 = hard right.
|
2016-02-27 16:31:15 +00:00
|
|
|
* @type {AudioRange}
|
2015-06-13 23:50:39 +00:00
|
|
|
* @signal
|
2017-08-27 21:50:31 +00:00
|
|
|
*/
|
2016-02-27 16:31:15 +00:00
|
|
|
this.pan = new Tone.Signal(0, Tone.Type.AudioRange);
|
|
|
|
|
2016-03-04 23:59:31 +00:00
|
|
|
/**
|
|
|
|
* always sends 0
|
|
|
|
* @type {Tone.Zero}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._zero = new Tone.Zero();
|
|
|
|
|
2016-02-27 16:31:15 +00:00
|
|
|
/**
|
|
|
|
* The analog to gain conversion
|
|
|
|
* @type {Tone.AudioToGain}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
this._a2g = new Tone.AudioToGain();
|
2014-06-21 17:06:27 +00:00
|
|
|
|
2015-03-24 20:29:48 +00:00
|
|
|
//CONNECTIONS:
|
2016-03-04 23:59:31 +00:00
|
|
|
this._zero.connect(this._a2g);
|
|
|
|
this.pan.chain(this._a2g, this._crossFade.fade);
|
2015-03-24 20:29:48 +00:00
|
|
|
//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
|
2017-04-30 19:03:49 +00:00
|
|
|
this.pan.value = Tone.defaultArg(initialPan, 0);
|
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
|
|
|
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.extend(Tone.Panner, Tone.AudioNode);
|
2014-04-05 22:05:42 +00:00
|
|
|
|
2016-02-27 16:31:15 +00:00
|
|
|
/**
|
2017-04-30 18:11:44 +00:00
|
|
|
* Indicates if the panner is using the new StereoPannerNode internally
|
|
|
|
* @type {Boolean}
|
|
|
|
* @static
|
2016-02-27 16:31:15 +00:00
|
|
|
* @private
|
2017-04-30 18:11:44 +00:00
|
|
|
* @readOnly
|
2016-02-27 16:31:15 +00:00
|
|
|
*/
|
2017-04-30 18:11:44 +00:00
|
|
|
Tone.Panner.hasStereoPanner = Tone.context && Tone.isFunction(Tone.context.createStereoPanner);
|
2016-02-27 16:31:15 +00:00
|
|
|
|
2014-06-21 17:06:27 +00:00
|
|
|
/**
|
2015-06-20 23:25:49 +00:00
|
|
|
* Clean up.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.Panner} this
|
2014-06-21 17:06:27 +00:00
|
|
|
*/
|
|
|
|
Tone.Panner.prototype.dispose = function(){
|
2017-08-27 21:50:31 +00:00
|
|
|
Tone.AudioNode.prototype.dispose.call(this);
|
2015-04-05 19:13:15 +00:00
|
|
|
this._writable("pan");
|
2017-04-30 18:11:44 +00:00
|
|
|
if (Tone.Panner.hasStereoPanner){
|
2015-03-24 20:29:48 +00:00
|
|
|
this._panner.disconnect();
|
|
|
|
this._panner = null;
|
|
|
|
this.pan = null;
|
|
|
|
} else {
|
2016-03-04 23:59:31 +00:00
|
|
|
this._zero.dispose();
|
|
|
|
this._zero = null;
|
2015-03-24 20:29:48 +00:00
|
|
|
this._crossFade.dispose();
|
|
|
|
this._crossFade = null;
|
|
|
|
this._splitter.dispose();
|
|
|
|
this._splitter = null;
|
|
|
|
this._merger.dispose();
|
|
|
|
this._merger = null;
|
2016-02-27 16:31:15 +00:00
|
|
|
this.pan.dispose();
|
2015-03-24 20:29:48 +00:00
|
|
|
this.pan = null;
|
2016-02-27 16:31:15 +00:00
|
|
|
this._a2g.dispose();
|
|
|
|
this._a2g = null;
|
2015-03-24 20:29:48 +00:00
|
|
|
}
|
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;
|
2017-08-27 21:50:31 +00:00
|
|
|
});
|