示例#1
0
def test_Inspection_indicators_04():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    comment_1 = abjad.LilyPondComment('comment 1')
    abjad.attach(comment_1, staff[0])
    comment_2 = abjad.LilyPondComment('comment 2')
    abjad.attach(comment_2, staff[0])

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

    indicators = abjad.inspect(staff[0]).indicators(abjad.LilyPondComment)
    assert comment_1 in indicators
    assert comment_2 in indicators
    assert len(indicators) == 2
示例#2
0
    def alternating_materials(self, annotated_durations: list, makers: dict):
        """Create alternating materials according to a list of named durations."""
        assert isinstance(annotated_durations[0],
                          list), "Each duration set must be a list."

        material_names = [dur[0].annotation for dur in annotated_durations]
        material_names = list(dict.fromkeys(material_names))

        for dur in annotated_durations:
            for maker, value in makers.items():
                if maker == dur[0].annotation:
                    if isinstance(value, str):
                        self.container.append(
                            abjad.Container(makers[maker],
                                            name=maker,
                                            identifier="% " + maker))
                    else:
                        selection = makers[maker](dur)
                        appendice = abjad.Container(selection,
                                                    name=maker,
                                                    identifier="% " + maker)
                        for item in appendice:
                            if isinstance(item, abjad.Tuplet):
                                item.name = "_"
                                item.identifier = "_"
                                # print(item.name)

                        # if isinstance(selection[0], abjad.Tuplet):
                        #     sel = abjad.Selection(selection).components(
                        #         abjad.Container)

                        #     for container in sel:
                        #         print(container)
                        #         container.name = maker
                        #         container.tag = maker
                        #         container.identifier = "% " + maker
                        # self.container.append(selection)
                        # else:
                        self.container.append(appendice)

        # add indices to materials and write comments in lilypond code to identify materials
        for i, name in enumerate(material_names):
            selectable = self.select_material(self.container, name)
            containers = abjad.select.components(selectable, abjad.Container)
            j = 0
            for container in containers:
                if container.name and container.identifier:
                    if name in container.name:
                        container.name = container.name + "_" + str(j)
                        container.identifier = container.identifier + "_" + str(
                            j)
                        if isinstance(container, abjad.Tuplet):
                            string = container.name
                            comment1 = abjad.LilyPondComment(string)
                            abjad.attach(comment1, container[0])
                            comment2 = abjad.LilyPondComment(
                                string, format_slot="after")
                            abjad.attach(comment2, container[-1])
                        j += 1
def test_scoretools_Inspection_get_indicator_11():

    note = abjad.Note("c'8")
    comment = abjad.LilyPondComment('comment')
    abjad.attach(comment, note)
    comment = abjad.LilyPondComment('another comment')
    abjad.attach(comment, note)

    statement = 'inspect(note).get_indicator(abjad.LilyPondComment)'
    assert pytest.raises(Exception, statement)
