
    rh                      S r SSKJr  / SQrSSKJrJr  SSKrSSKr	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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  \	R<                  (       a  SSKJr  SSK J!r!  \RD                  " S5      r#\	RH                  " SSS9r%\	RH                  " SSS9r& " S S\RN                  5      r( " S S \RR                  5      r* " S! S"\*5      r+S(S# jr,S)S$ jr- " S% S&\R\                  5      r/\+/r0\1S':X  a  SSKr\Rd                  " \/5        gg)*z
This module defines the Chord object, a subclass of :class:`~music21.note.GeneralNote`
as well as other methods, functions, and objects related to chords.
    )annotations)toolstablesChordChordExceptionfromIntervalVectorfromForteClass)IterableSequenceN)overload)beam)common)cacheMethod)
derivation)Duration)environment)exceptions21)interval)notepitch)tie)volume)r   )r   )stream)Stylechord_ChordBaseTypezmusic21.chord.ChordBase)bound
_ChordTypezmusic21.chord.Chordc                      \ rS rSrSrg)r   5    N)__name__
__module____qualname____firstlineno____static_attributes__r"       P/home/james-whalen/.local/lib/python3.13/site-packages/music21/chord/__init__.pyr   r   5   s    r(   r   c                    ^  \ rS rSr% SrSrSrSSSS.rS\S	'   \R                  \
R                  R                  5         S SU 4S jjjrU 4S jrU 4S jrSSU 4S jjjrS rS rS
S. S S jjr  S!S jrS r\S"S j5       r\S#S j5       r\R0                  S$S j5       r\S%S j5       r\R0                  S&S j5       rS'S jrS(S jrSrU =r$ ))	ChordBase:   a  
A base class for NotRest objects that have multiple underlying structures
like notes or unpitched percussion.

As of Version 7, ChordBase lies between Chord and NotRest in the music21
hierarchy, so that features can be shared with PercussionChord.

>>> cb = chord.ChordBase('C4 E4 G4')
>>> cb.notes
(<music21.note.Note C>, <music21.note.Note E>, <music21.note.Note G>)


**Equality**

Equality on ChordBase is strange, but necessary to help Chord and PercussionChord
do meaningful equality checks themselves.

Two ChordBase objects are equal if they pass all `super()`
equality tests and the **number** of stored Notes are the same.

>>> cb1 = chord.ChordBase('C4 E4 G4')
>>> cb2 = chord.ChordBase('C4 E4')
>>> cb1 == cb2
False

This is surprising, but it's necessary to make checking equality
of Chord objects and PercussionChord objects themselves easier.

>>> cb3 = chord.ChordBase('A#4 A#4 A#4')
>>> cb1 == cb3
True
Fzj
            Boolean read-only value describing if this
            GeneralNote object is a Note. Is Falsez
            Boolean read-only value describing if this
            GeneralNote object is a Rest. Is False

            >>> c = chord.Chord()
            >>> c.isRest
            False
            z%A :class:`music21.beam.Beams` object.)isNoteisRestbeamsdict[str, str]	_DOC_ATTRNc                4  >^ Uc  / n[        U[        5      (       a  SU;   a  UR                  5       nOU/n0 U l        / U l        [
        TU ]  " S0 TD6  [        U4S jS 5       5      (       d  U R                  US S9  g U R                  XR                  S9  g )N c              3  ,   >#    U  H	  oT;   v   M     g 7fNr"   ).0kkeywordss     r)   	<genexpr>%ChordBase.__init__.<locals>.<genexpr>   s     P*OQ=*Os   )durationtypequarterLengthuseDurationr"   )

isinstancestrsplit
_overrides_notessuper__init__any_add_core_or_initr;   selfnotesr8   	__class__s     `r)   rF   ChordBase.__init__p   s     =EeS!!e|
 -/*, 	$8$ P*OPPP""5d";""5mm"Dr(   c                   > [         TU ]  U5      (       d  g[        U R                  5      [        UR                  5      :w  a  ggNFT)rE   __eq__lenrK   rJ   otherrL   s     r)   rP   ChordBase.__eq__   s4    w~e$$tzz?c%++..r(   c                    > [         TU ]  5       $ r5   rE   __hash__rJ   rL   s    r)   rW   ChordBase.__hash__       w!!r(   c                   > [         TU ]  US9nUR                   H0  nX#l        UR	                  5       (       d  M   X#R
                  l        M2     U$ )z
As Chord objects have one or more Volume, objects, and Volume
objects store weak refs to the client object, need to specialize
deepcopy handling depending on if the chord has its own volume object.
)memo)rE   __deepcopy__rD   _chordAttachedhasVolumeInformationr   client)rJ   r\   newnrL   s       r)   r]   ChordBase.__deepcopy__   sL     g""- A"%%''"%	 
 
r(   c                ,    [        U R                  5      $ r5   )iterrD   rJ   s    r)   __iter__ChordBase.__iter__   s    DKK  r(   c                ,    [        U R                  5      $ )zb
Return the length of components in the chord.

>>> c = chord.Chord(['c', 'e', 'g'])
>>> len(c)
3
)rQ   rD   rf   s    r)   __len__ChordBase.__len__   s     4;;r(   r>   c                  SnUc  U R                   nSnU GH  n[        U[        R                  5      (       aO  U(       a  [        R
                  " XBS9nO[        R
                  " U5      nU R                  R                  U5        Mr  [        U[        5      (       ab  UR                   H2  nU R                  R                  [        R                  " U5      5        M4     U(       a  UR                   U l         SnSnM  M  [        U[        R                  5      (       a=  U R                  R                  U5        U(       a  UR                   U l         SnSnGMB  GME  [        U[        [        45      (       ai  U(       a0  U R                  R                  [        R
                  " XBS95        GM  U R                  R                  [        R
                  " U5      5        GM  [        SU 35      e   U R                   H	  nXl        M     U$ )a  
This is the private append method called by .add and called by __init__.

It differs from the public method in that a duration object can
be passed in which is used for the first note of the chord or as many pitches
as can use it -- it's all an optimization step to create as few duration objects
as is necessary.

Does not clear any caches.

Also requires that notes be iterable.

Changed in v9: incorrect arguments raise TypeError
FNT)r;   z!Could not process input argument )r;   r@   r   Pitchr   NoterD   appendr+   copydeepcopyNotRestrA   int	TypeErrorr^   )rJ   rK   r?   quickDurationrb   newNotes         r)   rH   ChordBase._add_core_or_init   s}   ( --K M A!U[[))"ii@G"iilG""7+Ay)) xxGKK&&t}}W'=>  ( $%JJDM"&K$)M ! At||,,""1% $%JJDM"&K$)M ! ASz**KK&&tyy'IJKK&&tyy|4  "CA3 GHH; > A#  r(   c                    [         R                  " U5      (       d  U/nU R                  USS9  U R                  5         g)a1  
Add a Note, Pitch, the `.notes` of another chord,
or string representing a Pitch,
or a list of any-of-the-above types to a Chord or PercussionChord.

Does no sorting.  That is on the Chord object.

>>> c = chord.Chord('C4 E4 G4')
>>> c.add('B3')
>>> c
<music21.chord.Chord B3 C4 E4 G4>
>>> c.duration
<music21.duration.Duration 1.0>

>>> c.add('A2', runSort=False)
>>> c
<music21.chord.Chord B3 C4 E4 G4 A2>

>>> c.add(['B5', 'C6'])
>>> c
<music21.chord.Chord A2 B3 C4 E4 G4 B5 C6>

>>> c.add(pitch.Pitch('D6'))
>>> c
<music21.chord.Chord A2 B3 C4 E4 G4 B5 C6 D6>

>>> n = note.Note('E6')
>>> n.duration.type = 'half'
>>> c.add(n)
>>> c
<music21.chord.Chord A2 B3 C4 E4 G4 B5 C6 D6 E6>
>>> c.duration
<music21.duration.Duration 1.0>
>>> c[-1]
<music21.note.Note E>
>>> c[-1].duration
<music21.duration.Duration 2.0>
Fr>   N)r   
isIterablerH   
clearCache)rJ   rK   s     r)   addChordBase.add  s:    T   ''GEu%8r(   c                   [        U[        5      (       ax  U R                   H]  n[        US5      (       d  M  UR                  R
                  U:X  d  M2  U R                  R                  U5        U R                  5           g   [        S5      e[        U[        R                  5      (       an  U R                   HS  n[        US5      (       d  M  UR                  U:X  d  M(  U R                  R                  U5        U R                  5           g   [        S5      e[        U[        R                  5      (       d  [        SU S35      e U R                  R                  U5        U R                  5         g! [         a    [        S5      ef = f)a-  
Removes a note or pitch from the chord.  Must be a pitch
equal to a pitch in the chord or a string specifying the pitch
name with octave or a note from a chord.  If not found,
raises a ValueError

>>> c = chord.Chord('C4 E4 G4')
>>> c.remove('E4')
>>> c
<music21.chord.Chord C4 G4>
>>> c.remove('D5')
Traceback (most recent call last):
ValueError: Chord.remove(x), x not in chord

>>> c = chord.Chord('C4 E4 G4')
>>> c.remove(pitch.Pitch('E4'))
>>> c
<music21.chord.Chord C4 G4>
>>> c.remove(pitch.Pitch('F#5'))
Traceback (most recent call last):
ValueError: Chord.remove(x), x not in chord


The Note also does not need to be the exact note of the
chord, just matches on equality

>>> c = chord.Chord('C4 E4 G4')
>>> c.remove(note.Note('E4'))
>>> c
<music21.chord.Chord C4 G4>

>>> c.remove(c[1])
>>> c
<music21.chord.Chord C4>

>>> c.remove(note.Note('B-2'))
Traceback (most recent call last):
ValueError: Chord.remove(x), x not in chord

>>> c.remove(4)
Traceback (most recent call last):
ValueError: Cannot remove 4 from a chord; try a Pitch or Note object

Like Python's list object, the remove method of chord does not take a list of strings.

>>> c = chord.Chord('C4 E4 G4')
>>> c.remove(['C4', 'E4'])
Traceback (most recent call last):
ValueError: Cannot remove ['C4', 'E4'] from a chord; try a Pitch or Note object
r   NzChord.remove(x), x not in chordzCannot remove z) from a chord; try a Pitch or Note object)r@   rA   rD   hasattrr   nameWithOctaveremoverz   
ValueErrorrm   r   rr   )rJ   
removeItemrb   s      r)   r   ChordBase.remove0  s=   f j#&&[[q'**77))Z7KK&&q)OO% ! >??j%++..[[1g&&177j+@KK&&q)OO%	 !
 >??*dll33 ,UV 	@KKz*OO 	@>??	@s   
+E6 6Fc                ,    [        U R                  5      $ r5   tuplerD   rf   s    r)   rK   ChordBase.notes  s    T[[!!r(   c                `    U R                    H  nUR                  c  M  UR                  s  $    g)ak  
Get or set a single tie based on all the ties in this Chord.

This overloads the behavior of the tie attribute found in all
NotRest classes.

If setting a tie, tie is applied to all pitches.

>>> c1 = chord.Chord(['c4', 'g4'])
>>> tie1 = tie.Tie('start')
>>> c1.tie = tie1
>>> c1.tie
<music21.tie.Tie start>

