§
    ƒØj+n  ã                  ó„  — d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlm	Z	 ddlm
Z
  e
j        d¦  «        Z G d	„ d
ej        ¦  «        Zd„ Zd!d„Zd!d„Zd!d„Zd„ Zd"d„Zd„ Z	 	 	 	 d#d„Zd$d„Zd„ Zd%d„Zd&d„Zd„ Zd„ Z G d„ dej        ¦  «        ZeeeeeeeeeeeeegZe d k    rddlZ ej!        e¦  «         dS dS )'z¡
This module defines the L, P, and R objects and their
related transformations as called on a :class:`~music21.chord.Chord`,
according to Neo-Riemannian theory.
é    )ÚannotationsN)Úexceptions21)Úchord)Úenharmonics)Úenvironmentzanalysis.neoRiemannianc                  ó   — e Zd ZdS )ÚLRPExceptionN)Ú__name__Ú
__module__Ú__qualname__© ó    ú“/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/music21/analysis/neoRiemannian.pyr	   r	       s   € € € € € Ø€Dr   r	   c                ó®   — d„ | j         D ¦   «         }t          j        |¦  «        }|                     ¦   «         }t	          j        | ¦  «        }||_         |S )a¡  
    Returns a copy of chord `c` with pitches simplified.

    Uses `:meth:music21.analysis.enharmonics.EnharmonicSimplifier.bestPitches`

    >>> c = chord.Chord('B# F- G')
    >>> c2 = analysis.neoRiemannian._simplerEnharmonics(c)
    >>> c2
    <music21.chord.Chord C E G>
    >>> c3 = analysis.neoRiemannian._simplerEnharmonics(c2)

    Returns a copy even if nothing has changed.

    >>> c2 is c3
    False
    c                ó   — g | ]	}|j         ‘Œ
S r   ©ÚnameWithOctave)Ú.0Úps     r   ú
<listcomp>z'_simplerEnharmonics.<locals>.<listcomp>5   s   € Ð5Ð5Ð5 a�Ô!Ð5Ð5Ð5r   )Úpitchesr   ÚEnharmonicSimplifierÚbestPitchesÚcopyÚdeepcopy)ÚcÚ	pitchListÚesÚ
newPitchesÚnewChords        r   Ú_simplerEnharmonicsr!   #   sT   € ð$ 6Ð5¨1¬9Ð5Ñ5Ô5€IÝ	Ô	)¨)Ñ	4Ô	4€BØ—’Ñ!Ô!€JÝŒ}˜QÑÔ€HØ!€HÔØ€Or   Tc                óü   — |                       ¦   «         rd}|                      ¦   «         }n3|                      ¦   «         r
d}| j        }n|du rt	          d¦  «        ‚| S t          | ||¦  «        }| j        |_        |S )aB  
    L transforms a major or minor triad through the 'Leading-Tone exchange'.
    A C major chord, under L, will return an E minor chord, by transforming the root
    to its leading tone, B.

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = analysis.neoRiemannian.L(c1)
    >>> c2.pitches
    (<music21.pitch.Pitch B3>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch G4>)

    Chords must be major or minor triads:

    >>> c3 = chord.Chord('C4 D4 E4')
    >>> analysis.neoRiemannian.L(c3)
    Traceback (most recent call last):
    music21.analysis.neoRiemannian.LRPException: Cannot perform L on this chord:
        not a major or minor triad

    If `raiseException` is `False` then the original chord is returned.

    >>> c4 = analysis.neoRiemannian.L(c3, raiseException=False)
    >>> c4 is c3
    True

    Accepts any music21 chord, with or without octave specified:

    >>> noOctaveChord = chord.Chord([0, 3, 7])
    >>> chordL = analysis.neoRiemannian.L(noOctaveChord)
    >>> chordL.pitches
    (<music21.pitch.Pitch C>, <music21.pitch.Pitch E->, <music21.pitch.Pitch A->)
    z-m2Úm2Tz:Cannot perform L on this chord: not a major or minor triad)ÚisMajorTriadÚrootÚisMinorTriadÚfifthr	   Ú_singlePitchTransformÚquarterLength©r   ÚraiseExceptionÚtransposeIntervalÚchangingPitchÚoutChords        r   ÚLr/   <   s�   € ðB 	‡~‚~ÑÔð 	Ø!ÐØŸš™œˆˆØ	
�ŠÑ	Ô	ð Ø ÐØœˆˆà˜TÐ!Ð!ÝÐ[Ñ\Ô\Ð\Øˆå$ QÐ(9¸=ÑIÔI€HØœ_€HÔà€Or   c                óâ   — |                       ¦   «         r
d}| j        }n3|                      ¦   «         r
d}| j        }n|du rt          d¦  «        ‚| S t	          | ||¦  «        }| j        |_        |S )aœ  
    P transforms a major or minor triad chord to its 'parallel':
    i.e. to the chord of the same diatonic name but opposite model.

    Example: A C major chord, under P, will return an C minor chord

    >>> c2 = chord.Chord('C4 E4 G4')
    >>> c3 = analysis.neoRiemannian.P(c2)
    >>> c3.pitches
    (<music21.pitch.Pitch C4>, <music21.pitch.Pitch E-4>, <music21.pitch.Pitch G4>)

    See :func:`~music21.analysis.neoRiemannian.L` for further details about error handling.

    OMIT_FROM_DOCS

    >>> c3 = chord.Chord('C4 D4 E4')
    >>> analysis.neoRiemannian.P(c3)
    Traceback (most recent call last):
    music21.analysis.neoRiemannian.LRPException...
    z-A1ÚA1Tz:Cannot perform P on this chord: not a Major or Minor triad)r$   Úthirdr&   r	   r(   r)   r*   s        r   ÚPr3   m   s†   € ð* 	‡~‚~ÑÔð 	Ø!ÐØœˆˆØ	
