]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/new/numbers-as-easy-note-heads.ly
92850872e741d4f5b33167622b87be7a9492bcf7
[lilypond.git] / Documentation / snippets / new / numbers-as-easy-note-heads.ly
1 \version "2.13.36"
2
3 \header {
4   lsrtags = "pitches"
5   texidoc = "
6 Easy notation note heads use the @code{note-names} property
7 of the @code{NoteHead} object to determine what appears inside
8 the note head.  By overriding this property, it is possible
9 to print numbers representing the scale-degree.
10
11 A simple engraver can be created to do this for every note head
12 object it sees.
13 "
14   doctitle = "Numbers as easy note heads"
15 }
16
17 #(define Ez_numbers_engraver
18    (list
19     (cons 'acknowledgers
20           (list
21            (cons 'note-head-interface
22                  (lambda (engraver grob source-engraver)
23                    (let* ((context (ly:translator-context engraver))
24                           (tonic-pitch (ly:context-property context 'tonic))
25                           (tonic-name (ly:pitch-notename tonic-pitch))
26                           (grob-pitch
27                            (ly:event-property (event-cause grob) 'pitch))
28                           (grob-name (ly:pitch-notename grob-pitch))
29                           (delta (modulo (- grob-name tonic-name) 7))
30                           (note-names
31                            (make-vector 7 (number->string (1+ delta)))))
32                      (ly:grob-set-property! grob 'note-names note-names))))))))
33
34 #(set-global-staff-size 26)
35
36 \layout {
37   ragged-right = ##t
38   \context {
39     \Voice
40     \consists \Ez_numbers_engraver
41   }
42 }
43
44 \relative c' {
45   \easyHeadsOn
46   c4 d e f
47   g4 a b c \break
48
49   \key a \major
50   a,4 b cis d
51   e4 fis gis a \break
52
53   \key d \dorian
54   d,4 e f g
55   a4 b c d
56 }