Wilbert Berendsen <lilykde <at> xs4all.nl> writes:

> 
> Op zondag 24 mei 2009, schreef madMuze:
> > perhaps a Schemer could pull the X-extent info from the attachment point
> > notehead, divide it by 2 and send that to the offset. Meanwhile, it may to
> > helpful to know that:
> >  quarter-note head width = about 1.31
> >  half-note head width = about 1.39
> >  whole-note head width = about 1.96
> > (in staff space units)
> 
> Thanks! But I think lyrics and dynamics are also able to center themselves 
> nicely. So there must be way to get the center.
> 

I think the difference is that LyricTexts have NoteHeads as grob-parents,
while TextScripts have PaperColumns.

Here's something that's pretty hacky, but seems to work, at least
in this simple case:

#(define lastNoteHeadWidth 0)

#(define (centerTextFn grob grob-origin context)
    (cond ((grob::has-interface grob 'note-head-interface)
                (set! lastNoteHeadWidth (cdr (ly:grob-property grob 'X-
extent))))
          ((grob::has-interface grob 'text-script-interface)
                (let* ((xext (ly:grob-property grob 'X-extent))
                       (offset (* (- lastNoteHeadWidth (car xext) (cdr xext)) 
0.5)))
                (ly:grob-set-property! grob 'X-offset offset)))))
    
centerText = \applyOutput #'Voice #centerTextFn

{
    \centerText c'1-"Text"
    \centerText c'4-"Text"
}



_______________________________________________
lilypond-user mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to