§
    ƒØjs$  ã            
      óh  — d Z ddlmZ ddlmZ ddlZddlm	Z	 ddl
mZ  G d„ dej        ¦  «        Z ej        d	d
efde	fdefdefdefdefg¦  «        Z G d„ d	e¦  «        Z edddddd¬¦  «        Z edde ddd¬¦  «        Z eddeddd¬¦  «        Zedk    rddl
Z
 e
j        ¦   «          dS dS )aæ  
This module defines a single class, SortTuple, which is a named tuple that can
sort against bare offsets and other SortTuples.

This is a performance-critical object.

It also defines three singleton instances of the SortTupleLow class as ZeroSortTupleDefault,
ZeroSortTupleLow and
ZeroSortTupleHigh which are sortTuple at
offset 0.0, priority [0, -inf, inf] respectively:

>>> sorting.ZeroSortTupleDefault
SortTuple(atEnd=0, offset=0.0, priority=0, classSortOrder=0, isNotGrace=1, insertIndex=0)
>>> sorting.ZeroSortTupleLow
SortTuple(atEnd=0, offset=0.0, priority=-inf, classSortOrder=0, isNotGrace=1, insertIndex=0)
>>> sorting.ZeroSortTupleHigh
SortTuple(atEnd=0, offset=0.0, priority=inf, classSortOrder=0, isNotGrace=1, insertIndex=0)
é    )Úannotations)ÚinfN)ÚOffsetQL)Úexceptions21c                  ó   — e Zd ZdS )ÚSortingExceptionN)Ú__name__Ú
__module__Ú__qualname__© ó    ú„/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/music21/sorting.pyr   r   $   s   € € € € € Ø€Dr   r   Ú	SortTupleÚatEndÚoffsetÚpriorityÚclassSortOrderÚ
isNotGraceÚinsertIndexc                  ój   ‡ — e Zd ZdZˆ fd„Zˆ fd„Zˆ fd„Zˆ fd„Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zˆ xZS )r   a³  
    Derived class of namedTuple which allows for comparisons with pure ints/fractions.

    >>> n = note.Note()
    >>> s = stream.Stream()
    >>> s.insert(4, n)
    >>> st = n.sortTuple()
    >>> st
    SortTuple(atEnd=0, offset=4.0, priority=0, classSortOrder=20, isNotGrace=1, insertIndex=...)
    >>> st.shortRepr()
    '4.0 <0.20...>'
    >>> st.atEnd
    0
    >>> st.offset
    4.0

    >>> st < 5.0
    True
    >>> 5.0 > st
    True
    >>> st > 3.0
    True
    >>> 3.0 < st
    True

    >>> st == 4.0
    True

    >>> ts = bar.Barline('double')
    >>> s2 = stream.Stream()
    >>> s2.storeAtEnd(ts)
    >>> ts_st = ts.sortTuple()
    >>> ts_st
    SortTuple(atEnd=1, offset=0.0, priority=0, classSortOrder=-5, isNotGrace=1, insertIndex=...)
    >>> st < ts_st
    True
    >>> ts_st > 999999
    True
    >>> import math
    >>> ts_st == math.inf
    True

    Construct one w/ keywords:

    >>> st = sorting.SortTuple(atEnd=0, offset=1.0, priority=0, classSortOrder=20,
    ...           isNotGrace=1, insertIndex=323)
    >>> st.shortRepr()
    '1.0 <0.20.323>'

    or as tuple:

    >>> st = sorting.SortTuple(0, 1.0, 0, 20, 1, 323)
    >>> st.shortRepr()
    '1.0 <0.20.323>'

    c                óL   •—  t          t          | ¦  «        j        | g|¢R i |¤ŽS ©N)Úsuperr   Ú__new__)ÚclsÚtupElsÚkeywordsÚ	__class__s      €r   r   zSortTuple.__new__j   s0   ø€ à,�u•Y Ñ$Ô$Ô,¨SÐF°6ÐFÐFÐF¸XÐFÐFÐFr   c                ó   •— t          |t          ¦  «        r!t          ¦   «                              |¦  «        S 	 | j        dk    r|t
          k    rdS | j        dk    rdS | j        |k    S # t          $ r
 t          cY S w xY w)Né   FT)	Ú
