Clock:
Filter:
Classes | Scheduling > Clocks

Clock : Object

abstract superclass for clocks
Source: Clock.sc

Description

Clock is an abstract class: it only defines an abstract set of methods that all clocks should implement. See its subclasses: SystemClock, TempoClock, AppClock for specific implementations.

Scheduling

A Clock keeps track of time and allows tasks to be scheduled for some time in the future (e.g. using sched, schedAbs or play methods). A task can be any Object. When the time at which a task was scheduled is up, the task is awoken, i.e. its awake method is evaluated. If the value returned by this method is a number, the task is automatically rescheduled for the time equal to its last scheduled time plus the return value (in beats).

Useful Tasks

Objects of different classes may do different things in response to being scheduled on a clock by having own implementation of the awake method. The Object: -awake method that all classes inherit simply calls the same object's next method, forwarding the beats argument as well as the return value, so subclasses may implement either one to equivalent effect, as far as clock scheduling is concerned. 1

Examples of useful objects to be scheduled on clocks:

Scheduling and Threads

Whenever a task is awaken, its awake method is called in the context of the main thread. Just before that, the main thread's logical time is set to the scheduling time of the awaken task, and its clock is set to the scheduling clock. Note however that if the task is a Routine it will then immediately start or resume its Function, setting itself as the current thread.

Class Methods

Inherited class methods

Undocumented class methods

Clock.bars2beats

Clock.beats

Clock.beats =

Clock.beats2bars

Clock.beats2secs(beats)

Clock.nextTimeOnGrid(quant: 1, phase: 0, referenceBeat)

Clock.play(task)

Clock.seconds

Clock.secs2beats(secs)

Clock.timeToNextBeat

Instance Methods

Inherited instance methods

[1] - However, note that the next method is also involved in the concept of streams.