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”.

</>

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.

</>

.setTicksAtTime ( )

#
ticks

The tick value to set

type: Ticks
time

When to set the tick value

type: Time
↪ returns Tone.Clock

this

Set the clock’s ticks at the given time.

</>

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

.getSecondsAtTime ( )

#
time

When to get the elapsed seconds

type: Time
↪ returns Seconds

The number of elapsed seconds

Return the elapsed seconds at the given time.

</>

.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"
</>

.getTicksAtTime ( )

#
time

When to get the tick value

type: Time
↪ returns Ticks

The tick value at the given time.

Get the clock’s ticks at the given time.

</>

.nextTickTime ( )

#
ticks

The tick number.

type: Ticks
before
type: Time
↪ returns Tone.Clock

this

Get the time of the next tick

</>
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

.once ( )

#
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 which is only invoked once

</>
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.

</>
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.

</>
docs generated Sep 15 2019