Skip to content

Commit 6761aea

Browse files
committed
Reorganized code after rebase
1 parent 48783f9 commit 6761aea

File tree

6 files changed

+45
-60
lines changed

6 files changed

+45
-60
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/processing_midi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ edition = "2024"
55

66
[dependencies]
77
bevy = { workspace = true }
8+
processing_core = { workspace = true }
89
bevy_midi = { git = "https://github.com/BlackPhlox/bevy_midi", branch = "latest" }
910

10-
1111
[lints]
1212
workspace = true

crates/processing_midi/src/lib.rs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
11
use bevy::prelude::*;
22
use bevy_midi::prelude::*;
33

4+
use processing_core::error::Result;
5+
46
pub struct MidiPlugin;
57

68
impl Plugin for MidiPlugin {
79
fn build(&self, app: &mut App) {
10+
// TODO: Update `bevy_midi` to treat connections as entities
11+
// in order to support hot-plugging
812
app.insert_resource(MidiOutputSettings {
9-
port_name: "output",
10-
})
11-
.add_plugins(MidiOutputPlugin);
13+
port_name: "libprocessing output",
14+
});
15+
16+
app.add_plugins(MidiOutputPlugin);
17+
}
18+
}
19+
20+
pub fn connect(In(port): In<usize>, output: Res<MidiOutput>) -> Result<()> {
21+
if let Some((_, port)) = output.ports().get(port) {
22+
output.connect(port.clone());
1223
}
24+
Ok(())
1325
}
1426

15-
pub fn connect(_port: usize) {
16-
// we need to work with the ECS
17-
// do we pass a MidiCommand to Bevy?
27+
pub fn disconnect(output: Res<MidiOutput>) -> Result<()> {
28+
output.disconnect();
29+
Ok(())
1830
}
1931

20-
pub fn disconnect() {}
21-
pub fn refresh_ports() {}
32+
pub fn refresh_ports(output: Res<MidiOutput>) -> Result<()> {
33+
output.refresh_ports();
34+
Ok(())
35+
}
36+
37+
pub fn play_notes(In((note, duration)): In<(u8, u64)>, output: Res<MidiOutput>) -> Result<()> {
38+
output.send([0b1001_0000, note, 127].into()); // Note on, channel 1, max velocity
39+
40+
std::thread::sleep(std::time::Duration::from_millis(duration));
2241

23-
pub fn play_notes() {}
42+
output.send([0b1000_0000, note, 127].into()); // Note on, channel 1, max velocity
43+
44+
Ok(())
45+
}

crates/processing_render/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ raw-window-handle = "0.6"
2121
half = "2.7"
2222
crossbeam-channel = "0.5"
2323
processing_core = { workspace = true }
24+
processing_midi = { workspace = true }
2425

2526
[build-dependencies]
2627
wesl = { workspace = true, features = ["package"] }

crates/processing_render/src/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod graphics;
44
pub mod image;
55
pub mod light;
66
pub mod material;
7-
pub mod midi;
87
pub mod render;
98
pub mod sketch;
109
pub(crate) mod surface;
@@ -1268,23 +1267,29 @@ pub fn gltf_light(gltf_entity: Entity, index: usize) -> error::Result<Entity> {
12681267
pub fn midi_refresh_ports() -> error::Result<()> {
12691268
app_mut(|app| {
12701269
let world = app.world_mut();
1271-
world.run_system_cached(midi::refresh_ports).unwrap()
1270+
world
1271+
.run_system_cached(processing_midi::refresh_ports)
1272+
.unwrap()
12721273
})
12731274
}
12741275

12751276
#[cfg(not(target_arch = "wasm32"))]
12761277
pub fn midi_connect(port: usize) -> error::Result<()> {
12771278
app_mut(|app| {
12781279
let world = app.world_mut();
1279-
world.run_system_cached_with(midi::connect, port).unwrap()
1280+
world
1281+
.run_system_cached_with(processing_midi::connect, port)
1282+
.unwrap()
12801283
})
12811284
}
12821285

12831286
#[cfg(not(target_arch = "wasm32"))]
12841287
pub fn midi_disconnect() -> error::Result<()> {
12851288
app_mut(|app| {
12861289
let world = app.world_mut();
1287-
world.run_system_cached(midi::disconnect).unwrap()
1290+
world
1291+
.run_system_cached(processing_midi::disconnect)
1292+
.unwrap()
12881293
})
12891294
}
12901295

@@ -1293,7 +1298,7 @@ pub fn midi_play_notes(note: u8, duration: u64) -> error::Result<()> {
12931298
app_mut(|app| {
12941299
let world = app.world_mut();
12951300
world
1296-
.run_system_cached_with(midi::play_notes, (note, duration))
1301+
.run_system_cached_with(processing_midi::play_notes, (note, duration))
12971302
.unwrap()
12981303
})
12991304
}

crates/processing_render/src/midi.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)