�ŠÑ	Ô	ð Ø ÐØœˆˆà˜TÐ!Ð!ÝÐ[Ñ\Ô\Ð\Øˆå$ QÐ(9¸=ÑIÔI€HØœ_€HÔà€Or   c                óü   — |                       ¦   «         r
d}| j        }n@|                      ¦   «         rd}|                      ¦   «         }n|du rt	          d¦  «        ‚| S t          | ||¦  «        }| j        |_        |S )aŸ  
    R transforms a major or minor triad to its relative, i.e. if
    major, to its relative minor and if minor, to its relative major.

    Example 1: A C major chord, under R, will return an A minor chord

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = analysis.neoRiemannian.R(c1)
    >>> c2.pitches
    (<music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch A4>)

    See :func:`~music21.analysis.neoRiemannian.L` for further details about error handling.

    OMIT_FROM_DOCS

    >>> c3 = chord.Chord('C4 D4 E4')
    >>> analysis.neoRiemannian.R(c3)
    Traceback (most recent call last):
    music21.analysis.neoRiemannian.LRPException...
    ÚM2z-M2Tz:Cannot perform R on this chord: not a Major or Minor triad)r$   r'   r&   r%   r	   r(   r)   r*   s        r   ÚRr6   ’   sŒ   € ð* 	‡~‚~ÑÔð 	Ø ÐØœˆˆØ	
�ŠÑ	Ô	ð Ø!ÐØŸš™œˆˆà˜TÐ!Ð!ÝÐ[Ñ\Ô\Ð\Øˆå$ QÐ(9¸=ÑIÔI€HØœ_€HÔà€Or   c                ój  — t          j        |¦  «        }t          j        | ¦  «        }t          t          |j        ¦  «        ¦  «        D ]Q}d|j        |         _        |j        |j        |         j        k    r"|j        |                              |d¬¦  «         ŒRt          j	        |j        ¦  «        S )z|
    Performs a neoRiemannian transformation on c that involves transposing `changingPitch` by
    `transposeInterval`.
    FT)ÚinPlace)
r   r   ÚrangeÚlenr   ÚspellingIsInferredÚnameÚ	transposer   ÚChord)r   r,   r-   ÚchangingPitchCopyr    Úis         r   r(   r(   ·   s¦   € õ
 œ mÑ4Ô4ÐÝŒ}˜QÑÔ€HÝ•3�xÔ'Ñ(Ô(Ñ)Ô)ð Kð KˆØ16ˆÔ˜ÔÔ.ØÔ! XÔ%5°aÔ%8Ô%=Ò=Ð=ØÔ˜QÔ×)Ò)Ð*;ÀTÐ)ÑJÔJÐJøÝŒ;�xÔ'Ñ(Ô(Ð(r   ÚLRPc                ó  — |j         }|D ]}|dk    rt          | ¦  «        }|j         |k    r dS Œ&|dk    rt          | ¦  «        }|j         |k    r dS ŒJ|dk    rt          | ¦  «        }|j         |k    r dS Œnt	          |› d�¦  «        ‚dS )a¾  
    Tests if two chords are related by a single L, P, R transformation,
    and returns that transform if so (otherwise, False).

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = chord.Chord('B3 E4 G4')
    >>> analysis.neoRiemannian.isNeoR(c1, c2)
    'L'

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = chord.Chord('C4 E-4 G4')
    >>> analysis.neoRiemannian.isNeoR(c1, c2)
    'P'

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = chord.Chord('C4 E4 A4')
    >>> analysis.neoRiemannian.isNeoR(c1, c2)
    'R'

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = chord.Chord('C-4 E-4 A-4')
    >>> analysis.neoRiemannian.isNeoR(c1, c2)
    False

    Option to limit to the search to only 1-2 transforms ('L', 'R', 'P', 'LR', 'LP', 'RP'). So:

    >>> c3 = chord.Chord('C4 E-4 G4')
    >>> analysis.neoRiemannian.isNeoR(c1, c3)
    'P'

    ... but not if P is excluded ...

    >>> analysis.neoRiemannian.isNeoR(c1, c3, transforms='LR')
    False
    r/   r6   r3   ú3 is not a NeoRiemannian transformation (L, R, or P)F)ÚnormalOrderr/   r6   r3   r	   )Úc1Úc2Ú
transformsÚc2NOr@   r   s         r   ÚisNeoRrI   Æ   sÂ   € ðL Œ>€Dàð Zð ZˆØ�Š8ˆ8Ý�"‘”ˆAØŒ} Ò$Ð$Ø�s�sð %à�#ŠXˆXÝ�"‘”ˆAØŒ} Ò$Ð$Ø�s�sð %à�#ŠXˆXÝ�"‘”ˆAØŒ} Ò$Ð$Ø�s�sð %õ  !ÐXÐXÐXÑYÔYÐYàˆ5r   c                óf   — g d¢}|j         }|D ]"}t          | |¬¦  «        }|j         |k    r|c S Œ#dS )a¡  
    Tests if there is a chromatic mediant relation between two chords
    and returns the type if so (otherwise, False).

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = chord.Chord('A-3 C4 E-4')
    >>> analysis.neoRiemannian.isChromaticMediant(c1, c2)
    'LFM'

    >>> c3 = chord.Chord('C4 E4 G4')
    >>> c4 = chord.Chord('C-4 E-4 A-4')
    >>> analysis.neoRiemannian.isChromaticMediant(c3, c4)
    False
    ©ÚUFMÚUSMÚLFMÚLSM©ÚtransformationF)rD   ÚchromaticMediants)rE   rF   ÚtransformListrH   Ú	transformÚ	thisChords         r   ÚisChromaticMediantrV      s]   € ð" 1Ð0Ð0€MàŒ>€Dà"ð ð ˆ	Ý% b¸ÐCÑCÔCˆ	ØÔ  DÒ(Ð(ØÐÐÐð )ð ˆ5r   Fc                ó’  — |                       ¦   «         s-|                      ¦   «         s|du rt          d| › d�¦  «        ‚| S |r|ddd…         }g }|D ]Ð}|dk    r9t          | ¦  «        } |r'|                     t          j        | ¦  «        ¦  «         ŒA|dk    r9t          | ¦  «        } |r'|                     t          j        | ¦  «        ¦  «         Œ€|dk    r9t          | ¦  «        } |r'|                     t          j        | ¦  «        ¦  «         Œ¿t          |› d	�¦  «        ‚|r|s|S d
