
    rh3                       S r SSKJr  SSKrSSKJr  SSKJr  SSKJr  SSKJr  SSKJ	r	  \R                  " S	5      r " S
 S\R                  5      r/ SQrSSS.rSSS.r1 SkrS rS r " S S\R(                  5      r " S S\	R,                  \5      r " S S\R0                  5      r\S:X  a  SSKr\R6                  " \5        gg)z7
Object models of barlines, including repeat barlines.
    )annotationsN)base)environment)exceptions21)expressions)repeatbarc                      \ rS rSrSrg)BarException    N)__name__
__module____qualname____firstlineno____static_attributes__r       E/home/james-whalen/.local/lib/python3.13/site-packages/music21/bar.pyr   r      s    r   r   )regulardotteddashedheavydoublefinalheavy-lightheavy-heavytickshortnoner   r   )light-lightlight-heavyr    r!   )r   r   >   r   r   r   r   r   c                d    U R                  5       [        ;   a  [        U R                  5          $ U $ )a~  
Convert a music21 barline name into the musicxml name --
essentially just changes the names of 'double' and 'final'
to 'light-light' and 'light-heavy'

Does not do error checking to make sure it's a valid name,
since setting the style on a Barline object already does that.

>>> bar.typeToMusicXMLBarStyle('final')
'light-heavy'
>>> bar.typeToMusicXMLBarStyle('regular')
'regular'
)lowerreverseBarTypeDictvalues    r   typeToMusicXMLBarStyler'   5   s)     {{}**!%++-00r   c                    U c  gU R                  5       n U [        ;   a  U $ U [        ;   a	  [        U    $ [        SU  35      e)z
Standardizes bar type names.

converts all names to lower case, None to 'regular',
and 'light-light' to 'double' and 'light-heavy' to 'final',
raises an error for unknown styles.
r   zcannot process style: )r#   barTypeListbarTypeDictr   r%   s    r   standardizeBarTyper+   H   sL     }KKME	+	5!! 3E7;<<r   c                     ^  \ rS rSrSr\" \R                  5       5      rSr	Sr
  SU 4S jjrS rS rS r\" \\S	S
9rS rSrU =r$ )Barline_   a  
A representation of a barline.
Barlines are conventionally assigned to Measure objects
using the leftBarline and rightBarline attributes.

>>> bl = bar.Barline('double')
>>> bl
<music21.bar.Barline type=double>

The type can also just be set via a keyword of "type".  Or if no type is specified,
a regular barline is returned.  Location can also be explicitly stored, but it's not
needed except for musicxml translation:

>>> bl2 = bar.Barline(type='dashed')
>>> bl2
<music21.bar.Barline type=dashed>
>>> bl3 = bar.Barline()
>>> bl3
<music21.bar.Barline type=regular>
>>> bl4 = bar.Barline(type='final', location='right')
>>> bl4
<music21.bar.Barline type=final>
>>> bl4.type
'final'

Note that the barline type 'ticked' only is displayed correctly in Finale and Finale Notepad.

N.B. for backwards compatibility reasons, currently
Bar objects do not use the style.Style class since
the phrase "style" was already used.
)typepauselocationc                Z   > [         TU ]  " S0 UD6  S U l        Xl        S U l        X l        g )Nr   )super__init___typer0   r1   r2   )selfr0   r2   keywords	__class__s       r   r5   Barline.__init__   s1     	$8$
	 
 !r   c                     SU R                    3$ )Nztype=)r0   r7   s    r   _reprInternalBarline._reprInternal   s    tyyk""r   c                    U R                   $ N)r6   r<   s    r   _getTypeBarline._getType   s    zzr   c                $    [        U5      U l        g r@   )r+   r6   r7   r&   s     r   _setTypeBarline._setType   s    '.
r   a+  
        Get and set the Barline type property.

        >>> b = bar.Barline()
        >>> b.type = 'tick'
        >>> b.type
        'tick'

        Synonyms are given for some types, based on
        musicxml styles:

        >>> b.type = 'light-light'
        >>> b.type
        'double'
        )docc                ,    [        U R                  5      $ )aR  
returns the musicxml style for the bar.  most are the same as
`.type` but "double" and "final" are different.

