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

    Class Scale

    A scale: a root pitch plus an ordered pattern of step intervals within a tuning system.

    stepPattern defines the intervals between consecutive degrees in tuning steps (e.g. [2, 2, 1, 2, 2, 2, 1] for major in 12-TET). The pattern is relative - the same pattern at a different rootStep gives the same scale type in a different key.

    Index

    Constructors

    • Parameters

      • name: string

        Human-readable scale name (e.g. "C Major", "D Dorian").

      • tuningSystem: TuningSystem

        The tuning system this scale operates in.

      • rootStep: number

        Step offset of the root note from A4 (= 0).

      • stepPattern: readonly number[]

        Intervals between consecutive scale degrees, in tuning steps. Must be non-empty with all values > 0.

      • OptionalpreferFlats: boolean

        Optional flat/sharp preference for note naming in getNotes(). When provided, overrides the root-name heuristic. Set by parseScaleSymbol using preferFlatsForKey(root, scaleType) for mode-aware accuracy.

      Returns Scale

    Properties

    name: string

    Human-readable scale name (e.g. "C Major", "D Dorian").

    preferFlats?: boolean

    Optional flat/sharp preference for note naming in getNotes(). When provided, overrides the root-name heuristic. Set by parseScaleSymbol using preferFlatsForKey(root, scaleType) for mode-aware accuracy.

    rootStep: number

    Step offset of the root note from A4 (= 0).

    stepPattern: readonly number[]

    Intervals between consecutive scale degrees, in tuning steps. Must be non-empty with all values > 0.

    tuningSystem: TuningSystem

    The tuning system this scale operates in.

    Methods

    • Returns true if the given step (or its pitch class) belongs to this scale. Comparison is by pitch class - octave is ignored.

      Parameters

      • step: number

      Returns boolean

    • Returns the diatonic chord built on a single scale degree (1-indexed). See getDiatonicChords for details on type and naming.

      Parameters

      • degree: number
      • type: "triad" | "seventh" = 'triad'

      Returns Chord

    • Returns the 1-indexed scale degree of the given step, or null if not in the scale. Comparison is by pitch class - octave is ignored.

      Parameters

      • step: number

      Returns number | null

    • Returns the diatonic chords built by stacking thirds on each scale degree.

      • 'triad' (default): three-note chord (root, 3rd, 5th).
      • 'seventh': four-note chord (root, 3rd, 5th, 7th).

      Chord names are canonical (e.g. Bm7b5, Caug), in 12-TET and in any tuning where every degree stands for a 12-TET note (retune); otherwise a structural label is used (e.g. "Step 3(0,5,11)").

      Scales with fewer than 5 notes may not support 'seventh' on every degree.

      Parameters

      • type: "triad" | "seventh" = 'triad'

      Returns Chord[]

    • Returns modal characteristics: brightness (relative to Ionian), the degrees that differ from the parallel major, traditional jazz avoid notes, and parent-family info.

      characteristicDegrees/characteristicIntervals and avoidNotes are computed in 12-TET and in any tuning where every degree stands for a 12-TET note; otherwise they are empty. Brightness uses MODE_BRIGHTNESS; returns 0 if the mode is unknown.

      Returns ModalCharacteristics

    • Derives a mode from the current scale by rotating its step pattern.

      Parameters

      • degree: number

        1-indexed mode degree (e.g. 2 for Dorian if current scale is Major). Must be an integer.

      Returns Scale

    • Returns the notes of the scale across the given number of octaves.

      The result always includes one extra note at the end: the root repeated one period above the last octave (e.g. 8 notes for a 7-note scale over 1 octave). This matches standard notation and is useful for display.

      Parameters

      • octaves: number = 1

        Number of octaves to span (default: 1).

      Returns Note[]

    • Returns the parent scale of this mode (e.g. D Dorian → C major), or null if this scale is not a recognized mode of a known family.

      Returns Scale | null

    • Returns the pitch classes of the scale degrees as step offsets within one period (0 to octaveSteps - 1), starting from the root pitch class.

      Does not include the repeated octave note. A 7-note scale returns 7 pitch classes.

      Returns number[]

    • Returns the relative mode within the same modal family (e.g. D Dorian → F Lydian). Returns null if the target mode is in a different family or either mode is unknown.

      Parameters

      • targetModeName: string

      Returns Scale | null

    • The same scale in another tuning: each degree goes to the step of tuning that stands for the same 12-TET note (TuningSystem.retuneStep). Name and flat/sharp preference are kept.

      Parameters

      Returns Scale | null

      The scale in tuning, or null when one of its degrees stands for no 12-TET note or tuning has no step for it.

    • Returns a new scale with the same pattern transposed by the given number of steps. Named with the new root and the same type ("C major" +2 → "D major"); the root takes the spelling of the key with fewer accidentals.

      Parameters

      • steps: number

      Returns Scale