
    rh[                      % S r SSKJr  SSKJr  SSKrSSKrSSKrSSKr	SSK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  \	R2                  (       a  SSKJr  \	R6                  " SSS9r\R:                  " S5      r\	R>                  S   r SSSSSSSS.r!S\"S'   Sr#S S!S"S#S$S%S&S.r$S'\"S('   1 S)kr%S*\"S+'   SS,SS-SSS.S.r&S\"S/'   S0r'S.r(S1r)S2r*S3S4S5S6S7S8S9S:S;S<S=S>S?S@.r+\+RY                  5        V Vs0 s H  u  pX_M	     snn r-\" S7\." SA5      \." SA5      -   4S6SB\." SA5      -   4S5\." SA5      4S=SB\." SC5      -   4SDS<\." SC5      4S;\." SE5      \." SE5      -   4SFS9\." SE5      4S?SG\." SC5      -   4SHS>\." SC5      4SI/5      r/0 SJSK_SLSM_SNSO_SPSQ_SRSS_STSU_SVSU_SWSX_SYSZ_S[S\_S]S^_S_S^_S`S^_SaSb_ScSb_SdSb_SeSb_SfSfSfSgSgSgSgSh.Er0Si r1\1" 5       r2SSj jr3SSk jr4    SSl jr5SSm jr6SSn jr7    SSo jr8SSp jr9SSq jr:   S     SSr jjr;\;4SSs jjr<\;4SSt jjr=\;S4Su jr> " Sv Sw\R~                  5      r@ " Sx Sy\R~                  5      rA " Sz S{\R~                  5      rB " S| S}\R                  \5      rD " S~ S\R                  \R                  5      rF " S S\R                  5      rG " S S\R                  5      rI\G\F\D/rJ\KS:X  a  SSKr\R                  " \I5        ggs  snn f )a+  
Classes for representing and manipulating pitches, pitch-space, and accidentals.

Each :class:`~music21.note.Note` object has a `Pitch` object embedded in it.
Some methods below, such as `Pitch.name`, `Pitch.step`, etc. are
made available directly in the `Note` object, so they will seem familiar.
    )annotations)OrderedDictN)overload)base)common)SlottedObjectMixin)StepName)defaults)environment)exceptions21)interval)prebase)stylenote	PitchTypePitch)boundpitch)aAtTbBeE            	      CDr   FGr   r   zdict[StepName, int]STEPREF)r   r   r   r    r!   r"   r#   r%   r&   r   r'   r(   r   r   zdict[int, StepName]STEPREF_REVERSED>   r   r   r%   r&   r   r'   r(   zset[StepName]	STEPNAMES         STEP_TO_DNN_OFFSETgcyْ?() #z##z###z####-z-----z----~z#~`z-`)naturalsharpdouble-sharptriple-sharpquadruple-sharpflatdouble-flattriple-flatquadruple-flat
