On Thu, Jul 20, 2023 at 2:25 PM David Kastrup <
dak@gnu.org> wrote:
Trevor Bača <trevorbaca@gmail.com> writes:
> %%% BEGIN %%%
>
> \version "2.25.6"
> \paper { indent = 0 tagline = ##f }
>
> \markuplist \column-lines {
> "TextSpanner.bound-details.text.left = \"red\" when spanner color is
> red;"
> "TextSpanner.bound-details.text.left = \"other\" when spanner color is
> not red:"
> " "
> }
>
> {
> \override TextSpanner.bound-details =
> #(grob-transformer
> 'bound-details
> (lambda (grob orig)
> (assoc-set! (alist-copy orig)
> 'left
> (assoc-set! (alist-copy (assoc-ref orig 'left))
> 'text
> (if (equal? red (ly:grob-property grob
> 'color))
> "red" "other")))))
> c'1
> - \tweak color #red
> \startTextSpan
> d'1
> e'1
> \stopTextSpan
> f'1
> - \tweak color #blue
> \startTextSpan
> g'1
> a'1
> \stopTextSpan
> }
>
> %%% END %%%
>
> But because successive calls to grob-transformer effectively overwrite
> earlier calls to grob-transformer, we can't use this pattern to (say)
> override bound-details.left.text and bound-details.left-broken.text at the
> same time:
Your analysis is wrong. Successive calls to grob-transformer work just
fine. Your problem is that successive \override incantations revert
previous incantations in the same context _unless_ you use \temporary
\override .
If you do your second grob-transformer invocation (or both) with a
\temporary \override, it will leave the first call in place. Of course
you'll need a double \revert then if you want to get rid of both calls.
Wow! Yes, \temporary \override (with double \revert) does exactly what I'm looking for:
%%% BEGIN %%%
\version "2.25.6"
\paper { indent = 0 }
\markuplist \column-lines {
"TextSpanner.bound-details.text.left = \"red\" when spanner color is red;"
"TextSpanner.bound-details.text.left = \"other\" otherwise;"
"TextSpanner.bound-details.text.left-broken = \"red-broken\" when spanner color is red;"
"TextSpanner.bound-details.text.left-broken = \"other-broken\" otherwise:"
" "
}
{
\override Score.BarNumber.transparent = ##t
\override TextSpanner.bound-details =
#(grob-transformer
'bound-details
(lambda (grob orig)
(assoc-set! (alist-copy orig)
'left
(assoc-set! (alist-copy (assoc-ref orig 'left))
'text
(if (equal? red (ly:grob-property grob 'color))
"red" "other"))))) % note \temporary here:
\temporary \override TextSpanner.bound-details =
#(grob-transformer
'bound-details
(lambda (grob orig)
(assoc-set! (alist-copy orig)
'left-broken
(assoc-set! (alist-copy (assoc-ref orig 'left-broken))
'text
(if (equal? red (ly:grob-property grob 'color))
"red-broken" "other-broken")))))
c'1
- \tweak color #red
\startTextSpan
d'1
\break
e'1
\stopTextSpan
f'1
- \tweak color #blue
\startTextSpan
g'1
\break
a'1
\stopTextSpan
% note double \revert here:
\revert TextSpanner.bound-details
\revert TextSpanner.bound-details
b'1
\startTextSpan
c''1
\stopTextSpan
}
%%% END %%%
Thank you, David!
--