pub struct Chord { /* private fields */ }Expand description
A collection of notes analyzed as one vertical sonority.
Chord accepts several note-like inputs, including whitespace-separated
pitch names, slices of pitches or notes, MIDI pitch numbers, vectors, and
None for an empty chord.
Implementations§
Source§impl Chord
impl Chord
Sourcepub fn known_chord_types() -> Vec<KnownChordType>
pub fn known_chord_types() -> Vec<KnownChordType>
Returns the unpitched chord types known to the music21-derived table.
Sourcepub fn pitched_common_name(&self) -> String
pub fn pitched_common_name(&self) -> String
Returns the primary music21-style common name with a pitch prefix.
Sourcepub fn pitched_common_names(&self) -> Vec<String>
pub fn pitched_common_names(&self) -> Vec<String>
Returns every known music21-style common name with pitch prefixes.
Most chords have a single common name, while some Forte-table entries have aliases. This method exposes all of them in table order.
Sourcepub fn chord_symbol(&self) -> Option<String>
pub fn chord_symbol(&self) -> Option<String>
Returns the preferred chord symbol, when available.
This is separate from Self::pitched_common_name: common names follow
the music21/Forte tables, while chord symbols use music21-style
figures such as Cmaj7, F#m7b5, or Ddom7dim5/CaddA,E-.
Sourcepub fn chord_symbols(&self) -> Vec<String>
pub fn chord_symbols(&self) -> Vec<String>
Returns ranked chord symbols for this pitch-class set.
Empty and microtonal chords return no symbols because this notation layer assumes twelve-tone equal-tempered pitch classes.
Sourcepub fn chord_symbol_with_root(
&self,
root: impl Into<PitchClassSpecifier>,
) -> Result<Option<String>>
pub fn chord_symbol_with_root( &self, root: impl Into<PitchClassSpecifier>, ) -> Result<Option<String>>
Returns the preferred chord symbol using an explicit root.
This is useful for pitch-class sets and browser tables where the caller already knows the harmonic spelling anchor and does not want an inversion/root inference pass to choose another chord member. String roots are parsed as pitch names; numeric roots are parsed as pitch classes, so use numbers for pitch-class-only values such as 10 or 11.
Sourcepub fn chord_symbols_with_root(
&self,
root: impl Into<PitchClassSpecifier>,
) -> Result<Vec<String>>
pub fn chord_symbols_with_root( &self, root: impl Into<PitchClassSpecifier>, ) -> Result<Vec<String>>
Returns ranked chord symbols using an explicit root.
Empty, microtonal, and rootless-with-respect-to-the-given-root chords return no symbols. Non-integer roots are rejected because chord symbols are generated in twelve-tone pitch-class space.
Sourcepub fn common_name(&self) -> String
pub fn common_name(&self) -> String
Returns the primary unpitched music21-style common name.
For chords with multiple table aliases, this is the first common name in
table order. Use Self::common_names to get every unpitched alias.
Sourcepub fn common_names(&self) -> Vec<String>
pub fn common_names(&self) -> Vec<String>
Returns all unpitched common-name aliases known for this chord.
Sourcepub fn root_pitch_name(&self) -> Option<String>
pub fn root_pitch_name(&self) -> Option<String>
Returns the inferred root pitch name when the chord has one.
Returns None for empty chords, where there is no pitch from which a
root can be inferred.
Sourcepub fn bass_pitch_name(&self) -> Option<String>
pub fn bass_pitch_name(&self) -> Option<String>
Returns the lowest pitch name in the chord.
Returns None for empty chords, where there is no bass pitch.
Source§impl Chord
impl Chord
Sourcepub fn has_component_volumes(&self) -> bool
pub fn has_component_volumes(&self) -> bool
Whether every note carries a volume of its own: music21’s
hasComponentVolumes, which counts the notes that have one and
compares the count against the whole chord. A chord where only some
notes have been given a volume reads as having none.
Sourcepub fn volume(&self) -> Volume
pub fn volume(&self) -> Volume
How loud the chord is. With volumes on its notes this is their average velocity, as music21 reads it; otherwise it is the chord’s own volume.
Sourcepub fn set_volume(&mut self, volume: Option<Volume>)
pub fn set_volume(&mut self, volume: Option<Volume>)
Sets the chord’s own volume, which drops any the notes carried.
Sourcepub fn set_volumes(&mut self, volumes: &[Volume]) -> Result<()>
pub fn set_volumes(&mut self, volumes: &[Volume]) -> Result<()>
Gives each note a volume from the list, cycling through it when the
chord has more notes than the list has volumes: music21’s
setVolumes. The chord’s own volume is dropped.
Sourcepub fn color(&self) -> Option<&str>
pub fn color(&self) -> Option<&str>
The colour the chord is written in, when the chord itself carries one rather than its notes.
Sourcepub fn set_color(&mut self, color: Option<String>)
pub fn set_color(&mut self, color: Option<String>)
Sets the colour the chord as a whole is written in.
Sourcepub fn notehead(&self) -> Notehead
pub fn notehead(&self) -> Notehead
The shape the chord as a whole is drawn with: music21’s notehead,
which a chord has in its own right and not only through its notes.
Sourcepub fn set_notehead(&mut self, notehead: Notehead)
pub fn set_notehead(&mut self, notehead: Notehead)
Sets that shape.
Sourcepub fn notehead_fill(&self) -> Option<bool>
pub fn notehead_fill(&self) -> Option<bool>
Whether the chord’s own note heads are filled, when it says.
Sourcepub fn set_notehead_fill(&mut self, fill: Option<bool>)
pub fn set_notehead_fill(&mut self, fill: Option<bool>)
Says whether they are filled.
Sourcepub fn notehead_parenthesis(&self) -> bool
pub fn notehead_parenthesis(&self) -> bool
Whether the chord’s own note heads are bracketed.
Sourcepub fn set_notehead_parenthesis(&mut self, parenthesis: bool)
pub fn set_notehead_parenthesis(&mut self, parenthesis: bool)
Says whether they are bracketed.
Sourcepub fn stem_direction(&self) -> StemDirection
pub fn stem_direction(&self) -> StemDirection
Which way the chord’s own stem points.
Sourcepub fn set_stem_direction(&mut self, direction: StemDirection)
pub fn set_stem_direction(&mut self, direction: StemDirection)
Sets which way it points.
Sourcepub fn color_of_pitch(&self, pitch: &Pitch) -> Option<&str>
pub fn color_of_pitch(&self, pitch: &Pitch) -> Option<&str>
The colour a pitch is written in: the note’s own colour when it has
one, and the chord’s otherwise, as music21’s getColor reads it.
Sourcepub fn tie(&self) -> Option<&Tie>
pub fn tie(&self) -> Option<&Tie>
The tie of the first note that carries one: music21’s chord-level
tie.
Sourcepub fn set_tie(&mut self, tie: Option<Tie>)
pub fn set_tie(&mut self, tie: Option<Tie>)
Ties every note in the chord, or unties them all with None.
Sourcepub fn lyrics(&self) -> &[Lyric]
pub fn lyrics(&self) -> &[Lyric]
The syllables sung on the chord, kept on its first note as music21 keeps them on the chord itself.
Sourcepub fn add_lyric(
&mut self,
text: &str,
number: Option<IntegerType>,
apply_raw: bool,
) -> Result<()>
pub fn add_lyric( &mut self, text: &str, number: Option<IntegerType>, apply_raw: bool, ) -> Result<()>
Adds a syllable as the next verse: music21’s addLyric.
Sourcepub fn annotate_intervals(
&self,
strip_specifiers: bool,
sort_pitches: bool,
) -> Result<Vec<String>>
pub fn annotate_intervals( &self, strip_specifiers: bool, sort_pitches: bool, ) -> Result<Vec<String>>
Names the interval from the chord’s lowest pitch up to each of the
others, highest first: music21’s annotateIntervals.
With strip_specifiers the names are bare numbers (8, 5, 3)
and sorted downward; without it they are full interval names (P8,
P5, M3). Repeated pitches are dropped first, and sort_pitches
measures from the lowest pitch rather than the written first one.
Sourcepub fn annotated_with_intervals(
&self,
strip_specifiers: bool,
sort_pitches: bool,
) -> Result<Self>
pub fn annotated_with_intervals( &self, strip_specifiers: bool, sort_pitches: bool, ) -> Result<Self>
Writes the interval names of Self::annotate_intervals onto the
chord as lyrics, one verse each.
Sourcepub fn string_harmonic(&self) -> Result<Option<Self>>
pub fn string_harmonic(&self) -> Result<Option<Self>>
Reads a string harmonic: given a chord whose second note is written
with a diamond head, the sounding pitch is the harmonic of the first
note that their distance picks out, and the chord comes back with it
added on top. A chord not written as a harmonic answers None.
This is music21’s Pitch.getStringHarmonic, which reads the notehead
off the chord rather than off the pitch it is called on.
Source§impl Chord
impl Chord
Sourcepub fn chord_step(&self, step: u8) -> Option<&Pitch>
pub fn chord_step(&self, step: u8) -> Option<&Pitch>
Returns the first pitch lying at the given chord step above the root,
so 3 is the third and 7 the seventh. Steps of eight and above are
folded down by an octave, so 9 finds a second.
Sourcepub fn seventh(&self) -> Option<&Pitch>
pub fn seventh(&self) -> Option<&Pitch>
Returns the seventh above the root, if the chord has one.
Sourcepub fn semitones_from_chord_step(&self, step: u8) -> Option<u8>
pub fn semitones_from_chord_step(&self, step: u8) -> Option<u8>
Returns the semitones from the root to the given chord step, within an octave, if the chord has that step.
Sourcepub fn has_repeated_chord_step(&self, step: u8) -> bool
pub fn has_repeated_chord_step(&self, step: u8) -> bool
Returns whether the chord has the given step spelled two different
ways, such as both E and E- above C.
Sourcepub fn has_any_enharmonic_spelled_pitches(&self) -> bool
pub fn has_any_enharmonic_spelled_pitches(&self) -> bool
Returns whether two pitches share a pitch class under different names,
such as C# and D-.
Sourcepub fn is_triad(&self) -> bool
pub fn is_triad(&self) -> bool
Returns whether the chord is exactly three distinct pitch names with a third and a fifth above the root, of any quality.
Sourcepub fn is_seventh(&self) -> bool
pub fn is_seventh(&self) -> bool
Returns whether the chord is exactly four distinct pitch names with a third, fifth and seventh above the root, of any quality.
Sourcepub fn is_major_triad(&self) -> bool
pub fn is_major_triad(&self) -> bool
Returns whether the chord is a correctly spelled major triad.
Sourcepub fn is_minor_triad(&self) -> bool
pub fn is_minor_triad(&self) -> bool
Returns whether the chord is a correctly spelled minor triad.
Sourcepub fn is_diminished_triad(&self) -> bool
pub fn is_diminished_triad(&self) -> bool
Returns whether the chord is a correctly spelled diminished triad.
Sourcepub fn is_augmented_triad(&self) -> bool
pub fn is_augmented_triad(&self) -> bool
Returns whether the chord is a correctly spelled augmented triad.
Sourcepub fn is_seventh_of_type(&self, semitones: &[u8]) -> bool
pub fn is_seventh_of_type(&self, semitones: &[u8]) -> bool
Returns whether the chord is a seventh chord whose pitches all lie at the given semitone offsets above the root.
Sourcepub fn is_dominant_seventh(&self) -> bool
pub fn is_dominant_seventh(&self) -> bool
Returns whether the chord is a dominant seventh: a major triad with a minor seventh.
Sourcepub fn is_half_diminished_seventh(&self) -> bool
pub fn is_half_diminished_seventh(&self) -> bool
Returns whether the chord is a half-diminished seventh.
Sourcepub fn is_diminished_seventh(&self) -> bool
pub fn is_diminished_seventh(&self) -> bool
Returns whether the chord is a fully diminished seventh.
Sourcepub fn is_incomplete_major_triad(&self) -> bool
pub fn is_incomplete_major_triad(&self) -> bool
Returns whether the chord is only a root and a major third above it.
Sourcepub fn is_incomplete_minor_triad(&self) -> bool
pub fn is_incomplete_minor_triad(&self) -> bool
Returns whether the chord is only a root and a minor third above it.
Sourcepub fn contains_triad(&self) -> bool
pub fn contains_triad(&self) -> bool
Returns whether the chord has a third and a fifth above its root. A dominant seventh is not a triad but contains one.
Sourcepub fn contains_seventh(&self) -> bool
pub fn contains_seventh(&self) -> bool
Returns whether the chord contains a triad and a seventh above its root.
Sourcepub fn quality(&self) -> TriadQuality
pub fn quality(&self) -> TriadQuality
Returns the quality of the triad above the root, following music21’s
Chord.quality: incomplete triads still count, and a chord with a
repeated or missing chord step is TriadQuality::Other.
Sourcepub fn is_consonant(&self) -> bool
pub fn is_consonant(&self) -> bool
Returns whether the chord is consonant in the common-practice sense: one pitch name, two whose closed-position interval is consonant, or a major or minor triad not in second inversion.
Sourcepub fn chord_step_with_root(&self, step: u8, root: &Pitch) -> Option<&Pitch>
pub fn chord_step_with_root(&self, step: u8, root: &Pitch) -> Option<&Pitch>
The first pitch at the given chord step above a root the caller
decided on, rather than the one the chord infers: music21’s
getChordStep(step, testRoot).
Sourcepub fn semitones_from_chord_step_with_root(
&self,
step: u8,
root: &Pitch,
) -> Option<u8>
pub fn semitones_from_chord_step_with_root( &self, step: u8, root: &Pitch, ) -> Option<u8>
The semitone distance from a caller-supplied root to the pitch at the
given chord step: music21’s semitonesFromChordStep(step, testRoot).
Sourcepub fn inversion_from_root(&self, root: &Pitch) -> Option<u8>
pub fn inversion_from_root(&self, root: &Pitch) -> Option<u8>
The inversion measured from a root the caller decided on: music21’s
inversion(testRoot=...).
Sourcepub fn is_augmented_sixth(&self, permit_any_inversion: bool) -> bool
pub fn is_augmented_sixth(&self, permit_any_inversion: bool) -> bool
Returns whether the chord is an Italian, French, German or Swiss
augmented sixth. Each must be in its conventional inversion unless
permit_any_inversion is set.
Sourcepub fn is_italian_augmented_sixth(
&self,
permit_any_inversion: bool,
restrict_doublings: bool,
) -> bool
pub fn is_italian_augmented_sixth( &self, permit_any_inversion: bool, restrict_doublings: bool, ) -> bool
Returns whether the chord is an Italian augmented sixth, such as
A- C F#.
Sourcepub fn is_french_augmented_sixth(&self, permit_any_inversion: bool) -> bool
pub fn is_french_augmented_sixth(&self, permit_any_inversion: bool) -> bool
Returns whether the chord is a French augmented sixth, such as
A- C D F#.
Sourcepub fn is_german_augmented_sixth(&self, permit_any_inversion: bool) -> bool
pub fn is_german_augmented_sixth(&self, permit_any_inversion: bool) -> bool
Returns whether the chord is a German augmented sixth, such as
A- C E- F#.
Sourcepub fn is_swiss_augmented_sixth(&self, permit_any_inversion: bool) -> bool
pub fn is_swiss_augmented_sixth(&self, permit_any_inversion: bool) -> bool
Returns whether the chord is a Swiss augmented sixth, such as
A- C D# F#.
Sourcepub fn is_ninth(&self) -> bool
pub fn is_ninth(&self) -> bool
Returns whether the chord is five distinct pitch names with a third, fifth, seventh and ninth above the root.
Sourcepub fn is_transpositionally_symmetrical(
&self,
require_intervallic_evenness: bool,
) -> bool
pub fn is_transpositionally_symmetrical( &self, require_intervallic_evenness: bool, ) -> bool
Returns whether some transposition other than the octave maps the
pitch-class set onto itself. With require_intervallic_evenness only
the evenly spaced sets count, the way Straus defines the property.
Sourcepub fn has_any_repeated_diatonic_note(&self) -> bool
pub fn has_any_repeated_diatonic_note(&self) -> bool
Returns whether two pitches share a letter under different
accidentals, such as E and E-.
Sourcepub fn interval_from_chord_step(&self, step: u8) -> Option<Interval>
pub fn interval_from_chord_step(&self, step: u8) -> Option<Interval>
Returns the interval from the root to the first pitch lying on the
given chord step, compound intervals included, so the third of
C3 G3 E4 C5 is a major tenth. None when the chord has no root or
no pitch on that step.
Source§impl Chord
impl Chord
Sourcepub fn resolution_chord(
&self,
tonic: &str,
mode: Option<&str>,
) -> Result<Option<Self>>
pub fn resolution_chord( &self, tonic: &str, mode: Option<&str>, ) -> Result<Option<Self>>
Returns the first likely tonal resolution chord in the given key.
This is intentionally conservative rather than a universal harmonic
oracle. It covers the resolution families that music21 exposes most
directly: dominant-function sonorities, leading-tone diminished
sonorities, and contextual augmented-sixth sonorities. Unsupported
chords return Ok(None).
Sourcepub fn resolution_chords(
&self,
tonic: &str,
mode: Option<&str>,
) -> Result<Vec<Self>>
pub fn resolution_chords( &self, tonic: &str, mode: Option<&str>, ) -> Result<Vec<Self>>
Returns likely tonal resolution chords in the given key.
Dominant-function chords resolve by root motion up a perfect fourth to
a diatonic triad in the supplied key, so secondary dominants such as
D7 in C major resolve to the G-major triad. Leading-tone diminished
sonorities resolve up by semitone to a diatonic triad. Italian, French,
German, and Swiss-style augmented-sixth sonorities in context resolve to
the dominant triad.
Sourcepub fn resolution_chords_in_key(&self, key: &Key) -> Result<Vec<Self>>
pub fn resolution_chords_in_key(&self, key: &Key) -> Result<Vec<Self>>
Returns likely tonal resolution chords in the supplied key.
Sourcepub fn resolution_suggestions_in_key(
&self,
key: &Key,
) -> Result<Vec<ChordResolutionSuggestion>>
pub fn resolution_suggestions_in_key( &self, key: &Key, ) -> Result<Vec<ChordResolutionSuggestion>>
Returns likely tonal resolution suggestions in the supplied key.
Sourcepub fn resolution_suggestions(&self) -> Result<Vec<ChordResolutionSuggestion>>
pub fn resolution_suggestions(&self) -> Result<Vec<ChordResolutionSuggestion>>
Returns likely tonal resolution chords with inferred key contexts.
This is a convenience wrapper around Self::resolution_chords for
exploratory tools: dominant-function sonorities are tested against the
key a perfect fourth above their root, leading-tone sonorities against
the key a semitone above their root, and augmented-sixth sonorities
against all built-in major/minor tonic spellings.
Sourcepub fn can_be_dominant_v(&self) -> bool
pub fn can_be_dominant_v(&self) -> bool
Returns whether the chord could serve as a dominant: a major triad or a dominant seventh.
Sourcepub fn can_be_tonic(&self) -> bool
pub fn can_be_tonic(&self) -> bool
Returns whether the chord could serve as a tonic: a major or minor triad.
Source§impl Chord
impl Chord
Sourcepub fn from_forte_class(notation: &str) -> Result<Self>
pub fn from_forte_class(notation: &str) -> Result<Self>
Builds the chord of a Forte set class from its name, 3-11 or
4-27B: music21’s fromForteClass. The pitches are the transposed
normal form from C, without octaves, so 3-11 is C E- G and 3-11B
is C E G.
Sourcepub fn from_forte_address(
cardinality: u8,
index: u8,
inversion: Option<i8>,
) -> Result<Self>
pub fn from_forte_address( cardinality: u8, index: u8, inversion: Option<i8>, ) -> Result<Self>
Builds the chord of a Forte set class from its table address: the
cardinality, the number within it, and 1, -1 or None for the
inversion, where None takes the form the table lists first.
Sourcepub fn from_interval_vector(vector: &[u8; 6], z_relation: bool) -> Option<Self>
pub fn from_interval_vector(vector: &[u8; 6], z_relation: bool) -> Option<Self>
Builds the chord whose interval-class vector this is: music21’s
fromIntervalVector. Z-related pairs share a vector; the first of
the pair is returned unless z_relation asks for the second. None
when no set class has the vector.
Sourcepub fn forte_class(&self) -> Option<String>
pub fn forte_class(&self) -> Option<String>
Returns the Forte class, such as "3-11B", when available.
Returns None when the chord’s pitch-class set has no Forte-table
entry, including empty or otherwise unsupported pitch-class sets.
Sourcepub fn normal_form(&self) -> Option<Vec<u8>>
pub fn normal_form(&self) -> Option<Vec<u8>>
Returns the normal form transposed to start on zero, [0, 3, 6, 8]
for C E G B-. This is the Forte-table form music21 reads off the
chord’s table address; Self::normal_order is music21’s
normalOrder, on the chord’s own pitch classes.
Returns None when the chord’s pitch-class set cannot be found in the
chord tables, including empty or otherwise unsupported pitch-class sets.
Sourcepub fn interval_class_vector(&self) -> Option<Vec<u8>>
pub fn interval_class_vector(&self) -> Option<Vec<u8>>
Returns the interval-class vector when table metadata is available.
Returns None when the chord’s pitch-class set cannot be found in the
chord tables, including empty or otherwise unsupported pitch-class sets.
Sourcepub fn invariance_vector(&self) -> Option<Vec<u8>>
pub fn invariance_vector(&self) -> Option<Vec<u8>>
Returns Robert Morris’s eight-entry invariance vector, when available.
The values are taken from the same music21 Forte table as
Self::forte_class and Self::interval_class_vector.
Sourcepub fn z_relation(&self) -> Option<String>
pub fn z_relation(&self) -> Option<String>
Returns this chord’s Z-related Forte class, when music21 records one.
Sourcepub fn prime_form(&self) -> Vec<u8> ⓘ
pub fn prime_form(&self) -> Vec<u8> ⓘ
Returns the Forte prime form of the pitch-class set, such as
[0, 3, 7] for any major or minor triad. Empty when the chord has no
table entry.
Sourcepub fn prime_form_string(&self) -> String
pub fn prime_form_string(&self) -> String
Returns the prime form in music21’s angle-bracket notation, such as
"<037>", with A and B standing for ten and eleven.
Sourcepub fn forte_class_tni(&self) -> Option<String>
pub fn forte_class_tni(&self) -> Option<String>
Returns the Forte class without the A/B inversion suffix, such as
"3-11" for both major and minor triads.
Sourcepub fn pitch_class_cardinality(&self) -> usize
pub fn pitch_class_cardinality(&self) -> usize
Returns the number of distinct pitch classes.
Sourcepub fn ordered_pitch_classes_string(&self) -> String
pub fn ordered_pitch_classes_string(&self) -> String
Returns the distinct pitch classes in ascending order in music21’s
angle-bracket notation, such as "<047>".
Sourcepub fn chord_tables_address_entry(&self) -> ChordTableAddress
pub fn chord_tables_address_entry(&self) -> ChordTableAddress
Where this chord’s set class sits in the Forte tables.
An empty chord answers all zeros rather than failing, which is the
one place music21’s Chord.chordTablesAddress differs from the
seekChordTablesAddress underneath it.
Sourcepub fn geometric_normal_form(&self) -> Vec<u8> ⓘ
pub fn geometric_normal_form(&self) -> Vec<u8> ⓘ
Returns music21’s geometricNormalForm: the distinct pitch classes
rotated so the intervals between neighbours read smallest first, then
written from zero, so both C E G and E G C are [0, 3, 8]. Empty
for an empty chord.
Sourcepub fn interval_vector_string(&self) -> String
pub fn interval_vector_string(&self) -> String
Returns the interval-class vector in music21’s angle-bracket
notation, <001110>; an empty chord reads <000000>.
Sourcepub fn normal_order(&self) -> Vec<u8> ⓘ
pub fn normal_order(&self) -> Vec<u8> ⓘ
Returns music21’s normalOrder: the most compact rotation of the
pitch classes, on the chord’s own pitch classes rather than
transposed to zero, so C E G B- is [4, 7, 10, 0] where
Self::normal_form is [0, 3, 6, 8]. Empty for an empty chord.
Sourcepub fn normal_order_string(&self) -> String
pub fn normal_order_string(&self) -> String
Returns Self::normal_order in music21’s angle-bracket notation,
<47A0>.
Sourcepub fn forte_class_number(&self) -> Option<u8>
pub fn forte_class_number(&self) -> Option<u8>
Returns the Forte class number within the cardinality, 11 for a
major or minor triad. None for an empty chord.
Sourcepub fn forte_class_tn(&self) -> Option<String>
pub fn forte_class_tn(&self) -> Option<String>
Returns the Forte class under transposition equivalence, with the
A/B inversion suffix: music21’s forteClassTn, the same as
Self::forte_class.
Sourcepub fn multiset_cardinality(&self) -> usize
pub fn multiset_cardinality(&self) -> usize
Returns the number of notes, counting repeated pitch classes: music21’s
multisetCardinality.
Sourcepub fn is_prime_form_inversion(&self) -> bool
pub fn is_prime_form_inversion(&self) -> bool
Returns whether the pitch-class set is the inversion of its prime
form, so its Forte class carries a B suffix.
Sourcepub fn has_z_relation(&self) -> bool
pub fn has_z_relation(&self) -> bool
Returns whether music21 records a Z-related set class for this chord.
Sourcepub fn are_z_relations(&self, other: &Chord) -> bool
pub fn are_z_relations(&self, other: &Chord) -> bool
Returns whether other belongs to the set class Z-related to this
chord’s, so the two share an interval vector without being related by
transposition or inversion.
Sourcepub fn is_false_diminished_seventh(&self) -> bool
pub fn is_false_diminished_seventh(&self) -> bool
Returns whether the pitch classes form a fully diminished seventh
however it is spelled: music21’s isFalseDiminishedSeventh, true for
C E- G- A where Self::is_diminished_seventh is not.
Source§impl Chord
impl Chord
Sourcepub fn new<T>(notes: T) -> Result<Self>where
T: IntoNotes,
pub fn new<T>(notes: T) -> Result<Self>where
T: IntoNotes,
Builds a chord from any supported note collection.
Empty inputs are valid: pass "", an empty vector or slice, or
Option::<&str>::None to construct an empty chord.
Sourcepub fn guitar_fingering(&self) -> Option<GuitarFingering>
pub fn guitar_fingering(&self) -> Option<GuitarFingering>
Returns a suggested standard-tuning guitar fingering.
The fingering is a compact voicing on six-string guitar in E2-A2-D3-G3-B3-E4 tuning. It prefers shapes that cover all chord pitches, place the root in the bass when possible, avoid internal muted strings, and stay within a small fret span.
Sourcepub fn guitar_fingering_with_tuning(
&self,
tuning: &GuitarTuning,
) -> Option<GuitarFingering>
pub fn guitar_fingering_with_tuning( &self, tuning: &GuitarTuning, ) -> Option<GuitarFingering>
Returns a suggested guitar fingering for the supplied tuning.
The tuning strings must be ordered from low to high. Fingering generation uses exact pitch spaces, so both the chord pitches and open-string octaves affect the result.
Sourcepub fn pitch_classes(&self) -> Vec<u8> ⓘ
pub fn pitch_classes(&self) -> Vec<u8> ⓘ
Returns the distinct pitch classes in ascending order.
Sourcepub fn polyrhythm_components(&self) -> Vec<UnsignedIntegerType> ⓘ
pub fn polyrhythm_components(&self) -> Vec<UnsignedIntegerType> ⓘ
Maps this chord’s pitch classes to a reduced integer polyrhythm ratio.
Pitch classes are measured from the inferred root when possible, or from the lowest pitch class otherwise. Each semitone offset is mapped to a compact just-intonation ratio and reduced to whole-number components.
Sourcepub fn polyrhythm_ratio_string(&self) -> String
pub fn polyrhythm_ratio_string(&self) -> String
Returns Self::polyrhythm_components formatted as a:b:c.
Sourcepub fn add<T>(&mut self, notes: T) -> Result<()>where
T: IntoNotes,
pub fn add<T>(&mut self, notes: T) -> Result<()>where
T: IntoNotes,
Adds pitches or notes to the end of the chord, as music21’s
Chord.add does. The chord is not re-sorted: the new notes sit after
the ones already there.
Sourcepub fn remove(&mut self, pitch: &Pitch) -> Result<()>
pub fn remove(&mut self, pitch: &Pitch) -> Result<()>
Removes the first note whose pitch equals this one, as music21’s
Chord.remove does, and errors when the chord has no such pitch.
Sourcepub fn remove_named(&mut self, name_with_octave: &str) -> Result<()>
pub fn remove_named(&mut self, name_with_octave: &str) -> Result<()>
Removes the first note whose written pitch name matches, as music21’s
Chord.remove does with a string.
Sourcepub fn pitches(&self) -> Vec<Pitch>
pub fn pitches(&self) -> Vec<Pitch>
Returns cloned pitches for every note in the chord, in input order.
Sourcepub fn iter_pitches(&self) -> impl Iterator<Item = &Pitch> + '_
pub fn iter_pitches(&self) -> impl Iterator<Item = &Pitch> + '_
Borrows the pitches in input order.
Chord::pitches is music21’s accessor and clones each pitch; an
Accidental owns two Strings, so that is two allocations a pitch a
caller that only reads them does not need.
Sourcepub fn notes_mut(&mut self) -> &mut [Note]
pub fn notes_mut(&mut self) -> &mut [Note]
The notes in input order, for editing in place. This is how a note’s
notation is changed through the chord: chord.notes_mut()[1] .set_notehead(Notehead::Diamond).
Sourcepub fn note_for_pitch(&self, pitch: &Pitch) -> Option<&Note>
pub fn note_for_pitch(&self, pitch: &Pitch) -> Option<&Note>
The first note whose pitch equals this one: music21’s per-note accessors take a pitch this way.
Sourcepub fn note_for_pitch_mut(&mut self, pitch: &Pitch) -> Option<&mut Note>
pub fn note_for_pitch_mut(&mut self, pitch: &Pitch) -> Option<&mut Note>
The first note whose pitch equals this one, for editing in place.
Sourcepub fn duration(&self) -> Option<&Duration>
pub fn duration(&self) -> Option<&Duration>
Returns the chord duration when one has been assigned.
Sourcepub fn set_duration(&mut self, duration: Duration)
pub fn set_duration(&mut self, duration: Duration)
Assigns a duration to the chord.
Sourcepub fn with_duration(self, duration: Duration) -> Self
pub fn with_duration(self, duration: Duration) -> Self
Returns a copy of this chord with the supplied duration.
Sourcepub fn inversion(&self) -> Option<u8>
pub fn inversion(&self) -> Option<u8>
Returns the inversion number the way music21 finds it: root position
is 0, and the number climbs with the chord step the bass sits on,
so a bass on the seventh is 3. None only for an empty chord.
Sourcepub fn inversion_name(&self) -> Result<Option<IntegerType>>
pub fn inversion_name(&self) -> Result<Option<IntegerType>>
Returns a human-readable inversion label.
Returns None whenever Self::inversion returns None.
The figured-bass number music21’s inversionName answers: 53, 6
and 64 for a triad, 7, 65, 43 and 42 for a seventh. None
when the chord has no inversion, and an error when it is neither a
triad nor a seventh, as music21 raises there. For the words, see
Self::inversion_text.
Sourcepub fn simplify_enharmonics(
&self,
key_context: Option<KeySignature>,
) -> Result<Self>
pub fn simplify_enharmonics( &self, key_context: Option<KeySignature>, ) -> Result<Self>
Returns a copy with simplified enharmonic spellings.
This mirrors music21’s explicit enharmonic simplification workflow: construction stays side-effect free, and callers can request simpler spellings with an optional key-signature context.
Sourcepub fn simplify_enharmonics_in_place(
&mut self,
key_context: Option<KeySignature>,
) -> Result<()>
pub fn simplify_enharmonics_in_place( &mut self, key_context: Option<KeySignature>, ) -> Result<()>
Simplifies this chord’s pitch spellings in place.
Sourcepub fn root(&self) -> Option<&Pitch>
pub fn root(&self) -> Option<&Pitch>
Returns the root, found the way music21’s Chord.root finds it.
Sourcepub fn found_root(&self) -> Option<&Pitch>
pub fn found_root(&self) -> Option<&Pitch>
The root the pitches imply, ignoring any override.
Sourcepub fn set_root(&mut self, root: Option<Pitch>)
pub fn set_root(&mut self, root: Option<Pitch>)
Fixes the root the chord reports, or clears the override with None:
music21’s root(newroot). The pitch need not be in the chord, which
is the point of it for oddly spelled or added-note chords.
Sourcepub fn bass(&self) -> Option<&Pitch>
pub fn bass(&self) -> Option<&Pitch>
Returns the lowest pitch, or the bass a caller fixed with
Self::set_bass.
Sourcepub fn found_bass(&self) -> Option<&Pitch>
pub fn found_bass(&self) -> Option<&Pitch>
The lowest pitch, ignoring any override.
Sourcepub fn overridden_bass(&self) -> Option<&Pitch>
pub fn overridden_bass(&self) -> Option<&Pitch>
The bass a caller fixed with Self::set_bass, and nothing when
none was.
Sourcepub fn overridden_root(&self) -> Option<&Pitch>
pub fn overridden_root(&self) -> Option<&Pitch>
The root a caller fixed with Self::set_root, and nothing when
none was.
Sourcepub fn set_bass(&mut self, bass: Option<Pitch>)
pub fn set_bass(&mut self, bass: Option<Pitch>)
Fixes the bass the chord reports, or clears the override with None:
music21’s bass(newbass). A pitch the chord does not already carry is
added below the others, as music21 adds it.
Sourcepub fn set_inversion(&mut self, inversion: u8) -> Result<()>
pub fn set_inversion(&mut self, inversion: u8) -> Result<()>
Rearranges the chord so it stands in the given inversion, raising the
bass by octaves until it does: music21’s inversion(newInversion).
An inversion the chord cannot reach is an error.
Sourcepub fn closed_position(
&self,
force_octave: Option<IntegerType>,
leave_redundant_pitches: bool,
) -> Self
pub fn closed_position( &self, force_octave: Option<IntegerType>, leave_redundant_pitches: bool, ) -> Self
Returns a copy with every pitch brought within an octave above the
bass, duplicates removed and the notes sorted, as music21’s
closedPosition does. force_octave moves the bass to that octave
first, carrying the rest of the chord with it.
Sourcepub fn remove_redundant_pitches_reporting(&self) -> (Self, Vec<Pitch>)
pub fn remove_redundant_pitches_reporting(&self) -> (Self, Vec<Pitch>)
The chord with duplicate pitches removed, and the pitches that went:
music21’s removeRedundantPitches, which hands back what it dropped.
Sourcepub fn remove_redundant_pitch_names_reporting(&self) -> (Self, Vec<Pitch>)
pub fn remove_redundant_pitch_names_reporting(&self) -> (Self, Vec<Pitch>)
The chord with pitches of the same name removed, and the ones that
went: music21’s removeRedundantPitchNames.
Sourcepub fn remove_redundant_pitch_classes_reporting(&self) -> (Self, Vec<Pitch>)
pub fn remove_redundant_pitch_classes_reporting(&self) -> (Self, Vec<Pitch>)
The chord with pitches of the same pitch class removed, and the ones
that went: music21’s removeRedundantPitchClasses.
Sourcepub fn remove_redundant_pitches(&self) -> Self
pub fn remove_redundant_pitches(&self) -> Self
Returns a copy keeping the first of every pitch that appears more than
once with the same name and octave. B-1 (B-flat, octave 1) and B
in octave -1 print alike but are different pitches, and so are C
with no octave of its own and C4.
Sourcepub fn remove_redundant_pitch_names(&self) -> Self
pub fn remove_redundant_pitch_names(&self) -> Self
Returns a copy keeping the first of every pitch name, regardless of octave.
Sourcepub fn remove_redundant_pitch_classes(&self) -> Self
pub fn remove_redundant_pitch_classes(&self) -> Self
Returns a copy keeping the first of every pitch class, so C# and
D- count as one.
Sourcepub fn sort_ascending(&self) -> Self
pub fn sort_ascending(&self) -> Self
Returns a copy sorted by staff position and then pitch space, so
F## sorts below G-.
Sourcepub fn transpose(&self, interval: &Interval) -> Result<Self>
pub fn transpose(&self, interval: &Interval) -> Result<Self>
Returns a copy with every note transposed by the interval.
Sourcepub fn scale_degrees(
&self,
scale: &Scale,
) -> Result<Vec<(Option<usize>, Option<Accidental>)>>
pub fn scale_degrees( &self, scale: &Scale, ) -> Result<Vec<(Option<usize>, Option<Accidental>)>>
Returns each pitch’s degree in scale with the accidental that
separates it from the scale’s spelling, as music21’s scaleDegrees
does: C E- G in C major is (1, None), (3, flat), (5, None). A pitch
whose letter the scale lacks reports (None, None).
Source§impl Chord
impl Chord
Sourcepub fn inversion_text(&self) -> String
pub fn inversion_text(&self) -> String
Returns music21’s inversionText: Root Position, First Inversion
and so on, or Unknown Position for an empty chord.
Sourcepub fn semi_closed_position(
&self,
force_octave: Option<IntegerType>,
leave_redundant_pitches: bool,
) -> Self
pub fn semi_closed_position( &self, force_octave: Option<IntegerType>, leave_redundant_pitches: bool, ) -> Self
Returns the chord in closed position with every repeated step raised
an octave, so an eight-note cluster spreads into a scale: music21’s
semiClosedPosition.
Sourcepub fn sort_chromatic_ascending(&self) -> Self
pub fn sort_chromatic_ascending(&self) -> Self
Returns a copy sorted by pitch space alone, so enharmonic pairs keep
their input order: music21’s sortChromaticAscending.
Sourcepub fn sort_diatonic_ascending(&self) -> Self
pub fn sort_diatonic_ascending(&self) -> Self
Returns a copy sorted by staff position and then pitch space, so
B#3 sorts below C4: music21’s sortDiatonicAscending, which is
also what Self::sort_ascending does.
Sourcepub fn sort_frequency_ascending(&self) -> Self
pub fn sort_frequency_ascending(&self) -> Self
Returns a copy sorted by frequency: music21’s sortFrequencyAscending.
Sourcepub fn pitch_names(&self) -> Vec<String>
pub fn pitch_names(&self) -> Vec<String>
Returns the pitch names in input order, without octaves.
Sourcepub fn note_pitch_classes(&self) -> Vec<u8> ⓘ
pub fn note_pitch_classes(&self) -> Vec<u8> ⓘ
The pitch class of every note, in the order the chord holds them and
with repeats kept: music21’s pitchClasses. For the sorted, distinct
list see Self::pitch_classes.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Chord
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Chord
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<Chord> for StreamElement
impl From<Chord> for StreamElement
Source§impl IntoIterator for Chord
impl IntoIterator for Chord
Source§impl<'a> IntoIterator for &'a Chord
impl<'a> IntoIterator for &'a Chord
Source§impl<'a> IntoIterator for &'a mut Chord
impl<'a> IntoIterator for &'a mut Chord
Auto Trait Implementations§
impl Freeze for Chord
impl RefUnwindSafe for Chord
impl Send for Chord
impl Sync for Chord
impl Unpin for Chord
impl UnsafeUnpin for Chord
impl UnwindSafe for Chord
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