Tone.Clock

↳ EXTENDS Tone

A 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 (
callback
,
frequency
)
callback

The callback to be invoked with the time of the audio event

type: function
frequency

The rate of the callback

DEFAULTS

{
callback : Tone.noOp ,
frequency : 1 ,
lookAhead : auto
}

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.

</>

.callback

↝ function #

The callback function to invoke at the scheduled tick.

</>
∿

.frequency

↝ BPM #

The rate the callback function should be invoked.

</>

.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

.dispose ( )

#
↪ returns Tone.Clock

this

Clean up

</>

.getStateAtTime ( )

#
time

The time to query.

type: Time
↪ returns String

The name of the state input in setStateAtTime.

Returns the scheduled state at the given time.

EXAMPLE

clock.start("+0.1");
clock.getStateAtTime("+0.1"); //returns "started"
</>

.pause ( )

#
time

The time when the clock should stop.

type: Time
default: now
↪ returns Tone.Clock

this

Pause the clock. Pausing does not reset the tick counter.

</>

.start ( )

#
time

The time the clock should start

type: Time
offset

Where the tick counter starts counting from.

type: Ticks
optional
↪ returns Tone.Clock

this

Start the clock at the given time. Optionally pass in an offset of where to start the tick counter from.

</>

.stop ( )

#
time

The time when the clock should stop.

type: Time
default: now
↪ returns Tone.Clock

this

Stop the clock. Stopping the clock resets the tick counter to 0.

EXAMPLE

clock.stop();
</>
docs generated Sep 15 2019