Created
September 23, 2024 09:33
-
-
Save FauxFaux/0d705f0cb492d62d78d038a5be0c1c31 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use bitfield_struct::bitfield; | |
#[bitfield(u8)] | |
struct Status { | |
#[bits(4)] | |
tag: u8, | |
#[bits(4)] | |
channel: u8, | |
} | |
enum Tags { | |
NoteOff, | |
NoteOn, | |
Cc, | |
PitchBend, | |
} | |
fn parse_status(status: u8) -> Option<(Tags, u8)> { | |
let status = Status::from(status); | |
use Tags::*; | |
let tag = match status.tag() { | |
0x8 => NoteOff, | |
0x9 => NoteOn, | |
0xB => Cc, | |
0xE => PitchBend, | |
_ => return None, | |
}; | |
Some((tag, status.channel())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment