
    rh                    *   S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  \R"                  (       a  SSKJr  \R(                  " S5      r0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S)_S*S+_S,S+_S-S.S/S0S0S0S1S2S2S3S4S5S6S7.Er SQ     SRS8 jjr " S9 S:\R0                  5      r " S; S<\R4                  5      r " S= S>\5      r " S? S@\5      r " SA SB\5      r " SC SD\5      r " SE SF\5      r  SSSG jr! " SH SI\RD                  5      r# " SJ SK\#5      r$ " SL SM\#5      r% " SN SO\RL                  5      r'\\\ \\%\$\#\!/r(\)SP:X  a  SSKr\RT                  " \'5        gg)TzH
This module defines objects for describing tempo and changes in tempo.
    )annotationsN)base)common)duration)environment)exceptions21)expressions)note)spanner)style)
OffsetQLIntempolarghissimo   
largamente    grave(   zmolto adagiolargo.   lento4   adagio8   slowlangsam	larghetto<   	adagiettoB   andanteH   	andantinoP   zandante moderatoS   maestosoX   moderato\   moderatel   x                           )
allegrettoanimatozallegro moderatoallegrofastschnellallegrissimozmolto allegro
   très vitevivacevivacissimoprestoprestissimoc                L    SU -  nX1-  nU[        U5      -  n[        SU-  5      $ )a  
Convert between equivalent tempi, where the speed stays the
same but the beat referent and number change.

60 bpm at quarter, going to half

>>> tempo.convertTempoByReferent(60, 1, 2)
30.0

60 bpm at quarter, going to 16th

>>> tempo.convertTempoByReferent(60, 1, 0.25)
240.0

60 at dotted quarter, get quarter

>>> tempo.convertTempoByReferent(60, 1.5, 1)
90.0

60 at dotted quarter, get half

>>> tempo.convertTempoByReferent(60, 1.5, 2)
45.0

60 at dotted quarter, get trip

>>> tempo.convertTempoByReferent(60, 1.5, 1/3)
270.0

A Fraction instance can also be used:

>>> tempo.convertTempoByReferent(60, 1.5, common.opFrac(1/3))
270.0

r   )float)	numberSrcquarterLengthBeatSrcquarterLengthBeatDstsrcDurPerBeatdurdstDurPerBeats         G/home/james-whalen/.local/lib/python3.13/site-packages/music21/tempo.pyconvertTempoByReferentrI   I   s8    R NM

.C% 455M m#$$    c                      \ rS rSrSrg)TempoException}    N__name__
__module____qualname____firstlineno____static_attributes__rN   rJ   rH   rL   rL   }       rJ   rL   c                  D    \ rS rSrSrSr\R                  rSS jr	S r
Srg)	TempoIndication   zv
A generic base class for all tempo indications to inherit.
Can be used to filter out all types of tempo indications.
   Nc                    Uc  U n[        U[        5      (       a  UR                  $ [        U[        5      (       a  U$ SUR                  ;   a  UR                  5       $ [        SU 35      e)zZ
Get the appropriate MetronomeMark from any sort of TempoIndication, regardless of class.
	TempoTextz9cannot derive a MetronomeMark from this TempoIndication: )
isinstanceMetricModulationnewMetronomeMetronomeMarkclassesgetMetronomeMarkrL   )selffounds     rH   getSoundingMetronomeMark(TempoIndication.getSoundingMetronomeMark   sn     =Ee-..%%%}--LEMM)))++ KE7SU UrJ   c                    U R                  S[        R                  R                  R                  S9nUc  gU R                  U5      $ )a  
Do activeSite and context searches to try to find the last relevant
MetronomeMark or MetricModulation object. If a MetricModulation mark is found,
return the new MetronomeMark, or the last relevant.

>>> s = stream.Stream()
>>> s.insert(0, tempo.MetronomeMark(number=120))
>>> mm1 = tempo.MetronomeMark(number=90)
>>> s.insert(20, mm1)
>>> mm1.getPreviousMetronomeMark()
<music21.tempo.MetronomeMark animato Quarter=120>
rW   )getElementMethodN)getContextByClassr   enumsElementSearchBEFORE_OFFSETrd   )rb   objs     rH   getPreviousMetronomeMark(TempoIndication.getPreviousMetronomeMark   sI      $$%66<ll6P6P6^6^ % `;,,S11rJ   rN   N)rP   rQ   rR   rS   __doc__classSortOrderr   	TextStyle_styleClassrd   rm   rT   rN   rJ   rH   rW   rW      s"     N//KU"2rJ   rW   c                  |   ^  \ rS rSrSrSU 4S jjrS rS rS r\	" \\SS9r
S	 rSS
 jrS rSS jrSS jrSrU =r$ )r[      z
>>> import music21
>>> tm = music21.tempo.TempoText('adagio')
>>> tm
<music21.tempo.TempoText 'adagio'>
>>> print(tm.text)
adagio
c                \   > [         TU ]  " S0 UD6  S U l        Ub  [        U5      U l        g g )NrN   )super__init___textExpressionstrtext)rb   r{   keywords	__class__s      rH   rx   TempoText.__init__   s3    $8$  $D	DI rJ   c                ,    [        U R                  5      $ ro   )reprr{   rb   s    rH   _reprInternalTempoText._reprInternal   s    DIIrJ   c                .    U R                   R                  $ )z(
Get the text used for this expression.
)ry   contentr   s    rH   _getTextTempoText._getText   s     ##+++rJ   c                &   U R                   ct  [        R                  " U5      U l         U R                  (       a  U R                  U R                   l        gU R                   R                  U l        U R                  5         gXR                   l        g)zx
Set the text of this repeat expression. This is also the primary way
that the stored TextExpression object is created.
N)ry   r	   TextExpressionhasStyleInformationr   applyTextFormattingr   rb   values     rH   _setTextTempoText._setText   sk    
 '#.#=#=e#DD ''-1ZZ$$* "1177
((*+0  (rJ   z
        Get or set the text as a string.

        >>> import music21
        >>> tm = music21.tempo.TempoText('adagio')
        >>> tm.text
        'adagio'
        >>> tm.getTextExpression()
        <music21.expressions.TextExpression 'adagio'>
        docc                    [        U R                  S9nU R                  (       a  U R                  Ul        U$ UR                  U l        U$ )z
Return a MetronomeMark object that is configured from this objects Text.

>>> tt = tempo.TempoText('slow')
>>> mm = tt.getMetronomeMark()
>>> mm.number
56
)r{   )r_   r{   r   r   rb   mms     rH   ra   TempoText.getMetronomeMark   s?     		*##zzBH 	 DJ	rJ   c                ^    U R                   c  g[        R                  " U R                   5      $ )z`
Return a TextExpression object for this text.

What is this a deepcopy and not the actual one?
N)ry   copydeepcopy)rb   numberImplicits     rH   getTextExpressionTempoText.getTextExpression   s(     '==!5!566rJ   c                .   Xl         U R                   R                  (       a  U R                   R                  U l        gU R                  (       a  U R                  U R                   l        gU R                   R                  U l        U R                  5         g)z0
Given a TextExpression, set it in this object.
N)ry   r   r   r   r   s     rH   setTextExpressionTempoText.setTextExpression	  sh      %33--33DJ%%)-D  & --33DJ$$&rJ   c                    Uc  U R                   nSUR                  l        U(       a  SUR                  l        U$ SUR                  l        U$ )zU
Apply the default text formatting to the text expression version of this tempo mark
bold   -   )ry   r   	fontStyle	absoluteY)rb   ter   s      rH   r   TempoText.applyTextFormatting  sI     :%%B#!#BHH 	 "$BHH	rJ   c                    S nUc  U R                   R                  n[         H  nU" U5      nU" U5      nX;   d  X1;   d  M    g   g)aH  
Return True or False if the supplied text seems like a
plausible Tempo indications be used for this TempoText.

