On Thu, Sep 22, 2011 at 6:08 PM, Thomas Morley <
thomasmorle...@googlemail.com> wrote:

> Hi David,
>
> 2011/9/23 David Nalesnik <david.nales...@gmail.com>
>
>> 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
     (cons
       (- (- (interval-center (X-extent grob))
     (/ (+ (cdr (X-extent (car targets)))
   (car (X-extent (cadr targets))))
2)))
           extra-Y-offset)))

\relative c' {
  \once \override Staff.TimeSignature #'tag = #"hello"
  \once \override TextScript #'extra-offset = #(center-between "hello" 0)
  c^"hello"
  c c
  \override Staff.BarLine #'tag = #"hello"
  c
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to