
    rh9                   0   % S r SSKJr  SSKJr  SSKrSSKrSSKJ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Jr  SSKJr  SSKJrJr  SSKJr  \R@                  " S5      r!\
RD                  (       a  SSK#J$r$  SSKJ%r%  \" 5       r&Sr'0 r(S\)S'   Sr*S#S jr+ " S S\RX                  5      r- " S S\-5      r. " S S\-5      r/ " S  S!\R`                  5      r1\./r2\3S":X  a  SSKr\Rh                  " 5         gg)$z
This module defines the :class:`~music21.meter.TimeSignature` object,
as well as component objects for defining nested metrical structures,
:class:`~music21.meter.MeterTerminal` and :class:`~music21.meter.MeterSequence` objects.
    )annotations)SequenceN)gcd)base)beam)common)MeterDivision)opFrac)defaults)duration)environment)MeterExceptionTimeSignatureException)style)slashToTupleproportionToFraction)MeterSequencemeter)OffsetQLstream128thz+dict[tuple[str, t.Any, int], MeterSequence]_meterSequenceAccentArchetypes) r   c                   SnSn[        U R                  R                  5      nSnSnU R                  5       R                   H}  nUR                  S:X  a  M  UR                  U:  d  M'  [        [        UR                  5      [        R                  5      (       a  M[  UR                  nUR                  R                  nM     Un[        U[        R                  5      (       a  UR                  nUR                  nGOSnUS:  ad  [        X7-  5      n	[        X7-  5      n
