]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/using-ly-grob-object-to-access-grobs-with--tweak.ly
d086c18b7d5bbfd129ac50f22671aedb0d379024
[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.36
5 \version "2.13.40"
6
7 \header {
8 %% Translation of GIT committish: 5160eccb26cee0bfd802d844233e4a8d795a1e94
9
10   texidoces = "
11
12 Se puede acceder @qq{lateralmente} a algunos grobs desde dentro de la
13 función de callback de otro grob.  Éstos se encuentran relacionados
14 normalmente como @qq{layout objects} (objetos de presentación) en la
15 sección @qq{Internal properties} (propiedades internas) de un
16 interface de grob.  Se usa la función @code{ly:grob-object} para
17 acceder a estos grobs.
18
19
20 Se presentan más abajo como ejemplo algunas formas de addecer a grobs
21 desde dentro de una función de callback de NoteHead, pero la técnica
22 no se limita a las cabezas de nota.  Sin embargo, la función de
23 callback de NoteHead es especialmente importante, porque es la función
24 de callback implícita que utiliza la instrucción @code{\\tweak}.
25
26
27 La función de ejemplo que se define abajo (\"display-grobs\") no es
28 probablemente tan útil, pero muestra que se está accediendo
29 efectivamente a los grobs.
30
31
32 Salida de ejemplo de la consola:
33
34
35 @example
36 --------------------
37 #-Grob Accidental -
38 #-Grob Arpeggio -
39 #-Grob Stem -
40 @end example
41
42
43 "
44
45   doctitlees = "Utilizar ly:grob-object para acceder a los grobs con \\tweak"
46
47
48   lsrtags = "tweaks-and-overrides"
49
50   texidoc = "
51 Some grobs can be accessed @qq{laterally} from within another grob's
52 callback.  These are usually listed as @qq{layout objects} in the
53 @qq{Internal properties} section of a grob-interface.  The function
54 @code{ly:grob-object} is used to access these grobs.
55
56
57 Demonstrated below are some ways of accessing grobs from within a
58 NoteHead callback, but the technique is not limited to NoteHeads.
59 However, the NoteHead callback is particularly important, since it is
60 the implicit callback used by the @code{\\tweak} command.
61
62
63 The example function defined below (\"display-grobs\") is probably not
64 that useful, but it demonstrates that the grobs are indeed being
65 accessed.
66
67
68 Example console output:
69
70
71 @example
72 --------------------
73 #-Grob Accidental -
74 #-Grob Arpeggio -
75 #-Grob Stem -
76 @end example
77
78
79 "
80   doctitle = "Using ly:grob-object to access grobs with \\tweak"
81 } % begin verbatim
82
83
84 #(define (notehead-get-accidental notehead)
85    ;; notehead is grob
86    (ly:grob-object notehead 'accidental-grob))
87
88 #(define (notehead-get-arpeggio notehead)
89    ;; notehead is grob
90    (let ((notecolumn (notehead-get-notecolumn notehead)))
91      (ly:grob-object notecolumn 'arpeggio)))
92
93 #(define (notehead-get-notecolumn notehead)
94    ;; notehead is grob
95    (ly:grob-parent notehead X))
96
97 #(define (notehead-get-stem notehead)
98    ;; notehead is grob
99    (let ((notecolumn (notehead-get-notecolumn notehead)))
100      (ly:grob-object notecolumn 'stem)))
101
102 #(define (display-grobs notehead)
103    ;; notehead is grob
104    (let ((accidental (notehead-get-accidental notehead))
105          (arpeggio (notehead-get-arpeggio notehead))
106          (stem (notehead-get-stem notehead)))
107      (format #t "~2&~a\n" (make-string 20 #\-))
108      (for-each
109       (lambda (x) (format #t "~a\n" x))
110       (list accidental arpeggio stem))))
111
112 \relative c' {
113   %% display grobs for each note head:
114   %\override NoteHead #'before-line-breaking = #display-grobs
115   <c
116   %% or just for one:
117   \tweak #'before-line-breaking #display-grobs
118   es
119   g>1\arpeggio
120 }