Library reference
Contents
Functions for sending MIDI data
void RK002_sendNoteOff(byte channel, byte key, byte velocity)
MIDI note-off event.
channel = MIDI channel number 0..15
key = MIDI key number 0..127
velocity = MIDI velocity 0..127
Remark: In MIDI, a note-on with velocity zero should (and will) be registered as a note off!
void RK002_sendNoteOn(byte channel, byte key, byte velocity)
Sends a MIDI note-on event.
channel = MIDI channel number 0..15
key = MIDI key number 0..127
velocity = MIDI velocity 0..127
Remark: In MIDI, a note-on with velocity zero should (and will) be registered as a note off!
void RK002_sendPolyPressure(byte channel, byte key, byte val)
Sends a MIDI polyphonic keypressure event.
channel = MIDI channel number 0..15
key = MIDI key number 0..127
val = key-pressure value 0..127
void RK002_sendControlChange(byte channel, byte nr, byte val)
Sends a MIDI control change.
channel = MIDI channel number 0..15
nr = MIDI controller number 0..127
val = controller value 0..127
void RK002_sendProgramChange(byte channel, byte nr)
Sends a MIDI program change.
channel = MIDI channel number 0..15
nr = program change number 0..127
void RK002_sendChannelPressure(byte channel, byte val)
Sends a MIDI channel pressure (=’aftertouch’).
channel = MIDI channel number 0..15
val = pressure value 0..127
void RK002_sendPitchBend(byte channel, int position)
Sends a MIDI channel pressure (=’aftertouch’).
channel = MIDI channel number 0..15
position = pitchbend position -8192 .. 8191
void RK002_sendSystemExclusive(unsigned n, const byte *data)
Sends a MIDI system exclusive message.
n = number of bytes to send
data = data to send
void RK002_sendTimeCodeQuarterFrame(byte mtc)
Sends a MIDI timecode message.
mtc = timecode
void RK002_sendSongSelect(byte songsel)
Sends a MIDI song select message.
songsel = selected song
void RK002_sendSongPosition(unsigned songpos)
Sends a MIDI song position message.
songpos = song position
RK002_sendTuneRequest()
Sends MIDI tune request message.
RK002_sendClock()
Sends MIDI clock message.
RK002_sendStart()
Sends MIDI start message.
RK002_sendContinue()
Sends MIDI continue message.
RK002_sendStop()
Sends MIDI stop message.
RK002_sendActiveSensing()
Sends MIDI active sensing message.
RK002_sendReset()
Sends MIDI active sensing message.
Call-back functions for receiving MIDI data
boolean RK002_onNoteOff(byte channel, byte key, byte velocity)
Callback function which is called when a MIDI note off message is received.
channel=MIDI channel 0..15
key=key number 0..127
velocity=velocity 0..127
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onNoteOn(byte channel, byte key, byte velocity)
Callback function which is called when a MIDI note on message is received.
channel=MIDI channel 0..15
key=key number 0..127
velocity=velocity 0..127
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onPolyPressure(byte channel, byte key, byte value)
Callback function which is called when a MIDI poly-pressure message is received.
channel=MIDI channel 0..15
key=key number 0..127
value=pressure value 0..127
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onControlChange(byte channel, byte nr, byte value)
Callback function which is called when a MIDI control change message is received.
channel=MIDI channel 0..15
nr=controller number 0..127
value=pressure value 0..127
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onProgramChange(byte channel, byte nr)
Callback function which is called when a MIDI program change message is received.
channel=MIDI channel 0..15
nr=program change value 0..127
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onChannelPressure(byte channel, byte val)
Callback function which is called when a MIDI program channel pressure (=’aftertouch’) message is received.
channel=MIDI channel 0..15
nr=program change value 0..127
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onPitchBend(byte channel, int val)
Callback function which is called when a MIDI pitchbend message is received.
channel=MIDI channel 0..15
val=value -8192..8191
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onSystemExclusive(unsigned n, const byte *data)
Callback function which is called when a MIDI sysex message is received.
n=number of bytes (inclusive F0 and F7)
data=sysex data (inclusive F0 and F7)
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onTimeCodeQuarterFrame(byte mtc)
Callback function which is called when a MIDI timecode message is received.
mtc=midi timecode
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onSongSelect(byte songsel)
Callback function which is called when a MIDI songselect message is received.
songsel=selected song
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onSongPosition(unsigned pos)
Callback function which is called when a MIDI song position message is received.
pos=song position
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onTuneRequest()
Callback function which is called when a MIDI tune request message is received.
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onClock()
Callback function which is called when a MIDI clock message is received OR a tick from the internal MIDI clock generator has passed.
should return ‘true’ to indicate that the MIDI clock message should be sent.
boolean RK002_onStart()
Callback function which is called when a MIDI start message is received.
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onContinue()
Callback function which is called when a MIDI continue message is received.
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onStop()
Callback function which is called when a MIDI stop message is received.
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onActiveSensing()
Callback function which is called when a MIDI active-sensing message is received.
should return ‘true’ to indicate that the original message must be sent thru
boolean RK002_onReset()
Callback function which is called when a MIDI reset message is received.
should return ‘true’ to indicate that the original message must be sent thru
bool RK002_onChannelMessage(byte sts, byte d1, byte d2)
Callback function which is called for all MIDI channel messages. Be carefull with this function, because ALL channel traffic is routed through this function.
Function & callbacks for clock generator
void RK002_clockSetTempo(unsigned int bpm_x10)
Set internal clock generator tempo.
bpm_x10=beats per minute x 10 (so 120.0 should be passed as 1200)
unsigned int RK002_clockGetTempo()
Get the current clock tempo (either internal, or measured from external).
returns beats per minute x 10
void RK002_clockSetMode(unsigned int mode)
Set the clock generator mode:
mode=0 : automatic
mode=1 : internal only
mode=2 : external only
boolean RK002_clockIsExtern()
Check whether the clockgenerator is running externally synced.
returns TRUE : clock is external
returns FALSE: clock is generated internally
void RK002_clockTap()
Tap the clock generator (makes sense only when internally clocked).
This can be used to implement a tap-tempo mechanism.
void RK002_onHeartBeat()
This function is called every “heartbeat”. The heartbeat timer is a fixed-rate timer running at 10ms interval (so the callback function is called at 100Hz). This callback should be used to implement time-based delays (in stead of the delay() function)
#define RK002_HEARTBEAT_IN_MS
This symbol can be used to implement real-time intervals. The value of this symbol contains the number of milliseconds of 1 heartbeat (currently 10 ms).
For example:
int longtimer = 0; void RK002_onHeartBeat() { // is timer running ? if (longtimer != 0) { // count 1 timer tick: longtimer--; // is timer timed-out? if (longtimer == 0) { // .. do something useful here: // ..... } } } void RK002_ControlChange(byte chn, byte nr) { if ((chn == 5) & (nr == 55)) { // start the 1-shot timer: // note: in this example we time 4 seconds = 4000ms, // so we have to count '4000 / RK002_HEARTBEAT_IN_MS' callbacks longtimer = 4000 / RK002_HEARTBEAT_IN_MS; } }
Functions & callbacks for parameters
void RK002_paramSet(unsigned param_nr, int val)
Set parameter value.
param_nr=parameter number
val=parameter value (will be bound-checked)
int RK002_paramGet(unsigned param_nr)
Get parameter value.
param_nr=parameter number
returns parameter value (bound-checked)
void RK002_onParamSet(unsigned param_nr, int val)
Callback function which is called whenever a parameter is set (regardless of value).
param_nr=parameter number
val=parameter value
void RK002_onParamChange(unsigned param_nr, int val)
Callback function which is called only when a parameter is changed.
param_nr=parameter number
val=parameter value
extern void RK002_sendBytes(unsigned n, const byte *dat);
Sends arbitrary bytes to the MIDI output. Be carefull with this function, because it can be used to send any byte to the MIDI output, including non-correct MIDI !
extern void RK002_sendChannelMessage(byte sts, byte d1, byte d2);
Sends a channel message to the MIDI output. This function can come-in handy in some situations.
Functions for debugging
RK002_printf(const char *fmt, ...)
Sends debug text message through MIDI sysex.