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: Steven Weber
Subject: RE: Coloring note heads by pitch
Date: Mon, 2 Nov 2009 11:45:16 -0800

Here's a solution I use for "easy" harp music where all C's and F's are red
and blue.  I'm cutting and pasting from several different files, so this
might not be in the right order, but at least it'll give you a good starting
point:

#(define (pitch-to-color pitch)
        (cond
                ((eqv? (ly:pitch-notename pitch) 0) (x11-color 'red))
                ((eqv? (ly:pitch-notename pitch) 3) (x11-color 'RoyalBlue))
        )
)

#(define (color-notehead-harp grob)
        "Color the notehead according to its pitch."
        (pitch-to-color (ly:event-property (ly:grob-property grob 'cause)
'pitch)))

\layout
{
        % Define the EasyHarpStaff context
        \context
        {
                \PianoStaff
                \type "Engraver_group"
                \name EasyHarpStaff
                \alias PianoStaff
                
                % Color C's red and F's blue
                \override NoteHead #'color = #color-notehead-harp
        }

        % Add EasyHarpStaff to Score
        \context
        {
                \Score
                \accepts EasyHarpStaff
        }
}

\score
{
        \new EasyHarpStaff
        <<
                c4 d e f |
                g a b c' |
        >>
}

--Steven

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Chris Angelico
Sent: Monday, November 02, 2009 11:05 AM
To: address@hidden
Subject: Coloring note heads by pitch

I've spent some time trying to figure this out, and I'm certain it's
possible; the only question is, what's the cleanest way to do it?

I want to print out score with each note color coded (middle C in red,
D in orange, E in green) to match a set of bells. Currently, I have a
fairly straightforward setup, but exceedingly tedious: identify the
bell AND give the music expression. What I'd like to do is make it
that I can simply key in the music as is, and then have some
scriptwork figure out what color to make each one based on its
staffposition.

Current code:

% Is there an alternative to this shocking editor inheritance?
bell = #(define-music-function (parser location bellnum mus) (integer?
ly:music?)
    (if (eq? bellnum 1) #{ \once \override NoteHead #'color = #red
  \once \override Stem #'color = #red       $mus #}
    (if (eq? bellnum 2) #{ \once \override NoteHead #'color = #orange
  \once \override Stem #'color = #orange    $mus #}
    (if (eq? bellnum 3) #{ \once \override NoteHead #'color = #yellow
  \once \override Stem #'color = #yellow    $mus #}
    (if (eq? bellnum 4) #{ \once \override NoteHead #'color = #green
  \once \override Stem #'color = #green     $mus #}
    (if (eq? bellnum 5) #{ \once \override NoteHead #'color =
#darkgreen \once \override Stem #'color = #darkgreen $mus #}
    (if (eq? bellnum 6) #{ \once \override NoteHead #'color = #cyan
  \once \override Stem #'color = #cyan      $mus #}
    (if (eq? bellnum 7) #{ \once \override NoteHead #'color =
#darkblue  \once \override Stem #'color = #darkblue  $mus #}
    (if (eq? bellnum 8) #{ \once \override NoteHead #'color = #magenta
  \once \override Stem #'color = #magenta   $mus #}
    #{ #}
    )))))))))



... and inside the Voice:
                % Every note must be entered as a bell identifier (#1
being the lowest bell, and #8 being the highest),
                % in addition to its note definition.
                s2
                \bell #1 c8(
                \bell #2 d8)
                \bell #3 e2
                \bell #3 e4
                \bell #5 g4.(
                \bell #4 f8)
                \bell #3 e4
                \bell #2 d4.(
                \bell #3 e8)
                \bell #4 f4
                \bell #3 e2
                r4

This is tedious and error-prone, as I have to give all information
twice. I'm pretty certain that my failure is due to my lack of
knowledge of the system, and that the experts on this list will be
able to offer a solution - maybe there's one already built and ready!

ChrisA
Hopeful in the trusting, rather than futile, sense! :)


_______________________________________________
lilypond-user mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/lilypond-user





reply via email to

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