Here is to simplify the usage of OSC in vl for the most common scenarios: the goal is to be using as few nodes and pins-to-configure to be able to receive and send osc-messages.
Receiving
- Create an OSCReceiver, give it a name and a port (or leave the defaults)
- Create OSCValue/s (Receive) nodes that refer to the OSCReceiver by name and listen for a specific osc-address
- done
- The Index on the OSCValue (Receive) refers to the index of the arguments of the osc-message: say you receive a message with arguments ffff you can use the Index to getslice a specific argument
- The Index and Count on the OSCValues (Receive) allows you to get a series of consecutive arguments of one message as a spread: say you’re receiving a message with arguments ssffff you can use Index=2 and Count=4 to get a spread of the 4 floats in the arguments
- OSCValue/s (Receive) are generic, so they can be connected to (spread of) string, float32, float64, int32 and int64, char, bool, color, v2, v3, v4, Spread-of-byte
- Note: if more than one osc-message with the same address arrives in one frame, only the last one is received
- Reason for connecting OSCReceivers with OSCValue/s (Receive) nodes via name is so that you don’t have to connect them via link and still be able to change the receiving udp port in one central spot.
Receiving a custom datatype
If you have an osc-message with arguments of different types (say sfff) and you can also parse those into a custom datatype that has those properties. The only thing you have to do, is provide an override for ArgsToValue that builds your datatype out of the osc-arguments, like so:
Sending
- Create an OSCSender and specify remote address and port
- Create an OSCValue/s (Send) and connect it to the OSCSender
- done
- OSCValue/s (Send) are generic, so they can take (spread of) string, float32, float64, int32, int64, char, bool, color, v2, v3, v4, Spread-of-byte
To send a bunch of messages as a bundle, simply cons them together and then use the OSCSender (Spread)
Sending a custom datatype
To send a custom datatype, the only thing you have to do, is to provide a custom override to ValueToArgs. See how you need to split down your datatype to types that OSC can understand, ie. string, float32, float64, int32 and int64
Download
VL.IO.SimpleOSC.vl (104.1 KB)
Test
- Requires VL >= 2020.1.x
- In your VL document set a dependency to both this file and VL Nugets > VL.IO.OSC
Thoughts
Please test and report your thoughts.
It bugs me a bit that Receiving and Sending are not entirely working the same way, ie while the receiver is connected to the values via name, the sender still needs to be connected via link. This should maybe be thought through a bit more… Any feedback welcome