half-sharpone-and-a-half-sharp	half-flatone-and-a-half-flati*    ♯i2 )r3   rE   i+ )r5      ♭rF   )r4   rF   )r2   u   ♮nr8   isr9   isisr:   isisisr;   isisisisr<   esr=   r   esesr>   esesesr?   esesesesr@   quarter-sharprA   ih	semisharpthree-quarter-sharprB   three-quarters-sharpisihsesquisharprC   rD   )quarter-flatehsemiflatthree-quarter-flatthree-quarters-flateseh
sesquiflatc                     S HD  n / n[         R                  5        H%  n[        U5      U :X  d  M  UR                  U5        M'     Us  $    g )N)r   r-   r   r,   )accidentalNameToModifiervalueslenappend)iamssyms      G/home/james-whalen/.local/lib/python3.13/site-packages/music21/pitch.py_sortModifiersrg      sA    +224C3x1}

3 5 
     c                b    U [         ;   a  gU [         R                  5       ;   a  gU [        ;   a  gg)a  
Check if name is a valid accidental name string that can
be used to initialize an Accidental.

Standard accidental names are valid:

>>> pitch.isValidAccidentalName('double-flat')
True

Accidental modifiers are valid:

>>> pitch.isValidAccidentalName('--')
True

Alternate accidental names are valid:

>>> pitch.isValidAccidentalName('eses')
True

Anything else is not valid:

>>> pitch.isValidAccidentalName('two flats')
False
TF)r_   r`   alternateNameToAccidentalNamenames    rf   isValidAccidentalNamerm      s8    4 '' '..00 ,,rh   c                    U [         ;   a  U $ U [        ;   a	  [        U    $ U [        ;   a	  [        U    $ [        SU  S35      e)a  
Convert a valid accidental name to the standard accidental name.
Raises AccidentalException if name is not a valid accidental name.

>>> pitch.standardizeAccidentalName('double-flat')
'double-flat'

>>> pitch.standardizeAccidentalName('--')
'double-flat'

>>> pitch.standardizeAccidentalName('eses')
'double-flat'

>>> pitch.standardizeAccidentalName('two flats')
Traceback (most recent call last):
music21.pitch.AccidentalException: 'two flats' is not a supported accidental type
'z$' is not a supported accidental type)r_   modifierToAccidentalNamerj   AccidentalExceptionrk   s    rf   standardizeAccidentalNamerr      sO    $ '''''--,,,T22
$'KL
MMrh   c                n    [        U [        [        45      (       a  U $ U S;   a  gU S;   a  g[        U 5      $ )aJ  
Given a pitch class string
return the pitch class representation.
Ints and floats are returned unchanged;

>>> pitch._convertPitchClassToNumber(3)
3
>>> pitch._convertPitchClassToNumber('a')
10
>>> pitch._convertPitchClassToNumber('B')
11
>>> pitch._convertPitchClassToNumber('3')
3
>>> pitch._convertPitchClassToNumber(3.5)
3.5
)r   r   r   r   
   )r   r   r   r   r#   )
isinstanceintfloatpss    rf   _convertPitchClassToNumberrz      s;    & "sEl##	%%%%2wrh   c                    U S-  n U S $ )z
Given a pitch class number, return a string.

>>> pitch.convertPitchClassToStr(3)
'3'
>>> pitch.convertPitchClassToStr(10)
'A'
   X )pcs    rf   convertPitchClassToStrr     s     
bBVrh   c                l    [        U [        5      n [        [        R                  " U S-  5      5      S-
  $ )aU  
Utility conversion; does not process internals.
Converts a midiNote number to an octave number.
Assume C4 middle C, so 60 returns 4

>>> [pitch._convertPsToOct(59), pitch._convertPsToOct(60), pitch._convertPsToOct(61)]
[3, 4, 4]
>>> [pitch._convertPsToOct(12), pitch._convertPsToOct(0), pitch._convertPsToOct(-12)]
[0, -1, -2]
>>> pitch._convertPsToOct(135)
10

Note that while this is basically a floor operation, we only treat 6 digits as significant
(PITCH_SPACE_SIGNIFICANT_DIGITS)

>>> pitch._convertPsToOct(71.999)
4
>>> pitch._convertPsToOct(71.99999999)
5
>>> pitch._convertPsToOct(72)
5
r|   r,   )roundPITCH_SPACE_SIG_DIGITSrv   mathfloorrx   s    rf   _convertPsToOctr     s.    0 
r)	*Btzz"r'"#a''rh   c                   [        U [        5      (       a
  U S-  nSnSnOU [        U 5      :X  a  [        U 5      S-  nSnSnO[        U [        5      n U S-  n[	        US5      u  pS[        U5      n[        US5      S:X  a  SnX2-
  nO;SUs=:  a  S:  a
  O  OSnX2-
  nO$SUs=::  a  S:  a
  O  OSnX2-
  nOUS:  a  SnOSnSnSnUS:X  a"  US	;   a  [        S5      nUS-   S-  nUS
:X  a  SnOU[        ;   a  [        SU-   5      nUnOUS-
  S;   a  US:  a  [        US-
  5      nUS-   nOkUS-
  S;   a  [        SU-   5      nUS-
  nONUS-   S;   a  US::  a  [        SU-   5      nUS-
  nO+US-   S;   a  [        SU-   5      nUS-   nO[        SU 35      e[        U   n	US:w  a  [        US-  5      n
O[        S5      n
XX4$ )a_
  
Utility conversion; does not process internal representations.

Takes in a pitch space floating-point value or a MIDI note number (Assume
C4 middle C, so 60 returns 4).

Returns a tuple of Step, an Accidental object, a Microtone object or
None, and an int representing octave shift (which is nearly always zero, but can be 1
for a B with very high microtones).

>>> pitch._convertPsToStep(60)
('C', <music21.pitch.Accidental natural>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(66)
('F', <music21.pitch.Accidental sharp>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(67)
('G', <music21.pitch.Accidental natural>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(68)
('G', <music21.pitch.Accidental sharp>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(-2)
('B', <music21.pitch.Accidental flat>, <music21.pitch.Microtone (+0c)>, 0)

>>> pitch._convertPsToStep(60.5)
('C', <music21.pitch.Accidental half-sharp>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(62)
('D', <music21.pitch.Accidental natural>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(62.5)
('D', <music21.pitch.Accidental half-sharp>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(135)
('E', <music21.pitch.Accidental flat>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(70)
('B', <music21.pitch.Accidental flat>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(70.2)
('B', <music21.pitch.Accidental flat>, <music21.pitch.Microtone (+20c)>, 0)
>>> pitch._convertPsToStep(70.5)
('B', <music21.pitch.Accidental half-flat>, <music21.pitch.Microtone (+0c)>, 0)

Here is a case where perhaps D half-flat would be better:

>>> pitch._convertPsToStep(61.5)
('C', <music21.pitch.Accidental one-and-a-half-sharp>, <music21.pitch.Microtone (+0c)>, 0)


Note that Microtones can have negative and positive zeros.

>>> pitch._convertPsToStep(43.00001)
('G', <music21.pitch.Accidental natural>, <music21.pitch.Microtone (+0c)>, 0)
>>> pitch._convertPsToStep(42.999739)
('G', <music21.pitch.Accidental natural>, <music21.pitch.Microtone (-0c)>, 0)

A case where octave shift is not zero.  Here the ps of 59.8 would normally
imply octave 3, but because it is being represented by a C, it must appear
in the octave above what is implied by the ps.

>>> pitch._convertPsToStep(59.8)
('C', <music21.pitch.Accidental natural>, <music21.pitch.Microtone (-20c)>, 1)

A number very close to 60, however, is rounded, and gets no octave shift.

>>> pitch._convertPsToStep(59.9999999)
('C', <music21.pitch.Accidental natural>, <music21.pitch.Microtone (+0c)>, 0)
r|           r,         ?g      ?g      ?      ?r   )r   r#   r#   )r   r    r!   )r#   r   zcannot match condition for pc: d   )
ru   rv   r   r   divmod
AccidentalNATURAL_PCSPitchExceptionr*   	Microtone)ry   r   altermicropcRealpc_floatoctShiftaccpcNamerl   microObjs              rf   _convertPsToStepr   :  s   F "c"W	s2wWr\ 2-.b +] ?c!E MEE D EMEUQEMEQYE EE
 HzbGmmq&B 8H	{	U#
q&Y	5A:#a
q&Y	U#a
q&W	"U#a
q&W	e$a>rdCDDF#D zUS[)Q<h((rh   c                   [        U 5      nSnUS:  a  [        US5      u  p1X#-  nOUS:  a  US:  a  US-  nUS-  nUS:  a  M  US:  a  SnUS-   nOaSUs=::  a  S	:  a  O  OS
nUS-   nOIS	Us=::  a  S::  a  O  OSnUnO4SUs=:  a  S::  a  O  OSnUS-
  nOUS:  a  SnUS-
  nO[        SU 35      eXB-   [        U5      4$ )aq  
Given any floating point value, split into accidental and microtone components.

>>> pitch._convertCentsToAlterAndCents(125)
(1.0, 25.0)
>>> pitch._convertCentsToAlterAndCents(-75)
(-0.5, -25.0)
>>> pitch._convertCentsToAlterAndCents(-125)
(-1.0, -25.0)
>>> pitch._convertCentsToAlterAndCents(-200)
(-2.0, 0.0)
>>> pitch._convertCentsToAlterAndCents(235)
(2.5, -15.0)
r      r   ijr   i            Y@i      g      I@   K   r   2   zvalue exceeded range: )rw   r   
ValueError)shiftvaluealterAdd	increment
alterShiftcentss         rf   _convertCentsToAlterAndCentsr     s     %LEHs{!%-		ckSLEOH ck s{
			
			
	e	r	

	
1%9:: %,..rh   c                n    U S:  a  S[        U 5      -  n [        S[        R                  " U 5      -  5      $ )ap  
Given a harmonic number, return the total number shift in cents
assuming 12 tone equal temperament.

>>> pitch._convertHarmonicToCents(8)
3600
>>> [pitch._convertHarmonicToCents(x) for x in [5, 6, 7, 8]]
[2786, 3102, 3369, 3600]
>>> [pitch._convertHarmonicToCents(x) for x in [16, 17, 18, 19]]
[4800, 4905, 5004, 5098]

>>> [pitch._convertHarmonicToCents(x) for x in range(1, 33)]
[0, 1200, 1902, 2400, 2786, 3102, 3369, 3600, 3804, 3986, 4151,
 4302, 4441, 4569, 4688, 4800, 4905, 5004, 5098, 5186, 5271, 5351,
 5428, 5502, 5573, 5641, 5706, 5769, 5830, 5888, 5945, 6000]


Works with subHarmonics as well by specifying them as either 1/x or negative numbers.
note that -2 is the first subharmonic, since -1 == 1:

>>> [pitch._convertHarmonicToCents(1 / x) for x in [1, 2, 3, 4]]
[0, -1200, -1902, -2400]
>>> [pitch._convertHarmonicToCents(x) for x in [-1, -2, -3, -4]]
[0, -1200, -1902, -2400]

So the fifth subharmonic of the 7th harmonic,
which is C2->C3->G3->C4->E4->G4->B\`4 --> B\`3->E\`3->B\`2->G-\`2

>>> pitch._convertHarmonicToCents(7 / 5)
583
>>> pitch._convertHarmonicToCents(7.0) - pitch._convertHarmonicToCents(5.0)
583
r   r,   i  )absr   r   log2)r   s    rf   _convertHarmonicToCentsr     s3    D qySZ 		%(())rh   c                   SnSnSn/ nU (       d  gU(       aC  U  Vs/ s H  n[        UR                  5      PM     n	n[        S U	 5       5      [        U 5      -  nU(       d  U(       ae   / n[        R
                  " U S5       HG  u  p[        R                  " U5      nSUl        [        R                  " XS9nUR                  U5        MI     U(       aT  U H@  n[        R                  " U5      n[        R                   " UR"                  5      S-  nX^-  nMB     U[        U 5      -  nU(       an  U HZ  nUR$                  R&                  nUR(                  R*                  S-  nUS:X  a  US	;   a  US
-  nME  US:X  d  MM  US;   d  MU  US
-  nM\     U[        U 5      -  nXE-   U-   [-        UU-   U-   5      -  $ s  snf ! [        R                   a    [        R                  s $ f = f)aj  
Calculates the 'dissonance' of a list of pitches based on three criteria:
it is considered more consonant if 1. the numerator and denominator of the
Pythagorean ratios of its containing intervals are small (`smallPythagoreanRatio`);
2. it shows few double- or triple-accidentals (`accidentalPenalty`); 3. it shows
thirds that can form some triad (`triadAward`)
r   c              3  4   #    U  H  oS :  a  UOSv   M     g7f)r,   r   Nr~   .0r   s     rf   	<genexpr>#_dissonanceScore.<locals>.<genexpr>C  s     G;aU 1;s   r   N)	noteStartnoteEndg!a"k?r|   r-   )r-   r   r   r.   )   r"   )r   r   sumra   	itertoolscombinationscopydeepcopyoctaver   Intervalrb   IntervalExceptionr   infintervalToPythagoreanRatiologdenominatorgenericsimpleDirected	chromatic	semitonesrv   )pitchessmallPythagoreanRatioaccidentalPenalty
triadAwardscore_accidentalsscore_ratioscore_triad	intervalspaccidentalsp1p2this_intervalratiopenaltysimple_directedinterval_semitoness                    rf   _dissonanceScorer   ,  s    KK)+I-45Ws177|W5G;GG#g,V
	I#00!<]]2& 	 ( 1 1B K  /	 = &M77FEhhu001MAG"K	 ' 	s7|#&M+33BBO!.!8!8!B!BR!G!#(:f(Ds" A%*<*Fs" ' 	s7|#+k9SAVCTBUWaBb >c c cE 6 )) 	88O	s   F7*A$F< <$G#"G#c                   ^ ^ T SS  Vs/ s H  o"/UR                  5       -   PM     nn[        R                  " U6 n[        UU U4S jS9nT SS [	        U5      -   $ s  snf )zN
A brute-force way of simplifying -- useful if there are fewer than 5 pitches
r,   Nc                2   > T" TS S [        U 5      -   5      $ )Nr,   )list)x
oldPitches	scoreFuncs    rf   <lambda>._bruteForceEnharmonicsSearch.<locals>.<lambda>n  s    9ZPRQR^VZ[\V]E];^rh   key)getAllCommonEnharmonicsr   productminr   )r   r   r   all_possible_pitchesall_pitch_combinations
newPitchess   ``    rf   _bruteForceEnharmonicsSearchr   h  sn     HRRSRT~V~!C!";";"==~V&..0DE+1^_Jbq>D,,, Ws   Ac                   ^^ U S S mU SS   H7  nU/UR                  5       -   n[        UUU4S jS9nTR                  U5        M9     T$ )Nr,   c                   > T" TU /-   5      $ Nr~   )r   r   r   s    rf   r   *_greedyEnharmonicsSearch.<locals>.<lambda>v  s    :;K1Lrh   r   )r   r   rb   )r   r   oldPitch
candidatesnewPitchr   s    `   @rf   _greedyEnharmonicsSearchr   r  sV    BQJqrNZ("B"B"DD
z'LM(# # rh   c                x   U  Vs/ s H%  n[        U[        5      (       a  UO
[        U5      PM'     nnU(       a"  UR                  S5      R                  /U-   nSnOSn[	        U5      S:  a  [        XA5      nO[        XA5      n[        XF5       H  u  pxUR                  Ul        M     U(       a  USS nU$ s  snf )aZ	  
Tries to simplify the enharmonic spelling of a list of pitches, pitch-
or pitch-class numbers according to a given criterion.

A function can be passed as an argument to `criterion`, that is tried to be
minimized in a greedy left-to-right fashion.

>>> pitch.simplifyMultipleEnharmonics([11, 3, 6])
[<music21.pitch.Pitch B>, <music21.pitch.Pitch D#>, <music21.pitch.Pitch F#>]

>>> pitch.simplifyMultipleEnharmonics([3, 8, 0])
[<music21.pitch.Pitch E->, <music21.pitch.Pitch A->, <music21.pitch.Pitch C>]

>>> pitch.simplifyMultipleEnharmonics([pitch.Pitch('G3'),
...                                    pitch.Pitch('C-4'),
...                                    pitch.Pitch('D4')])
[<music21.pitch.Pitch G3>, <music21.pitch.Pitch B3>, <music21.pitch.Pitch D4>]

>>> pitch.simplifyMultipleEnharmonics([pitch.Pitch('A3'),
...                                    pitch.Pitch('B#3'),
...                                    pitch.Pitch('E4')])
[<music21.pitch.Pitch A3>, <music21.pitch.Pitch C4>, <music21.pitch.Pitch E4>]

The attribute `keyContext` is for supplying a KeySignature or a Key
which is used in the simplification:

>>> pitch.simplifyMultipleEnharmonics([6, 10, 1], keyContext=key.Key('B'))
[<music21.pitch.Pitch F#>, <music21.pitch.Pitch A#>, <music21.pitch.Pitch C#>]

>>> pitch.simplifyMultipleEnharmonics([6, 10, 1], keyContext=key.Key('C-'))
[<music21.pitch.Pitch G->, <music21.pitch.Pitch B->, <music21.pitch.Pitch D->]


Note that if there's no key context, then we won't simplify everything (at least
for now; this behavior may change, ).

>>> pitch.simplifyMultipleEnharmonics([pitch.Pitch('D--3'),
...                                    pitch.Pitch('F-3'),
...                                    pitch.Pitch('A--3')])
[<music21.pitch.Pitch D--3>, <music21.pitch.Pitch F-3>, <music21.pitch.Pitch A--3>]



>>> pitch.simplifyMultipleEnharmonics([pitch.Pitch('D--3'),
...                                    pitch.Pitch('F-3'),
...                                    pitch.Pitch('A--3')],
...                                    keyContext=key.Key('C'))
[<music21.pitch.Pitch C3>, <music21.pitch.Pitch E3>, <music21.pitch.Pitch G3>]

* Changed in v7.3: fixed a bug with compound intervals (such as formed against
  the tonic of a KeySignature defaulting to octave 4):

>>> pitch.simplifyMultipleEnharmonics([pitch.Pitch('B5')], keyContext=key.Key('D'))
[<music21.pitch.Pitch B5>]
majorTFr    r,   N)	ru   r   asKeytonicra   r   r   zipspellingIsInferred)	r   	criterion
keyContextr   r   remove_firstsimplifiedPitchesoldPnewPs	            rf   simplifyMultipleEnharmonicsr   {  s    r DKK7az!U++!q97JK &&w/556C

:8O4ZK *8
"&"9"9 9 -ab1) Ls   ,B7c                      \ rS rSrSrg)rq   i  r~   N__name__
__module____qualname____firstlineno____static_attributes__r~   rh   rf   rq   rq         rh   rq   c                      \ rS rSrSrg)r   i  r~   Nr  r~   rh   rf   r   r     r  rh   r   c                      \ rS rSrSrg)MicrotoneExceptioni  r~   Nr  r~   rh   rf   r
  r
    r  rh   r
  c                      \ rS rSrSrSr  S SS jjrS rS rS r	S r
S	 rS
 r\S 5       r\S 5       r\S 5       r\R"                  S 5       rSrg)r   i  a  
The Microtone object defines a pitch transformation above or below a
standard Pitch and its Accidental.

>>> m = pitch.Microtone(20)
>>> m.cents
20

>>> m.alter
0.2...

>>> print(m)
(+20c)
>>> m
<music21.pitch.Microtone (+20c)>

Microtones can be shifted according to the harmonic. Here we take the 3rd
harmonic of the previous microtone


>>> m.harmonicShift = 3
>>> m.harmonicShift
3
>>> m
<music21.pitch.Microtone (+20c+3rdH)>

>>> m.cents
1922

>>> m.alter
19.2...

Microtonal changes can be positive or negative.  Both Positive and negative
numbers can optionally be placed in parentheses Negative numbers in
parentheses still need the minus sign.

>>> m = pitch.Microtone('(-33.333333)')
>>> m
<music21.pitch.Microtone (-33c)>

>>> m = pitch.Microtone('33.333333')
>>> m
<music21.pitch.Microtone (+33c)>

Note that we round the display of microtones to the nearest cent, but we
keep the exact alteration in both .cents and .alter:

>>> m.cents
33.333...

>>> m.alter
0.3333...

)
_centShift_harmonicShiftc                    SU l         X l        [        U[        [        45      (       a  Xl         g U R                  U5        g Nr   )r  r  ru   rv   rw   _parseString)selfcentsOrStringharmonicShifts      rf   __init__Microtone.__init__  s5     &'#0mc5\22+Om,rh   c                    [        U 5      [        L a   [        U R                  U R                  5      $ [        R
                  " X5      $ r   )typer   r  r  r   defaultDeepcopy)r  memos     rf   __deepcopy__Microtone.__deepcopy__,  s6    :"T__d.A.ABB))$55rh   c                \     UR                   U R                   :X  a  gg! [         a     gf = f)a!  
Compare cents (including harmonicShift)

>>> m1 = pitch.Microtone(20)
>>> m2 = pitch.Microtone(20)
>>> m3 = pitch.Microtone(21)
>>> m1 == m2
True
>>> m1 == m3
False

>>> m2.harmonicShift = 3
>>> m1 == m2
False

Cannot compare True to a non-Microtone:

>>> m1 == pitch.Accidental(1)
False
TF)r   AttributeErrorr  others     rf   __eq__Microtone.__eq__2  s/    *	{{djj( 		s    
++c                \    U R                   U R                  [        U 5      4n[        U5      $ r   )r  r  r  hashr  
hashValuess     rf   __hash__Microtone.__hash__N  s-    OOJ


 Jrh   c                    [        U 5      $ r   strr  s    rf   _reprInternalMicrotone._reprInternalW      4yrh   c                B   Sn[        U R                  5      nU R                  S:  a  SU S3nOU R                  S:  a  U S3nUS:X  a  SnU R                  S:w  a5  [        R                  " U R                  5      nUSU R                   U S3-  n[
         U [         3$ )	z
Return a string representation.

>>> m1 = pitch.Microtone(20)
>>> print(m1)
(+20c)

Differs from the representation:

>>> m1
<music21.pitch.Microtone (+20c)>
r2   r   +c0cz-0cr,   H)r   r  r  r   ordinalAbbreviationMICROTONE_OPENMICROTONE_CLOSE)r  sub
roundShiftordAbbreviations       rf   __str__Microtone.__str__Z  s     4??+
??aj\#C__q L"Cd{ !#$889L9LMOQt**+O+<A>>C !#&788rh   c                ~   UR                  [        S5      nUR                  [        S5      nSnUS   S:X  d  US   R                  5       (       a7  [        R
                  " USS9u  p4US:X  a  [        SU 35      e[        U5      nO1US   S:X  a(  [        R
                  " USS	 SS9u  p4[        U5      S
-  nX l        g	)z 
Parse a string representation.
r2   r   r0  z0123456789.)numbersz"no numbers found in string value: r4   r,   Nr   )	replacer5  r6  isdigitr   getNumFromStrr
  rw   r  )r  r   	centValuenumunused_nonNums        rf   r  Microtone._parseStringy  s    
 nb1or2	 8s?eAh..00!'!5!5e]!SCby(+MeW)UVVc
I1X_!'!5!5eABi!WCc
RI#rh   c                     U R                   S-  $ )z[
Return the microtone value in accidental alter values.

>>> pitch.Microtone(20).alter
0.2
{Gz?)r   r+  s    rf   r   Microtone.alter  s     zzD  rh   c                F    [        U R                  5      U R                  -   $ )z
Return the microtone value in cents.  This is not a settable property.
To set the value in cents, simply use that value as a creation
argument.

>>> pitch.Microtone(20).cents
20
)r   r  r  r+  s    rf   r   Microtone.cents  s     't':':;dooMMrh   c                    U R                   $ )z7
Set or get the harmonic shift, altering the microtone
r  r+  s    rf   r  Microtone.harmonicShift  s    
 """rh   c                    Xl         g r   rK  r  r   s     rf   r  rL    s    #rh   N)r   r,   )r  zstr | int | float)r  r  r  r  __doc__	__slots__r  r  r   r&  r,  r:  r  propertyr   r   r  setterr  r~   rh   rf   r   r     s    5rI 12 	- -	-68 9>$. ! ! 	N 	N # # $ $rh   r   c                    ^  \ rS rSr% Sr\R                  rSr/ SQr	SSSS.r
S	\S
'   S*S+U 4S jjjrS rS rS rS rS rS rS rS rS rS r\S 5       rSS.S jrS rS rS r\S,S j5       r\R>                  S 5       r\S-S j5       r \ R>                  S  5       r \S,S! j5       r!\!R>                  S" 5       r!\S,S# j5       r"\"R>                  S.S$ j5       r"\S% 5       r#\#R>                  S& 5       r#\S' 5       r$\S( 5       r%S)r&U =r'$ )/r   i  a  
Accidental class, representing the symbolic and numerical representation of
pitch deviation from a pitch name (e.g., G, B).

Two accidentals are considered equal if their names are equal.

Accidentals have three defining attributes: a name, a modifier, and an
alter.  For microtonal specifications, the name and modifier are the same
except in the case of half-sharp, half-flat, one-and-a-half-flat, and
one-and-a-half-sharp.

Accidentals up to quadruple-sharp and quadruple-flat are allowed.

Natural-sharp etc. (for canceling a previous flat) are not yet supported officially.

>>> a = pitch.Accidental('sharp')
>>> a.name, a.alter, a.modifier
('sharp', 1.0, '#')
>>> a.style.color = 'red'

>>> import copy
>>> b = copy.deepcopy(a)
>>> b.style.color
'red'
)	_alter_displayStatus_displayType	_modifier_name_clientdisplayLocationdisplaySizedisplayStyle)rl   modifierr   setz1Size in display: "cue", "large", or a percentage.z3Style of display: "parentheses", "bracket", "both".z3Location of accidental: "normal", "above", "below".)r[  r\  rZ  dict[str, str]	_DOC_ATTRc                   > [         TU ]  5         SU l        S U l        SU l        SU l        SU l        S U l        SU l        SU l	        SU l
        U R                  U5        g )Nnormalfullr2   r   )superr  rV  rU  r\  r[  rZ  rY  rX  rW  rT  r^  )r  	specifier	__class__s     rf   r  Accidental.__init__  sf    $ # %!  ( $(
rh   c                    U R                   U R                  U R                  U R                  U R                  U R
                  U R                  U R                  4$ r   )rT  rU  rV  rW  rX  rZ  r[  r\  r+  s    rf   _hashValuesAccidental._hashValues  sN    KKNNJJ  	
 		
rh   c                4    [        U R                  5       5      $ r   )r#  ri  r+  s    rf   r&  Accidental.__hash__
  s    D$$&''rh   c           	         [        U 5      [        L aG  [        R                  [        5      nU R                  5        H  n[	        X#[        X5      5        M     U$ [        R                  " X5      $ r   )r  r   __new___getSlotsRecursivesetattrgetattrr   r  )r  r  newss       rf   r  Accidental.__deepcopy__  sV    :#$$Z0C,,. 01 /J))$55rh   c                f    [        U[        5      (       d  gU R                  UR                  :X  a  gg)z
Equality. Needed for pitch comparisons.

>>> a = pitch.Accidental('double-flat')
>>> b = pitch.Accidental('double-flat')
>>> c = pitch.Accidental('double-sharp')
>>> a == b
True

>>> a == c
False
FT)ru   r   rl   r  s     rf   r   Accidental.__eq__  s*     %,,99

"rh   c                T    U R                  U5      =(       d    U R                  U5      $ )z
Greater than or equal.  Based on the accidentals' alter function.

>>> a = pitch.Accidental('sharp')
>>> b = pitch.Accidental('flat')
>>> a >= b
True

)__gt__r   r  s     rf   __ge__Accidental.__ge__*  s!     {{5!7T[[%77rh   c                l    Ub  [        U[        5      (       d  gU R                  UR                  :  a  gg)z
Greater than.  Based on the accidentals' alter function.

>>> a = pitch.Accidental('sharp')
>>> b = pitch.Accidental('flat')
>>> a < b
False

>>> a > b
True

>>> a > 5
False
FTru   r   r   r  s     rf   rx  Accidental.__gt__6  .     =
5* = =::#rh   c                T    U R                  U5      =(       d    U R                  U5      $ )z
Less than or equal.  Based on the accidentals' alter function.

>>> a = pitch.Accidental('sharp')
>>> b = pitch.Accidental('flat')
>>> c = pitch.Accidental('sharp')
>>> a <= b
False

>>> a <= c
True
)__lt__r   r  s     rf   __le__Accidental.__le__L  s!     {{5!7T[[%77rh   c                l    Ub  [        U[        5      (       d  gU R                  UR                  :  a  gg)z
Less than. based on alter.

>>> a = pitch.Accidental('natural')
>>> b = pitch.Accidental('flat')
>>> a > b
True

>>> a < b
False

>>> a < 5
False
FTr|  r  s     rf   r  Accidental.__lt__[  r~  rh   c                    U R                   $ r   rk   r+  s    rf   r,  Accidental._reprInternalq      yyrh   c                    U R                   $ r   rk   r+  s    rf   r:  Accidental.__str__t  r  rh   c                .    [        S [         5       5      $ )a  
Returns a list of accidental names that have any sort of
semantic importance in music21.

You may choose a name not from this list (1/7th-sharp) but
if it's not on this list don't expect it to do anything for you.

This is a class method, so you may call it directly on the class:

Listed in alphabetical order. (TODO: maybe from lowest to highest
or something implying importance?)

>>> pitch.Accidental.listNames()
 ['double-flat', 'double-sharp', 'flat', 'half-flat',
  'half-sharp', 'natural', 'one-and-a-half-flat', 'one-and-a-half-sharp',
  'quadruple-flat', 'quadruple-sharp', 'sharp', 'triple-flat', 'triple-sharp']

Or call on an instance of an accidental:

>>> f = pitch.Accidental('flat')
>>> f.listNames()
 ['double-flat', 'double-sharp', 'flat', 'half-flat', 'half-sharp', 'natural',
  'one-and-a-half-flat', 'one-and-a-half-sharp', 'quadruple-flat', 'quadruple-sharp',
  'sharp', 'triple-flat', 'triple-sharp']
c              3  @   #    U  H  oR                  5       v   M     g 7fr   )lowerr   s     rf   r   'Accidental.listNames.<locals>.<genexpr>  s     B)AAggii)As   )sortedr_   )clss    rf   	listNamesAccidental.listNamesw  s    6 B)ABBBrh   FallowNonStandardValuec                  [        U[        5      (       a  UR                  5       nUS;   a  SU l        SU l        GOUS[
        S   SS4;   a  SU l        SU l        GOUS[
        S   S	S
4;   a  SU l        SU l        GOUS[
        S   SSS4;   a  SU l        SU l        GOUS[
        S   SS4;   a  SU l        SU l        GOnUS[
        S   SSSS4;   a  SU l        SU l        GOKUS[
        S   SSSSS4;   a  SU l        SU l        GO'US [
        S    S!S"S#S$4;   a  S U l        S$U l        GOUS%[
        S%   S&S'S(S)S*4;   a  S%U l        S*U l        OUS+[
        S+   S,S-4;   a  S+U l        S.U l        OUS/[
        S/   S0S14;   a  S/U l        S2U l        OUS3[
        S3   S4S54;   a  S3U l        S6U l        OUS7[
        S7   S8S94;   a  S7U l        S:U l        OaU(       d  [        U S;35      e[        U[        5      (       a  Xl        g<[        U[        [        45      (       a  Xl        g<[        U S;35      e[
        U R                     U l	        U R                  (       a  U R                  R                  5         g<g<)=a  
Change the type of the Accidental.  Strings, numbers, and Lilypond (German-like)
abbreviations are all accepted.  All other values will change
after setting.

>>> a = pitch.Accidental()
>>> a.set('sharp')
>>> a.alter
1.0

>>> a = pitch.Accidental()
>>> a.set(2)
>>> a.modifier == '##'
True

>>> a = pitch.Accidental()
>>> a.set(2.0)
>>> a.modifier == '##'
True

>>> a = pitch.Accidental('--')
>>> a.alter
-2.0
>>> a.set('half-sharp')
>>> a.alter
0.5
>>> a.name
'half-sharp'

Setting an illegal name is generally an error:

>>> a.set('flat-flat-up')
Traceback (most recent call last):
music21.pitch.AccidentalException: flat-flat-up is not a supported accidental type

But if 'allowNonStandardValue' is True then other names (if strings) or alters (if numbers)
are allowed:

>>> a.set('quintuple-sharp', allowNonStandardValue=True)
>>> a.set(5.0, allowNonStandardValue=True)
>>> a.name
'quintuple-sharp'
>>> a.alter
5.0

This is the argument that .name and .alter use to allow non-standard names


* Changed in v5: added allowNonStandardValue
)r8   rG   r   r8   r   r9   rH   r,   r   r:   rI   r          @r=   rL   r   r   r   r>   rM   g       rA   rP   rQ   rR   r   rB   rS   rT   rU   rV   g      ?rC   rW   rX   rY   r   rD   rZ   r[   r\   r]   g      r;   rJ   r-         @r<   rK   r         @r?   rN   g      r@   rO   g      z# is not a supported accidental typeN)ru   r*  r  rX  rT  r_   rq   rv   rw   rW  rY  informClient)r  rl   r  s      rf   r^  Accidental.set  s   f dC  ::<D&&"DJDKg7@$JJ DJDKn&>~&Na! !'DJDKf6v>c2NNDJDKm%=m%Lb" "&DJDKl$<\$J%t[#? ?%DJDK,./EF+-CV#S* * 0DJDKk#;K#H$dJ> >$DJDK+./DE*,A6"D* * /DJDKn&>~&N# #'DJDK'./@A:qR R*DJDKm%=m%L$ $&DJDK&./?@*bR R)DJDK()TF2U*VWW$$$!
D3,//")TF2U*VWW1$**=<<LL%%' rh   c                &    U R                   S;   a  gg)z
Return a boolean if this Accidental describes a twelve-tone, non-microtonal pitch.

>>> a = pitch.Accidental('half-flat')
>>> a.isTwelveTone()
False

>>> a = pitch.Accidental('###')
>>> a.isTwelveTone()
True
)rA   rB   rC   rD   FTrk   r+  s    rf   isTwelveToneAccidental.isTwelveTone  s     99 = =rh   c                    US;  a  [        SU S35      eUS:X  a  [        U5      nSU-   n[        XU5        U R                  (       a  U R                  R	                  5         gg)a  
Set an attribute of 'name', 'alter', and 'modifier', independently
of the other attributes.

>>> a = pitch.Accidental('natural')
>>> a.setAttributeIndependently('alter', 1.0)
>>> a.alter
1.0
>>> a.name
'natural'

>>> a.setAttributeIndependently('name', 'sori')
>>> a.setAttributeIndependently('modifier', '$')
>>> a.modifier
'$'
>>> a.name
'sori'
>>> a.alter
1.0

Only 'name', 'alter', and 'modifier' can be set independently:

>>> a.setAttributeIndependently('color', 'red')
Traceback (most recent call last):
music21.pitch.AccidentalException: Cannot set attribute color independently of other parts.

* New in v5: needed because .name, .alter, and .modifier run .set()
)rl   r   r]  zCannot set attribute z independently of other parts.r   _N)rq   rw   rp  rY  r  )r  	attributer   privateAttrNames       rf   setAttributeIndependently$Accidental.setAttributeIndependently%  sk    : 99%'	{2PQS S %LE	/u-<<LL%%' rh   c                L    Ub!  S H  n[        X5      n[        XU5        M     gg)aK  
Given another Accidental object, inherit all the display properties
of that object.

This is needed when transposing Pitches: we need to retain accidental display properties.

>>> a = pitch.Accidental('double-flat')
>>> a.displayType = 'always'
>>> b = pitch.Accidental('sharp')
>>> b.inheritDisplay(a)
>>> b.displayType
'always'
N)displayTypedisplayStatusr\  r[  rZ  )rq  rp  )r  r  attrr   s       rf   inheritDisplayAccidental.inheritDisplayO  s1     K,E*K rh   c                    U R                   $ )a  
Get or set the name of the Accidental, like 'sharp' or 'double-flat'

If the name is set to a standard name then it changes alter and modifier.

If set to a non-standard name, then it does not change them:

>>> a = pitch.Accidental()
>>> a.name = 'flat'
>>> a.alter
-1.0
>>> a.modifier
'-'
>>> a.name = 'flat-flat-up'
>>> a.alter
-1.0

* Changed in v5: changing the name here changes other values, conditionally
)rX  r+  s    rf   rl   Accidental.nameg  s    * zzrh   c                $    U R                  USS9  g NTr  r^  rN  s     rf   rl   r  ~  s    d3rh   c                    U R                   $ )a=  
Get or set the alter of the Accidental,
or the semitone shift caused by the Accidental where 1.0
is a shift up of one semitone, and -1.0 is the shift down of
one semitone.

>>> sharp = pitch.Accidental('sharp')
>>> sharp.alter
1.0

>>> sharp.alter = -1

After changing alter to a known other value, name changes:

>>> sharp.name
'flat'

But changing it to an unusual value does not change the name:

>>> notSoFlat = pitch.Accidental('flat')
>>> notSoFlat.alter = -0.9
>>> notSoFlat.name
'flat'

* Changed in v5: changing the alter here changes other values, conditionally
)rT  r+  s    rf   r   Accidental.alter  s    8 {{rh   c                $    U R                  USS9  g r  r  rN  s     rf   r   r    s     	d3rh   c                    U R                   $ )a  
Get or set the alter of the modifier, or the string symbol
used to modify the pitch name, such as "#" or
"-" for sharp and flat, respectively.  For a representation
likely to be read by non-music21 users, see `.unicode`.

>>> f = pitch.Accidental('flat')
>>> f.modifier
'-'
>>> f.modifier = '#'
>>> f.name
'sharp'

However, an unknown modifier does not change anything but is preserved:

>>> f.modifier = '&'
>>> f.modifier
'&'
>>> f.name
'sharp'

* Changed in v5: changing the modifier here changes
  other values, conditionally
)rW  r+  s    rf   r]  Accidental.modifier  s    4 ~~rh   c                R     U R                  USS9  g ! [         a	    Xl         g f = f)NFr  )r^  rq   rW  rN  s     rf   r]  r    s+    	#HHU%H8" 	#"N	#s    &&c                    U R                   $ )a  
Returns or sets the display type of the accidental

`"normal"` (default) displays it if it is the first in measure,
or is needed to contradict a previous accidental, etc.

other valid terms:

* "always"
* "never"
* "unless-repeated" (show always unless
  the immediately preceding note is the same)
* "even-tied" (stronger than always: shows even
  if it is tied to the previous note)
* "if-absolutely-necessary" (display only if it is absolutely necessary,
  like an F-natural after an F-sharp in the same measure, but not an
  F-natural following an F-sharp directly across a barline.  Nor an
  F-natural in a different octave immediately following an F-sharp).
  This is not yet implemented.

>>> a = pitch.Accidental('flat')
>>> a.displayType = 'unless-repeated'
>>> a.displayType
'unless-repeated'
>>> a.displayType = 'underwater'
Traceback (most recent call last):
music21.pitch.AccidentalException: Supplied display type is not supported: 'underwater'
)rV  r+  s    rf   r  Accidental.displayType  s    <    rh   c                :    US;  a  [        SU< 35      eXl        g )N)rb  alwaysneverzunless-repeated	even-tiedif-absolutely-necessaryz(Supplied display type is not supported: )rq   rV  rN  s     rf   r  r    s,     T T%(PQVPY&Z[[!rh   c                    U R                   $ )a  
Determines if this Accidental is to be displayed;
can be None (for not set), True, or False.  In general do not
set this, set .displayType instead.  Music21 will change displayStatus
at any time without warning.

While `.displayType` gives general rules about when this accidental
should be displayed or not, `displayStatus` determines whether after
applying those rules this accidental will be displayed.

In general, a `displayStatus` of `None` means that no high-level
processing of accidentals has happened.

Can be set to True or False (or None) directly for contexts where
the next program down the line cannot evaluate displayType.  See
stream.makeAccidentals() for more information.

Example:

>>> n0 = note.Note('C#4')
>>> n1 = note.Note('C#4')
>>> print(n0.pitch.accidental.displayStatus)
None
>>> print(n1.pitch.accidental.displayStatus)
None
>>> s = stream.Stream()
>>> s.append([n0, n1])
>>> s.makeAccidentals(inPlace=True)
>>> n0.pitch.accidental.displayStatus
True
>>> n1.pitch.accidental.displayStatus
False

>>> n1.pitch.accidental.displayStatus = 2
Traceback (most recent call last):
music21.pitch.AccidentalException: Supplied display status is not supported: 2
)rU  r+  s    rf   r  Accidental.displayStatus  s    N """rh   c                8    US;  a  [        SU 35      eXl        g )N)TFNz*Supplied display status is not supported: )rq   rU  rN  s     rf   r  r    s&    ++%(RSXRY&Z[[#rh   c                h    U R                   [        ;   a  [        U R                      $ U R                   $ )u  
Return a unicode representation of this accidental
or the best unicode representation if that is not possible.

>>> flat = pitch.Accidental('flat')
>>> flat.unicode
'♭'

Compare:

>>> sharp = pitch.Accidental('sharp')
>>> sharp.modifier
'#'
>>> sharp.unicode
'♯'

Some accidentals, such as double sharps, produce code points outside
the 2-byte set (so called "astral plane" unicode) and thus cannot be
used in every circumnstance.

>>> sharp = pitch.Accidental('quadruple-flat')
>>> sharp.unicode
'𝄫𝄫'
)r]  unicodeFromModifierr+  s    rf   unicodeAccidental.unicode  s*    8 ==//&t}}55== rh   c                    U R                   $ )a6  
Return the most complete representation of this Accidental.

>>> a = pitch.Accidental('double-flat')
>>> a.fullName
'double-flat'

Note that non-standard microtone names are converted to standard ones:

>>> a = pitch.Accidental('quarter-flat')
>>> a.fullName
'half-flat'

For now this is the same as `.name`.
rk   r+  s    rf   fullNameAccidental.fullName@  s    $ yyrh   )	rT  rY  rU  rV  rW  rX  rZ  r[  r\  )r8   )re  zint | str | floatreturnr*  r  rw   r   r*  )(r  r  r  r  rO  r   	TextStyle_styleClassrP  
_DOC_ORDERr`  __annotations__r  ri  r&  r  r   ry  rx  r  r  r,  r:  classmethodr  r^  r  r  r  rQ  rl   rR  r   r]  r  r  r  r  r  __classcell__)rf  s   @rf   r   r     s   2 //K
I 6J KMP!I~  0

(6(
8,8, C C< 27 z(z$'(T+0  , 
[[4 4  : \\4 4  6 __# # ! !> " " &# &#P $ $
 ! !@  rh   r   c            
         \ rS rSr% Sr/ SQr\rSS0rS\	S'    SoSSSSSSSSS	.                 SpS
 jjjr
S rS rSqS jrS rS rSrS jrSrS jrSrS jrSrS jr\SsS j5       r\R,                  StS j5       r\SuS j5       r\R,                  SvS j5       r\SwS j5       r\R,                  SxS j5       rSrS jrSyS jr\SzS j5       rSS.S jrSS.S  jr\S! 5       r\R,                  S" 5       r\S# 5       r\R,                  S$ 5       r\S{S% j5       r \ R,                  S|S& j5       r \S{S' j5       r!\S{S( j5       r"\"R,                  S}S) j5       r"\S{S* j5       r#\S+ 5       r$\S~S, j5       r%\%R,                  SS- j5       r%\SyS. j5       r&\&R,                  SS/ j5       r&\S{S0 j5       r'\'R,                  S1 5       r'\SS2 j5       r(\(R,                  SS3 j5       r(\SyS4 j5       r)\S{S5 j5       r*\S{S6 j5       r+S{S7 jr,S8S9S:S;S<S=S>S?.r-S@\	SA'   \S{SB j5       r.S8S9S:SCS<S=S>S?.r/S@\	SD'   \S{SE j5       r0\SzSF j5       r1\1R,                  SSG j5       r1\SzSH j5       r2\2R,                  SSI j5       r2SSJ jr3    SSK jr4 So   SSL jjr5    SSM jr6    SSN jr7SSO jr80 r9SP\	SQ'   \:      SSR j5       r;\:      SSS j5       r;      SST jr;\:SSU j5       r<\:SSV j5       r<SS.SSW jjr<\:SSX j5       r=\:SSY j5       r=SS.SSZ jjr=SSS[.   SS\ jjr>SS.SS] jjr?S^ r@SSS_ jjrA\SyS` j5       rB\BR,                  SSa j5       rB\:        SSb j5       rC\:SS.       SSc jj5       rCSS.       SSd jjrCSSSe.   SSf jjrDSSSe. SSg jjrESh rFSi rGSSSSSjSSSjSSk.	                 SSl jjrHSm rISnrJg)r   iX  a  
A fundamental object that represents a single pitch.

