1 %% Do not edit this file; it is auto-generated from LSR http://lsr.dsi.unimi.it
2 %% This file is in the public domain.
7 There is a way to enforce enharmonic modifications for notes in order
8 to have the minimum number of accidentals. In that case, ``Double
9 accidentals should be removed, as well as E-sharp (-> F), bC (-> B), bF
10 (-> E), B-sharp (-> C).'', as proposed by a request for a new feature.
11 In this manner, the most natural enharmonic notes are chosen in this
15 #(define (naturalise-pitch p)
16 (let* ((o (ly:pitch-octave p))
17 (a (ly:pitch-alteration p))
18 (n (ly:pitch-notename p)))
21 ((and (> a 1) (or (eq? n 6) (eq? n 2)))
24 ((and (< a -1) (or (eq? n 0) (eq? n 3)))
29 ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
30 ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
32 (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
33 (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
35 (ly:make-pitch o n a)))
37 #(define (naturalise music)
38 (let* ((es (ly:music-property music 'elements))
39 (e (ly:music-property music 'element))
40 (p (ly:music-property music 'pitch)))
43 (ly:music-set-property!
45 (map (lambda (x) (naturalise x)) es)))
48 (ly:music-set-property!
54 (set! p (naturalise-pitch p))
55 (ly:music-set-property! music 'pitch p)))
59 music = \relative c' { c4 d e f g a b c }
62 #(define-music-function (parser location m)
68 \transpose c ais \music
69 \naturaliseMusic \transpose c ais \music
70 \transpose c deses \music
71 \naturaliseMusic \transpose c deses \music
73 \layout { ragged-right = ##t}