10.04.2013 Views

in Snippets - LilyPond

in Snippets - LilyPond

in Snippets - LilyPond

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Contexts and engravers 364<br />

}<br />

}<br />

>><br />

}<br />

}<br />

\new Staff {<br />

\once \override Staff.TimeSignature #'stencil = ##f<br />

c1 | b<br />

}<br />

>><br />

c1<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Center<strong>in</strong>g markup on note heads automatically<br />

<br />

For technical reasons, text scripts attached to note heads cannot easily be centered on a note<br />

head’s width, unlike articulations.<br />

Instead of us<strong>in</strong>g trial-and-error offset tweaks, this snippet uses a Scheme engraver to reset<br />

the horizontal parent of each markup to a NoteColumn. This also allows text to follow note<br />

heads which have been shifted via force-hshift.<br />

#(def<strong>in</strong>e (Text_align_engraver ctx)<br />

(let ((scripts '())<br />

(note-column #f))<br />

(make-engraver<br />

(acknowledgers<br />

((note-column-<strong>in</strong>terface trans grob source)<br />

;; cache NoteColumn <strong>in</strong> this Voice context<br />

(set! note-column grob))<br />

((text-script-<strong>in</strong>terface trans grob source)<br />

;; whenever a TextScript is acknowledged,<br />

;; add it to `scripts' list<br />

(set! scripts (cons grob scripts))))<br />

((stop-translation-timestep trans)<br />

;; if any TextScript grobs exist,<br />

;; set NoteColumn as X-parent<br />

(for-each (lambda (script)<br />

(set! (ly:grob-parent script X) note-column))<br />

scripts)<br />

;; clear scripts ready for next timestep<br />

(set! scripts '())))))<br />

\layout {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!