Sam Doshi personal ramblings

Euclidean rhythms on the Monome Teletype

Earlier this year I did some work on a Euclidean rhythm operator for the Monome Teletype. Here is the pull request1, the beta firmware, and there is also a thread to discuss it on lines.

Euclidean rhythms

Euclidean rhythms were first described by Godfried Toussaint in his 2005 paper “The Euclidean Algorithm Generates Traditional Musical Rhythms”2. From the abstract:

The Euclidean algorithm (which comes down to us from Euclid’s Elements) computes the greatest common divisor of two given integers. It is shown here that the structure of the Euclidean algorithm may be used to generate, very efficiently, a large family of rhythms used as timelines (ostinatos), in sub-Saharan African music in particular, and world music in general. These rhythms, here dubbed Euclidean rhythms, have the property that their onset patterns are distributed as evenly as possible.

Once you’re more familiar with how they work, it’s well worth having a look through the paper. There is plenty of interesting information in there (along with all the maths).

In essence a Euclidean rhythm evenly spreads out a numbers of beats (or fill), along a repeating sequence of a given length. Thus, the Euclidean rhythm fill=4, length=16, is x...x...x...x... (a.k.a. four on the floor at 16th beats). Given that the rhythm repeats, this is more efficiently given as fill=1, length=4: x.... More interesting examples are in the paper.

On the Teletype

On the Teletype, Euclidean rhythms are implemented with a new operator, ER as follows:

ER fill length step

The operator either returns a 0 (i.e. no beat) or a 1 (a beat) for a given Euclidean rhythm, where fill is the number of played beats and length is the length of a single sequence (as previously described). The 3rd parameter, step, is the value of the rhythm at a given step. Particular care must be given as step is 0-based like many other operations on the Teletype, i.e. the first step is 0, and the last step in a sequence that has length 16 is 15!

Both fill and length accept values between 1 and 32 inclusive3, where filllength. Step may be any number—it is modulo (or wrapped) with the length, so that it is always in bounds. Any invalid input results in the operator returning a 0.

Some simple examples

Let’s look at the example of fill=4, length=16, i.e. x...x...x...x.... (These are best entered in LIVE mode.)

  • ER 4 16 0 returns a 1 (remember 0 is the first step)
  • ER 4 16 1 returns a 0
  • ER 4 16 2 returns a 0
  • ER 4 16 3 returns a 0
  • ER 4 16 4 returns a 1
  • ER 4 16 -1 returns a 0 (negative indices can be useful as we’ll see…)
  • ER 4 16 -4 returns a 1

Let’s create a simple script that outputs a four on the floor rhythm by using the ER operator. Enter the following scripts as I and SCRIPT 1, and then supply a 16th note trigger to input 1.

I:

T 0

SCRIPT 1:

IF ER 4 16 T : TR.PULSE A
T ADD 1 T

We’re using T to hold which step we’re on. We can update SCRIPT 1 to add a second output:

SCRIPT 1:

IF ER 4 16 T : TR.PULSE A
IF ER 6 16 T : TR.PULSE B
T ADD 1 T

Onset (or rotation or offset)

You might have noticed while playing with the above example that certain combinations of rhythms can’t be achieved as things stand, for example:

A: x...x...x...x...
B: ..x...x...x...x.

In order to create this rhythm we need to rotate one rhythm against the other. This is sometimes call the offset or the onset. In fact in our example rhythm B is the same A, but rotated 2 steps forwards (or backwards). Let’s modify SCRIPT 1 again:

SCRIPT 1:

IF ER 4 16 T : TR.PULSE A
Y SUB T 2
IF ER 4 16 Y : TR.PULSE B
T ADD 1 T

We’ve had to introduce another variable Y as we can’t fit everything on one line4. One thing that might not be obvious initially is that if we want to rotate a rhythm forwards we need to SUB, if we want to rotate a rhythm backwards we need to ADD. Thus if we want to use rotation with our Euclidean rhythms we can use the following:

ER fill length SUB step rotation

where rotation is the number of steps forward we wish to rotate the rhythm.

A four channel Euclidean drum machine

Finally, let’s recreate part of the drum machine from the video at the top of the page. We’re going use the pattern tracker to hold our values for fill, length and rotation for four drum sequences. Input 0 will be reset, and input 1 will be clock. The four trigger outputs A-D will trigger our drum modules.

I: set the time T to 0

T 0

SCRIPT 1: reset the time T to 0

T 0

SCRIPT 2: trigger scripts 3-6, increase T by 1

SCRIPT 3
SCRIPT 4
SCRIPT 5
SCRIPT 6
T ADD 1 T

SCRIPT 3: read fill, length and rotation from the first 3 rows respectively of column 0 of the pattern data

X PN 0 2
Y ER PN 0 0 PN 0 1 SUB T X
IF Y : TR.PULSE A

SCRIPT 4: as script 3, but use column 1

X PN 1 2
Y ER PN 1 0 PN 1 1 SUB T X
IF Y : TR.PULSE B

SCRIPT 5: as script 3, but use column 2

X PN 2 2
Y ER PN 2 0 PN 2 1 SUB T X
IF Y : TR.PULSE C

SCRIPT 6: as scripts 3 but use column 3

X PN 3 2
Y ER PN 3 0 PN 3 1 SUB T X
IF Y : TR.PULSE D

PATTERN: each column contains the fill in the first row, the length in the second and the rotation in the third for the four sequences

0|   4   6   4   9
1|  16  16  16  16
2|   0   2   2   0
3|   .   .   .   .
4|   .   .   .   .
.|
.|
.|

Start your clock and play around with the values on the pattern tracker (you can use the [ and ] keys to increment and decrement the value under the cursor too).


  1. And the bug fix
  2. Toussaint, G. T. (2005, July). The Euclidean algorithm generates traditional musical rhythms. In Proceedings of BRIDGES: Mathematical Connections in Art, Music and Science (pp. 47-56).
  3. As an aside, the values for all the Euclidean rhythms have been precomputed and saved as jagged C arrays (~2kb) to avoid having to perform Bjorklund’s algorithm on the Teletype.
  4. Well…, maybe not yet