LilyPond comments
=================

LilyPond comments begin with the ``%`` sign.
Abjad models LilyPond comments as marks.


Creating LilyPond comments
--------------------------

Use ``marktools`` to create LilyPond comments:

<abjad>
comment_1 = marktools.LilyPondComment('This is a LilyPond comment before a note.', 'before')
</abjad>

<abjad>
comment_1
print repr(comment_1) <hide
</abjad>


Attaching LilyPond comments to leaves
-------------------------------------

Attach LilyPond comments to a note, rest or chord with ``attach()``:

<abjad>
note = Note("cs''4")
show(note)
iotools.write_expr_to_ly(note, 'lilypond-comments-1', 'oedo') <hide
</abjad>

<abjad>
comment_1.attach(note)
</abjad>

<abjad>
f(note)
</abjad>

You can add LilyPond comments before, after or to the right of any leaf.


Attaching LilyPond comments to containers
-----------------------------------------

Use ``attach()`` to attach LilyPond comments to a container:

<abjad>
staff = Staff("c'8 d'8 e'8 f'8")
show(staff)
iotools.write_expr_to_ly(staff, 'lilypond-comments-2', 'oedo') <hide
</abjad>

<abjad>
staff_comment_1 = marktools.LilyPondComment('Here is a LilyPond comment before the staff.', 'before')
staff_comment_2 = marktools.LilyPondComment('Here is a LilyPond comment in the staff opening.', 'opening')
staff_comment_3 = marktools.LilyPondComment('Here is another LilyPond comment in the staff opening.', 'opening')
staff_comment_4 = marktools.LilyPondComment('LilyPond comment in the staff closing.', 'closing')
staff_comment_5 = marktools.LilyPondComment('LilyPond comment after the staff.', 'after')
</abjad>

<abjad>
staff_comment_1.attach(staff)
staff_comment_2.attach(staff)
staff_comment_3.attach(staff)
staff_comment_4.attach(staff)
staff_comment_5.attach(staff)
</abjad>

<abjad>
f(staff)
</abjad>

You can add LilyPond comments before, after, in the opening or in the closing of any container.


Getting the LilyPond comments attached to a component
-----------------------------------------------------

Use ``marktools`` to get all the LilyPond comments attached to a component:

<abjad>
marktools.get_lilypond_comments_attached_to_component(note)
print repr(marktools.get_lilypond_comments_attached_to_component(note)) <hide
</abjad>

Abjad returns a tuple of zero or more LilyPond comments.


Detaching LilyPond comments from a component one at a time
----------------------------------------------------------

Use ``detach()`` to detach LilyPond comments from a component one at a time:

<abjad>
comment_1 = marktools.get_lilypond_comments_attached_to_component(note)[0]
</abjad>

<abjad>
comment_1.detach()
print repr(comment_1.detach()) <hide
</abjad>

<abjad>
f(note)
</abjad>


Detaching all LilyPond comments attached to a component at once
---------------------------------------------------------------

Or use ``marktools`` to detach all LilyPond comments attached to a component at once:

<abjad>
for comment in marktools.get_lilypond_comments_attached_to_component(staff): print comment
</abjad>

<abjad>
marktools.detach_lilypond_comments_attached_to_component(staff)
</abjad>

<abjad>
f(staff)
</abjad>


Inspecting the component to which a LilyPond comment is attached
----------------------------------------------------------------

Use ``start_component`` to inspect the component to which a LilyPond comment is attached:

<abjad>
comment_1.attach(note)
</abjad>

<abjad>
comment_1.start_component
print repr(comment_1.start_component) <hide
</abjad>


Inspecting contents string of a LilyPond comment
------------------------------------------------

Use ``contents_string`` to inspect the written contents of a LiliyPond comment:

<abjad>
comment_1.contents_string
print repr(comment_1.contents_string) <hide
</abjad>
