]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/new/numbers-as-easy-note-heads.ly
Run scripts/auxiliar/update-with-convert-ly.sh
[lilypond.git] / Documentation / snippets / new / numbers-as-easy-note-heads.ly
1 \version "2.16.0"
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    (make-engraver
19     (acknowledgers
20      ((note-head-interface engraver grob source-engraver)
21       (let* ((context (ly:translator-context engraver))
22              (tonic-pitch (ly:context-property context 'tonic))
23              (tonic-name (ly:pitch-notename tonic-pitch))
24              (grob-pitch
25               (ly:event-property (event-cause grob) 'pitch))
26              (grob-name (ly:pitch-notename grob-pitch))
27              (delta (modulo (- grob-name tonic-name) 7))
28              (note-names
29               (make-vector 7 (number->string (1+ delta)))))
30         (ly:grob-set-property! grob 'note-names note-names))))))
31
32 #(set-global-staff-size 26)
33
34 \layout {
35   ragged-right = ##t
36   \context {
37     \Voice
38     \consists \Ez_numbers_engraver
39   }
40 }
41
42 \relative c' {
43   \easyHeadsOn
44   c4 d e f
45   g4 a b c \break
46
47   \key a \major
48   a,4 b cis d
49   e4 fis gis a \break
50
51   \key d \dorian
52   d,4 e f g
53   a4 b c d
54 }