>>> c1.getTie(c1.pitches[1])
<music21.tie.Tie start>
NrD   r   rJ   ds     r)   r   ChordBase.tie  s*    & Auu uu  r(   c                6    U R                    H	  nXl        M     g r5   r   )rJ   valuer   s      r)   r   r     s    AE r(   c                (   [        U R                  [        R                  5      (       a  U R                  $ U R	                  5       (       d%  [        R                  " U S9U l        U R                  $ / nU R
                   HA  nUR                  R                  c  M  UR                  UR                  R                  5        MC     [        R                  " U S9nU(       a.  [        [        [        U5      [        U5      -  5      5      Ul        X0l        U$ )a  
Get or set the :class:`~music21.volume.Volume` object for this
Chord.

When setting the .volume property, all pitches are treated as
having the same Volume object.

>>> c = chord.Chord(['g#', 'd-'])
>>> c.volume
<music21.volume.Volume realized=0.71>

>>> c.volume = volume.Volume(velocity=64)
>>> c.volume.velocityIsRelative = False
>>> c.volume
<music21.volume.Volume realized=0.5>

* Changed in v8: setting volume to a list of volumes is no longer supported.
  See :meth:`~music21.chord.ChordBase.setVolumes` instead

OMIT_FROM_DOCS

Make sure that empty chords have a volume:

>>> chord.Chord().volume
<music21.volume.Volume realized=0.71>
)r`   )r@   _volumer   VolumehasComponentVolumesrD   velocityro   rs   roundsumrQ   )rJ   
velocitiesinner_n
out_volumes       r)   r   ChordBase.volume  s    8 dllFMM22<<''))!==5DL<< 
{{G~~&&2!!'.."9"9: # ]]$/
"%eC
Oc*o,M&N"OJ!r(   c                   [        U[        R                  5      (       a?  Xl        U R                   H
  nS Ul        M     [        R                  R                  XSS9  g [        R                  " U5      (       a8  U R                  5       nUS:  a  [        U5      Ul        g [        U5      Ul        g [!        SU 35      e)NF	setClient   zunhandled setting expr: )r@   r   r   r`   rD   r   r   rr   
_setVolumer   isNum
_getVolumefloatvelocityScalarrs   r   r   )rJ   exprcvols       r)   r   r     s     dFMM**K[[ 	 !LL##D%#@\\$//#Cax%*4[""4y #;D6!BCCr(   c                    SnU R                    H  nUR                  5       (       d  M  US-  nM!     U[        U R                   5      :X  a  gg)a  
Utility method to determine if this object has component
:class:`~music21.volume.Volume` objects assigned to each
note-component.

>>> c1 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c1.setVolumes([60, 20, 120])
>>> [n.volume.velocity for n in c1]
[60, 20, 120]

>>> c1.hasComponentVolumes()
True

>>> c2 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c2.volume.velocity = 23
>>> c2.hasComponentVolumes()
False

>>> c3 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c3.setVolumes([0.2, 0.5, 0.8])
>>> [n.volume.velocity for n in c3]
[25, 64, 102]

>>> c4 = chord.Chord(['c4', 'd-1', 'g6'])
>>> c4.volume = 89
>>> c4.volume.velocity
89

>>> c4.hasComponentVolumes()
False
r   r   TF)rD   r_   rQ   )rJ   countr   s      r)   r   ChordBase.hasComponentVolumes  sK    @ A%%''
  C$$ r(   c                `   SU l         [        U R                  5       H  u  p#X[        U5      -     n[	        U[
        R                  5      (       a  UnOAUS:  a  [
        R                  " [        U5      S9nO[
        R                  " [        U5      S9nXl	        UR                  USS9  M     g)a  
Set as many individual volumes as appear in volumes.  If there are not
enough volumes, then cycles through the list of volumes here:

>>> c = chord.Chord(['g#', 'd-'])
>>> c.setVolumes([volume.Volume(velocity=96), volume.Volume(velocity=96)])
>>> c.hasComponentVolumes()
True

Note that this means that the chord itself does not have a volume at this moment!

>>> c.hasVolumeInformation()
False

>>> c.volume.velocity
96

But after having called the volume, now it does:

>>> c.hasVolumeInformation()
True

>>> c.volume.velocityIsRelative = False
>>> c.volume
<music21.volume.Volume realized=0.76>

* New in v8: replaces setting .volume to a list
Nr   )r   )r   Fr   )r   	enumeraterD   rQ   r@   r   r   r   rs   r`   r   )rJ   volumesir   v_entryvs         r)   
setVolumesChordBase.setVolumes  s    @ dkk*DA#g,./G'6==11Q;U7^DAs7|<AHLLeL, +r(   )rD   rC   r   r;   r5   )rK   ztt.Union[None, str, Sequence[str], Sequence[pitch.Pitch], Sequence[ChordBase], Sequence[note.NotRest], Sequence[int]])rJ   r   returnr   )r?   z"None | t.Literal[False] | Durationr   None)r   ztuple[note.NotRest, ...])r   tie.Tie | None)r   r   )r   z'music21.volume.Volume')r   z,None | 'music21.volume.Volume' | int | floatr   bool)r   z/Sequence['music21.volume.Volume' | int | float])r#   r$   r%   r&   __doc__r-   r.   r1   __annotations__updater   rr   rF   rP   rW   r]   rg   rj   rH   r{   r   propertyrK   r   setterr   r   r   r'   __classcell__rL   s   @r)   r+   r+   :   s6   @ FF6 9!I~   T\\++, 26"E/"E "EH" .!  IM= (F=~- 
-^M@^ " "  . 	ZZ  0 0f ]]D D$*^,- ,-r(   r+   c                  
  ^  \ rS rSr% SrSrS/rSS0rS\S'   \R                  \
R                  5         S SU 4S
 jjjrU 4S jrU 4S jrSS jrS rSU 4S jjr\SS j5       rSS jrSS.     SS jjrSS. SU 4S jjjr\SSSS.           SS jj5       r\SSSS.           SS jj5       r\SSSSS.           SS jj5       rSSSSS.           SS jjrSS jr\ SS	SS.       SS  jjj5       r\S	SS.       SS! jj5       r SS	SS.       SS" jjjrSS# jrSS$ jr\S	SS%.         SS& jj5       r\S	SSS'.         SS( jj5       rS	SSS'.         SS) jjrSS* jrSS+ jrSS, jrSS- jr S	S..     SS/ jjr!S0 r"S1 r#S2 r$S3 r%S4 r&S5 r'SS6 jr(SS7 jr)SS8 jr*S	S..S9 jr+S	S..S: jr,\SS	SS;.         SS< jj5       r-\ SSS	SS;.         SS= jjj5       r- SSS	SS;.         SS> jjjr-        SS? jr.SS@ jr/SSA jr0SSB jr1SSC.SD jr2\3SE 5       r4\3SF 5       r5\3SG 5       r6SH r7\3SSI j5       r8\3SSJ j5       r9\3SSK j5       r:SSC.SSL jjr;SSC.SSM jjr<\3SSN j5       r=\3SSO j5       r>\3SSP j5       r?SSSQ.SSR jjr@          SSS jrAST rB\3SU 5       rC\3SV 5       rDSSW.SSX jjrE\3SY 5       rF\3SZ 5       rGSSC.S[ jrH\3SS\ j5       rISS.S] jrJSS.S^ jrKSS.S_ jrL\ SS	S`.     SSa jjj5       rM\S	S`.     SSb jj5       rM SS	S`.     SSc jjjrM\SSd.     SSe jj5       rN\S	SSS'.     SSf jj5       rNS	SSS'.         SSg jjrNSSh jrOSSi jrPSj rQSk rRSl rSSSm jrT    SSn jrUSS	So.Sp jrVSS.Sq jrWSr rXSS.Ss jrYSt rZSS.Su jr[\\\3Sv 5       5       r]\\\3SSw j5       5       r^\\SSx j5       r_\_R                  SSy j5       r_\\\3SSz j5       5       ra\\S{ 5       rb\\S| 5       rc\\S} 5       rd\\S~ 5       re\\S 5       rf\\S 5       rg\\S 5       rh\\S 5       ri\\S 5       rj\\S 5       rk\\SS j5       rl\lR                  SS j5       rl\\\3S 5       5       rm\\S 5       rnSS jro\\SS j5       rp\\SS j5       rq\\SS j5       rr\\SS j5       rs\\SS j5       rt\tR                  S 5       rt\\SS j5       ru\\SS j5       rv\vR                  SS j5       rv\\SS j5       rw\\SS j5       rx\\\3S 5       5       ry\\S 5       rz\\\3S 5       5       r{\\\3SS j5       5       r|Sr}U =r~$ )r   iH  aM  
Class representing Chords.

A Chord functions like a Note object but has multiple pitches.

Create chords by passing a list of strings of pitch names:

>>> dMaj = chord.Chord(['D', 'F#', 'A'])
>>> dMaj
<music21.chord.Chord D F# A>

Pitch names can also include octaves:

>>> dMaj = chord.Chord(['D3', 'F#4', 'A5'])
>>> dMaj
<music21.chord.Chord D3 F#4 A5>

A single string with note names separated by spaces also works:

>>> myChord = chord.Chord('A4 C#5 E5')
>>> myChord
<music21.chord.Chord A4 C#5 E5>


Or you can combine already created Notes or Pitches:

>>> cNote = note.Note('C')
>>> eNote = note.Note('E')
>>> gNote = note.Note('G')

And then create a chord with note objects:

>>> cmaj = chord.Chord([cNote, eNote, gNote])
>>> cmaj  # default octave of 4 is used for these notes, since octave was not specified
<music21.chord.Chord C E G>

Or with pitches:

>>> cmaj2 = chord.Chord([pitch.Pitch('C'), pitch.Pitch('E'), pitch.Pitch('G')])
>>> cmaj2
<music21.chord.Chord C E G>

Chord has the ability to determine the root of a chord, as well as the bass note of a chord.
In addition, Chord is capable of determining what type of chord a particular chord is, whether
it is a triad or a seventh, major or minor, etc., as well as what inversion the chord is in.

A chord can also be created from pitch class numbers:

>>> c = chord.Chord([0, 2, 3, 5])
>>> c.pitches
(<music21.pitch.Pitch C>,
 <music21.pitch.Pitch D>,
 <music21.pitch.Pitch E->,
 <music21.pitch.Pitch F>)

Or from MIDI numbers:

>>> c = chord.Chord([72, 76, 79])
>>> c.pitches
(<music21.pitch.Pitch C5>, <music21.pitch.Pitch E5>, <music21.pitch.Pitch G5>)

(If the number is < 12, it is assumed to be an octaveless pitch-class number, if above
12, then a MIDI number.  To create chords below MIDI 12, create a Pitch object with that
MIDI number instead and then pass that to the Chord creator).


Duration or quarterLength also works:

>>> d = duration.Duration(2.0)
>>> myChord = chord.Chord('A4 C#5 E5', duration=d)
>>> myChord
<music21.chord.Chord A4 C#5 E5>
>>> myChord.duration
<music21.duration.Duration 2.0>
>>> myChord.duration is d
True

>>> myChord = chord.Chord('A4 C#5 E5', quarterLength=3.75)
>>> myChord.duration.type
'half'
>>> myChord.duration.dots
3


OMIT_FROM_DOCS

Test that durations are being created efficiently:

>>> dMaj.duration
<music21.duration.Duration 1.0>

>>> cmaj.pitches[0] is cNote.pitch
True

>>> cNote.duration
<music21.duration.Duration 1.0>

>>> cmaj.duration
<music21.duration.Duration 1.0>

>>> cmaj.duration is cNote.duration
True

Create a chord from two chords (or a chord + notes):

>>> eFlatSixFive = chord.Chord('G3 B-3 D-4 E-4')
>>> fFlat = chord.Chord('F-2 A-2 C-3 F-3')
>>> riteOfSpring = chord.Chord([fFlat, eFlatSixFive])
>>> riteOfSpring
<music21.chord.Chord F-2 A-2 C-3 F-3 G3 B-3 D-4 E-4>

Incorrect entries raise a TypeError:

>>> chord.Chord([base])
Traceback (most recent call last):
TypeError: Could not process input argument <module 'music21.base' from '...base...'>

**Equality**

Two chords are equal if the Chord passes all `super()`
equality tests and all their pitches are equal
(possibly in a different order)

>>> c1 = chord.Chord('C4 E4 G4')
>>> c2 = chord.Chord('E4 C4 G4')
>>> c1 == c2
True
>>> c3 = chord.Chord('E4 C#4 G4')
>>> c2 == c3
False
>>> n1 = note.Note('C4')
>>> c1 == n1
False
>>> c2.duration.quarterLength = 2.0
>>> c1 == c2
False
>>> c1 != c2
True
TpitchesisChordzj
            Boolean read-only value describing if this
            GeneralNote object is a Chord. Is Truer0   r1   Nc                   > Ub%  [        S U 5       5      (       a  [        SU 35      e[        TU ]  " SSU0UD6  U   Ub(  [	        S U 5       5      (       a  U R                  SS9  g g g )Nc              3     #    U  HK  n[        U[        R                  5      =(       a%    [        U[        R                  [        45      (       + v   MM     g 7fr5   )r@   r   GeneralNotern   r   r6   rb   s     r)   r9   !Chord.__init__.<locals>.<genexpr>  sF      %5.3 &043C3C%D &O-7DIIu;M-N)N&O.3s   AA8Use a PercussionChord to contain Unpitched objects; got rK   c              3  B   #    U  H  n[        U[        5      v   M     g 7fr5   )r@   rs   r   s     r)   r9   r     s     $GAZ3%7%7s   TinPlacer"   )rG   rt   rE   rF   allsimplifyEnharmonicsrI   s      r)   rF   Chord.__init__  s      %5.3%5 "5 "5 VW\V]^__1u11 	$G$G!G!G$$T$2 "Hr(   c                   > [         TU ]  U5      (       d  g[        U R                  5      [        UR                  5      :w  a  ggrO   )rE   rP   setr   rR   s     r)   rP   Chord.__eq__  s5    w~e$$t||EMM 22r(   c                    > [         TU ]  5       $ r5   rV   rX   s    r)   rW   Chord.__hash__  rZ   r(   c                   SU< 3n[        U[        5      (       aN  SU;   a9  UR                  SS5      u  pSU;   a  [        UR                  S5      5      nOU4nOSn [	        U5      nOSn[        U[        5      (       a   U R                  U   nGOZ[        U[        5      (       aM  UR                  5       nU R                   H"  nUR                  R                  U:X  d  M  Un  GO   [        U5      e[        U[        R                  5      (       aW  U R                   H  nXaL d  M	  Un  O   U R                   H!  nUR                  UR                  :X  d  M  Un  O   [        U5      e[        U[        R                  5      (       aX  U R                   H  nUR                  UL d  M  Un  O?   U R                   H  nUR                  U:X  d  M  Un  O   [        U5      e[        U5      eU(       d  U$ UnU H%  nUS:X  a  UR                  U S9nM  [!        Xx5      nM'     U$ ! [
         a     GNf = f! [        [        4 a    [        U5      ef = f)a  
Get item makes accessing pitch components for the Chord easier

>>> c = chord.Chord('C#4 D-4')
>>> cSharp = c[0]
>>> cSharp
<music21.note.Note C#>

>>> c['0.step']
'C'
>>> c['3.accidental']
Traceback (most recent call last):
KeyError: "Cannot access component with: '3.accidental'"

>>> c[5]
Traceback (most recent call last):
KeyError: 'Cannot access component with: 5'

>>> c['D-4']
<music21.note.Note D->

>>> c['D-4.style.color'] is None
True

Getting by note does not do very much:

>>> c[cSharp]
<music21.note.Note C#>

But we can get from another note

>>> cSharp2 = note.Note('C#4')
>>> cSharp2.duration.quarterLength = 3.0
>>> c[cSharp2] is cSharp
True
>>> c[cSharp2] is cSharp2
False

KeyError is raised if not in chord.

>>> notInChord = note.Note('G')
>>> c[notInChord]
Traceback (most recent call last):
KeyError: 'Cannot access component with: <music21.note.Note G>'

>>> c[None]
Traceback (most recent call last):
KeyError: 'Cannot access component with: None'
zCannot access component with: .r   r"   r   forceClient)r@   rA   rB   r   rs   r   rD   KeyError
IndexErrorupperr   r   r   rn   rm   r   getattr)	rJ   keykeyErrorStrattrStr
attributes	foundNoterb   currentValueattrs	            r)   __getitem__Chord.__getitem__  s)   j 7sg>c3cz"yya0'>!&w}}S'9!:J")J
#h
 Jc3, KK,	 S!!))+C[[77))S0 !I !
 {++TYY''[[8 !I !
 Aww#))+$%	 %
 #;//U[[))[[77c> !I !
 Aww#~$%	 %
 #;//;'''Dx+6646H&|:  w   j) ,{++,s   H% H6 %
H32H36Ic                   [        U[        5      (       aA  SU;   a;  UR                  S5      nSR                  USS 5      nUS   nX   n[	        XeU5        gX   nU R
                  R                  U5      n[        U[        5      (       a  [        R                  " U5      nO^[        U[        R                  5      (       a  [        R                  " US9nO*[        U[        R                  5      (       d  [        S5      eX R
                  U'   g)a  
Change either a note in the chord components, or set an attribute on a
component

>>> c = chord.Chord('C4 E4 G4')
>>> c[0] = note.Note('C#4')
>>> c
<music21.chord.Chord C#4 E4 G4>
>>> c['0.octave'] = 3
>>> c
<music21.chord.Chord C#3 E4 G4>
>>> c['E4'] = 'F4'
>>> c
<music21.chord.Chord C#3 F4 G4>
>>> c['G4.style.color'] = 'red'
>>> c['G4.style.color']
'red'
>>> c[-1].style.color
'red'

>>> c[0] = None
Traceback (most recent call last):
ValueError: Chord index must be set to a valid note object
r   r   Nr   z.Chord index must be set to a valid note object)r@   rA   rB   joinsetattrrD   indexr   rn   r   rm   r   )rJ   r   r   keySplitkeyFindr   keyObjkeyIndexs           r)   __setitem__Chord.__setitem__  s    2 c3C3Jyy~Hhhx"~.GB<D]FF%(;;$$V,eS!!IIe$Eu{{++IIE*EE499--MNN %Hr(   c                   > U R                   (       d  [        TU ]	  5       $ / nU R                    H  nUR                  UR                  5        M      SR                  U5      $ )Nr3   )r   rE   _reprInternalro   r   r   )rJ   
allPitches	thisPitchrL   s      r)   r   Chord._reprInternal  sP    ||7(**
Ii667 & xx
##r(   c                    S/nU  H*  n[         R                  " U5      nUR                  U5        M,     UR                  S5        SR                  U5      $ )ao  
Return a string representation of a vector or set

Static method.  Works on the class:

>>> chord.Chord.formatVectorString([0, 11])
'<0B>'

or an existing chord:

>>> c1 = chord.Chord(['D4', 'A4', 'F#5', 'D6'])
>>> c1.formatVectorString(c1.normalOrder)
'<269>'

or on a list that has nothing to do with the chord

>>> c1.formatVectorString([10, 11, 3, 5])
'<AB35>'

<> )r   convertPitchClassToStrro   r   )
vectorListmsgeeStrs       r)   formatVectorStringChord.formatVectorString  sL    , eA//2DJJt  	

3wws|r(   c                j    SnU R                    H   nUc  UnM
  [        R                  " X5      nM"     U$ )a  
Returns the lowest Pitch in the chord.

The only time findBass should be called is by bass() when it is
figuring out what the bass note of the chord is.

Generally call bass() instead:

>>> cmaj = chord.Chord(['C4', 'E3', 'G4'])
>>> cmaj._findBass()
<music21.pitch.Pitch E3>
N)r   r   getWrittenLowerNote)rJ   lowestr   s      r)   	_findBassChord._findBass  s8     I~"!55fH	 &
 r(   Fr   c                  U(       d  [         R                  " U 5      nOU n/ n/ nUR                   HU  n[        UR                  U5      U;  a'  UR                  [        UR                  U5      5        MD  UR                  U5        MW     UR                  nU Vs/ s H  n[        U5      PM     n	nU H?  nU	R                  [        U5      5      n
UR                  U
5        U	R                  U
5        MA     Xsl        U(       a  UR                  5         U(       d  U$ U Vs/ s H  oR                  PM     sn$ s  snf s  snf )zz
Common method for stripping pitches based on redundancy of one pitch
attribute. The `attribute` is provided by a string.
)
rp   rq   rD   r   r   ro   idr   poprz   )rJ   	attributer   	returnObjuniquePitchesdeleteComponentscompalteredrb   	alteredIdnIndexs              r)    _removePitchByRedundantAttribute&Chord._removePitchByRedundantAttribute  s    d+II$$Dtzz9-]B$$WTZZ%CD ''-	 % ""$+,GqRUG	,!A__RU+FKKMM&! "
 #  "%56%5GG%566 - 7s   D8 D=runSortc                  > [         R                  " U5      (       d  U/n[        S U 5       5      (       a  [        SU 35      e[        TU ]  U5        U(       a  U R                  SS9  gg)a  
Add a Note, Pitch, the `.notes` of another chord,
or string representing a pitch,
or a list of any-of-the-above types to a Chord.

If `runSort` is True (default=True) then after appending, the
chord will be sorted.

>>> c = chord.Chord('C4 E4 G4')
>>> c.add('B3')
>>> c
<music21.chord.Chord B3 C4 E4 G4>
>>> c.duration
<music21.duration.Duration 1.0>

>>> c.add('A2', runSort=False)
>>> c
<music21.chord.Chord B3 C4 E4 G4 A2>

>>> c.add(['B5', 'C6'])
>>> c
<music21.chord.Chord A2 B3 C4 E4 G4 B5 C6>

>>> c.add(pitch.Pitch('D6'))
>>> c
<music21.chord.Chord A2 B3 C4 E4 G4 B5 C6 D6>

>>> n = note.Note('E6')
>>> n.duration.type = 'half'
>>> c.add(n)
>>> c
<music21.chord.Chord A2 B3 C4 E4 G4 B5 C6 D6 E6>
>>> c.duration
<music21.duration.Duration 1.0>
>>> c[-1]
<music21.note.Note E>
>>> c[-1].duration
<music21.duration.Duration 2.0>

Overrides `ChordBase.add()` to permit sorting with `runSort`.
c              3  V   #    U  H  n[        U[        R                  5      v   M!     g 7fr5   )r@   r   	Unpitchedr   s     r)   r9   Chord.add.<locals>.<genexpr>M  s     <ez!T^^,,e   ')r   Tr   N)r   ry   rG   rt   rE   r{   sortAscending)rJ   rK   r  rL   s      r)   r{   	Chord.add  si    ^   ''GE<e<<<VW\V]^__Et, r(   )r   stripSpecifierssortPitchesc                   g r5   r"   rJ   r   r  r  
returnLists        r)   annotateIntervalsChord.annotateIntervalsS       	r(   )r  r  r  c                   g r5   r"   r  s        r)   r  r  ^  r   r(   )r   r  r  r  c                   g r5   r"   r  s        r)   r  r  i  r   r(   c                  [         R                  " U 5      nUR                  SS9  U(       a  UR                  5       n/ n[	        [        UR                  5      S-
  SS5       H  nUR                  U   n[        R                  " UR                  S   U5      n	USL a  U	R                  n
O)[        U	R                  R                  R                  5      n
UR                  U
5        M     U(       a  U(       a  UR                  SS9  U(       a  U$ U H.  n
U(       a  U R!                  U
5        M  UR!                  U
5        M0     U(       d  U$ g)	a  
Add lyrics to the chord that show the distance of each note from
the bass.  If returnList is True, a list of the intervals is returned instead.

By default, we show only the generic interval:

>>> c1 = chord.Chord(['C2', 'E2', 'G2', 'C3'])
>>> c2 = c1.annotateIntervals(inPlace=False)
>>> c2.lyrics
[<music21.note.Lyric number=1 syllabic=single text='8'>,
 <music21.note.Lyric number=2 syllabic=single text='5'>,
 <music21.note.Lyric number=3 syllabic=single text='3'>]

>>> [ly.text for ly in c2.lyrics]
['8', '5', '3']

The `stripSpecifiers` parameter can be used to show only the intervals size (3, 5, etc.)
or the complete interval specification (m3, P5, etc.)

>>> c3 = c1.annotateIntervals(inPlace=False, stripSpecifiers=False)
>>> c3.lyrics
[<music21.note.Lyric number=1 syllabic=single text='P8'>,
 <music21.note.Lyric number=2 syllabic=single text='P5'>,
 <music21.note.Lyric number=3 syllabic=single text='M3'>]

>>> [ly.text for ly in c3.lyrics]
['P8', 'P5', 'M3']

This chord was giving us problems:

>>> c4 = chord.Chord(['G4', 'E4', 'B3', 'E3'])
>>> c4.annotateIntervals(inPlace=True, stripSpecifiers=False)
>>> [ly.text for ly in c4.lyrics]
['m3', 'P8', 'P5']
>>> c4.annotateIntervals(inPlace=True, stripSpecifiers=False, returnList=True)
['m3', 'P8', 'P5']

If sortPitches is false it still gives problems:

>>> c4 = chord.Chord(['G4', 'E4', 'B3', 'E3'])
>>> c4.annotateIntervals(inPlace=True, stripSpecifiers=False, sortPitches=False)
>>> [ly.text for ly in c4.lyrics]
['m3', 'm6', 'm3']

>>> c = chord.Chord(['c4', 'd-4', 'g4'])
>>> c.annotateIntervals(inPlace=True)
>>> [ly.text for ly in c.lyrics]
['5', '2']

>>> c = chord.Chord(['c4', 'd-4', 'g4'])
>>> c.annotateIntervals(inPlace=True, stripSpecifiers=False)
>>> [ly.text for ly in c.lyrics]
['P5', 'm2']

>>> c = chord.Chord(['c4', 'd---4', 'g4'])
>>> c.annotateIntervals(inPlace=True, stripSpecifiers=False)
>>> [ly.text for ly in c.lyrics]
['P5', 'dd2']

>>> c = chord.Chord(['c4', 'g5', 'e6'])
>>> c.annotateIntervals(inPlace=True)
>>> [ly.text for ly in c.lyrics]
['5', '3']
Tr   r   r   r   F)reverseN)rp   rq   removeRedundantPitchesr  rangerQ   r   r   IntervalsemiSimpleNamerA   diatonicgenericsemiSimpleUndirectedro   sortaddLyric)rJ   r   r  r  r  r   
lyricsListjpr   notations              r)   r  r  t  s   T MM$	   .!A
s199~)1b1A		!A!!!))A,2A%'++qzz11FFGh' 2 {OODO)"Hh'

8$	 # H r(   c                z    [         R                  " U R                  5      nUc  gUR                  SS USS :X  a  gg)a  
Check if another Chord is a z-relation to this Chord.

>>> c1 = chord.Chord(['C', 'c#', 'e', 'f#'])
>>> c2 = chord.Chord(['C', 'c#', 'e-', 'g'])
>>> c3 = chord.Chord(['C', 'c#', 'f#', 'g'])
>>> c1.areZRelations(c2)
True

>>> c1.areZRelations(c3)
False

If there is no z-relation for the first chord, obviously return False:

>>> c4 = chord.Chord('C E G')
>>> c4.areZRelations(c3)
False
Fr      T)r   addressToZAddresschordTablesAddress)rJ   rS   zRelationAddresss      r)   areZRelationsChord.areZRelations  sG    & "33D4K4KL###Aa(,<Qq,AAr(   )find	allow_addc                   g r5   r"   rJ   newbassr9  r:  s       r)   bass
Chord.bass       	r(   c                   g r5   r"   r<  s       r)   r>  r?    r@  r(   c                  U(       Ga  [        U[        5      (       a-  [        R                  " U5      n[        R
                  " U5      nOe[        U[        R
                  5      (       a  UnOC[        U[        R                  5      (       a  UR                  nO[        S[        U5       35      eSnU R                   H  nXFL d  M	  Sn  O   U(       d3  U R                   H#  nUR                  UR                  :X  d  M  UnSn  O   U(       d3  U R                   H#  nUR                  UR                  :X  d  M  SnUn  O   U(       d2  U(       d  [        SU S35      eU/S U R                   5       Q7U l
        X@R                  S'   X@R                  S'   SU R                  ;   a  U R                  S	 g	SU R                  ;   a  USLa  U R                  S   $ USL a  g	SU R                  ;   a  U R                  S	 USLa  SU R                  ;   a  U R                  S   $ U R                  5       U R                  S'   U R                  S   $ )
a	  
Generally used to find and return the bass Pitch:

>>> cmaj1stInv = chord.Chord(['C4', 'E3', 'G5'])
>>> cmaj1stInv.bass()
<music21.pitch.Pitch E3>

Subclasses of Chord often have basses that are harder to determine.

>>> cmaj = harmony.ChordSymbol('CM')
>>> cmaj.bass()
<music21.pitch.Pitch C3>

>>> cmin_inv = harmony.ChordSymbol('Cm/E-')
>>> cmin_inv.bass()
<music21.pitch.Pitch E-3>

Can also be used in rare occasions to set the bass note to a new Pitch,
so long as that note is found in the chord:

>>> strange_chord = chord.Chord('E##4 F-4 C5')
>>> strange_chord.bass()
<music21.pitch.Pitch E##4>
>>> strange_chord.bass('F-4')
>>> strange_chord.bass()
<music21.pitch.Pitch F-4>

If the note assigned to the bass is not found, it will default to raising a
ChordException:

>>> strange_chord.bass('G--4')
Traceback (most recent call last):
music21.chord.ChordException: Pitch G--4 not found in chord

For the purposes of initializing from a ChordSymbol and in other cases,
a new bass can be added to the chord by setting `allow_add = True`:

>>> strange_chord.bass('G--4', allow_add=True)
>>> strange_chord.bass()
<music21.pitch.Pitch G--4>


By default, if nothing has been overridden, this method uses a
quick algorithm to find the bass among the
chord's pitches, if no bass has been previously specified. If this is
not intended, set find to False when calling this method, and 'None'
will be returned if no bass is specified

>>> em = chord.Chord(['E3', 'G3', 'B4'])
>>> print(em.bass(find=False))
None

* Changed in v8: raise an exception if setting a new bass
  to a pitch not in the chord, unless new keyword `allow_add` is `True`.

OMIT_FROM_DOCS

Test to make sure that cached basses still work by calling twice:

>>> a = chord.Chord(['C4'])
>>> a.bass()
<music21.pitch.Pitch C4>
>>> a.bass()
<music21.pitch.Pitch C4>

# After changing behavior uncomment these lines.

# Setting a new bass note might be helpful to move it to a different
# octave.  Otherwise, it is likely just to lead to confusion and
# hard to diagnose errors.
#
# >>> cmin_inv.bass('E-2')
# >>> cmin_inv.bass()
# <music21.pitch.Pitch E-2>
#
# To find the bass again from the pitches in the chord, set find=True
#
# >>> cmin_inv.bass(find=True)
# <music21.pitch.Pitch E-3>
#
# Subsequent calls after an overridden bass has been cleared by find=True
# will continue to return the algorithmically determined bass.
#
# >>> cmin_inv.bass()
# <music21.pitch.Pitch E-3>

znewbass should be a Pitch, not FTzPitch z not found in chordc              3  $   #    U  H  ov   M     g 7fr5   r"   r6   r0  s     r)   r9   Chord.bass.<locals>.<genexpr>  s     /H<a<s   r>  	inversionN)r@   rA   r   cleanedFlatNotationr   rm   r   rn   r   r<   r   r   namerC   _cacher  )rJ   r=  r9  r:  newbassPitchfoundBassInChordr0  s          r)   r>  r?    s   | '3'' 44W=${{73GU[[11&GTYY//&}}$'FtG}o%VWW &+\\$'+$ "
 $A''<+F+FF'(+/(	 & $Avv!2!22+/('(	 & $ (6':M)NOO ,I/H4<</HI&2OOF#".KKdkk)KK,T__$T)9??6**5=T__$'t$++ 5;;v&&"&.."2DKK;;v&&r(   c                Z    U R                  5       (       d  U R                  5       (       a  gg)z
Returns True if the chord is a Major Triad or a Dominant Seventh:

>>> gSeven = chord.Chord(['g', 'b', 'd', 'f'])
>>> gSeven.canBeDominantV()
True

>>> gDim = chord.Chord(['g', 'b-', 'd-'])
>>> gDim.canBeDominantV()
False
TF)isMajorTriadisDominantSeventhrf   s    r)   canBeDominantVChord.canBeDominantV  s'     $"8"8":":r(   c                Z    U R                  5       (       d  U R                  5       (       a  gg)z
Returns True if the chord is a major or minor triad:

>>> a = chord.Chord(['g', 'b', 'd', 'f'])
>>> a.canBeTonic()
False

>>> a = chord.Chord(['g', 'b', 'd'])
>>> a.canBeTonic()
True

TF)rM  isMinorTriadrf   s    r)   
canBeTonicChord.canBeTonic  s'     $"3"3"5"5r(   )forceOctaveleaveRedundantPitchesc                   g r5   r"   rJ   rU  r   rV  s       r)   closedPositionChord.closedPosition  r@  r(   rU  r   rV  c                   g r5   r"   rX  s       r)   rY  rZ    r@  r(   c                  U(       a  U nOR[         R                  " U 5      n[        R                  " U5      Ul        XR                  l        SUR                  l        UR                  5       nUb  UR                  nUc  UR                  nXa:  a  SnO
Xa:  a  SnOSnUbh  UR                  U:w  aX  UR                   H6  nUR                  c  UR                  Ul        U=R                  U-  sl        M8     UR                  U:w  a  MX  UR                   H  nUR                  c  UR                  Ul        UR                  UR                  S-   :  a4  U=R                  S-  sl        UR                  UR                  S-   :  a  M4  UR                  UR                  :  d  M  U=R                  S-  sl        M     USLa  UR                  SS9  UR                  SS9  U(       d  U$ g)a\  
Returns a new Chord object with the same pitch classes,
but now in closed position.

If `forcedOctave` is provided, the bass of the chord will
be shifted to that provided octave.

If inPlace is True then the original chord is returned with new pitches.

>>> chord1 = chord.Chord(['C#4', 'G5', 'E6'])
>>> chord2 = chord1.closedPosition()
>>> chord2
<music21.chord.Chord C#4 E4 G4>

Force octave changes the octave of the bass note (and all notes above it)

>>> c2 = chord.Chord(['C#4', 'G5', 'E6'])
>>> c2.closedPosition(forceOctave=2)
<music21.chord.Chord C#2 E2 G2>

>>> c3 = chord.Chord(['C#4', 'G5', 'E6'])
>>> c3.closedPosition(forceOctave=6)
<music21.chord.Chord C#6 E6 G6>

Redundant pitches are removed by default, but can be retained:

>>> c4 = chord.Chord(['C#4', 'C5', 'F7', 'F8'])
>>> c5 = c4.closedPosition(forceOctave=4, inPlace=False)
>>> c5
<music21.chord.Chord C#4 F4 C5>

>>> c6 = c4.closedPosition(forceOctave=4, inPlace=False, leaveRedundantPitches=True)
>>> c6
<music21.chord.Chord C#4 F4 F4 C5>

Implicit octaves work fine:

>>> c7 = chord.Chord(['A4', 'B4', 'A'])
>>> c7.closedPosition(forceOctave=4, inPlace=True)
>>> c7
<music21.chord.Chord A4 B4>

OMIT_FROM_DOCS

Very specialized fears:

Duplicate octaves were not working

>>> c7b = chord.Chord(['A4', 'B4', 'A5'])
>>> c7b.closedPosition(inPlace=True)
>>> c7b
<music21.chord.Chord A4 B4>

but the bass must remain A4:

>>> c7c = chord.Chord(['A4', 'B4', 'A5', 'G##6'])
>>> c7c.closedPosition(inPlace=True)
>>> c7c
<music21.chord.Chord A4 B4 G##5>

>>> str(c7c.bass())
'A4'

Complex chord for semiclosed-position testing:

>>> c8 = chord.Chord(['C3', 'E5', 'C#6', 'E-7', 'G8', 'C9', 'E#9'])
>>> c8.closedPosition(inPlace=True)
>>> c8
<music21.chord.Chord C3 C#3 E-3 E3 E#3 G3>

Implicit octave + forceOctave

>>> c9 = chord.Chord('C G E')
>>> c9.closedPosition(forceOctave=6)
<music21.chord.Chord C6 E6 G6>
rY  Nr   r      Tr   )rp   rq   r   
Derivationoriginmethodr>  octaveimplicitOctaver   psdiatonicNoteNumr%  r  )	rJ   rU  r   rV  r  pBasspBassOctavedifr0  s	            r)   rY  rZ    s   h Id+I#-#8#8#CI *.  '*:I  '  ",,K"#22(*llk1&..88+'('7'7AHC / llk1 ""A xx++$$%((R-'A $$%((R-'   5#8#88A # !,,,T,: 	- r(   c                L    U R                  5       (       d  gU R                  c  gg)a  
Returns True if the chord contains at least one of each of Third, Fifth, and Seventh.
raises an exception if the Root can't be determined

A ninth chord contains a seventh:

>>> c9 = chord.Chord(['C4', 'E4', 'G4', 'B4', 'D5'])
>>> c9.containsSeventh()
True

As does a cluster:

>>> cluster = chord.Chord('C D E F G A B')
>>> cluster.containsSeventh()
True

But a major triad does not:

>>> dMaj = chord.Chord([pitch.Pitch('D4'), pitch.Pitch('F#4'), pitch.Pitch('A5')])
>>> dMaj.containsSeventh()
False

Note that a seventh chord itself contains a seventh.

>>> cChord = chord.Chord(['C', 'E', 'G', 'B'])
>>> cChord.containsSeventh()
True


Empty chord returns False

>>> chord.Chord().containsSeventh()
False
FT)containsTriadseventhrf   s    r)   containsSeventhChord.containsSeventhe  s'    F !!##<<r(   c                <    U R                   c  gU R                  c  gg)a  
Returns True or False if there is no triad above the root.
"Contains vs. Is": A dominant-seventh chord contains a triad.

>>> cChord = chord.Chord(['C', 'E', 'G'])
>>> other = chord.Chord(['C', 'D', 'E', 'F', 'G'])
>>> cChord.containsTriad()
True

>>> other.containsTriad()
True

>>> scale = chord.Chord(['C', 'D-', 'E', 'F#', 'G', 'A#', 'B'])
>>> scale.containsTriad()
True

>>> c = chord.Chord('C4 D4')
>>> c.containsTriad()
False

>>> chord.Chord().containsTriad()
False
FT)thirdfifthrf   s    r)   rj  Chord.containsTriad  s!    2 ::::r(   c                f   S n[         R                  R                  S U R                   5       S S9n[	        U5      nU(       d  [        SU < 35      eUS:X  a  U R                  S   $ US:X  a  U R                  5       $ U Vs0 s H!  n[        R                  UR                     U_M#     nn[        U5      n[        U5       HF  nS	nXg   n	U	n
[        US-   Xs-   5       H  nX-  nXl   nX-
  S
;  a  Sn  OUn
M     U(       d  MB  XY   s  $    / nSnU Hw  n/ n[        R                  UR                     n	U H6  nU	U-   S-
  S-  U;   a  UR                  S	5        M%  UR                  S5        M8     U" U5      nUR                  U5        My     UR                  [        U5      5      nUU   $ s  snf )z
Looks for the root usually by finding the note with the most 3rds above
it.

Generally use root() instead, since if a chord doesn't know its root,
root() will run ._findRoot() automatically.
c                V    Sn[        U 5       H  u  p#USL d  M  USUS-   -  -  nM     U$ )a  
Returns a value for how likely this pitch is to be a root given the
number of thirds and fifths above it.

Takes a list of True's and False's where each value represents
whether a note has a 3rd, 5th, 7th, 9th, 11th, and 13th above it
and calculates a value based on that.  The highest score on
rootnessFunction is the root.

This formula might be tweaked if wrong notes are found.

Rootness function might be divided by the inversion number
in case that's a problem.
r   Tr      )r   )rootThirdListscore
root_indexvals       r)   rootnessFunction)Chord._findRoot.<locals>.rootnessFunction  s;     E#,]#;
$;Q*q.11E $< Lr(   c              3  8   #    U  H  oR                   v   M     g 7fr5   r   r   s     r)   r9   "Chord._findRoot.<locals>.<genexpr>  s     3Q[GG[   c                    U R                   $ r5   step)pps    r)   <lambda>!Chord._findRoot.<locals>.<lambda>  s    "''r(   r   zno pitches in chord r   r      T)   F)r3     r  r     rt  )r   miscuniquerD   rQ   r   r   r>  r   STEP_TO_DNN_OFFSETr  sortedr&  ro   r   max)rJ   ry  nonDuplicatingPitches
lenPitchesr0  stepNumsToPitchesstepNums
startIndexall_are_thirdsthis_step_numlast_step_numendIndexendIndexMod
endStepNumrootnessFunctionScoresorderedChordStepscurrentListOfThirdschordStepTestrootnessScoremostRootyIndexs                       r)   	_findRootChord._findRoot  s   	4 !' 2 23QT[[3Q7I !3 !K./
 #7x!@AA?<<?"1_99; ?T5U>S 6;5M5Maff5UWX5X>S 	 5U +,
+J!N$0M)M!*q.*2IJ&3%2
-W<%*N * K ~(77 ,& "$.&A"$!44QVV<M!2!M1A5:>OO'..t4'..u5	 "3 --@AM"))-8 ' 055c:P6QR$^44W5Us   (F.c                @   / n[        [        U R                  5      5       H+  nUR                  U R                  U   R                  5        M-     [        U5      nUS   /n[        S[        U5      5       H%  nX2   X2S-
     :w  d  M  UR                  X2   5        M'     / n[        S[        U5      5       H#  nXB   XBS-
     -
  S-  nUR                  U5        M%     UR                  US   US   -
  S-  5        / n[        S[        U5      5       HA  nUR                  S5      nUR                  U5        [        U5      n	UR                  U	5        MC     [        U5      n
U
S   n/ nSn[        S[        U5      5       H  nUR                  U5        XU   -  nM     U$ )ab  
Geometric Normal Form, as first defined by Dmitri Tymoczko, orders pitch classes
such that the spacing is prioritized with the smallest spacing between the first and
second pitch class first, then the smallest spacing between second and third pitch class,
and so on. This form has unique properties that make it useful.  It also transposes
to PC0

`geometricNormalForm` returns a list of pitch class integers in
geometric normal form.

Example 1: A major triad has geometricNormalForm of 038 not 047.

>>> c1 = chord.Chord('E4 C5 G6 C7')
>>> pcList = c1.geometricNormalForm()
>>> pcList
[0, 3, 8]

>>> c2 = chord.Chord(pcList)
>>> c2.orderedPitchClassesString
'<038>'

Compare this to the usual normalOrder transposed to PC0:

>>> normalOrder = c1.normalOrder
>>> normalOrderFirst = normalOrder[0]
>>> [(pc - normalOrderFirst) % 12 for pc in normalOrder]
[0, 4, 7]
r   r   r^  r   )r&  rQ   r   ro   
pitchClassr  r  r   )rJ   pitchClassListr   sortedPitchClassListuniquePitchClassListintervalListlPCrotationListbintervalTuplenewRotationListgeomNormChordgeomNormChordPitchesintervalSums                 r)   geometricNormalFormChord.geometricNormalForm  s   > s4<<()A!!$,,q/"<"<= *%n5 4Q 78q#234A#&*>1u*EE$++,@,CD 5 q#234A'*-Aa%-HHBNC$ 5 	1!47KB7OOSUUVq#l+,A  #A"!,/M.	 - !.'*  "q#m,-A ''4++K . $#r(   testRootc                  US:  a  US-  nUc  U R                  5       nUc  [        S5      eOe[        U[        R                  5      (       a  UR
                  nO9[        U[
        R                  5      (       a  UnO[        S[        U5       35      eUR                  nU R                   H!  nUR                  U-
  S-  S-   nXa:X  d  M  Us  $    g)a  
Returns the (first) pitch at the provided scaleDegree (Thus, it's
exactly like semitonesFromChordStep, except it instead of the number of
semitones.)

Returns None if none can be found.

>>> cmaj = chord.Chord(['C', 'E', 'G'])
>>> cmaj.getChordStep(3)  # will return the third of the chord
<music21.pitch.Pitch E>

>>> g = cmaj.getChordStep(5)  # will return the fifth of the chord
>>> g.name
'G'

>>> cmaj.getChordStep(6) is None
True

Ninths can be specified with either 9 or 2.  Similarly for elevenths
and thirteenths.

>>> c9 = chord.Chord('C4 E4 G4 B4 D5')
>>> c9.getChordStep(9)
<music21.pitch.Pitch D5>
>>> c9.getChordStep(2)
<music21.pitch.Pitch D5>

OMIT_FROM_DOCS

If `root` has been explicitly overridden as `None`, calling this raises `ChordException`:

>>> cmaj._overrides['root'] = None
>>> cmaj.getChordStep(6)
Traceback (most recent call last):
music21.chord.ChordException: Cannot run getChordStep without a root

(This is in OMIT_FROM_etc.)
   r  Nz&Cannot run getChordStep without a rootz testRoot should be a Pitch, not r   )
rootr   r@   r   rn   r   rm   r<   re  r   )rJ   	chordStepr  testRootPitchrootDNNr   diatonicDistances          r)   getChordStepChord.getChordStepM  s    X >NI  IIKM$$%MNN %$)),,$NNM%++..$M #CDNCS!TUU//I!*!:!:W!D IQN,   & r(   c                B   [        U[        5      (       a  [        R                  " U5      nU R                   HV  nUR                  UL d  M  UR
                  (       d  M'  UR                  R                  c  M@  UR                  R                  s  $    U R                   HW  nUR                  U:X  d  M  UR
                  (       d  M(  UR                  R                  c  MA  UR                  R                  s  $    U R
                  (       a  U R                  R                  $ g)aB  
For a pitch in this Chord, return the color stored in self.editorial,
or, if set for each component, return the color assigned to this
component.

First checks for "is" then "equals"

>>> p = pitch.Pitch('C4')
>>> n = note.Note(p)
>>> n.style.color = 'red'
>>> c = chord.Chord([n, 'E4'])
>>> c.getColor(p)
'red'
>>> c.getColor('C4')
'red'
>>> c.getColor('E4') is None
True

The color of any pitch (even a non-existing one) is the color of the chord if
the color of that pitch is not defined.

>>> c.style.color = 'pink'
>>> c.getColor('E4')
'pink'
>>> c.getColor('D#7')
'pink'
N)r@   rA   r   rm   rD   hasStyleInformationstylecolor)rJ   pitchTargetrb   s      r)   getColorChord.getColor  s    @ k3''++k2KAww+%(((QWW]]-F77==(  Aww+%(((QWW]]-F77==(  ##::###r(   c                    [        US5      (       a  UR                  nU R                   H   nUR                  UL d  M  UR                  s  $    U R                   H!  nUR                  U:X  d  M  UR                  s  $    g)a  
Given a pitch in this Chord, return an associated notehead
attribute, or return 'normal' if not defined for that Pitch.

If the pitch is not found, None will be returned.

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> n2.notehead = 'diamond'
>>> c1 = chord.Chord([n1, n2])
>>> c1.getNotehead(c1.pitches[1])
'diamond'

>>> c1.getNotehead(c1.pitches[0])
'normal'

>>> c1.getNotehead(pitch.Pitch('A#6')) is None
True

Will work if the two notes are equal in pitch

>>> c1.getNotehead(note.Note('G4'))
'diamond'
r   N)r~   r   rD   noteheadrJ   r0  r   s      r)   getNoteheadChord.getNotehead  sg    2 1gAAww!|zz!  Aww!|zz!  r(   c                    [        US5      (       a  UR                  nU R                   H   nUR                  UL d  M  UR                  s  $    U R                   H!  nUR                  U:X  d  M  UR                  s  $    g)aC  
Given a pitch in this Chord, return an associated noteheadFill
attribute, or return None if not defined for that Pitch.

If the pitch is not found, None will also be returned.

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> n2.noteheadFill = True
>>> c1 = chord.Chord([n1, n2])
>>> c1.getNoteheadFill(c1.pitches[1])
True

>>> print(c1.getNoteheadFill(c1.pitches[0]))
None

>>> c1.getNoteheadFill(pitch.Pitch('A#6')) is None
True

Will work if the two notes are equal in pitch

>>> c1.getNoteheadFill(note.Note('G4'))
True

Returns None if the pitch is not in the Chord:

r   N)r~   r   rD   noteheadFillr  s      r)   getNoteheadFillChord.getNoteheadFill  sg    8 1gAAww!|~~%  Aww!|~~%  r(   c                    [        US5      (       a  UR                  nU R                   H   nUR                  UL d  M  UR                  s  $    U R                   H!  nUR                  U:X  d  M  UR                  s  $    g)aa  
Given a pitch in this Chord, return an associated stem attribute, or
return 'unspecified' if not defined for that Pitch or None.

If the pitch is not found, None will be returned.

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> n2.stemDirection = 'double'
>>> c1 = chord.Chord([n1, n2])
>>> c1.getStemDirection(c1.pitches[1])
'double'

>>> c1.getStemDirection(c1.pitches[0])
'unspecified'

Will work if the two pitches are equal in pitch

>>> c1.getStemDirection(note.Note('G4'))
'double'

Returns None if a Note or Pitch is not in the Chord

>>> c1.getStemDirection(pitch.Pitch('A#4')) is None
True

r   N)r~   r   rD   stemDirectionr  s      r)   getStemDirectionChord.getStemDirection	  sg    8 1gAAww!|&  Aww!|&  r(   c                @     X   R                   $ ! [         a     gf = f)a  
Given a pitch in this Chord, return an associated Tie object, or return
None if not defined for that Pitch.

>>> c1 = chord.Chord(['d', 'e-', 'b-'])
>>> t1 = tie.Tie('start')
>>> c1.setTie(t1, c1.pitches[2])  # just to b-
>>> c1.getTie(c1.pitches[2]) == t1
True

>>> c1.getTie(c1.pitches[0]) is None
True

All notes not in chord return None

>>> c1.getTie(pitch.Pitch('F#2')) is None
True

>>> c1.getTie('B-')
<music21.tie.Tie start>
N)r   r   )rJ   r0  s     r)   getTieChord.getTie1  s%    ,	7;; 		s    
c                b     X   nUR                  U S9$ ! [         a    [        SU 35      ef = f)a  
For a given Pitch in this Chord, return the
:class:`~music21.volume.Volume` object.

Raises an exception if the pitch isn't in the chord
(TODO: consider changing to be like notehead, etc.)

>>> c = chord.Chord('C4 F4')
>>> c[0].volume = 2
>>> c.getVolume('C4')
<music21.volume.Volume realized=0.02>

>>> c.getVolume('F4')  # default
<music21.volume.Volume realized=0.71>

>>> c.getVolume('G4')
Traceback (most recent call last):
music21.chord.ChordException: the given pitch is not in the Chord: G4
r   %the given pitch is not in the Chord: )r   r   r   )rJ   r0  rb   s      r)   	getVolumeChord.getVolumeL  sD    (	NA<<D<11 	N #H!LMM	Ns    .c                *   U R                   (       a  U R                  n[        R                  " U5      n[        R                  " U5      nSnU H!  nUR
                  UR
                  :w  d  M  UnM#     [        R                  " U5      n[        U5      $ g)a  
Return a Z relation if it exists, otherwise return None.

>>> chord.fromIntervalVector((1, 1, 1, 1, 1, 1))
<music21.chord.Chord C C# E F#>

>>> chord.fromIntervalVector((1, 1, 1, 1, 1, 1)).getZRelation()
<music21.chord.Chord C D- E- G>

Z relation will always be zero indexed:

>>> c = chord.Chord('D D# F# G#')
>>> c.getZRelation()
<music21.chord.Chord C D- E- G>

>>> chord.Chord('C E G').getZRelation() is None
True
N)hasZRelationr5  r   addressToIntervalVectorintervalVectorToAddress
forteClassaddressToTransposedNormalFormr   )rJ   r5  r   	addressesrS   thisAddressprimes          r)   getZRelationChord.getZRelationg  s    & !%!8!8../ABA66q9I E())-?-J-JJ'E  ) 88?E<r(   c                    [        U R                  5       5      [        [        S U R                   5       5      5      :w  a  gg)at  
Returns True if for any given pitchClass there is at most one spelling of the note
(in any octave).

>>> cChord = chord.Chord('C4 E4 G4 C5')
>>> cChord.hasAnyEnharmonicSpelledPitches()
False

Notice that having a C in two different octaves is no problem.  However, this is False:

>>> cChord = chord.Chord('C4 E4 G4 B#4')
>>> cChord.hasAnyEnharmonicSpelledPitches()
True
c              3  8   #    U  H  oR                   v   M     g 7fr5   rH  rD  s     r)   r9   7Chord.hasAnyEnharmonicSpelledPitches.<locals>.<genexpr>  s     8VAr}  TF)rQ   _unorderedPitchClassesr   r   rf   s    r)   hasAnyEnharmonicSpelledPitches$Chord.hasAnyEnharmonicSpelledPitches  s4     t**,-S8V8V5V1WWr(   c                    [        [        S U R                   5       5      5      [        [        S U R                   5       5      5      :w  a  gg)a0  
Returns True if for any diatonic note (e.g., C or C# = C) there are two or more
different notes (such as E and E-) in the chord. If there are no repeated
scale degrees, return False.

>>> cChord = chord.Chord(['C', 'E', 'E-', 'G'])
>>> cChord.hasAnyRepeatedDiatonicNote()
True

This routine is helpful for anything that works with Generic intervals and chord
steps such as `.third` which makes sure that checking for root, second, third,
..., seventh will actually find all the different notes.

This following example returns False because chromatically identical notes of
different scale degrees do not count as a repeated diatonic note.
(See :meth:`~music21.chord.Chord.hasAnyEnharmonicSpelledPitches` for that method)

>>> other = chord.Chord(['C', 'E', 'F-', 'G'])
>>> other.hasAnyRepeatedDiatonicNote()
False
c              3  8   #    U  H  oR                   v   M     g 7fr5   r  rD  s     r)   r9   3Chord.hasAnyRepeatedDiatonicNote.<locals>.<genexpr>  s     0<a66<r}  c              3  8   #    U  H  oR                   v   M     g 7fr5   r  rD  s     r)   r9   r    s     <Z\VV\r}  TF)rQ   r   r   rf   s    r)   hasAnyRepeatedDiatonicNote Chord.hasAnyRepeatedDiatonicNote  s:    , s04<<001S<ZT\\<Z9Z5[[r(   c               l   Uc  U R                  5       nUc  [        S5      eU R                  U5      nU R                   Hr  n[        R
                  " X$5      nUR                  R                  R                  U:X  d  M?  UR                  R                  UR                  R                  -
  S:w  d  Mr    g   g)a  
Returns True if chordStep above testRoot (or self.root()) has two
or more different notes (such as E and E-) in it.  Otherwise
returns False.

>>> cChord = chord.Chord(['G2', 'E4', 'E-5', 'C6'])
>>> cChord.hasRepeatedChordStep(3)
True

>>> cChord.hasRepeatedChordStep(5)
False

z.Cannot run hasRepeatedChordStep without a rootr   TF)r  r   intervalFromChordStepr   r   r'  r)  r*  mod7	chromaticmod12)rJ   r  r  firstr   thisIntervals         r)   hasRepeatedChordStepChord.hasRepeatedChordStep  s     yy{H$%UVV**95I#,,XAL$$,,11Y>))//%//2G2GG1L	 & r(   c                  Uc   U R                  5       nUc  [        S5      eU R                   HA  n[        R                  " X#5      nUR
                  R                  R                  U:X  d  M?  Us  $    g! [         a    [        S5      ef = f)a  
Exactly like semitonesFromChordStep, except it returns the interval
itself instead of the number of semitones:

>>> cmaj = chord.Chord(['C', 'E', 'G'])
>>> cmaj.intervalFromChordStep(3)  # will return the interval between C and E
<music21.interval.Interval M3>

>>> cmaj.intervalFromChordStep(5)  # will return the interval between C and G
<music21.interval.Interval P5>

>>> print(cmaj.intervalFromChordStep(6))
None

Nz/Cannot run intervalFromChordStep without a root)r  r   r   r   r'  r)  r*  r  )rJ   r  r  r   r  s        r)   r  Chord.intervalFromChordStep  s      X99; $%VWWI#,,XAL$$,,11Y>## &  " X$%VWWXs   A5 5B)r9  r  transposeOnSetc                   g r5   r"   rJ   newInversionr9  r  r  s        r)   rF  Chord.inversion  r   r(   c                   g r5   r"   r  s        r)   rF  r   	  r   r(   c                  U R                   (       d  gUb  UnOU R                  5       nUb   [        U5      nU R                  XeU5        gSU R                  ;  a  U(       d  Ub(   Ub  U R                  5       c  g U R                  U5      $ SU R                  ;   a  U R                  S   $ g! [        [        4 a    [        S[        U5       35      ef = f! [
         a    [        S5      ef = f)ah  
Find the chord's inversion or (if called with a number) set the chord to
the new inversion.

When called without a number argument, returns an integer (or None)
representing which inversion (if any)
the chord is in. The Chord does not have to be complete, in which case
this function determines the inversion by looking at the relationship
of the bass note to the root.

Returns a maximum value of 5 for the fifth inversion of a thirteenth chord.
Returns 0 if the bass to root interval is a unison
or if interval is not a common inversion (1st-5th).
The octave of the bass and root are irrelevant to this calculation of inversion.
Returns None if the Chord has no pitches.

>>> g7 = chord.Chord(['g4', 'b4', 'd5', 'f5'])
>>> g7.inversion()
0
>>> g7.inversion(1)
>>> g7
<music21.chord.Chord B4 D5 F5 G5>

With implicit octaves, D becomes the bass (since octaves start on C):

>>> g7_implicit = chord.Chord(['g', 'b', 'd', 'f'])
>>> g7_implicit.inversion()
2

Note that in inverting a chord with implicit octaves, some
pitches will gain octave designations, but not necessarily all of them
(this behavior might change in the future):

>>> g7_implicit.inversion(1)
>>> g7_implicit
<music21.chord.Chord B D5 F5 G5>

Examples of each inversion:

>>> cTriad1stInversion = chord.Chord(['E1', 'G1', 'C2'])
>>> cTriad1stInversion.inversion()
1

>>> cTriad2ndInversion = chord.Chord(['G1', 'E2', 'C2'])
>>> cTriad2ndInversion.inversion()
2

>>> dSeventh3rdInversion = chord.Chord(['C4', 'B4'])
>>> dSeventh3rdInversion.bass(pitch.Pitch('B4'))
>>> dSeventh3rdInversion.inversion()
3

>>> gNinth4thInversion = chord.Chord(['G4', 'B4', 'D5', 'F5', 'A4'])
>>> gNinth4thInversion.bass(pitch.Pitch('A4'))
>>> gNinth4thInversion.inversion()
4

>>> bbEleventh5thInversion = chord.Chord(['B-', 'D', 'F', 'A', 'C', 'E-'])
>>> bbEleventh5thInversion.bass(pitch.Pitch('E-4'))
>>> bbEleventh5thInversion.inversion()
5

Repeated notes do not affect the inversion:

>>> gMajRepeats = chord.Chord(['G4', 'B5', 'G6', 'B6', 'D7'])
>>> gMajRepeats.inversion(2)
>>> gMajRepeats
<music21.chord.Chord D7 G7 B7 G8 B8>

>>> gMajRepeats.inversion(3)
Traceback (most recent call last):
music21.chord.ChordException: Could not invert chord: inversion may not exist

If testRoot is True then that temporary root is used instead of self.root().

Get the inversion for a seventh chord showing different roots

>>> dim7 = chord.Chord('B4 D5 F5 A-5 C6 E6 G6')
>>> dim7.inversion()
0
>>> dim7.inversion(testRoot=pitch.Pitch('D5'))
6
>>> dim7.inversion('six-four')
Traceback (most recent call last):
music21.chord.ChordException: Inversion must be an integer, got: <class 'str'>

Chords without pitches or otherwise impossible chords return -1, indicating
no normal inversion.

>>> chord.Chord().inversion(testRoot=pitch.Pitch('C5'))
-1

For Harmony subclasses, this method does not check to see if
the inversion is reasonable according to the figure provided.
see :meth:`~music21.harmony.ChordSymbol.inversionIsValid`
for checker method on ChordSymbolObjects.

If only two pitches given, an inversion is still returned, often as
if it were a triad:

>>> chord.Chord('C4 G4').inversion()
0
>>> chord.Chord('G4 C5').inversion()
2

If transposeOnSet is False then setting the inversion simply
sets the value to be returned later, which might be useful for
cases where the chords are poorly spelled, or there is an added note.

* Changed in v8: deal with chords without pitches
r   Nz#Inversion must be an integer, got: rF  zNot a normal inversion)r   r  rs   r   rt   r   r<   _setInversionrC   r>  _findInversion)rJ   r  r9  r  r  	rootPitchint_newInversions          r)   rF  r  	  s   n || I		I#a#&|#4  /NK0Th>R?$		(; )<
 &&y11DOO+??;// 	* a$'J4P\K]J^%_``a " ?$%=>>?s   B- &C -(CC.c                   USL a  XR                   S'   g[        U R                  5      S-   nUnSU R                   ;   a  U R                   S	 SU R                   ;   a  U R                   S	 U R                  SS9nXe:w  a  US:  a  [	        U R                  5      R
                  nU R                  5       nUR
                  U:  aI  UR                  b  U=R                  S	-  sl        OUR                  S	-   Ul        UR
                  U:  a  MI  U R                  5         U R                  SS9nUS	-  nXe:w  a  US:  a  M  US:X  a  [        S
5      eU R                  SS9  g)z$
Helper function for inversion(int)
FrF  Nr  r>  Tr9  r   r   z/Could not invert chord: inversion may not existr   )rC   rQ   r   rF  r  rd  r>  rb  rc  rz   r   r  )	rJ   r  r  r  numberOfRunsBeforeCrashingsoughtInversioncurrentInversioncurrentMaxMiditempBassPitchs	            r)   r  Chord._setInversion	  sQ    U"+7OOK(%(%6%:"&$//),T__$'>>t>416PST6T .11N IIKM""^3 ''3!((A-(+8+G+G!+KM(	  ""^3 OO#~~4~8&!+& 16PST6T &* !RSS4(r(   c                v   [         R                  " U R                  5       5      nSUl        [         R                  " U5      nSUl        [        R
                  " UU5      R                  nUS:X  a  SnO8US:X  a  SnO/US:X  a  SnO&US:X  a  SnOUS:X  a  SnOUS:X  a  SnOUS:X  a  SnOS	nXPR                  S
'   U$ )z"
Helper function for .inversion()
r   r  r   rt  r  r3  r  r  r   rF  )rp   rq   r>  rb  r   notesToGenericsimpleDirectedrI  )rJ   r  r  tempRootPitch
bassToRootinvs         r)   r  Chord._findInversion	  s     diik2 i0 ,,]-:<<JN 	 ?C1_C1_C1_C1_C1_C1_CC $'K 
r(   c                n    U R                  5       nUS:X  a  g/ SQn/ SQnU R                  5       (       d  U R                  b"  SUs=::  a
  S::  a   X!   $   [        SU< 35      eU R	                  5       (       a"  SUs=::  a
  S::  a   X1   $   [        S	U< 35      e[        S
5      e! [         a     gf = f)a  
Returns an integer representing the common abbreviation for the
inversion the chord is in. If chord is not in a common inversion,
returns None.

Third inversion sevenths return 42 not 2.

>>> a = chord.Chord(['G3', 'B3', 'F3', 'D3'])
>>> a.inversionName()
43
Nr   )r  A   +   *   )r!   rt  @   r   r3  z&Not a normal inversion for a seventh: r  z$Not a normal inversion for a triad: z3Not a triad or Seventh, cannot determine inversion.)rF  r   	isSeventhrk  isTriad)rJ   r  seventhMappingtriadMappings       r)   inversionNameChord.inversionName	  s    	.."C "9(">>t||7C}1}%**  %'McW%UVV\\^^C}1}#((  %'KC7%STT !VWW)  		s   B' '
B43B4c                    Sn U R                  5       nUS:X  a  U$ US:X  a  g[        R                  R                  U   S-   $ ! [         a    Us $ f = f)aL  
A helper method to return a readable inversion text (with capitalization) for a chord:

>>> chord.Chord('C4 E4 G4').inversionText()
'Root Position'
>>> chord.Chord('E4 G4 C5').inversionText()
'First Inversion'

>>> chord.Chord('B-3 C4 E4 G4').inversionText()
'Third Inversion'

>>> chord.Chord().inversionText()
'Unknown Position'
zUnknown Positionr   r   zRoot Positionz
 Inversion)rF  r   r   numberToolsordinals)rJ   UNKNOWNr  s      r)   inversionTextChord.inversionText
  sd     %	.."C "9N!8"!!**3/,>>  	N	s   A AApermitAnyInversionc                   U R                   nUS:X  a  U R                  US9(       a  gUS:X  a?  U R                  US9(       a  gU R                  US9(       a  gU R	                  US9(       a  gg)a  
returns True if the chord is an Augmented 6th chord in normal inversion.
(that is, in first inversion for Italian and German and second for French and Swiss)

>>> c = chord.Chord(['A-3', 'C4', 'E-4', 'F#4'])
>>> c.isAugmentedSixth()
True

Spelling matters

>>> c.pitches[3].getEnharmonic(inPlace=True)
>>> c
<music21.chord.Chord A-3 C4 E-4 G-4>
>>> c.isAugmentedSixth()
False

Italian:

>>> c = chord.Chord(['A-3', 'C4', 'F#4'])
>>> c.isAugmentedSixth()
True

If `permitAnyInversion` is True then any inversion is allowed.

r3  r&  Tr  F)pitchClassCardinalityisItalianAugmentedSixthisFrenchAugmentedSixthisGermanAugmentedSixthisSwissAugmentedSixth)rJ   r'  cardinalitys      r)   isAugmentedSixthChord.isAugmentedSixth1
  su    : 00! < <Pb < c!**>P*Q,,@R,S++?Q+Rr(   c                (    U R                  SSS5      $ )ax  
Returns True if chord is an Augmented Triad, that is,
if it contains only notes that are
either in unison with the root, a major third above the root,
or an augmented fifth above the
root. Additionally, the Chord must contain at least one of each third and
fifth above the root.

The chord might not seem to need to be spelled correctly
since incorrectly spelled Augmented Triads are
usually augmented triads in some other inversion
(e.g. C-E-Ab is a second-inversion augmented triad; C-Fb-Ab
is in first inversion).  However, B#-Fb-Ab does return False as it is not a
stack of two major thirds in any inversion.

Returns False if is not an augmented triad.

>>> c = chord.Chord(['C4', 'E4', 'G#4'])
>>> c.isAugmentedTriad()
True
>>> c = chord.Chord(['C4', 'E4', 'G4'])
>>> c.isAugmentedTriad()
False

Other spellings will give other roots!

>>> c = chord.Chord(['C4', 'E4', 'A-4'])
>>> c.isAugmentedTriad()
True
>>> c.root()
<music21.pitch.Pitch A-4>

>>> c = chord.Chord(['C4', 'F-4', 'A-4'])
>>> c.isAugmentedTriad()
True
>>> c = chord.Chord(['B#4', 'F-4', 'A-4'])
>>> c.isAugmentedTriad()
False

>>> chord.Chord().isAugmentedTriad()
False
)r3  r^  r   r  r  _checkTriadTyperf   s    r)   isAugmentedTriadChord.isAugmentedTriad[
  s    X ##J155r(   c                   U R                  SS9n[        UR                  5      S:X  a  g[        UR                  5      S:X  a`  U R                  5       nUR	                  SS9n[
        R                  " UR                  S   UR                  S   5      nUR                  5       $ [        UR                  5      S:X  a<  U R                  5       SL d  U R                  5       SL a  U R                  5       S:w  a  ggg)a  
Returns True if the chord is:

* one pitch (always consonant)

* two pitches: uses :meth:`~music21.interval.Interval.isConsonant()` , which
     checks if the interval is a major or minor third or sixth or perfect fifth.

* three pitches: if chord is a major or minor triad not in second inversion.

These rules define all common-practice consonances
(and earlier back to about 1300 all imperfect consonances)

>>> c1 = chord.Chord(['C3', 'E4', 'G5'])
>>> c1.isConsonant()
True

>>> c2 = chord.Chord(['G3', 'E-4', 'C5'])
>>> c2.isConsonant()
False

>>> c3 = chord.Chord(['F2', 'A2', 'C3', 'E-3'])
>>> c3.isConsonant()
False

>>> c4 = chord.Chord(['C1', 'G1', 'C2', 'G2', 'C3', 'G3'])
>>> c4.isConsonant()
True

>>> c5 = chord.Chord(['G1', 'C2', 'G2', 'C3', 'G3'])
>>> c5.isConsonant()
False

>>> c6 = chord.Chord(['F#'])
>>> c6.isConsonant()
True

>>> c7 = chord.Chord(['C1', 'C#1', 'D-1'])
>>> c7.isConsonant()
False

Spelling does matter:

>>> c8 = chord.Chord(['D-4', 'G#4'])
>>> c8.isConsonant()
False

>>> c9 = chord.Chord(['D3', 'A2', 'D2', 'D2', 'A4'])
>>> c9.isConsonant()
True

>>> c10 = chord.Chord(['D3', 'A2', 'D2', 'D2', 'A1'])
>>> c10.isConsonant()
False

>>> c11 = chord.Chord(['F3', 'D4', 'A4'])
>>> c11.isConsonant()
True

>>> c12 = chord.Chord(['F3', 'D4', 'A4', 'E#4'])
>>> c12.isConsonant()
False

OMIT_FROM_DOCS

Weird things used to happen when some notes have octaves and some don't:

>>> c13 = chord.Chord(['A4', 'B4', 'A'])
>>> c14 = c13.removeRedundantPitchNames(inPlace=False)
>>> c14
<music21.chord.Chord A4 B4>

>>> i14 = interval.Interval(c14.pitches[0], c14.pitches[1])
>>> i14
<music21.interval.Interval M2>

>>> i14.isConsonant()
False

>>> c13.isConsonant()
False

Fr   r   Tr  r   r3  )removeRedundantPitchNamesrQ   r   rY  r%  r   r'  isConsonantrM  rR  rF  )rJ   c2c3c4r   s        r)   r8  Chord.isConsonant
  s    l ++E+:rzz?a_!$$&B**5*9B!!"**Q-A?A==?"_!""$,0A0A0Ct0K)Q.r(   c                $    U R                  S5      $ )a  
Returns True if chord is a Diminished Seventh, that is,
if it contains only notes that are
either in unison with the root, a minor third above the root,
a diminished fifth, or a minor seventh
above the root. Additionally, must contain at least one of
each third and fifth above the root.
Chord must be spelled correctly. Otherwise returns false.

>>> a = chord.Chord(['c', 'e-', 'g-', 'b--'])
>>> a.isDiminishedSeventh()
True

>>> chord.Chord().isDiminishedSeventh()
False
)r   r3  rt  	   isSeventhOfTyperf   s    r)   isDiminishedSeventhChord.isDiminishedSeventh
  s    $ ##L11r(   c                    U R                  5       (       d  gU R                  5       nU R                   H5  n[        R                  " X#5      nUR
                  R                  U;  d  M5    g   g)aP  
