TickSource
internal class ↳ extends ToneWithContext<TickSourceOptions>
Uses TickSignal to track elapsed ticks with complex automation curves.
Constructor
Section titled “Constructor”new TickSource(frequency?: number)Parameters
-
frequency
numberoptionalThe initial frequency that the signal ticks at
new TickSource(options?: Partial<TickSourceOptions>)Parameters
- options
Partial<TickSourceOptions>optional
Properties
Section titled “Properties”frequency
Section titled “frequency”read-only
frequency: TickSignal<TypeName>The frequency the callback function should be invoked.
seconds
Section titled “seconds”seconds: numberThe time since ticks=0 that the TickSource has been running. Accounts for tempo curves
read-only
state: PlaybackStateReturns the playback state of the source, either “started”, “stopped” or “paused”.
ticks: numberThe number of times the callback was invoked. Starts counting at 0 and increments after the callback was invoked. Returns -1 when stopped.
Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(time: Time): thisCancel start/stop/pause and setTickAtTime events scheduled after the given time.
Parameters
-
time
TimeWhen to clear the events after
Returns this
forEachTickBetween()
Section titled “forEachTickBetween()”forEachTickBetween(startTime: number, endTime: number, callback: (when: number, ticks: number) => void): thisInvoke the callback event at all scheduled ticks between the start time and the end time
Parameters
-
startTime
numberThe beginning of the search range
-
endTime
numberThe end of the search range
-
callback
(when: number, ticks: number) => voidThe callback to invoke with each tick
Returns this
getSecondsAtTime()
Section titled “getSecondsAtTime()”getSecondsAtTime(time: Time): numberReturn the elapsed seconds at the given time.
Parameters
-
time
TimeWhen to get the elapsed seconds
Returns number The number of elapsed seconds
getStateAtTime()
Section titled “getStateAtTime()”getStateAtTime(time: Time): PlaybackStateReturns the scheduled state at the given time.
Parameters
-
time
TimeThe time to query.
Returns PlaybackState
getTicksAtTime()
Section titled “getTicksAtTime()”getTicksAtTime(time?: Time): numberGet the elapsed ticks at the given time
Parameters
-
time
TimeoptionalWhen to get the tick value
Returns number The number of ticks
getTimeOfTick()
Section titled “getTimeOfTick()”getTimeOfTick(tick: number, before?: number): numberGet 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
numberThe tick number.
-
before
numberoptionalWhen to measure the tick value from.
Returns number The time of the tick
pause()
Section titled “pause()”pause(time: Time): thisPause the clock. Pausing does not reset the tick counter.
Parameters
-
time
TimeThe time when the clock should stop.
Returns this
setTicksAtTime()
Section titled “setTicksAtTime()”setTicksAtTime(ticks: number, time: Time): thisSet the clock’s ticks at the given time.
Parameters
-
ticks
numberThe tick value to set
-
time
TimeWhen to set the tick value
Returns this
start()
Section titled “start()”start(time: Time, offset?: number): thisStart the clock at the given time. Optionally pass in an offset of where to start the tick counter from.
Parameters
-
time
TimeThe time the clock should start
-
offset
numberoptionalThe number of ticks to start the source at
Returns this
stop()
Section titled “stop()”stop(time: Time): thisStop the clock. Stopping the clock resets the tick counter to 0.
Parameters
-
time
TimeThe time when the clock should stop.
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): TickSourceOptionsReturns all of the default options belonging to the class.
Returns TickSourceOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString()