rstmt_core/pitch/impls/
impl_pclass.rs1use crate::freq::{Frequency, RawFrequency};
7use crate::pitch::{Flat, Natural, PitchClass, RawAccidental, RawPitchClass, Sharp};
8use num_traits::{Float, FromPrimitive};
9
10impl<P, K> PitchClass<P, K>
11where
12 P: RawPitchClass<Tag = K>,
13 K: RawAccidental,
14{
15 pub fn new() -> Self
16 where
17 P: Default,
18 K: Default,
19 {
20 Self {
21 class: P::default(),
22 kind: K::default(),
23 }
24 }
25
26 pub fn from_class(class: P) -> Self
27 where
28 K: Default,
29 {
30 Self {
31 class,
32 kind: K::default(),
33 }
34 }
35 pub const fn as_ptr(&self) -> *const P {
37 core::ptr::from_ref(self.get())
38 }
39 pub const fn as_mut_ptr(&mut self) -> *mut P {
41 core::ptr::from_mut(self.get_mut())
42 }
43 pub fn as_frequency<T>(&self) -> Frequency<T>
45 where
46 P: RawPitchClass<Tag = K>,
47 K: RawAccidental,
48 T: RawFrequency + Float + FromPrimitive,
49 {
50 Frequency::from_class_on_a4(self.get().index())
51 }
52 pub const fn get(&self) -> &P {
54 &self.class
55 }
56 pub const fn get_mut(&mut self) -> &mut P {
58 &mut self.class
59 }
60 pub fn is_natural(&self) -> bool
62 where
63 K: 'static,
64 {
65 Natural::of::<K>()
66 }
67 pub fn is_flat(&self) -> bool
69 where
70 K: 'static,
71 {
72 Flat::of::<K>()
73 }
74 pub fn is_sharp(&self) -> bool
76 where
77 K: 'static,
78 {
79 Sharp::of::<K>()
80 }
81}