
    rhn             
         S SK Jr  S SKJrJr  S SKrS SKrS SKrS SK	r	S SK
Jr  S SK
Jr  S SK
Jr  S SK
Jr  S SK
Jr  S S	K
Jr  S S
K
Jr  S SK
Jr  S SK
Jr  S SK
Jr  S SK
Jr  S SK
Jr  S SKJr  S SKJrJr  S SKJr  \R<                  (       a  S SKJ r   S SK
J!r!  S SK"J#r#  \RH                  " \%5      r&SSSS.   S7S jjr'SSSSSSSS.   S7S jjr(SSSSSS.   S7S jjr)SSS\RT                  4S.   S7S  jjr+SS!.S7S" jjr,S8S# jr- S9 S:S$ jjr.S;S% jr/SSSSSSSSSS&.	                     S<S' jjr0S=S( jr1SSSSSSSSS).                 S>S* jjr2  S?   S@S+ jjr3SSS,.   SAS- jjr4SSS,.   SBS. jjr5SSS/.       SCS0 jjr6SSS1.       SDS2 jjr7\Rp                  SES3 j5       r9 " S4 S5\	Rt                  5      r;\<S6:X  a  S SK
r
\
Rz                  " \;5        gg)F    )annotations)Iterable	GeneratorN)beam)clef)common)chord)defaults)duration)environment)expressions)key)meter)note)pitch)opFrac)
StreamTypeOffsetQL)StreamException)Fractionstream)StreamIteratorFT)inPlacesetStemDirectionsfailOnNoTimeSignaturec                  SSK Jn  U(       d  U R                  S5      nOU n[        XTR                  5      (       a  U/nO=[        UR                  UR                  5      5      nU(       d  UR                  " S5      eSnU GH@  nUR                  =(       d    UR                  [        R                  5      nUc  U(       a  UR                  " S5      eMT  / n	UR                  5       (       a=  UR                   H,  n
U	R                  U
R                  R                  5       5        M.     O)U	R                  UR                  R                  5       5        U	 GHh  n[!        U5      S::  a  M  / nU HL  nUR"                  R$                  (       a  UR'                  U5        M1  UR                  UR"                  5        MN     [)        U Vs/ s H  oR*                  PM     sn5      n[-        [-        U5      5      nUR.                  R*                  nUU:  a  M  SnUR0                  S:w  a  [-        UR0                  5      nO0UR2                  S:w  a  OUR4                  U:  a  UUR4                  -
  nUR7                  UUS	9n[9        U5       H1  u  nnUU   nUb	  UUl        M  [<        R>                  " 5       Ul        M3     GMk     GMC     AU(       a  [A        U5        S
URB                  l        US
La  U$ gs  snf )a  
Return a new Measure, or Stream of Measures, with beams applied to all
notes. Measures with Voices will process voices independently.

Note that `makeBeams()` is automatically called in show('musicxml') and
other formats if there is no beaming information in the piece (see
`haveBeamsBeenMade`).

If `inPlace` is True, this is done in-place; if `inPlace` is False,
this returns a modified deep copy.

.. note: Before Version 1.6, `inPlace` default was `True`; now `False`
         like most `inPlace` options in music21.  Also, in 1.8, no tuplets are made
         automatically.  Use makeTupletBrackets()

See :meth:`~music21.meter.TimeSignature.getBeams` for the algorithm used.

>>> aMeasure = stream.Measure()
>>> aMeasure.timeSignature = meter.TimeSignature('4/4')
>>> aNote = note.Note()
>>> aNote.quarterLength = 0.25
>>> aMeasure.repeatAppend(aNote, 16)
>>> bMeasure = aMeasure.makeBeams(inPlace=False)

>>> for i in range(4):
...   print(f'{i} {bMeasure.notes[i].beams!r}')
0 <music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>
1 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>
2 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/start>>
3 <music21.beam.Beams <music21.beam.Beam 1/stop>/<music21.beam.Beam 2/stop>>


This was formerly a bug -- we could not have a partial-left beam at the start of a
beam group.  Now merges across the archetypeSpan

>>> aMeasure = stream.Measure()
>>> aMeasure.timeSignature = meter.TimeSignature('4/4')
>>> for i in range(4):
...     aMeasure.append(note.Rest(quarterLength=0.25))
...     aMeasure.repeatAppend(note.Note('C4', quarterLength=0.25), 3)
>>> bMeasure = aMeasure.makeBeams(inPlace=False).notes
>>> for i in range(6):
...   print(f'{i} {bMeasure[i].beams!r}')
0 <music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>
1 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>
2 <music21.beam.Beams <music21.beam.Beam 1/stop>/<music21.beam.Beam 2/stop>>
3 <music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>
4 <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/continue>>
5 <music21.beam.Beams <music21.beam.Beam 1/stop>/<music21.beam.Beam 2/stop>>

Grace notes no longer interfere with beaming:

>>> m = stream.Measure()
>>> m.timeSignature = meter.TimeSignature('3/4')
>>> m.repeatAppend(note.Note(quarterLength=0.25), 4)
>>> m.repeatAppend(note.Rest(), 2)
>>> gn = note.Note(duration=duration.GraceDuration())
>>> m.insert(0.25, gn)
>>> m.makeBeams(inPlace=True)
>>> [n.beams for n in m.notes]
[<music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>,
<music21.beam.Beams>,
<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>>]

OMIT_FROM_DOCS
TODO: inPlace=False does not work in many cases  ?? still an issue? 2017
r   r   	makeBeamszEcannot process a stream that is neither a Measure nor has no MeasuresN:cannot process beams in a Measure without a time signature           )measureStartOffsetT)"music21r   coreCopyAsDerivation
isinstanceMeasurelistgetElementsByClassr   timeSignaturegetContextByClassr   TimeSignature	hasVoicesvoicesappendnotesAndRestslenr   isGraceremovesumquarterLengthr   barDurationpaddingLeftpaddingRighthighestTimegetBeams	enumeratebeamsr   BeamssetStemDirectionForBeamGroupsstreamStatus)sr   r   r   r   	returnObjmColllastTimeSignaturem
noteGroupsv
noteStreamdurListndsummeddurSumbarQLoffset	beamsListi	thisBeamss                         U/home/james-whalen/.local/lib/python3.13/site-packages/music21/stream/makeNotation.pyr   r   4   s   Z  **;7		 )^^,,Y11&..AB((WY Y   OOWq/B/B5CVCV/W$$,,PR R
;;==XX!!!//"8"8":;  aoo4467 %J:!#G::%%%%a(qzz*	   7;7a//7;<F F6N+F%11??E~
  &)F}}#.3&''%/!7!77)22:RX2YI!*-1%aL	('AG"jjlAG .] %) R 	%i0#'I d U <s   K2finalmeterStreamrefStreamOrTimeRangesearchContextinnerBarlinefinalBarlinebestClefr   c                  SSK Jn  SSK Jn	  Sn
U R                  5       (       aW  U(       a  U nO[        R
                  " U 5      nUR                  S5       H  nUR                  UUUUUUSS9  M     U(       a  gU$ U R                  5       (       a  U nOU R                  5       nUR                  (       d  UR                  5       nU(       d  [        R
                  " U5      n[        UR                  5      nUc  UR                  SSSS	9nOq[        U[         R"                  5      (       a&  UnU	R$                  " 5       nUR'                  SU5        O,[        XR$                  5      (       d  U	R(                  " S
5      eUR+                  5       nUR,                  =(       d    UR/                  [,        R0                  5      nUcX  UR                  [,        R0                  5      R3                  S5      R5                  5       nU(       d  [,        R6                  " USS9nUR9                  5       nU(       a'  [;        U Vs/ s H  nUR<                  PM     sn5      nOSnUb>  [        X)R$                  5      (       a  UR>                  nO[;        U5      n[;        UU5      nU RA                  5       nU URB                  l"        SURB                  l#        SnSnSn U	RH                  " 5       nUS-   Ul%        URM                  U5      nUc  Uc  U	R(                  " S5      eUULa   Ub  Un[        R
                  " U5      Ul'        US:X  aJ  UUl        US:  a=  U RP                  b0  UR'                  S[        R
                  " U RP                  5      5        [S        U5       H-  nU	RT                  " 5       nUUl+        URY                  SU5        M/     U(       a  UR[                  5         UR\                  R^                  S:X  a  U	R(                  " SU< S35      eURY                  UU5        UUR\                  R^                  -  nUU:  a  OUS-  nGMw  UR[                  5         [        U5      n/ n[         R"                  " S5      n[S        U5       H`  n UU    nURN                  b  URN                  nURa                  U5      n
U
UR\                  R^                  -   n!URc                  UU
U!S.5        Mb     U GH0  n"U"u  n#n$n%n[        U#URd                  5      (       a  URc                  U#5        M9  Sn&[S        U5       H,  n UU    n'U'S   n
U'S   n!U'S   nU
U$s=::  a  U!:  d  M&  O  M*  Sn&  O   U&(       d?  U$U%s=:X  a  U:X  a  O  OURg                  U#5        M  U	R(                  " SU# SU$ SU% S35      eU$U
-
  n(UR,                  U#L a  M  U(S:X  a!  [        U#[         R"                  5      (       a  M  Uc  UR'                  U(U#5        GM  UR                  U   R'                  U(U#5        GM3     U H  n)URc                  U)5        M     A[        UR                  U	RH                  5      5      S-
  n*[i        UR                  U	RH                  5      5       HJ  u  n nU U*:w  a  US;  a  UUl5        OUS;  a  UUl5        U(       d  M0  [,        R6                  " USS9Ul        ML     U(       d  URm                  SSS9  U$ / U l7        / U l8        U R[                  5         UR                  (       a  Un+OUR                  5       n+U+ H$  n#U R'                  URa                  U#5      U#5        M&     gs  snf )a  
Takes a stream and places all of its elements into
measures (:class:`~music21.stream.Measure` objects)
based on the :class:`~music21.meter.TimeSignature` objects
placed within
the stream. If no TimeSignatures are found in the
stream, a default of 4/4 is used.

If `inPlace` is True, the original Stream is modified and lost
if `inPlace` is False, this returns a modified deep copy.

Many advanced features are available:

(1) If a `meterStream` is given, the TimeSignatures in this
stream are used instead of any found in the Stream.
Alternatively, a single TimeSignature object
can be provided in lieu of the stream. This feature lets you
test out how a group of notes might be interpreted as measures
in a number of different metrical schemes.

(2) If `refStreamOrTimeRange` is provided, this Stream or List
is used to give the span that you want to make measures as
necessary to fill empty rests at the ends or beginnings of
Streams, etc.  Say for instance you'd like to make a complete
score from a short ossia section, then you might use another
Part from the Score as a `refStreamOrTimeRange` to make sure
that the appropriate measures of rests are added at either side.

(3) If `innerBarline` is not None, the specified Barline object
or string-specification of Barline style will be used to create
Barline objects between every created Measure. The default is None.

(4) If `finalBarline` is not None, the specified Barline object or
string-specification of Barline style will be used to create a Barline
objects at the end of the last Measure. The default is 'final'.

The `searchContext` parameter determines whether context
searches are used to find Clef and other notation objects.

Here is a simple example of makeMeasures:

A single measure of 4/4 is created from a Stream
containing only three quarter notes:

>>> sSrc = stream.Stream()
>>> sSrc.append(note.Note('C4', type='quarter'))
>>> sSrc.append(note.Note('D4', type='quarter'))
>>> sSrc.append(note.Note('E4', type='quarter'))
>>> sMeasures = sSrc.makeMeasures()
>>> sMeasures.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Barline type=final>

Notice that the last measure is incomplete -- makeMeasures
does not fill up incomplete measures.

We can also check that the measure created has
the correct TimeSignature:

>>> sMeasures[0].timeSignature
<music21.meter.TimeSignature 4/4>

Now let's redo this work in 2/4 by putting a TimeSignature
of 2/4 at the beginning of the stream and rerunning
makeMeasures. Now we will have two measures, each with
correct measure numbers:

>>> sSrc.insert(0.0, meter.TimeSignature('2/4'))
>>> sMeasuresTwoFour = sSrc.makeMeasures()
>>> sMeasuresTwoFour.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 2/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.note.Note E>
    {1.0} <music21.bar.Barline type=final>

Let us put 10 quarter notes in a Part.

>>> sSrc = stream.Part()
>>> n = note.Note('E-4')
>>> n.quarterLength = 1
>>> sSrc.repeatAppend(n, 10)

After we run makeMeasures, we will have
3 measures of 4/4 in a new Part object. This experiment
demonstrates that running makeMeasures does not
change the type of Stream you are using:

>>> sMeasures = sSrc.makeMeasures()
>>> len(sMeasures.getElementsByClass(stream.Measure))
3
>>> sMeasures.__class__.__name__
'Part'

Demonstrate what `makeMeasures` will do with `inPlace` = True:

>>> sScr = stream.Score()
>>> sPart = stream.Part()
>>> sPart.insert(0, clef.TrebleClef())
>>> sPart.insert(0, meter.TimeSignature('3/4'))
>>> sPart.append(note.Note('C4', quarterLength = 3.0))
>>> sPart.append(note.Note('D4', quarterLength = 3.0))
>>> sScr.insert(0, sPart)
>>> sScr.makeMeasures(inPlace=True)
>>> sScr.show('text')
{0.0} <music21.stream.Part 0x...>
    {0.0} <music21.stream.Measure 1 offset=0.0>
        {0.0} <music21.clef.TrebleClef>
        {0.0} <music21.meter.TimeSignature 3/4>
        {0.0} <music21.note.Note C>
    {3.0} <music21.stream.Measure 2 offset=3.0>
        {0.0} <music21.note.Note D>
        {3.0} <music21.bar.Barline type=final>

If after running makeMeasures you run makeTies, it will also split
long notes into smaller notes with ties.  Lyrics and articulations
are attached to the first note.  Expressions (fermatas,
etc.) will soon be attached to the last note but this is not yet done:

>>> p1 = stream.Part()
>>> p1.append(meter.TimeSignature('3/4'))
>>> longNote = note.Note('D#4')
>>> longNote.quarterLength = 7.5
>>> longNote.articulations = [articulations.Staccato()]
>>> longNote.lyric = 'hi'
>>> p1.append(longNote)
>>> partWithMeasures = p1.makeMeasures()
>>> partWithMeasures is not p1
True
>>> dummy = partWithMeasures.makeTies(inPlace=True)
>>> partWithMeasures.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 3/4>
    {0.0} <music21.note.Note D#>
{3.0} <music21.stream.Measure 2 offset=3.0>
    {0.0} <music21.note.Note D#>
{6.0} <music21.stream.Measure 3 offset=6.0>
    {0.0} <music21.note.Note D#>
    {1.5} <music21.bar.Barline type=final>

>>> allNotes = partWithMeasures.flatten().notes
>>> allNotes[0].articulations
[]

>>> allNotes[1].articulations
[]

>>> allNotes[2].articulations
[<music21.articulations.Staccato>]

>>> [allNotes[0].lyric, allNotes[1].lyric, allNotes[2].lyric]
['hi', None, None]

* Changed in v6: all but first attribute are keyword only

* Changed in v7: now safe to call `makeMeasures` directly on a score containing parts
r   )spannerr   NStreamTrS   F)returnDefaultrV   sortByCreationTime4meterStream is neither a Stream nor a TimeSignature!)recursemakeMeasuresr!   r    zDfailed to find TimeSignature in meterStream; cannot process Measuresztime signature z has no duration4/4)measuremStartmEndrd   re   rc   zcannot place element z with start/end /z within any measures)regularN)9r#   r[   r   hasPartLikeStreamscopydeepcopyr(   ra   r,   flattenisSortedsortedr0   r-   getTimeSignaturesr%   r   r+   r\   insertr   SpannerBundler   r*   ClefgetElementsByOffsetfirstrY   	offsetMapmaxendTimer8   	__class__
derivationoriginmethodr&   numbergetElementAtOrBeforer)   keySignaturerangeVoiceid
coreInsertcoreElementsChangedr5   r4   elementOffsetr.   Spanner
storeAtEndr:   rightBarlinesetDerivationMethod	_elements_endElements),r?   rT   rU   rV   rW   rX   rY   r   r[   r   rd   r@   	substreamsrcObj
voiceCounttsspannerBundleAccumclefObjoffsetMapListxoMaxrefStreamHighestTimepostomeasureCountrB   rC   thisTimeSignature
voiceIndexrE   postLenpostMeasureListrO   re   oneOffsetMapestartendmatchpostMeasureInfooNewsp	lastIndex
postSorteds,                                               rQ   ra   ra      s   b  F 	Ia(I"55h?I""{8L1>0<0<,4+/ # % @ ;;== FYY[F]]_F]]6*F'
 ..$ / 
 
K!4!4	5	5mmo1b!+}}55((FH H !..0 kk@V55dii@G++DII6JJ1MSSUmmFD9G $$&M }5}!AII}56 '*MM::#7#C#C #&';#< 4-. ;;=DDOO+DOOAL
NN!# (<<Q? $):)B((,- - %66%1 1 #mm,=>AO
 1AFA~!.."<DMM!..9:
  
+JAADLLA , !!# ((66!;((!"3!66FGI I1	**8889ALm p 	 $iGO++E27^G??& ! ##A&)55CCC 	1*0(, . 	/  &$0!5#z a))%%a(wA-a0O$X.F"6*D	*A%%%    #t#",,+A3.>ugQseK_`b b v~ 66Q; 19Au':':;; HHT1HHZ ''a0u &z !B ! 	 D++FNN;<q@I$11&..AB1	>#44!-#44!-8]]1d3AF C    > 	==JJAHHT''*A. A 6s   9])rU   fillGapstimeRangeFromBarDurationr   	hideRestsc          
     	   SSK Jn  U(       d  U R                  S5      nOU nSUR                  l        UR                  5       R                  (       a>  UR                  5       R                   H  nUR                  SUUUUS9  M     U(       a  gU$   S     SS jjn	Sn
SnU(       a  [        XvR                  5      (       a  U	" US	9nO[        XvR                  5      (       az  [        XR                  5      (       a  U	" US	9nO[        U[        R                  5      (       a9  Sn[        UR                  UR                  5      (       a  UR                  nU	" XS
9nO@UR                  5       (       a+  [        S UR!                  UR                  5       5       5      nUS:X  at  Uc  UR"                  nOd[        XR$                  5      (       a  UR&                  n
UR"                  nO1[(        R*                  " U5      (       a  [-        U5      n
[/        U5      nUR1                  5       (       a  [3        UR4                  5      nO3UR                  5       (       a  [3        UR!                  S5      5      nOU/nSnU GH  nUR&                  nUR"                  nUR6                  =(       d    Un[        XR                  5      (       ax  U=(       d    UnU(       a  U	" X5      nUR4                   H  nUR                  SUUUUS9  M     UR&                  nUR"                  n[-        UR8                  R:                  U5      nUU
-
  nUS:  aI  [<        R>                  " 5       nUUR@                  l        UURB                  l"        URG                  U
U5        UU-
  nUS:  aI  [<        R>                  " 5       nUUR@                  l        UURB                  l"        URG                  UU5        U(       d  GMu  URI                  5       nUc  GM  U Hj  n[<        R>                  " 5       nUR@                  R:                  UR@                  l        UURB                  l"        URG                  URJ                  U5        Ml     GM     UR                  5       (       ad  URM                  [<        R>                  4SS9  SnUR!                  UR                  5       H$  nURO                  UU5        UUR"                  -  nM&     USLa  U$ g)a  
Given a Stream with an offset not equal to zero,
fill with one Rest preceding this offset.
This can be called on any Stream,
a Measure alone, or a Measure that contains
Voices. This method recurses into Parts, Measures, and Voices,
since users are unlikely to want "loose" rests outside sub-containers.

If `refStreamOrTimeRange` is provided as a Stream, this
Stream is used to get min and max offsets. If a list is provided,
the list assumed to provide minimum and maximum offsets. Rests will
be added to fill all time defined within refStream.

If `fillGaps` is True, this will create rests in any
time regions that have no active elements.

If `timeRangeFromBarDuration` is True, and the calling Stream
is a Measure with a TimeSignature (or a Part containing them),
the time range will be determined
by taking the :meth:`~music21.stream.Measure.barDuration` and subtracting
:attr:`~music21.stream.Measure.paddingLeft` and
:attr:`~music21.stream.Measure.paddingRight`.
This keyword takes priority over `refStreamOrTimeRange`.
If both are provided, `timeRangeFromBarDuration`
prevails, unless no TimeSignature can be found, in which case, the function
falls back to `refStreamOrTimeRange`.

If `inPlace` is True, this is done in-place; if `inPlace` is False,
this returns a modified deepcopy.

>>> a = stream.Stream()
>>> a.insert(20, note.Note())
>>> len(a)
1
>>> a.lowestOffset
20.0
>>> a.show('text')
{20.0} <music21.note.Note C>

Now make some rests:

>>> b = a.makeRests(inPlace=False)
>>> len(b)
2
>>> b.lowestOffset
0.0
>>> b.show('text')
{0.0} <music21.note.Rest 20ql>
{20.0} <music21.note.Note C>
>>> b[0].duration.quarterLength
20.0

Same thing, but this time, with gaps, and hidden rests:

>>> a = stream.Stream()
>>> a.insert(20, note.Note('C4'))
>>> a.insert(30, note.Note('D4'))
>>> len(a)
2
>>> a.lowestOffset
20.0
>>> a.show('text')
{20.0} <music21.note.Note C>
{30.0} <music21.note.Note D>
>>> b = a.makeRests(fillGaps=True, inPlace=False, hideRests=True)
>>> len(b)
4
>>> b.lowestOffset
0.0
>>> b.show('text')
{0.0} <music21.note.Rest 20ql>
{20.0} <music21.note.Note C>
{21.0} <music21.note.Rest 9ql>
{30.0} <music21.note.Note D>
>>> b[0].style.hideObjectOnPrint
True

Now with measures:

>>> a = stream.Part()
>>> a.insert(4, note.Note('C4'))
>>> a.insert(8, note.Note('D4'))
>>> len(a)
2
>>> a.lowestOffset
4.0
>>> a.insert(0, meter.TimeSignature('4/4'))
>>> a.makeMeasures(inPlace=True)
>>> a.show('text', addEndTimes=True)
{0.0 - 0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0 - 0.0} <music21.clef.TrebleClef>
    {0.0 - 0.0} <music21.meter.TimeSignature 4/4>
{4.0 - 5.0} <music21.stream.Measure 2 offset=4.0>
    {0.0 - 1.0} <music21.note.Note C>
{8.0 - 9.0} <music21.stream.Measure 3 offset=8.0>
    {0.0 - 1.0} <music21.note.Note D>
    {1.0 - 1.0} <music21.bar.Barline type=final>
>>> a.makeRests(fillGaps=True, inPlace=True)
>>> a.show('text', addEndTimes=True)
{0.0 - 4.0} <music21.stream.Measure 1 offset=0.0>
    {0.0 - 0.0} <music21.clef.TrebleClef>
    {0.0 - 0.0} <music21.meter.TimeSignature 4/4>
    {0.0 - 4.0} <music21.note.Rest whole>
{4.0 - 8.0} <music21.stream.Measure 2 offset=4.0>
    {0.0 - 1.0} <music21.note.Note C>
    {1.0 - 4.0} <music21.note.Rest dotted-half>
{8.0 - 12.0} <music21.stream.Measure 3 offset=8.0>
    {0.0 - 1.0} <music21.note.Note D>
    {1.0 - 4.0} <music21.note.Rest dotted-half>
    {4.0 - 4.0} <music21.bar.Barline type=final>

* Changed in v6: all but first attribute are keyword only
* Changed in v7:
  - `inPlace` defaults False
  - Recurses into parts, measures, voices
  - Gave priority to `timeRangeFromBarDuration` over `refStreamOrTimeRange`
* Changed in v8: scores (or other streams having parts) edited `inPlace` return `None`.
r   r   	makeRestsNT)r   r   r   rU   r   c                    SnUb  UR                   R                  nOU b  U R                   R                  nU b  X R                  -  nX R                  -  n[	        US5      $ )zL
Needed for timeRangeFromBarDuration.
Returns 0.0 if no meter can be found.
r!   )r5   r4   r6   r7   ru   )rC   r   r   s      rQ   oHighTargetForMeasure(makeRests.<locals>.oHighTargetForMeasure_  sZ     >>>//D]==..D=MM!DNN"D4~    r!   )rC   )rC   r   c              3  L   #    U  H  oR                   R                  v   M     g 7fN)r5   r4   ).0rC   s     rQ   	<genexpr>makeRests.<locals>.<genexpr>  s      5a++5as   "$r&   )classFilterListr   )NN)rC   zstream.Measure | Noner   zmeter.TimeSignature | Nonereturnr   )(r#   r   r$   r>   tupletsiterpartsr   r%   r&   r   r   r+   
activeSitehasMeasuresr3   r(   r8   r\   lowestOffsetr   
isIterableminru   r,   r'   r-   r)   r5   r4   r   Restr   stylehideObjectOnPrintro   findGapsrM   makeTiessetElementOffset)r?   rU   r   r   r   r   r   r@   
inner_partr   
oLowTargetoHighTargetmaybe_measurebundlerB   	componentoLowoHights_or_measureinner_voiceqLenr	gapStreamr   accumulatedTimerC   s                             rQ   r   r     se   ~ **;7		 &*I"~~#..*00J  !#%9)A !  1  "&'+$ 
& JKi00/)<K	<<00.??36JK0%2E2EFF59i22FNNCC$-$8$8M3m]""$$  5>5Q5QRXR`R`5a K
 c'#//K,mm<<-::J.::K34412J23K i&&'				 	 i229=>26	%%%%%33H7Hi00-:M'3IQ(//%%d/709;H?W	 & (  0 ))D))Em77EE{SK j !8		A'+AJJ$(1AGG% Z+ U"!8		A'+AJJ$(1AGG%UA&8!**,I$"A		A/0zz/G/GAJJ,09AGG-$$QXXq1	 #Y d DII<F --fnn=A&&q/:q}},O > d r   rT   r   displayTiedAccidentalsr   c                  SSK Jn  U(       d  U R                  S5      nOU nU(       d  UR                  " S5      e[        R
                  " U5      (       d  U/n[        XeR                  5      (       aH  UR                   H  nUR                  USUUS9  M     U(       d  [        R                  " [        U5      $ gUR                  5       (       a>  UR                  UR                  5       H  nUR                  USUUS9  M     U(       d  U$ gUR!                  5       (       d  UR                  " S5      eUc  UR#                  SS	S
9nOPU(       dI  [$        R&                  " [(        R*                   S[(        R,                   35      n	UR/                  SU	5        Sn
[1        UR                  UR2                  5      5      nU
[5        U5      :  Gah  X   nUR7                  UR8                  5      nU
S-   [5        U5      :  a
  XS-      nS	nOQUR2                  " 5       nUR8                  nUUR:                  R<                  -   Ul        UR>                  S-   Ul        SnURA                  5       (       a  SnOS	nUR:                  R<                  nURA                  5       (       a  URB                  nSnOU/nS	nU GHe  nU GHZ  nURD                  RG                  U5      (       a  M&  URH                  nURK                  U5      n[M        UURN                  R<                  -   5      nUU-
  nUS::  a  Mr  UU:  a  Mz  UU-
  nURQ                  USUS9u  nnU(       aN  U(       a7  [        U[R        5      (       d  URB                  U   nOFURU                  U5      nO4URB                  S   nO$U(       a  [W        U5        URB                  S   nOSnUc  UnUR/                  SU5        U(       d  GM-  UR/                  UR8                  U5        URY                  U5        GM]     GMh     U
S-  n
U
[5        U5      :  a  GMh  UR                  UR2                  5       H  nUR[                  SS9  M     U(       d  U$ g)a  
Given a stream containing measures, examine each element in the
Stream. If the element's duration extends beyond the measure's boundary,
create a tied entity, placing the split Note in the next Measure.

Note that this method assumes that there is appropriate space in the
next Measure: this will not shift Note objects, but instead allocate
them evenly over barlines.

If `inPlace` is True, this is done in-place;
if `inPlace` is False, this returns a modified deep copy.

Put a 12-quarter-note-long note into a Stream w/ 4/4 as the duration.

>>> d = stream.Stream()
>>> d.insert(0, meter.TimeSignature('4/4'))
>>> n = note.Note('C4')
>>> n.quarterLength = 12
>>> d.insert(0, n)
>>> d.show('text')
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.note.Note C>

After running makeMeasures, we get nice measures, a clef, but only one
way-too-long note in Measure 1:

>>> x = d.makeMeasures()
>>> x.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note C>
{4.0} <music21.stream.Measure 2 offset=4.0>
<BLANKLINE>
{8.0} <music21.stream.Measure 3 offset=8.0>
    {0.0} <music21.bar.Barline type=final>
>>> n2 = x.measure(1).notes[0]
>>> n2.duration.quarterLength
12.0
>>> n2 is n
False

But after running makeTies, all is good:

>>> x.makeTies(inPlace=True)
>>> x.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note C>
{4.0} <music21.stream.Measure 2 offset=4.0>
    {0.0} <music21.note.Note C>
{8.0} <music21.stream.Measure 3 offset=8.0>
    {0.0} <music21.note.Note C>
    {4.0} <music21.bar.Barline type=final>
>>> m = x.measure(1).notes[0]
>>> m.duration.quarterLength
4.0
>>> m is n
False
>>> m.tie
<music21.tie.Tie start>
>>> x.measure(2).notes[0].tie
<music21.tie.Tie continue>
>>> x.measure(3).notes[0].tie
<music21.tie.Tie stop>

Same experiment, but with rests:

>>> d = stream.Stream()
>>> d.insert(0, meter.TimeSignature('4/4'))
>>> r = note.Rest()
>>> r.quarterLength = 12
>>> d.insert(0, r)
>>> x = d.makeMeasures()
>>> x.makeTies(inPlace=True)
>>> x.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Rest whole>
{4.0} <music21.stream.Measure 2 offset=4.0>
    {0.0} <music21.note.Rest whole>
{8.0} <music21.stream.Measure 3 offset=8.0>
    {0.0} <music21.note.Rest whole>
    {4.0} <music21.bar.Barline type=final>

Notes: uses base.Music21Object.splitAtQuarterLength() once it has figured out
what to split.

* Changed in v4: inPlace = False by default.
* Changed in v6: all but first attribute are keyword only
* New in v7: `classFilterList` acts as a filter on what elements will
  be operated on (i.e. have durations split and/or ties made.)
  The default `(note.GeneralNote,)` includes Notes, Chords, and Rests.

Here will we split and make ties only on Notes, leaving the too-long
rest in measure 1 alone.

>>> p = stream.Part()
>>> p.append(meter.TimeSignature('2/4'))
>>> p.insert(0.0, note.Rest(quarterLength=3.0))
>>> p.insert(3.0, note.Note(quarterLength=3.0))
>>> p.makeMeasures(inPlace=True)
>>> p.makeTies(classFilterList=[note.Note], inPlace=True)
>>> p.show('text', addEndTimes=True)
{0.0 - 3.0} <music21.stream.Measure 1 offset=0.0>
    {0.0 - 0.0} <music21.clef.TrebleClef>
    {0.0 - 0.0} <music21.meter.TimeSignature 2/4>
    {0.0 - 3.0} <music21.note.Rest dotted-half>
{2.0 - 4.0} <music21.stream.Measure 2 offset=2.0>
    {1.0 - 2.0} <music21.note.Note C>
{4.0 - 6.0} <music21.stream.Measure 3 offset=4.0>
    {0.0 - 2.0} <music21.note.Note C>
    {2.0 - 2.0} <music21.bar.Barline type=final>
>>> p.measure(3).notes[0].tie
<music21.tie.Tie stop>

OMIT_FROM_DOCS

configure ".previous" and ".next" attributes

Previously a note tied from one voice could not make ties into a note
in the next measure outside of voices.  Fixed May 2017

>>> p = stream.Part()
>>> m1 = stream.Measure(number=1)
>>> m2 = stream.Measure(number=2)
>>> m1.append(meter.TimeSignature('1/4'))
>>> v1 = stream.Voice(id='v1')
>>> v2 = stream.Voice(id=2)  # also test problems with int voice ids
>>> n1 = note.Note('C4')
>>> n1.tie = tie.Tie('start')
>>> n2 = note.Note('D--4')
>>> n2.tie = tie.Tie('start')
>>> v1.append(n1)
>>> v2.append(n2)
>>> n3 = note.Note('C4')
>>> n3.tie = tie.Tie('stop')
>>> m2.append(n3)
>>> m1.insert(0, v1)
>>> m1.insert(0, v2)
>>> p.append([m1, m2])
>>> p2 = p.makeTies()

test same thing with needed makeTies:

>>> p = stream.Part()
>>> m1 = stream.Measure(number=1)
>>> m2 = stream.Measure(number=2)
>>> m1.append(meter.TimeSignature('1/4'))
>>> v1 = stream.Voice(id='v1')
>>> v2 = stream.Voice(id=2)  # also test problems with int voice ids
>>> n1 = note.Note('C4', quarterLength=2)
>>> n2 = note.Note('B4')
>>> v1.append(n1)
>>> v2.append(n2)
>>> m1.insert(0, v1)
>>> m1.insert(0, v2)
>>> p.append(m1)
>>> p.insert(1.0, m2)
>>> p2 = p.makeTies()
>>> p2.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.meter.TimeSignature 1/4>
    {0.0} <music21.stream.Voice v1>
        {0.0} <music21.note.Note C>
    {0.0} <music21.stream.Voice 2>
        {0.0} <music21.note.Note B>
{1.0} <music21.stream.Measure 2 offset=1.0>
    {0.0} <music21.note.Note C>

>>> for n in p2.recurse().notes:
...     print(n, n.tie)
<music21.note.Note C> <music21.tie.Tie start>
<music21.note.Note B> None
<music21.note.Note C> <music21.tie.Tie stop>

Be helpful and wrap `classFilterList` in a list if need be.

>>> m = stream.Measure([note.Note(quarterLength=8.0)])
>>> m.insert(0, meter.TimeSignature('4/4'))
>>> p = stream.Part([m])
>>> p.makeTies(inPlace=True, classFilterList='Note')
>>> len(p.getElementsByClass(stream.Measure))
2
>>> p.recurse().last().tie
<music21.tie.Tie stop>
r   r   r   zcannot process an empty streamTr   Nz(cannot process a stream without measuresF)r^   rV   rf   r    )retainOriginr   r   ).r#   r   r$   r   r   r   r%   Opusscoresr   tcastr   rh   r(   r\   r   rn   r   r+   r
   meterNumeratormeterDenominatorBeatTypero   r'   r&   r0   r|   rM   r5   r4   r{   r,   r-   classSet
isdisjointr   r   r   r   splitAtQuarterLengthintgetElementByIdmoveNotesToVoicesr.   flattenUnnecessaryVoices)r?   rT   r   r   r   r   r@   subScorepr   mCountmeasureListrC   activeTSmNextmNextAddmOffsetmNextHasVoicesre   r   
mHasVoicesrE   r   vIdeOffseteEndovershotqLenWithinMeasureeRemaindstrc   s                                  rQ   r   r     s,   L 
 **:6		$$%EFF_--*+)[[))!((H+&*5K.=    ) 66*i00##%% --fmm<AJJ;#.D'6   =    ""$$%OPP 11T@E 2 G  &&'q)J)J(KL
 	1b!Fy33FNNCDK
3{#
#33AHH= A:K((
+EHNN$EhhG#&22@@AEL 88a<ELH??!N"N ##11 ;;==XXFJSFJA::((99dd
 //!,g

(@(@@A$;q=d? %)7N!33%!%+A 4 
7 "!)#s33"',,s"3C"'"6"6s";C $ll1o ")%0#ll1o";C
 

1g&
 8 $$U\\59&&u-E  H 	!Y 3{#
#\ //?(((6 @ r   r   c               j   / nU(       d  U R                  S5      nOU nUR                   H;  nUR                  R                  (       a  M   UR	                  UR                  5        M=     / nU H~  nUR
                  nU(       d  UR	                  SU45        M+  [        U5      S:  a.  [        R                  SU< 35        UR	                  SU45        Mh  UR	                  US   U45        M     SnSn	Sn
[        U5       H  u  nu  pU[        U5      S-
  :  a  X[S-      S   nOSnUbj  [        XR                  -   5      nU
b  U	c,  Uc  SUl        SUl        SnO9S	Ul        UR                  5       n	O!Ub  X:  a  S
Ul        Sn	SnOU
b
  Ub  SUl        Un
M     SUR                  l        U(       d  U$ g)an  
Given a flat Stream of mixed durations, designates the first and last tuplet of any group
of tuplets as the start or end of the tuplet, respectively.

>>> n = note.Note()
>>> n.duration.quarterLength = 1/3
>>> s = stream.Stream()
>>> s.insert(0, meter.TimeSignature('2/4'))
>>> s.repeatAppend(n, 6)
>>> tupletTypes = [x.duration.tuplets[0].type for x in s.notes]
>>> tupletTypes
[None, None, None, None, None, None]
>>> stream.makeNotation.makeTupletBrackets(s, inPlace=True)
>>> tupletTypes = [x.duration.tuplets[0].type for x in s.notes]
>>> tupletTypes
['start', None, 'stop', 'start', None, 'stop']

The tuplets must already be coherent.  See :class:`~music21.duration.TupletFixer`
for how to get that set up.

TODO: does not handle nested tuplets

* Changed in v1.8: `inPlace` is False by default
* Changed in v7: Legacy behavior of taking in a list of durations removed.
makeTupletBracketsNr    z3got multi-tuplet duration; cannot yet handle this. r   r!   	startStopFr   stopT)r$   r/   r   r1   r.   r   r0   environLocalwarnr:   r   r4   typebrackettotalTupletLengthr>   )r?   r   durationListr@   rH   	tupletMapdur
tupletListcompletionCountcompletionTargettupletPreviousrO   	tupletObj
tupletNexts                 rQ   r   r   W  s   6 -/L **+?@		 $$::AJJ' % GII[[
dC[)_q  Ej^T dC[)jmS12  !$O&*+/N(3Is9~!!"q5)!,J J  $_7H7H%HIO %)9)A%%0IN(-I%&)O%,IN'0'B'B'D$ #'J!'	#' "%  +
0F!%	"i  4l &*I" r   c                  ^ U R                  SS9mU R                  Tl        U4S jnU  H\  nUR                  (       a  TR                  [	        U5      5        M0  [        US5      (       a
  U" U5        MK  TR                  U5        M^     T$ )a  
Realize all ornaments on a stream

Creates a new stream that contains all realized ornaments in addition
to other elements in the original stream.

>>> s1 = stream.Stream()
>>> m1 = stream.Measure()
>>> m1.number = 1
>>> m1.append(meter.TimeSignature('4/4'))
>>> n1 = note.Note('C4', type='whole')
>>> n1.expressions.append(expressions.Mordent())
>>> m1.append(n1)
>>> m2 = stream.Measure()
>>> m2.number = 2
>>> n2 = note.Note('D4', type='whole')
>>> m2.append(n2)
>>> s1.append(m1)
>>> s1.append(m2)
>>> for x in s1.recurse(includeSelf=True):
...     x
<music21.stream.Stream ...>
<music21.stream.Measure 1 offset=0.0>
<music21.meter.TimeSignature 4/4>
<music21.note.Note C>
<music21.stream.Measure 2 offset=4.0>
<music21.note.Note D>

>>> s2 = stream.makeNotation.realizeOrnaments(s1)
>>> for x in s2.recurse(includeSelf=True):
...     x
<music21.stream.Stream ...>
<music21.stream.Measure 1 offset=0.0>
<music21.meter.TimeSignature 4/4>
<music21.note.Note C>
<music21.note.Note B>
<music21.note.Note C>
<music21.stream.Measure 2 offset=4.0>
<music21.note.Note D>

TODO: does not work for Gapful streams because it uses append rather
   than the offset of the original
realizeOrnaments)derivationMethodc                @  > SnU R                    Ht  n[        US5      (       d  M  UR                  U 5      u  p4nSnU H  nTR                  U5        M     Ub  TR                  U5        U H  nTR                  U5        M     Mv     USL a  TR                  U 5        g g )NFrealizeT)r   hasattrr
  r.   )innerElementelementHasBeenRealizedexpbeforeduringafterrH   	newStreams          rQ   realizeElementExpressions3realizeOrnaments.<locals>.realizeElementExpressions  s    !&++C3	**$'KK$=!FE%)"  # !  (  #  , "U*\* +r   r   )
cloneEmptyrM   isStreamr.   r  r  )r?   r  elementr  s      @rQ   r  r    s|    X .@AIxxI+& -g67w..)'2  )  r   c                    SSK Jn  U" 5       n[        U R                  U5      5      nU H5  nUR	                  U R                  U5      U5        U R                  U5        M7     U R	                  SU5        g)z@
Move notes into voices.  Happens inplace always.  Returns None
r   )r   N)music21.streamr   r'   r(   ro   r   r2   )sourcer   r   r   affectedElementsr   s         rQ   r   r      se    
 %
'C F55oFG

6''*A.a  MM!Sr   c                   [        U [        R                  5      (       d  g[        5       n[        U [        R
                  5      (       a  [        U 5      nOU /nU Hp  nUR                  b9  UR                  R                  S:X  d  [        U[        R                  5      (       a  MK  UR                  UR                  R                  5        Mr     U$ )a  
helper method for makeAccidentals to get the tie pitch set (or None)
from the prior

>>> n1 = note.Note('C4')
>>> n2 = note.Note('D4')
>>> n2.tie = tie.Tie('start')
>>> n3 = note.Note('E4')
>>> n3.tie = tie.Tie('stop')
>>> n4 = note.Note('F4')
>>> n4.tie = tie.Tie('continue')
>>> c = chord.Chord([n1, n2, n3, n4])
>>> tps = stream.makeNotation.getTiePitchSet(c)
>>> isinstance(tps, set)
True
>>> sorted(tps)
['D4', 'F4']

Non tie possessing objects return None

>>> r = bar.Repeat()
>>> stream.makeNotation.getTiePitchSet(r) is None
True

Note or Chord without ties, returns an empty set:

>>> n = note.Note('F#5')
>>> stream.makeNotation.getTiePitchSet(n)
set()

>>> pChord = percussion.PercussionChord([note.Unpitched('D4'), note.Note('E5')])
>>> stream.makeNotation.getTiePitchSet(pChord)
set()

Rest returns None

>>> r = note.Rest()
>>> stream.makeNotation.getTiePitchSet(r) is None
True
Nr   )r%   r   NotRestsetr	   	ChordBaser'   tier   	Unpitchedaddr   nameWithOctave)priortiePitchSetpreviousNotesrH   s       rQ   getTiePitchSetr'  1  s    T eT\\**%K%))U55=AEEJJ&0Jq$..4Q4Q../  r   )		pitchPastpitchPastMeasureuseKeySignaturealteredPitchescautionaryPitchClasscautionaryAlloverrideStatuscautionaryNotImmediateRepeatr%  c       	           SSK Jn
Jn  Sn/ n[        U[        R
                  5      (       a5  UnUR                  5       R                   Vs/ s H  oR                  PM     nn[        U R                  U
5      5      n[        U5       GH  u  nnUS:  Ga  UR                  c%  UUS-
     R                  [        UUS-
     5      -   nOMU(       aF  UUS-
     R                  [        UUS-
     5      -    Vs/ s H  nUR                  U;  d  M  UPM     nn UUS-
     [        R                     S   n[!        U5      n	U	bd  UR                  bW  UR                  R                  5       R                   Vs/ s H  oR                  PM     nnU	 Vs1 s H  nUU;   d  M  UiM     n	nUR                  b?  UR                  nUR                  5       R                   Vs/ s H  oR                  PM     nnUR'                  UUUUSUUSUUU	S9  GM     [        X5      (       a  SU R(                  l        ggs  snf s  snf s  snf s  snf ! ["        [$        4 a     Nf = fs  snf )	a  
Makes accidentals in place on a stream that contains Measures.
Helper for Stream.makeNotation and Part.makeAccidentals.

The function walks measures in order to update the values for the following keyword
arguments of :meth:`~music21.stream.base.makeAccidentals` and calls
that method on each Measure. (For this reason, the values supplied
for these arguments in the method signature will be used on the first
measure only, or in the case of `useKeySignature`, not at all if the first
measure contains a `KeySignature`.)::

    pitchPastMeasure
    useKeySignature
    tiePitchSet

Operates on the measures in place; make a copy first if this is not desired.

* Changed in v8: the Stream may have other elements besides measures and the method
    will still work.
r   )r&   r\   FNr    T)r(  r)  r*  r+  searchKeySignatureByContextr,  r-  r   r.  r/  r%  )r  r&   r\   r%   r   KeySignaturegetScalepitchesnamer'   r(   r:   r}   ornamentalPitchesr   r  r'  
IndexErrorr   makeAccidentalsr>   accidentals)r?   r(  r)  r*  r+  r,  r-  r.  r/  r%  r&   r\   ksLastksLastDiatonicr   measuresOnlyrO   rC   previousNoteOrChordksNewDiatonictps                        rQ   makeAccidentalsInMeasureStreamrA  j  sY   B /
 %*F "N/3#3#344 *0//*;*C*CD*CQ&&*CD"&q';';G'D"EL,'1 q5~~% Q'//2CLQRUVQVDW2XX !  !Q'//2CLQRUVQVDW2XX$5X +,vv^3 %&X ! $5
&21q5&9$,,&G&K#,-@A*q~~/I 67^^5L5L5N5V5V$W5VVV5VM$W0;"S"r]?R2K"S >>%^^F.4oo.?.G.GH.Gff.GNH	-")(-!5'))E# 	 	
E (^ !%)" e E"$5 %X"S0 
 IsO   
H/3H4H4AI1H9I
H>H> II9
IIIc                X   SSK Jn  / nU R                   H  n[        X15      (       a  UR	                  [        U5      5        M/  [        US5      (       d  MB  UR                   H?  n[        U[        R                  5      (       d  M$  UR	                  UR
                  5        MA     M     U$ )a,  
Returns all ornamental :class:`~music21.pitch.Pitch` objects found in any
ornaments in notes/chords in the stream (and substreams) as a Python list.

Very much like the pitches property, except that instead of returning all
the pitches found in notes and chords, it returns the ornamental pitches
found in the ornaments on the notes and chords.

If you want a list of _all_ the pitches in a stream, including the ornamental
pitches, you can call s.pitches and makeNotation.ornamentalPitches(s),
and then combine the two resulting lists into one big list.
r   )r\   r   )	r  r\   elementsr%   extendr7  r  r   Ornament)r?   r\   r   r   orns        rQ   r7  r7    s~     &DZZa  KK)!,-Q&&}}c;#7#788KK 5 56 %  Kr   )r(  r)  otherSimultaneousPitchesr+  r,  r-  r.  r/  c                  U R                    Hp  n	[        U	[         R                  5      (       d  M$  U	R                  U 5        U	R                  (       d  MH  U	R                  UUUUUUUS9  Uc  Mb  XR                  -  nMr     g)z
Makes accidentals for the ornamental pitches for any Ornaments on noteOrChord.
This is very similar to the processing in pitch.updateAccidentalDisplay, except
that there is no tie processing, since ornamental pitches cannot be tied.
)r(  r)  r+  r,  r-  r.  r/  N)r   r%   rE  resolveOrnamentalPitchesr7  updateAccidentalDisplay)
noteOrChordr(  r)  rG  r+  r,  r-  r.  r/  rF  s
             rQ   makeOrnamentalAccidentalsrL    s    " &&#{3344$$[1$$##-)!5'))E 	$ 	G  ...I% 'r   c              #    #    U(       a  U R                  5       OU R                  5       n/ nSnUR                   H  nSnUR                  (       a;  UR                  R	                  S5      (       a  UR                  R                  S5      nUS:X  a  SnU(       a  UR                  U5        US:X  a
  Uv   / nSnM  U(       a  M  U(       a  M  U/v   M     U(       a  Uv   gg7f)a?  
Generator that yields a List of NotRest objects that fall within a beam group.

If `skipNoBeams` is True, then NotRest objects that have no beams are skipped.

Recurse is True by default.

Unclosed beam groups (like start followed by a Rest before a stop), currently
will continue to yield until the first stop, but this behavior may change at any time in
the future as beaming-over-barlines with multiple voices or beaming across
Parts or PartStaffs is supported.

>>> from music21.stream.makeNotation import iterateBeamGroups
>>> sc = converter.parse('tinyNotation: 3/4 c8 d e f g4   a4 b8 a16 g16 f4')
>>> sc.makeBeams(inPlace=True)
>>> for beamGroup in iterateBeamGroups(sc):
...     print(beamGroup)
[<music21.note.Note C>, <music21.note.Note D>]
[<music21.note.Note E>, <music21.note.Note F>]
[<music21.note.Note B>, <music21.note.Note A>, <music21.note.Note G>]

>>> for beamGroup in iterateBeamGroups(sc, skipNoBeams=False):
...     print(beamGroup)
[<music21.note.Note C>, <music21.note.Note D>]
[<music21.note.Note E>, <music21.note.Note F>]
[<music21.note.Note G>]
[<music21.note.Note A>]
[<music21.note.Note B>, <music21.note.Note A>, <music21.note.Note G>]
[<music21.note.Note F>]

If recurse is False, assumes a flat Score:

>>> for beamGroup in iterateBeamGroups(sc, recurse=False):
...     print(beamGroup)

>>> for beamGroup in iterateBeamGroups(sc.flatten(), recurse=False):
...     print(beamGroup)
[<music21.note.Note C>, <music21.note.Note D>]
[<music21.note.Note E>, <music21.note.Note F>]
[<music21.note.Note B>, <music21.note.Note A>, <music21.note.Note G>]

* New in v6.7.
FNr    r   Tr   )r`   r   notesr;   getByNumbergetTypeByNumberr.   )r?   skipNoBeamsr`   iteratorcurrent_beam_groupin_beam_groupelfirst_el_types           rQ   iterateBeamGroupsrW    s     ` IPUVU[U[U]H-/Mnn"&88,,Q//HH44Q7MG# M%%b)F"$$!#!M]]$J      s   B>C#C#C#setNewStems overrideConsistentStemDirectionsc               >    [        U SSS9 H  n[        UUUS9  M     g)aP  
Find all beam groups and set all the `stemDirection` tags for notes/chords
in a beam group to point either up or down.  If any other stem direction is
encountered ('double', 'noStem', etc.) that note is skipped.

If all notes have the same (non-unspecified) direction, then they are left alone unless
`overrideConsistentStemDirections` is True (default: False).  For instance,
:meth:`~music21.clef.Clef.getStemDirectionForPitches` might say "down" but
if everything in the beamGroup is either

if `setANewStems` is True (as by default), then even notes with stemDirection
of 'unspecified' get a stemDirection.

The method currently assumes that the clef does not change within a beam group.  This
assumption may change in the future without notice.

Operates in place.  Run `copy.deepcopy(s)` beforehand for a non-inPlace version.

* New in v6.7.
T)rQ  r`   rX  N)rW  setStemDirectionOneGroup)r?   rY  rZ  	beamGroups       rQ   r=   r=   O  s)    6 'qdDI	 #-M	
 Jr   c                  U (       d  gU  Vs1 s H!  nUR                   S;   d  M  UR                   iM#     nnSU;   a  SnO[        U5      S:  a  SnOSnU S   R                  [        R                  5      nUc  gUn/ nU  H  nUR                  UR                  5        M      U(       d  gUR                  U5      n	U  HB  nUR                   n
U
S:X  a	  U(       d  M  U
S;   a  U(       d	  U(       a  M4  U
S;   d  M<  Xl         MD     gs  snf )	z
Helper function to set stem directions for one beam group (or perhaps a beat, etc.)

See setStemDirectionForBeamGroups for detailed information.

* New in v6.7.
N)updownunspecifiedra  F   Tr   )r_  r`  )stemDirectionr0   r*   r   rq   rD  r5  getStemDirectionForPitches)grouprY  rZ  rH   stem_directionshas_consistent_stem_directionsoptional_clef_contextclef_context	pitchListgroupStemDirectionnoteDirections              rQ   r\  r\  r  s    05 L1//-JJ 'qO L').&	_		!)-&).& -2!H,F,Ftyy,Q$3L#%I# %@@KM)+~-60;;0O /Ls
   DD)r`   addTiesc                  U(       a  U R                  SSS9nOU /nU GH  n[        UR                  5      nSnSnU GH  nUR                  R                  (       al  UR                  R
                  (       aQ  Ub  XhR                  R                  S   :X  a2  UR                  R                  S   n[        UR                  U-   5      nOSnSnM  [        UR                  R                  S   R                  5       U-
  5      n	U	S:X  a  SnSnM  UR                  [        R                  SS9n
U
(       a3  U
R                  [        UR                  UR                  -   5      :w  a  GM(  U
(       d  GM2  U
R                  R
                  (       d  GMP  SU	s=:  a  U
R                  :  d  GMj  O  GMo  U
R                  XS9u  pUR                  U
R                  U	-   U5        GM     GM     g)a  
Split notes or rests if doing so will complete any incomplete tuplets.
The element being split must have a duration that exceeds the
remainder of the incomplete tuplet.

The first note is edited; the additional notes are inserted in place.
(Destructive edit, so make a copy first if desired.)
Relies on :meth:`~music21.stream.base.splitAtQuarterLength`.

* New in v8.

>>> from music21.stream.makeNotation import splitElementsToCompleteTuplets
>>> s = stream.Stream(
...    [note.Note(quarterLength=1/3), note.Note(quarterLength=1), note.Note(quarterLength=2/3)]
... )
>>> splitElementsToCompleteTuplets(s)
>>> [el.quarterLength for el in s.notes]
[Fraction(1, 3), Fraction(2, 3), Fraction(1, 3), Fraction(2, 3)]
>>> [el.tie for el in s.notes]
[None, <music21.tie.Tie start>, <music21.tie.Tie stop>, None]

With `recurse`:

>>> m = stream.Measure([note.Note(quarterLength=1/6)])
>>> m.insert(5/6, note.Note(quarterLength=1/6))
>>> m.makeRests(inPlace=True, fillGaps=True)
>>> p = stream.Part([m])
>>> splitElementsToCompleteTuplets(p, recurse=True)
>>> [el.quarterLength for el in p.recurse().notesAndRests]
[Fraction(1, 6), Fraction(1, 3), Fraction(1, 3), Fraction(1, 6)]
TstreamsOnlyincludeSelfNr!   r   activeSiteOnly)rm  )r`   r'   r/   r   r   expressionIsInferredr   r4   r   nextr   GeneralNoterM   r   ro   )r?   r`   rm  rR  	containergeneral_noteslast_tupletpartial_tuplet_sumgnql_to_completenext_gnunused_left_edited_in_placerights                rQ   splitElementsToCompleteTupletsr    s   N 9949@3	Y445,0'*B##KK44 (K;;;N;Nq;Q,Q kk11!4%+B,<,<?Q,Q%R""%("###A&88:=OOQN$"%("ggd..tgDG7>>VBII@P@P4P-QQw7++@@@~=(=(===9@9U9U& :V :96/$$W^^n%DeL3  	 r   )r`   
onlyIfTiedc               n  ^ SU4S jjnU(       a  U R                  SSS9nOU /nU GH  nUR                   Vs/ s H  oc" U5      (       d  M  UPM     nn/ nSn	Sn
SnU GHH  nUR                  [        R                  SS9nX;   Ga  [        U[        R                  5      (       a  [        U[        R                  5      (       d[  [        U[        R                  5      (       GaJ  [        U[        R                  5      (       Ga*  UR                  UR                  :X  Ga  [        UR                  UR                  -   5      UR                  :X  a  [        UR                  R                  5      S:X  a  UR                  R                  S   U
:X  a  [        XR                  -   5      n	UR                  U5        X:X  ao  S	UR                   l        US   nUSS  H  nUR#                  U5        M     UR                  R%                  5         S
UR                  l        Xl        / nSn	Sn
SnGM  GM  UR                  R                  (       aU  UR                  n	UR                  R                  S   n
[&        R(                  (       a  U
c   eU
R+                  5       nU/nGM@  / nSn	Sn
SnGMK     GM     gs  snf )a  
Locate consecutive notes or rests in `s` (or its substreams if `recurse` is True)
that are unnecessarily expressed as tuplets and replace them with a single
element. These groups must:

    - be consecutive (with respect to :class:`~music21.note.GeneralNote` objects)
    - be all rests, or all :class:`~music21.note.NotRest`s with equal `.pitches`
    - all have :attr:`~music21.duration.Duration.expressionIsInferred` = `True`.
    - sum to the tuplet's total length
    - if `NotRest`, all must be tied (if `onlyIfTied` is True)

The groups are consolidated by prolonging the first note or rest in the group
and removing the subsequent elements from the stream. (Destructive edit,
so make a copy first if desired.)

* New in v8.

>>> s = stream.Stream()
>>> r = note.Rest(quarterLength=1/6)
>>> s.repeatAppend(r, 5)
>>> s.insert(5/6, note.Note(duration=r.duration))
>>> from music21.stream.makeNotation import consolidateCompletedTuplets
>>> consolidateCompletedTuplets(s)
>>> [el.quarterLength for el in s.notesAndRests]
[0.5, Fraction(1, 6), Fraction(1, 6), Fraction(1, 6)]

`mustBeTied` is `True` by default:

>>> s2 = stream.Stream()
>>> n = note.Note(quarterLength=1/3)
>>> s2.repeatAppend(n, 3)
>>> consolidateCompletedTuplets(s)
>>> [el.quarterLength for el in s2.notesAndRests]
[Fraction(1, 3), Fraction(1, 3), Fraction(1, 3)]

>>> consolidateCompletedTuplets(s2, onlyIfTied=False)
>>> [el.quarterLength for el in s2.notesAndRests]
[1.0]

Does nothing if tuplet definitions are not the same. (In which case, see
:class:`~music21.duration.TupletFixer` instead).

>>> s3 = stream.Stream([note.Rest(quarterLength=1/3), note.Rest(quarterLength=1/6)])
>>> for my_rest in s3.notesAndRests:
...   print(my_rest.duration.tuplets)
(<music21.duration.Tuplet 3/2/eighth>,)
(<music21.duration.Tuplet 3/2/16th>,)
>>> consolidateCompletedTuplets(s)
>>> [el.quarterLength for el in s3.notesAndRests]
[Fraction(1, 3), Fraction(1, 6)]

Does nothing if there are multiple (nested) tuplets.
c                   > U R                   R                  =(       aX    [        U R                   R                  5      S:  =(       a/    U R                  =(       d    U R
                  S L=(       d    T(       + $ )Nrb  )r   rt  r0   r   isRestr   )r{  r  s    rQ   is_reexpressible5consolidateCompletedTuplets.<locals>.is_reexpressible-  sT    KK,, DBKK''(1,DBbffD0B
N	
r   Tro  r!   Nrr  r    r   F )r{  znote.GeneralNoter   bool)r`   r/   previousr   rv  r%   r   r  r5  r   rM   r4   r0   r   r   r.   r>   r2   clearr   TYPE_CHECKINGr   )r?   r`   r  r  rR  rw  r{  reexpressibleto_consolidaterz  ry  completion_targetprev_gnfirst_note_in_group
other_notes     `            rQ   consolidateCompletedTupletsr    sN   x
 9949@3	&/&=&=V&=AQRTAU&=V13'*,0+/Bkk$"2"24kHG)DII..:gtyy3Q3Q"2t||44&w==JJ'//9 7>>G,A,AABbiiO++,1bkk6I6I!6LP[6[%+,>AQAQ,Q%R"%%b)%:5:I**2*8*;'&4QR&8
!((4 '9'00668;='0088I5 &(N),&"&K(,% ;" ;;&&)+)9)9&"$++"5"5a"8K*666(3(E(E(G%&(TN%'N),&"&K(,%]   Vs   J2J2c              #  (  #    0 nU R                    HB  nUR                  b$  UR                  R                  U[        U5      '   M4  SU[        U5      '   MD      Sv   U R                    H  nUR                  b,  UR	                  [        U5      S5      UR                  l        M<  UR	                  [        U5      S5      SL d  M\  [
        R                  " S5      Ul        SUR                  l        M     g! U R                    H  nUR                  b,  UR	                  [        U5      S5      UR                  l        M<  UR	                  [        U5      S5      SL d  M\  [
        R                  " S5      Ul        SUR                  l        M     f = f7f)a  
Restore accidental displayStatus on a Stream after an (inPlace) operation
that sets accidental displayStatus (e.g. a transposition).  Note that you
should not do this unless you know that the displayStatus values will still
be valid after the operation.

>>> sc = corpus.parse('bwv66.6')
>>> intv = interval.Interval('P8')
>>> classList = (key.KeySignature, note.Note)
>>> with stream.makeNotation.saveAccidentalDisplayStatus(sc):
...     sc.transpose(intv, inPlace=True, classFilterList=classList)

* New in v9.
NFTr   )r5  
accidentaldisplayStatusr   getr   
Accidental)r?   displayStatusesr   s      rQ   saveAccidentalDisplayStatusr  o  s3      -/OYY<<#%&\\%?%?OBqE"!&1	 	2A||'-<-@-@A-M*""2a5%0D8$//2-1* A||'-<-@-@A-M*""2a5%0D8$//2-1* s,   AFC5 A$F1F5A%F1FFc                  ^    \ 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  z6
Note: most Stream tests are found in stream/tests.py
zGtinyNotation: 2/2 c8 d e f   trip{a b c' a b c'}  f' e' d' G  a b c' d'c                   SSK Jn  UR                  " 5       n[        R                  " 5       nUR                  US5        U R                  [        U5      S5        [        U5        U R                  [        U5      S5        U R                  US   R                  S   S5        U R                  [        US   5      S5        U R                  [        [        UR                  S   R                  5      5      S5        g )Nr   r      r    r   z\[<music21.note.Note C>, <music21.note.Note C>, <music21.note.Note C>, <music21.note.Note C>])r#   r   r\   r   NoterepeatAppendassertEqualr0   r   classesstrr'   r-   r/   )selfr   r?   n1s       rQ   testNotesToVoicesTest.testNotesToVoices  s    "MMOYY[	r1Q#!Q#1a'2QqTA&T!((1+";";<=K	Lr   c                T  ^  SSK Jn  UR                  T R                  5      nUR	                  SSS9  [        U5      u  p4pVU 4S jnU" US/S-  5        [        USS	9  U" US/S-  5        [        U5        U" US
/S-  5        U H
  nSUl        M     [        U5        U" US/S-  5        [        USS9  U" US
/S-  5        [        U5        U" US/S-  5        [        U5        U" US
/S-  5        / SQn	[        U5       H  u  pX   Ul        M     [        U5        U" U/ SQ5        g )Nr   	converterTFr   r   c                   > TR                  [        U 5      [        U5      5        [        X5       H!  u  p#TR                  UR                  U5        M#     g r   )r  r0   ziprc  )re  expected	groupNoteexpectedStemDirectionr  s       rQ   testDirections9Test.testSetStemDirectionOneGroup.<locals>.testDirections  sE    SZX7474H0	  !8!8:OP 5Ir   ra  r  )rY  r_  r`  )rZ     r`  noStemdoubler_  r`  r  r  r`  )	r#   r  parseallaBreveBeamTestr   rW  r\  rc  r:   )r  r  r   abcrI   r  rH   dStemsrO   s   `          rQ   testSetStemDirectionOneGroup!Test.testSetStemDirectionOneGroup  s*   %OOD223	DE:&q)
a	Q
 	q=/A-. 6q=/A-. #q4&1*%A$AO  #q6(Q,' TJq4&1*% #q6(Q,' 	!#q4&1*%3aLDA$iAO ! #q>?r   c                   SSK Jn  UR                  U R                  5      nUR	                  SSS9  [        [        U5      5      S   n/ SQn[        U5       H  u  pVXE   Ul        M     [        U5        U R                  UR                  5       R                   Vs/ s H  ofR                  PM     snS/S	-  S
/S-  -   S/S	-  -   / SQ-   5        g s  snf )Nr   r  TFr  r1  r  r_  r  r`  r  r  )r#   r  r  r  r   r'   rW  r:   rc  r=   r  rk   rN  )r  r  r   rI   r  rO   rH   s          rQ   !testSetStemDirectionForBeamGroups&Test.testSetStemDirectionForBeamGroups  s    %OOD223	DE:"1%&r*3aLDA$iAO ! 	&a(199;3D3DE3Da//3DE!vhl2dVaZ??@	Es   Cc                    SSK Jn  UR                  S5      nUR                  SS9  U R	                  UR                  5       R                   Vs/ s H  o3R                  PM     sn/ SQ5        / SQn[        UR                  5       R                  U5       H  u  p5XSl        M     [        USSS	9  U R	                  UR                  5       R                   Vs/ s H  o3R                  PM     sn/ S
Q5        gs  snf s  snf )z
Stems that would all be up, starting from scratch,
but because of overrideConsistentStemDirections=False,
we only change the first group with an "unspecified" direction
r   r  ztinyNotation: 2/4 b8 f8 a8 b8Tr   )r_  r_  r_  r_  )r`  ra  r`  r`  FrX  )r_  r_  r`  r`  N)
r#   r  r  r   r  rk   rN  rc  r  r=   )r  r  r   rH   r  stemDirs         rQ   testSetStemDirectionConsistency$Test.testSetStemDirectionConsistency  s     	&OO;<	D!&'iik&7&78&7__&78$	
 9aiik//8JA%O 9 	&aT\ab&'iik&7&78&7__&78(	
 9 9s   C6C;c                   SSK Jn  UR                  U R                  5      n/ SQn[	        UR                  5       R                  SS  5       H  u  pEX4   Ul        M     UR                  SS9  U R                  UR                  5       R                   Vs/ s H  oUR                  PM     snS/S-  S	/S
-  -   S/S-  -   / SQ-   5        g s  snf )Nr   r  r  Tr   r_  r  r`  r  r  )
r#   r  r  r  r:   rk   rN  rc  r   r  )r  r  r   r  rO   rH   s         rQ   testMakeBeamsWithStemDirection#Test.testMakeBeamsWithStemDirection  s    %OOD2233aiik//45DA$iAO 6	D!199;3D3DE3Da//3DE!vhl2dVaZ??@	Es   C	c                f   SSK Jn  UR                  S5      n[        R                  " S5      nSUl        [        R                  " S5      nSUl        UR                  S5      R                  SU5        UR                  S5      R                  SU5        / UR                  5       R                  S   l	        / UR                  5       R                  S   l	        UR                  SS9  U R                  UR                  5       R                   Vs/ s H  oUR                  PM     snS	S	/5        g s  snf )
Nr   r  ztinyNotation: 4/4zd fg      ?r    Tr   ra  )r#   r  r  r	   Chordr4   rc   ro   rk   rN  makeNotationr  rc  )r  r  r   c1c2rH   s         rQ   testMakeBeamsOnEmptyChordTest.testMakeBeamsOnEmptyChord	  s    %OO/0[[[[			!Ar"			!C$%'		!"%'		!"	t$&'iik&7&78&7__&78M*	
8s   D.c                   SSK Jn  SSK Jn  UR                  S5      nX2R                     R                  5       nU R                  UR                  5        UR                  R                  5       nU R                  [        UR                  R                  5      S5        UR                  SS9  U R                  [        UR                  R                  5      S5        X2R                     R                  5       nS Ul        SnU R                  UR                   U5         UR                  SSS	9  S S S 5        g ! , (       d  f       g = f)
Nr   r  r   z tinyNotation: 2/4 r2 d8 d8 d8 d8Tr   r    r   )r   r   )r#   r  r   r  r&   lastassertIsNoner)   rN  rs   r  r0   r;   rN   r   assertRaisesRegexr   )r  r  r   r   m2m2_n0m1msgs           rQ   'testMakeBeamsFromTimeSignatureInContext,Test.testMakeBeamsFromTimeSignatureInContext	  s    %"OO>?~~##%"**+ U[[223Q7
T"U[[223Q7 ~~$$&J##F$:$:C@LLTLB A@@s   D77
Ec                J   SSK Jn  SSK Jn  UR                  U R                  5      nU R                  UR                  5       nUR                  [        R                  " 5       S9  S S S 5        U R                  [        WR                  5      S5        g ! , (       d  f       N4= f)Nr   r  r   )rT   r_   )r#   r  r   r  r  assertRaisesr   ra   r   Durationr  r  	exception)r  r  r   r   cms        rQ   testStreamExceptionsTest.testStreamExceptions&	  st    %"OOD223v556"NNx'8'8':N; 7R\\*B	D 76s   #B
B"c                   SSK Jn  UR                  " 5       nUR                  " SS9nUR	                  S[
        R                  " S5      5        UR	                  S[        R                  " SSS95        UR                  " S	S9nUR	                  S[
        R                  " S
5      5        UR	                  S[        R                  " SSS95        UR                  " SS9nUR	                  S[        R                  " SSS95        UR                  X4U/5        UR                  5       nU R                  [        XaR                     5      S5        U R                  XaR                     R                  5       R                  R                  5       R                  R                   S5        U R                  XaR                     S   R                  R                  5       R                  R                   S5        U R                  [        XaR                     S	   R                  5      S5        U R                  XaR                     S	   R                  R                  5       R                  R                   S5        g)z
From a real-world failure.  Should not be
making ties in an example that starts with a short TS
but moves to a longer one and all is valid.
r   r   r    r{   z3/4C4g      @)r4   rb  z6/1D4g      8@   E4N)r#   r   Partr&   ro   r   r+   r   r  r.   r   r  r0   rs   rN  r   r4   )r  r   r   r  r  m3pps          rQ   "testMakeTiesChangingTimeSignatures'Test.testMakeTiesChangingTimeSignatures/	  s    	#KKM^^1%
		!U((/0
		!TYYt378^^1%
		!U((/0
		!TYYt489^^1%
		!TYYt489	""ZZ\R/0!4NN+11399??AJJXXZ]^NN+A.44::<EESSUYZR/28891=NN+A.44::<EESSUYZr   c                   SSK Jn  SSK Jn  UR                  " [        R
                  " S5      [        R                  " S5      [        R                  " S5      /5      nSUR                  S   R                  l
        SUR                  S   R                  R                  l        SUR                  S   R                  l
        S	UR                  S   R                  R                  l        [        R                  [        R                  [        R                  4n[        U5         UR!                  UR#                  S
5      SUS9  U R%                  UR                  S   R&                  S5        U R)                  UR                  S   R                  R                  R                  5        U R%                  UR                  S   R&                  S5        U R)                  UR                  S   R                  R                  R                  5        S S S 5        U R%                  UR                  S   R&                  S5        U R+                  UR                  S   R                  R                  R                  S5        U R%                  UR                  S   R&                  S5        U R+                  UR                  S   R                  R                  R                  S	5        g ! , (       d  f       N= f)Nr   )intervalr   CC2D2Tr    Fr  )r   r   zD-2zE-2)r#   r  r   r&   r   Keyr   r  rN  r   r  r  r	   r  r3  r  	transposeIntervalr  r#  r  assertIs)r  r  r   rC   	classLists        rQ   testSaveAccidentalDisplayStatus$Test.testSaveAccidentalDisplayStatusG	  s    $"NNCGGCL$))D/499T?KL&'
#48
##1&'
#49
##1YYS-=-=>	(+KK))$/yKYQWWQZ66>aggaj..99GGHQWWQZ66>aggaj..99GGH , 	22E:aggaj&&11??F22E:aggaj&&11??G ,+s   $C+K$$
K2c                  ^^	 SSK JmJm	  UU	4S jnU" 5       nUR                  SS9  UR	                  5       nU R                  UR                  5       R                  S   R                  T	R                  S5      5        U R                  UR                  5       R                  S   R                  T	R                  S	5      5        U R                  UR                  5       R                  S   R                  5        UR	                  SS9  U R                  UR                  5       R                  S   R                  T	R                  S5      5        U R                  UR                  5       R                  S   R                  T	R                  S	5      5        TR                  " 5       nU" 5       nS
Ul        U" 5       nSUl        UR                  SU5        UR                  U5        UR                  SS9  UR	                  5       nU R                  UR                  R                  5       [         R"                     S   R                  T	R                  S5      5        U R                  UR                  R                  5       [         R"                     S   R                  5        UR	                  SS9  U R                  UR                  S   [         R"                     S   R                  T	R                  S	5      5        g )Nr   )r   r   c                 d  > TR                   " SS9n TR                  " SS9nTR                  " SS9nUR                  [        R
                  " S5      5        [        R                  " SSSS	9n[        R                  " S
SS9nT	R                  S5      Ul	        UR                  X4/5        TR                  " SS9n[        R                  " S
SS9nT	R                  S5      Ul	        [        R                  " SSS9nUR                  Xg/5        UR                  X%/5        U R                  SU5        U $ )N	mainScore)r   part0r    r  rb   Dhalf)r   dotsr  quarter)r   r   rb  r   r   )Scorer  r&   r.   r   r+   r   r  Tier   ro   )
scp0m01d1r  m02r  c3r   r   s
           rQ   getScore0Test.testMakeNotationRecursive.<locals>.getScore`	  s    -B(B..*CJJu**5123V!4B3Y/BWWW%BFJJx ..*C3Y/BWWV_BF3V,BJJx IIsj!IIaIr   Tr   r    r   rb  r   score1score2)r#   r   r   	stripTiesr   r  rk   rN  r  r  r   r   ro   r.   r   rs   r   r  )
r  r	  r?   ssops1s2oppr   r   s
           @@rQ   testMakeNotationRecursiveTest.testMakeNotationRecursive]	  s    '	( J	D!ZZ\++A.22CGGG4DE++A.22CGGFOD!))+++A.223	

4
 **1-1137773CD**1-113776?C[[]ZZ
		!R
		"
T"kkm))+DII6q9==swww?OP"))//+DII6q9==>
D!1dii0377Ir   r  N)__name__
__module____qualname____firstlineno____doc__r  r  r  r  r  r  r  r  r  r  r  r  __static_attributes__r  r   rQ   r  r    sO     bL "@H
2

"C&D[0H,.Jr   r  __main__)r?   r   r   zStreamType | None)r?   r   r   r   ))rv  )r  r   r   None)r$  z'music21.note.NotRest'r   set[str] | None)r?   zStreamType | StreamIteratorr(  list[pitch.Pitch] | Noner)  r  r*  zbool | key.KeySignaturer+  r  r,  r  r-  r  r.  r  r/  r  r%  r  r   r  )r?   r   r   zlist[pitch.Pitch])rK  znote.Note | chord.Chordr(  r  r)  r  rG  r  r+  r  r,  r  r-  r  r.  r  r/  r  )TT)r?   r   r   z)Generator[list[note.NotRest], None, None])r?   r   r   r  )re  zlist[note.NotRest]r   r  )r?   stream.Streamr`   r  rm  r  r   r  )r?   r  r`   r  r  r  r   r  )r   zt.Generator[None, None, None])>
__future__r   collections.abcr   r   
contextlibri   typingr   unittestr#   r   r   r   r	   r
   r   r   r   r   r   r   r   music21.common.numberToolsr   music21.common.typesr   r   music21.exceptions21r   r  	fractionsr   r   music21.stream.iteratorr   Environment__file__r   r   ra   r   rv  r   r   r  r   r'  rA  r7  rL  rW  r=   r\  r  r  contextmanagerr  TestCaser  r  mainTestr  r   rQ   <module>r/     s   # /                 - 5 0 ??"6 &&x0 qq qn ]/]/ ]/F "QQ Ql  %%'yy yx 27 xvK^ '7;?"7x )-/3-1-1!% )-!%^* ^* &^* -	^*
 +^* +^* ^* ^* ^* #'^* ^* 
^*@8 )-/37;-1!% )-#/&#/ &#/ -	#/
 5#/ +#/ #/ #/ #/ #'#/N D!D! /	D!T %*	 
 

 
 
L %*	0101
 
01l 	IMIM IM 	IM
 
IM^ 	|-|- |- 	|-
 
|-| 2 2HwJ8 wJv zT r   