RomanNumeral¶
roman_numeral ¶
Roman numeral analysis.
The RomanNumeral namespace parses roman-numeral strings into structured
analysis objects. Used by Progression for chord
progression conversions and by Key internally for
diatonic chord generation.
The parser handles:
- Case to encode mode: uppercase = major (
I,V,bVII), lowercase = minor (i,iv,vi) - Accidentals:
#,b,x(double-sharp),bb(double-flat) - Optional chord-type suffix:
Vmaj7,iim7,bIII7b5
Example
from tonal_py import RomanNumeral RomanNumeral.get("V").interval '5P' RomanNumeral.get("bVII").interval '7m' RomanNumeral.get("iv").major False RomanNumeral.get("Vmaj7").chord_type 'maj7'
Source parity: @tonaljs/roman-numeral
tokenize ¶
Tokenize a roman-numeral string into its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
A roman-numeral string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
str
|
empty when input doesn't match. |
Example
from tonal_py import RomanNumeral RomanNumeral.tokenize("VIIb5") ('VIIb5', '', 'VII', 'b5') RomanNumeral.tokenize("bVII") ('bVII', 'b', 'VII', '') RomanNumeral.tokenize("garbage") ('', '', '', '')
Source code in src/tonal_py/roman_numeral.py
get ¶
Parse a roman numeral from a string, int, Pitch, or Interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src
|
Any
|
One of:
- A string like |
required |
Returns:
| Type | Description |
|---|---|
RomanNumeral
|
A |
RomanNumeral
|
unrecognized input. |
Example
from tonal_py import RomanNumeral RomanNumeral.get("V").interval '5P' RomanNumeral.get("V").major True RomanNumeral.get("v").major False RomanNumeral.get("Vmaj7").chord_type 'maj7' RomanNumeral.get(2).roman # 0-based: 2 -> "III" 'III'
Source code in src/tonal_py/roman_numeral.py
names ¶
Return the seven roman numerals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
major
|
bool
|
If True (default), returns uppercase (major); if False, returns lowercase (minor). |
True
|
Returns:
| Type | Description |
|---|---|
list[str]
|
|
Example
from tonal_py import RomanNumeral RomanNumeral.names() ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII'] RomanNumeral.names(major=False) ['i', 'ii', 'iii', 'iv', 'v', 'vi', 'vii']