10.04.2013 Views

in Snippets - LilyPond

in Snippets - LilyPond

in Snippets - LilyPond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Tweaks and overrides 454<br />

3<br />

<br />

<br />

<br />

<br />

4 <br />

2<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

Us<strong>in</strong>g ly:grob-object to access grobs with \tweak<br />

Some grobs can be accessed “laterally” from with<strong>in</strong> another grob’s callback. These are usually<br />

listed as “layout objects” <strong>in</strong> the “Internal properties” section of a grob-<strong>in</strong>terface. The function<br />

ly:grob-object is used to access these grobs.<br />

Demonstrated below are some ways of access<strong>in</strong>g grobs from with<strong>in</strong> a NoteHead callback,<br />

but the technique is not limited to NoteHeads. However, the NoteHead callback is particularly<br />

important, s<strong>in</strong>ce it is the implicit callback used by the \tweak command.<br />

The example function def<strong>in</strong>ed below ("display-grobs") is probably not that useful, but it<br />

demonstrates that the grobs are <strong>in</strong>deed be<strong>in</strong>g accessed.<br />

Example console output:<br />

——————– #-Grob Accidental - #-Grob Arpeggio - #-Grob Stem -<br />

#(def<strong>in</strong>e (notehead-get-accidental notehead)<br />

;; notehead is grob<br />

(ly:grob-object notehead 'accidental-grob))<br />

#(def<strong>in</strong>e (notehead-get-arpeggio notehead)<br />

;; notehead is grob<br />

(let ((notecolumn (notehead-get-notecolumn notehead)))<br />

(ly:grob-object notecolumn 'arpeggio)))<br />

#(def<strong>in</strong>e (notehead-get-notecolumn notehead)<br />

;; notehead is grob<br />

(ly:grob-parent notehead X))<br />

#(def<strong>in</strong>e (notehead-get-stem notehead)<br />

;; notehead is grob<br />

(let ((notecolumn (notehead-get-notecolumn notehead)))<br />

(ly:grob-object notecolumn 'stem)))<br />

#(def<strong>in</strong>e (display-grobs notehead)<br />

;; notehead is grob<br />

(let ((accidental (notehead-get-accidental notehead))<br />

(arpeggio (notehead-get-arpeggio notehead))<br />

(stem (notehead-get-stem notehead)))<br />

(format (current-error-port) "~2&~a\n" (make-str<strong>in</strong>g 20 #\-))<br />

(for-each<br />

(lambda (x) (format (current-error-port) "~a\n" x))<br />

(list accidental arpeggio stem))))<br />

\relative c' {<br />

%% display grobs for each note head:<br />

%\override NoteHead #'before-l<strong>in</strong>e-break<strong>in</strong>g = #display-grobs<br />

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

Saved successfully!

Ooh no, something went wrong!