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