Abjad / abjad

Abjad is a Python API for building LilyPond files. Use Abjad to make PDFs of music notation.
https://abjad.github.io
GNU General Public License v3.0
234 stars 41 forks source link

Fix duplicate dynamics corner case #1553

Closed trevorbaca closed 11 months ago

trevorbaca commented 11 months ago

This behavior is good:

voice = abjad.Voice("c'4")
dynamic = abjad.Dynamic("p")
abjad.attach(dynamic, voice[0])
abjad.attach(abjad.Dynamic("f"), voice[0])
string = abjad.lilypond(voice)
print(string)
Traceback (most recent call last):
    ...
abjad.exceptions.PersistentIndicatorError: attempting to attach conflicting indicator to Note:
  Already attached:
    Dynamic(name='p', command=None, format_hairpin_stop=False, hide=False, leak=False, name_is_textual=False, ordinal=-2)
  Attempting to attach:
    Dynamic(name='f', command=None, format_hairpin_stop=False, hide=False, leak=False, name_is_textual=False, ordinal=2)

This behavior is a bug:

voice = abjad.Voice("c'4")
bundle = abjad.bundle(
    abjad.Dynamic("p"),
    abjad.Tweak(r"- \tweak color #red"),
)
abjad.attach(bundle, voice[0])
abjad.attach(abjad.Dynamic("f"), voice[0])
string = abjad.lilypond(voice)
print(string)
\new Voice
{
    c'4
    - \tweak color #red
    \p
    \f
}