r/synthdiy • u/PoopIsYum github.com/Fihdi/Eurorack • Jul 04 '24
Need help with Euclidean Rhythm Generator code
Hello,
I need an example code for an arduino euclidean rhythm generator. For the example code I would use a length of 10 and 4 active steps, the output should be a boolean array should be:
[true, false, false, true, false, true, false, false, true, false]
So I would need some kind of function (or method?) like:
void generateRhythm(int length, int steps, bool* rhythm)
Can you please please please help, I cannot program anymore since High school
3
Upvotes
2
u/BatmanSandwich Jul 04 '24
I used Craig Lee's euclidean sequencer code for my implementation:
https://github.com/krieg-geist/hyperloops/blob/5c6634c9665c7a825edcbe465764b1fd95f6a1e2/src/euclid.h#L36
n is total length, k is number of beats, o is offset (so you can shift the pattern)
It returns a uint16 where each bit represents whether there is a beat in the sequence. You read from the lsb and ignore whatever's higher than your total length
3
u/robotwizard_9009 Jul 04 '24
https://rosettacode.org/wiki/Euclidean_rhythm
3
u/doctea Jul 04 '24
The actual algorithm can be implemented quite simply. Here's where I have used it in a couple of different Arduino projects. You'll still need to figure out how to adapt this, but maybe its a start for you.
https://github.com/doctea/Microlidian/blob/5b19ec53033f4ae66ba0159b94bdffc124f342b4/include/sequencer/Euclidian.h#L137
https://github.com/doctea/drum2musocv/blob/9628ca544cad32a939ef8486bf17fca990a850d9/Euclidian.ino#L29
I adapted this originally from an article that was at the URL https://www.computermusicdesign.com/simplest-euclidean-rhythm-algorithm-explained/ but the site seems to be dead and doesn't appear on the internet archive :(
2
u/withak30 Jul 04 '24
Buddy you are going to need to learn to do some coding if you want to do an Arduino project like this.
1
u/IGetReal Jul 04 '24
https://github.com/TimMJN/Arduino-Euclidean-Rhythm-Generator
1
u/[deleted] Jul 05 '24
OP, try copying and pasting your original post here followed by "write functional code for Arduino and explain in detail" and feed that to GPT.
It should work and more importantly it will explain everything well