English 中文(简体)
Coloring notes in Lilypond by pitch
原标题:

lilypond can color notes in a arbitrary way using

override NoteHead # color = #red c

with the default color is black. But I like to color all notes by pitch, so that my kids can more easily learn to recognize the notes as the c, d, e, f, ... are associated with its own color. The above allows me to do this, but is rather verbose.

Is there a shortcut, macros of some sort, that allow me to do something along the lines of:

redc greend bluee

or even overwriting the default colors for each note by pitch so that I can even simply do:

c d e

and have each of them have a different color?

最佳回答

There is an example for this in the snippets:

%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 {
  
ew Staff 
elative c  {
    override NoteHead # color = #color-notehead
    c8 b d dis ees f g aes
  }
}

Sample image

问题回答

There s a question It is possible to color note heads depending on their pitch? at the LilyPond Snippet Repository. You get the answer by clicking on the stave.

OK, for the book Kid s Keyboard Course - Book #1 I bought earlier this year in Cambridge, I now have this color coding:

#(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))))




相关问题
Lilypond snippet for a separate coda

我不希望李利美,不要在乐团音乐的不常见之处,而是从狙击手存放处失踪,而不要看我的搜索词。 它基本上是除......外被 co死的 block脚石。

Shell Script to typeset Lilypond files with Textwrangler

I need a shell script which will allow me to typeset Lilypond files from TextWrangler (A Mac App). So far I have come up with this: #!/bin/sh /Applications/LilyPond.app/Contents/Resources/bin/...

Changing all the colors in Lilypond

In Lilypond I can change the color of one type of object with a line like override Staff.Clef # color = #(rgb-color 0.4 0.5 0.6) I d like to have everything in the same (non-default) color, but I ...

Lilypond Mac OS X build issue

I am trying to do a clean build of Lilypond on a clean install of Mac OS X. Dependencies have been installed using Brew. I do ./configure && make all in the Lilypond dir. It gets through the ...

Lilypond: Customize bar lines, recursively, automatically?

I m working on Carnatic music scores that involve complex time signatures, that will require modified bar lines Pattern for barlines for: 8/4 beats: 1 2 3 4 (dashed bar here) 5, 6 (Dotted Bar) 7, ...

Coloring notes in Lilypond by pitch

lilypond can color notes in a arbitrary way using override NoteHead # color = #red c with the default color is black. But I like to color all notes by pitch, so that my kids can more easily learn ...

热门标签