Struct redact_composer_musical::PitchClass

source ·
pub struct PitchClass(pub u8);
Expand description

An octave-independent note.

Tuple Fields§

§0: u8

Implementations§

source§

impl PitchClass

source

pub fn values() -> Vec<PitchClass>

Returns all valid PitchClass values (0..=11).

source

pub fn all_in_range<R: RangeBounds<Note>>(range: R) -> Vec<PitchClass>

Returns all pitch classes contained in the given note range.

use redact_composer_musical::{Note, NoteName::{C, F}, PitchClass as PC};

assert_eq!(
    PC::all_in_range(Note::from((C, 3))..=Note::from((F, 3))),
    vec![PC(0), PC(1), PC(2), PC(3), PC(4), PC(5)]
);

assert_eq!(
    PC::all_in_range(Note::from((C, 3))..=Note::from((C, 5))),
    PC::values()
);
source

pub fn in_octave(&self, octave: i8) -> Note

Returns the Note with this pitch class in a given octave.

use redact_composer_musical::{Note, NoteName::C, PitchClass};

assert_eq!(PitchClass::from(C).in_octave(4), Note(60));
source

pub fn above(&self, note: &Note) -> Note

Returns the next Note of this pitch class above the given note. If the given note is already of this pitch class, the note an octave above is returned.

use redact_composer_musical::{Note, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(G).above(&Note::from((C, 3))), Note::from((G, 3)));
assert_eq!(PitchClass::from(G).above(&Note::from((G, 3))), Note::from((G, 4)));
source

pub fn at_or_above(&self, note: &Note) -> Note

Returns the next Note of this pitch class at or above the given note.

use redact_composer_musical::{Note, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(G).at_or_above(&Note::from((C, 3))), Note::from((G, 3)));
assert_eq!(PitchClass::from(G).at_or_above(&Note::from((G, 3))), Note::from((G, 3)));
source

pub fn below(&self, note: &Note) -> Note

Returns the next Note of this pitch class below the given note. If the given note is already of this pitch class, the note an octave below is returned.

use redact_composer_musical::{Note, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(G).below(&Note::from((C, 3))), Note::from((G, 2)));
assert_eq!(PitchClass::from(G).below(&Note::from((G, 3))), Note::from((G, 2)));
source

pub fn at_or_below(&self, note: &Note) -> Note

Returns the next Note of this pitch class at or below the given note.

use redact_composer_musical::{Note, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(G).at_or_below(&Note::from((C, 3))), Note::from((G, 2)));
assert_eq!(PitchClass::from(G).at_or_below(&Note::from((G, 3))), Note::from((G, 3)));
source

pub fn interval_to(&self, other: &PitchClass) -> Interval

Returns the simple interval (ascending) from this pitch class to the nearest other pitch class.

use redact_composer_musical::{Interval, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(C).interval_to(&G.into()), Interval::P5);
source

pub fn interval_from(&self, other: &PitchClass) -> Interval

Returns the simple interval (ascending) from some other pitch class to this one.

use redact_composer_musical::{Interval, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(C).interval_from(&G.into()), Interval::P4);
source§

impl PitchClass

source

pub fn names(&self) -> Vec<NoteName>

Provides the note names matching this pitch class.

source

pub fn name_in_key(&self, key: &Key) -> NoteName

Returns this pitch class’s name within the context of a Key. Pitch classes not in the given key will return some variation of a name equating to the pitch class, but exactly which is subject to change.

Trait Implementations§

source§

impl Add<Interval> for PitchClass

source§

fn add(self, rhs: Interval) -> Self::Output

Returns the pitch class a given interval above this.

use redact_composer_musical::{Interval as I, NoteName::{C, G}, PitchClass};

assert_eq!(PitchClass::from(C) + I::P5, PitchClass::from(G));
assert_eq!(PitchClass::from(C) + I::Octave, PitchClass::from(C));
§

type Output = PitchClass

The resulting type after applying the + operator.
source§

impl AddAssign<Interval> for PitchClass

source§

fn add_assign(&mut self, rhs: Interval)

Performs the += operation. Read more
source§

impl Clone for PitchClass

source§

fn clone(&self) -> PitchClass

Returns a copy 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 Debug for PitchClass

source§

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

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

impl From<Note> for PitchClass

source§

fn from(value: Note) -> Self

Converts to this type from the input type.
source§

impl From<NoteName> for PitchClass

source§

fn from(value: NoteName) -> Self

Converts to this type from the input type.
source§

impl From<u8> for PitchClass

source§

fn from(value: u8) -> Self

Converts to this type from the input type.
source§

impl Hash for PitchClass

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 NoteIterator for PitchClass

source§

fn iter_notes_in_range<R: RangeBounds<Note>>( &self, note_range: R ) -> NoteIter<R>

Returns a note iterator (NoteIter) for notes of an interval pattern within the given note range.
source§

fn notes_in_range<R: RangeBounds<Note>>(&self, note_range: R) -> Vec<Note>

Returns all notes matching an interval pattern within the given note range.
source§

impl PartialEq<NoteName> for PitchClass

source§

fn eq(&self, note_name: &NoteName) -> bool

use redact_composer_musical::{NoteName::C, PitchClass};
assert!(PitchClass(0).eq(&C));
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<PitchClass> for Note

source§

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

use redact_composer_musical::{Note, NoteName::C, PitchClass};

assert!(Note::from((C, 3)) == PitchClass::from(C));
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<PitchClass> for NoteName

source§

fn eq(&self, pitch_class: &PitchClass) -> bool

use redact_composer_musical::{NoteName, PitchClass};
assert!(NoteName::C.eq(&PitchClass(0)));
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for PitchClass

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PitchClassCollection for PitchClass

source§

fn pitch_classes(&self) -> Vec<PitchClass>

Returns this type’s pitches.
source§

impl Sub<Interval> for PitchClass

source§

fn sub(self, rhs: Interval) -> Self::Output

Returns the pitch class a given interval below this.

use redact_composer_musical::{Interval as I, NoteName::{C, F}, PitchClass};

assert_eq!(PitchClass::from(C) - I::P5, PitchClass::from(F));
assert_eq!(PitchClass::from(C) - I::Octave, PitchClass::from(C));
§

type Output = PitchClass

The resulting type after applying the - operator.
source§

impl SubAssign<Interval> for PitchClass

source§

fn sub_assign(&mut self, rhs: Interval)

Performs the -= operation. Read more
source§

impl Copy for PitchClass

source§

impl Eq for PitchClass

source§

impl StructuralPartialEq for PitchClass

Auto Trait Implementations§

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> 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<T> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V