meter

Tools for modeling musical meter.

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true ]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0 ]; edge [color=lightslategrey, penwidth=1 ]; subgraph "cluster_abjad.meter" { graph [label="abjad.meter"]; node [color=1]; "abjad.meter.Meter" [URL="../api/abjad/meter.html#abjad.meter.Meter", color=black, fontcolor=white, label=Meter, target=_top]; "abjad.meter.MetricAccentKernel" [URL="../api/abjad/meter.html#abjad.meter.MetricAccentKernel", color=black, fontcolor=white, label="Metric\nAccent\nKernel", target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=2]; "builtins.object" [URL="https://docs.python.org/3.10/library/functions.html#object", label=object, target=_top]; } "builtins.object" -> "abjad.meter.Meter" [minlen=1]; "builtins.object" -> "abjad.meter.MetricAccentKernel" [minlen=2]; }


Classes

Meter

Meter models a common practice understanding of beats and other levels of rhythmic organization structured as a tree.

MetricAccentKernel

Metric accent kernel.

class abjad.meter.Meter(argument=(4, 4), increase_monotonic=None, preferred_boundary_depth=None)[source]

Meter models a common practice understanding of beats and other levels of rhythmic organization structured as a tree. Meter structure corresponds to the monotonically increasing sequence of factors in the numerator of a given time signature. Successively deeper levels of the tree divide time by successive factors.

Duple meter:

>>> meter = abjad.Meter((2, 4))
>>> meter
Meter('(2/4 (1/4 1/4))')
>>> print(meter.pretty_rtm_format)
(2/4 (
    1/4
    1/4))
>>> abjad.graph(meter)  

2/4 comprises two beats.

Triple meter:

>>> meter = abjad.Meter((3, 4))
>>> print(meter.pretty_rtm_format)
(3/4 (
    1/4
    1/4
    1/4))
>>> abjad.graph(meter)  

3/4 comprises three beats.

Quadruple meter:

>>> meter = abjad.Meter((4, 4))
>>> meter
Meter('(4/4 (1/4 1/4 1/4 1/4))')
>>> print(meter.pretty_rtm_format)
(4/4 (
    1/4
    1/4
    1/4
    1/4))
>>> abjad.graph(meter)  

4/4 comprises four beats.

Compound triple meter:

>>> meter = abjad.Meter((6, 8))
>>> print(meter.pretty_rtm_format)
(6/8 (
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))))
>>> abjad.graph(meter)  

6/8 comprises two beats of three parts each.

Another compound triple meter:

>>> meter = abjad.Meter((12, 8))
>>> print(meter.pretty_rtm_format)
(12/8 (
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))))
>>> abjad.graph(meter)  

12/8 comprises four beats of three parts each.

An asymmetric meter:

>>> meter = abjad.Meter((5, 4))
>>> print(meter.pretty_rtm_format)
(5/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> abjad.graph(meter)  

5/4 comprises two unequal beats. By default unequal beats are arranged from greatest to least.

Another asymmetric meter:

>>> meter = abjad.Meter((7, 4))
>>> print(meter.pretty_rtm_format)
(7/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> abjad.graph(meter)  

7/4 comprises three unequal beats. Beats are arranged from greatest to least by default.

The same asymmetric meter structured differently:

>>> meter = abjad.Meter(
...     (7, 4),
...     increase_monotonic=True,
... )
>>> print(meter.pretty_rtm_format)
(7/4 (
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))))
>>> abjad.graph(meter)  

7/4 with beats arragned from least to greatest.

Meter interpreted by default as containing two compound beats:

>>> meter = abjad.Meter((6, 4))
>>> meter
Meter('(6/4 ((3/4 (1/4 1/4 1/4)) (3/4 (1/4 1/4 1/4))))')
>>> print(meter.pretty_rtm_format)
(6/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))))
>>> abjad.graph(meter)  

Same meter customized to contain four compound beats:

