rstmt_core/notes/aspn.rs
1/*
2 Appellation: aspn <module>
3 Contrib: @FL03
4*/
5use crate::octave::Octave;
6
7/// An american scientific pitch notation ([`Aspn`]) representation of a musical note; this
8/// standard is used to represent notes in a way that is consistent with the
9/// American scientific pitch notation system, which uses a combination of a pitch class
10/// (represented as an integer) and an octave (represented as an [`Octave`]) to uniquely
11/// identify a musical note. The pitch class is the note's position in the chromatic scale,
12/// while the octave indicates the note's position in the musical range.
13#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
14#[cfg_attr(
15 feature = "serde",
16 derive(serde::Deserialize, serde::Serialize),
17 serde(deny_unknown_fields, default, rename_all = "snake_case")
18)]
19#[repr(C)]
20pub struct Aspn {
21 pub(crate) class: usize,
22 pub(crate) octave: Octave,
23}
24
25/// The [`AsAspn`] trait is used to convert a reference into a [`Aspn`]
26pub trait AsAspn {
27 fn as_aspn(&self) -> Aspn;
28}
29/// A trait for converting a type into a [`Aspn`]
30pub trait IntoAspn {
31 fn into_aspn(self) -> Aspn;
32}
33/*
34 ************* Implementations *************
35*/
36impl<T> AsAspn for T
37where
38 T: Clone + IntoAspn,
39{
40 fn as_aspn(&self) -> Aspn {
41 self.clone().into_aspn()
42 }
43}
44
45impl<T> IntoAspn for T
46where
47 T: Into<Aspn>,
48{
49 fn into_aspn(self) -> Aspn {
50 self.into()
51 }
52}