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

    Function keyTimelineFromNotes

    • Infer where the key changes from raw notes.

      The span is examined in minKeyBeats slots. Each slot's pitch-class distribution is correlated against all 24 major and minor key profiles, and the run of keys that best explains the piece is chosen, paying a cost per modulation that rises with the distance travelled around the circle of fifths and falls on strong beats. Adjacent slots agreeing on a key become one region.

      The metric accents that discount a modulation follow the signature in force at the beat in question, so a piece that changes meter is read in the meter it is actually in. The first downbeat is beat 0, so a pickup is written at negative beats and its notes argue for the key like any others rather than falling outside the span.

      Pivot chords are not reported here: naming one requires knowing which chord sounded at the boundary, which raw notes do not say. Use detectModulations when a chord timeline is in hand.

      Parameters

      Returns KeyRegion[]

      The key regions in time order; empty when nothing sounds.

      import { keyTimelineFromNotes } from '@libraz/libcantus';
      const notes = [
      { pitch: 60, startBeat: 0, durationBeat: 4 },
      { pitch: 64, startBeat: 4, durationBeat: 4 },
      ];
      const regions = keyTimelineFromNotes(notes);
      regions[0]?.key; // the key in force at the start