]> git.donarmstrong.com Git - lilypond.git/blob - input/test/smart-transpose.ly
Massive changes - see ChangeLog.
[lilypond.git] / input / test / smart-transpose.ly
1 #(ly:set-option 'old-relative)
2 \version "1.9.0"
3
4 \header {
5 texidoc="@cindex Smart Transpose
6 @example
7         Here's a copy of my feature request :
8 @quotation
9         Your task, if you accept it is to implement a \smarttranspose
10         command> that would translate such oddities into more natural
11         notations. Double accidentals should be removed, as well as E-sharp
12         (-> F), bC (-> B), bF (-> E), B-sharp (-> C).
13 @end quotation
14
15 You mean like this. (Sorry 'bout the nuked indentation.)
16
17 Modified to use the standard transpose mechanism. The question is
18 how useful these enharmonic modifications are. Mats B.
19 @end example
20 "
21 }
22
23 #(define  (unhair-pitch p)
24   (let* ((o (ly:pitch-octave p))
25          (a (ly:pitch-alteration p))
26          (n (ly:pitch-notename p)))
27
28     (cond
29      ((and (> a 0) (or (eq? n 6) (eq? n 2)))
30       (set! a (- a 1)) (set! n (+ n 1)))
31      ((and (< a 0) (or (eq? n 0) (eq? n 3)))
32       (set! a (+ a 1)) (set! n (- n 1))))
33
34     (cond
35      ((eq? a 2)  (set! a 0) (set! n (+ n 1)))
36      ((eq? a -2) (set! a 0) (set! n (- n 1))))
37
38     (if (< n 0) (begin (set!  o (- o 1)) (set! n (+ n 7))))
39     (if (> n 6) (begin (set!  o (+ o 1)) (set! n (- n 7))))
40
41     (ly:make-pitch o n a)))
42
43 #(define (simplify music)
44   (let* ((es (ly:get-mus-property music 'elements))
45          (e (ly:get-mus-property music 'element))
46          (p (ly:get-mus-property music 'pitch)))
47
48     (if (pair? es)
49         (ly:set-mus-property!
50          music 'elements
51          (map (lambda (x) (simplify x)) es)))
52
53     (if (ly:music? e)
54         (ly:set-mus-property!
55          music 'element
56          (simplify e)))
57
58     (if (ly:pitch? p)
59         (begin
60           (set! p (unhair-pitch p))
61           (ly:set-mus-property! music 'pitch p)))
62
63     music))
64
65 music = \notes \relative c' { c4 d  e f g a b  c }
66
67 \score {
68   \notes \context Staff {
69     \transpose c ais \music
70     \apply #simplify \transpose c ais \music
71   }
72   \paper { raggedright = ##t}
73 }
74
75