Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing all the colors in Lilypond

In Lilypond I can change the color of one type of object with a line like

\override Staff.Clef #'color = #(rgb-color 0.4 0.5 0.6)

I'd like to have everything in the same (non-default) color, but I neither found a list of all the objects I could color nor did I find a command to change all the colors at once. Could anybody please point me to either?

like image 676
Martin Küttler Avatar asked Mar 20 '11 17:03

Martin Küttler


2 Answers

The LilyPond Snippet Repository has a solution that iterates through the list of objects contained in all-grob-descriptions:

#(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)))))))

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

Note that this will change the color of every graphical object only if you run it in the proper context (Score, I think, will generally suffice), so you may need to do the following if you're in the middle of, say, a Voice context:

\stopStaff
\context Score
\applyContext #(override-color-for-all-grobs (x11-color 'blue))
\startStaff
like image 125
Kennis Koldewyn Avatar answered Nov 20 '22 15:11

Kennis Koldewyn


The list of graphical objects you need is at the bottom of this page. So a simple albeit tedious approach would be to iterate through all those objects you use, e.g.

\override Staff.Clef     #'color = #(rgb-color 0.4 0.5 0.6)
\override Staff.NoteHead #'color = #(rgb-color 0.4 0.5 0.6)
\override Staff.Beam     #'color = #(rgb-color 0.4 0.5 0.6)
\override Staff.Slur     #'color = #(rgb-color 0.4 0.5 0.6)

etc.

There's probably a much better way but I can't figure it out. Alternatively, as has been suggested before you could consider doing some post-processing on the output from Lilypond, which may be simpler depending on the tools you have available.

I strongly recommend that you read the excellent documentation, in particular how to navigate the Internals Reference as covered by the Learning Manual and the Notation Reference

Also you may obtain a better answer from the lilypond-user mailing list.

like image 36
Adam Spiers Avatar answered Nov 20 '22 16:11

Adam Spiers