Scale¶
scale ¶
Scale construction, detection, and analysis.
The Scale namespace builds scales from a tonic and type, detects scales
from notes, and answers questions like "what chords fit this scale?",
"what scales contain this scale?", and "what are the modes of this scale?".
Scale names follow the format <tonic> <type>, where:
- Tonic is any note name (
C,Bb,F#) - Type is any scale type from the ScaleType
dictionary (
major,dorian,harmonic minor,messiaen's mode #3...)
Either part can be omitted: "C" is just the tonic with no type, "major"
is the type with no tonic.
Example
from tonal_py import Scale Scale.get("C major").notes ('C', 'D', 'E', 'F', 'G', 'A', 'B') Scale.detect(["C", "D", "E", "F", "G", "A", "B"], {"match": "exact"}) ['C major']
Source parity: @tonaljs/scale
ScaleDetectOptions ¶
Bases: TypedDict
Options for detect.
Attributes:
| Name | Type | Description |
|---|---|---|
tonic |
str
|
Override the inferred tonic (which defaults to the first note in the input). Useful when the first note isn't actually the tonal center. |
match |
str
|
Either |
tokenize ¶
Split a scale string into (tonic, type).
Either component may be empty:
- "C major" -> ("C", "major")
- "major" -> ("", "major")
- "C" -> ("C", "")
- garbage -> ("", "garbage")
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Any
|
A scale string. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, str]
|
|
Example
from tonal_py import Scale Scale.tokenize("C major") ('C', 'major') Scale.tokenize("major") ('', 'major')
Source code in src/tonal_py/scale.py
get ¶
Build a Scale from a name string or [tonic, type] tokens.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Any
|
A scale name string or a 2-element list |
required |
Returns:
| Type | Description |
|---|---|
Scale
|
A |
Example
from tonal_py import Scale s = Scale.get("C major") s.notes ('C', 'D', 'E', 'F', 'G', 'A', 'B') s.tonic 'C' s.type 'major' Scale.get("major").notes # no tonic -> no notes ()
Source code in src/tonal_py/scale.py
detect ¶
Identify scales matching a list of notes.
The first note in the input is used as the tonic unless options.tonic
overrides it. By default, returns exact matches plus any scales that
extend the input. Pass match="exact" to suppress the extensions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notes_in
|
list[str]
|
Notes to detect scales from. |
required |
options
|
ScaleDetectOptions | None
|
See |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Matching scale names (e.g. |
Example
from tonal_py import Scale Scale.detect(["C", "D", "E", "F", "G", "A", "B"], {"match": "exact"}) ['C major']
Source code in src/tonal_py/scale.py
scale_chords ¶
Find chord types whose notes are all contained in this scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A scale name. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Chord aliases for chords compatible with the scale. |
Example
from tonal_py import Scale chords = Scale.scale_chords("C major") "M" in chords # major triad True "maj7" in chords # major 7 True
Source code in src/tonal_py/scale.py
extended ¶
Find scales that extend this one (contain all its notes plus more).
Accepts either a scale name or a 12-bit chroma string directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A scale name or chroma string. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Scale names whose pitch class set is a superset. |
Example
from tonal_py import Scale "major" in Scale.extended("C major pentatonic") True
Source code in src/tonal_py/scale.py
reduced ¶
Find scales contained within this one (subset of notes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A scale name. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Scale names whose pitch class set is a subset. |
Example
from tonal_py import Scale "major pentatonic" in Scale.reduced("C major") True
Source code in src/tonal_py/scale.py
scale_notes ¶
Sort + dedupe a notes list, then rotate so the first note is the tonic.
Useful for building a scale from a melodic fragment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notes_in
|
list[str]
|
A list of notes. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted unique pitch classes, rotated so the input's first note |
list[str]
|
is at index 0. |
Example
from tonal_py import Scale Scale.scale_notes(["G", "C", "E", "G", "A"]) ['G', 'A', 'C', 'E']
Source code in src/tonal_py/scale.py
mode_names ¶
Get all modes of a scale, paired with their starting tonics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
A scale name. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
List of |
Example
from tonal_py import Scale Scale.mode_names("C major") # doctest: +NORMALIZE_WHITESPACE [('C', 'major'), ('D', 'dorian'), ('E', 'phrygian'), ('F', 'lydian'), ('G', 'mixolydian'), ('A', 'minor'), ('B', 'locrian')]
Source code in src/tonal_py/scale.py
range_of ¶
Build a function that produces in-scale notes between two pitches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale_input
|
Any
|
A scale name or list of notes. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[str, str], list[str]]
|
A function |
Callable[[str, str], list[str]]
|
notes in the scale between (and including) the bounds. |
Example
from tonal_py import Scale rng = Scale.range_of("C major") rng("C4", "G4") ['C4', 'D4', 'E4', 'F4', 'G4']
Source code in src/tonal_py/scale.py
degrees ¶
Return a function mapping 1-based scale degree to a note name.
Degree 0 returns "". Negative degrees count backwards from the
scale's last note.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale_name
|
str
|
A scale name. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[int], str]
|
A function |
Example
from tonal_py import Scale deg = Scale.degrees("C major") deg(1) 'C' deg(5) 'G' deg(0) ''
Source code in src/tonal_py/scale.py
steps ¶
Return a function mapping 0-based step to a note name.
Like degrees but 0-indexed; wraps cyclically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scale_name
|
str
|
A scale name. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[int], str]
|
A function |
Example
from tonal_py import Scale step = Scale.steps("C major") step(0) 'C' step(7) # wraps to next octave's tonic 'C'