Exemple #1
0
    def __init__(self, component=None, cross_offset=None):
        import abjad

        assert isinstance(component, (abjad.Component, type(None)))
        self._component = component
        if component is None:
            components = ()
        else:
            components = list(abjad.select(component).components())
        result = []
        if cross_offset is None:
            result = components
        else:
            for component in components:
                append_x = True
                if not (
                    abjad.inspect(component).timespan().start_offset
                    < cross_offset
                    and cross_offset
                    < abjad.inspect(component).timespan().stop_offset
                ):
                    append_x = False
                if append_x:
                    result.append(component)
        self._components = tuple(result)
Exemple #2
0
def edit_cello_voice(score, durated_reservoir):
    """
    Edits cello voice.
    """
    voice = score["Cello Voice"]
    descents = durated_reservoir["Cello"]
    logical_tie = abjad.inspect(voice[-1]).logical_tie()
    for leaf in logical_tie.leaves:
        parent = abjad.inspect(leaf).parentage().parent
        index = parent.index(leaf)
        parent[index] = abjad.Chord(["e,", "a,"], leaf.written_duration)
    selection = voice[-len(descents[-1]) :]
    unison_descent = abjad.mutate(selection).copy()
    voice.extend(unison_descent)
    for chord in unison_descent:
        index = abjad.inspect(chord).parentage().parent.index(chord)
        parent[index] = abjad.Note(
            chord.written_pitches[1], chord.written_duration
        )
        articulation = abjad.Articulation("accent")
        abjad.attach(articulation, parent[index])
        articulation = abjad.Articulation("tenuto")
        abjad.attach(articulation, parent[index])
    voice.extend("a,1. ~ a,2")
    voice.extend("b,1 ~ b,1. ~ b,1.")
    voice.extend("a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,2")
    voice.extend("r4 r2.")
def test_LogicalTie__fuse_leaves_by_immediate_parent_01():
    """
    Fuse leaves in logical tie with same immediate parent.
    """

    staff = abjad.Staff(2 * abjad.Container("c'8 c'8"))
    leaves = abjad.select(staff).leaves()
    abjad.tie(leaves)

    logical_tie = abjad.inspect(leaves[1]).logical_tie()
    result = logical_tie._fuse_leaves_by_immediate_parent()

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            {
                c'4
                ~
            }
            {
                c'4
            }
        }
        """
    ), print(format(staff))

    assert len(result) == 2
    assert abjad.inspect(staff).wellformed()
def test_Leaf__split_by_durations_13():
    """
    After grace notes are removed from first split leaf.
    """

    note = abjad.Note("c'4")
    after_grace = abjad.AfterGraceContainer([abjad.Note(0, (1, 32))])
    abjad.attach(after_grace, note)

    new_leaves = note._split_by_durations([abjad.Duration(1, 8)])
    staff = abjad.Staff(new_leaves)

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            c'8
            ~
            \afterGrace
            c'8
            {
                c'32
            }
        }
        """
    ), print(format(staff))

    assert abjad.inspect(new_leaves[0]).after_grace_container() is None
    assert len(abjad.inspect(new_leaves[1]).after_grace_container()) == 1
    abjad.inspect(staff).wellformed()
Exemple #5
0
def edit_cello_voice(score, durated_reservoir):
    """
    Edits cello voice.
    """

    voice = score['Cello Voice']
    descents = durated_reservoir['Cello']

    logical_tie = abjad.inspect(voice[-1]).get_logical_tie()
    for leaf in logical_tie.leaves:
        parent = abjad.inspect(leaf).get_parentage().parent
        index = parent.index(leaf)
        parent[index] = abjad.Chord(['e,', 'a,'], leaf.written_duration)

    selection = voice[-len(descents[-1]):]
    unison_descent = abjad.mutate(selection).copy()
    voice.extend(unison_descent)
    for chord in unison_descent:
        index = abjad.inspect(chord).get_parentage().parent.index(chord)
        parent[index] = abjad.Note(
            chord.written_pitches[1], chord.written_duration)
        articulation = abjad.Articulation('accent')
        abjad.attach(articulation, parent[index])
        articulation = abjad.Articulation('tenuto')
        abjad.attach(articulation, parent[index])

    voice.extend('a,1. ~ a,2')
    voice.extend('b,1 ~ b,1. ~ b,1.')
    voice.extend('a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,1. ~ a,2')
    voice.extend('r4 r2.')
