]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/putting.itely
First round of doc reorg.
[lilypond.git] / Documentation / user / putting.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Working on LilyPond projects
3 @chapter Working on LilyPond projects
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 * How LilyPond files work::     
13 * Score is a single musical expression::  
14 * Troubleshooting (taking it all apart)::  
15 @end menu
16
17
18 @node Suggestions for writing LilyPond files
19 @section Suggestions for writing LilyPond files
20
21 Now you're ready to begin writing larger LilyPond files -- not just the
22 little examples in the tutorial, but whole pieces.  But how should you
23 go about doing it?
24
25 The best answer is ``however you want to do it.''  As long as LilyPond
26 can understand your files and produces the output that you want, it
27 doesn't matter what your files look like.  That said, sometimes we
28 make mistakes when writing files.  If LilyPond can't understand your
29 files, or produces output that you don't like, how do you fix the
30 problem?
31
32 Here are a few suggestions that can help you to avoid or fix
33 problems:
34
35 @itemize @bullet
36 @item Include @code{\version} numbers in every file.  Note that all
37 templates contain a @code{\version "2.7.32"} string.  We
38 highly recommend that you always include the @code{\version}, no matter
39 how small your file is.  Speaking from personal experience, it's
40 quite frustrating to try to remember which version of LilyPond you were
41 using a few years ago.  @code{convert-ly} requires you to declare
42 which version of LilyPond you used.
43
44 @item Include checks: See @ref{Bar check} and @ref{Octave check}.  If you
45 include checks every so often, then if you make a mistake, you can pinpoint
46 it quicker.  How often is ``every so often''?  It depends on the complexity
47 of the music.  For very simple music, perhaps just once or twice.  For
48 very complex music, every bar.
49
50 @item One bar per line of text.  If there is anything complicated, either in the music
51 itself or in the output you desire, it's often good to write only one bar
52 per line.  Saving screen space by cramming eight bars per line just isn't
53 worth it if you have to `debug' your files.
54
55 @item Comment your files, with either bar numbers (every so often) or
56 references to musical themes (``second theme in violins'', ``fourth
57 variation'').  You may not need it when you're writing the piece for
58 the first time, but if you want to go back and change something two
59 or three years later, you won't know how your file is structured if you
60 didn't comment the file.
61
62 @item Indent your braces.  A lot of problems are caused by an imbalance
63 in the number of @code{@{} and @code{@}}.
64
65 @end itemize
66
67 If you are entering music from an existing score (i.e. typesetting a
68 piece of existing sheet music),
69
70 @itemize @bullet
71
72 @item Enter one manuscript (the physical copy) system at a time (but still
73 only one bar per line of text), and
74 check each system when you finish it.  You may use the
75 @code{showLastLength} command to speed up processing -- see
76 @ref{Skipping corrected music}.
77
78 @item Define @code{mBreak = @{ \break @}} and insert @code{\mBreak}
79 in the input file whenever the manuscript has a line break.  This
80 makes it much easier to compare the LilyPond music to the original
81 music.  When you are finished proofreading your score, you may
82 define @code{mBreak = @{ @}} to remove all those line breaks.  This
83 will allow LilyPond to place line breaks wherever it feels are
84 best.
85
86 @end itemize
87
88
89
90
91 @node Extending the templates
92 @section Extending the templates
93
94 You've read the tutorial, you know how to write music.  But how can you
95 get the staves that you want?  The templates are ok, but what if you
96 want something that isn't covered?
97
98 Start off with the template that seems closest to what you want to end
99 up with.  Let's say that you want to write something for soprano and
100 cello.  In this case, we would start with ``Notes and lyrics'' (for the
101 soprano part).
102
103 @example
104 \version "2.7.39"
105 melody = \relative c' @{
106   \clef treble
107   \key c \major
108   \time 4/4
109
110   a4 b c d
111 @}
112
113 text = \lyricmode @{
114   Aaa Bee Cee Dee
115 @}
116
117 \score@{
118   <<
119     \new Voice = "one" @{
120       \autoBeamOff
121       \melody
122     @}
123     \new Lyrics \lyricsto "one" \text
124   >>
125   \layout @{ @}
126   \midi @{ \tempo 4=60 @}
127 @}
128 @end example
129
130 Now we want to add a cello part.  Let's look at the ``Notes only'' example:
131
132 @example
133 \version "2.7.39"
134 melody = \relative c' @{
135   \clef treble
136   \key c \major
137   \time 4/4
138
139   a4 b c d
140 @}
141      
142 \score @{
143 \new Staff \melody
144 \layout @{ @}
145 \midi @{ \tempo 4=60 @}
146 @}
147 @end example
148
149 We don't need two @code{\version} commands.  We'll need the @code{melody}
150 section.  We don't want two @code{\score} sections -- if we had two
151 @code{\score}s, we'd get the two parts separately.  We want them together,
152 as a duet.  Within the @code{\score} section, we don't need two
153 @code{\layout} or @code{\midi}.
154
155 If we simply cut and paste the @code{melody} section, we would end up with
156 two @code{melody} sections.  So let's rename them.  We'll call the one
157 for the soprano @code{sopranoMusic}, and the one for the cello can be
158 called @code{celloMusic}.  While we're doing this, let's rename @code{text}
159 to be @code{sopranoLyrics}.  Remember to rename both instances of all
160 these names -- both the initial definition (the
161 @code{melody = relative c' @{ } part) and the name's use (in the
162 @code{\score} section).
163
164 While we're doing this, let's change the cello part's staff -- celli
165 normally use bass clef.  We'll also give the cello some different
166 notes.
167
168 @example
169 \version "2.7.39"
170 sopranoMusic = \relative c' @{
171   \clef treble
172   \key c \major
173   \time 4/4
174
175   a4 b c d
176 @}
177
178 sopranoLyrics = \lyricmode @{
179   Aaa Bee Cee Dee
180 @}
181
182 celloMusic = \relative c @{
183   \clef bass
184   \key c \major
185   \time 4/4
186
187   d4 g fis8 e d4
188 @}
189
190 \score@{
191   <<
192     \new Voice = "one" @{
193       \autoBeamOff
194       \sopranoMusic
195     @}
196     \new Lyrics \lyricsto "one" \sopranoLyrics
197   >>
198   \layout @{ @}
199   \midi @{ \tempo 4=60 @}
200 @}
201 @end example
202
203 This is looking promising, but the cello part won't appear in the
204 score -- we haven't used it in the @code{\score} section.  If we
205 want the cello part to appear under the soprano part, we need to add
206
207 @example
208 \new Staff \celloMusic
209 @end example
210
211 @noindent
212 underneath the soprano stuff.  We also need to add @code{<<} and
213 @code{>>} around the music -- that tells LilyPond that there's
214 more than one thing (in this case staff) happening at once.  The
215 @code{\score} looks like this now
216
217 @example
218 \score@{
219   <<
220     <<
221       \new Voice = "one" @{
222         \autoBeamOff
223         \sopranoMusic
224       @}
225       \new Lyrics \lyricsto "one" \sopranoLyrics
226     >>
227     \new Staff \celloMusic
228   >>
229   \layout @{ @}
230   \midi @{ \tempo 4=60 @}
231 @}
232 @end example
233
234 @noindent
235 This looks a bit messy; the indentation is messed up now.  That is
236 easily fixed.  Here's the complete soprano and cello template.
237
238 @lilypond[quote,verbatim,ragged-right]
239 \version "2.7.39"
240 sopranoMusic = \relative c' {
241   \clef treble
242   \key c \major
243   \time 4/4
244
245   a4 b c d
246 }
247
248 sopranoLyrics = \lyricmode {
249   Aaa Bee Cee Dee
250 }
251
252 celloMusic = \relative c {
253   \clef bass
254   \key c \major
255   \time 4/4
256
257   d4 g fis8 e d4
258 }
259
260 \score{
261   <<
262     <<
263       \new Voice = "one" {
264         \autoBeamOff
265         \sopranoMusic
266       }
267       \new Lyrics \lyricsto "one" \sopranoLyrics
268     >>
269     \new Staff \celloMusic
270   >>
271   \layout { }
272   \midi { \tempo 4=60 }
273 }
274 @end lilypond
275
276
277
278 @node Fixing overlapping notation
279 @section Fixing overlapping notation
280
281 This may come as a surprise, but LilyPond isn't perfect.  Some notation
282 elements can overlap.  This is unfortunate, but (in most cases) is easily
283 solved.
284
285 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
286 e4^\markup{ \italic ritenuto } g b e
287 @end lilypond
288
289 @cindex padding
290
291 The easiest solution is to increase the distance between the object
292 (in this case text, but it could easily be fingerings or dynamics
293 instead) and the note.  In LilyPond, this is called the
294 @code{padding} property; it is measured in staff spaces.  For most
295 objects, this value is around 1.0 or less (it varies with each
296 object). We want to increase it, so let's try 1.5
297
298 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
299 \once \override TextScript #'padding = #1.5
300 e4^\markup{ \italic ritenuto } g b e
301 @end lilypond
302
303 That looks better, but it isn't quite big enough.  After experimenting
304 with a few values, we think 2.3 is the best number in this case.  However,
305 this number is merely the result of experimentation and my personal
306 taste in notation.  Try the above example with 2.3... but also try higher
307 (and lower) numbers.  Which do you think looks the best?
308
309 @cindex extra-offset
310
311 Another solution gives us complete control over placing the object -- we
312 can move it horizontally or vertically.  This is done with the
313 @code{extra-offset} property.  It is slightly more complicated and can
314 cause other problems.  When we move objects with @code{extra-offset},
315 the movement is done after LilyPond has placed all other objects.  This means
316 that the result can overlap with other objects.
317
318 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
319 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
320 e4^\markup{ \italic ritenuto } g b e
321 @end lilypond
322
323 With @code{extra-offset}, the first number controls the horizontal
324 movement (left is negative); the second number controls the vertical
325 movement (up is positive).  After a bit of experimenting, we decided
326 that these values look good
327
328 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
329 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
330 e4^\markup{ \italic ritenuto } g b e
331 @end lilypond
332
333 @noindent
334 Again, these numbers are simply the result of a few experiments and
335 looking at the output.  You might prefer the text to be slightly higher,
336 or to the left, or whatever.  Try it and look at the result!
337
338
339 @seealso
340
341 This manual: @ref{The \override command}, @ref{Common tweaks}.
342
343
344 @node How LilyPond files work
345 @section How LilyPond files work
346
347 The LilyPond input format is quite free-form, giving experienced
348 users a lot of flexibility to structure their files however they
349 wish.  However, this flexibility can make things confusing for
350 new users.  This section will explain some of this structure, but
351 may gloss over some details in favor of simplicity.  For a complete
352 description of the input format, see @ref{File structure}.
353
354 Most examples in this manual are little snippets -- for example
355
356 @example
357 c4 a b c
358 @end example
359
360 As you are (hopefully) aware by now, this will not compile by
361 itself.  These examples are shorthand for complete
362 examples.  They all need at least curly braces to compile
363
364 @example
365 @{
366   c4 a b c
367 @}
368 @end example
369
370 Most examples also make use of the @code{\relative c'}
371 (or @code{c''}) command.  This is not necessary to merely
372 compile the examples, but in most cases the output will
373 look very odd if you omit the @code{\relative c'}.
374
375 @lilypond[quote,fragment,ragged-right,verbatim]
376 \relative c'' {
377   c4 a b c
378 }
379 @end lilypond
380
381 Now we get to the only real stumbling block: LilyPond
382 input in this form is actually @emph{another}
383 shorthand.  Although it compiles and displays the
384 correct output, it is shorthand for
385
386 @example
387 \score @{
388   \relative c'' @{
389     c4 a b c
390   @}
391 @}
392 @end example
393
394 A @code{\score} must begin with a single music
395 expression.  Remember that a music expression could
396 be anything from a single note to a huge
397
398 @example
399 @{
400   \new GrandStaff <<
401     insert the whole score of a Wagner opera in here
402   >>
403 @}
404 @end example
405
406 @noindent
407 Since everything is inside @code{@{ ... @}}, it counts
408 as one music expression.
409
410 The @code{\score} can contain other things, such as
411
412 @example
413 \score @{
414   @{ c'4 a b c' @}
415   \layout @{ @}
416   \paper @{ @}
417   \midi @{ @}
418   \header @{ @}
419 @}
420 @end example
421
422 @noindent
423 Most people put some of those commands outside the
424 @code{\score} block -- for example, @code{\header} is
425 almost always placed above the @code{\score}.  That's
426 just another shorthand.
427
428 Another great shorthand is the ability to define
429 variables.  All the templates use this
430
431 @example
432 melody = \relative c' @{
433   c4 a b c
434 @}
435
436 \score @{
437   @{ \melody @}
438 @}
439 @end example
440
441 When LilyPond looks at this file, it takes the value of
442 @code{melody} (everything after the equals sign) and
443 inserts it whenever it sees
444 @code{\melody}.  There's nothing special about the
445 names -- it could be @code{melody}, @code{global},
446 @code{pianorighthand}, or @code{foofoobarbaz}.  You
447 can use whatever variable names you want.
448
449 For a complete definition
450 of the input format, see @ref{File structure}.
451
452
453 @node Score is a single musical expression
454 @section Score is a single musical expression
455
456 In the previous section, @ref{How LilyPond files work},
457 we saw the general organization of LilyPond input
458 files.  But we seemed to skip over the most important
459 part: how do we figure out what to write after
460 @code{\score}?
461
462 We didn't skip over it at all.  The big mystery is simply
463 that there @emph{is} no mystery.  This line explains it
464 all:
465
466 @example
467 A @code{\score} must begin with a single music expression.
468 @end example
469
470 @noindent
471 You may find it useful to review
472 @ref{Music expressions explained}.  In that section, we
473 saw how to build big music expressions from small
474 pieces -- we started from notes, then chords, etc.  Now
475 we're going to start from a big music expression and
476 work our way down.
477
478 @example
479 \score @{
480   @{   % this brace begins the overall music expression
481     \new GrandStaff <<
482       insert the whole score of a Wagner opera in here
483     >>
484   @}   % this brace ends the overall music expression
485   \layout @{ @}
486 @}
487 @end example
488
489 A whole Wagner opera would easily double the length of
490 this manual, so let's just do a singer and piano.  We
491 don't need a @code{GrandStaff} for this ensemble, so we
492 shall remove it.  We @emph{do} need a singer and a piano,
493 though.
494
495 @example
496 \score @{
497   @{
498     <<
499       \new Staff = "singer" <<
500       >>
501       \new PianoStaff = piano <<
502       >>
503     >>
504   @}
505   \layout @{ @}
506 @}
507 @end example
508
509 Remember that we use @code{<<} and @code{>>} to show
510 simultaneous music.  And we definitely want to show
511 the vocal part and piano part at the same time!
512
513 @example
514 \score @{
515   @{
516     <<
517       \new Staff = "singer" <<
518         \new Voice = "vocal" @{ @}
519       >>
520       \new Lyrics \lyricsto vocal \new Lyrics @{ @}
521       \new PianoStaff = "piano" <<
522         \new Staff = "upper" @{ @}
523         \new Staff = "lower" @{ @}
524       >>
525     >>
526   @}
527   \layout @{ @}
528 @}
529 @end example
530
531 Now we have a lot more details.  We have the singer's
532 staff: it contains a @code{Voice} (in LilyPond, this
533 term refers to a set of notes, not necessarily vocal
534 notes -- for example, a violin generally plays one
535 voice) and some lyrics.  We also have a piano staff:
536 it contains an upper staff (right hand) and a lower
537 staff (left hand).
538
539 At this stage, we could start filling in notes.  Inside
540 the curly braces next to @code{\new Voice = vocal},
541 we could start writing
542
543 @example
544 \relative c'' @{
545   a4 b c d
546 @}
547 @end example
548
549 But if we did that, the @code{\score} section would
550 get pretty long, and it would be harder to understand
551 what was happening.  So let's use identifiers (or
552 variables) instead.
553
554 @example
555 melody = @{ @}
556 text = @{ @}
557 upper = @{ @}
558 lower = @{ @}
559 \score @{
560   @{
561     <<
562       \new Staff = "singer" <<
563         \new Voice = "vocal" @{ \melody @}
564       >>
565       \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
566       \new PianoStaff = "piano" <<
567         \new Staff = "upper" @{ \upper @}
568         \new Staff = "lower" @{ \lower @}
569       >>
570     >>
571   @}
572   \layout @{ @}
573 @}
574 @end example
575
576 @noindent
577 Remember that you can use almost any name you like.  The
578 limitations on identifier names are detailed in
579 @ref{File structure}.
580
581 When writing a @code{\score} section, or when reading
582 one, just take it slowly and carefully.  Start with
583 the outer layer, then work on each smaller
584 layer.  It also really helps to be strict with
585 indentation -- make sure that each item on the same
586 layer starts on the same horizontal position in your
587 text editor!
588
589
590 @node Troubleshooting (taking it all apart)
591 @section Troubleshooting (taking it all apart)
592
593 Sooner or later, you will write a file that LilyPond cannot
594 compile.  The messages that LilyPond gives may help
595 you find the error, but in many cases you need to do some
596 investigation to determine the source of the problem.
597
598 The most powerful tools for this purpose are the
599 single line comment (indicated by @code{%}) and the block
600 comment (indicated by @code{%@{ ... %@}}).  If you don't
601 know where a problem is, start commenting out huge portions
602 of your input file.  After you comment out a section, try
603 compiling the file again.  If it works, then the problem
604 must exist in the portion you just commented.  If it doesn't
605 work, then keep on commenting out material until you have
606 something that works.
607
608 In an extreme case, you might end up with only
609
610 @example
611 \score @{
612   <<
613     % \melody
614     % \harmony
615     % \bass
616   >>
617   \layout@{@}
618 @}
619 @end example
620
621 @noindent
622 (in other words, a file without any music)
623
624 If that happens, don't give up.  Uncomment a bit -- say,
625 the bass part -- and see if it works.  If it doesn't work,
626 then comment out all of the bass music (but leave
627 @code{\bass} in the @code{\score} uncommented.
628
629 @example
630 bass = \relative c' @{
631 %@{
632   c4 c c c
633   d d d d
634 %@}
635 @}
636 @end example
637
638 Now start slowly uncommenting more and more of the
639 @code{bass} part until you find the problem line.
640