„ |D ¦   «         S |s| S t          | ¦  «        S )aë
  
    LRP_combinations takes a major or minor triad, transforms it according to the
    list of L, R, and P transformations in the given transformationString, and
    returns the result in triad.
    Certain combinations, such as LPLPLP, are cyclical, and therefore
    will return a copy of the original chord if `simplifyEnharmonics` = `True` (see
    :func:`~music21.analysis.neoRiemannian.completeHexatonic`, below).

    `leftOrdered` allows a user to work with their preferred function notation (left or right
    orthography).

    By default, `leftOrdered` is False, so transformations progress towards the right.
    Thus, 'LPR' will start by transforming the chord by L, then P, then R.

    If `leftOrdered` is True, the operations work in the opposite direction (right to left), so
    'LPR' indicates the result of the chord transformed by R, then P, then L.

    `simplifyEnharmonics` replaces multiple sharps and flats where they arise from
    combined transformations with the simpler enharmonic equivalent (e.g. C for D--).
    If simplifyEnharmonics is True, the resulting chord will be simplified
    to a collection of notes with at most 1 flat or 1 sharp, in their most common form.

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> c2 = analysis.neoRiemannian.LRP_combinations(c1, 'LP')
    >>> c2
    <music21.chord.Chord B3 E4 G#4>

    >>> c2b = analysis.neoRiemannian.LRP_combinations(c1, 'LP', leftOrdered=True)
    >>> c2b
    <music21.chord.Chord C4 E-4 A-4>

    >>> c3 = chord.Chord('C4 E4 G4 C5 E5')
    >>> c4 = analysis.neoRiemannian.LRP_combinations(c3, 'RLP')
    >>> c4
    <music21.chord.Chord C4 F4 A-4 C5 F5>

    >>> c5 = chord.Chord('B4 D#5 F#5')
    >>> c6 = analysis.neoRiemannian.LRP_combinations(c5,
    ...                        'LPLPLP', leftOrdered=True, simplifyEnharmonics=True)
    >>> c6
    <music21.chord.Chord B4 D#5 F#5>
    >>> c5 = chord.Chord('C4 E4 G4')
    >>> c6 = analysis.neoRiemannian.LRP_combinations(c5, 'LPLPLP', leftOrdered=True)
    >>> c6
    <music21.chord.Chord D--4 F-4 A--4>
    >>> c5 = chord.Chord('A-4 C4 E-5')
    >>> c6 = analysis.neoRiemannian.LRP_combinations(c5, 'LPLPLP')
    >>> c6
    <music21.chord.Chord G#4 B#3 D#5>

    Optionally: return all chords creating by the given string in order.

    >>> c7 = chord.Chord('C4 E4 G4')
    >>> c8 = analysis.neoRiemannian.LRP_combinations(
    ...            c7, 'LPLPLP', simplifyEnharmonics=True, eachOne=True)
    >>> c8
    [<music21.chord.Chord B3 E4 G4>,
    <music21.chord.Chord B3 E4 G#4>,
    <music21.chord.Chord B3 D#4 G#4>,
    <music21.chord.Chord C4 E-4 A-4>,
    <music21.chord.Chord C4 E-4 G4>,
    <music21.chord.Chord C4 E4 G4>]

    On that particular case of LPLPLP, see more in
    :func:`~music21.analysis.neoRiemannian.completeHexatonic`.
    Tz(Cannot perform transformations on chord z: not a major or minor triadNéÿÿÿÿr/   r6   r3   rC   c                ó,   — g | ]}t          |¦  «        ‘ŒS r   )r!   ©r   Úxs     r   r   z$LRP_combinations.<locals>.<listcomp>‡  s!   € Ð>Ð>Ð>¨qÕ'¨Ñ*Ô*Ð>Ð>Ð>r   )
