Skip to content

Instantly share code, notes, and snippets.

@FauxFaux
Created September 23, 2024 09:33
Show Gist options
  • Save FauxFaux/0d705f0cb492d62d78d038a5be0c1c31 to your computer and use it in GitHub Desktop.
Save FauxFaux/0d705f0cb492d62d78d038a5be0c1c31 to your computer and use it in GitHub Desktop.
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