Skip to main content

ChordSymbol

Struct ChordSymbol 

Source
pub struct ChordSymbol { /* private fields */ }
Expand description

Parsed chord symbol.

Implementations§

Source§

impl ChordSymbol

Source

pub fn parse(figure: impl Into<String>) -> Result<Self>

Parses a chord symbol such as "Cmaj7", "F#m7b5", or "Bb7#11".

A b after the root’s letter is read as a flat, as a lead sheet writes one; Self::parse_music21 reads a figure as music21 does.

Source

pub fn parse_music21(figure: impl Into<String>) -> Result<Self>

Parses a figure exactly as music21’s ChordSymbol reads one, where a root or a bass is a letter with only # and - after it. A b is not a flat there: Bb7 is a B major triad with a flattened seventh added, and Ebmaj7 is no figure at all, since bmaj7 names no kind.

The root is the letter at the front, or everything before a comma; the bass is a / and a letter wherever it stands, so C/B- add 2 adds a second to a C triad over B flat; and what is left names one of music21’s kinds and its modifications, or is a list of degrees over no kind at all — C35b7 is a root with a third, a fifth and a flat seventh added to it. Anything else is refused with music21’s words.

Source

pub fn no_chord(text: Option<String>) -> Self

A symbol saying nothing sounds, written N.C. unless text says otherwise: music21’s NoChord, whose kind is none. It has a root only because every symbol has one; it sounds no pitches at all.

Source

pub fn lyrics(&self) -> &[Lyric]

The syllables sung to the symbol, one per verse.

Source

pub fn lyrics_mut(&mut self) -> &mut Vec<Lyric>

The same, for editing in place.

Source

pub fn add_lyric( &mut self, text: &str, number: Option<IntegerType>, apply_raw: bool, )

Adds a syllable as a verse, as crate::note::Note::add_lyric does: music21’s addLyric.

Source

pub fn is_no_chord(&self) -> bool

Whether this says nothing sounds: music21’s NoChord.

Source

pub fn kind_text(&self) -> Option<&str>

How the kind is written where a score says, as M for a major triad: music21’s chordKindStr.

Source

pub fn set_kind_text(&mut self, text: Option<String>)

Says how the kind is written.

Source

pub fn placement(&self) -> Option<Placement>

Which side of the staff the symbol is written on, where a score says.

Source

pub fn set_placement(&mut self, placement: Option<Placement>)

Says which side of the staff the symbol is written on.

Source

pub fn duration(&self) -> &Duration

How long the symbol holds. A symbol as written takes no time, which is music21’s default; realize_chord_symbol_durations gives each one in a stream the time until the next.

Source

pub fn set_duration(&mut self, duration: Duration)

Says how long the symbol holds.

Source

pub fn with_duration(self, duration: Duration) -> Self

The same symbol holding for a given time.

Source

pub fn kind(&self) -> Option<&str>

music21’s chordKind: the kind the shorthand names, where it is one of music21’s abbreviations, so Cmaj7 is major-seventh and CN6 the Neapolitan. None for a shorthand the crate reads on its own.

Source

pub fn figure(&self) -> &str

Returns the original chord-symbol figure.

Source

pub fn root(&self) -> &Pitch

Returns the root pitch.

Source

pub fn bass(&self) -> Option<&Pitch>

Returns the slash bass pitch, if one was supplied.

Source

pub fn quality(&self) -> ChordQuality

Returns the parsed chord quality.

Source

pub fn extensions(&self) -> &[u8] ⓘ

Returns parsed extension degrees.

Source

pub fn alterations(&self) -> &[ChordAlteration]

Returns parsed alterations.

Source

pub fn omissions(&self) -> &[u8] ⓘ

Returns degrees omitted with no... or omit... markers.

Source

pub fn additions(&self) -> &[ChordAlteration]

Returns parsed added tones from add(...) groups.

Source

pub fn find_figure(&self) -> String

Rebuilds the figure from the parsed parts in one canonical spelling: music21’s findFigure. Whatever was typed, a half-diminished seventh comes back as m7b5, an augmented triad as aug, an added ninth as add(9), and the result parses back to the same chord.

Source

pub fn transpose(&self, interval: &Interval) -> Result<ChordSymbol>

The same chord on a transposed root and bass, its figure rebuilt by Self::find_figure: music21’s transpose, so B-/D up a major second is C/E.

Source

pub fn inversion_is_valid(&self, inversion: u8) -> bool

Whether the chord can stand in the given inversion: music21’s inversionIsValid, which reads the kind — first and second inversions for anything but a pedal, a third for the sevenths and the stacked kinds above them, a fourth for the ninths and up, a fifth for the elevenths and thirteenths. A shorthand naming no kind of music21’s is read by the extensions the crate found in it. Root position is not an inversion.

Source

pub fn chord_step_modifications(&self) -> &[ChordStepModification]

The degrees added to, taken from or altered in the kind: music21’s chordStepModifications, read off the figure or handed over.

Source

pub fn add_chord_step_modification( &mut self, modification: ChordStepModification, )

Adds a chord-step modification, which the next realization applies: music21’s addChordStepModification. One already there is not added twice.

Source

pub fn set_chord_step_modifications( &mut self, modifications: Vec<ChordStepModification>, )

Replaces every chord-step modification at once.

Source

pub fn from_kind(root: Pitch, kind: &str, bass: Option<Pitch>) -> Result<Self>

A symbol given as MusicXML gives one: a root, one of music21’s chord kinds, and a bass where it is not the root, rather than a figure. The figure is written as music21 would write that kind.

Source

pub fn with_kind(self, kind: &str) -> Self

The same symbol as a chord of another kind, with no modifications: a kind music21’s table has been given while a program runs, which the crate’s own table has not got.

Source

pub fn set_root(&mut self, root: Pitch)

Sets the root the symbol is sounded on.

Source

pub fn set_bass(&mut self, bass: Option<Pitch>)

Sets the bass, or takes it away with None.

Source

pub fn to_chord(&self) -> Result<Chord>

Realizes the symbol as a chord: Self::pitches, sounding together.

Source

pub fn pitches(&self) -> Result<Vec<Pitch>>

The pitches the symbol sounds, with their octaves, lowest first: music21’s ChordSymbol._updatePitches.

The root is taken from octave three and the kind laid out above it; a ninth, eleventh or thirteenth has its upper notes lifted an octave; a bass the kind can invert onto is put under the chord by raising the notes below it, and one it cannot is added an octave under the root; the chord-step modifications are applied; and the whole is moved down until nothing is above the D over middle C, or up until nothing is below the piano’s lowest A. So C/E is E3 G3 C4, C11 is C2 E2 G2 Bb2 D3 F3, and Gm/F# is F#2 G3 Bb3 D4.

A shorthand naming none of music21’s kinds is laid out the same way from the crate’s own reading of it.

Trait Implementations§

Source§

impl Clone for ChordSymbol

Source§

fn clone(&self) -> Self

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 ChordSymbol

Source§

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

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

impl<'de> Deserialize<'de> for ChordSymbol

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 From<ChordSymbol> for StreamElement

Source§

fn from(value: ChordSymbol) -> Self

Converts to this type from the input type.
Source§

impl FromStr for ChordSymbol

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(value: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for ChordSymbol

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ChordSymbol

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
Source§

impl StructuralPartialEq for ChordSymbol

Source§

impl TryFrom<&str> for ChordSymbol

Source§

type Error = Error

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

fn try_from(value: &str) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<String> for ChordSymbol

Source§

type Error = Error

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

fn try_from(value: String) -> Result<Self>

Performs the conversion.

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, 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.