Thanks very much for your solution - I'm not yet sure why it works...how does 'tweaks know about notehead color? All very baffling Outlook strikes again - try this \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))) (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 )))) ) (ly:make-pitch o n (/ a 4)) )) my-color = #(x11-color 'red) #(define (instrumentrange music instrument ) ( ly:music? string? ) (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) (let ((new-pitch (naturalize-instrument-range p instrument))) (ly:music-set-property! music 'pitch new-pitch) (if (and (not (equal? p new-pitch)) (color? my-color)) (ly:music-set-property! music 'tweaks (acons 'color my-color (ly:music-property music 'tweaks)))))) music)) naturalizeInstrumentRange = #(define-music-function (parser location instrument m ) ( string? ly:music? ) (instrumentrange m instrument )) \score { \new Staff \naturalizeInstrumentRange "clarinet" \relative c'' { d4 r16 d,,16 [ e'16 f16 ] e8 [ a,8 ] a''16 [ g'16 a16 e16 ] | % 4 f8 [ d8 ] r4 r2 | % 5 } } \score { \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
_______________________________________________ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user