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

    Function prevailingKeyOf

    • The single key that holds for most of a run of regions.

      Callers that only want one key — a key signature to print, a scale to offer — need the one the piece spends the most time in, not the one it happens to start on.

      Parameters

      • regions: readonly KeyRegion[]

        The regions to weigh, as returned by the key-region entry points.

      Returns ResolvedKey | null

      The longest-held key, or null when there are no regions.

      import { keyTimelineFromNotes, prevailingKeyOf } from '@libraz/libcantus';
      const notes = [{ pitch: 60, startBeat: 0, durationBeat: 4 }];
      const key = prevailingKeyOf(keyTimelineFromNotes(notes));