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

    Function keySignatureFifths

    • The key signature of a key, as a signed count of sharps (positive) or flats (negative) — the fifths value a notation format such as MusicXML writes.

      The tonic's letter and accidental place the key on the circle of fifths, and the mode moves it from there: lydian +1, major 0, mixolydian -1, dorian -2, natural minor -3, phrygian -4, locrian -5.

      A scale that is not a diatonic mode has no signature of its own, so it takes the signature of its parallel major or minor: a scale with a minor third and no major third counts as minor (-3), everything else as major (0). This is why A harmonic minor reports 0 — its G# is written as an accidental, not in the signature — and why A melodic minor reports 0 as well.

      The result is not clamped: a theoretical key such as Fb major reports -8. Clamp to ±7 if the consuming format cannot express more.

      Parameters

      • tonic: NoteLike

        The spelled tonic, as a note name, note data, or a Note; its accidental is worth seven fifths.

      • key: KeyLike

        The key/scale. This one stays a plain key/scale: it reads any 12-bit mask, including the tonic-less ones a key name cannot describe.

      Returns number

      The signed number of sharps (positive) or flats (negative).

      import { keySignatureFifths, majorKey, minorKey, parseNote } from '@libraz/libcantus';
      keySignatureFifths(parseNote('Bb'), majorKey(10)); // -2
      keySignatureFifths('A', minorKey(9)); // 0