lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Coloring note heads by pitch


From: Chris Angelico
Subject: Re: Coloring note heads by pitch
Date: Tue, 3 Nov 2009 16:36:51 +1100

On Tue, Nov 3, 2009 at 6:27 AM, Trevor Daniels <address@hidden> wrote:
> Hi Chris
>
> Does the example in the Learning Manual help? I think it does exactly what
> you want. See section 4.6.6.
>
> Trevor

Strange. I just looked up the manual, and it doesn't HAVE a section
4.6.6... and then found out why. Seems that when you google for
'lilypond learning manual', the first hit is an older version. This is
most peculiar, but it explains why I've been having trouble!

Very interesting there. I had no idea I could /override with a
function - guess that's obvious to anyone who's familiar with Scheme
though! I've made some changes to the code, and now it looks like
this:

% override a couple colors to make them match our bells
orange =3D #(rgb-color 1 0.5 0)
yellow =3D #(rgb-color 1 1 0)

% Taken straight from the docs and then tweaked very slightly
#(define (bell-color grob)
    "Color the notehead according to its position on the staff."
    (case (ly:grob-property grob 'staff-position)
      ; Why these aren't 1-8 I'm not wholly sure
      ((-6) red      )  ; for C
      ((-5) orange   )  ; for D
      ((-4) yellow   )  ; for E
      ((-3) green    )  ; for F
      ((-2) darkgreen)  ; for G
      ((-1) cyan     )  ; for A
      (( 0) darkblue )  ; for B
      (( 1) magenta  )  ; for >C
    )
)

\score {
    <<
        \new Staff <<
            \key c \major
            \time 3/4
            \tempo "" 4 =3D 120
            \new Voice \relative c' {
                \stemUp
                s2
                % Arrange to obtain color from procedure above
                \override NoteHead #'color =3D #bell-color
                \override Stem #'color =3D #bell-color
                c8(d8) e2 e4 g4.(f8) e4 d4.(e8) f4 e2
                r4
            }
        >>
    >>
    \layout { }
}


This is working perfectly (and leaving black any note outside the
range we can render) on the note heads. I guess it's not worth trying
to color the stems as well? It doesn't seem to work, which I think
might be because the stems don't have a staff-position attribute.

Many thanks for the help! Knew I could rely on you :)

ChrisA




reply via email to

[Prev in Thread] Current Thread [Next in Thread]