lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: visualizing grob ancestry


From: Mark Polesky
Subject: Re: visualizing grob ancestry
Date: Fri, 24 Jul 2009 00:06:43 -0700 (PDT)

Werner LEMBERG wrote:

> Very nice!  Perhaps this can be wrapped into an even more convenient
> function so that a user just have to say, for example,
> 
>   \getAncestry { }
> 
> at the place where grobs have to be manipulated.
> 
> Definitely very useful stuff!

Werner,

I reformatted the output (slightly) to minimize duplicates. Do you
prefer this version or the earlier one?

- Mark

\version "2.13.2"

#(define (grob-name grob)
  (if (ly:grob? grob)
      (assoc-ref (ly:grob-property grob 'meta) 'name)
      #f))

#(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 generation)
  (string-append
    (symbol->string (car lst))
    "\n"
    (let ((X-ancestry
            (if (list? (cadr lst))
                (format-ancestry (cadr lst) (1+ generation))
                (symbol->string (cadr lst))))
          (Y-ancestry
            (if (list? (caddr lst))
                (format-ancestry (caddr lst) (1+ generation))
                (symbol->string (caddr lst)))))
       (if (equal? X-ancestry Y-ancestry)
           (string-append
             (make-string (* generation 3) #\space)
             "X/Y: "
             (if (list? (cadr lst))
                (format-ancestry (cadr lst) (+ generation 2))
                (symbol->string (cadr lst)))
             "\n")
           (string-append
             (make-string (* generation 3) #\space)
             "X: " X-ancestry "\n"
             (make-string (* generation 3) #\space)
             "Y: " Y-ancestry "\n")))))

#(define (display-ancestry grob)
  (display
    (string-append
      (make-string 36 #\-)
      "\n"
      (format-ancestry (get-ancestry grob) 0))))

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



      




reply via email to

[Prev in Thread] Current Thread [Next in Thread]