-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmidi.rs
More file actions
60 lines (48 loc) · 1.38 KB
/
midi.rs
File metadata and controls
60 lines (48 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use processing_glfw::GlfwContext;
use processing::prelude::*;
use processing_render::render::command::DrawCommand;
use rand::prelude::*;
fn main() {
match sketch() {
Ok(_) => {
eprintln!("Sketch completed successfully");
exit(0).unwrap();
}
Err(e) => {
eprintln!("Sketch error: {:?}", e);
exit(1).unwrap();
}
};
}
fn sketch() -> error::Result<()> {
let mut glfw_ctx = GlfwContext::new(400, 400)?;
init(Config::default())?;
let width = 400;
let height = 400;
let surface = glfw_ctx.create_surface(width, height)?;
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
midi_refresh_ports()?;
for port in midi_list_ports()? {
println!("{port}");
}
midi_connect(1)?;
let mut rng = rand::rng();
while glfw_ctx.poll_events() {
graphics_begin_draw(graphics)?;
graphics_record_command(
graphics,
DrawCommand::Rect {
x: 10.0,
y: 10.0,
w: 100.0,
h: 100.0,
radii: [0.0, 0.0, 0.0, 0.0],
},
)?;
graphics_end_draw(graphics)?;
let note = rng.random_range(57..68);
let note_duration = rng.random_range(25..250);
midi_play_notes(note, note_duration)?;
}
Ok(())
}