>>> tt = tempo.TempoText('adagio')
>>> tt.isCommonTempoText()
True

>>> tt = tempo.TempoText('Largo e piano')
>>> tt.isCommonTempoText()
True

>>> tt = tempo.TempoText('undulating')
>>> tt.isCommonTempoText()
False
c                    U R                  5       n U R                  SS5      n U R                  SS5      n U R                  5       n U $ )N  .)stripreplacelower)ss    rH   	stripText.TempoText.isCommonTempoText.<locals>.stripText7  s=    	A		#r"A		#r"A	AHrJ   TF)ry   r   defaultTempoValues)rb   r   r   	candidates       rH   isCommonTempoTextTempoText.isCommonTempoText&  sP    "	 =((00E+I!),Ie$E!Y%7 , rJ   )ry   r   r{   ro   FNF)rP   rQ   rR   rS   rp   rx   r   r   r   propertyr{   ra   r   r   r   r   rT   __classcell__r}   s   @rH   r[   r[      sO    ",1  Hh 	- 	D"	7' " "rJ   r[   c                      \ rS rSrSrg)MetronomeMarkExceptioniL  rN   NrO   rN   rJ   rH   r   r   L  rU   rJ   r   c                  ^  ^  \ rS rSr% SrSS0rS\S'      S&SSSSS	.               S'U 4S
 jjjjrS rS r	S r
S rS r\" \\SS9rS rS(S jr\" \\SS9rS)S jr S(S*S jjr\" \\SS9rS rS r\" \\SS9rS(S+S jjrS(S jrS rS,S jrS-S jrS  rS! rS" rS# r S$ r!S%r"U =r#$ ).r_   iR  u  
A way of specifying a particular tempo with a text string,
a referent (a duration) and a number.

The `referent` attribute is a Duration object, or a string duration type or
a floating-point quarter-length value used to create a Duration.

MetronomeMarks, as Music21Object subclasses, also have .duration object
property independent of the `referent`.

>>> a = tempo.MetronomeMark('slow', 40, note.Note(type='half'))
>>> a.number
40
>>> a.referent
<music21.duration.Duration 2.0>
>>> a.referent.type
'half'
>>> print(a.text)
slow


Some text marks will automatically suggest a number.

>>> mm = tempo.MetronomeMark('adagio')
>>> mm.number
56
>>> mm.numberImplicit
True

For certain numbers, a text value can be set implicitly

>>> tm2 = tempo.MetronomeMark(number=208)
>>> print(tm2.text)
prestissimo
>>> tm2.referent
<music21.duration.Duration 1.0>

Unicode values work fine thanks to Python 3:

>>> marking = 'très vite'
>>> marking
'très vite'
>>> print(tempo.defaultTempoValues[marking])
144
>>> tm2 = tempo.MetronomeMark(marking)
>>> tm2.text.endswith('vite')
True
>>> tm2.number
144

For playback only (no score output) set numberSounding but no number:

>>> fast = tempo.MetronomeMark(numberSounding=168)
>>> fast
<music21.tempo.MetronomeMark Quarter=168 (playback only)>
	placementa  
            Staff placement: 'above', 'below', or None.

            A setting of None implies that the placement will be determined
            by notation software and no particular placement is demanded.

            This is not placed in the `.style` property, since for some expressions,
            the placement above or below an object has semantic
            meaning and is not purely presentational.
            zdict[str, str]	_DOC_ATTRNF)parenthesesplaybackOnlynumberSoundingr   c                 > [         T	U ]  " S0 UD6  Uc  [        U[        5      (       a  UnS nUb  [        R
                  " U5      OS U l        S U l        Ub  Xpl        OU R                  b  SU l        S U l        S U l	        Ub  Xl
        X@l        S U l        S U l        Uc  [        R                  " SS9nX0l        U R#                  5         U R%                  5         X`l        g )NFquartertyperN   )rw   rx   r\   intr   numToIntOrFloat_numberr   
_tempoTexttextImplicitr{   r   r   	_referentr   Durationreferent_updateNumberFromText_updateTextFromNumber_numberSounding)
rb   r{   numberr   r   r   r   r   r|   r}   s
            rH   rx   MetronomeMark.__init__  s     	$8$>js33FD /5.@F""6*d 	 #%"0\\%"'D I "-((i8H  	""$""$  .rJ   c                   SnU R                   nU R                  b  U R                   c  SnU R                  nU R                  c  U R                  R                   SU U 3$ U R                   SU R                  R                   SU U 3$ )Nr   z (playback only)=r   )r   r   r{   r   fullName)rb   soundingr   s      rH   r   MetronomeMark._reprInternal  s    +0C)H))F99mm,,-QvhxjAAii[$--"8"8!96(8*MMrJ   c                    U R                   cM  U R                  b?  U R                  U R                  U R                  5      SS9  U R                  b  SU l        gggg)z8
Update text if number is given and text is not defined
NF)updateNumberFromTextT)r   r   r   _getDefaultTextr{   r   r   s    rH   r   #MetronomeMark._updateTextFromNumber  s^     ??"t||'? MM$..t||</4  6yy$$(! % (@"rJ   c                    U R                   cD  U R                  b6  U R                  U R                  5      U l         U R                   b  SU l        gggg)z:
Update number if text is given and number is not defined
NT)r   r   _getDefaultNumberr   r   s    rH   r   #MetronomeMark._updateNumberFromText  sM     <<DOO$?11$//BDL||'&*# ( %@rJ   c                    U R                   $ ro   )r   r   s    rH   _getReferentMetronomeMark._getReferent  s    ~~rJ   c                   Uc  [         R                  " SS9U l        g [        R                  " U5      (       d  [        U[        5      (       a  [         R                  " U5      U l        g [        U[        R                  5      (       a  UR                   U l        g [        U[         R                  5      (       a  Xl        g [        SU 35      e)Nr   r   z0Cannot get a Duration from the supplied object: )
r   r   r   r   isNumr\   rz   r   Music21ObjectrL   r   s     rH   _setReferentMetronomeMark._setReferent  s    =%..I>DN\\%  Juc$:$:%..u5DNt1122"^^DNx0011"N !#STYSZ![\\rJ   z{
        Get or set the referent, or the Duration object that is the
        reference for the tempo value in BPM.
        r   c                J    U R                   c  g U R                   R                  $ ro   )r   r{   r   s    rH   r   MetronomeMark._getText  s    ??"###rJ   c                N   Uc  S U l         O[        U[        5      (       a  Xl         SU l        O_[        U5      U l         U R                  (       a  U R
                  U R                   l        OU R                   R
                  U l        SU l        U(       a  U R                  5         g g r   )r   r\   r[   r   r   r   r   )rb   r   r   s      rH   r   MetronomeMark._setText
  sz    ="DOy))#O %D'.DO''(,

%!__22
 %D&&(  rJ   a  
        Get or set a text string for this MetronomeMark. Internally implemented as a
        :class:`~music21.tempo.TempoText` object, which stores the text in
        a :class:`~music21.expression.TextExpression` object.

        >>> mm = tempo.MetronomeMark(number=123)
        >>> mm.text == None
        True
        >>> mm.text = 'medium fast'
        >>> print(mm.text)
        medium fast
        c                    U R                   $ ro   )r   r   s    rH   
_getNumberMetronomeMark._getNumber(  s    ||rJ   c                    [         R                  " U5      (       d  [        S5      e[         R                  " U5      U l        SU l        U(       a  U R                  5         g g )Nzcannot set number to a stringF)r   r   rL   r   r   r   r   )rb   r   updateTextFromNumbers      rH   
_setNumberMetronomeMark._setNumber+  sM     ||E"" !@AA--e4#&&(  rJ   a8  
        Get and set the number, or the numerical value of the Metronome.

        >>> mm = tempo.MetronomeMark('slow')
        >>> mm.number
        56
        >>> mm.numberImplicit
        True
        >>> mm.number = 52.5
        >>> mm.number
        52.5
        >>> mm.numberImplicit
        False
        c                    U R                   $ ro   )r   r   s    rH   _getNumberSounding MetronomeMark._getNumberSoundingE  s    ###rJ   c                b    [         R                  " U5      (       d  Ub  [        S5      eXl        g )Nz%cannot set numberSounding to a string)r   r   rL   r   r   s     rH   _setNumberSounding MetronomeMark._setNumberSoundingH  s(    ||E""u'8 !HII$rJ   a  
        Get and set the numberSounding, or the numerical value of the Metronome that
        is used for playback independent of display. If numberSounding is None, number is
        assumed to be numberSounding.

        >>> mm = tempo.MetronomeMark('slow')
        >>> mm.number
        56
        >>> mm.numberImplicit
        True
        >>> mm.numberSounding is None
        True
        >>> mm.numberSounding = 120
        >>> mm.numberSounding
        120
        c                    U(       a8  U R                   b+  [        U R                   U R                  R                  S5      $ U R                  b+  [        U R                  U R                  R                  S5      $ g)ai  
Get a BPM value where the beat is a quarter; must convert from the
defined beat to a quarter beat. Will return None if no beat number is defined.

This mostly used for generating MusicXML <sound> tags when necessary.

>>> mm = tempo.MetronomeMark(number=60, referent='half')
>>> mm.getQuarterBPM()
120.0
>>> mm.referent = 'quarter'
>>> mm.getQuarterBPM()
60.0
N      ?)r   rI   r   quarterLengthr   )rb   useNumberSoundings     rH   getQuarterBPMMetronomeMark.getQuarterBPM_  sk     !4!4!@)$*=*=*.--*E*E*-/ / ;;")$++*.--*E*E*-/ / rJ   c                n    [        USU R                  R                  5      nU(       d  Xl        gXl        g)aQ  
Given a value in BPM, use it to set the value of this MetronomeMark.
BPM values are assumed to refer only to quarter notes; different beat values,
if defined here, will be scaled


