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