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: Michael Lauer
Subject: Re: How to really center a text above a note?
Date: Mon, 25 May 2009 01:36:25 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

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"
}





reply via email to

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