MusicTheory Docs API Toolbox GitHub NuGet
Contents

API / MusicTheory

KeyDetector static class

Infers the key of a chord sequence with a cheap, explainable score over the 24 major/minor keys.
Per key: +1 for each chord whose root and triad quality are diatonic (minor keys also accept the harmonic-minor V and vii°; sus and power chords match any quality; 7ths and extensions count as their triad, so blues I7/IV7 fit), −1 for each chord that is not; +0.5 per tonic chord, +1 when the first chord is the tonic, +1.5 when the last is, and +1 per V→I move. So Am F C G is A minor before C major (it starts on Am), and Am Dm E7 Am is A minor (E7 is only diatonic there). Confidence is (max(score, 0) + 1) normalised over the returned candidates; the +1 keeps a single chord from looking certain.

Methods

static IReadOnlyList<KeyCandidate> Infer(IEnumerable<ChordSymbol> chords, int top = 3)
Ranks keys for a chord sequence, best first. Empty input gives an empty list.
static IReadOnlyList<KeyCandidate> Infer(IEnumerable<Chord> chords, int top = 3)
Ranks keys for a sequence of chords; see KeyDetector.Infer.