r$   r&   r	   r/   Úappendr   r   r6   r3   r!   )r   ÚtransformationStringr+   ÚleftOrderedÚsimplifyEnharmonicsÚeachOneÚ	chordListr@   s           r   ÚLRP_combinationsrb     s—  € ðT �>Š>ÑÔð  A§N¢NÑ$4Ô$4ð Ø˜TÐ!Ð!ÝØZ¸1ÐZÐZÐZñ\ô \ð \àˆàð :Ø3°D°D°b°DÔ9Ðà€Ià!ð Zð ZˆØ�Š8ˆ8Ý�!‘”ˆAØð 3Ø× Ò ¥¤¨qÑ!1Ô!1Ñ2Ô2Ð2øØ�#ŠXˆXÝ�!‘”ˆAØð 3Ø× Ò ¥¤¨qÑ!1Ô!1Ñ2Ô2Ð2øØ�#ŠXˆXÝ�!‘”ˆAØð 3Ø× Ò ¥¤¨qÑ!1Ô!1Ñ2Ô2Ð2øå !ÐXÐXÐXÑYÔYÐYàð 	*Ø"ð 	?ØÐà>Ð>°IÐ>Ñ>Ô>Ð>à"ð 	*ØˆHå& qÑ)Ô)Ð)r   c                ó  — | j         dk    rbg }| }t          t          t          t          t          t          g}|D ]3} ||¦  «        }|rt          |¦  «        }|                     |¦  «         Œ4|S |du rt          d¦  «        ‚dS )at  
    completeHexatonic returns the list of six triads generated by the operation PLPLPL.
    This six-part operation cycles between major and minor triads, ultimately returning to the
    input triad (or its enharmonic equivalent).
    This functions returns those six triads, ending with the original triad.

    `simplifyEnharmonics` is False, by default, giving double flats at the end.

    >>> c1 = chord.Chord('C4 E4 G4')
    >>> analysis.neoRiemannian.completeHexatonic(c1)
    [<music21.chord.Chord C4 E-4 G4>,
     <music21.chord.Chord C4 E-4 A-4>,
     <music21.chord.Chord C-4 E-4 A-4>,
     <music21.chord.Chord C-4 F-4 A-4>,
     <music21.chord.Chord C-4 F-4 A--4>,
     <music21.chord.Chord D--4 F-4 A--4>]

    `simplifyEnharmonics` can be set to True in order to avoid this.

    >>> c2 = chord.Chord('C4 E4 G4')
    >>> analysis.neoRiemannian.completeHexatonic(c2, simplifyEnharmonics=True)
    [<music21.chord.Chord C4 E-4 G4>,
     <music21.chord.Chord C4 E-4 A-4>,
     <music21.chord.Chord B3 D#4 G#4>,
     <music21.chord.Chord B3 E4 G#4>,
     <music21.chord.Chord B3 E4 G4>,
     <music21.chord.Chord C4 E4 G4>]
    z3-11TzHCannot perform transformations on this chord: not a major or minor triadN)ÚforteClassTnIr3   r/   r!   r\   r	   )r   r_   r+   ÚhexatonicListÚ	lastChordÚ
operationsÚ	operations          r   ÚcompleteHexatonicri   Ž  s¨   € ð: 	„˜&Ò Ð ØˆØˆ	Ý��A�q¥!¥QÐ'ˆ
Ø#ð 	,ð 	,ˆIØ!˜	 )Ñ,Ô,ˆIØ"ð ;Ý/°	Ñ:Ô:�	Ø× Ò  Ñ+Ô+Ð+Ð+ØÐà˜TÐ!Ð!ÝØZñ\ô \ð \ð "Ð!r   c                ó¢   — |                       ¦   «         }|j        }h d£dfh d£dfh d£dfh d£dfg}|D ]\  }}||v r|c S Œt          d	¦  «        ‚)
a@  
        Returns a lowercase string representing the
        "hexatonic system" that the chord `c` belongs to
        as classified by Richard Cohn, "Maximally Smooth Cycles,
        Hexatonic Systems, and the Analysis of Late-Romantic
        Triadic Progressions," *Music Analysis*, 15.1 (1996), 9-40,
        at p. 17.  Possible values are 'northern', 'western', 'eastern', or 'southern'

        >>> cMaj = chord.Chord('C E G')
        >>> analysis.neoRiemannian.hexatonicSystem(cMaj)
        'northern'

        >>> gMin = chord.Chord('G B- D')
        >>> analysis.neoRiemannian.hexatonicSystem(gMin)
        'western'

        Each chord in the :func:`~music21.analysis.neoRiemannian.completeHexatonic` of that chord
        is in the same hexatonic system, by definition or tautology.

        >>> for ch in analysis.neoRiemannian.completeHexatonic(cMaj):
        ...     print(analysis.neoRiemannian.hexatonicSystem(ch))
        northern
        northern
        northern
        northern
        northern
        northern

        Note that the classification looks only at the
        pitch class of the root of the chord.  Seventh chords,
        diminished triads, etc. will also be classified.

        >>> dDom65 = chord.Chord('F#4 D5 A5 C6')
        >>> analysis.neoRiemannian.hexatonicSystem(dDom65)
        'southern'
        >   r   é   é   Únorthern>   é   é   é	   Úeastern>   é   é   é
   Úsouthern>   é   é   é   Úwesternz'Odd pitch class that is not in 0 to 11!)r%   Ú
pitchClassr	   )r   r%   ÚrootPCÚmappingsÚpcSetÚpoleNames         r   ÚhexatonicSystemr   º  s�   € ðL �6Š6‰8Œ8€DØŒ_€Fà��˜JÐ'Ø��˜IÐ&Ø��˜ZÐ(Ø��˜YÐ'ð€Hð
 $ð ð ‰ˆˆxØ�Uˆ?ˆ?ØˆOˆOˆOð õ Ð@Ñ
AÔ
AÐAr   rL   c                ó*  — g d¢}||vrt          d|› �¦  «        ‚d}|dk    rd}n|dk    rd}n|dk    rd	}|                      ¦   «         rd
}n&|                      ¦   «         rd}nt          d¦  «        ‚t          | ||¬¦  «        } t	          | ¦  «        S )a3  
    Transforms a chord into the given chromatic mediant. Options:
    UFM = Upper Flat Mediant;
    USM = Upper Sharp Mediant;
    LFM = Lower Flat Mediant ;
    LSM = Lower Sharp Mediant;

    Each of these transformations
    is mode-preserving;
    involves root motion by a third;
    entails exactly one common-tone.

    >>> cMaj = chord.Chord('C5 E5 G5')
    >>> UFMcMaj = analysis.neoRiemannian.chromaticMediants(cMaj, transformation='UFM')
    >>> UFMcMaj.normalOrder
    [3, 7, 10]

    >>> USMcMaj = analysis.neoRiemannian.chromaticMediants(cMaj, transformation='USM')
    >>> USMcMaj.normalOrder
    [4, 8, 11]

    >>> LFMcMaj = analysis.neoRiemannian.chromaticMediants(cMaj, transformation='LFM')
    >>> [x.nameWithOctave for x in LFMcMaj.pitches]
    ['C5', 'E-5', 'A-5']

    >>> LSMcMaj = analysis.neoRiemannian.chromaticMediants(cMaj, transformation='LSM')
    >>> [x.nameWithOctave for x in LSMcMaj.pitches]
    ['C#5', 'E5', 'A5']

    Fine to call on a chord with multiple enharmonics,
    but will always simplify the output chromatic mediant.

    >>> cMajEnh = chord.Chord('D--5 F-5 A--5')
    >>> USM = analysis.neoRiemannian.chromaticMediants(cMaj, transformation='USM')
    >>> [x.nameWithOctave for x in USM.pitches]
    ['B4', 'E5', 'G#5']
    >>> USM.normalOrder == USMcMaj.normalOrder
    True
    rK   zTransformation must be one of ÚPRrM   ÚLPrN   ÚPLrO   ÚRPTFúChord must be major or minor©r^   )Ú
