use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub(super) struct Bits(pub(super) [u32; PARAM_IDS / 32]);
impl Bits {
pub(super) const EMPTY: Bits = Bits([0; PARAM_IDS / 32]);
pub(super) fn has(&self, i: u8) -> bool {
self.0[i as usize / 32] & (1 << (i % 32)) != 0
}
pub(super) fn set(&mut self, i: u8) {
self.0[i as usize / 32] |= 1 << (i % 32);
}
pub(super) fn clear(&mut self, i: u8) {
self.0[i as usize / 32] &= !(1 << (i % 32));
}
}
#[derive(Debug, Clone, Copy)]
pub(super) struct ParamTable<const K: usize> {
pub(super) ids: [u8; K],
pub(super) values: [u32; K],
pub(super) len: usize,
}
impl<const K: usize> ParamTable<K> {
pub(super) const EMPTY: Self = ParamTable {
ids: [0; K],
values: [0; K],
len: 0,
};
pub(super) fn get(&self, id: u8) -> Option<u32> {
self.ids[..self.len]
.iter()
.position(|&i| i == id)
.map(|i| self.values[i])
}
pub(super) fn put(&mut self, id: u8, value: u32) {
if let Some(i) = self.ids[..self.len].iter().position(|&i| i == id) {
self.values[i] = value;
} else if self.len < K {
self.ids[self.len] = id;
self.values[self.len] = value;
self.len += 1;
}
}
pub(super) fn iter(&self) -> impl Iterator<Item = (u8, u32)> + '_ {
self.ids[..self.len]
.iter()
.copied()
.zip(self.values[..self.len].iter().copied())
}
}
#[derive(Debug, Clone, Copy)]
pub(super) struct Shadow<const K: usize> {
pub(super) tone: Option<u8>,
pub(super) wave: Option<[i8; crate::WAVE_LEN]>,
pub(super) wave_before_tone: bool,
pub(super) wave_seq: u32,
pub(super) params: ParamTable<K>,
pub(super) initial: ParamTable<K>,
pub(super) on: bool,
pub(super) keys: [u8; CHORD_MAX],
pub(super) nkeys: u8,
pub(super) vel: u8,
pub(super) pitch: i32,
}
impl<const K: usize> Shadow<K> {
pub(super) const EMPTY: Self = Shadow {
tone: None,
wave: None,
wave_before_tone: false,
wave_seq: 0,
params: ParamTable::EMPTY,
initial: ParamTable::EMPTY,
on: false,
keys: [0; CHORD_MAX],
nkeys: 0,
vel: 0,
pitch: 0,
};
}
#[derive(Debug, Clone, Copy)]
pub(super) struct Slot<const K: usize> {
pub(super) active: bool,
pub(super) priority: u8,
pub(super) map: [u8; MAX_SFX_TRACKS],
pub(super) tracks: u8,
pub(super) touched: Bits,
pub(super) touched_track: Bits,
pub(super) saved: [ParamTable<K>; MAX_SFX_TRACKS],
pub(super) saved_global: ParamTable<K>,
}
impl<const K: usize> Slot<K> {
pub(super) const EMPTY: Slot<K> = Slot {
active: false,
priority: 0,
map: [0; MAX_SFX_TRACKS],
tracks: 0,
touched: Bits::EMPTY,
touched_track: Bits::EMPTY,
saved: [ParamTable::EMPTY; MAX_SFX_TRACKS],
saved_global: ParamTable::EMPTY,
};
}