def test_pad_voices_with_grace_skips_03():
    voice_0 = abjad.Voice(r"{ \times 4/5 { c'4 c'4 c'4 c'4 c'4 } }")
    voice_1 = abjad.Voice(r"{ \times 4/6 { c'4 c'4 c'4 c'4 c'4 c'4 } }")
    container = abjad.BeforeGraceContainer("cs'16")
    abjad.attach(container, abjad.get.leaf(voice_0, 0))
    container = abjad.BeforeGraceContainer("ds'16")
    abjad.attach(container, abjad.get.leaf(voice_1, 0))
    pang.pad_voices_with_grace_skips([voice_0, voice_1])

    string = abjad.lilypond(voice_0)
    assert string == abjad.String.normalize(r"""
        \new Voice
        {
            {
                \times 4/5
                {
                    \grace {
                        cs'16
                    }
                    c'4
                    c'4
                    c'4
                    c'4
                    c'4
                }
            }
        }
        """), print(string)

    string = abjad.lilypond(voice_1)
    assert string == abjad.String.normalize(r"""
        \new Voice
        {
            {
                \times 4/6
                {
                    \grace {
                        ds'16 * 6/5
                    }
                    c'4
                    c'4
                    c'4
                    c'4
                    c'4
                    c'4
                }
            }
        }
        """), print(string)
示例#2
0
def test_Note___copy___05():
    """
    Deepcopy orphan note.
    """

    note = abjad.Note("c'4")
    articulation = abjad.Articulation("staccato")
    abjad.attach(articulation, note)
    grace = abjad.BeforeGraceContainer("d'16")
    abjad.attach(grace, note)
    abjad.override(note).NoteHead.color = "#red"

    assert abjad.lilypond(note) == abjad.String.normalize(r"""
        \grace {
            d'16
        }
        \once \override NoteHead.color = #red
        c'4
        - \staccato
        """)

    new_note = copy.deepcopy(note)

    assert new_note is not note
    assert abjad.lilypond(new_note) == abjad.lilypond(note)
def test_mutate__split_leaf_by_durations_09():
    """
    Grace notes are removed from second split leaf.
    """

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

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

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

    abjad.wf.wellformed(staff)
示例#4
0
 def card_13():
     notes = [abjad.Note("F5", (3, 16)) for _ in range(2)]
     notes.append(blank_space())
     grace = abjad.BeforeGraceContainer([abjad.Note("E4", (1, 8))],
                                        command=r"\acciaccatura")
     abjad.attach(grace, notes[0])
     return notes
    def __call__(self, q_events):
        """
        Calls concatenating grace handler.
        """
        import abjadext.nauert

        grace_events, final_event = q_events[:-1], q_events[-1]

        if isinstance(final_event, abjadext.nauert.PitchedQEvent):
            pitches = final_event.pitches
        else:
            pitches = ()

        if grace_events:
            grace_container = abjad.BeforeGraceContainer()
            for q_event in grace_events:
                if isinstance(q_event, abjadext.nauert.PitchedQEvent):
                    if len(q_event.pitches) == 1:
                        leaf = abjad.Note(q_event.pitches[0],
                                          self.grace_duration)
                    else:
                        leaf = abjad.Chord(q_event.pitches,
                                           self.grace_duration)
                else:
                    leaf = abjad.Rest(self.grace_duration)
                grace_container.append(leaf)
        else:
            grace_container = None

        return pitches, grace_container
def test_mutate__fuse_leaves_by_immediate_parent_05():
    """
    Fuse leaves in logical tie with same immediate parent.
    """

    voice = abjad.Voice(r"c'16 ~ c'16 ~ c'16 ~ c'16 ~ c'16 r16 r16 r16 r4 r4")
    abjad.attach(abjad.BeforeGraceContainer("b'16"), voice[0])
    logical_tie = abjad.get.logical_tie(voice[0])
    result = abjad.mutate._fuse_leaves_by_immediate_parent(logical_tie)

    assert abjad.lilypond(voice) == abjad.String.normalize(
        r"""
        \new Voice
        {
            \grace {
                b'16
            }
            c'4
            ~
            c'16
            r16
            r16
            r16
            r4
            r4
        }
        """
    ), print(abjad.lilypond(voice))

    assert abjad.wf.wellformed(voice)
    assert len(result) == 1
def test_Meter_rewrite_meter_01():
    string = "| 4/4 c'4 c'8 c'4 c'4 c'8 |"
    container = abjad.parsers.reduced.parse_reduced_ly_syntax(string)
    staff = abjad.Staff()
    staff[:] = container
    grace_container = abjad.BeforeGraceContainer("c'16 d'16")
    abjad.attach(grace_container, staff[1])
    meter = abjad.Meter((4, 4))
    abjad.Meter.rewrite_meter(staff[:], meter)
    string = abjad.lilypond(staff)
    assert string == abjad.String.normalize(
        r"""
        \new Staff
        {
            \time 4/4
            c'4
            \grace {
                c'16
                d'16
            }
            c'8
            c'8
            ~
            c'8
            c'8
            ~
            c'8
            c'8
        }
        """
    ), print(string)
