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/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.

MetricAccentKernel

Metric accent kernel.

class abjad.meter.Meter(root_node: RhythmTreeContainer)[source]

Meter.

Meter models rhythmic organization structured as a tree.

4/4 grouped two different ways:

>>> rtc = abjad.meter.make_best_guess_rtc((4, 4))
>>> meter = abjad.Meter(rtc)
>>> print(meter.pretty_rtm_format)
(4/4 (
    1/4
    1/4
    1/4
    1/4))
>>> abjad.graph(meter)  
>>> string = "(4/4 ((2/4 (1/4 1/4)) (2/4 (1/4 1/4))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> print(meter.pretty_rtm_format)
(4/4 (
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> abjad.graph(meter)  

6/4 grouped four different ways:

>>> rtc = abjad.meter.make_best_guess_rtc((6, 4))
>>> meter = abjad.Meter(rtc)
>>> 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)  
>>> string = "(6/4 (1/4 1/4 1/4 1/4 1/4 1/4))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> print(meter.pretty_rtm_format)
(6/4 (
    1/4
    1/4
    1/4
    1/4
    1/4
    1/4))
>>> abjad.graph(meter)  
>>> string = "(6/4 ((2/4 (1/4 1/4)) (2/4 (1/4 1/4)) (2/4 (1/4 1/4))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> print(meter.pretty_rtm_format)
(6/4 (
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> abjad.graph(meter)  
>>> part = "(3/8 (1/8 1/8 1/8))"
>>> string = f"(6/4 ({part} {part} {part} {part}))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> 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)  

7/4 grouped three different ways:

>>> string = "(7/4 ((2/4 (1/4 1/4)) (2/4 (1/4 1/4)) (3/4 (1/4 1/4 1/4))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> 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)  
>>> string = "(7/4 ((2/4 (1/4 1/4)) (3/4 (1/4 1/4 1/4)) (2/4 (1/4 1/4))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> print(meter.pretty_rtm_format)
(7/4 (
    (2/4 (
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> abjad.graph(meter)  
>>> string = "(7/4 ((3/4 (1/4 1/4 1/4)) (2/4 (1/4 1/4)) (2/4 (1/4 1/4))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> 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)  

Attributes Summary

__eq__

Compares root_node.rtm_format of self to that of argument.

__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 offset_counter.

fraction_string

Gets fraction string.

generate_offset_kernel_to_denominator

Generates MAK (dictionary) of all offsets in self up to denominator.

implied_time_signature

Gets implied time signature of meter.

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.

pretty_rtm_format

Gets pretty RTM format of meter.

rewrite

Rewrites components according to meter.

root_node

Gets root node of meter.

rtm_format

Gets RTM format of meter.


Special methods

overridden __eq__(argument) bool[source]

Compares root_node.rtm_format of self to that of argument.

__graph__(**keywords) Graph[source]

Gets Graphviz format of meter.

>>> rtc = abjad.meter.make_best_guess_rtc((7, 4))
>>> meter = abjad.Meter(rtc)
>>> abjad.graph(meter)  
overridden __hash__() int[source]

Hashes meter.

__iter__() Iterator[tuple[tuple[int, int], tuple[int, int]]][source]

Iterates meter.

Iterates 5/4:

>>> rtc = abjad.meter.make_best_guess_rtc((5, 4))
>>> meter = abjad.Meter(rtc)
>>> 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))
overridden __repr__() str[source]

Gets repr.


Methods

generate_offset_kernel_to_denominator(denominator: int) MetricAccentKernel[source]

Generates MAK (dictionary) of all offsets in self up to denominator.

Keys of MAK are offsets.

Values of MAK are normalized weights of those offsets.

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

>>> rtc = abjad.meter.make_best_guess_rtc((4, 4))
>>> meter = abjad.Meter(rtc)
>>> kernel = meter.generate_offset_kernel_to_denominator(8)
>>> for offset, weight in sorted(kernel.kernel.items()):
...     print(f"{offset!r}\t{weight!r}")
... 
Offset((0, 1))	Fraction(3, 16)
Offset((1, 8))	Fraction(1, 16)
Offset((1, 4))	Fraction(1, 8)
Offset((3, 8))	Fraction(1, 16)
Offset((1, 2))	Fraction(1, 8)
Offset((5, 8))	Fraction(1, 16)
Offset((3, 4))	Fraction(1, 8)
Offset((7, 8))	Fraction(1, 16)
Offset((1, 1))	Fraction(3, 16)
rewrite(components: Sequence[Component], *, boundary_depth: int | None = None, initial_offset: Offset = Offset((0, 1)), maximum_dot_count: int | None = None, rewrite_tuplets: bool = True) None[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)  
>>> rtc = abjad.meter.make_best_guess_rtc((4, 4))
>>> meter = abjad.Meter(rtc)
>>> print(meter.pretty_rtm_format)
(4/4 (
    1/4
    1/4
    1/4
    1/4))
>>> meter.rewrite(staff[1][:])
>>> 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)  
>>> string = "(4/4 ((2/4 (1/4 1/4)) (2/4 (1/4 1/4))))"
>>> rtc = abjad.rhythmtrees.parse(string)[0]
>>> meter = abjad.Meter(rtc)
>>> print(meter.pretty_rtm_format)  
(4/4 (
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> meter.rewrite(staff[1][:])
>>> 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)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:])
>>> 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)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:], 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)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:], 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)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:], 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:

