Jump to content

Applying tweaks to one voice in \partCombine: Difference between revisions

From LilyPond wiki
mNo edit summary
mNo edit summary
 
Line 1: Line 1:
When using <code>\partCombine</code>, commands applying to a <code>Voice</code> 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 <code>event-class</code> argument are listed at the [{{LILYSTABLEDOC}}/internals/music-classes Internals Reference]
When using <code>\partCombine</code>, commands applying to a <code>Voice</code> 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 <code>event-class</code> argument are listed at the [{{LILYSTABLEDOC}}/internals/music-classes Internals Reference]


<lilypond version="2.24">
<lilypond version="2.26">
% LSR https://lists.gnu.org/archive/html/lilypond-user/2021-06/msg00242.html
% LSR https://lists.gnu.org/archive/html/lilypond-user/2021-06/msg00242.html


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


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


\partCombineUp \soprano \tweakEverywhere rhythmic-event font-size -3 \tenor
\partCombineUp \soprano
\partCombineUp \soprano \tweakEverywhere note-event Accidental.color #red \tenor
  \tweakEverywhere rhythmic-event font-size -3 \tenor
\partCombineUp \soprano
  \tweakEverywhere note-event Accidental.color #red \tenor
</lilypond>
</lilypond>


[[Category:Simultaneous notes]]
[[Category:Simultaneous notes]]
[[Category:Snippet]]
[[Category:Snippet]]

Latest revision as of 04:32, 6 August 2026

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.26"

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

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' }

\partCombineUp \soprano
  \tweakEverywhere rhythmic-event font-size -3 \tenor
\partCombineUp \soprano
  \tweakEverywhere note-event Accidental.color #red \tenor