Expand description
This is a plugin implementing OSC for bevy using rosc
.
§Basic usage
Add the BevyRoscPlugin
to your app, choosing the ip address at which you want to receive at.
Then add either the SingleAddressOscMethod
or MultiAddressOscMethod
component to your entity.
bevy_rosc
will automatically deliver matching messages to the component, where you can then retrieve them with the get_address
method.
use bevy::prelude::*;
use bevy_rosc::OscDispatcher;
use bevy_rosc::SingleAddressOscMethod;
use bevy_rosc::OscMethod;
use bevy_rosc::BevyRoscPlugin;
fn spawn(mut commands: Commands) {
commands
.spawn(SingleAddressOscMethod::new("/test/address".into()).unwrap());
}
fn print_received_osc_packets(mut query: Query<&mut SingleAddressOscMethod, (Changed<SingleAddressOscMethod>)>) {
for mut osc_method in query.iter_mut() {
match osc_method.get_message() {
Some(message) => println!("Method {:?} received: {:?}", osc_method.get_address(), message),
None => {}
}
}
}
fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(BevyRoscPlugin::new("0.0.0.0:31337").unwrap())
.add_systems(Startup, spawn)
.add_systems(Update, print_received_osc_packets)
.run();
}
§Advanced usage
There is the option to add custom osc method components.
Your component just has to implement OscMethod
and you need to add a method_dispatcher_system
for it.
Now your component will receive OSC messages at it’s address(es).
extern crate bevy_rosc;
use bevy::prelude::*;
use bevy_rosc::OscMethod;
use bevy_rosc::{method_dispatcher_system, BevyRoscPlugin};
use rosc::address::OscAddress;
use rosc::OscMessage;
#[derive(Component)]
struct MyOscMethod {
osc_address: OscAddress,
}
impl OscMethod for MyOscMethod {
fn get_addresses(&self) -> Vec<OscAddress> {
return vec![self.osc_address.clone()];
}
// This method is called when an OSC message was successfully matched with the method
fn receive_message(&mut self, osc_message: OscMessage) {
println!("MyOscMethod received: {:?}", osc_message)
}
}
fn startup(mut commands: Commands) {
commands.spawn(MyOscMethod {
osc_address: OscAddress::new("/test/address".into()).unwrap(),
});
}
fn main() {
App::new()
.add_plugins(MinimalPlugins)
.add_plugins(BevyRoscPlugin::new("0.0.0.0:31337").unwrap())
.add_systems(Update, method_dispatcher_system::<MyOscMethod>) // <-- Add dispatcher system for your method
.add_systems(Startup, startup)
.run();
}
Structs§
- Plugin implementing the default functionality for bevy_rosc
- Bevy component that can receive OSC messages at multiple addresses
- An event containing all OSC messages that were received this frame and their corresponding
rosc::address::Matcher
s - Dispatches received
OscPacket
s and sends theOscDispatchEvent
, which ultimately delivers messages to matchingOscMethod
s. - Bevy component that can receive OSC messages at one addresses
Traits§
- An OSC Method is capable of receiving OSC messages at one or multiple addresses.
Functions§
- This reads
OscDispatchEvent
s sent by the dispatcher and forwards the incoming messages toOscMethod
s