1 %% Do not edit this file; it is auto-generated from input/new
2 %% This file is in the public domain.
5 lsrtags
= "pitches,editorial-annotations,really-cool"
7 It is possible to color note heads depending on their pitch and/or their names:
8 the function used in this example even makes it possible to distinguish enharmonics.
10 doctitle
= "Coloring notes depending on their pitch"
13 %Association list of pitches to colors.
14 #(define color-mapping
16 (cons
(ly
:make-pitch
0 0 0) (x
11-color
'red
))
17 (cons
(ly
:make-pitch
0 0 1/2) (x
11-color
'green
))
18 (cons
(ly
:make-pitch
0 1 -
1/2) (x
11-color
'green
))
19 (cons
(ly
:make-pitch
0 2 0) (x
11-color
'red
))
20 (cons
(ly
:make-pitch
0 2 1/2) (x
11-color
'green
))
21 (cons
(ly
:make-pitch
0 3 -
1/2) (x
11-color
'red
))
22 (cons
(ly
:make-pitch
0 3 0) (x
11-color
'green
))
23 (cons
(ly
:make-pitch
0 4 1/2) (x
11-color
'red
))
24 (cons
(ly
:make-pitch
0 5 0) (x
11-color
'green
))
25 (cons
(ly
:make-pitch
0 5 -
1/2) (x
11-color
'red
))
26 (cons
(ly
:make-pitch
0 6 1/2) (x
11-color
'red
))
27 (cons
(ly
:make-pitch
0 1 0) (x
11-color
'blue
))
28 (cons
(ly
:make-pitch
0 3 1/2) (x
11-color
'blue
))
29 (cons
(ly
:make-pitch
0 4 -
1/2) (x
11-color
'blue
))
30 (cons
(ly
:make-pitch
0 5 1/2) (x
11-color
'blue
))
31 (cons
(ly
:make-pitch
0 6 -
1/2) (x
11-color
'blue
))
34 %Compare pitch and alteration (not octave).
35 #(define
(pitch-equals? p
1 p
2)
37 (= (ly
:pitch-alteration p
1) (ly
:pitch-alteration p
2))
38 (= (ly
:pitch-notename p
1) (ly
:pitch-notename p
2))))
40 #(define
(pitch-to-color pitch
)
41 (let
((color
(assoc pitch color-mapping pitch-equals?
)))
45 #(define
(color-notehead grob
)
47 (ly
:event-property
(ly
:grob-property grob
'cause
) 'pitch
)))
50 \new Staff
\relative c' {
51 \override NoteHead
#'color
= #color-notehead
52 c8 b d dis ees
f g aes