Musicology·A Field Guide

§ I.5 · The CLI Workshop · No. XIII

Euclidean Rhythm
Generator.

After Toussaint 2005 · cf. Bjorklund 2003

Distributes k pulses as evenly as possible across n steps using Bjorklund's algorithm — the same recursion that drives Euclid's GCD. The output recovers the rumba clave (3:8), the tresillo (3:8 rotation), the Cuban cinquillo (5:8), the Bulgarian aksak 7:12, the West African 7:16. Output as binary string, MIDI events, or LilyPond rhythm.

Why a command line

Composers and performers reach for Euclidean patterns constantly — the standard 3:2 son clave, the 5:8 tresillo, the asymmetric African timeline 7:12. Bjorklund's algorithm produces all of them in roughly thirty lines of code, and the CLI lets you script entire pattern banks in seconds. Pipe the binary form into a sequencer, the MIDI form into a DAW, the LilyPond form into a score.

Invocation

$ node 04-euclid.js 3 8                   # 3 pulses in 8 steps
$ node 04-euclid.js 5 16 --midi > pattern.mid
$ node 04-euclid.js 7 12 --format=lilypond
$ node 04-euclid.js 5 8 --rotate=2          # rotate the cycle

Sample output

x . x . x . x .          # default — euclid(3,8) is x..x..x.
                         # shown above as euclid(4,8) for clarity

x . . x . . x . . x . . x . . .   # euclid(5,16)

Scope

arguments    k n           positional, both positive integers, k ≤ n

flags        --format=binary        x . pattern (default)
             --format=midi          MIDI note_on/off events on a single pitch
             --format=lilypond      LilyPond rhythm notation
             --pitch=N              MIDI note for --format=midi (default 60)
             --bpm=N                tempo for --format=midi (default 120)
             --rotate=R             rotate the cycle by R steps

output       a single line for --format=binary; a sequence of MIDI events
             for --format=midi; a LilyPond rhythm string otherwise.

References

Source

cli/04-euclid.js ↗ raw
loading source…
← Back to the CLI workshop