]> git.donarmstrong.com Git - lilypond.git/blob - input/lsr/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
Merge branch 'dev/mf2pt1-build' of git://git.sv.gnu.org/lilypond
[lilypond.git] / input / lsr / transposing-pitches-with-minimum-accidentals-smart-transpose.ly
1 %% Do not edit this file; it is auto-generated from LSR http://lsr.dsi.unimi.it
2 %% This file is in the public domain.
3 %% Tags: pitches
4 \version "2.11.35"
5
6 \header { texidoc = "
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), bF
10 (-> E), B-sharp (-> C).'', as proposed by a request for a new feature.
11 In this manner, the most natural enharmonic notes are chosen in this
12 example.
13 " }
14 % begin verbatim
15 #(define  (naturalise-pitch p)
16   (let* ((o (ly:pitch-octave p))
17          (a (ly:pitch-alteration p))
18          (n (ly:pitch-notename p)))
19
20     (cond
21      ((and (> a 1) (or (eq? n 6) (eq? n 2)))
22       (set! a (- a 2))
23       (set! n (+ n 1)))
24      ((and (< a -1) (or (eq? n 0) (eq? n 3)))
25       (set! a (+ a 2))
26       (set! n (- n 1))))
27
28     (cond
29      ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
30      ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
31
32     (if (< n 0) (begin (set!  o (- o 1)) (set! n (+ n 7))))
33     (if (> n 6) (begin (set!  o (+ o 1)) (set! n (- n 7))))
34
35     (ly:make-pitch o n a)))
36
37 #(define (naturalise music)
38   (let* ((es (ly:music-property music 'elements))
39          (e (ly:music-property music 'element))
40          (p (ly:music-property music 'pitch)))
41
42     (if (pair? es)
43         (ly:music-set-property!
44          music 'elements
45          (map (lambda (x) (naturalise x)) es)))
46
47     (if (ly:music? e)
48         (ly:music-set-property!
49          music 'element
50          (naturalise e)))
51
52     (if (ly:pitch? p)
53         (begin
54           (set! p (naturalise-pitch p))
55           (ly:music-set-property! music 'pitch p)))
56
57     music))
58
59 music =  \relative c' { c4 d  e f g a b  c }
60
61 naturaliseMusic =
62 #(define-music-function (parser location m)
63                                         (ly:music?)
64                         (naturalise m))
65
66 \score {
67    \context Staff {
68     \transpose c ais \music
69     \naturaliseMusic \transpose c ais \music
70     \transpose c deses \music
71     \naturaliseMusic \transpose c deses \music
72   }
73   \layout { ragged-right = ##t}
74 }
75
76