renaming rate to frequency

This commit is contained in:
Yotam Mann 2015-02-10 16:33:18 -05:00
parent 9be7113fff
commit 51622a1272
2 changed files with 20 additions and 42 deletions

View file

@ -9,10 +9,10 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
* @internal
* @constructor
* @extends {Tone}
* @param {number} rate the rate of the callback
* @param {Tone.Frequency} frequency the rate of the callback
* @param {function} callback the callback to be invoked with the time of the audio event
*/
Tone.Clock = function(rate, callback){
Tone.Clock = function(frequency, callback){
/**
* the oscillator
@ -32,9 +32,8 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
/**
* the rate control signal
* @type {Tone.Signal}
* @private
*/
this._controlSignal = new Tone.Signal(1);
this.frequency = new Tone.Signal(frequency);
/**
* whether the tick is on the up or down
@ -48,43 +47,14 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
* with the time of that tick as the argument
* @type {function(number)}
*/
this.tick = this.defaultArg(callback, function(){});
this.tick = callback;
//setup
this._jsNode.noGC();
this.setRate(rate);
};
Tone.extend(Tone.Clock);
/**
* set the rate of the clock
* optionally ramp to the rate over the rampTime
* @param {Tone.Time} rate
* @param {Tone.Time=} rampTime
* @returns {Tone.Clock} `this`
*/
Tone.Clock.prototype.setRate = function(rate, rampTime){
//convert the time to a to frequency
var freqVal = this.secondsToFrequency(this.toSeconds(rate));
if (!rampTime){
this._controlSignal.cancelScheduledValues(0);
this._controlSignal.setValue(freqVal);
} else {
this._controlSignal.exponentialRampToValueNow(freqVal, rampTime);
}
return this;
};
/**
* return the current rate
*
* @return {number}
*/
Tone.Clock.prototype.getRate = function(){
return this._controlSignal.getValue();
};
/**
* start the clock
* @param {Tone.Time} time the time when the clock should start
@ -96,7 +66,7 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
this._oscillator.type = "square";
this._oscillator.connect(this._jsNode);
//connect it up
this._controlSignal.connect(this._oscillator.frequency);
this.frequency.connect(this._oscillator.frequency);
this._upTick = false;
var startTime = this.toSeconds(time);
this._oscillator.start(startTime);
@ -145,7 +115,9 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
//to account for the double buffering
var tickTime = now + self.samplesToSeconds(i + bufferSize * 2);
return function(){
self.tick(tickTime);
if (self.tick){
self.tick(tickTime);
}
};
}(), 0); // jshint ignore:line
} else if (sample < 0 && upTick){
@ -161,14 +133,15 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
*/
Tone.Clock.prototype.dispose = function(){
this._jsNode.disconnect();
this._controlSignal.dispose();
this.frequency.dispose();
this.frequency = null;
if (this._oscillator){
this._oscillator.disconnect();
this._oscillator = null;
}
this._jsNode.onaudioprocess = function(){};
this._jsNode = null;
this._controlSignal = null;
this._oscillator = null;
this.tick = null;
return this;
};

View file

@ -597,7 +597,12 @@ function(Tone){
*/
Tone.Transport.prototype.setBpm = function(bpm, rampTime){
var quarterTime = this.notationToSeconds(tatum.toString() + "n", bpm, transportTimeSignature) / 4;
this._clock.setRate(quarterTime, rampTime);
quarterTime = this.secondsToFrequency(quarterTime);
if (this.isUndef(rampTime)){
this._clock.frequency.value = quarterTime;
} else {
this._clock.frequency.rampTo(quarterTime, rampTime);
}
return this;
};
@ -608,7 +613,7 @@ function(Tone){
*/
Tone.Transport.prototype.getBpm = function(){
//convert the current frequency of the oscillator to bpm
var freq = this._clock.getRate();
var freq = this._clock.frequency.value;
return 60 * (freq / tatum);
};
@ -746,7 +751,7 @@ function(Tone){
*/
Tone.Transport.prototype.syncSignal = function(signal){
//overreaching. fix this.
signal.sync(this._clock._controlSignal);
signal.sync(this._clock.frequency);
return this;
};