Trevor,

On Sat, Sep 3, 2011 at 9:56 AM, Trevor Daniels <t.dani...@treda.co.uk>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
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to