Returns True if chord is a seventh chord of a particular type
as specified by intervalArray.  For instance `.isDiminishedSeventh()`
is just a thin wrapper around `.isSeventhOfType([0, 3, 6, 9])`
and `isDominantSeventh()` has intervalArray([0, 4, 7, 10])

intervalArray can be any iterable.

Though it checks on intervalArray, it does make sure that it is a
seventh chord, not D--, D##, G, B-

>>> chord.Chord('C E G B-').isSeventhOfType((0, 4, 7, 10))
True
>>> chord.Chord('C E G B-').isSeventhOfType((0, 3, 7, 10))
False
>>> chord.Chord('D-- D## G B-').isSeventhOfType((0, 4, 7, 10))
False
FT)r  r  r   r   r'  r  r  )rJ   intervalArrayr  r   r  s        r)   r@  Chord.isSeventhOfType  sY    & ~~yy{I#,,T=L%%++=@ & r(   c                (    U R                  SSS5      $ )a  
Returns True if chord is a Diminished Triad, that is,
if it contains only notes that are
either in unison with the root, a minor third above the
root, or a diminished fifth above the
root. Additionally, must contain at least one of each
third and fifth above the root.
Chord must be spelled correctly. Otherwise returns false.

>>> cChord = chord.Chord(['C', 'E-', 'G-'])
>>> cChord.isDiminishedTriad()
True
>>> other = chord.Chord(['C', 'E-', 'F#'])
>>> other.isDiminishedTriad()
False

