pub struct Key { /* private fields */ }Expand description
A tonal key with a tonic pitch and mode.
Implementations§
Source§impl Key
impl Key
Sourcepub fn from_tonic_mode<'a, M>(tonic: &str, mode: M) -> Result<Self>
pub fn from_tonic_mode<'a, M>(tonic: &str, mode: M) -> Result<Self>
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.
Builds a key from a tonic name and a mode. Without a mode the name
decides, as music21’s Key reads it: a trailing m is minor and a
trailing M major (F#m, EM), otherwise a lower-case name is minor
and an upper-case one major.
Sourcepub fn from_tonic(tonic: &str) -> Result<Self>
pub fn from_tonic(tonic: &str) -> Result<Self>
Builds a key and infers major/minor from tonic case.
Sourcepub fn tonic_pitch(&self) -> &Pitch
pub fn tonic_pitch(&self) -> &Pitch
Returns a borrowed tonic pitch.
Sourcepub fn transpose(&self, interval: &Interval) -> Result<Self>
pub fn transpose(&self, interval: &Interval) -> Result<Self>
Returns this key moved by the interval, keeping its mode.
Sourcepub fn as_scale(&self) -> Result<Scale>
pub fn as_scale(&self) -> Result<Scale>
Returns the Scale for this key’s mode on its tonic. Major and
minor cover ionian and aeolian; the other church modes map to their
scale types, and any other mode is an error.
Sourcepub fn tonic_pitch_name_with_case(&self) -> String
pub fn tonic_pitch_name_with_case(&self) -> String
Returns the tonic name in music21’s case convention: upper case for major, lower case for minor, unchanged for other modes.
Sourcepub fn sharps(&self) -> IntegerType
pub fn sharps(&self) -> IntegerType
Returns the number of sharps in the key signature.
Sourcepub fn key_signature(&self) -> KeySignature
pub fn key_signature(&self) -> KeySignature
Returns the matching key signature.
Sourcepub fn scale(&self) -> DiatonicScale
pub fn scale(&self) -> DiatonicScale
Returns the diatonic scale for this key.
Sourcepub fn pitch_from_degree(&self, degree: usize) -> Result<Pitch>
pub fn pitch_from_degree(&self, degree: usize) -> Result<Pitch>
Returns the pitch at a one-based scale degree.
Sourcepub fn pitches(&self) -> Result<Vec<Pitch>>
pub fn pitches(&self) -> Result<Vec<Pitch>>
Returns scale pitches from degree 1 through the octave.
Sourcepub fn triad_from_degree(&self, degree: usize) -> Result<Chord>
pub fn triad_from_degree(&self, degree: usize) -> Result<Chord>
Builds the diatonic triad on a one-based degree.
Sourcepub fn seventh_chord_from_degree(&self, degree: usize) -> Result<Chord>
pub fn seventh_chord_from_degree(&self, degree: usize) -> Result<Chord>
Builds the diatonic seventh chord on a one-based degree.
Sourcepub fn harmonized_triads(&self) -> Result<Vec<Chord>>
pub fn harmonized_triads(&self) -> Result<Vec<Chord>>
Returns all seven diatonic triads.
Sourcepub fn harmonized_sevenths(&self) -> Result<Vec<Chord>>
pub fn harmonized_sevenths(&self) -> Result<Vec<Chord>>
Returns all seven diatonic seventh chords.
Sourcepub fn derive_by_degree(&self, degree: usize, pitch: &Pitch) -> Result<Self>
pub fn derive_by_degree(&self, degree: usize, pitch: &Pitch) -> Result<Self>
Returns the relative major or minor key when applicable.
Returns the key of the same mode in which pitch is the given scale
degree: music21’s deriveByDegree, so C major with E as degree 5 is
A major and A minor with C as degree 3 is A minor again.
Sourcepub fn derive_by_degree_of(
&self,
scale_type: ScaleType,
degree: usize,
pitch: &Pitch,
) -> Result<Self>
pub fn derive_by_degree_of( &self, scale_type: ScaleType, degree: usize, pitch: &Pitch, ) -> Result<Self>
The same, reading the degree off a scale pattern the caller chooses rather than the key’s own.
music21 spells this as a settable .abstract on the key: the seventh
degree of a minor key is a whole tone below the tonic in the natural
form and a semitone below it in the harmonic form, so the key that has
E as its seventh is F-sharp minor by one reading and F minor by the
other. The key that comes back keeps this one’s mode either way.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Key
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Key
serde only.Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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