def test_mutate__split_container_by_duration_01():
    """
    Split one container in score.
    Adds tie after split.
    """

    staff = abjad.Staff()
    staff.append(abjad.Container("c'8 d'8"))
    staff.append(abjad.Container("e'8 f'8"))
    leaves = abjad.select(staff).leaves()
    abjad.beam(leaves[:2])
    abjad.beam(leaves[-2:])
    abjad.slur(leaves)

    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            {
                c'8
                [
                (
                d'8
                ]
            }
            {
                e'8
                [
                f'8
                )
                ]
            }
        }
        """), print(abjad.lilypond(staff))

    abjad.mutate._split_container_by_duration(staff[0], abjad.Duration(1, 32))

    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            {
                c'32
                [
                (
                ~
            }
            {
                c'16.
                d'8
                ]
            }
            {
                e'8
                [
                f'8
                )
                ]
            }
        }
        """), print(abjad.lilypond(staff))

    assert abjad.wf.wellformed(staff)
def test_Selection__immediately_precedes_11():

    upper_voice_1 = abjad.Voice("c''8 d''8 e''8 f''8")
    upper_voice_2 = abjad.Voice("g''8 a''8 b''8 c''8")
    lower_voice_1 = abjad.Voice("c'8 d'8 e'8 f'8")
    lower_voice_2 = abjad.Voice("g'8 a'8 b'8 c''8")
    staff_1 = abjad.Staff([upper_voice_1, lower_voice_1])
    staff_2 = abjad.Staff([upper_voice_2, lower_voice_2])
    staff_1.simultaneous = True
    staff_2.simultaneous = True
    container = abjad.Container([staff_1, staff_2])

    assert abjad.lilypond(container) == abjad.String.normalize(
        r"""
        {
            \new Staff
            <<
                \new Voice
                {
                    c''8
                    d''8
                    e''8
                    f''8
                }
                \new Voice
                {
                    c'8
                    d'8
                    e'8
                    f'8
                }
            >>
            \new Staff
            <<
                \new Voice
                {
                    g''8
                    a''8
                    b''8
                    c''8
                }
                \new Voice
                {
                    g'8
                    a'8
                    b'8
                    c''8
                }
            >>
        }
        """
    )

    assert abjad.Selection._immediately_precedes(staff_1, staff_2)
    assert abjad.Selection._immediately_precedes(staff_1, staff_2[0])
    assert abjad.Selection._immediately_precedes(staff_1, staff_2[0][0])
    assert abjad.Selection._immediately_precedes(staff_1, staff_2[1])
    assert abjad.Selection._immediately_precedes(staff_1, staff_2[1][0])

    assert abjad.Selection._immediately_precedes(staff_1[0], staff_2)
    assert abjad.Selection._immediately_precedes(staff_1[0], staff_2[0])
    assert abjad.Selection._immediately_precedes(staff_1[0], staff_2[0][0])
    assert abjad.Selection._immediately_precedes(staff_1[0], staff_2[1])
    assert abjad.Selection._immediately_precedes(staff_1[0], staff_2[1][0])

    assert abjad.Selection._immediately_precedes(staff_1[0][-1], staff_2)
    assert abjad.Selection._immediately_precedes(staff_1[0][-1], staff_2[0])
    assert abjad.Selection._immediately_precedes(staff_1[0][-1], staff_2[0][0])
    assert abjad.Selection._immediately_precedes(staff_1[0][-1], staff_2[1])
    assert abjad.Selection._immediately_precedes(staff_1[0][-1], staff_2[1][0])

    assert abjad.Selection._immediately_precedes(staff_1[1], staff_2)
    assert abjad.Selection._immediately_precedes(staff_1[1], staff_2[0])
    assert abjad.Selection._immediately_precedes(staff_1[1], staff_2[0][0])
    assert abjad.Selection._immediately_precedes(staff_1[1], staff_2[1])
    assert abjad.Selection._immediately_precedes(staff_1[1], staff_2[1][0])

    assert abjad.Selection._immediately_precedes(staff_1[1][-1], staff_2)
    assert abjad.Selection._immediately_precedes(staff_1[1][-1], staff_2[0])
    assert abjad.Selection._immediately_precedes(staff_1[1][-1], staff_2[0][0])
    assert abjad.Selection._immediately_precedes(staff_1[1][-1], staff_2[1])
    assert abjad.Selection._immediately_precedes(staff_1[1][-1], staff_2[1][0])
예제 #3
0
 def print(self):
     """Print ``muda.Material.container`` lilypond code."""
     print(abjad.lilypond(self.container))
예제 #4
0
def test_Container___setitem___08():
    r"""
    Replaces note in one score with container from another score.
    """

    notes = [
        abjad.Note("c'8"),
        abjad.Note("d'8"),
        abjad.Note("e'8"),
        abjad.Note("f'8"),
        abjad.Note("g'8"),
        abjad.Note("a'8"),
        abjad.Note("b'8"),
    ]
    voice_1 = abjad.Voice(notes[:3])
    abjad.beam(voice_1[:])

    assert abjad.lilypond(voice_1) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
            ]
        }
        """), print(abjad.lilypond(voice_1))

    voice_2 = abjad.Voice(notes[3:])
    abjad.mutate.wrap(voice_2[1:3], abjad.Container())
    leaves = abjad.select(voice_2).leaves()
    leaves = abjad.select(voice_2[1]).leaves()
    abjad.slur(leaves)

    assert abjad.lilypond(voice_2) == abjad.String.normalize(r"""
        \new Voice
        {
            f'8
            {
                g'8
                (
                a'8
                )
            }
            b'8
        }
        """), print(abjad.lilypond(voice_2))

    voice_1[1] = voice_2[1]

    assert abjad.lilypond(voice_1) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            {
                g'8
                (
                a'8
                )
            }
            e'8
            ]
        }
        """), print(abjad.lilypond(voice_1))

    assert abjad.wf.wellformed(voice_1)

    assert abjad.lilypond(voice_2) == abjad.String.normalize(r"""
        \new Voice
        {
            f'8
            b'8
        }
        """), print(abjad.lilypond(voice_2))

    assert abjad.wf.wellformed(voice_2)
예제 #5
0
def test_Container___setitem___20():
    r"""
    You can use setitem to empty the contents of a container.
    """

    staff = abjad.Staff("c'8 d'8 [ e'8 ] f'8")
    inner_container = abjad.Container()
    abjad.mutate.wrap(staff[1:3], inner_container)
    outer_container = abjad.Container()
    abjad.mutate.wrap(inner_container, outer_container)

    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            c'8
            {
                {
                    d'8
                    [
                    e'8
                    ]
                }
            }
            f'8
        }
        """), print(abjad.lilypond(staff))

    # sets contents of outer container to nothing
    outer_container[:] = []

    # outer container is empty and remains in score
    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            c'8
            {
            }
            f'8
        }
        """), print(abjad.lilypond(staff))

    assert abjad.lilypond(inner_container) == abjad.String.normalize(r"""
        {
            d'8
            [
            e'8
            ]
        }
        """), print(abjad.lilypond(inner_container))

    # ALTERNATIVE: use del(container)
    staff = abjad.Staff("c'8 d'8 [ e'8 ] f'8")
    inner_container = abjad.Container()
    abjad.mutate.wrap(staff[1:3], inner_container)
    outer_container = abjad.Container()
    abjad.mutate.wrap(inner_container, outer_container)

    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            c'8
            {
                {
                    d'8
                    [
                    e'8
                    ]
                }
            }
            f'8
        }
        """), print(abjad.lilypond(staff))

    # deletes outer container
    del outer_container[:]

    # outer container is empty and remains in score (as before)
    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            c'8
            {
            }
            f'8
        }
        """), print(abjad.lilypond(staff))

    # inner container leaves are still spanned
    assert abjad.lilypond(inner_container) == abjad.String.normalize(r"""
        {
            d'8
            [
            e'8
            ]
        }
        """), print(abjad.lilypond(inner_container))
