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