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)
    RK002_sendNoteOn(9,42,40);
  }
}

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
  euclid.inputClock();
  
  return true;
}

bool RK002_onStart()
{
  // sync Euclid generator to MIDI start
  euclid.reStart();
  
  return true;
}

void setup() 
{
  // setup the Euclid generator
  euclid.setOutputHandler(onEuclidOutput,0);
  euclid.setClockDiv(24);                                   // MIDI clock = 24 PPQN
  euclid.setPatLen(EUCLID_PATLEN);
  euclid.setPulses(EUCLID_PULSES);
}

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’)

RKEuclid::reStart()

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

RKEuclid::setClockDiv(v)

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

RKEuclid::setPatLen(v)

Set the pattern length of the generator.

RKEuclid::setPulses(v)

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

RKEuclid::setRotation(v)

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
0