mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
renaming rate to frequency
This commit is contained in:
parent
9be7113fff
commit
51622a1272
2 changed files with 20 additions and 42 deletions
|
@ -9,10 +9,10 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
|
||||||
* @internal
|
* @internal
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {Tone}
|
* @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
|
* @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
|
* the oscillator
|
||||||
|
@ -32,9 +32,8 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
|
||||||
/**
|
/**
|
||||||
* the rate control signal
|
* the rate control signal
|
||||||
* @type {Tone.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
|
* 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
|
* with the time of that tick as the argument
|
||||||
* @type {function(number)}
|
* @type {function(number)}
|
||||||
*/
|
*/
|
||||||
this.tick = this.defaultArg(callback, function(){});
|
this.tick = callback;
|
||||||
|
|
||||||
//setup
|
//setup
|
||||||
this._jsNode.noGC();
|
this._jsNode.noGC();
|
||||||
this.setRate(rate);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Tone.extend(Tone.Clock);
|
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
|
* start the clock
|
||||||
* @param {Tone.Time} time the time when the clock should start
|
* @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.type = "square";
|
||||||
this._oscillator.connect(this._jsNode);
|
this._oscillator.connect(this._jsNode);
|
||||||
//connect it up
|
//connect it up
|
||||||
this._controlSignal.connect(this._oscillator.frequency);
|
this.frequency.connect(this._oscillator.frequency);
|
||||||
this._upTick = false;
|
this._upTick = false;
|
||||||
var startTime = this.toSeconds(time);
|
var startTime = this.toSeconds(time);
|
||||||
this._oscillator.start(startTime);
|
this._oscillator.start(startTime);
|
||||||
|
@ -145,7 +115,9 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
|
||||||
//to account for the double buffering
|
//to account for the double buffering
|
||||||
var tickTime = now + self.samplesToSeconds(i + bufferSize * 2);
|
var tickTime = now + self.samplesToSeconds(i + bufferSize * 2);
|
||||||
return function(){
|
return function(){
|
||||||
self.tick(tickTime);
|
if (self.tick){
|
||||||
|
self.tick(tickTime);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}(), 0); // jshint ignore:line
|
}(), 0); // jshint ignore:line
|
||||||
} else if (sample < 0 && upTick){
|
} else if (sample < 0 && upTick){
|
||||||
|
@ -161,14 +133,15 @@ define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
|
||||||
*/
|
*/
|
||||||
Tone.Clock.prototype.dispose = function(){
|
Tone.Clock.prototype.dispose = function(){
|
||||||
this._jsNode.disconnect();
|
this._jsNode.disconnect();
|
||||||
this._controlSignal.dispose();
|
this.frequency.dispose();
|
||||||
|
this.frequency = null;
|
||||||
if (this._oscillator){
|
if (this._oscillator){
|
||||||
this._oscillator.disconnect();
|
this._oscillator.disconnect();
|
||||||
|
this._oscillator = null;
|
||||||
}
|
}
|
||||||
this._jsNode.onaudioprocess = function(){};
|
this._jsNode.onaudioprocess = function(){};
|
||||||
this._jsNode = null;
|
this._jsNode = null;
|
||||||
this._controlSignal = null;
|
this.tick = null;
|
||||||
this._oscillator = null;
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -597,7 +597,12 @@ function(Tone){
|
||||||
*/
|
*/
|
||||||
Tone.Transport.prototype.setBpm = function(bpm, rampTime){
|
Tone.Transport.prototype.setBpm = function(bpm, rampTime){
|
||||||
var quarterTime = this.notationToSeconds(tatum.toString() + "n", bpm, transportTimeSignature) / 4;
|
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;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -608,7 +613,7 @@ function(Tone){
|
||||||
*/
|
*/
|
||||||
Tone.Transport.prototype.getBpm = function(){
|
Tone.Transport.prototype.getBpm = function(){
|
||||||
//convert the current frequency of the oscillator to bpm
|
//convert the current frequency of the oscillator to bpm
|
||||||
var freq = this._clock.getRate();
|
var freq = this._clock.frequency.value;
|
||||||
return 60 * (freq / tatum);
|
return 60 * (freq / tatum);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -746,7 +751,7 @@ function(Tone){
|
||||||
*/
|
*/
|
||||||
Tone.Transport.prototype.syncSignal = function(signal){
|
Tone.Transport.prototype.syncSignal = function(signal){
|
||||||
//overreaching. fix this.
|
//overreaching. fix this.
|
||||||
signal.sync(this._clock._controlSignal);
|
signal.sync(this._clock.frequency);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue