rstmt_core/comp/impls/
impl_scale.rs1use crate::comp::Scale;
7use crate::freq::{Frequency, IntoFrequency, RawFrequency};
8use num_traits::{Float, FromPrimitive};
9
10impl<T> Scale<T> {
11 pub const fn new(root: T) -> Self {
12 Self {
13 root: Frequency(root),
14 }
15 }
16 pub const fn from_freq(root: Frequency<T>) -> Self {
18 Self { root }
19 }
20 pub const fn root(&self) -> &Frequency<T> {
22 &self.root
23 }
24 pub const fn root_mut(&mut self) -> &mut Frequency<T> {
26 &mut self.root
27 }
28 pub fn classify(&self, Frequency(freq): Frequency<T>) -> Option<isize>
34 where
35 T: RawFrequency + Float + FromPrimitive,
36 {
37 if freq <= T::zero() {
39 return None;
40 }
41 crate::classify_freq_with_scale(freq, self.root().value())
42 }
43 pub fn get_freq_of_class(&self, n: isize) -> Frequency<T>
49 where
50 T: RawFrequency + Float + FromPrimitive,
51 {
52 crate::compute_freq_of_pitch(n, self.root().value()).into_frequency()
53 }
54}