示例#4
0
def test_Inspection_indicators_02():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    abjad.slur(staff[:])
    comment = abjad.LilyPondComment("beginning of note content")
    abjad.attach(comment, staff[0])
    command = abjad.LilyPondLiteral(r"\slurDotted")
    abjad.attach(command, staff[0])

    assert format(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            % beginning of note content
            \slurDotted
            c'8
            (
            d'8
            e'8
            f'8
            )
        }
        """), format(staff)

    items = abjad.inspect(staff[0]).indicators()
    assert comment in items
    assert command in items
    assert len(items) == 3
def test_scoretools_Inspection_get_indicators_02():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    slur = abjad.Slur()
    abjad.attach(slur, staff[:])
    comment = abjad.LilyPondComment('beginning of note content')
    abjad.attach(comment, staff[0])
    command = abjad.LilyPondLiteral(r'\slurDotted')
    abjad.attach(command, staff[0])

    assert format(staff) == abjad.String.normalize(r'''
        \new Staff
        {
            % beginning of note content
            \slurDotted
            c'8
            (
            d'8
            e'8
            f'8
            )
        }
        '''), format(staff)

    items = abjad.inspect(staff[0]).get_indicators()
    assert comment in items
    assert command in items
    assert len(items) == 2
def test_scoretools_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)
示例#7
0
def test_get_has_indicator_04():

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

    assert abjad.get.has_indicator(staff[0], abjad.LilyPondComment)
    assert not abjad.get.has_indicator(staff[1], abjad.LilyPondComment)
def test_scoretools_Inspection_get_indicator_09():

    note = abjad.Note("c'8")
    comment = abjad.LilyPondComment('comment')
    abjad.attach(comment, note)

    indicator = abjad.inspect(note).get_indicator(abjad.LilyPondComment)
    assert indicator is comment
def test_scoretools_Inspection_report_modifications_01():

    voice = abjad.Voice("c'8 d'8 e'8 f'8")
    comment = abjad.LilyPondComment('Example voice', 'before')
    abjad.attach(comment, voice)
    abjad.override(voice).note_head.color = 'red'
    command = abjad.LilyPondLiteral("#(set-accidental-style 'forget)")
    abjad.attach(command, voice)
    beam = abjad.Beam()
    abjad.attach(beam, voice[:])
    abjad.override(beam).beam.thickness = 3

    assert format(voice) == abjad.String.normalize(
        r'''
        % Example voice
        \new Voice
        \with
        {
            \override NoteHead.color = #red
        }
        {
            #(set-accidental-style 'forget)
            \override Beam.thickness = #3
            c'8
            [
            d'8
            e'8
            \revert Beam.thickness
            f'8
            ]
        }
        '''
        )

    result = abjad.inspect(voice).report_modifications()

    assert format(result) == abjad.String.normalize(
        r'''
        % Example voice
        \new Voice
        \with
        {
            \override NoteHead.color = #red
        }
        {
            #(set-accidental-style 'forget)
            %%% 4 components omitted %%%
        }
        '''
        )
示例#10
0
def test_Inspection_indicators_04():

    staff = abjad.Staff("c'8 d'8 e'8 f'8")
    comment_1 = abjad.LilyPondComment("comment 1")
    abjad.attach(comment_1, staff[0])
    comment_2 = abjad.LilyPondComment("comment 2")
    abjad.attach(comment_2, staff[0])

    assert abjad.lilypond(staff) == abjad.String.normalize(r"""
        \new Staff
        {
            % comment 1
            % comment 2
            c'8
            d'8
            e'8
            f'8
        }
        """), abjad.lilypond(staff)

    indicators = abjad.get.indicators(staff[0], abjad.LilyPondComment)
    assert comment_1 in indicators
    assert comment_2 in indicators
    assert len(indicators) == 2
def test_scoretools_Inspection_report_modifications_02():

    tuplet = abjad.Tuplet((2, 3), "c'8 d'8 e'8")
    comment = abjad.LilyPondComment('Example tuplet', 'before')
    abjad.attach(comment, tuplet)
    abjad.override(tuplet).note_head.color = 'red'
    command = abjad.LilyPondLiteral("#(set-accidental-style 'forget)")
    abjad.attach(command, tuplet)
    beam = abjad.Beam()
    abjad.attach(beam, tuplet[:])
    abjad.override(beam).beam.thickness = 3

    assert format(tuplet) == abjad.String.normalize(
        r'''
        % Example tuplet
        \override NoteHead.color = #red
        \times 2/3 {
            #(set-accidental-style 'forget)
            \override Beam.thickness = #3
            c'8
            [
            d'8
            \revert Beam.thickness
            e'8
            ]
        }
        \revert NoteHead.color
        '''
        )

    result = abjad.inspect(tuplet).report_modifications()

    assert format(result) == abjad.String.normalize(
        r'''
        % Example tuplet
        \override NoteHead.color = #red
        \times 2/3 {
            #(set-accidental-style 'forget)
            %%% 3 components omitted %%%
        }
        \revert NoteHead.color
        '''
        )
示例#12
0
 def label_leaves(self, leaves, label):
     for leaf in leaves:
         label = abjad.LilyPondComment(label)
         abjad.attach(label, leaf)