2014-04-06 20:51:30 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/source/Oscillator", "Tone/signal/Scale"], function(Tone){
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* Low Frequency Oscillator
|
|
|
|
*
|
|
|
|
* LFO produces an output signal which can be attached to an AudioParam
|
|
|
|
* for constant control over that parameter
|
|
|
|
* the LFO can also be synced to the transport
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @extends {Tone}
|
|
|
|
* @param {number} rate
|
|
|
|
* @param {number=} outputMin
|
|
|
|
* @param {number=} outputMax
|
|
|
|
*/
|
2014-04-06 00:47:59 +00:00
|
|
|
Tone.LFO = function(rate, outputMin, outputMax){
|
2014-06-21 19:53:27 +00:00
|
|
|
/** @type {GainNode} */
|
|
|
|
this.input = this.context.createGain();
|
2014-06-17 17:01:06 +00:00
|
|
|
/** @type {Tone.Oscillator} */
|
2014-06-21 21:34:31 +00:00
|
|
|
this.oscillator = new Tone.Oscillator(this.defaultArg(rate, 1), "sine");
|
2014-06-22 02:56:51 +00:00
|
|
|
/**
|
|
|
|
@type {Tone.Scale}
|
|
|
|
@private
|
|
|
|
*/
|
2014-06-21 19:53:27 +00:00
|
|
|
this._scaler = new Tone.Scale(this.defaultArg(outputMin, 0), this.defaultArg(outputMax, 1));
|
|
|
|
/** alias for the output */
|
|
|
|
this.output = this._scaler;
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
//connect it up
|
2014-06-21 19:53:27 +00:00
|
|
|
this.chain(this.oscillator, this.output);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-15 21:38:07 +00:00
|
|
|
Tone.extend(Tone.LFO);
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* start the LFO
|
|
|
|
* @param {Tone.Time} time
|
|
|
|
*/
|
2014-04-06 00:47:59 +00:00
|
|
|
Tone.LFO.prototype.start = function(time){
|
|
|
|
this.oscillator.start(time);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* stop the LFO
|
|
|
|
* @param {Tone.Time} time
|
|
|
|
*/
|
2014-04-06 00:47:59 +00:00
|
|
|
Tone.LFO.prototype.stop = function(time){
|
|
|
|
this.oscillator.stop(time);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* Sync the start/stop/pause to the transport
|
|
|
|
* and the frequency to the bpm of the transport
|
|
|
|
*/
|
2014-06-15 21:38:07 +00:00
|
|
|
Tone.LFO.prototype.sync = function(){
|
|
|
|
this.oscillator.sync();
|
2014-06-25 16:47:47 +00:00
|
|
|
// Tone.Transport.syncSignal(this.oscillator.frequency);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unsync the LFO from transport control
|
|
|
|
*/
|
|
|
|
Tone.LFO.prototype.unsync = function(){
|
|
|
|
this.oscillator.unsync();
|
2014-06-25 16:47:47 +00:00
|
|
|
// this.oscillator.frequency.unsync();
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-06-15 21:38:07 +00:00
|
|
|
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* set the frequency
|
|
|
|
* @param {number} rate
|
|
|
|
*/
|
2014-04-07 00:12:40 +00:00
|
|
|
Tone.LFO.prototype.setFrequency = function(rate){
|
2014-04-06 00:47:59 +00:00
|
|
|
this.oscillator.setFrequency(rate);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* set the minimum output of the LFO
|
|
|
|
* @param {number} min
|
|
|
|
*/
|
2014-04-06 00:47:59 +00:00
|
|
|
Tone.LFO.prototype.setMin = function(min){
|
2014-06-21 19:53:27 +00:00
|
|
|
this._scaler.setOutputMin(min);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-04-05 00:24:19 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* set the maximum output of the LFO
|
|
|
|
* @param {number} min
|
|
|
|
*/
|
2014-04-06 00:47:59 +00:00
|
|
|
Tone.LFO.prototype.setMax = function(max){
|
2014-06-21 19:53:27 +00:00
|
|
|
this._scaler.setOuputMax(max);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-04-06 00:47:59 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* set the waveform of the LFO
|
|
|
|
* @param {string} type
|
|
|
|
*/
|
2014-04-06 00:47:59 +00:00
|
|
|
Tone.LFO.prototype.setType = function(type){
|
|
|
|
this.oscillator.setType(type);
|
2014-06-17 17:01:06 +00:00
|
|
|
};
|
2014-04-06 00:47:59 +00:00
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* pointer to the parent's connect method
|
|
|
|
* @private
|
|
|
|
*/
|
2014-04-11 23:17:01 +00:00
|
|
|
Tone.LFO.prototype._connect = Tone.prototype.connect;
|
|
|
|
|
2014-06-17 17:01:06 +00:00
|
|
|
/**
|
|
|
|
* override the connect method so that it 0's out the value
|
|
|
|
* if attached to an AudioParam
|
|
|
|
*
|
2014-06-21 19:53:27 +00:00
|
|
|
* @borrows Tone.Signal.connect as Tone.LFO.connect
|
2014-06-17 17:01:06 +00:00
|
|
|
*/
|
2014-06-21 19:53:27 +00:00
|
|
|
Tone.LFO.prototype.connect = Tone.Signal.prototype.connect;
|
2014-04-11 23:17:01 +00:00
|
|
|
|
2014-06-20 05:23:35 +00:00
|
|
|
/**
|
|
|
|
* disconnect and dispose
|
|
|
|
*/
|
|
|
|
Tone.LFO.prototype.dispose = function(){
|
|
|
|
this.oscillator.dispose();
|
|
|
|
this.output.disconnect();
|
2014-06-21 19:53:27 +00:00
|
|
|
this._scaler.dispose();
|
2014-06-20 05:23:35 +00:00
|
|
|
this.oscillator = null;
|
|
|
|
this.output = null;
|
2014-06-21 19:53:27 +00:00
|
|
|
this._scaler = null;
|
2014-06-20 05:23:35 +00:00
|
|
|
};
|
|
|
|
|
2014-04-06 00:47:59 +00:00
|
|
|
return Tone.LFO;
|
|
|
|
});
|