>>> b = bar.Barline('tick')
>>> b.musicXMLBarStyle()
'tick'

>>> b.type = 'double'
>>> b.musicXMLBarStyle()
'light-light'

>>> b.type = 'final'
>>> b.musicXMLBarStyle()
'light-heavy'

* Changed in v5.7: was a property before.
)r'   r0   r<   s    r   musicXMLBarStyleBarline.musicXMLBarStyle   s    & &dii00r   )r6   r2   r1   r0   )NN)r   r   r   r   __doc__listr*   keysvalidStylesclassSortOrderequalityAttributesr5   r=   rA   rE   propertyr0   rI   r   __classcell__)r9   s   @r   r-   r-   _   sc    > {'')*KN6 !"#/ HhD"1 1r   r-   c                      \ rS rSrSrSSS jjrS r\SS j5       r\R                  SS j5       r\SS j5       r
\
R                  SS	 j5       r
SS
 jrSrg)Repeat   a  
A Repeat barline.

The `direction` parameter can be one of `start` or `end`.
An `end` followed by a `start`
should be encoded as two `bar.Repeat` signs.

>>> rep = bar.Repeat(direction='end', times=3)
>>> rep
<music21.bar.Repeat direction=end times=3>

To apply a repeat barline assign it to either the `.leftBarline` or
`.rightBarline` attribute
of a measure.

>>> m = stream.Measure()
>>> m.leftBarline = bar.Repeat(direction='start')
>>> m.rightBarline = bar.Repeat(direction='end')
>>> m.insert(0.0, meter.TimeSignature('4/4'))
>>> m.repeatAppend(note.Note('D--5'), 4)
>>> p = stream.Part()
>>> p.insert(0.0, m)
>>> p.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
    {0.0} <music21.bar.Repeat direction=start>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note D-->
    {1.0} <music21.note.Note D-->
    {2.0} <music21.note.Note D-->
    {3.0} <music21.note.Note D-->
    {4.0} <music21.bar.Repeat direction=end>

The method :meth:`~music21.stream.Part.expandRepeats` on a
:class:`~music21.stream.Part` object expands the repeats, but
does not update measure numbers

>>> q = p.expandRepeats()
>>> q.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
    {0.0} <music21.bar.Barline type=double>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note D-->
    {1.0} <music21.note.Note D-->
    {2.0} <music21.note.Note D-->
    {3.0} <music21.note.Note D-->
    {4.0} <music21.bar.Barline type=double>
{4.0} <music21.stream.Measure 0a offset=4.0>
    {0.0} <music21.bar.Barline type=double>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note D-->
    {1.0} <music21.note.Note D-->
    {2.0} <music21.note.Note D-->
    {3.0} <music21.note.Note D-->
    {4.0} <music21.bar.Barline type=double>
Nc                    [         R                  R                  U 5        US:X  a  SnOSn[        R                  " U 4SU0UD6  S U l        S U l        Xl        X l        g )Nstartr   r   r0   )r   
RepeatMarkr5   r-   
_direction_times	directiontimes)r7   r[   r\   r8   barTypes        r   r5   Repeat.__init__  sZ    ""4(#GG8G8x8$( $ #
r   c                b    SU R                    3nU R                  b  USU R                   3-  nU$ )Nz
direction=z times=)r[   r\   )r7   msgs     r   r=   Repeat._reprInternal  s7    4>>*+::!WTZZL))C
r   c                J    U R                   c  [        S5      eU R                   $ )zx
Get or set the direction of this Repeat barline. Can be start or end.

