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