On Wed, Jul 19, 2023 at 2:24 AM David Kastrup <[email protected]> wrote:

> Trevor Bača <[email protected]> writes:
>
> > Hi,
> >
> > I'd like the left text of red text spanners to be set to "foo", and to
> set
> > the left text of all other text spanners to "bar".
> >
> > But I misunderstand how to return markup:
> >
> > %%% BEGIN %%%
> >
> > \version "2.25.3"
> >
> > % no left text set
> > {
> >   \once \override TextSpanner.bound-details.left.text =
> >     #(lambda (grob) (if (equal? red (ly:grob-property grob 'color)) "foo"
> > "bar"))
> >   c'1
> >   - \tweak color #red
> >   \startTextSpan
> >   c'1
> >   \stopTextSpan
> > }
> >
> > % no left text set
> > {
> >   \once \override TextSpanner.bound-details.left.text =
> >     #(lambda (grob) (if (equal? red (ly:grob-property grob 'color))
> >       (markup "foo")
> >       (markup "bar")))
> >   c'1
> >   - \tweak color #red
> >   \startTextSpan
> >   c'1
> >   \stopTextSpan
> > }
> >
> > %%% END %%%
> >
> > What's the right way to return markup from a Scheme function?
>
> You are doing fine in that regard, but subproperties don't have callback
> evaluation.
>

Ah, ok; thank you, David!

So, the take-away here is:

%%% BEGIN %%%

% Works because TupletNumber.text is property (not a subproperty):
{
  \once \override TupletNumber.text =
    #(lambda (grob) (if (equal? red (ly:grob-property grob 'color))
      (markup "RED")
      (markup "NOT RED")))
  \tweak color #red
  \times 2/3 { c'2 c' c' }
}

% Doesn't work because TextSpanner.bound-details.left.text is a subproperty:
{
  \once \override TextSpanner.bound-details.left.text =
    #(lambda (grob) (if (equal? red (ly:grob-property grob 'color)) "foo"
"bar"))
  c'1
  - \tweak color #red
  \startTextSpan
  c'1
  \stopTextSpan
}

%%% END %%%

The problem I'm wanting to solve has to do with swapping a text spanner's
right text for its right-broken text, conditionally based on the spanner's
end position. The problem looks complicated, so I'll introduce it as a
separate thread.

Trevor.

-- 
Trevor Bača
www.trevorbaca.com
soundcloud.com/trevorbaca

Reply via email to