>>> parser = abjad.rhythmtrees.RhythmTreeParser()
>>> meter = abjad.Meter(
...     "(6/4 ((3/8 (1/8 1/8 1/8)) (3/8 (1/8 1/8 1/8)) (3/8 (1/8 1/8 1/8)) (3/8 (1/8 1/8 1/8))))"
... )
>>> meter
Meter('(6/4 ((3/8 (1/8 1/8 1/8)) (3/8 (1/8 1/8 1/8)) (3/8 (1/8 1/8 1/8)) (3/8 (1/8 1/8 1/8))))')
>>> print(meter.pretty_rtm_format)
(6/4 (
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))))
>>> abjad.graph(meter)  

Prime divisions greater than 3 are converted to sequences of 2 and 3 summing to that prime. Summands are arranged from greatest to least by default. This means that 5 becomes 3+2 and 7 becomes 3+2+2 in the examples above.


Attributes Summary

__eq__

Compares numerator, denominator, increase_monotonic, preferred_boundary_depth.

__graph__

Gets Graphviz format of meter.

__hash__

Hashes meter.

__iter__

Iterates meter.

__repr__

Gets repr.

denominator

Gets denominator of meter.

depthwise_offset_inventory

Gets depthwise offset inventory of meter.

duration

Gets duration of meter.

fit_meters

Finds the best-matching sequence of meters for the offsets contained in argument.

fraction_string

Gets fraction string.

generate_offset_kernel_to_denominator

Generates a dictionary of all offsets in a meter up to denominator.

implied_time_signature

Gets implied time signature of meter.

increase_monotonic

Is true when meter divides large primes into collections of 2 and 3 that increase monotonically.

is_compound

Is true when meter is compound.

is_simple

Is true when meter is simple.

numerator

Gets numerator of meter.

pair

Gets pair of numerator and denominator of meter.

preferred_boundary_depth

Gets preferred boundary depth of meter.

pretty_rtm_format

Gets pretty RTM format of meter.

rewrite_meter

Rewrites components according to meter.

root_node

Gets root node of meter.

rtm_format

Gets RTM format of meter.


Special methods

overridden __eq__(argument)[source]

Compares numerator, denominator, increase_monotonic, preferred_boundary_depth.

__graph__(**keywords)[source]

Gets Graphviz format of meter.

Graphs 7/4:

>>> meter = abjad.Meter((7, 4))
>>> meter_graph = meter.__graph__()
>>> abjad.graph(meter_graph)  

Returns Graphviz graph.

overridden __hash__()[source]

Hashes meter.

Returns integer.

__iter__()[source]

Iterates meter.

Iterates 5/4:

>>> meter = abjad.Meter((5, 4))
>>> for pair in meter:
...     pair
... 
((0, 4), (1, 4))
((1, 4), (2, 4))
((2, 4), (3, 4))
((0, 4), (3, 4))
((3, 4), (4, 4))
((4, 4), (5, 4))
((3, 4), (5, 4))
((0, 4), (5, 4))

Yields pairs.

overridden __repr__()[source]

Gets repr.

Return type:

str


Methods

generate_offset_kernel_to_denominator(denominator, normalize=True)[source]

Generates a dictionary of all offsets in a meter up to denominator.

Keys are the offsets and the values are the normalized weights of those offsets.

>>> meter = abjad.Meter((4, 4))
>>> kernel = meter.generate_offset_kernel_to_denominator(8)
>>> for offset, weight in sorted(kernel.kernel.items()):
...     print(f"{offset!s}\t{weight!s}")
... 
0	3/16
1/8	1/16
1/4	1/8
3/8	1/16
1/2	1/8
5/8	1/16
3/4	1/8
7/8	1/16
1	3/16

This is useful for testing how strongly a collection of offsets responds to a given meter.

Returns dictionary.


Class & static methods

static fit_meters(argument, meters, denominator=32, discard_final_orphan_downbeat=True, maximum_run_length=None, starting_offset=None)[source]

Finds the best-matching sequence of meters for the offsets contained in argument.

