forked from chris-zen/coremidi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virtual-source.rs
38 lines (29 loc) · 980 Bytes
/
virtual-source.rs
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
extern crate coremidi;
use std::time::Duration;
use std::thread;
fn main() {
let client = coremidi::Client::new("example-client").unwrap();
let source = client.virtual_source("example-source").unwrap();
let note_on = create_note_on(0, 64, 127);
let note_off = create_note_off(0, 64, 127);
for i in 0..10 {
println!("[{}] Received note ...", i);
source.received(¬e_on).unwrap();
thread::sleep(Duration::from_millis(1000));
source.received(¬e_off).unwrap();
}
}
fn create_note_on(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
let data = &[
0x90 | (channel & 0x0f),
note & 0x7f,
velocity & 0x7f];
coremidi::PacketBuffer::new(0, data)
}
fn create_note_off(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
let data = &[
0x80 | (channel & 0x0f),
note & 0x7f,
velocity & 0x7f];
coremidi::PacketBuffer::new(0, data)
}