On 07/09/2010 10:34 PM, Neil Puttock wrote:
> Sounds good to me.
So, here we go ... (faster to achieve than I expected, thanks to a
conversation with a friend who is Scheme-experienced).
I've defined a Scheme function "naturalize-limit" which can be used to
define limits for different cases, and given two examples -- one where
the maximum alteration must be less than a whole tone, and one where the
maximum alteration must be less than or equal to 1/2-tone (the old
naturalizeMusic).
In principle I can also use these to define custom cases for the notes
c, e, f, b as well; not sure if I should, since the whole point of the
naturalizeMusic function is to kill things like c-flats and e-sharps,
and tonal transposition is already taken care of by Lilypond's default
options.
(Other possible improvements -- getting rid of the (set! ...) functions?
My Schemer friend laughed at these...:-)
Next step, hooking this into the transpose_mutable() function... :-)
#(define (naturalize-limit lim val)
(define (limit a)
(lim a val))
limit)
#(define (naturalize-pitch p high low)
(let ((o (ly:pitch-octave p))
(n (ly:pitch-notename p))
(a (ly:pitch-alteration p)))
(do ((aa 0))
((= aa a) (ly:make-pitch o n a))
(set! aa a)
(cond
((and (>= a (/ 1 2)) (or (eq? n 2) (eq? n 6)))
(set! a (- a (/ 1 2)))
(set! n (+ n 1)))
((and (<= a (/ -1 2)) (or (eq? n 0) (eq? n 3)))
(set! a (+ a (/ 1 2)))
(set! n (- n 1))))
(cond
((high a) (set! a (- a 1)) (set! n (+ n 1)))
((low a) (set! a (+ a 1)) (set! n (- n 1))))
(if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
(if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7)))))))
#(define (naturalize music high low)
(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) (naturalize x high low)) es)))
(if (ly:music? e)
(ly:music-set-property!
music 'element
(naturalize e high low)))
(if (ly:pitch? p)
(begin
(set! p (naturalize-pitch p high low))
(ly:music-set-property! music 'pitch p)))
music))
naturalizeMusic =
#(define-music-function (parser location m)
(ly:music?)
(naturalize m (naturalize-limit >= 1) (naturalize-limit <= -1)))
naturalizeMusicHarp =
#(define-music-function (parser location m)
(ly:music?)
(naturalize m (naturalize-limit > (/ 1 2)) (naturalize-limit < (/ -1 2))))
music = \relative c' { c4 d e g }
microphrase = \relative c'' { geses4 geseh ges geh g gih gis gisih gisis }
\score {
\new Staff {
\set Staff.extraNatural = ##f
\transpose c ais { \music }
\naturalizeMusic \transpose c ais { \music }
\transpose c deses { \music }
\naturalizeMusic \transpose c deses { \music }
\bar "||"
\naturalizeMusicHarp \transpose c ais { \music }
\naturalizeMusicHarp \transpose c deses { \music }
\bar "||"
\break
\time 9/4
\microphrase
\bar ":"
\naturalizeMusic { \microphrase }
\bar ":"
\naturalizeMusicHarp { \microphrase }
\break
\transpose c ais { \microphrase }
\bar ":"
\naturalizeMusic \transpose c ais { \microphrase }
\bar ":"
\naturalizeMusicHarp \transpose c ais { \microphrase }
\break
\transpose c deses { \microphrase }
\bar ":"
\naturalizeMusic \transpose c deses { \microphrase }
\bar ":"
\naturalizeMusicHarp \transpose c deses { \microphrase }
\break
\transpose c cih { \microphrase }
\bar ":"
\naturalizeMusic \transpose c cih { \microphrase }
\bar ":"
\naturalizeMusicHarp \transpose c cih { \microphrase }
}
\layout { }
}
_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel