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

48 lines
716 B

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