]> git.donarmstrong.com Git - lilypond.git/blobdiff - input/test/smart-transpose.ly
release: 1.5.23
[lilypond.git] / input / test / smart-transpose.ly
index 388ae4eec397ff91f580beddd09c5c8d8ca908e2..3674d81008b030e4e746d782c1e741fba021099e 100644 (file)
@@ -1,99 +1,73 @@
-\header {
-texidoc="LilyPond 1.3 is more flexible than some users realise.  Han-Wen could be very rich.
-";
-}
-
-% Btw, I've leant an el-neato trick for formatting code in email messages,
-% using inderect buffers.
-%
-% M-x make-indirect-buffer RET RET foo RET C-x b foo RET
-% Select region and then narrow: C-x n n
-% Set mode, eg: M-x sch TAB RET
-%
-
-%{
-    I've just entered a request on cosource.com :
+\version "1.5.18"
 
-        http://www.cosource.com/cgi-bin/cos.pl/wish/info/387
+\header {
+texidoc="
+@example
     Here's a copy of my feature request :
+@quotation
         Your task, if you accept it is to implement a \smarttranspose
         command> that would translate such oddities into more natural
-        notations. Double accidentals should be removed, as well as #E
-        (-> F), bC (-> B), bF (-> E), #B (-> C).
+        notations. Double accidentals should be removed, as well as E-sharp
+        (-> F), bC (-> B), bF (-> E), B-sharp (-> C).
+@end quotation
 
 You mean like this. (Sorry 'bout the nuked indentation.)
 
-Add IMPLEMENT_TYPE_P(Music, "music?"); to music.cc, and presto, done.
-
-That's an easy $ 100; if I'd make $ 200/hour for every hour I worked
-on Lily, I'd be very rich :)
-
-%}
+Modified to use the standard transpose mechanism. The question is
+how useful these enharmonic modifications are. Mats B.
+@end example
+"
+}
 
 #(define  (unhair-pitch p)
   (let* ((o (pitch-octave p))
          (a (pitch-alteration p))
-        (n (pitch-notename p)))
+         (n (pitch-notename p)))
 
     (cond
      ((and (> a 0) (or (eq? n 6) (eq? n 2)))
       (set! a (- a 1)) (set! n (+ n 1)))
      ((and (< a 0) (or (eq? n 0) (eq? n 3)))
       (set! a (+ a 1)) (set! n (- n 1))))
-    
+
     (cond
      ((eq? a 2)  (set! a 0) (set! n (+ n 1)))
      ((eq? a -2) (set! a 0) (set! n (- n 1))))
 
     (if (< n 0) (begin (set!  o (- o 1)) (set! n (+ n 7))))
-    (if (> n 7) (begin (set!  o (+ o 1)) (set! n (- n 7))))
-    
+    (if (> n 6) (begin (set!  o (+ o 1)) (set! n (- n 7))))
+
     (make-pitch o n a)))
 
-#(define (smart-transpose music pitch)
+#(define (simplify music)
   (let* ((es (ly-get-mus-property music 'elements))
-        (e (ly-get-mus-property music 'element))
-        (p (ly-get-mus-property music 'pitch))
-        (body (ly-get-mus-property music 'body))
-        (alts (ly-get-mus-property music 'alternatives)))
+         (e (ly-get-mus-property music 'element))
+         (p (ly-get-mus-property music 'pitch)))
 
     (if (pair? es)
-       (ly-set-mus-property
-        music 'elements
-        (map (lambda (x) (smart-transpose x pitch)) es)))
-    
-    (if (music? alts)
-       (ly-set-mus-property
-        music 'alternatives
-        (smart-transpose alts pitch)))
-    
-    (if (music? body)
-       (ly-set-mus-property
-        music 'body
-        (smart-transpose body pitch)))
+        (ly-set-mus-property
+         music 'elements
+         (map (lambda (x) (simplify x)) es)))
 
     (if (music? e)
-       (ly-set-mus-property
-        music 'element
-        (smart-transpose e pitch)))
-    
+        (ly-set-mus-property
+         music 'element
+         (simplify e)))
+
     (if (pitch? p)
-       (begin
-         (set! p (unhair-pitch (Pitch::transpose p pitch)))
-         (ly-set-mus-property music 'pitch p)))
-    
-    music))
+        (begin
+          (set! p (unhair-pitch p))
+          (ly-set-mus-property music 'pitch p)))
 
+    music))
 
 music = \notes \relative c' { c4 d  e f g a b  c }
 
 \score {
   \notes \context Staff {
     \transpose ais' \music
-    \apply #(lambda (x) (smart-transpose x (make-pitch 0 5 1)))
-      \music
+    \apply #simplify \transpose ais' \music
   }
-  \paper { linewidth = -1.; }
+  \paper { linewidth = -1. }
 }
+