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