use crate::freq::{Frequency, RawFrequency};
use crate::pitch::{Accidental, Flat, Natural, PitchClass, RawPitchClass, Sharp};
use num_traits::{Float, FromPrimitive};
impl<P, K> PitchClass<P, K>
where
P: RawPitchClass<Tag = K>,
K: Accidental,
{
pub fn new() -> Self {
Self {
class: P::new(),
kind: K::new(),
}
}
pub fn from_class(class: P) -> Self {
Self {
class,
kind: K::new(),
}
}
pub fn from_kind(kind: K) -> Self {
Self {
class: P::new(),
kind,
}
}
pub const fn as_ptr(&self) -> *const P {
core::ptr::from_ref(self.get())
}
pub const fn as_mut_ptr(&mut self) -> *mut P {
core::ptr::from_mut(self.get_mut())
}
pub fn as_frequency<T>(&self) -> Frequency<T>
where
P: RawPitchClass<Tag = K>,
K: Accidental,
T: RawFrequency + Float + FromPrimitive,
{
Frequency::from_class_on_a4(self.get().index())
}
pub const fn get(&self) -> &P {
&self.class
}
pub const fn get_mut(&mut self) -> &mut P {
&mut self.class
}
pub fn is_natural(&self) -> bool
where
K: 'static,
{
Natural::of::<K>()
}
pub fn is_flat(&self) -> bool
where
K: 'static,
{
Flat::of::<K>()
}
pub fn is_sharp(&self) -> bool
where
K: 'static,
{
Sharp::of::<K>()
}
}