>>> meters = [(3, 4), (4, 4), (5, 4)]
>>> meters = [abjad.Meter(_) for _ in meters]

Matches a series of hypothetical 4/4 measures:

>>> argument = [(0, 4), (4, 4), (8, 4), (12, 4), (16, 4)]
>>> for meter in abjad.Meter.fit_meters(argument, meters):
...     print(meter.implied_time_signature)
... 
TimeSignature(pair=(4, 4), hide=False, partial=None)
TimeSignature(pair=(4, 4), hide=False, partial=None)
TimeSignature(pair=(4, 4), hide=False, partial=None)
TimeSignature(pair=(4, 4), hide=False, partial=None)

Matches a series of hypothetical 5/4 measures:

>>> argument = [(0, 4), (3, 4), (5, 4), (10, 4), (15, 4), (20, 4)]
>>> for meter in abjad.Meter.fit_meters(argument, meters):
...     print(meter.implied_time_signature)
... 
TimeSignature(pair=(3, 4), hide=False, partial=None)
TimeSignature(pair=(4, 4), hide=False, partial=None)
TimeSignature(pair=(3, 4), hide=False, partial=None)
TimeSignature(pair=(5, 4), hide=False, partial=None)
TimeSignature(pair=(5, 4), hide=False, partial=None)

Coerces offsets from argument via MetricAccentKernel.count_offsets().

Returns list.

static rewrite_meter(components, meter, boundary_depth=None, initial_offset=None, maximum_dot_count=None, rewrite_tuplets=True)[source]

Rewrites components according to meter.

Rewrites the contents of a measure in a staff using the default meter for that measure’s time signature:

>>> lily_string = "| 2/4 c'2 ~ |"
>>> lily_string += "| 4/4 c'32 d'2.. ~ d'16 e'32 ~ |"
>>> lily_string += "| 2/4 e'2 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff[:] = container
>>> score = abjad.Score([staff], name="Score")
>>> abjad.show(staff)  
>>> meter = abjad.Meter((4, 4))
>>> print(meter.pretty_rtm_format)
(4/4 (
    1/4
    1/4
    1/4
    1/4))
>>> abjad.Meter.rewrite_meter(staff[1][:], meter)
>>> abjad.show(staff)  

Rewrites the contents of a measure in a staff using a custom meter:

>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff[:] = container
>>> score = abjad.Score([staff], name="Score")
>>> abjad.show(staff)  
>>> rtm = "(4/4 ((2/4 (1/4 1/4)) (2/4 (1/4 1/4))))"
>>> meter = abjad.Meter(rtm)
>>> print(meter.pretty_rtm_format)  
(4/4 (
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> abjad.Meter.rewrite_meter(staff[1][:], meter)
>>> abjad.show(staff)  

Limit the maximum number of dots per leaf using maximum_dot_count:

>>> lily_string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> abjad.show(staff)  

Without constraining the maximum_dot_count:

>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(measure[:], time_signature)
>>> abjad.show(staff)  

Constraining the maximum_dot_count to 2:

>>> lily_string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(
...     measure[:],
...     time_signature,
...     maximum_dot_count=2,
... )
>>> abjad.show(staff)  

Constraining the maximum_dot_count to 1:

>>> lily_string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(
...     measure[:],
...     time_signature,
...     maximum_dot_count=1,
... )
>>> abjad.show(staff)  

Constraining the maximum_dot_count to 0:

>>> lily_string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(
...     measure[:],
...     time_signature,
...     maximum_dot_count=0,
... )
>>> abjad.show(staff)  

Split logical ties at different depths of the Meter, if those logical ties cross any offsets at that depth, but do not also both begin and end at any of those offsets.

Consider the default meter for 9/8:

>>> meter = abjad.Meter((9, 8))
>>> print(meter.pretty_rtm_format)
(9/8 (
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))))

We can establish that meter without specifying a boundary_depth:

>>> lily_string = "| 9/8 c'2 d'2 e'8 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> abjad.show(staff)  
>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(measure[:], time_signature)
>>> abjad.show(staff)  

