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.10
8 lsrtags = "tweaks-and-overrides"
11 When working with grob callbacks, it can be helpful to understand a
12 grob's @qq{ancestry}. Most grobs have @qq{parents} which influence the
13 positioning of the grob. X- and Y-parents influence the horizontal and
14 vertical positions for the grob, respectively. Additionally, each
15 parent may have parents of its own.
18 Unfortunately, there are several aspects of a grob's ancestry that can
25 The types of parents a grob has may depend on context.
28 For some grobs, the X- and Y-parents are the same.
31 A particular @qq{ancestor} may be related to a grob in multiple ways.
34 The concept of @qq{generations} is misleading.
39 For example, the @code{System} grob can be both parent (on the Y-side)
40 and grandparent (twice on the X-side) to a @code{VerticalAlignment}
44 This macro prints (to the console) a textual representation of a grob's
52 \\once \\override NoteHead #'before-line-breaking = #display-ancestry
58 The following output is generated:
62 ------------------------------------
64 NoteHead X,Y: NoteColumn
68 X: NonMusicalPaperColumn
71 X: NonMusicalPaperColumn
78 doctitle = "Displaying grob ancestry"
82 #(define (grob-name grob)
84 (assoc-ref (ly:grob-property grob 'meta) 'name)
87 #(define (get-ancestry grob)
88 (if (not (null? (ly:grob-parent grob X)))
89 (list (grob-name grob)
90 (get-ancestry (ly:grob-parent grob X))
91 (get-ancestry (ly:grob-parent grob Y)))
94 #(define (format-ancestry lst padding)
96 (symbol->string (car lst))
99 (if (list? (cadr lst))
100 (format-ancestry (cadr lst) (+ padding 3))
101 (symbol->string (cadr lst))))
103 (if (list? (caddr lst))
104 (format-ancestry (caddr lst) (+ padding 3))
105 (symbol->string (caddr lst)))))
106 (if (equal? X-ancestry Y-ancestry)
109 (make-string padding #\space)
111 (if (list? (cadr lst))
112 (format-ancestry (cadr lst) (+ padding 5))
113 (symbol->string (cadr lst))))
116 (make-string padding #\space)
119 (make-string padding #\space)
124 #(define (display-ancestry grob)
127 (format #f "~3&~a~2%" (make-string 36 #\-))
128 (format-ancestry (get-ancestry grob) 0)
132 \once \override NoteHead #'before-line-breaking = #display-ancestry
134 \once \override Accidental #'before-line-breaking = #display-ancestry
135 \once \override Arpeggio #'before-line-breaking = #display-ancestry