예제 #6
0
def test_mutate_copy_02():
    """
    Copy one measure.
    """

    staff = abjad.Staff(
        [
            abjad.Container("c'8 d'"),
            abjad.Container("e'8 f'"),
            abjad.Container("g'8 a'"),
        ]
    )
    for container in staff:
        time_signature = abjad.TimeSignature((2, 8))
        abjad.attach(time_signature, container[0])
    leaves = abjad.select(staff).leaves()
    abjad.slur(leaves)
    abjad.trill_spanner(leaves)
    abjad.beam(leaves)

    assert abjad.lilypond(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            {
                \time 2/8
                c'8
                (
                \startTrillSpan
                [
                d'8
            }
            {
                \time 2/8
                e'8
                f'8
            }
            {
                \time 2/8
                g'8
                a'8
                )
                \stopTrillSpan
                ]
            }
        }
        """
    ), print(abjad.lilypond(staff))

    result = abjad.mutate.copy(staff[1:2])
    new = abjad.Staff(result)

    assert abjad.lilypond(new) == abjad.String.normalize(
        r"""
        \new Staff
        {
            {
                \time 2/8
                e'8
                f'8
            }
        }
        """
    ), print(abjad.lilypond(new))

    assert abjad.wf.wellformed(staff)
    assert abjad.wf.wellformed(new)
예제 #7
0
def test_Container___setitem___07():
    """
    Replaces note in one score with note from another score.
    """

    notes = [
        abjad.Note("c'8"),
        abjad.Note("d'8"),
        abjad.Note("e'8"),
        abjad.Note("f'8"),
        abjad.Note("g'8"),
        abjad.Note("a'8"),
    ]

    voice_1 = abjad.Voice(notes[:3])
    abjad.beam(voice_1[:])

    assert abjad.lilypond(voice_1) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
            ]
        }
        """), print(abjad.lilypond(voice_1))

    voice_2 = abjad.Voice(notes[3:])
    abjad.beam(voice_2[:])

    assert abjad.lilypond(voice_2) == abjad.String.normalize(r"""
        \new Voice
        {
            f'8
            [
            g'8
            a'8
            ]
        }
        """), print(abjad.lilypond(voice_2))

    voice_1[1] = voice_2[1]

    assert abjad.lilypond(voice_1) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            g'8
            e'8
            ]
        }
        """), print(abjad.lilypond(voice_1))

    assert abjad.wf.wellformed(voice_1)

    assert abjad.lilypond(voice_2) == abjad.String.normalize(r"""
        \new Voice
        {
            f'8
            [
            a'8
            ]
        }
        """), print(abjad.lilypond(voice_2))

    assert abjad.wf.wellformed(voice_2)
예제 #8
0
def test_mutate_copy_07():

    staff = abjad.Staff(
        [
            abjad.Container("c'8 d'"),
            abjad.Container("e'8 f'"),
            abjad.Container("g'8 a'"),
            abjad.Container("b'8 c''"),
        ]
    )
    for container in staff:
        time_signature = abjad.TimeSignature((2, 8))
        abjad.attach(time_signature, container[0])
    leaves = abjad.select(staff).leaves()
    abjad.beam(leaves)
    abjad.slur(leaves)

    assert abjad.lilypond(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            {
                \time 2/8
                c'8
                [
                (
                d'8
            }
            {
                \time 2/8
                e'8
                f'8
            }
            {
                \time 2/8
                g'8
                a'8
            }
            {
                \time 2/8
                b'8
                c''8
                )
                ]
            }
        }
        """
    ), print(abjad.lilypond(staff))

    result = abjad.mutate.copy(staff[-2:])
    new_staff = abjad.Staff(result)

    assert abjad.lilypond(new_staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            {
                \time 2/8
                g'8
                a'8
            }
            {
                \time 2/8
                b'8
                c''8
                )
                ]
            }
        }
        """
    ), print(abjad.lilypond(new_staff))

    assert abjad.wf.wellformed(staff)
    assert abjad.wf.wellformed(new_staff)
예제 #9
0
def test_mutate_copy_01():
    """
    Deep copies components.
    Returns Python list of copied components.
    """

    staff = abjad.Staff(
        [
            abjad.Container("c'8 d'"),
            abjad.Container("e'8 f'"),
            abjad.Container("g'8 a'"),
        ]
    )
    for container in staff:
        time_signature = abjad.TimeSignature((2, 8))
        abjad.attach(time_signature, container[0])
    leaves = abjad.select(staff).leaves()
    abjad.slur(leaves)
    abjad.trill_spanner(leaves)
    abjad.beam(leaves)

    assert abjad.lilypond(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            {
                \time 2/8
                c'8
                (
                \startTrillSpan
                [
                d'8
            }
            {
                \time 2/8
                e'8
                f'8
            }
            {
                \time 2/8
                g'8
                a'8
                )
                \stopTrillSpan
                ]
            }
        }
        """
    ), print(abjad.lilypond(staff))

    result = abjad.mutate.copy(leaves[2:4])
    new = abjad.Staff(result)

    assert abjad.lilypond(new) == abjad.String.normalize(
        r"""
        \new Staff
        {
            \time 2/8
            e'8
            f'8
        }
        """,
        print(abjad.lilypond(new)),
    )
    assert abjad.wf.wellformed(staff)
    assert abjad.wf.wellformed(new)
