[Top][All Lists]

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

Re: centering text on a measure

From: Trevor Daniels
Subject: Re: centering text on a measure
Date: Thu, 1 Sep 2011 09:09:22 +0100

Hi David

Perhaps you could turn this idea into a music function:

\relative c'' {
 a4 a a a |
   { a4 a a a | }
     \once \override MultiMeasureRest #'transparent = ##t
      R1_"XIII" |
 a4 a a a |


----- Original Message ----- From: "David Nalesnik" <address@hidden>
To: "lilypond-user" <address@hidden>
Cc: "Lilypond Dev" <address@hidden>
Sent: Thursday, September 01, 2011 5:27 AM
Subject: centering text on a measure

Hi all,

I've been experimenting with a way to center text on measures. (I create a lot of exercises with blanks or roman numerals between the staff, and it's nice not to need to position each one individually by trial and error.) I've come up with the following function which works, but I wonder if
there's a simpler or "more correct" way to go about this.

Also, I'm wondering why I can't apply this function to 'X-offset rather than 'extra-offset. I've attached a version of the file which returns an 'X-offset value, and it returns an error (also with 'self-alignment-X). Is
there a way to fix this?

Any suggestions will be much appreciated!


\version "2.15.8"

#(define (bounding-coords grob-coord bar-coords end-coord)
  (if (null? (cdr bar-coords))
      (cons (car bar-coords) end-coord)
      (if (and (< (car bar-coords) grob-coord)
                 (> (cadr bar-coords) grob-coord))
          (cons (car bar-coords)(cadr bar-coords))
(bounding-coords grob-coord (cdr bar-coords) end-coord))))

#(define (center-on-measure grob)
  (let* ((sys (ly:grob-system grob))
         (array (ly:grob-object sys 'all-elements))
(grob-coord (interval-center (ly:grob-extent grob sys X))) (grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta)
(bars (filter (lambda (x) (eq? 'NonMusicalPaperColumn (grob-name
                         (ly:grob-array->list array)))
         (bar-coords (sort (map (lambda (x) (interval-center
(ly:grob-extent x sys X))) bars) <))
         (bounds (bounding-coords grob-coord bar-coords (cdr
(ly:grob-extent sys sys X)))))

      (- (- grob-coord (/ (+ (car bounds) (cdr bounds)) 2)))

 \override TextScript #'extra-offset = #center-on-measure
 \repeat unfold 10 { s1_"|"^"|" }


lilypond-user mailing list

reply via email to

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