@libraz/libcantus - v1.1.0
    Preparing search index...

    Class Chord

    An immutable chord: a root pitch class, quality, interval template, and optional slash bass, optionally carrying a Key context. Analysis methods (roman, function, analyze, ...) use an explicitly passed key first and fall back to the carried context.

    import { Chord } from '@libraz/libcantus';
    Chord.parse('Cmaj7').invert(1).symbol(); // 'Cmaj7/E' (third in the bass)
    Index
    • Wrap a plain chord object.

      Parameters

      • data: ChordData

        The chord; it is copied, never retained or mutated.

      • Optionalkey: KeyLike

        Optional key context for analysis methods, in whatever form the caller holds it: a key name, a plain key/scale, or a Key.

      Returns Chord

    • get intervals(): number[]

      A copy of the semitone offsets above the root.

      Returns number[]

    • get bassPc(): number | undefined

      The slash-chord bass pitch class, or undefined in root position.

      Returns number | undefined

    • get spec(): ChordSpec

      The chord read structurally: the triad it is built on, its seventh, and the alterations, additions and omissions on top of them.

      The reading comes from the tones themselves, so a chord no symbol names — a detected pitch set, a custom interval template — still describes itself; only a template with no structural reading at all falls back to the one its quality names.

      Returns ChordSpec

      If the chord's template has no reading and its quality is unknown.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('Cmaj7').spec.base; // 'maj'
      Chord.parse('C/E').spec.bassPc; // 4
    • Build a chord from a root and quality.

      Parameters

      • root: string | number

        Root as a note name (e.g. 'Eb') or a pitch class.

      • quality: ChordQuality

        The chord quality.

      • Optionalbass: string | number

        Optional slash-chord bass, as a note name (e.g. 'Bb') or a pitch class. A named bass keeps its own spelling.

      Returns Chord

      The chord (without key context).

    • The chord a figured bass names: a bass note, the figures written under it, and the key that supplies every interval the figures leave unaltered.

      The inverse of Chord.figuredBass, and a static because the figures build a chord rather than read one. The result carries the given bass as its slash bass, so an inversion reads as one wherever a bass is measured against a root, and it keeps the letters the figures asked for. A moving figure such as 4-3 yields the chord it resolves into.

      No key context is attached — the key here decides what the figures mean, not how the chord is later analyzed — so use Chord.withKey to carry one on.

      Parameters

      • bass: NoteLike

        The bass note, spelled, as a note name, a MIDI number, or a Note; its octave, if any, is not used.

      • figures: string

        The figures written under the bass; empty for an unfigured note.

      • key: KeyLike

        The prevailing key; a key name, a plain key/scale, or a Key.

      Returns Chord

      The chord the figures name (without key context).

      If the figures are malformed or name no chord, if the key is not heptatonic, or if the figures sound a chord no ChordQuality names.

      import { Chord } from '@libraz/libcantus';
      Chord.fromFiguredBass('B', '6', 'C major').symbol(); // 'G/B'
      Chord.fromFiguredBass('G', 'n', 'C minor').symbol(); // 'G'
    • Parse a lead-sheet chord symbol (e.g. 'Cmaj7', 'F#m7b5', 'C/G').

      A symbol is English unless a system is asked for: unlike Key.parse, which reads the notation system off the name, 'B' here is always the B natural until 'german' says otherwise.

      Parameters

      • symbol: string

        The chord symbol.

      • Optionalopts: NoteNameOptions

        system reads the root and bass in that notation system instead of English.

      Returns Chord

      The chord (without key context).

      If the root or quality is not recognized. Use Chord.tryParse where failure is ordinary, such as a chord field read on every keystroke.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('H7', { system: 'german' }).symbol(); // 'B7'
    • Parse a lead-sheet chord symbol, reporting failure instead of throwing it.

      The same reading as Chord.parse, for the callers where a symbol that does not parse yet is the normal state of the input rather than a fault: a chord field can show what is wrong with what has been typed so far without a try around every keystroke.

      Parameters

      • symbol: string

        The chord symbol.

      • Optionalopts: NoteNameOptions

        system reads the root and bass in that notation system instead of English.

      Returns ParseResult<Chord>

      The chord (without key context), or the error explaining why the text is not one.

      import { Chord } from '@libraz/libcantus';
      const result = Chord.tryParse('Cmaj7(#11)');
      result.ok ? result.value.symbol() : result.error.message; // 'Cmaj7#11'
    • Identify the chords matching a set of pitches, keeping each match's recognition metadata beside the chord.

      Chord.detect discards the confidence signals a recognition UI needs — whether the set matched exactly, which chord tones were missing, which input notes were foreign, and which inversion the bass implies.

      Parameters

      Returns { chord: Chord; match: ChordMatch }[]

      Ranked interpretations, each with its chord and its match record.

      import { Chord } from '@libraz/libcantus';
      const [best] = Chord.detectMatches([60, 64, 67]);
      best?.match.exact; // true
    • A copy of this chord carrying the given key context.

      Only a spelling the caller supplied (via Chord.parse, Chord.of with a named root, or plain data carrying a hint) survives; a spelling that came from a previously attached key is re-derived, so re-keying a progression during a modulation does not keep the old key's letters and the order of withKey calls does not affect the result.

      Parameters

      • key: KeyLike

        The key context to attach; a key name, a plain key/scale, or a Key.

      Returns Chord

      The new chord.

    • The chord's sorted, deduplicated pitch classes.

      A slash bass is one of them, because the chord sounds it.

      Parameters

      • Optionalopts: { includeBass?: boolean }

        Set includeBass: false to enumerate the interval template alone, leaving a slash bass out.

      Returns number[]

      Pitch classes ascending in [0, 11].

      import { Chord } from '@libraz/libcantus';
      Chord.parse('F/G').pitchClasses(); // [0, 5, 7, 9]
      Chord.parse('F/G').pitchClasses({ includeBass: false }); // [0, 5, 9]
    • Whether a pitch is one of the chord's tones, ignoring octave.

      A slash bass counts, as it does in Chord.pitchClasses: the chord sounds it.

      Parameters

      • pitch: number

        A MIDI pitch or a bare pitch class.

      Returns boolean

      True when the pitch class belongs to the chord.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('Cmaj7').contains(64); // true
      Chord.parse('Cmaj7').contains(62); // false
    • A pitch's harmonic role in the chord: root, third, fifth, sixth, or seventh.

      The role follows the pitch's interval above the root, so it answers for the chord's own template rather than for the interval alone: the diminished fifth of a half-diminished seventh is its fifth, while the same interval over a chord that already has a perfect fifth is a #11 tension and has no basic role.

      Parameters

      • pitch: number

        A MIDI pitch or a bare pitch class.

      Returns ChordToneRole | null

      The chord-tone role, or null when the pitch is a tension or a foreign note.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('Cmaj7').roleOf(67); // 'fifth'
      Chord.parse('Cmaj7').roleOf(62); // null
    • The chord's Roman numeral in a key.

      Parameters

      • Optionalkey: KeyLike

        Key to analyze in, as a key name, a plain key/scale, or a Key; falls back to the carried context.

      • Optionalopts: ChordToRomanOptions

        Applied-numeral rendering options.

      Returns string

      The Roman numeral string.

      If no key is given and none is carried.

    • The chord's Roman numeral together with the reasoning behind it: the degree its root was read as, the quality that set the numeral's case and suffix, and what became of the bass.

      The numeral is exactly the one Chord.roman gives for the same arguments, so this is that method with its rationale attached — for teaching material, and for any interface whose users argue with the analysis. Ask for alternatives to see the numerals the other option settings would have rendered, and why this one was rendered instead.

      Parameters

      Returns RomanExplanation

      The numeral, its rationale, and the rejected readings.

      If no key is given and none is carried.

      import { Chord, Key } from '@libraz/libcantus';
      Chord.parse('G7').explain(Key.major('C')).roman; // 'V7'
      Chord.parse('D7').explain('C major', { alternatives: true }).alternatives.length;
    • The chord's harmonic function (tonic / subdominant / dominant) in a key.

      Parameters

      • Optionalkey: KeyLike

        Key to analyze in, as a key name, a plain key/scale, or a Key; falls back to the carried context.

      Returns HarmonicFunction

      The harmonic function.

      If no key is given and none is carried.

    • Full functional analysis: function, borrowing, Roman numeral, and the rationale behind them.

      Parameters

      • Optionalkey: KeyLike

        Key to analyze in, as a key name, a plain key/scale, or a Key; falls back to the carried context.

      • Optionalopts: AnalyzeChordOptions

        Applied-numeral rendering options, plus alternatives to collect the readings this analysis turned down; see AnalyzeChordOptions.

      Returns ChordAnalysis

      The chord analysis.

      If no key is given and none is carried.

      import { Chord, Key } from '@libraz/libcantus';
      Chord.parse('D7').analyze(Key.major('C'), { alternatives: true }).alternatives.length;
    • Whether the chord is borrowed from the parallel mode (modal interchange).

      Parameters

      • Optionalkey: KeyLike

        Key to analyze in, as a key name, a plain key/scale, or a Key; falls back to the carried context.

      Returns boolean

      True if the chord is borrowed.

      If no key is given and none is carried.

    • The origin of a non-diatonic chord (parallel mode or Neapolitan), or null.

      Parameters

      • Optionalkey: KeyLike

        Key to analyze in, as a key name, a plain key/scale, or a Key; falls back to the carried context.

      Returns BorrowedSource

      The borrowing source, or null.

      If no key is given and none is carried.

    • The chord written as the figures a bass would carry under it: 6, 64, 7, 65, 43, 42, or nothing at all for a root-position triad, with an accidental on any interval the key does not already give.

      The bass the figures are measured above is the chord's own slash bass, or its root in root position.

      Parameters

      • Optionalkey: KeyLike

        Key deciding which intervals need no accidental; a key name, a plain key/scale, or a Key. Falls back to the carried context.

      Returns string

      The figures, as realizeFiguredBass reads them.

      If no key is given and none is carried, if the key is not heptatonic, or if no figure names the chord — its bass is not one of its tones, its tones do not stack in diatonic thirds above that bass, or it is an added-tone or extended chord the notation has no abbreviation for.

      import { Chord, Key } from '@libraz/libcantus';
      Chord.parse('G/B').figuredBass(Key.major('C')); // '6'
      Chord.parse('G7/D').figuredBass('C major'); // '43'
    • The chords that can stand in for this one in a key: its tritone substitute, the diatonic triads a third away that share two of its tones, the parallel-mode chords with its harmonic function, and its chromatic mediants.

      Each candidate carries the relationship it realizes, its Roman numeral, and its harmonic function in the key.

      Parameters

      • Optionalkey: KeyLike

        Key the substitution is read in; a key name, a plain key/scale, or a Key. Falls back to the carried context.

      • Optionalopts: SubstituteOptions

        Set melodyPcs to the pitch classes a melody holds over this chord, so only substitutions that keep every one of them a chord tone are proposed.

      Returns Substitution[]

      The deduplicated candidates; the chords are plain data, spelled the way the key writes them.

      If no key is given and none is carried.

      import { Chord, Key } from '@libraz/libcantus';
      const subs = Chord.parse('G7').withKey(Key.major('C')).substitutions();
      subs.find((sub) => sub.type === 'tritone')?.chord.rootPc; // 1
    • The modal-interchange palette of the chord's key: the parallel mode's triads that the key itself does not contain, plus the Neapolitan, each with its Roman numeral and its borrowing source.

      The palette belongs to the key rather than to this chord, so it is the same list for every chord in it; it is reachable here because a chord is where a caller looking for somewhere else to go already is.

      Parameters

      • Optionalkey: KeyLike

        Key to borrow into; a key name, a plain key/scale, or a Key. Falls back to the carried context.

      Returns BorrowedChord[]

      The borrowed chords, spelled the way the mode they come from writes them.

      If no key is given and none is carried.

      import { Chord, formatChordSymbol, Key } from '@libraz/libcantus';
      const palette = Chord.parse('C').withKey(Key.major('C')).modalInterchange();
      palette.map((borrowed) => formatChordSymbol(borrowed.chord));
      // ['Cm', 'Ddim', 'Eb', 'Fm', 'Gm', 'Ab', 'Bb', 'Db']
    • The chord rendered as a lead-sheet symbol (e.g. 'Cmaj7', 'F#m7', 'C/G').

      Parameters

      • Optionalopts: ChordSymbolOptions

        Set flats: true to spell the root/bass with flats, or system to write them in another notation system.

      Returns string

      The chord symbol.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('Bb7').symbol({ system: 'german' }); // 'B7'
    • Realize the chord as one MIDI pitch per voice, ascending.

      A chord that carries a key passes it to the voicer, so the leading tone is not doubled; an explicit opts.key overrides it.

      Parameters

      • Optionalopts: VoicingOptions

        Voicing options; defaults to four SATB voices.

      Returns number[]

      MIDI pitches, ascending, one per voice.

      If no voicing fits the given ranges.

    • Realize the chord as a single styled voicing (close, drop2, drop3, shell, or rootless), optionally constraining the top voice.

      Parameters

      Returns number[]

      MIDI pitches, ascending.

    • The negative-harmony mirror of the chord about the key's tonic–dominant axis (major becomes minor and vice versa).

      Parameters

      • Optionalkey: KeyLike

        Key providing the reflection axis, as a key name, a plain key/scale, or a Key; falls back to the carried context.

      Returns Chord

      The mirrored chord, keeping any key context.

      If no key is given and none is carried.

    • The V7 that tonicizes this chord: a dominant seventh a perfect fifth above this chord's root.

      The target is the chord itself, so no key is involved and a borrowed or chromatic chord gets its dominant as readily as a diatonic one. A root spelling this chord supplied moves with the root, so Eb gives Bb7.

      Returns Chord

      The secondary dominant, keeping any key context.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('Eb').secondaryDominant().symbol(); // 'Bb7'
    • The n-th inversion: a copy whose bass is the chord tone n steps above the root in the interval template (invert(1) puts the third in the bass). n wraps around the template length; negative values count backwards.

      invert(0) (and any n that wraps to it) is root position, so it carries no slash bass and equals the original chord.

      Parameters

      • n: number

        The inversion number.

      Returns Chord

      The inverted chord, keeping any key context.

      If the chord has no intervals.

    • Transpose the chord by a number of semitones.

      The quality and interval template are carried over, so a chord that a symbol round-trip could not express — a custom interval set, an inversion — survives. A carried key moves with the chord, so the transposed chord keeps the same degree and function inside the transposed key.

      Parameters

      • semitones: number

        The signed semitone offset.

      Returns Chord

      The transposed chord, in the transposed key when one is carried.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('C/G').transpose(2).symbol(); // 'D/A'
    • Transpose the chord by a spelled interval.

      Unlike Chord.transpose, which picks letters from a semitone count, the interval's diatonic number decides them: a C chord up an augmented fourth is F#, up a diminished fifth Gb. As with the semitone form, the quality and interval template are carried over and a carried key moves with the chord.

      Parameters

      • interval: IntervalLike

        An interval name (e.g. 'A4', '-m3'), plain interval data, or an Interval; a descending interval moves down.

      Returns Chord

      The transposed chord, in the transposed key when one is carried.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('C').transposeBy('A4').symbol(); // 'F#'
      Chord.parse('C').transposeBy('d5').symbol(); // 'Gb'
    • The scales that fit over this chord, each with the tones it does not state sorted by what may be done with them: the ones to avoid outright, the ones a line may pass through, and the ones that may be added freely as color.

      Chord.scales ranks the same scales in the same order; this is that ranking read as playing advice, so a caller does not have to pair it with Chord.avoidNotes and Chord.tensions once per scale.

      Parameters

      • Optionallimit: number

        Greatest number of scales to report; all of them by default.

      Returns ChordScaleReportEntry[]

      One entry per reported scale, best fit first; see ChordScaleReportEntry.

      If limit is not a positive integer.

      import { Chord } from '@libraz/libcantus';
      Chord.of('C', 'maj7').scaleReport(1)[0]?.passing; // [5]
    • The available tensions (usable non-chord, non-avoid scale tones) of a scale over this chord.

      Parameters

      • scaleName: ScaleNameInput

        A scale of NAMED_SCALES, or one of its aliases, rooted on the chord root. The scales of WORLD_SCALES are refused here as they are by Chord.scales: chord-scale theory is a Western practice, and a scale from another tradition offered over a chord would read as an answer while being a category error.

      • Optionalopts: AvailableTensionsOptions

        Set resolvesTo to the plain chord this one resolves to, so a dominant resolving down a fifth onto a minor tonic takes the tensions that resolution makes available; see AvailableTensionsOptions.

      Returns number[]

      Tension pitch classes, ascending in [0, 11].

      If scaleName is not one of the named scales or their aliases.

      import { Chord } from '@libraz/libcantus';
      Chord.of('G', 'dom7').tensions('phrygianDominant', {
      resolvesTo: Chord.of('C', 'min').data,
      }); // [3, 8]
    • The avoid notes (scale tones a semitone above a chord tone) of a scale over this chord.

      Parameters

      • scaleName: ScaleNameInput

        A scale of NAMED_SCALES, or one of its aliases, rooted on the chord root. The scales of WORLD_SCALES are refused here as they are by Chord.scales: chord-scale theory is a Western practice, and a scale from another tradition offered over a chord would read as an answer while being a category error.

      • Optionalopts: AvoidNotesOptions

        Set use: 'melodic' to judge a line rather than a voicing, so a tone a line may pass through is not counted; see AvoidNotesOptions.

      Returns number[]

      Avoid-note pitch classes, ascending in [0, 11].

      If scaleName is not one of the named scales or their aliases.

      import { Chord } from '@libraz/libcantus';
      Chord.of('C', 'maj7').avoidNotes('ionian'); // [5]
      Chord.of('C', 'maj7').avoidNotes('ionian', { use: 'melodic' }); // []
    • Spell the chord tones with letter names, root first, in the key's spelling.

      A chord that already knows how its root is spelled — one from Chord.parse, or Chord.of with a named root — can spell itself with no key at all; a key is only needed to choose a spelling for a bare pitch class.

      A slash bass outside the chord tones is appended, so the spelled notes are the notes the chord sounds — the same set Chord.pitchClasses reports.

      Parameters

      • Optionalkey: KeyLike

        Key providing the spelled tonic, as a key name, a plain key/scale, or a Key — the tonic its letters are spelled from is derived from the key rather than asked of the caller. Falls back to the carried context, then to the chord's own root spelling.

      Returns Note[]

      Spelled octave-less notes in the chord's own (tertian) order, with any foreign slash bass last.

      If no key is given, none is carried, and the chord has no root spelling of its own.

    • Start a progression with this chord followed by others, carrying this chord's key context (if any).

      Parameters

      • ...others: Chord[]

        The chords following this one.

      Returns Progression

      The progression.

    • The chord placed at a beat, as the ChordSpan the arrangement and generation functions take.

      The interval template is recorded only when it departs from the one the quality names, so a standard chord yields the same span it always did while a custom template is not lost. Key context and spelling hints are not part of a span and are left behind.

      Parameters

      • startBeat: number

        Beat the chord starts on.

      Returns ChordSpan

      The span describing this chord at that beat.

      If startBeat is not finite, or the chord's quality is unknown.

      import { Chord } from '@libraz/libcantus';
      Chord.parse('Cmaj7').span(4); // { rootPc: 0, quality: 'maj7', startBeat: 4 }
    • Whether another chord has the same root, quality, intervals, and bass. Key context is not compared.

      Parameters

      • other: Chord

        The chord to compare.

      Returns boolean

      True if the chord data is identical.

    • The chord symbol, so a template literal or a log line reads as the chord.

      Returns string

      The symbol, e.g. 'Cmaj7'.