Skip to content

Commit c9e6e98

Browse files
committed
midi example is sufficient
1 parent d5cd798 commit c9e6e98

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

Cargo.lock

Lines changed: 25 additions & 2 deletions
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
@@ -49,6 +49,7 @@ web-sys = { version = "0.3", features = ["Window"] }
4949

5050
[dev-dependencies]
5151
glfw = "0.60.0"
52+
rand = "0.10.0"
5253

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

crates/processing_render/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,11 +1281,11 @@ pub fn midi_connect(port: usize) -> error::Result<()> {
12811281
}
12821282

12831283
#[cfg(not(target_arch = "wasm32"))]
1284-
pub fn midi_play_notes(note: u8) -> error::Result<()> {
1284+
pub fn midi_play_notes(note: u8, duration: u64) -> error::Result<()> {
12851285
app_mut(|app| {
12861286
let world = app.world_mut();
12871287
world
1288-
.run_system_cached_with(midi::play_notes, note)
1288+
.run_system_cached_with(midi::play_notes, (note, duration))
12891289
.unwrap()
12901290
})
12911291
}

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(_) => {
@@ -28,7 +30,8 @@ fn sketch() -> error::Result<()> {
2830

2931
midi_refresh_ports()?;
3032
midi_connect(0)?;
31-
midi_play_notes(60)?;
33+
34+
let mut rng = rand::rng();
3235

3336
while glfw_ctx.poll_events() {
3437
graphics_begin_draw(graphics)?;
@@ -46,7 +49,10 @@ fn sketch() -> error::Result<()> {
4649

4750
graphics_end_draw(graphics)?;
4851

49-
midi_play_notes(60)?;
52+
let note = rng.random_range(57..68);
53+
let note_duration = rng.random_range(25..250);
54+
midi_play_notes(note, note_duration)?;
5055
}
56+
5157
Ok(())
5258
}

0 commit comments

Comments
 (0)