Repository navigation
Conversation
|
Visual regression: 1 changed of 43 cases
If these changes are intentional, add the baseline |
tychedelia
left a comment
There was a problem hiding this comment.
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!
| .receiver | ||
| .as_ref() | ||
| .ok_or(ProcessingError::OscNotListening)?; | ||
| let mut buf = [0u8; decoder::MTU]; |
There was a problem hiding this comment.
nit: we can send more over localhost, might be worth sizing this for that use case when reading from localhost
| 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()))?; |
There was a problem hiding this comment.
we should try to rebind the listening port if it's available first, some apps will reply by default to where they received messages from. iirc there's some trickyness on windows here though that i can't remember
| /// 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 { |
There was a problem hiding this comment.
I think we should validate the address here
| use processing_core::app_mut; | ||
| use processing_core::error::{ProcessingError, Result}; | ||
|
|
||
| pub use rosc::{OscArray, OscMessage, OscType}; |
There was a problem hiding this comment.
nit: these leak into our public rust api. not a big deal for now and can easily be a follow up but we should try to either redefine them or opaquely newtype them.
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.OscMessageobjects withaddress,args,typetag(e.g."ff"for two floats),hostandport.str(msg)gives a readable form like/mouse 0.52 0.25.Changes
crates/processing_osc/crates/processing_core/src/error.rssrc/lib.rs,src/prelude.rs: addOscPluginand export theosc_*functionscrates/processing_pyo3/src/osc.rs: converts Python values to OSC types, defines theOscMessageclass &&crates/processing_pyo3/src/lib.rs: registers the Python functions andOscMessageexamples/osc.rsandcrates/processing_pyo3/examples/osc.pyroscinstead ofnannou_osc, sincenannou_oscdoesn't have a Bevy plugin. we could probably switch later without changing the API!some limitations
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