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!

RKArp - an arpeggiator

The RKArp library is a software component which can be used to create an arpeggiator.

basic usage is fairly straightforward, so let’s start with an example and use this to elaborate the code a bit more:

#include <RK002.h>
#include "RKArp.h"

// instantiate an arpeggiator object called 'myarp' from now:
RKArp myarp;

void onArpOutput(void *userarg, byte key, byte vel)

bool RK002_onNoteOn(byte chn, byte note, byte velocity)

  // no further processing:
  return false;

bool  RK002_onNoteOff(byte chn, byte note, byte velocity)
  // calling 'inputNote' with velocity 0 means: note-off

  // no further processing:
  return false;

bool RK002_onClock()

  // send clock thru:
  return true;

// initialize
void setup()

// the main loop
void loop()

In the example first an instance of the RKArp class is created, called ‘myarp’. This object represents an arpeggiator.

  • During the setup, the object ‘myarp’ is told to call a specific function when it wants to output data:

    The second argument is a user-configurable argument, which is provided back to the callback function upon callback. This can be used to store user-defined data. In this example we simply set the user-arg to ‘0’, because we don’t need any user-defined arguments here.

  • In the note-on handler all incoming notes (regardless of the MIDI channel) are directed to the arpeggiator.
  • In the note-off handler all incoming notes (regardless of MIDI channel) are directed to the arpeggiator (with velocity set to ‘0’ to indicate to the arp that it’s actually a note-off)

RKArp methods

RKArp::setOutputHandler(hnd,void *userarg)

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

void arphandler(void *serarg, byte key, byte vel)

The userarg can by any void* pointer. This argument is provided to the call-back function when it’s being called.

RKArp::inputNote(byte key, byte vel)

This is used to feed note data into the arpeggiator. Setting ‘vel’ to 0 indicates that a key is released.

RKArp::setMode(byte mode)
byte RKArp::getMode()

set/get the arpeggiator mode:
0 = off
1 = UP
2 = DOWN

RKArp::setOctaveMin(int8_t v)
int8_t RKArp::getOctaveMin()

set/get the lower octave: -1, -2, -3 etc.

RKArp::setOctaveMax(int8_t v)
int8_t RKArp::getOctaveMax()

set/get the higher octave: 1, 2, 3, etc.

RKArp::setHold(bool b)
bool RKArp::getHold()

set/get hold mode

RKArp::setClockLength(byte v)
byte RKArp::getClockLength()

set/get clock length (in MIDI clocks, so 24 clocks per quarter note, (= 6 clocks per note)

RKArp::setGateCode(byte v)
byte RKArp::getGateCode()

set/get the gate length:
1 = 1/4
2 = 2/4
3 = 3/4

RKArp::setTranspose(int8_t v);

set/get transpose

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