]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/coloring-notes-depending-on-their-pitch.ly
062dcea41296ca36d3d24b91ce2634bb416e3136
[lilypond.git] / Documentation / snippets / coloring-notes-depending-on-their-pitch.ly
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
5 %%
6 %% This file is in the public domain.
7 \version "2.14.2"
8
9 \header {
10   lsrtags = "pitches, really-cool, editorial-annotations"
11
12 %% Translation of GIT committish: 1cda7b7b8219cb97399b8e7b56c1115aaf82c002
13   texidocfr = "
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
16 entre enharmoniques.
17
18 "
19   doctitlefr = "Coloration des notes selon leur hauteur"
20
21   texidoc = "
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.
25
26 "
27   doctitle = "Coloring notes depending on their pitch"
28 } % begin verbatim
29
30 %Association list of pitches to colors.
31 #(define color-mapping
32    (list
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))))
49
50 %Compare pitch and alteration (not octave).
51 #(define (pitch-equals? p1 p2)
52    (and
53     (= (ly:pitch-alteration p1) (ly:pitch-alteration p2))
54     (= (ly:pitch-notename p1) (ly:pitch-notename p2))))
55
56 #(define (pitch-to-color pitch)
57    (let ((color (assoc pitch color-mapping pitch-equals?)))
58      (if color
59          (cdr color))))
60
61 #(define (color-notehead grob)
62    (pitch-to-color
63     (ly:event-property (event-cause grob) 'pitch)))
64
65 \score {
66   \new Staff \relative c' {
67     \override NoteHead #'color = #color-notehead
68     c8 b d dis ees f g aes
69   }
70 }
71