With a boundary_depth of 1 logical ties which cross any offsets created by nodes with a depth of 1 in this Meter’s rhythm tree - i.e. 0/8 3/8 6/8 and 9/8 - which do not also begin and end at any of those offsets, will be split:

>>> lily_string = "| 9/8 c'2 d'2 e'8 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(
...     measure[:],
...     time_signature,
...     boundary_depth=1,
... )
>>> abjad.show(staff)  

For this 9/8 meter, and this input notation, A boundary_depth of 2 causes no change, as all logical ties already align to multiples of 1/8

>>> lily_string = "| 9/8 c'2 d'2 e'8 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(
...     measure[:],
...     time_signature,
...     boundary_depth=2,
... )
>>> abjad.show(staff)  

Comparison of 3/4 and 6/8 at boundary_depths of 0 and 1:

>>> triple = "| 3/4 2 4 || 3/4 4 2 || 3/4 4. 4. |"
>>> triple += "| 3/4 2 ~ 8 8 || 3/4 8 8 ~ 2 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(triple)
>>> staff_1 = abjad.Staff()
>>> staff_1[:] = container
>>> duples = "| 6/8 2 4 || 6/8 4 2 || 6/8 4. 4. |"
>>> duples += "| 6/8 2 ~ 8 8 || 6/8 8 8 ~ 2 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(duples)
>>> staff_2 = abjad.Staff()
>>> staff_2[:] = container
>>> score = abjad.Score([staff_1, staff_2])

In order to see the different time signatures on each staff, we need to move some engravers from the Score context to the Staff context:

>>> engravers = [
...     "Timing_translator",
...     "Time_signature_engraver",
...     "Default_bar_line_engraver",
... ]
>>> score.remove_commands.extend(engravers)
>>> score[0].consists_commands.extend(engravers)
>>> score[1].consists_commands.extend(engravers)
>>> abjad.show(score)  

Here we establish a meter without specifying any boundary depth:

>>> for staff in score:
...     for container in staff:
...         leaf = abjad.get.leaf(container, 0)
...         time_signature = abjad.get.indicator(leaf, abjad.TimeSignature)
...         abjad.Meter.rewrite_meter(container[:], time_signature)
... 
>>> abjad.show(score)  

Here we reestablish meter at a boundary depth of 1

>>> for staff in score:
...     for container in staff:
...         leaf = abjad.get.leaf(container, 0)
...         time_signature = abjad.get.indicator(leaf, abjad.TimeSignature)
...         abjad.Meter.rewrite_meter(
...             container[:],
...             time_signature,
...             boundary_depth=1,
...         )
... 
>>> abjad.show(score)  

Note that the two time signatures are much more clearly disambiguated above.

Establishing meter recursively in measures with nested tuplets:

>>> lily_string = "| 4/4 c'16 ~ c'4 d'8. ~ "
>>> lily_string += "2/3 { d'8. ~ 3/5 { d'16 e'8. f'16 ~ } } "
>>> lily_string += "f'4 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(lily_string)
>>> staff = abjad.Staff()
>>> staff.append(container)
>>> score = abjad.Score([staff], name="Score")
>>> abjad.show(staff)  

When establishing a meter on a selection of components which contain containers, like tuplets or containers, rewrite_meter() will recurse into those containers, treating them as measures whose time signature is derived from the preprolated preprolated_duration of the container’s contents:

>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> abjad.Meter.rewrite_meter(
...     measure[:],
...     time_signature,
...     boundary_depth=1,
... )
>>> abjad.show(staff)  

Default rewrite behavior doesn’t subdivide the first note in this measure because the first note in the measure starts at the beginning of a level-0 beat in meter:

>>> staff = abjad.Staff("c'4.. c'16 ~ c'4")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.attach(abjad.TimeSignature((6, 8)), staff[0])
>>> meter = abjad.Meter((6, 8))
>>> abjad.Meter.rewrite_meter(staff[:], meter)
>>> abjad.show(staff)  

