4 lsrtags = "devel, scheme-language, tweaks-and-overrides"
7 When working with grob callbacks, it can be helpful to understand a
8 grob's @qq{ancestry}. Most grobs have @qq{parents} which influence the
9 positioning of the grob. X- and Y-parents influence the horizontal and
10 vertical positions for the grob, respectively. Additionally, each
11 parent may have parents of its own.
14 Unfortunately, there are several aspects of a grob's ancestry that can
17 * The types of parents a grob has may depend on context. * For some
18 grobs, the X- and Y-parents are the same. * A particular @qq{ancestor}
19 may be related to a grob in multiple ways. * The concept of
20 @qq{generations} is misleading.
23 For example, the @code{System} grob can be both parent (on the Y-side)
24 and grandparent (twice on the X-side) to a @code{VerticalAlignment}
28 This macro prints (to the console) a textual representation of a grob's
36 \\once \\override NoteHead.before-line-breaking = #display-ancestry
40 The following output is generated:
43 ------------------------------------
45 NoteHead X,Y: NoteColumn
49 X: NonMusicalPaperColumn
52 X: NonMusicalPaperColumn
59 doctitle = "Displaying grob ancestry"
61 %% http://lsr.di.unimi.it/LSR/Item?id=622
62 %% see also http://www.lilypond.org/doc/v2.18/Documentation/snippets/tweaks-and-overrides#tweaks-and-overrides-displaying-grob-ancestry
64 #(define (grob-name grob)
66 (assoc-ref (ly:grob-property grob 'meta) 'name)
69 #(define (get-ancestry grob)
70 (if (not (null? (ly:grob-parent grob X)))
71 (list (grob-name grob)
72 (get-ancestry (ly:grob-parent grob X))
73 (get-ancestry (ly:grob-parent grob Y)))
76 #(define (format-ancestry lst padding)
78 (symbol->string (car lst))
81 (if (list? (cadr lst))
82 (format-ancestry (cadr lst) (+ padding 3))
83 (symbol->string (cadr lst))))
85 (if (list? (caddr lst))
86 (format-ancestry (caddr lst) (+ padding 3))
87 (symbol->string (caddr lst)))))
88 (if (equal? X-ancestry Y-ancestry)
91 (make-string padding #\space)
93 (if (list? (cadr lst))
94 (format-ancestry (cadr lst) (+ padding 5))
95 (symbol->string (cadr lst))))
98 (make-string padding #\space)
101 (make-string padding #\space)
106 #(define (display-ancestry grob)
107 (format (current-error-port)
110 (format-ancestry (get-ancestry grob) 0)))
113 \once \override NoteHead.before-line-breaking = #display-ancestry
115 \once \override Accidental.before-line-breaking = #display-ancestry
116 \once \override Arpeggio.before-line-breaking = #display-ancestry