[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Notehead color on programmed pitch change
From: |
Thomas Morley |
Subject: |
Re: Notehead color on programmed pitch change |
Date: |
Tue, 26 May 2015 15:48:37 +0200 |
Hi Peter,
2015-05-25 13:20 GMT+02:00 Peter Gentry <address@hidden>:
> 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
No idea about this code is supposed to do:
> #(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.
All formating, indentation you may have done is gone in your mail.
Please make sure it is kept. It's very hard to read ...
> \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)) )
>
This is done already, delete it:
> (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 )
no type checking needed nor done here, delete it
> ( 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
How about:
\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) (set! o -1))
(if (>= o 3) (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))))
((equal? instrument "flute")
(if (< o 0) (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) (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))))
my-color = #(x11-color 'red)
#(define (instrumentrange music instrument)
(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))
mus =
\relative c'' {
d4 r16
des,,16 [ e'16 f16 ] e8 [ a,8 ] a'16 [ g'16 a16 e16 ] | % 4
f8 [ d8 ] r4 r2 | % 5
}
<<
\new Staff \mus
\naturalizeInstrumentRange "clarinet"
\new Staff \mus
>>
HTH,
Harm