Skip to content

Commit 5c88e04

Browse files
committed
stub midi example code
1 parent 87caa62 commit 5c88e04

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ processing_midi = { path = "crates/processing_midi" }
3030
[dependencies]
3131
bevy = { workspace = true }
3232
processing_render = { workspace = true }
33+
processing_midi = { workspace = true }
3334

3435
[dev-dependencies]
3536
glfw = "0.60.0"
@@ -77,6 +78,10 @@ path = "examples/materials.rs"
7778
name = "pbr"
7879
path = "examples/pbr.rs"
7980

81+
[[example]]
82+
name = "midi"
83+
path = "examples/midi.rs"
84+
8085
[profile.wasm-release]
8186
inherits = "release"
8287
opt-level = "z"

crates/processing_midi/src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
use bevy::prelude::*;
2+
use bevy_midi::prelude::*;
23

34
pub struct MidiPlugin;
45

56
impl Plugin for MidiPlugin {
67
fn build(&self, app: &mut App) {
7-
dbg!(app);
8+
app.insert_resource(MidiOutputSettings {
9+
port_name: "output",
10+
})
11+
.add_plugins(MidiOutputPlugin);
812
}
913
}
14+
15+
enum MidiCommand {}
16+
17+
pub fn connect(port: usize) {
18+
// we need to work with the ECS
19+
// do we pass a MidiCommand to Bevy?
20+
}
21+
22+
pub fn disconnect() {}
23+
pub fn refresh_ports() {}
24+
25+
pub fn play_notes() {}

examples/midi.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
mod glfw;
2+
3+
use glfw::GlfwContext;
4+
use processing::prelude::*;
5+
use processing_render::render::command::DrawCommand;
6+
7+
fn main() {
8+
match sketch() {
9+
Ok(_) => {
10+
eprintln!("Sketch completed successfully");
11+
exit(0).unwrap();
12+
}
13+
Err(e) => {
14+
eprintln!("Sketch error: {:?}", e);
15+
exit(1).unwrap();
16+
}
17+
};
18+
}
19+
20+
fn sketch() -> error::Result<()> {
21+
let mut glfw_ctx = GlfwContext::new(400, 400)?;
22+
init(Config::default())?;
23+
24+
let width = 400;
25+
let height = 400;
26+
let scale_factor = 1.0;
27+
28+
let surface = glfw_ctx.create_surface(width, height, scale_factor)?;
29+
let graphics = graphics_create(surface, width, height)?;
30+
31+
processing_midi::connect(0);
32+
33+
while glfw_ctx.poll_events() {
34+
graphics_begin_draw(graphics)?;
35+
36+
graphics_record_command(
37+
graphics,
38+
DrawCommand::Rect {
39+
x: 10.0,
40+
y: 10.0,
41+
w: 100.0,
42+
h: 100.0,
43+
radii: [0.0, 0.0, 0.0, 0.0],
44+
},
45+
)?;
46+
47+
graphics_end_draw(graphics)?;
48+
}
49+
Ok(())
50+
}

0 commit comments

Comments
 (0)