ValueErrorr&   r$   rb   r!   )r   rQ   Úoptionsr]   ÚLOs        r   rR   rR   ó  sÕ   € ðR +Ð*Ð*€GØ˜WÐ$Ð$ÝÐC¸'ÐCÐCÑDÔDÐDàÐØ˜ÒÐØ#ÐÐØ	˜5Ò	 Ð	 Ø#ÐÐØ	˜5Ò	 Ð	 Ø#Ðà‡~‚~ÑÔð 9ØˆˆØ	
�ŠÑ	Ô	ð 9ØˆˆåÐ7Ñ8Ô8Ð8å˜Ð0¸bÐAÑAÔA€Aå˜qÑ!Ô!Ð!r   Úupperc                ó
  — ddg}||vrt          d|› �¦  «        ‚d}|                      ¦   «         r	|dk    rd}n,|                      ¦   «         r	|dk    rd}nt          d¦  «        ‚t          | |¦  «        } t	          | ¦  «        S )aý  
    Transforms a chord into the upper or lower disjunct mediant.
    These transformations involve:
    root motion by a non-diatonic third;
    mode-change;
    no common-tones.

    >>> cMaj = chord.Chord('C5 E5 G5')
    >>> upr = analysis.neoRiemannian.disjunctMediants(cMaj, upperOrLower='upper')
    >>> [x.name for x in upr.pitches]
    ['B-', 'E-', 'G-']
    >>> lwr = analysis.neoRiemannian.disjunctMediants(cMaj, upperOrLower='lower')
    >>> [x.name for x in lwr.pitches]
    ['B', 'D#', 'G#']
    rŠ   ÚlowerzupperOrLower must be one of ÚPRPÚPLPr…   )r‡   r$   r&   rb   r!   )r   ÚupperOrLowerrˆ   r]   s       r   ÚdisjunctMediantsr�   3  s«   € ð" ˜Ð €GØ˜7Ð"Ð"ÝÐA¸ÐAÐAÑBÔBÐBà Ðà‡~‚~ÑÔð 9Ø˜7Ò"Ð"Ø#(Ð øØ	
�ŠÑ	Ô	ð 9Ø˜7Ò"Ð"Ø#(Ð øåÐ7Ñ8Ô8Ð8å˜Ð0Ñ1Ô1€Aå˜qÑ!Ô!Ð!r   c                ó&   — t          | dd¬¦  «        S )aI  
    Slide transform connecting major and minor triads with the third as the single common tone
    (i.e. with the major triad root a semi-tone below the minor). So:
    root motion by a semi-tone;
    mode-change;
    one common-tones.
    Slide is equivalent to 'LPR'.

    >>> cMaj = chord.Chord('C5 E5 G5')
    >>> slideUp = analysis.neoRiemannian.S(cMaj)
    >>> [x.name for x in slideUp.pitches]
    ['C#', 'E', 'G#']

    >>> aMin = chord.Chord('A4 C5 E5')
    >>> slideDown = analysis.neoRiemannian.S(aMin)
    >>> [x.name for x in slideDown.pitches]
    ['A-', 'C', 'E-']
    ÚLPRF©r_   ©rb   ©r   s    r   ÚSr–   W  s   € õ( ˜A˜u¸%Ð@Ñ@Ô@Ð@r   c                ó&   — t          | dd¬¦  «        S )a  
    The 'Neberverwandt' ('fifth-change') transform connects
    a minor triad with its major dominant, and so also
    a major triad with its minor sub-dominant,
    with one common tone in each case.
    This is equivalent to 'RLP'.

    >>> cMaj = chord.Chord('C5 E5 G5')
    >>> n1 = analysis.neoRiemannian.N(cMaj)
    >>> [x.name for x in n1.pitches]
    ['C', 'F', 'A-']

    >>> aMin = chord.Chord('A4 C5 E5')
    >>> n2 = analysis.neoRiemannian.N(aMin)
    >>> [x.name for x in n2.pitches]
    ['G#', 'B', 'E']
    ÚRLPFr“   r”   r•   s    r   ÚNr™   m  s   € õ& ˜A˜u¸%Ð@Ñ@Ô@Ð@r   c                  ó2   — e Zd Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚTestc                ó¬  — t          j        d¦  «        }t          |¦  «        }t          |¦  «        }|                      t          |¦  «        d¦  «         |                      |t           j        ¦  «         |                      t          |¦  «        d¦  «         t          j        d¦  «        }t          j        |¦  «        }t          d¦  «        D ]}t          |¦  «        }Œ|                      |j
        |j
        ¦  «         t          j        d¦  «        }t          j        |¦  «        }t          d¦  «        D ]}t          |¦  «        }Œ|                      |j
        |j
        ¦  «         t          j        d¦  «        }t          j        |¦  «        }t          d¦  «        D ]}t          |¦  «        }Œ|                      |j
        |j
        ¦  «         d S )Nú	C4 E-4 G4z <music21.chord.Chord C4 E-4 A-4>z<music21.chord.Chord C4 E4 G4>zC4 E4 G4 C5 C5 G5rk   zC4 E4 G4 C5 E5 G5)r   r>   r/   r3   ÚassertEqualÚstrÚassertIsInstancer   r   r9   r   r6   )ÚselfrF   Úc2_LÚc2_PÚc5ÚcopyC5r@   s          r   Ú testNeoRiemannianTransformationsz%Test.testNeoRiemannianTransformations†  s�  € ÝŒ[˜Ñ%Ô%ˆÝ�‰uŒuˆÝ�‰uŒuˆØ×Ò�˜T™œÐ$FÑGÔGÐGØ×Ò˜d¥E¤KÑ0Ô0Ð0Ø×Ò�˜T™œÐ$DÑEÔEÐEåŒ[Ð,Ñ-Ô-ˆÝ”˜rÑ"Ô"ˆÝ�q‘”ð 	ð 	ˆAÝ�2‘”ˆBˆBØ×Ò˜œ¨¬Ñ4Ô4Ð4åŒ[Ð,Ñ-Ô-ˆÝ”˜rÑ"Ô"ˆÝ�q‘”ð 	ð 	ˆAÝ�2‘”ˆBˆBØ×Ò˜œ¨¬Ñ4Ô4Ð4åŒ[Ð,Ñ-Ô-ˆÝ”˜rÑ"Ô"ˆÝ�q‘”ð 	ð 	ˆAÝ�2‘”ˆBˆBØ×Ò˜œ¨¬Ñ4Ô4Ð4Ð4Ð4r   c                ó¢  — t          j        d¦  «        }t          |d¦  «        }|                      t	          |¦  «        d¦  «         t          j        d¦  «        }t          |d¦  «        }|                      t	          |¦  «        d¦  «         t          j        d¦  «        }t          |dd¬¦  «        }|                      t	          |¦  «        d	¦  «         t          j        d
