enforce_time_signature

auxjad.mutate.enforce_time_signature(container: abjad.score.Container, time_signatures: Union[abjad.indicators.TimeSignature.TimeSignature, tuple, list], *, cyclic: bool = False, fill_with_rests: bool = True, close_container: bool = False, disable_rewrite_meter: bool = False, prettify_rewrite_meter: bool = True, boundary_depth: Optional[int] = None, maximum_dot_count: Optional[int] = None, rewrite_tuplets: bool = True, extract_trivial_tuplets: bool = True, fuse_across_groups_of_beats: bool = True, fuse_quadruple_meter: bool = True, fuse_triple_meter: bool = True, split_quadruple_meter: bool = True)None[source]

Mutates an input container (of type abjad.Container or child class) in place and has no return value; this function applies a time signature (or a list of time signatures) to the input container.

Basic usage:

The function mutates a container in place, applying a time signature to it.

>>> staff = abjad.Staff(r"c'1 d'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-9bf9zmnm19k.png
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     abjad.TimeSignature((2, 4))
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-kerf9uos62i.png

Note

Auxjad automatically adds this function as an extension function to abjad.mutate. It can thus be used from either auxjad.mutate or abjad.mutate namespaces. Therefore, the two lines below are equivalent:

>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     abjad.TimeSignature((2, 4)),
... )
>>> abjad.mutate.enforce_time_signature(
...     staff,
...     abjad.TimeSignature((2, 4)),
... )
Single value for second positional argument:

The second positional argument can take either abjad.TimeSignature or a tuple for a single time signature (for multiple time signatures, use a list as shown further below). By default, rests will be appended to the end of the staff if necessary.

