[Top][All Lists]

[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: Thu, 22 Sep 2011 18:59:09 -0500

On Thu, Sep 22, 2011 at 6:08 PM, Thomas Morley <address@hidden> wrote:
Hi David,

2011/9/23 David Nalesnik <address@hidden>
Hi Harm,
If there were some way to add a tag to a grob (not just a music _expression_), this would all be much simpler.  Something like this:

\once \override Stem #'tag = #"hello"

Then, you could add the same tag to another grob, and center the TextScript (or whatever) between the two grobs having the tag "hello".  There would never be any "wrong decisions" on the part of the function.  Is such a thing possible?   I think this could be a very useful program feature.

This is far beyond my knowledge I can't see any light in the darkness ;)

Well, it is possible to override a non-existent property (if you don't mind the warnings).  Here's a sketch which uses a tag to center a grob.  (I realize it will break with very little effort.) And with this, my descent into hackishness is complete . . .

\version "2.14.2"

#(define ((center-between tag extra-Y-offset) grob)
   (let* ((refp (ly:grob-system grob))
          (all-grobs (ly:grob-array->list (ly:grob-object refp 'all-elements)))
          (X-extent (lambda (q) (ly:grob-extent q refp X)))
          (targets (filter (lambda (q) (equal? (ly:grob-property q 'tag) tag)) all-grobs))) 
     ; center between right of grob to left and left of grob to right
       (- (- (interval-center (X-extent grob))
    (/ (+ (cdr (X-extent (car targets)))
  (car (X-extent (cadr targets))))

\relative c' {
  \once \override Staff.TimeSignature #'tag = #"hello"
  \once \override TextScript #'extra-offset = #(center-between "hello" 0)
  c c 
  \override Staff.BarLine #'tag = #"hello"

reply via email to

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