1 %% DO NOT EDIT this file manually; it is automatically
2 %% generated from LSR http://lsr.dsi.unimi.it
3 %% Make any changes in LSR itself, or in Documentation/snippets/new/ ,
4 %% and then run scripts/auxiliar/makelsr.py
6 %% This file is in the public domain.
10 lsrtags = "pitches, scheme-language, workaround"
13 This example uses some Scheme code to enforce enharmonic modifications
14 for notes in order to have the minimum number of accidentals. In this
15 case, the following rules apply:
17 Double accidentals should be removed
32 In this manner, the most natural enharmonic notes are chosen.
35 doctitle = "Transposing pitches with minimum accidentals (\"Smart\" transpose)"
39 #(define (naturalize-pitch p)
40 (let ((o (ly:pitch-octave p))
41 (a (* 4 (ly:pitch-alteration p)))
42 ;; alteration, a, in quarter tone steps,
43 ;; for historical reasons
44 (n (ly:pitch-notename p)))
46 ((and (> a 1) (or (= n 6) (= n 2)))
49 ((and (< a -1) (or (= n 0) (= n 3)))
53 ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
54 ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
55 (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
56 (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
57 (ly:make-pitch o n (/ a 4))))
59 #(define (naturalize music)
60 (let ((es (ly:music-property music 'elements))
61 (e (ly:music-property music 'element))
62 (p (ly:music-property music 'pitch)))
64 (ly:music-set-property!
66 (map (lambda (x) (naturalize x)) es)))
68 (ly:music-set-property!
73 (set! p (naturalize-pitch p))
74 (ly:music-set-property! music 'pitch p)))
78 #(define-music-function (parser location m)
82 music = \relative c' { c4 d e g }
86 \transpose c ais { \music }
87 \naturalizeMusic \transpose c ais { \music }
88 \transpose c deses { \music }
89 \naturalizeMusic \transpose c deses { \music }