>>> rtc = abjad.meter.make_best_guess_rtc((9, 8))
>>> meter = abjad.Meter(rtc)
>>> 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)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:])
>>> 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)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:], 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)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:], 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)
...         rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
...         meter = abjad.Meter(rtc)
...         meter.rewrite(container[:])
... 
>>> 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)
...         rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
...         meter = abjad.Meter(rtc)
...         meter.rewrite(container[:], 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, abjad.Meter.rewrite() will recurse into those containers, treating them as measures whose time signature is derived from the preprolated duration of the container’s contents:

>>> measure = staff[0]
>>> time_signature = abjad.get.indicator(measure[0], abjad.TimeSignature)
>>> rtc = abjad.meter.make_best_guess_rtc(time_signature.pair)
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(measure[:], 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])
>>> rtc = abjad.meter.make_best_guess_rtc((6, 8))
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(staff[:])
>>> 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])
>>> rtc = abjad.meter.make_best_guess_rtc((6, 8))
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(staff[:], boundary_depth=1)
>>> abjad.show(staff)  

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)  
>>> rtc = abjad.meter.make_best_guess_rtc((6, 4))
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(staff[:], 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)  
>>> rtc = abjad.meter.make_best_guess_rtc((6, 4))
>>> meter = abjad.Meter(rtc)
>>> meter.rewrite(
...     staff[:],
...     boundary_depth=1,
...     rewrite_tuplets=False,
... )
>>> abjad.show(staff)  

Class & static methods

static fit_meters(offset_counter: OffsetCounter, meters: Sequence[Meter], denominator: int = 32, maximum_run_length: int | None = None) list[Meter][source]

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

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

Matches a series of hypothetical 4/4 measures:

>>> pairs = [(0, 4), (4, 4), (8, 4), (12, 4), (16, 4)]
>>> offsets = [abjad.Offset(_) for _ in pairs]
>>> offset_counter = abjad.OffsetCounter(offsets)
>>> for meter in abjad.Meter.fit_meters(offset_counter, 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:

>>> pairs = [(0, 4), (3, 4), (5, 4), (10, 4), (15, 4), (20, 4)]
>>> offsets = [abjad.Offset(_) for _ in pairs]
>>> offset_counter = abjad.OffsetCounter(offsets)
>>> for meter in abjad.Meter.fit_meters(offset_counter, 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)

Read-only properties

denominator

Gets denominator of meter.

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

Gets depthwise offset inventory of meter.

>>> rtc = abjad.meter.make_best_guess_rtc((7, 4))
>>> meter = abjad.Meter(rtc)
>>> for depth, offsets in enumerate(meter.depthwise_offset_inventory):
...     print(f"{depth}:")
...     for offset in offsets:
...         print(f"    {offset!r}")
... 
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))
duration

Gets duration of meter.

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

Gets fraction string.

implied_time_signature

Gets implied time signature of meter.

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

Is true when meter is compound.

Compound meters written over 4:

>>> for numerator in range(1, 13):
...     rtc = abjad.meter.make_best_guess_rtc((numerator, 4))
...     meter = abjad.Meter(rtc)
...     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):
...     rtc = abjad.meter.make_best_guess_rtc((numerator, 8))
...     meter = abjad.Meter(rtc)
...     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).

