RKArp - an arpeggiator

The RKArp library is a software component which can be used to create an arpeggiator. It might not be the simplest implementation but with this method you can also arpeggiate more than just notes.

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

#include "RKArp.h"

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

void onArpOutput(void *userarg, byte key, byte vel)
{
  RK002_sendNoteOn(0,key,vel);
}

bool RK002_onNoteOn(byte chn, byte note, byte velocity)
{
  myarp.inputNote(note,velocity);

  // no further processing:
  return false;
}

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

  // no further processing:
  return false;
}

bool RK002_onClock()
{
  myarp.inputClock();

  // send clock thru:
  return true;
}

// initialize
void setup()
{
  myarp.setOutputHandler(onArpOutput,0);
}

// 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:
    myarp.setOutputHandler(onArpOutput,0);

    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
3 = ALTERNATE
4 = RANDOM
5 = AS_PLAYED

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
etc..

RKArp::setTranspose(int8_t v);
RKArp::getTranspose();

set/get transpose

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