コード例 #1
0
ファイル: SegmentMaker.py プロジェクト: Abjad/abjad
    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")
コード例 #2
0
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()
    leaf = leaves[0]
    marks = abjad.inspect(leaf).indicators(abjad.MetronomeMark)
    assert len(marks) == 1
コード例 #3
0
def test_LilyPondParser__indicators__MetronomeMark_03():

    target = abjad.Score([abjad.Staff([abjad.Note(0, 1)])])
    leaves = abjad.select(target).leaves()
    mark = abjad.MetronomeMark((1, 4), (59, 63))
    abjad.attach(mark, leaves[0], context="Staff")

    assert format(target) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                \tempo 4=59-63
                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()
    leaf = leaves[0]
    marks = abjad.inspect(leaf).indicators(abjad.MetronomeMark)
    assert len(marks) == 1
コード例 #4
0
def test_LilyPondParser__indicators__MetronomeMark_05():

    target = abjad.Score([abjad.Staff([abjad.Note(0, 1)])])
    mark = abjad.MetronomeMark(
        reference_duration=(1, 16),
        units_per_minute=(34, 55),
        textual_indication="Faster than a thousand suns",
    )
    leaves = abjad.select(target).leaves()
    abjad.attach(mark, leaves[0], context="Staff")

    assert format(target) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                \tempo "Faster than a thousand suns" 16=34-55
                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()
    leaf = leaves[0]
    marksn = abjad.inspect(leaf).indicators(abjad.MetronomeMark)
    assert len(marksn) == 1
コード例 #5
0
 def postprocess_breath_marks(self, score):
     breath_mark = indicatortools.BreathMark()
     leaves = select(score['Viola 1 Bowing Voice']).by_leaf()
     if isinstance(leaves[-1], scoretools.Note):
         attach(breath_mark, leaves[-1], name='breath_mark')
     leaves = select(score['Viola 2 Bowing Voice']).by_leaf()
     if isinstance(leaves[-1], scoretools.Note):
         attach(breath_mark, leaves[-1], name='breath_mark')
コード例 #6
0
def test_Selection_are_logical_voice_38():
    """
    Can not nest across differently named implicit voices.
    """

    container = abjad.Voice(
        r"""
        {
            {
                {
                    c'8
                    cs'8
                    \new Voice {
                        d'8
                        ef'8
                        e'8
                        f'8
                    }
                    fs'8
                    g'8
                }
            }
        }
        """
    )

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

    outer = (0, 1, 6, 7)
    inner = (2, 3, 4, 5)

    leaves = abjad.select(container).leaves()
    assert abjad.select([leaves[i] for i in outer]).are_logical_voice()
    assert abjad.select([leaves[i] for i in inner]).are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #7
0
def test_Selection__get_component_03():

    staff = abjad.Staff(
        r"""
        c'16
        r16
        d'8
        r8
        e'8.
        r8.
        f'4
        r4
        """
    )

    notes = [staff[0], staff[2], staff[4], staff[6]]
    rests = [staff[1], staff[3], staff[5], staff[7]]

    assert abjad.select(staff)._get_component(abjad.Note, 0) is notes[0]
    assert abjad.select(staff)._get_component(abjad.Note, 1) is notes[1]
    assert abjad.select(staff)._get_component(abjad.Note, 2) is notes[2]
    assert abjad.select(staff)._get_component(abjad.Note, 3) is notes[3]

    assert abjad.select(staff)._get_component(abjad.Rest, 0) is rests[0]
    assert abjad.select(staff)._get_component(abjad.Rest, 1) is rests[1]
    assert abjad.select(staff)._get_component(abjad.Rest, 2) is rests[2]
    assert abjad.select(staff)._get_component(abjad.Rest, 3) is rests[3]

    assert abjad.select(staff)._get_component(abjad.Staff, 0) is staff
コード例 #8
0
ファイル: trio.py プロジェクト: Abjad/intensive
def add_attachments(score):
    selection = abjad.select(score).components(abjad.Voice)
    for voice in selection:
        phrase_selection = abjad.select(voice).leaves().runs()
        for phrase in phrase_selection:
            if len(phrase) > 1:
                slur = abjad.Slur()
                abjad.attach(slur, phrase)
            accent = abjad.Articulation('accent')
            abjad.attach(accent, phrase[0])
    return score
コード例 #9
0
def test_Selection_are_logical_voice_36():
    """
    Logical voice can not extend across differently named voices.
    """

    container = abjad.Container(
        r"""
        c'8
        cs'8
        {
            {
                \context Voice = "foo" {
                    d'8
                    ef'8
                    e'8
                    f'8
                }
            }
        }
        fs'8
        g'8
        """
    )

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

    outer = (0, 1, 6, 7)
    inner = (2, 3, 4, 5)

    leaves = abjad.select(container).leaves()
    assert abjad.select([leaves[i] for i in outer]).are_logical_voice()
    assert abjad.select([leaves[i] for i in inner]).are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #10
