Skip to main content

KeySignature

Struct KeySignature 

Source
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

Source

pub fn new(sharps: IntegerType) -> Self

Creates a key signature from a sharp count.

Source

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.

Source

pub fn sharps(&self) -> Option<IntegerType>

Returns the number of sharps, with flats as negative values, or None for a non-traditional signature.

Source

pub fn set_sharps(&mut self, sharps: IntegerType)

Replaces the sharp count, turning a non-traditional signature back into a traditional one.

Source

pub fn set_altered_pitches(&mut self, pitches: Vec<Pitch>)

Replaces the altered pitches, turning the signature non-traditional.

Source

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.

Source

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.

Source

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.

Source

pub fn set_accidentals_apply_only_to_octave(&mut self, value: bool)

Sets whether the altered pitches apply only in their own octave.

Source

pub fn description(&self) -> String

The description music21 prints after of: 3 sharps, 1 flat, no sharps or flats, or pitches: [E-, G#].

Source

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.

Source

pub fn accidental_by_step(&self, step: char) -> Result<Option<Accidental>>

Returns the accidental this signature puts on a step letter, if any.

Source

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.

Source

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.

Source

pub fn scale(&self, mode: &str) -> Result<Scale>

Returns the major or minor scale this signature implies.

Source

pub fn as_key(&self, mode: &str) -> Key

Converts this signature to a key in the given mode.

Source

pub fn try_as_key(&self, mode: Option<&str>, tonic: Option<&str>) -> Result<Key>

Converts this signature to a key, optionally inferring mode from tonic.

Trait Implementations§

Source§

impl Clone for KeySignature

Source§

fn clone(&self) -> KeySignature

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeySignature

Source§

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

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

impl<'de> Deserialize<'de> for KeySignature

Available on crate feature serde only.
Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for KeySignature

Source§

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

KeySignature of 3 sharps, KeySignature of pitches: [E-, G#].

Source§

impl From<KeySignature> for StreamElement

Source§

fn from(value: KeySignature) -> Self

Converts to this type from the input type.
Source§

impl Serialize for KeySignature

Available on crate feature serde only.
Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.