]> git.donarmstrong.com Git - lilypond.git/blob - input/lsr/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
Merge branch 'lilypond/translation'
[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 \version "2.11.38"
4 \header {
5   lsrtags = "pitches"
6   texidoces = "Este ejemplo utiliza código de Scheme para forzar las modificaciones enarmónicas de las
7 notas, y así tener el menor número de alteraciones accidentales. En este caso
8 se aplican las siguientes reglas:
9
10 @itemize
11 @item
12 Se quitan las dobles alteraciones
13
14 @item
15 Si sostenido -> Do
16
17 @item
18 Mi sistenido -> Fa
19
20 @item
21 Do bemol -> Si
22
23 @item
24 Fa bemol -> Mi
25
26 @end itemize
27
28 De esta forma se selecciona el mayor número de notas enarmónicas naturales.
29 "
30
31   texidoc = "This example uses some Scheme code to enforce enharmonic modifications for
32 notes in order to have the minimum number of accidentals. In this
33 case, the following rules apply:
34
35 @itemize
36 @item
37 Double accidentals should be removed
38
39 @item
40 B sharp -> C
41
42 @item
43 E sharp -> F
44
45 @item
46 C flat -> B
47
48 @item
49 F flat -> E
50
51 @end itemize
52
53 In this manner, the most natural enharmonic notes are chosen.
54 "
55   doctitle = "Transposing music with minimum accidentals"
56 } % begin verbatim
57
58 #(define  (naturalize-pitch p)
59   (let* ((o (ly:pitch-octave p))
60          (a (* 4 (ly:pitch-alteration p))) 
61     ; alteration, a, in quarter tone steps, for historical reasons
62          (n (ly:pitch-notename p)))
63     (cond
64      ((and (> a 1) (or (eq? n 6) (eq? n 2)))
65       (set! a (- a 2))
66       (set! n (+ n 1)))
67      ((and (< a -1) (or (eq? n 0) (eq? n 3)))
68       (set! a (+ a 2))
69       (set! n (- n 1))))
70     (cond
71      ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
72      ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
73     (if (< n 0) (begin (set!  o (- o 1)) (set! n (+ n 7))))
74     (if (> n 6) (begin (set!  o (+ o 1)) (set! n (- n 7))))
75     (ly:make-pitch o n (/ a 4))))
76
77 #(define (naturalize music)
78   (let* ((es (ly:music-property music 'elements))
79          (e (ly:music-property music 'element))
80          (p (ly:music-property music 'pitch)))
81     (if (pair? es)
82         (ly:music-set-property!
83          music 'elements
84          (map (lambda (x) (naturalize x)) es)))
85     (if (ly:music? e)
86         (ly:music-set-property!
87          music 'element
88          (naturalize e)))
89     (if (ly:pitch? p)
90         (begin
91           (set! p (naturalize-pitch p))
92           (ly:music-set-property! music 'pitch p)))
93     music))
94
95 naturalizeMusic =
96 #(define-music-function (parser location m)
97                                         (ly:music?)
98                         (naturalize m))
99
100 music =  \relative c' { c4 d e g }
101
102 \score {
103   \new Staff {
104     \transpose c ais \music
105     \naturalizeMusic \transpose c ais \music
106     \transpose c deses \music
107     \naturalizeMusic \transpose c deses \music
108   }
109   \layout { ragged-right = ##t }
110 }