pub struct Key { /* private fields */ }Expand description
A tonal key with a tonic pitch and mode.
Implementations§
Source§impl Key
impl Key
Sourcepub fn color(&self) -> Option<&str>
pub fn color(&self) -> Option<&str>
The colour the key’s signature is drawn in, if one was said.
Sourcepub fn set_color(&mut self, color: Option<String>)
pub fn set_color(&mut self, color: Option<String>)
Sets the colour the key’s signature is drawn in.
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 and the colour it is drawn in.
Sourcepub fn scale(&self) -> Scale
pub fn scale(&self) -> Scale
The scale this key is written in: its tonic, and the diatonic mode that tonic stands on within the key’s own signature.
The mode is read off the signature rather than the mode’s name, so
every key has one. The church modes come out as themselves, D dorian
as ScaleType::Dorian on D, and a mode music21 keeps no signature for
takes the major signature on its tonic, as music21 gives it, and so
reads as major.
music21’s own Key.getScale answers the relative major for a church
mode, a C major scale for D dorian. The crate answers the mode.
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 pitch_from_degree(&self, degree: usize) -> Result<Pitch>
pub fn pitch_from_degree(&self, degree: usize) -> Result<Pitch>
The pitch on a one-based scale degree, counting on up past the
octave: in C major the ninth degree is D5, which is what stacking
thirds on the upper degrees needs. A tonic given with no octave is
read in octave 4.
Scale::pitch_at_degree is music21’s pitchFromDegree, which reads
the eighth degree as the tonic again.
Sourcepub fn pitches(&self) -> Result<Vec<Pitch>>
pub fn pitches(&self) -> Result<Vec<Pitch>>
The scale’s pitches from the tonic up to its octave, eight in all.
Sourcepub fn triad_from_degree(&self, degree: usize) -> Result<Chord>
pub fn triad_from_degree(&self, degree: usize) -> Result<Chord>
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>
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>,
Source§impl From<Key> for StreamElement
impl From<Key> for StreamElement
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