[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
applying a tweak or callback to an \after-ed grob
From: |
Kieren MacMillan |
Subject: |
applying a tweak or callback to an \after-ed grob |
Date: |
Sat, 8 Oct 2016 13:28:27 -0400 |
Hi all,
I’ve been using David K’s lovely \after function (which should, IMO, be
polished up and rolled into the distro!) to great effect in my recent
engravings.
However, I’m having difficulty figuring out how to apply tweaks to the grobs
that are \after-ed.
For example, see the snippet included below.
Any hints would be appreciated.
Thanks,
Kieren.
________________________
%%% SNIPPET BEGINS
\version "2.19"
\paper { ragged-right = ##f }
hairpinWithCenteredText =
#(define-music-function (parser location text) (markup?)
#{
\once \override Voice.Hairpin.after-line-breaking =
#(lambda (grob)
(let* ((stencil (ly:hairpin::print grob))
(par-y (ly:grob-parent grob Y))
(dir (ly:grob-property par-y 'direction))
(new-stencil (ly:stencil-aligned-to
(ly:stencil-combine-at-edge
(ly:stencil-aligned-to stencil X CENTER)
Y dir
(ly:stencil-aligned-to (grob-interpret-markup
grob text) X CENTER))
X LEFT))
(staff-space (ly:output-def-lookup (ly:grob-layout grob)
'staff-space))
(staff-line-thickness
(ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
(grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta)
'name)))
(par-x (ly:grob-parent grob X))
(dyn-text (eq? (grob-name par-x) 'DynamicText ))
(dyn-text-stencil-x-length
(if dyn-text
(interval-length
(ly:stencil-extent (ly:grob-property par-x 'stencil) X))
0))
(x-shift
(if dyn-text
(-
(+ staff-space dyn-text-stencil-x-length)
(* 0.5 staff-line-thickness)) 0))
(original (ly:grob-original grob))
(pieces (if (ly:grob? original)
(ly:spanner-broken-into original)
'())))
(ly:grob-set-property! grob 'Y-offset 0) ;; ensure correct alignment
(ly:grob-set-property! grob 'stencil
(ly:stencil-translate-axis
(if (or (null? pieces)
(and (pair? pieces)
(eq? grob (car pieces))))
new-stencil
stencil)
x-shift X))))
#})
hairpinPoco = \hairpinWithCenteredText \markup { \italic poco }
after =
#(define-music-function (parser location t e m)
(ly:duration? ly:music? ly:music?)
#{
\context Bottom <<
#m
{ \skip $t <> -\tweak extra-spacing-width #empty-interval $e }
>>
#})
test = {
\once \hairpinPoco g1\< g\!
\once \hairpinPoco \after 2 \< g1 g\!
}
\score { \test }
%%% SNIPPET ENDS
________________________________
Kieren MacMillan, composer
‣ website: www.kierenmacmillan.info
‣ email: address@hidden