Skip to content

Commit

Permalink
add tosc_reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mhroth committed Apr 26, 2018
1 parent 1b5307a commit 7acc37a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion 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
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion 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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7acc37a

Please sign in to comment.