lilypond-user
[Top][All Lists]
Advanced

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

Re: Adding text to slurs


From: Urs Liska
Subject: Re: Adding text to slurs
Date: Thu, 8 Nov 2018 17:29:51 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1


Am 08.11.18 um 16:00 schrieb pablocordal:
Hi everyone!

I really have a special need with this function we have been talking about:

<code>
annotatedSlur =
#(define-music-function (parser location padding text) (number? 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))
           (shift (- (interval-center (ly:stencil-extent stencil X))
                    (interval-center (ly:stencil-extent markup-stencil X))))
           (new-stencil
            (ly:stencil-combine-at-edge
             stencil
             Y dir
             (ly:stencil-translate-axis markup-stencil shift X)
             padding)))
          (ly:grob-set-property! grob 'stencil new-stencil)))
    #})
</code>

The funcion works fine, but I think it would be even better if it could
receive another number. This number should move the text horizontally in the
slur- sometimes, the text collides with another element, and it would be
great to move it forward or backward a little.

Any master coder out there can help me with this please?


annotatedSlur =
#(define-music-function (parser location padding hor-offset text) (number? number? 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))
          (shift (+ hor-offset
                   (- (interval-center (ly:stencil-extent stencil X))
                   (interval-center (ly:stencil-extent markup-stencil X)))))
          (new-stencil
           (ly:stencil-combine-at-edge
            stencil
            Y dir
            (ly:stencil-translate-axis markup-stencil shift X)
            padding)))
         (ly:grob-set-property! grob 'stencil new-stencil)))
   #})

{
  \annotatedSlur 2 1 "Here"
  c'1 ( d' )
}

But of course this means you have to use "0" everytime you do *not* need the horizontal offset.

Best
Urs


Thank you. Best regards



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user



reply via email to

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