Hello all,

As per earlier discussion on the -user list:
http://www.mail-archive.com/lilypond-u...@gnu.org/msg51183.html

... I finally managed to put some time and mental energy towards
chromatic transposition, in particular, the naturalizeMusic function
from the LSR.

I've attached a draft version that makes two changes to the original:

    (1) it takes out the original's focus on quarter-tones as the
        units of alteration, and changes the conditions for rewriting
        so that it will let pass any alteration less than a whole tone
        (so e.g. 3/4-flats and sharps will not be rewritten; but see
        below for caveat ...)

    (2) it introduces a (do ...) loop to make sure that the process of
        naturalization converges.  This way you don't get accidental
        (pun intended:-) double-flats hanging around due to weird
        transpositions.

        (Example: take the music of bb. 9-10 in the sample music, and
        put it through the _original_ naturalizeMusic function.  You get
        left with a g-double-flat instead of an f-natural.)

What I still would like to do is make optional the question of the
largest alteration permitted.  See lines 15--17 of the code:

     (cond
      ((>= a 1) (set! a (- a 1)) (set! n (+ n 1)))
      ((<= a -1) (set! a (+ a 1)) (set! n (- n 1))))

In the original naturalizeMusic function, these conditional statements
were the equivalent of (> a (/ 1 2)) and (< a (/ -1 2)), which rewrote
any alteration larger than a semitone.

As Hans Aberg pointed out, this can be important for e.g. harp music
where there is a strict limit of +/- 1/2-tone on note alterations.

The best way to achieve this seems to be to make those conditions
variables in the function definition, something like,

 (define (naturalize-pitch p toohigh toolow)

     ...

     (cond
      ((toohigh a) (set! a (- a 1)) (set! n (+ n 1)))
      ((toolow a) (set! a (+ a 1)) (set! n (- n 1))))

... with toohigh or toolow being defined to give both a predicate (>,
>=, <, <=) and a value (1, -1, (/ 1 2), (/ -1 2) ...)

I'm shaky on how to define toohigh or twolow, though (not so much a
schemer as a meddler): can someone advise?

Thanks & best wishes,

    -- Joe

#(define (naturalize-pitch p)
   (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
      ((>= a 1) (set! a (- a 1)) (set! n (+ n 1)))
      ((<= a -1) (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)
   (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)) es)))
     (if (ly:music? e)
         (ly:music-set-property!
          music 'element
          (naturalize e)))
     (if (ly:pitch? p)
         (begin
           (set! p (naturalize-pitch p))
           (ly:music-set-property! music 'pitch p)))
     music))

naturalizeMusic =
#(define-music-function (parser location m)
   (ly:music?)
   (naturalize m))

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 "||"
    \break
    
    \time 9/4
    \microphrase
    \bar ":"
    \naturalizeMusic { \microphrase }
    \break
    
    \transpose c ais { \microphrase }
    \bar ":"
    \naturalizeMusic \transpose c ais { \microphrase }
    \break
    
    \transpose c deses { \microphrase }
    \bar ":"
    \naturalizeMusic \transpose c deses { \microphrase }
    \break
    
    \transpose c cih { \microphrase }
    \bar ":"
    \naturalizeMusic \transpose c cih { \microphrase }
  }
  \layout { }
}

_______________________________________________
lilypond-devel mailing list
lilypond-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to