Take back control of your electronic setup with our small, smart music tools: The RK002 Smart MIDI Processor cable, RK006 all-connecting music hub and RK008 Realtime MIDI Recorder!

Retrokits / RK-002 MIDI Processing? Just DUY it!

RKEuclid -Euclidean generator

The Euclidean generator makes it possible to generate Euclidean patterns. It is possible to use these patterns to trigger drum notes for example.

A very cool and ispiring project can be found here: music-pattern-generator
Thanks to Wouter Hisschemöller for his amazing and inspiring work!

Below is an example sketch using 1 Euclidean generator to generate a single trigger pattern on MIDI channel 10 (=GM drum channel). The number of pulses (=’probability’) can be modified by using the modwheel.

// get the class definition
#include "RKEuclid.h"

// number of steps in the Euclid pattern in this example
#define EUCLID_PATLEN   8

// default number of pulses in the Euclid pattern in this example
// (can be altered by modwheel)
#define EUCLID_PULSES   4           

// 1x instance of a Euclid pattern generator
RKEuclid euclid;

// the 'handler' which is called when the Euclidean generator outputs 1 step
// note: 'isactive' indicates that this step should be 'accented'
void onEuclidOutput(void *userarg, bool isactive)
  if (isactive)
    // output the trigger note (example)

bool RK002_onControlChange(byte chn, byte nr, byte val)
  // is this the modwheel controller?
  if (nr == 1)
    // map modwheel value 0..100% --> 0..patlen
    // and set this as 'number of pulses' / 'probability'
    euclid.setPulses(val * euclid.getPatLen() / 128);
  return true;

bool RK002_onClock()
  // sync Euclid generator to MIDI clock
  return true;

bool RK002_onStart()
  // sync Euclid generator to MIDI start
  return true;

void setup() 
  // setup the Euclid generator
  euclid.setClockDiv(24);                                   // MIDI clock = 24 PPQN

void loop() 

RKEuclid methods

RKEuclid::setOutputHandler(hnd,void *userarg)

Sets the output handler of the Euclid generator. The handler must be defined as follows:

void euclidHandler(void *userarg, bool isactive)

the output handler is called for every step, but ‘isactive’ is set only when the step is ‘accented’

bool RKEuclid::inputClock()

This function must be called to feed clock input to the Euclid generator. It returns ‘true’ when an accented step should be output (as an alternative to ‘setOutputHandler’)


This function is used to resync the generator at (MIDI)start.


Set the clock divider (ex. 24 PPQN when using MIDI clock as input)


Set the pattern length of the generator.


Set the number of pulses of the generator (should be <= patlen !).


Set the ‘rotation’ of the pattern: this means that the pattern is phase-shifted.

Shopping cart0
There are no products in the cart!
Continue shopping