is_simple

Is true when meter is simple.

Simple meters written over 4:

>>> for numerator in range(1, 13):
...     rtc = abjad.meter.make_best_guess_rtc((numerator, 4))
...     meter = abjad.Meter(rtc)
...     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):
...     rtc = abjad.meter.make_best_guess_rtc((numerator, 8))
...     meter = abjad.Meter(rtc)
...     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.

numerator

Gets numerator of meter.

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

Gets pair of numerator and denominator of meter.

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

Gets pretty RTM format of meter.

>>> rtc = abjad.meter.make_best_guess_rtc((7, 4))
>>> meter = abjad.Meter(rtc)
>>> 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))))
root_node

Gets root node of meter.

>>> rtc = abjad.meter.make_best_guess_rtc((7, 4))
>>> meter = abjad.Meter(rtc)
>>> for item in meter.root_node:
...     item
... 
RhythmTreeContainer((3, 4))
RhythmTreeContainer((2, 4))
RhythmTreeContainer((2, 4))
rtm_format

Gets RTM format of meter.

>>> rtc = abjad.meter.make_best_guess_rtc((7, 4))
>>> meter = abjad.Meter(rtc)
>>> 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))))'
class abjad.meter.MetricAccentKernel(kernel: dict | None = None)[source]

Metric accent kernel.

>>> rtc = abjad.meter.make_best_guess_rtc((7, 8))
>>> hierarchy = abjad.Meter(rtc)
>>> kernel = hierarchy.generate_offset_kernel_to_denominator(8)
>>> for offset, weight in kernel.kernel.items():
...     print(f"{offset!r}: {weight!r}")
... 
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:

>>> pairs = [(0, 8), (1, 8), (1, 8), (3, 8)]
>>> offsets = [abjad.Offset(_) for _ in pairs]
>>> offset_counter = abjad.OffsetCounter(offsets)
>>> kernel(offset_counter)
Fraction(1, 2)

Attributes Summary

__call__

Calls metric accent kernal on offset_counter.

__eq__

Is true when argument is a metric accent kernal with a kernal equal to that of self.

__hash__

Hashes metric accent kernel.

__repr__

Gets repr.

duration

Gets duration.

from_meter

Create a metric accent kernel from meter.

kernel

The kernel dictionary.


Special methods

overridden __call__(offset_counter: OffsetCounter) Fraction[source]

Calls metric accent kernal on offset_counter.

>>> 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)  
>>> rtc = abjad.meter.make_best_guess_rtc((4, 4))
>>> meter = abjad.Meter(rtc)
>>> kernel = abjad.MetricAccentKernel.from_meter(meter)
>>> offset_counter = abjad.OffsetCounter(score)
>>> kernel(offset_counter)
Fraction(10, 33)
overridden __eq__(argument) bool[source]

Is true when argument is a metric accent kernal with a kernal equal to that of self.

overridden __hash__() int[source]

Hashes metric accent kernel.

overridden __repr__() str[source]

Gets repr.


Class & static methods

static from_meter(meter: Meter, denominator: int = 32) MetricAccentKernel[source]

Create a metric accent kernel from meter.


Read-only properties

duration

Gets duration.

kernel

The kernel dictionary.


Functions

illustrate_meter_list

Illustrates meters.

make_best_guess_rtc

Makes best-guess rhythm-tree container.

abjad.meter.illustrate_meter_list(meter_list: list[Meter], denominator: int = 16, range_: tuple | None = None, scale: float = 1.0) LilyPondFile[source]

Illustrates meters.

The PNG image that would be rendered below fails to draw vertical lines in Postscript. But the output renders correctly as a PDF. To see the effect of this function, paste the excerpt below into a test file and call LilyPond on that test file:

>>> pairs = [(3, 4), (5, 16), (7, 8)]
>>> rtcs = [abjad.meter.make_best_guess_rtc(_) for _ in pairs]
>>> meters = [abjad.Meter(_) for _ in rtcs]
>>> lilypond_file = abjad.meter.illustrate_meter_list(meters, scale=0.5)
abjad.meter.make_best_guess_rtc(pair: tuple[int, int], *, increase_monotonic: bool = False) RhythmTreeContainer[source]

