Affichage de la généalogie d’un objet

Lorsque l’on manipule des rappels d’objet (grob callbacks), il peut être intéressant d’en maîtriser les ascendants. La plupart des objets graphiques ont des parents, lesquels auront une influence sur le positionnement de l’objet en question. Ainsi, les parents des côtés X et Y influenceront respectivement les positions horizontale et verticale de l’objet. De plus, chacun des parents peut avoir ses propres parents.

Certains aspects de la lignée d’un objet peuvent toutefois porter à confusion :

Par exemple, l’objet System peut, vis à vis d’un objet VerticalAlignment, être à la fois parent (par son côté Y) et grand parent (par deux fois du côté X).

La macro ci-dessous affiche à l’écran une représentation textuelle de l’ascendance d’un grob.

Elle se lance ainsi :

{ \once \override NoteHead.before-line-breaking = #display-ancestry c }

et génère la sortie suivante :

NoteHead
X,Y: NoteColumn
     X: PaperColumn
        X,Y: System
     Y: VerticalAxisGroup
        X: NonMusicalPaperColumn
           X,Y: System
        Y: VerticalAlignment
           X: NonMusicalPaperColumn
              X,Y: System
           Y: System
%% http://lsr.di.unimi.it/LSR/Item?id=622

#(define (get-ancestry grob)
  (if (not (null? (ly:grob-parent grob X)))
      (list (grob::name grob)
            (get-ancestry (ly:grob-parent grob X))
            (get-ancestry (ly:grob-parent grob Y)))
      (grob::name grob)))

#(define (format-ancestry lst padding)
   (string-append
    (symbol->string (car lst))
    "\n"
    (let ((X-ancestry
           (if (list? (cadr lst))
               (format-ancestry (cadr lst) (+ padding 3))
               (symbol->string (cadr lst))))
          (Y-ancestry
           (if (list? (caddr lst))
               (format-ancestry (caddr lst) (+ padding 3))
               (symbol->string (caddr lst)))))
      (if (equal? X-ancestry Y-ancestry)
          (string-append
           (format #f "~&")
           (make-string padding #\space)
           "X,Y: "
           (if (list? (cadr lst))
               (format-ancestry (cadr lst) (+ padding 5))
               (symbol->string (cadr lst))))
          (string-append
           (format #f "~&")
           (make-string padding #\space)
           "X: " X-ancestry
           "\n"
           (make-string padding #\space)
           "Y: " Y-ancestry
           (format #f "~&"))))
    (format #f "~&")))

#(define (display-ancestry grob)
   (format (current-error-port)
      "~3&~a~2%~a~&"
      (make-string 36 #\-)
      (if (ly:grob? grob)
          (format-ancestry (get-ancestry grob) 0)
          (format #f "~a is not a grob" grob))))

\relative c' {
  \once \override NoteHead.before-line-breaking = #display-ancestry
  f4
  \once \override Accidental.before-line-breaking = #display-ancestry
  \once \override Arpeggio.before-line-breaking = #display-ancestry
  <f as c>4\arpeggio
}

[image of music]


LilyPond snippets v2.25.15 (branche de développement).