def test_LilyPondParser__functions__grace_01():

    target = abjad.Container(
        [abjad.Note("c'4"),
         abjad.Note("d'4"),
         abjad.Note("e'2")])

    grace = abjad.BeforeGraceContainer(
        [abjad.Note("g''16"), abjad.Note("fs''16")])

    abjad.attach(grace, target[2])

    assert abjad.lilypond(target) == abjad.String.normalize(r"""
        {
            c'4
            d'4
            \grace {
                g''16
                fs''16
            }
            e'2
        }
        """)

    string = r"{ c'4 d'4 \grace { g''16 fs''16} e'2 }"
    parser = abjad.parser.LilyPondParser()
    result = parser(string)
    assert abjad.lilypond(target) == abjad.lilypond(
        result) and target is not result
示例#9
0
def pad_voices_with_grace_skips(voices):
    """
    Pad voices with grace skips to fix the spacing issue with full-length
    tuplet brackets.
    """
    longest_durations = _get_longest_durations(voices)
    for voice in voices:
        for measure_number in longest_durations:
            first_leaf = abjad.get.leaf(voice[measure_number], 0)
            multiplier = _get_tuplet_multiplier(first_leaf)
            stored_duration, stored_multiplier = longest_durations[
                measure_number]
            if abjad.get.grace(first_leaf):
                container = abjad.get.parentage(first_leaf).parent
                assert isinstance(container, abjad.BeforeGraceContainer)
                duration = abjad.get.duration(container)
                if duration < stored_duration:
                    container.insert(0, abjad.Skip(stored_duration - duration))
                if multiplier != stored_multiplier:
                    multiplier = stored_multiplier / multiplier
                    multiplier = multiplier.reduce()
                    if multiplier != 1:
                        for leaf in container:
                            leaf.multiplier = multiplier
            else:
                multiplier = stored_multiplier / multiplier
                multiplier = multiplier.reduce()
                if multiplier == 1:
                    skip = abjad.Skip(stored_duration)
                else:
                    skip = abjad.Skip(stored_duration, multiplier=multiplier)
                container = abjad.BeforeGraceContainer([skip])
                abjad.attach(container, first_leaf)
示例#10
0
def test_Container_append_06():
    """
    Can not insert grace container into container.
    """

    staff = abjad.Staff("c' d' e'")
    grace_container = abjad.BeforeGraceContainer("f'16 g'")

    with pytest.raises(Exception):
        staff.append(grace_container)
示例#11
0
    def __call__(
        self, q_events: typing.Sequence[QEvent]
    ) -> tuple[
        tuple[abjad.NamedPitch, ...],
        typing.Optional[tuple],
        typing.Optional[abjad.BeforeGraceContainer],
    ]:
        """
        Calls concatenating grace handler.
        """
        grace_events, final_event = q_events[:-1], q_events[-1]
        attachments: tuple | None
        if grace_events and self._replace_rest_with_final_grace_note:
            index = self._find_last_pitched_q_event(q_events)
            grace_events, final_event = q_events[:index], q_events[index]

        if isinstance(final_event, PitchedQEvent):
            # TODO: we are only supporting preserving attachments for PitchedQEvent
            pitches = final_event.pitches
            attachments = final_event.attachments
        else:
            pitches = ()
            attachments = None

        grace_events_list = list(grace_events)
        if self._discard_grace_rest:
            for q_event in grace_events_list:
                if isinstance(q_event, SilentQEvent):
                    grace_events_list.remove(q_event)
        grace_events = tuple(grace_events_list)

        grace_container: abjad.BeforeGraceContainer | None
        if grace_events:
            grace_container = abjad.BeforeGraceContainer()
            for q_event in grace_events:
                leaf: abjad.Leaf
                if isinstance(q_event, PitchedQEvent):
                    if len(q_event.pitches) == 1:
                        leaf = abjad.Note(q_event.pitches[0], self.grace_duration)
                    else:
                        leaf = abjad.Chord(q_event.pitches, self.grace_duration)
                else:
                    leaf = abjad.Rest(self.grace_duration)
                q_event_attachments = (
                    None if not hasattr(q_event, "attachments") else q_event.attachments
                )
                # assert hasattr(q_event, "attachments")
                # q_event_attachments = q_event.attachments
                if q_event_attachments is not None:
                    abjad.annotate(leaf, "q_event_attachments", q_event_attachments)
                grace_container.append(leaf)
        else:
            grace_container = None

        return tuple(pitches), attachments, grace_container
