sustain_notes

auxjad.mutate.sustain_notes(container: abjad.score.Container, *, sustain_multimeasure_rests: bool = True, rewrite_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 will sustain all pitched leaves until the next pitched leaf, thus replacing all rests in between them.

Basic usage:

Simply call the function on a container.

>>> staff = abjad.Staff(r"c'16 r8. d'16 r8. e'16 r8. f'16 r8.")
>>> abjad.show(staff)
../_images/sustain_notes-w1e1pmruyce.png
>>> auxjad.mutate.sustain_notes(staff)
>>> abjad.show(staff)
../_images/sustain_notes-ythfpvkrvue.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.close_containers(staff)
>>> abjad.mutate.close_containers(staff)
Leaves with same pitch:

Leaves are sustained until the next pitched leaf, even if the pitch is the same.

>>> staff = abjad.Staff(r"c'16 r8. c'16 r8. c'16 r8. c'16 r8.")
>>> abjad.show(staff)
../_images/sustain_notes-oliqicqqw7q.png
>>> auxjad.mutate.sustain_notes(staff)
>>> abjad.show(staff)
../_images/sustain_notes-3alcbmhc2jt.png
Consecutive leaves with the same pitch:

Consecutive pitched leaves with a same pitch will not be tied.

>>> staff = abjad.Staff(
...     r"<c' e'>16 r8. <c' e'>4 <c' e'>4 <c' e'>16 r8."
... )
>>> abjad.show(staff)
../_images/sustain_notes-ek4ujjintt8.png
>>> auxjad.mutate.sustain_notes(staff)
>>> abjad.show(staff)
../_images/sustain_notes-f7au6hojq99.png
Tuplets:

This function handles tuplets.

>>> staff = abjad.Staff(
...     r"\times 2/3 {c'4 d'4 r4} r8 e'8 \times 2/3 {f'8 r4}"
... )
>>> abjad.show(staff)
../_images/sustain_notes-nsjvhnyrkea.png
>>> auxjad.mutate.sustain_notes(staff)
>>> abjad.show(staff)
../_images/sustain_notes-26l9hob8wko.png
Complex example:

This function can handle containers with a mixture of notes, chords, and rests, as well as tuplets.

>>> staff = abjad.Staff(
...     r"c'16 r8. d'16 r8. r8 r32 <e' g'>32 r16 r4 "
...     r"\times 2/3 {r4 f'4 r4} r4 g'8 r8 a'4 ~ "
...     r"a'16 r8. b'4 c''8 r8 "
...     r"r4. d''8 \times 4/5 {r8 d''2}"
... )
>>> abjad.show(staff)
../_images/sustain_notes-cpw7dvpegge.png
>>> auxjad.mutate.sustain_notes(staff)
>>> abjad.show(staff)
../_images/sustain_notes-z8t2jwxsvar.png
Multi-measure rests:

This mutation also handles multi-measure rests, including ones with non-assignable durations:

>>> staff = abjad.Staff(
...     r"r4 c'16 r8. d'16 r4.. "
...     r"R1"
...     r"r4 e'4 r2"
...     r"\time 5/8 r8 f'4 r4"
...     r"R1 * 5/8 "
...     r"r8 g'8 a'8 r4"
... )
>>> abjad.show(staff)
../_images/sustain_notes-mJOOARIUAp.png
>>> auxjad.mutate.sustain_notes(staff)
>>> abjad.show(staff)
../_images/sustain_notes-iLTiWERSvO.png
sustain_multimeasure_rests:

By default, notes are tied across multi-measure rests.

>>> staff = abjad.Staff(
...     r"r4 c'16 r8. d'16 r4.. "
...     r"R1"
...     r"r4 e'4 r2"
...     r"\time 5/8 r8 f'4 r4"
...     r"R1 * 5/8 "
...     r"r8 g'8 a'8 r4"
... )
>>> abjad.show(staff)
../_images/sustain_notes-P2CLdKi6Cs.png

To disable sustaining across those, set sustain_multimeasure_rests to False:

>>> auxjad.mutate.sustain_notes(staff, sustain_multimeasure_rests=True)
>>> abjad.show(staff)
../_images/sustain_notes-9WeilArLex.png
rewrite_meter:

By default, auxjad.mutate.auto_rewrite_meter() is summoned after notes are sustained.

>>> staff = abjad.Staff(
...     r"r4 c'16 r8. d'16 r4.. "
...     r"R1"
...     r"r4 e'4 r2"
...     r"\time 5/8 r8 f'4 r4"
...     r"R1 * 5/8 "
...     r"r8 g'8 a'8 r4"
... )
>>> abjad.show(staff)
../_images/sustain_notes-Egibb7mRfJ.png

To disable this behaviour, set rewrite_meter to False:

>>> auxjad.mutate.sustain_notes(staff, rewrite_meter=False)
>>> abjad.show(staff)
../_images/sustain_notes-iTuoVMoWgm.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.