Tone.js/Tone/component/Panner.js

87 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-08-24 19:46:55 +00:00
define(["Tone/core/Tone", "Tone/component/DryWet", "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
* @type {Tone.DryWet}
* @private
*/
this._dryWet = new Tone.DryWet();
/**
* @type {Tone.Merge}
* @private
*/
2014-11-04 06:23:59 +00:00
this._merger = this.output = new Tone.Merge();
2014-06-21 17:06:27 +00:00
/**
* @type {Tone.Split}
* @private
*/
this._splitter = new Tone.Split();
/**
* the pan control
* @type {Tone.Signal}
*/
2014-06-23 17:30:00 +00:00
this.pan = this._dryWet.wetness;
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
this._splitter.left.connect(this._dryWet.dry);
this._splitter.right.connect(this._dryWet.wet);
//merge it back together
this._dryWet.dry.connect(this._merger.left);
this._dryWet.wet.connect(this._merger.right);
//initial value
this.setPan(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
/**
* set the l/r pan.
*
* 0 = 100% left.
* 1 = 100% right.
*
* @param {number} pan 0-1
2014-12-02 06:42:08 +00:00
* @param {Tone.Time=} rampTime ramp to the pan position
2014-06-21 17:06:27 +00:00
*/
Tone.Panner.prototype.setPan = function(pan, rampTime){
this._dryWet.setWet(pan, rampTime);
};
/**
* clean up
*/
Tone.Panner.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2014-06-21 17:06:27 +00:00
this._dryWet.dispose();
this._splitter.dispose();
this._merger.dispose();
this._dryWet = null;
this._splitter = null;
this._merger = null;
this.pan = null;
2014-06-18 21:01:31 +00:00
};
return Tone.Panner;
2014-06-21 17:06:27 +00:00
});