]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/using-ly-grob-object-to-access-grobs-with--tweak.ly
LSR updates from tarball - July 2012
[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: b482c3e5b56c3841a88d957e0ca12964bd3e64fa
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 %% Translation of GIT committish: d5307870fe0ad47904daba73792c7e17b813737f
53   texidocfr = "
54 Certains objets graphiques ne sont accessibles que par le biais d'un
55 @emph{callback} à partir d'un autre @code{grob}.  Ils sont normalement
56 listés dans les « @emph{layout objects} » au sein de la section
57 « Propriétés internes » d'une @emph{grob-interface}.  La fonction
58 @code{ly:grob-object} permet d'accéder à ces objets.
59
60 Voici plusieurs moyens d'accéder aux objets par un @emph{callback} sur
61 @code{NoteHead}.  D'autres biais sont naturellement possible ;
62 @code{NoteHead} a cependant l'avantage incontestable d'être utilisé
63 implicitement par la commande @code{\\tweak}.
64
65 La fonction @code{display-grobs} définie ci-dessous n'est probablement
66 pas très utile.  Elle indique toutefois qu'il est tout à fait possible
67 d'accéder aux objets.
68
69 Voici par exemple ce qui sera émis dans la console :
70
71 @example
72 --------------------
73 #<Grob Accidental >
74 #<Grob Arpeggio >
75 #<Grob Stem >
76 @end example
77
78 "
79   doctitlefr = "Utilisation de ly:grob-object pour accéder aux grobs avec \\tweak"
80
81   texidoc = "
82 Some grobs can be accessed @qq{laterally} from within another grob's
83 callback. These are usually listed as @qq{layout objects} in the
84 @qq{Internal properties} section of a grob-interface. The function
85 @code{ly:grob-object} is used to access these grobs.
86
87
88 Demonstrated below are some ways of accessing grobs from within a
89 NoteHead callback, but the technique is not limited to NoteHeads.
90 However, the NoteHead callback is particularly important, since it is
91 the implicit callback used by the @code{\\tweak} command.
92
93
94 The example function defined below (\"display-grobs\") is probably not
95 that useful, but it demonstrates that the grobs are indeed being
96 accessed.
97
98
99 Example console output:
100
101
102 -------------------- #-Grob Accidental - #-Grob Arpeggio - #-Grob Stem -
103
104
105
106 "
107   doctitle = "Using ly:grob-object to access grobs with \\tweak"
108 } % begin verbatim
109
110 #(define (notehead-get-accidental notehead)
111    ;; notehead is grob
112    (ly:grob-object notehead 'accidental-grob))
113
114 #(define (notehead-get-arpeggio notehead)
115    ;; notehead is grob
116    (let ((notecolumn (notehead-get-notecolumn notehead)))
117      (ly:grob-object notecolumn 'arpeggio)))
118
119 #(define (notehead-get-notecolumn notehead)
120    ;; notehead is grob
121    (ly:grob-parent notehead X))
122
123 #(define (notehead-get-stem notehead)
124    ;; notehead is grob
125    (let ((notecolumn (notehead-get-notecolumn notehead)))
126      (ly:grob-object notecolumn 'stem)))
127
128 #(define (display-grobs notehead)
129    ;; notehead is grob
130    (let ((accidental (notehead-get-accidental notehead))
131          (arpeggio (notehead-get-arpeggio notehead))
132          (stem (notehead-get-stem notehead)))
133      (format (current-error-port) "~2&~a\n" (make-string 20 #\-))
134      (for-each
135       (lambda (x) (format (current-error-port) "~a\n" x))
136       (list accidental arpeggio stem))))
137
138 \relative c' {
139   %% display grobs for each note head:
140   %\override NoteHead #'before-line-breaking = #display-grobs
141   <c
142   %% or just for one:
143   \tweak #'before-line-breaking #display-grobs
144   es
145   g>1\arpeggio
146 }