]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/snippets/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
Docs: reorganize documentation directory structure
[lilypond.git] / Documentation / snippets / 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 \version "2.13.1"
4
5 \header {
6   lsrtags = "pitches"
7
8 %% Translation of GIT committish: 4866dfd58d5c3a8cab4c6c06d5c4fca8e05a3cd7
9 doctitlees = "Transportar música con el menor número de alteraciones"
10 texidoces = "
11 Este ejemplo utiliza código de Scheme para forzar las
12 modificaciones enarmónicas de las notas, y así tener el menor
13 número de alteraciones accidentales. En este caso se aplican las
14 siguientes reglas:
15
16 @itemize
17 @item
18 Se quitan las dobles alteraciones
19
20 @item
21 Si sostenido -> Do
22
23 @item
24 Mi sistenido -> Fa
25
26 @item
27 Do bemol -> Si
28
29 @item
30 Fa bemol -> Mi
31
32 @end itemize
33
34 De esta forma se selecciona el mayor número de notas enarmónicas
35 naturales.
36
37 "
38
39 %% Translation of GIT committish: e75f1604a1b866c853dee42dbffcb7800c706a5f
40   doctitlede = "Noten mit minimaler Anzahl an Versetzungszeichen transponieren."
41   texidocde = "Dieses Beispiel benutzt Scheme-Code, um enharmonische
42 Verwechslungen für Noten zu erzwingen, damit nur eine minimale Anzahl
43 an Versetzungszeichen ausgegeben wird.  In diesem Fall gelten die
44 folgenden Regeln:
45
46 @itemize
47 @item
48 Doppelte Versetzungszeichen sollen entfernt werden
49
50 @item
51 His -> C
52
53 @item
54 Eis -> F
55
56 @item
57 Ces -> B
58
59 @item
60 Fes -> E
61
62 @end itemize
63
64 Auf diese Art werden am meisten natürliche Tonhöhen als enharmonische
65 Variante gewählt.
66 "
67
68
69   texidoc = "
70 This example uses some Scheme code to enforce enharmonic modifications
71 for notes in order to have the minimum number of accidentals.  In this
72 case, the following rules apply:
73
74 Double accidentals should be removed
75
76
77 B sharp -> C
78
79
80 E sharp -> F
81
82
83 C flat -> B
84
85
86 F flat -> E
87
88
89 In this manner, the most natural enharmonic notes are chosen. 
90
91 "
92   doctitle = "Transposing pitches with minimum accidentals (\"Smart\" transpose)"
93 } % begin verbatim
94
95 #(define (naturalize-pitch p)
96   (let ((o (ly:pitch-octave p))
97         (a (* 4 (ly:pitch-alteration p)))
98         ;; alteration, a, in quarter tone steps,
99         ;; for historical reasons
100         (n (ly:pitch-notename p)))
101     (cond
102      ((and (> a 1) (or (eq? n 6) (eq? n 2)))
103       (set! a (- a 2))
104       (set! n (+ n 1)))
105      ((and (< a -1) (or (eq? n 0) (eq? n 3)))
106       (set! a (+ a 2))
107       (set! n (- n 1))))
108     (cond
109      ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
110      ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
111     (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
112     (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
113     (ly:make-pitch o n (/ a 4))))
114
115 #(define (naturalize music)
116   (let ((es (ly:music-property music 'elements))
117         (e (ly:music-property music 'element))
118         (p (ly:music-property music 'pitch)))
119     (if (pair? es)
120        (ly:music-set-property!
121          music 'elements
122          (map (lambda (x) (naturalize x)) es)))
123     (if (ly:music? e)
124        (ly:music-set-property!
125          music 'element
126          (naturalize e)))
127     (if (ly:pitch? p)
128        (begin
129          (set! p (naturalize-pitch p))
130          (ly:music-set-property! music 'pitch p)))
131     music))
132
133 naturalizeMusic =
134 #(define-music-function (parser location m)
135   (ly:music?)
136   (naturalize m))
137
138 music = \relative c' { c4 d e g }
139
140 \score {
141   \new Staff {
142     \transpose c ais { \music }
143     \naturalizeMusic \transpose c ais { \music }
144     \transpose c deses { \music }
145     \naturalizeMusic \transpose c deses { \music }
146   }
147   \layout { }
148 }