Ejemplo n.º 1
0
def apply_scratch(selections):
    start_dynamic = abjad.Dynamic("sfp")
    stop_dynamic = abjad.Dynamic("ff")
    scratch_text = abjad.Markup(
        r"""\override #'(style . "box") \override #'(box-padding . 0.5) \italic \box \whiteout \small "scratch" """,
        literal=True,
    )
    start_scratch_span = abjad.StartTextSpan(
        left_text=scratch_text,
        style="solid-line-with-hook",
    )
    abjad.tweak(start_scratch_span).padding = 2
    abjad.tweak(start_scratch_span).staff_padding = 3
    stop_scratch_span = abjad.StopTextSpan()
    scratch_dynamic = abjad.Dynamic("f")
    ties = abjad.select(selections).logical_ties(pitched=True)
    for i, tie in enumerate(ties):
        if len(tie) < 2:
            abjad.attach(start_dynamic, tie[0])
        else:
            if i % 2 == 0:
                abjad.attach(start_dynamic, tie[0])
                abjad.attach(abjad.StartHairpin("<"), tie[0])
                abjad.attach(stop_dynamic, tie[-1])
            else:
                next_leaf = abjad.get.leaf(tie[-1], 1)
                abjad.attach(start_scratch_span, tie[0])
                abjad.attach(scratch_dynamic, tie[0])
                abjad.attach(stop_scratch_span, next_leaf)
Ejemplo n.º 2
0
 def _make_bow_contact_point_tweaks(leaf, bow_contact_point):
     if bow_contact_point is None:
         return
     abjad.tweak(leaf.note_head).stencil = "#ly:text-interface::print"
     abjad.tweak(leaf.note_head).text = bow_contact_point.markup
     y_offset = float((4 * bow_contact_point.degrees) - 2)
     abjad.tweak(leaf.note_head).Y_offset = f"#{y_offset}"
Ejemplo n.º 3
0
 def attach_middle_leaf(self, leaf: abjad.Chord, novent) -> None:
     for note_idx, note_head in enumerate(leaf.note_heads):
         if note_idx in self.optional_pitch_indices:
             abjad.tweak(
                 note_head).font_size = self._font_size_optional_note
         else:
             abjad.tweak(note_head).font_size = 0
Ejemplo n.º 4
0
    def _attach_rhythm_annotation_spanner(self, selection):
        from . import piecewise

        if not self.annotation_spanner_text and not self.frame:
            return
        leaves = []
        for leaf in abjad.iterate(selection).leaves():
            if abjad.get.parentage(leaf).get(abjad.OnBeatGraceContainer):
                continue
            leaves.append(leaf)
        container = abjad.get.before_grace_container(leaves[0])
        if container is not None:
            leaves_ = abjad.select(container).leaves()
            leaves[0:0] = leaves_
        container = abjad.get.after_grace_container(leaves[-1])
        if container is not None:
            leaves_ = abjad.select(container).leaves()
            leaves.extend(leaves_)
        string = self.annotation_spanner_text
        if string is None:
            string = self._make_rhythm_annotation_string()
        color = self.annotation_spanner_color or "#darkyellow"
        command = piecewise.rhythm_annotation_spanner(
            string,
            abjad.tweak(color).color,
            abjad.tweak(8).staff_padding,
            leak_spanner_stop=True,
            selector=classes.select().leaves(),
        )
        command(leaves)
Ejemplo n.º 5
0
def test_Note___copy___07():
    """
    Copy note with tweaks in notehead.
    """

    note = abjad.Note("c'4")
    abjad.tweak(note.note_head).color = "#red"
    abjad.tweak(note.note_head).Accidental.color = "#red"
    copied_note = copy.copy(note)
    string = abjad.lilypond(copied_note)
    assert string == abjad.String.normalize(r"""
        \tweak Accidental.color #red
        \tweak color #red
        c'4
        """), print(string)
Ejemplo n.º 6
0
 def _apply_tweaks(argument, tweaks, i=None, total=None):
     if not tweaks:
         return
     manager = abjad.tweak(argument)
     literals = []
     for item in tweaks:
         if isinstance(item, tuple):
             assert len(item) == 2
             manager_, i_ = item
             if 0 <= i_ and i_ != i:
                 continue
             if i_ < 0 and i_ != -(total - i):
                 continue
         else:
             manager_ = item
         assert isinstance(manager_, abjad.TweakInterface)
         literals.append(bool(manager_._literal))
         if manager_._literal is True:
             manager._literal = True
         tuples = manager_._get_attribute_tuples()
         for attribute, value in tuples:
             setattr(manager, attribute, value)
     if True in literals and False in literals:
         message = "all tweaks must be literal"
         message += ", or else all tweaks must be nonliteral:\n"
         strings = [f"    {repr(_)}" for _ in tweaks]
         string = "\n".join(strings)
         message += string
         raise Exception(message)
Ejemplo n.º 7
0
def test_NoteHead___init___04():
    """
    Initialize note-head with tweak manager.
    """

    note_head = abjad.NoteHead("cs''", tweaks=abjad.tweak("red").color)

    assert format(note_head) == "\\tweak color #red\ncs''"
Ejemplo n.º 8
0
 def style(
     self,
     style: str,
 ) -> None:
     if not isinstance(style, str):
         raise TypeError("'style' must be 'str'")
     self._style = style
     abjad.tweak(self._note_heads[1]).style = self._style