OMIT_FROM_DOCS

>>> chord.Chord().isDiminishedTriad()
False
>>> other = chord.Chord(['C', 'E-', 'F#', 'G-'])
>>> other.isDiminishedTriad()
False

This is in an OMIT section
)r3  
   r   r3  rt  r2  rf   s    r)   isDiminishedTriadChord.isDiminishedTriad#  s    8 ##J155r(   c                $    U R                  S5      $ )a  
Returns True if chord is a Dominant Seventh, that is,
if it contains only notes that are
either in unison with the root, a major third above the root,
a perfect fifth, or a major seventh
above the root. Additionally, must contain at least one of
each third and fifth above the root.
Chord must be spelled correctly. Otherwise returns false.

>>> a = chord.Chord(['b', 'g', 'd', 'f'])
>>> a.isDominantSeventh()
True

>>> chord.Chord().isDominantSeventh()
False

>>> c2 = chord.Chord('C4 E4 G4 A#4')
>>> c2.isDominantSeventh()
False
)r   r  r  rG  r?  rf   s    r)   rN  Chord.isDominantSeventhA  s    , ##M22r(   c                &    U R                   SS S:H  $ )a  
Returns True if chord is a Diminished Seventh, that is,
if it contains only notes that are
either in unison with the root, a minor third above the root,
a diminished fifth, or a diminished seventh
above the root. Additionally, must contain at least one of
each third and fifth above the root.
Chord MAY BE SPELLED INCORRECTLY. Otherwise returns False.


>>> c = chord.Chord('C D# G- A')
>>> c.isFalseDiminishedSeventh()
True

>>> chord.Chord().isFalseDiminishedSeventh()
False

>>> chord.Chord('C4 E4 G4').isFalseDiminishedSeventh()
False

Correctly spelled diminished seventh chords are also false diminished sevenths.

>>> chord.Chord('C4 E-4 G-4 B--4').isFalseDiminishedSeventh()
True
Nr3  )r     r   )r5  rf   s    r)   isFalseDiminishedSeventhChord.isFalseDiminishedSeventhY  s    6 &&r*j88r(   c               .    U R                  SSU/ SQ5      $ )a3  
Returns True if the chord is a French augmented sixth chord
(flat 6th scale degree in bass, tonic, second scale degree, and raised 4th).

N.B. The root() method of music21.chord.Chord determines
the root based on the note with
the most thirds above it. However, under this definition, a
1st-inversion french augmented sixth chord
resembles a second inversion chord, not the first inversion
subdominant chord it is based
upon. We fix this by adjusting the root. First, however, we
check to see if the chord is
in second inversion to begin with, otherwise it is not
a Fr+6 chord. This is to avoid ChordException errors.

>>> fr6a = chord.Chord(['A-3', 'C4', 'D4', 'F#4'])
>>> fr6a.isFrenchAugmentedSixth()
True

Spelling matters:

>>> fr6b = chord.Chord(['A-3', 'C4', 'D4', 'G-4'])
>>> fr6b.isFrenchAugmentedSixth()
False

>>> fr6b = chord.Chord(['A-3', 'C4', 'E--4', 'F#4'])
>>> fr6b.isFrenchAugmentedSixth()
False

Inversion matters:

>>> fr6c = chord.Chord(['C4', 'D4', 'F#4', 'A-4'])
>>> fr6c.isFrenchAugmentedSixth()
False

Unless `permitAnyInversion` is True

>>> fr6c.isFrenchAugmentedSixth(permitAnyInversion=True)
True

* Changed in v7: `permitAnyInversion` added

OMIT_FROM_DOCS

>>> chord.Chord().isFrenchAugmentedSixth()
False

>>> fr6d = chord.Chord(['A-3', 'C-4', 'D4', 'F#4'])
>>> fr6d.isFrenchAugmentedSixth()
False
)r     r   r  ))M3zm-6d5zA-4)m7zM-2_isAugmentedSixthHelperrJ   r'  s     r)   r+  Chord.isFrenchAugmentedSixthv  s$    h ++9	
 	
r(   c               .    U R                  SSU/ SQ5      $ )a  
Returns True if the chord is a German augmented sixth chord
(flat 6th scale degree in bass, tonic, flat third scale degree, and raised 4th).


>>> gr6a = chord.Chord(['A-3', 'C4', 'E-4', 'F#4'])
>>> gr6a.isGermanAugmentedSixth()
True

Spelling matters (see isSwissAugmentedSixth)

>>> gr6b = chord.Chord(['A-3', 'C4', 'D#4', 'F#4'])
>>> gr6b.isGermanAugmentedSixth()
False

Inversion matters:

>>> gr6c = chord.Chord(['C4', 'E-4', 'F#4', 'A-4'])
>>> gr6c.isGermanAugmentedSixth()
False

unless `permitAnyInversion` is True:

>>> gr6c.isGermanAugmentedSixth(permitAnyInversion=True)
True

* Changed in v7: `permitAnyInversion` added

OMIT_FROM_DOCS

>>> chord.Chord().isGermanAugmentedSixth()
False

>>> gr6d = chord.Chord(['A-3', 'C-4', 'E-4', 'F#4'])
>>> gr6d.isGermanAugmentedSixth()
False

r     r   r   )d3zA-6rS  d7zA-2rV  rX  s     r)   r,  Chord.isGermanAugmentedSixth  s$    N ++9	
 	
r(   c                $    U R                  S5      $ )a  
Returns True if chord is a Half Diminished Seventh, that is,
if it contains only notes that are
either in unison with the root, a minor third above the root, a
diminished fifth, or a major seventh
above the root. Additionally, must contain at least one of each third,
fifth, and seventh above the root.
Chord must be spelled correctly. Otherwise returns false.


>>> c1 = chord.Chord(['C4', 'E-4', 'G-4', 'B-4'])
>>> c1.isHalfDiminishedSeventh()
True

Incorrectly spelled chords are not considered half-diminished sevenths
>>> c2 = chord.Chord(['C4', 'E-4', 'G-4', 'A#4'])
>>> c2.isHalfDiminishedSeventh()
False

Nor are incomplete chords
>>> c3 = chord.Chord(['C4', 'G-4', 'B-4'])
>>> c3.isHalfDiminishedSeventh()
False

>>> chord.Chord().isHalfDiminishedSeventh()
False
)r   r3  rt  rG  r?  rf   s    r)   isHalfDiminishedSeventhChord.isHalfDiminishedSeventh  s    : ##M22r(   c                    U R                   SS S:w  a  gU R                  nUc  gU R                   HD  n[        R                  " U R                  5       U5      nUR                  R                  S;  d  MD    g   g)a  
Returns True if the chord is an incomplete Major triad, or, essentially,
a dyad of root and major third


>>> c1 = chord.Chord(['C4', 'E3'])
>>> c1.isMajorTriad()
False
>>> c1.isIncompleteMajorTriad()
True

Note that complete major triads return False:

>>> c2 = chord.Chord(['C4', 'E3', 'G5'])
>>> c2.isIncompleteMajorTriad()
False

Remember, MAJOR Triad:

>>> c3 = chord.Chord(['C4', 'E-3'])
>>> c3.isIncompleteMajorTriad()
False

Must be spelled properly

>>> c1 = chord.Chord(['C4', 'F-4'])
>>> c1.isIncompleteMajorTriad()
False

Empty Chords return False

>>> chord.Chord().isIncompleteMajorTriad()
False

OMIT_FROM_DOCS

Swap the two notes:

>>> c1 = chord.Chord(['C####4', 'E----4'])
>>> c1.isIncompleteMajorTriad()
False
Nr  )r  r  F)r   r  Tr5  ro  r   r   r'  r  r  r  rJ   ro  r   r  s       r)   isIncompleteMajorTriadChord.isIncompleteMajorTriad  sp    X ""2A&&0

