]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/putting.itely
New doc section on fixing overlapping notation.
[lilypond.git] / Documentation / user / putting.itely
1 @c -*- coding: latin-1; mode: texinfo; -*-
2 @node Putting it all together
3 @chapter Putting it all together
4
5 This section explains how to use the rest of the documentation and
6 how to solve common problems.
7
8 @menu
9 * Suggestions for writing LilyPond files::  
10 * Extending the templates::     
11 * Fixing overlapping notation::  
12 @end menu
13
14
15 @node Suggestions for writing LilyPond files
16 @section Suggestions for writing LilyPond files
17
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
20 go about doing it?
21
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
27 problem?
28
29 Here are a few suggestions that can help you to avoid or fix
30 problems:
31
32 @itemize @bullet
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.
40
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.
46
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.
51
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.
58
59 @end itemize
60
61
62 @node Extending the templates
63 @section Extending the templates
64
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?
68
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
72 soprano part).
73
74 @example
75 \version "2.4.0"
76 melody = \relative c' @{
77   \clef treble
78   \key c \major
79   \time 4/4
80
81   a4 b c d
82 @}
83
84 text = \lyricmode @{
85   Aaa Bee Cee Dee
86 @}
87
88 \score@{
89   <<
90     \context Voice = one @{
91       \autoBeamOff
92       \melody
93     @}
94     \lyricsto "one" \new Lyrics \text
95   >>
96   \layout @{ @}
97   \midi @{ \tempo 4=60 @}
98 @}
99 @end example
100
101 Now we want to add a cello part.  Let's look at the ``Notes only'' example:
102
103 @example
104 \version "2.4.0"
105 melody = \relative c' @{
106   \clef treble
107   \key c \major
108   \time 4/4
109
110   a4 b c d
111 @}
112      
113 \score @{
114 \new Staff \melody
115 \layout @{ @}
116 \midi @{ \tempo 4=60 @}
117 @}
118 @end example
119
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}.
125
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).
134
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
137 notes.
138
139 @example
140 \version "2.4.0"
141 sopranoMusic = \relative c' @{
142   \clef treble
143   \key c \major
144   \time 4/4
145
146   a4 b c d
147 @}
148
149 sopranoLyrics = \lyricmode @{
150   Aaa Bee Cee Dee
151 @}
152
153 celloMusic = \relative c @{
154   \clef bass
155   \key c \major
156   \time 4/4
157
158   d4 g fis8 e d4
159 @}
160
161 \score@{
162   <<
163     \context Voice = one @{
164       \autoBeamOff
165       \sopranoMusic
166     @}
167     \lyricsto "one" \new Lyrics \sopranoLyrics
168   >>
169   \layout @{ @}
170   \midi @{ \tempo 4=60 @}
171 @}
172 @end example
173
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
177
178 @example
179 \new Staff \celloMusic
180 @end example
181
182 @noindent
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
187
188 @example
189 \score@{
190 <<
191   <<
192     \context Voice = one @{
193       \autoBeamOff
194       \sopranoMusic
195     @}
196     \lyricsto "one" \new Lyrics \sopranoLyrics
197   >>
198   \new Staff \celloMusic
199 >>
200   \layout @{ @}
201   \midi @{ \tempo 4=60 @}
202 @}
203 @end example
204
205 @noindent
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.
208
209 @lilypond[quote,verbatim,raggedright]
210 \version "2.4.0"
211 sopranoMusic = \relative c' {
212   \clef treble
213   \key c \major
214   \time 4/4
215
216   a4 b c d
217 }
218
219 sopranoLyrics = \lyricmode {
220   Aaa Bee Cee Dee
221 }
222
223 celloMusic = \relative c {
224   \clef bass
225   \key c \major
226   \time 4/4
227
228   d4 g fis8 e d4
229 }
230
231 \score{
232   <<
233   <<
234     \context Voice = one {
235       \autoBeamOff
236       \sopranoMusic
237     }
238     \lyricsto "one" \new Lyrics \sopranoLyrics
239   >>
240   \new Staff \celloMusic
241   >>
242   \layout { }
243   \midi { \tempo 4=60 }
244 }
245 @end lilypond
246
247
248
249 @node Fixing overlapping notation
250 @section Fixing overlapping notation
251
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
254 solved.
255
256 @lilypond[quote,fragment,raggedright,verbatim,relative=2]
257 e4^\markup{ \italic ritenuto } g b e
258 @end lilypond
259
260 @cindex padding
261
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
267 try 1.5
268
269 @lilypond[quote,fragment,raggedright,verbatim,relative=2]
270 \once \override TextScript #'padding = #1.5
271 e4^\markup{ \italic ritenuto } g b e
272 @end lilypond
273
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.
277
278 @cindex extra-offset
279
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.
286
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
290 @end lilypond
291
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
296
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
300 @end lilypond
301
302
303 @seealso
304
305 This manual: @ref{The \override command}, @ref{Common tweaks}.
306
307