On 16.06.2018 19:41, Kieren MacMillan wrote:
I would like my chord names to be centred until they’re of a certain width (say
as wide as Cm7), and anything wider than that would extend to the right from a
position slightly to the left of the note column they’re attached to (as if
X-offset = -1).
Would this best be done with a Scheme callback function (maybe attached to
#'after-line-breaking or #'before-line-breaking)? I'm happy to try to solve the
problem myself (i.e., poke around at the Scheme until I run into a serious
roadblock), but want to at least start down the correct path.
You can even set self-alignment-X itself to a callback, like in the
attached (slightly overcomplicated) library file I use for lyrics
alignment. In this example, all lyric syllables up to a width of 3
(staff-spaces, I guess) get the default self-alignment-X of 0, all lyric
syllables wider than 11 get -.8, and values between are interpolated.
HTH, Simon
\version "2.19.25"
#(define (lyric-text::interpolate-alignment grob)
(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, i.e. a smooth transition between
;; constants and interpolation
(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
}
}_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user