afterglow.rhythm

Functions to help work with musical time, evolved from the original version in Overtone.

beat-ms

(beat-ms b bpm)

Convert b beats to milliseconds at the given bpm.

enhanced-phase

(enhanced-phase marker phase desired-ratio)

Calculate a phase with respect to multiples or fractions of a marker (beat, bar, or phrase), given the phase with respect to that marker, the number of that marker, and the desired ratio. A desired-ratio of 1 returns the phase unchanged; 1/2 oscillates twice as fast, 3/4 oscillates 4 times every three markers…

IMetronome

protocol

A time-keeping tool for music-related systems.

members

metro-add-bpm-watch

(metro-add-bpm-watch metro key f)

Register a function to be called whenever the metronome’s BPM changes. The key and function arguments are the same as found in clojure.core/add-watch, and in fact are passed on to it.

metro-adjust

(metro-adjust metro ms)

Adds a number of milliseconds to the start time of the metronome.

metro-bar

(metro-bar metro)(metro-bar metro bar)

Returns the current bar number or the timestamp (in milliseconds) of the given bar.

metro-bar-phase

(metro-bar-phase metro)(metro-bar-phase metro phase)

Returns the distance traveled into the current bar as a phase number ranging from [0.0, 1.0), or adjusts the phase to match the one supplied.

metro-bar-start

(metro-bar-start metro start-bar)

Restarts the metronome at start-bar, keeping the beat phase unchanged in case it is being synced to an external source.

metro-beat

(metro-beat metro)(metro-beat metro beat)

Returns the current beat number or the timestamp (in milliseconds) of the given beat.

metro-beat-phase

(metro-beat-phase metro)(metro-beat-phase metro phase)

Returns the distance traveled into the current beat as a phase number ranging from [0.0, 1.0), or adjusts the phase to match the one supplied.

metro-bpb

(metro-bpb metro)(metro-bpb metro new-bpb)

Get the current beats per bar or change it to new-bpb

metro-bpm

(metro-bpm metro)(metro-bpm metro new-bpm)

Get the current bpm or change the bpm to new-bpm.

metro-bpp

(metro-bpp metro)(metro-bpp metro new-bpp)

Get the current bars per phrase, or change it to new-bpp

metro-ding

(metro-ding metro)

Returns the duration of one phrase in milliseconds.

metro-marker

(metro-marker metro)

Returns the current time as "phrase.bar.beat"

metro-phrase

(metro-phrase metro)(metro-phrase metro phrase)

Returns the current phrase number or the timestamp (in milliseconds) of the given phrase.

metro-phrase-phase

(metro-phrase-phase metro)(metro-phrase-phase metro phase)

Returns the distance traveled into the current phrase as a phase number ranging from [0.0, 1.0), or adjusts the phase to match the one supplied.

metro-phrase-start

(metro-phrase-start metro start-phrase)

Restarts the metronome at start-phrase, keeping the beat phase unchanged in case it is being synced to an external source.

metro-remove-bpm-watch

(metro-remove-bpm-watch metro key)

Stop calling the function which was registered with the specified key.

metro-snapshot

(metro-snapshot metro)(metro-snapshot metro instant)

Take a snapshot of the current beat, bar, phrase, and phase state. If instant is supplied, calculates a snapshot for the corresponding time rather than the current time.

metro-start

(metro-start metro)(metro-start metro start-beat)

Returns the start time of the metronome. Also restarts the metronome at start-beat if given.

metro-tick

(metro-tick metro)

Returns the duration of one beat in milleseconds.

metro-tock

(metro-tock metro)

Returns the duration of one bar in milliseconds.

ISnapshot

protocol

A snapshot to support a series of beat and phase calculations with respect to a given instant in time. Used by Afterglow so that all phase computations performed when updating a frame of DMX data have a consistent sense of when they are being run, to avoid, for example, half the lights acting as if they are at the very end of a beat while the rest are at the beginning of the next beat, due to a fluke in timing as their evaluation occurs over time. Snapshots also extend the notions of beat phase to enable oscillators with frequencies that are fractions or multiples of a beat.

members

snapshot-bar-phase

(snapshot-bar-phase snapshot)(snapshot-bar-phase snapshot bar-ratio)

Determine the metronome’s phase at the time of the snapshot with respect to a multiple or fraction of bars. Calling this with a bar-ratio of 1 (the default if not provided) is equivalent to metro-bar-phase, calling with a bar-ratio equal to metro-bpp is equivalent to metro-phrase-phase, 1/2 oscillates twice as fast as 1, 3/4 oscillates 4 times every three bars… Phases range from [0-1).

snapshot-bar-within-phrase

(snapshot-bar-within-phrase snapshot)

Returns the bar number within the snapshot relative to the start of the phrase: Ranges from 1 to the value returned by metro-bpp for the metronome.

snapshot-beat-phase

(snapshot-beat-phase snapshot)(snapshot-beat-phase snapshot beat-ratio)

Determine the metronome’s phase at the time of the snapshot with respect to a multiple or fraction of beats. Calling this with a beat-ratio of 1 (the default if not provided) is equivalent to metro-beat-phase, calling with a beat-ratio equal to metro-bpb is equivalent to metro-bar-phase, 1/2 oscillates twice as fast as 1, 3/4 oscillates 4 times every three beats… Phases range from [0-1).

snapshot-beat-within-bar

(snapshot-beat-within-bar snapshot)

Returns the beat number within the snapshot relative to the start of the bar: The down beat is 1, and the range goes up to the value returned by metro-bpb for the metronome.

snapshot-beat-within-phrase

(snapshot-beat-within-phrase snapshot)

Returns the beat number within the snapshot relative to the start of the phrase: The first beat is 1, and the range goes up to the values returned by metro-bpb times metro-bpp for the metronome.

snapshot-down-beat?

(snapshot-down-beat? snapshot)

True if the current beat at the time of the snapshot was the first beat in its bar.

snapshot-marker

(snapshot-marker snapshot)

Returns the time represented by the snapshot as "phrase.bar.beat

snapshot-phrase-phase

(snapshot-phrase-phase snapshot)(snapshot-phrase-phase snapshot phrase-ratio)

Determine the metronome’s phase at the time of the snapshot with respect to a multiple or fraction of phrases. Calling this with a phrase-ratio of 1 (the default if not provided) is equivalent to metro-phrase-phase, 1/2 oscillates twice as fast as 1, 3/4 oscillates 4 times every three bars… Phases range from [0-1).

snapshot-phrase-start?

(snapshot-phrase-start? snapshot)

True if the current beat at the time of the snapshot wass the first beat in its phrase.

marker-number

(marker-number instant start interval)

Helper function to calculate the beat, bar, or phrase number in effect at a given instant (in milliseconds), given a starting point (start, also in milliseconds), and the interval (also in milliseconds) between beats, bars, or phrases.

marker-phase

(marker-phase instant start interval)

Helper function to calculate the beat, bar, or phrase phase at a given instant (in millseconds), given a start time (also in milliseconds) and interval (in milliseconds) between beats, bars, or phrases.

metronome

(metronome bpm & {:keys [bpb bpp], :or {bpb 4, bpp 8}})

A metronome is a beat management tool. Tell it what BPM you want, and it will compute beat, bar, and phrase timestamps accordingly. See the IMetronome interface for full details.

normalize-phase

(normalize-phase phase)

Makes sure a phase value is in the range [0.0,1.0)