
    rh|                   T   % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  \
" S/ SQ5      r\
" S/ SQ5      r\R8                  " S5      r\R<                  " SSS9r\R@                  " S5      r!\R@                  " S5      r"0 r#S\$S'   0 r%S\$S'   \RL                  " 5       r'Sr(S \$S!'   SS" jr)0 S#S$_S%S$_S&S'_S(S)_S*S)_S+S)_S,S-_S.S-_S/S-_S0S-_S1S-_S2S-_S3S4_S5S6_S7S8_S9S:_S;S<_S=S<S=S>.Er*0 0 S?.r+S@\$SA'   0 SBSC_SDSE_SFSG_SHSI_SJSK_SLSM_SNSO_SPSQ_SRSS_STSU_SVSW_SXSY_SZS[_S\S]_S^S__S`Sa_SbSc_0 SdSe_SfSg_ShSi_SjSk_SlSm_SnSo_SpSq_SrSs_StSu_SvSw_SxSy_SzS{_S|S}_S~S_SS_SS_SS_ESSSSSSSSSSSSSSS.Er,S\$S'   S r-S r.SS jr/SS jr0        SS jr1      SS jr2SSS jjr3      SS jr4  S       SS jjr5 " S S\Rl                  5      r7 " S S\Rp                  5      r9 " S S\:\95      r; " S S\Rx                  5      r=S\=R|                  l          " S S\R~                  5      r@ " S S\R~                  5      rA\=/rB\CS:X  a  SSKr\R                  " \@5        gg)z7
Music21 class for dealing with Roman Numeral analysis
    )annotationsN)
