Fantastic! Thanks again.

On Tue, Jan 31, 2023 at 7:28 PM Jean Abou Samra <[email protected]> wrote:

> On 01/02/2023 01:23, Ahanu Banerjee wrote:
> > Is it possible to have one of the arguments rely on a property of
> another argument?
> >
> > In my example, I want the default value for "parenColor" to be the same
> as the color of the "parenItem":
> >
> > \version "2.24"
> > \language "english"
> > altParen = #(define-music-function
> >      (parenColor parenSize parenItem)
> >      ( (color? "black") (number? -4) ly:music?)
> >    #{
> >      \tweak Parentheses.font-size #parenSize \tweak Parentheses.color
> #parenColor \parenthesize #parenItem
> >    #})
> > { c \altParen -\tweak color "green" \upbow }
>
>
> Well, the color you want to access isn't a property of parentItem.
> parenItem is just a bit of music. Rather, it is a property of the
> grob that will eventually be caused by the music parentItem. So,
> in the music function, the color is not available. However, what
> you can do is writing a callback which runs waay later in the process,
> and can access it. Cf.
>
>
> https://extending-lilypond.readthedocs.io/en/latest/extending/backend.html#understanding-callbacks
>
> \version "2.24.0"
>
> \language "english"
>
> #(define (color-from-host grob)
>    (ly:grob-property (ly:grob-object grob 'sticky-host) 'color))
>
> altParen = #(define-music-function
>      (parenColor parenSize parenItem)
>      ( (color? color-from-host) (number? -4) ly:music?)
>    #{
>      \tweak Parentheses.font-size #parenSize \tweak Parentheses.color
> #parenColor \parenthesize #parenItem
>    #})
> { c \altParen -\tweak color "green" \upbow }
>
>
>
> Actually, because this is a common pattern for grobs like parentheses
> which attach to another grob, there is a shortcut:
>
> \version "2.24.0"
>
> \language "english"
>
> altParen = #(define-music-function
>      (parenColor parenSize parenItem)
>      ( (color? (sticky-grob-interface::inherit-property 'color)) (number?
> -4) ly:music?)
>    #{
>      \tweak Parentheses.font-size #parenSize \tweak Parentheses.color
> #parenColor \parenthesize #parenItem
>    #})
> { c \altParen -\tweak color "green" \upbow }
>
>
>
> Jean
>
>
>

Reply via email to