]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
Merge branch 'master' into lilypond/translation
[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 %% Translation of GIT committish: bbf8fd2b5a3ebf20a1fdc91613dc49045a53a270
11   texidocit = "
12 Questo esempio usa del codice Scheme per imporre delle modifiche
13 enarmoniche alle note che permettano di avere il numero minimo di
14 alterazioni.  In questo caso si applica la seguente regola:
15
16 Le doppie alterazioni devono essere eliminate
17
18
19 Si diesis -> Do
20
21
22 Mi diesis -> Fa
23
24
25 Do bemolle -> Si
26
27
28 Fa bemolle -> Mi
29
30
31 In questo modo vengono scelti i suoni enarmonici più semplici.
32
33 "
34   doctitleit = "Trasposizione delle altezze con numero minimo di alterazioni"
35
36   lsrtags = "pitches"
37
38
39
40 %% Translation of GIT committish: 6977ddc9a3b63ea810eaecb864269c7d847ccf98
41 doctitlees = "Transportar música con el menor número de alteraciones"
42 texidoces = "
43 Este ejemplo utiliza código de Scheme para forzar las
44 modificaciones enarmónicas de las notas, y así tener el menor
45 número de alteraciones accidentales. En este caso se aplican las
46 siguientes reglas:
47
48 @itemize
49 @item
50 Se quitan las dobles alteraciones
51
52 @item
53 Si sostenido -> Do
54
55 @item
56 Mi sistenido -> Fa
57
58 @item
59 Do bemol -> Si
60
61 @item
62 Fa bemol -> Mi
63
64 @end itemize
65
66 De esta forma se selecciona el mayor número de notas enarmónicas
67 naturales.
68
69 "
70
71
72 %% Translation of GIT committish: 0a868be38a775ecb1ef935b079000cebbc64de40
73   doctitlede = "Noten mit minimaler Anzahl an Versetzungszeichen transponieren."
74   texidocde = "Dieses Beispiel benutzt Scheme-Code, um enharmonische
75 Verwechslungen für Noten zu erzwingen, damit nur eine minimale Anzahl
76 an Versetzungszeichen ausgegeben wird.  In diesem Fall gelten die
77 folgenden Regeln:
78
79 @itemize
80 @item
81 Doppelte Versetzungszeichen sollen entfernt werden
82
83 @item
84 His -> C
85
86 @item
87 Eis -> F
88
89 @item
90 Ces -> B
91
92 @item
93 Fes -> E
94
95 @end itemize
96
97 Auf diese Art werden am meisten natürliche Tonhöhen als enharmonische
98 Variante gewählt.
99 "
100
101
102 %% Translation of GIT committish: 3b125956b08d27ef39cd48bfa3a2f1e1bb2ae8b4
103   texidocfr = "
104 Cet exemple, grâce à un peu de code Scheme, donne la priorité aux
105 enharmoniques afin de limiter le nombre d'altérations supplémentaires.
106 La règle appliquable est@tie{}:
107
108 @itemize
109 @item
110 Les altérations doubles sont supprimées
111
112 @item
113 Si dièse -> Do
114
115 @item
116 Mi dièse -> Fa
117
118 @item
119 Do bémol -> Si
120
121 @item
122 Fa bémol -> Mi
123
124 @end itemize
125
126 Cette façon de procéder aboutit à plus d'enharmoniques naturelles.
127
128 "
129   doctitlefr = "Transposition et réduction du nombre d'altérations accidentelles"
130
131   texidoc = "
132 This example uses some Scheme code to enforce enharmonic modifications
133 for notes in order to have the minimum number of accidentals.  In this
134 case, the following rules apply:
135
136 Double accidentals should be removed
137
138
139 B sharp -> C
140
141
142 E sharp -> F
143
144
145 C flat -> B
146
147
148 F flat -> E
149
150
151 In this manner, the most natural enharmonic notes are chosen.
152
153 "
154   doctitle = "Transposing pitches with minimum accidentals (\"Smart\" transpose)"
155 } % begin verbatim
156
157 #(define (naturalize-pitch p)
158    (let ((o (ly:pitch-octave p))
159          (a (* 4 (ly:pitch-alteration p)))
160          ;; alteration, a, in quarter tone steps,
161          ;; for historical reasons
162          (n (ly:pitch-notename p)))
163      (cond
164       ((and (> a 1) (or (eq? n 6) (eq? n 2)))
165        (set! a (- a 2))
166        (set! n (+ n 1)))
167       ((and (< a -1) (or (eq? n 0) (eq? n 3)))
168        (set! a (+ a 2))
169        (set! n (- n 1))))
170      (cond
171       ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
172       ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
173      (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
174      (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
175      (ly:make-pitch o n (/ a 4))))
176
177 #(define (naturalize music)
178    (let ((es (ly:music-property music 'elements))
179          (e (ly:music-property music 'element))
180          (p (ly:music-property music 'pitch)))
181      (if (pair? es)
182          (ly:music-set-property!
183           music 'elements
184           (map (lambda (x) (naturalize x)) es)))
185      (if (ly:music? e)
186          (ly:music-set-property!
187           music 'element
188           (naturalize e)))
189      (if (ly:pitch? p)
190          (begin
191            (set! p (naturalize-pitch p))
192            (ly:music-set-property! music 'pitch p)))
193      music))
194
195 naturalizeMusic =
196 #(define-music-function (parser location m)
197    (ly:music?)
198    (naturalize m))
199
200 music = \relative c' { c4 d e g }
201
202 \score {
203   \new Staff {
204     \transpose c ais { \music }
205     \naturalizeMusic \transpose c ais { \music }
206     \transpose c deses { \music }
207     \naturalizeMusic \transpose c deses { \music }
208   }
209   \layout { }
210 }
211