¦  «        }t          |d¦  «        }|                      t	          |¦  «        d¦  «         t          j        d¦  «        }	t          |	dd¬¦  «        }
|                      |	|
¦  «         |                      t          ¦  «        5  t          |	dd¬¦  «         d d d ¦  «         n# 1 swxY w Y   t          j        d¦  «        }|                      t          ¦  «        5  t          |dd¬¦  «         d d d ¦  «         n# 1 swxY w Y   t          j        d¦  «        }t          |dd¬¦  «        }|                      t          j        d¦  «        j        |j        ¦  «         d S )NúC4 E4 G4r‚   z<music21.chord.Chord B3 E4 G#4>zC4 E4 G4 C5 E5r˜   z%<music21.chord.Chord C4 F4 A-4 C5 F5>Tr†   z'<music21.chord.Chord C4 E-4 A-4 C5 E-5>úC-4 E-4 G-4z <music21.chord.Chord B-3 E-4 G4>zB- D# F#F)r+   zB# F G#úB# E# G#zC# E G#)	r   r>   rb   rž   rŸ   ÚassertIsÚassertRaisesr	   r   )r¡   r¤   Úc5_TÚc6Úc6_TÚc7Úc7_TÚc8Úc8_TÚd_sharp_min_misspelledÚd_sharp_min_transformedÚf_min_misspelledÚe_sharp_minÚe_sharp_min_transformeds                 r   ÚtestNeoRiemannianCombinationsz"Test.testNeoRiemannianCombinations   sÁ  € ÝŒ[˜Ñ$Ô$ˆÝ  DÑ)Ô)ˆØ×Ò�˜T™œÐ$EÑFÔFÐFåŒ[Ð)Ñ*Ô*ˆÝ  EÑ*Ô*ˆØ×Ò�˜T™œÐ$KÑLÔLÐLåŒ[Ð)Ñ*Ô*ˆÝ  D°dÐ;Ñ;Ô;ˆØ×Ò�˜T™œÐ$MÑNÔNÐNåŒ[˜Ñ'Ô'ˆÝ  DÑ)Ô)ˆØ×Ò�˜T™œÐ$FÑGÔGÐGå!&¤¨ZÑ!8Ô!8ÐÝ"2Ð3IÈ4ØBGð#Iñ #Iô #IÐà�ŠÐ,Ð.EÑFÔFÐFØ×Ò�|Ñ,Ô,ð 	Pð 	PÝÐ3°TÈ$ÐOÑOÔOÐOð	Pð 	Pð 	Pñ 	Pô 	Pð 	Pð 	Pð 	Pð 	Pð 	Pð 	Pøøøð 	Pð 	Pð 	Pð 	Põ !œ; yÑ1Ô1ÐØ×Ò�|Ñ,Ô,ð 	Jð 	JÝÐ-¨tÀDÐIÑIÔIÐIð	Jð 	Jð 	Jñ 	Jô 	Jð 	Jð 	Jð 	Jð 	Jð 	Jð 	Jøøøð 	Jð 	Jð 	Jð 	Jõ ”k *Ñ-Ô-ˆÝ"2°;ÀÐUYÐ"ZÑ"ZÔ"ZÐØ×Ò�œ YÑ/Ô/Ô7Ð9PÔ9XÑYÔYÐYÐYÐYs$   Å5FÆFÆFÇG,Ç,G0Ç3G0c                óî  — t          j        d¦  «        }t          j        d¦  «        }t          ||¦  «        }|                      |d¦  «         t          j        d¦  «        }t          ||¦  «        }|                      |d¦  «         t          ||d¬¦  «        }|                      |¦  «         t          j        d¦  «        }t          ||¦  «        }|                      |d	¦  «         t          j        d
¦  «        }t          ||¦  «        }	|                      |	d¦  «         t          j        d¦  «        }
t          ||
¦  «        }t          ||
¦  «        }|                      |¦  «         |                      |¦  «         t          j        d¦  «        }t          j        d¦  «        }t          ||¦  «        }t          ||¦  «        }|                      |¦  «         |                      |d¦  «         d S )Nr¨   zB3 E4 G4r/   r�   r3   ÚLR)rG   zC4 E4 A4r6   z
C4 E-4 A-4rN   zC-4 E-4 A-4r©   zC-4 E--4 A--4)r   r>   rI   rž   ÚassertFalserV   )r¡   rE   rF   Úans1Úc3Úans2Úc4Úans3r¤   Úans4r®   Úans5Úans6r°   r²   Úans7Úans8s                    r   Ú
testIsNeoRzTest.testIsNeoRÀ  sÀ  € åŒ[˜Ñ$Ô$ˆåŒ[˜Ñ$Ô$ˆÝ�b˜"‰~Œ~ˆØ×Ò˜˜sÑ#Ô#Ð#åŒ[˜Ñ%Ô%ˆÝ�b˜"‰~Œ~ˆØ×Ò˜˜sÑ#Ô#Ð#å�b˜"¨Ð.Ñ.Ô.ˆØ×Ò˜ÑÔÐåŒ[˜Ñ$Ô$ˆÝ�b˜"‰~Œ~ˆØ×Ò˜˜sÑ#Ô#Ð#åŒ[˜Ñ&Ô&ˆÝ! " bÑ)Ô)ˆØ×Ò˜˜uÑ%Ô%Ð%åŒ[˜Ñ'Ô'ˆÝ�b˜"‰~Œ~ˆÝ! " bÑ)Ô)ˆØ×Ò˜ÑÔÐØ×Ò˜ÑÔÐåŒ[˜Ñ'Ô'ˆÝŒ[˜Ñ)Ô)ˆÝ�b˜"‰~Œ~ˆÝ! " bÑ)Ô)ˆØ×Ò˜ÑÔÐØ×Ò˜˜uÑ%Ô%Ð%Ð%Ð%r   c                óÎ  — t          j        d¦  «        }t          j        d¦  «        }t          |d¬¦  «        }|                      |j        g d¢¦  «         t          |d¬¦  «        }|                      |j        g d¢¦  «         t          |d¬¦  «        }|                      d	„ |j        D ¦   «         g d
¢¦  «         t          |d¬¦  «        }|                      d„ |j        D ¦   «         g d¢¦  «         t          |d¬¦  «        }|                      d„ |j        D ¦   «         g d¢¦  «         t          |d¬¦  «        }|                      d„ |j        D ¦   «         g d¢¦  «         d S )NúC5 E5 G5zC#5 E#5 G#5rL   rP   )rv   rw   rt   rM   )rk   rl   rx   rN   c                ó   — g | ]	}|j         ‘Œ
S r   r   rZ   s     r   r   z%Test.testMediants.<locals>.<listcomp>ð  ó   € ÐDÐDÐD¨q˜!Ô*ÐDÐDÐDr   )ÚC5zE-5zA-5rO   c                ó   — g | ]	}|j         ‘Œ
S r   r   rZ   s     r   r   z%Test.testMediants.<locals>.<listcomp>ó  rË   r   )zC#5ÚE5ÚA5rŠ   )r�   c                ó   — g | ]	}|j         ‘Œ
S r   ©r<   rZ   s     r   r   z%Test.testMediants.<locals>.<listcomp>ö  s   € Ð>Ð>Ð> Q˜!œ&Ð>Ð>Ð>r   )ÚBÚEÚGrŒ   c                ó   — g | ]	}|j         ‘Œ
S r   r   rZ   s     r   r   z%Test.testMediants.<locals>.<listcomp>ù  s   € ÐJÐJÐJ¨q˜!Ô*ÐJÐJÐJr   )rÌ   rÎ   rÏ   )r   r>   rR   rž   rD   r   r�   )	r¡   Úc9Úc9aÚUFMcMajÚUSMcMajÚLFMcMajÚLSMcMajÚupChromaticÚdownChromatics	            r   ÚtestMediantszTest.testMediantsä  s�  € åŒ[˜Ñ$Ô$ˆÝŒk˜-Ñ(Ô(ˆå# B°uÐ=Ñ=Ô=ˆØ×Ò˜Ô,¨j¨j¨jÑ9Ô9Ð9å# B°uÐ=Ñ=Ô=ˆØ×Ò˜Ô,¨j¨j¨jÑ9Ô9Ð9å# B°uÐ=Ñ=Ô=ˆØ×ÒÐDÐD°G´OÐDÑDÔDÐFZÐFZÐFZÑ[Ô[Ð[å# B°uÐ=Ñ=Ô=ˆØ×ÒÐDÐD°G´OÐDÑDÔDÐFYÐFYÐFYÑZÔZÐZå& s¸ÐAÑAÔAˆØ×ÒÐ>Ð>¨+Ô*=Ð>Ñ>Ô>ÀÀÀÑPÔPÐPå(¨¸7ÐCÑCÔCˆØ×ÒÐJÐJ°MÔ4IÐJÑJÔJØ+Ð+Ð+ñ	-ô 	-ð 	-ð 	-ð 	-r   c                ó  — t          j        d¦  «        }t          j        d¦  «        }t          |¦  «        }|                      d„ |j        D ¦   «         g d¢¦  «         t          |¦  «        }|                      d„ |j        D ¦   «         g d¢¦  «         t          |¦  «        }|                      d„ |j        D ¦   «         g d¢¦  «         t          |¦  «        }|                      d	„ |j        D ¦   «         g d
¢¦  «         d S )NrÉ   zA4 C5 E5c                ó   — g | ]	}|j         ‘Œ
S r   rÑ   rZ   s     r   r   z Test.testSnN.<locals>.<listcomp>  s   € Ð:Ð:Ð: Q˜!œ&Ð:Ð:Ð:r   )zC#rÓ   úG#c                ó   — g | ]	}|j         ‘Œ
S r   rÑ   rZ   s     r   r   z Test.testSnN.<locals>.<listcomp>  s   € Ð<Ð<Ð< Q˜!œ&Ð<Ð<Ð<r   )úA-ÚCzE-c                ó   — g | ]	}|j         ‘Œ
S r   rÑ   rZ   s     r   r   z Test.testSnN.<locals>.<listcomp>  ó   € Ð5Ð5Ð5 Q˜!œ&Ð5Ð5Ð5r   )rä   ÚFrã   c                ó   — g | ]	}|j         ‘Œ
S r   rÑ   rZ   s     r   r   z Test.testSnN.<locals>.<listcomp>  ræ   r   )rá   rÒ   rÓ   )r   r>   r–   rž   r   r™   )r¡   Úc10Úc11ÚslideUpÚ	slideDownÚN1ÚN2s          r   ÚtestSnNzTest.testSnNü  s  € åŒk˜*Ñ%Ô%ˆÝŒk˜*Ñ%Ô%ˆå�C‘&”&ˆØ×ÒÐ:Ð:¨'¬/Ð:Ñ:Ô:Ð<MÐ<MÐ<MÑNÔNÐNå�c‘F”Fˆ	Ø×ÒÐ<Ð<¨)Ô*;Ð<Ñ<Ô<Ð>OÐ>OÐ>OÑPÔPÐPåˆs‰VŒVˆØ×ÒÐ5Ð5¨"¬*Ð5Ñ5Ô5Ð7GÐ7GÐ7GÑHÔHÐHåˆs‰VŒVˆØ×ÒÐ5Ð5¨"¬*Ð5Ñ5Ô5Ð7GÐ7GÐ7GÑHÔHÐHÐHÐHr   c                ó  — t          t          j        d¦  «        ¦  «        }t          t          j        g d¢¦  «        ¦  «        }|                      |j        |j        ¦  «         |                      |j        t          j        d¦  «        j        ¦  «         t          j        d¦  «        }t          |dd¬¦  «        }t          j        g d¢¦  «        }t          |dd¬¦  «        }|                      |j        d	         j        ¦  «         |j        D ]}|                      |j        ¦  «         Œ|                      |j        |j        ¦  «         |                      |j        t          j        d
¦  «        j        ¦  «         d S )NzC# E# G#)rn   ro   rl   rª   zB D# F#r‚   Fr“   )rx   rv   rs   r   z	A# D# F##)	r/   r   r>   rž   r   rb   Ú
assertTruer;   r¼   )r¡   Úc_sharp_maj_named_transformedÚ%c_sharp_maj_pitch_classes_transformedÚb_maj_namedÚb_maj_named_transformedÚb_maj_pitch_classesÚb_maj_pitch_classes_transformedr   s           r   ÚtestInstantiatingChordPCNumbersz$Test.testInstantiatingChordPCNumbers  s™  € å()­%¬+°jÑ*AÔ*AÑ(BÔ(BÐ%Ý01µ%´+¸i¸i¸iÑ2HÔ2HÑ0IÔ0IÐ-Ø×ÒÐ6Ô>Ø>ÔFñ	Hô 	Hð 	Hà×ÒÐ>ÔFÝœ ZÑ0Ô0Ô8ñ	:ô 	:ð 	:õ ”k )Ñ,Ô,ˆÝ"2°;ÀØGLð#Nñ #Nô #NÐå#œk¨*¨*¨*Ñ5Ô5ÐÝ*:Ð;NÐPTØOTð+Vñ +Vô +VÐ'à�ŠÐ+Ô3°AÔ6ÔIÑJÔJÐJØ0Ô8ð 	3ð 	3ˆAØ×Ò˜QÔ1Ñ2Ô2Ð2Ð2à×ÒÐ0Ô8Ø8Ô@ñ	Bô 	Bð 	Bà×ÒÐ8Ô@Ýœ [Ñ1Ô1Ô9ñ	;ô 	;ð 	;ð 	;ð 	;r   N)	r
   r   r   r¦   r¹   rÇ   rÞ   rï   rø   r   r   r   r›   r›   „  sv   € € € € € ð5ð 5ð 5ð4Zð Zð Zð@"&ð "&ð "&ðH-ð -ð -ð0Ið Ið Ið";ð ;ð ;ð ;ð ;r   r›   Ú__main__)T)rA   )TFFF)FT)rL   )rŠ   )"Ú__doc__Ú