>>> mm = tempo.MetronomeMark(number=60, referent='half')
>>> mm.setQuarterBPM(240)  # set to 240 for a quarter
>>> mm.number  # a half is half as fast
120
r   N)rI   r   r   r   r   )rb   r   	setNumbers      rH   setQuarterBPMMetronomeMark.setQuarterBPMx  s*     'uc4==3N3NO#( KrJ   c                d   [        U[        5      (       a  UR                  nOUnSnUR                  5       [        ;   a  [        UR                  5          nOU[        ;   a	  [        U   nUcC  UR                  S5       H.  n[         H!  nXTR                  5       :X  d  M  [        U   nM#     M0     U$ )z
Given a tempo text expression or an TempoText, get the default number.

>>> mm = tempo.MetronomeMark()
>>> mm._getDefaultNumber('schnell')
132
>>> mm._getDefaultNumber('adagio')
56
>>> mm._getDefaultNumber('Largo e piano')
46
Nr   )r\   r[   r{   r   r   split)rb   	tempoTexttempoStrpostwordkeys         rH   r   MetronomeMark._getDefaultNumber  s     i++ ~~H H>>11%hnn&67D++%h/D< s+-Cjjl*1#6 . , rJ   c                (   [         R                  " U5      (       a  UnO[        U5      n/ n[        R	                  5        H  u  pVUR                  Xe/5        M     UR                  5         SnU H  u  peXb-
  Us=::  a
  Xb-   ::  d  M  O  M  Un  U$    U$ )a8  
Given a tempo number try to get a text expression;
presently only looks for approximate matches

The `spread` value is a +/- shift around the default tempo
indications defined in defaultTempoValues


>>> mm = tempo.MetronomeMark()
>>> mm._getDefaultText(92)
'moderate'
>>> mm._getDefaultText(208)
'prestissimo'
N)r   r   rA   r   itemsappendsort)rb   r   spreadtempoNumbermatchesr  
tempoValuer  s           rH   r   MetronomeMark._getDefaultText  s     << K-K$6$<$<$> HNNJ12 %?$+ J#L
8KLL %,
 rJ   c                    U R                   c  gU R                  (       a  U R                  (       a+  U(       a#  U R                   R                  U R                  S9$ gg)a  
If there is a TextExpression available that is not implicit, return it;
otherwise, return None.

>>> mm = tempo.MetronomeMark('presto')
>>> mm.number
184
>>> mm.numberImplicit
True
>>> mm.getTextExpression()
<music21.expressions.TextExpression 'presto'>
>>> mm.textImplicit
False

>>> mm = tempo.MetronomeMark(number=90)
>>> mm.numberImplicit
False
>>> mm.textImplicit
True
>>> mm.getTextExpression() is None
True
>>> mm.getTextExpression(returnImplicit=True)
<music21.expressions.TextExpression 'maestoso'>
N)r   )r   r   r   r   )rb   returnImplicits     rH   r   MetronomeMark.getTextExpression  sR    2 ??"  T%6%6>??44#22 5 4 4 <J%6rJ   c                   [         R                  " U5      (       a  UnOD[        U[        5      (       a#  [        R
                  " U5      nUR                  nOUR                  nU R                  b,  [        U R                  U R                  R                  U5      nOSn[        U R                  U[        R
                  " U5      S9$ )a)  
Return a new MetronomeMark object that has an equivalent speed but
different number and referent values based on a supplied referent
(given as a Duration type, quarterLength, or Duration object).


>>> mm1 = tempo.MetronomeMark(number=60, referent=1.0)
>>> mm1.getEquivalentByReferent(0.5)
<music21.tempo.MetronomeMark larghetto Eighth=120>
>>> mm1.getEquivalentByReferent(duration.Duration('half'))
<music21.tempo.MetronomeMark larghetto Half=30>

>>> mm1.getEquivalentByReferent('longa')
<music21.tempo.MetronomeMark larghetto Imperfect Longa=3.75>

Nr{   r   r   )r   r   r\   rz   r   r   r   r   rI   r   r_   r{   )rb   r   r   d	newNumbers        rH   getEquivalentByReferent%MetronomeMark.getEquivalentByReferent  s    " <<!!$M#&&!!(+AOOM$22M;;".t{{/3}}/J/J/<>I I$))I&.&7&7&FH 	HrJ   c                @    [        U R                  U R                  US9$ )zU
Return a new MetronomeMark object that has an equivalent number but a new referent.
r  )r_   r{   r   )rb   r   s     rH   getMaintainedNumberWithReferent-MetronomeMark.getMaintainedNumberWithReferent  s      $))DKK&.0 	0rJ   c                d    U R                  5       nUb  SU R                  5       -  $ [        S5      e)az  
Return the duration in seconds for each quarter length
(not necessarily the referent) of this MetronomeMark.