0
def test_Selection__get_component_04():
    """
    Iterates backwards with negative values of n.
    """

    staff = abjad.Staff(
        r"""
        c'16
        r16
        d'8
        r8
        e'8.
        r8.
        f'4
        r4
        """
    )

    notes = [staff[0], staff[2], staff[4], staff[6]]
    rests = [staff[1], staff[3], staff[5], staff[7]]

    assert abjad.select(staff)._get_component(abjad.Note, -1) is notes[3]
    assert abjad.select(staff)._get_component(abjad.Note, -2) is notes[2]
    assert abjad.select(staff)._get_component(abjad.Note, -3) is notes[1]
    assert abjad.select(staff)._get_component(abjad.Note, -4) is notes[0]

    assert abjad.select(staff)._get_component(abjad.Rest, -1) is rests[3]
    assert abjad.select(staff)._get_component(abjad.Rest, -2) is rests[2]
    assert abjad.select(staff)._get_component(abjad.Rest, -3) is rests[1]
    assert abjad.select(staff)._get_component(abjad.Rest, -4) is rests[0]
コード例 #11
0
def test_Inspection_timespan_11():
    """
    Offset on leaves works in nested contexts.
    """

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    staff = abjad.Staff([abjad.Note(0, (1, 8)), voice, abjad.Note(0, (1, 8))])
    leaves = abjad.select(staff).leaves()
    for i, leaf in enumerate(leaves):
        start_offset = abjad.inspect(leaf).timespan().start_offset
        assert start_offset == i * abjad.Offset(1, 8)
    leaves = abjad.select(voice).leaves()
    for i, leaf in enumerate(leaves):
        start_offset = abjad.inspect(leaf).timespan().start_offset
        assert start_offset == i * abjad.Offset(1, 8) + abjad.Offset(1, 8)
コード例 #12
0
def test_Selection_are_logical_voice_30():
    """
    Logical voice can not extend across differently named implicit voices.
    """

    voice_1 = abjad.Voice([abjad.Note(n, (1, 8)) for n in range(4)])
    voice_2 = abjad.Voice([voice_1])
    notes = [abjad.Note(n, (1, 8)) for n in range(4, 8)]
    container = abjad.Container([voice_2] + notes)

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #13
0
def test_Selection_are_logical_voice_28():
    """
    Logical voice can not extend across differently named implicit voices.
    """

    voice = abjad.Voice([abjad.Note(n, (1, 8)) for n in range(4)])
    voice.name = "foo"
    container = abjad.Container([voice])
    notes = [abjad.Note(n, (1, 8)) for n in range(4, 8)]
    container = abjad.Container([container] + notes)

    r"""
    {
        {
            \context Voice = "foo" {
                c'8
                cs'8
                d'8
                ef'8
            }
        }
        e'8
        f'8
        fs'8
        g'8
    }
    """

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #14
0
ファイル: test_Mutation_swap.py プロジェクト: Abjad/abjad
def test_Mutation_swap_02():
    """
    Moves parentage, children from container to empty voice.
    """

    voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }")
    leaves = abjad.select(voice).leaves()
    voice.name = "foo"
    abjad.beam(leaves)

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

    new_voice = abjad.Voice()
    new_voice.name = "foo"
    abjad.mutate(voice[1:2]).swap(new_voice)

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

    assert abjad.inspect(voice).wellformed()
コード例 #15
0
ファイル: test_Mutation_swap.py プロジェクト: Abjad/abjad
def test_Mutation_swap_06():
    """
    Trying to move parentage, children from components that are not
    parent-contiguous raises exception.
    """

    voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }")
    leaves = abjad.select(voice).leaves()
    abjad.beam(leaves)

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

    tuplet = abjad.Tuplet((2, 3), [])
    with pytest.raises(Exception):
        abjad.mutate([voice[0], voice[2]]).swap(tuplet)
コード例 #16
0
ファイル: Descendants.py プロジェクト: Abjad/abjad
    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)
コード例 #17
0
def test_Component__sibling_03():

    staff = abjad.Staff(r"c'4 \times 2/3 { d'8 e'8 f'8 } g'2")

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

    leaves = abjad.select(staff).leaves()
    tuplet = staff[1]

    assert leaves[0]._sibling(-1) is None
    assert leaves[0]._sibling(1) is tuplet

    assert tuplet._sibling(-1) is leaves[0]
    assert tuplet._sibling(1) is leaves[4]

    assert leaves[1]._sibling(-1) is leaves[0]
    assert leaves[1]._sibling(1) is leaves[2]