=I#,,TYY[)DL%%++69 &
 r(   c                    U R                   SS S:w  a  gU R                  nUc  gU R                   HD  n[        R                  " U R                  5       U5      nUR                  R                  S;  d  MD    g   g)aF  
returns True if the chord is an incomplete Minor triad, or, essentially,
a dyad of root and minor third

>>> c1 = chord.Chord(['C4', 'E-3'])
>>> c1.isMinorTriad()
False
>>> c1.isIncompleteMinorTriad()
True
>>> c2 = chord.Chord(['C4', 'E-3', 'G5'])
>>> c2.isIncompleteMinorTriad()
False

OMIT_FROM_DOCS

>>> c3 = chord.Chord(['C4', 'E4'])
>>> c3.isIncompleteMinorTriad()
False

>>> c3 = chord.Chord(['C4', 'D#4'])
>>> c3.isIncompleteMinorTriad()
False

>>> c3 = chord.Chord(['C###4', 'E---4'])
>>> c3.isIncompleteMinorTriad()
False

>>> chord.Chord().isIncompleteMinorTriad()
False
Nr  )r  r3  F)r   r3  Trf  rg  s       r)   isIncompleteMinorTriadChord.isIncompleteMinorTriad8  sp    @ ""2A&&0

=I#,,TYY[)DL%%++69 &
 r(   )restrictDoublingsr'  c               $   U R                  SSUSS/5      nU(       d  gU(       ak  U R                  5       nU R                  nU R                  nU(       d  gU R                   H+  nUR
                  UR
                  :X  a  M  XuLd  M%  XtLd  M+    g   g)a  
Returns True if the chord is a properly spelled Italian augmented sixth chord in
first inversion.  Otherwise returns False.

If restrictDoublings is set to True then only the tonic may be doubled.

>>> c1 = chord.Chord(['A-4', 'C5', 'F#6'])
>>> c1.isItalianAugmentedSixth()
True

Spelling matters:

>>> c2 = chord.Chord(['A-4', 'C5', 'G-6'])
>>> c2.isItalianAugmentedSixth()
False

So does inversion:

>>> c3 = chord.Chord(['F#4', 'C5', 'A-6'])
>>> c3.isItalianAugmentedSixth()
False
>>> c4 = chord.Chord(['C5', 'A-5', 'F#6'])
>>> c4.isItalianAugmentedSixth()
False

If inversions don't matter to you, add `permitAnyInversion=True`:

>>> c3.isItalianAugmentedSixth(permitAnyInversion=True)
True
>>> c4.isItalianAugmentedSixth(permitAnyInversion=True)
True

If doubling rules are turned on then only the tonic can be doubled:

>>> c4 = chord.Chord(['A-4', 'C5', 'F#6', 'C6', 'C7'])
>>> c4.isItalianAugmentedSixth(restrictDoublings=True)
True
>>> c5 = chord.Chord(['A-4', 'C5', 'F#6', 'C5', 'F#7'])
>>> c5.isItalianAugmentedSixth(restrictDoublings=True)
False
>>> c5.isItalianAugmentedSixth(restrictDoublings=False)
True

* Changed in v7: `restrictDoublings` is keyword only.  Added `permitAnyInversion`.
)r3  r  r   r   r]  rS  FT)rW  r  ro  rp  r   rH  )rJ   rm  r'  	aug6checkr  ro  rp  r0  s           r)   r*  Chord.isItalianAugmentedSixthf  s    \ 00M*	
	 99;DJJEJJE \\66UZZ'>am 	 "
 r(   c                N   U R                   SS U:w  a  gU R                  5       (       a  g U(       d  U R                  5       U:w  a  gU R	                  5       nU R
                  nUc  g[        R                  " XV5      nUR                  US   ;  a  gU R                  nUc  g[        R                  " XX5      n	U	R                  US   ;  a  g[        U5      S:  a  gU R                  n
U
c  g[        R                  " XZ5      nUR                  US   ;  a  gg! [         a     gf = f)zU
Helper method for simplifying checking Italian, German, etc. Augmented
Sixth chords
Nr3  Fr   r   Tr  )r5  r  rF  r   r  ro  r   r'  directedSimpleNamerp  rQ   rk  )rJ   chordTableAddressrequiredInversionr'  intervalsCheckr  ro  thirdIntervalrp  fifthIntervalrk  seventhIntervals               r)   rW  Chord._isAugmentedSixthHelper  s"    ""2A&*;;..00	%$..*:>O*O yy{

= ))$6++>!3DD

= ))$6++>!3DD~",,?"++D:--^A5FF9  		s   D 
D$#D$c                L   U R                   SS U:w  a  gU R                  5       (       d  gU R                  5       (       a  gU R                  nU R                  nU R                  5       nUR                  nUR                  U-
  S-  nX:w  a  gUR                  U-
  S-  n	X:w  a  gg)a$  
Helper method for `isMajorTriad`, `isMinorTriad`, `isDiminishedTriad`, and
`isAugmentedTriad` that checks the chordAddress first, then the number
of semitones the third should be and fifth.  Deals with strange corner
cases like C, E###, G--- not being a major triad, as quickly as possible.
Nr3  Fr^  T)r5  r  r  ro  rp  r  r  )
rJ   chordAddressthirdSemitonesfifthSemitonesro  rp  r  rootPitchClassrv  rw  s
             r)   r3  Chord._checkTriadType  s     ""2A&,6||~~..00 



yy{))N:b@*))N:b@*r(   c                (    U R                  SSS5      $ )a  
Returns True if chord is a Major Triad, that is, if it contains only notes that are
either in unison with the root, a major third above the root, or a perfect fifth above the
root. Additionally, must contain at least one of each third and fifth above the root.
Chord must be spelled correctly. Otherwise returns false.

Example:

>>> cChord = chord.Chord(['C', 'E', 'G'])
>>> other = chord.Chord(['C', 'G'])
>>> cChord.isMajorTriad()
True
>>> other.isMajorTriad()
False

Notice that the proper spelling of notes is crucial

>>> chord.Chord(['B-', 'D', 'F']).isMajorTriad()
True
>>> chord.Chord(['A#', 'D', 'F']).isMajorTriad()
False

(See: :meth:`~music21.chord.Chord.forteClassTn` to catch this case; major triads
in the forte system are 3-11B no matter how they are spelled.)

>>> chord.Chord(['A#', 'D', 'F']).forteClassTn == '3-11B'
True


OMIT_FROM_DOCS

Strange chords like [C,E###,G---] used to return True.  E### = G
and G--- = E, so the chord is found to be a major triad, even though it should
not be.  This bug is now fixed.

>>> chord.Chord(['C', 'E###', 'G---']).isMajorTriad()
False
>>> chord.Chord(['C', 'E', 'G', 'E###', 'G---']).isMajorTriad()
False


>>> chord.Chord().isMajorTriad()
False
)r3     r   r  r  r2  rf   s    r)   rM  Chord.isMajorTriad   s    \ ##KA66r(   c                (    U R                  SSS5      $ )a  
Returns True if chord is a Minor Triad, that is, if it contains only notes that are
either in unison with the root, a minor third above the root, or a perfect fifth above the
root. Additionally, must contain at least one of each third and fifth above the root.
Chord must be spelled correctly. Otherwise returns false.

Example:

>>> cChord = chord.Chord(['C', 'E-', 'G'])
>>> cChord.isMinorTriad()
True
>>> other = chord.Chord(['C', 'E', 'G'])
>>> other.isMinorTriad()
False

OMIT_FROM_DOCS

>>> chord.Chord().isMinorTriad()
False
)r3  r  r   r3  r  r2  rf   s    r)   rR  Chord.isMinorTriad0  s    , ##J155r(   )requireIntervallicEvennessc                   U R                   (       d  gU R                  nUR                  S:X  a  U$ UR                  UR                  4nUS;   a  gU(       d  US;   a  gg)a3  
Returns True if the Chord is symmetrical under transposition
and False otherwise.  A pitch-class-based way of looking at this, is
can all the pitch classes be transposed up some number of semitones 1-11
and end up with the same pitch-classes.  Like the dyad F-B can have each
note transposed up 6 semitones and get another B-F = F-B dyad.

A tonally-focused way of looking at this would be to ask, "Are we unable
to distinguish root position vs. some inversion of the basic chord by ear alone?"
For instance, we can see (visually) that C-Eb-Gb-Bbb is a diminished-seventh
chord in root position, while
Eb-Gb-Bbb-C is a diminished-seventh in first inversion.
But if the chord were heard in isolation
it would not be possible to tell the inversion at all, since diminished-sevenths
are transpositionally symmetrical.

With either way of looking at it,
there are fourteen set classes of 2-10 pitch classes have this property,
including the augmented triad:

>>> chord.Chord('C E G#').isTranspositionallySymmetrical()
True

But the major triad is not transpositionally symmetrical:

>>> chord.Chord('C E G').isTranspositionallySymmetrical()
False

The whole-tone scale and the Petrushka chord are both transpositionally symmetrical:

>>> wholeToneAsChord = chord.Chord('C D E F# G# B- C')
>>> wholeToneAsChord.isTranspositionallySymmetrical()
True

>>> petrushka = chord.Chord([0, 1, 3, 6, 7, 9])
>>> petrushka.isTranspositionallySymmetrical()
True

If `requireIntervallicEvenness` is True then only chords that also have
even spacing / evenly divide the octave are considered transpositionally
symmetrical.  The normal cases are the F-B (06) dyad, the augmented triad,
the diminished-seventh chord, and the whole-tone scale collection:

>>> wholeToneAsChord.isTranspositionallySymmetrical(requireIntervallicEvenness=True)
True

>>> petrushka.isTranspositionallySymmetrical(requireIntervallicEvenness=True)
False

Note that complements of these chords (except the whole-tone collection) are
not transpositionally symmetrical if `requireIntervallicEvenness` is required:

>>> chord.Chord([0, 4, 8]).isTranspositionallySymmetrical(requireIntervallicEvenness=True)
True

>>> chord.Chord([1, 2, 3, 5, 6, 7, 9, 10, 11]).isTranspositionallySymmetrical(
...       requireIntervallicEvenness=True)
False

Empty chords and the total aggregate cannot have their inversion determined by ear alone.
So they are `True` with or without `requireIntervallicEvenness`.

>>> chord.Chord().isTranspositionallySymmetrical()
True

>>> chord.Chord(list(range(12))).isTranspositionallySymmetrical()
True

Monads (single-note "chords") cannot be transposed 1-11 semitones to recreate themselves,
so they return `False` by default:

>>> chord.Chord('C').isTranspositionallySymmetrical()
False

But they are the only case where `requireIntervallicEvenness` actually switches from
`False` to `True`, because they do evenly divide the octave.

>>> chord.Chord('C').isTranspositionallySymmetrical(requireIntervallicEvenness=True)
True

11-note chords return `False` in either case:

>>> chord.Chord(list(range(11))).isTranspositionallySymmetrical()
False
Tr   ))r  rt  )r3  r^  )r  rM  )rt  #   )r^  r   )
)r  r>  )r  rQ  )rt  r  )rt     )rt     )r  r>  )r  rQ  )r  rM  )r>  r^  )rG  rt  F)rD   r5  r.  r  )rJ   r  addresslookups       r)   isTranspositionallySymmetrical$Chord.isTranspositionallySymmetricalH  sm    l {{))!#--%%w'9'9: 
 
 )f 9
 /
 r(   c                    [        U R                  5      n[        U5      S:w  a  gU R                  c  gU R                  c  gU R
                  c  gg)a  
Returns True if chord contains at least one of each of Third, Fifth, and Seventh,
and every note in the chord is a Third, Fifth, or Seventh, such that there are no
repeated scale degrees (ex: E and E-). Else return false.

Example:

>>> cChord = chord.Chord(['C', 'E', 'G', 'B'])
>>> cChord.isSeventh()
True
>>> other = chord.Chord(['C', 'D', 'E', 'F', 'G', 'B'])
>>> other.isSeventh()
False

OMIT_FROM_DOCS

>>> chord.Chord().isSeventh()
False
r  FT)r   
pitchNamesrQ   ro  rp  rk  rJ   uniquePitchNamess     r)   r  Chord.isSeventh  sN    * t/ A%::::<<r(   c                    [        U R                  5      n[        U5      S:w  a  gU R                  c  gU R                  c  gU R
                  c  g [        U R                  S5      5      $ ! [         a     gf = f)aZ  
Returns True if chord contains at least one of each of Third, Fifth, Seventh, and Ninth
and every note in the chord is a Third, Fifth, Seventh, or Ninth, such that there are no
repeated scale degrees (ex: E and E-). Else return false.

Example:

>>> cChord = chord.Chord(['C', 'E', 'G', 'B', 'D'])
>>> cChord.isNinth()
True
>>> other = chord.Chord(['C', 'E', 'F', 'G', 'B'])
>>> other.isNinth()
False

OMIT_FROM_DOCS

>>> chord.Chord().isNinth()
False

>>> chord.Chord('C C# C## C### C###').isNinth()
False

>>> chord.Chord('C C# E B D').isNinth()
False

>>> chord.Chord('C E G C- D').isNinth()
False
r  Fr  )	r   r  rQ   ro  rp  rk  r   r  r   r  s     r)   isNinthChord.isNinth  sz    < t/ A%::::<<	))!,-- 	 	s   A+ +
A87A8c               .    U R                  SSU/ SQ5      $ )a  
Returns true if it is a respelled German augmented 6th chord with
sharp 2 instead of flat 3.  This chord has many names,
Swiss Augmented Sixth, Alsatian Chord, English A6, Norwegian, etc.
as well as doubly-augmented sixth, which is a bit of a misnomer since
it is the 4th that is doubly augmented, not the sixth.

>>> chord.Chord('A-4 C5 D#5 F#6').isSwissAugmentedSixth()
True

Respelled as a German Augmented Sixth does not count:

>>> chord.Chord('A-4 C5 E-5 F#6').isSwissAugmentedSixth()
False

Inversions matter:

>>> ch3 = chord.Chord('F#4 D#5 C6 A-6')
>>> ch3.isSwissAugmentedSixth()
False

unless `permitAnyInversion` is given:

>>> ch3.isSwissAugmentedSixth(permitAnyInversion=True)
True

* Changed in v7: `permitAnyInversion` added
r[  r  ))m3zM-6)dd5zAA-4r_  rV  rX  s     r)   r-  Chord.isSwissAugmentedSixth  s#    : ++;	
 	
r(   c                    [        U R                  5      n[        U5      S:X  a#  U R                  (       a  U R                  (       a  gg)a}  
Returns True if this Chord is a triad of some sort.  It could even be a rather
exotic triad so long as the chord contains at least one Third and one Fifth and
all notes have the same name as one of the three notes.

Note: only returns True if triad is spelled correctly.

Note the difference of "containsTriad" vs. "isTriad":
A dominant-seventh chord is NOT a triad, but it contains two triads.

>>> cChord = chord.Chord(['C4', 'E4', 'A4'])
>>> cChord.isTriad()
True

>>> other = chord.Chord(['C', 'D', 'E', 'F', 'G'])
>>> other.isTriad()
False

>>> incorrectlySpelled = chord.Chord(['C', 'D#', 'G'])
>>> incorrectlySpelled.isTriad()
False

>>> incorrectlySpelled.pitches[1].getEnharmonic(inPlace=True)
>>> incorrectlySpelled
<music21.chord.Chord C E- G>
>>> incorrectlySpelled.isTriad()
True

OMIT_FROM_DOCS

>>> chord.Chord().isTriad()
False
>>> chord.Chord('C4 E4 G4 B#4').isTriad()
False
r3  TF)r   r  rQ   ro  rp  r  s     r)   r  Chord.isTriad:  s4    J t/ A%$**r(   c               "    U R                  SUS9$ )a  
Remove all but one instance of a pitch that appears twice.

It removes based on the name of the note and the octave, so the same
note name in two different octaves is retained.

If `inPlace` is True, a copy is not made and a list of deleted pitches is returned;
otherwise make and return a copy.

>>> c1 = chord.Chord(['c2', 'e3', 'g4', 'e3'])
>>> c1
<music21.chord.Chord C2 E3 G4 E3>

>>> removedList = c1.removeRedundantPitches(inPlace=True)
>>> c1
<music21.chord.Chord C2 E3 G4>
>>> removedList
[<music21.pitch.Pitch E3>]

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

>>> c2 = chord.Chord(['c2', 'e3', 'g4', 'c5'])
>>> c2c = c2.removeRedundantPitches(inPlace=False)
>>> c2c
<music21.chord.Chord C2 E3 G4 C5>

It is a known bug that because pitch.nameWithOctave gives
the same value for B-flat in octave 1 as B-natural in octave
negative 1, negative octaves can screw up this method.
With all the things left to do for music21, it doesn't seem
a bug worth squashing at this moment, but FYI:

>>> p1 = pitch.Pitch('B-')
>>> p1.octave = 1
>>> p2 = pitch.Pitch('B')
>>> p2.octave = -1
>>> c3 = chord.Chord([p1, p2])
>>> removedPitches = c3.removeRedundantPitches(inPlace=True)
>>> c3.pitches
(<music21.pitch.Pitch B-1>,)

>>> c3.pitches[0].name
'B-'
>>> c3.pitches[0].octave
1
>>> removedPitches
[<music21.pitch.Pitch B-1>]
>>> removedPitches[0].name
'B'
>>> removedPitches[0].octave
-1

The first pitch survives:

>>> c3.pitches[0] is p1
True

>>> c3.pitches[0] is p2
False

* Changed in v6: inPlace defaults to False.
r   r   r  rJ   r   s     r)   r%  Chord.removeRedundantPitchesd  s%    @ 445E=D 5 F 	Fr(   c               "    U R                  SUS9$ )a  
Remove all but the FIRST instance of a pitch class with more than one
instance of that pitch class.

If `inPlace` is True, a copy is not made and a list of deleted pitches is returned;
otherwise a copy is made and that copy is returned.

>>> c1 = chord.Chord(['c2', 'e3', 'g4', 'e3'])
>>> removed = c1.removeRedundantPitchClasses(inPlace=True)
>>> c1.pitches
(<music21.pitch.Pitch C2>, <music21.pitch.Pitch E3>, <music21.pitch.Pitch G4>)

>>> c2 = chord.Chord(['c5', 'e3', 'g4', 'c2', 'e3', 'f-4'])
>>> removed = c2.removeRedundantPitchClasses(inPlace=True)
>>> c2.pitches
(<music21.pitch.Pitch C5>, <music21.pitch.Pitch E3>, <music21.pitch.Pitch G4>)

* Changed in v6: inPlace defaults to False.
r  r   r  r  s     r)   removeRedundantPitchClasses!Chord.removeRedundantPitchClasses  s#    ( 44\=D 5 F 	Fr(   c               "    U R                  SUS9$ )a  
Remove all but the FIRST instance of a pitch class with more than one
instance of that pitch name regardless of octave (but note that
spelling matters, so that in the example, the F-flat stays even
though there is already an E.)

If `inPlace` is True, a copy is not made and a list of deleted pitches is returned;
otherwise a copy is made and that copy is returned.

>>> c2 = chord.Chord(['c5', 'e3', 'g4', 'c2', 'e3', 'f-4'])
>>> c2
<music21.chord.Chord C5 E3 G4 C2 E3 F-4>

>>> rem = c2.removeRedundantPitchNames(inPlace=True)
>>> c2
<music21.chord.Chord C5 E3 G4 F-4>
>>> rem
[<music21.pitch.Pitch C2>, <music21.pitch.Pitch E3>]

* Changed in v6: inPlace defaults to False.
rH  r   r  r  s     r)   r7  Chord.removeRedundantPitchNames  s#    , 44V=D 5 F 	Fr(   r  c                   g r5   r"   rJ   newrootr9  s      r)   r  
Chord.root       	r(   c                   g r5   r"   r  s      r)   r  r    r  r(   c                  U(       Gah  [        U[        5      (       a-  [        R                  " U5      n[        R
                  " U5      nO][        U[        R                  5      (       a  UR                  nO1[        U[        R
                  5      (       a  UnO[        SU< 35      eSnU R                   H  nX5L d  M	  Sn  O   U(       d3  U R                   H#  nUR                  UR                  :X  d  M  UnSn  O   U(       d1  U R                   H!  nUR                  UR                  :X  d  M  Un  O   X0R                  S'   X0R                  S'   SU R                  ;   a  U R                  S	 gUSL af  SU R                  ;   a  U R                  S	 SU R                  ;   a  U R                  S	 U R                  5       U R                  S'   U R                  S   $ SU R                  ;  aP  USLaK  SU R                  ;   a  U R                  S   $ U R                  5       U R                  S'   U R                  S   $ SU R                  ;   a  U R                  S   $ g)al  
Returns the root of the chord.  Or if given a Pitch as the
newroot will override the algorithm and always return that Pitch.

>>> cmaj = chord.Chord(['E3', 'C4', 'G5'])
>>> cmaj.root()
<music21.pitch.Pitch C4>

Examples:

>>> cmaj = chord.Chord(['E', 'G', 'C'])
>>> cmaj.root()
<music21.pitch.Pitch C>

For some chords we make an exception.  For instance, take this chord in
B-flat minor:

>>> aDim7no3rd = chord.Chord(['A3', 'E-4', 'G4'])

It could be considered a type of E-flat 11 chord with a 3rd, but no 5th,
7th, or 9th, in 5th inversion.  That doesn't make sense, so we should
call it an A dim 7th chord
with no 3rd.

>>> aDim7no3rd.root()
<music21.pitch.Pitch A3>

>>> aDim7no3rdInv = chord.Chord(['E-3', 'A4', 'G4'])
>>> aDim7no3rdInv.root()
<music21.pitch.Pitch A4>

The root of a 13th chord (which could be any chord in any inversion) is
designed to be the bass:

>>> chord.Chord('F3 A3 C4 E-4 G-4 B4 D5').root()
<music21.pitch.Pitch F3>

Multiple pitches in different octaves do not interfere with root.

>>> lotsOfNotes = chord.Chord(['E3', 'C4', 'G4', 'B-4', 'E5', 'G5'])
>>> r = lotsOfNotes.root()
>>> r
<music21.pitch.Pitch C4>

>>> r is lotsOfNotes.pitches[1]
True

Setting of a root may happen for a number of reasons, such as
in the case where music21's idea of a root differs from the interpreter's.

To specify the root directly, pass the pitch to the root function:

>>> cSus4 = chord.Chord('C4 F4 G4')
>>> cSus4.root()  # considered by music21 to be an F9 chord in 2nd inversion
<music21.pitch.Pitch F4>

Change it to be a Csus4:

>>> cSus4.root('C4')
>>> cSus4.root()
<music21.pitch.Pitch C4>

Note that if passing in a string as the root,
the root is set to a pitch in the chord if possible.

>>> cSus4.root() is cSus4.pitches[0]
True


You might also want to supply an "implied root." For instance, some people
call a diminished seventh chord (generally viio7)
a dominant chord with an omitted root (Vo9) -- here we will specify the root
to be a note not in the chord:

>>> vo9 = chord.Chord(['B3', 'D4', 'F4', 'A-4'])
>>> vo9.root()
<music21.pitch.Pitch B3>

>>> vo9.root(pitch.Pitch('G3'))
>>> vo9.root()
<music21.pitch.Pitch G3>

When setting a root, the pitches of the chord are left untouched:

>>> [p.nameWithOctave for p in vo9.pitches]
['B3', 'D4', 'F4', 'A-4']

By default, this method uses an algorithm to find the root among the
chord's pitches, if no root has been previously specified.  If a root
has been explicitly specified, as in the Csus4 chord above, it can be
returned to the original root() by setting find explicitly to True:

>>> cSus4.root(find=True)
<music21.pitch.Pitch F4>

Subsequent calls without find=True have also removed the overridden root:

>>> cSus4.root()
<music21.pitch.Pitch F4>

If for some reason you do not want the root-finding algorithm to be
run (for instance, checking to see if an overridden root has been
specified) set find=False.  "None" will be returned if no root has been specified.

>>> c = chord.Chord(['E3', 'G3', 'B4'])
>>> print(c.root(find=False))
None

Chord symbols, for instance, have their root already specified on construction:

>>> d = harmony.ChordSymbol('CM/E')
>>> d.root(find=False)
<music21.pitch.Pitch C4>

There is no need to set find=False in this case, however, the
algorithm will skip the slow part of finding the root if it
has been specified (or already found and no pitches have changed).


A chord with no pitches has no root and raises a ChordException.

>>> chord.Chord().root()
Traceback (most recent call last):
music21.chord.ChordException: no pitches in chord <music21.chord.Chord ...>

* Changed in v5.2: `find` is a keyword-only parameter,
  `newroot` finds `Pitch` in `Chord`
zCannot find a Pitch in FTr  rF  N)r@   rA   r   rG  r   rm   r   rn   r   r   r   rH  rC   rI  r  )rJ   r  r9  newroot_pitchfoundRootInChordr0  s         r)   r  r    s   P '3'' 44W= %G 4GTYY// 'GU[[11 ' #:7+!FGG  %\\ %'+$ "
 $A''=+G+GG()+/(	 & $Avv!3!33() &
 '4OOF#"/KKdkk)KK,T\(OOF+dkk)KK,"&.."2DKK;;v&&DOO+U1B${{6**&*nn&6F#{{6**t&??6**r(   )rV  c                   g r5   r"   rX  s       r)   semiClosedPositionChord.semiClosedPosition  s     r(   c                   U $ r5   r"   rX  s       r)   r  r    s	     r(   c                  U R                  UUUS9nUSL a  U n[        R                  (       a  SSKJn  [        XE5      (       d   e[        R                  " UR                  5      nU(       av  / n/ n[        U5       HX  u  pU
R                  U;  a  UR                  U
R                  5        M2  U
=R                  S-  sl        UR                  U
5        MZ     UnU(       a  Mv  UR                  5         UR                  SS9  USL a  U$ g)	ac  
Similar to :meth:`~music21.chord.Chord.ClosedPosition` in that it
moves everything within an octave EXCEPT if there's already
a pitch at that step, then it puts it up an octave.  It's a
very useful display standard for dense post-tonal chords.

>>> c1 = chord.Chord(['C3', 'E5', 'C#6', 'E-7', 'G8', 'C9', 'E#9'])
>>> c2 = c1.semiClosedPosition(inPlace=False)
>>> c2
<music21.chord.Chord C3 E-3 G3 C#4 E4 E#5>

`leaveRedundantPitches` still works, and gives them a new octave!

>>> c3 = c1.semiClosedPosition(
...     inPlace=False,
...     leaveRedundantPitches=True,
...     )
>>> c3
<music21.chord.Chord C3 E-3 G3 C4 E4 C#5 E#5>

of course `forceOctave` still works, as does `inPlace=True`.

>>> c1.semiClosedPosition(
...     forceOctave=2,
...     inPlace=True,
...     leaveRedundantPitches=True,
...     )
>>> c1
<music21.chord.Chord C2 E-2 G2 C3 E3 C#4 E#4>

r[  Tr   )Streamr   r   FN)rY  tTYPE_CHECKINGmusic21.streamr  r@   rp   r   r   r  ro   rb  rz   r  )rJ   rU  r   rV  r9  r  remainingPitches	usedStepsnewRemainingPitchesr   r0  s              r)   r  r    s    N   [)07L ! N d?B??-b))))99RZZ0I"$!"2366*$$QVV,HHMH'..q1 4  3  	
&eI r(   c                T    U R                  XS9nUc  gUR                  R                  $ )aO	  
Returns the number of semitones (mod12) above the root that the
chordStep lies (i.e., 3 = third of the chord; 5 = fifth, etc.) if one
exists.  Or None if it does not exist.