Exemple #6
0
def test_Inspection_leaf_17():
    """
    Does connect in sequence of alternating tuplets and notes.
    """

    notes = [abjad.Note(i, abjad.Duration(1, 8)) for i in range(3)]
    tuplet_1 = abjad.Tuplet((2, 3), notes)
    notes = [abjad.Note(i, abjad.Duration(1, 8)) for i in range(4, 7)]
    tuplet_2 = abjad.Tuplet((2, 3), notes)
    voice = abjad.Voice([tuplet_1, abjad.Note(3, (1, 8)), tuplet_2])

    assert format(voice) == abjad.String.normalize(
        r"""
        \new Voice
        {
            \times 2/3 {
                c'8
                cs'8
                d'8
            }
            ef'8
            \times 2/3 {
                e'8
                f'8
                fs'8
            }
        }
        """
    )

    assert abjad.inspect(tuplet_1[-1]).leaf(1) is voice[1]
    assert abjad.inspect(voice[1]).leaf(1) is tuplet_2[0]

    assert abjad.inspect(voice[1]).leaf(-1) is tuplet_1[-1]
    assert abjad.inspect(tuplet_2[0]).leaf(-1) is voice[1]
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))
Exemple #8
0
def test_Inspection_leaf_18():
    """
    Does connect through asymmetrically nested tuplets.
    """

    inner_tuplet = abjad.Tuplet((2, 3), "c'8 c'8 c'8")
    contents = [abjad.Note("c'4"), inner_tuplet, abjad.Note("c'4")]
    tuplet = abjad.Tuplet((2, 3), contents)

    assert format(tuplet) == abjad.String.normalize(
        r"""
        \times 2/3 {
            c'4
            \times 2/3 {
                c'8
                c'8
                c'8
            }
            c'4
        }
        """
    )

    assert abjad.inspect(tuplet[0]).leaf(1) is inner_tuplet[0]
    assert abjad.inspect(inner_tuplet[-1]).leaf(1) is tuplet[-1]
    assert abjad.inspect(tuplet[-1]).leaf(-1) is inner_tuplet[-1]
    assert abjad.inspect(inner_tuplet[0]).leaf(-1) is tuplet[0]
Exemple #9
0
def test_Mutation_fuse_05():
    """
    Fuses leaves with differing LilyPond multipliers.
    """

    staff = abjad.Staff([abjad.Skip((1, 1)), abjad.Skip((1, 1))])
    staff[0].multiplier = (1, 16)
    staff[1].multiplier = (5, 16)

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            s1 * 1/16
            s1 * 5/16
        }
        """
    ), print(format(staff))

    assert abjad.inspect(staff).duration() == abjad.Duration(3, 8)

    abjad.mutate(staff[:]).fuse()

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            s1 * 3/8
        }
        """
    )

    assert abjad.inspect(staff).duration() == abjad.Duration(3, 8)
    assert abjad.inspect(staff).wellformed()
Exemple #10
0
def test_Staff___getitem___08():

    staff = abjad.Staff(
        [
            abjad.Note("c'4"),
            abjad.Rest((1, 4)),
            abjad.Chord([2, 3, 4], (1, 4)),
            abjad.Skip((1, 4)),
            abjad.Tuplet((4, 5), 4 * abjad.Note(0, (1, 16))),
        ]
    )

    assert len(staff) == 5
    assert abjad.inspect(staff).wellformed()
    selection = staff[:]
    assert len(selection) == 5
    assert isinstance(selection, abjad.Selection)
    assert isinstance(selection[0], abjad.Note)
    assert isinstance(selection[1], abjad.Rest)
    assert isinstance(selection[2], abjad.Chord)
    assert isinstance(selection[3], abjad.Skip)
    assert isinstance(selection[4], abjad.Tuplet)
    for x in selection:
        assert x._parent == staff
    assert abjad.inspect(staff).wellformed()
Exemple #11
0
    def comment_measure_numbers(score):
        """
        Comments measure numbers in ``score``.
        """
        import abjad

        offset_to_measure_number = {}
        for context in abjad.iterate(score).components(abjad.Context):
            if not context.is_simultaneous:
                break
        measures = abjad.select(context).leaves().group_by_measure()
        for i, measure in enumerate(measures):
            measure_number = i + 1
            first_leaf = abjad.select(measure).leaf(0)
            start_offset = abjad.inspect(first_leaf).timespan().start_offset
            offset_to_measure_number[start_offset] = measure_number
        for leaf in abjad.iterate(score).leaves():
            offset = abjad.inspect(leaf).timespan().start_offset
            measure_number = offset_to_measure_number.get(offset, None)
            if measure_number is None:
                continue
            context = abjad.inspect(leaf).parentage().get(abjad.Context)
            if context.name is None:
                string = (
                    f"% [{context.lilypond_type} measure {measure_number}]"
                )
            else:
                string = f"% [{context.name} measure {measure_number}]"
            literal = abjad.LilyPondLiteral(string, "absolute_before")
            abjad.attach(literal, leaf, tag="COMMENT_MEASURE_NUMBERS")
