.. _moduleAnalysis.metrical:

music21.analysis.metrical
=========================

.. WARNING: DO NOT EDIT THIS FILE: AUTOMATICALLY GENERATED. Edit the .py file directly

.. module:: music21.analysis.metrical

Various tools and utilities for doing metrical or rhythmic analysis.

See the chapter :ref:`overviewMeters` for more information on defining metrical structures in music21.




.. function:: labelBeatDepth(streamIn)


    Modify a Stream in place by annotating metrical analysis symbols.

    This assumes that the Stream is already partitioned into Measures.



    >>> from music21 import *
    >>> s = stream.Stream()
    >>> ts = meter.TimeSignature('4/4')
    >>> s.insert(0, ts)
    >>> n = note.Note()
    >>> s.repeatAppend(n, 4)
    >>> post = analysis.metrical.labelBeatDepth(s)
    >>> ts.beatSequence
    <MeterSequence {{1/8+1/8}+{1/8+1/8}+{1/8+1/8}+{1/8+1/8}}>



.. function:: thomassenMelodicAccent(streamIn)


    adds a attribute melodicAccent to each note of 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: http://www.music-cog.ohio-state.edu/Humdrum/commands/melac.html

    Takes in a Stream of :class:`~music21.note.Note` objects (use `.flat.notes` to get it, or
    better `.flat.getElementsByClass('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:



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



