Notes de coloriage dans LilyPond par pitch
-
19-09-2019 - |
Question
lilypond Les notes de couleur peuvent-elles de manière arbitraire utilisant
\override NoteHead #'color = #red c
avec la couleur par défaut est noir. Mais j'aime colorer toutes les notes par pitch, afin que mes enfants puissent plus facilement apprendre à reconnaître les notes car les C, D, E, F, ... sont associés à sa propre couleur. Ce qui précède me permet de le faire, mais est plutôt verbeux.
Y a-t-il un raccourci, des macros en quelque sorte, qui me permettent de faire quelque chose dans le sens de:
redc greend bluee
ou même écraser les couleurs par défaut pour chaque note par pitch afin que je puisse même faire:
c d e
Et chacun d'eux a-t-il une couleur différente?
La solution
Il y en a un exemple dans le extraits:
%Association list of pitches to colors.
#(define color-mapping
(list
(cons (ly:make-pitch 0 0 0) (x11-color 'red))
(cons (ly:make-pitch 0 0 1/2) (x11-color 'green))
(cons (ly:make-pitch 0 1 -1/2) (x11-color 'green))
(cons (ly:make-pitch 0 2 0) (x11-color 'red))
(cons (ly:make-pitch 0 2 1/2) (x11-color 'green))
(cons (ly:make-pitch 0 3 -1/2) (x11-color 'red))
(cons (ly:make-pitch 0 3 0) (x11-color 'green))
(cons (ly:make-pitch 0 4 1/2) (x11-color 'red))
(cons (ly:make-pitch 0 5 0) (x11-color 'green))
(cons (ly:make-pitch 0 5 -1/2) (x11-color 'red))
(cons (ly:make-pitch 0 6 1/2) (x11-color 'red))
(cons (ly:make-pitch 0 1 0) (x11-color 'blue))
(cons (ly:make-pitch 0 3 1/2) (x11-color 'blue))
(cons (ly:make-pitch 0 4 -1/2) (x11-color 'blue))
(cons (ly:make-pitch 0 5 1/2) (x11-color 'blue))
(cons (ly:make-pitch 0 6 -1/2) (x11-color 'blue))
))
%Compare pitch and alteration (not octave).
#(define (pitch-equals? p1 p2)
(and
(= (ly:pitch-alteration p1) (ly:pitch-alteration p2))
(= (ly:pitch-notename p1) (ly:pitch-notename p2))))
#(define (pitch-to-color pitch)
(let ((color (assoc pitch color-mapping pitch-equals?)))
(if color
(cdr color))))
#(define (color-notehead grob)
(pitch-to-color
(ly:event-property (ly:grob-property grob 'cause) 'pitch)))
\score {
\new Staff \relative c' {
\override NoteHead #'color = #color-notehead
c8 b d dis ees f g aes
}
}
Autres conseils
Il y a une question Il est possible de colorer les têtes de note en fonction de leur terrain? au Référentiel de l'extrait de LilyPond. Vous obtenez la réponse en cliquant sur le stave.
Ok, pour le livre Cours de clavier pour enfants - Livre n ° 1 J'ai acheté plus tôt cette année à Cambridge, j'ai maintenant ce codage couleur:
#(define color-mapping
(list
(cons (ly:make-pitch 0 0 0) (x11-color 'magenta))
(cons (ly:make-pitch 0 1 -1/2) (x11-color 'grey))
(cons (ly:make-pitch 0 1 0) (x11-color 'grey))
(cons (ly:make-pitch 0 1 1/2) (x11-color 'grey))
(cons (ly:make-pitch 0 2 0) (x11-color 'red))
(cons (ly:make-pitch 0 2 1/2) (x11-color 'red))
(cons (ly:make-pitch 0 3 -1/2) (x11-color 'green))
(cons (ly:make-pitch 0 3 0) (x11-color 'green))
(cons (ly:make-pitch 0 4 -1/2) (x11-color 'blue))
(cons (ly:make-pitch 0 4 0) (x11-color 'blue))
(cons (ly:make-pitch 0 4 1/2) (x11-color 'blue))
(cons (ly:make-pitch 0 5 0) (x11-color 'yellow))
(cons (ly:make-pitch 0 5 -1/2) (x11-color 'yellow))
(cons (ly:make-pitch 0 5 1/2) (x11-color 'yellow))
(cons (ly:make-pitch 0 6 1/2) (x11-color 'purple))
(cons (ly:make-pitch 0 6 0) (x11-color 'purple))
(cons (ly:make-pitch 0 6 -1/2) (x11-color 'purple))))