4 texidoc="@cindex Smart Transpose
6 Here's a copy of my feature request :
8 Your task, if you accept it is to implement a \smarttranspose
9 command> that would translate such oddities into more natural
10 notations. Double accidentals should be removed, as well as E-sharp
11 (-> F), bC (-> B), bF (-> E), B-sharp (-> C).
14 You mean like this. (Sorry 'bout the nuked indentation.)
16 Modified to use the standard transpose mechanism. The question is
17 how useful these enharmonic modifications are. Mats B.
22 #(define (unhair-pitch p)
23 (let* ((o (ly:pitch-octave p))
24 (a (ly:pitch-alteration p))
25 (n (ly:pitch-notename p)))
28 ((and (> a 0) (or (eq? n 6) (eq? n 2)))
29 (set! a (- a 1)) (set! n (+ n 1)))
30 ((and (< a 0) (or (eq? n 0) (eq? n 3)))
31 (set! a (+ a 1)) (set! n (- n 1))))
34 ((eq? a 2) (set! a 0) (set! n (+ n 1)))
35 ((eq? a -2) (set! a 0) (set! n (- n 1))))
37 (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
38 (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
40 (ly:make-pitch o n a)))
42 #(define (simplify music)
43 (let* ((es (ly:get-mus-property music 'elements))
44 (e (ly:get-mus-property music 'element))
45 (p (ly:get-mus-property music 'pitch)))
50 (map (lambda (x) (simplify x)) es)))
59 (set! p (unhair-pitch p))
60 (ly:set-mus-property! music 'pitch p)))
64 music = \notes \relative c' { c4 d e f g a b c }
67 \notes \context Staff {
68 \transpose c ais \music
69 \apply #simplify \transpose c ais \music
71 \paper { raggedright = ##t}