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

    Function parseKeyName

    • Parse a key name such as 'C major', 'gis moll' or '嬰ト短調'.

      The name is a tonic followed by a mode word, in any of the supported notation systems; German also accepts its hyphenated form ('gis-Moll'). Without a system the name is attributed by detectNoteNameSystem, so a mode word is itself enough to pick one: 'B dur' is B flat major while 'B major' is B major.

      German carries the mode twice, in the word and in the case of the tonic (C dur, c moll). When the two disagree the word wins — 'C moll' is C minor — because the word is what the writer said and the case only what they typed. A German name with no mode word is decided by its case alone ('gis' is G sharp minor, 'Gis' G sharp major); a bare tonic in any other system names a major key.

      Parameters

      • text: string

        The key name.

      • Optionalopts: NoteNameOptions

        system reads the name in that notation system instead of detecting it.

      Returns KeyName

      The spelled tonic and the mode.

      If the text is not a key name in the given (or detected) system, if it mixes two systems, or if the tonic carries an octave. Use tryParseKeyName where failure is ordinary, such as a key field read on every keystroke.

      import { formatNote, parseKeyName } from '@libraz/libcantus';
      const key = parseKeyName('gis moll');
      formatNote(key.tonic); // 'G#'
      key.mode; // 'minor'