clockblocks.moment.Moment

class clockblocks.moment.Moment(value: float, units: str | DurationUnits = 'beats', relative: bool = False)[source]

Bases: object

Represents a point on a clock’s timeline. Can be either in beats or in time (as defined by units), and can be either relative (measured from a clock’s current beat/time) or absolute (measured from the clock’s start).

User code should generally construct via one of the classmethods:

Moment.at_beat(8) # absolute: beat 8 of the clock Moment.at_time(8) # absolute: 8 seconds (in the clock’s time) since it started Moment.after_beats(2) # relative: 2 beats from now Moment.after_time(0.5) # relative: 0.5 seconds from now

resolve(clock) returns an absolute Moment on that clock (a no-op if already absolute). The final scheduling process works only with absolute Moments, which are either pinned to a specific beat or a specific time in the clock’s timeline. Relative moments or MetricPhaseTargets are resolved at scheduling time into absolute moments.

Parameters:
  • value – how far along the timeline this moment sits, in the given units

  • units – whether value counts beats or time (“beats”/”time”, or a DurationUnits)

  • relative – if True, value is an offset from the clock’s current position rather than a point measured from the clock’s start

Methods

after_beats(beats)

A relative moment, the given number of beats from a clock's current beat.

after_time(time)

A relative moment, the given amount of time from a clock's current time.

at_beat(beat)

An absolute moment at the given beat of a clock.

at_time(time)

An absolute moment at the given time on a clock.

beat_on(clock)

This (absolute) moment expressed as a beat of clock.

resolve(clock)

Pin this moment to an absolute one on the given clock.

scheduler_time(clock)

The scheduler-time at which this (absolute) moment occurs on clock.

classmethod at_beat(beat: float) → Moment[source]

An absolute moment at the given beat of a clock.

Parameters:

beat – beat, counted from the clock’s start

classmethod at_time(time: float) → Moment[source]

An absolute moment at the given time on a clock.

Parameters:

time – time in seconds, counted from the clock’s start

classmethod after_beats(beats: float) → Moment[source]

A relative moment, the given number of beats from a clock’s current beat.

Parameters:

beats – how many beats from now

classmethod after_time(time: float) → Moment[source]

A relative moment, the given amount of time from a clock’s current time.

Parameters:

time – how many seconds from now

resolve(clock: Clock) → Moment[source]

Pin this moment to an absolute one on the given clock. A no-op if it is already absolute; a relative moment is measured out from the clock’s current beat or time.

Parameters:

clock – the clock whose timeline the result is measured against

Returns:

an absolute Moment on that clock

beat_on(clock: Clock) → float[source]

This (absolute) moment expressed as a beat of clock.

scheduler_time(clock: Clock) → float[source]

The scheduler-time at which this (absolute) moment occurs on clock.