pub struct Scale(_);
Expand description

A scale is a list of notes. For example, the C2 Major scale contains the notes [C2, D2, E2, F2, G2, A3, B3].

Example:

use music_theory::theory::*;
let scale = Scale::wrap(
    vec![Note::C1, Note::D1, Note::E1, Note::F1, Note::G1, Note::A2, Note::B2]
).unwrap();
assert!(scale.contains_all(&[Note::E1, Note::A2]));

Implementations§

source§

impl Scale

source

pub fn as_octave_steps(&self) -> Option<Steps>

Will try to convert the scale to steps that define an octave scale. This means it needs to fit into one octave. It will add a last step so the steps wrap back onto the first note.

Example:

use music_theory::theory::*;
let W = Interval::WHOLE;
let H = Interval::SEMI;
assert_eq!( // C Major
    Scale::wrap(vec![Note::C1, Note::D1, Note::E1, Note::F1, Note::G1, Note::A2, Note::B2])
        .unwrap().as_octave_steps(),
    Steps::wrap(vec![W, W, H, W, W, W, H])
);

Trait Implementations§

source§

impl AsChord for Scale

source§

fn as_chord(&self) -> Chord

Borrow self and return a Chord.
source§

impl AsEnharmonicNotes for Scale

source§

fn as_enharmonic_notes(&self) -> Vec<EnharmonicNote>

Borrow self and return a vector of EnharmonicNote.
source§

impl AsEnharmonicNotesWithStart for Scale

source§

fn as_enharmonic_notes_with_start( &self, start: Option<EnharmonicNote> ) -> Vec<EnharmonicNote>

Borrow self and return a vector of EnharmonicNote. You can optionally specify a starting note. This will affect the spelling. Subsequent notes will be spelled with subsequent letters.
source§

impl AsPCs for Scale

source§

fn as_pcs(&self) -> PCs

Borrow self and return PCs.
source§

impl AsRootedChord for Scale

source§

fn as_rooted_chord(&self) -> RootedChord

Borrow self and return a RootedChord.
source§

impl AsSteps for Scale

source§

fn as_steps(&self, complete_octave_cycle: bool) -> Steps

Borrow self and return Steps. complete_octave_cycle instructs whether the steps should wrap around the starting note to complete the octave.
source§

impl AsSubs for Scale

source§

fn as_subs(&self, max_len: Option<usize>) -> Vec<Self>

Generate all subs sets with optional maximal subset length. The output size of this grows really fast with the input size so be aware: 2, 5, 16, 65, 326, 1957, 13700, 109601, 986410, 9864101, 108505112.
source§

impl Clone for Scale

source§

fn clone(&self) -> Scale

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 Scale

source§

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

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

impl Default for Scale

source§

fn default() -> Scale

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

impl Hash for Scale

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 Index<usize> for Scale

§

type Output = Note

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for Scale

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl ModeTrait for Scale

source§

fn next_mode_mut(&mut self)

Modify the value so it turns into it’s next mode.
source§

fn next_mode(self) -> Self

Take the value and give back it’s next mode.
source§

fn mode(self, mode: Mode) -> Self

Take the value and give back it’s Nth mode.
source§

impl Ord for Scale

source§

fn cmp(&self, other: &Scale) -> Ordering

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

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

impl PartialEq<Scale> for Scale

source§

fn eq(&self, other: &Scale) -> 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 PartialOrd<Scale> for Scale

source§

fn partial_cmp(&self, other: &Scale) -> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl VecWrapper for Scale

§

type Item = Note

The type the new type wraps.
source§

fn len(&self) -> usize

Return the length of the inner vector.
source§

fn is_empty(&self) -> bool

Return whether the inner vector is empty or not.
source§

fn iter(&self) -> Iter<'_, Self::Item>

Iterate over the inner vector.
source§

fn contains(&self, item: &Self::Item) -> bool

Returns whether the inner vector contains an item.
source§

fn contains_all(&self, items: &[Self::Item]) -> bool

Returns whether the inner vector contains all of the given items.
source§

fn contains_any(&self, items: &[Self::Item]) -> bool

Returns whether the inner vector contains any of the given items.
source§

impl Wrapper for Scale

§

type Inner = Vec<Note, Global>

The type the new type wraps.
source§

fn wrap(scale: Self::Inner) -> Option<Self>

Try to wrap a Self::Inner type into the Self type.
source§

fn unwrap(self) -> Self::Inner

Unwrap a Self type into a Self::Inner type.
source§

impl Eq for Scale

source§

impl StructuralEq for Scale

source§

impl StructuralPartialEq for Scale

Auto Trait Implementations§

§

impl RefUnwindSafe for Scale

§

impl Send for Scale

§

impl Sync for Scale

§

impl Unpin for Scale

§

impl UnwindSafe for Scale

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ModeIteratorSpawner<T> for Twhere T: ModeTrait + VecWrapper,

source§

fn mode_iter(self) -> ModeIterator<T>

Spawn the mode iterator.
source§

impl<T> ToChord for Twhere T: AsChord,

source§

fn to_chord(self) -> Chord

Take self and return Chord.
source§

impl<T> ToEnharmonicNotes for Twhere T: AsEnharmonicNotes,

source§

fn to_enharmonic_notes(self) -> Vec<EnharmonicNote, Global>

Take self and return a vector of EnharmonicNote.
source§

impl<T> ToEnharmonicNotesWithStart for Twhere T: AsEnharmonicNotesWithStart,

source§

fn to_enharmonic_notes_with_start( self, start: Option<EnharmonicNote> ) -> Vec<EnharmonicNote, Global>

Take self and return a vector of EnharmonicNote. You can optionally specify a starting note. This will affect the spelling. Subsequent notes will be spelled with subsequent letters.
source§

impl<T> ToOwned for Twhere 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> ToPCs for Twhere T: AsPCs,

source§

fn to_pcs(self) -> Vec<PC, Global>

Take self and return PCs.
source§

impl<T> ToRootedChord for Twhere T: AsRootedChord,

source§

fn to_rooted_chord(self) -> RootedChord

Take self and return a RootedChord.
source§

impl<T> ToSteps for Twhere T: AsSteps,

source§

fn to_steps(self, complete_octave_cycle: bool) -> Steps

Take self and return Steps. complete_octave_cycle instructs whether the steps should wrap around the starting note to complete the octave.
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.