rstmt_core/notes/impls/
impl_note_base.rs

1/*
2    Appellation: impl_note_base <module>
3    Created At: 2025.12.20:09:35:09
4    Contrib: @FL03
5*/
6use crate::notes::note_base::NoteBase;
7use crate::octave::Octave;
8use crate::pitch::{Accidental, PitchClass, PitchClassRepr, RawPitchClass};
9
10impl<P, K> NoteBase<P, K>
11where
12    P: RawPitchClass<Tag = K>,
13    K: Accidental,
14{
15    /// constructs a new [`NoteBase`] instance
16    pub const fn new(class: PitchClass<P, K>, octave: Octave) -> Self {
17        Self { class, octave }
18    }
19    /// initialize a new instance of the note from the given octave
20    pub fn from_octave(octave: Octave) -> Self
21    where
22        P: PitchClassRepr,
23    {
24        Self {
25            class: PitchClass::new(),
26            octave,
27        }
28    }
29    /// returns a reference to the current class
30    pub const fn class(&self) -> &PitchClass<P, K> {
31        &self.class
32    }
33    /// returns a mutable reference to the current class
34    pub const fn class_mut(&mut self) -> &mut PitchClass<P, K> {
35        &mut self.class
36    }
37    /// returns a reference to the current octave
38    pub const fn octave(&self) -> &Octave {
39        &self.octave
40    }
41    /// returns a mutable reference to the current octave
42    pub const fn octave_mut(&mut self) -> &mut Octave {
43        &mut self.octave
44    }
45    /// returns string formatted following the American Standard Pitch Notation (ASPN) of:
46    /// "C.4", "D#.5", etc.
47    pub fn aspn(&self) -> String {
48        format!("{}.{}", self.class().name(), self.octave().value())
49    }
50}