def test_Inspection_bar_line_crossing_01():
    """
    Works with partial.
    """

    staff = abjad.Staff("c'8 d'8 e'4 f'8")
    time_signature = abjad.TimeSignature((2, 8), partial=abjad.Duration(1, 8))
    abjad.attach(time_signature, staff[0])

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

    assert not abjad.inspect(staff[0]).bar_line_crossing()
    assert not abjad.inspect(staff[1]).bar_line_crossing()
    assert abjad.inspect(staff[2]).bar_line_crossing()
    assert not abjad.inspect(staff[3]).bar_line_crossing()
def test_Leaf__split_by_durations_04():
    """
    REGRESSION.
    
    Splits note into tuplet monads and then fuses monads.

    Ties split notes.

    This test comes from #272 in GitHub.
    """

    staff = abjad.Staff(r"\times 2/3 { c'8 [ d'8 e'8 ] }")
    leaf = abjad.inspect(staff).leaf(0)
    new_leaves = leaf._split_by_durations([abjad.Duration(1, 20)])

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            \times 2/3 {
                \times 4/5 {
                    c'16.
                    [
                    ~
                    c'16
                }
                d'8
                e'8
                ]
            }
        }
        """
    ), print(format(staff))

    assert abjad.inspect(staff).wellformed()
    def _replace(self, old_leaf, new_leaf):
        after_grace = abjad.inspect(old_leaf).get_after_grace_container()
        if after_grace is not None:
            old_after_grace = after_grace
            grace_notes = list(iterate(old_after_grace).by_leaf())
            detach(scoretools.GraceContainer, old_leaf)

        indicator_expressions = abjad.inspect(old_leaf).get_indicators(unwrap=False)
        #for indicator_expression in indicator_expressions:
        #    detach(indicator, old_leaf)

        timespan = old_leaf._timespan
        start_offset = old_leaf._start_offset
        stop_offset = old_leaf._stop_offset
        logical_measure_number = old_leaf._logical_measure_number
        mutate(old_leaf).replace(new_leaf)
        new_leaf._timespan = timespan
        new_leaf._start_offset = start_offset
        new_leaf._stop_offset = stop_offset
        new_leaf._logical_measure_number = logical_measure_number

        if after_grace is not None:
            new_after_grace = scoretools.AfterGraceContainer(grace_notes)
            attach(new_after_grace, new_leaf)

        for indicator_expression in indicator_expressions:
            attach(indicator_expression, new_leaf)
def test_Leaf__split_by_durations_14():
    """
    After grace notes are removed from first split leaf.
    """

    note = abjad.Note("c'4")
    grace = abjad.AfterGraceContainer([abjad.Note(0, (1, 32))])
    abjad.attach(grace, note)

    new_leaves = note._split_by_durations([abjad.Duration(5, 32)])
    staff = abjad.Staff(new_leaves)

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            c'8
            ~
            c'32
            ~
            \afterGrace
            c'16.
            {
                c'32
            }
        }
        """
    ), print(format(staff))

    abjad.inspect(staff).wellformed()
 def _get_lilypond_format_bundle(self, leaf):
     import consort
     lilypond_format_bundle = self._get_basic_lilypond_format_bundle(leaf)
     if self._is_my_first_leaf(leaf):
         # Add color command
         if isinstance(self._color, consort.Color):
             string = r'\colorSpan #-4 #4 {}'.format(
                 self._color._lilypond_format,
                 )
         else:
             string = r"\colorSpan #-4 #4 #(x11-color '{})"
         string = string.format(self._color)
         lilypond_format_bundle.opening.commands.append(string)
         # Check for previous spanner and terminate if it exists
         previous_leaf = leaf._get_leaf(-1)
         if (
             previous_leaf is not None and
             abjad.inspect(previous_leaf).has_spanner(type(self))
             ):
             string = r'\)'
             lilypond_format_bundle.right.spanner_stops.append(string)
         # Start the spanner
         string = r'\('
         lilypond_format_bundle.right.spanner_starts.append(string)
     if self._is_my_last_leaf(leaf):
         # Check for next spanner, don't terminate if it exists
         next_leaf = leaf._get_leaf(1)
         if (
             next_leaf is None or
             not abjad.inspect(next_leaf).has_spanner(type(self))
             ):
             string = r'<> \)'
             lilypond_format_bundle.closing.commands.append(string)
     return lilypond_format_bundle