コード例 #18
0
ファイル: make_breath_voices.py プロジェクト: trevorbaca/cary
 def attach_glissandi(nucleus_voice):
     selections = [[]]
     leaves = abjad.iterate(nucleus_voice).leaves()
     for leaf_index, leaf in enumerate(leaves):
         if 641 <= leaf_index:
             leaf_index += 2
         string = letter_maker.nuclei[leaf_index]
         if string == 0:
             glissando = False
         else:
             result = letter_maker.get_body_pitch_shape_glissando(string)
             pitch, shape, glissando = result
         if glissando:
             assert isinstance(leaf, abjad.Note), repr(leaf)
             selections[-1].append(leaf)
         elif not selections[-1] == []:
             selections.append([])
     if selections[-1] == []:
         selections.pop()
     selections = [abjad.select(_) for _ in selections]
     for selection in selections:
         next_leaf = abjad.inspect(selection[-1]).leaf(1)
         if next_leaf is not None:
             selection = selection + [next_leaf]
         abjad.glissando(selection, allow_repeats=True)
         triples = abjad.sequence(selection).nwise(n=3)
         for left_note, middle_note, right_note in triples:
             if not (left_note.written_pitch ==
                 middle_note.written_pitch ==
                 right_note.written_pitch):
                 continue
             abjad.override(middle_note).note_head.transparent = True
             grob_proxy = abjad.override(middle_note).glissando
             grob_proxy.bound_details__left__padding = -1.2
コード例 #19
0
def test_Selection_are_logical_voice_17():
    """
    Logical voice can not extend across differently named implicit voices.
    """

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #20
0
def test_LilyPondParser__indicators__TimeSignature_01():

    target = abjad.Score([abjad.Staff([abjad.Note(0, 1)])])
    time_signature = abjad.TimeSignature((8, 8))
    abjad.attach(time_signature, target[0][0])

    assert format(target) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                \time 8/8
                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()
    leaf = leaves[0]
    time_signatures = abjad.inspect(leaf).indicators(abjad.TimeSignature)
    assert len(time_signatures) == 1
コード例 #21
0
def test_LilyPondParser__indicators__MetronomeMark_01():

    target = abjad.Score([abjad.Staff([abjad.Note(0, 1)])])
    mark = abjad.MetronomeMark(textual_indication="As fast as possible")
    abjad.attach(mark, target[0][0], context="Staff")

    assert format(target) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                \tempo "As fast as possible"
                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()
    leaf = leaves[0]
    marks = abjad.inspect(leaf).indicators(abjad.MetronomeMark)
    assert len(marks) == 1
コード例 #22
0
ファイル: markup.py プロジェクト: trevorbaca/baca
def make_repeated_markup(markups):
    return baca.tools.MarkupSpecifier(
        markup=markups,
        selector=abjad.select().
            by_logical_tie(pitched=True).
            get_item(0, apply_to_each=True),
        )
コード例 #23
0
ファイル: test_setting.py プロジェクト: Abjad/abjad
def test_setting_02():
    r"""
    Works with leaf metronome mark interface.

    Includes LilyPond \set command.
    """

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    score = abjad.Score([staff])
    moment = abjad.SchemeMoment(24)
    leaves = abjad.select(score).leaves()
    abjad.setting(leaves[1]).score.tempo_wholes_per_minute = moment

    assert format(score) == abjad.String.normalize(
        r"""
        \new Score
        <<
            \new Staff
            {
                c'8
                \set Score.tempoWholesPerMinute = #(ly:make-moment 24 1)
                d'8
                e'8
                f'8
            }
        >>
        """
    )
コード例 #24
0
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()
コード例 #25
0
def test_Selection_are_contiguous_logical_voice_01():
    """
    Components that start at the same moment are bad.
    Even if components are all part of the same logical voice.
    """

    voice = abjad.Voice(
        r"""
        {
            c'8
            d'8
        }
        \new Voice {
            e'8
            f'8
        }
        {
            g'8
            a'8
        }
        """
    )

    selection = abjad.select([voice, voice[0]])
    assert not selection.are_contiguous_logical_voice()
    selection = voice[0:1] + voice[0][:]
    assert not selection.are_contiguous_logical_voice()
    selection = voice[-1:] + voice[-1][:]
    assert not selection.are_contiguous_logical_voice()
