Euclidean rhythms

Euclidean patterns app screenshot

Euclidean patterns

Last week I read a really interesting article about computer generated rhythms: “Generating African rhythms using the euclidean algorithm” on Ruin & Wesen’s website. Usually I’m not so impressed by generative and algorithmic music, but this formula gives some very cool results.

The formula is simple really. It’s an algorithm to distribute an amount of notes as evenly as possible over a period of time, where time is divided in equal parts. A very basic example: Say you have one measure of sixteen sixteenth notes and there are four notes to be played, then this is how those four notes would be equally distributed by the algorithm:

x . . . x . . . x . . . x . . .

A basic house or techno kick drum pattern. There’s four notes on sixteen steps, so the division is easy, 16 / 4 = 4. It gives you one note every four steps. But it gets more interesting when the numbers don’t divide so easily. Take five hits on sixteen steps. Then the pattern becomes more irregular:

x . . . x . . x . . x . . x . .

It’s these irregular patterns that create the best rhythms. Especially when several patterns are combined. In Ruin & Wesen’s article there’s a few audio examples and here’s a video on of a MiniCommand MIDI controller generating Euclidean rhythms on a Machinedrum.

The algorithm

The algorithm is very well explained in the article I mentioned, so I won’t repeat it here. There’s another article on the weblog of Robin Price which includes a Max/MSP example, there’s a Pure Data example by Dave Poulter as well as one in Java by Kristopher Reese.

Absolutely worth reading is the paper by Godfried Toussaint who as far as I know first recognized the connection between the Euclidean algorithm and musical rhythms. It’s downlaodable as a PDF: “The Euclidean Algorithm Generates Traditional Musical Rhythms”.

The Flash app

Get Adobe Flash player

Download the full source code here.

This is a Flash app I made over the weekend to quickly try out combining rhythms. It’s by no means complete, but it does work:

  • To create a new pattern doubleclick somewhere in the lower panel. A basic sixteen step quarter note pattern appears where you clicked.
  • To edit the pattern doubleclick it’s center circle. A settings popup appears with sliders for pattern length and number of hits. Change these to quickly get a feel for how these Euclidean patterns work. The ‘Sound’ dropdown menu lets you select a different sample for the pattern to play.
  • Click and drag the center circle to move a pattern.
  • The controls at the top are obvious: Start / stop playback, adjust volume and change tempo (in beats per minute).

You will notice that when you create a new pattern while patterns are already playing, the new pattern is not synchronized. To synchronize all patterns stop and restart playback.

Euclid of Alexandria

Euclid of Alexandria

There’s a lot I should add to make this a complete app: An open and save option for pattern combinations and their settings, an option to load and use your own samples, basic sample editing like volume, speed and sample start adjustment and more pattern options.
But the first thing I’d like to do is to add MIDI output. So I can use these patterns to drive music software like Ableton Live or hardware like my Machinedrum. It seems Java is the easiest way to write software that can use MIDI, so next I will be learning to program Java.

