From 21a17ec326046cce3465194e55ac7f31bd142290 Mon Sep 17 00:00:00 2001 From: fred Date: Wed, 27 Mar 2002 01:02:09 +0000 Subject: [PATCH] lilypond-1.5.17 --- input/test/unfold-all-repeats.ly | 25 ++++++++++++++++ scm/music-functions.scm | 51 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 input/test/unfold-all-repeats.ly diff --git a/input/test/unfold-all-repeats.ly b/input/test/unfold-all-repeats.ly new file mode 100644 index 0000000000..6d35bbc565 --- /dev/null +++ b/input/test/unfold-all-repeats.ly @@ -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 + } +} + + diff --git a/scm/music-functions.scm b/scm/music-functions.scm index b708b44768..52a9a4a5e3 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -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)) + -- 2.39.5