]> git.donarmstrong.com Git - lilypond.git/blob - input/test/smart-transpose.ly
update syntax in .ly files.
[lilypond.git] / input / test / smart-transpose.ly
1 \version "1.7.6"
2
3 \header {
4 texidoc="
5 @example
6     Here's a copy of my feature request :
7 @quotation
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).
12 @end quotation
13
14 You mean like this. (Sorry 'bout the nuked indentation.)
15
16 Modified to use the standard transpose mechanism. The question is
17 how useful these enharmonic modifications are. Mats B.
18 @end example
19 "
20 }
21
22 #(define  (unhair-pitch p)
23   (let* ((o (ly:pitch-octave p))
24          (a (ly:pitch-alteration p))
25          (n (ly:pitch-notename p)))
26
27     (cond
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))))
32
33     (cond
34      ((eq? a 2)  (set! a 0) (set! n (+ n 1)))
35      ((eq? a -2) (set! a 0) (set! n (- n 1))))
36
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))))
39
40     (ly:make-pitch o n a)))
41
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)))
46
47     (if (pair? es)
48         (ly:set-mus-property!
49          music 'elements
50          (map (lambda (x) (simplify x)) es)))
51
52     (if (ly:music? e)
53         (ly:set-mus-property!
54          music 'element
55          (simplify e)))
56
57     (if (ly:pitch? p)
58         (begin
59           (set! p (unhair-pitch p))
60           (ly:set-mus-property! music 'pitch p)))
61
62     music))
63
64 music = \notes \relative c' { c4 d  e f g a b  c }
65
66 \score {
67   \notes \context Staff {
68     \transpose c ais \music
69     \apply #simplify \transpose c ais \music
70   }
71   \paper { linewidth = -1. }
72 }
73
74 %% new-chords-done %%