extract_trivial_tuplets¶
- auxjad.mutate.extract_trivial_tuplets(selection: abjad.select.Selection) → None[source]¶
Mutates an input
abjad.Selection
in place and has no return value; this function looks for tuplets filled with rests or with tied notes or chords and replaces them with a single leaf.- Basic usage:
Usage is simple:
>>> staff = abjad.Staff( ... r"\times 2/3 {r4 r2} \times 2/3 {c'8 ~ c'8 ~ c'2}" ... ) >>> abjad.show(container)
>>> auxjad.mutate(container[:]).extract_trivial_tuplets() >>> abjad.show(container)
It also works with containers with tuplets within tuplets.
>>> container = abjad.Container(r"\times 4/5 {r2. \times 2/3 {r2 r4}}") >>> abjad.show(container)
>>> auxjad.mutate(container[:]).extract_trivial_tuplets() >>> abjad.show(container)
>>> container = abjad.Container( ... r"\times 4/5 {c'2. ~ \times 2/3 {c'2 ~ c'4}}" ... ) >>> abjad.show(container)
>>> auxjad.mutate(staff[:]).extract_trivial_tuplets() >>> abjad.show(container)
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(staff[:]).extract_trivial_tuplets() >>> abjad.mutate(staff[:]).extract_trivial_tuplets()
- Partial extraction:
This function also extracts tuplets within tuplets.
>>> container = abjad.Container( ... r"r2 \times 2/3 {r2 r4} \times 4/5 {c'2. \times 2/3 {r2 r4}}" ... ) >>> abjad.show(container)
>>> auxjad.mutate(container[:]).extract_trivial_tuplets() >>> abjad.show(container)
Tip
Use
auxjad.mutate.rests_to_multimeasure_rest()
to replace measures filled with rests by a single multi-measure rest. That function makes use ofauxjad.mutate.extract_trivial_tuplets()
, so it is not necessary to flatten the empty tuplets beforehand.- Time signature changes:
Works with measures with any time signature.
>>> container = abjad.Staff(r"\time 3/4 r2. \times 3/2 {r4 r4}") >>> auxjad.mutate(container[:]).extract_trivial_tuplets() >>> abjad.show(container)
- Non-assignable durations:
This function also extracts tuplets which sum up to a non-assignable duration. In this case, it creates multiple leaves and substitutes them for the original tuplet. Indicators are passed on to the first leaf of the new leaves.
>>> staff = abjad.Staff(r"\time 6/4 c'4\f \times 5/6 {g1.\p}") >>> abjad.show(staff)
>>> abjad.mutate(staff[:]).extract_trivial_tuplets() >>> abjad.show(staff)
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)
Warning
The input selection 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.