Exemple #17
0
def test_Parentage_orphan_01():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")

    assert abjad.inspect(staff).parentage().orphan
    for note in staff:
        assert not abjad.inspect(note).parentage().orphan
Exemple #18
0
def test_Inspection_leaf_01():

    staff = abjad.Staff(
        [abjad.Voice("c'8 d'8 e'8 f'8"), abjad.Voice("g'8 a'8 b'8 c''8")]
    )

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

    leaves = abjad.select(staff).leaves()
    assert abjad.inspect(leaves[0]).leaf(-1) is None
    assert abjad.inspect(leaves[0]).leaf(0) is leaves[0]
    assert abjad.inspect(leaves[0]).leaf(1) is leaves[1]
Exemple #19
0
def test_Inspection_leaf_08():
    """
    Does not continue across contiguous anonymous voices inside a staff.
    """

    voice_1 = abjad.Voice([abjad.Note(i, (1, 8)) for i in range(4)])
    voice_2 = abjad.Voice([abjad.Note(i, (1, 8)) for i in range(4, 8)])
    staff = abjad.Staff([voice_1, voice_2])

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

    assert abjad.inspect(voice_1[3]).leaf(1) is None
    assert abjad.inspect(voice_2[0]).leaf(-1) is None
Exemple #20
0
def test_Inspection_leaf_16():
    """
    Does connect in sequence of alternating containers and notes.
    """

    container_1 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(2)])
    container_2 = abjad.Container([abjad.Note(i, (1, 8)) for i in range(3, 5)])
    voice = abjad.Voice([container_1, abjad.Note(2, (1, 8)), container_2])

    assert format(voice) == abjad.String.normalize(
        r"""
        \new Voice
        {
            {
                c'8
                cs'8
            }
            d'8
            {
                ef'8
                e'8
            }
        }
        """
    )

    assert abjad.inspect(container_1[1]).leaf(1) is voice[1]
    assert abjad.inspect(voice[1]).leaf(1) is container_2[0]

    assert abjad.inspect(voice[1]).leaf(-1) is container_1[1]
    assert abjad.inspect(container_2[0]).leaf(-1) is voice[1]
def test_Inspection_timespan_26():
    """
    Offset seconds work with explicit metronome mark.
    """

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    mark = abjad.MetronomeMark(abjad.Duration(1, 8), 48)
    abjad.attach(mark, staff[0], context="Staff")

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

    start_offset = (
        abjad.inspect(staff[0]).timespan(in_seconds=True).start_offset
    )
    assert start_offset == abjad.Offset(0)
    start_offset = (
        abjad.inspect(staff[1]).timespan(in_seconds=True).start_offset
    )
    assert start_offset == abjad.Offset(5, 4)
