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: Thomas Morley
Subject: Re: centering text on a measure
Date: Fri, 30 Sep 2011 00:59:15 +0200

2011/9/23 David Nalesnik <address@hidden>
(...)
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 . . .
(...)

Hi David,

I thought a while about your "hackishness" :)

As a first step it seems to be possible to add a grob-custom-property to define-grob-properties.scm in some way (thanks to Arnold from the german lilypond forum, who had the idea http://www.lilypondforum.de/index.php).

The code below gives only the name, description and the type of argument of the new grob-custom-property. But the little test shows no problems and no warning in the log.

\version "2.14.2"

#(define (define-grob-custom-property symbol type? description)
  (if (not (equal? (object-property symbol 'backend-doc) #f))
      (ly:error (_ "symbol ~S redefined") symbol))

  (set-object-property! symbol 'backend-type? type?)
  (set-object-property! symbol 'backend-doc description)
  symbol)
 
#(define all-user-grob-custom-properties
  (map
   (lambda (x)
     (apply define-grob-custom-property x))

   `(
     (tigs ,string? "Tag marker in grob for function center-between")
     )))

#(define ((center-between tags 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 'tigs) tags)) 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 #'tigs = #"hello"
  \once \override TextScript #'extra-offset = #(center-between "hello" 0)
  c^"hello"
  c c\once \override NoteHead #'test = ##f
  c
  \once \override Staff.BarLine #'tigs = #"hello"
 
 
  \once \override TextScript #'extra-offset = #(center-between "bla" 0)
  \once \override NoteHead #'tigs = #"bla"
  c^"xy|yx"
  \once \override NoteHead #'tigs = #"bla"
  c
  c
  c

  \once \override Script #'extra-offset = #(center-between "blub" 0)
  \once \override Stem #'tigs = #"blub"
  c\turn
  \once \override Stem #'tigs = #"blub"
  c c
  c
}

A second step might be to add a interface to the new grob-custom-property. But in define-grob-interfaces.scm you can read:


;; The interfaces defined here generally have no code (e.g.,
;; dynamic-interface), or have callbacks defined entirely in
;; scheme.  Others interfaces are defined in lily/*.cc with the
;; ADD_INTERFACE function

So I don't know if it's possible.


Best,
  Harm





reply via email to

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