lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Override multiple properties in one statement?


From: Ahanu Banerjee
Subject: Re: Override multiple properties in one statement?
Date: Thu, 30 Jun 2022 19:25:40 -0400

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 <jean@abou-samra.fr> 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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]