Tone.Clock

↳ EXTENDS Tone.Emitter

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
}

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

.callback

function #

The callback function to invoke at the scheduled tick.

</>

.frequency

BPM #

The rate the callback function should be invoked.

</>

.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

</>

.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
optional
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();
</>

.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"
</>
inherited from Tone.Emitter

.emit ( )

#
event

The name of the event.

type: String
args...

The arguments to pass to the functions listening.

type: *
↪ returns Tone.Emitter

this

Invoke all of the callbacks bound to the event with any arguments passed in.

</>
inherited from Tone.Emitter

.on ( )

#
event

The name of the event to listen for.

type: String
callback

The callback to invoke when the event is emitted

↪ returns Tone.Emitter

this

Bind a callback to a specific event.

</>
inherited from Tone.Emitter

.off ( )

#
event

The event to stop listening to.

type: String
callback

The callback which was bound to the event with Tone.Emitter.on. If no callback is given, all callbacks events are removed.

optional
↪ returns Tone.Emitter

this

Remove the event listener.

</>
docs generated Sep 15 2019