2014-06-21 21:34:31 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/effect/Effect", "Tone/component/LFO", "Tone/component/Panner"], function(Tone){
|
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2015-07-04 16:40:33 +00:00
|
|
|
* @class Tone.AutoPanner is a Tone.Panner with an LFO connected to the pan amount.
|
2015-07-04 19:25:37 +00:00
|
|
|
* More on using autopanners [here](https://www.ableton.com/en/blog/autopan-chopper-effect-and-more-liveschool/).
|
2014-06-21 21:34:31 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone.Effect}
|
2015-06-22 05:20:57 +00:00
|
|
|
* @param {Frequency|Object} [frequency] Rate of left-right oscillation.
|
2015-02-27 21:53:10 +00:00
|
|
|
* @example
|
2015-06-22 05:20:57 +00:00
|
|
|
* //create an autopanner and start it's LFO
|
|
|
|
* var autoPanner = new Tone.AutoPanner("4n").toMaster().start();
|
|
|
|
* //route an oscillator through the panner and start it
|
|
|
|
* var oscillator = new Tone.Oscillator().connect(autoPanner).start();
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-08-24 23:28:42 +00:00
|
|
|
Tone.AutoPanner = function(){
|
|
|
|
|
2014-08-25 14:23:37 +00:00
|
|
|
var options = this.optionsObject(arguments, ["frequency"], Tone.AutoPanner.defaults);
|
2014-08-24 23:28:42 +00:00
|
|
|
Tone.Effect.call(this, options);
|
2014-06-21 21:34:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the lfo which drives the panning
|
|
|
|
* @type {Tone.LFO}
|
2014-08-23 21:04:01 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2015-06-07 16:12:03 +00:00
|
|
|
this._lfo = new Tone.LFO({
|
|
|
|
"frequency" : options.frequency,
|
|
|
|
"amplitude" : options.depth,
|
|
|
|
"min" : 0,
|
|
|
|
"max" : 1,
|
|
|
|
});
|
2014-06-21 21:34:31 +00:00
|
|
|
|
2015-02-11 19:37:48 +00:00
|
|
|
/**
|
|
|
|
* The amount of panning between left and right.
|
|
|
|
* 0 = always center. 1 = full range between left and right.
|
2015-06-13 23:50:39 +00:00
|
|
|
* @type {NormalRange}
|
|
|
|
* @signal
|
2015-02-11 19:37:48 +00:00
|
|
|
*/
|
2015-04-24 17:13:00 +00:00
|
|
|
this.depth = this._lfo.amplitude;
|
2015-02-11 19:37:48 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* the panner node which does the panning
|
|
|
|
* @type {Tone.Panner}
|
2014-08-23 18:24:20 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-08-23 18:24:20 +00:00
|
|
|
this._panner = new Tone.Panner();
|
2014-06-21 21:34:31 +00:00
|
|
|
|
2015-02-10 16:40:27 +00:00
|
|
|
/**
|
2015-06-22 05:20:57 +00:00
|
|
|
* How fast the panner modulates between left and right.
|
2015-06-13 23:50:39 +00:00
|
|
|
* @type {Frequency}
|
|
|
|
* @signal
|
2015-02-10 16:40:27 +00:00
|
|
|
*/
|
|
|
|
this.frequency = this._lfo.frequency;
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
//connections
|
2014-08-23 18:24:20 +00:00
|
|
|
this.connectEffect(this._panner);
|
2014-08-23 21:04:01 +00:00
|
|
|
this._lfo.connect(this._panner.pan);
|
2015-02-10 16:40:27 +00:00
|
|
|
this.type = options.type;
|
2015-04-24 17:13:00 +00:00
|
|
|
this._readOnly(["depth", "frequency"]);
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//extend Effect
|
|
|
|
Tone.extend(Tone.AutoPanner, Tone.Effect);
|
2014-08-24 23:28:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* defaults
|
|
|
|
* @static
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
2014-08-25 14:23:37 +00:00
|
|
|
Tone.AutoPanner.defaults = {
|
|
|
|
"frequency" : 1,
|
2015-02-11 19:37:48 +00:00
|
|
|
"type" : "sine",
|
2015-04-24 17:13:00 +00:00
|
|
|
"depth" : 1
|
2014-08-24 23:28:42 +00:00
|
|
|
};
|
2014-06-21 21:34:31 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-22 05:20:57 +00:00
|
|
|
* Start the effect.
|
|
|
|
* @param {Time} [time=now] When the LFO will start.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.AutoPanner} this
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.AutoPanner.prototype.start = function(time){
|
2014-08-23 21:04:01 +00:00
|
|
|
this._lfo.start(time);
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
2015-06-22 05:20:57 +00:00
|
|
|
/**
|
|
|
|
* Stop the effect.
|
|
|
|
* @param {Time} [time=now] When the LFO will stop.
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.AutoPanner} this
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.AutoPanner.prototype.stop = function(time){
|
2014-08-23 21:04:01 +00:00
|
|
|
this._lfo.stop(time);
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
2014-12-08 16:02:55 +00:00
|
|
|
/**
|
2015-02-27 21:53:10 +00:00
|
|
|
* Sync the panner to the transport.
|
2015-06-14 00:20:36 +00:00
|
|
|
* @param {Time} [delay=0] Delay time before starting the effect after the
|
2015-04-24 17:13:00 +00:00
|
|
|
* Transport has started.
|
2015-06-22 05:20:57 +00:00
|
|
|
* @returns {Tone.AutoPanner} this
|
2014-12-08 16:02:55 +00:00
|
|
|
*/
|
2015-04-24 17:13:00 +00:00
|
|
|
Tone.AutoPanner.prototype.sync = function(delay){
|
|
|
|
this._lfo.sync(delay);
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-12-08 16:02:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2015-02-27 21:53:10 +00:00
|
|
|
* Unsync the panner from the transport
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.AutoPanner} this
|
2014-12-08 16:02:55 +00:00
|
|
|
*/
|
|
|
|
Tone.AutoPanner.prototype.unsync = function(){
|
|
|
|
this._lfo.unsync();
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-12-08 16:02:55 +00:00
|
|
|
};
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2015-06-22 05:20:57 +00:00
|
|
|
* Type of oscillator attached to the AutoFilter.
|
|
|
|
* Possible values: "sine", "square", "triangle", "sawtooth".
|
|
|
|
* @memberOf Tone.AutoFilter#
|
2015-02-10 16:40:27 +00:00
|
|
|
* @type {string}
|
|
|
|
* @name type
|
2014-08-25 13:57:36 +00:00
|
|
|
*/
|
2015-02-10 16:40:27 +00:00
|
|
|
Object.defineProperty(Tone.AutoPanner.prototype, "type", {
|
|
|
|
get : function(){
|
|
|
|
return this._lfo.type;
|
|
|
|
},
|
|
|
|
set : function(type){
|
|
|
|
this._lfo.type = type;
|
|
|
|
}
|
|
|
|
});
|
2014-08-25 13:57:36 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-06-14 00:54:29 +00:00
|
|
|
* @returns {Tone.AutoPanner} this
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
|
|
|
Tone.AutoPanner.prototype.dispose = function(){
|
2014-08-23 19:51:21 +00:00
|
|
|
Tone.Effect.prototype.dispose.call(this);
|
2014-08-23 21:04:01 +00:00
|
|
|
this._lfo.dispose();
|
|
|
|
this._lfo = null;
|
2015-02-10 16:40:27 +00:00
|
|
|
this._panner.dispose();
|
2014-08-23 18:24:20 +00:00
|
|
|
this._panner = null;
|
2015-04-24 17:13:00 +00:00
|
|
|
this._writable(["depth", "frequency"]);
|
2015-02-10 16:40:27 +00:00
|
|
|
this.frequency = null;
|
2015-04-24 17:13:00 +00:00
|
|
|
this.depth = null;
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-06-21 21:34:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return Tone.AutoPanner;
|
|
|
|
});
|