Skip to content

Commit 07983d5

Browse files
committed
PacketBuffer rewrite
Main improvement is that small packet lists are allocated directly on the stack. When adding packets to a list, it is now also possible for them to be merged with previous packets (same behaviour as MIDIPacketListAdd).
1 parent f554dd3 commit 07983d5

File tree

4 files changed

+291
-112
lines changed

4 files changed

+291
-112
lines changed

examples/send.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ fn print_destinations() {
6868
}
6969

7070
fn create_note_on(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
71-
let data = vec![
71+
let data = &[
7272
0x90 | (channel & 0x0f),
7373
note & 0x7f,
7474
velocity & 0x7f];
75-
coremidi::PacketBuffer::from_data(0, data)
75+
coremidi::PacketBuffer::new(0, data)
7676
}
7777

7878
fn create_note_off(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
79-
let data = vec![
79+
let data = &[
8080
0x80 | (channel & 0x0f),
8181
note & 0x7f,
8282
velocity & 0x7f];
83-
coremidi::PacketBuffer::from_data(0, data)
83+
coremidi::PacketBuffer::new(0, data)
8484
}

examples/virtual-source.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ fn main() {
2222
}
2323

2424
fn create_note_on(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
25-
let data = vec![
25+
let data = &[
2626
0x90 | (channel & 0x0f),
2727
note & 0x7f,
2828
velocity & 0x7f];
29-
coremidi::PacketBuffer::from_data(0, data)
29+
coremidi::PacketBuffer::new(0, data)
3030
}
3131

3232
fn create_note_off(channel: u8, note: u8, velocity: u8) -> coremidi::PacketBuffer {
33-
let data = vec![
33+
let data = &[
3434
0x80 | (channel & 0x0f),
3535
note & 0x7f,
3636
velocity & 0x7f];
37-
coremidi::PacketBuffer::from_data(0, data)
37+
coremidi::PacketBuffer::new(0, data)
3838
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use std::thread;
1717
let client = coremidi::Client::new("example-client").unwrap();
1818
let output_port = client.output_port("example-port").unwrap();
1919
let destination = coremidi::Destination::from_index(0).unwrap();
20-
let note_on = coremidi::PacketBuffer::from_data(0, vec![0x90, 0x40, 0x7f]);
21-
let note_off = coremidi::PacketBuffer::from_data(0, vec![0x80, 0x40, 0x7f]);
20+
let note_on = coremidi::PacketBuffer::new(0, &[0x90, 0x40, 0x7f]);
21+
let note_off = coremidi::PacketBuffer::new(0, &[0x80, 0x40, 0x7f]);
2222
output_port.send(&destination, &note_on).unwrap();
2323
thread::sleep(Duration::from_millis(1000));
2424
output_port.send(&destination, &note_off).unwrap();
@@ -121,7 +121,7 @@ pub struct Port { object: Object }
121121
/// let client = coremidi::Client::new("example-client").unwrap();
122122
/// let output_port = client.output_port("example-port").unwrap();
123123
/// let destination = coremidi::Destination::from_index(0).unwrap();
124-
/// let packets = coremidi::PacketBuffer::from_data(0, vec![0x90, 0x40, 0x7f]);
124+
/// let packets = coremidi::PacketBuffer::new(0, &[0x90, 0x40, 0x7f]);
125125
/// output_port.send(&destination, &packets).unwrap();
126126
/// ```
127127
#[derive(Debug)]

0 commit comments

Comments
 (0)