You can optionally specify a note.Note object to try as the root.  It
does not change the Chord.root object.  We use these methods to figure
out what the root of the triad is.

Currently, there is a bug that in the case of a triply diminished third
(e.g., "c" => "e----"), this function will incorrectly claim no third
exists.  Perhaps this should be construed as a feature.

In the case of chords such as C, E-, E, semitonesFromChordStep(3)
will return the number for the first third, in this case 3.  It
will not return 4, nor a list object (3, 4).  You probably do not
want to be using tonal chord manipulation functions on chords such
as these anyway.  Check for such cases with
chord.hasAnyRepeatedDiatonicNote first.

Tools with the expression "chordStep" in them refer to the diatonic
third, fifth, etc., of the chord.  They have little to do with
the scale degree of the scale or key that the chord is embedded
within.  See "chord.scaleDegrees" for this functionality.

>>> cChord = chord.Chord(['E3', 'C4', 'G5'])
>>> cChord.semitonesFromChordStep(3)  # distance from C to E
4

>>> cChord.semitonesFromChordStep(5)  # C to G
7

Omitted chordSteps return None

>>> print(cChord.semitonesFromChordStep(6))
None

Note that the routine returns the semitones to the FIRST third.
This chord has two thirds, C and C#

>>> aChord = chord.Chord(['a2', 'c4', 'c#5', 'e#7'])
>>> aChord.semitonesFromChordStep(3)
3

>>> aChord.semitonesFromChordStep(5)
8
>>> print(aChord.semitonesFromChordStep(2))
None


Test whether this strange chord gets the B# as 0 semitones:

>>> c = chord.Chord(['C4', 'E4', 'G4', 'B#4'])
>>> c.semitonesFromChordStep(7)
0

If testRoot is set to a Pitch object then that note is used as the root of the chord
regardless of anything else that might be considered.

A-minor: 1st inversion.

>>> aMin = chord.Chord(['C4', 'E4', 'A4'])
>>> aMin.semitonesFromChordStep(3)
3
>>> aMin.semitonesFromChordStep(5)
7

C6 chord, jazz like, root position:

>>> cPitch = pitch.Pitch('C4')
>>> c6 = aMin  # renaming for clarity
>>> c6.semitonesFromChordStep(3, testRoot = cPitch)
4
>>> c6.semitonesFromChordStep(5, testRoot = cPitch) is None
True
>>> c6.semitonesFromChordStep(6, testRoot = cPitch)
9
r  N)r  r  r  )rJ   r  r  tempInts       r)   semitonesFromChordStepChord.semitonesFromChordStep  s2    ^ ,,Y,J?$$***r(   c                    UcE  U R                   (       a4  XR                  l        U R                    H  nXR                  l        M     g[        U[        5      (       a  [
        R                  " U5      nSnU R                    H&  nUR
                  UL d  M  XR                  l        Sn  O   U(       d7  U R                    H'  nUR
                  U:X  d  M  XR                  l        Sn  O   U(       d  [        SU 35      eg)ae  
Set color for specific pitch.

>>> c = chord.Chord('C4 E4 G4')
>>> c.setColor('red', 'C4')
>>> c['0.style.color']
'red'
>>> c.setColor('blue')  # set for whole chord
>>> c.style.color
'blue'
>>> c['E4.style.color']
'blue'

>>> c.setColor('red', 'C9')
Traceback (most recent call last):
music21.chord.ChordException: the given pitch is not in the Chord: C9
NFTr  )rD   r  r  r@   rA   r   rm   r   )rJ   r   r  rb   matchr   s         r)   setColorChord.setColorV  s    & 4;;$JJ[[ % !S))++k2KAww+% %	 
 [[77k)$)GGM E	 !
  7}EG G r(   c                   Uc+  U R                   (       a  U R                   S   R                  nO+[        U[        5      (       a  [        R                  " U5      nSnU R                    H  nUR                  UL d  M  Xl        Sn  O   U(       d-  U R                    H  nUR                  U:X  d  M  Xl        Sn  O   U(       d  [        SU 35      eg)a  
Given a notehead attribute as a string and a pitch object in this
Chord, set the notehead attribute of that pitch to the value of that
notehead. Valid notehead type names are found in note.noteheadTypeNames
(see below):

>>> for noteheadType in note.noteheadTypeNames:
...    noteheadType
...
'arrow down'
'arrow up'
'back slashed'
'circle dot'
'circle-x'
'circled'
'cluster'
'cross'
'diamond'
'do'
'fa'
'fa up'
'inverted triangle'
'la'
'left triangle'
'mi'
'none'
'normal'
'other'
're'
'rectangle'
'slash'
'slashed'
'so'
'square'
'ti'
'triangle'
'x'

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> c1 = chord.Chord([n1, n2])
>>> c1.setNotehead('diamond', c1.pitches[1])  # just to g
>>> c1.getNotehead(c1.pitches[1])
'diamond'

>>> c1.getNotehead(c1.pitches[0])
'normal'

If a chord has two of the same pitch, but each associated with a different notehead, then
object equality must be used to distinguish between the two.

>>> c2 = chord.Chord(['D4', 'D4'])
>>> secondD4 = c2.pitches[1]
>>> c2.setNotehead('diamond', secondD4)
>>> for i in [0, 1]:
...     c2.getNotehead(c2.pitches[i])
...
'normal'
'diamond'

By default, assigns to first pitch:

>>> c3 = chord.Chord('C3 F4')
>>> c3.setNotehead('slash', None)
>>> c3['0.notehead']
'slash'

Less safe to match by string, but possible:

>>> c3.setNotehead('so', 'F4')
>>> c3['1.notehead']
'so'

Error:

>>> c3.setNotehead('so', 'G4')
Traceback (most recent call last):
music21.chord.ChordException: the given pitch is not in the Chord: G4

Nr   FTr  )rD   r   r@   rA   rm   r  r   rJ   nhr  r  r   s        r)   setNoteheadChord.setNotehead  s    d 4;;++a...KS))++k2KAww+%
	 
 [[77k)!#J E	 !
  #H!VWW r(   c                   Uc+  U R                   (       a  U R                   S   R                  nO+[        U[        5      (       a  [        R                  " U5      nSnU R                    H  nUR                  UL d  M  Xl        Sn  O   U(       d-  U R                    H  nUR                  U:X  d  M  Xl        Sn  O   U(       d  [        SU 35      eg)a  
Given a noteheadFill attribute as a string (or False) and a pitch object in this
Chord, set the noteheadFill attribute of that pitch to the value of that
notehead. Valid noteheadFill names are True, False, None (default)

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> c1 = chord.Chord([n1, n2])
>>> c1.setNoteheadFill(False, c1.pitches[1])  # just to g
>>> c1.getNoteheadFill(c1.pitches[1])
False

>>> c1.getNoteheadFill(c1.pitches[0]) is None
True

If a chord has two of the same pitch, but each associated with a different notehead, then
object equality must be used to distinguish between the two.

>>> c2 = chord.Chord(['D4', 'D4'])
>>> secondD4 = c2.pitches[1]
>>> c2.setNoteheadFill(False, secondD4)
>>> for i in [0, 1]:
...     print(c2.getNoteheadFill(c2.pitches[i]))
...
None
False

By default, assigns to first pitch:

>>> c3 = chord.Chord('C3 F4')
>>> c3.setNoteheadFill(False, None)
>>> c3['0.noteheadFill']
False

Less safe to match by string, but possible:

>>> c3.setNoteheadFill(True, 'F4')
>>> c3['1.noteheadFill']
True

Error:
>>> c3.setNoteheadFill(True, 'G4')
Traceback (most recent call last):
music21.chord.ChordException: the given pitch is not in the Chord: G4

Nr   FTr  )rD   r   r@   rA   rm   r  r   r  s        r)   setNoteheadFillChord.setNoteheadFill  s    ` 4;;++a...KS))++k2KAww+%!#	 
 [[77k)%'N E	 !
  #H!VWW r(   c                   Uc+  U R                   (       a  U R                   S   R                  nO+[        U[        5      (       a  [        R                  " U5      nSnU R                    H  nUR                  UL d  M  Xl        Sn  O   U(       d-  U R                    H  nUR                  U:X  d  M  Xl        Sn  O   U(       d  [        SU 35      eg)a#  
Given a stem attribute as a string and a pitch object in this Chord,
set the stem attribute of that pitch to the value of that stem. Valid
stem directions are found note.stemDirectionNames (see below).

>>> for name in note.stemDirectionNames:
...     name
...
'double'
'down'
'noStem'
'none'
'unspecified'
'up'

>>> n1 = note.Note('D4')
>>> n2 = note.Note('G4')
>>> c1 = chord.Chord([n1, n2])
>>> c1.setStemDirection('double', c1.pitches[1])  # just to g
>>> c1.getStemDirection(c1.pitches[1])
'double'

>>> c1.getStemDirection(c1.pitches[0])
'unspecified'

If a chord has two of the same pitch, but each associated with a
different stem, then object equality must be used to distinguish
between the two.

>>> c2 = chord.Chord(['D4', 'D4'])
>>> secondD4 = c2.pitches[1]
>>> c2.setStemDirection('double', secondD4)
>>> for i in [0, 1]:
...    print(c2.getStemDirection(c2.pitches[i]))
...
unspecified
double

By default, assigns to first pitch:

>>> c3 = chord.Chord('C3 F4')
>>> c3.setStemDirection('down', None)
>>> c3['0.stemDirection']
'down'

Less safe to match by string, but possible:

>>> c3.setStemDirection('down', 'F4')
>>> c3['1.stemDirection']
'down'

Error:
>>> c3.setStemDirection('up', 'G4')
Traceback (most recent call last):
music21.chord.ChordException: the given pitch is not in the Chord: G4

Nr   FTr  )rD   r   r@   rA   rm   r  r   )rJ   stemr  r  r   s        r)   setStemDirectionChord.setStemDirection*  s    t 4;;++a...KS))++k2KAww+%"&	 
 [[77k)&*O E	 !
  7}EG G r(   c                
   Uc+  U R                   (       a  U R                   S   R                  nO+[        U[        5      (       a  [        R                  " U5      n[        U[        5      (       a  [
        R                  " U5      nOUnSnU R                    H   nUR                  UL d  XRL d  M  X5l        Sn  O   U(       d.  U R                    H  nX%UR                  4;   d  M  X5l        Sn  O   U(       d  [        SU 35      eg)a  
Given a tie object (or a tie type string) and a pitch or Note in this Chord,
set the pitch's tie attribute in this chord to that tie type.

>>> c1 = chord.Chord(['d3', 'e-4', 'b-4'])
>>> t1 = tie.Tie('start')
>>> c1.setTie(t1, 'b-4')  # or it can be done with a pitch.Pitch object
>>> c1.getTie(c1.pitches[2]) is t1
True

Setting a tie with a chord with the same pitch twice requires
getting the exact pitch object out to be sure which one:

>>> c2 = chord.Chord(['D4', 'D4'])
>>> secondD4 = c2.pitches[1]
>>> c2.setTie('start', secondD4)
>>> for i in [0, 1]:
...    print(c2.getTie(c2.pitches[i]))
...
None
<music21.tie.Tie start>

>>> c3 = chord.Chord('C3 F4')
>>> c3.setTie('start', None)
>>> c3.getTie(c3.pitches[0])
<music21.tie.Tie start>

Less safe to match by string, because there might be multiple
pitches with the same name in the chord, but possible:

>>> c4 = chord.Chord('D4 F#4')
>>> c4.setTie('start', 'F#4')
>>> c4.getTie('F#4')
<music21.tie.Tie start>

Setting a tie on a note not in the chord is an error:

>>> c3.setTie('stop', 'G4')
Traceback (most recent call last):
music21.chord.ChordException: the given pitch is not in the Chord: G4
Nr   FTr  )rD   r   r@   rA   rm   r   Tier   )rJ   tieObjOrStrr  tieObjr  r   s         r)   setTieChord.setTiex  s    T 4;;++a...KS))++k2K k3''WW[)F FAww+%)9	 
 [[agg,."E E	 !
  7}EG G r(   c                   [        U[        5      (       a  [        R                  " U5      nO][        U[        R
                  5      (       a  UR                  nO1[        U[        R                  5      (       a  UnO[        SU< 35      eSnU R                   H<  nUR                  UL d  UR                  U:X  d  M$  Xl        UR                  USS9  Sn  O   U(       d  [        SU 35      eg)aB  
Set the :class:`~music21.volume.Volume` object of a specific Pitch.

* Changed in v8: after appearing in ChordBase in v7, it has been properly
    moved back to Chord itself.  The ability to change just the first note's
    volume has been removed.  Use `Chord().volume = vol` to change the
    volume for a whole chord.
zCannot setVolume on target Fr   Tr  N)r@   rA   r   rm   r   rn   r   rD   r`   r   r   )rJ   r   targetr  r  r   s         r)   	setVolumeChord.setVolume  s     fc""++f-K		** ,,K,, K:6*EFFAww+%K)?!
SE2   #H!VWW r(   )r   
keyContextc                   U(       a  U nO[         R                  " U 5      n[        R                  " U R                  US9n[        [        U5      5       H  nXE   UR                  U   l        M     USL a  U$ g)a  
Calls `pitch.simplifyMultipleEnharmonics` on the pitches of the chord.

Simplifies the enharmonics in the sense of making a more logical chord.  Note below
that E# is added there because C# major is simpler than C# F G#.

>>> c = chord.Chord('C# F G#')
>>> c.pitches
(<music21.pitch.Pitch C#>, <music21.pitch.Pitch F>, <music21.pitch.Pitch G#>)

>>> c.simplifyEnharmonics(inPlace=True)
>>> c.pitches
(<music21.pitch.Pitch C#>, <music21.pitch.Pitch E#>, <music21.pitch.Pitch G#>)

If `keyContext` is provided the enharmonics are simplified based on the supplied
Key or KeySignature.

>>> c.simplifyEnharmonics(inPlace=True, keyContext=key.Key('A-'))
>>> c.pitches
(<music21.pitch.Pitch D->, <music21.pitch.Pitch F>, <music21.pitch.Pitch A->)
)r  FN)rp   rq   r   simplifyMultipleEnharmonicsr   r&  rQ   rD   )rJ   r   r  r  r   r   s         r)   r   Chord.simplifyEnharmonics  sm    , Id+I33DLLZXs7|$A(/
IQ% % e r(   c                    U R                  US9$ )Nr   )sortDiatonicAscendingr  s     r)   r  Chord.sortAscending  s    ))')::r(   c                f    [         R                  " U 5      nUR                  R                  S S9  U$ )zS
Same as sortAscending but notes are sorted by midi number, so F## sorts above G-.
c                .    U R                   R                  $ r5   )r   rd  xs    r)   r  .Chord.sortChromaticAscending.<locals>.<lambda>  s    177::r(   r  rp   rq   rD   r,  rJ   newChords     r)   sortChromaticAscendingChord.sortChromaticAscending  s-     ==&!56r(   c                  U(       a5  U R                   R                  SS5      (       a  gU nU R                  5         O[        R                  " U 5      nUR
                  R                  S S9  SUR                   S'   U(       d  U$ g)a#  
The notes are sorted by :attr:`~music21.pitch.Pitch.diatonicNoteNum`
or vertical position on a grand staff (so F## sorts below G-).
Notes that are the identical diatonicNoteNum are further sorted by
:attr:`~music21.pitch.Pitch.ps` (midi numbers that accommodate floats).

We return a new Chord object with the notes arranged from lowest to highest
(unless inPlace=True)

>>> cMajUnsorted = chord.Chord(['E4', 'C4', 'G4'])
>>> cMajSorted = cMajUnsorted.sortDiatonicAscending()
>>> cMajSorted.pitches[0].name
'C'

>>> c2 = chord.Chord(['E4', 'C4', 'G4'])
>>> c2.sortDiatonicAscending(inPlace=True)
>>> c2
<music21.chord.Chord C4 E4 G4>

>>> sameDNN = chord.Chord(['F#4', 'F4'])
>>> sameDNN.sortDiatonicAscending()
<music21.chord.Chord F4 F#4>

* Changed in v6: if inPlace is True do not return anything.
isSortedAscendingDiatonicFNc                Z    U R                   R                  U R                   R                  4$ r5   )r   re  rd  r  s    r)   r  -Chord.sortDiatonicAscending.<locals>.<lambda>-  s    QWW-D-Daggjj,Qr(   r  T)rI  getrz   rp   rq   rD   r,  )rJ   r   r  s      r)   r  Chord.sortDiatonicAscending  sv    4 {{:EBBIOO d+I"QR8<	45 r(   c                f    [         R                  " U 5      nUR                  R                  S S9  U$ )z
Same as above, but uses a note's frequency to determine height; so that
C# would be below D- in 1/4-comma meantone, equal in equal temperament,
but below it in (most) just intonation types.
c                .    U R                   R                  $ r5   )r   	frequencyr  s    r)   r  .Chord.sortFrequencyAscending.<locals>.<lambda>:  s    177+<+<r(   r  r  r  s     r)   sortFrequencyAscendingChord.sortFrequencyAscending3  s-     ==&!<=r(   c                   [        US5      (       a  UnO[        R                  " U5      nU(       d  [        R                  " U 5      nOU nUR
                   H  nUR                  USS9  M     U(       d  U$ g)a  
Transpose the Chord by the user-provided value. If the value
is an integer, the transposition is treated in half steps and
enharmonics might be simplified (not done yet). If the value is a
string, any Interval string specification can be provided.

If inPlace is set to True (default = False) then the original
chord is changed.  Otherwise a new Chord is returned.

We take a three-note chord (G, A, C#) and transpose it up a minor
third, getting the chord B-flat, C, E.

>>> a = chord.Chord(['g4', 'a3', 'c#6'])
>>> b = a.transpose('m3')
>>> b
<music21.chord.Chord B-4 C4 E6>

Here we create the interval object first (rather than giving
a string) and specify transposing down six semitones, instead
of saying A-4.

>>> aInterval = interval.Interval(-6)
>>> b = a.transpose(aInterval)
>>> b
<music21.chord.Chord C#4 E-3 G5>

If `inPlace` is True then rather than returning a new chord, the
chord itself is changed.

>>> a.transpose(aInterval, inPlace=True)
>>> a
<music21.chord.Chord C#4 E-3 G5>

r)  Tr   N)r~   r   r'  rp   rq   rD   	transpose)rJ   r   r   intervalObjpostrb   s         r)   r  Chord.transpose=  sh    F 5*%%K"++E2K==&DDAKKTK2  Kr(   c                     [         R                  " U 5      $ ! [         R                   a    [         R                  " SSSS5      s $ f = f)a  
Return a four-element ChordTableAddress that represents that raw data location for
information on the set class interpretation of this Chord as well as the original
pitchClass

The data format is a Forte set class cardinality, index number, and
inversion status (where 0 is invariant, and -1 and 1 represent
inverted or not, respectively).

>>> c = chord.Chord(['D4', 'F#4', 'B-4'])
>>> c.chordTablesAddress
ChordTableAddress(cardinality=3, forteClass=12, inversion=0, pcOriginal=2)

>>> c = chord.Chord('G#2 A2 D3 G3')
>>> c.chordTablesAddress
ChordTableAddress(cardinality=4, forteClass=6, inversion=0, pcOriginal=2)

This method caches the result so that it does not need to be looked up again.

One change from chord.tables.seekChordTablesAddress: the empty chord returns
a special address instead of raising an exception:

>>> chord.Chord().chordTablesAddress
ChordTableAddress(cardinality=0, forteClass=0, inversion=0, pcOriginal=0)
r   )r   seekChordTablesAddressChordTablesExceptionChordTableAddressrf   s    r)   r5  Chord.chordTablesAddressw  sD    8	80066** 	8++Aq!Q77	8s    -AAc           
     
   [        S U R                   5       5      (       a  gU R                  nUR                  S:X  a  gUR                  S:X  a  [	        U R                  5      S:X  a  gU R                   Vs1 s H  o"R
                  iM     nnU R                   Vs1 s H  o"R                  iM     nn[	        U5      S:X  a[  [	        U5      S:X  a  g[	        U5      S:X  a;  [        R                  " U R                  S   U R                  S   5      R                  $ g	[	        U5      S:X  a  g
g[        R                  " U5      nUR                  S:X  Ga?  U R                   Vs1 s H  o"R
                  iM     nnU R                   Vs1 s H  o"R                  iM     nnU R                  S   nUR                  nU R                  SS  H  nUR                  U:w  d  M  Un  O   [        S5      e[        R                  " Xh5      n	[	        U5      S:  a'  U	R                  R                  n
U
S:w  a  SOSnU
 SU 3$ [	        U5      S:  a  U	R                   S-   $ [        R                  " U R                  S   U R                  S   5      R                  $ U R"                  nSS jnU R$                  U R&                  U R(                  U R*                  U R,                  U R.                  U R0                  U R0                  U R0                  S.	nUS:X  a  U R3                  5       (       a  US   $ U R5                  5       (       a  US   $ U R5                  SS9(       a'  US   S-   U R7                  5       R9                  5       -   $ U R;                  5       (       a  US   $ U R;                  SS9(       a'  US   S-   U R7                  5       R9                  5       -   $ SUS   -   $ US:X  aZ  U R=                  5       (       a  US   $ U R=                  SS9(       a'  US   S-   U R7                  5       R9                  5       -   $ US   $ US:X  aZ  U R?                  5       (       a  US   $ U R?                  SS9(       a'  US   S-   U R7                  5       R9                  5       -   $ US   $ US;   a  U" U 5      (       a  US   $ SUS   -   $ X;   a  US   nX   nU" 5       (       d  SU-   nU$ U(       d  SU-   $ US   $ s  snf s  snf s  snf s  snf ) a  
Return the most common name associated with this Chord as a string.
Checks some common enharmonic equivalents.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.commonName
'minor triad'

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.commonName
'major triad'

>>> c2b = chord.Chord(['c', 'f-', 'g'])
>>> c2b.commonName
'enharmonic equivalent to major triad'

>>> c3 = chord.Chord(['c', 'd-', 'e', 'f#'])
>>> c3.commonName
'all-interval tetrachord'

Chords with no common names just return the Forte Class

>>> c3 = chord.Chord([0, 1, 2, 3, 4, 9])
>>> c3.commonName
'forte class 6-36B'

Dominant seventh and German/Swiss sixths are distinguished

>>> c4a = chord.Chord(['c', 'e', 'g', 'b-'])
>>> c4a.commonName
'dominant seventh chord'

>>> c4b = chord.Chord(['c', 'e', 'g', 'a#'])
>>> c4b.commonName
'German augmented sixth chord'

>>> c4c = chord.Chord(['c', 'e', 'f##', 'a#'])
>>> c4c.commonName  # some call it Alsacian or English
'Swiss augmented sixth chord'

When in an unusual inversion, augmented sixth chords have their inversion added:

>>> c4b = chord.Chord('A#3 C4 E4 G4')
>>> c4b.commonName
'German augmented sixth chord in root position'


Dyads are called by actual name:

>>> dyad1 = chord.Chord('C E')
>>> dyad1.commonName
'Major Third'
>>> dyad2 = chord.Chord('C F-')
>>> dyad2.commonName
'Diminished Fourth'

Compound intervals are given in full if there are only two distinct pitches:

>>> dyad1 = chord.Chord('C4 E5')
>>> dyad1.commonName
'Major Tenth'

But if there are more pitches, then the interval is given in a simpler form:

>>> dyad1 = chord.Chord('C4 C5 E5 C6')
>>> dyad1.commonName
'Major Third with octave doublings'


If there are multiple enharmonics present just the simple
number of semitones is returned.

>>> dyad1 = chord.Chord('C4 E5 F-5 B#7')
>>> dyad1.commonName
'4 semitones'



Special handling of one- and two-pitchClass chords:

>>> gAlone = chord.Chord(['G4'])
>>> gAlone.commonName
'note'
>>> gAlone = chord.Chord('G4 G4')
>>> gAlone.commonName
'unison'
>>> gAlone = chord.Chord('G4 G5')
>>> gAlone.commonName
'Perfect Octave'
>>> gAlone = chord.Chord('G4 G6')
>>> gAlone.commonName
'Perfect Double-octave'
>>> gAlone = chord.Chord('G4 G5 G6')
>>> gAlone.commonName
'multiple octaves'
>>> gAlone = chord.Chord('F#4 G-4')
>>> gAlone.commonName
'enharmonic unison'

>>> chord.Chord().commonName
'empty chord'

Microtonal chords all have the same commonName:

>>> chord.Chord('C`4 D~4').commonName
'microtonal chord'

Enharmonic equivalents to common sevenths and ninths are clarified:

>>> chord.Chord('C4 E4 G4 A##4').commonName
'enharmonic equivalent to major seventh chord'

>>> chord.Chord('C4 E-4 G4 A#4 D4').commonName
'enharmonic equivalent to minor-ninth chord'

* Changed in v5.5: special cases for checking enharmonics in some cases
* Changed in v6.5: better handling of 0-, 1-, and 2-pitchClass and microtonal chords.
* Changed in v7: Inversions of augmented sixth-chords are specified.
* Changed in v7.3: Enharmonic equivalents to common seventh and ninth chords are specified.

OMIT_FROM_DOCS

>>> chord.Chord('C E G C-').commonName
'enharmonic equivalent to major seventh chord'

>>> chord.Chord('C E G B--').commonName
'enharmonic equivalent to minor seventh chord'

>>> chord.Chord('C E G A').commonName
'minor seventh chord'
c              3  J   #    U  H  oR                  5       (       + v   M     g 7fr5   )isTwelveTonerD  s     r)   r9   #Chord.commonName.<locals>.<genexpr>  s     :\>>###\s   !#zmicrotonal chordr   empty chordr   r   unisonr  zmultiple octaveszenharmonic unisonzenharmonic octavesNz#Will never happen, just for typing.sr   	 semitonez with octave doublingsc                $   U R                  5       (       d  gU R                  5       R                  S5      nUR                  U R                  ;  a  gU R
                  nU(       d  gUR                  S5      nUR                  U R                  ;  a  gg)z;
For testing minor-minor sevenths and major-major sevenths
FP5T)r  r  r  rH  r  ro  )r   hypothetical_fifthro  hypothetical_sevenths       r)   ,_isSeventhWithPerfectFifthsAboveRootAndThirdFChord.commonName.<locals>._isSeventhWithPerfectFifthsAboveRootAndThirdW  st     ;;==!"!3!3D!9!&&all:GGE#(??4#8 #((<r(   )	z3-11Az3-11Bz3-10z3-12z4-27Az4-28z5-27Az5-27Bz5-34z4-27BTr&  z in r3  zenharmonic to z4-25z3-8A)z4-20z4-26zenharmonic equivalent to zforte class )r   r   r   r   ) rG   r   r5  r.  rQ   rH  rd  r   r'  niceNamer   addressToCommonNamesr  r   r  simpleUndirectedsemiSimpleNiceNamer  rR  rM  rH  r4  rc  rA  r  rN  r,  r$  lowerr-  r+  r*  )rJ   ctar0  r  	pitchPSesctnp0p0pitchClassp1relevantIntervalsimpleUnpluralr  r  enharmonicTestsouttests                    r)   
commonNameChord.commonName  s   L :T\\:::%%%??a ??a4<< A%*.,,7,Q&&,J7'+||4|!|I4:!#y>Q&#y>Q&#,,T\\!_dll1oNWWW-9~"*+))#.??a*.,,7,Q&&,J7'+||4|!|I4 aB==L\\!"%<<</B &
 %%JKK'008:"+55FF (A2"9VH559~!'::=UUU$$T\\!_dll1oFOOO__
	$ &&&&**))11,,\\\\LL

  %%''1v,,..1v,,,E1v););)=)C)C)EEE++--1v++t+D1v););)=)C)C)EEE'#a&006!**,,1v,,,E1v););)=)C)C)EEE1v6!++--1v---F1v););)=)C)C)EEE1v++ <DAA1v2SV;;*a&C".D661C7J!J..q6Mw 84 84s   8S0S5$S:	S?c                ,   [         R                  " [        S-  U R                  5      nUc0  U R                  (       a  U R                  S   R
                  nX l        U R                  n[         R                  (       a  [        U[        5      (       d   eU$ )aj  
Get or set the duration of this Chord as a Duration object.

>>> c = chord.Chord(['a', 'c', 'e'])
>>> c.duration
<music21.duration.Duration 1.0>

Durations can be overridden after the fact:

>>> d = duration.Duration()
>>> d.quarterLength = 2
>>> c.duration = d
>>> c.duration
<music21.duration.Duration 2.0>

>>> c.duration == d
True

>>> c.duration is d
True
Nr   )r  castr   	_durationrD   r;   r  r@   )rJ   r   pitchZeroDurationd_outs       r)   r;   Chord.duration  sh    0 FF8D=$..19 $A 7 7.N??eX....r(   c                V    [        U[        5      (       a  Xl        g[        SU 35      e)z
Set a Duration object.
z$this must be a Duration object, not N)r@   r   r"  r   )rJ   durationObjs     r)   r;   r%    s+    
 k8,,(N !#G}!UVVr(   c                F     U R                  S5      $ ! [         a     gf = f)a  
Shortcut for getChordStep(5), but caches it and does not raise exceptions

>>> cMaj1stInv = chord.Chord(['E3', 'C4', 'G5'])
>>> cMaj1stInv.fifth
<music21.pitch.Pitch G5>

>>> cMaj1stInv.fifth.midi
79

>>> chord.Chord('C4 D4').fifth is None
True

OMIT_FROM_DOCS

>>> chord.Chord().fifth
r  Nr  r   rf   s    r)   rp  Chord.fifth  *    (	$$Q'' 		    
  c                z     [         R                  " U R                  S5      $ ! [         R                   a     gf = f)a  
Return the Forte set class name as a string. This assumes a Tn
formation, where inversion distinctions are represented.

(synonym: forteClassTn)

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClass
'3-11A'

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClass
'3-11B'

Empty chords return 'N/A'

>>> chord.Chord().forteClass
'N/A'

Non-twelve-tone chords return as if all microtones and non-twelve-tone
accidentals are removed:

>>> chord.Chord('c~4 d`4').forteClass
'2-2'
tnN/Ar   addressToForteNamer5  r  rf   s    r)   r  Chord.forteClass  s8    6	,,T-D-DdKK** 		    # ::c                .    U R                   R                  $ )a  
Return the number of the Forte set class within the defined set group.
That is, if the set is 3-11, this method returns 11.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClassNumber
11

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClassNumber
11
)r5  r  rf   s    r)   forteClassNumberChord.forteClassNumber  s     &&111r(   c                    U R                   $ )z
A synonym for "forteClass"

Return the Forte Tn set class name, where inversion distinctions are
represented:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClass
'3-11A'

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClassTn
'3-11B'
)r  rf   s    r)   forteClassTnChord.forteClassTn  s      r(   c                z     [         R                  " U R                  S5      $ ! [         R                   a     gf = f)a  
Return the Forte TnI class name, where inversion distinctions are not
represented.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.forteClassTnI
'3-11'

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.forteClassTnI
'3-11'

Empty chords return 'N/A'

>>> chord.Chord().forteClassTnI
'N/A'

Non-twelve-tone chords return as if all microtones and non-twelve-tone
accidentals are removed:

>>> chord.Chord('c~4 d`4').forteClassTnI
'2-2'
tnir/  r0  rf   s    r)   forteClassTnIChord.forteClassTnI0  s8    2	,,T-D-DeLL** 		r3  c                B   / n/ nU R                    H  nUR                  UR                   5        M!     UR                  S5        UR                  SSR                  U5      -   S-   5        UR                  U R                  R                  5        SR                  U5      $ )aX  
Return the most complete representation of this Note, providing
duration and pitch information.

>>> c = chord.Chord(['D', 'F#', 'A'])
>>> c.fullName
'Chord {D | F-sharp | A} Quarter'

>>> chord.Chord(['d1', 'e4-', 'b3-'], quarterLength=2/3).fullName
'Chord {D in octave 1 | E-flat in octave 4 | B-flat in octave 3} Quarter Triplet (2/3 QL)'

r   z {z | z} r   )r   ro   fullNamer   r;   )rJ   r   subr0  s       r)   r?  Chord.fullNameN  s|     AJJ!**' 