`Pitch` objects are most often created by passing in a note name
(C, D, E, F, G, A, B), an optional accidental (one or more "#"s or "-"s,
where "-" means flat), and an optional octave number:

>>> highEflat = pitch.Pitch('E-6')
>>> highEflat.name
'E-'
>>> highEflat.step
'E'
>>> highEflat.accidental
<music21.pitch.Accidental flat>
>>> highEflat.octave
6

The `.nameWithOctave` property gives back what we put in, `'E-6'`:

>>> highEflat.nameWithOctave
'E-6'


`Pitch` objects represent themselves as the class name followed
by the `.nameWithOctave`:

>>> p1 = pitch.Pitch('a#4')
>>> p1
<music21.pitch.Pitch A#4>

Printing a `pitch.Pitch` object or converting it
to a string gives a more compact form:

>>> print(p1)
A#4
>>> str(p1)
'A#4'

.. warning:: A `Pitch` without an accidental has a `.accidental` of None,
    not Natural.  This can lead to problems if you assume that every
    `Pitch` or `Note` has a `.accidental` that you can call `.alter`
    or something like that on:

    >>> c = pitch.Pitch('C4')
    >>> c.accidental is None
    True

    >>> alters = []
    >>> for pName in ['G#5', 'B-5', 'C6']:
    ...     p = pitch.Pitch(pName)
    ...     alters.append(p.accidental.alter)
    Traceback (most recent call last):
    AttributeError: 'NoneType' object has no attribute 'alter'
    >>> alters
    [1.0, -1.0]


If a `Pitch` doesn't have an associated octave, then its
`.octave` value is None.  This means that it represents
any G#, regardless of octave.  Transposing this note up
an octave doesn't change anything.

>>> anyGSharp = pitch.Pitch('G#')
>>> anyGSharp.octave is None
True
>>> print(anyGSharp.transpose('P8'))
G#

Sometimes we need an octave for a `Pitch` even if it's not
specified.  For instance, we can't play an octave-less `Pitch`
in MIDI or display it on a staff.  So there is an `.implicitOctave`
tag to deal with these situations; by default it's always 4 (unless
defaults.pitchOctave is changed)

>>> anyGSharp.implicitOctave
4

If a `Pitch` has its `.octave` explicitly set, then `.implicitOctave`
always equals `.octave`.

>>> highEflat.implicitOctave
6

If an integer or float >= 12 is passed to the constructor then it is
used as the `.ps` attribute, which is for most common piano notes, the
same as a MIDI number:

>>> pitch.Pitch(65)
<music21.pitch.Pitch F4>

>>> pitch.Pitch(65.5).accidental
<music21.pitch.Accidental half-sharp>


A `pitch.Pitch` object can also be created using only a number
from 0-11, that number is taken to be a `pitchClass`, where
0 = C, 1 = C#/D-, etc. and no octave is set.

>>> p2 = pitch.Pitch(3)
>>> p2
<music21.pitch.Pitch E->
>>> p2.octave is None
True

Since in instantiating pitches from numbers,
`pitch.Pitch(3)` could be either a D# or an E-flat,
this `Pitch` object has an attribute called `.spellingIsInferred` that
is set to `True`.  That means that when it is transposed or
displayed, other functions or programs should feel free to substitute an
enharmonically equivalent pitch in its place:

>>> p2.spellingIsInferred
True
>>> p1.spellingIsInferred
False

As MIDI numbers < 12 are almost unheard of in actual music,
there is unlikely to be confusion between
a pitchClass instantiation and a MIDI number instantiation, but if one must be
clear, use `midi=` in the constructor:

>>> lowE = pitch.Pitch(midi=3)
>>> lowE.name, lowE.octave
('E-', -1)


Instead of using a single string or integer for creating the object, a succession
of named keywords can be used instead:

>>> p3 = pitch.Pitch(name='C', accidental='#', octave=7, microtone=-30)
>>> p3.fullName
'C-sharp in octave 7 (-30c)'

The full list of supported keywords are: `name`, `accidental` (which
can be a string or an :class:`~music21.pitch.Accidental` object), `octave`,
microtone (which can be a number or a :class:`~music21.pitch.Microtone` object),
`pitchClass` (0-11), `fundamental` (another `Pitch` object representing the
fundamental for this harmonic; `harmonic` is not yet supported, but should be),
and `midi` or `ps` (two ways of specifying nearly the same thing, see below).

Using keywords to create `Pitch` objects is especially important if
extreme pitches might be found.  For instance, the first `Pitch` is B-double flat
in octave 3, not B-flat in octave -3.  The second object creates that low `Pitch`
properly:

>>> p4 = pitch.Pitch('B--3')
>>> p4.accidental
<music21.pitch.Accidental double-flat>
>>> p4.octave
3

>>> p5 = pitch.Pitch(step='B', accidental='-', octave=-3)
>>> p5.accidental
<music21.pitch.Accidental flat>
>>> p5.octave
-3

Internally, pitches are represented by their
scale step (`self.step`), their octave, and their
accidental. `Pitch` objects use these three elements to figure out their
pitch space representation (`self.ps`); altering any
of the first three changes the pitch space (ps) representation.
Similarly, altering the .ps representation
alters the first three.

>>> aSharp = pitch.Pitch('A#5')
>>> aSharp.ps
82.0

>>> aSharp.octave = 4
>>> aSharp.ps
70.0

>>> aSharp.ps = 60.0
>>> aSharp.nameWithOctave
'C4'

Two Pitches are equal if they represent the same
pitch and are spelled the same (enharmonics do not count).
A Pitch is greater than another Pitch if its `.ps` is greater than
the other.  Thus, C##4 > D-4.

>>> pitch.Pitch('C#5') == pitch.Pitch('C#5')
True
>>> pitch.Pitch('C#5') == pitch.Pitch('D-5')
False
>>> pitch.Pitch('C##5') > pitch.Pitch('D-5')
True

A consequence of comparing enharmonics for equality but .ps for comparisons
is that a `Pitch` can be neither less than
nor greater than another `Pitch` without being equal:

>>> pitch.Pitch('C#5') == pitch.Pitch('D-5')
False
>>> pitch.Pitch('C#5') > pitch.Pitch('D-5')
False
>>> pitch.Pitch('C#5') < pitch.Pitch('D-5')
False

To check for enharmonic equality, use the .ps attribute:

>>> pitch.Pitch('C#5').ps == pitch.Pitch('D-5').ps
True


Advanced construction of pitch with keywords:

>>> pitch.Pitch(name='D', accidental=pitch.Accidental('double-flat'))
<music21.pitch.Pitch D-->
>>> f = pitch.Pitch(pitchClass=5, octave=4,
...                 microtone=pitch.Microtone(30), fundamental=pitch.Pitch('B-2'))
>>> f
<music21.pitch.Pitch F4(+30c)>
>>> f.fundamental
<music21.pitch.Pitch B-2>

If contradictory keyword attributes (like `name='E-', accidental='#'`) are passed in,
behavior is not defined, but unlikely to make you happy.

Pitches are ProtoM21Objects, so they retain some attributes there
such as .classes and .groups, but they don't have Duration or Sites objects
and cannot be put into Streams
)rl   nameWithOctavestep
pitchClassr   midigermanfrenchspanishitaliandutchr   a  
            Returns True or False about whether enharmonic spelling
            Has been inferred on pitch creation or whether it has
            been specified directly.

            MIDI 61 is C# or D- equally.

            >>> p = pitch.Pitch('C4')
            >>> p.spellingIsInferred
            False
            >>> p.ps = 61
            >>> p.spellingIsInferred
            True
            >>> p.name
            'C#'
            >>> p.name = 'C#'
            >>> p.spellingIsInferred
            False

            This makes a difference in transposing.  For instance:

            >>> pInferred = pitch.Pitch(61)
            >>> pNotInferred = pitch.Pitch('C#4')
            >>> pInferred.nameWithOctave, pNotInferred.nameWithOctave
            ('C#4', 'C#4')
            >>> pInferred.spellingIsInferred, pNotInferred.spellingIsInferred
            (True, False)

            >>> inferredTransposed = pInferred.transpose('A1')
            >>> inferredTransposed.nameWithOctave
            'D4'
            >>> notInferredTransposed = pNotInferred.transpose('A1')
            >>> notInferredTransposed.nameWithOctave
            'C##4'

            An operation like diatonic transposition should retain the spelling is inferred
            for the resulting object

            >>> inferredTransposed.spellingIsInferred, notInferredTransposed.spellingIsInferred
            (True, False)

            But Chromatic transposition can change an object to inferred spelling:

            >>> p3 = notInferredTransposed.transpose(1)  # C## -> E- not to C###
            >>> p3.nameWithOctave
            'E-4'
            >>> p3.spellingIsInferred
            True
        r_  r`  N)r  r   
accidental	microtoner  r  ry   fundamentalc                  S U l         [        R                  U l        S U l        S U l        S U l        S U l        SU l        S U l	        S U l
        Ub[  [        U[        5      (       a  Xl        OH[        U5      SS u  U l        U l        SU l        US:  a  [!        US-  5      S-
  U l        O	Ub  X l        Ub  X0l        Ub,  [        U["        5      (       a  X@l        O[#        U5      U l        Ub,  [        U[&        5      (       a  XPl        O['        U5      U l        Ub  X`l        U	b  Xl	        Ub  Xpl        Ub  Xl        g g )NFr   r   Tr|   r,   )_groupsr
   	pitchStep_step_overridden_freq440_accidental
