close_container¶
- auxjad.mutate.close_container(container: abjad.score.Container) → None[source]¶
Mutates an input container (of type
abjad.Container
or child class) in place and has no return value; this function changes the time signature of the last measure of an underfull in order to make it full.- Basic usage:
Returns the missing duration of the last measure of any container or child class. If no time signature is encountered, it uses LilyPond’s convention and considers the container as in 4/4.
>>> container1 = abjad.Staff(r"c'4 d'4 e'4 f'4") >>> container2 = abjad.Staff(r"c'4 d'4 e'4") >>> container3 = abjad.Staff(r"c'4 d'4 e'4 f'4 | c'4") >>> container4 = abjad.Staff(r"c'4 d'4 e'4 f'4 | c'4 d'4 e'4 f'4") >>> auxjad.mutate.close_container(container1) >>> auxjad.mutate.close_container(container2) >>> auxjad.mutate.close_container(container3) >>> auxjad.mutate.close_container(container4) >>> abjad.show(container1)
>>> abjad.show(container2)
>>> abjad.show(container3)
>>> abjad.show(container4)
Note
Auxjad automatically adds this function as an extension function to
abjad.mutate
. It can thus be used from eitherauxjad.mutate
orabjad.mutate
namespaces. Therefore, the two lines below are equivalent:>>> auxjad.mutate.close_containers(staff) >>> abjad.mutate.close_containers(staff)
- Time signature changes:
Handles any time signatures as well as changes of time signature.
>>> container1 = abjad.Staff(r"\time 4/4 c'4 d'4 e'4 f'4 g'") >>> container2 = abjad.Staff(r"\time 3/4 a2. \time 2/4 c'4") >>> container3 = abjad.Staff(r"\time 5/4 g1 ~ g4 \time 4/4 af'2") >>> auxjad.mutate.close_container(container1) >>> auxjad.mutate.close_container(container2) >>> auxjad.mutate.close_container(container3) >>> abjad.show(container1)
>>> abjad.show(container2)
>>> abjad.show(container3)
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 aabjad.Staff
. The present function works with eitherabjad.Container
andabjad.Staff
.>>> container = abjad.Container(r"\time 3/4 c'4 d'4 e'4") >>> abjad.show(container)
>>> staff = abjad.Staff([container]) >>> abjad.show(container)
- Partial time signatures:
Correctly handles partial time signatures.
>>> container = abjad.Staff(r"c'4 d'4 e'4 f'4 g'4") >>> time_signature = abjad.TimeSignature((3, 4), partial=(1, 4)) >>> abjad.attach(time_signature, container[0]) >>> auxjad.mutate.close_container(container) >>> abjad.show(container)
Error
If a container is malformed, i.e. it has an underfilled measure before a time signature change, the function raises a
ValueError
exception.>>> container = abjad.Container(r"\time 5/4 g''1 \time 4/4 f'4") >>> auxjad.mutate.close_container(container) ValueError: 'container' is malformed, with an underfull measure preceding a time signature change
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.