]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/putting.itely
Merge with master
[lilypond.git] / Documentation / user / putting.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @node Putting it all together
11 @chapter Putting it all together
12
13 This chapter discusses general LilyPond concepts and how to
14 create @code{\score} blocks.
15
16
17 @menu
18 * Extending the templates::     
19 * How LilyPond files work::     
20 * Score is a single musical expression::  
21 @end menu
22
23
24 @node Extending the templates
25 @section Extending the templates
26
27 You've read the tutorial, you know how to write music.  But how can you
28 get the staves that you want?  The templates are ok, but what if you
29 want something that isn't covered?
30
31 Start off with the template that seems closest to what you want to end
32 up with.  Let's say that you want to write something for soprano and
33 cello.  In this case, we would start with @q{Notes and lyrics} (for the
34 soprano part).
35
36 @example
37 \version "2.9.13"
38 melody = \relative c' @{
39   \clef treble
40   \key c \major
41   \time 4/4
42
43   a4 b c d
44 @}
45
46 text = \lyricmode @{
47   Aaa Bee Cee Dee
48 @}
49
50 \score@{
51   <<
52     \new Voice = "one" @{
53       \autoBeamOff
54       \melody
55     @}
56     \new Lyrics \lyricsto "one" \text
57   >>
58   \layout @{ @}
59   \midi @{ @}
60 @}
61 @end example
62
63 Now we want to add a cello part.  Let's look at the @q{Notes only} example:
64
65 @example
66 \version "2.9.13"
67 melody = \relative c' @{
68   \clef treble
69   \key c \major
70   \time 4/4
71
72   a4 b c d
73 @}
74
75 \score @{
76 \new Staff \melody
77 \layout @{ @}
78 \midi @{ @}
79 @}
80 @end example
81
82 We don't need two @code{\version} commands.  We'll need the @code{melody}
83 section.  We don't want two @code{\score} sections -- if we had two
84 @code{\score}s, we'd get the two parts separately.  We want them together,
85 as a duet.  Within the @code{\score} section, we don't need two
86 @code{\layout} or @code{\midi}.
87
88 If we simply cut and paste the @code{melody} section, we would end up with
89 two @code{melody} sections.  So let's rename them.  We'll call the section
90 for the soprano @code{sopranoMusic} and the section for the cello
91 @code{celloMusic}.  While we're doing this, let's rename @code{text}
92 to be @code{sopranoLyrics}.  Remember to rename both instances of all
93 these names -- both the initial definition (the
94 @code{melody = relative c' @{ } part) and the name's use (in the
95 @code{\score} section).
96
97 While we're doing this, let's change the cello part's staff -- celli
98 normally use bass clef.  We'll also give the cello some different
99 notes.
100
101 @example
102 \version "2.9.13"
103 sopranoMusic = \relative c' @{
104   \clef treble
105   \key c \major
106   \time 4/4
107
108   a4 b c d
109 @}
110
111 sopranoLyrics = \lyricmode @{
112   Aaa Bee Cee Dee
113 @}
114
115 celloMusic = \relative c @{
116   \clef bass
117   \key c \major
118   \time 4/4
119
120   d4 g fis8 e d4
121 @}
122
123 \score@{
124   <<
125     \new Voice = "one" @{
126       \autoBeamOff
127       \sopranoMusic
128     @}
129     \new Lyrics \lyricsto "one" \sopranoLyrics
130   >>
131   \layout @{ @}
132   \midi @{ @}
133 @}
134 @end example
135
136 This is looking promising, but the cello part won't appear in the
137 score -- we haven't used it in the @code{\score} section.  If we
138 want the cello part to appear under the soprano part, we need to add
139
140 @example
141 \new Staff \celloMusic
142 @end example
143
144 @noindent
145 underneath the soprano stuff.  We also need to add @code{<<} and
146 @code{>>} around the music -- that tells LilyPond that there's
147 more than one thing (in this case, @code{Staff}) happening at once.  The
148 @code{\score} looks like this now
149
150 @example
151 \score@{
152   <<
153     <<
154       \new Voice = "one" @{
155         \autoBeamOff
156         \sopranoMusic
157       @}
158       \new Lyrics \lyricsto "one" \sopranoLyrics
159     >>
160     \new Staff \celloMusic
161   >>
162   \layout @{ @}
163   \midi @{ @}
164 @}
165 @end example
166
167 @noindent
168 This looks a bit messy; the indentation is messed up now.  That is
169 easily fixed.  Here's the complete soprano and cello template.
170
171 @lilypond[quote,verbatim,ragged-right]
172 \version "2.9.13"
173 sopranoMusic = \relative c' {
174   \clef treble
175   \key c \major
176   \time 4/4
177
178   a4 b c d
179 }
180
181 sopranoLyrics = \lyricmode {
182   Aaa Bee Cee Dee
183 }
184
185 celloMusic = \relative c {
186   \clef bass
187   \key c \major
188   \time 4/4
189
190   d4 g fis8 e d4
191 }
192
193 \score{
194   <<
195     <<
196       \new Voice = "one" {
197         \autoBeamOff
198         \sopranoMusic
199       }
200       \new Lyrics \lyricsto "one" \sopranoLyrics
201     >>
202     \new Staff \celloMusic
203   >>
204   \layout { }
205   \midi { }
206 }
207 @end lilypond
208
209
210
211 @node How LilyPond files work
212 @section How LilyPond files work
213
214 The LilyPond input format is quite free-form, giving experienced
215 users a lot of flexibility to structure their files however they
216 wish.  However, this flexibility can make things confusing for
217 new users.  This section will explain some of this structure, but
218 may gloss over some details in favor of simplicity.  For a complete
219 description of the input format, see @ref{File structure}.
220
221 Most examples in this manual are little snippets -- for example
222
223 @example
224 c4 a b c
225 @end example
226
227 As you are (hopefully) aware by now, this will not compile by
228 itself.  These examples are shorthand for complete
229 examples.  They all need at least curly braces to compile
230
231 @example
232 @{
233   c4 a b c
234 @}
235 @end example
236
237 Most examples also make use of the @code{\relative c'}
238 (or @code{c''}) command.  This is not necessary to merely
239 compile the examples, but in most cases the output will
240 look very odd if you omit the @code{\relative c'}.
241
242 @lilypond[quote,fragment,ragged-right,verbatim]
243 \relative c'' {
244   c4 a b c
245 }
246 @end lilypond
247
248 Now we get to the only real stumbling block: LilyPond
249 input in this form is actually @emph{another}
250 shorthand.  Although it compiles and displays the
251 correct output, it is shorthand for
252
253 @example
254 \score @{
255   \relative c'' @{
256     c4 a b c
257   @}
258 @}
259 @end example
260
261 A @code{\score} must begin with a single music
262 expression.  Remember that a music expression could
263 be anything from a single note to a huge
264
265 @example
266 @{
267   \new GrandStaff <<
268     insert the whole score of a Wagner opera in here
269   >>
270 @}
271 @end example
272
273 @noindent
274 Since everything is inside @code{@{ ... @}}, it counts
275 as one music expression.
276
277 The @code{\score} can contain other things, such as
278
279 @example
280 \score @{
281   @{ c'4 a b c' @}
282   \layout @{ @}
283   \midi @{ @}
284   \header @{ @}
285 @}
286 @end example
287
288 @noindent
289 Some people put some of those commands outside the
290 @code{\score} block -- for example, @code{\header} is
291 often placed above the @code{\score}.  That's just
292 another shorthand that LilyPond accepts.
293
294 @cindex variables
295 @cindex indentifiers
296
297 Another great shorthand is the ability to define
298 variables.  All the templates use this
299
300 @example
301 melody = \relative c' @{
302   c4 a b c
303 @}
304
305 \score @{
306   @{ \melody @}
307 @}
308 @end example
309
310 When LilyPond looks at this file, it takes the value of
311 @code{melody} (everything after the equals sign) and
312 inserts it whenever it sees
313 @code{\melody}.  There's nothing special about the
314 names -- it could be @code{melody}, @code{global},
315 @code{pianorighthand}, or @code{foofoobarbaz}.  You
316 can use whatever variable names you want.  For
317 more details, see
318 @ref{Saving typing with identifiers and functions}.
319
320 For a complete definition
321 of the input format, see @ref{File structure}.
322
323
324 @node Score is a single musical expression
325 @section Score is a single musical expression
326
327 In the previous section, @ref{How LilyPond files work},
328 we saw the general organization of LilyPond input
329 files.  But we seemed to skip over the most important
330 part: how do we figure out what to write after
331 @code{\score}?
332
333 We didn't skip over it at all.  The big mystery is simply
334 that there @emph{is} no mystery.  This line explains it
335 all:
336
337 @quotation
338 @emph{A @code{\score} must begin with a single music expression.}
339 @end quotation
340
341 @noindent
342 You may find it useful to review
343 @ref{Music expressions explained}.  In that section, we
344 saw how to build big music expressions from small
345 pieces -- we started from notes, then chords, etc.  Now
346 we're going to start from a big music expression and
347 work our way down.
348
349 @example
350 \score @{
351   @{   % this brace begins the overall music expression
352     \new GrandStaff <<
353       insert the whole score of a Wagner opera in here
354     >>
355   @}   % this brace ends the overall music expression
356   \layout @{ @}
357 @}
358 @end example
359
360 A whole Wagner opera would easily double the length of
361 this manual, so let's just do a singer and piano.  We
362 don't need a @code{GrandStaff} for this ensemble, so we
363 shall remove it.  We @emph{do} need a singer and a piano,
364 though.
365
366 @example
367 \score @{
368   @{
369     <<
370       \new Staff = "singer" <<
371       >>
372       \new PianoStaff = piano <<
373       >>
374     >>
375   @}
376   \layout @{ @}
377 @}
378 @end example
379
380 Remember that we use @code{<<} and @code{>>} to show
381 simultaneous music.  And we definitely want to show
382 the vocal part and piano part at the same time!
383
384 @example
385 \score @{
386   @{
387     <<
388       \new Staff = "singer" <<
389         \new Voice = "vocal" @{ @}
390       >>
391       \new Lyrics \lyricsto vocal \new Lyrics @{ @}
392       \new PianoStaff = "piano" <<
393         \new Staff = "upper" @{ @}
394         \new Staff = "lower" @{ @}
395       >>
396     >>
397   @}
398   \layout @{ @}
399 @}
400 @end example
401
402 Now we have a lot more details.  We have the singer's
403 staff: it contains a @code{Voice} (in LilyPond, this
404 term refers to a set of notes, not necessarily vocal
405 notes -- for example, a violin generally plays one
406 voice) and some lyrics.  We also have a piano staff:
407 it contains an upper staff (right hand) and a lower
408 staff (left hand).
409
410 At this stage, we could start filling in notes.  Inside
411 the curly braces next to @code{\new Voice = vocal},
412 we could start writing
413
414 @example
415 \relative c'' @{
416   a4 b c d
417 @}
418 @end example
419
420 But if we did that, the @code{\score} section would
421 get pretty long, and it would be harder to understand
422 what was happening.  So let's use identifiers (or
423 variables) instead.
424
425 @example
426 melody = @{ @}
427 text = @{ @}
428 upper = @{ @}
429 lower = @{ @}
430 \score @{
431   @{
432     <<
433       \new Staff = "singer" <<
434         \new Voice = "vocal" @{ \melody @}
435       >>
436       \new Lyrics \lyricsto vocal \new Lyrics @{ \text @}
437       \new PianoStaff = "piano" <<
438         \new Staff = "upper" @{ \upper @}
439         \new Staff = "lower" @{ \lower @}
440       >>
441     >>
442   @}
443   \layout @{ @}
444 @}
445 @end example
446
447 @noindent
448 Remember that you can use almost any name you like.  The
449 limitations on identifier names are detailed in
450 @ref{File structure}.
451
452 When writing a @code{\score} section, or when reading
453 one, just take it slowly and carefully.  Start with
454 the outer layer, then work on each smaller
455 layer.  It also really helps to be strict with
456 indentation -- make sure that each item on the same
457 layer starts on the same horizontal position in your
458 text editor!
459
460