예제 #10
0
#
# DEMO 3#
staff = abjad.Staff("c'4 c'4 c'4 r4 c'4 c'4 r8 c'8 c'4 r1")
selections = abjad.select(staff[:])
handler = DynamicHandler(
    dynamic_list=["f", "mp", "p", "mf", "ff"],
    flare_boolean_vector=[1, 0, 0, 1],
    flare_forget=False,
    forget=False,
    name="dynamic_handler_one",
)
for run in abjad.select(selections).runs():
    ties = abjad.select(run).logical_ties()
    maker = AddSpannerAnchor(leaf=ties[-1][-1],
                             anchor_dur=abjad.Duration(1, 16))
    maker.add_spanner_anchor()
    new_ties = ties + abjad.select(
        [abjad.LogicalTie(items=maker.calc_anchor()[-1])])
    print("NEW TIES")
    print(new_ties)
    print("TIE 0")
    print(new_ties[0])
    print("TIE -1")
    print(new_ties[-1])
    handler(new_ties)
print(abjad.lilypond(staff))

# WHY DOES THE SPANNER ANCHOR ONLY EXIST AS A NOTE WITH NO LOGICAL TIE?
# WHY DOES ABJAD NOT RECOGNIZE THAT THE ANCHOR IS IN THE SELECTION?
# MULTIPLIERS DISAPPEAR AFTER abjad.show()
예제 #11
0
def test_Container_append_04():
    """
    Append spanned leaf from donor container to recipient container.
    """

    voice_1 = abjad.Voice("c'8 d'8 e'8")
    abjad.beam(voice_1[:])

    assert abjad.lilypond(voice_1) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
            ]
        }
        """), print(abjad.lilypond(voice_1))

    voice_2 = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.beam(voice_2[:])

    assert abjad.lilypond(voice_2) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        """), print(abjad.lilypond(voice_2))

    voice_1.append(voice_2[-1])

    assert abjad.lilypond(voice_1) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
            ]
            f'8
            ]
        }
        """), print(abjad.lilypond(voice_1))

    assert abjad.wf.wellformed(voice_1)

    assert abjad.lilypond(voice_2) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
        }
        """), print(abjad.lilypond(voice_2))

    assert abjad.wf.wellformed(voice_2)
예제 #12
0
def test_Voice_lilypond_voice_resolution_03():
    """
    Container containing a run of leaves.
    Two like-structured simultaneouss in the middle of the run.
    LilyPond handles this example perfectly.
    LilyPond colors the four note_heads of the soprano voice red.
    LilyPond colors all other note_heads black.
    """

    container = abjad.Container(r"""
        c'8
        <<
            \context Voice = "alto" {
                d'8
                e'8
            }
            \context Voice = "soprano" {
                f'8
                g'8
            }
        >>
        <<
            \context Voice = "alto" {
                a'8
                b'8
            }
            \context Voice = "soprano" {
                c''8
                d''8
            }
        >>
        e''8
        """)

    abjad.override(container[1][1]).note_head.color = "red"
    abjad.override(container[2][1]).note_head.color = "red"

    assert abjad.lilypond(container) == abjad.String.normalize(r"""
        {
            c'8
            <<
                \context Voice = "alto"
                {
                    d'8
                    e'8
                }
                \context Voice = "soprano"
                \with
                {
                    \override NoteHead.color = #red
                }
                {
                    f'8
                    g'8
                }
            >>
            <<
                \context Voice = "alto"
                {
                    a'8
                    b'8
                }
                \context Voice = "soprano"
                \with
                {
                    \override NoteHead.color = #red
                }
                {
                    c''8
                    d''8
                }
            >>
            e''8
        }
        """)