1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Putting it all together
3 @chapter Putting it all together
5 This chapter is an extention of the tutorial, dealing with FIXME.
9 * Extending the templates::
10 * How LilyPond files work::
11 * Score is a single musical expression::
12 * Organizing larger pieces::
13 * An orchestral part::
17 @node Extending the templates
18 @section Extending the templates
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?
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
31 melody = \relative c' @{
49 \new Lyrics \lyricsto "one" \text
52 \midi @{ \tempo 4=60 @}
56 Now we want to add a cello part. Let's look at the ``Notes only'' example:
60 melody = \relative c' @{
71 \midi @{ \tempo 4=60 @}
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}.
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).
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
96 sopranoMusic = \relative c' @{
104 sopranoLyrics = \lyricmode @{
108 celloMusic = \relative c @{
118 \new Voice = "one" @{
122 \new Lyrics \lyricsto "one" \sopranoLyrics
125 \midi @{ \tempo 4=60 @}
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
134 \new Staff \celloMusic
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
147 \new Voice = "one" @{
151 \new Lyrics \lyricsto "one" \sopranoLyrics
153 \new Staff \celloMusic
156 \midi @{ \tempo 4=60 @}
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.
164 @lilypond[quote,verbatim,ragged-right]
166 sopranoMusic = \relative c' {
174 sopranoLyrics = \lyricmode {
178 celloMusic = \relative c {
193 \new Lyrics \lyricsto "one" \sopranoLyrics
195 \new Staff \celloMusic
198 \midi { \tempo 4=60 }
204 @node How LilyPond files work
205 @section How LilyPond files work
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}.
214 Most examples in this manual are little snippets -- for example
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
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'}.
235 @lilypond[quote,fragment,ragged-right,verbatim]
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
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
261 insert the whole score of a Wagner opera in here
267 Since everything is inside @code{@{ ... @}}, it counts
268 as one music expression.
270 The @code{\score} can contain other things, such as
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.
288 Another great shorthand is the ability to define
289 variables. All the templates use this
292 melody = \relative c' @{
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.
309 For a complete definition
310 of the input format, see @ref{File structure}.
313 @node Score is a single musical expression
314 @section Score is a single musical expression
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
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
327 A @code{\score} must begin with a single music expression.
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
340 @{ % this brace begins the overall music expression
342 insert the whole score of a Wagner opera in here
344 @} % this brace ends the overall music expression
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,
359 \new Staff = "singer" <<
361 \new PianoStaff = piano <<
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!
377 \new Staff = "singer" <<
378 \new Voice = "vocal" @{ @}
380 \new Lyrics \lyricsto vocal \new Lyrics @{ @}
381 \new PianoStaff = "piano" <<
382 \new Staff = "upper" @{ @}
383 \new Staff = "lower" @{ @}
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
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
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
422 \new Staff = "singer" <<
423 \new Voice = "vocal" @{ \melody @}
425 \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
426 \new PianoStaff = "piano" <<
427 \new Staff = "upper" @{ \upper @}
428 \new Staff = "lower" @{ \lower @}
437 Remember that you can use almost any name you like. The
438 limitations on identifier names are detailed in
439 @ref{File structure}.
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
450 @node Organizing larger pieces
451 @section Organizing larger pieces
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.
458 By using variables, also known as identifiers, it is possible to break
459 up complex music expressions. An identifier is assigned as follows
462 namedMusic = @{ @dots{} @}
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
471 @lilypond[quote,ragged-right,verbatim,nofragment]
475 { \seufzer \seufzer }
478 The name of an identifier should have alphabetic characters only; no
479 numbers, underscores or dashes. The assignment should be outside of
482 It is possible to use variables for many other types of objects in the
488 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
491 Depending on its contents, the identifier can be used in different
492 places. The following example uses the above variables
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.
507 @node An orchestral part
508 @section An orchestral part
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.
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
521 hornNotes = \relative c @{
528 Then, an individual part is made by putting the following in a file
531 \include "horn-music.ly"
533 instrument = "Horn in F"
537 \transpose f c' \hornNotes
544 \include "horn-music.ly"
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
556 @lilypond[quote,ragged-right]
557 \transpose f c' \relative c {
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
574 When printing the part, multi-rests
575 must be condensed. This is done by setting a run-time variable
578 \set Score.skipBars = ##t
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
586 @lilypond[quote,ragged-right]
587 \transpose f c' \relative c {
589 \set Score.skipBars = ##t
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
601 \include "bassoon-music.ly"
602 \include "horn-music.ly"
605 \new Staff \hornNotes
606 \new Staff \bassoonNotes
613 @lilypond[quote,ragged-right]
621 r4 d,8 f | gis4 c | b bes |
622 a8 e f4 | g d | gis f
627 More in-depth information on preparing parts and scores can be found
628 in the notation manual; see @ref{Orchestral music}.
630 Setting run-time variables (`properties') is discussed in
631 @ref{Changing context properties on the fly}.