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