|
From: | Stephen Corey |
Subject: | Re: Coloring note heads by pitch |
Date: | Mon, 02 Nov 2009 21:53:03 -0800 |
User-agent: | Thunderbird 2.0.0.23 (X11/20090817) |
Chris Angelico wrote:
This is the script I'm using for handbells, based on pitch, not staff position. Just change "black" to your X11 color choice. Posted back on 9/12/09I've spent some time trying to figure this out, and I'm certain it's possible; the only question is, what's the cleanest way to do it? I want to print out score with each note color coded (middle C in red, D in orange, E in green) to match a set of bells. Currently, I have a fairly straightforward setup, but exceedingly tedious: identify the bell AND give the music expression. What I'd like to do is make it that I can simply key in the music as is, and then have some scriptwork figure out what color to make each one based on its staffposition. Current code: % Is there an alternative to this shocking editor inheritance? bell = #(define-music-function (parser location bellnum mus) (integer? ly:music?) (if (eq? bellnum 1) #{ \once \override NoteHead #'color = #red \once \override Stem #'color = #red $mus #} (if (eq? bellnum 2) #{ \once \override NoteHead #'color = #orange \once \override Stem #'color = #orange $mus #} (if (eq? bellnum 3) #{ \once \override NoteHead #'color = #yellow \once \override Stem #'color = #yellow $mus #} (if (eq? bellnum 4) #{ \once \override NoteHead #'color = #green \once \override Stem #'color = #green $mus #} (if (eq? bellnum 5) #{ \once \override NoteHead #'color = #darkgreen \once \override Stem #'color = #darkgreen $mus #} (if (eq? bellnum 6) #{ \once \override NoteHead #'color = #cyan \once \override Stem #'color = #cyan $mus #} (if (eq? bellnum 7) #{ \once \override NoteHead #'color = #darkblue \once \override Stem #'color = #darkblue $mus #} (if (eq? bellnum 8) #{ \once \override NoteHead #'color = #magenta \once \override Stem #'color = #magenta $mus #} #{ #} ))))))))) ... and inside the Voice: % Every note must be entered as a bell identifier (#1 being the lowest bell, and #8 being the highest), % in addition to its note definition. s2 \bell #1 c8( \bell #2 d8) \bell #3 e2 \bell #3 e4 \bell #5 g4.( \bell #4 f8) \bell #3 e4 \bell #2 d4.( \bell #3 e8) \bell #4 f4 \bell #3 e2 r4 This is tedious and error-prone, as I have to give all information twice. I'm pretty certain that my failure is due to my lack of knowledge of the system, and that the experts on this list will be able to offer a solution - maybe there's one already built and ready! ChrisA Hopeful in the trusting, rather than futile, sense! :)
Regards, Stephen Corey Roseville, California \version "2.12.1" %Association list of pitches to colors, C4 - C7 %Excludes Cb, Fb, E#, B# and double accidentals #(define color-mapping (list (cons (ly:make-pitch -1 0 0) (x11-color 'black)) ; C4 (cons (ly:make-pitch -1 0 1/2) (x11-color 'black)) ; C#4 (cons (ly:make-pitch -1 1 -1/2) (x11-color 'black)) ; (D flat) (cons (ly:make-pitch -1 1 0) (x11-color 'black)) ; D4 (cons (ly:make-pitch -1 1 1/2) (x11-color 'black)) ; D#4 (cons (ly:make-pitch -1 2 -1/2) (x11-color 'black)) ; (E flat) (cons (ly:make-pitch -1 2 0) (x11-color 'black)) ; E4 (cons (ly:make-pitch -1 3 0) (x11-color 'black)) ; F4 (cons (ly:make-pitch -1 3 1/2) (x11-color 'black)) ; F#4 (cons (ly:make-pitch -1 4 -1/2) (x11-color 'black)) ; (G flat) (cons (ly:make-pitch -1 4 0) (x11-color 'black)) ; G4 (cons (ly:make-pitch -1 4 1/2) (x11-color 'black)) ; G#4 (cons (ly:make-pitch -1 5 -1/2) (x11-color 'black)) ; (A flat) (cons (ly:make-pitch -1 5 0) (x11-color 'black)) ; A4 (cons (ly:make-pitch -1 5 1/2) (x11-color 'black)) ; A#4 (cons (ly:make-pitch -1 6 -1/2) (x11-color 'black)) ; (B flat) (cons (ly:make-pitch -1 6 0) (x11-color 'black)) ; B4 (cons (ly:make-pitch 0 0 0) (x11-color 'black)) ; C5 (cons (ly:make-pitch 0 0 1/2) (x11-color 'black)) ; C#5 (cons (ly:make-pitch 0 1 -1/2) (x11-color 'black)) ; (D flat) (cons (ly:make-pitch 0 1 0) (x11-color 'black)) ; D5 (cons (ly:make-pitch 0 1 1/2) (x11-color 'black)) ; D#5 (cons (ly:make-pitch 0 2 -1/2) (x11-color 'black)) ; (E flat) (cons (ly:make-pitch 0 2 0) (x11-color 'black)) ; E5 (cons (ly:make-pitch 0 3 0) (x11-color 'black)) ; F5 (cons (ly:make-pitch 0 3 1/2) (x11-color 'black)) ; F#5 (cons (ly:make-pitch 0 4 -1/2) (x11-color 'black)) ; (G flat) (cons (ly:make-pitch 0 4 0) (x11-color 'black)) ; G5 (cons (ly:make-pitch 0 4 1/2) (x11-color 'black)) ; G#5 (cons (ly:make-pitch 0 5 -1/2) (x11-color 'black)) ; (A flat) (cons (ly:make-pitch 0 5 0) (x11-color 'black)) ; A5 (cons (ly:make-pitch 0 5 1/2) (x11-color 'black)) ; A#5 (cons (ly:make-pitch 0 6 -1/2) (x11-color 'black)) ; (B flat) (cons (ly:make-pitch 0 6 0) (x11-color 'black)) ; B5 (cons (ly:make-pitch 1 0 0) (x11-color 'black)) ; C6 (cons (ly:make-pitch 1 0 1/2) (x11-color 'black)) ; C#6 (cons (ly:make-pitch 1 1 -1/2) (x11-color 'black)) ; (D flat) (cons (ly:make-pitch 1 1 0) (x11-color 'black)) ; D6 (cons (ly:make-pitch 1 1 1/2) (x11-color 'black)) ; D#6 (cons (ly:make-pitch 1 2 -1/2) (x11-color 'black)) ; (E flat) (cons (ly:make-pitch 1 2 0) (x11-color 'black)) ; E6 (cons (ly:make-pitch 1 3 0) (x11-color 'black)) ; F6 (cons (ly:make-pitch 1 3 1/2) (x11-color 'black)) ; F#6 (cons (ly:make-pitch 1 4 -1/2) (x11-color 'black)) ; (G flat) (cons (ly:make-pitch 1 4 0) (x11-color 'black)) ; G6 (cons (ly:make-pitch 1 4 1/2) (x11-color 'black)) ; G#6 (cons (ly:make-pitch 1 5 -1/2) (x11-color 'black)) ; (A flat) (cons (ly:make-pitch 1 5 0) (x11-color 'black)) ; A6 (cons (ly:make-pitch 1 5 1/2) (x11-color 'black)) ; A#6 (cons (ly:make-pitch 1 6 -1/2) (x11-color 'black)) ; (B flat) (cons (ly:make-pitch 1 6 0) (x11-color 'black)) ; B6 (cons (ly:make-pitch 2 0 0) (x11-color 'black)) ; C7 )) %Compare pitch and alteration and octave #(define (pitch-equals? p1 p2) (and (= (ly:pitch-alteration p1) (ly:pitch-alteration p2)) (= (ly:pitch-notename p1) (ly:pitch-notename p2)) (= (ly:pitch-octave p1) (ly:pitch-octave 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 (event-cause grob) 'pitch))) #(set-global-staff-size 26) \header { title = "Handbell Color Template" subtitle = "" composer = "" arranger = "" } upper = \relative c' { \override NoteHead #'color = #color-notehead \override Staff.TimeSignature #'style = #'() \clef treble \key c \major \time 4/4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This forces bar numbers on every measure % \override Score.BarNumber #'break-visibility = #end-of-line-invisible %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% r1 r2 r4 d8 dis e f fis g gis a ais b c cis d dis e f fis g gis a ais b c b bes a aes g ges f e ees d des c b bes a aes g ges f e ees d des r2 r1 r \bar "|." } lower = \relative c { \override NoteHead #'color = #color-notehead \override Staff.TimeSignature #'style = #'() \clef bass \key c \major \time 4/4 c8 cis d dis e f fis g gis a ais b c cis r4 r1 r r r r r2 c8 b bes a aes g ges f e ees d des c1 } \score { \new PianoStaff << \new Staff = "upper" \upper \new Staff = "lower" \lower >> >> \layout { indent = 0.0 \cm } \midi { \context { \Score tempoWholesPerMinute = #(ly:make-moment 100 4) } } }
[Prev in Thread] | Current Thread | [Next in Thread] |