_microtone_octaver   r  rY  ru   r*  rl   r   r  rv   r   r  r   r  r  r  ry   )r  rl   r  r   r  r  r  r  ry   r  keywordss              rf   r  Pitch.__init__w  sC    *.  (11
/3 
 -1*. "& #( (, (, $$$ 	 /?t.DQq.I+	4+*.'2:#&tby>A#5DLI!L!*j11",",Z"8 )Y//!*!*9!5!(O"*I>G rh   c                    [        U 5      $ r   r)  r+  s    rf   r,  Pitch._reprInternal  r.  rh   c                    U R                   nU R                  b2  U R                  R                  S:w  a  U[        U R                  5      -   $ U$ r  )r  r  r   r*  r  rl   s     rf   r:  Pitch.__str__  sA    ""??&4??+@+@A+E#doo...Krh   c                   [        U[        5      (       d  [        $ U R                  UR                  :X  aO  U R                  UR                  :X  a5  U R
                  UR
                  :X  a  U R                  UR                  :X  a  gg)a  
Are two pitches equal?

They must both sound the same and be spelled the same.
Enharmonic equivalence is not equality, nor is impliedOctave
or is a pitch without an accidental equal to a pitch with a
natural accidental.  (See `:meth:`~music21.pitch.Pitch.isEnharmonic` for
a method that does not require spelling equivalence, and for an example
of how to compare notes without accidentals to notes with natural
accidentals.)

>>> c = pitch.Pitch('C2')
>>> c.octave
2
>>> cs = pitch.Pitch('C#4')
>>> cs.octave
4
>>> c == cs
False
>>> c != cs
True

>>> seven = 7
>>> c == seven
False

>>> c != seven
True

>>> df = pitch.Pitch('D-4')
>>> cs == df
False

Implied octaves do not equal explicit octaves

>>> c4 = pitch.Pitch('C4')
>>> cImplied = pitch.Pitch('C')
>>> c4 == cImplied
False
>>> c4.ps == cImplied.ps
True

Note: currently spellingIsInferred and fundamental
are not checked -- this behavior may change in the future.
TF)ru   r   NotImplementedr   r  r  r  r  s     rf   r   Pitch.__eq__  s`    \ %''!!KK5<<'II+OOu'7'77NNeoo5rh   c           	     x   [        U 5      [        L a  [        R                  [        5      nU R                   Hh  n[	        XS5      nUS;   a  [        X#U5        M#  US:X  a  [        X#S5        M7  Uc  [        X#S5        MH  [        X#[        R                  " XA5      5        Mj     U$ [        R                  " X5      $ )z
highly optimized -- it knows exactly what can only have a scalar value and
just sets that directly, only running deepcopy on the other bits.

And _client should NOT be deepcopied.  In fact, it is cleared to nothing.
deepcopy of note will set it back.
N)r  r  r  r   rY  )
r  r   rn  __dict__rq  rp  r   r   r   r  )r  r  rr  kvs        rf   r  Pitch.__deepcopy__  s     :--&C]]DT* : :CA&)^CD)YCD)CDMM!$:; # J))$55rh   c           	         U R                   U R                  U R                  U R                  U R                  U R
                  [        U 5      4n[        U5      $ r   )r  r  r   r  r   r  r  r#  r$  s     rf   r&  Pitch.__hash__$  sK    OO##NNKKIIJ

 Jrh   c                p    [        U[        5      (       d  [        $ U R                  UR                  :  a  gg)z
Accepts enharmonic equivalence. Based entirely on pitch space
representation.

>>> a = pitch.Pitch('c4')
>>> b = pitch.Pitch('c#4')
>>> a < b
True
TFru   r   r  ry   r  s     rf   r  Pitch.__lt__0  s-     %''!!77UXXrh   c                t    U R                  U5      nU[        L a  [        $ U(       a  gU R                  U5      $ )a  
Less than or equal.  Based on the accidentals' alter function.
Note that to be equal enharmonics must be the same. So two pitches can
be neither lt nor gt and not equal to each other!

>>> a = pitch.Pitch('d4')
>>> b = pitch.Pitch('d8')
>>> c = pitch.Pitch('d4')
>>> b <= a
False
>>> a <= b
True
>>> a <= c
True

>>> d = pitch.Pitch('c##4')
>>> c >= d
False
>>> c <= d
False

Do not rely on this behavior -- it may be changed in a future version
to create a total ordering.
T)r  r  r   )r  r  	lt_results      rf   r  Pitch.__le__A  s5    2 KK&	&!!{{5!!rh   c                p    [        U[        5      (       d  [        $ U R                  UR                  :  a  gg)z
Accepts enharmonic equivalence. Based entirely on pitch space
representation.

>>> a = pitch.Pitch('d4')
>>> b = pitch.Pitch('d8')
>>> a > b
False
TFr  r  s     rf   rx  Pitch.__gt__a  s-     %''!!77UXXrh   c                t    U R                  U5      nU[        L a  [        $ U(       a  gU R                  U5      $ )a  
Greater than or equal.  Based on the accidentals' alter function.
Note that to be equal enharmonics must be the same. So two pitches can
be neither lt nor gt and not equal to each other!

>>> a = pitch.Pitch('d4')
>>> b = pitch.Pitch('d8')
>>> c = pitch.Pitch('d4')
>>> a >= b
False
>>> b >= a
True
>>> a >= c
True
>>> c >= a
True

>>> d = pitch.Pitch('c##4')
>>> c >= d
False
>>> c <= d
False

Do not rely on this behavior -- it may be changed in a future version
to create a total ordering.
T)rx  r  r   )r  r  	gt_results      rf   ry  Pitch.__ge__s  s5    6 KK&	&!!{{5!!rh   c                h    U R                   c  [        R                  " 5       U l         U R                   $ )zG
Similar to Groups on music21 object, returns or sets a Groups object.
)r  r   Groupsr+  s    rf   groupsPitch.groups  s%    
 <<;;=DL||rh   c                    Xl         g r   )r  )r  rr  s     rf   r  r    s    rh   c                    U R                   $ )a  
Stores an optional accidental object contained within the
Pitch object.  This might return None, which is different
from a natural accidental:

>>> a = pitch.Pitch('E-')
>>> a.accidental.alter
-1.0
>>> a.accidental.modifier
'-'

>>> b = pitch.Pitch('C4')
>>> b.accidental is None
True
>>> b.accidental = pitch.Accidental('natural')
>>> b.accidental is None
False
>>> b.accidental
<music21.pitch.Accidental natural>
)r  r+  s    rf   r  Pitch.accidental  s    , rh   c                   [        U[        5      (       a  Xl        OUc  S U l        O[        U[        5      (       a  [        U5      U l        O[        U[        5      (       a  [        U5      U l        S U l        Od[        U[        5      (       a@  [        US-  5      u  p#[        U5      U l        [        U5      S:  a  [        U5      U l
        O[        SU< 35      eU R                  5         g )Nr   rF  z/Accidental should be an Accidental object, not )ru   r   r  r*  rv   r  rw   r   r   r   r  r   r  )r  r   r   r   s       rf   r  r	    s    eZ(($]#Ds##)%0Ds##)%0D"DOu%%7FLE)%0D5zD !*5!1NuiXYYrh   c                Z    U R                   c  [        S5      nXl         U$ U R                   $ )a&  
Returns or sets the microtone object contained within the
Pitch object. Microtones must be supplied in cents.

>>> p = pitch.Pitch('E-4')
>>> p.microtone.cents == 0
True
>>> p.ps
63.0
>>> p.microtone = 33  # adjustment in cents
>>> str(p)
'E-4(+33c)'
>>> p.microtone
<music21.pitch.Microtone (+33c)>

>>> (p.name, p.nameWithOctave)  # these representations are unchanged
('E-', 'E-4')
>>> p.microtone = '(-12c'  # adjustment in cents
>>> p
<music21.pitch.Pitch E-4(-12c)>
>>> p.microtone = pitch.Microtone(-30)
>>> p
<music21.pitch.Pitch E-4(-30c)>
r   )r  r   )r  mts     rf   r  Pitch.microtone  s+    4 ??"1B OI??"rh   c                    [        U[        [        [        45      (       a  [	        U5      U l        g Uc  [	        S5      U l        g [        U[        5      (       a  Xl        g [        SU 35      e)Nr   z#Cannot get a microtone object from )ru   r*  rw   rv   r   r  r   rN  s     rf   r  r    sW    ec5#.//'.DO]'lDOy))#O #Fug!NOOrh   c                    U R                   b   U R                   R                  5       (       d  gU R                  b  U R                  R                  S:w  a  gg)aW  
Return True if this Pitch is
one of the twelve tones available on a piano
keyboard. Returns False if it instead
has a non-zero microtonal adjustment or
has a quarter tone accidental.

>>> p = pitch.Pitch('g4')
>>> p.isTwelveTone()
True
>>> p.microtone = -20
>>> p.isTwelveTone()
False

>>> p2 = pitch.Pitch('g~4')
>>> p2.isTwelveTone()
False
Fr   T)r  r  r  r  r   r+  s    rf   r  Pitch.isTwelveTone 	  sE    & ??&??//11??&4>>+?+?1+Drh   c                    U R                   U R                  -
  nUS:  a  US-  nUS:  a  M  US:  a  US-  nUS:  a  M  [        US-  5      $ )au  
Get cent deviation of this pitch from MIDI pitch.

>>> p = pitch.Pitch('c~4')
>>> p.ps
60.5
>>> p.midi  # midi values automatically round up at 0.5
61
>>> p.getCentShiftFromMidi()
-50
>>> p.microtone = -25
>>> p.ps
60.25
>>> p.midi
60
>>> p.getCentShiftFromMidi()
25


>>> p = pitch.Pitch('c#4')
>>> p.microtone = -25
>>> p.ps
60.75
>>> p.midi
61
>>> p.getCentShiftFromMidi()
-25

>>> p = pitch.Pitch('c#~4')
>>> p.ps
61.5
>>> p.midi
62
>>> p.getCentShiftFromMidi()
-50
>>> p.microtone = -3
>>> p.ps
61.47
>>> p.midi
61
>>> p.getCentShiftFromMidi()
47
>>> p.microtone = 3
>>> p.ps
61.53
>>> p.midi
62
>>> p.accidental
<music21.pitch.Accidental one-and-a-half-sharp>
>>> p.getCentShiftFromMidi()
-47

>>> p = pitch.Pitch('c`4')  # quarter tone flat
>>> p.getCentShiftFromMidi()
-50
>>> p.microtone = 3
>>> p.getCentShiftFromMidi()
-47

Absurd octaves that MIDI can't handle will still give the right sounding pitch
out of octave:

>>> p = pitch.Pitch('c~4')
>>> p.octave = 10
>>> p.ps
132.5
>>> p.midi
121
>>> p.getCentShiftFromMidi()
-50
>>> p.octave = -1
>>> p.getCentShiftFromMidi()
-50
>>> p.octave = -2
>>> p.getCentShiftFromMidi()
-50
g      &g      (@g      &@r   )ry   r  r   )r  midiDistances     rf   getCentShiftFromMidiPitch.getCentShiftFromMidi	  sc    \ ww* U"D L U"T!D L T! \C'((rh   c                    SnU R                   b  XR                   R                  -  nU R                  b  XR                  R                  -  nU$ )a  
Get the number of half-steps shifted
by this pitch, such as 1.0 for a sharp, -1.0 for a flat,
0.0 for a natural, 2.0 for a double sharp,
and -0.5 for a quarter tone flat.

Thus, the alter value combines the pitch change
suggested by the Accidental and the Microtone combined.

>>> p = pitch.Pitch('g#4')
>>> p.alter
1.0
>>> p.microtone = -25  # in cents
>>> p.alter
0.75

To change the alter value, change either the accidental
or the microtone.
r   )r  r   r  r  )r  posts     rf   r   Pitch.alterr	  sF    * ??&OO)))D??&NN(((Drh   FinPlacec                  U(       a  U nO[         R                  " U 5      nUR                  b  UR                  R                  S:X  a&  SUl        UR                  R
                  S-
  Ul        OUR                  R                  S:X  a&  SUl        UR                  R
                  S-   Ul        OUR                  R                  S:X  a&  SUl        UR                  R
                  S-   Ul        O?UR                  R                  S:X  a%  SUl        UR                  R
                  S-
  Ul        U(       d  U$ U R                  5         g)	a  
Convert any quarter tone Accidentals to Microtones.

tilde is the symbol for half-sharp, so G#~ is G three-quarters sharp.

>>> p = pitch.Pitch('G#~')
>>> str(p), p.microtone
('G#~', <music21.pitch.Microtone (+0c)>)
>>> p.convertQuarterTonesToMicrotones(inPlace=True)
>>> p.ps
68.5
>>> str(p), p.microtone
('G#(+50c)', <music21.pitch.Microtone (+50c)>)

>>> p = pitch.Pitch('A')
>>> p.accidental = pitch.Accidental('half-flat')  # back-tick
>>> str(p), p.microtone
('A`', <music21.pitch.Microtone (+0c)>)
>>> x = p.convertQuarterTonesToMicrotones(inPlace=False)
>>> str(x), x.microtone
('A(-50c)', <music21.pitch.Microtone (-50c)>)
>>> str(p), p.microtone
('A`', <music21.pitch.Microtone (+0c)>)
NrC   r   rA   rB   r   rD   r   )r   r   r  rl   r  r   r  )r  r  	returnObjs      rf   convertQuarterTonesToMicrotones%Pitch.convertQuarterTonesToMicrotones	  s   2 Id+I+##((K7'+	$&/&9&9&?&?"&D	#%%**l:'+	$&/&9&9&?&?"&D	#%%**.DD'*	$&/&9&9&?&?"&D	#%%**.CC'+	$&/&9&9&?&?"&D	#rh   c               R   U(       a  U nO[         R                  " U 5      nUR                  R                  n[	        U5      u  pEUR
                  b(  [        UR
                  R                  U-   5      Ul        O[        U5      Ul        XRl        U(       d  U$ U R                  5         g)a  
Convert any Microtones available to quarter tones, if possible.

>>> p = pitch.Pitch('g3')
>>> p.microtone = 78
>>> str(p)
'G3(+78c)'
>>> p.convertMicrotonesToQuarterTones(inPlace=True)
>>> str(p)
'G#3(-22c)'

>>> p = pitch.Pitch('d#3')
>>> p.microtone = 46
>>> p
<music21.pitch.Pitch D#3(+46c)>
>>> p.convertMicrotonesToQuarterTones(inPlace=True)
>>> p
<music21.pitch.Pitch D#~3(-4c)>

>>> p = pitch.Pitch('f#2')
>>> p.microtone = -38
>>> p.convertMicrotonesToQuarterTones(inPlace=True)
>>> str(p)
'F~2(+12c)'

N)	r   r   r  r   r   r  r   r   r  )r  r  r  r   r   r   s         rf   convertMicrotonesToQuarterTones%Pitch.convertMicrotonesToQuarterTones	  s    6 Id+I##))8?
+#-$$**Z7$9I  $.j#9I #rh   c                    U R                   n[        U R                  S-   S-  [        U   -   5      nU R                  b  X R                  R
                  -   nU R                  b  X R                  R
                  -   nU$ )a  
The ps property permits getting and setting
a pitch space value, a floating point number
representing pitch space, where 60.0 is C4, middle C,
61.0 is C#4 or D-4, and floating point values are
microtonal tunings (0.01 is equal to one cent), so
a quarter-tone sharp above C5 is 72.5.

Note that the choice of 60.0 for C4 makes it identical
to the integer value of 60 for .midi, but .midi
does not allow for microtones and is limited to 0-127
while .ps allows for notes before midi 0 or above midi 127.

>>> a = pitch.Pitch('C4')
>>> a.ps
60.0

Changing the ps value for `a` will change the step and octave:

>>> a.ps = 45
>>> a
<music21.pitch.Pitch A2>
>>> a.ps
45.0


Notice that ps 61 represents both
C# and D-flat.  Thus, "spellingIsInferred"
will be true after setting our pitch to 61:

>>> a.ps = 61
>>> a
<music21.pitch.Pitch C#4>
>>> a.ps
61.0
>>> a.spellingIsInferred
True

Microtonal accidentals and pure Microtones are allowed, as are extreme ranges:

>>> b = pitch.Pitch('B9')
>>> b.accidental = pitch.Accidental('half-flat')
>>> b
<music21.pitch.Pitch B`9>
>>> b.ps
130.5

>>> p = pitch.Pitch('c4')
>>> p.microtone = 20
>>> print('%.1f' % p.ps)
60.2

Octaveless pitches use their .implicitOctave attributes:

>>> d = pitch.Pitch('D#')
>>> d.octave is None
True
>>> d.implicitOctave
4
>>> d.ps
63.0

>>> d.octave = 5
>>> d.ps
75.0

Setting with microtones

>>> p = pitch.Pitch()
>>> p.ps = 61
>>> p.ps
61.0
>>> p.spellingIsInferred
True
>>> p.ps = 61.5  # get a quarter tone
>>> p
<music21.pitch.Pitch C#~4>
>>> p.ps = 61.7  # set a microtone
>>> print(p)
C#~4(+20c)
>>> p.ps = 61.4  # set a microtone
>>> print(p)
C#~4(-10c)

The property is called when self.step, self.octave
or self.accidental are changed.
r,   r|   )r  rw   implicitOctaver)   r  r   r  r  )r  r  ry   s      rf   ry   Pitch.ps	  sn    r zzT((1,2gdmCD??&oo+++B??&nn***B	rh   c                    [        U5      u  U l        o l        nUR                  S:X  a  S U l        OX l        [        U5      U-   U l        SU l        g )Nr8   T)r   r  r  rl   r  r   r   r   )r  r   r   r   s       rf   ry   r#  T
  sO     5EU4K1	3 88y "DO!O%e,x7 #'rh   c                    S nU" U R                   5      nUS:  a  SUS-  -   nUS:  a  US-  nU$ US:  a
  SUS-  -   nU$ UnU$ )a6  
Get or set a pitch value in MIDI.
MIDI pitch values are like ps values (pitchSpace) rounded to
the nearest integer; while the ps attribute will accommodate floats.

>>> c = pitch.Pitch('C4')
>>> c.midi
60
>>> c.midi =  23.5
>>> c.midi
24

Note that like ps (pitchSpace), MIDI notes do not distinguish between
sharps and flats, etc.

>>> dSharp = pitch.Pitch('D#4')
>>> dSharp.midi
63
>>> eFlat = pitch.Pitch('E-4')
>>> eFlat.midi
63

Midi values are constrained to the space 0-127.  Higher or lower
values will be transposed octaves to fit in this space.

>>> veryHighFHalfFlat = pitch.Pitch('F')
>>> veryHighFHalfFlat.octave = 12
>>> veryHighFHalfFlat.accidental = pitch.Accidental('half-flat')
>>> veryHighFHalfFlat
<music21.pitch.Pitch F`12>
>>> veryHighFHalfFlat.ps
160.5
>>> veryHighFHalfFlat.midi
125
>>> veryHighFHalfFlat.octave = 9
>>> veryHighFHalfFlat.midi
125

>>> notAsHighNote = pitch.Pitch()
>>> notAsHighNote.ps = veryHighFHalfFlat.midi
>>> notAsHighNote
<music21.pitch.Pitch F9>

Note that the conversion of improper midi values to proper
midi values is done before assigning .ps:

>>> a = pitch.Pitch()
>>> a.midi = -10
>>> a.midi
2
>>> a.ps
2.0
>>> a.spellingIsInferred
True

More absurd octaves:

>>> p = pitch.Pitch('c~4')
>>> p.octave = -1
>>> p.ps
0.5
>>> p.midi
1
>>> p.octave = -2
>>> p.ps
-11.5
>>> p.midi
1
c                4    [         R                  " U S-   5      $ )a5  
This is round "up" at 0.5 (regardless of negative or positive)

Python 3 now uses rounding mechanisms so that odd numbers round one way, even another.
But we needed a consistent direction for all half-sharps/flats to go,
and now long after Python 2 is no longer supported, this behavior is grandfathered in.
r   )r   r   )r   s    rf   schoolYardRounding&Pitch.midi.<locals>.schoolYardRounding
  s     ::a#g&&rh      l   r|   s   r   rx   )r  r'  	roundedPSr   s       rf   r  
Pitch.midid
  so    N	' 'tww/	s?	B/E!
 	 ]R(E  Erh   c                    [        U5      nUS:  a  SUS-  -   nUS:  a  US-  nOUS:  a  SUS-  -   nXl        SU l        g)zQ
midi values are constrained within the range of 0 to 127
floating point values,
r)  r*  r|   r+  r   TN)r   ry   r   rN  s     rf   r  r-  
  sX     e3;
+E!QY$E #'rh   c                z    U R                   b#  U R                  U R                   R                  -   $ U R                  $ )a  
Gets or sets the name (pitch name with accidental but
without octave) of the Pitch.

>>> p = pitch.Pitch('D#5')
>>> p.name
'D#'

>>> p.name = 'C#'
>>> p.name
'C#'

>>> a = pitch.Pitch('G#')
>>> a.name
'G#'

Does not simplify enharmonics

>>> a = pitch.Pitch('B---')
>>> a.name
'B---'
)r  r  r]  r+  s    rf   rl   
Pitch.name
  s1    0 ??&99t777799rh   c           	     F    UR                  5       n/ n/ nSnU HF  nUS;   a*  U(       d  [        SU< S35      eUR	                  U5        M3  SnUR	                  U5        MH     SR                  U5      nSR                  U5      n[        U5      S	:X  a  Xl        S
U l        O<[        U5      S	:  a  US   U l        [        US	S
 5      U l        O[        SU< 35      eU(       a  [        U5      nXpl        g
g
! [         a    [        SU< S[        U5       S35      ef = f)z]
Set name, which may be provided with or without octave values. C4 or D-3
are both accepted.
zArgument to name, z, must be a string, not .F
0123456789z.Cannot have octave given before pitch name in Tr2   r,   Nr   zCannot make a name out of )stripr  r   r  rb   joinra   r  r  r   r   rv   r   )r  usrStroctFoundoctNotfoundNonOctavecharoctFoundStrr   s           rf   rl   r0  
  s-   	e\\^F
 !D|#%$'UV\U__`%abb%!%d#  ggh'v;!I"DO[1_q	DI(4DO #=fZ!HII%F K ;  	e1&;STXY_T`Saabcdd	es   C9 9'D c                z    U R                   b#  U R                  U R                   R                  -   $ U R                  $ )uv   
Name presently returns pitch name and accidental without octave.

>>> a = pitch.Pitch('G#')
>>> a.unicodeName
'G♯'
)r  r  r  r+  s    rf   unicodeNamePitch.unicodeName  s1     ??&99t666699rh   c                x    U R                   c  U R                  $ U R                  [        U R                   5      -   $ )a  
Return or set the pitch name with an octave designation.
If no octave as been set, no octave value is returned.


>>> gSharp = pitch.Pitch('G#4')
>>> gSharp.nameWithOctave
'G#4'

>>> dFlatFive = pitch.Pitch()
>>> dFlatFive.step = 'D'
>>> dFlatFive.accidental = pitch.Accidental('flat')
>>> dFlatFive.octave = 5
>>> dFlatFive.nameWithOctave
'D-5'
>>> dFlatFive.nameWithOctave = 'C#6'
>>> dFlatFive.name
'C#'
>>> dFlatFive.octave
6


N.B. -- it's generally better to set the name and octave separately, especially
since you may at some point encounter very low pitches such as "A octave -1", which
will be interpreted as "A-flat, octave 1".  Our crude setting algorithm also does
not support octaves above 9.

>>> lowA = pitch.Pitch()
>>> lowA.name = 'A'
>>> lowA.octave = -1
>>> lowA.nameWithOctave
'A-1'
>>> lowA.nameWithOctave = lowA.nameWithOctave
>>> lowA.name
'A-'
>>> lowA.octave
1

Octave must be included in nameWithOctave or an exception is raised:

>>> a = pitch.Pitch()
>>> a.nameWithOctave = 'C#9'
>>> a.nameWithOctave = 'C#'
Traceback (most recent call last):
music21.pitch.PitchException: Cannot set a nameWithOctave with 'C#'

Set octave to None explicitly instead.
)r   rl   r*  r+  s    rf   r  Pitch.nameWithOctave'  s1    d ;;9999s4;;///rh   c                     [        U5      nUSUS-
   n[        US   5      nX0l        X@l        g !   [	        SU< 35      e= f)Nr   r,   r   z!Cannot set a nameWithOctave with )ra   rv   rl   r   r   )r  r   lenValrl   r   s        rf   r  r@  ^  sS    	PZF6A:&Dr^FI K	P #DUI!NOOs	   -0 Ac                x    U R                   c  U R                  $ U R                  [        U R                   5      -   $ )u   
Return the pitch name with octave with unicode accidental symbols,
if available.

Read-only property.

>>> p = pitch.Pitch('C#4')
>>> p.unicodeNameWithOctave
'C♯4'
)r   r=  r*  r+  s    rf   unicodeNameWithOctavePitch.unicodeNameWithOctavei  s4     ;;#####c$++&666rh   c                    U R                   nU R                  b  USU R                  R                   3-  nU R                  b  USU R                   3-  nU R                  b,  U R
                  R                  S:w  a  USU R                   3-  nU$ )a   
Return the most complete representation of this Pitch,
providing name, octave, accidental, and any
microtonal adjustments.

>>> p = pitch.Pitch('A-3')
>>> p.microtone = 33.33
>>> p.fullName
'A-flat in octave 3 (+33c)'

>>> p = pitch.Pitch('A`7')
>>> p.fullName
'A-half-flat in octave 7'
r4   z in octave r    )r  r  r  r   r  r  r   r  s     rf   r  Pitch.fullNamez  s      yy??&a00122D;;"k$++//D??&4>>+?+?1+Da())Drh   c                    U R                   $ )aB  
The diatonic name of the note; i.e. does not give the
accidental or octave.

>>> a = pitch.Pitch('B-3')
>>> a.step
'B'

Upper-case or lower-case names can be given to `.step` -- they
will be converted to upper-case

>>> b = pitch.Pitch()
>>> b.step = 'c'
>>> b.step
'C'

Changing the `.step` does not change the `.accidental` or
`.octave`:

>>> a = pitch.Pitch('F#5')
>>> a.step = 'D'
>>> a.nameWithOctave
'D#5'

Giving a value that includes an accidental raises a PitchException.
Use .name instead to change that.

>>> b = pitch.Pitch('E4')
>>> b.step = 'B-'
Traceback (most recent call last):
music21.pitch.PitchException: Cannot make a step out of 'B-'

This is okay though:

>>> b.name = 'B-'

Note that if spelling is inferred, setting the step does NOT
give that enharmonic.  Perhaps it should, but best to make people use
.getLowerEnharmonic or .getHigherEnharmonic instead.

>>> b.ps = 60
>>> b.nameWithOctave
'C4'
>>> b.spellingIsInferred
True
>>> b.step = 'B'
>>> b.accidental is None  # maybe this should set to B#? But that could be screwy.
True
>>> b.spellingIsInferred
False
)r  r+  s    rf   r  
Pitch.step  s    j zzrh   c                    UR                  5       R                  5       n[        U5      S:X  a  U[        ;   a  Xl        SU l        O[        SU< 35      eU R                  5         g)z6
This does not change octave or accidental, only step
r,   FzCannot make a step out of N)r4  upperra   r+   r  r   r   r  )r  r6  s     rf   r  rJ    sW    
 %%'v;!) 3J&+D# #=fZ!HIIrh   c                2    [        U R                  5      S-  $ )a>  
Returns or sets the integer value for the pitch, 0-11, where C=0,
C#=1, D=2, etc. to B=11. Can be set using integers (0-11) or 'A' or 'B'
for 10 or 11.

>>> a = pitch.Pitch('a3')
>>> a.pitchClass
9
>>> dis = pitch.Pitch('d3')
>>> dis.pitchClass
2
>>> dis.accidental = pitch.Accidental('#')
>>> dis.pitchClass
3

If a string "A" or "B" is given to pitchClass, it is
still returned as an int.

>>> dis.pitchClass = 'A'
>>> dis.pitchClass
10
>>> dis.name
'B-'

Extreme octaves will not affect pitchClass

>>> dis.octave = -10
>>> dis.pitchClass
10

In the past, certain microtones and/or octaves were returning pc 12!
This is now fixed.

>>> flattedC = pitch.Pitch('C4')
>>> flattedC.microtone = -4
>>> print(flattedC)
C4(-4c)
>>> flattedC.pitchClass
0
>>> print(flattedC.ps)
59.96
>>> flattedC.octave = -3
>>> print(flattedC.ps)
-24.04
>>> flattedC.pitchClass
0

Note that the pitchClass of a microtonally altered pitch is the pitch class of
the nearest pitch.  Python 3 uses the "round-to-even" method so C~4 (C half sharp 4)
is pitchClass 0, since 60.5 rounds to 60.0

>>> p = pitch.Pitch('C~4')
>>> p.ps
60.5
>>> p.pitchClass
0

However, for backwards compatability, the MIDI number of a microtone
is created by using "schoolyard" rounding which always rounds 0.5 upwards, which
can cause some unusual behavior:

>>> p.midi
61
>>> pitch.Pitch(midi=p.midi).pitchClass
1


This means that pitchClass + microtone is NOT a good way to estimate the frequency
of a pitch.  For instance, if we take a pitch that is 90% of the way between pitchClass
0 (C) and pitchClass 1 (C#/D-flat), this formula gives an inaccurate answer of 1.9, not
0.9:

>>> p = pitch.Pitch('C4')
>>> p.microtone = 90
>>> p
<music21.pitch.Pitch C4(+90c)>
>>> p.pitchClass + (p.microtone.cents / 100.0)
1.9

More examples of setting the pitchClass.

>>> a = pitch.Pitch('a3')
>>> a.pitchClass = 3
>>> a
<music21.pitch.Pitch E-3>
>>> a.spellingIsInferred
True
>>> a.pitchClass = 'A'
>>> a
<music21.pitch.Pitch B-3>

Changing pitchClass does not remove microtones.

>>> a.microtone = 20
>>> a.pitchClass = 1
>>> a
<music21.pitch.Pitch C#3(+20c)>
r|   )r   ry   r+  s    rf   r  Pitch.pitchClass  s    H TWW~""rh   c                ^    [        U5      n[        U5      SS u  U l        U l        SU l        g )Nr   r   T)rz   r   r  r  r   )r  r   valueOuts      rf   r  rN  B  s3     9?&6x&@1&E#	4# #'rh   c                ,    [        U R                  5      $ )a  
Returns or sets a string representation of the pitch class,
where integers greater than 10 are replaced by A and B,
respectively. Can be used to set pitch class by a
string representation as well (though this is also
possible with :attr:`~music21.pitch.Pitch.pitchClass`).

>>> a = pitch.Pitch('a#3')
>>> a.pitchClass
10
>>> a.pitchClassString
'A'

We can set the pitchClassString as well:

>>> a.pitchClassString = 'B'
>>> a.pitchClass
11
)r   r  r+  s    rf   pitchClassStringPitch.pitchClassStringM  s    * &doo66rh   c                    Xl         g r   )r  )r  r  s     rf   rR  rS  d  s    rh   c                    U R                   $ )a;  
Returns or sets the octave of the note.
Setting the octave updates the pitchSpace attribute.

>>> a = pitch.Pitch('g')
>>> a.octave is None
True
>>> a.implicitOctave
4
>>> a.ps  ## will use implicitOctave
67.0
>>> a.name
'G'

>>> a.octave = 14
>>> a.octave
14
>>> a.implicitOctave
14
>>> a.name
'G'
>>> a.ps
187.0
)r  r+  s    rf   r   Pitch.octavei  s    4 ||rh   c                Z    Ub  [        U5      U l        OS U l        U R                  5         g r   )rv   r  r  rN  s     rf   r   rV    s&    u:DLDLrh   c                T    U R                   c  [        R                  $ U R                   $ )a  
Returns the octave of the Pitch, or defaultOctave if
octave was never set. To set an octave, use .octave.
Default octave is usually 4.

>>> p = pitch.Pitch('C#')
>>> p.octave is None
True
>>> p.implicitOctave
4

Cannot be set.  Instead, just change the `.octave` of the pitch
)r   r
   pitchOctaver+  s    rf   r"  Pitch.implicitOctave  s$     ;;''';;rh   c                P   U R                   b  U R                   R                  nOSnU R                  nU[        U5      :w  a  [	        S5      e[        U5      nUS:X  a  US:w  a  SnOUS-  nUS:X  a  U$ US:  a	  X!S-  -   nU$ US;   a  S	nOS
n[        U5      S-
  nX$-   US	-  -   nU$ )u  
Read-only property. Returns a unicode string of the name
of a Pitch in the German system
(where B-flat = B, B = H, etc.)
(Microtones and Quarter tones raise an error).  Note that
Ases is used instead of the also acceptable Asas.

>>> print(pitch.Pitch('B-').german)
B
>>> print(pitch.Pitch('B').german)
H
>>> print(pitch.Pitch('E-').german)
Es
>>> print(pitch.Pitch('C#').german)
Cis
>>> print(pitch.Pitch('A--').german)
Ases
>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.german
Traceback (most recent call last):
music21.pitch.PitchException:
    Es geht nicht "german" zu benutzen mit Microtönen.  Schade!

Note these rarely used pitches:

>>> print(pitch.Pitch('B--').german)
Heses
>>> print(pitch.Pitch('B#').german)
His
r   u<   Es geht nicht "german" zu benutzen mit Microtönen.  Schade!r   r   r3  r,   rH   )r%   r&   r'   r(   r3  rL   rs  )r  r   r  rv   r   r   )r  	tempAltertempSteptempNamefirstFlatNamemultipleFlatss         rf   r  Pitch.german  s    B ??&--II		I& !_``	N	s?BQ	>O]t#34HO44 $ #	NQ.M/=43GHHOrh   c                p   U R                   b  U R                   R                  nOSnU R                  nU[        U5      :w  a  [	        S5      e[        U5      nSSSSS.nSS	S
SSSSS.nUS:X  a  XB   $ US:  a  US:  a  [	        S5      eXB   X1   -   S-   $ US-  nUS:  a  [	        S5      eXB   X1   -   S-   $ )a  
Read-only attribute. Returns the name
of a Pitch in the Italian system
(F-sharp is fa diesis, C-flat is do bemolle, etc.)
(Microtones and Quarter tones raise an error).


>>> print(pitch.Pitch('B-').italian)
si bemolle
>>> print(pitch.Pitch('B').italian)
si
>>> print(pitch.Pitch('E-9').italian)
mi bemolle
>>> print(pitch.Pitch('C#').italian)
do diesis
>>> print(pitch.Pitch('A--4').italian)
la doppio bemolle
>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.italian
Traceback (most recent call last):
music21.pitch.PitchException: Non si puo usare `italian` con microtoni

Note these rarely used pitches:

>>> print(pitch.Pitch('E####').italian)
mi quadruplo diesis
>>> print(pitch.Pitch('D---').italian)
re triplo bemolle
r   z(Non si puo usare `italian` con microtonirG  z doppio z triplo z quadruplo )r,   r   r-   r   doremifasollasir$   r   zEntirely too many sharpsdiesisr   zEntirely too many flatsbemolle)r  r   r  rv   r   )r  r\  r]  cardinalityMapsolfeggeMaps        rf   r  Pitch.italian  s    B ??&--II		I& !KLL	N	 ZJ=Q t$T!49 >((]1}$%?@@(>+DDxOO!BI1}$%>??(>+DDyPPrh   c                    U R                   c  g[        U R                   R                  5      nUS:X  a  gUS:X  a  gUS:X  a  gUS:X  a  gg)	Nr2   r,   r   z dobler-    tripler   u    cuádruple)r  r   r   )r  rc   s     rf   _getSpanishCardinalPitch._getSpanishCardinal  sN    ??"DOO))*AAvaa a$rh   rh  ri  rc  rd  re  rf  rg  )r   r   r%   r&   r   r'   r(   zdict[StepName, str]_SPANISH_DICTc                F   U R                   b  U R                   R                  nOSnU R                  U R                     nU[	        U5      :w  a  [        S5      eUS:X  a  U$ US;   a  X R                  5       -   S-   $ US;   a  X R                  5       -   S-   $ [        S5      e)as  
Read-only attribute. Returns the name
of a Pitch in Spanish
(Microtones and Quarter tones raise an error).

>>> print(pitch.Pitch('B-').spanish)
si bemol
>>> print(pitch.Pitch('E-').spanish)
mi bemol
>>> print(pitch.Pitch('C#').spanish)
do sostenido
>>> print(pitch.Pitch('A--').spanish)
la doble bemol
>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.spanish
Traceback (most recent call last):
music21.pitch.PitchException: Unsupported accidental type.

Note these rarely used pitches:

>>> print(pitch.Pitch('B--').spanish)
si doble bemol
>>> print(pitch.Pitch('B#').spanish)
si sostenido
r   zUnsupported accidental type.>   r  r  r  r   z bemol>   r,   r   r-   r   z
 sostenido)r  r   rs  r  rv   r   rq  )r  r\  solfeges      rf   r  Pitch.spanish6  s    8 ??&--II$$TYY/I& !?@@>N**5577(BB,&5577,FF !?@@rh   u   ré_FRENCH_DICTc                   U R                   b  U R                   R                  nOSnU R                  U R                     nU[	        U5      :w  a  [        S5      e[        U5      S:  a  [        S5      e[	        U5      nUS:X  a  U$ [        U5      S:X  a  UnOM[        U5      S:X  a  US-   nO8[        U5      S:X  a  US	-   nO#[        U5      S:X  a  US
-   nO[        SU 35      eU[        U5      -  S:X  a  US-   nU$ US-   nU$ )u  
Read-only attribute. Returns the name
of a Pitch in the French system
(where A = la, B = si, B-flat = si bémol, C-sharp = do dièse, etc.)
(Microtones and Quarter tones raise an error).  Note that
do is used instead of the also acceptable ut.

>>> print(pitch.Pitch('B-').french)
si bémol

>>> print(pitch.Pitch('B').french)
si

>>> print(pitch.Pitch('E-').french)
mi bémol

>>> print(pitch.Pitch('C#').french)
do dièse

>>> print(pitch.Pitch('A--').french)
la double bémol

>>> p1 = pitch.Pitch('C')
>>> p1.accidental = pitch.Accidental('half-sharp')
>>> p1.french
Traceback (most recent call last):
music21.pitch.PitchException: On ne peut pas utiliser les microtones avec "french."
    Quelle Dommage!
r   zEOn ne peut pas utiliser les microtones avec "french." Quelle Dommage!r  ux   On ne peut pas utiliser les altération avec puissance supérieure à quatre avec "french." Ça me fait une belle jambe!r   r  z doubler  rp  z
 quadruplezCannot deal with tempStep: u    dièseu    bémol)r  r   rw  r  rv   r   r   )r  r\  r]  tempNumberedStepr^  s        rf   r  Pitch.frenchn  s&   @ ??&--II))$))4I& WY Y y>C @  	N	>O^s"'^s"')3^s"')3^s"',6 #>xj!IJJs9~%,')3HO')3HOrh   c                    U R                   $ )a  
The frequency property gets or sets the frequency of
the pitch in hertz.

If the frequency has not been overridden, then
it is computed based on A440Hz and equal temperament

>>> a = pitch.Pitch()
>>> a.frequency = 440.0
>>> a.frequency
440.0
>>> a.name
'A'
>>> a.octave
4

Microtones are captured if the frequency doesn't correspond to any standard note.

>>> a.frequency = 450.0
>>> a
<music21.pitch.Pitch A~4(-11c)>
freq440r+  s    rf   	frequencyPitch.frequency  s    0 ||rh   c                    Xl         g r   r|  rN  s     rf   r~  r    s    rh   c                ~    U R                   (       a  U R                   $ U R                  S-
  nSU R                  U-  -  $ )aE  
Gets the frequency of the note as if it's in an equal temperament
context where A4 = 440hz.  The same as .frequency so long
as no other temperaments are currently being used.

Since we don't have any other temperament objects at present,
this is the same as .frequency always.

>>> a = pitch.Pitch('A4')
>>> a.freq440
440.0
E        {@)r  ry   _twelfth_root_of_two)r  A4offsets     rf   r}  Pitch.freq440  s>     ##+++ ww|HD55ABBrh   c                    S[         R                  " US-  5      [         R                  " S5      -  -  S-   n[        U[        5      nX0l        g )Nr|   r  r   r  )r   r   r   r   ry   )r  r   r  r   s       rf   r}  r    s?    TXXeem,txx{:;b@ 4/0rh   c                N   [        U5      n[        R                  " U 5      nUS:X  a  U$ U R                  b(  [	        UR
                  R                  U-   5      Ul        O[	        U5      Ul        [        5       nUR                  Ul        [        R                  " U 5      Ul	        U$ )a.  
Return a Pitch object representing the harmonic found above this Pitch.

>>> p = pitch.Pitch('a4')
>>> print(p.getHarmonic(2))
A5
>>> print(p.getHarmonic(3))
E6(+2c)
>>> print(p.getHarmonic(4))
A6
>>> print(p.getHarmonic(5))
C#7(-14c)
>>> print(p.getHarmonic(6))
E7(+2c)
>>> print(p.getHarmonic(7))
F#~7(+19c)
>>> print(p.getHarmonic(8))
A7

>>> p2 = p.getHarmonic(2)
>>> p2
<music21.pitch.Pitch A5>
>>> p2.fundamental
<music21.pitch.Pitch A4>
>>> p2.transpose('p5', inPlace=True)
>>> p2
<music21.pitch.Pitch E6>
>>> p2.fundamental
<music21.pitch.Pitch E5>

Or we can iterate over a list of the next 8 odd harmonics:

>>> allHarmonics = ''
>>> for i in [9, 11, 13, 15, 17, 19, 21, 23]:
...     allHarmonics += ' ' + str(p.getHarmonic(i))
>>> print(allHarmonics)
B7(+4c) D~8(+1c) F~8(-9c) G#8(-12c) B-8(+5c) C9(-2c) C#~9(+21c) E`9(-22c)

Microtonally adjusted notes also generate harmonics:

>>> q = pitch.Pitch('C4')
>>> q.microtone = 10
>>> q.getHarmonic(2)
<music21.pitch.Pitch C5(+10c)>
>>> q.getHarmonic(3)
<music21.pitch.Pitch G5(+12c)>

The fundamental is stored with the harmonic.

>>> h7 = pitch.Pitch('A4').getHarmonic(7)
>>> print(h7)
F#~7(+19c)
>>> h7.fundamental
<music21.pitch.Pitch A4>
>>> h7.harmonicString()
'7thH/A4'
>>> h7.harmonicString('A3')
'14thH/A3'

>>> h2 = h7.getHarmonic(2)
>>> h2
<music21.pitch.Pitch F#~8(+19c)>
>>> h2.fundamental
<music21.pitch.Pitch F#~7(+19c)>
>>> h2.fundamental.fundamental
<music21.pitch.Pitch A4>
>>> h2.transpose(-24, inPlace=True)
>>> h2
<music21.pitch.Pitch F#~6(+19c)>
>>> h2.fundamental.fundamental
<music21.pitch.Pitch A2>
r   )
r   r   r   r  r   r  r   r   r~  r  )r  number	centShifttempfinals        rf   getHarmonicPitch.getHarmonic  s    R ,F3	mmD)>K??&&t~~';';i'GHDN&y1DN .. MM$/ rh   c                D   [        U[        5      (       a  [        U5      nU nUR                  UR                  ::  a  [	        SSU SU  S3-   5      e/ n[        SS5       HB  nUR                  U5      nUR                  XE45        UR                  UR                  :  d  MB    O   [        U5      S:  ar  US   u  pgUR                  UR                  :  a  UR                  UR                  -
  nOUR                  UR                  :  a  UR                  UR                  -
  nOhSnOeUS	   u  pUS
   u  pUR                  U
R                  -
  nUR                  UR                  -
  nX::  a  U
n[        U5      * nU	nOUn[        U5      nUn[        U[        5      S-  nXh4$ )a  
Given another Pitch as a fundamental, find the harmonic
of that pitch that is equal to this Pitch.

Returns a tuple of harmonic number and the number of cents that
the first Pitch object would have to be shifted to be the exact
harmonic of this fundamental.

Microtones applied to the fundamental are irrelevant,
as the fundamental may be microtonally shifted to find a match to this Pitch.

Example: G4 is the third harmonic of C3, albeit 2 cents flatter than
the true 3rd harmonic.


>>> p = pitch.Pitch('g4')
>>> f = pitch.Pitch('c3')
>>> p.harmonicFromFundamental(f)
(3, 2.0)
>>> p.microtone = p.harmonicFromFundamental(f)[1]  # adjust microtone
>>> int(f.getHarmonic(3).frequency) == int(p.frequency)
True

The shift from B-5 to the 7th harmonic of C3 is more substantial
and likely to be noticed by the audience.  To make p the 7th harmonic
it'd have to be lowered by 31 cents.  Note that the
second argument is a float, but because the default rounding of
music21 is to the nearest cent, the 0.0 is not a significant digit.
I.e. it might be more like 31.3 cents.

>>> p = pitch.Pitch('B-5')
>>> f = pitch.Pitch('C3')
>>> p.harmonicFromFundamental(f)
(7, -31.0)
z5cannot find an equivalent harmonic for a fundamental r0   z ) that is not above this Pitch (r1   r,       r   r   r  r   r   )ru   r*  r   ry   r   ranger  rb   ra   r   r   r   )r  r  targetfoundrc   r   harmonicMatchmatchgapharmonicLowercandidateLowerharmonicHighercandidateHigherdistanceLowerdistanceHighers                  rf   harmonicFromFundamentalPitch.harmonicFromFundamentalV  s   P k3'',K 99& Gk]"B4&JK  q"A''*ALL! ttfii  u:>#(8 Mxx&))#hh*FII%ii%((*,1"I)M.3Bi+N"II(9(99M,//&));N .&=)) - (.) .C/036!!rh   c                0   Uc$  U R                   c  [        S5      eU R                   n[        U[        5      (       a  [	        U5      nU R                  U5      u  p#[        U* 5      n[        R                  " U5      nUS:X  a	  U U SU 3$ U U SU SU 3$ )a9  
Return a string representation of a harmonic equivalence.

N.B. this has nothing to do with what string a string player
would use to play the harmonic on.  (Perhaps should be
renamed).


>>> pitch.Pitch('g4').harmonicString('c3')
'3rdH(-2c)/C3'

>>> pitch.Pitch('c4').harmonicString('c3')
'2ndH/C3'

>>> p = pitch.Pitch('c4')
>>> p.microtone = 20  # raise 20
>>> p.harmonicString('c3')
'2ndH(+20c)/C3'

>>> p.microtone = -20  # lower 20
>>> p.harmonicString('c3')
'2ndH(-20c)/C3'

>>> p = pitch.Pitch('c4')
>>> f = pitch.Pitch('c3')
>>> f.microtone = -20
>>> p.harmonicString(f)
'2ndH(+20c)/C3(-20c)'
>>> f.microtone = +20
>>> p.harmonicString(f)
'2ndH(-20c)/C3(+20c)'

>>> p = pitch.Pitch('A4')
>>> p.microtone = 69
>>> p.harmonicString('c2')
'7thH/C2'

>>> p = pitch.Pitch('A4')
>>> p.harmonicString('c2')
'7thH(-69c)/C2'
zDno fundamental is defined for this Pitch: provide one as an argumentr   H/r3  /)	r  r   ru   r*  r   r  r   r   r4  )r  r  harmonicr   r  abbrs         rf   harmonicStringPitch.harmonicString  s    X '$ &D E E**Kk3'',K66{Cuf%	))(3A:ZvR}55ZvQyk;-@@rh   c                   [        U[        5      (       a  [        U5      nO[        R                  " U5      nU R                  U5      u  p#U* nUR                  b!  UR                  R                  U-   Ul        X!4$ US:w  a  X1l        X!4$ )a  
Given a Pitch that is a plausible target for a fundamental,
return the harmonic number and a potentially shifted fundamental
that describes this Pitch.


>>> g4 = pitch.Pitch('g4')
>>> g4.harmonicAndFundamentalFromPitch('c3')
(3, <music21.pitch.Pitch C3(-2c)>)
r   )ru   r*  r   r   r   r  r  r   )r  r  r  r   s       rf   harmonicAndFundamentalFromPitch%Pitch.harmonicAndFundamentalFromPitch  s     fc""6]F]]6*F66v> '  &//55=F  z#( rh   c                f    U R                  U5      u  p![        R                  " U5      nU U SU 3$ )a  
Given a Pitch that is a plausible target for a fundamental,
find the harmonic number and a potentially shifted fundamental
that describes this Pitch. Return a string representation.

