LSR: Update.
[lilypond.git] / input / lsr / coloring-notes-depending-on-their-pitch.ly
blob96608ab8f87d2ab2a545188cc4055cbfb2f01df6
1 %% Do not edit this file; it is auto-generated from input/new
2 %% This file is in the public domain.
3 %% Note: this file works from version 2.12.0
4 \version "2.13.1"
5 \header {
6 lsrtags = "pitches,editorial-annotations,really-cool"
7 texidoc = "
8 It is possible to color note heads depending on their pitch and/or their names:
9 the function used in this example even makes it possible to distinguish enharmonics.
11 doctitle = "Coloring notes depending on their pitch"
12 } % begin verbatim
14 %Association list of pitches to colors.
15 #(define color-mapping
16 (list
17 (cons (ly:make-pitch 0 0 0) (x11-color 'red))
18 (cons (ly:make-pitch 0 0 1/2) (x11-color 'green))
19 (cons (ly:make-pitch 0 1 -1/2) (x11-color 'green))
20 (cons (ly:make-pitch 0 2 0) (x11-color 'red))
21 (cons (ly:make-pitch 0 2 1/2) (x11-color 'green))
22 (cons (ly:make-pitch 0 3 -1/2) (x11-color 'red))
23 (cons (ly:make-pitch 0 3 0) (x11-color 'green))
24 (cons (ly:make-pitch 0 4 1/2) (x11-color 'red))
25 (cons (ly:make-pitch 0 5 0) (x11-color 'green))
26 (cons (ly:make-pitch 0 5 -1/2) (x11-color 'red))
27 (cons (ly:make-pitch 0 6 1/2) (x11-color 'red))
28 (cons (ly:make-pitch 0 1 0) (x11-color 'blue))
29 (cons (ly:make-pitch 0 3 1/2) (x11-color 'blue))
30 (cons (ly:make-pitch 0 4 -1/2) (x11-color 'blue))
31 (cons (ly:make-pitch 0 5 1/2) (x11-color 'blue))
32 (cons (ly:make-pitch 0 6 -1/2) (x11-color 'blue))
35 %Compare pitch and alteration (not octave).
36 #(define (pitch-equals? p1 p2)
37 (and
38 (= (ly:pitch-alteration p1) (ly:pitch-alteration p2))
39 (= (ly:pitch-notename p1) (ly:pitch-notename p2))))
41 #(define (pitch-to-color pitch)
42 (let ((color (assoc pitch color-mapping pitch-equals?)))
43 (if color
44 (cdr color))))
46 #(define (color-notehead grob)
47 (pitch-to-color
48 (ly:event-property (ly:grob-property grob 'cause) 'pitch)))
50 \score {
51 \new Staff \relative c' {
52 \override NoteHead #'color = #color-notehead
53 c8 b d dis ees f g aes