1 %% DO NOT EDIT this file manually; it is automatically
2 %% generated from LSR http://lsr.dsi.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 = "pitches, really-cool, editorial-annotations"
12 %% Translation of GIT committish: 1cda7b7b8219cb97399b8e7b56c1115aaf82c002
14 Les têtes de note peuvent adopter une couleur différenete selon leur
15 hauteur ou leur nom : la fonction utilisée ici fait même la distinction
19 doctitlefr = "Coloration des notes selon leur hauteur"
22 It is possible to color note heads depending on their pitch and/or
23 their names: the function used in this example even makes it possible
24 to distinguish enharmonics.
27 doctitle = "Coloring notes depending on their pitch"
30 %Association list of pitches to colors.
31 #(define color-mapping
33 (cons (ly:make-pitch 0 0 NATURAL) (x11-color 'red))
34 (cons (ly:make-pitch 0 0 SHARP) (x11-color 'green))
35 (cons (ly:make-pitch 0 1 FLAT) (x11-color 'green))
36 (cons (ly:make-pitch 0 2 NATURAL) (x11-color 'red))
37 (cons (ly:make-pitch 0 2 SHARP) (x11-color 'green))
38 (cons (ly:make-pitch 0 3 FLAT) (x11-color 'red))
39 (cons (ly:make-pitch 0 3 NATURAL) (x11-color 'green))
40 (cons (ly:make-pitch 0 4 SHARP) (x11-color 'red))
41 (cons (ly:make-pitch 0 5 NATURAL) (x11-color 'green))
42 (cons (ly:make-pitch 0 5 FLAT) (x11-color 'red))
43 (cons (ly:make-pitch 0 6 SHARP) (x11-color 'red))
44 (cons (ly:make-pitch 0 1 NATURAL) (x11-color 'blue))
45 (cons (ly:make-pitch 0 3 SHARP) (x11-color 'blue))
46 (cons (ly:make-pitch 0 4 FLAT) (x11-color 'blue))
47 (cons (ly:make-pitch 0 5 SHARP) (x11-color 'blue))
48 (cons (ly:make-pitch 0 6 FLAT) (x11-color 'blue))))
50 %Compare pitch and alteration (not octave).
51 #(define (pitch-equals? p1 p2)
53 (= (ly:pitch-alteration p1) (ly:pitch-alteration p2))
54 (= (ly:pitch-notename p1) (ly:pitch-notename p2))))
56 #(define (pitch-to-color pitch)
57 (let ((color (assoc pitch color-mapping pitch-equals?)))
61 #(define (color-notehead grob)
63 (ly:event-property (event-cause grob) 'pitch)))
66 \new Staff \relative c' {
67 \override NoteHead #'color = #color-notehead
68 c8 b d dis ees f g aes