X:X  d  U[        R                  [           ::  a  O)US[        R                  " U5      -  -  nUS-  nUS:  a  Md  Sn[        R                  [           nSnUS:  a\  X|:  a  UnOT [        R                   " U5      u  pU(       d
  U[        :X  a  O)US[        R                  " U5      -  -  nUS-  nUS:  a  M\  Un[        R                   " U5      u  pU(       d  [%        S	U 35      e['        U5      n[        R(                  R+                  5        H  u  nnUU:X  d  M  Un  O   SnUS:  a*  UU-  U-  nU[        U5      :X  a  OUS-  nUS-  nUS:  a  M*  [        U5      nUU-  n[        U5      n[-        XE5      nUU-  nUU-  nXE:X  a  US
;  a  SnSnO+XE:w  a  US:X  a  US-  nUS-  nOXE:w  a  US:X  a
  US-  nUS-  nUS:X  aH  US:X  aB  [/        S5      n[/        S5      nUR1                  U 5      nUR1                  U 5      nUU::  a  U$ U$ US:X  ay  US:X  as  [/        S5      n[/        S5      n[/        S5      nUR1                  U 5      nUR1                  U 5      nUR1                  U 5      n[3        UUU5      nUU:X  a  U$ UU:X  a  U$ U$ [/        5       nUR5                  U SU 35        U$ ! ["         a    [%        S5      ef = f)a"  
Given a Measure (or any Stream) with elements in it, get a TimeSignature that contains all
elements.

Note: this does not yet accommodate triplets.

>>> s = converter.parse('tinynotation: C4 D4 E8 F8').flatten().notes
>>> m = stream.Measure()
>>> for el in s:
...     m.insert(el.offset, el)
>>> ts = meter.bestTimeSignature(m)
>>> ts
<music21.meter.TimeSignature 3/4>

>>> s2 = converter.parse('tinynotation: C8. D16 E8 F8. G16 A8').flatten().notes
>>> m2 = stream.Measure()
>>> for el in s2:
...     m2.insert(el.offset, el)
>>> ts2 = meter.bestTimeSignature(m2)
>>> ts2
<music21.meter.TimeSignature 6/8>

>>> s3 = converter.parse('C2 D2 E2', format='tinyNotation').flatten().notes
>>> m3 = stream.Measure()
>>> for el in s3:
...     m3.insert(el.offset, el)
>>> ts3 = meter.bestTimeSignature(m3)
>>> ts3
<music21.meter.TimeSignature 3/2>

>>> s4 = converter.parse('C8. D16 E8 F8. G16 A8 C4. D4.', format='tinyNotation').flatten().notes
>>> m4 = stream.Measure()
>>> for el in s4:
...     m4.insert(el.offset, el)
>>> ts4 = meter.bestTimeSignature(m4)
>>> ts4
<music21.meter.TimeSignature 12/8>

>>> s5 = converter.parse('C4 D2 E4 F2', format='tinyNotation').flatten().notes
>>> m5 = stream.Measure()
>>> for el in s5:
...     m5.insert(el.offset, el)
>>> ts5 = meter.bestTimeSignature(m5)
>>> ts5
<music21.meter.TimeSignature 6/4>

>>> s6 = converter.parse('C4 D16.', format='tinyNotation').flatten().notes
>>> m6 = stream.Measure()
>>> for el in s6:
...     m6.insert(el.offset, el)
>>> ts6 = meter.bestTimeSignature(m6)
>>> ts6
<music21.meter.TimeSignature 11/32>

Complex durations (arose in han2.abc, number 445)

>>> m7 = stream.Measure()
>>> m7.append(note.Note('D', quarterLength=3.5))
>>> m7.append(note.Note('E', quarterLength=5.5))
>>> ts7 = meter.bestTimeSignature(m7)
>>> ts7
<music21.meter.TimeSignature 9/4>
      @r              
      Fz)Cannot find a good match for this measurez#cannot find a type for denominator )r!      r"      z3/4z6/8   z6/4z12/8z3/2/)r
   r   quarterLengthrecursenotesAndRests
isinstance	fractionsFractiondots	numeratordenominatorinttypeToDurationMIN_DENOMINATOR_TYPEr   dotMultiplierquarterLengthToClosestTypeZeroDivisionErrorr   floattypeFromNumDictitemsr   TimeSignatureaverageBeatStrengthmaxload)measminDurQL
minDurDotssumDurQLr-   r.   e
minDurTesti
partsFloor	partsRealmatchdurationMinLimitdTypefloatDenominatornumtypeName
multipliergcdValuets1ts2str1str2ts3str3mtss                              L/home/james-whalen/.local/lib/python3.13/site-packages/music21/meter/base.pybestTimeSignaturerV   <   s(   D H Jdmm112H IK\\^))??c!OOh&"6!//#:I<N<NOOHJ * J(I..//&&	**!eX23Jx45I'!X%<%<=Q%RR (1v/C/CJ/O+OP
FA !e #223GH!e,-
R'BB:N !55#q6+?+?
+K'KLJFA !e ::8D #Fxj!QRR !-%55;;=MC5 #&  >
 
!e"X-8IC	N*!OJFA !e 	N	J&*+y.)	!X- IV$;			!kQ&6Q	q		!kQ&6Q	q A~+*E"E"&&t,&&t,4<JJ 
aK1,E"F#E"&&t,&&t,&&t,dD!9J$YJJ _
9+Q{m,-	_ % R$%PQQRs   O O5c                      \ rS rSrSrSrg)TimeSignatureBasei  zN
A base class for TimeSignature and SenzaMisuraTimeSignature to
inherit from.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__rY       rU   rX   rX     s     	r`   rX   c                  f  ^  \ rS rSr% Sr\R                  rSrSr	SSSSS	S
S.r
S\S'   S=S>U 4S jjjrS rS=S>S jjrS?S>S jjr\S 5       r\R$                  S 5       rS r\S 5       r\R$                  S 5       r\S 5       r\R$                  S 5       r\S@S j5       r\R$                  SAS j5       r\SBS j5       r\SBS j5       r\SCS j5       r\R$                  SDS j5       r\SES j5       r\S@S  j5       r\SCS! j5       r\SES" j5       r\SFS# j5       r\SFS$ j5       r\SES% j5       r \SGS& j5       r!\!R$                  SHS' j5       r!S(S).SIS* jjr"SIS+ jr#SJSKS, jjr$ SL     SMS- jjr%S?SIS. jjr&SNS/ jr' SO     SPS0 jjr(SQS1 jr)S2 r*  SRS3 jr+S4 r,S5 r-S6 r.S7 r/S8 r0S9 r1S: r2SSS; jr3S<r4U =r5$ )Tr8   i  a  
The `TimeSignature` object represents time signatures in musical scores
(4/4, 3/8, 2/4+5/16, Cut, etc.).

`TimeSignatures` should be present in the first `Measure` of each `Part`
that they apply to.  Alternatively you can put the time signature at the
front of a `Part` or at the beginning of a `Score`, and they will work
within music21, but they won't necessarily display properly in MusicXML,
Lilypond, etc.  So best is to create structures where the TimeSignature
goes in the first Measure of the score, as below:

>>> s = stream.Score()
>>> p = stream.Part()
>>> m1 = stream.Measure()
>>> ts = meter.TimeSignature('3/4')
>>> m1.insert(0, ts)
>>> m1.insert(0, note.Note('C#3', type='half'))
>>> n = note.Note('D3', type='quarter')
>>> m1.insert(1.0, n)
>>> m1.number = 1
>>> p.insert(0, m1)
>>> s.insert(0, p)
>>> s.show('t')
{0.0} <music21.stream.Part ...>
    {0.0} <music21.stream.Measure 1 offset=0.0>
        {0.0} <music21.meter.TimeSignature 3/4>
        {0.0} <music21.note.Note C#>
        {1.0} <music21.note.Note D>

Basic operations on a TimeSignature object are designed to be very simple.

>>> ts.ratioString
'3/4'

>>> ts.numerator
3

>>> ts.beatCount
3

>>> ts.beatCountName
'Triple'

>>> ts.beatDuration.quarterLength
1.0

As an alternative to putting a `TimeSignature` in a Stream at a specific
position (offset), it can be assigned to a special property in Measure that
positions the TimeSignature at the start of a Measure.  Notice that when we
`show()` the Measure (or if we iterate through it), the TimeSignature
appears as if it's in the measure itself:

>>> m2 = stream.Measure()
>>> m2.number = 2
>>> ts2 = meter.TimeSignature('2/4')
>>> m2.timeSignature = ts2
>>> m2.append(note.Note('E3', type='half'))
>>> p.append(m2)
>>> s.show('text')
{0.0} <music21.stream.Part ...>
    {0.0} <music21.stream.Measure 1 offset=0.0>
        {0.0} <music21.meter.TimeSignature 3/4>
        {0.0} <music21.note.Note C#>
        {1.0} <music21.note.Note D>
    {2.0} <music21.stream.Measure 2 offset=2.0>
        {0.0} <music21.meter.TimeSignature 2/4>
        {0.0} <music21.note.Note E>

Once a Note has a local TimeSignature, a Note can get its beat position and
other meter-specific parameters.  Remember `n`, our quarter note at offset
2.0 of `m1`, a 3/4 measure? Let's get its beat:

>>> n.beat
2.0

This feature is more useful if there are more beats:

>>> m3 = stream.Measure()
>>> m3.timeSignature = meter.TimeSignature('3/4')
>>> eighth = note.Note(type='eighth')
>>> m3.repeatAppend(eighth, 6)
>>> [thisNote.beatStr for thisNote in m3.notes]
['1', '1 1/2', '2', '2 1/2', '3', '3 1/2']

Now lets change its measure's TimeSignature and see what happens:

>>> sixEight = meter.TimeSignature('6/8')
>>> m3.timeSignature = sixEight
>>> [thisNote.beatStr for thisNote in m3.notes]
['1', '1 1/3', '1 2/3', '2', '2 1/3', '2 2/3']

TimeSignature('6/8') defaults to fast 6/8:

>>> sixEight.beatCount
2

>>> sixEight.beatDuration.quarterLength
1.5

>>> sixEight.beatDivisionCountName
'Compound'

Let's make it slow 6/8 instead:

>>> sixEight.beatCount = 6
>>> sixEight.beatDuration.quarterLength
0.5

>>> sixEight.beatDivisionCountName
'Simple'

Now let's look at the `beatStr` for each of the notes in `m3`:

>>> [thisNote.beatStr for thisNote in m3.notes]
['1', '2', '3', '4', '5', '6']

As of v7, 3/8 also defaults to fast 3/8, that is, one beat:

>>> meter.TimeSignature('3/8').beatCount
1

`TimeSignatures` can also use symbols instead of numbers

>>> tsCommon = meter.TimeSignature('c')  # or common
>>> tsCommon.beatCount
4
>>> tsCommon.denominator
4

>>> tsCommon.symbol
'common'

>>> tsCut = meter.TimeSignature('cut')
>>> tsCut.beatCount
2
>>> tsCut.denominator
2

>>> tsCut.symbol
'cut'

For other time signatures, the symbol is '' (not set) or 'normal'

>>> sixEight.symbol
''


For complete details on using this object, see
:ref:`User's Guide Chapter 14: Time Signatures <usersGuide_14_timeSignatures>` and
:ref:`User's Guide Chapter 55: Advanced Meter <usersGuide_55_advancedMeter>` and


That's it for the simple aspects of `TimeSignature` objects.  You know
enough to get started now!

Under the hood, they're extremely powerful.  For musicians, TimeSignatures
do (at least) three different things:

* They define where the beats in the measure are and how many there are.

* They indicate how the notes should be beamed

* They give a sense of how much accent or weight each note gets, which
  also defines which are important notes and which might be ornaments.

These three aspects of `TimeSignatures` are controlled by the
:attr:`~music21.meter.TimeSignature.beatSequence`,
:attr:`~music21.meter.TimeSignature.beamSequence`, and
:attr:`~music21.meter.TimeSignature.accentSequence` properties of the
`TimeSignature`.  Each of them is an independent
:class:`~music21.meter.MeterSequence` element which might have nested
properties (e.g., an 11/16 meter might be beamed as {1/4+1/4+{1/8+1/16}}),
so if you want to change how beats are calculated or beams are generated
you'll want to learn more about `meter.MeterSequence` objects.

There's a fourth `MeterSequence` object inside a TimeSignature, and that is
the :attr:`~music21.meter.TimeSignature.displaySequence`. That determines
how the `TimeSignature` should actually look on paper.  Normally this
`MeterSequence` is pretty simple.  In '4/4' it's usually just '4/4'.  But
if you have the '11/16' time above, you may want to have it displayed as
'2/4+3/16' or '11/16 (2/4+3/16)'.  Or you might want the written
TimeSignature to contradict what the notes imply.  All this can be done
with .displaySequence.

**Equality**

For two time signatures to be considered equal,
they have the same name and internal structure.

The name is tested by the :attr:`~music21.meter.TimeSignature.symbol`.
This helps distinguish between 'Cut' and '2/2', for example.

>>> tsCut = meter.TimeSignature('Cut')
>>> ts22 = meter.TimeSignature('2/2')
>>> tsCut == ts22
False

The internal structure is currently tested simply by the
:attr:`~music21.meter.TimeSignature.beatCount` and
:attr:`~music21.meter.TimeSignature.ratioString` attributes.

The check of :attr:`~music21.meter.TimeSignature.beatCount`
helps to distinguish the 'fast' (2-beat) from 'slow' (6-beat)
versions of 6/8, for example.

>>> fast68 = meter.TimeSignature('fast 6/8')
>>> slow68 = meter.TimeSignature('slow 6/8')
>>> fast68 == slow68
False

Complementing this,
:attr:`~music21.meter.TimeSignature.ratioString`
provides a check of the internal divsions such that
'2/8+3/8' is different from '3/8+2/8', for example,
despite the fact that they could both be written as '5/8'.

>>> ts2n3 = meter.TimeSignature('2/8+3/8')
>>> ts3n2 = meter.TimeSignature('3/8+2/8')
>>> ts2n3 == ts3n2
False

For a less restrictive test of this, see
:meth:`~music21.meter.TimeSignature.ratioEqual`
which returns True for all cases of '5/8'.

>>> ts2n3.ratioEqual(ts3n2)
True

Yes, equality is ever True:

>>> one44 = meter.TimeSignature('4/4')
>>> another44 = meter.TimeSignature()  # '4/4' by default
>>> one44 == another44
True

r"   )symbolratioString	beatCountzDA :class:`~music21.meter.MeterSequence` governing beat partitioning.zDA :class:`~music21.meter.MeterSequence` governing automatic beaming.zFA :class:`~music21.meter.MeterSequence` governing accent partitioning.z`
            A :class:`~music21.meter.MeterSequence` governing the display of the TimeSignature.z
            A string representation of how to display the TimeSignature.
            can be "common", "cut", "single-number" (i.e.,
            no denominator), or "normal" or "".a)  
            If set to `True` (default is `False`) then the denominator
            will be displayed as a symbol rather than
            a number.  Hindemith uses this in his scores.
            Finale and other MusicXML readers do not support this
            so do not expect proper output yet.)beatSequencebeamSequenceaccentSequencedisplaySequencerb   symbolizeDenominatorzdict[str, str]	_DOC_ATTRc                  > [         TU ]  " S0 UD6  Uc#  [        R                   S[        R                   3nS U l        SU l        [        U l        [        U l	        [        U l
        [        U l        SU l        U R                  X5        g )Nr%   r   FrY   )super__init__r   meterNumeratormeterDenominatorBeatType_overriddenBarDurationrb   _SENTINEL_METER_SEQUENCErh   re   rg   rf   ri   resetValues)selfvalue	divisionskeywords	__class__s       rU   rm   TimeSignature.__init__  s{    $8$=../q1R1R0STE>B#.F+C-E+C*/!*r`   c                    U R                   $ N)rc   rs   s    rU   _reprInternalTimeSignature._reprInternal"  s    r`   c                P    SU l         SU l        SU l        U R                  X5        g)zT
reset all values according to a new value and optionally, the number of
divisions.
r   FN)rb   ri   rp   r;   )rs   rt   ru   s      rU   rr   TimeSignature.resetValues%  s+    
  %*!&*# 			%#r`   c                   UR                  5       S;   a
  SnSU l        OUR                  5       S;   a	  SnSU l        [        U5      U l        [	        U5      u  p4nU[
        R                  :X  a6  US-  S:X  a  US	:  a  [
        R                  nOUS:X  a  [
        R                  nU[
        R                  :g  n[        X5      U l	        [        X5      U l
        [        X5      U l        Uc2  U R                  5         U R                  US9   U R                  S5        g
g
! [         a    [         R#                  SU /5         g
f = f)a  
Load up a TimeSignature with a string value.

>>> ts = meter.TimeSignature()
>>> ts.load('4/4')
>>> ts
<music21.meter.TimeSignature 4/4>

>>> ts.load('c')
>>> ts.symbol
'common'

>>> ts.load('2/4+3/8')
>>> ts
<music21.meter.TimeSignature 2/4+3/8>

>>> ts.load('fast 6/8')
>>> ts.beatCount
2
>>> ts.load('slow 6/8')
>>> ts.beatCount
6

Loading destroys all preexisting internal representations
)r   c4/4r   )cut	allabrevez2/2r   r#   r      NfavorCompoundzcannot set default accents for:)lowerrb   r   rh   r   r	   NONEFASTSLOWrf   re   rg   _setDefaultBeamPartitions_setDefaultBeatPartitions_setDefaultAccentWeightsr   environLocal
printDebug)rs   rt   ru   r-   r.   divisionr   s          rU   r;   TimeSignature.load6  s4   @ ;;=O+E"DK[[]22EDK,U3 ,8+>(	})))1}!kQ&6(--a(--!]%7%77 *%;)%; ,E=**,***GS--a0  " S'')JD(QRSs   
D !E Ec                .    U R                   R                  $ )ay  
Returns or sets a simple string representing the time signature ratio.

>>> threeFour = meter.TimeSignature('3/4')
>>> threeFour.ratioString
'3/4'

It can also be set to load a new one, but '.load()' is better:

>>> threeFour.ratioString = '5/8'  # now this variable name is dumb!
>>> threeFour.numerator
5
>>> threeFour.denominator
8

>>> complexTime = meter.TimeSignature('2/4+3/8')
>>> complexTime.ratioString
'2/4+3/8'

For advanced users, getting the ratioString is the equivalent of
:attr:`~music21.meter.core.MeterSequence.partitionDisplay` on the displaySequence:

>>> complexTime.displaySequence.partitionDisplay
'2/4+3/8'
)rh   partitionDisplayr{   s    rU   rc   TimeSignature.ratioString~  s    6 ##444r`   c                &    U R                  U5        g rz   )rr   )rs   newRatioStrings     rU   rc   r     s    (r`   c                v    Uc  gUR                   U R                   :X  a  UR                  U R                  :X  a  gg)zn
A basic form of comparison; does not determine if any internal structures are equal; o
only outermost ratio.
FT)r-   r.   )rs   others     rU   
ratioEqualTimeSignature.ratioEqual  s6    
 =OOt~~-%%)9)99r`   c                .    U R                   R                  $ )a  
Return the numerator of the TimeSignature as a number.

Can set the numerator for a simple TimeSignature.
To set the numerator of a complex TimeSignature, change beatCount.

(for complex TimeSignatures, note that this comes from the .beamSequence
of the TimeSignature)


>>> ts = meter.TimeSignature('3/4')
>>> ts.numerator
3
>>> ts.numerator = 5
>>> ts
<music21.meter.TimeSignature 5/4>


In this case, the TimeSignature is silently being converted to 9/8
to get a single digit numerator:

>>> ts = meter.TimeSignature('2/4+5/8')
>>> ts.numerator
9

Setting a summed time signature's numerator will change to a
simple time signature

>>> ts.numerator = 11
>>> ts
<music21.meter.TimeSignature 11/8>
)rf   r-   r{   s    rU   r-   TimeSignature.numerator  s    D   ***r`   c                r    U R                   n[        U5      S-   [        U5      -   nU R                  U5        g Nr%   )r.   strrr   )rs   rt   r.   r   s       rU   r-   r     s3    &&Uc)C,<<(r`   c                .    U R                   R                  $ )a  
Return the denominator of the TimeSignature as a number or set it.

(for complex TimeSignatures, note that this comes from the .beamSequence
of the TimeSignature)

>>> ts = meter.TimeSignature('3/4')
>>> ts.denominator
4
>>> ts.denominator = 8
>>> ts.ratioString
'3/8'


In this following case, the TimeSignature is silently being converted to 9/8
to get a single digit denominator:

>>> ts = meter.TimeSignature('2/4+5/8')
>>> ts.denominator
8
)rf   r.   r{   s    rU   r.   TimeSignature.denominator  s    .   ,,,r`   c                r    U R                   n[        U5      S-   [        U5      -   nU R                  U5        g r   )r-   r   rr   )rs   rt   numeratorValuer   s       rU   r.   r     s1    ^,s2SZ?(r`   c                    U R                   (       a  U R                   $ U R                  nUb  UR                  $ [        R                  " S5      $ )a{  
Return a :class:`~music21.duration.Duration` object equal to the
total length of this TimeSignature.

>>> ts = meter.TimeSignature('5/16')
>>> ts.barDuration
<music21.duration.Duration 1.25>

>>> ts2 = meter.TimeSignature('3/8')
>>> d = ts2.barDuration
>>> d.type
'quarter'
>>> d.dots
1
>>> d.quarterLength
1.5

This can be overridden to create different representations
or to contradict the meter.

>>> d2 = duration.Duration(1.75)
>>> ts2.barDuration = d2
>>> ts2.barDuration
<music21.duration.Duration 1.75>

An uninitialized TimeSignature returns 4.0 for 4/4

>>> meter.TimeSignature().barDuration
<music21.duration.Duration 4.0>
r   )rp   rf   r   Duration)rs   rf   s     rU   barDurationTimeSignature.barDuration  sL    @ &&...((#  (((   ##r`   c                    Xl         g rz   )rp   rs   rt   s     rU   r   r   %  s    &+#r`   c                     SU R                   -  $ )z
Returns 4.0 / denominator.  Might seem a bit silly but used often.

>>> a = meter.TimeSignature('3/2')
>>> a.beatLengthToQuarterLengthRatio
2.0
r   r.   r{   s    rU   beatLengthToQuarterLengthRatio,TimeSignature.beatLengthToQuarterLengthRatio)  s     T%%%%r`   c                     U R                   S-  $ )z
Returns denominator/4.0.
r   r   r{   s    rU   quarterLengthToBeatLengthRatio,TimeSignature.quarterLengthToBeatLengthRatio4  s    
 #%%r`   c                ,    [        U R                  5      $ )a  
Return or set the count of beat units, or the number of beats in this TimeSignature.

When setting beat units, one level of sub-partitions is automatically defined.
Users can specify beat count values as integers or as lists of durations.
For more precise configuration of the beat MeterSequence,
manipulate the .beatSequence attribute directly.

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatCount
3
>>> ts.beatDuration.quarterLength
1.0
>>> ts.beatCount = [1, 1, 1, 1, 1, 1]
>>> ts.beatCount
6
>>> ts.beatDuration.quarterLength
0.5

Setting a beat-count directly is a simple, high-level way to configure the beatSequence.
Note that his may not configure lower level partitions correctly,
and will raise an error if the provided beat count is not supported by the
overall duration of the .beatSequence MeterSequence.

>>> ts = meter.TimeSignature('6/8')
>>> ts.beatCount  # default is 2 beats
2
>>> ts.beatSequence
<music21.meter.core.MeterSequence {{1/8+1/8+1/8}+{1/8+1/8+1/8}}>
>>> ts.beatDivisionCountName
'Compound'
>>> ts.beatCount = 6
>>> ts.beatSequence
<music21.meter.core.MeterSequence
    {{1/16+1/16}+{1/16+1/16}+{1/16+1/16}+{1/16+1/16}+{1/16+1/16}+{1/16+1/16}}>
>>> ts.beatDivisionCountName
'Simple'
>>> ts.beatCount = 123
Traceback (most recent call last):
music21.exceptions21.TimeSignatureException: cannot partition beat with provided value: 123

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatCount = 6
>>> ts.beatDuration.quarterLength
0.5
)lenre   r{   s    rU   rd   TimeSignature.beatCount?  s    d 4$$%%r`   c                     U R                   R                  U5        [	        U R                   5      S:  a  U R                   R                  5         g g ! [         a    [        SU 35      ef = f)Nz+cannot partition beat with provided value: r   )re   	partitionr   r   r   subdividePartitionsEqualr   s     rU   rd   r   s  sp    	`''. t  !A%668 &  	`(+VW\V])^__	`s   A A+c                .    U R                   R                  $ )z
Return the beat count name, or the name given for the number of beat units.
For example, 2/4 is duple; 9/4 is triple.

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatCountName
'Triple'

>>> ts = meter.TimeSignature('6/8')
>>> ts.beatCountName
'Duple'
)re   partitionStrr{   s    rU   beatCountNameTimeSignature.beatCountName}  s       ---r`   c                    / nU R                    H(  nUR                  UR                  R                  5        M*     [	        [        U5      5      S:X  a  U R                   S   R                  $ [        SU 35      e)a  
Return a :class:`~music21.duration.Duration` object equal to the beat unit
of this Time Signature, if and only if this TimeSignature has a uniform beat unit.

Otherwise, raises an exception in v7.1 but will change to returning NaN
soon fasterwards.

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatDuration
<music21.duration.Duration 1.0>
>>> ts = meter.TimeSignature('6/8')
>>> ts.beatDuration
<music21.duration.Duration 1.5>

>>> ts = meter.TimeSignature('7/8')
>>> ts.beatDuration
<music21.duration.Duration 0.5>

>>> ts = meter.TimeSignature('3/8')
>>> ts.beatDuration
<music21.duration.Duration 1.5>
>>> ts.beatCount = 3
>>> ts.beatDuration
<music21.duration.Duration 0.5>

Cannot do this because of asymmetry

>>> ts = meter.TimeSignature('2/4+3/16')
>>> ts.beatDuration
Traceback (most recent call last):
music21.exceptions21.TimeSignatureException: non-uniform beat unit: [2.0, 0.75]

* Changed in v7: return NaN rather than raising Exception in property.
r   r   znon-uniform beat unit: )re   appendr   r&   r   setr   )rs   postmss      rU   beatDurationTimeSignature.beatDuration  sj    H ##BKK112 $s4y>Q$$Q'000(+B4&)IJJr`   c                &   / n[        U R                  5      S:X  a  gU R                  S   n[        U[        5      (       d  gU R                   H  nUR	                  [        U5      5        M     [        [        U5      5      S:X  a  [        U5      $ g)a  
Return the count of background beat units found within one beat,
or the number of subdivisions in the beat unit in this TimeSignature.

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatDivisionCount
2

>>> ts = meter.TimeSignature('6/8')
>>> ts.beatDivisionCount
3

>>> ts = meter.TimeSignature('15/8')
>>> ts.beatDivisionCount
3

>>> ts = meter.TimeSignature('3/8')
>>> ts.beatDivisionCount
1

>>> ts = meter.TimeSignature('13/8', 13)
>>> ts.beatDivisionCount
1

* Changed in v7: return 1 instead of a TimeSignatureException.
r   r   )r   re   r)   r   r   r   )rs   r   
beat_seq_0r   s       rU   beatDivisionCountTimeSignature.beatDivisionCount  s    : t  !Q& &&q)
*m44 ##BKKB  $ s4y>Qz?"r`   c                8    U R                   nUS:X  a  gUS:X  a  gg)a  
Return the beat count name, or the name given for the number of beat units.
For example, 2/4 is duple; 9/4 is triple.

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatDivisionCountName
'Simple'

>>> ts = meter.TimeSignature('6/8')
>>> ts.beatDivisionCountName
'Compound'

Rare cases of 5-beat divisions return 'Other', like this 10/8 divided into
5/8 + 5/8 with no further subdivisions:

>>> ts = meter.TimeSignature('10/8')
>>> ts.beatSequence.partition(2)
>>> ts.beatSequence
<music21.meter.core.MeterSequence {5/8+5/8}>
>>> for i, mt in enumerate(ts.beatSequence):
...     ts.beatSequence[i] = mt.subdivideByCount(5)
>>> ts.beatSequence
<music21.meter.core.MeterSequence {{1/8+1/8+1/8+1/8+1/8}+{1/8+1/8+1/8+1/8+1/8}}>
>>> ts.beatDivisionCountName
'Other'
r!   Simpler#   CompoundOther)r   )rs   beatDivisions     rU   beatDivisionCountName#TimeSignature.beatDivisionCountName  s(    8 --1Qr`   c                V   / nU R                    Hm  n[        U[        5      (       a0  U H(  nUR                  UR                  R
                  5        M*     MH  UR                  UR                  R
                  5        Mo     [        [        U5      5      S:X  a  / nU R                   S   n[        U[        5      (       a5  U H-  nUR                  c  M  UR                  UR                  5        M/     U$ UR                  b  UR                  UR                  5        U$ [        SU 35      e)a1  
Return the beat division, or the durations that make up one beat,
as a list of :class:`~music21.duration.Duration` objects, if and only if
the TimeSignature has a uniform beat division for all beats.

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatDivisionDurations
[<music21.duration.Duration 0.5>,
 <music21.duration.Duration 0.5>]

>>> ts = meter.TimeSignature('6/8')
>>> ts.beatDivisionDurations
[<music21.duration.Duration 0.5>,
 <music21.duration.Duration 0.5>,
 <music21.duration.Duration 0.5>]

Value returned of non-uniform beat divisions will change at any time
after v7.1 to avoid raising an exception.

OMIT_FROM_DOCS

Previously a time signature with beatSequence containing only
MeterTerminals would raise exceptions.

>>> ts = meter.TimeSignature('2/128')
>>> ts.beatSequence[0]
<music21.meter.core.MeterTerminal 1/128>
>>> ts.beatDivisionDurations
[<music21.duration.Duration 0.03125>]

>>> ts = meter.TimeSignature('1/128')
>>> ts.beatSequence[0]
<music21.meter.core.MeterTerminal 1/128>
>>> ts.beatDivisionDurations
[<music21.duration.Duration 0.03125>]
r   r   znon uniform beat division: )	re   r)   r   r   r   r&   r   r   r   )rs   r   mtsubMtoutr   s         rU   beatDivisionDurations#TimeSignature.beatDivisionDurations  s    L ##B"m,,EKK < <=   BKK556 $ s4y>QC**1-J*m44'E~~1

5>>2 (
 J $$0

:../J(+Ftf)MNNr`   c                    / nU R                   nU HC  nUR                  UR                  S5      5        UR                  UR                  S5      5        ME     U$ )ax  
Return a subdivision of the beat division, or a list
of :class:`~music21.duration.Duration` objects representing each beat division
divided by two.

>>> ts = meter.TimeSignature('3/4')
>>> ts.beatSubDivisionDurations
[<music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>,
 <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>]

>>> ts = meter.TimeSignature('6/8')
>>> ts.beatSubDivisionDurations
[<music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>,
 <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>,
 <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>]
      ?)r   r   augmentOrDiminish)rs   r   srcds       rU   beatSubDivisionDurations&TimeSignature.beatSubDivisionDurationsG  sS    $ ((AKK++C01KK++C01  r`   c                8    U R                    SU R                   3$ )aC  
Return the classification of this TimeSignature,
such as Simple Triple or Compound Quadruple.

>>> ts = meter.TimeSignature('3/4')
>>> ts.classification
'Simple Triple'
>>> ts = meter.TimeSignature('6/8')
>>> ts.classification
'Compound Duple'
>>> ts = meter.TimeSignature('4/32')
>>> ts.classification
'Simple Quadruple'
 )r   r   r{   s    rU   classificationTimeSignature.classificationa  s#      ,,-Qt/A/A.BCCr`   c                J    U R                   c  gU R                   R                  $ )NFrh   summedNumeratorr{   s    rU   r   TimeSignature.summedNumerators  s#    '##333r`   c                @    U R                   b  XR                   l        g g rz   r   r   s     rU   r   r   y  s    +38  0 ,r`   Tr   c                  [        U R                  5      S:X  Ga  U R                  S:X  a  U R                  R	                  S5        GOU R                  S:X  a$  U(       a  U R                  R	                  S5        GOU R                  S:X  a$  U(       a  U R                  R	                  S5        GOhU R                  S:X  a  U R                  R	                  / SQ5        GO9U R                  S:X  a&  U(       a  U R                  R	                  / SQ5        GOU R                  S:X  a  U R                  R	                  S5        OU R                  S	:X  a#  U(       a  U R                  R	                  S5        OU R                  S
:  aI  U R                  S-  S:X  a6  U(       a/  U R                  S-  nU R                  R	                  S/U-  5        OKU R                  R	                  U R                  5        O%U R                  R	                  U R                  5        [        U R                  5      S:  a   U R                  R                  5         gg! [         a    U R                  S:  a   g gf = f)a\  
Set default beat partitions based on numerator and denominator.

>>> ts = meter.TimeSignature('3/4')
>>> len(ts.beatSequence)  # first, not zeroth, level stores beat
3
>>> ts = meter.TimeSignature('6/8')
>>> len(ts.beatSequence)
2
>>> ts = meter.TimeSignature('slow 6/8')
>>> len(ts.beatSequence)
6

* Changed in v7: favorCompound is keyword only
r   r!   r$   r#   )r   r   r   	   )r#   r#   r#   r"         r      N)r   rh   r-   re   r   r   r   r.   )rs   r   num_tripless      rU   r   'TimeSignature._setDefaultBeatPartitions  s   $ t##$)~~"!!++A.1$!!++A.1$!!++A.1$!!++I61$!!++I61$!!++A.2%-!!++A.2%$..1*<*Am"nn1!!++QC+,=> !!++DNN;
 ''(<(<= t  !A%!!::< & " ##s* +s   2I I-,I-c                b   U R                   R                  (       a  gU R                  S:X  a  U R                  S;   a  gU R                  S:X  a  U R                  [	        SS5      ;   a  gU R                  S:X  a  U R                  [	        SS5      ;   a  gU R                  S;   a  U R                   R                  U R                  5        U R                  S	:X  aQ  [	        [        U R                   5      5       H.  nU R                   U   R                  S
5      U R                   U'   M0     ggU R                  S:X  a  S
S/nU R                   R                  U5        U R                  S	:X  aS  [	        [        U R                   5      5       H0  nU R                   U   R                  X!   5      U R                   U'   M2     ggU R                  S:X  a  U R                   R                  S5        gU R                  S;   a6  U R                   R                  S/[        U R                  S-  5      -  5        gg)zI
This method sets default beam partitions when partitionRequest is None.
r   )r   r!   r#      r   r$       r   )r!   r#   r"   r"   r!      r#      )r$   r   r   r         N)	rf   r   r.   r-   ranger   r   	subdivider/   )rs   rB   defaults      rU   r   'TimeSignature._setDefaultBeamPartitions  s   
 ,,"t~~'B#%1+(E#%2,(F ^^y(''71$s4#4#456A+/+<+<Q+?+I+I!+LD%%a( 7 % ^^q !fG''01$s4#4#456A+/+<+<Q+?+I+I'*+UD%%a( 7 % ^^q ''*^^55''c$..12D.E(EFr`   c                   U R                    SU R                   3nU R                  R                  5       (       a6  [	        U R                  5      S:  a  [	        U R                  5      nOSnX#U4nOU R                  n[
        n [        R                  " [        U   5      U l	        g! [         GaA    [        U5      nUR                  UUS9  [	        UR                  5       5      nU R                  R                  U-  nS/U-  n[!        U5       H  n	X-  n
UR#                  U
SU	S9X'   M     [%        U5      n0 nS['        SUS-
  5      -  n[!        U5       H  nU['        SU5      -  XS-   '   M     U R                  R)                  S/U-  5        [!        U5       H  n	XU	      U R                  U	   l        M     U[
        :w  a)  [        R                  " U R                  5      [        U'    g gf = f)	al  
This method sets default accent weights based on common hierarchical notions for meters;
each beat is given a weight, as defined by the top level count of self.beatSequence

>>> ts1 = meter.TimeSignature('4/4')
>>> ts1._setDefaultAccentWeights(4)
>>> [mt.weight for mt in ts1.accentSequence]
[1.0, 0.0625, 0.125, 0.0625, 0.25, 0.0625, 0.125, 0.0625,
 0.5, 0.0625, 0.125, 0.0625, 0.25, 0.0625, 0.125, 0.0625]

>>> ts2 = meter.TimeSignature('3/4')
>>> ts2._setDefaultAccentWeights(4)
>>> [mt.weight for mt in ts2.accentSequence]
[1.0, 0.0625, 0.125, 0.0625, 0.25, 0.0625, 0.125, 0.0625,
 0.5, 0.0625, 0.125, 0.0625, 0.25, 0.0625, 0.125, 0.0625,
 0.5, 0.0625, 0.125, 0.0625, 0.25, 0.0625, 0.125, 0.0625]

>>> ts2._setDefaultAccentWeights(3)  # lower depth
>>> [mt.weight for mt in ts2.accentSequence]
[1.0, 0.125, 0.25, 0.125, 0.5, 0.125, 0.25, 0.125, 0.5, 0.125, 0.25, 0.125]

r%   r   N)firstPartitionFormr   quantize)alignindexr!   )r-   r.   re   isUniformPartitionr   '_meterSequenceAccentArchetypesNoneCachecopydeepcopyr   rg   KeyErrorr   subdivideNestedHierarchyflattenr   r&   r   offsetToDepthr:   powr   weight)rs   depthtsStrr   cacheKeyr   accentCountdivStep
weightIntsrB   qlmaxIntweightValuesweightValueMinxs                  rU   r   &TimeSignature._setDefaultAccentWeights  s   6 >>"!D$4$4#56//114$$%)%():):%;"%)"59H!%!2!2>H
&	^"&--.x8#D  !	^u%B '';M ( O bjjl+K&&44{BG{*J;'[ " 0 0:Q 0 O
 ( _FLQ
!33N6] '5s1ay&@U# # ))1#*;<;'0<]0K##A&- ( BB;?==I\I\;].x8 CA!	^s   "B' 'EG32G3c                  ^ ^^^^	^
 SSK Jm
  [        TT
R                  5      (       a  Tm	[	        T5      mONT(       aE  [        TS   [
        R                  5      (       a#  T
R                  " 5       m	T	R                  T5        O/ $ [        T5      S::  a  T Vs/ s H  nSPM     sn$ [        R                  R                  T5      m[        R                  R                  T5      mSUUU UU	U
4S jjn[        [        [        R                  5      5       H   n[!        T5       H  u  pgU" XgU5        M     M"     [        R                  R#                  T5      m[        R                  R%                  T5      mT$ s  snf )a  
Given a qLen position and an iterable of Music21Objects, return a list of Beams objects.

The iterable can be a list (of elements) or a Stream (preferably flat)
or a :class:`~music21.stream.iterator.StreamIterator` from which Durations
and information about note vs. rest will be
extracted.

Objects are assumed to be adjoining; offsets are not used, except for
measureStartOffset()

Must process a list/Stream at time, because we cannot tell when a beam ends
unless we see the context of adjoining durations.

>>> a = meter.TimeSignature('2/4', 2)
>>> a.beamSequence[0] = a.beamSequence[0].subdivide(2)
>>> a.beamSequence[1] = a.beamSequence[1].subdivide(2)
>>> a.beamSequence
<music21.meter.core.MeterSequence {{1/8+1/8}+{1/8+1/8}}>
>>> b = [note.Note(type='16th') for _ in range(8)]
>>> c = a.getBeams(b)
>>> len(c) == len(b)
True
>>> print(c)
[<music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/stop>/<music21.beam.Beam 2/stop>>,
 <music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/stop>/<music21.beam.Beam 2/stop>>]

>>> a = meter.TimeSignature('6/8')
>>> b = [note.Note(type='eighth') for _ in range(6)]
>>> c = a.getBeams(b)
>>> print(c)
[<music21.beam.Beams <music21.beam.Beam 1/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>>,
 <music21.beam.Beams <music21.beam.Beam 1/stop>>,
 <music21.beam.Beams <music21.beam.Beam 1/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>>,
 <music21.beam.Beams <music21.beam.Beam 1/stop>>]

>>> fourFour = meter.TimeSignature('4/4')
>>> nList = [note.Note(type=d) for d in ('eighth', 'quarter', 'eighth',
...                                      'eighth', 'quarter', 'eighth')]
>>> beamList = fourFour.getBeams(nList)
>>> print(beamList)
[None, None, None, None, None, None]

Pickup measure support included by taking in an additional measureStartOffset argument.

>>> twoTwo = meter.TimeSignature('2/2')
>>> nList = [note.Note(type='eighth') for _ in range(5)]
>>> beamList = twoTwo.getBeams(nList, measureStartOffset=1.5)
>>> print(beamList)
[None,
 <music21.beam.Beams <music21.beam.Beam 1/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>>,
 <music21.beam.Beams <music21.beam.Beam 1/continue>>,
 <music21.beam.Beams <music21.beam.Beam 1/stop>>]

Fixed in v.7 -- incomplete final measures in 6/8:

>>> sixEight = meter.TimeSignature('6/8')
>>> nList = [note.Note(type='quarter'), note.Note(type='eighth'), note.Note(type='eighth')]
>>> beamList = sixEight.getBeams(nList)
>>> print(beamList)
[None, None, None]

And Measure objects with :attr:`~music21.stream.Measure.paddingRight` set:

>>> twoFour = meter.TimeSignature('2/4')
>>> m = stream.Measure([note.Note(type='eighth') for _ in range(3)])
>>> m.paddingRight = 0.5
>>> twoFour.getBeams(m)
[<music21.beam.Beams <music21.beam.Beam 1/start>>,
 <music21.beam.Beams <music21.beam.Beam 1/stop>>,
 None]
r   r   r   Nc                $  > TU    nUc  g[         R                  (       a!  [        U[        R                  5      (       d   eUS-   nXCR                  5       ;  a  gUR                  nUR                  T-   n[        U5      n[        XeR                  -   5      nUn	U [        T5      S-
  :H  n
U S:H  nU
(       d  TU S-      OSnU(       d  TU S-
     OSnTR                  R                  U5      nUR                  U5      u  nnUc  SnOUR                  U	5      S   nUU:X  a  X:X  d	  Uc  US:X  a  STU '   gU(       a"  TS:X  a  SnUb  XLR                  5       ;  a  SnGO"U
(       aF  [        TTR                  5      (       a  TR                  S:X  a  SnUb  XMR                  5       ;  a  SnOUb  XMR                  5       ;  a@  US:X  a	  Uc  STU '   gUc	  US:  a  SnOU	U:  a  SnOUb  XLR                  5       ;  a  SnOSnOUbF  XMR                  5       ;   a3  UR!                  U5      S	;   a  Ub  XLR                  5       ;   a  SOSnO9SnO6Ub  XLR                  5       ;  a  SnOU	U:  a  S
nOU	U:  a  SnO[#        S5      eUR%                  UU5        g)zp
Note that this can compute the beams for non-Note things like rests
they just cannot be applied to the object.
Nr   r   r   startzpartial-rightstoppartial-left)r  r  continuezcannot match beamType)tTYPE_CHECKINGr)   r   Beams
getNumbersr   offsetr
   r&   r   rf   getLeveloffsetToSpanMeasurepaddingRightgetTypeByNumberr   setByNumber)rB   elr  beams
beamNumberdurposr  end	startNextisLastisFirstbeamNextbeamPrevious	archetypearchetypeSpanStartarchetypeSpanEndarchetypeSpanNextStartbeamType	beamsListmeasureStartOffsetrs   srcList	srcStreamr   s                      rU   fixBeamsOneElementDepth7TimeSignature.getBeams.<locals>.fixBeamsOneElementDepth  s   
 aLE}!%4444J !1!1!33++C))00C3KE0001C"%I3w<!++FAvG/5yQ'4H3:9QU+L ))2259I 4=3I3I%3P0 0 ),&)2)?)?	)J1)M&
 &&+ (Z1_  $	! -2"$%-@-@-BB.H *Y"G"G!*!7!73!>! (%-D-D-FF-H %;R;R;T)T?x'7#'IaL%*q.-H"22  .H%;N;N;P)P.H&H *"&=&=&??$44Z@D\\'*48K8K8M*MwSbH  .H "':':'<<! -- & 44! --DEE j(3r`   )rB   r/   r"  zbase.Music21Objectr  r/   )music21r   r)   Streamlistr   Music21Objectr  r   r   r   r  
naiveBeamsremoveSandwichedUnbeamablesr   beamableDurationTypes	enumeratesanitizePartialBeamsmergeConnectingPartialBeams)rs   r4  r3  _r6  outer_depthouter_iouter_elr2  r5  r   s   ```     @@@rU   getBeamsTimeSignature.getBeams3  s)   l 	#gv}}--I7mGGAJ0B0BCC (IW%Iw<1")*'QD'**JJ))'2	JJ::9E	`	4 `	4H !T%?%?!@AK &/w%7!';G &8 B JJ33I>	JJ::9E	e +s   E7c                    [        U[        5      (       a  [        R                  " U5      U l        g[        X5      U l        g)a  
Set an independent display value for a meter.

>>> a = meter.TimeSignature()
>>> a.load('3/4')
>>> a.setDisplay('2/8+2/8+2/8')
>>> a.displaySequence
<music21.meter.core.MeterSequence {2/8+2/8+2/8}>
>>> a.beamSequence
<music21.meter.core.MeterSequence {{1/8+1/8}+{1/8+1/8}+{1/8+1/8}}>
>>> a.beatSequence  # a single top-level partition is default for beat
<music21.meter.core.MeterSequence {{1/8+1/8}+{1/8+1/8}+{1/8+1/8}}>
>>> a.setDisplay('3/4')
>>> a.displaySequence
<music21.meter.core.MeterSequence {3/4}>
N)r)   r   r   r   rh   )rs   rt   partitionRequests      rU   
setDisplayTimeSignature.setDisplayJ  s1    " e]++#'==#7D  $1#ID r`   c                    Sn[        U5      n[        [        U R                  5      5       H/  nX!:X  a    gX R                  U   R                  R
                  -  nM1     g)a+  
Return True or False if the qLenPos is at the start of an accent
division.

>>> a = meter.TimeSignature('3/4', 3)
>>> a.accentSequence.partition([2, 1])
>>> a.accentSequence
<music21.meter.core.MeterSequence {2/4+1/4}>
>>> a.getAccent(0.0)
True
>>> a.getAccent(1.0)
False
>>> a.getAccent(2.0)
True
r   TF)r
   r   r   rg   r   r&   )rs   qLenPosr&  rB   s       rU   	getAccentTimeSignature.getAccentb  sX      /s4../0A~&&q)22@@@C 1 r`   c                    [        U[        5      (       d  U/nOUnU R                  R                  U5      n[	        [        U5      5       H  nX5[        U5      -     XE   l        M     g)a  
Set accent weight, or floating point scalars, for the accent MeterSequence.
Provide a list of float values; if this list is shorter than the length
of the MeterSequence, it will be looped; if this list is longer,
only the relevant values at the beginning will be used.

If the accent MeterSequence is subdivided, the level of depth to set is given by the
optional level argument.

>>> a = meter.TimeSignature('4/4', 4)
>>> len(a.accentSequence)
4
>>> a.setAccentWeight([0.8, 0.2])
>>> a.getAccentWeight(0.0)
0.8...
>>> a.getAccentWeight(0.5)
0.8...
>>> a.getAccentWeight(1.0)
0.2...
>>> a.getAccentWeight(2.5)
0.8...
>>> a.getAccentWeight(3.5)
0.2...
N)r)   r   rg   r  r   r   r  )rs   weightslevel
weightListmsLevelrB   s         rU   setAccentWeightTimeSignature.setAccentWeightz  s\    8 '8,,!J J%%..u5s7|$A *s:+> ?GJ %r`   c                    USL a  UR                   nSn[        U5      nUS:X  a  gU H'  nU R                  U R                  U5      SSS9nX6-  nM)     X4-  $ )a  
returns a float of the average beat strength of all objects (or if notesOnly is True
[default] only the notes) in the `Stream` specified as streamIn.


>>> s = converter.parse('C4 D4 E8 F8', format='tinyNotation').flatten().notes.stream()
>>> sixEight = meter.TimeSignature('6/8')
>>> sixEight.averageBeatStrength(s)
0.4375
>>> threeFour = meter.TimeSignature('3/4')
>>> threeFour.averageBeatStrength(s)
0.5625

If `notesOnly` is `False` then test objects will give added
weight to the beginning of the measure:

>>> sixEight.averageBeatStrength(s, notesOnly=False)
0.4375
>>> s.insert(0.0, clef.TrebleClef())
>>> s.insert(0.0, clef.BassClef())
>>> sixEight.averageBeatStrength(s, notesOnly=False)
0.625
Tr   r   F)forcePositionMatchpermitMeterModulus)notesr   getAccentWeight$getMeasureOffsetOrMeterModulusOffset)rs   streamIn	notesOnlytotalWeighttotalObjectsr"  elWeights          rU   r9   !TimeSignature.averageBeatStrength  sv    0 ~~H8}1B++99"=#'E , CH #K	 
 ))r`   c                    UR                  5       nU R                  SS9nX#-   U R                  R                  :  a  U$ X#-
  U R                  R                  -  nU$ )a	  
Return the measure offset based on a Measure, if it exists,
otherwise based on meter modulus of the TimeSignature.

>>> m = stream.Measure()
>>> ts1 = meter.TimeSignature('3/4')
>>> m.insert(0, ts1)
>>> n1 = note.Note()
>>> m.insert(2, n1)
>>> ts1.getMeasureOffsetOrMeterModulusOffset(n1)
2.0

Exceeding the range of the Measure gets a modulus

>>> n2 = note.Note()
>>> m.insert(4.0, n2)
>>> ts1.getMeasureOffsetOrMeterModulusOffset(n2)
1.0

Can be applied to Notes in a Stream with a TimeSignature.

>>> ts2 = meter.TimeSignature('5/4')
>>> s2 = stream.Stream()
>>> s2.insert(0, ts2)
>>> n3 = note.Note()
>>> s2.insert(3, n3)
>>> ts2.getMeasureOffsetOrMeterModulusOffset(n3)
3.0

>>> n4 = note.Note()
>>> s2.insert(5, n4)
>>> ts2.getMeasureOffsetOrMeterModulusOffset(n4)
0.0
F)includeMeasurePadding)_getMeasureOffsetr   r&   )rs   r"  mOffsettsMeasureOffsetr   s        rU   r\  2TimeSignature.getMeasureOffsetOrMeterModulusOffset  sb    F &&(00u0M%)9)9)G)GGN .$2B2B2P2PPDKr`   c                   [        U5      n[        U R                   Vs/ s H  oUR                  PM     sn5      S-  nU R                  R	                  U5      nU(       aY  [
        R                  SU R                  R                  SU R                  R                  /5        XR                  R                  -  nU(       a  UR                  UUS9nXS   :w  a  U$ XwR                  U5         R                  $ s  snf )a  
Given a qLenPos,  return an accent level. In general, accents are assumed to
define only a first-level weight.

If `forcePositionMatch` is True, an accent will only be returned if the
provided qLenPos is a near exact match to the provided quarter length. Otherwise,
half of the minimum quarter length will be provided.

If `permitMeterModulus` is True, quarter length positions greater than
the duration of the Meter will be accepted as the modulus of the total meter duration.

>>> ts1 = meter.TimeSignature('3/4')
>>> [ts1.getAccentWeight(x) for x in range(3)]
[1.0, 0.5, 0.5]

Calling getAccentWeight on durations beyond the score returns an error:

>>> [ts1.getAccentWeight(x) for x in range(6)]
Traceback (most recent call last):
music21.exceptions21.MeterException: cannot access from qLenPos 3.0
    where total duration is 3.0

The error is removed if permitMeterModulus is employed:

>>> [ts1.getAccentWeight(x, permitMeterModulus=True) for x in range(6)]
[1.0, 0.5, 0.5, 1.0, 0.5, 0.5]
r   z self.duration.quarterLengthzself.barDuration.quarterLength)rY  r   )r
   minrg   r  r  r   r   r   r&   r   r  offsetToIndex)	rs   rM  rR  rX  rY  r   	minWeightrT  	localSpans	            rU   r[  TimeSignature.getAccentWeight  s    : / !%!4!45!42YY!4579<=	%%..u5##/1L1L143C3C3Q3QST  0 0 > >>G  ,,W@R - TI A,&  ,,W56===# 6s   C7c                >    U R                   R                  U5      S-   $ )a  
Given an offset (quarterLength position), get the beat, where beats count from 1

If you want a fractional number for the beat, see `getBeatProportion`.

TODO: In a future version -- getBeat will probably do what getBeatProportion does now,
    but just with 1 added to it.

>>> a = meter.TimeSignature('3/4', 3)
>>> a.getBeat(0)
1
>>> a.getBeat(2.5)
3
>>> a.beatSequence.partition(['3/8', '3/8'])
>>> a.getBeat(2.5)
2
r   )re   rk  )rs   r  s     rU   getBeatTimeSignature.getBeat'  s     $   ..v6::r`   c                ,   / nUR                  S5        [        U R                  5      S:X  a  U$ U R                  R                  nSnU R                   H>  n[        X4R                  R                  -   5      nX2:  a  Us  $ UR                  U5        M@     g)z
Return offset positions in a list for the start of each beat,
assuming this object is found at offset zero.

>>> a = meter.TimeSignature('3/4')
>>> a.getBeatOffsets()
[0.0, 1.0, 2.0]
>>> a = meter.TimeSignature('6/8')
>>> a.getBeatOffsets()
[0.0, 1.5]
r   r   N)r   r   re   r   r&   r
   r   )rs   r   	endOffsetor   s        rU   getBeatOffsetsTimeSignature.getBeatOffsets;  s     Ct  !Q&K((66IA''1{{8889>KA	 (r`   c                f    U R                   U R                   R                  U5         R                  $ )aZ  
Returns a :class:`~music21.duration.Duration`
object representing the length of the beat
found at qLenPos.  For most standard
meters, you can give qLenPos = 0
and get the length of any beat in
the TimeSignature; but the simpler
:attr:`music21.meter.TimeSignature.beatDuration` parameter,
will do that for you just as well.

The advantage of this method is that
it will work for asymmetrical meters, as the second
example shows.


Ex. 1: beat duration for 3/4 is always 1.0
no matter where in the meter you query.


>>> ts1 = meter.TimeSignature('3/4')
>>> ts1.getBeatDuration(0.5)
<music21.duration.Duration 1.0>
>>> ts1.getBeatDuration(2.5)
<music21.duration.Duration 1.0>


Ex. 2: same for 6/8:


>>> ts2 = meter.TimeSignature('6/8')
>>> ts2.getBeatDuration(2.5)
<music21.duration.Duration 1.5>


Ex. 3: but for a compound meter of 3/8 + 2/8,
where you ask for the beat duration
will determine the length of the beat:


>>> ts3 = meter.TimeSignature('3/8+2/8')  # will partition as 2 beat
>>> ts3.getBeatDuration(0.5)
<music21.duration.Duration 1.5>
>>> ts3.getBeatDuration(1.5)
<music21.duration.Duration 1.0>
)re   rk  r   )rs   rM  s     rU   getBeatDurationTimeSignature.getBeatDurationT  s-    \   !2!2!@!@!IJSSSr`   c                   [        US5      u  p#[        U5      n[        R                  " U5      nUS-
  [	        U R
                  5      S-
  :  a!  [        SU< SU R
                  < SU < 35      eU R
                  US-
     R                  nU R
                  R                  5       US-
     u  pV[        XTR                  U-  -   5      nU$ )ac  
Given a beat value, convert into an offset position.


>>> ts1 = meter.TimeSignature('3/4')
>>> ts1.getOffsetFromBeat(1)
0.0
>>> ts1.getOffsetFromBeat(2)
1.0
>>> ts1.getOffsetFromBeat(3)
2.0
>>> ts1.getOffsetFromBeat(3.5)
2.5
>>> ts1.getOffsetFromBeat(3.25)
2.25

Get the offset from beat 8/3 (2.6666): give a Fraction, get a Fraction.

>>> from fractions import Fraction
>>> ts1.getOffsetFromBeat(Fraction(8, 3))
Fraction(5, 3)

>>> ts1 = meter.TimeSignature('6/8')
>>> ts1.getOffsetFromBeat(1)
0.0
>>> ts1.getOffsetFromBeat(2)
1.5

Check that 2.5 is 2.5 + (0.5 * 1.5):

>>> ts1.getOffsetFromBeat(2.5)
2.25

Decimals only need to be pretty close to work.
(But Fractions are better as demonstrated above)

>>> ts1.getOffsetFromBeat(2.33)
2.0
>>> ts1.getOffsetFromBeat(2.66)
2.5

Works for asymmetrical meters as well:

>>> ts3 = meter.TimeSignature('3/8+2/8')  # will partition as 2 beat
>>> ts3.getOffsetFromBeat(1)
0.0
>>> ts3.getOffsetFromBeat(2)
1.5
>>> ts3.getOffsetFromBeat(1.66)
1.0
>>> ts3.getOffsetFromBeat(2.5)
2.0


Let's try this on a real piece, a 4/4 chorale with a one beat pickup.  Here we get the
normal offset for beat 4 from the active TimeSignature, but we subtract out
the pickup length which is in a `Measure`'s :attr:`~music21.stream.Measure.paddingLeft`
property, and thus see the distance from the beginning of the measure to beat 4 in
quarter notes

>>> c = corpus.parse('bwv1.6')
>>> for m in c.parts.first().getElementsByClass(stream.Measure):
...     ts = m.timeSignature or m.getContextByClass(meter.TimeSignature)
...     print(m.number, ts.getOffsetFromBeat(4.0) - m.paddingLeft)
0 0.0
1 3.0
2 3.0
...
r   zrequested beat value (z ) not found in beat partitions (z) of ts )divmodr/   r   addFloatPrecisionr   re   r   r   getLevelSpanr
   r&   )rs   beatbeatIntbeatFractionbeatDuroStartunused_oEndr   s           rU   getOffsetFromBeatTimeSignature.getOffsetFromBeat  s    N !'tQg, //=Q;T../!33(T..67 7
 ##GaK099"//<<>w{Kf 5 5 DEFr`   c                    U R                   R                  U5      nU R                   R                  U5      u  p4US-   X-
  4$ )a  
Given a quarterLength position, get the beat,
where beats count from 1, and return the
amount of qLen into this beat the supplied qLenPos
is.

>>> a = meter.TimeSignature('3/4', 3)
>>> a.getBeatProgress(0)
(1, 0)
>>> a.getBeatProgress(0.75)
(1, 0.75)
>>> a.getBeatProgress(1.0)
(2, 0.0)
>>> a.getBeatProgress(2.5)
(3, 0.5)


Works for specifically partitioned meters too:

>>> a.beatSequence.partition(['3/8', '3/8'])
>>> a.getBeatProgress(2.5)
(2, 1.0)
r   )re   rk  r  )rs   rM  	beatIndexr  
unused_ends        rU   getBeatProgressTimeSignature.getBeatProgress  sD    0 %%33G<	 --::7C1}go--r`   c                    U R                   R                  U5      nU R                   R                  U5      u  p4XC-
  nX-
  n[        US-   Xe-  -   5      $ )aS  
Given a quarter length position into the meter, return the numerical progress
through the beat (where beats count from one) with a floating-point or fractional value
between 0 and 1 appended to this value that gives the proportional progress into the beat.

For faster, integer values, use simply `.getBeat()`

>>> ts1 = meter.TimeSignature('3/4')
>>> ts1.getBeatProportion(0.0)
1.0
>>> ts1.getBeatProportion(0.5)
1.5
>>> ts1.getBeatProportion(1.0)
2.0

>>> ts3 = meter.TimeSignature('3/8+2/8')  # will partition as 2 beat
>>> ts3.getBeatProportion(0.75)
1.5
>>> ts3.getBeatProportion(2.0)
2.5
r   )re   rk  r  r
   )rs   rM  r  r  r'  
totalRangeprogresss          rU   getBeatProportionTimeSignature.getBeatProportion  sW    , %%33G<	&&33G<
[
?i!mx'<=>>r`   c                    [        U R                  R                  U5      5      nU R                  R                  U5      u  p4XC-
  nX-
  nXe-  S:X  a  US-    nU$ [	        Xe-  5      u  pUS-    SU SU	 3nU$ )a  
Return a string presentation of the beat.

>>> ts1 = meter.TimeSignature('3/4')
>>> ts1.getBeatProportionStr(0.0)
'1'
>>> ts1.getBeatProportionStr(0.5)
'1 1/2'
>>> ts1.getBeatProportionStr(1.0)
'2'
>>> ts3 = meter.TimeSignature('3/8+2/8')  # will partition as 2 beat
>>> ts3.getBeatProportionStr(0.75)
'1 1/2'
>>> ts3.getBeatProportionStr(2)
'2 1/2'

>>> ts4 = meter.TimeSignature('6/8')  # will partition as 2 beat
r   r   r   r%   )r/   re   rk  r  r   )
rs   rM  r  r  r'  r  r  r   abs
             rU   getBeatProportionStr"TimeSignature.getBeatProportionStr  s    & ))77@A	&&33G<
[
?!c)!m_D  ((=>DA!m_AaS!-Dr`   c                8    U R                   R                  X5      $ )a  
Return the number of levels of beat partitioning given a QL into the TimeSignature.
Note that by default beat partitioning always has a single, top-level partition.

The `align` parameter is passed to the :meth:`~music21.meter.MeterSequence.offsetToDepth`
method, and can be used to find depths based on start position overlaps.

>>> a = meter.TimeSignature('3/4', 3)
>>> a.getBeatDepth(0)
1
>>> a.getBeatDepth(1)
1
>>> a.getBeatDepth(2)
1

>>> b = meter.TimeSignature('3/4', 1)
>>> b.beatSequence[0] = b.beatSequence[0].subdivide(3)
>>> b.beatSequence[0][0] = b.beatSequence[0][0].subdivide(2)
>>> b.beatSequence[0][1] = b.beatSequence[0][1].subdivide(2)
>>> b.beatSequence[0][2] = b.beatSequence[0][2].subdivide(2)
>>> b.getBeatDepth(0)
3
>>> b.getBeatDepth(0.5)
1
>>> b.getBeatDepth(1)
2
)re   r  )rs   rM  r   s      rU   getBeatDepthTimeSignature.getBeatDepth3  s    8   ..w>>r`   )rp   rg   rf   re   rh   rb   ri   )r   N)rt   r   rz   )returnduration.Duration)rt   r  )r  r5   )r  r/   )rt   r/   )r  r   )r  zlist[duration.Duration])r  bool)rt   r  )r  None)r#   )r  r/   r  r  )r   )r4  z.stream.Stream | t.Sequence[base.Music21Object]r3  r   r  zlist[beam.Beams | None])rM  r   r  r  )r   )rQ  zSequence[float] | floatrR  r/   r  r  )T)r   FF)r   )6rZ   r[   r\   r]   r^   r   	TextStyle_styleClassclassSortOrderequalityAttributesrj   __annotations__rm   r|   rr   r;   propertyrc   setterr   r-   r.   r   r   r   rd   r   r   r   r   r   r   r   r   r   r   r   rF  rJ  rN  rU  r9   r\  r[  rp  ru  rx  r  r  r  r  r  r_   __classcell__rw   s   @rU   r8   r8     s   kX //KN _^bc3!3!I~ $+ +  $"FSP 5 58 ) )  !+ !+F ) ) - -0 ) )
 )$ )$V , , & & & & 1& 1&f 9 9 . . )K )KV - -^ ! !F 7O 7Or  2 D D" 4 4
 9 9 :> 5n%PO^l (+U=U %U 
	UnJ04 &'#@!6#@"#@+/#@J$*L,\ DI+02>h;(2.T`Vp.8?8>? ?r`   r8   c                  6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )SenzaMisuraTimeSignatureiS  a   
A SenzaMisuraTimeSignature represents the absence of a TimeSignature

It is NOT a TimeSignature subclass, only because it has none of the attributes
of a TimeSignature.

>>> smts = meter.SenzaMisuraTimeSignature('0')
>>> smts.text
'0'
>>> smts
<music21.meter.SenzaMisuraTimeSignature 0>
c                .   > [         TU ]  5         Xl        g rz   )rl   rm   text)rs   r  rw   s     rU   rm   !SenzaMisuraTimeSignature.__init__a  s    	r`   c                H    U R                   c  g[        U R                   5      $ )Nr   )r  r   r{   s    rU   r|   &SenzaMisuraTimeSignature._reprInternale  s    99tyy>!r`   )r  rz   )	rZ   r[   r\   r]   r^   rm   r|   r_   r  r  s   @rU   r  r  S  s    " "r`   r  c                      \ rS rSrSrS rSrg)Testir  z&
All other tests moved to meter.tests
c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr  globals)rs   r  s     rU   testCopyAndDeepcopyTest.testCopyAndDeepcopyv  s    7D')$r`   rY   N)rZ   r[   r\   r]   r^   r  r_   rY   r`   rU   r  r  r  s    %r`   r  __main__)r<   zstream.Streamr  z'music21.meter.TimeSignature')5r^   
__future__r   collections.abcr   r   r*   mathr   typingr  unittestr8  r   r   r   music21.common.enumsr	   music21.common.numberToolsr
   r   r   r   music21.exceptions21r   r   r   music21.meter.toolsr   r   music21.meter.corer   Environmentr   r  music21.common.typesr   r   rq   r1   r   r  r   rV   r;  rX   r8   r  TestCaser  
_DOC_ORDERrZ   mainTestrY   r`   rU   <module>r     s   
 # $         . -    G  B ,&&w/??- )? 
   OQ  K P*6 'DP	** 	D?% D?P:"0 ">%8 % _
 z r`   