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!

Examples

Tempo Clock intern/extern/tap

In this example operation of the clock generator is shown. The sketch sets the internal tempo to 150.0 bpm, and displays the measured tempo on each beat (=24 clocks).

#include <RK002.h>

RK002_DECLARE_INFO("SAMPLE CODE","duy@retrokits.com","1.0","7b47d3dd-991a-4197-ac02-d340cdabfb59")

int beatctr = 0;

// clock tick handler: this is called 24x per quarter note:
// either from the internal clock generator
//   or
// when a MIDI clock message (=0xF8) is received
bool RK002_onClock()
{
  beatctr = (beatctr + 1) % 24;
  if (beatctr == 0)
  {
    RK002_printf("tempo=%d (%s)",RK002_clockGetTempo(),RK002_clockIsExtern()?"EXTERNAL":"INTERNAL");
  }

  return true;
}

#define TAPMIDICHN 5

bool RK002_onNoteOn(byte channel, byte note, byte velocity)
{
  // receive any note-on on the TAP channel: tap the internal clock generator
  if (channel == (TAPMIDICHN-1))
  {
    RK002_clockTap();
  }
}

// initialize
void setup()
{
  // set internal clock generator tempo to 150.0 bpm:
  RK002_clockSetTempo(1500);
}

// the main loop
void loop()
{
  RK002_loop();
}

Novation Circuit

In this example the cable can be used to play the drum channels on the Novation Circuit.

#include <RK002.h>

#define APP_NAME "CIRCUIT example"
#define APP_AUTHOR "www.retrokits.com"
#define APP_VERSION "0.0.1"
#define APP_GUID "15fead90-5085-4ca0-b7a4-a93fe6c95686"

RK002_DECLARE_INFO(APP_NAME,APP_AUTHOR,APP_VERSION,APP_GUID);
RK002_DECLARE_PARAM(ENABLECHROMATIC,1,0,4,0)

// CC values for changing pitch
byte pitchtable[]=
{
  0,1,2,4,5,7,9,10,12,14,17,19,21,23,26,29,
  32,35,39,42,46,50,55,59,64,69,74,80,86,93,99,107,115,122,127
};

// CC numbers for drum pitch
byte drumPitchCC[] ={0,14,46,34,55};

// note numbers mapping from lowest control octave
byte controlKeys[] ={0,60,64,62,65};

//handler triggered on note on message:
bool RK002_onNoteOn(byte channel, byte note, byte velocity)
{
  byte enableChromaticParam = RK002_paramGet(ENABLECHROMATIC);

  if (channel == 1)
  {
    // switch to lowest Circuit octave to control replay:
    note = min(note, 40); // pitch table is limited to three octaves (+ 5 control notes)
    if (note > 4)
    {
      // pressed note not lowest control octave:
      if (controlKeys[enableChromaticParam] != 0)
      {
        RK002_sendControlChange(10,drumPitchCC[enableChromaticParam], pitchtable[note - 5]);
        RK002_sendNoteOn(10,controlKeys[enableChromaticParam], velocity);
      }
    }
    else
    {
      //  we are in control octave, set control index pointer
      RK002_paramSet(ENABLECHROMATIC, note);
    }
  }

  return true;

}

bool RK002_onNoteOff(byte channel, byte note, byte velocity)
{
  byte enableChromaticParam = RK002_paramGet(ENABLECHROMATIC);

  if (channel == 1)
  {
    if (note > 4)
    {
      if (controlKeys[enableChromaticParam] != 0)
      {
        RK002_sendNoteOff(10,controlKeys[enableChromaticParam], velocity);
      }
    }
  }

  return true;
}

// disable clock for loopback cable mode
bool RK002_onClock()
{
  return false;
}

bool RK002_onStart()
{
  return false;
}

bool RK002_onContinue()
{
  return false;
}

bool RK002_onStop()
{
  return false;
}

// initialize
void setup()
{
}

// the main loop
void loop()
{
}
Shopping cart0
There are no products in the cart!
Continue shopping
0