>>> mm1 = tempo.MetronomeMark(referent=1.0, number=60.0)
>>> mm1.secondsPerQuarter()
1.0
>>> mm1 = tempo.MetronomeMark(referent=2.0, number=60.0)
>>> mm1.secondsPerQuarter()
0.5
>>> mm1 = tempo.MetronomeMark(referent=2.0, number=30.0)
>>> mm1.secondsPerQuarter()
1.0
      N@z5cannot derive seconds as getQuarterBPM() returns None)r   r   )rb   qbpms     rH   secondsPerQuarterMetronomeMark.secondsPerQuarter   s8     !!#$,,...()`aarJ   c                |    [         R                  " U5      (       a  UnOUR                  nU R                  5       U-  $ )aK  
Given a duration specified as a :class:`~music21.duration.Duration` object or a
quarter length, return the resultant time in seconds at the tempo specified by
this MetronomeMark.

>>> mm1 = tempo.MetronomeMark(referent=1.0, number=60.0)
>>> mm1.durationToSeconds(60)
60.0
>>> mm1.durationToSeconds(duration.Duration('16th'))
0.25
)r   r   r   r#  )rb   durationOrQuarterLengthqls      rH   durationToSecondsMetronomeMark.durationToSeconds5  s8     <</00(B(66B%%'",,rJ   c                    [         R                  " U5      (       a  US::  a  [        S5      eXR                  5       -  n[        R
                  " US9$ )aK  
Given a duration in seconds,
return a :class:`~music21.duration.Duration` object equal to that time.

>>> mm1 = tempo.MetronomeMark(referent=1.0, number=60.0)
>>> mm1.secondsToDuration(0.25)
<music21.duration.Duration 0.25>
>>> mm1.secondsToDuration(0.5).type
'eighth'
>>> mm1.secondsToDuration(1)
<music21.duration.Duration 1.0>
g        z*seconds must be a number greater than zeror   )r   r   r   r#  r   r   )rb   secondsr'  s      rH   secondsToDurationMetronomeMark.secondsToDurationH  sG     ||G$$3()UVV--//  r22rJ   )r   r   r   r   r   r   r   r   r   r   r{   r   )NNN)r{   zstr | int | Noner   OffsetQLIn | Noner   z@OffsetQLIn | str | duration.Duration | base.Music21Object | Noner   boolr   r0  r   r/  r   zbool | NonereturnNoneT)r1  int | float | None)r   r4  )r1  zfloat | None)   r   )$rP   rQ   rR   rS   rp   r   __annotations__rx   r   r   r   r   r   r   r   r   r   r{   r   r   r   r   r   r   r   r  r   r   r   r  r  r#  r(  r-  rT   r   r   s   @rH   r_   r_   R  sj   7r 	 	!I~  ""&MQ	0. ""*.$(0.0.  0. K	0. 0. 0. (0. "0. 
0. 0.d	N
)+]" l 9 H$
)" Hh - D )-	) j* 3 F$%
 02D K N$2 (<B4D!HT0b*-&3 3rJ   r_   c                      \ rS rSrSrg)MetricModulationExceptioni\  rN   NrO   rN   rJ   rH   r8  r8  \  rU   rJ   r8  c                     ^  \ rS rSrSrU 4S jrS rS rS r\	" \\SS9r
S	 rS
 r\	" \\SS9rS rS r\	" \\SS9rS rS r\	" \\SS9r\	S 5       rS rSS jr  S   SS jjrSrU =r$ )r]   ia  a
  
A class for representing the relationship between two MetronomeMarks.
Generally this relationship is one of equality, where the number is maintained but
the referent that number is applied to each change.

The basic definition of a MetricModulation is given by supplying two MetronomeMarks,
one for the oldMetronome, the other for the newMetronome. High level properties,
oldReferent and newReferent, and convenience methods permit only setting the referent.

The `classicalStyle` attribute determines of the first MetronomeMark describes the
new tempo, not the old (the reverse of expected usage).

The `maintainBeat` attribute determines if, after an equality statement,
the beat is maintained. This is relevant for moving from 3/4 to 6/8, for example.

>>> s = stream.Stream()
>>> mm1 = tempo.MetronomeMark(number=60)
>>> s.append(mm1)
>>> s.repeatAppend(note.Note(quarterLength=1), 2)
>>> s.repeatAppend(note.Note(quarterLength=0.5), 4)

>>> mmod1 = tempo.MetricModulation()
>>> mmod1.oldReferent = 0.5  # can use Duration objects
>>> mmod1.newReferent = 'quarter'  # can use Duration objects
>>> s.append(mmod1)
>>> mmod1.updateByContext()  # get number from last MetronomeMark on Stream
>>> mmod1.newMetronome
<music21.tempo.MetronomeMark animato Quarter=120>

>>> s.append(note.Note())
>>> s.repeatAppend(note.Note(quarterLength=1.5), 2)

>>> mmod2 = tempo.MetricModulation()
>>> s.append(mmod2)  # if the obj is added to Stream, can set referents
>>> mmod2.oldReferent = 1.5  # will get number from previous MetronomeMark
>>> mmod2.newReferent = 'quarter'
>>> mmod2.newMetronome
<music21.tempo.MetronomeMark animato Quarter=80>

Note that an initial metric modulation can set old and new referents and get None as
tempo numbers:

>>> mmod3 = tempo.MetricModulation()
>>> mmod3.oldReferent = 'half'
>>> mmod3.newReferent = '16th'
>>> mmod3
<music21.tempo.MetricModulation
    <music21.tempo.MetronomeMark
        Half=None>=<music21.tempo.MetronomeMark 16th=None>>

test w/ more sane referents that either the old or the new can change without a tempo number

>>> mmod3.oldReferent = 'quarter'
>>> mmod3.newReferent = 'eighth'
>>> mmod3
<music21.tempo.MetricModulation
    <music21.tempo.MetronomeMark
        Quarter=None>=<music21.tempo.MetronomeMark Eighth=None>>
>>> mmod3.oldMetronome
<music21.tempo.MetronomeMark Quarter=None>
>>> mmod3.oldMetronome.number = 60

New number automatically updates:

>>> mmod3
<music21.tempo.MetricModulation
    <music21.tempo.MetronomeMark larghetto
        Quarter=60>=<music21.tempo.MetronomeMark larghetto Eighth=60>>
