]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/putting.itely
Second round of reorg for the Learning manual.
[lilypond.git] / Documentation / user / putting.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Putting it all together
3 @chapter Putting it all together
4
5 This chapter is an extention of the tutorial, dealing with FIXME.
6
7
8 @menu
9 * Extending the templates::     
10 * How LilyPond files work::     
11 * Score is a single musical expression::  
12 * Organizing larger pieces::    
13 * An orchestral part::          
14 @end menu
15
16
17 @node Extending the templates
18 @section Extending the templates
19
20 You've read the tutorial, you know how to write music.  But how can you
21 get the staves that you want?  The templates are ok, but what if you
22 want something that isn't covered?
23
24 Start off with the template that seems closest to what you want to end
25 up with.  Let's say that you want to write something for soprano and
26 cello.  In this case, we would start with ``Notes and lyrics'' (for the
27 soprano part).
28
29 @example
30 \version "2.7.39"
31 melody = \relative c' @{
32   \clef treble
33   \key c \major
34   \time 4/4
35
36   a4 b c d
37 @}
38
39 text = \lyricmode @{
40   Aaa Bee Cee Dee
41 @}
42
43 \score@{
44   <<
45     \new Voice = "one" @{
46       \autoBeamOff
47       \melody
48     @}
49     \new Lyrics \lyricsto "one" \text
50   >>
51   \layout @{ @}
52   \midi @{ \tempo 4=60 @}
53 @}
54 @end example
55
56 Now we want to add a cello part.  Let's look at the ``Notes only'' example:
57
58 @example
59 \version "2.7.39"
60 melody = \relative c' @{
61   \clef treble
62   \key c \major
63   \time 4/4
64
65   a4 b c d
66 @}
67      
68 \score @{
69 \new Staff \melody
70 \layout @{ @}
71 \midi @{ \tempo 4=60 @}
72 @}
73 @end example
74
75 We don't need two @code{\version} commands.  We'll need the @code{melody}
76 section.  We don't want two @code{\score} sections -- if we had two
77 @code{\score}s, we'd get the two parts separately.  We want them together,
78 as a duet.  Within the @code{\score} section, we don't need two
79 @code{\layout} or @code{\midi}.
80
81 If we simply cut and paste the @code{melody} section, we would end up with
82 two @code{melody} sections.  So let's rename them.  We'll call the one
83 for the soprano @code{sopranoMusic}, and the one for the cello can be
84 called @code{celloMusic}.  While we're doing this, let's rename @code{text}
85 to be @code{sopranoLyrics}.  Remember to rename both instances of all
86 these names -- both the initial definition (the
87 @code{melody = relative c' @{ } part) and the name's use (in the
88 @code{\score} section).
89
90 While we're doing this, let's change the cello part's staff -- celli
91 normally use bass clef.  We'll also give the cello some different
92 notes.
93
94 @example
95 \version "2.7.39"
96 sopranoMusic = \relative c' @{
97   \clef treble
98   \key c \major
99   \time 4/4
100
101   a4 b c d
102 @}
103
104 sopranoLyrics = \lyricmode @{
105   Aaa Bee Cee Dee
106 @}
107
108 celloMusic = \relative c @{
109   \clef bass
110   \key c \major
111   \time 4/4
112
113   d4 g fis8 e d4
114 @}
115
116 \score@{
117   <<
118     \new Voice = "one" @{
119       \autoBeamOff
120       \sopranoMusic
121     @}
122     \new Lyrics \lyricsto "one" \sopranoLyrics
123   >>
124   \layout @{ @}
125   \midi @{ \tempo 4=60 @}
126 @}
127 @end example
128
129 This is looking promising, but the cello part won't appear in the
130 score -- we haven't used it in the @code{\score} section.  If we
131 want the cello part to appear under the soprano part, we need to add
132
133 @example
134 \new Staff \celloMusic
135 @end example
136
137 @noindent
138 underneath the soprano stuff.  We also need to add @code{<<} and
139 @code{>>} around the music -- that tells LilyPond that there's
140 more than one thing (in this case staff) happening at once.  The
141 @code{\score} looks like this now
142
143 @example
144 \score@{
145   <<
146     <<
147       \new Voice = "one" @{
148         \autoBeamOff
149         \sopranoMusic
150       @}
151       \new Lyrics \lyricsto "one" \sopranoLyrics
152     >>
153     \new Staff \celloMusic
154   >>
155   \layout @{ @}
156   \midi @{ \tempo 4=60 @}
157 @}
158 @end example
159
160 @noindent
161 This looks a bit messy; the indentation is messed up now.  That is
162 easily fixed.  Here's the complete soprano and cello template.
163
164 @lilypond[quote,verbatim,ragged-right]
165 \version "2.7.39"
166 sopranoMusic = \relative c' {
167   \clef treble
168   \key c \major
169   \time 4/4
170
171   a4 b c d
172 }
173
174 sopranoLyrics = \lyricmode {
175   Aaa Bee Cee Dee
176 }
177
178 celloMusic = \relative c {
179   \clef bass
180   \key c \major
181   \time 4/4
182
183   d4 g fis8 e d4
184 }
185
186 \score{
187   <<
188     <<
189       \new Voice = "one" {
190         \autoBeamOff
191         \sopranoMusic
192       }
193       \new Lyrics \lyricsto "one" \sopranoLyrics
194     >>
195     \new Staff \celloMusic
196   >>
197   \layout { }
198   \midi { \tempo 4=60 }
199 }
200 @end lilypond
201
202
203
204 @node How LilyPond files work
205 @section How LilyPond files work
206
207 The LilyPond input format is quite free-form, giving experienced
208 users a lot of flexibility to structure their files however they
209 wish.  However, this flexibility can make things confusing for
210 new users.  This section will explain some of this structure, but
211 may gloss over some details in favor of simplicity.  For a complete
212 description of the input format, see @ref{File structure}.
213
214 Most examples in this manual are little snippets -- for example
215
216 @example
217 c4 a b c
218 @end example
219
220 As you are (hopefully) aware by now, this will not compile by
221 itself.  These examples are shorthand for complete
222 examples.  They all need at least curly braces to compile
223
224 @example
225 @{
226   c4 a b c
227 @}
228 @end example
229
230 Most examples also make use of the @code{\relative c'}
231 (or @code{c''}) command.  This is not necessary to merely
232 compile the examples, but in most cases the output will
233 look very odd if you omit the @code{\relative c'}.
234
235 @lilypond[quote,fragment,ragged-right,verbatim]
236 \relative c'' {
237   c4 a b c
238 }
239 @end lilypond
240
241 Now we get to the only real stumbling block: LilyPond
242 input in this form is actually @emph{another}
243 shorthand.  Although it compiles and displays the
244 correct output, it is shorthand for
245
246 @example
247 \score @{
248   \relative c'' @{
249     c4 a b c
250   @}
251 @}
252 @end example
253
254 A @code{\score} must begin with a single music
255 expression.  Remember that a music expression could
256 be anything from a single note to a huge
257
258 @example
259 @{
260   \new GrandStaff <<
261     insert the whole score of a Wagner opera in here
262   >>
263 @}
264 @end example
265
266 @noindent
267 Since everything is inside @code{@{ ... @}}, it counts
268 as one music expression.
269
270 The @code{\score} can contain other things, such as
271
272 @example
273 \score @{
274   @{ c'4 a b c' @}
275   \layout @{ @}
276   \paper @{ @}
277   \midi @{ @}
278   \header @{ @}
279 @}
280 @end example
281
282 @noindent
283 Most people put some of those commands outside the
284 @code{\score} block -- for example, @code{\header} is
285 almost always placed above the @code{\score}.  That's
286 just another shorthand.
287
288 Another great shorthand is the ability to define
289 variables.  All the templates use this
290
291 @example
292 melody = \relative c' @{
293   c4 a b c
294 @}
295
296 \score @{
297   @{ \melody @}
298 @}
299 @end example
300
301 When LilyPond looks at this file, it takes the value of
302 @code{melody} (everything after the equals sign) and
303 inserts it whenever it sees
304 @code{\melody}.  There's nothing special about the
305 names -- it could be @code{melody}, @code{global},
306 @code{pianorighthand}, or @code{foofoobarbaz}.  You
307 can use whatever variable names you want.
308
309 For a complete definition
310 of the input format, see @ref{File structure}.
311
312
313 @node Score is a single musical expression
314 @section Score is a single musical expression
315
316 In the previous section, @ref{How LilyPond files work},
317 we saw the general organization of LilyPond input
318 files.  But we seemed to skip over the most important
319 part: how do we figure out what to write after
320 @code{\score}?
321
322 We didn't skip over it at all.  The big mystery is simply
323 that there @emph{is} no mystery.  This line explains it
324 all:
325
326 @example
327 A @code{\score} must begin with a single music expression.
328 @end example
329
330 @noindent
331 You may find it useful to review
332 @ref{Music expressions explained}.  In that section, we
333 saw how to build big music expressions from small
334 pieces -- we started from notes, then chords, etc.  Now
335 we're going to start from a big music expression and
336 work our way down.
337
338 @example
339 \score @{
340   @{   % this brace begins the overall music expression
341     \new GrandStaff <<
342       insert the whole score of a Wagner opera in here
343     >>
344   @}   % this brace ends the overall music expression
345   \layout @{ @}
346 @}
347 @end example
348
349 A whole Wagner opera would easily double the length of
350 this manual, so let's just do a singer and piano.  We
351 don't need a @code{GrandStaff} for this ensemble, so we
352 shall remove it.  We @emph{do} need a singer and a piano,
353 though.
354
355 @example
356 \score @{
357   @{
358     <<
359       \new Staff = "singer" <<
360       >>
361       \new PianoStaff = piano <<
362       >>
363     >>
364   @}
365   \layout @{ @}
366 @}
367 @end example
368
369 Remember that we use @code{<<} and @code{>>} to show
370 simultaneous music.  And we definitely want to show
371 the vocal part and piano part at the same time!
372
373 @example
374 \score @{
375   @{
376     <<
377       \new Staff = "singer" <<
378         \new Voice = "vocal" @{ @}
379       >>
380       \new Lyrics \lyricsto vocal \new Lyrics @{ @}
381       \new PianoStaff = "piano" <<
382         \new Staff = "upper" @{ @}
383         \new Staff = "lower" @{ @}
384       >>
385     >>
386   @}
387   \layout @{ @}
388 @}
389 @end example
390
391 Now we have a lot more details.  We have the singer's
392 staff: it contains a @code{Voice} (in LilyPond, this
393 term refers to a set of notes, not necessarily vocal
394 notes -- for example, a violin generally plays one
395 voice) and some lyrics.  We also have a piano staff:
396 it contains an upper staff (right hand) and a lower
397 staff (left hand).
398
399 At this stage, we could start filling in notes.  Inside
400 the curly braces next to @code{\new Voice = vocal},
401 we could start writing
402
403 @example
404 \relative c'' @{
405   a4 b c d
406 @}
407 @end example
408
409 But if we did that, the @code{\score} section would
410 get pretty long, and it would be harder to understand
411 what was happening.  So let's use identifiers (or
412 variables) instead.
413
414 @example
415 melody = @{ @}
416 text = @{ @}
417 upper = @{ @}
418 lower = @{ @}
419 \score @{
420   @{
421     <<
422       \new Staff = "singer" <<
423         \new Voice = "vocal" @{ \melody @}
424       >>
425       \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
426       \new PianoStaff = "piano" <<
427         \new Staff = "upper" @{ \upper @}
428         \new Staff = "lower" @{ \lower @}
429       >>
430     >>
431   @}
432   \layout @{ @}
433 @}
434 @end example
435
436 @noindent
437 Remember that you can use almost any name you like.  The
438 limitations on identifier names are detailed in
439 @ref{File structure}.
440
441 When writing a @code{\score} section, or when reading
442 one, just take it slowly and carefully.  Start with
443 the outer layer, then work on each smaller
444 layer.  It also really helps to be strict with
445 indentation -- make sure that each item on the same
446 layer starts on the same horizontal position in your
447 text editor!
448
449
450 @node Organizing larger pieces
451 @section Organizing larger pieces
452
453 When all of the elements discussed earlier are combined to produce
454 larger files, the @code{\score} blocks get a lot bigger, because the
455 music expressions are longer, and, in the case of polyphonic pieces,
456 more deeply nested.  Such large expressions can become unwieldy.
457
458 By using variables, also known as identifiers, it is possible to break
459 up complex music expressions.  An identifier is assigned as follows
460
461 @example
462 namedMusic = @{ @dots{} @}
463 @end example
464
465 @noindent
466 The contents of the music expression @code{namedMusic}, can be used
467 later by preceding the name with a backslash, i.e., @code{\namedMusic}.
468 In the next example, a two-note motive is repeated two times by using
469 variable substitution
470
471 @lilypond[quote,ragged-right,verbatim,nofragment]
472 seufzer = {
473   e'4( dis'4)
474 }
475 { \seufzer \seufzer }
476 @end lilypond
477
478 The name of an identifier should have alphabetic characters only; no
479 numbers, underscores or dashes.  The assignment should be outside of
480 running music.
481
482 It is possible to use variables for many other types of objects in the
483 input.  For example,
484
485 @example
486 width = 4.5\cm
487 name = "Wendy"
488 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
489 @end example
490
491 Depending on its contents, the identifier can be used in different
492 places.  The following example uses the above variables
493
494 @example
495 \paper @{
496   \aFivePaper
497   line-width = \width
498 @}
499 @{ c4^\name @}
500 @end example
501
502 More information on the possible uses of identifiers is given in the
503 technical manual, in @ref{Input variables and Scheme}.
504 @c fixme: the ref is too technical.
505
506
507 @node An orchestral part
508 @section An orchestral part
509
510 In orchestral music, all notes are printed twice.  Once in a part for
511 the musicians, and once in a full score for the conductor.  Identifiers can
512 be used to avoid double work.  The music is entered once, and stored in
513 a variable.  The contents of that variable is then used to generate
514 both the part and the full score.
515
516 It is convenient to define the notes in a special file.  For example,
517 suppose that the file @file{horn-music.ly} contains the following part
518 of a horn/@/bassoon duo
519
520 @example
521 hornNotes = \relative c @{
522   \time 2/4
523   r4 f8 a cis4 f e d
524 @}
525 @end example
526
527 @noindent
528 Then, an individual part is made by putting the following in a file
529
530 @example
531 \include "horn-music.ly"
532 \header @{
533   instrument = "Horn in F"
534 @}
535
536 @{
537  \transpose f c' \hornNotes
538 @}
539 @end example
540
541 The line
542
543 @example
544 \include "horn-music.ly"
545 @end example
546
547 @noindent
548 substitutes the contents of @file{horn-music.ly} at this position in
549 the file, so @code{hornNotes} is defined afterwards.  The command
550 @code{\transpose f@tie{}c'} indicates that the argument, being
551 @code{\hornNotes}, should be transposed by a fifth upwards.  Sounding
552 @samp{f} is denoted by notated @code{c'}, which corresponds with the
553 tuning of a normal French Horn in@tie{}F.  The transposition can be seen
554 in the following output
555
556 @lilypond[quote,ragged-right]
557 \transpose f c' \relative c {
558   \time 2/4
559   r4 f8 a cis4 f e d
560 }
561 @end lilypond
562
563 In ensemble pieces, one of the voices often does not play for many
564 measures.  This is denoted by a special rest, the multi-measure
565 rest.  It is entered with a capital @samp{R} followed by a duration
566 (1@tie{}for a whole note, 2@tie{}for a half note, etc.).  By multiplying the
567 duration, longer rests can be constructed.  For example, this rest
568 takes 3@tie{}measures in 2/4 time
569
570 @example
571 R2*3
572 @end example
573
574 When printing the part, multi-rests
575 must be condensed.  This is done by setting a run-time variable
576
577 @example
578 \set Score.skipBars = ##t
579 @end example
580
581 @noindent
582 This command sets the property @code{skipBars} in the
583 @code{Score} context to true (@code{##t}).  Prepending the rest and
584 this option to the music above, leads to the following result
585
586 @lilypond[quote,ragged-right]
587 \transpose f c' \relative c {
588   \time 2/4
589   \set Score.skipBars = ##t 
590   R2*3
591   r4 f8 a cis4 f e d
592 }
593 @end lilypond
594
595
596 The score is made by combining all of the music together.  Assuming
597 that the other voice is in @code{bassoonNotes} in the file
598 @file{bassoon-music.ly}, a score is made with
599
600 @example
601 \include "bassoon-music.ly"
602 \include "horn-music.ly"
603
604 <<
605   \new Staff \hornNotes
606   \new Staff \bassoonNotes
607 >>
608 @end example
609
610 @noindent
611 leading to 
612
613 @lilypond[quote,ragged-right]
614 \relative c <<
615   \new Staff {
616     \time 2/4 R2*3
617     r4 f8 a cis4 f e d
618   }
619   \new Staff {
620     \clef bass
621     r4 d,8 f | gis4 c | b bes |
622     a8 e f4 | g d | gis f
623   }
624 >>
625 @end lilypond
626
627 More in-depth information on preparing parts and scores can be found
628 in the notation manual; see @ref{Orchestral music}.
629
630 Setting run-time variables (`properties') is discussed in
631 @ref{Changing context properties on the fly}.
632
633