Skip to content
Tone.js

TickSource

internal class ↳ extends ToneWithContext<TickSourceOptions>

Uses TickSignal to track elapsed ticks with complex automation curves.

new TickSource(frequency?: number)

Parameters

  • frequency number optional

    The initial frequency that the signal ticks at

new TickSource(options?: Partial<TickSourceOptions>)

Parameters

read-only

frequency: TickSignal<TypeName>

The frequency the callback function should be invoked.

read-only

name: string

The name of the class

Default: "TickSource"

seconds: number

The time since ticks=0 that the TickSource has been running. Accounts for tempo curves

read-only

Returns the playback state of the source, either “started”, “stopped” or “paused”.

ticks: number

The number of times the callback was invoked. Starts counting at 0 and increments after the callback was invoked. Returns -1 when stopped.

cancel(time: Time): this

Cancel start/stop/pause and setTickAtTime events scheduled after the given time.

Parameters

  • time Time

    When to clear the events after

Returns this

dispose(): this

Clean up

Returns this

forEachTickBetween(startTime: number, endTime: number, callback: (when: number, ticks: number) => void): this

Invoke the callback event at all scheduled ticks between the start time and the end time

Parameters

  • startTime number

    The beginning of the search range

  • endTime number

    The end of the search range

  • callback (when: number, ticks: number) => void

    The callback to invoke with each tick

Returns this

getSecondsAtTime(time: Time): number

Return the elapsed seconds at the given time.

Parameters

  • time Time

    When to get the elapsed seconds

Returns number The number of elapsed seconds

getStateAtTime(time: Time): PlaybackState

Returns the scheduled state at the given time.

Parameters

  • time Time

    The time to query.

Returns PlaybackState

getTicksAtTime(time?: Time): number

Get the elapsed ticks at the given time

Parameters

  • time Time optional

    When to get the tick value

Returns number The number of ticks

getTimeOfTick(tick: number, before?: number): number

Get the time of the given tick. The second argument is when to test before. Since ticks can be set (with setTicksAtTime) there may be multiple times for a given tick value.

Parameters

  • tick number

    The tick number.

  • before number optional

    When to measure the tick value from.

Returns number The time of the tick

pause(time: Time): this

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

Parameters

  • time Time

    The time when the clock should stop.

Returns this

setTicksAtTime(ticks: number, time: Time): this

Set the clock’s ticks at the given time.

Parameters

  • ticks number

    The tick value to set

  • time Time

    When to set the tick value

Returns this

start(time: Time, offset?: number): this

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

Parameters

  • time Time

    The time the clock should start

  • offset number optional

    The number of ticks to start the source at

Returns this

stop(time: Time): this

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

Parameters

  • time Time

    The time when the clock should stop.

Returns this

static

getDefaults(): TickSourceOptions

Returns all of the default options belonging to the class.

Returns TickSourceOptions