use sim_lib_pitch_core::PitchClass;
use sim_lib_serial_core::{AlphabetError, AlphabetId, FiniteAlphabet, SerialAlphabet};
const CANONICAL_CLASSES: [PitchClass; 12] = [
PitchClass::C,
PitchClass::CS,
PitchClass::D,
PitchClass::DS,
PitchClass::E,
PitchClass::F,
PitchClass::FS,
PitchClass::G,
PitchClass::GS,
PitchClass::A,
PitchClass::AS,
PitchClass::B,
];
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PitchClassAlphabet {
inner: FiniteAlphabet<PitchClass>,
}
impl PitchClassAlphabet {
pub fn try_new() -> Result<Self, AlphabetError> {
Ok(Self {
inner: FiniteAlphabet::try_new(
AlphabetId::try_new("pitch-class/12tet-v1")?,
CANONICAL_CLASSES.to_vec(),
)?,
})
}
pub fn id(&self) -> &AlphabetId {
self.inner.id()
}
pub fn classes(&self) -> &[PitchClass] {
self.inner.symbols()
}
}
impl SerialAlphabet for PitchClassAlphabet {
type Symbol = PitchClass;
fn id(&self) -> &AlphabetId {
self.inner.id()
}
fn symbols(&self) -> &[Self::Symbol] {
self.inner.symbols()
}
}