コード例 #26
0
ファイル: holds.py プロジェクト: mirrorecho/rwestmusic-copper
    def music(self, **kwargs):
        my_music = self.container_type()
        if self.line:

            # TO DO... this won't let holds overlap the silence... consider re-implementing to allow that
            self.add_silence(my_music, self.line.silence_counts, self.line.silence_ly)

            # TO DO... update to support multiple indices
            pitch = self.line.pitch_segments.get_pitch_numbers()[self.indices[0]]

            my_rhythms = self.get_rhythm_selection()
            # TO DO... consider using transpose instead of setting written pitch for each note?
            logical_ties = abjad.select(my_rhythms).by_logical_tie(pitched=True)
            for i, logical_tie in enumerate(logical_ties):
                for note in logical_tie:
                    note.written_pitch = pitch
            my_music.extend(my_rhythms)
            # TO DO... this would make more sense on the Pitches class... but won't work with PitchSegment, so keeping here for now
            if self.pitch_respell == "sharps":
                abjad.mutate(my_music).pitch_respell_with_sharps()
            elif self.pitch_respell == "flats":
                abjad.mutate(my_music).pitch_respell_with_flats()

            # TO DO... ditto as above
            self.add_silence(my_music, self.line.silence_post_counts, self.line.silence_post_ly)

        else:
            print("WARNING: tried to create hold with no line referenced")
        return my_music
