1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Putting it all together
3 @chapter Putting it all together
5 This chapter discusses general LilyPond concepts and how to
6 create @code{\score} blocks.
10 * Extending the templates::
11 * How LilyPond files work::
12 * Score is a single musical expression::
16 @node Extending the templates
17 @section Extending the templates
19 You've read the tutorial, you know how to write music. But how can you
20 get the staves that you want? The templates are ok, but what if you
21 want something that isn't covered?
23 Start off with the template that seems closest to what you want to end
24 up with. Let's say that you want to write something for soprano and
25 cello. In this case, we would start with ``Notes and lyrics'' (for the
30 melody = \relative c' @{
48 \new Lyrics \lyricsto "one" \text
55 Now we want to add a cello part. Let's look at the ``Notes only'' example:
59 melody = \relative c' @{
74 We don't need two @code{\version} commands. We'll need the @code{melody}
75 section. We don't want two @code{\score} sections -- if we had two
76 @code{\score}s, we'd get the two parts separately. We want them together,
77 as a duet. Within the @code{\score} section, we don't need two
78 @code{\layout} or @code{\midi}.
80 If we simply cut and paste the @code{melody} section, we would end up with
81 two @code{melody} sections. So let's rename them. We'll call the section
82 for the soprano @code{sopranoMusic} and the section for the cello
83 @code{celloMusic}. While we're doing this, let's rename @code{text}
84 to be @code{sopranoLyrics}. Remember to rename both instances of all
85 these names -- both the initial definition (the
86 @code{melody = relative c' @{ } part) and the name's use (in the
87 @code{\score} section).
89 While we're doing this, let's change the cello part's staff -- celli
90 normally use bass clef. We'll also give the cello some different
95 sopranoMusic = \relative c' @{
103 sopranoLyrics = \lyricmode @{
107 celloMusic = \relative c @{
117 \new Voice = "one" @{
121 \new Lyrics \lyricsto "one" \sopranoLyrics
128 This is looking promising, but the cello part won't appear in the
129 score -- we haven't used it in the @code{\score} section. If we
130 want the cello part to appear under the soprano part, we need to add
133 \new Staff \celloMusic
137 underneath the soprano stuff. We also need to add @code{<<} and
138 @code{>>} around the music -- that tells LilyPond that there's
139 more than one thing (in this case, @code{Staff}) happening at once. The
140 @code{\score} looks like this now
146 \new Voice = "one" @{
150 \new Lyrics \lyricsto "one" \sopranoLyrics
152 \new Staff \celloMusic
160 This looks a bit messy; the indentation is messed up now. That is
161 easily fixed. Here's the complete soprano and cello template.
163 @lilypond[quote,verbatim,ragged-right]
165 sopranoMusic = \relative c' {
173 sopranoLyrics = \lyricmode {
177 celloMusic = \relative c {
192 \new Lyrics \lyricsto "one" \sopranoLyrics
194 \new Staff \celloMusic
203 @node How LilyPond files work
204 @section How LilyPond files work
206 The LilyPond input format is quite free-form, giving experienced
207 users a lot of flexibility to structure their files however they
208 wish. However, this flexibility can make things confusing for
209 new users. This section will explain some of this structure, but
210 may gloss over some details in favor of simplicity. For a complete
211 description of the input format, see @ref{File structure}.
213 Most examples in this manual are little snippets -- for example
219 As you are (hopefully) aware by now, this will not compile by
220 itself. These examples are shorthand for complete
221 examples. They all need at least curly braces to compile
229 Most examples also make use of the @code{\relative c'}
230 (or @code{c''}) command. This is not necessary to merely
231 compile the examples, but in most cases the output will
232 look very odd if you omit the @code{\relative c'}.
234 @lilypond[quote,fragment,ragged-right,verbatim]
240 Now we get to the only real stumbling block: LilyPond
241 input in this form is actually @emph{another}
242 shorthand. Although it compiles and displays the
243 correct output, it is shorthand for
253 A @code{\score} must begin with a single music
254 expression. Remember that a music expression could
255 be anything from a single note to a huge
260 insert the whole score of a Wagner opera in here
266 Since everything is inside @code{@{ ... @}}, it counts
267 as one music expression.
269 The @code{\score} can contain other things, such as
281 Some people put some of those commands outside the
282 @code{\score} block -- for example, @code{\header} is
283 often placed above the @code{\score}. That's just
284 another shorthand that LilyPond accepts.
286 Another great shorthand is the ability to define
287 variables. All the templates use this
290 melody = \relative c' @{
299 When LilyPond looks at this file, it takes the value of
300 @code{melody} (everything after the equals sign) and
301 inserts it whenever it sees
302 @code{\melody}. There's nothing special about the
303 names -- it could be @code{melody}, @code{global},
304 @code{pianorighthand}, or @code{foofoobarbaz}. You
305 can use whatever variable names you want. For
307 @ref{Saving typing with identifiers and functions}.
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 @emph{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