Skip to main content

Chord

Struct Chord 

Source
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

Source

pub fn new<T>(notes: T) -> Result<Self>
where T: IntoNotes + Clone,

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.

Source

pub fn empty() -> Result<Self>

Builds an empty chord.

Source

pub fn known_chord_types() -> Vec<KnownChordType>

Returns the unpitched chord types known to the music21-derived table.

Source

pub fn pitched_common_name(&self) -> String

Returns the primary music21-style common name with a pitch prefix.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn common_names(&self) -> Vec<String>

Returns all unpitched common-name aliases known for this chord.

Source

pub fn pitch_classes(&self) -> Vec<u8>

Returns the distinct pitch classes in ascending order.

Source

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.

Source

pub fn polyrhythm_ratio_string(&self) -> String

Returns Self::polyrhythm_components formatted as a:b:c.

Source

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

Returns cloned pitches for every note in the chord, in input order.

Source

pub fn notes(&self) -> &[Note]

Returns the notes in input order.

Source

pub fn duration(&self) -> Option<&Duration>

Returns the chord duration when one has been assigned.

Source

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

Assigns a duration to the chord.

Source

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

Returns a copy of this chord with the supplied duration.

Source

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.

Source

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

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.

Source

pub fn normal_form(&self) -> Option<Vec<u8>>

Returns the transposed normal form 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.

Source

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.

Source

pub fn inversion(&self) -> Option<u8>

Returns the tertian inversion number, where root position is 0.

Returns None for empty chords, chords with fewer than three distinct pitch classes, or chords whose bass-to-root interval does not match a supported tertian inversion.

Source

pub fn inversion_name(&self) -> Option<String>

Returns a human-readable inversion label.

Returns None whenever Self::inversion returns None.

Source

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

Source

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.

Source

pub fn resolution_chords_in_key(&self, key: &Key) -> Result<Vec<Self>>

Returns likely tonal resolution chords in the supplied key.

Source

pub fn resolution_suggestions_in_key( &self, key: &Key, ) -> Result<Vec<ChordResolutionSuggestion>>

Returns likely tonal resolution suggestions in the supplied key.

Source

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.

Trait Implementations§

Source§

impl Clone for Chord

Source§

fn clone(&self) -> Chord

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Chord

Source§

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

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

impl<'de> Deserialize<'de> for Chord

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 Chord

Source§

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

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

impl From<Chord> for StreamElement

Source§

fn from(value: Chord) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Chord

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 Serialize for Chord

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 TryFrom<&[&str]> for Chord

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<&[Note]> for Chord

Source§

type Error = Error

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

fn try_from(value: &[Note]) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<&[Pitch]> for Chord

Source§

type Error = Error

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

fn try_from(value: &[Pitch]) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<&[String]> for Chord

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

impl TryFrom<&[i32]> for Chord

Source§

type Error = Error

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

fn try_from(value: &[IntegerType]) -> Result<Self>

Performs the conversion.
Source§

impl TryFrom<&str> for Chord

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 Chord

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§

§

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> 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,