\version "2.19.25" #(define (lyric-text::interpolate-alignment grob) "Calculates values for 'self-alignment-X using the width = X-extent of the syllable. Values are zero up to @var{lower-threshold}, @var{maximum} above @{upper-threshold}, with a smooth interpolation inbetween." (let* ((width (cdr (ly:grob-property grob 'X-extent))) (lower-threshold 3) (upper-threshold 11) (maximum (- 4/5)) ;; calculate parameters for use in the ‘sigmoid’ cubic function with ;; (sigmoid lower-threshold) --> 0 ;; (sigmoid upper-threshold) --> maximum ;; and zero ‘slope’ in both these points (a (/ (* 2 maximum) (+ (- (expt upper-threshold 3)) (* 3 upper-threshold upper-threshold lower-threshold) (* -3 upper-threshold lower-threshold lower-threshold) (expt lower-threshold 3)))) (b (/ (- maximum (* a (+ (expt upper-threshold 3) (* 2 (expt lower-threshold 3)) (* -3 upper-threshold (expt lower-threshold 2))))) (expt (- upper-threshold lower-threshold) 2))) (c (/ (- maximum (* b (- (expt upper-threshold 2) (expt lower-threshold 2))) (* a (- (expt upper-threshold 3) (expt lower-threshold 3)))) (- upper-threshold lower-threshold))) (d (- maximum (* upper-threshold c) (* (expt upper-threshold 2) b) (* (expt upper-threshold 3) a))) (sigmoid (lambda (x) (+ (* a x x x) (* b x x) (* c x) d)))) ;(format #t "The four parameters have been determined as: \n a ~a \n b ~a \n c ~a \n d ~a\n" a b c d) (cond ((<= width lower-threshold) 0) ((< lower-threshold width upper-threshold) (sigmoid width)) ((>= width upper-threshold) maximum)))) \layout { \context { \Lyrics \override LyricText.self-alignment-X = #lyric-text::interpolate-alignment \override LyricText.before-line-breaking = #(lambda (grob) (let ((extent (ly:grob-property grob 'X-extent)) (txt (ly:grob-property grob 'text))) (format #t "For ~a, X-extent is ~a\n" txt extent))) } } << { \repeat unfold 8 g'8\noBeam } \addlyrics { llll lllll llllll lllllll llllllll lllllllll llllllllll llllllllllll } >>