Debian Codegraph @

third_party/rust/coremidi/examples/virtual-source.rs

raw
1 extern crate coremidi;
2
3 use std::thread;
4 use std::time::Duration;
5
6 fn main() {
7 let client = coremidi::Client::new("Example Client").unwrap();
8 let source = client.virtual_source("Example Source").unwrap();
9
10 let note_on = create_note_on(0, 64, 127);
11 let note_off = create_note_off(0, 64, 127);
12
13 for i in 0..10 {
14 println!("[{}] Sending note...", i);
15
16 source.received(&note_on).unwrap();
17
18 thread::sleep(Duration::from_millis(1000));
19
20 source.received(&note_off).unwrap();
21 }
22 }
23
24 fn create_note_on(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
25 let data = &[0x90 | (channel & 0x0f), note & 0x7f, velocity & 0x7f];
26 coremidi::PacketBuffer::new(0, data)
27 }
28
29 fn create_note_off(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
30 let data = &[0x80 | (channel & 0x0f), note & 0x7f, velocity & 0x7f];
31 coremidi::PacketBuffer::new(0, data)
32 }