1 %% Do not edit this file; it is automatically
2 %% generated from LSR http://lsr.dsi.unimi.it
3 %% This file is in the public domain.
7 lsrtags = "pitches, editorial-annotations"
10 It is possible to color note heads depending on their pitch and/or
11 their names: the function used in this example even makes it possible
12 to distinguish enharmonics.
15 doctitle = "Coloring notes depending on their pitch"
18 %Association list of pitches to colors.
19 #(define color-mapping
21 (cons (ly:make-pitch 0 0 NATURAL) (x11-color 'red))
22 (cons (ly:make-pitch 0 0 SHARP) (x11-color 'green))
23 (cons (ly:make-pitch 0 1 FLAT) (x11-color 'green))
24 (cons (ly:make-pitch 0 2 NATURAL) (x11-color 'red))
25 (cons (ly:make-pitch 0 2 SHARP) (x11-color 'green))
26 (cons (ly:make-pitch 0 3 FLAT) (x11-color 'red))
27 (cons (ly:make-pitch 0 3 NATURAL) (x11-color 'green))
28 (cons (ly:make-pitch 0 4 SHARP) (x11-color 'red))
29 (cons (ly:make-pitch 0 5 NATURAL) (x11-color 'green))
30 (cons (ly:make-pitch 0 5 FLAT) (x11-color 'red))
31 (cons (ly:make-pitch 0 6 SHARP) (x11-color 'red))
32 (cons (ly:make-pitch 0 1 NATURAL) (x11-color 'blue))
33 (cons (ly:make-pitch 0 3 SHARP) (x11-color 'blue))
34 (cons (ly:make-pitch 0 4 FLAT) (x11-color 'blue))
35 (cons (ly:make-pitch 0 5 SHARP) (x11-color 'blue))
36 (cons (ly:make-pitch 0 6 FLAT) (x11-color 'blue))))
38 %Compare pitch and alteration (not octave).
39 #(define (pitch-equals? p1 p2)
41 (= (ly:pitch-alteration p1) (ly:pitch-alteration p2))
42 (= (ly:pitch-notename p1) (ly:pitch-notename p2))))
44 #(define (pitch-to-color pitch)
45 (let ((color (assoc pitch color-mapping pitch-equals?)))
49 #(define (color-notehead grob)
51 (ly:event-property (event-cause grob) 'pitch)))
54 \new Staff \relative c' {
55 \override NoteHead #'color = #color-notehead
56 c8 b d dis ees f g aes