]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-1.5.17
authorfred <fred>
Wed, 27 Mar 2002 01:02:09 +0000 (01:02 +0000)
committerfred <fred>
Wed, 27 Mar 2002 01:02:09 +0000 (01:02 +0000)
input/test/unfold-all-repeats.ly [new file with mode: 0644]
scm/music-functions.scm

diff --git a/input/test/unfold-all-repeats.ly b/input/test/unfold-all-repeats.ly
new file mode 100644 (file)
index 0000000..6d35bbc
--- /dev/null
@@ -0,0 +1,25 @@
+
+\header { 
+texidoc = "The standard function unfold-repeats will recursively unfold
+all repeats for correct MIDI output. Thanks to Rune Zedeler."
+}
+
+
+mel = \notes \context Staff {
+  \repeat tremolo 8 {c'32 e' }
+  \repeat percent 2 { c''8 d'' }
+  \repeat volta 2 {c'4 d' e' f'} 
+  \alternative {
+    { g' a' a' g' }
+    {f' e' d' c' }
+  }
+  \bar "|."
+}
+
+\score { \notes {
+  \mel \break
+  \apply #unfold-repeats \mel
+ }
+}
+
+
index b708b44768c993e9527cba9a81216a40e5203033..52a9a4a5e3f66a1cbe73648d0e13fd01ff0372f6 100644 (file)
@@ -8,3 +8,54 @@
                 (number->string (ly-get-mus-property mus 'denominator))
                 ))
 
+(define (unfold-repeats music)
+"
+[Rune Zedeler]
+
+Han-Wen Nienhuys wrote:
+
+> It shouldn't be hard to write a Scheme function to replace all repeats
+> with unfold repeats.
+[...]
+> Left to the reader as an exercise.
+
+With thanks to Han-Wen:
+
+
+"
+  (let* ((es (ly-get-mus-property music 'elements))
+         (e (ly-get-mus-property music 'element))
+         (body (ly-get-mus-property music 'body))
+         (alts (ly-get-mus-property music 'alternatives))
+         (n  (ly-music-name music)))
+
+    (if (equal? n "Repeated_music")
+        (begin
+          (ly-set-mus-property
+           music 'length Repeated_music::unfolded_music_length)
+          (ly-set-mus-property
+           music 'iterator-ctor Unfolded_repeat_iterator::constructor)))
+
+    (if (pair? es)
+        (ly-set-mus-property
+         music 'elements
+         (map unfold-repeats es)))
+
+    (if (music? alts)
+        (ly-set-mus-property
+         music 'alternatives
+         (unfold-repeats alts)))
+
+    (if (music? body)
+        (ly-set-mus-property
+         music 'body
+         (unfold-repeats body)))
+
+    (if (music? e)
+        (ly-set-mus-property
+         music 'element
+         (unfold-repeats e)))
+
+
+    music))
+