]> git.donarmstrong.com Git - lilypond.git/blob - input/test/reverse-music.ly
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / input / test / reverse-music.ly
1
2 \version "2.7.39"
3 % possible rename to scheme-something.
4 \header { texidoc="@cindex Scheme Reverse Music
5 Symmetric, or palindromical music can be produced, first, by printing
6 some music, and second, by printing the same music applying a Scheme
7 function to reverse the syntax.
8 "
9 }
10
11 music =  \relative c'' { c4 d4( e4 f4 }
12
13 #(define (reverse-music music)
14   (let* ((elements (ly:music-property music 'elements))
15          (reversed (reverse elements))
16          (e (ly:music-property music 'element))
17          (span-dir (ly:music-property music 'span-direction)))
18
19     (ly:music-set-property! music 'elements reversed)
20
21     (if (ly:music? e)
22         (ly:music-set-property!
23          music 'element
24          (reverse-music e)))
25
26     (if (ly:dir? span-dir)
27         (ly:music-set-property! music 'span-direction (- span-dir)))
28
29     (map reverse-music reversed)
30
31     music))
32
33 \score {
34   \context Voice {
35     \music
36     \applyMusic #reverse-music \music
37   }
38   \layout { ragged-right = ##t}
39 }
40
41