diff --git a/tinyosc.c b/tinyosc.c index 13fa09ee69..3bfc616969 100644 --- a/tinyosc.c +++ b/tinyosc.c @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, Martin Roth (mhroth@gmail.com) + * Copyright (c) 2015-2018, Martin Roth (mhroth@gmail.com) * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -154,6 +154,14 @@ unsigned char *tosc_getNextMidi(tosc_message *o) { return m; } +tosc_message *tosc_reset(tosc_message *o) { + int i = 0; + while (o->format[i] != '\0') ++i; + i = (i + 4) & ~0x3; // advance to the next multiple of 4 after trailing '\0' + o->marker = o->format + i - 1; // -1 to account for ',' format prefix + return o; +} + void tosc_writeBundle(tosc_bundle *b, uint64_t timetag, char *buffer, const int len) { *((uint64_t *) buffer) = htonll(BUNDLE_ID); *((uint64_t *) (buffer + 8)) = htonll(timetag); diff --git a/tinyosc.h b/tinyosc.h index e39c926ff2..c55d152317 100644 --- a/tinyosc.h +++ b/tinyosc.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015, Martin Roth (mhroth@gmail.com) + * Copyright (c) 2015-2018, Martin Roth (mhroth@gmail.com) * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -122,6 +122,13 @@ void tosc_getNextBlob(tosc_message *o, const char **buffer, int *len); */ unsigned char *tosc_getNextMidi(tosc_message *o); +/** + * Resets the read head to the first element. + * + * @return The same tosc_message pointer. + */ +tosc_message *tosc_reset(tosc_message *o); + /** * Parse a buffer containing an OSC message. * The contents of the buffer are NOT copied.