Skip to main content

Key

Struct Key 

Source
pub struct Key { /* private fields */ }
Expand description

A tonal key with a tonic pitch and mode.

Implementations§

Source§

impl Key

Source

pub fn from_tonic_mode<'a, M>(tonic: &str, mode: M) -> Result<Self>
where M: Into<Option<&'a str>>,

Builds a key from a tonic and mode.

Pass a mode string such as "major", "minor", "dorian", or None::<&str> to infer major/minor from tonic case.

Source

pub fn from_tonic(tonic: &str) -> Result<Self>

Builds a key and infers major/minor from tonic case.

Source

pub fn tonic(&self) -> Pitch

Returns a cloned tonic pitch.

Source

pub fn tonic_pitch(&self) -> &Pitch

Returns a borrowed tonic pitch.

Source

pub fn mode(&self) -> &str

Returns the key mode.

Source

pub fn sharps(&self) -> IntegerType

Returns the number of sharps in the key signature.

Source

pub fn key_signature(&self) -> KeySignature

Returns the matching key signature.

Source

pub fn scale(&self) -> DiatonicScale

Returns the diatonic scale for this key.

Source

pub fn pitch_from_degree(&self, degree: usize) -> Result<Pitch>

Returns the pitch at a one-based scale degree.

Source

pub fn pitches(&self) -> Result<Vec<Pitch>>

Returns scale pitches from degree 1 through the octave.

Source

pub fn triad_from_degree(&self, degree: usize) -> Result<Chord>

Builds the diatonic triad on a one-based degree.

Source

pub fn seventh_chord_from_degree(&self, degree: usize) -> Result<Chord>

Builds the diatonic seventh chord on a one-based degree.

Source

pub fn harmonized_triads(&self) -> Result<Vec<Chord>>

Returns all seven diatonic triads.

Source

pub fn harmonized_sevenths(&self) -> Result<Vec<Chord>>

Returns all seven diatonic seventh chords.

Source

pub fn relative(&self) -> Result<Self>

Returns the relative major or minor key when applicable.

Source

pub fn parallel(&self) -> Result<Self>

Returns the parallel major or minor key when applicable.

Trait Implementations§

Source§

impl Clone for Key

Source§

fn clone(&self) -> Key

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 Debug for Key

Source§

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

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

impl FromStr for Key

Source§

type Err = Error

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

fn from_str(value: &str) -> Result<Self>

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

impl TryFrom<&str> for Key

Source§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<String> for Key

Source§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnsafeUnpin for Key

§

impl UnwindSafe for Key

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.