Re: Setting default arguments for music function?
Fantastic! Thanks again. On Tue, Jan 31, 2023 at 7:28 PM Jean Abou Samra 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 > > >
Re: Setting default arguments for music function?
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 OpenPGP_signature Description: OpenPGP digital signature
Re: Setting default arguments for music function?
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 } Thanks, -Ahanu On Tue, Jan 31, 2023 at 7:10 PM Ahanu Banerjee wrote: > Thanks! I had no idea that that resource existed. > Appreciate all your help. > > -Ahanu > > On Tue, Jan 31, 2023 at 7:08 PM Jean Abou Samra > wrote: > >> On 01/02/2023 01:04, Ahanu Banerjee wrote: >> > Is it possible to specify default values for a function to use when >> arguments are missing? In the example below, I want the default font size >> to be -4 and the default color to be blue without having to specify it each >> time, but I also want the ability to change those values in rare cases. >> > >> > \version "2.24" >> > \language "english" >> > altParen = #(define-music-function >> > (parenColor parenSize parenItem) >> > (color? number? ly:music?) >> >#{ >> > \tweak Parentheses.font-size #parenSize \tweak Parentheses.color >> #parenColor \parenthesize #parenItem >> >#}) >> > { c \altParen "blue" #-4 \upbow } >> >> >> Perhaps read this: >> >> >> https://extending-lilypond.readthedocs.io/en/latest/extending/music.html#optional-arguments >> >> Best, >> Jean >> >> >>
Re: Setting default arguments for music function?
Thanks! I had no idea that that resource existed. Appreciate all your help. -Ahanu On Tue, Jan 31, 2023 at 7:08 PM Jean Abou Samra wrote: > On 01/02/2023 01:04, Ahanu Banerjee wrote: > > Is it possible to specify default values for a function to use when > arguments are missing? In the example below, I want the default font size > to be -4 and the default color to be blue without having to specify it each > time, but I also want the ability to change those values in rare cases. > > > > \version "2.24" > > \language "english" > > altParen = #(define-music-function > > (parenColor parenSize parenItem) > > (color? number? ly:music?) > >#{ > > \tweak Parentheses.font-size #parenSize \tweak Parentheses.color > #parenColor \parenthesize #parenItem > >#}) > > { c \altParen "blue" #-4 \upbow } > > > Perhaps read this: > > > https://extending-lilypond.readthedocs.io/en/latest/extending/music.html#optional-arguments > > Best, > Jean > > >
Re: Setting default arguments for music function?
On 01/02/2023 01:04, Ahanu Banerjee wrote: > Is it possible to specify default values for a function to use when arguments > are missing? In the example below, I want the default font size to be -4 and > the default color to be blue without having to specify it each time, but I > also want the ability to change those values in rare cases. > > \version "2.24" > \language "english" > altParen = #(define-music-function > (parenColor parenSize parenItem) > (color? number? ly:music?) > #{ > \tweak Parentheses.font-size #parenSize \tweak Parentheses.color > #parenColor \parenthesize #parenItem > #}) > { c \altParen "blue" #-4 \upbow } Perhaps read this: https://extending-lilypond.readthedocs.io/en/latest/extending/music.html#optional-arguments Best, Jean OpenPGP_signature Description: OpenPGP digital signature
Setting default arguments for music function?
Is it possible to specify default values for a function to use when arguments are missing? In the example below, I want the default font size to be -4 and the default color to be blue without having to specify it each time, but I also want the ability to change those values in rare cases. \version "2.24" \language "english" altParen = #(define-music-function (parenColor parenSize parenItem) (color? number? ly:music?) #{ \tweak Parentheses.font-size #parenSize \tweak Parentheses.color #parenColor \parenthesize #parenItem #}) { c \altParen "blue" #-4 \upbow } Thanks, -Ahanu