Re: Override multiple properties in one statement?
Thanks; I think you are right about it being convoluted, and I will just continue using explicit \tweak and \override statements. Cheers, -Ahanu On Thu, Jun 30, 2022 at 4:18 PM Jean Abou Samra wrote: > > > Le 30/06/2022 à 22:04, Ahanu Banerjee a écrit : > > Hello, > > > > Is it possible to override or tweak multiple properties of one object > > at once, using one statement? i.e., without typing "\tweak" or > > "\override" multiple times? (Of course, defining a new function > > consisting of multiple statements is possible, but it's not practical > > when there are many combinations of properties to change throughout a > > document.) > > > > For example: > > > > \version "2.23.10" > > { c > > -\tweak outside-staff-priority #'() > > -\tweak whiteout ##t > > -\tweak Y-offset #0.25 > > -\tweak X-offset #1.5 > > ^\markup "text" } > > > You could use > > \version "2.23.10" > > alistPropertyTweak = > #(define-music-function (tweaks item) (alist? symbol-list-or-music?) > (fold (lambda (pair previous) > (once (propertyTweak (car pair) > (cdr pair) > previous))) > item > tweaks)) > > { c'1 \alistPropertyTweak #'((outside-staff-priority . ()) > (whiteout . #t) > (Y-offset . 0.25) > (X-offset . 1.5)) > ^"text" >\once \alistPropertyTweak #'((outside-staff-priority . ()) > (whiteout . #t) > (Y-offset . 0.25) > (X-offset . 1.5)) > TextScript >c'^"text" > } > > > On the other hand, this may not necessarily be overly > practical because in order to write any values in LilyPond > syntax, you have to replace the quote ' with a backquote > ` and use ,#{ #} to write LilyPond code. For example: > > { >c'\alistPropertyTweak #`((text . ,#{ \markup \bold "a" #})) > ^"b" > } > > > Compare with > > { >c'\tweak text \markup \bold "a" ^"b" > } > > > Ultimately, I think it is wiser to use \tweak or \override > explicitly. That's of course up to you though. By the way, > in Frescobaldi, you have an interface for defining snippets > that are convenient to insert, in Tools > Coding > Fragments. > > Best, > Jean > > > > >
Re: Override multiple properties in one statement?
Ahanu Banerjee writes: > Hello, > > Is it possible to override or tweak multiple properties of one object at > once, using one statement? i.e., without typing "\tweak" or "\override" > multiple times? (Of course, defining a new function consisting of multiple > statements is possible, but it's not practical when there are many > combinations of properties to change throughout a document.) > > For example: > > \version "2.23.10" > { c > -\tweak outside-staff-priority #'() > -\tweak whiteout ##t > -\tweak Y-offset #0.25 > -\tweak X-offset #1.5 > ^\markup "text" } If the only variable here is "text", you may use mtw = -\tweak outside-staff-priority #'() -\tweak whiteout ##t -\tweak Y-offset #0.25 -\tweak X-offset #1.5 ^ \etc { c\mtw "text" } -- David Kastrup
Re: Override multiple properties in one statement?
Le 30/06/2022 à 22:04, Ahanu Banerjee a écrit : Hello, Is it possible to override or tweak multiple properties of one object at once, using one statement? i.e., without typing "\tweak" or "\override" multiple times? (Of course, defining a new function consisting of multiple statements is possible, but it's not practical when there are many combinations of properties to change throughout a document.) For example: \version "2.23.10" { c -\tweak outside-staff-priority #'() -\tweak whiteout ##t -\tweak Y-offset #0.25 -\tweak X-offset #1.5 ^\markup "text" } You could use \version "2.23.10" alistPropertyTweak = #(define-music-function (tweaks item) (alist? symbol-list-or-music?) (fold (lambda (pair previous) (once (propertyTweak (car pair) (cdr pair) previous))) item tweaks)) { c'1 \alistPropertyTweak #'((outside-staff-priority . ()) (whiteout . #t) (Y-offset . 0.25) (X-offset . 1.5)) ^"text" \once \alistPropertyTweak #'((outside-staff-priority . ()) (whiteout . #t) (Y-offset . 0.25) (X-offset . 1.5)) TextScript c'^"text" } On the other hand, this may not necessarily be overly practical because in order to write any values in LilyPond syntax, you have to replace the quote ' with a backquote ` and use ,#{ #} to write LilyPond code. For example: { c'\alistPropertyTweak #`((text . ,#{ \markup \bold "a" #})) ^"b" } Compare with { c'\tweak text \markup \bold "a" ^"b" } Ultimately, I think it is wiser to use \tweak or \override explicitly. That's of course up to you though. By the way, in Frescobaldi, you have an interface for defining snippets that are convenient to insert, in Tools > Coding > Fragments. Best, Jean
Override multiple properties in one statement?
Hello, Is it possible to override or tweak multiple properties of one object at once, using one statement? i.e., without typing "\tweak" or "\override" multiple times? (Of course, defining a new function consisting of multiple statements is possible, but it's not practical when there are many combinations of properties to change throughout a document.) For example: \version "2.23.10" { c -\tweak outside-staff-priority #'() -\tweak whiteout ##t -\tweak Y-offset #0.25 -\tweak X-offset #1.5 ^\markup "text" } Thanks, -Ahanu
Re: \override multiple properties?
Aaron Hill writes: > On 2020-02-02 2:26 am, David Kastrup wrote: >> Aaron Hill writes: >> >>> Music functions certainly give you the most flexibility, although >>> there are simple cases where you can use 2.19's \etc keyword as a >>> shorthand to defining the function yourself: >>> >>> \version "2.19" >>> stemColor = \override Stem.color = \etc >>> { d'8 \stemColor #red e' f' \undo \stemColor ##f g' } >>> >>> Note the \undo command above is less ideal as one needs to provide >>> a >>> dummy argument to the function. >> Why not \undo \stemColor #red here ? ##f makes no sense. > > I did not want to give the impression that the arguments *had* to > match. One could just as easily say \undo \stemColor #blue and get > the same outcome. \undo only seems to care about which properties are > \overridden, not the specific values. So the argument to the music > function in this case does not matter. My choice of "false" was > purely arbitrary, but I guess it was too confusing. > > A scenario where the mismatch would make sense is using the function > several times in a row: > > > { d \stemColor #red e f \stemColor #blue g a > \stemColor #green f c \undo \stemColor #'() d } > > > This pattern reinforces that it is not required to \undo each > application of the function. That's just because you have not been using \temporary \stemColor here. Non-\temporary overrides implicitly cancel the last existing override at that level, so \undo \stemColor #green would be "correct" here. The principal purpose of \undo is that it works even if you don't know the details involved, so it seems self-defeating to use it in a manner relying on knowing the details. > If \undo \stemColor #'() proves to be undesirable, nothing stops a > user just doing the \undo by hand with a manual \revert Stem.color or > a suitably-defined \noStemColor. Again, \undo is for those occasions where you are not really interested in the details. It's always equivalent to something explicit, of course. If you write stemColor = \override Stem.color = \etc \void \displayLilyMusic \undo \stemColor #red you get the output lilypond /tmp/baba.ly GNU LilyPond 2.21.0 Processing `/tmp/baba.ly' Parsing... \revert Stem.color And there is nothing wrong with that. -- David Kastrup
Re: \override multiple properties?
On 2020-02-02 2:26 am, David Kastrup wrote: Aaron Hill writes: Music functions certainly give you the most flexibility, although there are simple cases where you can use 2.19's \etc keyword as a shorthand to defining the function yourself: \version "2.19" stemColor = \override Stem.color = \etc { d'8 \stemColor #red e' f' \undo \stemColor ##f g' } Note the \undo command above is less ideal as one needs to provide a dummy argument to the function. Why not \undo \stemColor #red here ? ##f makes no sense. I did not want to give the impression that the arguments *had* to match. One could just as easily say \undo \stemColor #blue and get the same outcome. \undo only seems to care about which properties are \overridden, not the specific values. So the argument to the music function in this case does not matter. My choice of "false" was purely arbitrary, but I guess it was too confusing. A scenario where the mismatch would make sense is using the function several times in a row: { d \stemColor #red e f \stemColor #blue g a \stemColor #green f c \undo \stemColor #'() d } This pattern reinforces that it is not required to \undo each application of the function. If \undo \stemColor #'() proves to be undesirable, nothing stops a user just doing the \undo by hand with a manual \revert Stem.color or a suitably-defined \noStemColor. -- Aaron Hill
Re: \override multiple properties?
Aaron Hill writes: > Music functions certainly give you the most flexibility, although > there are simple cases where you can use 2.19's \etc keyword as a > shorthand to defining the function yourself: > > > \version "2.19" > > stemColor = \override Stem.color = \etc > > { d'8 \stemColor #red e' f' \undo \stemColor ##f g' } > > > Note the \undo command above is less ideal as one needs to provide a > dummy argument to the function. Why not \undo \stemColor #red here ? ##f makes no sense. -- David Kastrup
Re: \override multiple properties?
On 2020-02-01 6:46 pm, Bric wrote: In my case i am needing to override a series of notes and then revert. (So, don't want to use "\once"). I have already used your construct, coupling it with reverting directives grouped the same way (with a named group): emphasizeStem = { \override Stem.thickness = #3.0 \override Stem.color = #'(0.5 0.3 0.2) } revertStem = { \revert Stem.thickness \revert Stem.color } The \undo command can be useful to avoid needing to individually \revert: { d'8 \emphasizeStem d' e' f' \undo \emphasizeStem g'4 d' } What would be nice is be able to parametrize those blocks somehow But, i guess, that can only be done with a Scheme function? I'm shaky on scheme. Music functions certainly give you the most flexibility, although there are simple cases where you can use 2.19's \etc keyword as a shorthand to defining the function yourself: \version "2.19" stemColor = \override Stem.color = \etc { d'8 \stemColor #red e' f' \undo \stemColor ##f g' } Note the \undo command above is less ideal as one needs to provide a dummy argument to the function. Here would be one way to parameterize \emphasizeStem: \version "2.19" emphasizeStem = #(define-music-function (thickness color) ((number? 3) color?) #{ \override Stem.thickness = #thickness \override Stem.color = #color #}) { \emphasizeStem #red d'8 e'4 \emphasizeStem 6 #blue f'2 } The above demonstrates how the first argument could be made optional. -- Aaron Hill
Re: \override multiple properties?
> On February 1, 2020 at 7:06 PM Aaron Hill wrote: > related \overrides into their own music variable or function, if there > needs to be some parameterization: > > > \version "2.18" > > emphasizeStem = { >\override Stem.thickness = #3.0 >\override Stem.color = #'(0.5 0.3 0.2) > } > > % . . . > \new Voice \with { \emphasizeStem } { b'4 c''2. } > % . . . > \new Voice { e'8 g' \once \emphasizeStem f'4 a'2 } > % . . . > > > Grouping related \overrides together in a well-named variable promotes > readability, reusability and maintainability. As an added bonus, \once > can be used with the variable without needing to apply it to every > \override. In my case i am needing to override a series of notes and then revert. (So, don't want to use "\once"). I have already used your construct, coupling it with reverting directives grouped the same way (with a named group): emphasizeStem = { \override Stem.thickness = #3.0 \override Stem.color = #'(0.5 0.3 0.2) } revertStem = { \revert Stem.thickness \revert Stem.color } Then i mark up a set of notes with the above two, as start and end markers, like so: e'8 \emphasizeStem gis'' cis'' e'' dis'' \revertStem fis'' What would be nice is be able to parametrize those blocks somehow But, i guess, that can only be done with a Scheme function? I'm shaky on scheme.
Re: \override multiple properties?
On 2020-02-01 7:54 am, David Kastrup wrote: Bric writes: Is it possible to override multiple with just one "\override" directive? something like this (wrong syntax): \override { Voice.Stem.thickness = #3.0 Voice.Stem.color = #(rgb-color 0.3 0.1 0.1) } to reduce redundant syntax, if one had to override many at once. No. It's not like the savings in this case would be overwhelming. To that point, the better and already existing solution is to move these related \overrides into their own music variable or function, if there needs to be some parameterization: \version "2.18" emphasizeStem = { \override Stem.thickness = #3.0 \override Stem.color = #'(0.5 0.3 0.2) } % . . . \new Voice \with { \emphasizeStem } { b'4 c''2. } % . . . \new Voice { e'8 g' \once \emphasizeStem f'4 a'2 } % . . . Grouping related \overrides together in a well-named variable promotes readability, reusability and maintainability. As an added bonus, \once can be used with the variable without needing to apply it to every \override. -- Aaron Hill
Re: \override multiple properties?
Bric writes: > The documentation examples are showing single property overrides, like so: > > \override Voice.Stem.thickness = #3.0 > > Is it possible to override multiple with just one "\override" directive? > > something like this (wrong syntax): > > \override { Voice.Stem.thickness = #3.0 > Voice.Stem.color = #(rgb-color 0.3 0.1 0.1) > } > > > to reduce redundant syntax, if one had to override many at once. No. It's not like the savings in this case would be overwhelming. -- David Kastrup
\override multiple properties?
The documentation examples are showing single property overrides, like so: \override Voice.Stem.thickness = #3.0 Is it possible to override multiple with just one "\override" directive? something like this (wrong syntax): \override { Voice.Stem.thickness = #3.0 Voice.Stem.color = #(rgb-color 0.3 0.1 0.1) } to reduce redundant syntax, if one had to override many at once.