Skip to content

OSC Codec

nanosynth.osc

Minimal standalone OSC message/bundle encode/decode.

OscMessage

An Open Sound Control message with an address pattern and typed arguments.

Supports encoding to and decoding from the OSC binary wire format. Contents can be ints, floats, strings, bytes, bools, None, nested messages/bundles, or arrays. Uses C++ acceleration when available, falling back to a pure-Python implementation.

Args: address: OSC address pattern (e.g. "/s_new") or integer address. contents: Typed arguments (int, float, str, bytes, bool, None, OscMessage, OscBundle, or sequences thereof).

to_datagram

to_datagram() -> bytes

Encode this message to an OSC binary datagram.

from_datagram classmethod

from_datagram(datagram: bytes) -> OscMessage

Decode an OSC binary datagram into an OscMessage.

Raises OscError on malformed input (both the native and pure-Python paths).

to_list

to_list() -> list[Any]

Convert to a nested list representation: [address, arg1, arg2, ...].

to_osc

to_osc() -> OscMessage

Return self (identity, for protocol compatibility with OscBundle).

OscBundle

A timestamped collection of OSC messages and/or nested bundles.

Bundles allow multiple messages to be dispatched atomically at a specified time. A None timestamp means "immediately".

Args: timestamp: NTP timestamp (seconds since 1900-01-01) at which to execute the contents, or None for immediate execution. contents: Sequence of OscMessage and/or OscBundle instances.

from_datagram classmethod

from_datagram(datagram: bytes) -> OscBundle

Decode an OSC binary datagram into an OscBundle.

Raises OscError on malformed input (both the native and pure-Python paths).

to_datagram

to_datagram(realtime: bool = True) -> bytes

Encode this bundle to an OSC binary datagram.

find_free_port

find_free_port() -> int

Find and return an available UDP port number.