Lilypond Music einfärben

Zur Navigation springen Zur Suche springen
Alle Objekte einer Stimme einfärben (Noten, Bögen, ...)

Scheme-Code

#(ly:load "x11-color.scm")

colorGrob =
#(define-music-function (my-grob my-color color-on)
   (symbol? color? boolean?)
   ;; check for the boolean argument
   (if color-on
       ;; either set the color for the grob type
       #{
         \temporary \override #my-grob #'color = #my-color
       #}
       ;; or revert it
       #{
         \revert #my-grob #'color
       #}))

colorGrobs =
#(define-music-function (my-grob-list my-color color-on)
   (symbol-list? color? boolean?)
   (if (null? my-grob-list)
       ;; issue an empty music expression
       #{ #}
       #{
         % color the first grob type of the current list
         \colorGrob #(car my-grob-list) #my-color #color-on
         % recursively call itself with the remainder
         % of the current list.
         \colorGrobs #(cdr my-grob-list) #my-color #color-on
       #}))

allGrobNames =
#(define-scheme-function (parser location)()
   ;; create a list with all grob names from LilyPond
   (map (lambda (gd) (car gd)) all-grob-descriptions))

colorMusic =
#(define-music-function (my-color music)
   (color? ly:music?)
   #{
     \colorGrobs \allGrobNames #my-color ##t
     #music
     \colorGrobs \allGrobNames #my-color ##f
   #})

Anwendung

\version "2.20.0"
\language "deutsch"

\relative c' {
  c4 d e f \colorMusic #green { g4( a h) c }
  \colorMusic #(x11-color 'DodgerBlue) { h16-\f a f4. g2-> }
  \colorMusic #red { c1 }
}

Graphische Ausgabe

ColorMusic.png

Links