This entry was posted in ActionScript and tagged , , , , , , , . Bookmark the permalink. Both comments and trackbacks are currently closed.


  1. Posted January 28, 2011 at 01:07 | Permalink


    Thanks for the linkback to my post. Nice article as well. The flash app is nicely done, and extremely useful in hearing the combinations of these derived Euclidean Rhythms. Something I hadn’t considered doing myself- although I’m not really a drummer (I’m a saxophonist). Makes for an interesting concept of possibly changing these combined, complex rhythms into something closely related using genetic algorithms, which might provide a means for creating even more rich rhythms using this Euclidean ideology. I might have to play around with the idea some this weekend.

    Let me know if you need any help with the Java MIDI API, I’ve spent a while learning it for another music related project (Generating Tonal Harmonic Progressions using Reinforcement Learning). I’d love to collaborate with you on some projects at some point; Its always nice to find people with the same interests in electroacoustics (although I am more on the side of computationally generated music). Still might lead to some interesting ideas…

  2. Posted February 1, 2011 at 23:25 | Permalink

    Hi Kristopher,

    Thanks for your comment. Although I’m not sure I understand all you write, I think it’s about an algorithm that takes a combination of several of these polyrhythms and lets them evolve so they together form a more complex combined rhythm. A combination that isn’t random but where the rhythms grow together in a meaningful way according to the algorithm. That would be very interesting to hear and to know about.

    And thanks for your offer of help on the Java MIDI API. The MIDI side of Java doesn’t give me too many problems at the moment. I find the graphics and GUI programming takes the most time to get used to. And I need to learn more about Threads. But in general learning Java as a Flash developer is a lot easier than I thought it would be.

    It would be great if we could collaborate on a future project. I hope there will be an occasion to do so.

  3. Posted February 15, 2011 at 00:28 | Permalink

    Hey, just wanted to chime in and say that this is awesome!
    Great work (both of you)!
    Have fun learning Java, it’s not that different from AS3 so you wont have any trouble.

  4. Posted February 16, 2011 at 13:28 | Permalink

    Thanks! Yes, Java is easier than I thought it would be. Or at least it’s easy to get started. I like it. At the moment the GUI stuff takes most time to get used to; Swing component layout and screen repaints. And Threads are a new concept for me.

  5. ThomasR
    Posted May 12, 2011 at 05:08 | Permalink

    Hey wouter,
    a very brutal question:
    are you sure this is a correct implementation of the algorithm?
    citing from the article:
    For example E(5; 13) = [1001010010100].

    where the “small” [10] and “big” [100] are distributed evenly

    but in the (very beautiful!) applet, having 5 fills in 13 steps returns [1001001001010]

    (where the “small” fragments [10] are distributed next too each other at the end, and the “big” fragments [100] distributed together at the beginning…)

    please correct me if i’m wrong!

  6. Posted May 18, 2011 at 23:12 | Permalink

    Hi Thomas,
    Yes you’re right. I never noticed this, but it is wrong indeed. Euclid(5, 13) should go like this:
    So it looks like the algorithm stops one iteration too early. I’ll see if I can fix the error. Thanks for noticing!

  7. Tony
    Posted May 27, 2011 at 15:04 | Permalink

    It would be cool if the tempo could be slaved to incoming midi clock events. Now the solution would be using 120 bpm in both, your java application and the DAW, e.g. Ableton Live, then later controling tempo in Live via midi clock.

  8. Posted May 29, 2011 at 19:15 | Permalink

    @Tony: That’s something I hope to add in the future. Send MIDI clock or follow incoming MIDI clock. Or both ideally of course.

  9. Neil
    Posted June 16, 2011 at 23:56 | Permalink

    This is really interesting stuff

    I’ve been working on some stuff recently involving non-standard pattern lengths and cross-rhythms (among other things) as its basis, though I’ve been using the Nord Modular G2, so it’ll be interesting to see if I can build something in the G2 environment which will generate these rhythms… should be possible. Good work!

    If anyone’s interested, here’s a couple of the tunes I’ve done- it’s certainly in a similar sort of area

  10. Phoebe Jiang
    Posted June 18, 2011 at 16:53 | Permalink

    Awesome article and app! I have fun playing around with the flash! It’s really useful and necessary to put an app on it so people will have a better understanding of Euclidean rhythm. I’ve never thought that it would be so beautiful when math and music are combined.

  11. Per Karlsson
    Posted August 24, 2011 at 12:12 | Permalink

    Thank you for a great application
    I am trying to figure out how to get Flash to play sounds in that kind of exact sync that I hear in your app. The problem is that I get completly lost in the code. Do you have a suggestion on where to find the methods timing sound and triggering sound?

    Best regards
    Per Karlsson

  12. Posted August 24, 2011 at 12:13 | Permalink

    @Per: There’s an earlier post on exactly that subject on this site: I hope that will help you.

  13. Posted October 5, 2011 at 13:02 | Permalink

    Nice one, I can also recommend the softwareprogram synthedit (demo is free and has almost no limitations except less presets..which you can go around haha) to build this kind of sequencers. I already made quite some based on waveform-functions (every sound has it’s own rhythm when slowed down, reading out peaks, zero-crossings or mids, or combining them) ,counting matrices, divisions, automatic-recording etc etc. The euclidian-rhythm-generator shouldn’t be too hard to reconstruct and you get easy access to midi implementation, modulation routing or maybe implementing more mathematical functions to be combined with the euclidian (what happens if you transform from one shape to the other?).

    ok, to prove my point..I just made one within one hour… independent amount of steps (up to 64 right now) and independent gate-division: set amount of steps independent from the squence itself for small offsets and amount of steps between each step (being rounded off to fit into the 64-step sequence). With some easy adds I can also add seperate counters with independent tempo adjusts and play-direction for each sequence. XD if you want some info/ideas/help, just contact me..I suppose you can see my e-mail..otherwise, leave a message and I’ll probably get a notice…

  14. Posted October 5, 2011 at 13:05 | Permalink

    @Sirsicksik: I’ve heard of synthedit. Sounds easy to work with. At the moment I prefer to program everything myself because I enjoy programming and learn a lot by writing these applications. And for me there is no need to get them done quickly.
    But still, what you say about Synthedit sounds interesting and it might be a good way for me to do prototypes. Thanks for the info.

  15. Posted October 5, 2011 at 15:13 | Permalink

    Hey Wouter,

    cool to see you’re working with this algorithm too! I’m working on an Arduino version to live in my modular analog synth, will let you know when I make some progress..

    groet, Jilt

  16. Posted October 5, 2011 at 15:15 | Permalink

    @Jilt: Hi Jilt, sounds interesting. I sent you an email.

  17. Douglas
    Posted October 28, 2011 at 05:31 | Permalink

    Did you ever make a java version?

  18. Posted October 28, 2011 at 05:32 | Permalink

    @Douglas: Yes, it is on this site as well.

6 Trackbacks

  1. [...] Wayne Reese] Pure Data + Java – Dave Poulter Flash/ActionScript (pictured above) – Euclidean rhythms [Wouter Hisschemöller] Max for Live (pictured below) – Euclidean sequencer [Robin [...]

  2. By – The Bjorklund Algorithm on March 20, 2011 at 02:47

    [...] This is an excerpt from the somewhat melodramatically titled paper, The Euclidean Algorithm Generates Traditional Musical Rhythms. In short, sequences generated by the equal spacing algorithm described resemble various traditional rhythms, or otherwise sound pretty good. Create Digital Music did a post on various musical applications of it recently, like this neat little sequencer in flash. [...]

  3. By Euclidean rhythms update on May 20, 2011 at 19:59

    [...] rhythms update By Wouter | Published: May 20, 2011 E(5, 13) patternThere’s an error in the Euclidean rhythms generator I posted in January. A few days ago I got a comment by Thomas pointing out the app generates wrong [...]

  4. By Euclidean MIDI Patterns on May 22, 2011 at 15:49

    [...] MIDI Patterns By Wouter | Published: May 22, 2011 ScreenshotIn January I posted a Euclidean rhythm generator in Flash. Polyrhythms generated by a mathematical algorithm. I wanted [...]

  5. [...] January I posted a Euclidean rhythm generator in Flash. Polyrhythms generated by a mathematical algorithm. I wanted [...]

  6. [...] afspelen in Java, dat een aantal ingebouwde midi-instrumenten bevat. Hisschemöller heeft ook een flashversie beschikbaar die je direct in je browser kunt [...]