5 texidoc="@cindex Smart Transpose
7 There is a way to enforce enharmonic modifications for notes in order
8 to have the minimum number of accidentals. In that case, ``Double
9 accidentals should be removed, as well as E-sharp (-> F), bC (-> B),
10 bF (-> E), B-sharp (-> C).'', as proposed by a request for a new feature.
11 In this example, the double accidentals are removed after transposing
17 % Modified to use the standard transpose mechanism. The question is
18 % how useful these enharmonic modifications are. Mats B.
20 % Why not to have a function that minimizes the number of accidentals? -HJJ
23 #(define (unhair-pitch p)
24 (let* ((o (ly:pitch-octave p))
25 (a (ly:pitch-alteration p))
26 (n (ly:pitch-notename p)))
29 ((and (> a 2) (or (eq? n 6) (eq? n 2)))
32 ((and (< a -2) (or (eq? n 0) (eq? n 3)))
37 ((eq? a 4) (set! a 0) (set! n (+ n 1)))
38 ((eq? a -4) (set! a 0) (set! n (- n 1))))
40 (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
41 (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
43 (ly:make-pitch o n a)))
45 #(define (simplify music)
46 (let* ((es (ly:music-property music 'elements))
47 (e (ly:music-property music 'element))
48 (p (ly:music-property music 'pitch)))
51 (ly:music-set-property!
53 (map (lambda (x) (simplify x)) es)))
56 (ly:music-set-property!
62 (set! p (unhair-pitch p))
63 (ly:music-set-property! music 'pitch p)))
67 music = \notes \relative c' { c4 d e f g a b c }
70 \notes \context Staff {
71 \transpose c ais \music
72 \apply #simplify \transpose c ais \music
74 \paper { raggedright = ##t}