|
From: | Damian leGassick |
Subject: | Re: color notehead according to absolute pitch |
Date: | Sat, 09 Aug 2008 10:56:12 +0100 |
thanks jayit doesn't handle b-sharp yet - but other than that it's pretty compact for absolute pitch
apologies in advance to kenny for slightly hijacking the thread but...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)
i can make it work by modifying your previous suggestion, along these lines:
#(define (pitch-to-color pitch) (cond((and (eqv? (ly:pitch-alteration pitch) 0) (eqv? (ly:pitch-notename pitch) 0)) (x11-color 'red)) ((and (eqv? (ly:pitch-alteration pitch) 1/2) (eqv? (ly:pitch- notename pitch) 0)) (x11-color 'green)) ((and (eqv? (ly:pitch-alteration pitch) -1/2) (eqv? (ly:pitch- notename pitch) 1)) (x11-color 'green)) ((and (eqv? (ly:pitch-alteration pitch) 0) (eqv? (ly:pitch-notename pitch) 2)) (x11-color 'red)) ((and (eqv? (ly:pitch-alteration pitch) 1/2) (eqv? (ly:pitch- notename pitch) 2)) (x11-color 'green)) ((and (eqv? (ly:pitch-alteration pitch) -1/2) (eqv? (ly:pitch- notename pitch) 3)) (x11-color 'red)) ((and (eqv? (ly:pitch-alteration pitch) 0) (eqv? (ly:pitch-notename pitch) 3)) (x11-color 'green)) ((and (eqv? (ly:pitch-alteration pitch) 1/2) (eqv? (ly:pitch- notename pitch) 4)) (x11-color 'red)) ((and (eqv? (ly:pitch-alteration pitch) 0) (eqv? (ly:pitch-notename pitch) 5)) (x11-color 'green)) ((and (eqv? (ly:pitch-alteration pitch) -1/2) (eqv? (ly:pitch- notename pitch) 5)) (x11-color 'red)) ((and (eqv? (ly:pitch-alteration pitch) 1/2) (eqv? (ly:pitch- notename pitch) 6)) (x11-color 'red)) ((and (eqv? (ly:pitch-alteration pitch) 0) (eqv? (ly:pitch-notename pitch) 1)) (x11-color 'blue)) ((and (eqv? (ly:pitch-alteration pitch) 1/2) (eqv? (ly:pitch- notename pitch) 3)) (x11-color 'blue)) ((and (eqv? (ly:pitch-alteration pitch) -1/2) (eqv? (ly:pitch- notename pitch) 4)) (x11-color 'blue)) ((and (eqv? (ly:pitch-alteration pitch) 1/2) (eqv? (ly:pitch- notename pitch) 5)) (x11-color 'blue)) ((and (eqv? (ly:pitch-alteration pitch) -1/2) (eqv? (ly:pitch- notename pitch) 6)) (x11-color 'blue))
) )but, as you can see it's hardly great programming style and somewhat error prone.
any further help would be hugely appreciated — other than the obvious, which is 'go and learn scheme! ' ;-) — as i've been struggling with this one for months now.
thanks again damian On 9 Aug 2008, at 05:12, Jay Anderson wrote:
If anyone can come up with a nice solution, this should definitely be added to the LSR...I'm not sure this is a nice solution yet, but it is at least a little easier to manipulate the color mapping and it handles enharmonic spellings easily. Let me know what you think. -----Jay \version "2.11.54" %Association list of semitones from middle c to colors. #(define color-mapping (list (cons (ly:pitch-semitones (ly:make-pitch 0 0 0)) (x11-color 'blue)) (cons 2 (x11-color 'yellow)) (cons 3 (x11-color 'red)) (cons -1 (x11-color 'green)) (cons 5 (x11-color 'purple)) (cons 7 (x11-color 'cyan)) (cons 8 (x11-color 'ForestGreen)) )) #(define (pitch-to-color pitch) (let ((color (assv (ly:pitch-semitones pitch) color-mapping))) (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 } }
[Prev in Thread] | Current Thread | [Next in Thread] |