rstmt_core/note/
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 super::NoteBase;
7use crate::octave::Octave;
8use crate::pitch::{Accidental, PitchClass, PitchClassRepr, RawAccidental, RawPitchClass};
9
10impl<P, K> NoteBase<P, K>
11where
12    P: RawPitchClass<Tag = K>,
13    K: RawAccidental,
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        K: Accidental,
24    {
25        Self {
26            class: PitchClass::new(),
27            octave,
28        }
29    }
30    /// returns a reference to the current class
31    pub const fn class(&self) -> &PitchClass<P, K> {
32        &self.class
33    }
34    /// returns a mutable reference to the current class
35    pub const fn class_mut(&mut self) -> &mut PitchClass<P, K> {
36        &mut self.class
37    }
38    /// returns a reference to the current octave
39    pub const fn octave(&self) -> &Octave {
40        &self.octave
41    }
42    /// returns a mutable reference to the current octave
43    pub const fn octave_mut(&mut self) -> &mut Octave {
44        &mut self.octave
45    }
46    /// returns string formatted following the American Standard Pitch Notation (ASPN) of:
47    /// "C.4", "D#.5", etc.
48    pub fn aspn(&self) -> String {
49        format!("{}.{}", self.class().name(), self.octave().value())
50    }
51}