Jump to content

Setting a color for all staff objects automatically (obsolete in 2.25)

From LilyPond wiki
(Redirected from LSR 443)

To color all objects on a staff is a laborious task. However, this can be automated by using some Scheme code to access the list of objects contained in all-grob-descriptions. All graphical objects which live in the Staff context can then be colored by setting their color property.

This snippet is obsolete in LilyPond 2.25, which introduces a much simpler method:

\layout { property-defaults.color = "blue" }

\version "2.24"

%% http://lsr.di.unimi.it/LSR/Item?id=443

#(define (override-color-for-all-grobs color)
  (lambda (context)
   (let loop ((x all-grob-descriptions))
    (if (not (null? x))
     (let ((grob-name (caar x)))
      (ly:context-pushpop-property context grob-name 'color color)
      (loop (cdr x)))))))

\relative c' {
  \applyContext #(override-color-for-all-grobs (x11-color 'blue))
  c4\pp\< d e f
  \grace { g16[( a g fis]) } g1\ff\!
}