>>> pitch.Pitch('g4').harmonicAndFundamentalStringFromPitch('c3')
'3rdH/C3(-2c)'

>>> pitch.Pitch('c4').harmonicAndFundamentalStringFromPitch('c3')
'2ndH/C3'

>>> p = pitch.Pitch('c4')
>>> p.microtone = 20  # raise 20
>>> p.harmonicAndFundamentalStringFromPitch('c3')
'2ndH/C3(+20c)'

>>> p.microtone = -20  # lower 20
>>> p.harmonicAndFundamentalStringFromPitch('c3')
'2ndH/C3(-20c)'

>>> p = pitch.Pitch('c4')
>>> f = pitch.Pitch('c3')
>>> f.microtone = -20
>>> p.harmonicAndFundamentalStringFromPitch(f)
'2ndH/C3'
>>> f.microtone = +20
>>> p.harmonicAndFundamentalStringFromPitch(f)
'2ndH/C3'

>>> p = pitch.Pitch('A4')
>>> p.microtone = 69
>>> p.harmonicAndFundamentalStringFromPitch('c2')
'7thH/C2'

>>> p = pitch.Pitch('A4')
>>> p.harmonicAndFundamentalStringFromPitch('c2')
'7thH/C2(-69c)'
r  )r  r   r4  )r  r  r  r  s       rf   %harmonicAndFundamentalStringFromPitch+Pitch.harmonicAndFundamentalStringFromPitch&  s=    T !% D D[ Q))(3D6K=11rh   c                    UR                   b  U R                   c  UR                  U R                  -
  S-  S:H  $ UR                  U R                  :H  $ )aq	  