isinstanceÚtupler   Ú__eq__r   ÚINFINITYr   Ú
ValueErrorÚNotImplemented©ÚselfÚotherr   s     €r   r#   zSortTuple.__eq__n   sŽ   ø€ Ý�e�UÑ#Ô#ð 	)Ý‘7”7—>’> %Ñ(Ô(Ð(ð	"ØŒz˜QŠˆ 5­HÒ#4Ð#4Ø�uØ”˜q’�Ø�tà”{ eÒ+Ð+øÝð 	"ð 	"ð 	"Ý!Ð!Ð!Ð!ð	"øøøó   ¹A) ÁA) Á
A) Á)A=Á<A=c                óÐ   •— t          |t          ¦  «        r!t          ¦   «                              |¦  «        S 	 | j        dk    rdS | j        |k     S # t          $ r
 t          cY S w xY w)Nr    F)r!   r"   r   Ú__lt__r   r   r%   r&   r'   s     €r   r,   zSortTuple.__lt__{   st   ø€ Ý�e�UÑ#Ô#ð 	)Ý‘7”7—>’> %Ñ(Ô(Ð(ð	"ØŒz˜QŠˆØ�uà”{ UÒ*Ð*øÝð 	"ð 	"ð 	"Ý!Ð!Ð!Ð!ð	"øøøs   ¹A Á
A ÁA%Á$A%c                ó   •— t          |t          ¦  «        r!t          ¦   «                              |¦  «        S 	 | j        dk    r|t
          k    rdS | j        dk    rdS | j        |k    S # t          $ r
 t          cY S w xY w)Nr    TF)	r!   r"   r   Ú__gt__r   r$   r   r%   r&   r'   s     €r   r.   zSortTuple.__gt__†   sŽ   ø€ Ý�e�UÑ#Ô#ð 	)Ý‘7”7—>’> %Ñ(Ô(Ð(ð	"ØŒz˜QŠˆ 5­HÒ#4Ð#4Ø�tØ”˜q’�Ø�uà”{ UÒ*Ð*øÝð 	"ð 	"ð 	"Ý!Ð!Ð!Ð!ð	"øøør*   c                ó.   — |                       |¦  «         S r   )r#   ©r(   r)   s     r   Ú__ne__zSortTuple.__ne__“   s   € Ø—;’;˜uÑ%Ô%Ð%Ð%r   c                óV   — |                       |¦  «        p|                      |¦  «        S r   )r,   r#   r0   s     r   Ú__le__zSortTuple.__le__–   ó%   € Ø�{Š{˜5Ñ!Ô!Ð7 T§[¢[°Ñ%7Ô%7Ð7r   c                óV   — |                       |¦  «        p|                      |¦  «        S r   )r.   r#   r0   s     r   Ú__ge__zSortTuple.__ge__™   r4   r   c                óŠ  — g }| j         r|                     d¦  «         n'|                     t          | j        ¦  «        ¦  «         |                     d¦  «         |                     t          | j        ¦  «        ¦  «         |                     d¦  «         |                     t          | j        ¦  «        ¦  «         | j        dk    r|                     d¦  «         |                     d¦  «         |                     t          | j        ¦  «        ¦  «         |                     d¦  «         d                     |¦  «        S )aÆ  
        Returns a nice representation of a SortTuple

        >>> st = sorting.SortTuple(atEnd=0, offset=1.0, priority=0, classSortOrder=20,
        ...           isNotGrace=1, insertIndex=323)
        >>> st.shortRepr()
        '1.0 <0.20.323>'

        >>> st = sorting.SortTuple(atEnd=1, offset=1.0, priority=4, classSortOrder=7,
        ...           isNotGrace=0, insertIndex=200)
        >>> st.shortRepr()
        'End <4.7.[Grace].200>'
        ÚEndz <ú.r   z.[Grace]ú>Ú )	r   ÚappendÚstrr   r   r   r   r   Újoin)r(   Ú	reprPartss     r   Ú	shortReprzSortTuple.shortReprœ   s'  € ð ˆ	ØŒ:ð 	/Ø×Ò˜UÑ#Ô#Ð#Ð#à×Ò�S ¤Ñ-Ô-Ñ.Ô.Ð.Ø×Ò˜ÑÔÐØ×Ò�˜Tœ]Ñ+Ô+Ñ,Ô,Ð,Ø×Ò˜ÑÔÐØ×Ò�˜TÔ0Ñ1Ô1Ñ2Ô2Ð2àŒ?˜aÒÐØ×Ò˜ZÑ(Ô(Ð(Ø×Ò˜ÑÔÐØ×Ò�˜TÔ-Ñ.Ô.Ñ/Ô/Ð/Ø×Ò˜ÑÔÐØ�wŠw�yÑ!Ô!Ð!r   c                óB   ‡ ‡— ˆˆ fd„‰ j         D ¦   «         } ‰ j        |Ž S )a  
        return a new SortTuple identical to the previous, except with
        the given keyword modified.  Works only with keywords.

        >>> st = sorting.SortTuple(atEnd=0, offset=1.0, priority=0, classSortOrder=20,
        ...           isNotGrace=1, insertIndex=32)
        >>> st2 = st.modify(offset=2.0)
        >>> st2.shortRepr()
        '2.0 <0.20.32>'
        >>> st2
        SortTuple(atEnd=0, offset=2.0, priority=0, classSortOrder=20, isNotGrace=1, insertIndex=32)

        >>> st3 = st2.modify(atEnd=1, isNotGrace=0)
        >>> st3.shortRepr()
        'End <0.20.[Grace].32>'

        The original tuple is never modified (hence tuple):

        >>> st.offset
        1.0

        Changing offset, but nothing else, helps in creating .flatten() positions.
        c           	     óX   •— g | ]&}‰                      |t          ‰|¦  «        ¦  «        ‘Œ'S r   )ÚgetÚgetattr)Ú.0Úattrr   r(   s     €€r   ú