def test_Leaf__split_by_durations_15():
    """
    Grace notes are removed from second split leaf.
    """

    note = abjad.Note("c'4")
    grace = abjad.GraceContainer([abjad.Note(0, (1, 32))])
    abjad.attach(grace, note)

    new_leaves = note._split_by_durations([abjad.Duration(1, 16)])
    staff = abjad.Staff(new_leaves)

    assert format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            \grace {
                c'32
            }
            c'16
            ~
            c'8.
        }
        """
    ), print(format(staff))

    abjad.inspect(staff).wellformed()
def test_Inspection_has_indicator_05():

    staff = abjad.Staff("c'2 d'2")
    stem_tremolo = abjad.StemTremolo(16)
    abjad.attach(stem_tremolo, staff[0])

    assert abjad.inspect(staff[0]).has_indicator(abjad.StemTremolo)
    assert not abjad.inspect(staff[1]).has_indicator(abjad.StemTremolo)
def test_Inspection_duration_04():
    """
    Clock duration can not calculate without metronome mark.
    """

    note = abjad.Note("c'4")
    with pytest.raises(Exception):
        abjad.inspect(note).duration(in_seconds=True)
def test_Inspection_has_indicator_02():

    staff = abjad.Staff("c'2 d'2")
    articulation = abjad.Articulation("staccato")
    abjad.attach(articulation, staff[0])

    assert abjad.inspect(staff[0]).has_indicator(abjad.Articulation)
    assert not abjad.inspect(staff[1]).has_indicator(abjad.Duration)
def test_Inspection_has_indicator_04():

    staff = abjad.Staff("c'2 d'2")
    comment = abjad.LilyPondComment("comment")
    abjad.attach(comment, staff[0])

    assert abjad.inspect(staff[0]).has_indicator(abjad.LilyPondComment)
    assert not abjad.inspect(staff[1]).has_indicator(abjad.LilyPondComment)
def test_Inspection_duration_02():
    """
    Container can not calculate duration in seconds without metronome mark.
    """

    container = abjad.Container("c'8 d'8 e'8 f'8")
    with pytest.raises(Exception):
        abjad.inspect(container).duration(in_seconds=True)
def make_annotated_phrase(phrase, color=None):
    duration = abjad.inspect(phrase).get_duration()
    durations = [inspect(_).get_duration() for _ in phrase]
    leaves = scoretools.LeafMaker()([0], durations)
    annotated_phrase = scoretools.Tuplet.from_duration(duration, leaves)
    if color:
        override(annotated_phrase).tuplet_bracket.color = color
    return annotated_phrase
Exemple #29
0
def test_Container_remove_02():
    """
    Containers remove nested containers correctly.
    abjad.Container abjad.detaches from parentage.
    abjad.Container returns after removal.
    """

    staff = abjad.Staff("{ c'8 d'8 } { e'8 f'8 }")
    leaves = abjad.select(staff).leaves()
    sequential = staff[0]
    abjad.beam(leaves)

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

    staff.remove(sequential)

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

    assert abjad.inspect(staff).wellformed()

    assert format(sequential) == abjad.String.normalize(
        r"""
        {
            c'8
            [
            d'8
        }
        """
    )

    assert abjad.inspect(sequential).wellformed()
Exemple #30
0
    def add_final_bar_line(self, abbreviation="|.", to_each_voice=False):
        r"""
        Add final bar line to end of score.


            >>> staff = abjad.Staff("c'4 d'4 e'4 f'4")
            >>> score = abjad.Score([staff])
            >>> abjad.show(score) # doctest: +SKIP

        ..  docs::

            >>> abjad.f(score)
            \new Score
            <<
                \new Staff
                {
                    c'4
                    d'4
                    e'4
                    f'4
                }
            >>


        >>> bar_line = score.add_final_bar_line()
        >>> abjad.show(score) # doctest: +SKIP

        ..  docs::

            >>> abjad.f(score)
            \new Score
            <<
                \new Staff
                {
                    c'4
                    d'4
                    e'4
                    f'4
                    \bar "|." %! SCORE_1
                }
            >>

        Set ``to_each_voice`` to true to make part extraction easier.

        Returns bar line.
        """
        import abjad

        bar_line = abjad.BarLine(abbreviation)
        if not to_each_voice:
            last_leaf = abjad.inspect(self).leaf(-1)
            abjad.attach(bar_line, last_leaf, tag="SCORE_1")
        else:
            for voice in abjad.iterate(self).components(abjad.Voice):
                last_leaf = abjad.inspect(voice).leaf(-1)
                abjad.attach(bar_line, last_leaf, tag="SCORE_1")
        return bar_line
Exemple #31
0
def test_Mutation_scale_04():
    """
    Scales leaves by tie- and tuplet-generating multiplier.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.mutate(voice).scale(abjad.Multiplier(5, 6))

    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            \tweak edge-height #'(0.7 . 0)
            \times 2/3 {
                c'8
                ~
                c'32
            }
            \tweak edge-height #'(0.7 . 0)
            \times 2/3 {
                d'8
                ~
                d'32
            }
            \tweak edge-height #'(0.7 . 0)
            \times 2/3 {
                e'8
                ~
                e'32
            }
            \tweak edge-height #'(0.7 . 0)
            \times 2/3 {
                f'8
                ~
                f'32
            }
        }
        """), print(format(voice))

    assert abjad.inspect(voice).wellformed()
def test_scoretools_Container___setitem___12():
    r'''Replaces multiple spanned leaves with with single leaf.
    '''

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    beam = abjad.Beam()
    abjad.attach(beam, staff[:])
    note = abjad.Note("c''8")
    staff[1:3] = [note]

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

    assert abjad.inspect(staff).is_well_formed()
def test_spannertools_DuratedComplexBeam_isolated_nib_direction_01():
    r'''Span isolated_nib_direction note when isolated_nib_direction is set to
    true.
    '''

    container = abjad.Container("c'8")
    beam = abjad.DuratedComplexBeam(isolated_nib_direction=True)
    abjad.attach(beam, container[:])

    assert format(container) == abjad.String.normalize(
        r'''
        {
            \set stemLeftBeamCount = 1
            \set stemRightBeamCount = 1
            c'8
            [
            ]
        }
        '''
        )

    assert abjad.inspect(container).is_well_formed()
def test_Leaf__split_by_durations_02():
    """
    Splits note into assignable notes.

    Does tie split notes.
    """

    staff = abjad.Staff("c'8 [ d'8 e'8 ]")

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

    new_leaves = staff[1]._split_by_durations(
        [abjad.Duration(1, 32)],
        tie_split_notes=True,
    )

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

    assert abjad.inspect(staff).wellformed()
Exemple #35
0
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___36():
    r'''Override LilyPond SpacingSpanner grob on Abjad containers.
    LilyPond SpacingSpanner lives at Score by default.
    Abjad SpacingSpanner abjad.overrides usually
    require context promotion.
    '''

    staff = abjad.Staff("abj: | 2/8 c'8 d'8 || 2/8 e'8 f'8 |")
    leaves = abjad.select(staff).leaves()
    beam = abjad.Beam()
    abjad.attach(beam, leaves)
    abjad.override(beam).score.spacing_spanner.strict_grace_spacing = True
    abjad.override(beam).score.spacing_spanner.strict_note_spacing = True
    abjad.override(beam).score.spacing_spanner.uniform_stretching = True

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff
        {
            {   % measure
                \time 2/8
                \override Score.SpacingSpanner.strict-grace-spacing = ##t
                \override Score.SpacingSpanner.strict-note-spacing = ##t
                \override Score.SpacingSpanner.uniform-stretching = ##t
                c'8
                [
                d'8
            }   % measure
            {   % measure
                e'8
                \revert Score.SpacingSpanner.strict-grace-spacing
                \revert Score.SpacingSpanner.strict-note-spacing
                \revert Score.SpacingSpanner.uniform-stretching
                f'8
                ]
            }   % measure
        }
        ''')

    assert abjad.inspect(staff).is_well_formed()
Exemple #36
0
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___22():
    r'''Override LilyPond abjad.NoteColumn grob.
    '''

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    abjad.override(staff).note_column.ignore_collision = True

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff
        \with
        {
            \override NoteColumn.ignore-collision = ##t
        }
        {
            c'8
            d'8
            e'8
            f'8
        }
        ''')

    assert abjad.inspect(staff).is_well_formed()
Exemple #37
0
def test_Container___setitem___18():
    r"""
    Extremely small coequal indices indicate first slice in staff.
    """

    voice = abjad.Voice("c'8 [ d'8 e'8 f'8 ]")
    voice[-1000:-1000] = [abjad.Rest('r8')]

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

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

    assert abjad.inspect(voice).wellformed()
def test_scoretools_Inspection_get_effective_04():
    r'''Clefs carry over to notes following.
    '''

    staff = abjad.Staff("c'8 d'8 e'8 f'8 g'8 a'8 b'8 c''8")
    clef = abjad.Clef('treble')
    abjad.attach(clef, staff[0])
    clef = abjad.Clef('bass')
    abjad.attach(clef, staff[4])
    result = [abjad.inspect(note).get_effective(abjad.Clef) for note in staff]
    clef_names = [
        'treble',
        'treble',
        'treble',
        'treble',
        'bass',
        'bass',
        'bass',
        'bass',
    ]
    clefs = [abjad.Clef(name) for name in clef_names]
    assert result == clefs
Exemple #39
0
def test_Container_extend_03():
    """
    Extending container with empty list leaves container unchanged.
    """

    voice = abjad.Voice("c'8 d'8")
    abjad.beam(voice[:])
    voice.extend([])

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

    assert abjad.inspect(voice).wellformed()
Exemple #40
0
def test_Container_extend_09():
    """
    Extend container with LilyPond input string.
    """

    container = abjad.Container([])
    container.extend("c'4 ( d'4 e'4 f'4 )")

    assert format(container) == abjad.String.normalize(
        r"""
        {
            c'4
            (
            d'4
            e'4
            f'4
            )
        }
        """
        ), print(format(container))

    assert abjad.inspect(container).wellformed()
Exemple #41
0
def test_scoretools_Inspection_get_sounding_pitches_01():

    staff = abjad.Staff("<c''' e'''>4 <d''' fs'''>4")
    glockenspiel = abjad.Glockenspiel()
    abjad.attach(glockenspiel, staff[0])
    abjad.Instrument.transpose_from_sounding_pitch(staff)

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff
        {
            \set Staff.instrumentName = \markup { Glockenspiel }
            \set Staff.shortInstrumentName = \markup { Gkspl. }
            <c' e'>4
            <d' fs'>4
        }
        ''')

    sounding_pitches = abjad.inspect(staff[0]).get_sounding_pitches()
    assert sounding_pitches == (
        abjad.NamedPitch("c'''"),
        abjad.NamedPitch("e'''"),
    )
def test_Container_extend_01():
    """
    Extend container with list of leaves.
    """

    voice = abjad.Voice("c'8 d'8")
    abjad.beam(voice[:])
    voice.extend([abjad.Note("c'8"), abjad.Note("d'8")])

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

    assert abjad.inspect(voice).wellformed()
Exemple #43
0
def test_Mutation_scale_05():
    """
    Undo scale of 5/4 with scale of 4/5.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.mutate(voice).scale(abjad.Multiplier(5, 4))

    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            ~
            c'32
            d'8
            ~
            d'32
            e'8
            ~
            e'32
            f'8
            ~
            f'32
        }
        """)

    abjad.mutate(voice).scale(abjad.Multiplier(4, 5))

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

    assert abjad.inspect(voice).wellformed()
def test_spannertools_PianoPedalSpanner_03():
    r'''Piano pedal spanner supports una corda pedal.
    '''

    staff = abjad.Staff("c'8 c'8 c'8 c'8")
    piano_pedal_spanner = abjad.PianoPedalSpanner(kind='corda')
    abjad.attach(piano_pedal_spanner, staff[:])

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff
        {
            \set Staff.pedalSustainStyle = #'mixed
            c'8
            \unaCorda
            c'8
            c'8
            c'8
            \treCorde
        }
        ''')

    assert abjad.inspect(staff).is_well_formed()
Exemple #45
0
def test_spannertools_TrillSpanner_pitch_01():
    r'''Works with pitch.
    '''

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    trill = abjad.TrillSpanner(pitch=abjad.NamedPitch(1))
    abjad.attach(trill, staff[:2])

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

    assert abjad.inspect(staff).is_well_formed()
def test_Container_insert_06():
    """
    Insert works with really big negative values.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.beam(voice[:])
    voice.insert(-1000, abjad.Rest((1, 8)))

    assert abjad.inspect(voice).wellformed()
    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            r8
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        """)
Exemple #47
0
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___45():
    r'''Override LilyPond TextScript grob.
    '''

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

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff
        {
            \override TextScript.color = #red
            c'8
            d'8
            e'8
            \revert TextScript.color
            f'8
        }
        ''')

    assert abjad.inspect(staff).is_well_formed()
def test_Container_insert_01():
    """
    Insert component into container at index i.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.beam(voice[:])
    voice.insert(0, abjad.Rest((1, 8)))

    assert abjad.inspect(voice).wellformed()
    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            r8
            c'8
            [
            d'8
            e'8
            f'8
            ]
        }
        """)
Exemple #49
0
def test_lilypondproxytools_LilyPondGrobNameManager___setattr___29():
    r'''Override LilyPond abjad.NoteHead grob.
    '''

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.override(voice).note_head.color = 'red'

    assert format(voice) == abjad.String.normalize(r'''
        \new Voice
        \with
        {
            \override NoteHead.color = #red
        }
        {
            c'8
            d'8
            e'8
            f'8
        }
        ''')

    assert abjad.inspect(voice).is_well_formed()
def test_Container_insert_04():
    """
    Insert works with really big positive values.
    """

    staff = abjad.Staff([abjad.Note(n, (1, 8)) for n in range(4)])
    abjad.beam(staff[:])
    staff.insert(1000, abjad.Rest((1, 4)))

    assert abjad.inspect(staff).wellformed()
    assert format(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            c'8
            [
            cs'8
            d'8
            ef'8
            ]
            r4
        }
        """)
