1 %% Do not edit this file; it is auto-generated from LSR!
6 There is a way to enforce enharmonic modifications for notes in order
7 to have the minimum number of accidentals. In that case, ``Double
8 accidentals should be removed, as well as E-sharp (-> F), bC (-> B), bF
9 (-> E), B-sharp (-> C).'', as proposed by a request for a new feature.
10 In this manner, the most natural enharmonic notes are chosen in this
14 #(define (naturalise-pitch p)
15 (let* ((o (ly:pitch-octave p))
16 (a (ly:pitch-alteration p))
17 (n (ly:pitch-notename p)))
20 ((and (> a 1) (or (eq? n 6) (eq? n 2)))
23 ((and (< a -1) (or (eq? n 0) (eq? n 3)))
28 ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
29 ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
31 (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
32 (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
34 (ly:make-pitch o n a)))
36 #(define (naturalise music)
37 (let* ((es (ly:music-property music 'elements))
38 (e (ly:music-property music 'element))
39 (p (ly:music-property music 'pitch)))
42 (ly:music-set-property!
44 (map (lambda (x) (naturalise x)) es)))
47 (ly:music-set-property!
53 (set! p (naturalise-pitch p))
54 (ly:music-set-property! music 'pitch p)))
58 music = \relative c' { c4 d e f g a b c }
61 #(define-music-function (parser location m)
67 \transpose c ais \music
68 \naturaliseMusic \transpose c ais \music
69 \transpose c deses \music
70 \naturaliseMusic \transpose c deses \music
72 \layout { ragged-right = ##t}