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