Setting boundary depth to 1 subdivides the first note in this measure:

>>> staff = abjad.Staff("c'4.. c'16 ~ c'4")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.attach(abjad.TimeSignature((6, 8)), staff[0])
>>> meter = abjad.Meter((6, 8))
>>> abjad.Meter.rewrite_meter(staff[:], meter, boundary_depth=1)
>>> abjad.show(staff)  

Another way of doing this is by setting preferred boundary depth on the meter itself:

>>> staff = abjad.Staff("c'4.. c'16 ~ c'4")
>>> score = abjad.Score([staff], name="Score")
>>> abjad.attach(abjad.TimeSignature((6, 8)), staff[0])
>>> meter = abjad.Meter((6, 8), preferred_boundary_depth=1)
>>> abjad.Meter.rewrite_meter(staff[:], meter)
>>> abjad.show(staff)  

This makes it possible to divide different meters in different ways.

Rewrites notes and tuplets:

>>> lily_string = r"c'8 ~ c'8 ~ c'8 \times 6/7 { c'4. r16 }"
>>> lily_string += r" \times 6/7 { r16 c'4. } c'8 ~ c'8 ~ c'8"
>>> staff = abjad.Staff(lily_string)
>>> score = abjad.Score([staff], name="Score")
>>> abjad.attach(abjad.TimeSignature((6, 4)), staff[0])
>>> abjad.show(staff)  
>>> meter = abjad.Meter((6, 4))
>>> abjad.Meter.rewrite_meter(
...     staff[:],
...     meter,
...     boundary_depth=1,
... )
>>> abjad.show(staff)  

The tied note rewriting is good while the tuplet rewriting could use some adjustment.

Rewrites notes but not tuplets:

>>> lily_string = r"c'8 ~ c'8 ~ c'8 \times 6/7 { c'4. r16 }"
>>> lily_string += r" \times 6/7 { r16 c'4. } c'8 ~ c'8 ~ c'8"
>>> staff = abjad.Staff(lily_string)
>>> score = abjad.Score([staff], name="Score")
>>> abjad.attach(abjad.TimeSignature((6, 4)), staff[0])
>>> abjad.show(staff)  
>>> meter = abjad.Meter((6, 4))
>>> abjad.Meter.rewrite_meter(
...     staff[:],
...     meter,
...     boundary_depth=1,
...     rewrite_tuplets=False,
... )
>>> abjad.show(staff)  

Operates in place and returns none.


Read-only properties

denominator

Gets denominator of meter.

>>> meter = abjad.Meter((7, 4))
>>> meter.denominator
4

Returns positive integer.

depthwise_offset_inventory

Gets depthwise offset inventory of meter.

>>> meter = abjad.Meter((7, 4))
>>> for depth, offsets in enumerate(meter.depthwise_offset_inventory):
...     print(depth, offsets)
... 
0 (Offset((0, 1)), Offset((7, 4)))
1 (Offset((0, 1)), Offset((3, 4)), Offset((5, 4)), Offset((7, 4)))
2 (Offset((0, 1)), Offset((1, 4)), Offset((1, 2)), Offset((3, 4)), Offset((1, 1)), Offset((5, 4)), Offset((3, 2)), Offset((7, 4)))

Returns dictionary.

duration

Gets duration of meter.

>>> meter = abjad.Meter((7, 4))
>>> meter.duration
Duration(7, 4)

Returns duration.

fraction_string

Gets fraction string.

implied_time_signature

Gets implied time signature of meter.

>>> abjad.Meter((4, 4)).implied_time_signature
TimeSignature(pair=(4, 4), hide=False, partial=None)

Returns time signature.

increase_monotonic

Is true when meter divides large primes into collections of 2 and 3 that increase monotonically.

An asymmetric meter with beats arranged greatest to least:

>>> meter = abjad.Meter(
...     (7, 4),
...     increase_monotonic=False,
... )
>>> meter.increase_monotonic
False
>>> print(meter.pretty_rtm_format)
(7/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))

