On 07/10/2010 12:25 PM, Joseph Wakeling wrote: > On second thoughts, it seems like transposition constraints for the > whole of LP could be set by four naturalize-limits: upper and lower > limits respectively for c, e, f, b; and upper and lower limits for > everything else.
OK, done. The attached example now contains a "complete" naturalize-pitch which allows the user to define the too-high and too-low rules for e, b and c, f respectively, as well as for the rest of the notes. This allows the definition of a "naturalizeMusicTonal" expression which seems to leave properly-transposed stuff (by Lilypond's defaults) untouched. The aim would be to allow the user to define custom naturalization rules alongside defaults, e.g: \withMusicProperty #'naturalize = ##f % don't employ naturalization, use Lilypond's default % functionality \withMusicProperty #'naturalize = #'chromatic % typical naturalize-music function \withMusicProperty #'naturalize = #'harp % naturalize with nothing > 1/2-tone \withMusicProperty #'naturalize = #'tonal % superfluous since Lilypond 2.13.14+ already handles this, % but if the user wants to be sure ... :-) \withMusicProperty #'naturalize = #((naturalize-limit >= 1) (naturalize-limit < (/ -1 2)) (naturalize-limit >= (/ 1 2)) (naturalize-limit < (/ -1 2))) % custom choice of user (my notation may be wrong here, but it % gives the idea of what the user could do). I see why Lisp is % sometimes referred to as "Lost in sodding parentheses" ... ! Note that the naturalization process could be employed in transposition_mutable() or it could be employed after transposition (if any) has been carried out, so the naturalization rules could be used to enforce style choices anywhere in the composition. e.g. \naturalizeChromatic ... bes8 \naturalizeOff ces % I really, really want this c-flat. \naturalizeOn % default option, same as \naturalizeChromatic There could even be two different music properties (#'naturalize or #'transposition-style?) depending on at what stage one wishes to apply naturalization; or with warnings if untransposed music is nevertheless altered by the naturalization process. Are there any other thoughts for what more needs to be done with the naturalize-pitch function itself? Or is it good to go in terms of hooking into Lilypond ... ? Thanks & best wishes, -- Joe
#(define (naturalize-limit lim val) (define (limit a) (lim a val)) limit) #(define (naturalize-pitch p high low higheb lowcf) (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 (higheb a) (or (eq? n 2) (eq? n 6))) (set! a (- a (/ 1 2))) (set! n (+ n 1))) ((and (lowcf a) (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 higheb lowcf) (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 higheb lowcf)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (naturalize e high low higheb lowcf))) (if (ly:pitch? p) (begin (set! p (naturalize-pitch p high low higheb lowcf)) (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) (naturalize-limit >= (/ 1 2)) (naturalize-limit <= (/ -1 2)))) naturalizeMusicHarp = #(define-music-function (parser location m) (ly:music?) (naturalize m (naturalize-limit > (/ 1 2)) (naturalize-limit < (/ -1 2)) (naturalize-limit >= (/ 1 2)) (naturalize-limit <= (/ -1 2)))) naturalizeMusicTonal = #(define-music-function (parser location m) (ly:music?) (naturalize m (naturalize-limit > 1) (naturalize-limit < -1) (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 } \bar ":" \naturalizeMusic \transpose c ais { \music } \bar ":" \naturalizeMusicHarp \transpose c ais { \music } \bar ":" \naturalizeMusicTonal \transpose c ais { \music } \bar "||" \transpose c deses { \music } \bar ":" \naturalizeMusic \transpose c deses { \music } \bar ":" \naturalizeMusicHarp \transpose c deses { \music } \bar ":" \naturalizeMusicTonal \transpose c deses { \music } \bar "||" \break \time 9/4 \microphrase \bar ":" \naturalizeMusic { \microphrase } \bar ":" \naturalizeMusicHarp { \microphrase } \bar ":" \naturalizeMusicTonal{ \microphrase } \break \transpose c ais { \microphrase } \bar ":" \naturalizeMusic \transpose c ais { \microphrase } \bar ":" \naturalizeMusicHarp \transpose c ais { \microphrase } \bar ":" \naturalizeMusicTonal \transpose c ais { \microphrase } \break \transpose c deses { \microphrase } \bar ":" \naturalizeMusic \transpose c deses { \microphrase } \bar ":" \naturalizeMusicHarp \transpose c deses { \microphrase } \bar ":" \naturalizeMusicTonal \transpose c deses { \microphrase } \break \transpose c cih { \microphrase } \bar ":" \naturalizeMusic \transpose c cih { \microphrase } \bar ":" \naturalizeMusicHarp \transpose c cih { \microphrase } \bar ":" \naturalizeMusicTonal \transpose c cih { \microphrase } } \layout { } }
_______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel