4 lsrtags = "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
21 The types of parents a grob has may depend on context.
24 For some grobs, the X- and Y-parents are the same.
27 A particular @qq{ancestor} may be related to a grob in multiple ways.
30 The concept of @qq{generations} is misleading.
35 For example, the @code{System} grob can be both parent (on the Y-side)
36 and grandparent (twice on the X-side) to a @code{VerticalAlignment}
40 This macro prints (to the console) a textual representation of a grob's
48 \\once \\override NoteHead #'before-line-breaking = #display-ancestry
54 The following output is generated:
58 ------------------------------------
60 NoteHead X,Y: NoteColumn
64 X: NonMusicalPaperColumn
67 X: NonMusicalPaperColumn
74 doctitle = "Displaying grob ancestry"
77 #(define (grob-name grob)
79 (assoc-ref (ly:grob-property grob 'meta) 'name)
82 #(define (get-ancestry grob)
83 (if (not (null? (ly:grob-parent grob X)))
84 (list (grob-name grob)
85 (get-ancestry (ly:grob-parent grob X))
86 (get-ancestry (ly:grob-parent grob Y)))
89 #(define (format-ancestry lst padding)
91 (symbol->string (car lst))
94 (if (list? (cadr lst))
95 (format-ancestry (cadr lst) (+ padding 3))
96 (symbol->string (cadr lst))))
98 (if (list? (caddr lst))
99 (format-ancestry (caddr lst) (+ padding 3))
100 (symbol->string (caddr lst)))))
101 (if (equal? X-ancestry Y-ancestry)
104 (make-string padding #\space)
106 (if (list? (cadr lst))
107 (format-ancestry (cadr lst) (+ padding 5))
108 (symbol->string (cadr lst))))
111 (make-string padding #\space)
114 (make-string padding #\space)
119 #(define (display-ancestry grob)
122 (format #f "~3&~a~2%" (make-string 36 #\-))
123 (format-ancestry (get-ancestry grob) 0)
127 \once \override NoteHead #'before-line-breaking = #display-ancestry
129 \once \override Accidental #'before-line-breaking = #display-ancestry
130 \once \override Arpeggio #'before-line-breaking = #display-ancestry