]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/using-ly-grob-object-to-access-grobs-with--tweak.ly
Rerun scripts/auxiliar/update-with-convert-ly.sh
[lilypond.git] / Documentation / snippets / using-ly-grob-object-to-access-grobs-with--tweak.ly
1 %% DO NOT EDIT this file manually; it is automatically
2 %% generated from LSR http://lsr.dsi.unimi.it
3 %% Make any changes in LSR itself, or in Documentation/snippets/new/ ,
4 %% and then run scripts/auxiliar/makelsr.py
5 %%
6 %% This file is in the public domain.
7 \version "2.17.6"
8
9 \header {
10   lsrtags = "devel, scheme-language, tweaks-and-overrides"
11
12   texidoc = "
13 Some grobs can be accessed @qq{laterally} from within another grob's
14 callback. These are usually listed as @qq{layout objects} in the
15 @qq{Internal properties} section of a grob-interface. The function
16 @code{ly:grob-object} is used to access these grobs.
17
18
19 Demonstrated below are some ways of accessing grobs from within a
20 NoteHead callback, but the technique is not limited to NoteHeads.
21 However, the NoteHead callback is particularly important, since it is
22 the implicit callback used by the @code{\\tweak} command.
23
24
25 The example function defined below (\"display-grobs\") is probably not
26 that useful, but it demonstrates that the grobs are indeed being
27 accessed.
28
29
30 Example console output:
31
32
33 -------------------- #-Grob Accidental - #-Grob Arpeggio - #-Grob Stem -
34
35
36
37 "
38   doctitle = "Using ly:grob-object to access grobs with \\tweak"
39 } % begin verbatim
40
41 #(define (notehead-get-accidental notehead)
42    ;; notehead is grob
43    (ly:grob-object notehead 'accidental-grob))
44
45 #(define (notehead-get-arpeggio notehead)
46    ;; notehead is grob
47    (let ((notecolumn (notehead-get-notecolumn notehead)))
48      (ly:grob-object notecolumn 'arpeggio)))
49
50 #(define (notehead-get-notecolumn notehead)
51    ;; notehead is grob
52    (ly:grob-parent notehead X))
53
54 #(define (notehead-get-stem notehead)
55    ;; notehead is grob
56    (let ((notecolumn (notehead-get-notecolumn notehead)))
57      (ly:grob-object notecolumn 'stem)))
58
59 #(define (display-grobs notehead)
60    ;; notehead is grob
61    (let ((accidental (notehead-get-accidental notehead))
62          (arpeggio (notehead-get-arpeggio notehead))
63          (stem (notehead-get-stem notehead)))
64      (format (current-error-port) "~2&~a\n" (make-string 20 #\-))
65      (for-each
66       (lambda (x) (format (current-error-port) "~a\n" x))
67       (list accidental arpeggio stem))))
68
69 \relative c' {
70   %% display grobs for each note head:
71   %\override NoteHead.before-line-breaking = #display-grobs
72   <c
73   %% or just for one:
74   \tweak before-line-breaking #display-grobs
75   es
76   g>1\arpeggio
77 }