rstmt_core/note/
impl_aspn.rs

1/*
2    Appellation: impl_aspn <module>
3    Created At: 2025.12.20:08:16:03
4    Contrib: @FL03
5*/
6use super::Aspn;
7use crate::octave::Octave;
8use rstmt_traits::PitchMod;
9
10impl Aspn {
11    pub fn new(class: usize, Octave(octave): Octave) -> Self {
12        Self {
13            class,
14            octave: Octave(octave),
15        }
16    }
17    /// returns a new note from a pitch value
18    pub fn from_pitch(pitch: usize) -> Self {
19        Self::new(pitch.pmod(), Octave(4))
20    }
21    /// returns a copy to the index of the note's class
22    pub const fn class(&self) -> usize {
23        self.class
24    }
25    /// returns a mutable reference to the index of the note's class
26    pub fn class_mut(&mut self) -> &mut usize {
27        &mut self.class
28    }
29    /// returns a copy to the octave of the note
30    pub const fn octave(&self) -> Octave {
31        self.octave
32    }
33    /// returns a mutable reference to the current octave
34    pub const fn octave_mut(&mut self) -> &mut Octave {
35        &mut self.octave
36    }
37    /// set the pitch class of the note
38    pub fn set_class(&mut self, class: usize) -> &mut Self {
39        self.class = class.pmod();
40        self
41    }
42    /// set the octave of the note
43    pub fn set_octave(&mut self, octave: Octave) -> &mut Self {
44        self.octave = octave;
45        self
46    }
47    /// consumes the current instance to create another with the given pitch class
48    pub fn with_class(self, class: usize) -> Self {
49        Self { class, ..self }
50    }
51    /// consumes the current instance to create another with the given octave
52    pub fn with_octave(self, octave: Octave) -> Self {
53        Self { octave, ..self }
54    }
55}