rstmt_core/pitch/impls/
impl_pclass.rs1use crate::freq::{Frequency, RawFrequency};
7use crate::pitch::{Accidental, Flat, Natural, PitchClass, RawPitchClass, Sharp};
8use num_traits::{Float, FromPrimitive};
9
10impl<P, K> PitchClass<P, K>
11where
12 P: RawPitchClass<Tag = K>,
13 K: Accidental,
14{
15 pub fn new() -> Self {
16 Self {
17 class: P::new(),
18 kind: K::new(),
19 }
20 }
21
22 pub fn from_class(class: P) -> Self {
23 Self {
24 class,
25 kind: K::new(),
26 }
27 }
28
29 pub fn from_kind(kind: K) -> Self {
30 Self {
31 class: P::new(),
32 kind,
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: Accidental,
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}