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.
A non-traditional signature, E- and G# together, is flagged as one
and lists its pitches; it keeps a count as well, as music21’s does
since 14acfa0f2.
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:
E- and G# together, say, which no count of sharps can express.
Its count is nought.
Sourcepub fn sharps(&self) -> IntegerType
pub fn sharps(&self) -> IntegerType
Returns the number of sharps, with flats as negative values.
Sourcepub fn set_sharps(&mut self, sharps: IntegerType)
pub fn set_sharps(&mut self, sharps: IntegerType)
Replaces the sharp count, leaving the flag and any pitches written
over it as they are, as music21’s sharps setter does.
Sourcepub fn set_altered_pitches(&mut self, pitches: Vec<Pitch>)
pub fn set_altered_pitches(&mut self, pitches: Vec<Pitch>)
Writes pitches over the ones the count implies, as music21’s
alteredPitches setter does. It does not make the signature
non-traditional; Self::set_non_traditional does that.
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.
Sourcepub fn set_non_traditional(&mut self, non_traditional: bool)
pub fn set_non_traditional(&mut self, non_traditional: bool)
Flags the signature non-traditional or traditional, its count and pitches left as they are.
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, drawn in the colour this one is.
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§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
Source§impl PartialEq for KeySignature
impl PartialEq for KeySignature
Auto Trait Implementations§
impl Forget for KeySignature
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