experimental.osc
Open Sound Control over UDP implementation.
See - https://opensoundcontrol.stanford.edu/ - https://hexler.net/touchosc/manual/introduction
- class experimental.osc.OpenSoundPacket(data: bytes)
A container object for the Open Sound Control packet(s) we receive.
Contains the address of the message and the data
- Property address
The address string of the packet
- Property values
The values included in the packet
- Parameters
data –
The raw byte data read from the UDP socket. The byte data consists of the following data: #. leading ‘/’ character
slash-separated address (e.g. foo/bar)
null terminator (0x00 byte)
’,’ character
type arguments
”f” character for 32-bit float
”i” character for 32-bit signed integer
”s” character for string (null-terminated)
”b” character for blob (32-bit int -> n, followed by n bytes of data)
assorted non-standard types
null terminator(s)
payload bytes (lengths are type dependent)
Every argument starts on an 4-aligned byte, so there are filler nulls to pad strings out to a multiple of 32 bits
- property address: str
This packet’s address
- property values: list[int | float | str | bytearray]
The array of values included in this packet
We support OSC 1.0 + a subset of 1.1 types
- class experimental.osc.OpenSoundServer(recv_port=9000, send_port=9001, send_addr='192.168.4.100')
The OSC server.
This object owns the socket and is responsible for sending & receiving messages
To use, instantiate the server and assign a callback. Then call receive_data() in the main loop:
import europi def main(): srv = OpenSoundServer(9000) @srv.data_handler def process_data(connection=None, data=None): # process the data, send anything back over the connection if needed ... while True: srv.receive_data()
- Parameters
recv_port – The UDP port we accept messages on. TouchOSC uses port 9000 by default, so we use that here for convenience
send_port – The UDP port we send outgoing messages on.
send_addr – The IP address of the host we send outgoing messages to
- data_handler(func)
Decorator for the function to UDP packet reception
The provided function must accept the following keyword arguments: - connection: socket A socket connection to the client - data: str The request the client sent
- Parameters
func – The function to handle the request.
- default_callback(connection=None, data: Optional[OpenSoundPacket] = None)
Default callback function when we receive data
Does nothing
- receive_data()
Check if we have any new data to process, invoke data_handler as needed
- send_data(address, *args)
Transmit a packet
- Parameters
address – The OSC address to send to
args – The values to encode in the packet. Allowed types are int, float, bool, str, and bytearray. Bools are converted to 0/1 integers
- experimental.osc.align_next_word(n)
Return the index of the next word-alined byte
We assume 4-byte/32-bit words. If we’re already word-aligned, we increment to the next one
- Parameters
n – The current index in a byte array