This is default beahvior.

The same asymmetric meter with unequal beats arranged least to greatest:

>>> meter = abjad.Meter((7, 4), increase_monotonic=True)
>>> meter.increase_monotonic
True
>>> print(meter.pretty_rtm_format)
(7/4 (
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))))
is_compound

Is true when meter is compound.

Compound meters written over 4:

>>> for numerator in range(1, 13):
...     meter = abjad.Meter((numerator, 4))
...     string = True if meter.is_compound else ""
...     print(str(meter.fraction_string), string)
... 
1/4 
2/4 
3/4 
4/4 
5/4 
6/4 True
7/4 
8/4 
9/4 True
10/4 
11/4 
12/4 True

Compound meters written over 8:

>>> for numerator in range(1, 13):
...     meter = abjad.Meter((numerator, 8))
...     string = True if meter.is_compound else ""
...     print(str(meter.fraction_string), string)
... 
1/8 
2/8 
3/8 
4/8 
5/8 
6/8 True
7/8 
8/8 
9/8 True
10/8 
11/8 
12/8 True

Compound meters defined equal to those meters with a numerator divisible by 3 (but not equal to 3).

Returns true or false.

is_simple

Is true when meter is simple.

Simple meters written over 4:

>>> for numerator in range(1, 13):
...     meter = abjad.Meter((numerator, 4))
...     string = True if meter.is_simple else ""
...     print(str(meter.fraction_string), string)
... 
1/4 True
2/4 True
3/4 True
4/4 True
5/4 True
6/4 
7/4 True
8/4 True
9/4 
10/4 True
11/4 True
12/4 

Simple meters written over 8:

>>> for numerator in range(1, 13):
...     meter = abjad.Meter((numerator, 8))
...     string = True if meter.is_simple else ""
...     print(str(meter.fraction_string), string)
... 
1/8 True
2/8 True
3/8 True
4/8 True
5/8 True
6/8 
7/8 True
8/8 True
9/8 
10/8 True
11/8 True
12/8 

Simple meters defined equal to those meters with a numerator not divisible by 3.

Meters with numerator equal to 3 are also defined as simple.

Returns true or false.

numerator

Gets numerator of meter.

>>> meter = abjad.Meter((7, 4))
>>> meter.numerator
7

Returns positive integer.

pair

Gets pair of numerator and denominator of meter.

>>> meter = abjad.Meter((6, 4))
>>> meter.pair
(6, 4)

Returns pair.

preferred_boundary_depth

Gets preferred boundary depth of meter.

No preferred boundary depth:

>>> abjad.Meter((6, 8)).preferred_boundary_depth is None
True

Customized preferred boundary depth:

>>> meter = abjad.Meter(
...     (6, 8),
...     preferred_boundary_depth=1,
... )
>>> meter.preferred_boundary_depth
1

Used by abjad.Meter.rewrite_meter().

Defaults to none.

Set to integer or none.

Returns integer or none.

pretty_rtm_format

Gets pretty RTM format of meter.

>>> meter = abjad.Meter((7, 4))
>>> print(meter.pretty_rtm_format)
(7/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))

Returns string.

root_node

Gets root node of meter.

>>> meter = abjad.Meter((7, 4))
>>> for _ in meter.root_node:
...     _
... 
RhythmTreeContainer((3, 4))
RhythmTreeContainer((2, 4))
RhythmTreeContainer((2, 4))

Returns rhythm tree node.

rtm_format

Gets RTM format of meter.

>>> meter = abjad.Meter((7, 4))
>>> meter.rtm_format
'(7/4 ((3/4 (1/4 1/4 1/4)) (2/4 (1/4 1/4)) (2/4 (1/4 1/4))))'

Returns string.

class abjad.meter.MetricAccentKernel(kernel=None)[source]

Metric accent kernel.

