lilypond-user
[Top][All Lists]
Advanced

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

Notehead color on programmed pitch change


From: Peter Gentry
Subject: Notehead color on programmed pitch change
Date: Mon, 25 May 2015 12:20:14 +0100

I have a short script to confine music to an instruments range. I wish to colour the noteheads on any pitches which have been changed to fit the instrument range.
 
Try as I may all attempts to modify existing snippets have failed -  I was particulary baffled by the snippet
 
#(define (pitch-to-color pitch)
(let ((color (assoc pitch colo-mapping pitch-equals?)))
(if color
(cdr color))) 
 
which in the abscence of a need for color-mapping  I couldn't replace with
 
(color (x11-color 'red))
 
The above is not in the script as all attempts just failed - can anyone help please.
 
\version "2.19.15"
#(define (naturalize-instrument-range p instrument)
(let ((o (ly:pitch-octave p))
  (a (* 4 (ly:pitch-alteration p)))
;; alteration, a, in quarter tone steps,
;; for historical reasons
(n (ly:pitch-notename p)))
 
(define oct1 o)
(cond
   ((equal? instrument "clarinet" )
 (if (<= o -1) (begin (set! o -1 )))
 (if (>= o 3) (begin (set! o 2 )))
(cond
( (and (= o -1) (<= a 2) (<= n 1)) (set! o 0))
( (and (= o  2) (>  n 3))           (set! o 1))
( (and (= o  2) (<= n 3))           (set! o 2)) )
 
(if (> o 2) (begin (set! o 2 ))))
 
((equal? instrument "flute")
    (if (< o 0) (begin (set! o 0 )))
(cond
( (and (= o 0) (< a  0) (= n 0)) (set! o 1))
( (and (= o 2) (> n  3))         (set! o 1))
( (and (= o 2) (<= n 3))         (set! o 2)) )
 
(if (> o 2) (begin (set! o 2 )))) )
 
;; just in for checking
(if (or (< oct1 o) (> oct1 o))
(display (string-append " oct= " (number->string oct1) " o= " (number->string o) "\n")))
 
(ly:make-pitch o n (/ a 4)) ))
 
 
 
#(define (instrumentrange music instrument )
(  ly:music? number? )
(let ((es (ly:music-property music 'elements))
(e (ly:music-property music 'element))
(p (ly:music-property music 'pitch)))
 
(if (pair? es)
(ly:music-set-property! music 'elements
 
(map (lambda (x) (instrumentrange x instrument)) es)))
 (if (ly:music? e) (ly:music-set-property! music 'element
 
(instrumentrange e instrument )))
(if (ly:pitch? p)
 (begin (set! p (naturalize-instrument-range p instrument))
 (ly:music-set-property! music 'pitch p)))
   music))
 
naturalizeInstrumentRange =
#(define-music-function (parser location  instrument m )
 ( string? ly:music? )
 (instrumentrange m instrument ))
 
 \score {
  \naturalizeInstrumentRange "clarinet"
  \new Staff
   \relative c'' {
 d4 r16  d,,16 [  e'16 f16 ]  e8 [  a,8 ]  a'16 [  g'16 a16 e16 ]   |  % 4
 f8 [  d8 ]  r4  r2   |  % 5
 }}
 

regards
Peter Gentry

 

reply via email to

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