Tone.Clock
↳ EXTENDS ToneA sample accurate clock which provides a callback at the given rate. While the callback is not sample-accurate (it is still susceptible to loose JS timing), the time passed in as the argument to the callback is precise. For most applications, it is better to use Tone.Transport instead of the Clock by itself since you can synchronize multiple callbacks.
CONSTRUCTOR
new Tone.Clock (The callback to be invoked with the time of the audio event
The rate of the callback
DEFAULTS
EXAMPLE
//the callback will be invoked approximately once a second
//and will print the time exactly once a second apart.
var clock = new Tone.Clock(function(time){
console.log(time);
}, 1);Members
._lookAhead
↝ Number or String #The time which the clock will schedule events in advance of the current time. Scheduling notes in advance improves performance and decreases the chance for clicks caused by scheduling events in the past. If set to “auto”, this value will be automatically computed based on the rate of requestAnimationFrame (0.016 seconds). Larger values will yeild better performance, but at the cost of latency. Values less than 0.016 are not recommended.
.lookAhead
↝ Number or String #The time which the clock will schedule events in advance of the current time. Scheduling notes in advance improves performance and decreases the chance for clicks caused by scheduling events in the past. If set to “auto”, this value will be automatically computed based on the rate of requestAnimationFrame (0.016 seconds). Larger values will yeild better performance, but at the cost of latency. Values less than 0.016 are not recommended.
.state
↝ Tone.State READONLY #Returns the playback state of the source, either “started”, “stopped” or “paused”.
.ticks
↝ Ticks READONLY #The number of times the callback was invoked. Starts counting at 0 and increments after the callback was invoked.
Methods
.getStateAtTime ( )
#Returns the scheduled state at the given time.
EXAMPLE
clock.start("+0.1");
clock.getStateAtTime("+0.1"); //returns "started".pause ( )
#The time when the clock should stop.
this
Pause the clock. Pausing does not reset the tick counter.
.start ( )
#The time the clock should start
Where the tick counter starts counting from.
this
Start the clock at the given time. Optionally pass in an offset of where to start the tick counter from.
.stop ( )
#The time when the clock should stop.
this
Stop the clock. Stopping the clock resets the tick counter to 0.
EXAMPLE
clock.stop();