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

    Function parseChordSymbol

    • Parse a lead-sheet chord symbol into a Chord.

      Accepts <root><quality>[/<bass>], e.g. Cmaj7, F#m7b5, Bb7, C/G, C6/9, C6/9/E. Root and bass letters are case-insensitive, matching parseNote. A / is ambiguous between a slash bass and the 6/9 quality; the text splits at the last / whose right-hand side is a valid bare note preceded by a recognized quality, so 6/9 (with or without a further slash bass) parses as a quality.

      The root and bass are read in system, so a German chart's H7, As7 and Ges/B are read by asking for 'german'. The system is never inferred: with none given the symbol is English, where B is the B natural and H no note at all. Case carries nothing in a chord symbol — unlike a German key name, where the case of the tonic is the mode — so the quality suffix alone says major or minor. Where a German root's flat suffix could equally open the quality, the longest root that leaves a known quality behind wins: Asus4 is an A suspended chord and Assus4 the A flat one.

      The quality suffix is read structurally when no name covers it, so a chart's bracketed tensions parse as readily as the names do: Cmaj7(#11), C7(b9,#11), C7(13), Csus4(add9), C-Δ9, C6/9(#11). A / between two figures separates them as it does inside brackets, which is what the sixth and ninth of a 6/9 are. Such a chord carries the tones it names and reports the nearest quality name (see chordSpecQuality); read chordSpecOf for its structure.

      The parsed chord carries the root/bass spellings as enharmonic hints (rootSpelling/bassSpelling) so formatChordSymbol can reproduce flat spellings such as Bbmaj7 instead of respelling them with sharps.

      Parameters

      • text: string

        The chord symbol text.

      • Optionalopts: NoteNameOptions

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

      Returns ChordData

      The parsed chord.

      If the root or quality is not recognized in that system. Use tryParseChordSymbol where failure is ordinary, such as a chord field read on every keystroke.

      import { parseChordSymbol, formatChordSymbol } from '@libraz/libcantus';
      const c = parseChordSymbol('Bbmaj7');
      formatChordSymbol(c); // 'Bbmaj7' — flat spelling is preserved on round-trip
      parseChordSymbol('H7', { system: 'german' }).rootPc; // 11 — the B natural
      parseChordSymbol('B', { system: 'german' }).rootPc; // 10 — the German B flat