10.04.2013 Views

in Snippets - LilyPond

in Snippets - LilyPond

in Snippets - LilyPond

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Pitches 6<br />

Color<strong>in</strong>g notes depend<strong>in</strong>g on their pitch<br />

It is possible to color note heads depend<strong>in</strong>g on their pitch and/or their names: the function used<br />

<strong>in</strong> this example even makes it possible to dist<strong>in</strong>guish enharmonics.<br />

%Association list of pitches to colors.<br />

#(def<strong>in</strong>e color-mapp<strong>in</strong>g<br />

(list<br />

(cons (ly:make-pitch 0 0 NATURAL) (x11-color 'red))<br />

(cons (ly:make-pitch 0 0 SHARP) (x11-color 'green))<br />

(cons (ly:make-pitch 0 1 FLAT) (x11-color 'green))<br />

(cons (ly:make-pitch 0 2 NATURAL) (x11-color 'red))<br />

(cons (ly:make-pitch 0 2 SHARP) (x11-color 'green))<br />

(cons (ly:make-pitch 0 3 FLAT) (x11-color 'red))<br />

(cons (ly:make-pitch 0 3 NATURAL) (x11-color 'green))<br />

(cons (ly:make-pitch 0 4 SHARP) (x11-color 'red))<br />

(cons (ly:make-pitch 0 5 NATURAL) (x11-color 'green))<br />

(cons (ly:make-pitch 0 5 FLAT) (x11-color 'red))<br />

(cons (ly:make-pitch 0 6 SHARP) (x11-color 'red))<br />

(cons (ly:make-pitch 0 1 NATURAL) (x11-color 'blue))<br />

(cons (ly:make-pitch 0 3 SHARP) (x11-color 'blue))<br />

(cons (ly:make-pitch 0 4 FLAT) (x11-color 'blue))<br />

(cons (ly:make-pitch 0 5 SHARP) (x11-color 'blue))<br />

(cons (ly:make-pitch 0 6 FLAT) (x11-color 'blue))))<br />

%Compare pitch and alteration (not octave).<br />

#(def<strong>in</strong>e (pitch-equals? p1 p2)<br />

(and<br />

(= (ly:pitch-alteration p1) (ly:pitch-alteration p2))<br />

(= (ly:pitch-notename p1) (ly:pitch-notename p2))))<br />

#(def<strong>in</strong>e (pitch-to-color pitch)<br />

(let ((color (assoc pitch color-mapp<strong>in</strong>g pitch-equals?)))<br />

(if color<br />

(cdr color))))<br />

#(def<strong>in</strong>e (color-notehead grob)<br />

(pitch-to-color<br />

(ly:event-property (event-cause grob) 'pitch)))<br />

\score {<br />

\new Staff \relative c' {<br />

\override NoteHead #'color = #color-notehead<br />

c8 b d dis ees f g aes<br />

}<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!