1 @c -*- coding: latin-1; mode: texinfo; -*-
2 @node Putting it all together
3 @chapter Putting it all together
5 This section explains how to use the rest of the documentation and
6 how to solve common problems.
9 * Suggestions for writing LilyPond files::
10 * Extending the templates::
14 @node Suggestions for writing LilyPond files
15 @section Suggestions for writing LilyPond files
17 Now you're ready to begin writing larger LilyPond files -- not just the
18 little examples in the tutorial, but whole pieces. But how should you
21 The best answer is ``however you want to do it.'' As long as LilyPond
22 can understand your files and produces the output that you want, it
23 doesn't matter what your files look like. That said, sometimes we
24 make mistakes when writing files. If LilyPond can't understand your
25 files, or produces output that you don't like, how do you fix the
28 Here are a few suggestions that can help you to avoid or fix
32 @item Include @code{\version} numbers in every file. Note that all
33 templates contain a @code{\version "2.6.0"} string. We
34 highly recommend that you always include the @code{\version}, no matter
35 how small your file is. Speaking from personal experience, it's
36 quite frustrating to try to remember which version of LilyPond you were
37 using a few years ago. @code{convert-ly} requires you to declare
38 which version of LilyPond you used.
40 @item Include checks: See @ref{Bar check} and @ref{Octave check}. If you
41 include checks every so often, then if you make a mistake, you can pinpoint
42 it quicker. How often is ``every so often''? It depends on the complexity
43 of the music. For very simple music, perhaps just once or twice. For
44 very complex music, every bar.
46 @item One bar per line. If there is anything complicated, either in the music
47 itself or in the output you desire, it's often good to write only one bar
48 per line. Saving screen space by cramming eight bars per line just isn't
49 worth it if you have to `debug' your files.
51 @item Comment your files, with either bar numbers (every so often) or
52 references to musical themes (``second theme in violins'', ``fourth
53 variation''). You may not need it when you're writing the piece for
54 the first time, but if you want to go back and change something two
55 or three years later, you won't know how your file is structured if you
56 don't comment the file.
61 @node Extending the templates
62 @section Extending the templates
64 You've read the tutorial, you know how to write music. But how can you
65 get the staves that you want? The templates are ok, but what if you
66 want something that isn't covered?
68 Start off with the template that seems closest to what you want to end
69 up with. Let's say that you want to write something for soprano and
70 cello. In this case, we would start with ``Notes and lyrics'' (for the
75 melody = \relative c' @{
89 \context Voice = one @{
93 \lyricsto "one" \new Lyrics \text
96 \midi @{ \tempo 4=60 @}
100 Now we want to add a cello part. Let's look at the ``Notes only'' example:
104 melody = \relative c' @{
115 \midi @{ \tempo 4=60 @}
119 We don't need two @code{\version} commands. We'll need the @code{melody}
120 section. We don't want two @code{\score} sections -- if we had two
121 @code{\score}s, we'd get the two parts separately. We want them together,
122 as a duet. Within the @code{\score} section, we don't need two
123 @code{\layout} or @code{\midi}.
125 If we simply cut and paste the @code{melody} section, we would end up with
126 two @code{melody} sections. So let's rename them. We'll call the one
127 for the soprano @code{sopranoMusic}, and the one for the cello can be
128 called @code{celloMusic}. While we're doing this, let's rename @code{text}
129 to be @code{sopranoLyrics}. Remember to rename both instances of all
130 these names -- both the initial definition (the
131 @code{melody = relative c' @{ } part) and the name's use (in the
132 @code{\score} section).
134 While we're doing this, let's change the cello part's staff -- celli
135 normally use bass clef. We'll also give the cello some different
140 sopranoMusic = \relative c' @{
148 sopranoLyrics = \lyricmode @{
152 celloMusic = \relative c @{
162 \context Voice = one @{
166 \lyricsto "one" \new Lyrics \sopranoLyrics
169 \midi @{ \tempo 4=60 @}
173 This is looking promising, but the cello part won't appear in the
174 score -- we haven't used it in the @code{\score} section. If we
175 want the cello part to appear under the soprano part, we need to add
178 \new Staff \celloMusic
182 underneath the soprano stuff. We also need to add @code{<<} and
183 @code{>>} around the music -- that tells LilyPond that there's
184 more than one thing (in this case staff) happening at once. The
185 @code{\score} looks like this now
191 \context Voice = one @{
195 \lyricsto "one" \new Lyrics \sopranoLyrics
197 \new Staff \celloMusic
200 \midi @{ \tempo 4=60 @}
205 This looks a bit messy; the indentation is messed up now. That is
206 easily fixed. Here's the complete soprano and cello template.
208 @lilypond[quote,verbatim,raggedright]
210 sopranoMusic = \relative c' {
218 sopranoLyrics = \lyricmode {
222 celloMusic = \relative c {
233 \context Voice = one {
237 \lyricsto "one" \new Lyrics \sopranoLyrics
239 \new Staff \celloMusic
242 \midi { \tempo 4=60 }