clockblocks.utilities

Module containing the free functions that make up clockblocks’ most convenient interface. Rather than calling methods on a particular clock, these operate on whichever clock is running the current thread: most importantly wait() and fork(), along with getters and setters for that clock’s tempo (set_tempo(), set_tempo_target(), apply_tempo_envelope(), and their rate/beat-length counterparts).

Functions

apply_beat_length_function(function[, ...])

Drive the current clock's beat length (in seconds per beat) by following a function of beats/time.

apply_rate_function(function[, ...])

Drive the current clock's rate (in beats per second) by following a function of beats/time.

apply_tempo_envelope(envelope[, truncate, loop])

Append a ready-made TempoEnvelope onto the current clock's tempo curve.

apply_tempo_function(function[, ...])

Drive the current clock's tempo (in beats per minute) by following a function of beats/time.

current_clock()

Get the Clock active on the current thread, or None if none is active.

fork(forked_function[, args, kwargs, name, ...])

Run forked_function on a new child clock of the currently active clock, so it proceeds in parallel while staying coordinated under the same musical time.

get_beat()

Return how many beats have passed on the currently active clock (see beat).

get_beat_length()

Return the current beat length (in seconds per beat) of the currently active clock (see beat_length).

get_rate()

Return the current rate (in beats per second) of the currently active clock (see rate).

get_tempo()

Return the current tempo (in beats per minute) of the currently active clock (see tempo).

get_time()

Return how much time has passed on the currently active clock (see time) — in seconds if it is the master clock, or parent clock beats if it is a forked child clock.

meaningfully_greater_than(a, b, *[, ...])

True if a is meaningfully greater than b (mirror of meaningfully_less_than()).

meaningfully_less_than(a, b, *[, rel_tol, ...])

True if a is meaningfully less than b — i.e. a < b and not merely by rounding noise (see near_equal()).

near_equal(a, b, *[, rel_tol, abs_tol])

True if a and b are equal to within floating-point reconstruction noise.

set_beat_length(beat_length)

Immediately set the beat length of the current clock (see beat_length).

set_beat_length_target(beat_length_target, when)

Smoothly change the current clock's beat length to beat_length_target (in seconds per beat), arriving at when.

set_beat_length_targets(beat_length_targets, ...)

Set several beat-length targets at once, building a multi-segment tempo curve on the current clock.

set_rate(rate)

Immediately set the rate of the current clock (see rate).

set_rate_target(rate_target, when[, ...])

Smoothly change the current clock's rate to rate_target (in beats per second), arriving at when.

set_rate_targets(rate_targets, whens[, ...])

Set several rate targets at once, building a multi-segment tempo curve on the current clock.

set_tempo(tempo)

Immediately set the tempo of the current clock (see tempo).

set_tempo_target(tempo_target, when[, ...])

Smoothly change the current clock's tempo to tempo_target (in beats per minute), arriving at when.

set_tempo_targets(tempo_targets, whens[, ...])

Set several tempo targets at once, building a multi-segment tempo curve on the current clock.

stop_tempo_loop_or_function()

Stop following any function or looping envelope previously started on the current clock's tempo (via apply_tempo_function()/apply_rate_function()/apply_beat_length_function() or a looping apply_tempo_envelope()).

terminate_forked_children()

Kill the child clocks of the currently active clock, returning once they have finished unwinding (see terminate_forked_children()).

wait(dt[, units])

Block the clock currently active on this thread for dt beats (or seconds, if units="time"), yielding to the scheduler.

wait_for_children_to_finish()

Block on the currently active clock until its child clocks have finished (see wait_for_children_to_finish()).

wait_for_clock_to_finish(clock)

Block on the currently active clock until clock has finished (see wait_for_clock_to_finish()).

wait_forever()

Block forever on the currently active clock (see wait_forever()) — usually to keep the main script alive while child clocks do the work.

wait_until(when[, units])

Block the clock currently active on this thread until the absolute beat (or time, if units="time") given by when.