Skip to main content

Scale

Struct Scale 

Source
pub struct Scale {
    pub tonic: PitchClass,
    pub mode: Mode,
}
Expand description

A concrete scale: a Mode anchored to a tonic pitch class.

§Examples

use sim_lib_pitch_core::PitchClass;
use sim_lib_pitch_scale::Scale;

let c_major = Scale::major(PitchClass::C);
assert_eq!(c_major.degree_of(PitchClass::G), Some(5));

Fields§

§tonic: PitchClass

The tonic pitch class.

§mode: Mode

The mode of the scale.

Implementations§

Source§

impl Scale

Source

pub const fn new(tonic: PitchClass, mode: Mode) -> Self

Constructs a scale from a tonic and mode.

Source

pub const fn major(tonic: PitchClass) -> Self

Constructs a major scale on tonic.

Source

pub const fn minor_natural(tonic: PitchClass) -> Self

Constructs a natural minor scale on tonic.

Source

pub const fn minor_harmonic(tonic: PitchClass) -> Self

Constructs a harmonic minor scale on tonic.

Source

pub const fn minor_melodic(tonic: PitchClass) -> Self

Constructs a melodic minor scale on tonic.

Source

pub const fn dorian(tonic: PitchClass) -> Self

Constructs a Dorian scale on tonic.

Source

pub const fn phrygian(tonic: PitchClass) -> Self

Constructs a Phrygian scale on tonic.

Source

pub const fn lydian(tonic: PitchClass) -> Self

Constructs a Lydian scale on tonic.

Source

pub const fn mixolydian(tonic: PitchClass) -> Self

Constructs a Mixolydian scale on tonic.

Source

pub const fn aeolian(tonic: PitchClass) -> Self

Constructs an Aeolian scale on tonic.

Source

pub const fn locrian(tonic: PitchClass) -> Self

Constructs a Locrian scale on tonic.

Source

pub const fn whole_tone(tonic: PitchClass) -> Self

Constructs a whole-tone scale on tonic.

Source

pub const fn diminished(tonic: PitchClass) -> Self

Constructs a diminished (octatonic) scale on tonic.

Source

pub const fn chromatic(tonic: PitchClass) -> Self

Constructs a chromatic scale on tonic.

Source

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

Returns the scale’s pitch classes in ascending degree order from the tonic.

Source

pub fn mask(self) -> PitchClassMask

Returns the scale’s pitch classes as a PitchClassMask.

Source

pub fn degree_of(self, pitch_class: PitchClass) -> Option<usize>

Returns the one-based scale degree of pitch_class, or None if it is not in the scale.

Source

pub fn pitch_at_degree( self, degree: usize, ) -> Result<PitchClass, PitchScaleError>

Returns the pitch class at the one-based degree, wrapping past the octave.

Source

pub fn try_pitch_at_degree( self, degree: usize, ) -> Result<PitchClass, PitchScaleError>

Returns the pitch class at the one-based degree, wrapping past the octave.

Source

pub fn transpose_diatonic( self, pitch: Pitch, steps: i32, ) -> Result<Pitch, PitchScaleError>

Transposes pitch by steps scale degrees, staying within the scale and adjusting octaves as needed.

Returns PitchScaleError::PitchClassOutOfScale if pitch is not a member of the scale.

Source

pub fn chord_tone_to_scale_tone( chord_tone: usize, ) -> Result<usize, PitchScaleError>

Maps a one-based chord-tone index (root, third, fifth, …) to the one-based scale degree it occupies in tertian stacking.

Source

pub fn scale_tone_to_diatonic(scale_tone: usize) -> Result<i32, PitchScaleError>

Maps a one-based scale degree to its zero-based diatonic step offset from the tonic.

Trait Implementations§

Source§

impl Clone for Scale

Source§

fn clone(&self) -> Scale

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Scale

Source§

impl Debug for Scale

Source§

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

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

impl Eq for Scale

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 PartialEq for Scale

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Scale

Auto Trait Implementations§

§

impl Freeze for Scale

§

impl RefUnwindSafe for Scale

§

impl Send for Scale

§

impl Sync for Scale

§

impl Unpin for Scale

§

impl UnsafeUnpin for Scale

§

impl UnwindSafe for Scale

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