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