int(0) Applying tweaks to one voice in \partCombine - LilyPond wiki Jump to content

Applying tweaks to one voice in \partCombine

From LilyPond wiki

When using \partCombine, commands applying to a Voice context affect both parts since when are merged in the same Voice. This snippet defines a music function to apply tweaks to all elements of a certain kind in a music expression. This can be used to apply modifications to all grobs caused by elements of a music expression regardless of the context structure. Possible values for the event-class argument are listed at the Internals Reference

\version "2.24.0"

%% Original thread: https://lists.gnu.org/archive/html/lilypond-user/2021-06/msg00242.html

\paper { tagline = ##f }

tweakEverywhere =
#(define-music-function (parser location event-class property value music)
                        (symbol? symbol-list-or-symbol? scheme? ly:music?)
     (for-some-music
        (lambda (m)
           (if (music-is-of-type? m event-class)
                 (begin
                    (set! (ly:music-property m 'tweaks)
                             (cons (cons
                                     (if (symbol? property)
                                         property
                                         (apply cons* property))
                                     value)
                                   (ly:music-property m 'tweaks)))
                    #t)
                 #f))
        music)
     music)

soprano = { des' ees' fes' ges' fes' ges' aes' bes' }
tenor = { des' ees' fes' ges' des' ees' fes' ges' }

% Replace with \partCombineUp (uppercase C) in version 2.20 and later.
\partCombineUp \soprano \tweakEverywhere rhythmic-event font-size -3 \tenor
\partCombineUp \soprano \tweakEverywhere note-event Accidental.color #red \tenor