namedtuple)chord)common)defaults)environment)exceptions21)notation)harmony)intervalkey)note)pitch)scaleFigureTuple)	aboveBassalterprefixChordFigureTuple)r   r   r   r   romanTRomanNumeral)boundz#*-*b*o*[1-9xyz]z[b\-]$zdict[str, scale.ConcreteScale]_scaleCachezdict[str, key.Key]	_keyCache))   )r      )r      )r      r   )r   r    )r   r   r   )r   r   )r   r      )r   r!   )r!   )   r   r    r   )r   r    r   r   )r   r   r   r!   )r"   r    r   r!   )	   r"   r   r    r   )r"   r   r    r   r   )r#   r   r    r   r   )r#   r"   r   r   r   )r"   r   r    r   r!   ztuple[tuple[int, ...], ...]FIGURES_IMPLYING_ROOTc                    U [         ;   a  [        R                  " [         U    5      nU$ [        R                  " U 5      nU[         UR                  '   U$ )zl
get a key from the cache if it is there; otherwise
create a new key and put it in the cache and return it.
)r   copyr   KeytonicPitchNameWithCase)keyStrkeyObjs     G/home/james-whalen/.local/lib/python3.13/site-packages/music21/roman.py_getKeyFromCacher,   L   sL    
 
 9V,- M 39	&//0M    53 36367537757397539975953979593653656b536b56434364242bb7b5b3o7u   ø7)b7b5b3bb7b53b7b53majorminorzdict[str, dict]figureShorthandsModeId   iZ   V7P   VF   V65D   I6A   V6?   V43=   I64<   IV;   i6:   viio79   V427   viio655   viio64   z#viio653   ii2   z#viio61   ii650   ii43/   ii42.   IV6-   ii6+   VI*   #VI)   vi(   viio'   z#viio&   iio%   iio42$   bII6#   It6"   Ger65!   iio43                                           
   )iio65Fr43z#vioz#vio6IIISw43vVIIVII7IV65IV7iiiiii6vi6zdict[str, int]functionalityScoresc                H   U R                  SS5      n [        R                  U 5      (       a  U S-  n [        R                  " SSU 5      n [        R                  " SSU 5      n [        R                  " SS	U 5      n [
        R                  U 5      n[        U5      S
:X  a   US   R                  S5      (       a  SUS   /n/ nU H\  n[        R                  " SSU5      n[        R                  " SSU5      n[        R                  " S	SU5      nUR                  U5        M^     U$ )a  
Expands shorthand notation into a list with all figures expanded:

>>> roman.expandShortHand('64')
['6', '4']
>>> roman.expandShortHand('973')
['9', '7', '3']
>>> roman.expandShortHand('11b3')
['11', 'b3']
>>> roman.expandShortHand('b13#9-6')
['b13', '#9', '-6']
>>> roman.expandShortHand('-')
['5', '-3']

Slashes don't matter:

>>> roman.expandShortHand('6/4')
['6', '4']

Note that this is not where abbreviations get expanded:

>>> roman.expandShortHand('')
[]
>>> roman.expandShortHand('7')  # not 7, 5, 3
['7']
>>> roman.expandShortHand('4/3')  # not 6, 4, 3
['4', '3']

Note that this is ['6'] not ['6', '3']:

>>> roman.expandShortHand('6')
['6']

Returns a list of individual shorthands.
/r/   r0   11x13y15z   r   5)
replaceENDWITHFLAT_REmatchresubSHORTHAND_REfindalllenendswithappend)	shorthandshorthandGroups
shGroupOutshs       r+   expandShortHandr      s   H !!#r*II&&S	tS),ItS),ItS),I"**95O
?q _Q%7%@%@%E%E 23JVVCr"VVCr"VVCr""	 
 r-   c                   U R                  S5      nUS:X  a  SnOUS:X  a  SnOSnU(       a`  UR                  S5      (       dB  UR                  S5      (       d,  UR                  S5      (       d  UR                  S	5      (       a  US:X  a  SnU R                  S
5      nU(       a  US:X  a  US:X  a  US:X  a  S	nX1-   $ US:w  a   X1-   $ )z
Correct a given inversionString suffix given a chord of various qualities.

>>> c = chord.Chord('E3 C4 G4')
>>> roman.correctSuffixForChordQuality(c, '6')
'6'

>>> c = chord.Chord('E3 C4 G-4')
>>> roman.correctSuffixForChordQuality(c, '6')
'o6'

r    r   o   +r/      °/o   ør"   r   r#   )semitonesFromChordStep
startswith)chordObjinversionString	fifthTypequalityNameseventhTypes        r+   correctSuffixForChordQualityr      s     //2IA~	aO66s;;.99$??.99$??.99$??#K11!4KyA~"!3K (( A((r-   c                Z   Uc$  [         R                  " U R                  5       5      n[        X5      nUS   R                  n/ nU R
                  nU R                  nU R                  nUS:w  a  SnSn	Sn
ObU R                  5       n	U	(       a  SOU R                  5       n
U	=(       d0    U
=(       d'    U R                  5       =(       d    U R                  5       n[        US S9 H  nUR                  nUR                  S:w  a   UR                  UL a  U	(       d  U
(       a  SnO(UR                  S:w  a  UR                  UL a	  U(       a  SnUR                  S:X  a:  UR                  U:w  a(  US:w  a   US-   nX;  a  UR!                  SU5        M  M  M  M  U[#        UR                  5      -   nX;  d  M  UR%                  U5        M     SR'                  U5      nUR(                  nU[*        ;   a  U[*        U   ;   a
  [*        U   nOU[,        ;   a	  [,        U   nUS	;   a  S
n[/        X5      nU$ )a"  
(Note: this will become a private function by v10.)

Returns the post-RN figure for a given chord in a given key.

If keyObj is none, it uses the root as a major key:

>>> roman.postFigureFromChordAndKey(
...     chord.Chord(['F#2', 'D3', 'A-3', 'C#4']),
...     key.Key('C'),
...     )
'o6#5b3'

The function substitutes shorthand (e.g., '6' not '63')

>>> roman.postFigureFromChordAndKey(
...     chord.Chord(['E3', 'C4', 'G4']),
...     key.Key('C'),
...     )
'6'

>>> roman.postFigureFromChordAndKey(
...     chord.Chord(['E3', 'C4', 'G4', 'B-5']),
...     key.Key('F'),
...     )
'65'

>>> roman.postFigureFromChordAndKey(
...     chord.Chord(['E3', 'C4', 'G4', 'B-5']),
...     key.Key('C'),
...     )
'6b5'

We reduce common omissions from seventh chords to be '7' instead
of '75', '73', etc.

>>> roman.postFigureFromChordAndKey(
...     chord.Chord(['A3', 'E-4', 'G-4']),
...     key.Key('b-'),
...     )
'o7'

OMIT_FROM_DOCS

Fails on German Augmented 6th chords in root position.  Calls them
half-diminished chords.

(This is in OMIT_FROM_etc.)
r   r   Fc                b    SU R                   -  U R                  U R                  R                  4$ )N)r   r   r   ps)tups    r+   <lambda>+postFigureFromChordAndKey.<locals>.<lambda>b  s     b3==&8#))SYY\\%Rr-   r   r   r/   8)r5   r6   r4   )r   r'   rootfigureTuplesr   thirdfifthpitchClassCardinalityisMajorTriadisMinorTriadisDiminishedTriadisAugmentedTriadsortedr   r   r   insertstrr   joinmoderN   figureShorthandsr   )r   r*   chordFigureTuplesbassFigureAlterallFigureStringListr   r   chordCardinalitychordObjIsStandardTriadr   r   ftr   figureStringallFigureStringkey_modes                   r+   postFigureFromChordAndKeyr     s   d ~)$X6'*00ONNENNE  551"',,. ,u(2G2G2I ++))++ ((*	 	  &RT <<1U!2| lla((e#)F<<1xx?*v|%|:'..q,? ; 0<* "C$55L6#**<85T8 gg12O{{H ''O?ST\?],].?	,	,*?; ,&28MOr-   c                    / nU R                  5       nU R                   HL  n[        XAU5      n[        UR                  UR
                  UR                  U5      nUR                  U5        MN     U$ )aI	  
(This will become a private function in v10)

Return a set of tuplets for each pitch showing the presence of a note, its
interval above the bass its alteration (float) from a step in the given
key, an `alterationString`, and the pitch object.

Note though that for roman numerals, the applicable key is almost always
the root.

For instance, in C major, F# D A- C# would be:

>>> roman.figureTuples(
...     chord.Chord(['F#2', 'D3', 'A-3', 'C#4']),
...     key.Key('C'),
...     )
[ChordFigureTuple(aboveBass=1, alter=1.0, prefix='#', pitch=<music21.pitch.Pitch F#2>),
 ChordFigureTuple(aboveBass=6, alter=0.0, prefix='', pitch=<music21.pitch.Pitch D3>),
 ChordFigureTuple(aboveBass=3, alter=-1.0, prefix='b', pitch=<music21.pitch.Pitch A-3>),
 ChordFigureTuple(aboveBass=5, alter=1.0, prefix='#', pitch=<music21.pitch.Pitch C#4>)]

In c-minor, the A- is a normal note, so the prefix is '' not 'b'.  The natural minor is used
exclusively.

>>> roman.figureTuples(
...     chord.Chord(['F#2', 'D3', 'A-3', 'C#4']),
...     key.Key('c'),
...     )
[ChordFigureTuple(aboveBass=1, alter=1.0, prefix='#', pitch=<music21.pitch.Pitch F#2>),
 ChordFigureTuple(aboveBass=6, alter=0.0, prefix='', pitch=<music21.pitch.Pitch D3>),
 ChordFigureTuple(aboveBass=3, alter=0.0, prefix='', pitch=<music21.pitch.Pitch A-3>),
 ChordFigureTuple(aboveBass=5, alter=1.0, prefix='#', pitch=<music21.pitch.Pitch C#4>)]

A C dominant-seventh chord in c minor alters the bass but not the 7th degree

>>> roman.figureTuples(
...     chord.Chord(['E3', 'C4', 'G4', 'B-5']),
...     key.Key('c'),
...     )
[ChordFigureTuple(aboveBass=1, alter=1.0, prefix='#', pitch=<music21.pitch.Pitch E3>),
 ChordFigureTuple(aboveBass=6, alter=0.0, prefix='', pitch=<music21.pitch.Pitch C4>),
 ChordFigureTuple(aboveBass=3, alter=0.0, prefix='', pitch=<music21.pitch.Pitch G4>),
 ChordFigureTuple(aboveBass=5, alter=0.0, prefix='', pitch=<music21.pitch.Pitch B-5>)]

>>> roman.figureTuples(
...     chord.Chord(['C4', 'E4', 'G4', 'C#4']),
...     key.Key('C'),
...     )
[ChordFigureTuple(aboveBass=1, alter=0.0, prefix='', pitch=<music21.pitch.Pitch C4>),
 ChordFigureTuple(aboveBass=3, alter=0.0, prefix='', pitch=<music21.pitch.Pitch E4>),
 ChordFigureTuple(aboveBass=5, alter=0.0, prefix='', pitch=<music21.pitch.Pitch G4>),
 ChordFigureTuple(aboveBass=1, alter=1.0, prefix='#', pitch=<music21.pitch.Pitch C#4>)]
)basspitchesfigureTupleSolor   r   r   r   r   )chordObject	keyObjectresultr   	thisPitch
shortTupleappendTuples          r+   r   r     sp    l FD ((	$Y4@
&z';';'1'7'7'1'8'8'02 	k" ) Mr-   c                (   UR                  U 5      u  p4[        R                  " X 5      nUR                  R                  R
                  nUc  SnSnO4UR                  n[        U5      n	U	S:  a	  SSU	-  -  nOU	S:  a  SU	-  nOSn[        XhU5      n
U
$ )a  
Return a single tuple for a pitch and key showing the interval above
the bass, its alteration from a step in the given key, an alteration
string, and the pitch object.

For instance, in C major, an A-3 above an F# bass would be:

>>> roman.figureTupleSolo(
...     pitch.Pitch('A-3'),
...     key.Key('C'),
...     pitch.Pitch('F#2'),
...     )
FigureTuple(aboveBass=3, alter=-1.0, prefix='b')

These figures can be more complex in minor, so this is a good reference, showing
that natural minor is always used.

>>> c = key.Key('c')
>>> c_as_bass = pitch.Pitch('C3')
>>> for name in ('E--', 'E-', 'E', 'E#', 'A--', 'A-', 'A', 'A#', 'B--', 'B-', 'B', 'B#'):
...     ft = roman.figureTupleSolo(pitch.Pitch(name + '4'), c, c_as_bass)
...     print(f'{name:4s} {ft}')
E--  FigureTuple(aboveBass=3, alter=-1.0, prefix='b')
E-   FigureTuple(aboveBass=3, alter=0.0, prefix='')
E    FigureTuple(aboveBass=3, alter=1.0, prefix='#')
E#   FigureTuple(aboveBass=3, alter=2.0, prefix='##')
A--  FigureTuple(aboveBass=6, alter=-1.0, prefix='b')
A-   FigureTuple(aboveBass=6, alter=0.0, prefix='')
A    FigureTuple(aboveBass=6, alter=1.0, prefix='#')
A#   FigureTuple(aboveBass=6, alter=2.0, prefix='##')
B--  FigureTuple(aboveBass=7, alter=-1.0, prefix='b')
B-   FigureTuple(aboveBass=7, alter=0.0, prefix='')
B    FigureTuple(aboveBass=7, alter=1.0, prefix='#')
B#   FigureTuple(aboveBass=7, alter=2.0, prefix='##')

Returns a namedtuple called a FigureTuple.
r/           r   br   #)	$getScaleDegreeAndAccidentalFromPitchr   Intervaldiatonicgenericmod7r   intr   )pitchObjr*   r   unused_scaleStepscaleAccidentalthisIntervalr   rootAlterationString	alterDiffr   r   s              r+   r   r     s    T )/(S(ST\(]%$$T4L%%--22I!	#))	I19#&"u*#5 QY#&; #% i4HIKr-   c                   [        U [        [        45      (       a  [        R                  " U 5      n O*[        U [        R                  5      (       d  [        S5      e/ nU R                   H  nUR                  UR                  5        M      UR                  S5      nUR                  S5      nSnSnUR                  U;   a  SnOUR                  U;   a  SnO[        SU5      R                  n[        SU5      R                  n	/ n
U H  nU
R                  UR                  5        M      / nU	 H  nUR                  UR                  5        M      [        [        U
5      [        U5      -  5      n[        [        U5      [        U5      -  5      nX:  a  SnO	X:  a  SnOgU(       aY  [        R                  " S5      nUR                  S:X  a  UR!                  5       nOUR#                  5       nU R%                  U5        O0U(       a(  [        R                  " S5      nU R%                  U5        OgU['        U 5      -   $ )	a  
Returns the roman numeral string expression (either tonic or dominant) that
best matches the inChord. Useful when you know inChord is either tonic or
dominant, but only two pitches are provided in the chord. If neither tonic
nor dominant is possibly correct, False is returned

>>> roman.identifyAsTonicOrDominant(['B2', 'F5'], key.Key('C'))
'V65'

>>> roman.identifyAsTonicOrDominant(['B3', 'G4'], key.Key('g'))
'i6'

>>> roman.identifyAsTonicOrDominant(['C3', 'B-4'], key.Key('f'))
'V7'

Notice that this -- with B-natural is also identified as V7 because
it is returning the roman numeral root and the inversion name, not yet
checking for correctness.

>>> roman.identifyAsTonicOrDominant(['C3', 'B4'], key.Key('f'))
'V7'

>>> roman.identifyAsTonicOrDominant(['D3'], key.Key('f'))
False
z,inChord must be a Chord or a list of stringsr   r    FTI7rS   rM   )
isinstancelisttupler   Chord
ValueErrorr   r   namepitchFromDegreer   r   setr   toRomanr   lowerupperr   romanInversionName)inChordinKeypitchNameListr   oneRootfiveRootoneChordIdentifiedfiveChordIdentifiedoneRomanChordfiveRomanChordonePitchNameListfivePitchNameList
oneMatchesfiveMatchesrootScaleDegs                  r+   identifyAsTonicOrDominantr*    s   : 'D%=))++g&--GHHM__QVV$ ##A&G$$Q'H||}$!	-	'"$T5199%dE2::A##AFF+  A$$QVV,   -.]1CCD
#/03}3EEF#!%%"&~~a(:: '--/L'--/LW	~~a(X,W555r-   c                R   Uc  U R                  5       nU R                  5       (       d  U R                  b  US:X  a  gUS:X  a  gUS:X  a  gUS:X  a  gg	U R                  5       (       d*  U R	                  5       (       d  U R                  5       (       a  US:X  a  g	US:X  a  g
US:X  a  gg	g	)a<  
Extremely similar to Chord's inversionName() method, but returns string
values and allows incomplete triads.

>>> roman.romanInversionName(chord.Chord('E4 G4 C5'))
'6'

>>> roman.romanInversionName(chord.Chord('G4 B4 C5 E5'))
'43'

Manually set the inversion to see what would happen.

>>> roman.romanInversionName(chord.Chord('C5 E5 G5'), inv=2)
'64'

>>> roman.romanInversionName(chord.Chord('C5 E5 G5'), inv=0)
''

Uncommon/unusual chords return an empty string

>>> roman.romanInversionName(chord.Chord('C5 C#4'))
''

Does not return ninth or eleventh chord figures.
r   r4   r   r?   r!   rC   r   rE   r/   r2   64)	inversion	isSeventhseventhisTriadisIncompleteMajorTriadisIncompleteMinorTriad)r  invs     r+   r  r  b  s    8 {!goo9!8AXAXAX
//

--//--//!8AXAXr-   c                
   UR                   S:w  a  U $ U R                  S;  a  U $ U R                  nU R                  nUS:X  a  SnSnO'US:X  a  SnSnOUS:  a  US-
  nUSS	 nOUS:  a  SU-   n[	        U R                  X#5      $ )
aq  
(This will become a private function in version 10)

Takes in a FigureTuple and a Key object and returns the same or a
new FigureTuple correcting for the fact that, for instance, Ab in c minor
is VI not vi.  Works properly only if the note is the root of the chord.

Used in RomanNumeralFromChord

These return new FigureTuple objects

>>> ft5 = roman.FigureTuple(aboveBass=6, alter=-1, prefix='')
>>> ft5a = roman.correctRNAlterationForMinor(ft5, key.Key('c'))
>>> ft5a
FigureTuple(aboveBass=6, alter=-1, prefix='b')
>>> ft5a is ft5
False

>>> ft6 = roman.FigureTuple(aboveBass=6, alter=0, prefix='')
>>> roman.correctRNAlterationForMinor(ft6, key.Key('c'))
FigureTuple(aboveBass=6, alter=0, prefix='b')

>>> ft7 = roman.FigureTuple(aboveBass=7, alter=1, prefix='#')
>>> roman.correctRNAlterationForMinor(ft7, key.Key('c'))
FigureTuple(aboveBass=7, alter=0, prefix='')

Does nothing for major and passes in the original Figure Tuple unchanged:

>>> ft1 = roman.FigureTuple(aboveBass=6, alter=-1, prefix='b')
>>> ft2 = roman.correctRNAlterationForMinor(ft1, key.Key('C'))
>>> ft2
FigureTuple(aboveBass=6, alter=-1, prefix='b')
>>> ft1 is ft2
True

Does nothing for steps other than 6 or 7:

>>> ft3 = roman.FigureTuple(aboveBass=4, alter=-1, prefix='b')
>>> ft4 = roman.correctRNAlterationForMinor(ft3, key.Key('c'))
>>> ft4
FigureTuple(aboveBass=4, alter=-1, prefix='b')
>>> ft3 is ft4
True
rM   r   r"   g      ?r   r/   r   r   r   N)r   r   r   r   r   )figureTupler*   r   r  s       r+   correctRNAlterationForMinorr7    s    ` {{gF*E&--|!	#"		3AB7	"%99{,,eJJr-   c                *
   0 SS_SS_SS_SS_SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SSSSSSSSS S S!.
EnSSSS
SSSSSSSSSSS".nS#S$S%S&S'.nS(S)S*S+S,S)S*S+S-.nUS.L nU R                   (       d
  [        5       $ U R                  5       nU R                  S/5      n	U	S0:X  a  S1n
OS2n
UcQ  U
(       a$  [	        UR
                  R                  5       5      nO#[	        UR
                  R                  5       5      nUnO+[        U[        5      (       a  [        R                  " U5      n[        XUR                  5      n[        X5      nUR                  S3:X  a  UR                  nOd[         R"                  " [         R$                  " S45      [         R&                  " UR                  5      5      nUR)                  UR                  5      nUR*                  S5:X  a  UR
                  R                  5       nOUR
                  R                  5       n[	        U5      n[,        R.                  " UR0                  5      nU
(       a  OU
(       d  UR                  5       n[3        U U5      nUR4                  U-   U-   nU
(       d3  UU;   a-  U R7                  S65      (       a  UR4                  U-   UU   -   nGO*U
(       d2  UU;   a,  U R7                  S75      (       a  UR4                  U-   UU   -   nOU(       d   UU;   a  U R9                  S1S89(       a  UU   nOU(       a  UU;   a  U R9                  S1S89(       a  UU   nUS.S9 nUS:;   aJ  U R:                  n[<        R>                  (       a  Uc   e[	        UR
                  R                  5       5      nOOUS;;   aI  U R@                  n[<        R>                  (       a  Uc   e[	        UR
                  R                  5       5      nU(       a  US<:w  a  U RC                  5       (       d  U RE                  5       (       a  U R                  5       RG                  S=5      R
                  nURI                  U5      nU(       aE  [        UUS2S>9RJ                  n[M        U [        R                  " U5      S2S>9RN                  nU S?U 3n [        UUS2[P        RR                  [P        RR                  S@9nU R                   Ul         U$ ! [T        RV                   a!  n[Y        SAR[                  UXU5      5      eS.nAff = f)Bu#  
Takes a chord object and returns an appropriate chord name.  If keyObj is
omitted, the root of the chord is considered the key (if the chord has a
major third, it's major; otherwise it's minor).

>>> rn = roman.romanNumeralFromChord(
...     chord.Chord(['E-3', 'C4', 'G-6']),
...     key.Key('g#'),
...     )
>>> rn
<music21.roman.RomanNumeral bivo6 in g# minor>

The pitches remain the same with the same octaves:

>>> for p in rn.pitches:
...     p
<music21.pitch.Pitch E-3>
<music21.pitch.Pitch C4>
<music21.pitch.Pitch G-6>

>>> romanNumeral2 = roman.romanNumeralFromChord(
...     chord.Chord(['E3', 'C4', 'G4', 'B-4', 'E5', 'G5']),
...     key.Key('F'),
...     )
>>> romanNumeral2
<music21.roman.RomanNumeral V65 in F major>

Note that vi and vii in minor, by default, signifies what you might think of
alternatively as #vi and #vii:

>>> romanNumeral3 = roman.romanNumeralFromChord(
...     chord.Chord(['A4', 'C5', 'E-5']),
...     key.Key('c'),
...     )
>>> romanNumeral3
<music21.roman.RomanNumeral vio in c minor>

>>> romanNumeral4 = roman.romanNumeralFromChord(
...     chord.Chord(['A-4', 'C5', 'E-5']),
...     key.Key('c'),
...     )
>>> romanNumeral4
<music21.roman.RomanNumeral bVI in c minor>
>>> romanNumeral4.sixthMinor
<Minor67Default.CAUTIONARY: 2>

>>> romanNumeral5 = roman.romanNumeralFromChord(
...     chord.Chord(['B4', 'D5', 'F5']),
...     key.Key('c'),
...     )
>>> romanNumeral5
<music21.roman.RomanNumeral viio in c minor>

>>> romanNumeral6 = roman.romanNumeralFromChord(
...     chord.Chord(['B-4', 'D5', 'F5']),
...     key.Key('c'),
...     )
>>> romanNumeral6
<music21.roman.RomanNumeral bVII in c minor>

Diminished and half-diminished seventh chords can omit the third and still
be diminished: (n.b. we also demonstrate that chords can be created from a
string):

>>> romanNumeralDim7 = roman.romanNumeralFromChord(
...     chord.Chord('A3 E-4 G-4'),
...     key.Key('b-'),
...     )
>>> romanNumeralDim7
<music21.roman.RomanNumeral viio7 in b- minor>

For reference, odder notes:

>>> romanNumeral7 = roman.romanNumeralFromChord(
...     chord.Chord(['A--4', 'C-5', 'E--5']),
...     key.Key('c'),
...     )
>>> romanNumeral7
<music21.roman.RomanNumeral bbVI in c minor>

>>> romanNumeral8 = roman.romanNumeralFromChord(
...     chord.Chord(['A#4', 'C#5', 'E#5']),
...     key.Key('c'),
...     )
>>> romanNumeral8
<music21.roman.RomanNumeral #vi in c minor>

>>> romanNumeral10 = roman.romanNumeralFromChord(
...     chord.Chord(['F#3', 'A3', 'E4', 'C5']),
...     key.Key('d'),
...     )
>>> romanNumeral10
<music21.roman.RomanNumeral #iiiø7 in d minor>


Augmented 6ths without key context

>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 C#5'),
...     )
<music21.roman.RomanNumeral It6 in g minor>

>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 B-4 C#5'),
...     )
<music21.roman.RomanNumeral Ger65 in g minor>

>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 A4 C#5'),
...     )
<music21.roman.RomanNumeral Fr43 in g minor>

>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 A#4 C#5'),
...     )
<music21.roman.RomanNumeral Sw43 in g minor>

With correct key context:

>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 C#5'),
...     key.Key('G')
...     )
<music21.roman.RomanNumeral It6 in G major>

With incorrect key context does not find an augmented 6th chord:

>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 C#5'),
...     key.Key('C')
...     )
<music21.roman.RomanNumeral #io6b3 in C major>

Empty chords, including :class:`~music21.harmony.NoChord` objects, give empty RomanNumerals:

>>> roman.romanNumeralFromChord(harmony.NoChord())
<music21.roman.RomanNumeral>

Augmented 6th chords in other inversions do not currently find correct roman numerals

* Changed in v7: i7 is given for a tonic or subdominant minor-seventh chord in major:

>>> roman.romanNumeralFromChord(
...     chord.Chord('C4 E-4 G4 B-4'),
...     key.Key('C'))
<music21.roman.RomanNumeral i7 in C major>

>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 B-4 C5'),
...     key.Key('G'))
<music21.roman.RomanNumeral iv65 in G major>

minor-Major chords are written with a [#7] modifier afterwards:

>>> roman.romanNumeralFromChord(
...     chord.Chord('C4 E-4 G4 B4'),
...     key.Key('C'))
<music21.roman.RomanNumeral i7[#7] in C major>
>>> roman.romanNumeralFromChord(
...     chord.Chord('E-4 G4 B4 C5'),
...     key.Key('C'))
<music21.roman.RomanNumeral i65[#7] in C major>

Former bugs that are now fixed:

>>> romanNumeral11 = roman.romanNumeralFromChord(
...     chord.Chord(['E4', 'G4', 'B4', 'D5']),
...     key.Key('C'),
...     )
>>> romanNumeral11
<music21.roman.RomanNumeral iii7 in C major>

>>> roman.romanNumeralFromChord(chord.Chord('A3 C4 E-4 G4'), key.Key('c'))
<music21.roman.RomanNumeral viø7 in c minor>

>>> roman.romanNumeralFromChord(chord.Chord('A3 C4 E-4 G4'), key.Key('B-'))
<music21.roman.RomanNumeral viiø7 in B- major>

>>> romanNumeral9 = roman.romanNumeralFromChord(
...     chord.Chord(['C4', 'E5', 'G5', 'C#6']),
...     key.Key('C'),
...     )
>>> romanNumeral9
<music21.roman.RomanNumeral I#853 in C major>

Not an augmented 6th:

>>> roman.romanNumeralFromChord(
...     chord.Chord('E4 G4 B-4 C#5')
...     )
<music21.roman.RomanNumeral io6b5b3 in c# minor>


The preferSecondaryDominants option defaults to False, but if set to True,
then certain rare figures are swapped with their
more common secondary dominant equivalent to produce
Roman numerals like 'V/V' instead of 'II'.

This has no effect on most chords.
A change is triggered if and only if:

* the chord is a major triad or dominant seventh

* the chord is not diatonic to the primary key (i.e., chromatically altered)

* the root of secondary key is diatonic to the primary key.

So first without setting preferSecondaryDominants:

>>> cd = chord.Chord('D F# A')
>>> rn = roman.romanNumeralFromChord(cd, 'C')
>>> rn.figure
'II'

And now with preferSecondaryDominants=True:

>>> rn = roman.romanNumeralFromChord(cd, 'C', preferSecondaryDominants=True)
>>> rn.figure
'V/V'

Dominant sevenths must be spelt correctly
(see conditions at :meth:`~music21.chord.Chord.isDominantSeventh`).

So let's try D dominant seventh in various contexts.

>>> cd = chord.Chord('F#4 A4 C5 D5')

In G major this still comes out without recourse to a secondary,
whether preferSecondaryDominants is True or False.

>>> rn = roman.romanNumeralFromChord(cd, 'G')
>>> rn.figure
'V65'

>>> rn = roman.romanNumeralFromChord(cd, 'G', preferSecondaryDominants=True)
>>> rn.figure
'V65'

In C major it does come through as a secondary

>>> rn = roman.romanNumeralFromChord(cd, 'C', preferSecondaryDominants=True)
>>> rn.figure
'V65/V'

"German Augmented sixth" chords are left intact, without change.
This is thanks to the constraints on
spelling and on the root of the secondary degree.

>>> cd = chord.Chord('Ab4 C5 Eb5 F#5')
>>> rn = roman.romanNumeralFromChord(cd, 'C', preferSecondaryDominants=True)
>>> rn.figure
'Ger65'

Let's check that with a dominant seventh spelling and minor key context:

>>> cd = chord.Chord('Ab4 C5 Eb5 Gb5')
>>> rn = roman.romanNumeralFromChord(cd, 'c', preferSecondaryDominants=True)
>>> rn.figure
'bVIb753'

So that's a context in which the root is diatonic,
but the possible secondary root is not.
Now let's do the opposite case with a root that is not diatonic
and a secondary that is.

>>> cd = chord.Chord('Ab4 C5 Eb5 Gb5')
>>> rn = roman.romanNumeralFromChord(cd, 'c', preferSecondaryDominants=True)
>>> rn.figure
'bVIb753'

Watch out, because there are still a lot of chords that
preferSecondaryDominants will alter.
This is deliberate: this option defaults to false
so it does not run unless a user specifically initiates it
and actively wants to make modifications.
Power users could create more specific conditions in which to call it,
e.g., before/after specific chords,
and they can only do so if it errs on the side of more changes.

For example, in minor, 'I' will be mapped to 'V/iv'.

>>> cd = chord.Chord('F4 A4 C5')
>>> rn = roman.romanNumeralFromChord(cd, 'f')
>>> rn.figure
'I'

>>> cd = chord.Chord('F4 A4 C5')
>>> rn = roman.romanNumeralFromChord(cd, 'f', preferSecondaryDominants=True)
>>> rn.figure
'V/iv'

This might be appropriate in the middle of a progression like
i, V/iv, iv.
By contrast, it's probably not wanted for a tierce de picardie at the end
iv6, V, I.
This kind of context-sensitivity is not currently included.

OMIT_FROM_DOCS

Note that this should be III+642 gives III+#642 (# before 6 is unnecessary)

# >>> roman.romanNumeralFromChord(chord.Chord('B3 D3 E-3 G3'), key.Key('c'))
# <music21.roman.RomanNumeral III+642 in c minor>


These two are debatable -- is the harmonic minor or the natural minor used as the basis?

# >>> roman.romanNumeralFromChord(chord.Chord('F4 A4 C5 E-5'), key.Key('c'))
# <music21.roman.RomanNumeral IVb753 in c minor>
# <music21.roman.RomanNumeral IV75#3 in c minor>

# >>> roman.romanNumeralFromChord(chord.Chord('F4 A4 C5 E5'), key.Key('c'))
# <music21.roman.RomanNumeral IV7 in c minor>
# <music21.roman.RomanNumeral IV#75#3 in c minor>

(This is in OMIT_FROM_etc.)
z#ivo6b3r   z#ivob64It64z#ivobb64z#ivob5b3It53z	#ivob5bb3u   IIø#643r   u   IIø75#3Fr7u	   IIø7b5#3u   IIø6#42Fr42u	   IIøb6#42u   IIø65Fr65u   IIø65b3z#ii64b3r   u   #iiø7Sw7z	#iib7bb53z#iib642Sw42z#iibb642Sw65r   Ger43Ger42Ger7)
z#ii6b5b3z	#ii6b5bb3z	#ivo6b5b3z
#ivo6bb5b3z	#ivob64b3z#ivobb64bb3z	#ivob6b42z
#ivob6bb42u   #ivø7z#ivobb7b5bb3)io6b3iob64iob5b3u   Iø64b3u   Iøb7b53u   Iøb642u   Iø6b5b3i64b3ib7bb53ibb642i6b5bb3io6b5b3iob64b3iob6b42r4   r?   rC   rE   )b75b3rA   b64b36b42z7[#7]z65[#7]z43[#7]z42[#7]z#7)75b3r?   b643rP  z#753z6#53z64#3rE   Nr   r   TFr   r   rL   )r   r   r"   r   )r   r   r"      )permitAnyInversionr!   )ItGeFrSwrU   P4)preferSecondaryDominantsr   )updatePitches
sixthMinorseventhMinorz;Could not parse {0} from chord {1} as an RN in key {2}: {3}).r   r   r   r   r,   r  r  r  r  r   r   r'   r   tonicr7  r   r   intervalFromGenericAndChromaticGenericIntervalChromaticIntervaltransposePitchr   r   r  r   r   r   isSeventhOfTypeisAugmentedSixthr   tTYPE_CHECKINGr/  isDominantSeventhr   	transposegetScaleDegreeFromPitchromanNumeralAloneromanNumeralFromChordfigureMinor67Default
CAUTIONARY
fbNotationModifierExceptionRomanNumeralExceptionformat)r   r*   r[  aug6subsaug6NoKeyObjectSubsminorSeventhSubsminorMajorSeventhSubs
noKeyGivenr   	thirdTypeisMajorThird
rootKeyObjr   
tonicPitchtransposeIntervaltonicPitchNamealteredKeyObj	stepRomanr   rnStringnationalityStartr   r/  possibleSecondaryTonicdegreesecondaryAsRomanprimaryFigurernstrerrors                                r+   rl  rl    sb   J
56 	F 	F	
 	V 	F 	E 	U 	F 	V 	& 	F 	6  	%!" 	U#$ 	6%& 	F'( =HB %* 	 	 D.J~ ==?D//2IA~ ~)$))//*;<J)$))//*;<J	FC	 	 	v||	4B	$R	0B	xx1}\\
 %DD$$Q'&&rxx02 '55fllC
{{g#..0#..0$^4Mr||,IOO%	/-HOyy9$6H#33((7799y(+;O+LL!%::**=9999y(+@+QQ("''4'@H%
--''4'@&x0#BQ<|+NNE(((%ejj&6&6&89F-&&G***%gll&8&8&:;F 	!''))X-B-B-D-D!)!:!:4!@!E!E//0FG+F,2EJ . /@.?  2(25'':P2QKP4 5;F  (*:);<HL(F%%00~?X?XZ !!BJI '' L#$fXxJL 	LLs   !)S T1TTc                  (    \ rS rSrSrSrSrSrSrSr	g)	rn  i  a  
Enumeration that can be passed into :class:`~music21.roman.RomanNumeral`'s
keyword arguments `sixthMinor` and `seventhMinor` to define how Roman numerals
on the sixth and seventh scale degrees are parsed in minor.

Here is a little helper function that creates the chord in c-minor with the given
`sixthMinor` interpretation in order to show how Minor67Default affects the
interpretation of `vi`.

>>> vi = lambda sixChord, quality: ' '.join(p.name for p in roman.RomanNumeral(
...                                            sixChord,
...                                            'c',
...                                            sixthMinor=quality).pitches)

The default for new chords is `QUALITY`, which means that the chord quality
(major, minor, diminished) determines what note is the root, lowered ^6
or raised ^6:

>>> vi('vi', roman.Minor67Default.QUALITY)
'A C E'
>>> vi('VI', roman.Minor67Default.QUALITY)
'A- C E-'

The enumeration `FLAT` means that lowered ^6 is used for the root no matter what.
(Note that `FLAT` does not mean that the root will have a flat sign on it,
for instance, in f-sharp minor, lowered ^6 is D natural. and in a-sharp minor,
lowered ^6 is F#.)

>>> vi('vi', roman.Minor67Default.FLAT)
'A- C- E-'
>>> vi('VI', roman.Minor67Default.FLAT)
'A- C E-'

Conversely, `SHARP` implies that raised ^6 is used no matter what.

>>> vi('vi', roman.Minor67Default.SHARP)
'A C E'
>>> vi('VI', roman.Minor67Default.SHARP)
'A C# E'

Since `FLAT` assumes lowered ^6 whether the chord is major or minor (or anything else),
to get a raised ^6 with the `FLAT` enumeration add a sharp before the name:

>>> vi('#vi', roman.Minor67Default.FLAT)
'A C E'

Likewise, with `SHARP`, a flat sign is needed to get lowered ^6:

>>> vi('bVI', roman.Minor67Default.SHARP)
'A- C E-'

The enumeration of `CAUTIONARY` is identical to `QUALITY` except that it
ignores the `#` in #vi and the `b` in bVI, allowing users to write these
chords in two different way.  `CAUTIONARY` is recommended in the case where
users from different systems of training are working together, and no
exotic chords (such as major triads on raised ^6) are used.

>>> vi('#vi', roman.Minor67Default.CAUTIONARY)
'A C E'
>>> vi('vi', roman.Minor67Default.CAUTIONARY)
'A C E'
>>> vi('bVI', roman.Minor67Default.CAUTIONARY)
'A- C E-'
>>> vi('VI', roman.Minor67Default.CAUTIONARY)
'A- C E-'

Whereas `QUALITY` follows a strict interpretation of what preceeding sharp and flat
signs mean.  With `QUALITY`, since vi is already sharpened, #vi raises it even more.
And since VI is already flattened, bVI lowers it even further:

>>> vi('vi', roman.Minor67Default.QUALITY)
'A C E'
>>> vi('#vi', roman.Minor67Default.QUALITY)
'A# C# E#'
>>> vi('VI', roman.Minor67Default.QUALITY)
'A- C E-'
>>> vi('bVI', roman.Minor67Default.QUALITY)
'A-- C- E--'

If you are using the `CAUTIONARY` enum, these odd chords can still be created, but
an additional sharp or flat should be used.

>>> vi('##vi', roman.Minor67Default.CAUTIONARY)
'A# C# E#'
>>> vi('bbVI', roman.Minor67Default.CAUTIONARY)
'A-- C- E--'

For other odd chords that are contrary to the standard minor interpretation
in the "wrong" direction, the interpretation is the same as `QUALITY`.

For instance, here is a major triad on raised ^6 (what might be generally
conceived of as V/ii), in the `QUALITY` and `CAUTIONARY` systems:

>>> vi('#VI', roman.Minor67Default.QUALITY)
'A C# E'
>>> vi('#VI', roman.Minor67Default.CAUTIONARY)
'A C# E'

And a minor triad on lowered ^6.

>>> vi('bvi', roman.Minor67Default.QUALITY)
'A- C- E-'
>>> vi('bvi', roman.Minor67Default.CAUTIONARY)
'A- C- E-'

All these examples use ^6, but the same concepts apply to ^7 using
`seventhMinor` instead.

This enumeration applies to secondary chords built on ^6 or ^7:

>>> vi('V/vi', roman.Minor67Default.QUALITY)
'E G# B'
>>> vi('V/VI', roman.Minor67Default.QUALITY)
'E- G B-'

>>> vi('V/vi', roman.Minor67Default.FLAT)
'E- G B-'
>>> vi('V/VI', roman.Minor67Default.FLAT)
'E- G B-'

* Changed in v8: previously `sixthMinor` and `seventhMinor` did
  not carry over to secondary roman numerals.
r   r!   r   r    N)
__name__
__module____qualname____firstlineno____doc__QUALITYro  SHARPFLAT__static_attributes__r  r-   r+   rn  rn    s    zv GJEDr-   rn  c                      \ rS rSrSrSrg)RomanExceptionik  zN
RomanException will be removed in v10.  Catch RomanNumeralException instead.
r  N)r  r  r  r  r  r  r  r-   r+   r  r  k  s    r-   r  c                      \ rS rSrSrg)rr  iq  r  N)r  r  r  r  r  r  r-   r+   rr  rr  q  s    r-   rr  c                  V  ^  \ rS rSr% SrSr\R                  " S5      r\R                  " S5      r	\R                  " S5      r
\R                  " S5      r\R                  " S5      r\R                  " S	5      r\R                  " S
5      rSSSSS.r\R                  " S5      r0 SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S)_S*S+_S,S-_S.S/_S0S1_S2S3S4S5S6.ErS7\S8'     S^S9S9\R(                  \R(                  S:.   S_U 4S; jjjjrS< rS= rS> rS? rS`S@ jrSaSA jrSbSB jrScSC jr Sd     SeSD jjrS`SE jrS`SF jr S`SG jr!S`SH jr"      SfSI jr#    SgSJ jr$      ShSK jr%SaSL jr&SMSN.SiU 4SO jjjr'\(SjSP j5       r)\)RT                  SkSQ j5       r)\(SjSR j5       r+\+RT                  SlSS j5       r+\(SjST j5       r,\(SU 5       r-\-RT                  SV 5       r-\(SmSW j5       r. Sd   SnSX jjr/\(SoSY j5       r0\0RT                  SpSZ j5       r0 Sq SrS[ jjr1 Ss StS\ jjr2S]r3U =r4$ )ur   ix  u@  
A RomanNumeral object is a specialized type of
:class:`~music21.harmony.Harmony` object that stores the function and scale
degree of a chord within a :class:`~music21.key.Key`.

>>> ivInE = roman.RomanNumeral('IV', key.Key('E'))
>>> ivInE.pitches
(<music21.pitch.Pitch A4>, <music21.pitch.Pitch C#5>, <music21.pitch.Pitch E5>)

Octaves assigned are arbitrary (generally C-4 or above) and just exist
to keep the pitches properly sorted.

Major and minor are written with capital and lowercase numerals respectively.
Inversions and seventh-, ninth-, etc. chords are specified by putting the
figured bass symbols directly after the chord.  Keys can be specified with
Key objects or (less efficiently) a string.

Dominant-seventh chord in c minor.

>>> roman.RomanNumeral('V7', 'c').pitches
(<music21.pitch.Pitch G4>, <music21.pitch.Pitch B4>,
 <music21.pitch.Pitch D5>, <music21.pitch.Pitch F5>)

Minor chord on the fifth scale degree, in second inversion:

>>> roman.RomanNumeral('v64', 'c').pitches
(<music21.pitch.Pitch D4>, <music21.pitch.Pitch G4>, <music21.pitch.Pitch B-4>)


If no Key is given then it exists as a theoretical, keyless RomanNumeral;
e.g., V in any key.  But when realized, keyless RomanNumerals are
treated as if they are in C major.

>>> V = roman.RomanNumeral('V')
>>> V.quality
'major'

>>> V.inversion()
0

>>> V.forteClass
'3-11B'

>>> V.scaleDegree
5

Default key is C Major

>>> for p in V.pitches:
...     p
<music21.pitch.Pitch G4>
<music21.pitch.Pitch B4>
<music21.pitch.Pitch D5>

Neapolitan chords can be written as 'N6', 'bII6', or simply 'N'

>>> neapolitan = roman.RomanNumeral('N6', 'c#')
>>> neapolitan.key
<music21.key.Key of c# minor>

>>> neapolitan.isMajorTriad()
True

>>> neapolitan.scaleDegreeWithAlteration
(2, <music21.pitch.Accidental flat>)

>>> for p in neapolitan.pitches:
...     p
<music21.pitch.Pitch F#4>
<music21.pitch.Pitch A4>
<music21.pitch.Pitch D5>

>>> neapolitan2 = roman.RomanNumeral('bII6', 'g#')
>>> [str(p) for p in neapolitan2.pitches]
['C#5', 'E5', 'A5']

>>> neapolitan2.scaleDegree
2

Here's another dominant seventh chord in minor:

>>> em = key.Key('e')
>>> dominantV = roman.RomanNumeral('V7', em)
>>> [str(p) for p in dominantV.pitches]
['B4', 'D#5', 'F#5', 'A5']

Now using the older terminology where the case does not determine the
quality, it becomes a minor-seventh chord:

>>> minorV = roman.RomanNumeral('V43', em, caseMatters=False)
>>> [str(p) for p in minorV.pitches]
['F#4', 'A4', 'B4', 'D5']

(We will do this `str(p) for p in` thing enough that let's make a helper function:)

>>> def cp(rn_in):  # cp = chord pitches
...     return [str(p) for p in rn_in.pitches]
>>> cp(minorV)
['F#4', 'A4', 'B4', 'D5']

In minor -- VII and VI are assumed to refer to the flattened scale degree, while
vii, viio, viio7, viiø7 and vi, vio, vio7, and viø7 all refer to the sharpened scale
degree.  To get a minor triad on lowered 6 for instance, you will need to use 'bvi'
while to get a major triad on raised 6, use '#VI'.

The actual rule is that if the chord implies minor, diminished, or half-diminished,
an implied "#" is read before the figure.  Anything else does not add the sharp.
The lowered (natural minor) is the assumed basic chord.

>>> majorFlatSeven = roman.RomanNumeral('VII', em)
>>> cp(majorFlatSeven)
['D5', 'F#5', 'A5']

>>> minorSharpSeven = roman.RomanNumeral('vii', em)
>>> cp(minorSharpSeven)
['D#5', 'F#5', 'A#5']

>>> majorFlatSix = roman.RomanNumeral('VI', em)
>>> cp(majorFlatSix)
['C5', 'E5', 'G5']

>>> minorSharpSix = roman.RomanNumeral('vi', em)
>>> cp(minorSharpSix)
['C#5', 'E5', 'G#5']


These rules can be changed by passing in a `sixthMinor` or `seventhMinor` parameter set to
a member of :class:`music21.roman.Minor67Default`:

>>> majorSharpSeven = roman.RomanNumeral('VII', em, seventhMinor=roman.Minor67Default.SHARP)
>>> cp(majorSharpSeven)
['D#5', 'F##5', 'A#5']

For instance, if you prefer a harmonic minor context where VI (or vi) always refers
to the lowered 6 and viio (or VII) always refers to the raised 7, send along
`sixthMinor=roman.Minor67Default.FLAT` and `seventhMinor=roman.Minor67Default.SHARP`

>>> dimHarmonicSeven = roman.RomanNumeral('viio', em, seventhMinor=roman.Minor67Default.SHARP)
>>> cp(dimHarmonicSeven)
['D#5', 'F#5', 'A5']

>>> majHarmonicSeven = roman.RomanNumeral('bVII', em, seventhMinor=roman.Minor67Default.SHARP)
>>> cp(majHarmonicSeven)
['D5', 'F#5', 'A5']


>>> majHarmonicSix = roman.RomanNumeral('VI', em, sixthMinor=roman.Minor67Default.FLAT)
>>> cp(majHarmonicSix)
['C5', 'E5', 'G5']
>>> minHarmonicSix = roman.RomanNumeral('#vi', em, sixthMinor=roman.Minor67Default.FLAT)
>>> cp(minHarmonicSix)
['C#5', 'E5', 'G#5']

See the docs for :class:`~music21.roman.Minor67Default` for more information on
configuring sixth and seventh interpretation in minor
along with the useful `CAUTIONARY` setting where CAUTIONARY sharp and flat accidentals
are allowed but not required.

Either of these is the same way of getting a minor iii in a minor key:

>>> minoriii = roman.RomanNumeral('iii', em, caseMatters=True)
>>> cp(minoriii)
['G4', 'B-4', 'D5']

>>> minoriiiB = roman.RomanNumeral('IIIb', em, caseMatters=False)
>>> cp(minoriiiB)
['G4', 'B-4', 'D5']

`caseMatters=False` will prevent `sixthMinor` or `seventhMinor` from having effect.

>>> vii = roman.RomanNumeral('viio', 'a', caseMatters=False,
...                           seventhMinor=roman.Minor67Default.QUALITY)
>>> cp(vii)
['G5', 'B-5', 'D-6']

Can also take a scale object, here we build a first-inversion chord
on the raised-three degree of D-flat major, that is, F#-major (late
Schubert would be proud.)

>>> sharp3 = roman.RomanNumeral('#III6', scale.MajorScale('D-'))
>>> sharp3.scaleDegreeWithAlteration
(3, <music21.pitch.Accidental sharp>)

>>> cp(sharp3)
['A#4', 'C#5', 'F#5']

>>> sharp3.figure
'#III6'

Figures can be changed and pitches will change. (Caution: there are still some bugs on this
for extreme edge cases).

>>> sharp3.figure = 'V'
>>> cp(sharp3)
['A-4', 'C5', 'E-5']

A diminished chord is specified with an `o` (the letter-O) or `°` symbol:

>>> leadingToneSeventh = roman.RomanNumeral(
...     'viio', scale.MajorScale('F'))
>>> cp(leadingToneSeventh)
['E5', 'G5', 'B-5']
>>> cp(roman.RomanNumeral('vii°7', 'F'))
['E5', 'G5', 'B-5', 'D-6']

Note in the above example we passed in a Scale object not a Key.  This can be used
in the theoretical case of applying roman numerals in 7-note scales that are not
major or minor.  (see the documentation for the
:attr:`~music21.roman.RomanNumeral.scaleCardinality` attribute for scales other than
7-note scales).

Half-diminished seventh chords can be written with either `ø` or `/o` symbol:

>>> cp(roman.RomanNumeral('viiø7', 'F'))
['E5', 'G5', 'B-5', 'D6']
>>> cp(roman.RomanNumeral('vii/o7', 'F'))
['E5', 'G5', 'B-5', 'D6']

RomanNumeral objects can also be created with an int (number)
for the scale degree:

>>> majorKeyObj = key.Key('C')
>>> roman.RomanNumeral(1, majorKeyObj)
<music21.roman.RomanNumeral I in C major>

>>> minorKeyObj = key.Key('c')
>>> roman.RomanNumeral(1, minorKeyObj)
<music21.roman.RomanNumeral i in c minor>

A little modal mixture:

>>> lessObviousDiminished = roman.RomanNumeral(
...     'vio', scale.MajorScale('c'))
>>> for p in lessObviousDiminished.pitches:
...     p
<music21.pitch.Pitch A4>
<music21.pitch.Pitch C5>
<music21.pitch.Pitch E-5>

>>> diminished7th = roman.RomanNumeral(
...     'vio7', scale.MajorScale('c'))
>>> for p in diminished7th.pitches:
...     p
<music21.pitch.Pitch A4>
<music21.pitch.Pitch C5>
<music21.pitch.Pitch E-5>
<music21.pitch.Pitch G-5>

>>> diminished7th1stInv = roman.RomanNumeral(
...     'vio65', scale.MajorScale('c'))
>>> for p in diminished7th1stInv.pitches:
...     p
<music21.pitch.Pitch C4>
<music21.pitch.Pitch E-4>
<music21.pitch.Pitch G-4>
<music21.pitch.Pitch A4>

>>> halfDim7th2ndInv = roman.RomanNumeral(
...     'ivø43', scale.MajorScale('F'))
>>> for p in halfDim7th2ndInv.pitches:
...     p
<music21.pitch.Pitch F-4>
<music21.pitch.Pitch A-4>
<music21.pitch.Pitch B-4>
<music21.pitch.Pitch D-5>

>>> alteredChordHalfDim3rdInv = roman.RomanNumeral(
...     'biiø42', scale.MajorScale('F'))
>>> cp(alteredChordHalfDim3rdInv)
['F-4', 'G-4', 'B--4', 'D--5']

>>> alteredChordHalfDim3rdInv.intervalVector
[0, 1, 2, 1, 1, 1]

>>> alteredChordHalfDim3rdInv.commonName
'half-diminished seventh chord'

>>> alteredChordHalfDim3rdInv.romanNumeral
'bii'

>>> alteredChordHalfDim3rdInv.romanNumeralAlone
'ii'

Tones may be omitted by putting the number in a bracketed [noX] clause.
These numbers refer to the note above the root, not above the bass:

>>> openFifth = roman.RomanNumeral('V[no3]', key.Key('F'))
>>> openFifth.pitches
(<music21.pitch.Pitch C5>, <music21.pitch.Pitch G5>)
>>> openFifthInv = roman.RomanNumeral('V64[no3]', key.Key('F'))
>>> openFifthInv.pitches
(<music21.pitch.Pitch G4>, <music21.pitch.Pitch C5>)

Some theoretical traditions express a viio7 as a V9 chord with omitted
root. Music21 allows that:

>>> fiveOhNine = roman.RomanNumeral('V9[no1]', key.Key('g'))
>>> cp(fiveOhNine)
['F#5', 'A5', 'C6', 'E-6']

Putting [no] or [add] should never change the root

>>> fiveOhNine.root()
<music21.pitch.Pitch D5>

Tones may be added by putting a number (with an optional accidental) in
a bracketed [addX] clause:

>>> susChord = roman.RomanNumeral('I[add4][no3]', key.Key('C'))
>>> susChord.pitches
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch F4>, <music21.pitch.Pitch G4>)
>>> susChord.root()
<music21.pitch.Pitch C4>

Figures such as 'V54' give the same result:

>>> anotherSus = roman.RomanNumeral('V54', key.Key('C'))
>>> anotherSus.pitches
(<music21.pitch.Pitch G4>, <music21.pitch.Pitch C5>, <music21.pitch.Pitch D5>)

Putting it all together:

>>> weirdChord = roman.RomanNumeral('V65[no5][add#6][b3]', key.Key('C'))
>>> cp(weirdChord)
['B-4', 'E#5', 'F5', 'G5']
>>> weirdChord.root()
<music21.pitch.Pitch G5>

Other scales besides major and minor can be used.
Just for kicks (no worries if this is goobley-gook):

>>> ots = scale.OctatonicScale('C2')
>>> rn_I9 = roman.RomanNumeral('I9', ots, caseMatters=False)
>>> cp(rn_I9)
['C2', 'E-2', 'G-2', 'A2', 'C3']

>>> romanNumeral2 = roman.RomanNumeral(
...     'V7#5b3', ots, caseMatters=False)
>>> cp(romanNumeral2)
['G-2', 'A-2', 'C#3', 'E-3']

>>> rn_minor_64_secondary = roman.RomanNumeral('v64/V', key.Key('e'))
>>> rn_minor_64_secondary
<music21.roman.RomanNumeral v64/V in e minor>

>>> rn_minor_64_secondary.figure
'v64/V'

>>> cp(rn_minor_64_secondary)
['C#5', 'F#5', 'A5']

>>> rn_minor_64_secondary.secondaryRomanNumeral
<music21.roman.RomanNumeral V in e minor>

Dominant 7ths can be specified by the character 'd' followed by the figure
indicating the inversion of the chord:

>>> r = roman.RomanNumeral('bVIId7', key.Key('B-'))
>>> r.figure
'bVIId7'

>>> cp(r)
['A-5', 'C6', 'E-6', 'G-6']

>>> r = roman.RomanNumeral('VId42')
>>> r.figure
'VId42'

>>> r.key = key.Key('B-')
>>> cp(r)
['F5', 'G5', 'B5', 'D6']

>>> r = roman.RomanNumeral('IVd43', key.Key('B-'))
>>> r.figure
'IVd43'

>>> cp(r)
['B-4', 'D-5', 'E-5', 'G5']

>>> r2 = roman.RomanNumeral('V42/V7/vi', key.Key('C'))
>>> cp(r2)
['A4', 'B4', 'D#5', 'F#5']

>>> r2.secondaryRomanNumeral
<music21.roman.RomanNumeral V7/vi in C major>

>>> r2.secondaryRomanNumeral.secondaryRomanNumeral
<music21.roman.RomanNumeral vi in C major>


The I64 chord can also be specified as Cad64, which
simply parses as I64:

>>> r = roman.RomanNumeral('Cad64', key.Key('C'))
>>> r
<music21.roman.RomanNumeral Cad64 in C major>
>>> cp(r)
['G4', 'C5', 'E5']

>>> r = roman.RomanNumeral('Cad64', key.Key('c'))
>>> r
<music21.roman.RomanNumeral Cad64 in c minor>
>>> cp(r)
['G4', 'C5', 'E-5']

Works also for secondary romans:

>>> r = roman.RomanNumeral('Cad64/V', key.Key('c'))
>>> r
<music21.roman.RomanNumeral Cad64/V in c minor>
>>> cp(r)
['D5', 'G5', 'B5']


In a major context, i7 and iv7 and their inversions are treated as minor-7th
chords:

>>> r = roman.RomanNumeral('i7', 'C')
>>> r
<music21.roman.RomanNumeral i7 in C major>
>>> cp(r)
['C4', 'E-4', 'G4', 'B-4']

>>> r = roman.RomanNumeral('iv42', 'C')
>>> cp(r)
['E-4', 'F4', 'A-4', 'C5']

For a minor-Major 7th chord in major, write it as i[add7] or i7[#7] or another inversion:

>>> minorMajor = roman.RomanNumeral('i[add7]', 'C')
>>> minorMajor
<music21.roman.RomanNumeral i[add7] in C major>
>>> cp(minorMajor)
['C4', 'E-4', 'G4', 'B4']
>>> cp(roman.RomanNumeral('i7[#7]', 'C'))
['C4', 'E-4', 'G4', 'B4']

Note that this is not the same as i#7, which gives a rather unusual chord in major.

>>> cp(roman.RomanNumeral('i#7', 'C'))
['C4', 'E-4', 'G4', 'B#4']

In minor, it's just fine.  I mean, just as fine:

>>> cp(roman.RomanNumeral('i#7', 'c'))
['C4', 'E-4', 'G4', 'B4']


>>> cp(roman.RomanNumeral('i42[#7]', 'C'))
['B4', 'C5', 'E-5', 'G5']

As noted above, Minor-Major 7th chords in minor have a different form in root position:

>>> cp(roman.RomanNumeral('i#7', 'c'))
['C4', 'E-4', 'G4', 'B4']

(these are both the same)

>>> cp(roman.RomanNumeral('i#753', 'c'))
['C4', 'E-4', 'G4', 'B4']
>>> cp(roman.RomanNumeral('i7[#7]', 'c'))
['C4', 'E-4', 'G4', 'B4']


Other inversions are the same as with major keys:

>>> cp(roman.RomanNumeral('i65[#7]', 'c'))
['E-4', 'G4', 'B4', 'C5']
>>> cp(roman.RomanNumeral('i43[#7]', 'c'))
['G4', 'B4', 'C5', 'E-5']



The RomanNumeral constructor accepts a keyword 'updatePitches' which is
passed to harmony.Harmony. By default, it
is `True`, but can be set to `False` to initialize faster if pitches are not needed.

>>> r = roman.RomanNumeral('vio', em, updatePitches=False)
>>> r.pitches
()

**Equality**

Two RomanNumerals compare equal if their `NotRest` components
(noteheads, beams, expressions, articulations, etc.) are equal
and if their figures and keys are equal:

>>> c1 = chord.Chord('C4 E4 G4 C5')
>>> c2 = chord.Chord('C3 E4 G4')
>>> rn1 = roman.romanNumeralFromChord(c1, 'C')
>>> rn2 = roman.romanNumeralFromChord(c2, 'C')
>>> rn1 == rn2
True
>>> rn1.duration.type = 'half'
>>> rn1 == rn2
False
>>> rn3 = roman.RomanNumeral('I', 'd')
>>> rn2 == rn3
False
>>> rn3.key = key.Key('C')
>>> rn2 == rn3
True
>>> rn4 = roman.RomanNumeral('ii', 'C')
>>> rn2 == rn4
False
>>> rn4.figure = 'I'
>>> rn2 == rn4
True

>>> rn5 = roman.RomanNumeral('bII6', 'c')
>>> rn6 = roman.RomanNumeral('bII6', 'c')
>>> rn5 == rn6
True
>>> rn7 = roman.RomanNumeral('N6', 'c')
>>> rn5 == rn7
False


* Changed in v6.5: caseMatters is keyword only. It along with sixthMinor and
  seventhMinor are now the only allowable keywords to pass in.
* Changed in v7: RomanNumeral.romanNumeral will always give a "b" for a flattened
  degree (i.e., '-II' becomes 'bII') as this is what people expect in looking at
  the figure.

* Changed in v7.3: figures that are not normally used to indicate inversion
  such as V54 (a suspension) no longer give strange inversions.

* Changed in v8: Figures are now validated as alphanumeric or containing one of
  the following symbols (after the example "V"):

>>> specialCharacterFigure = roman.RomanNumeral('V#+-/[]')
>>> specialCharacterFigure
<music21.roman.RomanNumeral V#+-/[]>

And degree symbols (`°`) convert to `o`:

>>> dimSeventh = roman.RomanNumeral('vii°7', 'c')
>>> dimSeventh
<music21.roman.RomanNumeral viio7 in c minor>

Otherwise, an invalid figure raises `RomanNumeralException`:

>>> roman.RomanNumeral("V64==53")
Traceback (most recent call last):
music21.roman.RomanNumeralException: Invalid figure: V64==53

OMIT_FROM_DOCS

Things that were giving us trouble:

>>> dminor = key.Key('d')
>>> rn = roman.RomanNumeral('iiø65', dminor)
>>> cp(rn)
['G4', 'B-4', 'D5', 'E5']

>>> rn.romanNumeral
'ii'

>>> rn3 = roman.RomanNumeral('III', dminor)
>>> cp(rn3)
['F4', 'A4', 'C5']

Should be the same as above no matter when the key is set:

>>> r = roman.RomanNumeral('VId7', key.Key('B-'))
>>> cp(r)
['G5', 'B5', 'D6', 'F6']

>>> r.key = key.Key('B-')
>>> cp(r)
['G5', 'B5', 'D6', 'F6']

This was getting B-flat.

>>> r = roman.RomanNumeral('VId7')
>>> r.key = key.Key('B-')
>>> cp(r)
['G5', 'B5', 'D6', 'F6']

>>> r = roman.RomanNumeral('IVd6/5')
>>> r.key = key.Key('Eb')
>>> cp(r)
['C5', 'E-5', 'G-5', 'A-5']

>>> r = roman.RomanNumeral('vio', em)
>>> cp(r)
['C#5', 'E5', 'G5']

We can omit an arbitrary number of steps:

>>> r = roman.RomanNumeral('Vd7[no3no5no7]', key.Key('C'))
>>> cp(r)
['G4']

Was setting a root of D5:

>>> r = roman.RomanNumeral('V754', key.Key('C'))
>>> cp(r)
['G4', 'C5', 'D5', 'F5']

A symbol that looks like the degree symbol but isn't:

>>> roman.RomanNumeral('viiº')
<music21.roman.RomanNumeral viio>

(NOTE: all this is omitted -- look at OMIT_FROM_DOCS above)
)rm  r   z^(b+|-+|#+)z(\[(no[1-9]+)+]\s*)+z\[add(b*|-*|#*)(\d+)+]\s*z\[(b+|-+|#+)(\d+)]z(It|Ger|Fr|Sw)\+?z'(IV|I{1,3}|VI{0,2}|iv|i{1,3}|vi{0,2}|N)z(.*?)/([#a-np-zA-NP-Z].*)r2   rC   r?   )rU  rX  GerrY  z	(\d)/(\d)
addedStepsa  
            Returns a list of the added steps, each as a tuple of
            modifier as a string (which might be empty) and a chord factor as an int.

            >>> rn = roman.RomanNumeral('V7[addb6]', 'C')
            >>> rn.addedSteps
            [('-', 6)]
            >>> rn.pitches
            (<music21.pitch.Pitch G4>,
             <music21.pitch.Pitch B4>,
             <music21.pitch.Pitch D5>,
             <music21.pitch.Pitch E-5>,
             <music21.pitch.Pitch F5>)

            You can add multiple added steps:

            >>> strange = roman.RomanNumeral('V7[addb6][add#6][add-8]')
            >>> strange.addedSteps
            [('-', 6), ('#', 6), ('-', 8)]
            >>> ' '.join([p.nameWithOctave for p in strange.pitches])
            'G4 B4 D5 E-5 E#5 F5 G-5'

            NOTE: The modifier name is currently changed from 'b' to '-', but
            this might change in a future version to match `bracketedAlteration`.
            bracketedAlterationsa  
            Returns a list of the bracketed alterations, each as a tuple of
            modifier as a string and a chord factor as an int.

            >>> rn = roman.RomanNumeral('V7[b5]')
            >>> rn.bracketedAlterations
            [('b', 5)]
            >>> rn.pitches
            (<music21.pitch.Pitch G4>,
             <music21.pitch.Pitch B4>,
             <music21.pitch.Pitch D-5>,
             <music21.pitch.Pitch F5>)

            NOTE: The bracketed alteration name is currently left as 'b', but
            this might change in a future version to match `addedSteps`.

            The difference between a bracketed alteration and just
            putting b5 in is that, a bracketed alteration changes
            notes already present in a chord and does not imply that
            the normally present notes would be missing.  Here, the
            presence of 7 and b5 means that no 3rd should appear.

            >>> rn2 = roman.RomanNumeral('V7b5')
            >>> rn2.bracketedAlterations
            []
            >>> len(rn2.pitches)
            3
            >>> [p.name for p in rn2.pitches]
            ['G', 'D-', 'F']

            * Changed in v6.5: always returns a list, even if it is empty.
            caseMattersu5  
            Boolean to determine whether the case (upper or lowercase) of the
            figure determines whether it is major or minor.  Defaults to True;
            not everything has been tested with False yet.

            >>> roman.RomanNumeral('viiø7', 'd').caseMatters
            True
            figuresWrittenu  
            Returns a string containing any figured-bass figures as passed in:

            >>> roman.RomanNumeral('V65').figuresWritten
            '65'
            >>> roman.RomanNumeral('V').figuresWritten
            ''
            >>> roman.RomanNumeral('Fr43', 'c').figuresWritten
            '43'
            >>> roman.RomanNumeral('I7#5b3').figuresWritten
            '7#5b3'

            Note that the `o` and `ø` symbols are quality designations and not
            figures:

            >>> roman.RomanNumeral('viio6').figuresWritten
            '6'
            >>> roman.RomanNumeral('viiø7').figuresWritten
            '7'
            figuresNotationObja  
            Returns a :class:`~music21.figuredBass.notation.Notation` object
            that represents the figures in a RomanNumeral

            >>> rn = roman.RomanNumeral('V65')
            >>> notationObj = rn.figuresNotationObj
            >>> notationObj
            <music21.figuredBass.notation.Notation 6,5>
            >>> notationObj.numbers
            (6, 5, 3)

            >>> rn = roman.RomanNumeral('Ib75#3')
            >>> notationObj = rn.figuresNotationObj
            >>> notationObj.numbers
            (7, 5, 3)
            >>> notationObj.modifiers
            (<music21.figuredBass.notation.Modifier b flat>,
             <music21.figuredBass.notation.Modifier None None>,
             <music21.figuredBass.notation.Modifier # sharp>)
            frontAlterationAccidentala  
            An optional :class:`~music21.pitch.Accidental` object
            representing the chromatic alteration of a RomanNumeral, if any

            >>> roman.RomanNumeral('bII43/vi', 'C').frontAlterationAccidental
            <music21.pitch.Accidental flat>

            >>> roman.RomanNumeral('##IV').frontAlterationAccidental
            <music21.pitch.Accidental double-sharp>

            For most roman numerals this will be None:

            >>> roman.RomanNumeral('V', 'f#').frontAlterationAccidental

            Changing this value will not change existing pitches.

            * Changed in v6.5: always returns a string, never None
            frontAlterationStringa  
            A string representing the chromatic alteration of a RomanNumeral, if any

            >>> roman.RomanNumeral('bII43/vi', 'C').frontAlterationString
            'b'
            >>> roman.RomanNumeral('V', 'f#').frontAlterationString
            ''

            Changing this value will not change existing pitches.

            * Changed in v6.5: always returns a string, never None
             frontAlterationTransposeIntervala  
            An optional :class:`~music21.interval.Interval` object
            representing the transposition of a chromatically altered chord from
            the normal scale degree:

            >>> sharpFour = roman.RomanNumeral('#IV', 'C')
            >>> sharpFour.frontAlterationTransposeInterval
            <music21.interval.Interval A1>
            >>> sharpFour.frontAlterationTransposeInterval.niceName
            'Augmented Unison'

            Flats, as in this Neapolitan (bII6) chord, are given as diminished unisons:

            >>> roman.RomanNumeral('N6', 'C').frontAlterationTransposeInterval
            <music21.interval.Interval d1>

            Most RomanNumerals will have None and not a perfect unison for this value
            (this is for the speed of creating objects)

            >>> intv = roman.RomanNumeral('V', 'e-').frontAlterationTransposeInterval
            >>> intv is None
            True

            Changing this value will not change existing pitches.
            impliedQualityax  
            The quality of the chord implied by the figure:

            >>> roman.RomanNumeral('V', 'C').impliedQuality
            'major'
            >>> roman.RomanNumeral('ii65', 'C').impliedQuality
            'minor'
            >>> roman.RomanNumeral('viio7', 'C').impliedQuality
            'diminished'

            The impliedQuality can differ from the actual quality
            if there are not enough notes to satisfy the implied quality,
            as in this half-diminished chord on vii which does not also
            have a seventh:

            >>> incorrectSeventh = roman.RomanNumeral('vii/o', 'C')
            >>> incorrectSeventh.impliedQuality
            'half-diminished'
            >>> incorrectSeventh.quality
            'diminished'

            >>> powerChordMinor = roman.RomanNumeral('v[no3]', 'C')
            >>> powerChordMinor.impliedQuality
            'minor'
            >>> powerChordMinor.quality
            'other'

            If case does not matter then an empty quality is implied:

            >>> roman.RomanNumeral('II', 'C', caseMatters=False).impliedQuality
            ''

            impliedScaleaY  
            If no key or scale is passed in as the second object, then
            impliedScale will be set to C major:

            >>> roman.RomanNumeral('V').impliedScale
            <music21.scale.MajorScale C major>

            Otherwise this will be empty:

            >>> roman.RomanNumeral('V', key.Key('D')).impliedScale
            omittedStepsa  
            A list of integers showing chord factors that have been
            specifically omitted:

            >>> emptyNinth = roman.RomanNumeral('V9[no7][no5]', 'C')
            >>> emptyNinth.omittedSteps
            [7, 5]
            >>> emptyNinth.pitches
            (<music21.pitch.Pitch G4>,
             <music21.pitch.Pitch B4>,
             <music21.pitch.Pitch A5>)

            Usually an empty list:

            >>> roman.RomanNumeral('IV6').omittedSteps
            []
            
pivotChorda  
            Defaults to None; if not None, stores another interpretation of the
            same RN in a different key; stores a RomanNumeral object.

            While not enforced, for consistency the pivotChord should be
            the new interpretation going forward (to the right on the staff)

            >>> rn = roman.RomanNumeral('V7/IV', 'C')
            >>> rn.pivotChord is None
            True
            >>> rn.pivotChord = roman.RomanNumeral('V7', 'F')
            r  a  
            A string representing everything before the slash
            in a RomanNumeral with applied chords.  In other roman numerals
            it is the same as `figure`:

            >>> rn = roman.RomanNumeral('bII43/vi', 'C')
            >>> rn.primaryFigure
            'bII43'

            >>> rnSimple = roman.RomanNumeral('V6', 'a')
            >>> rnSimple.primaryFigure
            'V6'

            Changing this value will not change existing pitches.
            rk  a  
            Returns a string of just the roman numeral part (I-VII or i-vii) of
            the figure:

            >>> roman.RomanNumeral('V6').romanNumeralAlone
            'V'

            Chromatic alterations and secondary numerals are omitted:

            >>> rn = roman.RomanNumeral('#II7/vi', 'C')
            >>> rn.romanNumeralAlone
            'II'

            Neapolitan chords are changed to 'II':

            >>> roman.RomanNumeral('N6').romanNumeralAlone
            'II'

            Currently augmented-sixth chords return the "national" base.  But this
            behavior may change in future versions:

            >>> roman.RomanNumeral('It6').romanNumeralAlone
            'It'
            >>> roman.RomanNumeral('Ger65').romanNumeralAlone
            'Ger'

            This will be controversial in some circles, but it's based on a root in
            isolation, and does not imply tonic quality:

            >>> roman.RomanNumeral('Cad64').romanNumeralAlone
            'I'
            scaleCardinalitya  
            Stores how many notes are in the scale; defaults to 7 for diatonic, obviously.

            >>> roman.RomanNumeral('IV', 'a').scaleCardinality
            7

            Probably you should not need to change this.  And most code is untested
            with other cardinalities.  But it is (in theory) possible to create
            roman numerals on octatonic scales, etc.

            Changing this value will not change existing pitches.
            scaleDegreea  
            An int representing what degree of the scale the figure
            (or primary figure in the case of secondary/applied numerals)
            is on.  Discounts any front alterations:

            >>> roman.RomanNumeral('vi', 'E').scaleDegree
            6

            Note that this is 2, not 1.5 or 6 or 6.5 or something like that:

            >>> roman.RomanNumeral('bII43/vi', 'C').scaleDegree
            2

            Empty RomanNumeral objects have the special scaleDegree of 0:

            >>> roman.RomanNumeral().scaleDegree
            0

            Changing this value will not change existing pitches.

            * Changed in v6.5: empty RomanNumeral objects get scaleDegree 0, not None.
            secondaryRomanNumerala  
            An optional roman.RomanNumeral object that represents the part
            after the slash in a secondary/applied RomanNumeral object.  For instance,
            in the roman numeral, `C: V7/vi`, the `secondaryRomanNumeral` would be
            the roman numeral `C: vi`.  The key of the `secondaryRomanNumeral`
            is the key of the original RomanNumeral.  In cases such as
            V/V/V, the `secondaryRomanNumeral` can itself have a
            `secondaryRomanNumeral`.

            >>> rn = roman.RomanNumeral('V7/vi', 'C')
            >>> rn.secondaryRomanNumeral
            <music21.roman.RomanNumeral vi in C major>
            ab  
            An optional key.Key object for secondary/applied RomanNumeral that
            represents the key that the part of the figure *before* the slash
            will be interpreted in.  For instance in the roman numeral,
            `C: V7/vi`, the `secondaryRomanNumeralKey` would be `a minor`, since
            the vi (submediant) refers to an a-minor triad, and thus the `V7`
            part is to be read as the dominant seventh in `a minor`.

            >>> rn = roman.RomanNumeral('V7/vi', 'C')
            >>> rn.secondaryRomanNumeralKey
            <music21.key.Key of a minor>
            a  
            How should vii, viio,  and VII be parsed in minor?
            Defaults to Minor67Default.QUALITY.

            This value should be passed into the constructor initially.
            Changing it after construction will not change the pitches.
            a  
            How should vi, vio and VI be parsed in minor?
            Defaults to Minor67Default.QUALITY.

            This value should be passed into the constructor initially.
            Changing it after construction will not change the pitches.
            z
            A boolean indicating whether an implied scale is being used:

            >>> roman.RomanNumeral('V').useImpliedScale
            True
            >>> roman.RomanNumeral('V', 'A').useImpliedScale
            False
            )secondaryRomanNumeralKeyr^  r]  useImpliedScalezdict[str, str]	_DOC_ATTRT)r  r\  r]  r^  c               .  > SU l         S U l        S U l        S U l        X0l        SU l        [        U[        5      (       a  [        R                  " U5      nU R                  (       a  Sn[        U[        R                  5      (       a  UR                  nOd[        U[        R                  5      (       a  UR                  nO8[        U[         5      (       a#  U(       a  US   R#                  5       (       a  SOSnUS:X  a  US;   d  US:X  a  US;   a  UR%                  5       n[        U[         5      (       aO  [&        R(                  " SS	U5      nUR+                  S
S	5      nUR+                  SS	5      nUR+                  SS5      nO[-        S[        U5       35      e[/        S U 5       5      (       d  [1        SU 35      eXl        S U l        SU l        SU l        S U l        S U l        SU l        SU l         [B        U l"        U(       d  [F        RH                  " 5       U l"        SU l%        S U l&        SU l'        / U l(        / U l)        / U l*        SU l+        X l
        XPl,        X`l-        [\        T	U ]  " U4SU0UD6  SU l0        SU l+        S U l1        SU l2        g )Nr/   r"   r   rL   rM   )IIr   r{   r   )rO   r  ra   rU   z(?<!\d)0r      ºr   r   r   zExpected str or int: got c              3  X   #    U  H   oR                  5       =(       d    US ;   v   M"     g7f)u   #°+-/[]N)isalnum).0chars     r+   	<genexpr>(RomanNumeral.__init__.<locals>.<genexpr>	  s!     KFD<<>7TZ%77Fs   (*zInvalid figure: Fr\  T)3r  r  r  r  r  r  r  r  r   r  r   r'   r   r   DiatonicScaletyper   isupperr  r   r   r   	TypeErrorallrr  _figure_scaler  r  r  r  rk  r  _NOTATION_SINGLETONr  rp  Notationr  r  r  r  r  r  _parsingCompleter]  r^  super__init__writeAsChord_functionalityScorefollowsKeyChange)
selfrm  
keyOrScaler  r\  r]  r^  keywordsr   	__class__s
            r+   r  RomanNumeral.__init__S	  sH    #%8<"6:%-1!,%&fc""^^F+Fj#''22%??D
E,?,?@@%??D
C00Z&0m&;&;&=&=77DW_3M)MF6L,L#\\^F fc""VVKf5F^^D#.F^^D#.F^^D$/F7V~FGG KFKKK'*:6((CDD  !*,"HL-@D&&(#%7J&0&9&9&;D##%6:%*;=!')13 %$(I}II  $-1 &+r-   c                @    [         R                  R                  X5      $ )z?
Compare equality, just based on NotRest and on figure and key
)r   NotRest__eq__)r  others     r+   r  RomanNumeral.__eq__	  s     ||""4//r-   c                    [        U 5      S-	  $ )Nr   )idr  s    r+   __hash__RomanNumeral.__hash__	  s    $x1}r-   c                z    [        U R                  S5      (       a  [        U R                  5      $ U R                  $ )Nr_  )hasattrr   r   figureAndKeyrm  r  s    r+   _reprInternalRomanNumeral._reprInternal	  s.    488W%%t(());;r-   c                J   [        U R                  [        5      (       d  [        SU R                  < 35      eU R                  (       a  U R
                  nOU R                  nU R                  U5      u  p!US:X  a&  [        US5      (       a  UR                  S:X  a  SnOSnX l
        U R                  U5      nU R                  U5      nU R                  U5      n[        R                  " SSU5      n[        R                  " S	S
U5      n[        R                  " SSU5      nU R!                  U5      nU R#                  X!5      u  p!U R%                  U5      nU R'                  X!5      nX l        SR+                  [-        U5      5      n[.        R0                  " U5      U l        g)zd
Parse the .figure object into its component parts.

Called from the superclass, Harmony.__init__()
zgot a non-string figure: Cad64r   rM   i64r_   z^N6r   z^N53bIIz^N,N)r  r  r   rr  r  r  r   _correctForSecondaryRomanNumeralr  r   r  _parseOmittedSteps_parseAddedSteps_parseBracketedAlterationsr   r   _parseFrontAlterations_parseRNAloneAmidstAug6_setImpliedQualityFromString_adjustMinorVIandVIIByQualityr  r   r   rp  r  r  )r  useScaleworkingFigureshFigs       r+   _parseFigureRomanNumeral._parseFigure	  sd    $,,,,'*CDLLCS(TUU((H{{H$($I$I($S!G#x((X]]g-E % %*//>--m<77F ufm<vum<tV];33MB"&">">}"W99-H::=S+78","5"5e"<r-   c                   SnUR                  S5      (       d  UR                  S5      (       a	  USS  nSnGO'UR                  S5      (       a	  USS  nSnGOUR                  S	5      (       a  USS  nSnOUR                  S
5      (       a  USS  nSnOSU;   aO  [        R                  " SU5      nUc  [        SU S35      eUR	                  S5      UR	                  S5      -   nSnOwU R
                  (       a+  U R                  R                  5       U R                  :X  a  SnO;U R
                  (       a*  U R                  R                  5       U R                  :X  a  SnX l	        U$ )Nr/   r   r   r   
diminishedr   r!   half-diminishedr   r   	augmenteddz/(?P<leading>.*)d(?P<figure>7|6/?5|4/?3|4/?2|2)$z,Cannot make a dominant-seventh chord out of z3. Figure should be in ('7', '65', '43', '42', '2').leadingrm  dominant-seventhrL   rM   )
r   r   r   rr  groupr  rk  r  r  r  )r  r  r  ms       r+   r  )RomanNumeral._setImpliedQualityFromString	  sc   ##C((M,D,DT,J,J)!"-M)N%%d++)!"-M.N%%d++)!"-M.N%%c**)!"-M(NM!K][Ay+B=/ RH HI I GGI.1BBM/N$"8"8">">"@DDZDZ"Z$N$"8"8">">"@DDZDZ"Z$N,r-   c                   U R                   (       d  g U R                    H  u  p[        R                  " SSU5      n U R                  U5      nUc  M4  [        R                  " U5      nUR                  c  XCl        M_  UR                  R                  UR                  R                  UR                  -   5        M     g ! [        R
                   a     M  f = f)Nr   -)r  r   r   getChordStepr   ChordExceptionr   
Accidental
accidentalr  r   )r  alterNotation	chordStep
alterPitchnewAccidentals        r+   _correctBracketedPitches%RomanNumeral._correctBracketedPitches
  s    ((*.*C*C&]FF3];M!..y9
 % % 0 0 ?((0,9)))--j.C.C.I.IML_L_._` +D '' s   B??CCc                    US:X  a  SnU$ US:X  a  SnU$ US:X  a  SnU$ US:X  a  SnU$ US	:X  a  S
nU$ US:X  a  SnU$ US:X  a  SnU$ SnU$ )a  
Given an implied quality, return the number of semitones that should be included.

Relies entirely on impliedQuality. Note that in the case of 'diminished'
it could be either diminished triad or diminished seventh. We return for diminished
seventh since a missing chordStep for the 7th degree doesn't affect the processing.

Returns a tuple of 2 or 3 length showing the number of
semitones for third, fifth, [seventh]
or the empty tuple () if not found.

>>> r = roman.RomanNumeral()
>>> r._findSemitoneSizeForQuality('major')
(4, 7)
>>> r._findSemitoneSizeForQuality('minor')
(3, 7)
>>> r._findSemitoneSizeForQuality('half-diminished')
(3, 6, 10)
>>> r._findSemitoneSizeForQuality('augmented')
(4, 8)
>>> r._findSemitoneSizeForQuality('dominant-seventh')
(4, 7, 10)
>>> r._findSemitoneSizeForQuality('not-a-quality')
()
>>> r._findSemitoneSizeForQuality('diminished')
(3, 6, 9)

OMIT_FROM_DOCS

This one is not currently used.

>>> r._findSemitoneSizeForQuality('minor-seventh')
(3, 7, 10)

(This is in OMIT_FROM_etc.)
rL   )r   r"   rM   )r   r"   r  )r   r   r#   r  )r   r   r   r  )r   r   zminor-seventh)r   r"   r   r  )r   r"   r   r  r  )r  r  correctSemitoness      r+   _findSemitoneSizeForQuality(RomanNumeral._findSemitoneSizeForQuality
  s    L W$%    w&%   |+(   00)   {*%   .)   11)    "r-   c                ,  ^  SS jnSU 4S jjnT R                  U5      nSn[        XT5       Hh  u  pgU" U5      (       a  M  T R                  U5      nUc  M*  X:X  a  M1  Xx-
  n	T R                  U5      n
[        R
                  (       a  U
c   eU" X5        Mj     [        U5      S:X  am  [        T R                  R                  5      S:  aI  T R                  S:X  a8  T R                  S5      S	:X  a"  U" S5      (       d  U" T R                  S
5        gggggg)ad  
Fixes notes that should be out of the scale
based on what the chord "impliedQuality" (major, minor, augmented,
diminished) by changing their accidental.

An intermediary step in parsing figures.

>>> r = roman.RomanNumeral()
>>> r.pitches = ['C4', 'E4', 'G4']
>>> r._matchAccidentalsToQuality('minor')
>>> ' '.join([p.name for p in r.pitches])
'C E- G'
>>> r._matchAccidentalsToQuality('augmented')
>>> ' '.join([p.name for p in r.pitches])
'C E G#'
>>> r._matchAccidentalsToQuality('diminished')
>>> ' '.join([p.name for p in r.pitches])
'C E- G-'
>>> r.pitches = ['C4', 'E4', 'G4', 'B4']
>>> r._matchAccidentalsToQuality('diminished')
>>> ' '.join([p.name for p in r.pitches])
'C E- G- B--'

This was a problem before:

>>> r.pitches = ['C4', 'E4', 'G4', 'B#4']
>>> r._matchAccidentalsToQuality('diminished')
>>> ' '.join([p.name for p in r.pitches])
'C E- G- B--'
c                (   US:  a	  SSU-
  -  nOUS::  a  US-  nU R                   c  [        R                  " U5      U l         g U R                   nU[        UR                  5      -  nUS:  a	  SSU-
  -  nOUS::  a  US-  nUR                  U5        g )Nr   r   r   i)r  r   r  r  r   r  )faultyPitchinner_correctedSemisaccs      r+   correctFaultyPitchCRomanNumeral._matchAccidentalsToQuality.<locals>.correctFaultyPitchq
  s    #q(')R2F-F'G$%+$*$%%-).)9)9:N)O&!,,$CII6$'1,+-6J1J+K()R/(B.(,-r-   c                   > TR                   R                   HT  nUR                  U :X  d  M  UR                  R                  c  M.  UR                  R                  R
                  S:w  d  MT    g   g)z
Skip adjusting chordSteps with explicit accidentals.

For a figure like V7b5, make sure not to correct the b5 back,
even though the implied quality requires a Perfect 5th.
r   TF)r  figuresnumbermodifierr  r   )r  rm  r  s     r+   shouldSkipThisChordStepHRomanNumeral._matchAccidentalsToQuality.<locals>.shouldSkipThisChordStep
  sW     1199MMY."OO66B"OO66<<A	 :
 r-   )r   r    r"   Nr!   r   rM   r"   rS  r   )r  pitch.Pitchr  r  )r  r  returnbool)r  zipr   r  rf  rg  r   r  r  r  r/  )r  r  r  r  r   chordStepsToExaminethisChordStepthisCorrect	thisSemiscorrectedSemischordStepNotNones   `          r+   _matchAccidentalsToQuality'RomanNumeral._matchAccidentalsToQualityR
  s   >	.$	  ;;NK' +..A*T&M&}5533MBI '(4N#00?'333/@ +U  A%#d.E.E.M.M*NRS*S""g-$2M2Ma2PTV2V /q11&t||R8 2 3W- +T%r-   c                *   Uc  U R                   nUb  U R                  R                  U5      nOSnU(       a  UR                  S5      nUR                  S5      n[	        UUU R
                  U R                  U R                  S9nX`l        UR                  S:X  a  SnO-UR                  S:X  a  SnOUR                  S5      S:X  a  SnOSn[        R                  " UR                  5       R                  U5      U l        U R                  nUnX4$ UnX4$ )a4  
Creates .secondaryRomanNumeral object and .secondaryRomanNumeralKey Key object
inside the RomanNumeral object (recursively in case of V/V/V/V etc.) and returns
the figure and scale that should be used instead of figure for further working.

Returns a tuple of (newFigure, newScale).
In case there is no secondary slash, returns the original figure and the original scale.

If figure is None, uses newFigure.

>>> k = key.Key('C')
>>> r = roman.RomanNumeral('I', k)  # will not be used below
>>> r._correctForSecondaryRomanNumeral(k)  # uses 'I'. nothing should change
('I', <music21.key.Key of C major>)
>>> r.secondaryRomanNumeral is None
True
>>> r.secondaryRomanNumeralKey is None
True
>>> r._correctForSecondaryRomanNumeral(k, 'V/V')
('V', <music21.key.Key of G major>)
>>> r._correctForSecondaryRomanNumeral(k, 'V65/IV')
('V65', <music21.key.Key of F major>)
>>> r._correctForSecondaryRomanNumeral(k, 'viio/bVII')
('viio', <music21.key.Key of B- major>)

>>> r._correctForSecondaryRomanNumeral(k, 'V9/vi')
('V9', <music21.key.Key of a minor>)
>>> r.secondaryRomanNumeral
<music21.roman.RomanNumeral vi in C major>
>>> r.secondaryRomanNumeralKey
<music21.key.Key of a minor>

Recursive:

>>> r._correctForSecondaryRomanNumeral(k, 'V7/V/V')
('V7', <music21.key.Key of D major>)
>>> r.secondaryRomanNumeral
<music21.roman.RomanNumeral V/V in C major>
>>> r.secondaryRomanNumeralKey
<music21.key.Key of D major>
>>> r.secondaryRomanNumeral.secondaryRomanNumeral
<music21.roman.RomanNumeral V in C major>
>>> r.secondaryRomanNumeral.secondaryRomanNumeralKey
<music21.key.Key of G major>
Nr   r!   )r  r]  r^  rM   rL   r   )r  _secondarySlashRegexr   r  r   r  r]  r^  r  qualityr   r   r'   r   r  r  )	r  r  rm  r   r  secondaryFigurer  secondaryModer  s	            r+   r  -RomanNumeral._correctForSecondaryRomanNumeral
  s   d >\\F--33F;EE!KKNM#kk!nO$0 ,,??!..%! *?&$,,7 '&..'9 '&==a@AE ' ' -0GG%**,11-D) 44H)M (( #M((r-   c                   / nU R                   R                  U5      nU(       a  UR                  5       nUR                  SS5      nUR                  SS5      nUSS R	                  S5       Vs/ s H"  oU(       d  M  [        U5      S-  =(       d    SPM$     nnU R                   R                  SU5      nX l        U$ s  snf )ar  
Remove omitted steps from a working figure and return the remaining figure,
setting self.omittedSteps to the omitted parts

>>> rn = roman.RomanNumeral()
>>> rn._parseOmittedSteps('7[no5][no3]')
'7'
>>> rn.omittedSteps
[5, 3]

All omitted are mod 7:

>>> rn = roman.RomanNumeral()
>>> rn._parseOmittedSteps('13[no11][no9][no7]b3')
'13b3'
>>> rn.omittedSteps
[4, 2, 7]

 r/   z][r   r   nor"   )_omittedStepsRegexsearchr  r   splitr  r   r  )r  r  r  r   r  r   s         r+   r  RomanNumeral._parseOmittedSteps  s    ( ''..}=KKMEMM#r*EMM$+E7<Qr{7H7H7NT7N!RS_SVaZ_1_7NLT 3377MJM(	 Us   /
B>=B>c                6   / nU R                   R                  U5      nU HS  nUR                  S5      R                  SS5      nUR                  S5      nU[	        U5      4nUR                  U5        MU     U R                   R                  SU5      nX l        U$ )a  
Remove added steps from a working figure and return the remaining figure,
setting self.addedSteps to a list of tuples of alteration and number

>>> rn = roman.RomanNumeral()
>>> rn._parseAddedSteps('7[add6][add#2]')
'7'
>>> rn.addedSteps
[('', 6), ('#', 2)]

All added are not mod 7.  Flat "b" becomes "-"

>>> rn = roman.RomanNumeral()
>>> rn._parseAddedSteps('13[addbb11]b3')
'13b3'
>>> rn.addedSteps
[('--', 11)]
r   r   r  r!   r/   )_addedStepsRegexfinditerr  r   r  r   r   r  )r  r  r  matchesr  matchAlterationmatchDegreeaddTuples           r+   r  RomanNumeral._parseAddedSteps'  s    & 
''00?Aggaj00c:O''!*K'[)9:Hh'	  --11"mD$r-   c                   U R                   R                  U5      nU HL  nUR                  S5      n[        UR                  S5      5      nXE4nU R                  R                  U5        MN     U R                   R                  SU5      nU$ )z
remove bracketed alterations from a figure and store them in `.bracketedAlterations`

>>> rn = roman.RomanNumeral()
>>> rn._parseBracketedAlterations('7[#5][b3]')
'7'
>>> rn.bracketedAlterations
[('#', 5), ('b', 3)]

r   r!   r/   )_bracketedAlterationRegexr+  r  r  r  r   r   )r  r  r,  r  r-  r.  newTuples          r+   r  'RomanNumeral._parseBracketedAlterationsF  s~     0099-HAggajOaggaj/K'5H%%,,X6	 
 66::2}Mr-   c                   SnSnSnU R                   R                  U5      nU(       a  UR                  5       n[        U5      nUS   S;   a  US-  n[        R
                  " [        R                  " S5      [        R                  " U5      5      n[        R                  " U5      nUnU R                   R                  SU5      nX l        X0l        X@l        U$ )a  
removes front alterations from a workingFigure and sets
`.frontAlterationString`, `.frontAlterationTransposeInterval`
and `.frontAlterationAccidental`.

>>> rn = roman.RomanNumeral()
>>> print(rn.frontAlterationTransposeInterval)
None

>>> rn._parseFrontAlterations('bVI')
'VI'
>>> rn.frontAlterationString
'b'
>>> rn.frontAlterationTransposeInterval
<music21.interval.Interval d1>
>>> rn.frontAlterationAccidental
<music21.pitch.Accidental flat>
r/   Nr   )r   r  r   r   )_alterationRegexr   r  r   r   r`  ra  rb  r   r  r   r  r  r  )r  r  r  r  r  r   r  
alterations           r+   r  #RomanNumeral._parseFrontAlterationsZ  s    & !#+/($(!%%++M:KKMEUJQx:%b 
/7/W/W((+**:60, ).(8(8(D%$)! 1155b-HM%:"0P-)B&r-   c                4   U R                   R                  U5      nU R                  R                  U5      nU(       d  U(       d  [        SU< 35      eU(       GaS  [	        U[
        R                  5      (       a  UR                  S:X  d<  [	        U[        R                  5      (       a  UR                  S:X  az  UR                  bm  [
        R                  " UR                  S5      nX l        SU l        U R                  b2  U R                  R                  n[
        R                  " US5      U l        UR                  S5      nUS;   a#  SU l        ["        R$                  " S	5      U l        O6US
:X  a  SU l        O(US:X  a"  SU l        ["        R$                  " S	5      U l        U R                  R)                  SU5      nU R*                  R)                  SU5      nU(       a  US   R-                  5       (       d  U R.                  U   U-   nORU(       aK  US:w  aE  US   S:X  a<  [1        U5      S:  d  US   R-                  5       (       d  U R.                  U   USS -   nX`l        US
:w  a  SnU R4                  R7                  U5        US;   a  SnU R4                  R7                  U5        X4$ [8        R:                  (       a  Uc   eUR                  S5      n[<        R>                  " U5      U l        U R                   R)                  SU5      nXl        X4$ )a  
Sets and removes from workingFigure the roman numeral alone, possibly
changing the useScale in the case of augmented sixths.

Returns the remains of the figure alone with the scale to be used

>>> useScale = key.Key('C')
>>> rn = roman.RomanNumeral()
>>> workingFig, outScale = rn._parseRNAloneAmidstAug6('V7', useScale)
>>> workingFig
'7'
>>> outScale is useScale
True
>>> rn.romanNumeralAlone
'V'

>>> rn = roman.RomanNumeral()
>>> workingFig, outScale = rn._parseRNAloneAmidstAug6('Ger65', useScale)
>>> workingFig
'65'
>>> rn.scaleDegreeWithAlteration
(4, <music21.pitch.Accidental sharp>)


Working figures might be changed to defaults:

>>> rn = roman.RomanNumeral()
>>> workingFig, outScale = rn._parseRNAloneAmidstAug6('Fr+6', useScale)
>>> workingFig
'43'
>>> outScale
<music21.key.Key of c minor>
>>> rn.scaleDegree
2

>>> rn = roman.RomanNumeral()
>>> workingFig, outScale = rn._parseRNAloneAmidstAug6('It6', scale.MajorScale('C'))
>>> outScale
<music21.key.Key of c minor>
zNo roman numeral found in rL   NrM   Tr   )rU  r  r   sharprX  r!   rY  r/   z\1\2r   rU  r2   )r  r   rW  )r  r   ) _romanNumeralAloneRegexr   _augmentedSixthRegexrr  r  r   r'   r   r   r  r  r_  r  r  r  r  r  r   r  r  r   _slashedAug6Invisdigit_aug6defaultInversionsr   rk  r  r   rf  rg  r   	fromRoman)	r  r  r  romanNormalMatch	aug6Matchsecondary_tonicaug6typefixTuplerk  s	            r+   r  $RomanNumeral._parseRNAloneAmidstAug6  s   \  77==mL--33MB		'*D]DU(VWWHcgg..8==G3K"8U-@-@AA$MMW4$NN6778>>7;$,!'+$ 00<&*&C&C&I&IO47GGOW4UD1;D??1;MH=(#$ 161A1A'1J.T!#$ T!#$ 161A1A'1J. 5599"mLM 0044WmLM a(8(@(@(B(B $ ; ;H E U$&#A&#-=)A-,Q/7799 $ ; ;H EVWVXHY Y%-"4#))00:<'#))00: && '333 0 6 6q 9%//0ABD 88<<ROM%6"&&r-   c                (    U R                  SU5      ng)a  
Fix minor vi and vii to always be #vi and #vii if `.caseMatters`.

>>> rn = roman.RomanNumeral()
>>> rn.scaleDegree = 6
>>> rn.impliedQuality = 'minor'
>>> rn.adjustMinorVIandVIIByQuality(key.Key('c'))
>>> rn.frontAlterationTransposeInterval
<music21.interval.Interval A1>

>>> rn.frontAlterationAccidental
<music21.pitch.Accidental sharp>


>>> rn = roman.RomanNumeral()
>>> rn.scaleDegree = 6
>>> rn.impliedQuality = 'major'
>>> rn.adjustMinorVIandVIIByQuality(key.Key('c'))
>>> rn.frontAlterationTransposeInterval is None
True
>>> rn.frontAlterationAccidental is None
True

* Changed in v6.4: public function became hook to private function having the actual guts
r/   N)r  )r  r  unused_workingFigures      r+   adjustMinorVIandVIIByQuality)RomanNumeral.adjustMinorVIandVIIByQuality  s    :  $AA"hOr-   c                  ^ ^ SU4S jjnSU 4S jjm[        USS5      S:w  a  U$ T R                  S;  a  U$ T R                  (       d  U$ T R                  S:X  a  T R                  nOT R                  nU[
        R                  :X  a  U$ T R                  S;   nU[
        R                  :X  a  U" U5      $ U[
        R                  :X  a  U(       d  U$ U" U5      $ T R                  (       a  T R                  R                  S	:X  a  U(       d  U$ U" U5      $ T R                  R                  nUS
:  a	  U(       a  U$ US::  a  U" U5      $ U$ )a  
Fix minor vi and vii to always be #vi and #vii if `.caseMatters`.

Altering `workingFigure` became necessary to handle these chromatic figures:
https://github.com/cuthbertLab/music21/issues/437

>>> rn = roman.RomanNumeral('viio#6', 'a')
>>> ' '.join([p.name for p in rn.pitches])
'B D G#'
>>> rn = roman.RomanNumeral('viio6#4', 'a')
>>> ' '.join([p.name for p in rn.pitches])
'D G# B'
>>> rn = roman.RomanNumeral('viio4#2', 'a')
>>> ' '.join([p.name for p in rn.pitches])
'F G# B D'
>>> rn = roman.RomanNumeral('viio#853', 'a')
>>> ' '.join([p.name for p in rn.pitches])
'G# B D'
>>> rn = roman.RomanNumeral('viio##853', 'a')
>>> ' '.join([p.name for p in rn.pitches])
'G# B D G##'

* Changed in v6.4: Made private when `workingFigure`
  was added to the signature and returned.
c                6  > T" [         R                  " S5      S5        SU ;   a  U R                  SS5      n U $ SU ;   a  U R                  SS5      n U $ SU ;   a  U R                  SS	5      n U $ S
U ;   a  U R                  S
S5      n U $ U R                  SS5      n U $ )NA1r   z##z##8z#8z#22z#44z#6r2   r/   )r   r  r   )wFigchangeFrontAlterations    r+   sharpen;RomanNumeral._adjustMinorVIandVIIByQuality.<locals>.sharpen-  s    !("3"3D"91=t|||E40 K ||D#. K ||D#.
 K	 ||D#. K ||D"-Kr-   c                n  > TR                   nU(       a  [        R                  " X /5      nUTl         TR                  c  [	        S5      eTR                  =R
                  U-  sl        TR                  R
                  S:X  a  S Tl         S Tl        g g U Tl         [        R                  " U5      Tl        g )NzHCannot have a RN with frontAlterationTransposeInterval and no accidentalr   )r  r   addr  r  r   r   r  )intVr   fatinewFatir  s       r+   rQ  IRomanNumeral._adjustMinorVIandVIIByQuality.<locals>.changeFrontAlteration?  s    88D",,|48?5119#b  ..44=411771<<@D959D2 = 9=5161A1A%1H.r-   r   NrM   r5  r   )rM   r  r  r   r   r   )rP  r   r  r   )rV  zinterval.Intervalr   r  )getattrr  r  r]  r^  rn  r  r  r  r  r  r   )r  r  r  rR  minorDefaultnormallyRaised
frontAlterrQ  s   `      @r+   r  *RomanNumeral._adjustMinorVIandVIIByQuality  s:   <	$	I& 8VT*g5  6)     q ??L,,L>...  ,,0ZZ>///=))^333!$$}--11T5S5S5Y5Y]^5^%(("=11 77==JQ>$$r!}--$$r-   c                   U R                   b  U R                   nO7U R                  (       a  U R                  b  U R                  nOU R                  nSUR                  ;   a  SU l        OUR                  5       U l        U R                  U R                  5      nUR                  U[        R                  R                  S9nU/nUn[        U R                  R                  5      n[        U5       GH  nXg-
  S-
  nUU R                  R                  U   -   S-
  n	UR                  U	[        R                  R                  S9n
U R                  R                   U   R#                  U
R$                  5      n[&        R(                  " U5      nU
R*                  b  U
R*                  Ul        O[,        R.                  Ul        UR0                  UR0                  :  a  U=R*                  S-  sl        UR3                  U5        UnGM     U R4                  (       a  U R4                  R6                  S:w  a  [8        R:                  R=                  [8        R>                  " U5      5      nURA                  SS5      URA                  SS5      URA                  SS5      URA                  S	S5      4nU H$  nX;  d  M
  U R4                  RC                  US
S9  M&     [E        U5      U l#        U R                  R                  [H        ;  a  U RK                  U RM                  5       5        U RO                  U RP                  5        U RS                  5         U RT                  (       d  U RV                  (       a  U RK                  U RK                  5       5        U RT                  (       a  / nU RT                   H4  nU RY                  U5      nUc  M  UR3                  UR$                  5        M6     / nU RF                   H&  nUR$                  U;  d  M  UR3                  U5        M(     [E        U5      U l#        U RV                  (       Ga~  U RV                   GHm  u  nnSU;   a  UR[                  S5      S-  nOUR[                  S5      nU R\                  U-   S-
  n	UR                  U	[        R                  R                  S9nUR^                  b   UR^                  =R`                  U-  sl0        O[&        Rb                  " U5      Ul/        UR0                  UR0                  :  a1  U=R*                  S-  sl        UR0                  UR0                  :  a  M1  UR0                  UR0                  :X  a/  URd                  URd                  :  a  U=R*                  S-  sl        UU RF                  ;  d  GM\  U Rg                  U5        GMp     U RF                  (       d  [i        SU Rj                  < 35      eg)z?
Utility function to update the pitches to the new figure etc.
Nr  r"   )	directionr   r   r!   r   r   TinPlacer  r   r  z?_updatePitches() was unable to derive pitches from the figure: )6r  r  r  r   classesr  getDegreeMaxUniquebassScaleDegreeFromNotationr  r  r   	Direction	ASCENDINGr   numbersrange	modifiersmodifyPitchNamer  r   Pitchoctaver   pitchOctaver   r   r  	semitonesr   toolsallChordStepsr  getrc  r  r   r$   r   r   r  r  r  r  r  r  countr  r  r   r  diatonicNoteNumrU  rr  rm  )r  r  bassScaleDegree	bassPitchr   	lastPitchnumberNotesjrQ   thisScaleDegreenewPitch	pitchNamenewNewPitch	chord_map	non_alterr   omittedPitchesthisCSp
newPitchesaddAccidental
stepNumberr7  
addedPitchs                           r+   _updatePitchesRomanNumeral._updatePitches~  s   
 ((444H!!d&7&7&C((HxxH h...$%D!$,$?$?$AD!::4;R;RS,,_HaHa,b	&/[	$1199:{#A!#A."&"9"9"A"A!"D E"# $O  //:?//:S:S 0 UH//99!<LLX]][I++i0K*%-__"%-%9%9"~~	,""a'"NN;'#I! $$ 1199CCqH11%++g2FGIa&a&a&a&	I %	-99HH\`Ha % W~""**2GGIIdiik"''(;(;< 	%%'IIdiik"N++%%f-="))!&&1 ,
 J!\\	>>7%%i0 * !,DL???-1__)z-'!.!4!4S!9B!>J!.!4!4S!9J#'#3#3j#@1#D%55o@E@Y@Y 6 [
((4))//:=/,1,<,<Z,HJ) mmill2%%*% !mmill2 MMY\\1&669R9RR %%*%T\\1HHZ(/ .=2 ||'QRVR]R]Q`a  r-   Fra  c                  > [         TU ]  XS9nU(       d!  U R                  R                  USS9Ul        U$ U R                  R                  USS9U l        g)aP  
Overrides :meth:`~music21.harmony.Harmony.transpose` so that `key`
attribute is transposed as well.

>>> rn = roman.RomanNumeral('I', 'C')
>>> rn
<music21.roman.RomanNumeral I in C major>
>>> rn.transpose(4)
<music21.roman.RomanNumeral I in E major>
>>> rn.transpose(-4, inPlace=True)
>>> rn
<music21.roman.RomanNumeral I in A- major>
ra  FN)r  ri  r   )r  valuerb  postr  s       r+   ri  RomanNumeral.transpose  sX     w  8xx))%)?DHKxx))%)?DHr-   c                    U R                   S;   a  U R                   $ U R                  c  U R                   $ U R                  R                  R                  SS5      U R                   -   $ )a`  
Read-only property that returns either the romanNumeralAlone (e.g. just
II) or the frontAlterationAccidental.modifier (with 'b' for '-') + romanNumeralAlone
(e.g. #II, bII)

>>> rn = roman.RomanNumeral('#II7')
>>> rn.romanNumeral
'#II'

>>> rn = roman.RomanNumeral('Ger+6')
>>> rn.romanNumeral
'Ger'

>>> rn = roman.RomanNumeral('bbII/V')
>>> rn.romanNumeral
'bbII'
>>> rn = roman.RomanNumeral('--II/V')
>>> rn.romanNumeral
'bbII'

OMIT_FROM_DOCS

>>> rn.romanNumeral = 'V'
Traceback (most recent call last):
ValueError: Cannot set romanNumeral property of RomanNumeral objects

(This is in OMIT_FROM_etc.)
)r  rY  rU  rX  r  r   )rk  r  r  r   r  s    r+   romanNumeralRomanNumeral.romanNumeral	  sf    < !!%>>)))))1)))..77??SI(() 	*r-   c                    [        S5      e)Nz8Cannot set romanNumeral property of RomanNumeral objects)r  r  r  s     r+   r  r  /  s    STTr-   c                ,    U R                   =(       d    S$ )zY
Gets or sets the entire figure (the whole enchilada).
(these docs are overridden below)
r/   )r  r  s    r+   rm  RomanNumeral.figure3  s     ||!r!r-   c                    Xl         U R                  (       a(  / U l        U R                  5         U R	                  5         g g N)r  r  r  r  r  )r  	newFigures     r+   rm  r  ;  s5       (*D%! !r-   c                "   U R                   c  U R                  $ SnU R                   R                  n[        US5      (       a  UR                  n[        U R                   S5      (       a  SU R                   R
                  -   nOMU R                   R                  R                  S:X  a  SnO&U R                   R                  R                  S:X  a  SnUS:X  a  UR                  5       nOUS:X  a  UR                  5       nU R                   S	U U 3$ )
z
Returns the figure and the key and mode as a string

>>> rn = roman.RomanNumeral('V65/V', 'e')
>>> rn.figureAndKey
'V65/V in e minor'

Without a key, it is the same as figure:

>>> roman.RomanNumeral('V7').figureAndKey
'V7'
r/   r  r   r#  
MajorScalez major
MinorScalez minorz in )
r   rm  r_  r  r  r   r  r  r  r  )r  r   r_  s      r+   r  RomanNumeral.figureAndKeyC  s     88;;5&!!JJE488V$$&DXX((L8DXX((L8D8KKMEXKKME++d5'$00r-   c                    U R                   $ )ac  
Gets or Sets the current Key (or Scale object) for a given
RomanNumeral object.

If a new key is set, then the pitches will probably change:

>>> r1 = roman.RomanNumeral('V')

(No key means an implicit C-major)

>>> r1.key is None
True

>>> [str(p) for p in r1.pitches]
['G4', 'B4', 'D5']

Change to A major

>>> r1.key = key.Key('A')
>>> [str(p) for p in r1.pitches]
['E5', 'G#5', 'B5']

>>> r1
<music21.roman.RomanNumeral V in A major>

>>> r1.key
<music21.key.Key of A major>

>>> r1.key = key.Key('e')
>>> [str(p) for p in r1.pitches]
['B4', 'D#5', 'F#5']

>>> r1
<music21.roman.RomanNumeral V in e minor>
)r  r  s    r+   r   RomanNumeral.keyf  s    J {{r-   c                   XR                   :X  a  Ub  g[        U[        5      (       a  [        U5      nOUb   UR                  nSU;   a(  UR                  [        ;  a  U[        UR                  '   OSU;   at  UR                  n[        USS5      (       a8  USR                  UR                   Vs/ s H  oDR                  PM     sn5      -  nU[        ;   a
  [        U   nOU[        U'   O[        SU< S	3S
-   5      e Xl         Ub"  [        US5      (       ac  UR                   (       dR  SU l        U R                   b"  U R                   R%                  SS5      U l        O#[(        R*                  " S5      U l        OSU l        U R,                  (       a  U R/                  5         gg!   [        SR                  U5      5      e= fs  snf )zO
Provide a new key or scale, and re-configure the RN with the
existing figure.
NzJCannot call classes on object {0!r}, send only Key or Scale Music21Objectsr'   Scale
isConcreteF_z"Cannot get a key from this object z, send only zKey or Scale objectsTr   C)r  r  r   r,   rc  rr  rs  r(   r   r  rZ  r   r   nameWithOctaver   r  r  r  deriver  r   r  r  r  )r  r  
keyClasses	scaleHashr  s        r+   r   r    s    $)? j#&&)*5J#B'//

 
"44IECMIj??@J& 'OO	:|U;;3=3E3EF3Ea))3EF" I +!,Y!7J-7K	*+8lS,-. .
  J55&11#'D {{&$(KK$6$6q#$>!$)$4$4S$9!#(D    ! !UB+..4fZ.@B B Gs   F( 1G
(Gc                2    U R                   U R                  4$ )a  
Returns a two element tuple of the scale degree and the
accidental that alters the scale degree for things such as #ii or
bV.

Note that vi and vii in minor have a frontAlterationAccidental of
<sharp> even if it is not preceded by a `#` sign.

Has the same effect as setting .scaleDegree and
.frontAlterationAccidental separately

>>> v = roman.RomanNumeral('V', 'C')
>>> v.scaleDegreeWithAlteration
(5, None)

>>> neapolitan = roman.RomanNumeral('N6', 'c#')
>>> neapolitan.scaleDegreeWithAlteration
(2, <music21.pitch.Accidental flat>)
)r  r  r  s    r+   scaleDegreeWithAlteration&RomanNumeral.scaleDegreeWithAlteration  s    * !?!???r-   c                   Uc  U R                   n[        R                  " S5      nSnU/nUR                  [        ;  a  U R
                  $ UR                   HO  nUS-
  nX6-   n[        R                  " U5      u  p[        R                  " U U	 35      n
UR                  U
5        MQ     [        R                  " U5      nUR                  5       R                  nX-
  nU R
                  U-
  U R                  -  nUS:X  a  U R                  nU$ )a  
Given a notationObject from
:class:`music21.figuredBass.notation.Notation`
return the scaleDegree of the bass.

>>> fbn = figuredBass.notation.Notation('6,3')
>>> V = roman.RomanNumeral('V')
>>> V.bassScaleDegreeFromNotation(fbn)
7

>>> fbn2 = figuredBass.notation.Notation('#6,4')
>>> vi = roman.RomanNumeral('vi')
>>> vi.bassScaleDegreeFromNotation(fbn2)
3

Can figure it out directly from an existing RomanNumeral:

>>> ii65 = roman.RomanNumeral('ii65', 'C')
>>> ii65.bassScaleDegreeFromNotation()
4

Simple test:

>>> I = roman.RomanNumeral('I')
>>> I.bassScaleDegreeFromNotation()
1

Figures that do not imply a bass like 54 just return the instance
:attr:`scaleDegree`:

>>> V = roman.RomanNumeral('V54')
>>> V.bassScaleDegreeFromNotation()
5
C3r   r   r   )r  r   rl  rh  r$   r  r   convertDiatonicNumberToStepr   r   r  r   rt  r  )r  notationObjectccDNNr   rQ   distanceToMovenewDiatonicNumbernewStep	newOctaver{  	tempChordrootDNNstaffDistanceFromBassToRootbassSDs                  r+   re  (RomanNumeral.bassScaleDegreeFromNotation  s   N !!44NKK#!!)>>###''AUN!%!6!)!E!E!"#G{{gYyk#:;HNN8$ ( KK(	.."22&-n###&AA''(Q;**Fr-   c                P   U R                   b  U R                   $ U R                  (       aB  U R                  R                  S5      nSnU H  n [        U   S-  nX$-  nM     [        U5      $  [        U R                     nU$ ! [
         a    Sn N7f = f! [
         a    Sn U$ f = f)a  
Return or set a number from 1 to 100 representing the relative
functionality of this RN.figure (possibly given the mode, etc.).

Numbers are ordinal, not cardinal.

>>> rn1 = roman.RomanNumeral('V7')
>>> rn1.functionalityScore
80

>>> rn2 = roman.RomanNumeral('vi6')
>>> rn2.functionalityScore
10

>>> rn2.functionalityScore = 99
>>> rn2.functionalityScore
99

For secondary dominants, the functionality scores are multiplied, reducing
all but the first by 1/100th:

>>> rn3 = roman.RomanNumeral('V')
>>> rn3.functionalityScore
70

>>> rn4 = roman.RomanNumeral('vi')
>>> rn4.functionalityScore
40

>>> rn5 = roman.RomanNumeral('V/vi')
>>> rn5.functionalityScore
28
r   g      Y@rP   r   )r  r  rm  r'  r   KeyErrorr  )r  r  scoref	scoreParts        r+   functionalityScoreRomanNumeral.functionalityScore(  s    F ##/+++%%kk'',GE" 3A 6 <I "  u:	'4E    " !I"  	E	s$   B.B BBB%$B%c                    Xl         g r  )r  r  s     r+   r  r  _  s    #( r-   c                    U R                   S:w  a  gU R                  (       d  gU R                  R                  S:w  a  gU R                  S:w  a  gU(       a  U R	                  5       S:w  a  gg)aK  
Music21's Chord class contains methods for identifying chords of a particular type,
such as :meth:`~music21.chord.Chord.isAugmentedSixth`.

Some similar chord types are defined not only by the structure of a chord but
by its relation to a key.
The Neapolitan sixth is a notable example.
A chord is a Neapolitan sixth if it is a major triad, in first inversion, and
(here's the key-dependent part) rooted on the flattened second scale degree.

>>> chd = chord.Chord(['F4', 'Ab4', 'Db5'])
>>> rn = roman.romanNumeralFromChord(chd, 'C')
>>> rn.isNeapolitan()
True

As this is key-dependent, changing the key changes the outcome.

>>> rn = roman.romanNumeralFromChord(chd, 'Db')
>>> rn.isNeapolitan()
False

The 'N', 'N6' and 'N53' shorthand forms are accepted.

>>> rn = roman.RomanNumeral('N')
>>> rn.isNeapolitan()
True

>>> rn = roman.RomanNumeral('N6')
>>> rn.isNeapolitan()
True

Requiring first inversion is optional.

>>> rn = roman.RomanNumeral('bII')
>>> rn.isNeapolitan(require1stInversion=False)
True

>>> rn = roman.RomanNumeral('N53')
>>> rn.isNeapolitan(require1stInversion=False)
True

r!   FflatrL   r   T)r  r  r  r  r-  )r  require1stInversions     r+   isNeapolitanRomanNumeral.isNeapolitanc  s_    X q --))..&8<<7"4>>#3q#8r-   c                   U(       a*  U R                   (       a  U R                   R                  SS9$ U R                  (       d  U R                  (       d  gU R                  (       a)  [        U R                  [        R                  5      (       d  gU R                  R                  nUS;  a  gU R                  nU[        SS5      ;  a  gU R                  nUS;  a  gU R                  (       a  U R                  R                  nOSn1 S	kn1 S
knUS:X  a&  X4U4U;   a  gUS:X  a  U R                  5       (       a  ggUS:X  a%  X4U4U;   a  gUS:X  a  U R                  5       (       a  gg)u  
Checks if a RomanNumeral is an instance of 'modal mixture' in which the chord is
not diatonic in the key specified, but
would be in the parallel (German: variant) major / minor
and can therefore be thought of as a 'mixture' of major and minor modes, or
as a 'borrowing' from the one to the other.

Examples include "i" in major or "I" in minor (*sic*).

Specifically, this method returns True for all and only the following cases in any
inversion:

Major context (example of C major):

* scale degree 1 and triad quality minor (minor tonic chord, c);

* scale degree 2 and triad quality diminished (covers both iio and iiø7);

* scale degree b3 and triad quality major (Eb);

* scale degree 4 and triad quality minor (f);

* scale degree 5 and triad quality minor (g, NB: potentially controversial);

* scale degree b6 and triad quality major (Ab);

* scale degree b7 and triad quality major (Bb); and

* scale degree 7, and it is a diminished seventh (specifically b-d-f-ab).

Minor context (example of c minor):

* scale degree 1 and triad quality major (major tonic chord, C);

* scale degree 2 and triad quality minor (d, not diminished);

* scale degree #3 and triad quality minor (e);

* scale degree 4 and triad quality major (F);

* scale degree #6 and triad quality minor (a); and

* scale degree 7, and it is a half-diminished seventh (specifically b-d-f-a).

This list is broadly consistent with (and limited to) borrowing between the major and
natural minor, except for excluding V (G-B-D) and viio (B-D-F) in minor.
There are several borderline caes and this in-/exclusion is all open to debate, of course.
The choices here reflect this method's primarily goal to aid anthologizing and
pointing to clear cases of mixture in common practice Classical music.
At least in that context, V and viio are not generally regarded as mixure.

By way of example usage, here are both major and minor versions of the
tonic and subdominant triads in the major context.

>>> roman.RomanNumeral('I', 'D-').isMixture()
False

>>> roman.RomanNumeral('i', 'D-').isMixture()
True

>>> roman.RomanNumeral('IV', 'F').isMixture()
False

>>> roman.RomanNumeral('iv', 'F').isMixture()
True

For any cases extending beyond triad/seventh chords, major/minor keys,
and the like, this method simply returns False.

So when the mode is not major or minor (including when it's undefined), that's False.

>>> rn = roman.RomanNumeral('iv', 'C')
>>> rn.key.mode
'major'

>>> rn.isMixture()
True

>>> rn.key.mode = 'hypomixolydian'
>>> rn.isMixture()
False

A scale for a key never returns True for mixture.

>>> rn = roman.RomanNumeral('i', scale.MajorScale('D'))  # mode undefined
>>> rn.isMixture()
False

Likewise, anything that's not a triad or seventh will return False:

>>> rn = roman.romanNumeralFromChord(chord.Chord("C D E"))
>>> rn.isMixture()
False

Note that Augmented sixth chords do count as sevenths but never indicate modal mixture
(not least because those augmented sixths are the same in both major and minor).

>>> rn = roman.RomanNumeral('Ger65')
>>> rn.isSeventh()
True

>>> rn.isMixture()
False

False is also returned for any case in which the triad quality is not
diminished, minor, or major:

>>> rn = roman.RomanNumeral('bIII+')
>>> rn.quality
'augmented'

>>> rn.isMixture()
False

(That specific example of bIII+ in major is a borderline case that
arguably ought to be included and may be added later without a deprecation cycle.)

Naturally, really extended usages such as scale degrees beyond 7 (in the
Octatonic mode, for instance) also return False.

The evaluateSecondaryNumeral parameter allows users to choose whether to consider
secondary Roman numerals (like V/vi) or to ignore them.
When considered, exactly the same rules apply but recasting the comparison on
the secondaryRomanNumeral.
This is an extended usage that is open to debate and liable to change.

>>> roman.RomanNumeral('V/bVI', 'E-').isMixture()
False

>>> roman.RomanNumeral('V/bVI', 'E-').isMixture(evaluateSecondaryNumeral=True)
True

In case of secondary numeral chains, read the last one for mixture.

>>> roman.RomanNumeral('V/V/bVI', 'E-').isMixture(evaluateSecondaryNumeral=True)
True

OMIT_FROM_DOCS

Test that the 'C' key has not had its mode permanently changed with the
hypomixolydian change above:

>>> roman.RomanNumeral('iv', 'C').key.mode
'major'

(This is in OMIT_FROM_etc.)
T)evaluateSecondaryNumeralFrK   r   r   )r  rM   rL   natural>   r   rM   r  r!   r  r  r   rL   r  r   rM   r  r    rM   r  r   rL   r  r"   rL   r  >   r   rL   r  r!   rM   r  r   rM   r:  r   rL   r  r   rM   r:  rL   r"   rM   )r  	isMixturer0  r.  r   r  r'   r   r  ri  r  r  r  isDiminishedSeventhisHalfDiminishedSeventh)r  r  r   r  r  frontAccidentalNamemajorKeyMixturesminorKeyMixturess           r+   r  RomanNumeral.isMixture  sD   l $(B(B--77QU7VVt~~xxz$((CGG<<xx}}))&&eAqk),,::))"&"@"@"E"E"+	
	
 7?&9:>NN")A)A)C)C  W_&9:>NN")E)E)G)Gr-   )r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r   r  r  rk  r  r  r  r  r^  r]  r  r  )r/   N)rm  z	str | intr  z*key.Key | scale.ConcreteScale | str | None)r  r   r  r   )r  None)r  r   r  ztuple[int, ...])r  r   r  r  r  )r  key.Key | scale.ConcreteScalerm  z
str | Noner  )tuple[str, key.Key | scale.ConcreteScale])r  r   r  r  r  r  )r  r  r  r  )r  r   r  r  r  r   )r  r   r  zT | None)r  r   )r  r   )r  r   )r  z#tuple[int, pitch.Accidental | None])r  zfbNotation.Notation | Noner  r  )r  r  )r  r  )T)r  r  )F)r  r  )5r  r  r  r  r  equalityAttributesr   compiler6  r%  r*  r2  r<  r;  r  r?  r=  r  __annotations__rn  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rI  r  r  ri  propertyr  setterrm  r  r   r  re  r  r  r  r  __classcell__)r  s   @r+   r   r   x  s\   ^	~ + zz.1$;<zz">? "