Return True if another Pitch is an enharmonic equivalent of this Pitch.

>>> p1 = pitch.Pitch('C#3')
>>> p2 = pitch.Pitch('D-3')
>>> p3 = pitch.Pitch('D#3')
>>> p1.isEnharmonic(p2)
True
>>> p2.isEnharmonic(p1)
True
>>> p3.isEnharmonic(p1)
False

Pitches are enharmonics of themselves:

>>> pC = pitch.Pitch('C4')
>>> pC.isEnharmonic(pC)
True

Notes that sound in different octaves are not enharmonics:

>>> pitch.Pitch('C#4').isEnharmonic( pitch.Pitch('D-5') )
False

However, different octave numbers can be the same enharmonic,
because octave number is relative to the `step` (natural form) of the pitch.

>>> pitch.Pitch('C4').isEnharmonic( pitch.Pitch('B#3') )
True
>>> pitch.Pitch('C4').isEnharmonic( pitch.Pitch('B#4') )
False

If either pitch is octaveless, then a pitch in any octave will match:

>>> pitch.Pitch('C#').isEnharmonic( pitch.Pitch('D-9') )
True
>>> pitch.Pitch('C#4').isEnharmonic( pitch.Pitch('D-') )
True

Quarter tone enharmonics work as well:

>>> pC.accidental = pitch.Accidental('one-and-a-half-sharp')
>>> pC
<music21.pitch.Pitch C#~4>
>>> pD = pitch.Pitch('D4')
>>> pD.accidental = pitch.Accidental('half-flat')
>>> pD
<music21.pitch.Pitch D`4>
>>> pC.isEnharmonic(pD)
True

Microtonally altered pitches do not return True unless the microtones are the same:

>>> pSharp = pitch.Pitch('C#4')
>>> pSharp.microtone = 20
>>> pFlat = pitch.Pitch('D-4')
>>> pSharp.isEnharmonic(pFlat)
False

>>> pFlat.microtone = 20
>>> pSharp.isEnharmonic(pFlat)
True

Extreme enharmonics also work:

>>> p4 = pitch.Pitch('B##3')
>>> p5 = pitch.Pitch('E---4')
>>> p4.isEnharmonic(p5)
True

If either pitch has no octave then the comparison is done without
regard to octave:

>>> pSharp4 = pitch.Pitch('C#4')
>>> pFlatNoOctave = pitch.Pitch('D-')
>>> pSharp4.isEnharmonic(pFlatNoOctave)
True
>>> pFlatNoOctave.isEnharmonic(pSharp4)
True

`isEnharmonic` can be combined with a test to see if two pitches have the
same step to ensure that they both sound the same and are written
the same, without regard to the presence or absence of an accidental
(this is used in `:meth:~music21.stream.base.Stream.stripTies`):

>>> pD4 = pitch.Pitch('D4')
>>> pDNatural4 = pitch.Pitch('D4', accidental=pitch.Accidental('natural'))
>>> pD4 == pDNatural4
False
>>> pD4.isEnharmonic(pDNatural4) and pD4.step == pDNatural4.step
True
>>> pEbb4 = pitch.Pitch('E--4')
>>> pD4.isEnharmonic(pEbb4) and pD4.step == pEbb4.step
False
r|   r   )r   ry   r  s     rf   isEnharmonicPitch.isEnharmonicV  sJ    @ <<4;;#6HHtww&",11 88tww&&rh   z/dict[t.Literal['d2', '-d2'], interval.Interval]_transpositionIntervalsc                    g r   r~   r  r  ups      rf   _getEnharmonicHelperPitch._getEnharmonicHelper       	rh   c                    g r   r~   r  s      rf   r  r    r  rh   c                   SnU(       d  SnX0R                   ;  a#  [        R                  " U5      U R                   U'   U R                   U   nU R                  nUR	                  U SS9nU(       d  Uc  SUl        U$ UR
                  U l        UR                  U l        UR                  b  UR                  U l        Uc  SU l        gUR                  U l        g)zH
abstracts the code from `getHigherEnharmonic` and `getLowerEnharmonic`
d2z-d2N)maxAccidental)r  r   r   r   transposePitchr  r  r  )r  r  r  intervalStringintervalObjoctaveStoredr   s          rf   r  r    s     26"N!=!==;C;L;L^;\D((822>B{{&&t4&@#HDIllDO{{&!"#"   hhrh   c                   U $ r   r~   r  r  s     rf   getHigherEnharmonicPitch.getHigherEnharmonic      rh   c                   g r   r~   r  s     rf   r  r        rh   c               R    U(       a  U R                  SSS9  gU R                  SSS9$ )a=  
Returns an enharmonic `Pitch` object that is a higher
enharmonic.  That is, the `Pitch` a diminished-second above
the current `Pitch`.

>>> p1 = pitch.Pitch('C#3')
>>> p2 = p1.getHigherEnharmonic()
>>> print(p2)
D-3

We can also set it in place (in which case it returns None):

>>> p1 = pitch.Pitch('C#3')
>>> p1.getHigherEnharmonic(inPlace=True)
>>> print(p1)
D-3

The method even works for certain CRAZY enharmonics

>>> p3 = pitch.Pitch('D--3')
>>> p4 = p3.getHigherEnharmonic()
>>> print(p4)
E----3

But not for things that are just utterly insane:

>>> p4.getHigherEnharmonic()
Traceback (most recent call last):
music21.pitch.AccidentalException: -5 is not a supported accidental type

Note that half accidentals (~ = half-sharp, ` = half-flat)
get converted to microtones:

>>> pHalfSharp = pitch.Pitch('D~4')
>>> p3QuartersFlat = pHalfSharp.getHigherEnharmonic()
>>> print(p3QuartersFlat)
E-4(-50c)

OMIT_FROM_DOCS

(Same thing if done in place; prior bug)

>>> pHalfSharp = pitch.Pitch('D~4')
>>> pHalfSharp.getHigherEnharmonic(inPlace=True)
>>> print(pHalfSharp)
E-4(-50c)
Tr  r  NFr  r  s     rf   r  r    s4    b %%dt%<,,Ut,DDrh   c                   U $ r   r~   r  s     rf   getLowerEnharmonicPitch.getLowerEnharmonic)  r  rh   c                   g r   r~   r  s     rf   r  r  -  r  rh   c               R    U(       a  U R                  SSS9  gU R                  SSS9$ )a  
returns a Pitch enharmonic that is a diminished second
below the current note

If `inPlace` is set to true, changes the current Pitch and returns None.

>>> p1 = pitch.Pitch('E-')
>>> p2 = p1.getLowerEnharmonic()
>>> print(p2)
D#


