]> git.donarmstrong.com Git - lilypond.git/blob - input/lsr/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
Merge master into nested-bookparts
[lilypond.git] / input / lsr / transposing-pitches-with-minimum-accidentals-smart-transpose.ly
1 %% Do not edit this file; it is auto-generated from input/new
2 %% This file is in the public domain.
3 \version "2.11.62"
4 \header {
5 doctitlees = "Transportar música con el menor número de alteraciones"
6 texidoces = "
7 Este ejemplo utiliza código de Scheme para forzar las
8 modificaciones enarmónicas de las notas, y así tener el menor
9 número de alteraciones accidentales. En este caso se aplican las
10 siguientes reglas:
11
12 @itemize
13 @item
14 Se quitan las dobles alteraciones
15
16 @item
17 Si sostenido -> Do
18
19 @item
20 Mi sistenido -> Fa
21
22 @item
23 Do bemol -> Si
24
25 @item
26 Fa bemol -> Mi
27
28 @end itemize
29
30 De esta forma se selecciona el mayor número de notas enarmónicas
31 naturales.
32
33 "
34   lsrtags = "pitches"
35   texidoc = "This example uses some Scheme code to enforce enharmonic
36 modifications for notes in order to have the minimum number of
37 accidentals.  In this case, the following rules apply:
38
39 @itemize
40 @item
41 Double accidentals should be removed
42
43 @item
44 B sharp -> C
45
46 @item
47 E sharp -> F
48
49 @item
50 C flat -> B
51
52 @item
53 F flat -> E
54
55 @end itemize
56
57 In this manner, the most natural enharmonic notes are chosen.
58 "
59   doctitle = "Transposing music with minimum accidentals"
60 } % begin verbatim
61
62 #(define  (naturalize-pitch p)
63   (let* ((o (ly:pitch-octave p))
64          (a (* 4 (ly:pitch-alteration p)))
65     ; alteration, a, in quarter tone steps, for historical reasons
66          (n (ly:pitch-notename p)))
67     (cond
68      ((and (> a 1) (or (eq? n 6) (eq? n 2)))
69       (set! a (- a 2))
70       (set! n (+ n 1)))
71      ((and (< a -1) (or (eq? n 0) (eq? n 3)))
72       (set! a (+ a 2))
73       (set! n (- n 1))))
74     (cond
75      ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
76      ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
77     (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
78     (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
79     (ly:make-pitch o n (/ a 4))))
80
81 #(define (naturalize music)
82   (let* ((es (ly:music-property music 'elements))
83          (e (ly:music-property music 'element))
84          (p (ly:music-property music 'pitch)))
85     (if (pair? es)
86         (ly:music-set-property!
87          music 'elements
88          (map (lambda (x) (naturalize x)) es)))
89     (if (ly:music? e)
90         (ly:music-set-property!
91          music 'element
92          (naturalize e)))
93     (if (ly:pitch? p)
94         (begin
95           (set! p (naturalize-pitch p))
96           (ly:music-set-property! music 'pitch p)))
97     music))
98
99 naturalizeMusic =
100 #(define-music-function (parser location m)
101                                         (ly:music?)
102                         (naturalize m))
103
104 music = \relative c' { c4 d e g }
105
106 \score {
107   \new Staff {
108     \transpose c ais { \music }
109     \naturalizeMusic \transpose c ais { \music }
110     \transpose c deses { \music }
111     \naturalizeMusic \transpose c deses { \music }
112   }
113   \layout { }
114 }