Ejemplo n.º 9
0
def test_NoteHead___init___04():
    """
    Initialize note-head with tweak manager.
    """

    note_head = abjad.NoteHead("cs''", tweaks=abjad.tweak("#red").color)

    assert abjad.lilypond(note_head) == "\\tweak color #red\ncs''"
Ejemplo n.º 10
0
def test_NoteHead___init___04():
    """
    Initialize note-head with tweak manager.
    """

    note_head = abjad.NoteHead("cs''", tweaks=abjad.tweak('red').color)

    assert format(note_head) == "\\tweak color #red\ncs''"
Ejemplo n.º 11
0
    def process_logical_tie(self, music, music_logical_tie, data_logical_tie,
                            leaf_index):

        parent_event = data_logical_tie.parent
        if pluck_strings := getattr(parent_event, "pluck_strings", None):
            for i, note_head in enumerate(music[leaf_index].note_heads):
                if i not in pluck_strings:
                    abjad.tweak(note_head).transparent = True
Ejemplo n.º 12
0
def test_NoteHead___copy___01():

    note_head_1 = abjad.NoteHead("cs''")
    note_head_1.is_cautionary = True
    note_head_1.is_forced = True
    abjad.tweak(note_head_1).color = "red"
    abjad.tweak(note_head_1).font_size = -2

    note_head_2 = copy.copy(note_head_1)

    assert isinstance(note_head_1, abjad.NoteHead)
    assert isinstance(note_head_2, abjad.NoteHead)
    assert note_head_1 == note_head_2
    assert note_head_1 is not note_head_2
    assert note_head_1.is_cautionary == note_head_2.is_cautionary
    assert note_head_1.is_forced == note_head_2.is_forced
    assert note_head_1.tweaks == note_head_2.tweaks
    assert note_head_1.tweaks is not note_head_2.tweaks
Ejemplo n.º 13
0
def test_NoteHead___copy___01():

    note_head_1 = abjad.NoteHead("cs''")
    note_head_1.is_cautionary = True
    note_head_1.is_forced = True
    abjad.tweak(note_head_1).color = 'red'
    abjad.tweak(note_head_1).font_size = -2

    note_head_2 = copy.copy(note_head_1)

    assert isinstance(note_head_1, abjad.NoteHead)
    assert isinstance(note_head_2, abjad.NoteHead)
    assert note_head_1 == note_head_2
    assert note_head_1 is not note_head_2
    assert note_head_1.is_cautionary == note_head_2.is_cautionary
    assert note_head_1.is_forced == note_head_2.is_forced
    assert note_head_1.tweaks == note_head_2.tweaks
    assert note_head_1.tweaks is not note_head_2.tweaks
Ejemplo n.º 14
0
class PluckSegment(calliope.Segment):
    def process_logical_tie(self, music, music_logical_tie, data_logical_tie,
                            leaf_index):

        parent_event = data_logical_tie.parent
        if pluck_strings := getattr(parent_event, "pluck_strings", None):
            for i, note_head in enumerate(music[leaf_index].note_heads):
                if i not in pluck_strings:
                    abjad.tweak(note_head).transparent = True

        if def_event := getattr(parent_event, "def_event", None):
            if not isinstance(music[leaf_index], abjad.Skip):
                for i, note_head in enumerate(music[leaf_index].note_heads):
                    if note_head.written_pitch.number in def_event.existing_map:
                        abjad.tweak(note_head).style = "harmonic"
                        abjad.tweak(note_head).size = 4
                    else:
                        abjad.tweak(note_head).style = "harmonic-black"
Ejemplo n.º 15
0
 def is_parenthesized(
     self,
     is_parenthesized: bool,
 ) -> None:
     if not isinstance(is_parenthesized, bool):
         raise TypeError("'is_parenthesized' must be 'bool'")
     self._is_parenthesized = is_parenthesized
     self._note_heads[0].is_parenthesized = self._is_parenthesized
     if self._is_parenthesized:
         abjad.tweak(self._note_heads[0]).ParenthesesItem__font_size = -4
Ejemplo n.º 16
0
    def attach(self, leaf: abjad.Chord, novent) -> None:
        abjad.attach(
            abjad.LilyPondLiteral(
                "\\once \\override ParenthesesItem.font-size = #0.75"),
            leaf,
        )
        abjad.attach(
            abjad.LilyPondLiteral(
                "\\once \\override ParenthesesItem.padding = #0.1"),
            leaf,
        )

        for note_idx, note_head in enumerate(leaf.note_heads):
            if note_idx in self.optional_pitch_indices:
                note_head.is_parenthesized = True
                abjad.tweak(
                    note_head).font_size = self._font_size_optional_note
            else:
                abjad.tweak(note_head).font_size = 0