The lower enharmonic can have a different octave than
the original.

>>> p1 = pitch.Pitch('C-3')
>>> p2 = p1.getLowerEnharmonic()
>>> print(p2)
B2

>>> p1 = pitch.Pitch('C#3')
>>> p1.getLowerEnharmonic(inPlace=True)
>>> print(p1)
B##2
TFr  Nr  r  s     rf   r  r  1  s3    6 %%du%=,,Uu,EErh   r  
mostCommonc               r   U(       a  U nO[         R                  " U 5      nUR                  b[  [        UR                  R                  5      S:  a  UR
                  S;  a  O'U R                  nU R                  Ul        Uc  SUl        U(       a  UR
                  S:X  a  SUl        [        S5      Ul        OwUR
                  S:X  a  SUl        [        S5      Ul        OOUR
                  S	:X  a  S
Ul        [        S5      Ul        O'UR
                  S:X  a  SUl        [        S5      Ul        U(       a  gU$ )a  
Returns a new Pitch (or sets the current one if inPlace is True)
that is either the same as the current pitch or has fewer
sharps or flats if possible.  For instance, E# returns F,
while A# remains A# (i.e., does not take into account that B- is
more common than A#).  Useful to call if you ever have an
algorithm that might take your piece far into the realm of
double or triple flats or sharps.

If mostCommon is set to True, then the most commonly used
enharmonic spelling is chosen (that is, the one that appears
first in key signatures as you move away from C on the circle
of fifths).  Thus, G-flat becomes F#, A# becomes B-flat,
D# becomes E-flat, D-flat becomes C#, G# and A-flat are left
alone.

>>> p1 = pitch.Pitch('B#5')
>>> p1.simplifyEnharmonic().nameWithOctave
'C6'

>>> p2 = pitch.Pitch('A#2')
>>> p2.simplifyEnharmonic(inPlace=True)
>>> p2
<music21.pitch.Pitch A#2>

>>> p3 = pitch.Pitch('E--3')
>>> p4 = p3.transpose(interval.Interval('-A5'))
>>> p4.simplifyEnharmonic()
<music21.pitch.Pitch F#2>

Setting `mostCommon` = `True` simplifies enharmonics
even further.

>>> pList = [pitch.Pitch('A#4'), pitch.Pitch('B-4'),
...          pitch.Pitch('G-4'), pitch.Pitch('F#4')]
>>> [str(p.simplifyEnharmonic(mostCommon=True)) for p in pList]
['B-4', 'B-4', 'F#4', 'F#4']

Note that pitches with implicit octaves retain their implicit octaves.
This might change the pitch space for B#s and C-s.

>>> pList = [pitch.Pitch('B'), pitch.Pitch('C#'), pitch.Pitch('G'), pitch.Pitch('A--')]
>>> [str(p.simplifyEnharmonic()) for p in pList]
['B', 'C#', 'G', 'G']

>>> pList = [pitch.Pitch('C-'), pitch.Pitch('B#')]
>>> [p.ps for p in pList]
[59.0, 72.0]
>>> [p.simplifyEnharmonic().ps for p in pList]
[71.0, 60.0]
Nr  )zE#zB#zC-zF-zD#r   r=   zA#r   zG-r'   r9   zD-r%   )
r   r   r  r   r   rl   r   ry   r  r   )r  r  r  r  
saveOctaves        rf   simplifyEnharmonicPitch.simplifyEnharmonicR  s   t Id+I+I((../#5!.FF "[[
#ww	%'+I$~~%!$	'1&'9	$4'!$	'1&'9	$4'!$	'1'':	$4'!$	'1'':	$rh   c                  U(       a  U nO[         R                  " U 5      nUR                  b  UR                  R                  S:  a  UR	                  SS9  OUR                  R                  S:  a  UR                  SS9  O_U R                  S;   a  UR                  SS9  O?UR	                  SS9  O/U R                  S;   a  UR                  SS9  OUR	                  SS9  U(       a  U R                  5         gU$ )a  
Returns a new Pitch that is the(/an) enharmonic equivalent of this Pitch.
Can be thought of as flipEnharmonic or something like that.

N.B.: n1.name == getEnharmonic(getEnharmonic(n1)).name is not necessarily true.
For instance:

    getEnharmonic(E##) => F#
    getEnharmonic(F#) => G-
    getEnharmonic(A--) => G
    getEnharmonic(G) => F##

However, for all cases not involving double sharps or flats
(and even many that do), getEnharmonic(getEnharmonic(n)) = n

For the most ambiguous cases, it's good to know that these are the enharmonics:

       C <-> B#, D <-> C##, E <-> F-; F <-> E#, G <-> F##, A <-> B--, B <-> C-

However, isEnharmonic() for A## and B certainly returns True.

>>> p = pitch.Pitch('d#')
>>> print(p.getEnharmonic())
E-
>>> p = pitch.Pitch('e-8')
>>> print(p.getEnharmonic())
D#8

Other tests:

>>> print(pitch.Pitch('c-3').getEnharmonic())
B2
>>> print(pitch.Pitch('e#2').getEnharmonic())
F2
>>> print(pitch.Pitch('f#2').getEnharmonic())
G-2
>>> print(pitch.Pitch('c##5').getEnharmonic())
D5
>>> print(pitch.Pitch('g3').getEnharmonic())
F##3
>>> print(pitch.Pitch('B7').getEnharmonic())
C-8

Octaveless Pitches remain octaveless:

>>> p = pitch.Pitch('a-')
>>> p.getEnharmonic()
<music21.pitch.Pitch G#>
>>> p = pitch.Pitch('B#')
>>> p.getEnharmonic()
<music21.pitch.Pitch C>


Works with half-sharps, but converts them to microtones:

>>> dHalfSharp = pitch.Pitch('D~')
>>> print(dHalfSharp.getEnharmonic())
E-(-50c)
Nr   Tr  )r%   r&   r(   )r   r   r  r   r  r  r  r  )r  r  r  s      rf   getEnharmonicPitch.getEnharmonic  s    z D==&D??&$$q((((6&&*'''599/++D+9,,T,:yyO+'''5(((6Krh   c                T    U R                   b  U R                   R                  5         gg)zL
if this pitch is attached to a note, then let it know that it has changed.
N)rY  pitchChangedr+  s    rf   r  Pitch.informClient
  s#     <<#LL%%' $rh   c                \   / nU R                  SS9nUc  U$ UR                  U R                  :w  a  UR                  U5        U n  UR                  SS9nUc  OKUR
                  b$  [        UR
                  R                  5      U:  a  OX2;  a  UR                  U5        OOM_  U n  UR                  SS9nUc   U$ UR
                  b&  [        UR
                  R                  5      U:  a   U$ X2;  a  UR                  U5        O U$ Me  ! [         a     Mu  f = f! [         a     U$ f = f)a  
Return all common unique enharmonics for a pitch,
or those that do not involve more than two accidentals.

>>> p = pitch.Pitch('c#3')
>>> p.getAllCommonEnharmonics()
[<music21.pitch.Pitch D-3>, <music21.pitch.Pitch B##2>]

"Higher" enharmonics are listed before "Lower":

>>> p = pitch.Pitch('G4')
>>> p.getAllCommonEnharmonics()
[<music21.pitch.Pitch A--4>, <music21.pitch.Pitch F##4>]

By setting `alterLimit` to a higher or lower number we
can limit the maximum number of notes to return:

>>> p = pitch.Pitch('G-6')
>>> p.getAllCommonEnharmonics(alterLimit=1)
[<music21.pitch.Pitch F#6>]

If you set `alterLimit` to 3 or 4, you're stretching the name of
the method; some of these are certainly not *common* enharmonics:

>>> p = pitch.Pitch('G-6')
>>> enharmonics = p.getAllCommonEnharmonics(alterLimit=3)
>>> [str(enh) for enh in enharmonics]
['A---6', 'F#6', 'E##6']

Music21 does not support accidentals beyond quadruple sharp/flat, so
`alterLimit` = 4 is the most you can use. (Thank goodness!)
Fr  )	r  rl   rb   r  rq   r  r   r   r  )r  
alterLimitr  r1  s       rf   r   Pitch.getAllCommonEnharmonics  sU   B !###E#29K66TYYKKN))%)8 y||'q||))*Z7}A  (((7 y  ||'q||))*Z7
 	 }A  '   '  s$   D (D 
DD
D+*D+c                N    [         U R                     S-   SU R                  -  -   $ )u  
Returns (or takes) an integer that uniquely identifies the
diatonic version of a note, that is ignoring accidentals.
The number returned is the diatonic interval above C0 (the lowest C on
a Bösendorfer Imperial Grand), so G0 = 5, C1 = 8, etc.
Numbers can be negative for very low notes.

C4 (middleC) = 29, C#4 = 29, C##4 = 29, D-4 = 30, D4 = 30, etc.


>>> c = pitch.Pitch('c4')
>>> c.diatonicNoteNum
29

Unlike MIDI numbers (or `.ps`), C and C# has the same `diatonicNoteNum`:

>>> c = pitch.Pitch('c#4')
>>> c.diatonicNoteNum
29

But D-double-flat has a different `diatonicNoteNum` than C.

>>> d = pitch.Pitch('d--4')
>>> d.accidental.name
'double-flat'
>>> d.diatonicNoteNum
30


>>> lowC = pitch.Pitch('c1')
>>> lowC.diatonicNoteNum
8

>>> b = pitch.Pitch()
>>> b.step = 'B'
>>> b.octave = -1
>>> b.diatonicNoteNum
0

An `implicitOctave` of 4 is used if octave is not set:

>>> c = pitch.Pitch('C')
>>> c.diatonicNoteNum
29

`diatonicNoteNum` can also be set.  Changing it
does not change the Accidental associated with the `Pitch`.

>>> lowDSharp = pitch.Pitch('C#7')  # start high !!!
>>> lowDSharp.diatonicNoteNum = 9  # move low
>>> lowDSharp.octave
1
>>> lowDSharp.name
'D#'


Negative diatonicNoteNums are possible,
in case, like John Luther Adams, you want
to notate the sounds of sub-sonic Earth rumblings.

>>> lowLowA = pitch.Pitch('A')
>>> lowLowA.octave = -1
>>> lowLowA.diatonicNoteNum
-1

>>> lowLowLowD = pitch.Pitch('D')
>>> lowLowLowD.octave = -3
>>> lowLowLowD.diatonicNoteNum
-19
r,   r!   )r/   r  r"  r+  s    rf   diatonicNoteNumPitch.diatonicNoteNum]  s)    P "$)),q0A8K8K4KLLrh   c                `    [        US-
  S-  5      nUS-
  SU-  -
  nSnXC   nX l        XPl        g )Nr,   r!   r$   )rv   r   r  )r  newNumr   noteNameNum	pitchListnoteNames         rf   r  r    s>    fqjA%&qjAJ/*M	&3	rh   c                   g r   r~   r  r   r  s      rf   	transposePitch.transpose       	rh   c                   g r   r~   r  s      rf   r  r    r  rh   c               Z   [        U[        R                  5      (       a  UnO[        R                  " U5      nUR	                  U 5      n[        U[
        5      (       d  U R                  Ul        UR                  SL a  UR                  SSS9  U(       d  U$ UR                  U l        U R                  b  UR                  U l	        UR                  U l
        UR                  U l        UR                  U l        UR                  b%  [        R                  " UR                  5      U l        g)a  
Transpose the pitch by the user-provided value.  If the value is an
integer, the transposition is treated in half steps. If the value is a
string, any Interval string specification can be provided.
Alternatively, a :class:`music21.interval.Interval` object can be
supplied.

>>> aPitch = pitch.Pitch('g4')
>>> bPitch = aPitch.transpose('m3')
>>> bPitch
<music21.pitch.Pitch B-4>
>>> cPitch = bPitch.transpose(interval.GenericInterval(2))
>>> cPitch
<music21.pitch.Pitch C-5>


An interval object can also be a certain number of semitones,
in which case, the spelling of the resulting note (sharp or flat, etc.)
is up to the system to choose.

>>> aInterval = interval.Interval(-6)
>>> bPitch = aPitch.transpose(aInterval)
>>> bPitch
<music21.pitch.Pitch C#4>


Transpose fFlat down 5 semitones -- sort of like a Perfect 4th, but
should be respelled:

>>> fFlat = pitch.Pitch('F-4')
>>> newPitch = fFlat.transpose(-5)
>>> newPitch
<music21.pitch.Pitch B3>

>>> aPitch
<music21.pitch.Pitch G4>

>>> aPitch.transpose(aInterval, inPlace=True)
>>> aPitch
<music21.pitch.Pitch C#4>

Implicit octaves remain implicit:

>>> anyGSharp = pitch.Pitch('G#')
>>> print(anyGSharp.transpose('P8'))
G#
>>> print(anyGSharp.transpose('P5'))
D#

If the accidental of a pitch is chosen by music21, not
given by the user, then after transposing, music21 will
simplify the spelling again:

>>> pc6 = pitch.Pitch(6)
>>> pc6
<music21.pitch.Pitch F#>
>>> pc6.spellingIsInferred
True
>>> pc6.transpose('-m2')
<music21.pitch.Pitch F>

OMIT_FROM_DOCS

Test to make sure that extreme ranges work

>>> dPitch = pitch.Pitch('D2')
>>> lowC = dPitch.transpose('m-23')
>>> lowC
<music21.pitch.Pitch C#-1>

>>> otherPitch = pitch.Pitch('D2')
>>> otherPitch.transpose('m-23', inPlace=True)
>>> print(otherPitch)
C#-1

Test an issue with inPlace not setting spellingIsInferred

>>> pc6.transpose(10, inPlace=True)
>>> pc6.spellingIsInferred
True

Test an issue with inPlace not setting microtone.

>>> flatAndAHalf = pitch.Accidental('one-and-a-half-flat')
>>> dFlatAndAHalf = pitch.Pitch('D2')
>>> dFlatAndAHalf.accidental = flatAndAHalf
>>> dPitch = pitch.Pitch('D2')
>>> intv = interval.Interval(dFlatAndAHalf, dPitch)
>>> dPitch.transpose(intv, inPlace=True)
>>> dPitch
<music21.pitch.Pitch D#2(+50c)>

Tr  N)ru   r   IntervalBaser   r  rv   r   r  rl   r   r  r  r  r   r   )r  r   r  r  r   s        rf   r  r    s    H eX2233K"++E2K&&t,%%%#'#:#:A 4'  $ ?H
 DI{{&hhllDO }}D&'&:&:D#||'"&--"=rh   )minimizer  c                  U R                   c  [        S5      eU(       a  U nO[        R                  " U 5      nUR                   c   e UR                  UR                  -
  S::  a  OU=R                   S-  sl         M5  U(       a6   UR                  UR                  -
  S:  a  OU=R                   S-  sl         M5  U(       d  U$ g)aK  
Given a source Pitch, shift it down some number of octaves until it is below the
target.

If `minimize` is True, a pitch below the target will move up to the
nearest octave.

>>> higherG = pitch.Pitch('G5')
>>> lowerG = higherG.transposeBelowTarget(pitch.Pitch('C#4'))
>>> lowerG
<music21.pitch.Pitch G3>
>>> higherG
<music21.pitch.Pitch G5>


To change the pitch itself, set inPlace to True:

>>> p = pitch.Pitch('G5')
>>> p.transposeBelowTarget(pitch.Pitch('C#4'), inPlace=True)
>>> p
<music21.pitch.Pitch G3>


If already below the target, make no change:

>>> pitch.Pitch('G#3').transposeBelowTarget(pitch.Pitch('C#6'))
<music21.pitch.Pitch G#3>

Below target includes being the same as the target

>>> pitch.Pitch('g#8').transposeBelowTarget(pitch.Pitch('g#1'))
<music21.pitch.Pitch G#1>


This does nothing because it is already low enough:

>>> pitch.Pitch('g#2').transposeBelowTarget(pitch.Pitch('f#8'))
<music21.pitch.Pitch G#2>

But with minimize=True, it will actually RAISE the pitch so that it is the closest
pitch to the target

>>> target = pitch.Pitch('f#8')
>>> pitch.Pitch('g#2').transposeBelowTarget(target, minimize=True)
<music21.pitch.Pitch G#7>

>>> pitch.Pitch('f#2').transposeBelowTarget(target, minimize=True)
<music21.pitch.Pitch F#8>

If the original pitch is octaveless, raises a PitchException:

>>> pitch.Pitch('d').transposeBelowTarget(pitch.Pitch('e2'), minimize=True)
Traceback (most recent call last):
music21.pitch.PitchException: Cannot call transposeBelowTarget with an octaveless Pitch.

If the target pitch is octaveless, assumes it has the default of octave 4.
(The reason for this asymmetry is that the target pitch is never altered
while the original pitch (or its copy) is).

>>> pitch.Pitch('f4').transposeBelowTarget(pitch.Pitch('e'), minimize=True)
<music21.pitch.Pitch F3>

* Changed in v3: default for inPlace=False.
Nz:Cannot call transposeBelowTarget with an octaveless Pitch.r   r,   r|   r   r   r   r   ry   r  r  r  r  srcs        rf   transposeBelowTargetPitch.transposeBelowTargetH  s    P ;; !]^^C--%Czz%%% vv		!Q&JJ!OJ  99svv%*JJ!OJ	  Jrh   c                  U R                   c  [        S5      eU(       a  U nO[        R                  " U 5      nUR                   c   e UR                  UR                  -
  S:  a  OU=R                   S-  sl         M5  U(       a6   UR                  UR                  -
  S:  a  OU=R                   S-  sl         M5  U(       d  U$ g)a\  
Given a source Pitch, shift it up octaves until it is above the target.

If `minimize` is True, a pitch above the target will move down to the
nearest octave.

>>> pitch.Pitch('d2').transposeAboveTarget(pitch.Pitch('e4'))
<music21.pitch.Pitch D5>


To change the pitch itself, set inPlace to True:

>>> p = pitch.Pitch('d2')
>>> p.transposeAboveTarget(pitch.Pitch('e4'), inPlace=True)
>>> p
<music21.pitch.Pitch D5>

If already above the target, make no change:

>>> pitch.Pitch('d7').transposeAboveTarget(pitch.Pitch('e2'))
<music21.pitch.Pitch D7>

Accept the same pitch:

>>> pitch.Pitch('d2').transposeAboveTarget(pitch.Pitch('d8'))
<music21.pitch.Pitch D8>

If minimize is True, we go the closest position:

>>> pitch.Pitch('d#8').transposeAboveTarget(pitch.Pitch('d2'), minimize=True)
<music21.pitch.Pitch D#2>

>>> pitch.Pitch('d7').transposeAboveTarget(pitch.Pitch('e2'), minimize=True)
<music21.pitch.Pitch D3>

>>> pitch.Pitch('d0').transposeAboveTarget(pitch.Pitch('e2'), minimize=True)
<music21.pitch.Pitch D3>

If the original pitch is octaveless, raises a PitchException:

>>> pitch.Pitch('d').transposeAboveTarget(pitch.Pitch('e2'), minimize=True)
Traceback (most recent call last):
music21.pitch.PitchException: Cannot call transposeAboveTarget with an octaveless Pitch.

If the target pitch is octaveless, assumes it has the default of octave 4.
(The reason for this asymmetry is that the target pitch is never altered
while the original pitch (or its copy) is).

>>> pitch.Pitch('d4').transposeAboveTarget(pitch.Pitch('e'), minimize=True)
<music21.pitch.Pitch D5>

* Changed in v3: default for inPlace=False.
Nz:Cannot call transposeAboveTarget with an octaveless Pitch.r   r,   r|   r  r  s        rf   transposeAboveTargetPitch.transposeAboveTarget  s    t ;; !]^^C--%Czz%%%  vv		!Q&JJ!OJ  66FII%*JJ!OJ	  Jrh   c                    U R                   c  gU HO  nUR                  U R                  :X  d  M  UR                   R                  U R                   R                  :X  d  MO    g   g)a{  
Determine if this pitch is in the collection of supplied altered
pitches, derived from a KeySignature object

>>> ks = key.KeySignature(2)
>>> altered = ks.alteredPitches
>>> altered
[<music21.pitch.Pitch F#>, <music21.pitch.Pitch C#>]

>>> cs = pitch.Pitch('c#')
>>> gs = pitch.Pitch('g#')
>>> cs._nameInKeySignature(altered)
True
>>> gs._nameInKeySignature(altered)
False

Note that False is returned regardless of the name if the
key signature has no entry for the pitch:

>>> pitch.Pitch('G')._nameInKeySignature(altered)
False

Other accidentals for pitches whose `.step` is in the
key signature also do not match:

>>> f = pitch.Pitch('F')
>>> f._nameInKeySignature(altered)
False
>>> f.accidental = pitch.Accidental('natural')
>>> f._nameInKeySignature(altered)
False
>>> pitch.Pitch('F##')._nameInKeySignature(altered)
False
>>> pitch.Pitch('C-')._nameInKeySignature(altered)
False
FT)r  r  rl   r  alteredPitchesr   s      rf   _nameInKeySignaturePitch._nameInKeySignature  sP    J ??"Avv"<<$$(<(<<   rh   c                N    U H  nUR                   U R                   :X  d  M    g   g)a%  
Determine if this pitch is in the collection of supplied altered
pitches, derived from a KeySignature object

>>> a = pitch.Pitch('c')
>>> b = pitch.Pitch('g')
>>> ks = key.KeySignature(2)
>>> a._stepInKeySignature(ks.alteredPitches)
True

>>> b._stepInKeySignature(ks.alteredPitches)
False

TF)r  r  s      rf   _stepInKeySignaturePitch._stepInKeySignature3  s&      Avv"   rh   T)		pitchPastpitchPastMeasureotherSimultaneousPitchesr  cautionaryPitchClasscautionaryAlloverrideStatuscautionaryNotImmediateRepeatlastNoteWasTiedc       	          ^ ^^ T R                   mUU 4S jmSUU4S jjn
Uc  / nUc  / nUc  / nSnX!-   nUSL a#  Tc  OTR                  c  OTR                  S;   a  gTb  TR                  S:X  a  STl        gU	SL a$  Tb   TR                  S:w  a  STl        gSTl        ggU(       a*  U(       a#  [        U 4S	 jU 5       5      (       a	  U
" S5        gU(       d  Tb[  U(       d  TR                  S
;   aD  TR                  S:X  a  T R                  U5      Tl        gT R                  U5      (       + Tl         gTb-  TR                  SL a  T R                  U5      (       a  STl        gTb  TR                  S:X  a  T R                  U5      (       a  U
" S5        g[        U5       H_  nUR                  T R                  :X  d  M  UR                  T R                  :X  d  M;  UR                  T R                  :w  a
  U
" S5          g  O   USL d  Tb  TR                  S;   a	  U
" S5        gSnUSL a0  Tb  TR                  S:w  a  [        T R                  5      nTUl         OT n[        U5      n[        [        U5      S-
  SS5       GHH  nUU:  a  SnSnTb  TR                  S:X  a    GO)OASn[        U[        U5      5       H$  nUU   R                  T R                  :w  d  M"  Sn  O   SnUSL a"  Tb  T R                  U5      (       d	  STl          gUSL a@  Tb  TR                  S:w  a-  [        UU   R                  5      nUU   R                   Ul         OUU   nUR                  UR                  :w  a  M  T R                  UU   R                  :X  a  SnOSnUSL a2  UR                   b%  UR                   R                  SL a  Tb  STl          gUSL a  UR                   b  UR                   bt  Tbq  UR                   R                  UR                   R                  :X  aC  T R                  U5      SL a#  USL d  UR                   R                  SL a  SnGM  STl        Sn  GOnUR                   b  UR                   R                  S:X  a  UR                   b  UR                   R                  S:X  a  USL a-  T R                  U5      SL a  USL a	  U
" S5        O^Tb  STl        OST R                  U5      SL a  USL a	  U
" S5        O1T R                  U5      SL a  USL a  USL a	  U
" S5        O
Tb  STl        Sn  GOUR                   b  UR                  UR                  :w  au  UR                   R                  S:w  a[  UR                   b  UR                   R                  SL a5  USL a  USL a  GM+  USL a  Tb  TR                  S:X  a  GMF  U
" S5        Sn  GOUR                   b  UR                   R                  S:X  a6  Tb3  UR                   b&  UR                   R                  S:w  a  STl        Sn  GOUR                   bk  UR                   b^  UR                   R                  UR                   R                  :w  a0  Tb-  U(       d  UR                   R                  S:w  a  STl        Sn  GO%UR                   cL  UR                   b?  Tb<  UR                   R                  S:X  a  T R                  U5      Tl        OSTl        Sn  OUSL a  UR                   b  UR                   b  UR                   R                  UR                   R                  :X  az  Tbw  USL ar  USL a&  UR                   R                  SLa  STl        SnSn  OLUR                   R                  SL a  SnGM  T R                  U5      (       d  STl        OSTl        Sn  gGMK     USL a)  T R                  U5      SL a	  U
" S5        gTb  STl        ggU(       dF  TbC  TR                  S:X  a  T R                  U5      Tl        gT R                  U5      (       + Tl        gU(       d$  Tc   T R                  U5      (       a	  U
" S5        gggg)a
  
Given an ordered list of Pitch objects in `pitchPast`, determine if
this pitch's Accidental object needs to be created or updated with a
natural or other cautionary accidental.

Changes to this Pitch object's Accidental object are made in-place.

`pitchPast` is a list of pitches preceding this pitch in the same measure.
If None, a new list will be made.

`pitchPastMeasure` is a list of pitches preceding this pitch but in a
previous measure. If None, a new list will be made.

`otherSimultaneousPitches` is a list of other pitches in this simultaneity, for use
when `cautionaryPitchClass` is True.

The `alteredPitches` list supplies pitches from a :class:`~music21.key.KeySignature`
object using the :attr:`~music21.key.KeySignature.alteredPitches` property.
If None, a new list will be made.

If `cautionaryPitchClass` is True, comparisons to past accidentals are
made regardless of register. That is, if a past sharp is found two
octaves above a present natural, a natural sign is still displayed.
Note that this has nothing to do with whether a sharp (not in the key
signature) is found in a different octave from the same note in a
different octave.  The sharp must always be displayed.  Notes
with displayType = 'if-absolutely-necessary' will ignore the True
setting.

If `overrideStatus` is True, this method will ignore any current
`displayStatus` setting found on the Accidental. By default, this does
not happen. If `displayStatus` is set to None, the Accidental's
`displayStatus` is set.

If `cautionaryNotImmediateRepeat` is True, cautionary accidentals will
be displayed for an altered pitch even if that pitch had already been
displayed as altered (unless it's an immediate repetition).  Notes
with displayType = 'if-absolutely-necessary' will ignore the True
setting.

If `lastNoteWasTied` is True then this note will be treated as
immediately following a tie.

>>> a = pitch.Pitch('a')
>>> past = [pitch.Pitch('a#'), pitch.Pitch('c#'), pitch.Pitch('c')]
>>> a.updateAccidentalDisplay(pitchPast=past, cautionaryAll=True)
>>> a.accidental, a.accidental.displayStatus
(<music21.pitch.Accidental natural>, True)

>>> b = pitch.Pitch('a')
>>> past = [pitch.Pitch('a#'), pitch.Pitch('c#'), pitch.Pitch('c')]
>>> b.updateAccidentalDisplay(pitchPast=past)  # should add a natural
>>> b.accidental, b.accidental.displayStatus
(<music21.pitch.Accidental natural>, True)

In this example, the method will not add a natural because the match is
pitchSpace and our octave is different.

>>> a4 = pitch.Pitch('a4')
>>> past = [pitch.Pitch('a#3'), pitch.Pitch('c#'), pitch.Pitch('c')]
>>> a4.updateAccidentalDisplay(pitchPast=past, cautionaryPitchClass=False)
>>> a4.accidental is None
True

v8 -- made keyword-only and added `otherSimultaneousPitches`.
c                 2   > T c  [        S5      m T Tl        g g )Nr8   )r   r  )r   r  s   rf   none_to_natural6Pitch.updateAccidentalDisplay.<locals>.none_to_natural  s    { +"% rh   c                ,   > T" 5         Tc   eU Tl         g r   )r  )newDisplayStatusr   r  s    rf   set_displayStatus8Pitch.updateAccidentalDisplay.<locals>.set_displayStatus  s    ?"? 0Crh   NF)TFr  Tr  c              3     >#    U  H>  nUR                   TR                   :H  =(       a    UR                  TR                  :g  v   M@     g 7fr   )r  r  )r   pSimultr  s     rf   r   0Pitch.updateAccidentalDisplay.<locals>.<genexpr>  s<      97G LLDII-W'2D2D2WW7s   AA	)FNr8   )r  r  r  r,   r   )r  bool)r  r  r  anyrl   r  r  reversedr  r   r   ra   r  r  )r  r  r  r   r  r  r  r  r  r  r  (displayAccidentalIfNoPreviousAccidentalspitchPastAll	thisPPastsetFromPitchPastpSelfoutOfMeasureLengthrc   pPastInMeasurecontinuousRepeatsInMeasurejpPastoctaveMatchr   r  s   `                      @@rf   updateAccidentalDisplayPitch.updateAccidentalDisplayG  s   b oo	&	1 	1 I#!!N 490'3U"{""*""m3 ?s'9 %Cd"??k1(-C%  )-C% %$ 979 9 9 d#  '3+<+<+M88y((,(@(@(PC%   -1,D,D^,T(TC%  /''4/..~>>$)!  ;#((i"7..~>>!$' "),I~~*y/?/?4;;/N>>TYY.%d+ - T!OO'>>d# ! D([+DD$))$E"EE !!12 s<(1,b"5A %%!&-2*?s:S'S  "&q#l"34A $A559L9LL5:2 5 26. %' 44^DD$(! %,;T(Tl1o223 $0?#=#= $Q zzUZZ' {{l1o444"# +d2((4((66$>?(-C% -4&&2&&2o&&++u/?/?/D/DD ,,^<E$-!,,::eC?C<(-C%'+$ "".&&++y8''/**//9<-5 00@DH +u 4)$/?05C- ..~>$F6$>%d+
 ..~>$F6%?(E1%d+
 ,1)#'  "".jjEJJ.&&++y8''/**88EA%',@E,I5(OOO/HH!$'#'  ##+&&++y8''3'',,	9$(!#'  "".&&2&&++u/?/?/D/DDo"e&6&6&B&BF_&_$(!#' 
 ""*&&2o##((I5(,(@(@(PC%(,C%#' 
 -5&&2&&2&&++u/?/?/D/DDo!T)0E9!,,::%G ).C%?D<'+$%%33u<?C<33NCC,0),1)'+$ g 6p 4t; ''75@!$'?(-C% # "coxx9$$($<$<^$L!(,(@(@(P$P! "ck''77!$' 8 '2!rh   c                   SSK Jn  SSK Jn  UR                  nSnUR	                  US   5      S:X  a  SnU(       d  g[
        R                  " US   US   5      nUR                  S:X  a  US   R                  S	5      nOUR                  S
:X  a  US   R                  S5      nOUR                  S:X  a  US   R                  S5      nOUR                  S:X  a  US   R                  S5      nOtUR                  S:X  a  US   R                  S5      nOOUR                  S:X  a  US   R                  S
5      nO*UR                  S:X  a  US   R                  S5      nOUS   nUR                  " UR                  5      nSUl        SUl        SUl        UR                  " US   R                  5      n	UR                  " US   R                  5      n
UR	                  US   5      U
l        UR                  XU/5      nU$ )a@  
Given a chord, determines whether the chord constitutes a string
harmonic and then returns a new chord with the proper sounding pitch
added.

>>> n1 = note.Note('d3')
>>> n2 = note.Note('g3')
>>> n2.notehead = 'diamond'
>>> n2.noteheadFill = False
>>> p1 = pitch.Pitch('d3')
>>> harmChord = chord.Chord([n1, n2])
>>> harmChord.quarterLength = 1
>>> newChord = p1.getStringHarmonic(harmChord)
>>> newChord.quarterLength = 1
>>> pitchList = newChord.pitches
>>> pitchList
(<music21.pitch.Pitch D3>, <music21.pitch.Pitch G3>, <music21.pitch.Pitch D5>)

otherwise returns False

r   r   )chordFr,   diamondTr|   r   r!   r-   r    r   r.   r   noStem)music21r   r"  r   getNoteheadr   notesToChromaticintervalClassr  Noter  noteheadParenthesisnoteheadFillstemDirectionnoteheadChord)r  chordInr   r"  r  isStringHarmonicchordIntsoundingPitchnoteOutnote1note2chordOuts               rf   getStringHarmonicPitch.getStringHarmonic  s   0 	!!OO	 y|,	9#,,Yq\9Q<H!!R'%aL44Q7M##q(%aL44Q7M##q(%aL44Q7M##q(%aL44Q7M##q(%aL44Q7M##q(%aL44Q7M##q(%aL44Q7M &aLM))M889&*## (		)A,556		)A,556 ,,Yq\: ;;g67rh   )r  rY  r  r  r  r  r  r  r}  r  r  r  rl   r   r  ry   r   r  r   )rl   zstr | int | float | Noner  zStepName | Noner   
int | Noner  z%Accidental | str | int | float | Noner  zMicrotone | int | float | Noner  zint | PitchClassString | Noner  r9  ry   zfloat | Noner  zPitch | None)r  object)r  r  )r  base.Groups)rr  r;  )r  zAccidental | None)r   z%str | Accidental | None | int | float)r  r   )r   z$float | int | str | None | Microtone)r  rv   r  r  )r6  r*  r  )r  r	   )r6  r	   r  None)r   zint | PitchClassString)r  r9  )r   zint | float | None)r   int | float)r  rv   r  r   )r  str | Pitchr  ztuple[int, float])r  zstr | Pitch | Noner  r*  )r  r>  r  ztuple[int, Pitch])r  r>  r  r*  )r  r   r  r  )r  r   r  t.Literal[True]r  r  r  r<  )r  r   r  t.Literal[False]r  r  r  r   )r  r   r  r  r  r  r  PitchType | None)r  r   r  r@  r  r   )r  r   r  r?  r  r<  )r  r   r  r  r  rA  )r  r   r  rA  )r   )r  r   r  rv   r  zlist[PitchType])r  rv   )r  r   r   !interval.IntervalBase | str | intr  r?  r  r<  )r  r   r   rB  r  r@  r  r   )r  r   r   rB  r  r  r  rA  )r  list[Pitch] | Noner  rC  r   rC  r  rC  r  r  r  r  r  r  r  r  r  r  )Kr  r  r  r  rO  r  TWELFTH_ROOT_OF_TWOr  r`  r  r  r,  r:  r   r  r&  r  r  rx  ry  rQ  r  rR  r  r  r  r  r   r  r  ry   r  rl   r=  r  rD  r  r  r  rR  r   r"  r  r  rq  rs  r  rw  r  r~  r}  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r   r  r  r  r  r  r  r  r7  r  r~   rh   rf   r   r   X  s   _B;J / 	 02!I~ 2j -1P (,$(=A7;9="&"&+/P)P %P "	P
 ;P 5P 7P  P  P )Pd5p62
 ""@$!"H   ]]     .  , # #@ P P4V)p  6 :? 2 h :? - b ^ ^@ YY' ' Y Yv 
[[' '$  8 
[[&! &!P   40 40l P P 7 7   8 4 4l 
[[  c# c#J ' ' 7 7,    6 ]]   ( : :z 8Q 8Qt" *M&  *A *AZ )L%  B BH  2   C C( ^^ aFa"-6a"%6a"f 6:;A$2;A;Az   
 B,2",2 
,2`d'N PRLQ&5!%*. 
 &6!%*3 