c                   > [         TU ]  " S0 UD6  SU l        SU l        SU l        S U l        SU l        S U l        S U l        g )NFr   rN   )	rw   rx   classicalStylemaintainBeattransitionSymbolarrowDirectionr   _oldMetronome_newMetronome)rb   r|   r}   s     rH   rx   MetricModulation.__init__  sO    $8$#! #" ! "!rJ   c                8    U R                    SU R                   3$ )Nr   )oldMetronomer^   r   s    rH   r   MetricModulation._reprInternal  s!    ##$Ad&7&7%899rJ   c                p    Uc  O,[        US5      (       a  SUR                  ;  a  [        S5      eXl        g )Nr`   r_   z?oldMetronome property must be set with a MetronomeMark instance)hasattrr`   r8  r?  r   s     rH   _setOldMetronome!MetricModulation._setOldMetronome  :    =	**oU]].R+QS S"rJ   c                    U R                   b'  U R                   R                  c  U R                  5         U R                   $ ro   )r?  r   updateByContextr   s    rH   _getOldMetronome!MetricModulation._getOldMetronome  s8    )!!((0$$&!!!rJ   a  
        Get or set the left :class:`~music21.tempo.MetronomeMark` object
        for the old, or previous value.

        >>> mm1 = tempo.MetronomeMark(number=60, referent=1)
        >>> mm1
        <music21.tempo.MetronomeMark larghetto Quarter=60>
        >>> mmod1 = tempo.MetricModulation()
        >>> mmod1.oldMetronome = mm1

        Note that we do need to have a proper MetronomeMark instance to figure this out:

        >>> mmod1.oldMetronome = 'junk'
        Traceback (most recent call last):
        music21.tempo.MetricModulationException: oldMetronome property
            must be set with a MetronomeMark instance
        r   c                    Uc  [        S5      eU R                  b  U R                  R                  U5      nO$U R                  5       nUb  UR                  U5      nUb  X l        g [	        US9U l        g )Nzcannot set old referent to Noner   )r8  r?  r  rm   r_   rb   r   r   s      rH   _setOldReferent MetricModulation._setOldReferent  st    =+,MNN)##;;EBB ..0B~//6>!# "/!>DrJ   c                J    U R                   b  U R                   R                  $ g ro   )r?  r   r   s    rH   _getOldReferent MetricModulation._getOldReferent  %    )%%... *rJ   a  
        Get or set the referent of the old MetronomeMark.

        >>> mm1 = tempo.MetronomeMark(number=60, referent=1)
        >>> mmod1 = tempo.MetricModulation()
        >>> mmod1.oldMetronome = mm1
        >>> mmod1.oldMetronome
        <music21.tempo.MetronomeMark larghetto Quarter=60>
        >>> mmod1.oldReferent = 0.25
        >>> mmod1.oldMetronome
        <music21.tempo.MetronomeMark larghetto 16th=240>

        c                p    Uc  O,[        US5      (       a  SUR                  ;  a  [        S5      eXl        g )Nr`   r_   z?newMetronome property must be set with a MetronomeMark instance)rF  r`   r8  r@  r   s     rH   _setNewMetronome!MetricModulation._setNewMetronome  rI  rJ   c                    U R                   b'  U R                   R                  c  U R                  5         U R                   $ ro   )r@  r   rK  r   s    rH   _getNewMetronome!MetricModulation._getNewMetronome
  s8    )!!((0$$&!!!rJ   a'  
        Get or set the right :class:`~music21.tempo.MetronomeMark`
        object for the new, or following value.

        >>> mm1 = tempo.MetronomeMark(number=60, referent=1)
        >>> mm1
        <music21.tempo.MetronomeMark larghetto Quarter=60>
        >>> mmod1 = tempo.MetricModulation()
        >>> mmod1.newMetronome = mm1
        >>> mmod1.newMetronome = 'junk'
        Traceback (most recent call last):
        music21.tempo.MetricModulationException: newMetronome property must be
            set with a MetronomeMark instance
        c                    Uc  [        S5      eS nU R                  b  U R                  R                  U5      nO2U R                  b  U R                  R	                  U5      nO	[        US9nX l        g )Nzcannot set new referent to NonerO  )r8  r@  r  r?  r  r_   rP  s      rH   _setNewReferent MetricModulation._setNewReferent   sn    =+,MNN)##;;EBB+##CCEJB .BrJ   c                J    U R                   b  U R                   R                  $ g ro   )r@  r   r   s    rH   _getNewReferent MetricModulation._getNewReferent1  rV  rJ   a  
        Get or set the referent of the new MetronomeMark.

        >>> mm1 = tempo.MetronomeMark(number=60, referent=1)
        >>> mmod1 = tempo.MetricModulation()
        >>> mmod1.newMetronome = mm1
        >>> mmod1.newMetronome
        <music21.tempo.MetronomeMark larghetto Quarter=60>
        >>> mmod1.newReferent = 0.25
        >>> mmod1.newMetronome
        <music21.tempo.MetronomeMark larghetto 16th=240>
        c                J    U R                   b  U R                   R                  $ g)a&  
Get and the number of the MetricModulation, or the number
assigned to the new MetronomeMark.

>>> s = stream.Stream()
>>> mm1 = tempo.MetronomeMark(number=60)
>>> s.append(mm1)
>>> s.repeatAppend(note.Note(quarterLength=1), 2)
>>> s.repeatAppend(note.Note(quarterLength=0.5), 4)

>>> mmod1 = tempo.MetricModulation()
>>> mmod1.oldReferent = 0.5  # can use Duration objects
>>> mmod1.newReferent = 'quarter'
>>> s.append(mmod1)
>>> mmod1.updateByContext()
>>> mmod1.newMetronome
<music21.tempo.MetronomeMark animato Quarter=120>
>>> mmod1.number
120
N)r@  r   r   s    rH   r   MetricModulation.numberB  s'    , )%%,,, *rJ   c                   U R                  5       nSnUbh  U R                  b=  U R                  R                  b&  UR                  U R                  R                  5      nO[	        UR                  UR
                  S9nUb  X l        U R                  bV  U R                  R                  b>  U R                  R
                  b&  U R                  R
                  U R                  l        gggg)z
Update this metric modulation based on the context,
or the surrounding MetronomeMarks or MetricModulations.
The object needs to reside in a Stream for this to be effective.
Nr   r   )rm   r?  r   r  r_   r   r@  )rb   mmLastmmOlds      rH   rK   MetricModulation.updateByContextc  s     ..0"".**33?66&&//1 &v-3]]<!&*&&//;&&--9(,(:(:(A(AD% : < +rJ   c                   Uc  U R                   c  SnOU R                  c  SnUS;  a  [        SU 35      eUS:X  a!  U R                   R                  U5      U l        gUS:X  a!  U R                  R                  U5      U l         gg)a  
Set the other side of the metric modulation to
an equality; side can be specified, or if one side
is None, that side will be set.

>>> mm1 = tempo.MetronomeMark(number=60, referent=1)
>>> mmod1 = tempo.MetricModulation()
>>> mmod1.newMetronome = mm1
>>> mmod1.setEqualityByReferent(None, 2)
>>> mmod1
<music21.tempo.MetricModulation
     <music21.tempo.MetronomeMark larghetto
           Half=30>=<music21.tempo.MetronomeMark larghetto Quarter=60>>

Nleftrightrk  rl  "cannot set equality for a side of )r?  r@  rL   r  rb   sider   s      rH   setEqualityByReferent&MetricModulation.setEqualityByReferent~  s      <!!)##+(( #EdV!LMM7?!%!3!3!K!K"DV^!%!3!3!K!K"D rJ   c                   Uc  U R                   c  SnOU R                  c  SnUS;  a  [        SU 35      eUS:X  a!  U R                   R                  U5      U l        gUS:X  a!  U R                  R                  U5      U l         gg)z
Set the other side of the metric modulation not based on equality,
but on a direct translation of the tempo value.

