Tone.js/Tone/component/Panner.js

79 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-02-02 17:48:04 +00:00
define(["Tone/core/Tone", "Tone/component/CrossFade", "Tone/component/Merge", "Tone/component/Split"],
function(Tone){
"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)
2014-06-21 17:06:27 +00:00
*/
Tone.Panner = function(initialPan){
2014-11-04 06:23:59 +00:00
Tone.call(this, 1, 0);
2014-06-21 17:06:27 +00:00
/**
* the dry/wet knob
2015-02-02 17:48:04 +00:00
* @type {Tone.CrossFade}
2014-06-21 17:06:27 +00:00
* @private
*/
2015-02-02 17:48:04 +00:00
this._crossFade = new Tone.CrossFade();
2015-02-11 20:28:33 +00:00
2014-06-21 17:06:27 +00:00
/**
* @type {Tone.Merge}
* @private
*/
2014-11-04 06:23:59 +00:00
this._merger = this.output = new Tone.Merge();
2015-02-11 20:28:33 +00:00
2014-06-21 17:06:27 +00:00
/**
* @type {Tone.Split}
* @private
*/
this._splitter = new Tone.Split();
2015-02-11 20:28:33 +00:00
2014-06-21 17:06:27 +00:00
/**
* the pan control
* @type {Tone.Signal}
*/
2015-02-02 17:48:04 +00:00
this.pan = this._crossFade.fade;
2014-06-21 17:06:27 +00:00
//CONNECTIONS:
this.input.connect(this._splitter.left);
this.input.connect(this._splitter.right);
//left channel is dry, right channel is wet
2015-02-02 17:48:04 +00:00
this._splitter.connect(this._crossFade, 0, 0);
this._splitter.connect(this._crossFade, 1, 1);
2014-06-21 17:06:27 +00:00
//merge it back together
2015-02-02 17:48:04 +00:00
this._crossFade.a.connect(this._merger.left);
this._crossFade.b.connect(this._merger.right);
2014-06-21 17:06:27 +00:00
//initial value
this.pan.value = this.defaultArg(initialPan, 0.5);
2014-06-18 21:01:31 +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(){
Tone.prototype.dispose.call(this);
2015-02-02 17:48:04 +00:00
this._crossFade.dispose();
this._crossFade = null;
2014-06-21 17:06:27 +00:00
this._splitter.dispose();
this._splitter = null;
2015-02-02 17:48:04 +00:00
this._merger.dispose();
2014-06-21 17:06:27 +00:00
this._merger = null;
this.pan = null;
2015-02-02 17:48:04 +00:00
return this;
2014-06-18 21:01:31 +00:00
};
return Tone.Panner;
2014-06-21 17:06:27 +00:00
});