lilypond-user
[Top][All Lists]
Advanced

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

Re: How to get multiple text spanners at the same height?


From: SoundsFromSound
Subject: Re: How to get multiple text spanners at the same height?
Date: Wed, 15 May 2013 10:27:08 -0700 (PDT)

This is perfect for what I need.  Thank you.  One question though: what would
be the easiest way to "center" this span (so the dashes line up in the
center of the words, rather than along the bottom of the letters)?

Is there a way to do this in LilyPond or should I tweak this once my score
outputs (SVG) and then mess around in Inkscape or something?  I'm not sure
what the best way would be.

Ben

quote author="Thomas Morley-2">
Hi,

a first try to do it more automatically:


\version "2.16.2"

addTextSpannerText =
#(define-music-function (parser location text)(string?)
   "
   Add text to TextSpanner.

   @var{text} should be entered using dashes to indicate hyphenation.
   Additional dashes may be used to affect spacing.
   "
#{
   \once \override TextSpanner #'after-line-breaking =
     #(lambda (grob)
       (let* ((stil (ly:grob-property grob 'stencil))
              (layout (ly:grob-layout grob))
              (staff-space (ly:staff-symbol-staff-space grob))
              (line-thickness (ly:output-def-lookup layout 'line-thickness))
              ;; have we been split?
              (orig (ly:grob-original grob))
              ;; if yes, get the split pieces (our siblings)
              (siblings (if (ly:grob? orig)
                            (ly:spanner-broken-into orig)
                            '()))
              ;; get all (broken) stencils
              (stils
                (if (null? siblings)
                  (list stil)
                  (map
                    (lambda (x) (ly:grob-property x 'stencil))
                    siblings)))
              ;; get the length of all stencils
              (stil-x-lengths
                (map
                  (lambda (x) (interval-length (ly:stencil-extent x X)))
                  stils))
              ;; split the input-string into parts
              (text-lst (string-split text #\-))
              ;; how many parts did we get
              (txt-lst-length (length text-lst))
              ;; get a divisor to split `text-lst' into parts to be printed
              ;; before and after the line break.
              ;; TODO: find better method
              (partial (if (null? siblings)
                           1
                           (floor (/ txt-lst-length (length siblings)))))
              ;; get the parts
              ;; adding an empty string at end of first line,
              ;; an start of second line
              (head (append (list-head text-lst partial) '("")))
              (tail (cons "" (list-tail text-lst partial)))
              ;; get lists of whiteout-markups
              (mrkp-whiteout-proc
                (lambda (x) (markup
                              #:whiteout
                              #:pad-markup line-thickness
                              x)))
              (lst (map mrkp-whiteout-proc text-lst))
              (lst-head (map mrkp-whiteout-proc head))
              (lst-tail (map mrkp-whiteout-proc tail))
              ;; procedures to get the text-stencils.
              (mrkp
                (lambda (x y)
                #{
                   \markup
                     \override #`(line-width . ,(+ staff-space y))
                     \fill-line
                     $x
                #}))
              (text-stil (lambda (x y) (grob-interpret-markup grob
(mrkp x y)))))

    (ly:grob-set-property! grob 'stencil
      (cond ((null? siblings)

                 (ly:stencil-add
                   stil
                   (text-stil lst (car stil-x-lengths))))
            ((and (= (length siblings) 2)
                  (eq? (car siblings) grob))
                 (ly:stencil-add
                   stil
                   (text-stil lst-head (car stil-x-lengths))))
            ((and (= (length siblings) 2)
                  (eq? (cadr siblings) grob))
                 (ly:stencil-add
                   stil
                   (text-stil lst-tail
                              (+ (* 4 staff-space) (cadr stil-x-lengths)))))
            (else (begin
                     (ly:warning "More than two linebreaks are not
supported.")
                     stil))))))
#})


  \relative c'' {
    \addTextSpannerText "cres-cen-do"
    c1\startTextSpan
    d'2 d\stopTextSpan
    \addTextSpannerText "cres-cen-do"
    c1\startTextSpan
    \break
    d'2 d\stopTextSpan
    \break
    \addTextSpannerText "ral-len-tan-do"
    c1\startTextSpan
    d'2 d\stopTextSpan
    \addTextSpannerText "ral-len-tan-do"
    c,1\startTextSpan
    \break
    d2 d\stopTextSpan
    \break
    \addTextSpannerText "poco-a-poco-cres-cen-do"
    c,1\startTextSpan
    d2 d\stopTextSpan
    \addTextSpannerText "poco-a-poco-cres-cen-do"
    c,1\startTextSpan
    \break
    d2 d\stopTextSpan
    \break
    \addTextSpannerText "You-may-want-to-use-additional-------dashes"
    c'1\startTextSpan
    \break
    d2 d d d\stopTextSpan
  }


HTH,
  Harm

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


text-spanner-multiple-text-01.png (59K)
<http://lilypond.1069038.n5.nabble.com/attachment/145833/0/text-spanner-multiple-text-01.png>





-----
composer | sound designer
--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/How-to-get-multiple-text-spanners-at-the-same-height-tp145793p145962.html
Sent from the User mailing list archive at Nabble.com.



reply via email to

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