lilypond-user
[Top][All Lists]
Advanced

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

Re: centering text on a measure


From: David Nalesnik
Subject: Re: centering text on a measure
Date: Sat, 3 Sep 2011 12:36:56 -0500

Trevor,

On Sat, Sep 3, 2011 at 9:56 AM, Trevor Daniels <address@hidden> wrote:

It would be nice if TextSpanner could
centre its text between the left and right
bounds (like the number on a tuplet bracket)
but it doesn't, AFAIK.  

Thank you for this idea!  

I've adapted the snippet for centering text on hairpins
 http://lsr.dsi.unimi.it/LSR/Snippet?id=233
to give an approximation of this.  Basically,  I've replaced the default TextSpanner stencil with a blank with the same extents to which I add a text.  The argument allows you to position this text using an alignment value.  The example shows a few alignments over one-measure groups on the first line, two-measure groups on the second.  (Unfortunately, if I don't blank out the default stencil, the text appears on top of the extender line, and of course the distance between the individual dashes or dots isn't adapted to make for a nice fit.  Insert bad memories of another notation program here.)

Uncommenting the line in \music { . . . } shows that the alignment does affect spacing.

\version "2.15.8"

#(define ((spanner-with-movable-text text value) grob)
   (let* ((spanner-stencil (ly:line-spanner::print grob))
          (new (ly:make-stencil "" (ly:stencil-extent spanner-stencil X)
             (ly:stencil-extent spanner-stencil Y))))   
     (ly:stencil-aligned-to
       (ly:stencil-add
(ly:stencil-aligned-to new X value)
(ly:stencil-aligned-to (grob-interpret-markup grob text) X CENTER))
       X LEFT)))
       
pattern = \relative c'' {
  c8\startTextSpan
  c c c
  c c c
  c\stopTextSpan
}

music = {
  \override TextSpanner #'stencil = #(spanner-with-movable-text "|" LEFT)
  \pattern
  \override TextSpanner #'stencil = #(spanner-with-movable-text "|" -0.5)
  %% uncomment to see vertical adjustment
  %\override TextSpanner #'stencil = #(spanner-with-movable-text "|" 2)
  \pattern
  \override TextSpanner #'stencil = #(spanner-with-movable-text "|" CENTER)
  \pattern
  \override TextSpanner #'stencil = #(spanner-with-movable-text "|" 0.5)
  \pattern
  \override TextSpanner #'stencil = #(spanner-with-movable-text "|" RIGHT)
  \pattern
}
  
\relative c'' {
  \hideNotes
  \music
  \time 2/4
  \music
}

Now, I suppose the text's position is dependent on the NoteColumn grobs to which the spanner is attached.  Would it be possible to reset the attachment point to another grob? (I could use offsets as in the original function, but that will once again bring in the 'extra-offset issue.)
 
It would be a nice
extension to request, though.

I agree that this would be great feature for LilyPond.  How would I go about making a request? 

David


reply via email to

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