lilypond-user
[Top][All Lists]
Advanced

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

Re: Align text above clef


From: Urs Liska
Subject: Re: Align text above clef
Date: Mon, 15 Oct 2018 13:57:02 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1



Am 15.10.2018 um 13:16 schrieb Urs Liska:
Hi Mats,

thank you for the suggestion.


Am 15.10.2018 um 12:54 schrieb Mats Bengtsson:
Hi,


On 2018-10-15 11:22, Urs Liska wrote:
Hi,

I have to center-align some texts above and below clefs like in the attached image.

Before I start fiddling around with the Clef stencil and combine the markups I'd like to ask if there's a simpler and more straightforward way to achieve that.

Ideally I'd like to have the markups at a fixed vertical position so several of those on one system will align properly.
How about using the break-alignable-interface, see http://lilypond.org/doc/v2.19/Documentation/notation/aligning-objects#using-the-break_002dalignable_002dinterface ?
A starting point could be

\relative c'{
  \clef alto
  \override Score.RehearsalMark.break-align-symbols= #'(clef)
  \override Score.Clef.break-align-anchor-alignment = #CENTER
  \mark "text"
  c e f g
}

Well, this does solve the horizontal alignment issue, but I can't use it because I need always *two* such texts, one above and one below the clef.

OK, I did get into creating a custom stencil, and (building on what I got from the list last week) it was quite possible. The following code creates two markup stencils, horizontally aligns them over the clef and calculate a padding based on the original clef's vertical extent and the staff symbol positions:

\version "2.19.82"

annotateClef =
#(define-music-function (padding text-above text-below) ((number? 1) markup? 
markup?)
   #{
     \once \override Staff.Clef.after-line-breaking =
     #(lambda (grob)
        (let*
         ((stencil (ly:clef::print grob))
          ;; miniml distance between center staff line and markup
          (padding-threshold 5)
          ;; reference point of the original clef
          (vpos (/ (ly:grob-property grob 'staff-position) 2))
          ;; upper and lower edges of the clef
          (vextent (ly:stencil-extent stencil Y))
          (clef-top (+ vpos (cdr vextent)))
          (clef-bottom (+ vpos (car vextent)))
          ;; calculate padding acknowledging distance to clef *and* to staff
          (padding-top (max padding (- padding-threshold clef-top)))
          (padding-bottom (max padding (+ padding-threshold clef-bottom)))
          ;; create stencil for upper text and horizontal shift for centering
          (markup-stencil-above (grob-interpret-markup grob text-above))
          (shift-above (- (interval-center (ly:stencil-extent stencil X))
                   (interval-center (ly:stencil-extent markup-stencil-above 
X))))
          ;; create stencil for lower text
          (markup-stencil-below (grob-interpret-markup grob text-below))
          (shift-below (- (interval-center (ly:stencil-extent stencil X))
                   (interval-center (ly:stencil-extent markup-stencil-below 
X))))
          ;; combine the three stencils
          (new-stencil
           (ly:stencil-combine-at-edge
            (ly:stencil-combine-at-edge
             stencil Y DOWN
             (ly:stencil-translate-axis markup-stencil-below shift-below X)
             padding-bottom)
            Y UP
            (ly:stencil-translate-axis markup-stencil-above shift-above X)
            padding-top)))
         (ly:grob-set-property! grob 'stencil new-stencil)))
   #})

\relative {
  \annotateClef "Treble" "G"
  \clef treble
  c'1
  \annotateClef "Tenor" "C"
  \clef tenor
  c1
  \annotateClef "Soprano" "C"
  \clef soprano
  c1
}

I have one more general question, though (fortunately it doesn't matter in my actual example): calculating the padding manually does (I think) the same as using the outside-staff-padding property in general: it uses the "bounding box" of the markup as its reference. Is there any way to have markups be padded above or below the staff so that different text elements' *baselines* are aligned?

Urs



reply via email to

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