Sending an OSC Message¶
Here I'll explain how to send a simple OSC message, aswell as breaking down the code to explain how it works.
In this example I will assume you have already initialized a Peer object called peer, if you need help with this please refer to the Peer Object Tutorial.
message = OSCMessage(
address="/test/message", #(1)!
args=(
OSCInt(value=42), #(2)!
OSCString(value="Hello_World!") #(3)!
)
)
peer.send_message(message) #(4)!
- The
addressparameter specifies the OSC address pattern for the message. In this case, the message is being sent to the address/test/message. - The first argument in the
argstuple is anOSCIntobject with a value of42. This represents a 32-bit integer argument in the OSC message. - The second argument in the
argstuple is anOSCStringobject with a value ofHello_World!. This represents a string argument in the OSC message. - The
send_messagemethod of thePeerobject is called with the constructedOSCMessageobject as an argument. This sends the OSC message to the specified address with the provided arguments.
Here is the example from before, where we send a simple messsage, with two arguments. The arguments are an integer with the value 42, and a string with the value Hello_World!.
Below is a list of possible argument types that are compatible with OSC messages in PyOSC:
OSCInt- Represents a 32-bit integer.OSCFloat- Represents a 32-bit floating-point number.OSCString- Represents a string.OSCInt64- Represents a 64-bit integer.OSCTimeTag- Represents an OSC Time Tag.OSCDouble- Represents a 64-bit floating-point number.OSCBlob- Represents a binary large object (blob).OSCChar- Represents a single character.OSCSymbol- Represents an OSC symbol.OSCNil- Represents a nil value.OSCRGBA- Represents an RGBA color value.OSCMidi- Represents a MIDI message.OSCImpulse- Represents an impulse value.OSCArray- Represents an array of OSC arguments.- Boolean values are represented using
OSCFalseandOSCTrue.