2013/04/20

coloring notes



\version "2.16.0"

#(define-public ((color-notehead nnn) grob)
   
   (define color-mapping
     (vector
      (list
       (cons (ly:make-pitch 0 0 0) (rgb-color 1 .5 0))
       (cons (ly:make-pitch 0 4 0) (rgb-color .3 .7 0))
       )
      (list
       (cons (ly:make-pitch 0 1 0) (rgb-color 1 0 1))
       (cons (ly:make-pitch 0 5 0) (rgb-color .5 0 1))
       )
      )
     )
   
   (define (pitch-to-color pitch)
     (let*
      (
       (vvv (vector-ref color-mapping nnn))
       (ccc (assoc pitch vvv))
       )
      (if ccc
          (cdr ccc))
      )
     )
   
   (pitch-to-color
    (ly:event-property (event-cause grob) 'pitch))
   )

aaa = \relative c' { c8 d e f g a b c }

\score {
  <<
    \new Staff <<
      \override Staff.NoteHead #'color = #(color-notehead 0)
      \aaa
    >>
    \new Staff <<
      \override Staff.NoteHead #'color = #(color-notehead 1)
      \aaa
    >>
  >>
}

cf. Coloring notes depending on their pitch
http://lsr.dsi.unimi.it/LSR/Item?id=572

AddThis