コード例 #27
0
ファイル: test_Inspection_leaf.py プロジェクト: Abjad/abjad
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]
コード例 #28
0
def test_Leaf__split_by_durations_16():

    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 format(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            {
                c'8
                [
                (
                d'8
                ]
            }
            {
                e'8
                [
                f'8
                )
                ]
            }
        }
        """
    ), print(format(staff))

    new_leaves = leaves[0]._split_by_durations(
        [abjad.Duration(1, 32)], tie_split_notes=False
    )

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

    assert abjad.inspect(staff).wellformed()
コード例 #29
0
ファイル: test_Mutation_fuse.py プロジェクト: Abjad/abjad
def test_Mutation_fuse_06():
    """
    Fuses two unincorporated tuplets with same multiplier.
    """

    tuplet_1 = abjad.Tuplet((2, 3), "c'8 d'8 e'8")
    abjad.beam(tuplet_1[:])
    tuplet_2 = abjad.Tuplet((2, 3), "c'16 d'16 e'16")
    abjad.slur(tuplet_2[:])

    assert format(tuplet_1) == abjad.String.normalize(
        r"""
        \times 2/3 {
            c'8
            [
            d'8
            e'8
            ]
        }
        """
    ), print(format(tuplet_1))

    assert format(tuplet_2) == abjad.String.normalize(
        r"""
        \times 2/3 {
            c'16
            (
            d'16
            e'16
            )
        }
        """
    ), print(format(tuplet_2))

    tuplets = abjad.select([tuplet_1, tuplet_2])
    new = abjad.mutate(tuplets).fuse()

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

    assert len(tuplet_1) == 0
    assert len(tuplet_2) == 0
    assert new is not tuplet_1 and new is not tuplet_2
    assert abjad.inspect(new).wellformed()
コード例 #30
0
ファイル: test_Container_remove.py プロジェクト: Abjad/abjad
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()
コード例 #31
0
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()
コード例 #32
0
 def contents(
     self,
     contents: abjad.Container,
 ) -> None:
     if not isinstance(contents, abjad.Container):
         raise TypeError("'contents' must be 'abjad.Container' or child "
                         "class")
     if not abjad.select(contents).leaves().are_contiguous_logical_voice():
         raise ValueError("'contents' must be contiguous logical voice")
     if isinstance(contents, abjad.Score):
         self._contents = abjad.mutate.copy(contents[0])
     elif isinstance(contents, abjad.Tuplet):
         self._contents = abjad.Container([abjad.mutate.copy(contents)])
     else:
         self._contents = abjad.mutate.copy(contents)
     dummy_container = abjad.mutate.copy(contents)
     self._current_window = dummy_container[:]
     dummy_container[:] = []
     self._is_first_window = True
コード例 #33
0
    def make_music(self, time_signature_pairs):
        music = self.make_basic_rhythm(time_signature_pairs, )

        shards = abjad.mutate(music[:]).split(time_signature_pairs)
        beam_specifier = rmakers.BeamSpecifier(
            beam_divisions_together=self.beams,
            beam_each_division=self.beams,
            beam_rests=self.beams,
        )
        time_signature_pairs = abjad.CyclicTuple(time_signature_pairs)
        for i, shard in enumerate(shards):
            leaves = abjad.select(shard).leaves()
            if not all(isinstance(_, abjad.Rest) for _ in leaves):
                beam_specifier([shard])
            container = abjad.Container(time_signature_pairs[i])
            abjad.mutate(shard).wrap(container)

        # music = self.add_attachments(music)
        return music
コード例 #34
0
    def _apply_trills(self, selections):
        container = abjad.Container()
        container.append(selections)

        for tie in abjad.iterate(container).logical_ties(pitched=True):
            if isinstance(tie[0], abjad.Chord):
                old_chord = tie[0]
                base_pitch = old_chord.written_pitches[0]
                trill_pitch = old_chord.written_pitches[-1]
                interval_ = abjad.NamedInterval().from_pitch_carriers(
                    base_pitch, trill_pitch)
                new_leaf = abjad.Note(base_pitch, old_chord.written_duration)

                trill_start = abjad.LilyPondLiteral(r'\pitchedTrill',
                                                    format_slot='before')
                trill_literal = abjad.LilyPondLiteral(
                    f'\startTrillSpan {trill_pitch}', format_slot='after')
                trill_stop = abjad.LilyPondLiteral(r'\stopTrillSpan',
                                                   format_slot='after')
                abjad.attach(trill_start, new_leaf)
                abjad.attach(trill_literal, new_leaf)
                last_leaf = tie[-1]
                next_leaf = abjad.inspect(last_leaf).leaf(1)
                if next_leaf != None:
                    abjad.attach(trill_stop, next_leaf)

                indicators = abjad.inspect(old_chord).indicators()
                for indicator in indicators:
                    abjad.attach(indicator, new_leaf)

                parent = abjad.inspect(old_chord).parentage().parent
                parent[parent.index(old_chord)] = new_leaf

                tail = abjad.select(tie).leaves()[1:]
                for leaf in tail:
                    new_tail = abjad.Note(base_pitch, leaf.written_duration)
                    parent = abjad.inspect(leaf).parentage().parent
                    parent[parent.index(leaf)] = new_tail
                    indicators = abjad.inspect(leaf).indicators()
                    for indicator in indicators:
                        abjad.attach(indicator, new_tail)

        return container[:]
コード例 #35
0
ファイル: SegmentMaker.py プロジェクト: adammccartney/arctic
 def _handle_dynamics(self):
     voice = self._score[f"{self.instrument_name}_Music_Voice"]
     leaves = abjad.select(voice).leaves()
     if not leaves:
         return
     music_durations = [abjad.inspect(_).duration() for _ in leaves]
     maker = rmakers.multiplied_duration(abjad.Skip)
     dynamics_skips = maker(music_durations)
     dynamics_voice = self._score[f"{self.instrument_name}_Dynamics_Voice"]
     dynamics_voice.extend(dynamics_skips)
     for expression in self.dynamics:
         index = expression[0]
         string = expression[1]
         leaf = dynamics_voice[index]
         if string in ("<", ">"):
             indicator = abjad.LilyPondLiteral("\\" + string, "after")
         elif string == "-|":
             indicator = abjad.LilyPondLiteral(r"\<", "after")
             stencil = abjad.Scheme("constante-hairpin")
             abjad.override(leaf).hairpin.stencil = stencil
         elif string == "<!":
             indicator = abjad.LilyPondLiteral(r"\<", "after")
             stencil = abjad.Scheme("abjad-flared-hairpin")
             abjad.override(leaf).hairpin.stencil = stencil
         elif string == "!>":
             indicator = abjad.LilyPondLiteral(r"\>", "after")
             stencil = abjad.Scheme("abjad-flared-hairpin")
             abjad.override(leaf).hairpin.stencil = stencil
         else:
             indicator = abjad.Dynamic(string)
         abjad.attach(indicator, leaf)
         if len(expression) == 3:
             staff_padding = expression[2]
             string = r"\override DynamicLineSpanner.staff-padding ="
             string += f" {staff_padding}"
             command = abjad.LilyPondLiteral(string)
             abjad.attach(command, leaf)
     last_leaf = dynamics_voice[-1]
     prototype = abjad.LilyPondLiteral
     if not abjad.inspect(last_leaf).has_indicator(prototype):
         if not abjad.inspect(last_leaf).has_indicator(abjad.Dynamic):
             indicator = abjad.LilyPondLiteral(r"\!", "after")
             abjad.attach(indicator, last_leaf)
コード例 #36
0
def test_scoretools_Voice_lilypond_voice_resolution_03():
    r'''Two like-named voices in two differently named staves.
    LilyPond gives unterminated beam warnings.
    LilyPond gives grob direction programming errors.
    We conclude that LilyPond identifies two separate voices.
    Good example for Abjad voice resolution.
    '''

    container = abjad.Container()
    container.append(abjad.Staff([abjad.Voice("c'8 d'8")]))
    container.append(abjad.Staff([abjad.Voice("e'8 f'8")]))
    container[0].name = 'staff1'
    container[1].name = 'staff2'
    container[0][0].name = 'voicefoo'
    container[1][0].name = 'voicefoo'
    beam = abjad.Beam()
    leaves = abjad.select(container).leaves()
    statement = 'attach(beam, leaves)'
    pytest.raises(Exception, statement)
コード例 #37
0
    def make_score_with_indicators_03(self):
        r'''Make 200-note staff with dynamic on every note.

        2.12 (r9704) initialization:     53,450,195 function calls (!!)
        2.12 (r9710) initialization:      2,124,500 function calls
        2.12 (r9724) initialization:      2,122,591 function calls

        2.12 (r9704) LilyPond format:       533,927 function calls
        2.12 (r9710) LilyPond format:        91,280 function calls
        2.12 (r9724) LilyPond format:        96,806 function calls

        '''
        import abjad
        staff = abjad.Staff(200 * abjad.Note("c'16"))
        selector = abjad.select().leaves()
        for note in selector(staff):
            dynamic = abjad.Dynamic('f')
            abjad.attach(dynamic, note)
        return staff
コード例 #38
0
def test_Parentage_logical_voice_11():
    """
    Leaves inside different staves have different logical voice signatures,
    even when the staves have the same name.
    """

    container = abjad.Container([abjad.Staff("c'8 c'8"), abjad.Staff("c'8 c'8")])
    container[0].name = container[1].name = "staff"

    assert abjad.lilypond(container) == abjad.String.normalize(
        r"""
        {
            \context Staff = "staff"
            {
                c'8
                c'8
            }
            \context Staff = "staff"
            {
                c'8
                c'8
            }
        }
        """
    )

    leaves = abjad.select(container).leaves()
    assert (
        abjad.get.parentage(leaves[0]).logical_voice()
        == abjad.get.parentage(leaves[1]).logical_voice()
    )
    assert (
        abjad.get.parentage(leaves[0]).logical_voice()
        != abjad.get.parentage(leaves[2]).logical_voice()
    )
    assert (
        abjad.get.parentage(leaves[2]).logical_voice()
        == abjad.get.parentage(leaves[3]).logical_voice()
    )
    assert (
        abjad.get.parentage(leaves[2]).logical_voice()
        != abjad.get.parentage(leaves[0]).logical_voice()
    )
コード例 #39
0
ファイル: ferneyhough.py プロジェクト: aarongrisez/abjad
 def make_nested_tuplet(
     self,
     tuplet_duration,
     outer_tuplet_proportions,
     inner_tuplet_subdivision_count,
     ):
     """
     Makes nested tuplet.
     """
     outer_tuplet = abjad.Tuplet.from_duration_and_ratio(
         tuplet_duration,
         outer_tuplet_proportions,
         )
     inner_tuplet_proportions = inner_tuplet_subdivision_count * [1]
     selector = abjad.select().leaves()
     last_leaf = selector(outer_tuplet)[-1]
     right_logical_tie = abjad.inspect(last_leaf).logical_tie()
     right_logical_tie.to_tuplet(inner_tuplet_proportions)
     return outer_tuplet
コード例 #40
0
def make_desordre_cell(pitches):
    """
    Makes a Désordre cell.
    """

    notes = [abjad.Note(pitch, (1, 8)) for pitch in pitches]
    notes = abjad.Selection(notes)
    beam = abjad.Beam()
    abjad.attach(beam, notes)
    slur = abjad.Slur()
    abjad.attach(slur, notes)
    clef = abjad.Dynamic('f')
    abjad.attach(clef, notes[0])
    dynamic = abjad.Dynamic('p')
    abjad.attach(dynamic, notes[1])

    # make the lower voice
    lower_voice = abjad.Voice(notes)
    lower_voice.name = 'RH Lower Voice'
    command = abjad.LilyPondLiteral(r'\voiceTwo')
    abjad.attach(command, lower_voice)
    n = int(math.ceil(len(pitches) / 2.))
    chord = abjad.Chord([pitches[0], pitches[0] + 12], (n, 8))
    articulation = abjad.Articulation('>')
    abjad.attach(articulation, chord)

    # make the upper voice
    upper_voice = abjad.Voice([chord])
    upper_voice.name = 'RH Upper Voice'
    command = abjad.LilyPondLiteral(r'\voiceOne')
    abjad.attach(command, upper_voice)

    # combine them together
    container = abjad.Container([lower_voice, upper_voice])
    container.is_simultaneous = True

    # make all 1/8 beats breakable
    leaves = abjad.select(lower_voice).leaves()
    for leaf in leaves[:-1]:
        bar_line = abjad.BarLine('')
        abjad.attach(bar_line, leaf)

    return container
コード例 #41
0
def test_scoretools_Selection_are_logical_voice_18():
    r'''Logical voice can not extend acrossdifferently named implicit voices.
    '''

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

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #42
0
def test_scoretools_Selection_are_logical_voice_20():
    r'''Logical voice can not extend across differently named implicit voices.
    '''

    container = abjad.Container(r'''
        \new Staff {
            c'8
            cs'8
            d'8
            ef'8
        }
        {
            e'8
            f'8
            fs'8
            g'8
        }
        ''')

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
def test_scoretools_Parentage__get_spanners_that_dominate_component_pair_04():
    r'''No spanners dominate empty slice following voice.
    '''

    voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }")
    leaves = abjad.select(voice).leaves()
    beam = abjad.Beam()
    abjad.attach(beam, leaves[:4])
    glissando = abjad.Glissando()
    abjad.attach(glissando, leaves[-4:])
    trill = abjad.TrillSpanner()
    abjad.attach(trill, leaves)

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

    pair = (voice[2], None)
    receipt = voice._get_spanners_that_dominate_component_pair(*pair)

    assert len(receipt) == 0
    assert receipt == []
コード例 #44
0
def test_scoretools_Selection_are_logical_voice_09():
    r'''Logical voice encompasses across like-named voices.
    '''

    staff = abjad.Staff(r'''
        \context Voice = "foo" {
            c'8
            d'8
            e'8
            f'8
        }
        \context Voice = "foo" {
            g'8
            a'8
            b'8
            c''8
        }
        ''')

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

    leaves = abjad.select(staff).leaves()
    assert leaves.are_logical_voice()
コード例 #45
0
def test_Selection_are_logical_voice_14():
    """
    Logical voice can extend across like-named staves.
    Logical voice can not extend across differently named implicit voices.
    """

    container = abjad.Container(r"""
        \context Staff = "foo" {
            c'8
            cs'8
            d'8
            ef'8
        }
        \context Staff = "foo" {
            e'8
            f'8
            fs'8
            g'8
        }
        """)

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #46
0
 def attach(self, score):
     violin_staff = score['Violin Staff']
     viola_staff = score['Viola Staff']
     cello_staff = score['Cello Staff']
     abjad.attach(abjad.Clef('bass'), abjad.select(cello_staff).leaves()[0])
     abjad.attach(abjad.instruments.Cello(),
                  abjad.select(cello_staff).leaves()[0])
     abjad.attach(abjad.Clef('alto'), abjad.select(viola_staff).leaves()[0])
     abjad.attach(abjad.instruments.Viola(),
                  abjad.select(viola_staff).leaves()[0])
     abjad.attach(abjad.Clef('treble'),
                  abjad.select(violin_staff).leaves()[0])
     abjad.attach(abjad.instruments.Violin(),
                  abjad.select(violin_staff).leaves()[0])
コード例 #47
0
def test_Selection_are_logical_voice_18():
    """
    Logical voice can not extend acrossdifferently named implicit voices.
    """

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

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #48
0
def test_Selection_are_logical_voice_09():
    """
    Logical voice encompasses across like-named voices.
    """

    staff = abjad.Staff(r"""
        \context Voice = "foo" {
            c'8
            d'8
            e'8
            f'8
        }
        \context Voice = "foo" {
            g'8
            a'8
            b'8
            c''8
        }
        """)

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

    leaves = abjad.select(staff).leaves()
    assert leaves.are_logical_voice()
def test_scoretools_Selection_are_contiguous_logical_voice_01():
    r'''Components that start at the same moment are bad.
    Even if components are all part of the same logical voice.
    '''

    voice = abjad.Voice(r'''
        {
            c'8
            d'8
        }
        \new Voice {
            e'8
            f'8
        }
        {
            g'8
            a'8
        }
        ''')
    r'''
    \new Voice {
        {
            c'8
            d'8
        }
        \new Voice {
            e'8
            f'8
        }
        {
            g'8
            a'8
        }
    }
    '''

    selection = abjad.select([voice, voice[0]])
    assert not selection.are_contiguous_logical_voice()
    selection = voice[0:1] + voice[0][:]
    assert not selection.are_contiguous_logical_voice()
    selection = voice[-1:] + voice[-1][:]
    assert not selection.are_contiguous_logical_voice()
コード例 #50
0
ファイル: test_Mutation_fuse.py プロジェクト: tuchang/abjad
def test_Mutation_fuse_10():

    tuplet_1 = abjad.Tuplet((2, 3), "c'8")
    tuplet_2 = abjad.Tuplet((2, 3), "c'4")
    voice = abjad.Voice([tuplet_1, tuplet_2, abjad.Note("c'4")])
    leaves = abjad.select(voice).leaves()
    abjad.slur(leaves)

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

    tuplets = voice[:2]
    abjad.mutate(tuplets).fuse()

    assert format(voice) == abjad.String.normalize(r"""
        \new Voice
        {
            \times 2/3 {
                c'8
                (
                c'4
            }
            c'4
            )
        }
        """), print(format(voice))

    assert abjad.inspect(voice).wellformed()
コード例 #51
0
def test_Container___setitem___02():
    """
    Replaces in-score leaf with out-of-score container.
    """

    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.Container("c'16 c'16 c'16")

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

    assert abjad.inspect(voice).wellformed()
コード例 #52
0
def test_scoretools_Selection_are_logical_voice_24():
    r'''Logical voice can not extend across differently named implicit voices.
    NOTE: THIS IS THE LILYPOND LACUNA.
    LilyPond *does* extend logical voice in this case.
    Abjad does not.
    '''

    container = abjad.Container(r'''
        \context Voice = "foo" {
            c'8
            cs'8
            d'8
            ef'8
        }
        e'8
        f'8
        fs'8
        g'8
        ''')

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #53
0
def test_Leaf__split_by_durations_05():
    """
    Assignable duration produces two notes.
    """

    voice = abjad.Voice(r"c'8 \times 2/3 { d'8 e'8 f'8 }")
    leaves = abjad.select(voice).leaves()
    abjad.beam(leaves)

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

    new_leaves = leaves[1]._split_by_durations([abjad.Duration(1, 24)],
                                               tie_split_notes=False)

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

    assert abjad.inspect(voice).wellformed()
コード例 #54
0
def test_Selection_are_logical_voice_20():
    """
    Logical voice can not extend across differently named implicit voices.
    """

    container = abjad.Container(r"""
        \new Staff {
            c'8
            cs'8
            d'8
            ef'8
        }
        {
            e'8
            f'8
            fs'8
            g'8
        }
        """)

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #55
0
def test_Selection_are_logical_voice_19():
    """
    Logical voice can not extend across differently named implicit voices.
    """

    container = abjad.Container(r"""
        {
            c'8
            d'8
            e'8
            f'8
        }
        \new Staff {
            g'8
            a'8
            b'8
            c''8
        }
        """)

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

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()
コード例 #56
0
def test_scoretools_Selection__get_dominant_spanners_08():
    r'''Only trill dominates first two notes.
    abjad.Note that trill abjad.attaches to notes.
    abjad.Note that beam and glissando abjad.attach to containers.
    '''

    voice = abjad.Voice("{ c'8 d'8 } { e'8 f'8 } { g'8 a'8 }")
    leaves = abjad.select(voice).leaves()
    beam = abjad.Beam()
    abjad.attach(beam, leaves[:4])
    glissando = abjad.Glissando()
    abjad.attach(glissando, leaves[-4:])
    trill = abjad.TrillSpanner()
    abjad.attach(trill, leaves)

    receipt = leaves[:2]._get_dominant_spanners()

    assert len(receipt) == 2
    assert (beam, 0) in receipt
    assert (trill, 0) in receipt
コード例 #57
0
def test_scoretools_Leaf__split_by_durations_22():
    r'''Split leaf outside of score and fracture spanners.
    '''

    note = abjad.Note("c'8")
    beam = abjad.Beam()
    abjad.attach(beam, abjad.select(note))

    assert format(note) == "c'8\n[\n]"

    halves = note._split_by_durations(
        [abjad.Duration(1, 32)],
        fracture_spanners=True,
    )

    assert format(halves[0][0]) == "c'32\n~\n[\n]"
    assert abjad.inspect(halves[0][0]).is_well_formed()

    assert format(halves[1][0]) == "c'16.\n[\n]"
    assert abjad.inspect(halves[1][0]).is_well_formed()
コード例 #58
0
ファイル: Descendants.py プロジェクト: aarongrisez/abjad
 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)
コード例 #59
0
def test_scoretools_Container___setitem___01():
    r'''Replaces in-score leaf with out-of-score leaf.
    '''

    voice = abjad.Voice("c'8 [ d'8 ] e'8 f'8")
    leaves = abjad.select(voice).leaves()
    abjad.attach(abjad.Glissando(), leaves)

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

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

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

    assert abjad.inspect(voice).is_well_formed()
コード例 #60
0
def test_Selection_are_logical_voice_24():
    """
    Logical voice can not extend across differently named implicit voices.
    NOTE: THIS IS THE LILYPOND LACUNA.
    LilyPond *does* extend logical voice in this case.
    Abjad does not.
    """

    container = abjad.Container(r"""
        \context Voice = "foo" {
            c'8
            cs'8
            d'8
            ef'8
        }
        e'8
        f'8
        fs'8
        g'8
        """)

    assert abjad.lilypond(container) == abjad.String.normalize(r"""
        {
            \context Voice = "foo"
            {
                c'8
                cs'8
                d'8
                ef'8
            }
            e'8
            f'8
            fs'8
            g'8
        }
        """)

    leaves = abjad.select(container).leaves()
    assert leaves[:4].are_logical_voice()
    assert leaves[4:].are_logical_voice()
    assert not leaves.are_logical_voice()