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

    Function detectKeyBest

    • The single best key interpretation of a pitch set.

      The counterpart of detectChordBest: the ranked list is the general answer, but a caller that just wants "what key is this" should not have to index into it and assert the result is there. The winner is the candidate whose key profile correlates best with the input distribution, with the same deterministic tie-break detectKey applies, so its score is a finite correlation in [-1, 1] rather than a membership share.

      This is where DetectKeyOptions.explain earns its keep: the winner is the only match a caller of this function sees, and with explain it carries both its own rationale and the candidates it beat.

      Parameters

      • pitches: readonly number[]

        MIDI pitches or bare pitch classes.

      • opts: DetectKeyOptions = {}

        How to weigh the input, which profile to rank with, and whether the modes take part; see DetectKeyOptions.

      Returns KeyMatch | null

      The top-ranked key, or null when nothing sounds.

      When weights does not have one entry per pitch, profile is not a known name or a valid pair of 12-entry vectors, or modes names something that is not a church mode.

      When a pitch is outside the MIDI domain or the input exceeds the budget.

      import { detectKeyBest } from '@libraz/libcantus';
      detectKeyBest([0, 2, 4, 5, 7, 9, 11])?.mode; // 'major'