>>> hierarchy = abjad.Meter((7, 8))
>>> kernel = hierarchy.generate_offset_kernel_to_denominator(8)
>>> kernel
MetricAccentKernel(kernel={Offset((0, 1)): Fraction(3, 14), Offset((7, 8)): Fraction(3, 14), Offset((3, 8)): Fraction(1, 7), Offset((5, 8)): Fraction(1, 7), Offset((1, 8)): Fraction(1, 14), Offset((1, 4)): Fraction(1, 14), Offset((1, 2)): Fraction(1, 14), Offset((3, 4)): Fraction(1, 14)})

Call the kernel against an expression from which offsets can be counted to receive an impulse-response:

>>> offsets = [(0, 8), (1, 8), (1, 8), (3, 8)]
>>> kernel(offsets)
Fraction(1, 2)

Attributes Summary

__call__

Calls metrical accent kernal on argument.

__eq__

Is true when argument is a metrical accent kernal with a kernal equal to that of this metrical accent kernel.

__hash__

Hashes metric accent kernel.

__repr__

Gets repr.

count_offsets

Count offsets in argument.

duration

Gets duration.

from_meter

Create a metric accent kernel from meter.

kernel

The kernel datastructure.


Special methods

overridden __call__(argument)[source]

Calls metrical accent kernal on argument.

>>> upper_staff = abjad.Staff("c'8 d'4. e'8 f'4.")
>>> lower_staff = abjad.Staff(r"\clef bass c4 b,4 a,2")
>>> score = abjad.Score([upper_staff, lower_staff])
>>> kernel = abjad.MetricAccentKernel.from_meter((4, 4))
>>> kernel(score)
Fraction(10, 33)

Returns float.

overridden __eq__(argument)[source]

Is true when argument is a metrical accent kernal with a kernal equal to that of this metrical accent kernel.

Returns true or false.

overridden __hash__()[source]

Hashes metric accent kernel.

Returns integer.

overridden __repr__()[source]

Gets repr.

Return type:

str


Class & static methods

static count_offsets(argument)[source]

Count offsets in argument.

>>> upper_staff = abjad.Staff("c'8 d'4. e'8 f'4.")
>>> lower_staff = abjad.Staff(r"\clef bass c4 b,4 a,2")
>>> score = abjad.Score([upper_staff, lower_staff])
>>> abjad.show(score)  
>>> MetricAccentKernel = abjad.MetricAccentKernel
>>> leaves = abjad.select.leaves(score)
>>> counter = abjad.MetricAccentKernel.count_offsets(leaves)
>>> for offset, count in sorted(counter.items.items()):
...     offset, count
... 
(Offset((0, 1)), 2)
(Offset((1, 8)), 2)
(Offset((1, 4)), 2)
(Offset((1, 2)), 4)
(Offset((5, 8)), 2)
(Offset((1, 1)), 2)
>>> a = abjad.Timespan(0, 10)
>>> b = abjad.Timespan(5, 15)
>>> c = abjad.Timespan(15, 20)
>>> counter = MetricAccentKernel.count_offsets((a, b, c))
>>> for offset, count in sorted(counter.items.items()):
...     offset, count
... 
(Offset((0, 1)), 1)
(Offset((5, 1)), 1)
(Offset((10, 1)), 1)
(Offset((15, 1)), 2)
(Offset((20, 1)), 1)

Returns counter.

Return type:

OffsetCounter

static from_meter(meter, denominator=32, normalize=True)[source]

Create a metric accent kernel from meter.

Returns new metric accent kernel.


Read-only properties

duration

Gets duration.

kernel

The kernel datastructure.

Returns dict.


Functions

illustrate_meter_list

Illustrates meters.

abjad.meter.illustrate_meter_list(meter_list, denominator=16, range_=None, scale=None)[source]

Illustrates meters.

>>> meters = [abjad.Meter(_) for _ in [(3, 4), (5, 16), (7, 8)]]
>>> lilypond_file = abjad.meter.illustrate_meter_list(meters, scale=0.5)
>>> abjad.show(lilypond_file)  
Return type:

LilyPondFile