Thanks a lot, I'll check it out!

Erik

----- Ursprungligt meddelande -----
Från: "Andrew Bernard" <andrew.bern...@gmail.com>
Till:"lilypond-user Mailinglist" <lilypond-user@gnu.org>
Kopia:
Skickat:Mon, 25 Jul 2016 19:23:40 +1000
Ämne:Re: bis

 Hi Erik,

 This is a use for a text spanner with centred text that I had been
 asking about on the list for some time, Eventually I wrote a function
 to do it with the kind help of Thomas Morley also. Very useful - I
 always said so!

 Have a look at this - it may do what you require.

 Andrew

 == snip

 version "2.19.37"

 include "/home/andro/lib/lilypond/scheme.ily"

 % Annotation bracket with centred text.
 % Andrew Bernard and Thomas Morley

 TextSpannerCentredText =
 #(define-music-function (text extra-length) (string? pair?)
 "Use TextSpanner semantics to create spanner brackets with centred
text"
 #{
 once override TextSpanner.after-line-breaking =
 #(lambda (grob)
 (let* (
 ;; get stencil of grob
 (stil (ly:grob-property grob 'stencil))
 ;; get spanner length
 (spanner-len (interval-length (ly:stencil-extent stil X)))
 ;; make stencil from text arg
 (text-stil (grob-interpret-markup grob
 (markup #:sans #:upright text)))
 ;; get text length
 (text-len (interval-length (ly:stencil-extent text-stil X))))
 ;; if text length exceeds the spanner length we cannot really
proceed.
 ;; do nothing - make an ordinary text spanner and warn.
 (if (>= text-len spanner-len)
 (begin
 (ly:warning "text length longer than spanner")
 #f
 )
 (let* (
 ;; get direction, up or down
 (dir (ly:grob-property grob 'direction))
 ;; some padding
 (padding 1)
 ;; line thickness
 (thickness 0.25)
 ;; extra length on left, negative values shorten
 (left-ext (car extra-length))
 ;; extra length on right, negative values shorten
 (right-ext (cdr extra-length))
 ;; calculate length considering text length
 (path-part-len (/ (- spanner-len text-len) 2))
 ;; make left bracket stencil
 (path-left-part-stil
 (make-path-stencil
 `(
 moveto ,(- left-ext) ,(* -1 dir)
 lineto ,(- left-ext) 0
 lineto ,path-part-len 0
 )
 thickness 1 1 #f))
 ;; make right bracket stencil
 (path-right-part-stil
 (make-path-stencil
 `(
 moveto ,(+ path-part-len right-ext) ,(* -1 dir)
 lineto ,(+ path-part-len right-ext) 0
 lineto 0 0
 )
 thickness 1 1 #f))
 ;; make complete stencil combining left and right parts
 ;; and text
 (full-stil
 (stack-stencils X RIGHT padding
 (list
 path-left-part-stil
 (centered-stencil text-stil)
 path-right-part-stil)))
 )
 ;; set grob stencil to fully constructed stencil
 (ly:grob-set-property! grob 'stencil full-stil)
 ))))
 #}
 )

 {
 c' d' ees' fis'
 once override TextSpanner.direction = #DOWN
 TextSpannerCentredText "6"" #'(0 . 0)
 g' startTextSpan
 a' bes' c'' stopTextSpan
 TextSpannerCentredText "x3" #'(2 . 1)
 bes'startTextSpan a' g' c'stopTextSpan
 TextSpannerCentredText "x3" #'(2 . -6)
 c''1startTextSpan
 c''1stopTextSpan
 }

 == snip

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

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

Reply via email to