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