
    rh                    0   S r SSKJr  SSKrSSKrSSKJr  SSKJr  \R                  " S5      r
 " S S\R                  5      r " S	 S
\R                  R                  5      r " S S\R                   5      rSr\S:X  a  SSKr\R(                  " \5        gg)z9
Tools for performing voice-leading analysis with trees.
    )annotationsN)environment)exceptions21ztree.analysisc                      \ rS rSrSrg)HorizontalityException    N__name__
__module____qualname____firstlineno____static_attributes__r	       O/home/james-whalen/.local/lib/python3.13/site-packages/music21/tree/analysis.pyr   r          r   r   c                  h    \ rS rSrSrSrSS jrS rS rS r	\
S	 5       r\
S
 5       r\
S 5       rSrg)Horizontality    zy
A horizontality of consecutive PitchedTimespan objects.

It must be initiated with a list or tuple of Timespan objects.
	timespansNc                    [        U[        R                  R                  5      (       d  [	        SU< 35      eU(       d  [	        S5      e[        S U 5       5      (       d  [	        S5      e[        U5      U l        g )Nz"timespans must be a sequence, not z9there must be at least one timespan in the timespans listc              3  `   #    U  H$  n[        US 5      =(       a    [        US5      v   M&     g7f)offsetendTimeN)hasattr.0xs     r   	<genexpr>)Horizontality.__init__.<locals>.<genexpr>5   s&     U9a71h'AGAy,AA9s   ,.z5only Timespan objects can be added to a horizontality)
isinstancecollectionsabcSequencer   alltupler   )selfr   s     r   __init__Horizontality.__init__/   sj    )[__%=%=>>(+Mi])[\\(KM MU9UUU()`aay)r   c                     U R                   U   $ Nr   )r(   items     r   __getitem__Horizontality.__getitem__;   s    ~~d##r   c                ,    [        U R                  5      $ r,   )lenr   )r(   s    r   __len__Horizontality.__len__>   s    4>>""r   c                    / nU  H<  nSR                  S UR                   5       5      nSU S3nUR                  U5        M>     SR                  U5      nS[        U 5      R                   SU S3$ )	Nz, c              3  8   #    U  H  oR                   v   M     g 7fr,   )nameWithOctave)r   ys     r   r    )Horizontality.__repr__.<locals>.<genexpr>D   s     %J	1&6&6	s   (z,) <z: >)joinpitchesappendtyper   )r(   pitchStringsr   joinedPitchesoutpitchStrs         r   __repr__Horizontality.__repr__A   su    A II%J		%JJMm_B'C$  88L)4:&&'r(155r   c                $   [        U 5      S:  a  g[        S U  5       5      (       d  gU S   R                  S   U S   R                  S   U S   R                  S   4nUS   US   s=:  a
  US   :  a   g  US   US   s=:  a
  US   :  a   g  gg)z
Is true if the Horizontality contains a passing tone; currently defined as three tones in
one direction.

(TODO: better check)
   Fc              3  L   #    U  H  n[        UR                  5      v   M     g 7fr,   r1   r>   r   s     r   r    /Horizontality.hasPassingTone.<locals>.<genexpr>V        2TS^^T   "$r         T)r1   r&   r>   r(   r>   s     r   hasPassingToneHorizontality.hasPassingToneL   s     t9q=2T222GOOAGOOAGOOA

 1:
/WQZ/ 0QZ'!*1wqz1 2r   c                0   [        U 5      S:  a  g[        S U  5       5      (       d  gU S   R                  S   U S   R                  S   U S   R                  S   4nUS   US   :X  a-  [        US   R                  US   R                  -
  5      S:  a  gg)z8
Is true if the Horizontality contains a neighbor tone.
rH   Fc              3  L   #    U  H  n[        UR                  5      v   M     g 7fr,   rJ   r   s     r   r    0Horizontality.hasNeighborTone.<locals>.<genexpr>j   rL   rM   r   rN   rO   T)r1   r&   r>   abspsrP   s     r   hasNeighborToneHorizontality.hasNeighborTonec   s    
 t9q=2T222 GOOAGOOAGOOA

 1:#71:==71:==01A5r   c                    [        5       nU  H'  nUR                  [        UR                  5      5        M)     [	        U5      S:X  a  gg)zU
Is true if the Horizontality contains no motion (including enharmonic restatements)
rN   TF)setaddr'   r>   r1   )r(   	pitchSetsr   s      r   hasNoMotionHorizontality.hasNoMotionw   s<    
 E	AMM%		*+ y>Qr   r,   )r   r   r   r   __doc__	__slots__r)   r.   r2   rE   propertyrQ   rX   r^   r   r	   r   r   r   r       s^    I*$#6  ,  & 	 	r   r   c                      \ rS rSrSrg)Test   r	   Nr
   r	   r   r   rd   rd      r   r   rd   r	   __main__)r`   
__future__r   collections.abcr#   unittestmusic21r   r   EnvironmentenvironLocalTreeExceptionr   r$   r%   r   TestCaserd   
_DOC_ORDERr   mainTestr	   r   r   <module>rq      s    #     &&7	\77 	aKOO,, aN	8 	 
 zT r   