You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
OSC2MIDI/OSC2Midi.cpp

47 lines
718 B

#include "OSC2Midi.h"
#include <string.h>
#include <stdlib.h>
/*
TODO: this will return rather unpredictable numbers when
given strings with numbers > 255.
*/
uint8_t getVar(const char *str, int index)
{
const char *offset = str;
// skip the first /
if (strncmp(str, "/", strlen("/")) == 0)
{
offset++;
}
if (index == -1)
{
return atoi(offset);
}
while (index > 0)
{
const char *new_offset = strstr(offset, "/");
if (new_offset) {
offset = new_offset + 1;
} else {
return 0;
}
index--;
}
return atoi(offset);
}
uint8_t getCC(const char *str)
{
return getVar(str, 1);
}
uint8_t getMIDIChannel(const char *str)
{
return getVar(str, 0);
}