]> git.donarmstrong.com Git - lilypond.git/blobdiff - input/new/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
LSR: Update.
[lilypond.git] / input / new / transposing-pitches-with-minimum-accidentals-smart-transpose.ly
diff --git a/input/new/transposing-pitches-with-minimum-accidentals-smart-transpose.ly b/input/new/transposing-pitches-with-minimum-accidentals-smart-transpose.ly
deleted file mode 100644 (file)
index 1ff8444..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-\version "2.12.0"
-\header {
-  lsrtags = "pitches"
-  texidoc = "This example uses some Scheme code to enforce enharmonic
-modifications for notes in order to have the minimum number of
-accidentals.  In this case, the following rules apply:
-
-@itemize
-@item
-Double accidentals should be removed
-
-@item
-B sharp -> C
-
-@item
-E sharp -> F
-
-@item
-C flat -> B
-
-@item
-F flat -> E
-
-@end itemize
-
-In this manner, the most natural enharmonic notes are chosen.
-"
-  doctitle = "Transposing music with minimum accidentals"
-}
-
-#(define  (naturalize-pitch p)
-  (let* ((o (ly:pitch-octave p))
-         (a (* 4 (ly:pitch-alteration p)))
-         ; alteration, a, in quarter tone steps,
-         ; for historical reasons
-         (n (ly:pitch-notename p)))
-    (cond
-     ((and (> a 1) (or (eq? n 6) (eq? n 2)))
-      (set! a (- a 2))
-      (set! n (+ n 1)))
-     ((and (< a -1) (or (eq? n 0) (eq? n 3)))
-      (set! a (+ a 2))
-      (set! n (- n 1))))
-    (cond
-     ((> a 2) (set! a (- a 4)) (set! n (+ n 1)))
-     ((< a -2) (set! a (+ a 4)) (set! n (- n 1))))
-    (if (< n 0) (begin (set! o (- o 1)) (set! n (+ n 7))))
-    (if (> n 6) (begin (set! o (+ o 1)) (set! n (- n 7))))
-    (ly:make-pitch o n (/ a 4))))
-
-#(define (naturalize music)
-  (let* ((es (ly:music-property music 'elements))
-         (e (ly:music-property music 'element))
-         (p (ly:music-property music 'pitch)))
-    (if (pair? es)
-       (ly:music-set-property!
-         music 'elements
-         (map (lambda (x) (naturalize x)) es)))
-    (if (ly:music? e)
-       (ly:music-set-property!
-         music 'element
-         (naturalize e)))
-    (if (ly:pitch? p)
-       (begin
-         (set! p (naturalize-pitch p))
-         (ly:music-set-property! music 'pitch p)))
-    music))
-
-naturalizeMusic =
-#(define-music-function (parser location m)
-  (ly:music?)
-  (naturalize m))
-
-music = \relative c' { c4 d e g }
-
-\score {
-  \new Staff {
-    \transpose c ais { \music }
-    \naturalizeMusic \transpose c ais { \music }
-    \transpose c deses { \music }
-    \naturalizeMusic \transpose c deses { \music }
-  }
-  \layout { }
-}