abjad.meter

abjad.meter.illustrate_meter_list(meter_list)

Illustrates meters.

abjad.meter.make_best_guess_rtc(pair, *[, ...])

Makes best-guess rhythm-tree container.

abjad.meter.Meter(root_node)

Meter.

abjad.meter.MetricAccentKernel([kernel])

Metric accent kernel.

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))))
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)  

denominator

Gets denominator of meter.

depthwise_offset_inventory

Gets depthwise offset inventory of meter.

duration

Gets duration of meter.

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(components, *[, boundary_depth, ...])

Rewrites components according to meter.

root_node

Gets root node of meter.

rtm_format

Gets RTM format of meter.

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.

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)
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 defined equal to those meters with a numerator divisible by 3 (but not equal to 3).

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
is_simple

Is true when meter is simple.

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.

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 
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))))
rewrite(components: Sequence[Component], *, boundary_depth: int | None = None, do_not_rewrite_tuplets: bool = False, initial_offset: Offset = Offset((0, 1)), maximum_dot_count: int | None = None) 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:

>>> string = "| 2/4 c'2 ~ |"
>>> string += "| 4/4 c'32 d'2.. ~ d'16 e'32 ~ |"
>>> string += "| 2/4 e'2 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 2/4 c'2 ~ |"
>>> string += "| 4/4 c'32 d'2.. ~ d'16 e'32 ~ |"
>>> string += "| 2/4 e'2 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 3/4 c'32 d'8 e'8 fs'4... |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 9/8 c'2 d'2 e'8 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 9/8 c'2 d'2 e'8 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 9/8 c'2 d'2 e'8 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(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:

>>> string = "| 4/4 c'16 ~ c'4 d'8. ~ "
>>> string += "2/3 { d'8. ~ 3/5 { d'16 e'8. f'16 ~ } } f'4 |"
>>> container = abjad.parsers.reduced.parse_reduced_ly_syntax(string)
>>> tuplet = abjad.select.tuplet(container, -1)
>>> abjad.tweak(tuplet, r"\tweak text #tuplet-number::calc-fraction-text")
>>> 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:

>>> string = r"c'8 ~ c'8 ~ c'8 \times 6/7 { c'4. r16 }"
>>> string += r" \times 6/7 { r16 c'4. } c'8 ~ c'8 ~ c'8"
>>> staff = abjad.Staff(string)
>>> string = r"\tweak text #tuplet-number::calc-fraction-text"
>>> for tuplet in abjad.select.tuplets(staff):
...     abjad.tweak(tuplet, 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:

>>> string = r"c'8 ~ c'8 ~ c'8 \times 6/7 { c'4. r16 }"
>>> string += r" \times 6/7 { r16 c'4. } c'8 ~ c'8 ~ c'8"
>>> staff = abjad.Staff(string)
>>> string = r"\tweak text #tuplet-number::calc-fraction-text"
>>> for tuplet in abjad.select.tuplets(staff):
...     abjad.tweak(tuplet, 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,
...     do_not_rewrite_tuplets=True,
... )
>>> abjad.show(staff)  
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)

duration

Gets duration.

kernel

The kernel dictionary.

duration

Gets duration.

kernel

The kernel dictionary.