
    rhT(                       S SK J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\R                  R                  5      r
\
R                  S	\
R                  S
\
R                  S\
R                  S\
R                  S\
R                   S\
R"                  S\
R$                  S\
R&                  S\
R(                  S\
R*                  S0r\
R.                  S\
R0                  S\
R2                  S\
R4                  S\
R6                  S\
R8                  S\
R:                  S0r0 \E\Er\
R.                  S\
R0                  S\
R2                  S\
R4                  S\
R6                  S\
R8                  S\
R:                  S0r0 \E\Er S    S!S jjr  S"   S#S jjr! " S S\RD                  5      r#\$S:X  a  S SKr\RJ                  " \#5        gg)$    )annotationsN)common)key)roman)scalec                  \    \ 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)HarmonicFunction   TTpTgttPtGSSpSgssPsGDDpDgddPdG N)__name__
__module____qualname____firstlineno__TONIC_MAJORTONIC_MAJOR_PARALLELKLANG_MINORTONIC_MAJOR_GEGENKLANG_MINORTONIC_MINORTONIC_MINOR_PARALLELKLANG_MAJORTONIC_MINOR_GEGENKLANG_MAJORSUBDOMINANT_MAJOR%SUBDOMINANT_MAJOR_PARALLELKLANG_MINOR"SUBDOMINANT_MAJOR_GEGENKLANG_MINORSUBDOMINANT_MINOR%SUBDOMINANT_MINOR_PARALLELKLANG_MAJOR"SUBDOMINANT_MINOR_GEGENKLANG_MAJORDOMINANT_MAJOR"DOMINANT_MAJOR_PARALLELKLANG_MINORDOMINANT_MAJOR_GEGENKLANG_MINORDOMINANT_MINOR"DOMINANT_MINOR_PARALLELKLANG_MAJORDOMINANT_MINOR_GEGENKLANG_MAJOR__static_attributes__r       [/home/james-whalen/.local/lib/python3.13/site-packages/music21/analysis/harmonicFunction.pyr	   r	      sj    K&*##' K&*##' ,0))-&,0))-&N)-&&*#N)-&&*#r5   r	   IibIIiiIVivVvvibviibIIIiiibVIbVIIIIIz#iiiVIVIIc                $   [        U[        5      (       a  [        R                  " U5      n[        n[        U[        R                  5      (       a  UR
                  S:X  a  [        n X    n[        R                  " X15      $ ! [         a     gf = f)u[
  
Takes harmonic function labels (such as 'T' for major tonic)
with a key (keyOrScale, default = 'C') and
returns the corresponding :class:`~music21.roman.RomanNumeral` object.

>>> analysis.harmonicFunction.functionToRoman('T')
<music21.roman.RomanNumeral I in C major>

The harmonicFunction argument can be a string (as shown),
though strictly speaking, it's handled through a special HarmonicFunction enum object.

>>> fn = analysis.harmonicFunction.HarmonicFunction.TONIC_MAJOR
>>> str(fn)
'T'

>>> analysis.harmonicFunction.functionToRoman(fn).figure
'I'

As with Roman numerals, this is case sensitive.
For instance, 't' indicates a minor tonic
as distinct from the major tonic, 'T'.

>>> analysis.harmonicFunction.functionToRoman('t').figure
'i'

There are 18 main functional labels supported in all, for
the three functional categories
(T for tonic, S for subdominant, and D for dominant) and
three relevant transformation types (none, P, and G)
all in upper and lower case (for major/minor):
T, Tp, Tg, t, tP, tG,
S, Sp, Sg, s, sP, sG,
D, Dp, Dg, d, dP, dG.

Note that this module uses terminology from modern German music theory
where Functional notation ('HarmonicFunctionstheorie') is typically used
throughout the curriculum in preference over Roman numerals ('Stufentheorie').

First, note the false friend: here 'P' for 'Parallel'
connects a major triad with the minor triad a minor third below (e.g. C-a).
(in English-speaking traditions this would usually be 'relative').

Second, note that this module uses
'G' (and 'g'), standing for
'Gegenklänge' or 'Gegenparallelen'.
'L' (and 'l') for Leittonwechselklänge is equivalent to this.
(Again, 'G' is more common in modern German-language music theory).

Use the keyOrScale argement to specify a key.
This makes a difference where 6th and 7th degrees of minor are involved.

>>> analysis.harmonicFunction.functionToRoman('sP', keyOrScale='C').figure
'bVI'

>>> analysis.harmonicFunction.functionToRoman('sP', keyOrScale='a').figure
'VI'

Some of the 18 main functions overlap, with two functional labels
referring to the same Roman numeral figure.
For instance both 'Tg' and 'Dp' simply map to 'iii':

>>> analysis.harmonicFunction.functionToRoman('Tp').figure
'vi'

>>> analysis.harmonicFunction.functionToRoman('Sg').figure
'vi'

The reverse operation is handled by the complementary
:func:`~music21.analysis.harmonicFunction.romanToFunction`.
In this case, :func:`~music21.analysis.harmonicFunction.romanToFunction`
follows the convention of preferring the P-version over alternatives.

>>> rn = roman.RomanNumeral('vi')
>>> str(analysis.harmonicFunction.romanToFunction(rn))
'Tp'

minorN)

isinstancestrr   KeyfunctionFigureTuplesMajormodefunctionFigureTuplesMinorKeyErrorr   RomanNumeral)thisHarmonicFunction
keyOrScalereferenceTuplesfigures       r6   functionToRomanrV   h   sz    ` *c""WWZ(
/O*cgg&&:??g+E3 6 f11  s   (B 
BBc                   [         nU R                  (       a   U R                  R                  S:X  a  [        nUR	                  5        H9  u  p4U R
                  U:X  d  M  U(       a  [        [        U5      S   5      s  $ Us  $    g)a  
Takes a Roman numeral and returns a corresponding harmonic function label.

>>> rn1 = roman.RomanNumeral('VI', 'a')
>>> fn1 = analysis.harmonicFunction.romanToFunction(rn1)
>>> fn1
<HarmonicFunction.SUBDOMINANT_MINOR_PARALLELKLANG_MAJOR>

This can be converted into a string:

>>> str(fn1)
'sP'

Optionally, set onlyHauptHarmonicFunction to True to return
a simplified version with only the HauptHarmonicFunction
(one of t, T, s, S, d, D: major and minor forms of the tonic, subdominant and dominant).

>>> fn1 = analysis.harmonicFunction.romanToFunction(rn1, onlyHauptHarmonicFunction=True)
>>> fn1
<HarmonicFunction.SUBDOMINANT_MINOR>

>>> str(fn1)
's'

Inversions are not currently considered (they may be in a future version of this).
This function simply uses the romanNumeral attribute of the roman.RomanNumeral object.
This excludes inversions, but
includes, where applicable, the frontAlterationAccidental.modifier.

>>> rn2 = roman.RomanNumeral('bII6', 'g')
>>> fn2 = analysis.harmonicFunction.romanToFunction(rn2)
>>> fn2
<HarmonicFunction.SUBDOMINANT_MINOR_GEGENKLANG_MAJOR>

>>> str(fn2)
'sG'

See further notes on the complementary
:func:`~music21.analysis.harmonicFunction.functionToRoman`.
rI   r   N)rM   r   rN   rO   itemsromanNumeralr	   rK   )rnonlyHauptHarmonicFunctionrT   thisKey	thisValues        r6   romanToFunctionr^      sh    X 0O	vv66;;'!7O-335??i'('GQ88 6 r5   c                  ,    \ rS rSrS rS rS rS rSrg)Testi  c                    [          H  n[        U5        M     [         H  n[        U5        M     SnU R                  [        [        U5        g)z
Test that all the entries in the functionFigureTuples
(both major and minor) are represented in the HarmonicFunction enum.

Also tests one fake (invalid) function label.
TPGN)rM   r	   rO   assertRaises
ValueError)selfrR   fakeExamples      r6   testAllFunctionLabelsInEnum Test.testAllFunctionLabelsInEnum  sF     %> 12 %>$= 12 %> *&6Dr5   c                j    U R                  [        [        R                  5      R                  S5        g )Nr7   )assertEqualrV   r	   r"   rU   re   s    r6   testFunctionToRomanTest.testFunctionToRoman  s$    )9)E)EFMMsSr5   c                H   [         R                  " SS5      n[        U5      nU R                  U[        R
                  5        U R                  [        U5      S5        [        USS9nU R                  U[        R                  5        U R                  [        U5      S5        g )NrE   fr   T)r[   r   )	r   rQ   r^   assertIsr	   r&   rj   rK   r%   )re   rZ   fn1fn2s       r6   testSimplifiedTest.testSimplified  s|    s+b!c+KKLS4(bDAc+778S3'r5   c                b    U R                  [        [        R                  " S5      5      S5        g )Ni6r   )rj   r^   r   rQ   rk   s    r6   testIgnoresInversionTest.testIgnoresInversion"  s"    ););D)ABCHr5   r   N)	r   r   r    r!   rg   rl   rs   rw   r4   r   r5   r6   r`   r`     s    E"T	(Ir5   r`   __main__)C)rR   r	   rS   z#key.Key | scale.ConcreteScale | strreturnzroman.RomanNumeral | None)F)rZ   zroman.RomanNumeralr[   boolr{   zHarmonicFunction | None)&
__future__r   unittestmusic21r   r   r   r   enumsStrEnumr	   r"   r%   r-   r)   r(   r+   r.   r1   r#   r*   r0   _functionFigureTuplesKeyNeutralr&   r3   r/   r$   r,   r'   r2   rM   rO   rV   r^   TestCaser`   r   mainTestr   r5   r6   <module>r      s    #     +v||++ +6   #  #77::D&&&&##S##S44d7744f## * 44f44f77115::E11577 %  44e44e77116::D11477 %  CF[2 ?[20[2~ 7<8/38.8x!I8 !IJ zT r5   