pub struct PitchClass(/* private fields */);Expand description
A mod-12 pitch class, where C = 0 and values increase by semitone to B = 11.
Pitch classes are octave-agnostic: every C, regardless of register, shares the
pitch class C. The inner u8 is always in the range 0..12.
§Examples
use sim_lib_pitch_core::PitchClass;
assert_eq!(PitchClass::C.transpose(7), PitchClass::G);
assert_eq!(PitchClass::E.interval_class(PitchClass::C), 4);Implementations§
Source§impl PitchClass
impl PitchClass
Sourcepub fn new(value: u8) -> Result<Self, PitchError>
pub fn new(value: u8) -> Result<Self, PitchError>
Constructs a pitch class from a raw value, rejecting values of 12 or more.
Sourcepub fn transpose(self, semitones: i32) -> Self
pub fn transpose(self, semitones: i32) -> Self
Returns this pitch class shifted up by semitones (or down if negative),
wrapping within the mod-12 octave.
Sourcepub fn invert(self, axis: PitchClass) -> Self
pub fn invert(self, axis: PitchClass) -> Self
Returns the inversion of this pitch class about axis, wrapping within the
mod-12 octave.
Sourcepub fn interval_class(self, other: PitchClass) -> u8
pub fn interval_class(self, other: PitchClass) -> u8
Returns the interval class (0..=6) between this pitch class and other,
the smaller of the ascending and descending distances.
Sourcepub fn canonical_name(self) -> &'static str
pub fn canonical_name(self) -> &'static str
Returns the canonical sharp-spelled name of this pitch class (for example
"C#" for pitch class 1).
Trait Implementations§
Source§impl Clone for PitchClass
impl Clone for PitchClass
Source§fn clone(&self) -> PitchClass
fn clone(&self) -> PitchClass
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for PitchClass
Source§impl Debug for PitchClass
impl Debug for PitchClass
impl Eq for PitchClass
Source§impl Hash for PitchClass
impl Hash for PitchClass
Source§impl Ord for PitchClass
impl Ord for PitchClass
Source§fn cmp(&self, other: &PitchClass) -> Ordering
fn cmp(&self, other: &PitchClass) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for PitchClass
impl PartialEq for PitchClass
Source§impl PartialOrd for PitchClass
impl PartialOrd for PitchClass
impl StructuralPartialEq for PitchClass
Auto Trait Implementations§
impl Freeze for PitchClass
impl RefUnwindSafe for PitchClass
impl Send for PitchClass
impl Sync for PitchClass
impl Unpin for PitchClass
impl UnsafeUnpin for PitchClass
impl UnwindSafe for PitchClass
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more