§
    ƒØj9  ã                  óö   — d Z ddlmZ ddlZddlZddlmZ ddlmZ  ej        d¦  «        Z	d„ Z
dd
„Z G d„ dej        ¦  «        Z G d„ dej        ¦  «        Ze
gZedk    rddlZ ej        e¦  «         dS dS )zç
Various tools and utilities for doing metrical or rhythmic analysis.

See the chapter :ref:`User's Guide Chapter 14: Time Signatures <usersGuide_14_timeSignatures>`
for more information on defining
metrical structures in music21.
é    )ÚannotationsN)Úenvironment)Ústreamzanalysis.metricalc                ó  — |                       t          j        ¦  «        D ]ë}|                     d¬¦  «        d         }t	          j        |¦  «        }|j                             d¬¦  «         |j        D ]–}t          |d¦  «        rE|j
        �>t                               d||j
        |j
        j        g¦  «         |j
        j        d	k    rŒWt          |                     |j        ¦  «        ¦  «        D ]}|                     d
¦  «         ŒŒ—Œì| S )aÉ  
    Modify a Stream in place by annotating metrical analysis symbols.

    This assumes that the Stream is already partitioned into Measures.

    >>> s = stream.Stream()
    >>> ts = meter.TimeSignature('4/4')
    >>> s.insert(0, ts)
    >>> n = note.Note(type='eighth')
    >>> s.repeatAppend(n, 8)
    >>> s.makeMeasures(inPlace=True)
    >>> post = analysis.metrical.labelBeatDepth(s)
    >>> sOut = []
    >>> for n in s.flatten().notes:
    ...     stars = "".join([l.text for l in n.lyrics])
    ...     sOut.append(f'{n.beatStr:8s} {stars}')
    >>> print("\n".join(sOut))
    1        ****
    1 1/2    *
    2        **
    2 1/2    *
    3        ***
    3 1/2    *
    4        **
    4 1/2    *
    F)ÚsortByCreationTimer   é   )ÚdepthÚtieNz	note, tieÚstopÚ*)ÚgetElementsByClassr   ÚMeasureÚgetTimeSignaturesÚcopyÚdeepcopyÚbeatSequenceÚsubdivideNestedHierarchyÚnotesAndRestsÚhasattrr
   ÚenvironLocalÚ
