How to use the abjad.String.normalize function in abjad

To help you get started, we’ve selected a few abjad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Abjad / abjad / tests / test_Spanner_format.py View on Github external
def test_Spanner_format_01():
    """
    Base Spanner class makes no format-time contributions.
    However, base spanner causes no explosions at format-time, either.
    """

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    spanner = abjad.Spanner()
    abjad.attach(spanner, staff[:])

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            c'8
            d'8
            e'8
            f'8
        }
        """
        )

    assert abjad.inspect(staff).wellformed()
github Abjad / abjad / tests / test_LilyPondParser__indicators__MetronomeMark.py View on Github external
def test_LilyPondParser__indicators__MetronomeMark_04():

    target = abjad.Score([abjad.Staff([abjad.Note(0, 1)])])
    mark = abjad.MetronomeMark(
        reference_duration=(1, 4),
        units_per_minute=60,
        textual_indication="Like a majestic swan, alive with youth and vigour!",
    )
    leaves = abjad.select(target).leaves()
    abjad.attach(mark, leaves[0], context="Staff")

    assert format(target) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                \tempo "Like a majestic swan, alive with youth and vigour!" 4=60
                c'1
            }
        >>
        """
    )

    parser = abjad.parser.LilyPondParser()
    result = parser(format(target))
    assert format(target) == format(result) and target is not result
    leaves = abjad.select(result).leaves()
github Abjad / abjad / tests / test_Mutation_replace.py View on Github external
def test_Mutation_replace_02():
    """
    Moves parentage from one old note to five new notes.

    Equivalent to staff[:1] = new_notes.
    """

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    abjad.beam(staff[:2])
    abjad.beam(staff[2:])

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

    old_notes = staff[:1]
github Abjad / abjad / tests / test_Leaf__set_duration.py View on Github external
r"""
        \new Voice
        {
            c'8
            [
            r8
            e'8
            ]
            f'8
        }
        """
    ), print(format(voice))

    voice[1]._set_duration(abjad.Duration(5, 32))

    assert format(voice) == abjad.String.normalize(
        r"""
        \new Voice
        {
            c'8
            [
            r8
            r32
            e'8
            ]
            f'8
        }
        """
    ), print(format(voice))

    assert abjad.inspect(voice).wellformed()
github Abjad / abjad / tests / test_LogicalTie__add_or_remove_notes_to_achieve_written_duration.py View on Github external
def test_LogicalTie__add_or_remove_notes_to_achieve_written_duration_01():
    """
    Change trivial logical tie to nontrivial logical tie.
    """

    staff = abjad.Staff("c'8 [ ]")
    logical_tie = abjad.inspect(staff[0]).logical_tie()
    logical_tie._add_or_remove_notes_to_achieve_written_duration(abjad.Duration(5, 32))

    assert abjad.inspect(staff).wellformed()
    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            c'8
            [
            ]
            ~
            c'32
            [
            ]
        }
        """
    ), print(format(staff))
github Abjad / abjad / tests / test_Staff_engraver_consists.py View on Github external
def test_Staff_engraver_consists_01():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    staff.consists_commands.append("Horizontal_bracket_engraver")
    staff.consists_commands.append("Instrument_name_engraver")

    assert abjad.inspect(staff).wellformed()
    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
github Abjad / abjad / tests / test_Inspection_leaf.py View on Github external
def test_Inspection_leaf_25():
    """
    Returns none on nested differently named voices.
    """

    inner_voice = abjad.Voice([abjad.Note(i, (1, 8)) for i in range(3)])
    inner_voice.name = "Your Voice"
    outer_voice = abjad.Voice([inner_voice, abjad.Note(3, (1, 8))])
    outer_voice.name = "My Voice"

    assert format(outer_voice) == abjad.String.normalize(
        r"""
        \context Voice = "My Voice"
        {
            \context Voice = "Your Voice"
            {
                c'8
                cs'8
                d'8
            }
            ef'8
        }
        """
    )

    assert abjad.inspect(inner_voice[0]).leaf(1) is inner_voice[1]
    assert abjad.inspect(inner_voice[1]).leaf(1) is inner_voice[2]
github Abjad / abjad / tests / test_Note___init__.py View on Github external
def test_Note___init___06():
    """
    Initializes note from chord.
    """

    chord = abjad.Chord([2, 3, 4], (1, 4))
    note = abjad.Note(chord)

    assert format(note) == abjad.String.normalize(
        r"""
        d'4
        """
    )

    assert abjad.inspect(note).wellformed()
github Abjad / abjad / tests / test_GraceContainer.py View on Github external
def test_GraceContainer_01():

    notes = [
        abjad.Note(0, (1, 16)),
        abjad.Note(2, (1, 16)),
        abjad.Note(4, (1, 16)),
    ]
    grace_container = abjad.GraceContainer(notes)

    assert format(grace_container) == abjad.String.normalize(
        r"""
        \grace {
            c'16
            d'16
            e'16
        }
        """
    )

    assert isinstance(grace_container, abjad.Container)
    assert len(grace_container) == 3
github Abjad / abjad / tests / test_Mutation_extract.py View on Github external
[
                d'8
            }
            {
                e'8
                f'8
                ]
            }
        }
        """
    ), print(format(staff))

    container = staff[0]
    abjad.mutate(container).extract()

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

    assert not container