Ejemplo n.º 17
0
def attach_clicks(selections):
    cyc_clicks = evans.CyclicList(
        [
            "XSB(c.2 clicks per second)",
            "XSB(c.3 clicks/s)",
            "XSB(c.4)",
            "XSB(c.5)",
            "XSB(c.6)",
            "XSB(c.7)",
            "XSB(c.8)",
            "slow bow",
            "norm.",
            "quasi noise",
        ],
        forget=False,
    )
    for leaf in abjad.Selection(selections).leaves():
        text = cyc_clicks(r=1)[0]
        mark = abjad.Markup(fr"\upright {{ {text} }}", direction=abjad.Up)
        span = abjad.StartTextSpan(
            left_text=mark,
            style="dashed-line-with-arrow",
        )
        abjad.tweak(span).padding = 6.75
        abjad.attach(span, leaf)
        abjad.attach(abjad.StopTextSpan(), leaf)
    first_leaf = abjad.Selection(selections).leaf(0)
    abjad.attach(abjad.Dynamic("fff"), first_leaf)
    abjad.detach(abjad.StopTextSpan(), first_leaf)
    final = abjad.StartTextSpan(
        left_text=abjad.Markup(r"\upright { quasi noise }"),
        style="invisible-line",
    )
    abjad.tweak(final).padding = 6.75
    final_leaf = abjad.Selection(selections).leaf(-1)
    start_span_indicator = [
        _
        for _ in abjad.get.indicators(final_leaf)
        if isinstance(_, abjad.StartTextSpan)
    ]
    abjad.detach(start_span_indicator[0], final_leaf)
    abjad.attach(final, final_leaf)
    abjad.attach(abjad.StopTextSpan(), abjad.get.leaf(final_leaf, 1))
Ejemplo n.º 18
0
def apply_spanner(selections):
    for run in abjad.Selection(selections).runs():
        start = abjad.StartTextSpan(
            left_text=abjad.Markup(r"\upright noise"),
            right_text=abjad.Markup(r"\markup \upright XSB"),
            style="dashed-line-with-arrow",
        )
        abjad.tweak(start).staff_padding = 2
        stop = abjad.StopTextSpan()
        abjad.attach(start, abjad.Selection(run).leaf(0))
        abjad.attach(stop, abjad.get.leaf(abjad.Selection(run).leaf(-1), 1))