&*!%*8<     AF 5Ep     @E FH 	\\
 
\| 38 Wt(HV GM GMR   , !	
 
  
 %*	, "	
 
  	AA,A 	A
 
AT bb 
bN ',%*	U 0>	Ur,\. '+-159+/%)#$-1 %E( $E( +	E(
 #3E( )E( #E( E( E( '+E( E(NErh   c                      \ rS rSrS rSrg)TestiY  c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestrH  globals)r  rH  s     rf   testCopyAndDeepcopyTest.testCopyAndDeepcopyZ  s    7D')$rh   r~   N)r  r  r  r  rK  r  r~   rh   rf   rF  rF  Y  s    %rh   rF  __main__)rl   r*  r  r  )rl   r*  r  r*  )ry   zint | float | PitchClassStringr  r=  )r   rv   r  r*  )ry   r=  r  rv   )ry   r=  r  z+tuple[StepName, Accidental, Microtone, int])r  ztuple[float, float])r   r=  r  rv   )TTT)r   list[Pitch]r   r  r   r  r   r  )r   rN  )MrO  
__future__r   collectionsr   r   r   r   typingr   r   unittestr%  r   r   music21.common.objectsr   music21.common.typesr	   r
   r   r   r   r   r   TYPE_CHECKINGr   TypeVarr   EnvironmentenvironLocalLiteralPitchClassStringr)   r  r   r*   r+   r/   rD  r   r5  r6  r_   itemsrp   chrr  rj   rg   accidentalModifiersSortedrm   rr   rz   r   r   r   r   r   r   r   r   r   Music21Exceptionrq   r   r
  ProtoM21Objectr   
StyleMixinr   r   TestCaserF  r  r  mainTest)r  r  s   00rf   <module>rc     s   # #         5 )       ??IIk1	&&w/99CD  
	
	
	
	
	
	 	  %





) %  ?	= >	
	
	
	
	
	
	
+ '  &   
      .F-K-K-MN-MTQAD-MN !S\CL()
Hs7|#$	3w<	8c'l"##g,S\CL()	3w<	8c'l"##g,#   !!'! N! n	!
 !! 	&! ! M! m!  ! \! 	,! ! 1! 2!  "!!" )#!$  
/0!'1! : +, %NNJ"<(8X)X)X)v+/\$*T 48/3(,9c,09c(,9c "&9cx EU - AQ  4DPT Md	,77 		\22 		66 	S$&&(: S$l`
'')9)9 `
L{;G"" {;Bx%8 % Z+
 zT og Os   K=