<listcomp>z$SortTuple.modify.<locals>.<listcomp>Ô   s1   ø€ ÐTÐTÐT¸t�8—<’< ¥g¨d°DÑ&9Ô&9Ñ:Ô:ÐTÐTÐTr   )Ú_fieldsr   )r(   r   ÚoutLists   `` r   ÚmodifyzSortTuple.modify»   s4   øø€ ð2 UÐTÐTÐTÐTÀtÄ|ÐTÑTÔTˆØˆtŒ~˜wÐ'Ð'r   c                óŠ   ‡ ‡— t          ‰‰ j        ¦  «        st          d¦  «        ‚ˆˆ fd„‰ j        D ¦   «         } ‰ j        |Ž S )aâ  
        Add all attributes from one sortTuple to another,
        returning a new one.

        >>> n = note.Note()
        >>> n.offset = 10
        >>> s = stream.Stream()
        >>> s.offset = 10
        >>> n.sortTuple()
        SortTuple(atEnd=0, offset=10.0, priority=0, classSortOrder=20, isNotGrace=1, insertIndex=0)
        >>> s.sortTuple()
        SortTuple(atEnd=0, offset=10.0, priority=0, classSortOrder=-20, isNotGrace=1, insertIndex=0)
        >>> s.sortTuple().add(n.sortTuple())
        SortTuple(atEnd=0, offset=20.0, priority=0, classSortOrder=0, isNotGrace=1, insertIndex=0)

        Note that atEnd and isNotGrace are equal to other's value. are upper bounded at 1 and
        take the maxValue of either.
        ú,Cannot add attributes from a different classc           	     ó²   •— g | ]S}|d v r,t          t          ‰|¦  «        t          ‰|¦  «        ¦  «        n t          ‰|¦  «        t          ‰|¦  «        z   ‘ŒTS ©)r   r   )ÚmaxrD   ©rE   rF   r)   r(   s     €€r   rG   z!SortTuple.add.<locals>.<listcomp>í   sv   ø€ ð .ð .ð .ð ð Ð6Ð6Ð6õ •w˜t TÑ*Ô*­G°E¸4Ñ,@Ô,@ÑAÔAÐAå! $¨Ñ-Ô-µ¸¸tÑ0DÔ0DÑDð.ð .ð .r   ©r!   r   r   rH   ©r(   r)   rI   s   `` r   ÚaddzSortTuple.add×   sl   øø€ õ& ˜% ¤Ñ0Ô0ð 	SÝ"Ð#QÑRÔRÐRð.ð .ð .ð .ð .ð !%¤ð.ñ .ô .ˆð
 ˆtŒ~˜wÐ'Ð'r   c                óŠ   ‡ ‡— t          ‰‰ j        ¦  «        st          d¦  «        ‚ˆˆ fd„‰ j        D ¦   «         } ‰ j        |Ž S )a­  
        Subtract all attributes from to another.  atEnd and isNotGrace take the min value of either.

        >>> n = note.Note()
        >>> n.offset = 10
        >>> s = stream.Stream()
        >>> s.offset = 10
        >>> n.sortTuple()
        SortTuple(atEnd=0, offset=10.0, priority=0, classSortOrder=20, isNotGrace=1, insertIndex=0)
        >>> s.sortTuple()
        SortTuple(atEnd=0, offset=10.0, priority=0, classSortOrder=-20, isNotGrace=1, insertIndex=0)
        >>> s.sortTuple().sub(n.sortTuple())
        SortTuple(atEnd=0, offset=0.0, priority=0, classSortOrder=-40, isNotGrace=1, insertIndex=0)

        Note that atEnd and isNotGrace are lower bounded at 0.
        rL   c           	     ó²   •— g | ]S}|d v r,t          t          ‰|¦  «        t          ‰|¦  «        ¦  «        n t          ‰|¦  «        t          ‰|¦  «        z
  ‘ŒTS rN   )ÚminrD   rP   s     €€r   rG   z!SortTuple.sub.<locals>.<listcomp>  sv   ø€ ð -ð -ð -ð ð Ð5Ð5Ð5õ •w˜t TÑ*Ô*­G°E¸4Ñ,@Ô,@ÑAÔAÐAå   tÑ,Ô,­w°u¸dÑ/CÔ/CÑCð-ð -ð -r   rQ   rR   s   `` r   ÚsubzSortTuple.subô   sl   øø€ õ" ˜% ¤Ñ0Ô0ð 	SÝ"Ð#QÑRÔRÐRð-ð -ð -ð -ð -ð  $œ|ð-ñ -ô -ˆð
 ˆtŒ~˜wÐ'Ð'r   )r	   r
   r   Ú__doc__r   r#   r,   r.   r1   r3   r6   r@   rJ   rS   rW   Ú__classcell__)r   s   @r   r   r   1   sü   ø€ € € € € ð7ð 7ðpGð Gð Gð Gð Gð"ð "ð "ð "ð "ð	"ð 	"ð 	"ð 	"ð 	"ð"ð "ð "ð "ð "ð&ð &ð &ð8ð 8ð 8ð8ð 8ð 8ð"ð "ð "ð>(ð (ð (ð8(ð (ð (ð:(ð (ð (ð (ð (ð (ð (r   g        r    )r   r   r   r   r   r   Ú__main__)rX   Ú
__future__r   Úmathr   r$   ÚtypingÚtÚmusic21.common.typesr   Úmusic21r   ÚMusic21Exceptionr   Ú
NamedTupleÚintÚ_SortTupleBaser   ÚZeroSortTupleDefaultÚZeroSortTupleLowÚZeroSortTupleHighr	   ÚmainTestr   r   r   ú<module>ri      s¼  ððð ð$ #Ð "Ð "Ð "Ð "Ð "à  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð à )Ð )Ð )Ð )Ð )Ð )Ø  Ð  Ð  Ð  Ð  Ð  ð	ð 	ð 	ð 	ð 	�|Ô4ñ 	ô 	ð 	ð �”˜kØˆc€NØˆxÐØ�ÐØ�sÐØ�3ÐØ�CÐð,ñ ô €ð\(ð \(ð \(ð \(ð \(�ñ \(ô \(ð \(ð~ !�y q°¸qÐQRØ,-¸1ð>ñ >ô >Ð ð �9 1¨S¸H¸9ÐUVØ()°qð:ñ :ô :Ð ð �I A¨c¸HÐUVØ)*¸ð;ñ ;ô ;Ð ð
 ˆzÒÐØ€N€N€NØ€GÔÑÔÐÐÐð Ðr   