lilypond-user
[Top][All Lists]
Advanced

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

Re: Center text over measure


From: Lukas-Fabian Moser
Subject: Re: Center text over measure
Date: Fri, 11 May 2018 21:53:26 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0


Well, looking more closely shows me that I'd prefer a solution that doesn't even require a a separate *voice*. The problem is that I'll also have to *export* the stuff in a clean way to MusicXML, and I don't think a hidden additional layer should be the way to go. Ideally I'd have something like a \measureMarkup that would apply (and center) the markup to the measure (instead of to a note or rest). But I would also be able to go with a solution where I can attach the markup to the first element in a measure and have it positioned relative to the measure.

I looked at the implementation of the MeasureCounter stencil (which does the alignment centered in a measure); maybe also its habit of repeating the script with parentheses if the measure is broken might be useful.

But, of couse, it would be even better not to hijack an engraver (whose syntax of \start ... and \stop ... does not suit your application anyway) but to create a new one instead. But I'm afraid this is beyond my abilities.

\version "2.19.80"


#(define-public (test-stencil grob)
  "Print a text centered over a measure.  Broken measures get the text in
parentheses."
  (let* ((text (ly:grob-property grob 'text))
         (orig (ly:grob-original grob))
         (siblings (ly:spanner-broken-into orig)) ; have we been split?
         (text
           (if (or (null? siblings)
                   (eq? grob (car siblings)))
              text
              (make-parenthesize-markup text )))
         (text  (grob-interpret-markup grob text))
         (text  (ly:stencil-aligned-to
                text  X (ly:grob-property grob 'self-alignment-X)))
         (left-bound (ly:spanner-bound grob LEFT))
         (right-bound (ly:spanner-bound grob RIGHT))
         (refp (ly:grob-common-refpoint left-bound right-bound X))
         (spacing-pair
           (ly:grob-property grob
                             'spacing-pair
                             '(break-alignment . break-alignment)))
         (ext-L (ly:paper-column::break-align-width left-bound
                                                    (car spacing-pair)))
         (ext-R (ly:paper-column::break-align-width right-bound
                                                    (cdr spacing-pair)))
         (text
           (ly:stencil-translate-axis
             text
             (+ (* 0.5 (- (car ext-R)
                          (cdr ext-L)))
                (- (cdr ext-L)
                   (ly:grob-relative-coordinate grob refp X)))
             X)))
    text  ))


\layout {
  \context {
    \Staff
    \consists "Measure_counter_engraver"
    \override MeasureCounter.font-name = #"Century Schoolbook L"
    \override MeasureCounter.text = ""
    \override MeasureCounter.stencil = #test-stencil
  }
}



\new Staff \relative c' {
  \startMeasureCount
  c4 d e d c d e d
  \once \override Staff.MeasureCounter.text = "Take a look at this bar"
  c4 d \bar "" \break e f g f e d

  \once \override Staff.MeasureCounter.text = "or at that"
  g a b c
  \stopMeasureCount
}



Best
Lukas



reply via email to

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