Skip to content

Commit 8c64160

Browse files
committed
ndk: Make examples in ndk::midi compilable
1 parent 83fe4b2 commit 8c64160

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

ndk/src/midi/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@ pub enum MidiOpcode {
2828
/// The length of the received message. The caller should limit the passed `buffer` slice to
2929
/// this length after [`MidiOutputPort::receive()`] returns.
3030
/// ```no_run
31-
/// let output_port: MidiOutputPort = ...;
31+
/// use ndk::midi::{MidiOutputPort, MidiOpcode};
32+
///
33+
/// let output_port: MidiOutputPort = todo!();
3234
/// let mut buffer = [0u8; 128];
3335
/// if let Ok(MidiOpcode::Data { length, .. }) = output_port.receive(&mut buffer) {
34-
/// let buffer = &buffer[..length];
35-
/// ...
36+
/// // process message
37+
/// if let [message, key, velocity] = &buffer[..length] {
38+
/// if message & 0xF0 == 0x90 { /* Note On message */ }
39+
/// else if message & 0xF0 == 0x80 { /* Note Off message */ }
40+
/// else { /* */ }
41+
/// }
3642
/// }
3743
/// ```
3844
length: usize,

0 commit comments

Comments
 (0)