Skip to content

Commit 5b1a825

Browse files
committed
midi example is sufficient
1 parent 412495d commit 5b1a825

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

Cargo.lock

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ processing_render = { workspace = true }
3232

3333
[dev-dependencies]
3434
glfw = "0.60.0"
35+
rand = "0.10.0"
3536

3637
[target.'cfg(target_os = "linux")'.dev-dependencies]
3738
glfw = { version = "0.60.0", features = ["wayland"] }

crates/processing_render/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use config::*;
1919
#[cfg(not(target_arch = "wasm32"))]
2020
use bevy::log::tracing_subscriber;
2121
use bevy::render::RenderPlugin;
22-
use bevy::render::settings::{RenderCreation, WgpuSettings};
2322
use bevy::{
2423
app::{App, AppExit},
2524
asset::{AssetEventSystems, io::AssetSourceBuilder},
@@ -1411,11 +1410,11 @@ pub fn midi_connect(port: usize) -> error::Result<()> {
14111410
}
14121411

14131412
#[cfg(not(target_arch = "wasm32"))]
1414-
pub fn midi_play_notes(note: u8) -> error::Result<()> {
1413+
pub fn midi_play_notes(note: u8, duration: u64) -> error::Result<()> {
14151414
app_mut(|app| {
14161415
let world = app.world_mut();
14171416
world
1418-
.run_system_cached_with(midi::play_notes, note)
1417+
.run_system_cached_with(midi::play_notes, (note, duration))
14191418
.unwrap()
14201419
})
14211420
}

crates/processing_render/src/midi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ pub fn refresh_ports(output: Res<MidiOutput>) -> Result<()> {
3333
Ok(())
3434
}
3535

36-
pub fn play_notes(In(note): In<u8>, output: Res<MidiOutput>) -> Result<()> {
36+
pub fn play_notes(In((note, duration)): In<(u8, u64)>, output: Res<MidiOutput>) -> Result<()> {
3737
output.send([0b1001_0000, note, 127].into()); // Note on, channel 1, max velocity
3838

39-
// output.send([0b1000_0000, note, 127].into()); // Note on, channel 1, max velocity
39+
std::thread::sleep(std::time::Duration::from_millis(duration));
40+
41+
output.send([0b1000_0000, note, 127].into()); // Note on, channel 1, max velocity
4042

4143
Ok(())
4244
}

examples/midi.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use glfw::GlfwContext;
44
use processing::prelude::*;
55
use processing_render::render::command::DrawCommand;
66

7+
use rand::prelude::*;
8+
79
fn main() {
810
match sketch() {
911
Ok(_) => {
@@ -30,7 +32,8 @@ fn sketch() -> error::Result<()> {
3032

3133
midi_refresh_ports()?;
3234
midi_connect(0)?;
33-
midi_play_notes(60)?;
35+
36+
let mut rng = rand::rng();
3437

3538
while glfw_ctx.poll_events() {
3639
graphics_begin_draw(graphics)?;
@@ -48,7 +51,10 @@ fn sketch() -> error::Result<()> {
4851

4952
graphics_end_draw(graphics)?;
5053

51-
midi_play_notes(60)?;
54+
let note = rng.random_range(57..68);
55+
let note_duration = rng.random_range(25..250);
56+
midi_play_notes(note, note_duration)?;
5257
}
58+
5359
Ok(())
5460
}

0 commit comments

Comments
 (0)