|
From: | Andrew Bernard |
Subject: | Spanner with centred text |
Date: | Thu, 20 Aug 2015 12:32:26 +1000 |
User-agent: | Microsoft-MacOutlook/0.0.0.150807 |
Greetings All, Here’s a first cut at making a horizontal spanning bracket with centred text. Leveraging the semantics of TextSpanners, this is remarkably useful – at least for the scores that I encounter. Limitations are that it does not do line breaking, for one. Considering this aspect, I’m not sure that it is warranted, as it is perplexing to then know where to put the text or whether to duplicate the text on the next line, and so on. And of course, if this is being used to indicate repeats it does not represent a true musical repeat in lilypond, and so breaks midi etc. Also, the code is not yet smart enough to extend to barlines. A great deal of thanks is due to Thomas Morley for mentoring me in the development of this code. Is this useful enough to deserve a place in LSR, or openlilylib? Andrew ==== \version "2.19.25" % Annotation bracket with centred text. % Andrew Bernard and Thomas Morley TextSpannerCentredText = #(define-music-function (text) (string?) "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 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) ;; 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 0 ,(* -1 dir) lineto 0 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 ,(* -1 dir) lineto ,path-part-len 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\"" g' \startTextSpan a' bes' c'' \stopTextSpan \TextSpannerCentredText "x3" bes'\startTextSpan a' g' c'\stopTextSpan } |
[Prev in Thread] | Current Thread | [Next in Thread] |