add OSC send and receive by v10101a · Pull Request #293 · processing/libprocessing
Repository navigation
add OSC send and receive - #293
Open
v10101a wants to merge 2 commits into processing:main from v10101a:osc
Open
add OSC send and receive #293 v10101a wants to merge 2 commits into processing:main from v10101a:osc
Conversation
v10101a commented Nov 25, 2026 · edited Loading
Copy link Copy Markdown
Contributor
first attempt for #179 , adds OSC over UDP for Rust and Python
API
osc_listen(port): starts listening for OSC messages onportand returns the port. fails with an error if the port is already in use.osc_send(host, port, address, args...): sends one message, e.g.osc_send("127.0.0.1", 12000, "/mouse", 0.5, 0.25).osc_read(): returns every message received since the last call, oldest first. it can be called every frame likemidi_read().osc_stop(): stops listening and closes the port.osc_read()gives an error untilosc_listen()is called again.- Python: messages are
OscMessageobjects withaddress,args,typetag(e.g."ff"for two floats),hostandport.str(msg)gives a readable form like/mouse 0.52 0.25.
Changes
- added
crates/processing_osc/ - added osc error messages to
crates/processing_core/src/error.rs src/lib.rs,src/prelude.rs: addOscPluginand export theosc_*functions- added
crates/processing_pyo3/src/osc.rs: converts Python values to OSC types, defines theOscMessageclass &&crates/processing_pyo3/src/lib.rs: registers the Python functions andOscMessage - added OSC IN/OUT examples
examples/osc.rsandcrates/processing_pyo3/examples/osc.py - used
roscinstead ofnannou_osc, sincenannou_oscdoesn't have a Bevy plugin. we could probably switch later without changing the API!
some limitations
- IPv4 only (no IPv6, TCP or multicast yet)
- only one listening port at a time.
- foats are sent as 32-bit.
tested on macOS with TouchDesigner
LLM use: wrote the crate and bindings, reviewed the API, and wrote first version of example code with Claude Code
v10101a added 2 commits November 25, 2026 02:29
add OSC send and receive, python example, rust example
4dfafd9
fix formatting
831db0b
github-actions
Bot
commented
Nov 25, 2026
Copy link Copy Markdown
|
Visual regression: 1 changed of 43 cases
If these changes are intentional, add the baseline |
View reviewed changes
tychedelia left a comment
Copy link Copy Markdown
Member
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Looks good! A few minor comments. On the design for follow-ups:
- Right now we are using a bevy resource in order to store the OSC state. We should store these as components so that
osc_listenreturns a handle (aka Bevy entity) to a port and the read/write APIs accept this handle. I think it would be fine in Python if we want to have a "default" or no-arg version that just uses a default global osc state, that would be cool as it's definitely more ergonomic. But we also want to let users read/write to multiple OSC servers. - We should have concenience methods for reading just the latest value. For example, an OSC source may write at 100Hz but we render at 60Hz, a sketch typically just wants the latest value. I'd propose something like
osc.value(addr, default)/osc.values(addr, default), a lookup of the latest value for each address. - We should consider an
osc_event(msg)callback on the sketch. Personally I prefer polling directly in the sketch but this is what the processing serial library does and could be convenient for some use cases. - It would be nice to have something like
msg.reply("/foo", 1)to reply directly to a message (when dealing with raw messages).
Feel free to fix anything here but I'm also happy to merge and keep going!
Comment thread crates/processing_osc/src/lib.rs| .receiver | ||
| .as_ref() | ||
| .ok_or(ProcessingError::OscNotListening)?; | ||
| let mut buf = [0u8; decoder::MTU]; |
| encoder::encode(&OscPacket::Message(message)).map_err(|e| failed(format!("{e:?}")))?; | ||
| if self.sender.is_none() { | ||
| let socket = | ||
| UdpSocket::bind((Ipv4Addr::UNSPECIFIED, 0)).map_err(|e| failed(e.to_string()))?; |
| /// Returns the receiver address, with `host` looked up (e.g. `127.0.0.1:9000`). | ||
| #[cfg(not(target_arch = "wasm32"))] | ||
| pub fn osc_send(host: &str, port: u16, address: &str, args: Vec<OscType>) -> Result<SocketAddr> { | ||
| let message = OscMessage { |
| use processing_core::app_mut; | ||
| use processing_core::error::{ProcessingError, Result}; | ||
|
|
||
| pub use rosc::{OscArray, OscMessage, OscType}; |
This branch has not been deployed
No deployments
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment