lilypond-user
[Top][All Lists]
Advanced

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

Re: bis


From: erik
Subject: Re: bis
Date: Mon, 25 Jul 2016 13:54:56 +0200


Thanks a lot, I'll check it out!

Erik


----- Ursprungligt meddelande -----
Från:
"Andrew Bernard" <address@hidden>

Till:
"lilypond-user Mailinglist" <address@hidden>
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''1\startTextSpan
c''1\stopTextSpan
}


== snip

_______________________________________________
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]