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