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.)
19 #(define (unhair-pitch p)
20 (let* ((o (pitch-octave p))
21 (a (pitch-alteration p))
22 (n (pitch-notename p)))
25 ((and (> a 0) (or (eq? n 6) (eq? n 2)))
26 (set! a (- a 1)) (set! n (+ n 1)))
27 ((and (< a 0) (or (eq? n 0) (eq? n 3)))
28 (set! a (+ a 1)) (set! n (- n 1))))
31 ((eq? a 2) (set! a 0) (set! n (+ n 1)))
32 ((eq? a -2) (set! a 0) (set! n (- n 1))))
34 (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
35 (if (> n 7) (begin (set! o (+ o 1)) (set! n (- n 7))))
39 #(define (smart-transpose music pitch)
40 (let* ((es (ly-get-mus-property music 'elements))
41 (e (ly-get-mus-property music 'element))
42 (p (ly-get-mus-property music 'pitch))
43 (body (ly-get-mus-property music 'body))
44 (alts (ly-get-mus-property music 'alternatives)))
49 (map (lambda (x) (smart-transpose x pitch)) es)))
54 (smart-transpose alts pitch)))
59 (smart-transpose body pitch)))
64 (smart-transpose e pitch)))
68 (set! p (unhair-pitch (Pitch::transpose p pitch)))
69 (ly-set-mus-property music 'pitch p)))
74 music = \notes \relative c' { c4 d e f g a b c }
77 \notes \context Staff {
78 \transpose ais' \music
79 \apply #(lambda (x) (smart-transpose x (make-pitch 0 5 1)))
82 \paper { linewidth = -1. }