Ejemplo n.º 19
0
def attach_material(selections):
    ties = abjad.Selection(selections).logical_ties()
    first_leaf = abjad.Selection(ties).leaf(0)
    center_leaf = abjad.Selection(ties[len(ties) // 2]).leaf(0)
    last_leaf = abjad.Selection(ties).leaf(-1)
    cyc_dynamics = evans.CyclicList(["p", "f"], forget=False)
    cyc_hairpins = evans.CyclicList(["<", ">"], forget=False)
    for tie in ties:
        dynamic = abjad.Dynamic(cyc_dynamics(r=1)[0])
        abjad.attach(dynamic, tie[0])
    for tie in ties[:-1]:
        hairpin = abjad.StartHairpin(cyc_hairpins(r=1)[0])
        abjad.attach(hairpin, tie[0])
    start = abjad.StartTextSpan(
        left_text=abjad.Markup(r"\upright norm."),
        style="dashed-line-with-arrow",
    )
    middle = abjad.StartTextSpan(
        left_text=abjad.Markup(r"\upright msp."),
        right_text=abjad.Markup(r"\markup \upright st."),
        style="dashed-line-with-arrow",
    )
    middle_stop = abjad.StopTextSpan()
    final_stop = abjad.StopTextSpan()
    abjad.tweak(start).staff_padding = 2
    abjad.tweak(middle).staff_padding = 2
    abjad.attach(start, first_leaf)
    abjad.attach(middle_stop, center_leaf)
    abjad.attach(middle, center_leaf)
    abjad.attach(final_stop, last_leaf)
    for leaf in abjad.Selection(selections).leaves():
        literal_1 = abjad.LilyPondLiteral(
            r"\once \override Staff.Tie.transparent = ##t",
            format_slot="before",
        )
        abjad.attach(literal_1, leaf)
        literal_2 = abjad.LilyPondLiteral(
            r"\once \override Dots.staff-position = #1.75",
            format_slot="before",
        )
        abjad.attach(literal_2, leaf)
Ejemplo n.º 20
0
 def _format_leaf(leaf, leaves):
     indicators = abjad.get.indicators(leaf)
     bow_contact_point = indicators[0]
     bow_motion_technique = indicators[1]
     if bow_contact_point is None:
         return
     if bow_contact_point.degrees is None:
         abjad.tweak(leaf.note_head).style = "#'cross"
         return
     if len(leaves) == 1:
         return
     _make_bow_contact_point_tweaks(leaf, bow_contact_point)
     if not _next_leaf_is_bowed(leaf, leaves):
         return
     glissando = abjad.Glissando()
     if bow_motion_technique is not None:
         style = f"#'{bow_motion_technique.glissando_style}"
         abjad.tweak(glissando).style = style
     abjad.attach(glissando, leaf, tag=tag)
     if not omit_bow_changes:
         _make_bow_change_contributions(leaf, leaves, bow_contact_point)
Ejemplo n.º 21
0
def test_mutate_copy_09():
    """
    Copies tweaks.
    """
    staff = abjad.Staff("c'4 cs' d' ds'")
    abjad.tweak(staff[1].note_head).color = "#red"
    abjad.tweak(staff[1].note_head).Accidental.color = "#red"
    copied_staff = abjad.mutate.copy(staff)
    string = abjad.lilypond(copied_staff)

    assert string == abjad.String.normalize(
        r"""
        \new Staff
        {
            c'4
            \tweak Accidental.color #red
            \tweak color #red
            cs'4
            d'4
            ds'4
        }
        """
    ), print(string)
    assert abjad.wf.wellformed(staff)
Ejemplo n.º 22
0
 def style(
     self,
     style: str,
 ) -> None:
     if not isinstance(style, str):
         raise TypeError("'style' must be 'str'")
     self._style = style
     if not self._style.endswith('flageolet'):
         abjad.tweak(self._note_head).style = self._style
     else:
         flageolet = abjad.LilyPondLiteral(
             r'\flageolet',
             format_slot='after',
         )
         abjad.attach(flageolet, self)
Ejemplo n.º 23
0
def test_LilyPondGrobNameManager___setattr___20():
    """
    Notehead style abjad.overrides are handled just like all other
    note_head grob abjad.overrides, even for note_heads in chords.
    """

    chord = abjad.Chord([1, 2, 3], (1, 4))
    abjad.tweak(chord.note_heads[0]).style = "harmonic"

    assert format(chord) == abjad.String.normalize(r"""
        <
            \tweak style #'harmonic
            cs'
            d'
            ef'
        >4
        """)
Ejemplo n.º 24
0
def test_NoteHead___deepcopy___01():

    note_head_1 = abjad.NoteHead("cs''")
    abjad.tweak(note_head_1).color = "red"
    note_head_1.is_cautionary = True
    note_head_1.is_forced = True

    note_head_2 = copy.deepcopy(note_head_1)

    assert isinstance(note_head_1, abjad.NoteHead)
    assert isinstance(note_head_2, abjad.NoteHead)
    assert note_head_1 == note_head_2
    assert note_head_1 is not note_head_2
    assert note_head_1.is_cautionary == note_head_2.is_cautionary
    assert note_head_1.is_forced == note_head_2.is_forced
    assert note_head_1.tweaks == note_head_2.tweaks
    assert note_head_1.tweaks is not note_head_2.tweaks
Ejemplo n.º 25
0
def test_Chord___deepcopy___01():
    """
    Chord deepchopies note-heads.
    """

    chord_1 = abjad.Chord("<c' e' g'>4")
    abjad.tweak(chord_1.note_heads[0]).color = "red"
    chord_2 = copy.deepcopy(chord_1)

    assert abjad.lilypond(chord_1) == abjad.String.normalize(
        r"""
        <
            \tweak color #red
            c'
            e'
            g'
        >4
        """
    )

    assert abjad.lilypond(chord_2) == abjad.String.normalize(
        r"""
        <
            \tweak color #red
            c'
            e'
            g'
        >4
        """
    )

    assert chord_2.note_heads[0]._client is chord_2
    assert chord_2.note_heads[1]._client is chord_2
    assert chord_2.note_heads[2]._client is chord_2

    assert abjad.lilypond(chord_1) == abjad.lilypond(chord_2)
    assert chord_1 is not chord_2

    assert chord_1.note_heads[0] == chord_2.note_heads[0]
    assert chord_1.note_heads[1] == chord_2.note_heads[1]
    assert chord_1.note_heads[2] == chord_2.note_heads[2]

    assert chord_1.note_heads[0] is not chord_2.note_heads[0]
    assert chord_1.note_heads[1] is not chord_2.note_heads[1]
    assert chord_1.note_heads[2] is not chord_2.note_heads[2]
Ejemplo n.º 26
0
def test_Chord___copy___04():
    """
    Chord copies tweaked note-heads.
    """

    chord_1 = abjad.Chord("<c' e' g'>4")
    abjad.tweak(chord_1.note_heads[0]).color = "red"
    chord_2 = copy.copy(chord_1)

    assert format(chord_1) == abjad.String.normalize(
        r"""
        <
            \tweak color #red
            c'
            e'
            g'
        >4
        """
    )

    assert format(chord_2) == abjad.String.normalize(
        r"""
        <
            \tweak color #red
            c'
            e'
            g'
        >4
        """
    )

    assert chord_2.note_heads[0]._client is chord_2
    assert chord_2.note_heads[1]._client is chord_2
    assert chord_2.note_heads[2]._client is chord_2

    assert format(chord_1) == format(chord_2)
    assert chord_1 is not chord_2

    assert chord_1.note_heads[0] == chord_2.note_heads[0]
    assert chord_1.note_heads[1] == chord_2.note_heads[1]
    assert chord_1.note_heads[2] == chord_2.note_heads[2]

    assert chord_1.note_heads[0] is not chord_2.note_heads[0]
    assert chord_1.note_heads[1] is not chord_2.note_heads[1]
    assert chord_1.note_heads[2] is not chord_2.note_heads[2]
Ejemplo n.º 27
0
def test_Chord___copy___04():
    """
    Chord copies tweaked note-heads.
    """

    chord_1 = abjad.Chord("<c' e' g'>4")
    abjad.tweak(chord_1.note_heads[0]).color = "red"
    chord_2 = copy.copy(chord_1)

    assert format(chord_1) == abjad.String.normalize(
        r"""
        <
            \tweak color #red
            c'
            e'
            g'
        >4
        """
    )

    assert format(chord_2) == abjad.String.normalize(
        r"""
        <
            \tweak color #red
            c'
            e'
            g'
        >4
        """
    )

    assert chord_2.note_heads[0]._client is chord_2
    assert chord_2.note_heads[1]._client is chord_2
    assert chord_2.note_heads[2]._client is chord_2

    assert format(chord_1) == format(chord_2)
    assert chord_1 is not chord_2

    assert chord_1.note_heads[0] == chord_2.note_heads[0]
    assert chord_1.note_heads[1] == chord_2.note_heads[1]
    assert chord_1.note_heads[2] == chord_2.note_heads[2]

    assert chord_1.note_heads[0] is not chord_2.note_heads[0]
    assert chord_1.note_heads[1] is not chord_2.note_heads[1]
    assert chord_1.note_heads[2] is not chord_2.note_heads[2]
Ejemplo n.º 28
0
 def _transform_brackets(self, selections):
     for tuplet in abjad.select(selections).components(abjad.Tuplet):
         for rest_group in abjad.select(
                 tuplet).rests().group_by_contiguity():
             abjad.mutate.fuse(rest_group)
         inner_durs = []
         for _ in tuplet[:]:
             if isinstance(_, abjad.Tuplet):
                 inner_durs.append(_.multiplied_duration)
             else:
                 inner_durs.append(_.written_duration)
         tuplet_dur = sum(inner_durs)
         imp_num, imp_den = tuplet.implied_prolation.pair
         head_dur = tuplet_dur / imp_den
         dur_string = self._assemble_notehead(head_dur)
         abjad.tweak(
             tuplet
         ).TupletNumber.text = f'#(tuplet-number::append-note-wrapper(tuplet-number::non-default-tuplet-fraction-text {imp_den} {imp_num}) "{dur_string}")'
def test_LilyPondGrobNameManager___setattr___20():
    """
    Notehead style abjad.overrides are handled just like all other
    note_head grob abjad.overrides, even for note_heads in chords.
    """

    chord = abjad.Chord([1, 2, 3], (1, 4))
    abjad.tweak(chord.note_heads[0]).style = "harmonic"

    assert format(chord) == abjad.String.normalize(
        r"""
        <
            \tweak style #'harmonic
            cs'
            d'
            ef'
        >4
        """
    )
Ejemplo n.º 30
0
def test_NoteHeadList___setitem___03():
    """
    Set note-head with tweaked note-head.
    """

    chord = abjad.Chord("<c' cs'' f''>4")
    note_head = abjad.NoteHead(3)
    abjad.tweak(note_head).color = "red"
    chord.note_heads[0] = note_head

    assert format(chord) == abjad.String.normalize(r"""
        <
            \tweak color #red
            ef'
            cs''
            f''
        >4
        """)

    assert abjad.inspect(chord).wellformed()
Ejemplo n.º 31
0
def test_NoteHeadList_append_01():
    """
    Append tweaked note-head to chord.
    """

    chord = abjad.Chord("<c' d'>4")
    note_head = abjad.NoteHead("b'")
    abjad.tweak(note_head).style = 'harmonic'
    chord.note_heads.append(note_head)

    assert format(chord) == abjad.String.normalize(r"""
        <
            c'
            d'
            \tweak style #'harmonic
            b'
        >4
        """)

    assert note_head._client is chord
Ejemplo n.º 32
0
def test_NoteHeadList___setitem___03():
    """
    Set note-head with tweaked note-head.
    """

    chord = abjad.Chord("<c' cs'' f''>4")
    note_head = abjad.NoteHead(3)
    abjad.tweak(note_head).color = "red"
    chord.note_heads[0] = note_head

    assert format(chord) == abjad.String.normalize(
        r"""
        <
            \tweak color #red
            ef'
            cs''
            f''
        >4
        """
    )

    assert abjad.inspect(chord).wellformed()
Ejemplo n.º 33
0
def add_acciaccatura(
    nth_event: int,
    pitch: ji.JIPitch,
    novent_line: lily.NOventLine,
    add_glissando: bool = False,
    use_artifical_harmonic: bool = False,
) -> None:
    if use_artifical_harmonic:
        abjad_note = abjad.Chord(
            _get_artifical_harmonic_pitches(pitch),
            abjad.Duration(1, 8),
        )
        abjad.tweak(abjad_note.note_heads[1]).style = "harmonic"
        pitch = pitch + ji.r(4, 1)

    else:
        abjad_note = abjad.Note(
            lily.convert2abjad_pitch(pitch, globals_.RATIO2PITCHCLASS),
            abjad.Duration(1, 8),
        )
    novent_line[nth_event].acciaccatura = attachments.Acciaccatura(
        [pitch], abjad_note, add_glissando)
Ejemplo n.º 34
0
def test_NoteHeadList_append_01():
    """
    Append tweaked note-head to chord.
    """

    chord = abjad.Chord("<c' d'>4")
    note_head = abjad.NoteHead("b'")
    abjad.tweak(note_head).style = "harmonic"
    chord.note_heads.append(note_head)

    assert format(chord) == abjad.String.normalize(
        r"""
        <
            c'
            d'
            \tweak style #'harmonic
            b'
        >4
        """
    )

    assert note_head._client is chord
Ejemplo n.º 35
0
def trill_spanner(
    *tweaks: abjad.TweakInterface,
    alteration: str = None,
    harmonic: bool = None,
    left_broken: bool = None,
    map: abjad.Expression = None,
    right_broken: bool = None,
    selector: abjad.Expression = classes.select().tleaves().rleak(),
    start_trill_span: abjad.StartTrillSpan = None,
    stop_trill_span: abjad.StopTrillSpan = None,
) -> SpannerIndicatorCommand:
    r"""
    Attaches trill spanner indicators.

    ..  container:: example

        Attaches trill spanner to trimmed leaves (leaked to the right):

        >>> stack = baca.stack(
        ...     baca.figure(
        ...         [1, 1, 5, -1],
        ...         16,
        ...         affix=baca.rests_around([2], [4]),
        ...         restart_talea=True,
        ...         treatments=[-1],
        ...     ),
        ...     rmakers.beam(),
        ...     baca.trill_spanner(),
        ...     baca.tuplet_bracket_staff_padding(2),
        ... )
        >>> selection = stack([[0, 2, 10], [18, 16, 15, 20, 19], [9]])
        >>> lilypond_file = abjad.LilyPondFile.rhythm(selection)
        >>> rmakers.attach_markup_struts(lilypond_file)
        >>> abjad.show(lilypond_file) # doctest: +SKIP

        ..  docs::

            >>> string = abjad.lilypond(lilypond_file[abjad.Score])
            >>> print(string)
            \new Score
            <<
                \new GlobalContext
                {
                    \time 11/8
                    s1 * 11/8
                }
                \new Staff
                {
                    \tweak text #tuplet-number::calc-fraction-text
                    \times 9/10 {
                        \override TupletBracket.staff-padding = 2
                        r8
                        - \tweak staff-padding 11
                        - \tweak transparent ##t
                        ^ \markup I
                        c'16
                        [
                        \startTrillSpan
                        d'16
                        ]
                        bf'4
                        ~
                        bf'16
                        r16
                    }
                    \tweak text #tuplet-number::calc-fraction-text
                    \times 9/10 {
                        fs''16
                        [
                        e''16
                        ]
                        ef''4
                        ~
                        ef''16
                        r16
                        af''16
                        [
                        g''16
                        ]
                    }
                    \times 4/5 {
                        a'16
                        r4
                        \stopTrillSpan
                        \revert TupletBracket.staff-padding
                    }
                }
            >>

    ..  container:: example

        Attaches trill to trimmed leaves (leaked to the right) in every
        run:

        >>> stack = baca.stack(
        ...     baca.figure(
        ...         [1, 1, 5, -1],
        ...         16,
        ...         affix=baca.rests_around([2], [4]),
        ...         restart_talea=True,
        ...         treatments=[-1],
        ...     ),
        ...     rmakers.beam(),
        ...     baca.new(
        ...         baca.trill_spanner(),
        ...         map=baca.runs(),
        ...         ),
        ...     baca.tuplet_bracket_staff_padding(2),
        ... )
        >>> selection = stack([[0, 2, 10], [18, 16, 15, 20, 19], [9]])
        >>> lilypond_file = abjad.LilyPondFile.rhythm(selection)
        >>> rmakers.attach_markup_struts(lilypond_file)
        >>> abjad.show(lilypond_file) # doctest: +SKIP

        ..  docs::

            >>> string = abjad.lilypond(lilypond_file[abjad.Score])
            >>> print(string)
            \new Score
            <<
                \new GlobalContext
                {
                    \time 11/8
                    s1 * 11/8
                }
                \new Staff
                {
                    \tweak text #tuplet-number::calc-fraction-text
                    \times 9/10 {
                        \override TupletBracket.staff-padding = 2
                        r8
                        - \tweak staff-padding 11
                        - \tweak transparent ##t
                        ^ \markup I
                        c'16
                        [
                        \startTrillSpan
                        d'16
                        ]
                        bf'4
                        ~
                        bf'16
                        r16
                        \stopTrillSpan
                    }
                    \tweak text #tuplet-number::calc-fraction-text
                    \times 9/10 {
                        fs''16
                        [
                        \startTrillSpan
                        e''16
                        ]
                        ef''4
                        ~
                        ef''16
                        r16
                        \stopTrillSpan
                        af''16
                        [
                        \startTrillSpan
                        g''16
                        \stopTrillSpan
                        ]
                    }
                    \times 4/5 {
                        a'16
                        \startTrillSpan
                        r4
                        \stopTrillSpan
                        \revert TupletBracket.staff-padding
                    }
                }
            >>

    ..  container:: example

        Tweaks trill spanner:

        >>> stack = baca.stack(
        ...     baca.figure(
        ...         [1, 1, 5, -1],
        ...         16,
        ...         affix=baca.rests_around([2], [4]),
        ...         restart_talea=True,
        ...         treatments=[-1],
        ...     ),
        ...     rmakers.beam(),
        ...     baca.new(
        ...         baca.trill_spanner(
        ...             abjad.tweak("#red").color,
        ...             alteration='M2',
        ...             ),
        ...         ),
        ...     baca.tuplet_bracket_staff_padding(2),
        ... )
        >>> selection = stack([[0, 2, 10], [18, 16, 15, 20, 19], [9]])
        >>> lilypond_file = abjad.LilyPondFile.rhythm(selection)
        >>> rmakers.attach_markup_struts(lilypond_file)
        >>> abjad.show(lilypond_file) # doctest: +SKIP

        ..  docs::

            >>> string = abjad.lilypond(lilypond_file[abjad.Score])
            >>> print(string)
            \new Score
            <<
                \new GlobalContext
                {
                    \time 11/8
                    s1 * 11/8
                }
                \new Staff
                {
                    \tweak text #tuplet-number::calc-fraction-text
                    \times 9/10 {
                        \override TupletBracket.staff-padding = 2
                        r8
                        - \tweak staff-padding 11
                        - \tweak transparent ##t
                        ^ \markup I
                        \pitchedTrill
                        c'16
                        [
                        - \tweak color #red
                        \startTrillSpan d'
                        d'16
                        ]
                        bf'4
                        ~
                        bf'16
                        r16
                    }
                    \tweak text #tuplet-number::calc-fraction-text
                    \times 9/10 {
                        fs''16
                        [
                        e''16
                        ]
                        ef''4
                        ~
                        ef''16
                        r16
                        af''16
                        [
                        g''16
                        ]
                    }
                    \times 4/5 {
                        a'16
                        r4
                        \stopTrillSpan
                        \revert TupletBracket.staff-padding
                    }
                }
            >>

    """
    if alteration is not None:
        prototype = (abjad.NamedPitch, abjad.NamedInterval, str)
        if not isinstance(alteration, prototype):
            message = "trill spanner 'alteration' must be pitch, interval, str:"
            message += f"\n   {alteration}"
            raise Exception(message)
    interval = pitch = None
    if alteration is not None:
        try:
            pitch = abjad.NamedPitch(alteration)
        except Exception:
            try:
                interval = abjad.NamedInterval(alteration)
            except Exception:
                pass
    start_trill_span = start_trill_span or abjad.StartTrillSpan()
    if pitch is not None or interval is not None:
        start_trill_span = abjad.new(start_trill_span,
                                     interval=interval,
                                     pitch=pitch)
    if harmonic is True:
        string = "#(lambda (grob) (grob-interpret-markup grob"
        string += r' #{ \markup \musicglyph #"noteheads.s0harmonic" #}))'
        abjad.tweak(start_trill_span).TrillPitchHead.stencil = string
    stop_trill_span = stop_trill_span or abjad.StopTrillSpan()
    return SpannerIndicatorCommand(
        left_broken=left_broken,
        map=map,
        right_broken=right_broken,
        selector=selector,
        start_indicator=start_trill_span,
        stop_indicator=stop_trill_span,
        tags=[_site(inspect.currentframe())],
        tweaks=tweaks,
    )
Ejemplo n.º 36
0
    baca.hairpin(
        'pp < mf',
        selector=baca.leaves()[1:],
        ),
    baca.make_monads('1/4  1/6  1/6  1/10  1/10  1/10'),
    baca.staff_positions(
        [4, 4, 2, 6, 4, 2],
        allow_repeats=True,
        ),
    )

maker(
    ('rh', 6),
    baca.hairpin(
        'p -- !',
        abjad.tweak(True).to_barline,
        selector=baca.leaves().rleak(),
        ),
    baca.make_monads('1/4  1/6  1/6  1/8  1/8  1/8'),
    baca.markup(
        r'\baca-fz-markup',
        direction=abjad.Down,
        literal=True,
        ),
    baca.markup(
        r'\baca-mpz-markup',
        direction=abjad.Down,
        literal=True,
        selector=baca.pleaves()[1:],
        ),
    baca.staff_positions(
Ejemplo n.º 37
0
        lines = file.readlines()

        if len(lines) > 0:

            for line in lines:

                c = Chord.from_string(line)

                lower_pitches = [p for p in c.pitches if p.midi_number < 60]
                lower_abjad_chord = abjad.Chord([], abjad.Duration(1, 1))
                if len(lower_pitches) > 0:
                    for i in range(0, len(lower_pitches)):
                        lower_abjad_chord.note_heads.extend(
                            [lower_pitches[i].midi_number - 60])
                        if lower_pitches[i].is_harmonic_tone == False:
                            abjad.tweak(lower_abjad_chord.note_heads[i]
                                        ).style = 'harmonic'
                    lower_staff_components.append(lower_abjad_chord)
                else:
                    lower_staff_components.append(
                        abjad.Rest(abjad.Duration(1, 1)))

                upper_pitches = [p for p in c.pitches if p.midi_number >= 60]
                upper_abjad_chord = abjad.Chord([], abjad.Duration(1, 1))
                if len(upper_pitches) > 0:
                    for i in range(0, len(upper_pitches)):
                        upper_abjad_chord.note_heads.extend(
                            [upper_pitches[i].midi_number - 60])
                        if upper_pitches[i].is_harmonic_tone == False:
                            abjad.tweak(upper_abjad_chord.note_heads[i]
                                        ).style = 'harmonic'
                    upper_staff_components.append(upper_abjad_chord)
Ejemplo n.º 38
0
# rh

maker(
    'rh',
    baca.alternate_bow_strokes(),
    baca.chunk(
        baca.bar_extent_persistent((-4, 4)),
        baca.literal([
            r'\once \override RHStaff.StaffSymbol.line-positions ='
            " #'(8.2 8 7.8 -5.8 -6 -6.2)"
            ]),
        baca.staff_lines(7),
        ),
    baca.dynamic(
        'mp-sempre',
        abjad.tweak(-0.9).self_alignment_X,
        ),
    baca.literal(r'\override DynamicLineSpanner.staff-padding = 2.5'),
    baca.literal(r'\override Score.BarNumber.transparent = ##t'),
    baca.markup(
        r'\huitzil-directly-on-bridge-markup',
        abjad.tweak(3).staff_padding,
        literal=True,
        ),
    baca.staff_position(8),
    baca.tuplet_bracket_down(),
    )

maker(
    ('rh', (1, 4)),
    baca.rest_position(0),
Ejemplo n.º 39
0
        baca.bar_line_transparent(),
        baca.span_bar_transparent(),
        selector=baca.leaves(),
        ),
    baca.pitch(
        'A1',
        selector=baca.leaves().rleak()[-1],
        ),
    baca.time_signature_stencil_false(),
    )

maker(
    ('vc', 1),
    baca.markup(
        baca.markups.string_number(3),
        abjad.tweak(2.5).padding,
        direction=abjad.Down,
        ),
    baca.pitch('A2'),
    baca.rhythm("{ c'1 * 1/4 }"),
    )

maker(
    ('vc', (14, 24)),
    baca.rhythm("{ c'1 * 19/8 }"),
    baca.suite(
        baca.pitch('A2'),
        baca.repeat_tie_to(),
        ),
    )
Ejemplo n.º 40
0
maker(
    'Global_Skips',
    baca.metronome_mark(
        '78',
        selector=baca.leaf(1 - 1),
        ),
    )

# vc

maker(
    ('vc', 1),
    baca.markup(
        r'\huitzil-phrasing-dynamics-see-preface-markup',
        abjad.tweak(9).staff_padding,
        direction=abjad.Down,
        literal=True,
        ),
    baca.rhythm(music_),
    )

maker(
    ('vc', (1, 51)),
    baca.tuplet_bracket_staff_padding(3),
    )

maker(
    ('vc', 8),
    baca.suite(
        baca.untie_to(
Ejemplo n.º 41
0
    )

# vcr

maker(
    ('vcr', [1, 15]),
    baca.mmrest_transparent(),
    )

# rh

maker(
    'rh',
    baca.only_score(
        baca.breathe(
            abjad.tweak(False).X_extent,
            abjad.tweak((0, 5)).extra_offset,
            ),
        ),
    baca.only_segment(
        baca.breathe(
            abjad.tweak(False).X_extent,
            abjad.tweak((-1.5, 2)).extra_offset,
            ),
        ),
    baca.only_segment(
        baca.chunk(
            baca.literal(r'\override DynamicLineSpanner.staff-padding = 7'),
            baca.literal([
                r'\stopStaff',
                r'\once \override RHStaff.StaffSymbol.line-positions ='
Ejemplo n.º 42
0
    )

maker(
    ('rh', (1, 3)),
    # FUTURE: use this once LilyPond fixes DynamicLineSpanner bug:
    #baca.hairpin(
    #    'mp -- !',
    #    abjad.tweak(True).to_barline,
    #    selector=baca.leaves().rleak(),
    #    ),
    # FUTURE: replace this once LilyPond fixes DynamicLineSpanner bug:
    baca.chunk(
        baca.dynamic('mp'),
        baca.hairpin(
            'mp -- !',
            abjad.tweak(True).to_barline,
            selector=baca.leaves()[1:].rleak(),
            ),
        ),
    baca.markup(
        r'\baca-mfz-markup',
        direction=abjad.Down,
        literal=True,
        selector=baca.leaves(),
        ),
    )

maker(
    ('rh', 2),
    baca.make_monads('1/4  1/8  1/6'),
    baca.staff_positions(
Ejemplo n.º 43
0
    )

maker(
    ('rh', 18),
    # TODO: make +ARCH_A_SCORE work
    baca.only_score(
        baca.hairpin_to_barline(),
        ),
    )

maker(
    ('rh', (18, 23)),
    baca.text_spanner(
        '(trem. mod.) => stretto => largo => stretto =>'
            ' largo => stretto =>',
        abjad.tweak(6).staff_padding,
        bookend=False,
        pieces=baca.lparts([1, 1, 1, 1, 1, 1 + 1]),
        right_broken=True,
        selector=baca.leaves().rleak(),
        ),
    )

maker(
    ('rh', (18, 23)),
    baca.make_monads('1/2  1/2  1/2  1/2  1/2  1/2'),
    baca.markup(
        r'\baca-ffz-markup',
        direction=abjad.Down,
        literal=True,
        ),
Ejemplo n.º 44
0
maker(
    ('vc', (7, 19)),
    baca.pitch('A1'),
    )

maker(
    (['vn', 'va', 'vc'], (7, 19)),
    baca.dynamic('fff'),
    baca.markup('gridato possibile'),
    )

maker(
    ('vn', (11, 15)),
    baca.text_spanner(
        'grid. possibile => flaut. possibile',
        abjad.tweak(5).staff_padding,
        ),
    )

maker(
    (['va', 'vc'], (13, 15)),
    baca.text_spanner(
        'grid. possibile => flaut. possibile',
        abjad.tweak(5).staff_padding,
        ),
    )

maker(
    ('perc', (19, 22)),
    baca.dynamic('p-sempre'),
    baca.laissez_vibrer(