Universal Music Theory Library - v0.12.0
    Preparing search index...

    Class KeyDetection

    Key Detection Module Implements correlation key finding (Krumhansl-Schmuckler) with a choice of key profiles.

    Index

    Constructors

    Properties

    majorProfile: number[] = ...

    Krumhansl-Kessler major weights, the default profile (KEY_PROFILES.krumhansl.major).

    minorProfile: number[] = ...

    Krumhansl-Kessler minor weights, the default profile (KEY_PROFILES.krumhansl.minor).

    Methods

    • Detects the most likely key based on an array of notes. Each note counts once, or by its duration when durations is given (as in the original Krumhansl-Schmuckler algorithm). Notes outside 12-TET count for the nearest 12-TET pitch class.

      Parameters

      • notes: Note[]

        The notes to analyse.

      • Optionaldurations: readonly number[]

        Optional duration of each note, in any unit (only proportions matter).

      • options: KeyDetectionOptions = {}

        profile: which key profile to correlate with (default Krumhansl-Kessler); modes: also read church modes.

      Returns { confidence: number; key: string }[]

      Array of possible keys sorted by confidence (Pearson correlation coefficient).

      • confidence: number

        Pearson correlation with the profile, -1 to 1.

      • key: string

        Key name with a capitalized mode: 'C Major', 'Eb Minor'; with modes, the first may be a church mode ('D Dorian').

      RangeError if durations does not match notes in length, or holds a negative or non-finite value.

    • Detects the most likely key from a pitch class histogram (index 0 = C, 1 = C#/Db, … 11 = B), e.g. total durations per pitch class accumulated over a piece.

      Parameters

      • weights: readonly number[]

        12 non-negative weights.

      • options: KeyDetectionOptions = {}

        profile: which key profile to correlate with (default Krumhansl-Kessler); modes: also read church modes.

      Returns { confidence: number; key: string }[]

      Array of possible keys sorted by confidence; empty when all weights are 0.

      • confidence: number

        Pearson correlation with the profile, -1 to 1.

      • key: string

        Key name with a capitalized mode: 'C Major', 'Eb Minor'; with modes, the first may be a church mode ('D Dorian').

      RangeError if there are not 12 weights, or one is negative or non-finite.