]> git.donarmstrong.com Git - lilypond.git/blob - input/test/music-box.ly
af8efd382b493fbe4fae78b7dc92dcc56ab59169
[lilypond.git] / input / test / music-box.ly
1 \version "2.9.16"
2 \sourcefilename "music-box.ly"
3
4 \include "deutsch.ly"
5 % possible rename to scheme- something.  -gp
6 % TODO: ask if it needs to have so many empty bars in the middle.  -gp
7 \header{ texidoc = "@cindex Scheme Music Box
8 This example shows prelude in C major of WTK1, but coded
9 using Scheme functions to avoid typing work. " }
10
11
12 #(define (transform music)
13   (let* ((es (ly:music-property music 'elements))
14          (n  (ly:music-property music 'name)))
15    (if (not (equal? n 'SequentialMusic))
16      (ly:warning "transform needs SequentialMusic, got ~a" n)
17      (begin
18       (let recurse ((elts es))
19        (if (not (equal? elts '()))
20          (begin
21            ((trans (ly:music-property (cadr elts) 'elements)) (car elts))
22            (set-cdr! elts (cddr elts))
23            (recurse (cdr elts))
24          )))))
25    music
26   ))
27
28 #(define ((trans pitches) music)
29   (let* ((es (ly:music-property music 'elements))
30          (e (ly:music-property music 'element))
31          (p (ly:music-property music 'pitch)))
32
33     (if (pair? es)
34         (ly:music-set-property!
35          music 'elements
36          (map (trans pitches) es)))
37
38     (if (ly:music? e)
39         (ly:music-set-property!
40          music 'element
41          ((trans pitches) e)))
42
43     (if (ly:pitch? p)
44        (let* ((o (ly:pitch-octave p))
45               (n (ly:pitch-notename p))
46               (i (+ (* 7 o) n))
47               (pes (ly:music-property (list-ref pitches i) 'elements))
48               (pnew (ly:music-property (car pes) 'pitch))
49              )
50           (ly:music-set-property! music 'pitch pnew)
51         ))
52     music))
53
54
55 pat =  \transpose c c' \repeat unfold 2 {
56   << { \context Staff = "up" {r8 e16 f g e f g } }
57     { \context Staff = "down" <<
58       \context Voice = "vup"  { \stemUp \tieUp r16 d8.~d4 }
59       \context Voice = "vdwn" { \stemDown  c2 }
60     >> }
61   >>
62 }
63
64 enda =  { r8 f,16 a, c f c a, \stemUp c \change Staff = down
65       a, f, a, f, d, f, d, \change Staff = up \stemNeutral
66       r8 g16 h d' f' d' h d' h g h d f e\prall d <e g c'>1^\fermata \bar "|."
67 }
68 endb =  {\stemUp \tieUp r16 c,8.~c,4~c,2 r16 h,,8.~h,,4~h,,2 c,1 \bar "|."}
69 endc =  {\stemDown \tieDown c,,2~c,, c,,~c,, c,,1_\fermata }
70
71
72 prelude =
73 #(define-music-function (parser location patterns) (ly:music?)
74                         (transform patterns))
75
76
77 \score {
78    \transpose c c' \context PianoStaff <<
79        \new Staff = "up"   { \clef "G"  }
80        \new Staff = "down" { \clef "F" }
81        { \prelude {
82            \pat {c e g c' e' }
83            \pat {c d a d' f' }
84        }
85         
86 %{
87                                 %Etc.
88
89                                 %we get the idea now.
90
91
92          \pat {h, d g d' f' }
93          \pat {c e g c' e' }
94
95          \pat {c e a e' a' }
96          \pat {c d fis a d'  }
97          \pat {h, d g d' g' }
98          \pat {h, c e g c' }
99          \pat {a, c e g c'  }
100          \pat {d, a, d fis c' }
101          \pat {g, h, d g h }
102          \pat {g, b, e g cis'  }
103          \pat {f, a, d a d' }
104          \pat {f, as, d f h }
105          \pat {e, g, c g c' }
106          \pat {e, f, a, c f }
107          \pat {d, f, a, c f }
108
109          \pat {g,, d, g, h, f }
110          \pat {c, e, g, c e }
111          \pat {c, g, b, c e }
112          \pat {f,, f, a, c e  }
113          \pat {fis,, c, a, c es }
114          \pat {as,, f, h, c d }
115          \pat {g,, f, g, h, d }
116          \pat {g,, e, g, c e }
117          \pat {g,, d, g, c f }
118          \pat {g,, d, g, h, f }
119          \pat {g,, es, a, c fis }
120          \pat {g,, e, g, c g }
121          \pat {g,, d, g, c f }
122          \pat {g,, d, g, h, f }
123          \pat {c,, c, g, b, e }
124 %}
125      }
126    >>
127
128    \layout {
129        \context {
130            \PianoStaff
131            \override VerticalAlignment #'forced-distance = #10
132        }
133        line-width = 18.0 \cm
134    }
135
136    
137   \midi {
138     \context {
139       \Score
140       tempoWholesPerMinute = #(ly:make-moment 80 4)
141       }
142     }
143
144
145 }
146