def test_Container___setitem___03():
    """
    Replaces in-score container with out-of-score leaf.
    """

    voice = abjad.Voice("{ c'8 [ d'8 } { e'8 f'8 ] }")
    leaves = abjad.select(voice).leaves()

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

    voice[1] = abjad.Note("c''8")

    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            {
                c'8
                [
                d'8
            }
            c''8
        }
        """)

    assert abjad.inspect(voice).wellformed()
def test_Container_insert_05():
    """
    Insert works with negative values.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    abjad.beam(voice[:])
    voice.insert(-1, abjad.Note(4.5, (1, 8)))

    assert abjad.inspect(voice).wellformed()
    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            c'8
            [
            d'8
            e'8
            eqs'8
            f'8
            ]
        }
        """)
def test_Staff___getitem___01():

    staff = abjad.Staff([
        abjad.Note("c'4"),
        abjad.Rest((1, 4)),
        abjad.Chord([2, 3, 4], (1, 4)),
        abjad.Skip((1, 4)),
        abjad.Tuplet((4, 5), 4 * abjad.Note(0, (1, 16))),
        ])

    assert len(staff) == 5
    assert abjad.inspect(staff).wellformed()
    assert isinstance(staff[0], abjad.Note)
    assert isinstance(staff[1], abjad.Rest)
    assert isinstance(staff[2], abjad.Chord)
    assert isinstance(staff[3], abjad.Skip)
    assert isinstance(staff[4], abjad.Tuplet)
    assert isinstance(staff[-5], abjad.Note)
    assert isinstance(staff[-4], abjad.Rest)
    assert isinstance(staff[-3], abjad.Chord)
    assert isinstance(staff[-2], abjad.Skip)
    assert isinstance(staff[-1], abjad.Tuplet)
def test_spannertools_PianoPedalSpanner_02():
    r'''Piano pedal spanner supports sostenuto pedal.
    '''

    staff = abjad.Staff("c'8 c'8 c'8 c'8")
    piano_pedal_spanner = abjad.PianoPedalSpanner(kind='sostenuto')
    abjad.attach(piano_pedal_spanner, staff[:])

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff
        {
            \set Staff.pedalSustainStyle = #'mixed
            c'8
            \sostenutoOn
            c'8
            c'8
            c'8
            \sostenutoOff
        }
        ''')

    assert abjad.inspect(staff).is_well_formed()
Exemple #55
0
 def _as_graphviz_node(self):
     import abjad
     score_index = abjad.inspect(self).get_parentage().score_index
     score_index = '_'.join(str(_) for _ in score_index)
     class_name = type(self).__name__
     if score_index:
         name = '{}_{}'.format(class_name, score_index)
     else:
         name = class_name
     node = abjad.graphtools.GraphvizNode(
         name=name,
         attributes={
             'margin': 0.05,
         },
     )
     table = abjad.graphtools.GraphvizTable(attributes={
         'border': 2,
         'cellpadding': 5,
         'style': 'rounded',
     }, )
     node.append(table)
     return node
Exemple #56
0
def noteTied(note: abj.core.Note) -> TieTypes:
    """
    Returns an int describind the state:
        0: not tied
        1: tied forward
        2: tied backwards
        3: tied in both directions

    tied = noteTied(note)
    forward = tied & 0b01
    backwards = tied & 0b10
    both = tied & 0b11
    """
    logical_tie = abj.inspect(note).logical_tie()
    if len(logical_tie) == 1:
        return TieTypes.NOTTIED
    if note is logical_tie[0]:
        return TieTypes.TIEDFORWARD
    elif note is logical_tie[-1]:
        return TieTypes.TIEDBACKWARD
    else:
        return TieTypes.TIEDBOTH
Exemple #57
0
def test_scoretools_Staff_engraver_removals_01():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    staff.remove_commands.append('Time_signature_engraver')
    staff.remove_commands.append('Bar_number_engraver')

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

    assert abjad.inspect(staff).is_well_formed()
def test_spannertools_OctavationSpanner_adjust_automatically_01():

    maker = abjad.NoteMaker()
    notes = maker([24, 26, 27, 29], [(1, 8)])
    container = abjad.Container(notes)

    octavation_spanner = abjad.OctavationSpanner()
    abjad.attach(octavation_spanner, container[:])
    octavation_spanner.adjust_automatically(ottava_breakpoint=14)

    assert format(container) == abjad.String.normalize(r"""
        {
            \ottava #1
            c'''8
            d'''8
            ef'''8
            f'''8
            \ottava #0
        }
        """)

    assert abjad.inspect(container).is_well_formed()
def test_scoretools_Inspection_get_indicators_03():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    clef = abjad.Clef('treble')
    abjad.attach(clef, staff[0])
    dynamic = abjad.Dynamic('p')
    abjad.attach(dynamic, staff[0])

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

    indicators = abjad.inspect(staff[0]).get_indicators()
    assert len(indicators) == 2
Exemple #60
0
 def markup(
     self,
     markup: str,
 ) -> None:
     if markup is not None:
         if not isinstance(markup, str):
             raise TypeError("'markup' must be 'str'")
         self._markup = markup
         markup = abjad.Markup(
             self._markup,
             direction=self._direction,
         )
         abjad.attach(markup, self)
         if self._centre_markup:
             self._attach_centre_markup()
         else:
             self._detach_centre_markup()
     else:
         self._markup = markup
         if abjad.inspect(self).indicator(abjad.Markup):
             abjad.detach(abjad.Markup, self)
         self._detach_centre_markup()