@libraz/libcantus - v0.9.3
    Preparing search index...

    Class Key

    An immutable key/scale: a KeyScale (root pitch class plus mode mask) paired with a spelled tonic that anchors letter-name spelling. Acts as the factory for key-aware chords.

    import { Key } from '@libraz/libcantus';
    Key.major('C').chord(4).symbol(); // 'G' (the diatonic triad on scale degree 4)
    Index
    • Wrap a key/scale and its spelled tonic.

      Parameters

      • scale: KeyScale

        The key/scale; its root is normalized to a pitch class.

      • tonic: Note

        The spelled tonic anchoring letter-name spelling.

      Returns Key

    • get rootPc(): number

      The tonic pitch class (0..11).

      Returns number

    • get isMinor(): boolean

      Whether the scale has a minor third and no major third.

      Returns boolean

    • A major key.

      Parameters

      • root: string | number

        Tonic as a note name (e.g. 'Eb') or a pitch class; a numeric root is spelled with whichever accidental side yields the fewest accidentals across the scale.

      Returns Key

      The major key.

    • A natural-minor key.

      Parameters

      • root: string | number

        Tonic as a note name or a pitch class; a numeric root is spelled with whichever accidental side yields the fewest accidentals across the scale.

      Returns Key

      The minor key.

    • A key on a named scale (e.g. 'dorian', 'harmonicMinor').

      Parameters

      • name: string

        The scale name, a key of the scale module's named-scale table.

      • root: string | number

        Tonic as a note name or a pitch class.

      Returns Key

      The key.

      If the name is not a known scale.

    • Wrap an existing KeyScale, synthesizing a spelled tonic when none is given (flat-preferred for minor-third scales, sharp-preferred otherwise).

      Parameters

      • scale: KeyScale

        The key/scale to wrap.

      • Optionaltonic: Note

        Optional spelled tonic.

      Returns Key

      The key.

    • The scale's pitch classes in ascending scale-degree order (degree 0 first).

      Returns number[]

      One pitch class per scale degree.

    • The spelled scale, one note per degree (e.g. C D E F G A B for C major).

      Returns Note[]

      Spelled octave-less notes in scale-degree order.

    • The spelled scale as letter-name strings.

      Returns string[]

      One name per scale degree.

    • Build a chord on a scale degree, carrying this key as context.

      With an explicit quality the quality's interval template is attached to the degree's diatonic root; without one the scale-correct diatonic triad is stacked (e.g. a diminished triad on the leading tone of a major key).

      Parameters

      • degree: number

        0-based scale degree of the chord root.

      • Optionalquality: ChordQuality

        Optional chord quality.

      Returns Chord

      The chord, with this key attached.

    • The diatonic triad on a scale degree, carrying this key as context.

      Parameters

      • degree: number

        0-based scale degree of the chord root.

      Returns Chord

      The triad, with this key attached.

    • The diatonic seventh chord on a scale degree, carrying this key as context.

      Parameters

      • degree: number

        0-based scale degree of the chord root.

      Returns Chord

      The seventh chord, with this key attached.

    • Build the chord denoted by a Roman numeral in this key (including applied chords such as 'V7/V'), carrying this key as context.

      Parameters

      • text: string

        The Roman numeral.

      Returns Chord

      The chord, with this key attached.

      If the numeral is not valid.

    • Whether a pitch belongs to the scale.

      Parameters

      • x: number | Note

        A MIDI pitch, bare pitch class, or note.

      Returns boolean

      True if the pitch class is a scale tone.

    • The plain key data, for JSON serialization.

      Private class fields do not serialize, so an explicit toJSON keeps JSON.stringify(key) from collapsing to {}. The result pairs the KeyScale with the spelled tonic, enough to reconstruct the key via Key.of.

      Returns { scale: KeyScale; tonic: NoteData }

      The key/scale and its spelled tonic.