# A Euclidean rhythm operator for the Teletype

I’m just cutting and pasting the content of my pull request on Github…

This is my work in progress PR to add a Euclidean rhythms operator to the teletype.

``````ER f l i
``````

where

• `f` = fill
• `l` = length
• `i` = index (0-based)

The output is a `1` or `0`.

The index is modulo’d against the length.

The data is precomputed using a Haskell script, it only includes lengths up to 32. As far as I can tell, most algorithms to compute a Euclidean rhythm are at best O(n), whereas this is O(1). The code+data adds ~2kb to the ROM size.

Open questions:

• Is `ER` the best name for the operator? Initially I was using `EUCLID` but it’s a bit too long.
• Should the index be modulo’d by length?
• What to do about out of bound values (fill > length, length > 32)?
11 Likes

quite impressive

nice demo too

“er” is fine in my opinion

Super! And nice to see the Haskell code, too.

great work! thanks for sharing!

indeed! I’ve just done a course in functional programming and am bubbling over with joy seeing haskell in good use in the wild

What course did you take? I took FP101x in the fall of 2014.

Thanks, the Haskell algorithm itself comes from here, there is another implementation in the hmt library too.

1 Like

@bens took it at college

very refreshing and enlightening!

pulled and published a release for those that want to try this out!

3 Likes

amazing amazingly fast

merci

1 Like

Blimey that’s a bit fast. Hope you checked my pointer maths!

One little tip, if you’re trying to do offsets you need to subtract the offset, e.g.

``````ER f l SUB i o
``````

where `f` = fill, `l` = length, `i` = index and `o` = offset.

Also the index is zero based.

2 Likes

everything looked good, though i admit my review was cursory.

but this is why i made it a point version-- good for everyone to test and comment prior to a version bump.

1 Like

Really really cool! Your making the teletype even more amazing

1 Like

Hi,
Is there a proper syntax/code reference for the Euclidean rhythm implementation posted somewhere?
Thank you for making this.
Really want to give it a try.

Only the info at the top of this thread so far. I can write up some more stuff for you if you want me to? It needs doing, but I probably won’t have time till Monday.

First question though, do you know what a Euclidean rhythm is?

1 Like

Yes I am very familiar with Euclidean patterns. Some years ago I have actually built a Max engine for that
BUT
I think we should have a proper writeup for this great feature in the Teletype that explains properly all the elements of syntax and implementation.

Yes please ! 20 what ? 20 characters my lord !

I don’t own teletype,but for me CLIDE is a good name…
If it is not too long.

So… I’ve just been trying to write up something (and checking it all on my Teletype as I’ve been going along), and I’ve noticed that negative indexes aren’t working properly (due to the way that the `%` operator works in C). I’ll try to get it fixed tomorrow.

1 Like

Pull request to fix the negative step value bug:

1 Like

I’ve posted Euclidean rhythms on the Monome Teletype on my (new) website. I’m hoping it should be enough to get people started.

There is only one gotcha, the examples with negative numbers, `ER 4 16 -1` and `ER 4 16 -4`, don’t work at the moment. They’ll need a new release of the firmware to fix a bug. @tehn any chance of an updated teletype beta?

4 Likes