1 %% DO NOT EDIT this file manually; it is automatically
2 %% generated from LSR http://lsr.di.unimi.it
3 %% Make any changes in LSR itself, or in Documentation/snippets/new/ ,
4 %% and then run scripts/auxiliar/makelsr.py
6 %% This file is in the public domain.
10 lsrtags = "editorial-annotations, pitches, really-cool"
13 It is possible to color note heads depending on their pitch and/or
14 their names: the function used in this example even makes it possible
15 to distinguish enharmonics.
18 doctitle = "Coloring notes depending on their pitch"
21 %Association list of pitches to colors.
22 #(define color-mapping
24 (cons (ly:make-pitch 0 0 NATURAL) (x11-color 'red))
25 (cons (ly:make-pitch 0 0 SHARP) (x11-color 'green))
26 (cons (ly:make-pitch 0 1 FLAT) (x11-color 'green))
27 (cons (ly:make-pitch 0 2 NATURAL) (x11-color 'red))
28 (cons (ly:make-pitch 0 2 SHARP) (x11-color 'green))
29 (cons (ly:make-pitch 0 3 FLAT) (x11-color 'red))
30 (cons (ly:make-pitch 0 3 NATURAL) (x11-color 'green))
31 (cons (ly:make-pitch 0 4 SHARP) (x11-color 'red))
32 (cons (ly:make-pitch 0 5 NATURAL) (x11-color 'green))
33 (cons (ly:make-pitch 0 5 FLAT) (x11-color 'red))
34 (cons (ly:make-pitch 0 6 SHARP) (x11-color 'red))
35 (cons (ly:make-pitch 0 1 NATURAL) (x11-color 'blue))
36 (cons (ly:make-pitch 0 3 SHARP) (x11-color 'blue))
37 (cons (ly:make-pitch 0 4 FLAT) (x11-color 'blue))
38 (cons (ly:make-pitch 0 5 SHARP) (x11-color 'blue))
39 (cons (ly:make-pitch 0 6 FLAT) (x11-color 'blue))))
41 %Compare pitch and alteration (not octave).
42 #(define (pitch-equals? p1 p2)
44 (= (ly:pitch-alteration p1) (ly:pitch-alteration p2))
45 (= (ly:pitch-notename p1) (ly:pitch-notename p2))))
47 #(define (pitch-to-color pitch)
48 (let ((color (assoc pitch color-mapping pitch-equals?)))
52 #(define (color-notehead grob)
54 (ly:event-property (event-cause grob) 'pitch)))
57 \new Staff \relative c' {
58 \override NoteHead.color = #color-notehead
59 c8 b d dis ees f g aes