PitchClass

Struct PitchClass 

Source
pub struct PitchClass<P = CNote, K = <P as RawPitchClass>::Tag>
where P: RawPitchClass<Tag = K>, K: RawAccidental,
{ /* private fields */ }
Expand description

The PitchClass implementations works to generically define the structure for a pitch class. This is accomplished through the use of two type parameters: N, which defines the note (e.g., C, D, E, etc.), and K, which defines the kind of pitch (e.g., sharp, flat, natural, etc.).

Note: This struct isn’t designed to be used directly, rather through type aliases such as C, DSharp, EFlat, etc.

Implementations§

Source§

impl<P, K> PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source

pub fn new() -> Self
where P: Default, K: Default,

Source

pub fn from_class(class: P) -> Self
where K: Default,

Source

pub const fn as_ptr(&self) -> *const P

returns a pointer to the class

Source

pub const fn as_mut_ptr(&mut self) -> *mut P

returns a mutable pointer to the class

Source

pub fn as_frequency<T>(&self) -> Frequency<T>

convert the pitch class into a Frequency based on the standard A4 tuning

Source

pub const fn get(&self) -> &P

returns a reference to the defined class

Source

pub const fn get_mut(&mut self) -> &mut P

returns a mutable reference to the defined class

Source

pub fn is_natural(&self) -> bool
where K: 'static,

returns true if the class is considered natural

Source

pub fn is_flat(&self) -> bool
where K: 'static,

returns true if the class is considered flat

Source

pub fn is_sharp(&self) -> bool
where K: 'static,

returns true if the class is considered sharp

Source§

impl<N> PitchClass<N>
where N: RawPitchClass,

Source

pub const fn natural(class: N) -> PitchClass<N, Natural>
where N: RawPitchClass<Tag = Natural>,

initialize a new, natural pitch class

Source

pub const fn sharp(class: N) -> PitchClass<N, Sharp>
where N: RawPitchClass<Tag = Sharp>,

initialize a sharp instance of the given class

Source

pub const fn flat(class: N) -> PitchClass<N, Flat>
where N: RawPitchClass<Tag = Flat>,

initialize a flat instance of the given class

Trait Implementations§

Source§

impl<T1, A1, T2, A2> Add<PitchClass<T2, A2>> for PitchClass<T1, A1>
where T1: RawPitchClass<Tag = A1>, A1: RawAccidental, T2: RawPitchClass<Tag = A2>, A2: RawAccidental,

Add two pitch-classes producing a wrapped semitone count in the tonal space.

Note: returning a compile-time PitchClass subtype from an operator requires a type-level index; that’s not possible for arbitrary runtime sums. We therefore return an i32 semitone value (0..11) using PitchMod::pmod. Callers can convert that numeric result into any runtime/compile-time representation they prefer.

Source§

type Output = isize

The resulting type after applying the + operator.
Source§

fn add(self, rhs: PitchClass<T2, A2>) -> Self::Output

Performs the + operation. Read more
Source§

impl<P, K> AsRef<isize> for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

fn as_ref(&self) -> &isize

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<P, K> AsRef<str> for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<P, K> Borrow<isize> for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

fn borrow(&self) -> &isize

Immutably borrows from an owned value. Read more
Source§

impl<P, K> Clone for PitchClass<P, K>
where P: RawPitchClass<Tag = K> + Clone, K: RawAccidental + Clone,

Source§

fn clone(&self) -> PitchClass<P, K>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P, K> Debug for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P, K> Default for PitchClass<P, K>
where P: RawPitchClass<Tag = K> + Default, K: RawAccidental + Default,

Source§

fn default() -> PitchClass<P, K>

Returns the “default value” for a type. Read more
Source§

impl<P, K> Deref for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

type Target = P

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<P, K> Display for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P, K> FromStr for PitchClass<P, K>
where P: PitchClassRepr<Tag = K>, K: Accidental,

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<P, K> Hash for PitchClass<P, K>
where P: RawPitchClass<Tag = K> + Hash, K: RawAccidental + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<P, K> Ord for PitchClass<P, K>
where P: RawPitchClass<Tag = K> + Ord, K: RawAccidental + Ord,

Source§

fn cmp(&self, other: &PitchClass<P, K>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<P, K> PartialEq<PitchClass<P, K>> for isize
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

fn eq(&self, other: &PitchClass<P, K>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P, K> PartialEq<isize> for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

fn eq(&self, other: &isize) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P, K> PartialEq for PitchClass<P, K>
where P: RawPitchClass<Tag = K> + PartialEq, K: RawAccidental + PartialEq,

Source§

fn eq(&self, other: &PitchClass<P, K>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P, K> PartialOrd for PitchClass<P, K>

Source§

fn partial_cmp(&self, other: &PitchClass<P, K>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T1, A1, T2, A2> Sub<PitchClass<T2, A2>> for PitchClass<T1, A1>
where T1: RawPitchClass<Tag = A1>, A1: RawAccidental, T2: RawPitchClass<Tag = A2>, A2: RawAccidental,

Source§

type Output = isize

Subtract two pitch-classes producing a wrapped signed semitone interval.

Source§

fn sub(self, rhs: PitchClass<T2, A2>) -> Self::Output

Performs the - operation. Read more
Source§

impl<P, K> TryFrom<isize> for PitchClass<P, K>
where P: PitchClassRepr<Tag = K>, K: Accidental,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: isize) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<P, K> Copy for PitchClass<P, K>
where P: RawPitchClass<Tag = K> + Copy, K: RawAccidental + Copy,

Source§

impl<P, K> Eq for PitchClass<P, K>
where P: RawPitchClass<Tag = K> + Eq, K: RawAccidental + Eq,

Source§

impl<P, K> Send for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

impl<P, K> StructuralPartialEq for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Source§

impl<P, K> Sync for PitchClass<P, K>
where P: RawPitchClass<Tag = K>, K: RawAccidental,

Auto Trait Implementations§

§

impl<P, K> Freeze for PitchClass<P, K>
where P: Freeze, K: Freeze,

§

impl<P, K> RefUnwindSafe for PitchClass<P, K>

§

impl<P, K> Unpin for PitchClass<P, K>
where P: Unpin, K: Unpin,

§

impl<P, K> UnwindSafe for PitchClass<P, K>
where P: UnwindSafe, K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.