printDebugÚtypeÚrangeÚgetBeatDepthÚoffsetÚaddLyric)ÚstreamInÚmÚtsÚtsTempÚnÚunused_is         úŽ/Users/tedpeters/Documents/Projects/Claude Projects/Misc Tools/notename-sheets/.venv/lib/python3.11/site-packages/music21/analysis/metrical.pyÚlabelBeatDepthr$      s  € ð8 ×(Ò(­¬Ñ8Ô8ð  ð  ˆð × Ò °EÐ Ñ:Ô:¸1Ô=ˆõ ”˜rÑ"Ô"ˆØÔ×4Ò4¸1Ð4Ñ=Ô=Ð=à”ð 	 ð 	 ˆAÝ�q˜%Ñ Ô ð  Q¤UÐ%6Ý×'Ò'¨°a¸¼ÀÄÄ
Ð(KÑLÔLÐLØ”5”: Ò'Ð'ØÝ! &×"5Ò"5°a´hÑ"?Ô"?Ñ@Ô@ð  ð  �Ø—
’
˜3‘”��ð ð	 ð €Oó    r   ústream.Streamc                ó8  — t          | ¦  «        dz
  }d}t          | ¦  «        D ]õ\  }}|dk    rd|j        _        Œ||k    r||j        _        Œ+| |dz
           j        j        }|j        j        }| |dz            j        j        }||k    r||k    rd}d}	nr||k    r||k    rd}d}	na||k    r||k    rd}d}	nP||k     r||k    rd}d}	n?||k    r||k     rd}d}	n.||cxk     r|k     rn nd	}d
}	n||cxk    r|k    rn nd}d}	nd}d}	||z  |j        _        |	}ŒödS )aR  
    Adds an attribute, 'melodicAccent' to each note's `.editorial`
    within a :class:`~music21.stream.Stream` object
    according to the method postulated in Joseph M. Thomassen, "Melodic accent: Experiments and
    a tentative model," ''Journal of the Acoustical Society of America'', Vol. 71, No. 6 (1982) pp.
    1598-1605; with, Erratum, ''Journal of the Acoustical Society of America'', Vol. 73,
    No. 1 (1983) p.373, and in David Huron and Matthew Royal,
    "What is melodic accent? Converging evidence
    from musical practice." ''Music Perception'', Vol. 13, No. 4 (1996) pp. 489-516.

    Similar to the humdrum melac_ tool.

    .. _melac: https://www.humdrum.org/Humdrum/commands/melac.html

    Takes in a Stream of :class:`~music21.note.Note` objects (use `.flatten().notes` to get it, or
    better `.flatten().getElementsByClass(note.Note)` to filter out chords)
    and adds the attribute to
    each.  Note that Huron and Royal's work suggests that melodic accent has a correlation
    with metrical accent only for solo works/passages; even treble passages do not have a
    strong correlation. (Gregorian chants were found to have a strong ''negative'' correlation
    between melodic accent and syllable onsets)

    Following Huron's lead, we assign a `melodicAccent` of 1.0 to the first note in a piece
    and take the accent marker of the first interval alone to the second note and
    of the last interval alone to be the accent of the last note.

    Example from Thomassen, figure 5:

    >>> s = converter.parse('tinynotation: 7/4 c4 c c d e d d')
    >>> analysis.metrical.thomassenMelodicAccent(s.flatten().notes)
    >>> for n in s.flatten().notes:
    ...    (n.pitch.nameWithOctave, n.editorial.melodicAccent)
    ('C4', 1.0)
    ('C4', 0.0)
    ('C4', 0.0)
    ('D4', 0.33)
    ('E4', 0.5561)
    ('D4', 0.17)
    ('D4', 0.0)

    é   g      ð?r   g        g�Âõ(\�ê?gÃõ(\�ÂÅ?g¸…ëQ¸æ?g�Âõ(\�Ò?g…ëQ¸Õ?gq=
×£på?ç      à?N)ÚlenÚ	enumerateÚ	editorialÚmelodicAccentÚpitchÚps)
r   ÚmaxNotesÚp2AccentÚir!   ÚlastPsÚthisPsÚnextPsÚ
thisAccentÚ
nextAccents
             r#   ÚthomassenMelodicAccentr8   L   s´  € õZ �8‰}Œ}˜qÑ €HØ€HÝ˜(Ñ#Ô#ð &ð &‰ˆˆ1Ø�Š6ˆ6Ø(+ˆAŒKÔ%ØØ�(Š]ˆ]Ø(0ˆAŒKÔ%Øà˜!˜a™%”Ô&Ô)ˆØ””ˆØ˜!˜a™%”Ô&Ô)ˆà�VÒÐ ¨&Ò 0Ð 0ØˆJØˆJˆJØ�vÒÐ &¨FÒ"2Ð"2ØˆJØˆJˆJØ�vÒÐ &¨FÒ"2Ð"2ØˆJØˆJˆJØ�fŠ_ˆ_ ¨&¢ ØˆJØˆJˆJØ�fŠ_ˆ_ ¨&¢ ØˆJØˆJˆJØ�fÐ%Ð%Ò%Ð%˜vÒ%Ð%Ð%Ð%Ð%ØˆJØˆJˆJØ�fÐ%Ð%Ò%Ð%˜vÒ%Ð%Ð%Ð%Ð%ØˆJØˆJˆJàˆJØˆJà$.°Ñ$9ˆŒÔ!ØˆˆðM&ð &r%   c                  ó   — e Zd ZdZd„ ZdS )ÚTestExternalTc                óÜ  — ddl m} ddl m} t          j        ¦   «         }|                     d¦  «        }|                     |¦  «         |                     ¦   «         }d|_        | 	                    |d¦  «         |                     ¦   «         }d|_        | 	                    |d¦  «         | 
                    ¦   «         }t          |¦  «        }| j        r|                     ¦   «          d	S d	S )
z?
        Need to test direct meter creation w/o stream
        r   )Únote)Úmeterz4/4r(   é   r)   é   N)Úmusic21r<   r=   r   ÚStreamÚTimeSignatureÚappendÚNoteÚquarterLengthÚrepeatAppendÚmakeMeasuresr$   Úshow)Úselfr<   r=   Úsr   r!   s         r#   Ú
testSinglezTestExternal.testSingleª   sæ   € ð 	!Ð Ð Ð Ð Ð Ø!Ð!Ð!Ð!Ð!Ð!ÝŒM‰OŒOˆØ× Ò  Ñ'Ô'ˆà	�Š�‰ŒˆØ�IŠI‰KŒKˆØˆŒØ	�Š�q˜!ÑÔÐà�IŠI‰KŒKˆØˆŒØ	�Š�q˜!ÑÔÐà�NŠNÑÔˆÝ˜1ÑÔˆàŒ9ð 	Ø�FŠF‰HŒHˆHˆHˆHð	ð 	r%   N)Ú__name__Ú
__module__Ú__qualname__rH   rK   © r%   r#   r:   r:   §   s(   € € € € € Ø€Dðð ð ð ð r%   r:   c                  ó   — e Zd ZdS )ÚTestN)rL   rM   rN   rO   r%   r#   rQ   rQ   Ã   s   € € € € € Ø€Dr%   rQ   Ú__main__)r   r&   )Ú__doc__Ú
__future__r   r   Úunittestr@   r   r   ÚEnvironmentr   r$   r8   ÚTestCaser:   rQ   Ú
_DOC_ORDERrL   ÚmainTestrO   r%   r#   ú<module>rZ      s.  ððð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à&ˆ{Ô&Ð':Ñ;Ô;€ð-ð -ð -ð^Uð Uð Uð Uðvð ð ð ð �8Ô$ñ ô ð ð8	ð 	ð 	ð 	ð 	ˆ8Ôñ 	ô 	ð 	ð Ð€
àˆzÒÐØ€N€N€NØ€GÔ�TÑÔÐÐÐð Ðr%   