pub struct KeySignature { /* private fields */ }Expand description
A key signature represented by the number of sharps.
Flats are represented as negative sharps, so B-flat major has -2.
Implementations§
Source§impl KeySignature
impl KeySignature
Sourcepub fn new(sharps: IntegerType) -> Self
pub fn new(sharps: IntegerType) -> Self
Creates a key signature from a sharp count.
Sourcepub fn from_altered_pitches(pitches: Vec<Pitch>) -> Self
pub fn from_altered_pitches(pitches: Vec<Pitch>) -> Self
Creates a non-traditional key signature from the pitches it alters,
as music21 does when alteredPitches is assigned: E- and G#
together, say, which no count of sharps can express. Such a signature
has no sharp count and no key.
Sourcepub fn sharps(&self) -> Option<IntegerType>
pub fn sharps(&self) -> Option<IntegerType>
Returns the number of sharps, with flats as negative values, or
None for a non-traditional signature.
Sourcepub fn set_sharps(&mut self, sharps: IntegerType)
pub fn set_sharps(&mut self, sharps: IntegerType)
Replaces the sharp count, turning a non-traditional signature back into a traditional one.
Sourcepub fn set_altered_pitches(&mut self, pitches: Vec<Pitch>)
pub fn set_altered_pitches(&mut self, pitches: Vec<Pitch>)
Replaces the altered pitches, turning the signature non-traditional.
Sourcepub fn is_non_traditional(&self) -> bool
pub fn is_non_traditional(&self) -> bool
Whether the signature is a list of altered pitches rather than a count of sharps or flats.
music21’s isNonTraditional. There sharps answers nought when this
is true; Self::sharps answers None, which says both things at
once.
Sourcepub fn set_non_traditional(&mut self, non_traditional: bool)
pub fn set_non_traditional(&mut self, non_traditional: bool)
Makes the signature non-traditional, or traditional again: the setter
of music21’s isNonTraditional.
Turning it on drops the sharp count and starts an empty list of altered pitches; turning it off restores a count of nought. Setting it to what it already is does nothing.
Sourcepub fn accidentals_apply_only_to_octave(&self) -> bool
pub fn accidentals_apply_only_to_octave(&self) -> bool
Whether the altered pitches of a non-traditional signature carry
octaves that limit where they apply, as F#4 altering only that
octave. music21 records the flag; applying it is a stream’s job.
Sourcepub fn set_accidentals_apply_only_to_octave(&mut self, value: bool)
pub fn set_accidentals_apply_only_to_octave(&mut self, value: bool)
Sets whether the altered pitches apply only in their own octave.
Sourcepub fn description(&self) -> String
pub fn description(&self) -> String
The description music21 prints after of: 3 sharps, 1 flat,
no sharps or flats, or pitches: [E-, G#].
Sourcepub fn altered_pitches(&self) -> Result<Vec<Pitch>>
pub fn altered_pitches(&self) -> Result<Vec<Pitch>>
Returns the pitches this signature alters, in circle-of-fifths order
and without octaves: F# C# G# for three sharps, B- E- A- for three
flats; a non-traditional signature answers the pitches it was given.
Sourcepub fn accidental_by_step(&self, step: char) -> Result<Option<Accidental>>
pub fn accidental_by_step(&self, step: char) -> Result<Option<Accidental>>
Returns the accidental this signature puts on a step letter, if any.
Sourcepub fn transpose(&self, interval: &Interval) -> Result<Self>
pub fn transpose(&self, interval: &Interval) -> Result<Self>
Returns the signature of the major key this one’s major tonic moves to by the interval.
Sourcepub fn transpose_pitch_from_c(&self, pitch: &Pitch) -> Result<Pitch>
pub fn transpose_pitch_from_c(&self, pitch: &Pitch) -> Result<Pitch>
Transposes a pitch spelled in C into this key signature the way
music21’s transposePitchFromC does: up a fifth per sharp, or up a
fourth per flat, keeping the pitch’s own octave, so E4 in two sharps
is F#4 and in three flats G4.
Trait Implementations§
Source§impl Clone for KeySignature
impl Clone for KeySignature
Source§fn clone(&self) -> KeySignature
fn clone(&self) -> KeySignature
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KeySignature
impl Debug for KeySignature
Source§impl<'de> Deserialize<'de> for KeySignature
Available on crate feature serde only.
impl<'de> Deserialize<'de> for KeySignature
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 Display for KeySignature
impl Display for KeySignature
Source§impl From<KeySignature> for StreamElement
impl From<KeySignature> for StreamElement
Source§fn from(value: KeySignature) -> Self
fn from(value: KeySignature) -> Self
Auto Trait Implementations§
impl Freeze for KeySignature
impl RefUnwindSafe for KeySignature
impl Send for KeySignature
impl Sync for KeySignature
impl Unpin for KeySignature
impl UnsafeUnpin for KeySignature
impl UnwindSafe for KeySignature
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