On 7/11/11, Wilbert Berendsen <[email protected]> wrote:
> And to place an ending bar line on the end of the last line I use the
> alignGrob trick posted to this list sometime ago:
>
> http://old.nabble.com/Re%3A-left-aligning-grobs-to-other-grobs-p31138286.html
>
Hi, Wilbert --
Since you found a use for that function, I thought I'd post a newer
version with some improvements (including suggestions from Gilles
Thibault).
Best,
David
\version "2.14.1"
alignGrob =
#(define-music-function (parser location grob-to-align reference-grob dir corr)
(string? symbol? number? number?)
#{
\overrideProperty $grob-to-align #'extra-offset #(lambda (grob)
(let* ((sys (ly:grob-system grob))
(array (ly:grob-object sys 'all-elements))
(default-coord (ly:grob-relative-coordinate grob sys X))
(grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
(lst (filter
(lambda (x) (eq? $reference-grob (grob-name x)))
(ly:grob-array->list array))))
;; find the grob with the X-coordinate closest to object to be aligned
(let ((ref (car lst)))
(define closest (lambda (x)
(if (< (abs (- default-coord
(ly:grob-relative-coordinate (car x) sys X)))
(abs (- default-coord
(ly:grob-relative-coordinate ref sys X))))
(set! ref (car x)))
(if (not (null? (cdr x)))
(closest (cdr x)))))
(closest lst)
;; return extra-offset based on choice of alignment
(cons
(cond ((< $dir 0) (- (car (ly:grob-extent ref sys X))
(car (ly:grob-extent grob sys X))))
((= $dir 0) (- (interval-center (ly:grob-extent ref sys X))
(interval-center (ly:grob-extent grob sys X))))
((> $dir 0) (- (cdr (ly:grob-extent ref sys X))
(cdr (ly:grob-extent grob sys X)))))
$corr))))
#}
)
ln = \markup \with-color #red \draw-line #'(0 . 6)
uparrow = \markup \combine \arrow-head #Y #UP ##f \draw-line #'(0 . -2)
downarrow = \markup \combine \arrow-head #Y #DOWN ##f \draw-line #'(0 . 2)
\relative c' {
%% bar 1
\time 3/4
\key d \major
d
\alignGrob #"TextScript" #'KeySignature #0 #6
e-\ln
\alignGrob #"TextScript" #'Clef #1 #5.5
fis-\ln
%% bar 2
\time 5/4
\alignGrob #"TextScript" #'BarLine #0 #-5.5
e^\ln
\alignGrob #"TextScript" #'Hairpin #1 #1
d(_\ln
\alignGrob #"TextScript" #'Slur #0 #0
e_\uparrow
\alignGrob #"TextScript" #'StaffSymbol #0 #0
fis^\markup \center-column { "mid-staff" \downarrow } d)\<
%% bar 3
\time 3/4
\alignGrob #"TextScript" #'TimeSignature #-1 #-5
e^\ln
\alignGrob #"TextScript" #'TimeSignature #1 #-5
fis^\ln d
%% bar 5
\alignGrob #"TextScript" #'Stem #0 #-5.5
e\!^\ln fis
\alignGrob #"TextScript" #'Accidental #0 #0
d!_\uparrow
%% bar 6
\time 2/4
\alignGrob #"Stem" #'NoteHead #0 #0
fis
\alignGrob #"Stem" #'NoteHead #0 #0
\alignGrob #"Script" #'BarLine #0 #0.5
\alignGrob #"TextScript" #'StaffSymbol #1 #0
d\fermata _"end"
\bar "||"
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user