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

70 lines
1.5 KiB

/*
OSC2MIDI
OSC2MIDI is a heavily extended port of https://github.com/tadas-s/OSC2Midi
(c)2020 H. Wirtz <wirtz@parasitstudio.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#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);
}