referent can be a string type or an int/float quarter length
Nrk  rl  rm  rn  )r?  r@  rL   r  ro  s      rH   setOtherByReferent#MetricModulation.setOtherByReferent  s     <!!)##+(( #EdV!LMM7?!%!3!3!S!ST\!]DV^!%!3!3!S!ST\!]D rJ   )r@  r?  r>  r;  r<  r   r=  )Nr   )rp  z
str | Noner   zstr | int | float)rP   rQ   rR   rS   rp   rx   r   rG  rL  r   rC  rQ  rT  oldReferentrX  r[  r^   r^  ra  newReferentr   rK  rq  rt  rT   r   r   s   @rH   r]   r]   a  s    DL" :
#" ,.> E L$?&/ ?O B K#" ,.> E L "/ ?O B K - -@B6B "%^^  ^ ^rJ   r]   c           	     b    U R                  U5      n U R                  U5      n UR                  U5      n UR                  U5      n	X-
  X-
  -  n
UR	                  UUS9nU HA  nUR                  U5      n UR                  U5        XU-
  -  U-   nUR                  X>5        MC     g! [        R                   a  n[        S5      UeSnAff = f! [        R                   a  n[        S5      UeSnAff = f! [        R                   a  n[        S5      UeSnAff = f! [        R                   a  n[        S5      UeSnAff = f! [        R                   aP  nUSL a"  XU-
  -  U-   nUR                  X5         SnAGM!  [        SU< S	UR                  < S
3-   S-   5      UeSnAff = f)a	  
Assume that element1 and element2 are two elements in sourceStream
and destinationStream with other elements (say eA, eB, eC) between
them.  For instance, element1 could be the downbeat at offset 10
in sourceStream (a Stream representing a score) and offset 20.5
in destinationStream (which might be a Stream representing the
timing of notes in particular recording at approximately but not
exactly qtr = 30). Element2 could be the following downbeat in 4/4,
at offset 14 in source but offset 25.0 in the recording:

>>> sourceStream = stream.Stream()
>>> destinationStream = stream.Stream()
>>> element1 = note.Note('C4', type='quarter')
>>> element2 = note.Note('G4', type='quarter')
>>> sourceStream.insert(10, element1)
>>> destinationStream.insert(20.5, element1)
>>> sourceStream.insert(14, element2)
>>> destinationStream.insert(25.0, element2)

Suppose eA, eB, and eC are three quarter notes that lie
between element1 and element2 in sourceStream
and destinationStream, as in:

>>> eA = note.Note('D4', type='quarter')
>>> eB = note.Note('E4', type='quarter')
>>> eC = note.Note('F4', type='quarter')
>>> sourceStream.insert(11, eA)
>>> sourceStream.insert(12, eB)
>>> sourceStream.insert(13, eC)
>>> destinationStream.append([eA, eB, eC])  # not needed if autoAdd were true

then running this function will cause eA, eB, and eC
to have offsets 21.625, 22.75, and 23.875 respectively
in destinationStream:

>>> tempo.interpolateElements(element1, element2,
...         sourceStream, destinationStream, autoAdd=False)
>>> for el in [eA, eB, eC]:
...    print(el.getOffsetBySite(destinationStream))
21.625
22.75
23.875

if the elements between element1 and element2 do not yet
appear in destinationStream, they are automatically added
unless autoAdd is False.

(with the default autoAdd, elements are automatically added to new streams):

>>> destStream2 = stream.Stream()
>>> destStream2.insert(10.1, element1)
>>> destStream2.insert(50.5, element2)
>>> tempo.interpolateElements(element1, element2, sourceStream, destStream2)
>>> for el in [eA, eB, eC]:
...    print('%.1f' % (el.getOffsetBySite(destStream2),))
20.2
30.3
40.4

(unless autoAdd is set to False, in which case a Tempo Exception arises:)

>>> destStream3 = stream.Stream()
>>> destStream3.insert(100, element1)
>>> destStream3.insert(500, element2)
>>> eA.id = 'blah'
>>> tempo.interpolateElements(element1, element2, sourceStream, destStream3, autoAdd=False)
Traceback (most recent call last):
music21.tempo.TempoException: Could not find element <music21.note.Note D> with id ...
z'could not find element1 in sourceStreamNz,could not find element1 in destinationStreamz'could not find element2 in sourceStreamz,could not find element2 in destinationStream)offsetStart	offsetEndTzCould not find element z	 with id r   z)in destinationStream and autoAdd is false)
getOffsetBySiter   Music21ExceptionrL   getElementsByOffsetsetOffsetBySiter   SitesExceptioninsertid)element1element2sourceStreamdestinationStreamautoAddstartOffsetSrcestartOffsetDestendOffsetSrcendOffsetDestscaleAmountinterpolatedElementselelOffsetSrcdestinationOffsets                  rH   interpolateElementsr    s   PO!11,?T"223DEO//=T 001BC "38UVK';;" <  #((6	E01 "-n0L!MQ` `0D #- (( OFGQNO (( TKLRSST
 (( OFGQNO (( TKLRSST "" 	J$%0.4P%QUd$d!!(():??$-iy23ABC IJJ	Jsz   B* C C: D" 9E
*C>C

CC7&C22C7:DDD"E6EE
F. F)$F))F.c                      \ rS rSrSrSrg)TempoChangeSpanneri)  z<
Spanners showing tempo-change.  They do nothing right now.
rN   NrP   rQ   rR   rS   rp   rT   rN   rJ   rH   r  r  )       	rJ   r  c                      \ rS rSrSrSrg)RitardandoSpanneri0  z&
Spanner representing a slowing down.
rN   Nr  rN   rJ   rH   r  r  0  r  rJ   r  c                      \ rS rSrSrSrg)AccelerandoSpanneri7  z%
Spanner representing a speeding up.
rN   Nr  rN   rJ   rH   r  r  7  r  rJ   r  c                  z    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)Testi?  c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr  globals)rb   r  s     rH   testCopyAndDeepcopyTest.testCopyAndDeepcopy@  s    7D')$rJ   c                    [        S[        R                  " SS9S9nU R                  UR                  S5        [        S5      nU R                  UR                  S5        g )Nr   r   r   r   r   Lebhaft)r_   r
   NoteassertEqualr   r[   r{   )rb   mm1tm1s      rH   	testSetupTest.testSetupD  sI    2		y0IJR(	"9-rJ   c                   [        5         [        S5        [        S5      nU R                  UR                  S5        U R	                  UR
                  5        U R                  UR                  S5        [        S5      nU R                  UR                  S5        UR                  5       nU R                  UR                  S5        g )Nr   r   r;   r0   )r[   r_   r  r   
assertTruer   r{   ra   )rb   r   tm2s      rH   testUnicodeTest.testUnicodeK  s    ( 8$B'))*B'%<0!!#C(rJ   c                	   SSK Jn  UR                  S5      nU R                  UR                  R
                  S5        U R                  UR                  R                  S5        SUR                  l        U R                  UR                  R
                  S5        SUR                  l        S UR                  l        UR                  nU R                  US5        UR                  5       nU R                  UR                  S5        U R                  UR                  R
                  S5        U R                  UR                  R                  S5        [        R                  " S5      nS	UR                  l        S
UR                  l        U R                  UR                  R
                  S	5        U R                  UR                  R                  S
5        UR                  U5        U R                  UR                  R
                  S	5        U R                  UR                  R                  S
5        U R                  UR                  UR                  5        UR                  5         UR                  nU R                  US5        U R                  UR                  R
                  S	5        U R                  UR                  R                  S
5        [        R                  " S5      nU R                  UR                   5        U R#                  UR                   5        UR                  U5        U R                  UR                  R
                  S	5        U R                  UR                  R                  S
5        U R                  UR                  UR                  5        UR                  5         UR                  nU R                  US5        U R                  UR                  R
                  S	5        U R                  UR                  R                  S
5        S Ul        [        R                  " S5      nU R                  UR                   5        U R                  UR                   5        UR                  U5        U R                  UR                  R
                  S5        U R                  UR                  R                  S5        U R                  UR                  UR                  5        g )Nr   r   r   r   r   !   italicr!   &   
bolditaliczandante with no style)music21r   r[   r  r   r   r   
fontWeightr{   r   r   r	   r   r   assertIsassertFalser   r  )rb   r   tmtxte1te2te3te4s           rH   testTempoTextStyleTest.testTempoTextStyle]  s   !__X&++R0++V4++R0%" WWX&""$h/++R0++X6 ((3 		*		,,b1,,l;
S!++R0++\:bhh		* 	WWY'++R0++\: (()@A001../
S!++R0++\:bhh		* 	WW45++R0++\: (()@A001//0
S!++R0++V4bhh		*rJ   c                |   SSK Jn  UR                  5       nSUl        U R	                  UR
                  S5        U R                  UR                  5        SUl        U R	                  UR
                  S5        U R                  UR                  5        U R	                  UR                  R                  S5        UR                  5       nSUl        [        R                  " S5      Ul	        U R	                  UR
                  S5        U R	                  UR                  S	5        U R                  UR                  5        S
Ul        U R	                  UR                  S
5        U R                  UR                  5        U R	                  UR                  R                  S5        U R	                  [        U5      S5        g )Nr   r  r   r   slowishr   r>   g      @r3      z4<music21.tempo.MetronomeMark presto Dotted Half=200>)r  r   r_   r   r  r{   r  r   r  r   r   r   r   r   r   )rb   r   r   s      rH   testMetronomeMarkATest.testMetronomeMarkA  sF   !  "	(+(),)22C8   "'',(+C())*	C(**+22C8b#YZrJ   c                h   [        5       nU R                  UR                  S 5        U R                  UR                  S 5        [        SS9nU R                  UR                  S5        U R                  UR                  5        U R                  UR                  S 5        U R                  UR                  S 5        [        SSS9nU R                  UR                  S5        U R                  UR                  5        U R                  UR                  S5        U R                  UR                  5        g )Nd   r   e   rapido)r   r{   )r_   r  r   r   r   r  r{   r   s     rH   testMetronomeMarkBTest.testMetronomeMarkB  s    _**D1$/#&C(**+$'$/#H5C(**+(+)rJ   c                   SSK Jn  UR                  SSS9nUR                  SS9nUR                  5       nX$l        X4l        U R                  [        U5      S5        UR                  SSS9nUR                  5       nX$l        UR                  SS9  U R                  [        U5      S5        U R                  UR                  R                  5       S	5        U R                  UR
                  R                  5       S
5        g )Nr   r        ?r,   rf  16thrO  z<music21.tempo.MetricModulation <music21.tempo.MetronomeMark animato Eighth=120>=<music21.tempo.MetronomeMark animato 16th=120>>r!  g      >@)
r  r   r_   r]   rC  r^   r  rz   rt  r   )rb   r   r  mm2mmod1s        rH   testMetronomeModulationATest.testMetronomeModulationA  s    ! !!3s!;!!6!2&&(   	UM	N !!3s!;&&(   & 1UM	N
 	++99;TB++99;TBrJ   c                   SSK Jn  SSK Jn  UR                  5       nUR	                  5       nUR                  [        R                  " SS9S5        [        R                  " U5      nUR                  SSS	9nUR                  SU5        UR                  S
SS	9nUR                  SU5        UR                  XE/5        U R                  [        UR                  5       5      S5        g )Nr   r  streamrY   r+     r         ?r     r  z,<music21.tempo.MetronomeMark adagio 16th=56>)r  r   r  PartMeasurerepeatAppendr
   r  r   r   r_   r  r  r  rz   rm   rb   r   r  pm1m2r  r  s           rH   testGetPreviousMetronomeMarkA"Test.testGetPreviousMetronomeMarkA  s    !" KKM^^
		2A6]]2!!d!;
		!S!!s!;
		!S	"S99;<G	IrJ   c                   SSK Jn  SSK Jn  UR                  5       nUR	                  5       nUR                  [        R                  " SS9S5        [        R                  " U5      nUR                  S5      nUR                  SU5        UR                  SS	S
9nUR                  SU5        UR                  XE/5        U R                  [        UR!                  5       5      S5        g )Nr   r  r  rY   r+  r  r   r  r  r  z-<music21.tempo.MetronomeMark slow Quarter=56>)r  r   r  r  r  r  r
   r  r   r   r[   r  r_   r  r  rz   rm   r  s           rH   testGetPreviousMetronomeMarkB"Test.testGetPreviousMetronomeMarkB  s    !" KKM^^
		2A6]]2oof%
		!S!!s!;
		!S	"S99;<H	JrJ   c                   SSK Jn  SSK Jn  UR                  5       nUR	                  5       nUR                  [        R                  " SS9S5        [        R                  " U5      n[        R                  " U5      nUR                  S5      nUR                  SU5        UR                  5       nUR                  SSS	9Ul        UR                  S
S9  UR                  SU5        UR                  SSS9n	UR                  SU	5        UR                  XEU/5        U R!                  [#        U	R%                  5       5      S5        g )Nr   r  r  rY   r+  r  r   r   rf  r  rO  r  r  r  z+<music21.tempo.MetronomeMark lento 16th=52>)r  r   r  r  r  r  r
   r  r   r   r_   r  r]   rC  rt  r  r  rz   rm   )
rb   r   r  r  r  r  m3r  r  mm3s
             rH   testGetPreviousMetronomeMarkC"Test.testGetPreviousMetronomeMarkC  s   !" KKM^^
		2A6]]2]]2!!&)
		!S$$& ..".E/
		!S!!s!;
		!S	"" 	S99;<F	HrJ   c                h   SSK Jn  SSK Jn  UR                  5       nUR	                  5       nUR                  [        R                  " SS9S5        [        R                  " U5      n[        R                  " U5      nUR                  SS9nUR                  SU5        UR                  5       nUR                  SU5        UR                  XEU/5        S	Ul        U R                  [!        UR"                  5      S
5        UR%                  SS9  U R                  [!        UR&                  5      S5        g)z7
Test setting referents directly via context searches.
r   r  r  rY   r+  r  r)   r  r  z/<music21.tempo.MetronomeMark moderate 16th=368>r5  rO  z/<music21.tempo.MetronomeMark moderate Half=368>N)r  r  r   r  r  r  r
   r  r   r   r_   r  r]   r  rv  r  rz   rC  rt  r^   )	rb   r  r   r  r  r  r  r  r  s	            rH   testSetReferentATest.testSetReferentA+  s     	#!KKM^^
		2A6]]2]]2!!!,
		!S$$&
		!S	""S--.J	L*S--.J	LrJ   c                    SSK Jn  SSK Jn  UR                  5       nUR	                  SS9nUR                  U5        UR                  [        R                  " SS9S5        UR                  [        R                  " S	S9S
5        UR                  5       nS	Ul
        SUl        UR                  U5        UR                  5         U R                  [        UR                  R                   5      S5        U R                  UR                  R"                  S5        U R                  [        UR$                  5      S5        UR                  [        R                  " 5       5        UR                  [        R                  " SS9S5        UR                  5       nSUl
        SUl        UR                  U5        UR                  5         U R                  [        UR                  5      S5        U R                  [        UR$                  5      S5        g )Nr   r  r  r   r  rY   r+  r5  r  r  r   <music21.duration.Duration 0.5>r,   z1<music21.tempo.MetronomeMark animato Quarter=120>      ?z7<music21.tempo.MetronomeMark animato Dotted Quarter=80>z2<music21.tempo.MetronomeMark andantino Quarter=80>)r  r   r  Streamr_   r  r  r
   r  r]   rv  rw  rK  r  rz   rC  r   r   r^   rb   r   r  r   r  r  mmod2s          rH   testSetReferentBTest.testSetReferentBG  s   !"MMO!!!,		tyyq115	tyys3Q7&&(%	U//889;\]++22C8U//0L	N 	
	tyys3Q7&&(%	U//0R	TU//0M	OrJ   c                   SSK Jn  SSK Jn  UR                  5       nUR	                  SS9nUR                  U5        UR                  [        R                  " SS9S5        UR                  [        R                  " S	S9S
5        UR                  5       nUR                  U5        S	Ul
        SUl        U R                  [        UR                  R                  5      S5        U R                  UR                  R                   S5        U R                  [        UR"                  5      S5        UR                  [        R                  " 5       5        UR                  [        R                  " SS9S5        UR                  5       nUR                  U5        SUl
        SUl        U R                  [        UR                  5      S5        U R                  [        UR"                  5      S5        g )Nr   r  r  r   r  rY   r+  r5  r  r  r   r  r,   z3<music21.tempo.MetronomeMark larghetto Quarter=120>r  z9<music21.tempo.MetronomeMark larghetto Dotted Quarter=80>z2<music21.tempo.MetronomeMark larghetto Quarter=80>)r  r   r  r  r_   r  r  r
   r  r]   rv  rw  r  rz   rC  r   r   r^   r  s          rH   testSetReferentCTest.testSetReferentCk  sw   !"MMO!!!,		tyyq115	tyys3Q7&&(	%U//889;\]++22C8U//0N	P 	
	tyys3Q7&&(	%U//0T	VU//0M	OrJ   c                   SSK Jn  SSK Jn  UR                  5       nUR	                  SS9nUR                  U5        UR                  [        R                  " SS9S5        UR                  [        R                  " S	S9S
5        UR                  5       nUR                  U5        UR                  5         U R                  [        UR                  R                  5      S5        U R                  UR                  R                  S5        U R                  UR                   S 5        SUl        U R                  [        UR                   5      S5        g )Nr   r  r  r   r  rY   r+  r5  r  r  z<music21.duration.Duration 1.0>r  z/<music21.tempo.MetronomeMark larghetto 16th=60>)r  r   r  r  r_   r  r  r
   r  r]   rK  r  rz   rC  r   r   r^   rw  )rb   r   r  r   r  r  s         rH   testSetReferentDTest.testSetReferentD  s    !"MMO!!!,		tyyq115	tyys3Q7&&(	U//889;\]++22B7++T2 U//02cdrJ   c                   SSK Jn  UR                  5       n[        SS9nUR	                  U5        UR                  [        R                  " SS9S5        UR                  [        R                  " SS9S	5        [        5       nS
Ul	        SUl
        UR	                  U5        U R                  UR                  R                  S5        U R                  UR                  R                  S5        UR                  5       n[        SS9nUR	                  U5        UR                  [        R                  " SS9S5        UR                  [        R                  " SS9S	5        [        5       nS
Ul	        SUl
        UR	                  U5        U R                  UR                  R                  S5        U R                  UR                  R                  S5        U R                  UR                  S5        g )Nr   r  F   r  rY   r+  r5  r  r  eighthhalfr/   )r  r  r  r_   r  r  r
   r  r]   rv  rw  r  rC  r   r^   )rb   r  r   r  r  s        rH   testSetReferentETest.testSetReferentE  sm   "MMO2&		tyyq115	tyys3Q7 "$"	++22C8++22C8MMO2&		tyyq115	tyys3Q7 !"$"	++22C8++22C8s+rJ   c                   [        SSS9nU R                  UR                  5       S5        U R                  UR                  S5      S5        U R                  UR	                  S5      R
                  S5        [        SSS9nU R                  UR                  5       S5        U R                  UR                  S5      S5        U R                  UR	                  S5      R
                  S5        [        SSS9nU R                  UR                  5       S	5        U R                  UR                  S
5      S5        U R                  UR	                  S5      R
                  S5        [        SSS9nU R                  UR                  5       S5        U R                  UR                  S5      S5        U R                  UR	                  S5      R
                  S5        g )Nr   g      ^@rf  r  r,   r!  r   g       @r     g      n@r  gUUUUUU?   g     f@)r_   r  r#  r(  r-  r   assertAlmostEqualr   s     rH   testSecondsPerQuarterATest.testSecondsPerQuarterA  s   C6--/5--c2D9--d3AA5IC6--/5--b148--d3AA4HC6--/6--c2D9--d3AA5IC6r335u=--c2D9--d3AA5IrJ   c                <   [         R                  " SS9n[        SSU5      nSUR                  l        U R                  UR                  R                  UR                  5        U R                  UR                  R                  R                  UR                  5        g )Nr   r   r   r   rk  )r
   r  r_   r   justifyr  r   ry   )rb   halfNoter   s      rH   testStylesAreSharedTest.testStylesAreShared  sh    99&)62x0!bmm))2884bmm3399288DrJ   rN   N)rP   rQ   rR   rS   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rT   rN   rJ   rH   r  r  ?  sf    %.)$?+B[4*&C@I$J$H8L8OHODe0,>J*ErJ   r  __main__)r   )rB   int | floatrC   r  r1  rA   r3  )+rp   
__future__r   r   typingtunittestr  r   r   r   r   r   r	   r
   r   r   TYPE_CHECKINGmusic21.common.typesr   EnvironmentenvironLocalr   rI   r|  rL   r   rW   r[   r   r_   r8  r]   r  Spannerr  r  r  TestCaser  
_DOC_ORDERrP   mainTestrN   rJ   rH   <module>r     sl   #             ??/ &&w/2" R B	
 R R b B r   r     !" #$ = J 0%0%#0% 	0%h	\22 	
12d(( 12jQ Qj	^ 	F3O F3T	 	
Q^ Q^l
 48oEf	 		* 		+ 	_E8 _EH Y(8/ "35G!#

 zT rJ   