8

lilypond可以使用任意方式为音符着色

\override NoteHead #'color = #red c

默认颜色为黑色。但我喜欢按音高给所有音符上色,这样我的孩子们就可以更容易地学会识别音符,因为 c、d、e、f ……与它自己的颜色相关联。以上允许我这样做,但相当冗长。

是否有捷径,某种宏,可以让我按照以下方式做一些事情:

redc greend bluee

甚至按音高覆盖每个音符的默认颜色,这样我什至可以简单地执行以下操作:

c d e

他们每个人都有不同的颜色吗?

4

3 回答 3

12

片段中有一个示例:

%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
  }
}

示例图像

于 2009-12-14T18:27:55.140 回答
3

有一个问题可以根据音高为音符头着色吗?LilyPond Snippet Repository中。您可以通过点击五线谱来获得答案。

于 2009-12-14T18:26:04.240 回答
1

好的,对于我今年早些时候在剑桥买的《儿童键盘课程 - 第一册》这本书,我现在有了这个颜色编码:

#(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))))
于 2009-12-14T18:47:30.273 回答