TODO: show how changing direction changes type.
z1_direction unexpectedly None after initialization)rY   r   r<   s    r   r[   Repeat.direction#  s$     ??"RSSr   c                    UR                  5       S;   aF  UR                  5       U l        U R                  S:X  a  SU l        g U R                  S:X  a  SU l        g g [        SU 35      e)N)rW   endre   r   rW   r   z cannot set repeat direction to: )r#   rY   r0   r   rD   s     r   r[   rc   .  s^    ;;=,,#kkmDO%'#	G+)	 , !A%IJJr   c                    U R                   $ )ac  
Get or set the "times" property of this barline. This
defines how many times the repeat happens. A standard repeat
repeats 2 times; values equal to or greater than 0 are permitted.
A repeat of 0 skips the repeated passage.

>>> lb = bar.Repeat(direction='start')
>>> rb = bar.Repeat(direction='end')

Only end expressions can have times:

>>> lb.times = 3
Traceback (most recent call last):
music21.bar.BarException: cannot set repeat times on a start Repeat

>>> rb.times = 3
>>> rb.times = -3
Traceback (most recent call last):
music21.bar.BarException: cannot set repeat times to a value less than zero: -3
)rZ   r<   s    r   r\   Repeat.times9  s    , {{r   c                    Uc  S U l         g  [        U5      nUS:  a  [        SU 35      eU R                  S:X  a  [        S5      eX l         g ! [         a    [        SU< 35      ef = f)Nzcannot set repeat times to: r   z3cannot set repeat times to a value less than zero: rW   z)cannot set repeat times on a start Repeat)rZ   int
ValueErrorr   r[   )r7   r&   	candidates      r   r\   rg   Q  s    =DKJ	 1}"I%Q  ~~("#NOO#K  "25)< s   A A(c                R    U U R                    U 3n[        R                  " U5      $ )a  
Return a configured :class:`~music21.expressions.TextExpressions`
object describing the repeat times. Append this to the stream
for annotation of repeat times.

>>> rb = bar.Repeat(direction='end')
>>> rb.times = 3
>>> rb.getTextExpression()
<music21.expressions.TextExpression '3x'>

>>> rb.getTextExpression(prefix='repeat ', postfix=' times')
<music21.expressions.TextExpression 'repeat 3 t...'>
)rZ   r   TextExpression)r7   prefixpostfixr&   s       r   getTextExpressionRepeat.getTextExpressionh  s+     (4;;-y1))%00r   )rY   rZ   r[   r\   r0   )rW   N)r[   strr\   
int | None)returnrr   )r&   rr   )rt   rs   )r&   rs   rt   None) x)r   r   r   r   rK   r5   r=   rQ   r[   setterr\   rp   r   r   r   r   rT   rT      ss    6p   K K  . \\$ $,1r   rT   c                  &    \ rS rSrS rS rS rSrg)Testi{  c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr|   globals)r7   r|   s     r   testCopyAndDeepcopyTest.testCopyAndDeepcopy|  s    7D')$r   c                   SSK Jn  SSK Jn  SSK Jn  SSK Jn  UR                  5       n[        5       nXel        UR                  5       nUR                  U5        UR                  5       nUR                  U5        U R                  US   U5        U R                  US   U5        U R                  US   U5        UR                  5       n	UR                  SU	5        U R                  US   U	5        U R                  US   U5        g )Nr   stream)clef)note)metadata      )music21r   r   r   r   MeasurerT   leftBarlineBassClefappendNoteassertEqualMetadatainsert)
r7   r   r   r   r   mbcnmds
             r   testSortOrderTest.testSortOrder  s    "  $NNHMMO	IIK	 	1q!1q!1q!  	B1r"1q!r   c                   SSK Jn  SSK Jn  SSKJn  U" 5       nU R                  SUR                  5        UR                  U/5      nUR                  USS9nUR                  U5      nUS   nU R                  UR                  S5        g )	Nr   )	converterr   )r-   
StyleMixinpickle)fmtF)r   r   r   music21.barr-   assertNotInclassesStream	freezeStrthawStrr   hasStyleInformation)	r7   r   r   r-   r   sdatas2thawedBarlines	            r   testFreezeThawTest.testFreezeThaw  sz    %"'Iqyy1MM1#""1("3t$1::EBr   r   N)r   r   r   r   r   r   r   r   r   r   r   rz   rz   {  s    %"2Cr   rz   __main__)rK   
__future__r   unittestr   r   r   r   r   r   EnvironmentenvironLocalMusic21Exceptionr   r)   r*   r$   strongBarlineTypesr'   r+   Music21Objectr-   rX   rT   TestCaserz   r   mainTestr   r   r   <module>r      s    #       &&u-	<00 	 
  
 P &=.e1d   e1jc1V c1N+C8 +C\ zT r   