lilypond-user
[Top][All Lists]
Advanced

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

Modified slur stencil with added markup


From: Urs Liska
Subject: Modified slur stencil with added markup
Date: Thu, 11 Oct 2018 23:11:11 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1

Hi,

I modified the snippet http://lilypond.org/doc/v2.19/Documentation/snippets/text#text-center-text-below-hairpin-dynamics to create a slur with added centered text. It took me little effort to adapt the snippet to work with a slur instead of a hairpin but I have two problems I didn't manage to solve on my own. Here's the code:

\version "2.19.82"

annotatedSlur =
#(define-music-function (padding text) ((number? 1) markup?)
   #{
     \once \override Slur.after-line-breaking =
     #(lambda (grob)
        (let*
         ((stencil (ly:slur::print grob))
          (dir (ly:grob-property grob 'direction))
          (markup-stencil (grob-interpret-markup grob text))
          (new-stencil
           (ly:stencil-aligned-to
            (ly:stencil-combine-at-edge
             (ly:stencil-aligned-to stencil X CENTER)
             Y dir
             (ly:stencil-aligned-to markup-stencil X CENTER)
             padding)
            X LEFT)))
         (ly:grob-set-property! grob 'stencil new-stencil)))
   #})

{
  \annotatedSlur
  %\markup \score { c''' }
  \markup "hin."
  c''4 ( g' g' c'' )
}

The first problem is that the new stencil is incorrectly aligned horizontally to the note heads. The *whole* new object is now aligned to the left edge of the parent note column (rather than the center of the note head). I might get back to some old code to figure out how to retrieve the necessary data to calculate an offset of half the notehead, but before going down that road I'd like to know if there's not an easier way to combine two stencils while keeping one of them (the slur) exactly where it was before.

The alignment problem is especially problematic when the "markup" is wider than the slur.


The second problem is that this function doesn't increase the new stencil's notion of its Y-extent. Concretely: this doesn't push the whole thing downward. You can see this from the attached image showing how the added \markup \score is cut off at the upper paper edge.

I tried to calculate the height of the markup and add it to the stencil's Y-extent, but this didn't work. I can see why this won't have any effect in after-line-breaking, but is there any way to make the modified slur aware of its modified height? Is there a way to calculate the markup's dimensions already in the music-function stage?

I had no luck with that. I succeeded to retrieve the markup's extent by inserting another callback before-line-breaking, but I failed to essentially *adding that height to the original slur's Y-extent. (Which somewhat makes sense since that information may not be readily available yet at that stage ...)

Any suggestions?

Thanks
Urs

Attachment: document.png
Description: PNG image


reply via email to

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