Makes best-guess rhythm-tree container.

Prime divisions greater than 3 are converted to sequences of 2, 3 and 4 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 below.

>>> rtc = abjad.meter.make_best_guess_rtc((2, 4))
>>> print(rtc.pretty_rtm_format)
(2/4 (
    1/4
    1/4))
>>> rtc = abjad.meter.make_best_guess_rtc((3, 4))
>>> print(rtc.pretty_rtm_format)
(3/4 (
    1/4
    1/4
    1/4))
>>> rtc = abjad.meter.make_best_guess_rtc((4, 4))
>>> print(rtc.pretty_rtm_format)
(4/4 (
    1/4
    1/4
    1/4
    1/4))
>>> rtc = abjad.meter.make_best_guess_rtc((5, 4))
>>> print(rtc.pretty_rtm_format)
(5/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> rtc = abjad.meter.make_best_guess_rtc((5, 4), increase_monotonic=True)
>>> print(rtc.pretty_rtm_format)
(5/4 (
    (2/4 (
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))))
>>> rtc = abjad.meter.make_best_guess_rtc((6, 4))
>>> print(rtc.pretty_rtm_format)
(6/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))))
>>> rtc = abjad.meter.make_best_guess_rtc((7, 4))
>>> print(rtc.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))))
>>> rtc = abjad.meter.make_best_guess_rtc((7, 4), increase_monotonic=True)
>>> print(rtc.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))))
>>> rtc = abjad.meter.make_best_guess_rtc((8, 4))
>>> print(rtc.pretty_rtm_format)
(8/4 (
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))
    (2/4 (
        1/4
        1/4))))
>>> rtc = abjad.meter.make_best_guess_rtc((9, 4))
>>> print(rtc.pretty_rtm_format)
(9/4 (
    (3/4 (
        1/4
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))
    (3/4 (
        1/4
        1/4
        1/4))))
>>> rtc = abjad.meter.make_best_guess_rtc((2, 8))
>>> print(rtc.pretty_rtm_format)
(2/8 (
    1/8
    1/8))
>>> rtc = abjad.meter.make_best_guess_rtc((3, 8))
>>> print(rtc.pretty_rtm_format)
(3/8 (
    1/8
    1/8
    1/8))
>>> rtc = abjad.meter.make_best_guess_rtc((4, 8))
>>> print(rtc.pretty_rtm_format)
(4/8 (
    1/8
    1/8
    1/8
    1/8))
>>> rtc = abjad.meter.make_best_guess_rtc((5, 8))
>>> print(rtc.pretty_rtm_format)
(5/8 (
    (3/8 (
        1/8
        1/8
        1/8))
    (2/8 (
        1/8
        1/8))))
>>> rtc = abjad.meter.make_best_guess_rtc((5, 8), increase_monotonic=True)
>>> print(rtc.pretty_rtm_format)
(5/8 (
    (2/8 (
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))))
>>> rtc = abjad.meter.make_best_guess_rtc((6, 8))
>>> print(rtc.pretty_rtm_format)
(6/8 (
    (3/8 (
        1/8
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))))
>>> rtc = abjad.meter.make_best_guess_rtc((7, 8))
>>> print(rtc.pretty_rtm_format)
(7/8 (
    (3/8 (
        1/8
        1/8
        1/8))
    (2/8 (
        1/8
        1/8))
    (2/8 (
        1/8
        1/8))))
>>> rtc = abjad.meter.make_best_guess_rtc((7, 8), increase_monotonic=True)
>>> print(rtc.pretty_rtm_format)
(7/8 (
    (2/8 (
        1/8
        1/8))
    (2/8 (
        1/8
        1/8))
    (3/8 (
        1/8
        1/8
        1/8))))
>>> rtc = abjad.meter.make_best_guess_rtc((8, 8))
>>> print(rtc.pretty_rtm_format)
(8/8 (
    (2/8 (
        1/8
        1/8))
    (2/8 (
        1/8
        1/8))
    (2/8 (
        1/8
        1/8))
    (2/8 (
        1/8
        1/8))))
>>> rtc = abjad.meter.make_best_guess_rtc((9, 8))
>>> print(rtc.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))))
>>> rtc = abjad.meter.make_best_guess_rtc((12, 8))
>>> print(rtc.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))))