lilypond-user
[Top][All Lists]
Advanced

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

Re: How to really center a text above a note?


From: Mark Polesky
Subject: Re: How to really center a text above a note?
Date: Sun, 5 Jul 2009 10:06:34 -0700 (PDT)

Valentin Villenave wrote:
> 2009/6/29 Neil Puttock :
> > With apologies to Michael, here's a simpler method for centring
> > text using a grob callback, which effectively does the same as
> > your old code by retrieving the notehead (or rest) from the
> > PaperColumn then mimicking the centered_on_x_parent callback:
>
> Although I've been (shamefully) away from the LSR for the past
> few weeks, I can't help but thinking this could make a valuable
> snippet...

If the "unsafe assumption" on line 8 could be addressed, I think it
should be implemented in the source. Neil?
- Mark

Here it is again:

textScriptCenterOnParent = \override TextScript #'X-offset =
#(lambda (grob)
   (let* (
          ;; get parent in X axis (a PaperColumn)
          (paper-col (ly:grob-parent grob X))
          ;; extract array of grobs attached to this column
          (elts (ly:grob-object paper-col 'elements))
          ;; could be an unsafe assumption, but the first
          ;; element should be a NoteHead or Rest
          (rhythmic-head (ly:grob-array-ref elts 0)))

     (+
      ;; read self-alignment-X
      (ly:self-alignment-interface::x-aligned-on-self grob)
      ;; equivalent to ly:self-alignment-interface::centered-on-x-parent,
      ;; but using the extracted notehead/rest instead of the paper column
      (interval-center
       (ly:grob-robust-relative-extent rhythmic-head rhythmic-head X)))))



      




reply via email to

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