componenttools.copy_components_and_immediate_parent_of_first_component

abjad.tools.componenttools.copy_components_and_immediate_parent_of_first_component.copy_components_and_immediate_parent_of_first_component(components)[source]

New in version 1.1.

Clone components and immediate parent of first component.

The components must be thread-contiguous.

Return in newly created container equal to type of first element in copmonents.

If the parent of the first element in components is a tuplet then insure that the tuplet multiplier of the function output equals the tuplet multiplier of the parent of the first element in components.

abjad> voice = Voice(tuplettools.FixedDurationTuplet(Duration(2, 8), notetools.make_repeated_notes(3)) * 3)
abjad> pitchtools.set_ascending_named_diatonic_pitches_on_nontied_pitched_components_in_expr(voice)
abjad> beam = spannertools.BeamSpanner(voice.leaves[:4])
abjad> f(voice)
\new Voice {
    \times 2/3 {
        c'8 [
        d'8
        e'8
    }
    \times 2/3 {
        f'8 ]
        g'8
        a'8
    }
    \times 2/3 {
        b'8
        c''8
        d''8
    }
}
abjad> new_tuplet = componenttools.copy_components_and_immediate_parent_of_first_component(voice.leaves[:2])
abjad> new_tuplet
FixedDurationTuplet(1/6, [c'8, d'8])
abjad> f(new_tuplet)
\times 2/3 {
    c'8 [
    d'8 ]
}

Parent-contiguity is not required. Thread-contiguous components suffice.

abjad> new_tuplet = componenttools.copy_components_and_immediate_parent_of_first_component(voice.leaves[:5])
abjad> new_tuplet
FixedDurationTuplet(5/12, [c'8, d'8, e'8, f'8, g'8])
abjad> f(new_tuplet)
\times 2/3 {
    c'8 [
    d'8
    e'8
    f'8 ]
    g'8
}

Note

this function copies only the immediate parent of the first element in components. This function ignores any further parentage of components above the immediate parent of components.

Todo

this function should (but does not) copy marks that attach to components and to the immediate parent of the first component; extend function to do so.

Changed in version 2.0: renamed clonewp.with_parent() to componenttools.copy_components_and_immediate_parent_of_first_component().

Changed in version 2.0: renamed componenttools.clone_components_and_immediate_parent_of_first_component() to componenttools.copy_components_and_immediate_parent_of_first_component().

This Page