#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum JumpAt {
Now,
Beat,
Bar,
End,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct NoticeMask(pub u8);
impl NoticeMask {
pub const MARKER: NoticeMask = NoticeMask(1);
pub const BAR: NoticeMask = NoticeMask(1 << 1);
pub const BEAT: NoticeMask = NoticeMask(1 << 2);
pub const LOOP: NoticeMask = NoticeMask(1 << 3);
pub const JUMP: NoticeMask = NoticeMask(1 << 4);
pub const FINISHED: NoticeMask = NoticeMask(1 << 5);
pub const SFX: NoticeMask = NoticeMask(1 << 6);
pub const TRANSPOSE: NoticeMask = NoticeMask(1 << 7);
pub const NONE: NoticeMask = NoticeMask(0);
pub const ALL: NoticeMask = NoticeMask(0xff);
pub const DEFAULT: NoticeMask = NoticeMask(0x7f & !(1 << 1) & !(1 << 2));
pub const fn contains(self, other: NoticeMask) -> bool {
self.0 & other.0 == other.0
}
pub const fn union(self, other: NoticeMask) -> NoticeMask {
NoticeMask(self.0 | other.0)
}
}
impl Default for NoticeMask {
fn default() -> Self {
NoticeMask::DEFAULT
}
}
impl core::ops::BitOr for NoticeMask {
type Output = NoticeMask;
fn bitor(self, rhs: NoticeMask) -> NoticeMask {
self.union(rhs)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SeqNotice {
Marker { index: u8 },
Bar(u32),
Beat { bar: u32, beat: u8 },
Looped(u32),
Jumped { marker: u8 },
Finished,
Transposed { track: u8 },
}
impl SeqNotice {
pub const fn mask(&self) -> NoticeMask {
match self {
SeqNotice::Marker { .. } => NoticeMask::MARKER,
SeqNotice::Bar(_) => NoticeMask::BAR,
SeqNotice::Beat { .. } => NoticeMask::BEAT,
SeqNotice::Looped(_) => NoticeMask::LOOP,
SeqNotice::Jumped { .. } => NoticeMask::JUMP,
SeqNotice::Finished => NoticeMask::FINISHED,
SeqNotice::Transposed { .. } => NoticeMask::TRANSPOSE,
}
}
}
#[derive(Debug, Clone, Copy)]
pub(crate) struct NoticeQueue<const N: usize> {
buf: [SeqNotice; N],
head: usize,
len: usize,
pub(crate) mask: NoticeMask,
}
impl<const N: usize> NoticeQueue<N> {
pub(crate) const NEW: Self = NoticeQueue {
buf: [SeqNotice::Finished; N],
head: 0,
len: 0,
mask: NoticeMask::DEFAULT,
};
pub(crate) fn push(&mut self, n: SeqNotice) {
if N == 0 || !self.mask.contains(n.mask()) {
return;
}
let at = (self.head + self.len) % N;
self.buf[at] = n;
if self.len < N {
self.len += 1;
} else {
self.head = (self.head + 1) % N;
}
}
pub(crate) fn pop(&mut self) -> Option<SeqNotice> {
if self.len == 0 {
return None;
}
let n = self.buf[self.head];
self.head = (self.head + 1) % N;
self.len -= 1;
Some(n)
}
}