+@ A::&:; jj)ST::&BC$'tDMjj.Oj! j!4 	 !5j!t 	 uj!D 	 Ej!l 	 mj!T 	$ &Uj!x 	  "yj!P 	+ -Qj!B 	  Cj!D 	 
Ej!Z 	 [j!| 	 }j!T 	 Uj!r 	 sj!r 	 sj!J	 	 K	j!v	 	  "w	j!P
%Ej!I~ j` ;?Q,
 !))#++Q,Q, 9Q, Q,f0)=V#Ja"7 rY9~  W)-W) W) 
1	W)r@>('Rk'k' .k' 
1	k'ZP-P 
P>m%m% .m% 
	m%^pd .3  2 #* #*J U U " " ]]" "  1  1D $ $L 	ZZ;" ;"F @ @0 48>0> 
>@ 4 4l ) ) 266*.6r 49Q,0Q Qr-   u  
    Gives a string representation of the roman numeral, which
    is usually the same as what you passed in as a string:

    >>> roman.RomanNumeral('bVII65/V', 'C').figure
    'bVII65/V'

    There are a few exceptions.  If the RomanNumeral is initialized
    with an int, then it is converted to a string:

    >>> roman.RomanNumeral(2).figure
    'II'

    A `0` used for `o` in a diminished seventh chord is converted to `o`,
    and the `/o` form of half-diminished is converted to `ø`:

    >>> roman.RomanNumeral('vii07').figure
    'viio7'
    >>> roman.RomanNumeral('vii/o7').figure
    'viiø7'

    Changing this value will not change existing pitches.

    * Changed in v6.5: empty RomanNumerals now have figure of '' not None
    c                      \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r Sr!g )!Testi  c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr  globals)r  r  s     r+   testCopyAndDeepcopyTest.testCopyAndDeepcopy  s    7D')$r-   c                    [         R                  " S5      n[        S5      nUR                  U5      nU R	                  US5        g )Nz6,3rU   r"   )rp  r  r   re  assertEqual)r  fbnrU   sdbs       r+   testFBNTest.testFBN  s<    !!%(++C0a r-   c                   [        S5      nU R                  UR                  S 5        U R                  UR                  [        R
                  " / SQ5      R                  5        [        S5      nU R                  UR                  S5        U R                  UR                  R                  R                  S5        U R                  UR                  R                  R                  S5        [        R                  " S5      n[        SU5      nU R                  U5        [        R                  " S	5      n[        S
U5      nU R                  UR                  [        R
                  " / SQ5      R                  5        [        SU5      nU R                  XV5        [        SU5      nU R                  UR                  [        R
                  " SS/5      R                  5        [        SU5      nU R                  UR                  [        R
                  " SS/5      R                  5        [        SU5      nU R                  UR                  [        R
                  " S/5      R                  5        [        S[        R                  " S5      5      nU R                  UR                  [        R
                  " S5      R                  5        g )NrU   )G4B4D5bbVI6r2   z#Descending Doubly-Diminished Unisonr  rn   r  zii/o65)r  zB-4r  E5u   iiø65zV[no3]A4r  zV[no5]zC#5z	V[no3no5]z	V13[no11]zG4 B4 D5 F5 A5 E5)r   r  r  r   r   r  r  	chromaticro  r  directedNiceNamer   r  assertIsNotNoner   r'   )r  r1cMr2dminorr  rnRealSlashrnOmits           r+   
testFigureTest.testFigure  s   #<<dCU[[1C%D%L%LM'"**C0<<FFPPRTU<<EEVV>	@c"$#R (F+JJKK12::	
 #8V4)h/dD\)B)J)JKh/dE])C)K)KLk62dV)<)D)DEk3773<85H)I)Q)QRr-   c                    [        S5      nU R                  [        UR                  5      S5        U R                  [        UR                  5      S5        g )Nz
V9[b7][b5]z[('b', 7), ('b', 5)]z(<music21.pitch.Pitch G4>, <music21.pitch.Pitch B4>, <music21.pitch.Pitch D-5>, <music21.pitch.Pitch F-5>, <music21.pitch.Pitch A5>))r   r  r   r  r   )r  r  s     r+   testBracketedAlterationsTest.testBracketedAlterations  sG    ,'R4457MNRZZR	Sr-   c                   SSK Jn  UR                  5       nUR                  [        R
                  " S5      5        UR                  [        R                  " 5       5        UR                  5       nUR                  U5        UR                  5       nUR                  U5        SnU R                  [        US   5      U5        [        R                  " U5      nUR                   H\  nUR                  UR                  5       H:  nUR                  [        R
                  5       H  nUR!                  U5        M     M<     M^     U R                  [        UR#                  5       R                  [        R
                  5      5      S5        [        R                  " U5      nU R                  [        UR#                  5       R                  [        R
                  5      5      U5        UR#                  5       R                  [        R
                  5       H:  nUR$                  R'                  5        H  n	U	c  M  U	R!                  U5        M     M<     [        R                  " U5      n
U R                  [        U
R#                  5       R                  [        R
                  5      5      U5        U
R)                  SS9 HN  n[+        U[        R
                  5      (       d  M$  UR,                  c  M3  UR,                  R!                  U5        MP     [        R                  " U5      nU R                  [        UR#                  5       R                  [        R
                  5      5      U5        [/        UR)                  SS95       HV  n[+        XR0                  5      (       d  M  UR                  [        R
                  5       H  nUR!                  U5        M     MX     g )	Nr   )streamr   r   KeySignatureT)streamsOnlyF)music21r	  Measurer   r   r
  r   NotePartScorer  r   r&   deepcopypartsgetElementsByClassremoveflattensitesrr  recurser  
activeSiter  Stream)r  r	  r  r  stargetCounts1es2sites3s4r  s                r+   testYieldRemoveATest.testYieldRemoveA  s   "NN	!!!$%	KKM	LLN	.!"	

 ]]1A))&..9--c.>.>?AHHQK @ :  	RZZ\<<S=M=MNOQRS]]1

//0@0@AB	
 001A1ABA#KKN & C ]]1

//0@0@AB	
 -A!S--..<<+LL''*	 . ]]1

//0@0@AB	

 bjjUj34A!]]++--c.>.>?AHHQK @ 5r-   c                >   SSK Jn  [        R                  " S5      nUR	                  SU5      nU R                  [        UR                  5      S5        U R                  [        UR                  5      S5        U R                  [        UR                  5      S5        g )Nr   r   zf#rU   zf# minorzQ(<music21.pitch.Pitch C#5>, <music21.pitch.Pitch E#5>, <music21.pitch.Pitch G#5>)z=[(5, None), (7, <music21.pitch.Accidental sharp>), (2, None)])	r  r   r   r'   r   r  r   r   scaleDegrees)r  r   kr  s       r+   testScaleDegreesATest.testScaleDegreesA  sy    !GGDMQ'RVVj1

O)	
 	 K	
r-   c                R   SSK Jn  UR                  S[        R                  " S5      5      nU R                  UR                   Vs/ s H  n[        U5      PM     sn/ SQ5        UR                  nU R                  / SQU5        UR                  nU R                  US5        g s  snf )Nr   r%  zbii/o42F)zF-4zG-4zB--4zD--5)r   r   r!   r   r   r   zhalf-diminished seventh chord)
r  r   r   r   r  r  r   r   intervalVector
commonName)r  r   alteredChordHalfDim3rdInvr  ivcns         r+   testNeapolitanAndHalfDiminished$Test.testNeapolitanAndHalfDiminished  s    !$)$6$6u'',%.!6>>?>SV>?*	
 '55+R0&11<= @s   B$c                    SSK Jn  [        R                  " S5      n[        R
                  " S5      nUR                  X#5      nU R                  UR                  S5        g )Nr   r%  z
A3 E-4 G-4zb-re   )	r  r   r   r  r   r'   rl  r  rm  )r  r   r  r'  rnDim7s        r+   testOmittedFifthTest.testOmittedFifth  sD    !KK%GGDM,,Q20r-   c                	   SSK Jn  S n[        R                  " S5      nUR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  S	U5      nU R                  U" U5      S
5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S 5        UR	                  S!U5      nU R                  U" U5      S"5        UR	                  S#U5      nU R                  U" U5      S$5        UR	                  S%U5      nU R                  U" U5      S&5        UR	                  S'U5      nU R                  U" U5      S(5        UR	                  S)U5      nU R                  U" U5      S*5        UR	                  S+U5      nU R                  U" U5      S,5        UR	                  S-U5      nU R                  U" U5      S.5        UR	                  S/U5      nU R                  U" U5      S05        UR	                  S1U5      nU R                  U" U5      S25        UR	                  S3U5      nU R                  U" U5      S45        UR	                  S5U5      nU R                  U" U5      S65        UR	                  S7U5      nU R                  U" U5      S85        UR	                  S9U5      nU R                  U" U5      S:5        UR	                  S;U5      nU R                  U" U5      S<5        UR	                  S=U5      nU R                  U" U5      S>5        g )?Nr   r%  c                v    SR                  U R                   Vs/ s H  oR                  PM     sn5      $ s  snf Nr#  r   r   r  r  r   s     r+   r  !Test.testAllFormsOfVII.<locals>.p"  +    88qyyAy!--yABBA   6r  r   zB4 D5 F5rk   zD4 F4 B4viio64zF4 B4 D5viiz	B4 D5 F#5vii6z	D4 F#4 B4vii64z	F#4 B4 D5re   zB4 D5 F5 A-5ri   zD4 F4 A-4 B4viio43zF4 A-4 B4 D5viio42zA-4 B4 D5 F5zvii/o7zB4 D5 F5 A5u   viiø65zD4 F4 A4 B4u   viiø43zF4 A4 B4 D5zvii/o42zA4 B4 D5 F5r   z	B-4 D5 F5VII6z	D4 F4 B-4VII64z	F4 B-4 D5bVIIzB--4 D-5 F-5bVII6zD-4 F-4 B--4bVII64zF-4 B--4 D-5bviiz
B-4 D-5 F5bvii6z
D-4 F4 B-4bvii64z
F4 B-4 D-5bviiozB-4 D-5 F-5bviio6zD-4 F-4 B-4bviio64zF-4 B-4 D-5z#VIIz
B4 D#5 F#5z#viizB#4 D#5 F##5zVII+z
B-4 D5 F#5r  r   r   r'   r   r  r  r   r  r'  r  s        r+   testAllFormsOfVIITest.testAllFormsOfVII  sh   !	C GGCL*2
++2
+!,2
+q)2,*2,+2,+2/!,2/!,2/!,2/!,2.	1-2.	1-2.	1-2.q)2,*2,+2,*2/+2/!,2/*2-+2-!,2-+2.!,2.	1-2.*2-*2/*2-r-   c                	   SSK Jn  S n[        R                  " S5      nUR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  S	U5      nU R                  U" U5      S
5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S5        UR	                  SU5      nU R                  U" U5      S 5        UR	                  S!U5      nU R                  U" U5      S"5        UR	                  S#U5      nU R                  U" U5      S$5        UR	                  S%U5      nU R                  U" U5      S&5        UR	                  S'U5      nU R                  U" U5      S(5        UR	                  S)U5      nU R                  U" U5      S*5        UR	                  S+U5      nU R                  U" U5      S,5        UR	                  S-U5      nU R                  U" U5      S.5        UR	                  S/U5      nU R                  U" U5      S05        UR	                  S1U5      nU R                  U" U5      S25        UR	                  S3U5      nU R                  U" U5      S45        UR	                  S5U5      nU R                  U" U5      S65        UR	                  S7U5      nU R                  U" U5      S85        UR	                  S9U5      nU R                  U" U5      S:5        UR	                  S;U5      nU R                  U" U5      S<5        UR	                  S=U5      nU R                  U" U5      S>5        g )?Nr   r%  c                v    SR                  U R                   Vs/ s H  oR                  PM     sn5      $ s  snf r9  r:  r;  s     r+   r   Test.testAllFormsOfVI.<locals>.po  r=  r>  r  vioz	A4 C5 E-5vio6z	C4 E-4 A4vio64z	E-4 A4 C5r   zA4 C5 E5r   zC4 E4 A4vi64zE4 A4 C5vio7zA4 C5 E-5 G-5vio65zC4 E-4 G-4 A4vio43zE-4 G-4 A4 C5vio42zG-4 A4 C5 E-5   viø7zA4 C5 E-5 G5zvi/o65zC4 E-4 G4 A4zvi/o43zE-4 G4 A4 C5u   viø42zG4 A4 C5 E-5r{   z
A-4 C5 E-5VI6z
C4 E-4 A-4VI64z
E-4 A-4 C5bVIzA--4 C-5 E--5bVI6zC-4 E--4 A--4bVI64zE--4 A--4 C-5bvizA-4 C-5 E-5bvi6zC-4 E-4 A-4bvi64zE-4 A-4 C-5bviozA-4 C-5 E--5bvio6zC-4 E--4 A-4bvio64zE--4 A-4 C-5r}   z	A4 C#5 E5z#vizA#4 C#5 E#5zVI+z	A-4 C5 E5rP  rQ  s        r+   testAllFormsOfVITest.testAllFormsOfVIl  sh   !	C GGCLq)2,*2,+2,a(2
+q)2
+*2
+*20+20+20+20+2/!,2/!,2/!,2/a(2-q)2-*2-q)20*20+20q)2.*2.+2.*2/+2/!,2/q)2,q)2.q)2,r-   c                  ^ ^^ SSK Jm  S mS#UUU 4S jjnU" SSS/S5        U" S	/ S
QS5        U" S/ SQS5        U" S/ SQS5        U" SS/SS5        U" SS/SS5        U" S	S/SS5        U" S	S/SS5        U" S	S/SS5        U" SS/SS5        U" SS/SS5        U" SS/SS5        U" SS/S S5        U" SS/S!S5        U" SS/S"S5        g )$Nr   r%  c                v    SR                  U R                   Vs/ s H  oR                  PM     sn5      $ s  snf r9  r:  r;  s     r+   r  Test.testAugmented.<locals>.p  r=  r>  c                   > U Hj  nS Ha  nX3R                  5       4 HI  n[        R                  " U5      nX-   U-   nTR                  X5      n	TR	                  T
" U	5      U5        MK     Mc     Ml     g )N)r/   r   )r  r   r'   r   r  )countryfigure_listr   key_inrm  	with_pluskStrkey_objrn_strr  r  r   r  s             r+   test_numeral(Test.testAugmented.<locals>.test_numeral  sh    %!*I!' 8"%''$-!(!4v!="//@((27	 !9 "+ &r-   rU  r2   r/   z	F5 A5 D#6r  )r/   r2   r?   z6/5zF5 A5 C6 D#6rX  )r/   r2   rC   z4/3zF5 A5 B5 D#6rY  zF5 A5 B#5 D#6r.   z
F#4 A-4 C5r  r,  z
C4 F#4 A-4r4   zF#4 A-4 C5 E-5rC   zC4 E-4 F#4 A-4rE   zE-4 F#4 A-4 C5zD4 F#4 A-4 C5r?   zF#4 A-4 C5 D5zC4 D4 F#4 A-4zD#4 F#4 A-4 C5zF#4 A-4 C5 D#5zC4 D#4 F#4 A-4)a)r  r   )r  rx  r  r   s   ` @@r+   testAugmentedTest.testAugmented  s   !	C	8 	8 	TC9k2U2NCT1>BT1?C 	TD6<5TD6<5USE#3S9UTF$4c:UTF$4c:TC5/37TD6?C8TD6?C8TC5"2C8TD6#3S9TD6#3S9r-   c                r   / SQn[         R                  " S5      n[         R                  " S5      nU GH   n[        XB5      n[        R                  " UR
                  5      n[        U5      nUS;  aR  U R                  UR                  UR                  U SU 35        U R                  UR                   R                  S5        [        Xb5      nU R                  UR                  UR                  U SU 35        [        Xc5      nU R                  UR                  UR                  U SU 35        GM     g )N)r   r9  r:  r   rA  rB  rC  r   r;  r<  r=  r   r>  r?  r@  r  r  )rC  r;  z: )