__future__r   r   ÚunittestÚmusic21r   r   Úmusic21.analysisr   r   ÚEnvironmentÚenvironLocalÚMusic21Exceptionr	   r!   r/   r3   r6   r(   rI   rV   rb   ri   r   rR   r�   r–   r™   ÚTestCaser›   Ú
_DOC_ORDERr
   ÚmainTestr   r   r   ú<module>r     sv  ððð ð
 #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€à  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð à&ˆ{Ô&Ð'?Ñ@Ô@€ð
	ð 	ð 	ð 	ð 	�<Ô0ñ 	ô 	ð 	ðð ð ð2/ð /ð /ð /ðb#ð #ð #ð #ðJ#ð #ð #ð #ðJ)ð )ð )ð8ð 8ð 8ð 8ðtð ð ð@ %)Ø!&Ø).Ø"ðn*ð n*ð n*ð n*ð`*\ð *\ð *\ð *\ðX2Bð 2Bð 2Bðr>"ð >"ð >"ð >"ð@""ð ""ð ""ð ""ðHAð Að Að,Að Að Að._;ð _;ð _;ð _;ð _;ˆ8Ôñ _;ô _;ð _;ðH €qˆ!ˆQ��6ØÐ'¨¸,ØÐ)Øð	€
ð ˆzÒÐØ€N€N€NØ€GÔ�TÑÔÐÐÐð Ðr   