4 lsrtags = "pitches, scheme-language, workaround"
7 This example uses some Scheme code to enforce enharmonic modifications
8 for notes in order to have the minimum number of accidentals. In this
9 case, the following rules apply:
11 Double accidentals should be removed
26 In this manner, the most natural enharmonic notes are chosen.
29 doctitle = "Transposing pitches with minimum accidentals (\"Smart\" transpose)"
31 #(define (naturalize-pitch p)
32 (let ((o (ly:pitch-octave p))
33 (a (* 4 (ly:pitch-alteration p)))
34 ;; alteration, a, in quarter tone steps,
35 ;; for historical reasons
36 (n (ly:pitch-notename p)))
38 ((and (> a 1) (or (eqv? n 6) (eqv? n 2)))
41 ((and (< a -1) (or (eqv? n 0) (eqv? n 3)))
45 ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
46 ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
47 (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
48 (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
49 (ly:make-pitch o n (/ a 4))))
51 #(define (naturalize music)
52 (let ((es (ly:music-property music 'elements))
53 (e (ly:music-property music 'element))
54 (p (ly:music-property music 'pitch)))
56 (ly:music-set-property!
60 (ly:music-set-property!
65 (set! p (naturalize-pitch p))
66 (ly:music-set-property! music 'pitch p)))
70 #(define-music-function (m)
74 music = \relative c' { c4 d e g }
78 \transpose c ais { \music }
79 \naturalizeMusic \transpose c ais { \music }
80 \transpose c deses { \music }
81 \naturalizeMusic \transpose c deses { \music }