r   r'   r   r   r  r   rl  r  rm  r(   )r  augTestsc_minorc_majoraug6r  chrn_outs           r+   test_augmented_round_tripTest.test_augmented_round_trip  s    
 ''#,''#,Dd,BRZZ(B*2.F?*  FMMdV2fX;NO  !B!BCH +27FRYY$r&7JK*27FRYY$r&7JK r-   c                    [        S5      nUR                  nSUl        U R                  UR                  U5        [        S5      nUR                  nSUl        U R                  UR                  U5        g)z9
Setting the figure again doesn't double the alterations
rC  z#IVN)r   r   rm  r  )r  gerpitches_before
sharp_fours       r+   testSetFigureAgainTest.testSetFigureAgain  se     6"
n5!%(
#++!
++^<r-   c                   SSK Jn  UR                  SS5      nU R                  UR                   Vs/ s H  o3R
                  PM     sn/ SQ5        UR                  SS5      nU R                  UR                   Vs/ s H  o3R
                  PM     sn/ SQ5        UR                  SS5      nU R                  UR                   Vs/ s H  o3R
                  PM     sn/ S	Q5        g s  snf s  snf s  snf )
Nr   r%  vii07r  )BDr+  A-zvii/07)r  r  r+  Az	V7[add10])GB-r  r  r+  )r  r   r   r  r   r  )r  r   r  r  s       r+   testZeroForDiminishedTest.testZeroForDiminished  s    !-"**5*Q&&*57LM#."**5*Q&&*57KL S1"**5*Q&&*57QR 65 6s   C&<C+C0c                    [         R                  " / SQ5      n[        R                  " S5      n[	        X5      nU R                  UR                  S5        g )N)E4r  r  r  r  iii7r   r  r   r'   rl  r  rm  r  r  r'  r  s       r+   testIII7Test.testIII7  s<    KK01GGCL"1(F+r-   c                    [         R                  " / SQ5      n[        R                  " S5      n[	        X5      nU R                  UR                  S5        g )N)A3C4zE-4r  r  r_  r  r  s       r+   testHalfDimMinorTest.testHalfDimMinor  s<    KK12GGCL"1(G,r-   c                    [         R                  " / SQ5      n[        R                  " S5      n[	        X5      nU R                  UR                  S5        g )N)zF#3r  r  C5r  u   #iiiø7r  r  s       r+   testHalfDimIIITest.testHalfDimIII  s<    KK12GGCL"1(I.r-   c                    [         R                  " / SQ5      n[        R                  " S5      n[	        X5      nU R                  US5        [        X5      nU R                  UR                  S5        g )N)r  r  G5zC#6r  z#853zI#853)r   r  r   r'   r   r  rl  rm  )r  r  r'  r  r  s        r+   testAugmentedOctaveTest.testAugmentedOctave"  sV    KK12GGCL%a+F#"1(G,r-   c                    [        SS5      nU R                  UR                   Vs/ s H  o"R                  PM     sn/ SQ5        g s  snf )NzGer65/IVr  )D-r+  r  r  r   r  r   r  r  r  r  s      r+   testSecondaryAugmentedSixth Test.testSecondaryAugmentedSixth+  s7    *c*"**5*Q&&*57MN5   Ac                    [        SS5      nU R                  UR                   Vs/ s H  o"R                  PM     sn/ SQ5        g s  snf )NV7b5r  )r  r  r+  r  r  s      r+   testV7b5Test.testV7b5/  s7    &#&"**5*Q&&*57GH5r  c                (   [        SS5      nU R                  UR                   Vs/ s H  o"R                  PM     snSS/5        [        SS5      nU R                  UR                   Vs/ s H  o"R                  PM     snSS/5        g s  snf s  snf )Nz	viio[no5]rz  zG#r  zvii[no5]r  r  s      r+   testNo5Test.testNo53  sv    +s+"**5*Q&&*5c{C*c*"**5*Q&&*5c{C 6 6s   B
*Bc                   SnU HF  nU R                  US9   [        US5      nU R                  UR                  5       5        S S S 5        MH     SnU HF  nU R                  US9   [        US5      nU R	                  UR                  5       5        S S S 5        MH     SnU Hd  nU R                  US9   [        US5      nU R                  UR                  5       5        U R	                  UR                  SS95        S S S 5        Mf     g ! , (       d  f       GM  = f! , (       d  f       M  = f! , (       d  f       M  = f)N)r   r  z#IIr  bii6z#I)rm  rz  )r   N6N)N53r  F)r  )subTestr   assertFalser  
assertTrue)r  falseFiguresfigr  trueFiguresrootPositions         r+   testNeapolitanTest.testNeapolitan:  s     CS)!#s+  !23 *)   CS)!#s+ 12 *)   CS)!#s+  !23E JK *)  ' *) *) *)s$   ,D
%,D3A
D/

D	
D,	/
D>	c                p   S HU  nU R                  [        US5      R                  5       5        U R                  [        US5      R                  5       5        MW     S HU  nU R                  [        US5      R                  5       5        U R                  [        US5      R                  5       5        MW     g )N)rQ   r   bIIIr/  r   rb  rG  re   r  rz  )rO   rn   z#iiira   r   u   viiø7)r  r   r  r  )r  r  s     r+   testMixtureTest.testMixture]  s    JCOOLc2<<>?\#s3==?@	 K =C\#s3==?@OOLc2<<>?	 =r-   c                L   [        SS5      nUR                   Vs/ s H  o"R                  PM     nnU R                  U/ SQ5        [        R
                  " S5      [        R
                  " S5      4 H}  n[        R                  " S5      n[        XT5      nU R                  UR                  S5        [        R                  " S5      n[        Xt5      nU R                  UR                  S5        M     [        R
                  " S5      [        R
                  " S	5      4 H}  n[        R                  " S
5      n[        Xt5      nU R                  UR                  S5        [        R                  " S5      n[        Xt5      nU R                  UR                  S5        M     g s  snf )Ni7r  )r  E-r  r  r  zC4 E-4 G4 B-4zE-4 G4 B-4 C5i65r  gzG4 B-4 C5 E-5iv43zB-4 C5 E-5 G5iv42)
r   r   r  r  r   r'   r   r  rl  rm  )r  r  r  pitchStringsr'  ch1rn2r  s           r+   testMinorTonic7InMajorTest.testMinorTonic7InMajorj  s.   $$(*

3
1
3'=>''#,-A++o.C'/CSZZ._-B&r-BRYY. . ''#,-A_-B&r-BRYY/_-B&r-BRYY/ . 4s   F!c                  ^  SU 4S jjn[        SS5      nUR                   Vs/ s H  o3R                  PM     nnT R                  U/ SQ5        [        R
                  " S5      n[        US5      nT R                  UR                  S5        U" U5        [        R
                  " S5      n[        US5      nT R                  UR                  S5        U" U5        [        R
                  " S5      n	[        U	S	5      n
T R                  U
R                  S
5        U" U
S	5        [        R
                  " S5      n[        US	5      nT R                  UR                  S5        U" US	5        [        US5      nT R                  UR                  S5        U" US5        [        US5      nT R                  UR                  S5        U" US5        [        R
                  " S5      n	[        U	S5      n
T R                  U
R                  S
5        U" U
S5        [        R
                  " S5      n[        US5      nT R                  UR                  S5        U" US5        g s  snf )Nr  c           	       > U R                    Vs/ s H  o"R                  PM     nn[        U R                  U5      nUR                    Vs/ s H  o"R                  PM     nnTR	                  X5U SU SU  35        g s  snf s  snf )Nz not equal z for )r   r  r   rm  r  )rn_inr'  r  p_oldrn_newp_newr  s         r+   new_fig_equals_old_figure>Test.testMinorMajor7InMajor.<locals>.new_fig_equals_old_figure  sp    %*]]3]VV]E3!%,,2F%+^^4^VV^E4UeWKweE7+ST	 44s   A=Bzi7[#7])r  r  r  r  zC4 E-4 G4 B4zE-4 G4 B4 C5zi65[#7]zG4 B4 C5 E-5r  ziv43[#7]zB4 C5 E-5 G5ziv42[#7]r  zi#7r  )r  )r   r   r  r  r   r  rl  rm  )r  r  r  r  r  r  rn1ch2r  ch3rn3ch4rn4s   `            r+   testMinorMajor7InMajorTest.testMinorMajor7InMajor~  s   	U (C((*

3
1
3'<=kk.)#C-X.!#&kk.)#C-Y/!#&kk.)#C-Z0!#s+kk.)#C-Z0!#s+ $C-U+!#s+#C-Y/!#s+kk.)#C-Z0!#s+kk.)#C-Z0!#s+I 4s   Ic                    [        SS5      nU R                  UR                  5       R                  S5        U R                  UR                   Vs/ s H  o"R                  PM     sn/ SQ5        gs  snf )z
Fixes issue #1369
z	IV[add#7]r  F4)r  r  r  zE#5N)r   r  r   r  r   r  s      r+   test_addedPitch_sharp7Test.test_addedPitch_sharp7  sY     +s+1148BJJ?Jq**J?2	4?s   A0c                ,   [        SS5      nU R                  UR                  R                  S5        [        SS5      nU R                  UR                  R                  S5        [        SS5      nU R                  UR                  R                  S5        [        SS[        R
                  S9nU R                  UR                  R                  S	5        [        SS[        R
                  S9nU R                  UR                  R                  S
5        g )NbII7r  r  bII65r   r  bVII7)r^  r  r  )r   r  r/  r  rn  ro  )r  r  s     r+   test_sevenths_on_alteration Test.test_sevenths_on_alteration  s    &#&#.'3'#. '3'#.'3^5N5NO$/'3^5N5NO#.r-   c                   [         R                  " S5      n[        SU5      nU R                  UR                  S5        [        SUSS9nU R                  UR                  S5        [        SS5      nU R                  UR                  S5        [        S	[
        R                  " S5      5      nU R                  UR                  S
5        [        SS5      nU R                  UR                  S5        g)z<
Fix for https://github.com/cuthbertLab/music21/issues/1450
r  r!   rn   F)r  r  r   r/  r   r   r  ra   N)r   r'   r   r  rm  r   r  )r  minorKeyObjr  s      r+   test_int_figure_case_matters!Test.test_int_figure_case_matters  s     ggcl![)D)![e<D)!S!D)!U--c23D) !S!D)r-   c                   [         R                  " SSS9nUR                  S5      nU R                  UR                   Vs/ s H  o3R
                  PM     sn/ SQ5        [         R                  " SSS9nUR                  S5      nU R                  UR                   Vs/ s H  o3R
                  PM     sn/ SQ5        g s  snf s  snf )Nr  )r  r  Er+  r  r  r  )r   r   )r+  r  r  r  )r  r  r  r+  r  r  r  )r+  r  r  u   E♭)r   ConcreteScaler  r  r   unicodeName)r  mcsr  r  s       r+   test_scale_cachingTest.test_scale_caching  s    !!#/RSe$<A--<>RS!!#/STe$<A--<>UV = =s    B>Cr  N)"r  r  r  r  r  r  r  r  r"  r(  r1  r5  rR  rk  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r-   r+   r  r    s    %
!S>S6 p
 >1K.ZI-V :DL<=	S,-/-OID!LF@0(-,^4/*(Wr-   r  c                      \ rS rSrSrS rSrg)TestExternali  Tc                .   SSK Jn  UR                  S5      nUR                  5       nUR	                  S5      n0 nUR                  5        HW  n[        U[        R                  5      (       d  M$  [        Xd5      nUR                  nX;  a  SXX'   OXX==   S-  ss'   Xl        MY     U R                  (       a+  [        XUR                  SS9n	U	 H  n
[        XU
   5        M     UR!                  SU5        U R                  (       a  UR                  5         g g )Nr   )corpuszbwv103.6r   r   T)r   reverse)r  r  parsechordifyanalyzer  r  r   r  rl  rm  lyricshowr   rr  printr   )r  r  r   r  cKeyfiguresCacher   rncrm  
sortedList
thisFigures              r+   testFromChordifyTestExternal.testFromChordify  s    "LL$JJLyyA!U[[))+A4-+,L( (A-(   992B2BDQJ(
jz":; ) 	
A99FFH r-   r  N)r  r  r  r  r  r  r  r  r-   r+   r  r    s    Dr-   r  __main__)r)   r   r  key.Keyr  )r   chord.Chordr   r  r  zlist[ChordFigureTuple])r  r  r*   r  r   r  r  r   )r  zlist | tuple | chord.Chordr  r  r  zstr | t.Literal[False])r  r  r3  z
int | Noner  r   )r6  r   r*   r  r  r   )NF)r   r  r*   zkey.Key | str | Noner[  r  r  r   )Er  
__future__r   r&   enumr   typingrf  unittestcollectionsr   r  r   r   r   r   r	   music21.figuredBassr
   rp  r   r   r   r   r   r   r   r   EnvironmentenvironLocalTypeVarr   r  r   r   r   r  r   r  r  r$   r,   r   rN   r   r   r   r   r   r   r*  r  r7  rl  Enumrn  Music21Exceptionr  r  rr  Harmonyr   rm  TestCaser  r  
_DOC_ORDERr  mainTestr  r-   r+   <module>r     s.   #   	   "       6      (HI02[\ &&w/ IIc(
 zz-.I& /1+ 0 "	 " !))+ 	6 2 	$" 	# 
3	
 	# 	# C 
3 
3 	# 	# 	# 
4 E 
4  
4!$ t%& + 2) o 1'1'1' 	"1' 	1'
 
21' 	"1' 	"1' 
21' 
21' 	"1' 	"1' R1' 
21' b1' R1'  r!1'" 	"#1'$ b%1'& B'1'( B)1'* B+1', 
2-1'. 
2/1'0 	"11'2 
231'4 	"51'6 B71'8 R91': 
2;1'< R=1'> B?1'@ 
2A1'B RC1'D RE1'F 	a1' ^ 1n4n$)Nxv?D<<< < 	<~O6#O6O6 O6d6rEKEKEK EKT  $%*@@@ #@ 	@FTYY J\22 	J 	t'7?? t'pO   <Q	W8 Q	Wh8$$ > 

 zT r-   