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: Trevor Bača
Subject: Re: How to really center a text above a note?
Date: Mon, 29 Jun 2009 07:06:44 -0500



On Sun, May 24, 2009 at 8:36 PM, Michael Lauer <address@hidden> wrote:
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"
}



Hi Michael, hi Wilbert,

Mark Polesky just pointed out to me that a thread I started yesterday ...

   http://lists.gnu.org/archive/html/lilypond-user/2009-06/msg00735.html

... asks essentially the same question that you guys were tackling here. So I thought I'd respond back to your posts here.

First: Michael, that \centerText Scheme function you cooked up is very cool. If I'm reading correctly you're doing two things in the function. If the grob passed in is a notehead then you're saving the width (X-extent) of the notehead for use in the second condition. If the grob passed in is a TextScript then you're setting the X-offset of the TextScript to half the value of d, where d equals the width of the TextScript minus the width of the last known notehead. Yes? (So, basically exactly as David had sketched earlier in the thread?)

Second: there used to be a (somewhat more) direct way of specifying the point-on-notehead to which TextScripts would make reference during positioning. Here're some settings from 2006:


%%% BEGIN X-PARENT CENTERING SNIPPET %%%

\version "2.9.16"

textScriptCenterOnParent = \override TextScript #'X-offset =

      #(ly:make-simple-closure
        `(,+ ,(ly:make-simple-closure (list
 ly:self-alignment-interface::x-aligned-on-self))
      ,(ly:make-simple-closure (list
 ly:self-alignment-interface::centered-on-x-parent))))

\new Staff {
 \textScriptCenterOnParent
 \override TextScript #'self-alignment-X = #left
 c'4_\markup { MMM }
 \override TextScript #'self-alignment-X = #center
 c'4_\markup { MMM }
 \override TextScript #'self-alignment-X = #right
 c'4_\markup { MMM }
}

%%% END X-PARENT SNIPPET %%%


These are settings that I put together in September 2006 ...

   http://lists.gnu.org/archive/html/lilypond-user/2006-09/msg00088.html

... and, at that time, they worked great. See notehead-centering.png, reattached here for convenience.

(And I should also mention that I cobbled together the settings given above by looking at the settings for OctavateEight in define-grobs.scm rather blindly. But they worked great.)

But running that same code now (2.13.2) produces bizarre results. See weird-notehead-centering.png.

So, thinking about Michael's statement here ...

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

... is it possible that TextScripts *used to* have NoteHeads as grob-parents (at least in 2.9.16) and have since changed to have PaperColumns as grob parents, thus rendering the settings from 2.9.16 no longer functional?

Or is something else now going that would prevent calls to Self_alignment_interface::aligned_on_x_parent and centered_on_x_parent from working as they did previously?


Trevor.


--
Trevor Bača
address@hidden

Attachment: notehead-centering.png
Description: PNG image

Attachment: weird-notehead-centering.png
Description: PNG image


reply via email to

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