1 % DO NOT EDIT this file manually; it is automatically
2 % generated from Documentation/snippets/new
3 % Make any changes in Documentation/snippets/new/
4 % and then run scripts/auxiliar/makelsr.py
6 % This file is in the public domain.
7 %% Note: this file works from version 2.19.22
11 lsrtags = "pitches, scheme-language, workaround"
14 This example uses some Scheme code to enforce enharmonic modifications
15 for notes in order to have the minimum number of accidentals. In this
16 case, the following rules apply:
18 Double accidentals should be removed
33 In this manner, the most natural enharmonic notes are chosen.
36 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 (eqv? n 6) (eqv? n 2)))
49 ((and (< a -1) (or (eqv? n 0) (eqv? 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!
68 (ly:music-set-property!
73 (set! p (naturalize-pitch p))
74 (ly:music-set-property! music 'pitch p)))
78 #(define-music-function (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 }