7

45::c?+d23

4==))*wws|r(   c                     [         R                  " U R                  5      nUb  gg! [         R                   a     gf = f)a
  
Return True or False if the Chord has a Z-relation.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.hasZRelation
False

>>> c2 = chord.Chord(['c', 'c#', 'e', 'f#'])
>>> c2.hasZRelation  # it is c, c#, e-, g
True

OMIT_FROM_DOCS

>>> chord.Chord().hasZRelation
False
FT)r   r4  r5  r  )rJ   r  s     r)   r  Chord.hasZRelatione  sE    $	++D,C,CDD
  ** 		s    ' >>c                     [        [        R                  " U R                  5      5      $ ! [        R                   a    / SQs $ f = f)a  
Return the interval vector for this Chord as a list of integers.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.intervalVector
[0, 0, 1, 1, 1, 0]

>>> c2 = chord.Chord(['c', 'c#', 'e', 'f#'])
>>> c2.intervalVector
[1, 1, 1, 1, 1, 1]

>>> c3 = chord.Chord(['c', 'c#', 'e-', 'g'])
>>> c3.intervalVector
[1, 1, 1, 1, 1, 1]

OMIT_FROM_DOCS

>>> chord.Chord().intervalVector
[0, 0, 0, 0, 0, 0]
)r   r   r   r   r   r   )listr   r  r5  r  rf   s    r)   intervalVectorChord.intervalVector  s>    ,	&66t7N7NOPP** 	&%%	&s   (+ AAc                @    [         R                  U R                  5      $ )z
Return the interval vector as a string representation.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.intervalVectorString
'<001110>'
)r   r   rF  rf   s    r)   intervalVectorStringChord.intervalVectorString  s     ''(;(;<<r(   c                :    U R                   R                  S:X  a  gg)z
Return True or False if the Chord represents a set class inversion.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.isPrimeFormInversion
False

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.isPrimeFormInversion
True
r   TF)r5  rF  rf   s    r)   isPrimeFormInversionChord.isPrimeFormInversion  s     "",,2r(   c                ,    [        U R                  5      $ )z
Return an integer representing the cardinality of the multiset, or the
number of pitch values.

>>> c1 = chord.Chord(['D4', 'A4', 'F#5', 'D6'])
>>> c1.multisetCardinality
4
)rQ   pitchClassesrf   s    r)   multisetCardinalityChord.multisetCardinality  s     4$$%%r(   c                ,    [        U R                  5      $ )a/  
Return a tuple (immutable) of the notes contained in the chord.

Generally using .pitches or iterating over the chord is the best way to work with
the components of a chord, but in unusual cases, a chord may, for instance, consist
of notes with independent durations, volumes, or colors, or, more often, different tie
statuses.  `Chord` includes methods such as `.setTie()` for most of these features,
but from time to time accessing all the `Note` objects as a tuple can be valuable.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.duration.type = 'quarter'
>>> c1Notes = c1.notes
>>> c1Notes
(<music21.note.Note C>, <music21.note.Note E->, <music21.note.Note G>)

Note that to set duration independently, a new Duration object needs to
be created.  Internal notes for Chords created from strings or pitches
all share a Duration object.

>>> c1.duration is c1Notes[0].duration
True
>>> c1Notes[1].duration is c1Notes[2].duration
True

>>> c1Notes[2].duration = duration.Duration('half')
>>> c1.duration.type
'quarter'
>>> c1[2].duration.type
'half'

The property can also set the notes for a chord, but it must be
set to an iterable of literal Note objects.

>>> c1.notes = [note.Note('D#4'), note.Note('C#4')]
>>> c1
<music21.chord.Chord D#4 C#4>

Notice that the notes set this way are not sorted -- this is a property for
power users who want complete control.

Any incorrect assignment raises a TypeError:

>>> c1.notes = 'C E G'
Traceback (most recent call last):
TypeError: notes must be set with an iterable

>>> c1.notes = [pitch.Pitch('C'), pitch.Pitch('E')]
Traceback (most recent call last):
TypeError: every element of notes must be a note.Note object

In case of an error, the previous notes are not changed (for this reason,
`.notes` cannot take a generator expression).

>>> c1
<music21.chord.Chord D#4 C#4>

* New in v5.7
r   rf   s    r)   rK   Chord.notes  s    x T[[!!r(   c                    [         R                  " U5      (       d  [        S5      e[        S U 5       5      (       d  [        S5      eU R                  R                  5         U R                  USS9  g)z+
sets notes to an iterable of Note objects
z"notes must be set with an iterablec              3  V   #    U  H  n[        U[        R                  5      v   M!     g 7fr5   )r@   r   rn   r   s     r)   r9   Chord.notes.<locals>.<genexpr>
  s     >X:a++Xr  z1every element of notes must be a note.Note objectFr  N)r   ry   rt   r   rD   clearr{   )rJ   newNotess     r)   rK   rS    s^    
   **@AA>X>>>OPP5)r(   c                `   U R                   n [        R                  " U5      nU R                  n[        U5      nU H-  nU Vs/ s H
  ofU-   S-  PM     nn[        U5      U:X  d  M+  Us  $    [        S[        U R                  5      -   5      e! [        R                   a    / s $ f = fs  snf )a  
Return the normal order/normal form of the Chord represented as a list of integers:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.normalOrder
[0, 3, 7]

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.normalOrder
[0, 4, 7]

>>> c3 = chord.Chord(['d', 'f#', 'a'])
>>> c3.normalOrder
[2, 6, 9]

>>> c3 = chord.Chord(['B-4', 'D5', 'F5'])
>>> c3.normalOrder
[10, 2, 5]

To get normalOrder transposed to PC 0, do this:

>>> c3 = chord.Chord(['B-4', 'D5', 'F5'])
>>> normalOrder = c3.normalOrder
>>> firstPitch = normalOrder[0]
>>> [(pc - firstPitch) % 12 for pc in normalOrder]
[0, 4, 7]

To get normalOrder formatted as a vectorString run .formatVectorString on it:

>>> c3.normalOrder
[10, 2, 5]

>>> chord.Chord.formatVectorString(c3.normalOrder)
'<A25>'

(this is equivalent:)

>>> c3.formatVectorString(c3.normalOrder)
'<A25>'

OMIT_FROM_DOCS

These were giving problems before:

>>> chord.Chord('G#2 A2 D3 G3').normalOrder
[7, 8, 9, 2]

>>> chord.Chord('G3 D4 A-4 A4 C5 E5').normalOrder
[7, 8, 9, 0, 2, 4]

>>> chord.Chord('E#3 A3 C#4').normalOrder
[1, 5, 9]

>>> chord.Chord('B5 G4 D5 E-5 D6').normalOrder
[11, 2, 3, 7]

>>> chord.Chord().normalOrder
[]
r^  z(Could not find a normalOrder for chord: )	r5  r   r  r  orderedPitchClassesr   r   rA   orderedPitchClassesString)rJ   r  transposedNormalForm
orderedPCsmustBePresentPCstransposeAmountpcpossibleNormalOrders           r)   normalOrderChord.normalOrder  s    | %%	#)#G#G#L  --
z?)OI]"^I]2$8B#>I]"^&'+;;**  * G"4#A#ABC D 	D ** 	I	 #_s   B B+B('B(c                @    [         R                  U R                  5      $ )z
Return the normal order/normal form of the Chord as a string representation.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.normalOrder
[0, 3, 7]

>>> c1.normalOrderString
'<037>'
)r   r   rb  rf   s    r)   normalOrderStringChord.normalOrderString\  s     ''(8(899r(   c                v    [        5       nU R                   H  nUR                  UR                  5        M      U$ )z
helper function for orderedPitchClasses but also routines
like pitchClassCardinality which do not need sorting.

Returns a set of ints
)r   r   r{   r  rJ   pcGroupr0  s      r)   r  Chord._unorderedPitchClassesj  s.     %AKK% r(   c                F    [        [        U R                  5       5      5      $ )z
Return a list of pitch class integers, ordered form lowest to highest.

>>> c1 = chord.Chord(['D4', 'A4', 'F#5', 'D6'])
>>> c1.orderedPitchClasses
[2, 6, 9]
)rE  r  r  rf   s    r)   rZ  Chord.orderedPitchClassesv  s     F46689::r(   c                @    [         R                  U R                  5      $ )z
Return a string representation of the pitch class values.

>>> c1 = chord.Chord(['f#', 'e-', 'g'])
>>> c1.orderedPitchClassesString
'<367>'

Redundancies are removed

>>> c1 = chord.Chord(['f#', 'e-', 'e-', 'g'])
>>> c1.orderedPitchClassesString
'<367>'
)r   r   rZ  rf   s    r)   r[  Chord.orderedPitchClassesString  s     ''(@(@AAr(   c                4    [        U R                  5       5      $ )z
Return the cardinality of pitch classes, or the number of unique
pitch classes, in the Chord:

>>> c1 = chord.Chord(['D4', 'A4', 'F#5', 'D6'])
>>> c1.pitchClassCardinality
3
)rQ   r  rf   s    r)   r)  Chord.pitchClassCardinality  s     4..011r(   c                f    / nU R                    H  nUR                  UR                  5        M      U$ )z
Return a list of all pitch classes in the chord as integers. Not sorted

>>> c1 = chord.Chord(['D4', 'A4', 'F#5', 'D6'])
>>> c1.pitchClasses
[2, 9, 6, 2]
)r   ro   r  rh  s      r)   rO  Chord.pitchClasses  s,     ANN1<<( r(   c                l    U R                    Vs/ s H  oR                  R                  PM     sn$ s  snf )aD  
Return a list of Pitch names from each
:class:`~music21.pitch.Pitch` object's
:attr:`~music21.pitch.Pitch.name` attribute.

>>> c = chord.Chord(['g#', 'd-'])
>>> c.pitchNames
['G#', 'D-']

>>> c = chord.Chord('C4 E4 G4 C4')
>>> c.pitchNames
['C', 'E', 'G', 'C']

>>> c.pitchNames = ['c2', 'g2']
>>> c.pitchNames
['C', 'G']
)rD   r   rH  r   s     r)   r  Chord.pitchNames  s&    & '+kk2kk222s   1c                B   [         R                  " U5      (       af  [        US   [        5      (       a@  / U l        U H2  nU R                  R                  [        R                  " U5      5        M4     O[        SU 35      e[        SU 35      eU R                  5         g )Nr   z-must provide a list containing a Pitch, not: z,cannot set pitch name with provided object: )
r   
isListLiker@   rA   rD   ro   r   rn   r   rz   )rJ   r   rH  s      r)   r  rt    s    U##%(C(( !DKK&&tyy7 " %CE7KM M !#OPUw!WXXr(   c                   U R                   nUS:X  a  U$ US;   a  U R                  S   R                  $ U R                  S::  d  SU;   d  SU;   d  SU;   a3  U R	                  5       nUR                  R                  SS	5      nU S
U 3$  U R                  5       nUR                  R                  SS	5      nU SU 3$ ! [         a    U R                  S   n N>f = f)a"	  
Return a common name of this Chord including a pitch identifier, if possible:

Most common chords will use the root as the pitch name and have it at the beginning:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.pitchedCommonName
'C-minor triad'

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.pitchedCommonName
'C-major triad'

Because the hyphen is confusing w/ music21 flat notation, flats are displayed
as "b":

>>> c2a = chord.Chord('C-2 E-2 G-2')
>>> c2a.pitchedCommonName
'Cb-major triad'

Other forms might have the pitch elsewhere.  Thus, this is a method for display,
not for extracting information:

>>> c3 = chord.Chord('A#2 D3 F3')
>>> c3.pitchedCommonName
'enharmonic equivalent to major triad above A#'

Note that in this case, the bass, not the root is used to determine the pitch name:

>>> c4 = chord.Chord('D3 F3 A#3')
>>> c4.pitchedCommonName
'enharmonic equivalent to major triad above D'

>>> c5 = chord.Chord([1, 2, 3, 4, 5, 10])
>>> c5.pitchedCommonName
'forte class 6-36B above C#'

>>> c4 = chord.Chord('D3 F3 A#3')
>>> c4.pitchedCommonName
'enharmonic equivalent to major triad above D'


A single pitch just returns that pitch name:

>>> chord.Chord(['D3']).pitchedCommonName
'D'

Unless there is more than one octave:

>>> chord.Chord('D3 D4').pitchedCommonName
'Perfect Octave above D'
>>> chord.Chord('D3 D4 D5').pitchedCommonName
'multiple octaves above D'


Two different pitches give interval names:

>>> chord.Chord('F3 C4').pitchedCommonName
'Perfect Fifth above F'

Compound intervals are used unless there are multiple octaves:

>>> chord.Chord('E-3 C5').pitchedCommonName
'Major Thirteenth above Eb'
>>> chord.Chord('E-3 C5 C6').pitchedCommonName
'Major Sixth with octave doublings above Eb'


These one-pitch-class and two-pitch-class chords with multiple enharmonics are unusual:

>>> chord.Chord('D#3 E-3').pitchedCommonName
'enharmonic unison above D#'
>>> chord.Chord('D#3 E-3 D#4').pitchedCommonName
'enharmonic octaves above D#'
>>> chord.Chord('D#3 E-3 E3').pitchedCommonName
'1 semitone above D#'
>>> chord.Chord('D#3 E-3 F3 G--4').pitchedCommonName
'2 semitones above D#'

>>> chord.Chord().pitchedCommonName
'empty chord'

* Changed in v5.5: octaves never included, flats are converted,
  special tools for enharmonics.
* Changed in v6.5: special names for 0-, 1-, and 2-pitchClass chords.
r  )r   r  r   r  
enharmoniczforte classr  -r  z above )r  r   rH  r)  r>  replacer  r   )rJ   nameStrr>  bassNamer  rootNames         r)   pitchedCommonNameChord.pitchedCommonName  s    p //m#N((<<?''' %%*' G+')99;Dyy((c2HYghZ00'yy{ yy((c2HZq	** " '||A's   
B= =CCc                >    [        S U R                   5       5      nU$ )a6  
Get or set a list or tuple of all Pitch objects in this Chord.

>>> c = chord.Chord(['C4', 'E4', 'G#4'])
>>> c.pitches
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch G#4>)

>>> [p.midi for p in c.pitches]
[60, 64, 68]

>>> d = chord.Chord()
>>> d.pitches = c.pitches
>>> d.pitches
(<music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>, <music21.pitch.Pitch G#4>)

>>> c = chord.Chord(['C4', 'A4', 'E5'])
>>> c.bass()
<music21.pitch.Pitch C4>

>>> c.root()
<music21.pitch.Pitch A4>


Note here that the list will be converted to a tuple:

>>> c.pitches = ['C#4', 'A#4', 'E#5']
>>> c.pitches
(<music21.pitch.Pitch C#4>, <music21.pitch.Pitch A#4>, <music21.pitch.Pitch E#5>)

Bass and root information is also changed.

>>> c.bass()
<music21.pitch.Pitch C#4>

>>> c.root()
<music21.pitch.Pitch A#4>
c              3  8   #    U  H  oR                   v   M     g 7fr5   r   )r6   	components     r)   r9    Chord.pitches.<locals>.<genexpr>g  s     0^R]YR]r}  r   )rJ   r   s     r)   r   Chord.pitches?  s!    P ,10^RVR]R]0^+^r(   c                    / U l         U R                  5         U H2  nU R                   R                  [        R                  " U5      5        M4     g r5   )rD   rz   ro   r   rn   )rJ   r   r0  s      r)   r   r  j  s7    AKKtyy|, r(   c                     [        [        R                  " U R                  5      5      $ ! [        R                   a    / s $ f = f)a	  
Return a representation of the Chord as a prime-form list of pitch
class integers:

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.primeForm
[0, 3, 7]

>>> c2 = chord.Chord(['c', 'e', 'g'])
>>> c2.primeForm
[0, 3, 7]

OMIT_FROM_DOCS

>>> chord.Chord().primeForm
[]
)rE  r   addressToPrimeFormr5  r  rf   s    r)   	primeFormChord.primeForms  s=    &	11$2I2IJKK** 	I	s   (+ AAc                @    [         R                  U R                  5      $ )z
Return a representation of the Chord as a prime-form set class string.

>>> c1 = chord.Chord(['c', 'e-', 'g'])
>>> c1.primeFormString
'<037>'

>>> c1 = chord.Chord(['c', 'e', 'g'])
>>> c1.primeFormString
'<037>'
)r   r   r  rf   s    r)   primeFormStringChord.primeFormString  s     ''77r(   c                    U R                  S5      nU R                  S5      nUc  gU R                  S5      (       a  gU R                  S5      (       a  gUc  US:X  a  gUS:X  a  ggU R                  S5      (       a  gUS:X  a  US:X  a  gUS:X  a  US:X  a  gUS	:X  a  US:X  a  g
US:X  a  US:X  a  gg! [         a     gf = f)a  
Returns the quality of the underlying triad of a triad or
seventh, either major, minor, diminished, augmented, or other:

>>> a = chord.Chord(['a', 'c', 'e'])
>>> a.quality
'minor'

Inversions don't matter, nor do added tones so long as a root can be
found:

>>> a = chord.Chord(['f', 'b', 'd', 'g'])
>>> a.quality
'major'

>>> a = chord.Chord(['c', 'a-', 'e'])
>>> a.quality
'augmented'

>>> a = chord.Chord(['c', 'c#', 'd'])
>>> a.quality
'other'

Incomplete triads are returned as major or minor:

>>> a = chord.Chord(['c', 'e-'])
>>> a.quality
'minor'

>>> a = chord.Chord(['e-', 'g'])
>>> a.quality
'major'

Chords that contain more than one triad return 'other'

>>> chord.Chord('C C# E G').quality
'other'
>>> chord.Chord('C E- E G').quality
'other'
>>> chord.Chord('C E G- G').quality
'other'

Note these two edge cases:

>>> chord.Chord('C D E').quality  # NB! Major 9th.
'major'
>>> chord.Chord('C E--').quality
'other'

Empty chords are definitely 'other':

>>> chord.Chord().quality
'other'
r3  r  rS   r   r  majorminorr  r  	augmentedrt  
diminished)r  r   r  )rJ   ro  rp  s      r)   qualityChord.quality  s    r	//2E//2E
 =&&q))&&q))]z!&&q))aZEQJaZEQJaZEQJaZEQJ9  		s   "B4 4
C Cc                   SSK Jn  [        U S5      (       a  U R                  b  U R                  nOU R	                  UR
                  SS9nUc  g/ nU R                   H  nUR                  USUR                  R                  S9nUc  UR                  S	5        M>  UR                  UUR                  R                  S
9nUR                  UR                  :X  a  UR                  US45        M  UR                  Ul        U[        R                  " [!        UR"                  UR"                  -
  5      5      4nUR                  U5        M     U$ )a	  
Returns a list of two-element tuples for each pitch in the chord where
the first element of the tuple is the scale degree as an int and the
second is an Accidental object that specifies the alteration from the
scale degree (could be None if the note is not part of the scale).

It is easiest to see the utility of this method using a chord subclass,
:class:`music21.roman.RomanNumeral`, but it is also callable from this
Chord object if the Chord has a Key or Scale context set for it.

>>> k = key.Key('f#')  # 3-sharps minor
>>> rn = roman.RomanNumeral('V', k)
>>> rn.key
<music21.key.Key of f# minor>

>>> rn.pitches
(<music21.pitch.Pitch C#5>, <music21.pitch.Pitch E#5>, <music21.pitch.Pitch G#5>)

>>> rn.scaleDegrees
[(5, None), (7, <music21.pitch.Accidental sharp>), (2, None)]

>>> rn2 = roman.RomanNumeral('N6', k)
>>> rn2.pitches
(<music21.pitch.Pitch B4>, <music21.pitch.Pitch D5>, <music21.pitch.Pitch G5>)

>>> rn2.scaleDegrees  # N.B. -- natural form used for minor!
[(4, None), (6, None), (2, <music21.pitch.Accidental flat>)]

As mentioned above, the property can also get its scale from context if
the chord is embedded in a Stream.  Let's create the same V in f#-minor
again, but give it a context of c-sharp minor, and then c-minor instead:

>>> chord1 = chord.Chord(['C#5', 'E#5', 'G#5'])
>>> st1 = stream.Stream()
>>> st1.append(key.Key('c#'))  # c-sharp minor
>>> st1.append(chord1)
>>> chord1.scaleDegrees
[(1, None), (3, <music21.pitch.Accidental sharp>), (5, None)]

>>> st2 = stream.Stream()
>>> chord2 = chord.Chord(['C#5', 'E#5', 'G#5'])
>>> st2.append(key.Key('c'))  # c minor
>>> st2.append(chord2)        # same pitches as before gives different scaleDegrees
>>> chord2.scaleDegrees
[(1, <music21.pitch.Accidental sharp>),
 (3, <music21.pitch.Accidental double-sharp>),
 (5, <music21.pitch.Accidental sharp>)]

>>> st3 = stream.Stream()
>>> st3.append(key.Key('C'))  # C major
>>> chord2 = chord.Chord(['C4', 'C#4', 'D4', 'E-4', 'E4', 'F4'])  # 1st 1/2 of chromatic
>>> st3.append(chord2)
>>> chord2.scaleDegrees
[(1, None), (1, <music21.pitch.Accidental sharp>), (2, None),
 (3, <music21.pitch.Accidental flat>), (3, None), (4, None)]

If no context can be found, return `None`:

>>> chord.Chord('C4 E4 G4').scaleDegrees is None
True

* Changed in v6.5: will return `None` if no context can be found:
r   )scaler   NT)sortByCreationTimer  )comparisonAttribute	direction)NN)r  )music21r  r~   r   getContextByClassScaler   getScaleDegreeFromPitch	Direction
DESCENDINGro   pitchFromDegreerH  rb  r   
Accidentalrs   rd  )rJ   r  scdegreesr   degreeactualPitchtupleKeys           r)   scaleDegreesChord.scaleDegrees  s+   B 	"4DHH$8B'''MBzI//$*//44 0 F
 ~|, 00#oo88 1  ##y~~5NNFD>2)2)9)9K& & % 0 0Y\\KNN5R1S T VHNN8,' &( r(   c                F     U R                  S5      $ ! [         a     gf = f)a  
Shortcut for getChordStep(7), but caches the value

>>> bDim7_2ndInv = chord.Chord(['F2', 'A-3', 'B4', 'D5'])
>>> bDim7_2ndInv.seventh
<music21.pitch.Pitch A-3>

Test whether this strange chord gets the B# not the C or something else:

>>> c = chord.Chord(['C4', 'E4', 'G4', 'B#4'])
>>> c.seventh
<music21.pitch.Pitch B#4>

* Changed in v6.5: return None on empty chords/errors

OMIT_FROM_DOCS

>>> chord.Chord().seventh
r  Nr)  rf   s    r)   rk  Chord.seventhW  s*    ,	$$Q'' 		r,  c                F     U R                  S5      $ ! [         a     gf = f)a2  
Shortcut for getChordStep(3), but caches the value, and returns
None on errors.

>>> cMaj1stInv = chord.Chord(['E3', 'C4', 'G5'])
>>> cMaj1stInv.third
<music21.pitch.Pitch E3>

>>> cMaj1stInv.third.octave
3

* Changed in v6.5: return `None` on empty chords/errors

OMIT_FROM_DOCS

>>> chord.Chord().third
r3  Nr)  rf   s    r)   ro  Chord.thirdr  r+  r,  )r"  rD   r   r5   )rK   zmt.Union[None, Sequence[pitch.Pitch], Sequence[note.Note], Sequence[Chord], Sequence[str], str, Sequence[int]])r   z#int | str | note.Note | pitch.Pitch)r   rA   )r   pitch.Pitch | None)rJ   r   r  rA   r   z_ChordType | list[pitch.Pitch]r   )rJ   r   r   r   r  r   r  r   r  t.Literal[True]r   	list[str])rJ   r   r   r  r  r   r  r   r  t.Literal[False]r   r   )rJ   r   r   r  r  r   r  r   r  r  r   r   )rJ   r   r   r   r  r   r  r   r  r   r   z_ChordType | None | list[str])rJ   r   rS   r   r   r   )r=  r   r9  bool | Noner:  r   r   pitch.Pitch)r=  str | pitch.Pitch | note.Noter9  r  r:  r   r   r   )r=  $None | str | pitch.Pitch | note.Noter9  r  r:  r   r   r  r   )
rJ   r   rU  
int | Noner   r  rV  r   r   r   )
rJ   r   rU  r  r   r  rV  r   r   r   )
rJ   r   rU  r  r   r   rV  r   r   z_ChordType | None)r   r  )r   z	list[int])r  rs   r  znote.Note | pitch.Pitch | Noner   r  )r   zChord | None)
r  rs   r9  r   r  r  r  r   r   r   )
r  r   r9  r   r  r  r  r   r   rs   )
r  r  r9  r   r  r  r  r   r   r  )r  rs   r  r  r  r   r   r   )r  r  r   rs   )r   r  )
rs  ztuple[int, int, int]rt  rs   r'  r   ru  zlist[tuple[str, str]]r   r   )r  r   r9  r  r   r  )r  r  r9  r  r   r   )r  r  r9  r  r   r  )rJ   r   r   r  r   r   )rJ   r   r   r  r   r   )
rJ   r   rU  r  r   z"t.Literal[True] | t.Literal[False]rV  r   r   zNone | _ChordType)r  ztie.Tie | str)r   zvolume.Volumer  zstr | note.Note | pitch.Pitch)r   r   )r'  r   )r   ztuple[note.Note, ...])rX  zIterable[note.Note]r   r   )r   zset[int])r   rs   )r   r  )r   ztuple[pitch.Pitch, ...])r   zIterable[pitch.Pitch]r   r   )r#   r$   r%   r&   r   r   
_DOC_ORDERr1   r   r   r+   rF   rP   rW   r   r   r   staticmethodr   r  r  r{   r   r  r7  r>  rO  rS  rY  rl  rj  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rF  r  r  r  r$  r/  r   r4  r8  rA  r@  rH  rN  rN  r+  r,  rc  rh  rk  r*  rW  r3  rM  rR  r  r  r  r-  r  r%  r  r7  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r   r5  r  r;   r   rp  r  r5  r8  r<  r?  r  rF  rI  rL  rP  rK   rb  re  r  rZ  r[  r)  rO  r  r~  r   r  r  r  r  rk  ro  r'   r   r   s   @r)   r   r   H  s   JX G J 	 6!I~  Y(() 263/3 30"}~+&Z$  :2 	&7&7&7
 
&&7^ 	5-
 
5- 5-n   $   	
  $ 
  
 !% ', ! 	
  % 
   %* $ ', " 	
  % 
   $  ii i 	i
 i i 
#iV4    	
  
  
 * 	
  
  37Y' Y'/Y' 	Y'
 Y' 
Y'v"$  !%&+  !	
  $ 
   !%$)&+  "	
  $ 
  !%&+DD D 	D
  $D 
DL)VBX5t@$L 04	@@ -	@
 
@D-^"H%N&P6N6!L(6 ;? 8 <@ : 
 %)# 	
 #  
   " %)# 	
 #  
  "&Q %)#QQ 	Q
 #Q Q 
Qf')') ') 	')
 
')R!F$XL?B 6; (T +6 +6Z e eN 2 2&< 6 6: 3 3. 9 98 <A 9
v <A ,
\ 3 3< 7 7r + +Z <AUZ DL1/1 1 !	1
 .1 
1fB -7 -7^ 6 6. LQ un ! !F / /b ;@ "
J ' 'R 16 AFF 6; F. 49 F2 !  $  	    $/  	  8<@  $@4@ @ #	@D  $ !	 
   $)# "	 
  !%49&+BB B 2	B
  $B 
BHS+j*GXcXJAXFLG\CGJX$X3X@ .3t  D (- ; 05 &P +0 5t 8  8@ I  IX    D __W W   .  > 2 2  "  :  ,  6 & &4 = =  " 	& 	& ;" ;"z \\	* 	* ID  IDV : :
 ; ; B B  	2 	2   3 3(   m+ m+^ ( (T ^^- -  . 8 8 V  Vr ^ ^@   2   r(   r   c                   SnSnSn[        U [        5      (       a  SU ;   as  U R                  S5      n[        US   5      n[        R
                  " US   5      u  pV[        U5      nSUR                  5       ;   a  SnOSUR                  5       ;   a  SnO[        SU  35      e[        R                  " U 5      (       aR  [        U 5      S	::  a5  U (       a  U S   n[        U 5      S:  a  U S   n[        U 5      S
:  a  U S
   nO[        SU  35      e[        SU  35      e[        R                  " XU/5      n[        U5      $ )a  
Return a Chord given a Forte-class notation. The Forte class can be
specified as string (e.g., 3-11) or as a list of cardinality and number
(e.g., [8, 1]).

If no match is available, None is returned.

>>> chord.fromForteClass('3-11')
<music21.chord.Chord C E- G>

>>> chord.fromForteClass('3-11b')
<music21.chord.Chord C E G>

>>> chord.fromForteClass('3-11a')
<music21.chord.Chord C E- G>

>>> chord.fromForteClass((11, 1))
<music21.chord.Chord C D- D E- E F G- G A- A B->

Nr   ry  r   ar  r   z5cannot extract set-class representation from string: r3  r  "cannot handle specified notation: )r@   rA   rB   rs   r   getNumFromStrr  r   rv  rQ   r   r  r   )r1  cardnumr  notationPartsstr_numcharsr  s           r)   r	   r	     s=   * D
C
C(C  (?$NN3/M}Q'(D#11-2BCNGg,Cekkm#% GzRT T			8	$	$x=A{8}q qk8}q qk #EhZ!PQQA(LMM00$S1ABE<r(   c                   Sn[         R                  " U 5      (       a%  [        U 5      S:X  a  [        R                  " U 5      nUc  [        SU  35      e/ nU H1  nUR                  [        [        R                  " U5      5      5        M3     [        U5      S:X  a  US   $ [        U5      S:X  a  U(       d  US   $ [        U5      S:X  a  U(       a  US   $ g)a  
Return one or more Chords given an interval vector.

>>> chord.fromIntervalVector([0, 0, 0, 0, 0, 1])
<music21.chord.Chord C F#>

>>> chord.fromIntervalVector((5, 5, 5, 5, 5, 5)) is None
True

>>> chord.fromIntervalVector((1, 1, 1, 1, 1, 1))
<music21.chord.Chord C C# E F#>

>>> chord.fromIntervalVector((1, 1, 1, 1, 1, 1), getZRelation=True)
<music21.chord.Chord C D- E- G>

>>> chord.fromIntervalVector((1, 1, 1, 1, 1, 1)).getZRelation()
<music21.chord.Chord C D- E- G>

Nrt  r  r   r   r  )	r   rv  rQ   r   r  r   ro   r   r  )r1  r  addressListr  r  s        r)   r   r     s    ( K""x=A 88BKA(LMMDE&>>wGHI  4yA~Aw	TaAw	TaLAwr(   c                      \ rS rSrSrS rSrg)Testi  z#
Most tests now in test/test_chord
c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr  globals)rJ   r  s     r)   testCopyAndDeepcopyTest.testCopyAndDeepcopy  s    7D')$r(   r"   N)r#   r$   r%   r&   r   r  r'   r"   r(   r)   r  r    s    %r(   r  __main__)r1  zstr | Sequence[int]r   r   )F)3r   
__future__r   __all__collections.abcr
   r   rp   typingr  r   unittestr  r   r   music21.common.decoratorsr   r   music21.durationr   r   r   r   r   r   r   r   music21.chordr   r   r  r   music21.styler   EnvironmentenvironLocalTypeVarr   r   Music21Exceptionr   rr   r+   r   r	   r   TestCaser  r  r#   mainTestr"   r(   r)   <module>r     s   #
` .       1  %            ??#&&w/+3LMYY|+@A
	\22 	
J- J-\AUI AUJj4n'X%8 % W
 zT r(   