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.
The key signature of a key, as a signed count of sharps (positive) or flats (negative) — the
fifthsvalue 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.