rstmt_core/pitch/traits/
classifiers.rs

1/*
2    Appellation: classifiers <module>
3    Created At: 2025.12.21:09:08:08
4    Contrib: @FL03
5*/
6use crate::pitch::RawAccidental;
7use rstmt_traits::PitchMod;
8
9/// The [`RawPitchClass`] is a sealed trait used to define raw pitch class types.
10pub trait RawPitchClass
11where
12    Self: Send
13        + Sync
14        + AsRef<str>
15        + AsRef<isize>
16        + PartialEq<isize>
17        + PartialEq<str>
18        + core::borrow::Borrow<isize>
19        + core::fmt::Debug
20        + core::fmt::Display,
21{
22    type Tag: RawAccidental;
23
24    private! {}
25
26    fn new() -> Self
27    where
28        Self: Sized;
29    /// returns the name of the pitch class; i.e., "C", "D", "E", etc.
30    fn name(&self) -> &str;
31    /// returns the value associated with the pitch class
32    fn index(&self) -> isize;
33}
34
35/// [`PitchClassRepr`] extends [`RawPitchClass`], providing various initialization routines,
36/// defaults, and other methods useful for pitch class representations.
37pub trait PitchClassRepr: RawPitchClass
38where
39    Self: Default + core::str::FromStr<Err = crate::error::Error> + TryFrom<isize>,
40{
41    const IDX: isize;
42
43    /// returns true if the given value corresponds to this pitch class
44    fn is(value: isize) -> bool
45    where
46        Self: Sized,
47    {
48        value.pmod() == Self::IDX
49    }
50}