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: Peter Toye
Subject: Re: How to get multiple text spanners at the same height?
Date: Sun, 19 May 2013 15:37:39 +0100

Thomas,

That's fantastic now I've tried it. Thanks a lot.

Best regards,

Peter
mailto:address@hidden
www.ptoye.com

-------------------------
Monday, May 13, 2013, 2:23:58 AM, you wrote:

> Send lilypond-user mailing list submissions to
>         
address@hidden

> To subscribe or unsubscribe via the World Wide Web, visit
>         
https://lists.gnu.org/mailman/listinfo/lilypond-user
> or, via email, send a message with subject or body 'help' to
>         
address@hidden

> You can reach the person managing the list at
>         
address@hidden

> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of lilypond-user digest..."


> Today's Topics:

>    1. Re:How to get multiple text spanners at the same height?
>       (Thomas Morley)


> ----------------------------------------------------------------------

> Message: 1
> Date: Mon, 13 May 2013 03:23:51 +0200
> From: Thomas Morley <
address@hidden>
> To: Nick Payne <
address@hidden>
> Cc: 
address@hidden
> Subject: Re: How to get multiple text spanners at the same height?
> Message-ID:
>        
> <address@hidden>
> Content-Type: text/plain; charset="iso-8859-1"

> 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
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: text-spanner-multiple-text-01.png
> Type: image/png
> Size: 44622 bytes
> Desc: not available
> URL:
> <
http://lists.gnu.org/archive/html/lilypond-user/attachments/20130513/318d5cfd/attachment.png>

> ------------------------------

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


> End of lilypond-user Digest, Vol 126, Issue 76
> **********************************************
reply via email to

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