>>> staff = abjad.Staff(r"c'1 d'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-218f65bsco3.png
>>> auxjad.mutate.enforce_time_signature(staff, (3, 4))
>>> abjad.show(staff)
../_images/enforce_time_signature-u4p457k6ib7.png
close_container:

Set the optional keyword argument close_container to True in order to adjust the last measure’s time signature instead of filling it with rests.

>>> staff = abjad.Staff(r"c'1 d'1 e'1 f'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-tn1l53yimir.png
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     abjad.TimeSignature((3, 4)),
...     close_container=True,
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-1uhp08fqlpl.png
fill_with_rests:

Alternatively, to leave the last measure as it is input (i.e. not filling it with rests nor adjusting the time signature), set the optional keyword argument fill_with_rests to False (default value is True).

>>> staff = abjad.Staff(r"c'1 d'1 e'1 f'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-bit2y19hncr.png
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     abjad.TimeSignature((3, 4)),
...     fill_with_rests=False,
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-xo7fpeqsoek.png
Multiple values for second positional argument:

The second argument can also take a list of abjad.TimeSignature or tuple.

>>> staff = abjad.Staff(r"c'1 d'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-rl1csjn9osl.png
>>> time_signatures = [abjad.TimeSignature((3, 4)),
...                    abjad.TimeSignature((5, 4)),
...                    ]
>>> auxjad.mutate.enforce_time_signature(staff, time_signatures)
>>> abjad.show(staff)
../_images/enforce_time_signature-tqqrqi34bu.png
Repeated time signatures:

Consecutive identical time signatures are omitted. Also note that time signatures can also be represented as a list of tuple’s.

>>> staff = abjad.Staff(r"c'1 d'1 e'1 f'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-vn9ngz2k6cd.png
>>> time_signatures = [(2, 4),
...                    (2, 4),
...                    (4, 4),
...                    ]
>>> auxjad.mutate.enforce_time_signature(staff, time_signatures)
>>> abjad.show(staff)
../_images/enforce_time_signature-nj2c90o0pe.png

Alternatively, use None to indicate repeated time signatures:

>>> staff = abjad.Staff(r"c'1 d'1 e'1 f'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-2og5ld8bkxe.png
>>> time_signatures = [(2, 4),
...                    None,
...                    None,
...                    (3, 4),
...                    None,
...                    (4, 4),
...                    ]
>>> auxjad.mutate.enforce_time_signature(staff, time_signatures)
>>> abjad.show(staff)
../_images/enforce_time_signature-3s9h7p1k05x.png
Implicit time signature:

If the first time signature in a list is None, this function assumes the music is written in 4/4 time signature, although it does not force it in the output. This is similar to LilyPond’s behaviour, which fallbacks to a 4/4 time signature when none is present.

>>> staff = abjad.Staff(r"c'1 d'1 e'2. f'2.")
>>> time_signatures = [None,
...                    None,
...                    (3, 4),
...                    None,
...                    ]
>>> auxjad.mutate.enforce_time_signature(staff, time_signatures)
>>> abjad.show(staff)
../_images/enforce_time_signature-cJe2YevEo7.png
cyclic:

To cycle through the list of time signatures until the container is exhausted, set the optional keyword argument cyclic to True.

>>> staff = abjad.Staff(r"c'1 d'1 e'1 f'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-vl1bwp21saq.png
>>> time_signatures = [abjad.TimeSignature((3, 8)),
...                    abjad.TimeSignature((2, 8)),
...                    ]
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     time_signatures,
...     cyclic=True,
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-9mq64erlth6.png
disable_rewrite_meter:

By default, this function applies the mutation abjad.Meter.rewrite_meter() to its output.

>>> staff = abjad.Staff(r"c'1 ~ c'4 r8 d'4. e'4")
>>> time_signatures = [abjad.TimeSignature((5, 4)),
...                    abjad.TimeSignature((3, 4)),
...                    ]
>>> auxjad.mutate.enforce_time_signature(staff, time_signatures)
>>> abjad.show(staff)
../_images/enforce_time_signature-xsjbr0vnev9.png

To disable this, set the keyword argument disable_rewrite_meter to True.

>>> staff = abjad.Staff(r"c'1 ~ c'4 r8 d'4. e'4")
>>> time_signatures = [abjad.TimeSignature((5, 4)),
...                    abjad.TimeSignature((3, 4)),
...                    ]
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     time_signatures,
...     disable_rewrite_meter=True,
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-ezjnpwjd3xu.png
Tuplets:

The function handles tuplets, even if they must be split.

>>> staff = abjad.Staff(r"\times 2/3 {c'2 d'2 e'2} f'1")
>>> abjad.show(staff)
../_images/enforce_time_signature-v4ndqpmqjk.png
>>> time_signatures = [abjad.TimeSignature((2, 4)),
...                    abjad.TimeSignature((3, 4)),
...                    ]
>>> auxjad.mutate.enforce_time_signature(staff, time_signatures)
>>> abjad.show(staff)
../_images/enforce_time_signature-5jdoukq2rkd.png
Time signatures in the input container:

Note that any time signatures in the input container will be ignored.

>>> staff = abjad.Staff(r"\time 3/4 c'2. d'2. e'2. f'2.")
>>> abjad.show(staff)
../_images/enforce_time_signature-bnnz1hov5bu.png
>>> time_signatures = [abjad.TimeSignature((5, 8)),
...                    abjad.TimeSignature((1, 16)),
...                    abjad.TimeSignature((2, 4)),
...                    ]
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     time_signatures,
...     cyclic=True,
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-2l289r8sdzl.png
Tweaking abjad.Meter.rewrite_meter():

This function uses the default logical tie splitting algorithm from abjad.Meter.rewrite_meter().

>>> staff = abjad.Staff(r"c'4. d'8 e'2")
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     abjad.TimeSignature((4, 4)),
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-bykbobzx47.png

Set boundary_depth to a different number to change its behaviour.

>>> staff = abjad.Staff(r"c'4. d'8 e'2")
>>> auxjad.mutate.enforce_time_signature(
...     staff,
...     abjad.TimeSignature((4, 4)),
...     boundary_depth=1,
... )
>>> abjad.show(staff)
../_images/enforce_time_signature-wljhgmjh9c.png

Other arguments available for tweaking the output of abjad.Meter.rewrite_meter() are maximum_dot_count and rewrite_tuplets, which work exactly as the identically named arguments of abjad.Meter.rewrite_meter().

This function also accepts the arguments fuse_across_groups_of_beats, fuse_quadruple_meter, fuse_triple_meter, extract_trivial_tuplets, and split_quadruple_meter, which are passed on to auxjad.mutate.prettify_rewrite_meter() (the latter can be disabled by setting prettify_rewrite_meter to False). See the documentation of this function for more details on these arguments.

Note

When using abjad.Container’s, all time signatures in the output will be commented out with %%%. This is because Abjad only applies time signatures to containers that belong to a abjad.Staff. The present function works with either abjad.Container and abjad.Staff.

>>> container = abjad.Container(r"\time 3/4 c'4 d'4 e'4")
>>> abjad.show(container)
../_images/enforce_time_signature-ntl3jgbi7j.png
>>> staff = abjad.Staff([container])
>>> abjad.show(container)
../_images/enforce_time_signature-y5sjtx3j0v.png

Warning

The input container must be a contiguous logical voice. When dealing with a container with multiple subcontainers (e.g. a score containing multiple staves), the best approach is to cycle through these subcontainers, applying this function to them individually.