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