]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
Docs: run convert-ly for 2.14.0.
[lilypond.git] / Documentation / snippets / transposing-pitches-with-minimum-accidentals-smart-transpose.ly
1 %% DO NOT EDIT this file manually; it is automatically
2 %% generated from LSR http://lsr.dsi.unimi.it
3 %% Make any changes in LSR itself, or in Documentation/snippets/new/ ,
4 %% and then run scripts/auxiliar/makelsr.py
5 %%
6 %% This file is in the public domain.
7 \version "2.14.0"
8
9 \header {
10   lsrtags = "pitches"
11
12 %% Translation of GIT committish: 59caa3adce63114ca7972d18f95d4aadc528ec3d
13 doctitlees = "Transportar música con el menor número de alteraciones"
14 texidoces = "
15 Este ejemplo utiliza código de Scheme para forzar las
16 modificaciones enarmónicas de las notas, y así tener el menor
17 número de alteraciones accidentales. En este caso se aplican las
18 siguientes reglas:
19
20 @itemize
21 @item
22 Se quitan las dobles alteraciones
23
24 @item
25 Si sostenido -> Do
26
27 @item
28 Mi sistenido -> Fa
29
30 @item
31 Do bemol -> Si
32
33 @item
34 Fa bemol -> Mi
35
36 @end itemize
37
38 De esta forma se selecciona el mayor número de notas enarmónicas
39 naturales.
40
41 "
42
43
44 %% Translation of GIT committish: 0a868be38a775ecb1ef935b079000cebbc64de40
45   doctitlede = "Noten mit minimaler Anzahl an Versetzungszeichen transponieren."
46   texidocde = "Dieses Beispiel benutzt Scheme-Code, um enharmonische
47 Verwechslungen für Noten zu erzwingen, damit nur eine minimale Anzahl
48 an Versetzungszeichen ausgegeben wird.  In diesem Fall gelten die
49 folgenden Regeln:
50
51 @itemize
52 @item
53 Doppelte Versetzungszeichen sollen entfernt werden
54
55 @item
56 His -> C
57
58 @item
59 Eis -> F
60
61 @item
62 Ces -> B
63
64 @item
65 Fes -> E
66
67 @end itemize
68
69 Auf diese Art werden am meisten natürliche Tonhöhen als enharmonische
70 Variante gewählt.
71 "
72
73
74 %% Translation of GIT committish: 4ab2514496ac3d88a9f3121a76f890c97cedcf4e
75   texidocfr = "
76 Cet exemple, grâce à un peu de code Scheme, donne la priorité aux
77 enharmoniques  afin de limiter le nombre d'altérations supplémentaires.
78 La règle appliquable est :
79
80 @itemize
81 @item
82 Les altérations doubles sont supprimées
83
84 @item
85 Si dièse -> Do
86
87 @item
88 Mi dièse -> Fa
89
90 @item
91 Do bémol -> Si
92
93 @item
94 Fa bémol -> Mi
95
96 @end itemize
97
98 Cette façon de procéder aboutit à plus d'enharmoniques naturelles.
99
100 "
101
102   doctitlefr = "Transposition et réduction du nombrer d'altérations accidentelles"
103
104   texidoc = "
105 This example uses some Scheme code to enforce enharmonic modifications
106 for notes in order to have the minimum number of accidentals.  In this
107 case, the following rules apply:
108
109 Double accidentals should be removed
110
111
112 B sharp -> C
113
114
115 E sharp -> F
116
117
118 C flat -> B
119
120
121 F flat -> E
122
123
124 In this manner, the most natural enharmonic notes are chosen.
125
126 "
127   doctitle = "Transposing pitches with minimum accidentals (\"Smart\" transpose)"
128 } % begin verbatim
129
130 #(define (naturalize-pitch p)
131    (let ((o (ly:pitch-octave p))
132          (a (* 4 (ly:pitch-alteration p)))
133          ;; alteration, a, in quarter tone steps,
134          ;; for historical reasons
135          (n (ly:pitch-notename p)))
136      (cond
137       ((and (> a 1) (or (eq? n 6) (eq? n 2)))
138        (set! a (- a 2))
139        (set! n (+ n 1)))
140       ((and (< a -1) (or (eq? n 0) (eq? n 3)))
141        (set! a (+ a 2))
142        (set! n (- n 1))))
143      (cond
144       ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
145       ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
146      (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
147      (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
148      (ly:make-pitch o n (/ a 4))))
149
150 #(define (naturalize music)
151    (let ((es (ly:music-property music 'elements))
152          (e (ly:music-property music 'element))
153          (p (ly:music-property music 'pitch)))
154      (if (pair? es)
155          (ly:music-set-property!
156           music 'elements
157           (map (lambda (x) (naturalize x)) es)))
158      (if (ly:music? e)
159          (ly:music-set-property!
160           music 'element
161           (naturalize e)))
162      (if (ly:pitch? p)
163          (begin
164            (set! p (naturalize-pitch p))
165            (ly:music-set-property! music 'pitch p)))
166      music))
167
168 naturalizeMusic =
169 #(define-music-function (parser location m)
170    (ly:music?)
171    (naturalize m))
172
173 music = \relative c' { c4 d e g }
174
175 \score {
176   \new Staff {
177     \transpose c ais { \music }
178     \naturalizeMusic \transpose c ais { \music }
179     \transpose c deses { \music }
180     \naturalizeMusic \transpose c deses { \music }
181   }
182   \layout { }
183 }
184