Rank keys by how well they contain a set of note events, weighting each note
by how much of the music it actually occupies.
detectKey counts every pitch once, which lets a run of fast ornamental
notes outvote the sustained harmony that establishes the key. This weighs
each note by the same measure chord inference weighs its own histogram by, so
the two agree on what the music emphasises: duration times
velocity, with a note that carries no velocity counted at full weight rather
than at an assumed one. Notes that never sound (zero or negative duration)
are ignored. The weighted distribution is then ranked exactly as
detectKey ranks it, by correlation against a key profile, so score
is a finite correlation in [-1, 1].
The one term of that measure this cannot share is the metric accent, which
chord inference adds to an onset by the beat it falls on: the notes arrive
here without the meter they are counted in, and reading them against an
assumed one would rank the same notes differently under a signature the
caller never named. Ranking a whole piece is the coarser question, and the
accents are what separate one window from the next rather than one key from
another.
Which profile to rank with, whether the modes take part, and the
budget for processing imported note events; the weights are derived from the
notes themselves.
Rank keys by how well they contain a set of note events, weighting each note by how much of the music it actually occupies.
detectKey counts every pitch once, which lets a run of fast ornamental notes outvote the sustained harmony that establishes the key. This weighs each note by the same measure chord inference weighs its own histogram by, so the two agree on what the music emphasises: duration times velocity, with a note that carries no velocity counted at full weight rather than at an assumed one. Notes that never sound (zero or negative duration) are ignored. The weighted distribution is then ranked exactly as detectKey ranks it, by correlation against a key profile, so
scoreis a finite correlation in [-1, 1].The one term of that measure this cannot share is the metric accent, which chord inference adds to an onset by the beat it falls on: the notes arrive here without the meter they are counted in, and reading them against an assumed one would rank the same notes differently under a signature the caller never named. Ranking a whole piece is the coarser question, and the accents are what separate one window from the next rather than one key from another.