示例#12
0
    def __init__(self,
                 abjad_notes: tuple,
                 add_glissando: bool = False) -> None:
        self.abjad = abjad.BeforeGraceContainer(abjad_notes)

        if add_glissando:
            for item in self.abjad:
                abjad.attach(abjad.GlissandoIndicator(), item)
            self._set_glissando_layout(self.abjad,
                                       thickness=2,
                                       minimum_length=2.85)

        self._attach_grace_not_style(self.abjad)
        self.add_glissando = add_glissando
def test_mutate__fuse_leaves_by_immediate_parent_09():
    """
    Fuse leaves in logical tie with same immediate parent, with an indicator at
    the end of the logical tie after fusing.
    """

    staff = abjad.Staff(r"d'8 c'8 ~ c'32 r16 r16 r16 r4")

    indicators = (abjad.TimeSignature((3, 4)), abjad.StartBeam())
    for indicator in indicators:
        abjad.attach(indicator, staff[0])

    indicators = (
        abjad.BeforeGraceContainer("b'16"),
        abjad.Articulation("staccato"),
        abjad.Articulation("accent"),
        abjad.StopBeam(),
    )
    for indicator in indicators:
        abjad.attach(indicator, staff[1])

    logical_tie = abjad.get.logical_tie(staff[1])
    result = abjad.mutate._fuse_leaves_by_immediate_parent(logical_tie)

    assert abjad.lilypond(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            \time 3/4
            d'8
            [
            \grace {
                b'16
            }
            c'8
            - \staccato
            - \accent
            ~
            c'32
            ]
            r16
            r16
            r16
            r4
        }
        """
    ), print(abjad.lilypond(staff))

    assert abjad.wf.wellformed(staff)
    assert len(result) == 1
def test_mutate__fuse_leaves_by_immediate_parent_10():
    """
    Fuse leaves in logical tie with same immediate parent, with an indicator at
    every leaf of the logical tie after fusing.
    """

    staff = abjad.Staff(r"c'16 ~ c'16 ~ c'16 ~ c'16 ~ c'16 r16 r16 r16 r4 r4")
    indicators = (
        abjad.BeforeGraceContainer("b'16"),
        abjad.Clef("alto"),
        abjad.TimeSignature((3, 4)),
        abjad.Articulation("staccato"),
        abjad.Articulation("accent"),
        abjad.StemTremolo(16),
    )
    for indicator in indicators:
        abjad.attach(indicator, staff[0])
    logical_tie = abjad.get.logical_tie(staff[0])
    result = abjad.mutate._fuse_leaves_by_immediate_parent(logical_tie)

    assert abjad.lilypond(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            \grace {
                b'16
            }
            \time 3/4
            \clef "alto"
            c'4
            :16
            - \staccato
            - \accent
            ~
            c'16
            :16
            r16
            r16
            r16
            r4
            r4
        }
        """
    ), print(abjad.lilypond(staff))

    assert abjad.wf.wellformed(staff)
    assert len(result) == 1
示例#15
0
def test_Note___copy___06():
    """
    Deepcopy note in score.
    """

    staff = abjad.Staff("c'8 [ c'8 e'8 f'8 ]")
    note = staff[0]
    articulation = abjad.Articulation("staccato")
    abjad.attach(articulation, note)
    grace = abjad.BeforeGraceContainer("d'16")
    abjad.attach(grace, note)
    abjad.override(note).note_head.color = "red"

    assert abjad.lilypond(staff) == abjad.String.normalize(
        r"""
        \new Staff
        {
            \grace {
                d'16
            }
            \once \override NoteHead.color = #red
            c'8
            - \staccato
            [
            c'8
            e'8
            f'8
            ]
        }
        """
    )

    new_note = copy.deepcopy(note)

    assert new_note is not note
    assert abjad.get.parentage(note).parent is staff
    assert abjad.get.parentage(new_note).parent is not staff
    assert isinstance(abjad.get.parentage(new_note).parent, abjad.Staff)
    assert abjad.lilypond(new_note) == abjad.lilypond(note)
    assert abjad.lilypond(abjad.get.parentage(note).parent) == abjad.lilypond(
        abjad.get.parentage(new_note).parent
    )
示例#16
0
mats.delete(
    lambda _: muda.leaves(_)[:4],
    material_name="matD_2",
    replace_with_skips=True,
)
mats.delete(
    muda.leaf_1,
    material_name="matF",
    replace_with_skips=True,
)

# print(abjad.lilypond(mats.container))
# ATTACH

mats.attach(
    argument=abjad.BeforeGraceContainer("b'8"),
    select=muda.leaf_2,
    material_name="matH",
)

# LITERALS
literal00 = [
    r"\override Score.BarLine.stencil = ##f",
    r"\override Staff.NoteHead.no-ledgers = ##t",
    r"\override Staff.StaffSymbol.line-count = 1",
    r"\omit Clef",
]

# # when material_name is None, it attaches to ``mats.container`` leaves,
# # pitched or not.
mats.attach(literal00, muda.leaf_0)  # literal  # leaf