Skip to content

Commit

Permalink
Merge pull request #9 from BlackPhlox/0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackPhlox authored Jun 8, 2022
2 parents 774b7b7 + 82bc07e commit e4e7fc6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
<a href="https://github.com/bevyengine/bevy/blob/main/docs/plugins_guidelines.md#main-branch-tracking"><img src="https://img.shields.io/badge/Bevy%20tracking-released%20version-lightblue" alt="tracking bevy release branch"></a>
</div>
</br>
A plugin that uses [nannou_osc](https://github.com/nannou-org/nannou/tree/master/nannou_osc) that allows you to send (not yet implemented) and receive osc data for all who wants to control bevy from other programs or controllers.

A plugin that uses [nannou_osc](https://github.com/nannou-org/nannou/tree/master/nannou_osc) that allows you to send and receive osc data for all who wants to control bevy from other programs or controllers.

# Setup

To test `simple` and the `custom` example:
To test `simple`, `send` and the `custom` example:
1. Install [orca](https://hundredrabbits.itch.io/orca)
2. Copy/paste [this](https://git.sr.ht/~rabbits/orca-examples/tree/master/basics/_osc.orca) snippet into the program
3. Go to Communication -> Choose OSC Port and enter `34254`
Expand All @@ -30,6 +31,7 @@ https://user-images.githubusercontent.com/25123512/122121093-81b57300-ce2b-11eb-
|---|---|
|0.5|0.1.X|
|0.6|0.2.X|
|0.7|0.3.X|

# Licensing
The project is under dual license MIT and Apache 2.0, so joink to your hearts content, just remember the license agreements.
Expand Down
39 changes: 39 additions & 0 deletions examples/send.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use bevy::prelude::*;
use bevy_osc::{Osc, OscEvent, OscSender, OscSettings};
use nannou_osc::{Message, Packet, Type};

fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugin(Osc)
.insert_resource(OscSettings {
recv_addr: Some("127.0.0.1:34254"),
send_addr: Some("127.0.0.1:34254"),
log: false,
..Default::default()
})
.add_system(event_listener_system)
.add_system(event_sender_system)
.run();
}

//Make events a type param?
fn event_listener_system(mut events: EventReader<OscEvent>) {
for my_event in events.iter() {
info!("OSC Package: {:?}", my_event.packet);
}
}

//Notice: This is system sends a packet roughly every second, look at the fixed_timestep bevy example for a higher accuracy
fn event_sender_system(events: Option<Res<OscSender>>, time: Res<Time>, mut last_time: Local<f64>) {
let lst = time.seconds_since_startup() - *last_time;
if lst > 1.0 {
if let Some(sender) = events {
let _ = sender.send(Packet::Message(Message {
addr: "/c".to_string(),
args: Some(vec![Type::Int(1), Type::Int(2), Type::Int(3)]),
}));
}
*last_time = time.seconds_since_startup();
}
}
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use bevy::prelude::{App, Commands, EventWriter, Plugin, Res, ResMut};
use bevy::prelude::{App, Commands, Deref, EventWriter, Plugin, Res, ResMut};
use nannou_osc as osc;
use osc::{Connected, Receiver, Sender};

struct OscReceiver {
pub struct OscReceiver {
receiver: Receiver,
}

#[derive(Deref)]
#[allow(dead_code)]
struct OscSender {
sender: Sender<Connected>,
pub struct OscSender {
pub sender: Sender<Connected>,
}

#[derive(Clone)]
Expand Down

0 comments on commit e4e7fc6

Please sign in to comment.