An OSCMessage is an address followed by any number of data. Messages can have mixed data types like an integer followed by a string followed by a float, etc.
OSCMessages can be constructed with or without an address.
Set the address of the message in the constructor
OSCMessage msg("/address");
An OSCMessage constructed without an address is not valid until it is given an address.
Append an integer to the OSCMessage.
msg.add(1);
Append a float to the OSCMessage.
Append a boolean to the OSCMessage.
Append a string to the OSCMessage.
msg.add("hello");
Append a blob to the OSCMessage. Pass in the length of the blob as the second argument.
Replace the data at the given position with the data. Type
can be any of the supported data types.
//replace the data at the 0th position with a string
msg.set(0, "string");
Set the data at the given position to be a blob of the given length.
Append a double precision floating point value to the OSCMessage. NOTE: double is not supported on most Arduino platforms. It will fall back to float, when double is not supported.
Returns the integer at the given position
//returns the integer at the third position
msg.getInt(2);
Returns the float at the given position
Returns the boolean at the given position
Returns the double at the given position. NOTE: double is not supported by most Arduino platforms. This will fail silently if double is not supported.
Copy the string’s characters into the `strBuffer’, without any safetcheck’. Returns the number of copied characters.
Copy the string’s characters into the `strBuffer’, after checking that this doesn’t exceed the buffer’s ‘length’. Returns the number of copied characters.
Copy size
number of characters from the given ‘offset’ into the `strBuffer’, after checking that this doesn’t exceed the buffer’s ‘length’. Returns the number of copied characters.
char str[8];
//fill str with 8 characters from the 0th datum
msg.getString(str, 8, 0, 8);
Directly copy the blob’s bytes into the blob
buffer (without safety-check).
Returns the number of bytes from the blob.
Copy ‘size’ bytes from the blob, starting from ‘offset’, into the given `blobBuffer’, if the size doesn’t exceed the buffer’s (or the blob’s) ‘length’. Returns the number of bytes copied from the blob.
Returns the length of the blob in bytes.
Returns the type of the data at the given position.
OSCMessage msg("/address");
msg.add(1);
msg.getType(0); //-> returns 'i'
Returns true
when the data at the given position is an integer.
Returns true
when the data at the given position is a float.
Returns true
when the data at the given position is a boolean.
Returns true
when the data at the given position is a string.
Returns true
when the data at the given position is a blob.
Returns true
when the data at the given position is a double.
Returns the number of data the OSCMessage has.
Returns the size of the OSCMessage in bytes (if everything is 32-bit aligned).
Set the address of the OSCMessage.
Copy the address of the OSCMessage into the str
buffer. Copy after the given address offset (defaults to 0).
Output the message to the given transport layer which extends Arduino's Print class like the Serial
out.
msg.send(SLIPSerial);
Add the incoming byte to the OSCMessage where it will be decoded.
Add and decode the array of bytes as an OSCMessage.
Returns true if the message's address is a full match to the given pattern after the offset.
OSCMessage msg("/a/0");
msg.fullMatch("/0", 2); // ->returns true
Returns the number of matched characters of the message's address against the given pattern (optionally with an offset). Unlike fullMatch
, match
allows for partial matches
OSCMessage msg("/a/0");
msg.match("/a"); // ->returns 2
Invoke the given callback if the address if a full match with the pattern (after the offset). The message is passed into the callback function. Returns true if the pattern was a match and the callback function was invoked.
Invoke the given callback if the address if a match with the pattern (after the offset). The OSCMessage and the address offset is passed into the callback function. Returns true if the pattern was a match and the callback function was invoked.
//define a callback function for matching messages
void routeCallback(OSCMessage & message, int addressOffset){
//do something with the message...
//with the message below, the addressOffset will equal 2.
}
OSCMessage msg("/a/0");
msg.route("/a", routeCallback);
OSCMessages can be constructed with patterns and later routed or dispatched against addresses.
OSCMessage msg("/{a,b}/[0-9]");
msg.route("/a/0", a0_callback); //matches the address
msg.route("/b/2", b2_callback); //matches the address
msg.route("/c/11", c11_callback); //not invoked
A bundle is a group of OSCMessages with a timetag.
Construct an empty OSCBundle.
Construct the bundle with a timetag. timetag defaults to 0 (immediate).
Create a new message with the given address in the bundle. Returns the newly created OSCMessage.
//create a new OSCMessage and add some data to it
bundle.add("/message").add("data");
Return the OSCMessage in the bundle at the given position.
OSCBundle bundle
bundle.add("/a");
bundle.add("/b");
bundle.getOSCMessage(0);//returns the OSCMessage with the address "/a".
Return the OSCMessage in the bundle which matches the given address.
OSCBundle bundle
bundle.add("/a");
bundle.add("/b");
bundle.getOSCMessage("/b");//returns the second OSCMessage in the bundle
Invoke the callback function with all messages in the bundle which match the given pattern after the offset.
bundle.add("/a/0");
bundle.add("/b/0");
bundle.dispatch("/0", dispatchZero, 2);
Invoke the callback with all the OSCMessages in the bundle which match the given pattern. route
allows for partial matches.
Output the bundle to the given transport layer which extends Arduino's Print class (such as SLIPSerial
out).
bundle.send(SLIPSerial);
Add the incoming byte to the OSCBundle where it will be decoded.
Add and decode the array of bytes as an OSCBundle.
Many methods return this
which enables you to string together multiple commands.
This technique allows multiple lines to be condensed into one:
bundle.add("/address").add("data").add(0).send(SLIPSerial).empty();