lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: color notehead according to absolute pitch


From: Jay Anderson
Subject: Re: color notehead according to absolute pitch
Date: Sun, 10 Aug 2008 04:59:29 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Damian leGassick <damianlegassick <at> mac.com> writes:
> my own needs are for (e.g.) all d-sharps/e-flats/e-naturals/f-flats to  
> be red etc (parsing webern with hexatonic/octatonic scales for  
> analysis students)

You can do a very similar thing:

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]