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::
11 * Fixing overlapping notation::
15 @node Suggestions for writing LilyPond files
16 @section Suggestions for writing LilyPond files
18 Now you're ready to begin writing larger LilyPond files -- not just the
19 little examples in the tutorial, but whole pieces. But how should you
22 The best answer is ``however you want to do it.'' As long as LilyPond
23 can understand your files and produces the output that you want, it
24 doesn't matter what your files look like. That said, sometimes we
25 make mistakes when writing files. If LilyPond can't understand your
26 files, or produces output that you don't like, how do you fix the
29 Here are a few suggestions that can help you to avoid or fix
33 @item Include @code{\version} numbers in every file. Note that all
34 templates contain a @code{\version "2.6.0"} string. We
35 highly recommend that you always include the @code{\version}, no matter
36 how small your file is. Speaking from personal experience, it's
37 quite frustrating to try to remember which version of LilyPond you were
38 using a few years ago. @code{convert-ly} requires you to declare
39 which version of LilyPond you used.
41 @item Include checks: See @ref{Bar check} and @ref{Octave check}. If you
42 include checks every so often, then if you make a mistake, you can pinpoint
43 it quicker. How often is ``every so often''? It depends on the complexity
44 of the music. For very simple music, perhaps just once or twice. For
45 very complex music, every bar.
47 @item One bar per line. If there is anything complicated, either in the music
48 itself or in the output you desire, it's often good to write only one bar
49 per line. Saving screen space by cramming eight bars per line just isn't
50 worth it if you have to `debug' your files.
52 @item Comment your files, with either bar numbers (every so often) or
53 references to musical themes (``second theme in violins'', ``fourth
54 variation''). You may not need it when you're writing the piece for
55 the first time, but if you want to go back and change something two
56 or three years later, you won't know how your file is structured if you
57 don't comment the file.
62 @node Extending the templates
63 @section Extending the templates
65 You've read the tutorial, you know how to write music. But how can you
66 get the staves that you want? The templates are ok, but what if you
67 want something that isn't covered?
69 Start off with the template that seems closest to what you want to end
70 up with. Let's say that you want to write something for soprano and
71 cello. In this case, we would start with ``Notes and lyrics'' (for the
76 melody = \relative c' @{
90 \context Voice = one @{
94 \lyricsto "one" \new Lyrics \text
97 \midi @{ \tempo 4=60 @}
101 Now we want to add a cello part. Let's look at the ``Notes only'' example:
105 melody = \relative c' @{
116 \midi @{ \tempo 4=60 @}
120 We don't need two @code{\version} commands. We'll need the @code{melody}
121 section. We don't want two @code{\score} sections -- if we had two
122 @code{\score}s, we'd get the two parts separately. We want them together,
123 as a duet. Within the @code{\score} section, we don't need two
124 @code{\layout} or @code{\midi}.
126 If we simply cut and paste the @code{melody} section, we would end up with
127 two @code{melody} sections. So let's rename them. We'll call the one
128 for the soprano @code{sopranoMusic}, and the one for the cello can be
129 called @code{celloMusic}. While we're doing this, let's rename @code{text}
130 to be @code{sopranoLyrics}. Remember to rename both instances of all
131 these names -- both the initial definition (the
132 @code{melody = relative c' @{ } part) and the name's use (in the
133 @code{\score} section).
135 While we're doing this, let's change the cello part's staff -- celli
136 normally use bass clef. We'll also give the cello some different
141 sopranoMusic = \relative c' @{
149 sopranoLyrics = \lyricmode @{
153 celloMusic = \relative c @{
163 \context Voice = one @{
167 \lyricsto "one" \new Lyrics \sopranoLyrics
170 \midi @{ \tempo 4=60 @}
174 This is looking promising, but the cello part won't appear in the
175 score -- we haven't used it in the @code{\score} section. If we
176 want the cello part to appear under the soprano part, we need to add
179 \new Staff \celloMusic
183 underneath the soprano stuff. We also need to add @code{<<} and
184 @code{>>} around the music -- that tells LilyPond that there's
185 more than one thing (in this case staff) happening at once. The
186 @code{\score} looks like this now
192 \context Voice = one @{
196 \lyricsto "one" \new Lyrics \sopranoLyrics
198 \new Staff \celloMusic
201 \midi @{ \tempo 4=60 @}
206 This looks a bit messy; the indentation is messed up now. That is
207 easily fixed. Here's the complete soprano and cello template.
209 @lilypond[quote,verbatim,raggedright]
211 sopranoMusic = \relative c' {
219 sopranoLyrics = \lyricmode {
223 celloMusic = \relative c {
234 \context Voice = one {
238 \lyricsto "one" \new Lyrics \sopranoLyrics
240 \new Staff \celloMusic
243 \midi { \tempo 4=60 }
249 @node Fixing overlapping notation
250 @section Fixing overlapping notation
252 This may come as a surprise, but LilyPond isn't perfect. Some notation
253 elements can overlap. This is unfortunate, but (in most cases) is easily
256 @lilypond[quote,fragment,raggedright,verbatim,relative=2]
257 e4^\markup{ \italic ritenuto } g b e
262 The easiest solution is to increase the distance between the object
263 (in this case text, but it could easily be fingerings or dynamics
264 instead) and the note. In LilyPond, this is called the
265 @code{padding} property. For most objects, it is around 1.0 or
266 less (it varies with each object). We want to increase it, so let's
269 @lilypond[quote,fragment,raggedright,verbatim,relative=2]
270 \once \override TextScript #'padding = #1.5
271 e4^\markup{ \italic ritenuto } g b e
274 That looks better, but it isn't quite big enough. After experimenting
275 with a few values, I think 2.3 is the best number. I leave this as an
276 exercise for the reader.
280 Another solution gives us complete control over placing the object -- we
281 can move it horizontally or vertically. This is done with the
282 @code{extra-offset} property. It is slightly more complicated and can
283 cause other problems. When we move objects with @code{extra-offset},
284 the movement is done after LilyPond has placed all other objects. This means
285 that the result can overlap with other objects.
287 @lilypond[quote,fragment,raggedright,verbatim,relative=2]
288 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
289 e4^\markup{ \italic ritenuto } g b e
292 With @code{extra-offset}, the first number controls the horizontal
293 movement (left is negative); the second number controls the vertial
294 movement (up is positive). After a bit of experimenting, I decided
295 that these values look good
297 @lilypond[quote,fragment,raggedright,verbatim,relative=2]
298 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
299 e4^\markup{ \italic ritenuto } g b e
305 This manual: @ref{The \override command}, @ref{Common tweaks}.