]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
Nits in tutorial
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.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 @c \version "2.11.38"
11
12 @ignore
13 Tutorial guidelines:  (different from policy.txt!)
14 - unless you have a really good reason, use either
15     @lilypond[verbatim,quote,ragged-right]
16   or
17     @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
18
19   Don't use any other relative=X commands (make it a non-fragment
20   example), and don't use fragment without relative=2.
21
22 - use "aes" and "ees" instead of "as" and "es".  I know it's not
23   correct Dutch naming, but let's not confuse people with this
24   until we get to the Basic notation chapter.
25
26 - Add "Music Glossary: @rglos{foo}" to the _top_ of the relevant
27   portions of the tutorial.
28
29 @end ignore
30
31
32 @node Tutorial
33 @chapter Tutorial
34
35 This tutorial starts with an introduction to the LilyPond music
36 language and explains how to produce printed music.  After this first
37 contact we will explain how to create beautiful printed music 
38 containing common musical notation.
39
40 @menu
41 * First steps::                 
42 * Single staff notation::       
43 * Multiple notes at once::      
44 * Songs::                       
45 * Final touches::               
46 @end menu
47
48
49 @node First steps
50 @section First steps
51
52 This section gives a basic introduction to working with LilyPond.
53
54 @menu
55 * Compiling a file::            
56 * Simple notation::             
57 * Working on input files::
58 * How to read the manual::
59 @end menu
60
61
62 @node Compiling a file
63 @subsection Compiling a file
64
65 @qq{Compiling} is the term used for processing an input file
66 in LilyPond format to produce a file which can be printed and
67 (optionally) a MIDI file which can be played.  LilyPond input
68 files are simple text files.  The first example
69 shows what a simple input file looks like.
70
71 To create sheet music, we write an input file that specifies the
72 notation.  For example, if we write:
73
74 @example
75 @{
76   c' e' g' e'
77 @}
78 @end example
79
80 @noindent
81 the result looks like this:
82
83 @c  in this case we don't want verbatim
84 @lilypond[quote,ragged-right]
85 {
86   c' e' g' e'
87 }
88 @end lilypond
89
90 @warning{Notes and lyrics in LilyPond input must always be
91 surrounded by @strong{@{ curly braces @}}.  The braces
92 should also be surrounded by a space unless they are at the
93 beginning or end of a line to avoid ambiguities.  The braces may
94 be omitted in some examples in this manual, but don't forget them
95 in your own music!  For more information about the display of
96 examples in the manual, see @ref{How to read the manual}.}
97
98 @cindex case sensitive
99 In addition, LilyPond input is @strong{case sensitive}.
100 @w{@code{@{ c d e @}}} is valid input; @w{@code{@{ C D E @}}} will
101 produce an error message.
102
103 @smallspace
104
105 @subheading Entering music and viewing output
106
107 @cindex PDF file
108 @cindex viewing music
109
110 In this section we will explain what commands to run and how to
111 view or print the output.
112
113 Note that there are several other text editors available with
114 better support for LilyPond.  For more information, see
115 @rprogram{Text editor support}.
116
117 @warning{The first time you ever run LilyPond, it may take a
118 minute or two because all of the system fonts have to be analyzed
119 first.  After this, LilyPond will be much faster!}
120
121 @subsubheading MacOS X
122
123 If you double click @command{LilyPond.app}, it will open with an
124 example file.  Save it, for example, to @file{test.ly} on your
125 Desktop, and then process it with the menu command
126 @w{@code{Compile > Typeset File}}.  The resulting PDF file will be
127 displayed on your screen.
128
129 For future use of LilyPond, you should begin by selecting @q{New}
130 or @q{Open}.  You must save your file before typesetting it.  If
131 any errors occur in processing, please see the log window.
132
133
134 @subsubheading Windows
135
136 On Windows, if you double-click in the LilyPond icon on the
137 Desktop, it will open a simple text editor with an example file.
138 Save it, for example, to @file{test.ly} on your Desktop and then
139 double-click on the file to process it (the file icon looks like a
140 note).  After some seconds, you will get a file @file{test.pdf} on
141 your desktop.  Double-click on this PDF file to view the typeset
142 score.  An alternative method to process the @file{test.ly} file
143 is to drag and drop it onto the LilyPond icon using your mouse
144 pointer.
145
146 To edit an existing @file{.ly} file, right-click on it and
147 select @qq{Edit source}.  To get an empty file to start from, run
148 the editor as described above and use @qq{New} in
149 the @qq{File} menu, or right-click on the desktop and select
150 @qq{New..Text Document}, change its name to a name of your choice
151 and change the file extension to @code{.ly}.  Double-click the
152 icon to type in your LilyPond source code as before.
153
154 Double-clicking the file does not only result in a PDF file, but
155 also produces a @file{.log} file that contains some information on
156 what LilyPond has done to the file.  If any errors occur, please
157 examine this file.
158
159 @subsubheading UNIX
160
161 Create a text file called @file{test.ly} and enter:
162
163 @example
164 @{
165   c' e' g' e'
166 @}
167 @end example
168
169 To process @file{test.ly}, proceed as follows:
170
171 @example
172 lilypond test.ly
173 @end example
174
175 @noindent
176 You will see something resembling:
177
178 @example
179 lilypond test.ly
180 GNU LilyPond @version{}
181 Processing `test.ly'
182 Parsing...
183 Interpreting music...
184 Preprocessing graphical objects...
185 Finding the ideal number of pages...
186 Fitting music on 1 page...
187 Drawing systems...
188 Layout output to `test.ps'...
189 Converting to `test.pdf'...
190 @end example
191
192
193 @node Simple notation
194 @subsection Simple notation
195
196 LilyPond will add some notation elements automatically.  In the
197 next example, we have only specified four pitches, but LilyPond
198 has added a clef, time signature, and rhythms.
199
200 @lilypond[verbatim,quote,ragged-right]
201 {
202   c' e' g' e'
203 }
204 @end lilypond
205
206 @noindent
207 This behavior may be altered, but in most cases these automatic
208 values are useful.
209
210
211 @subheading Pitches
212
213 Music Glossary: @rglos{pitch}, @rglos{interval},
214 @rglos{scale}, @rglos{middle C}, @rglos{octave},
215 @rglos{accidental}.
216
217 The easiest way to enter notes is by using @code{\relative} mode.
218 In this mode, the octave is chosen automatically by assuming the
219 following note is always to be placed closest to the previous
220 note, i.e., it is to be placed in the octave which is within three
221 staff spaces of the previous note.  We begin by entering the most
222 elementary piece of music, a @notation{scale}, in which every note
223 is within just one staff space of the previous note.
224
225 @lilypond[verbatim,quote,ragged-right]
226 \relative c' {  % set the starting point to middle C
227   c d e f
228   g a b c
229 }
230 @end lilypond
231
232 The initial note is @notation{middle C}.  Each successive note is
233 placed closest to the previous note -- in other words, the first
234 @code{c} is the closest C to middle C.  This is followed by the
235 closest D to the previous note.  We can create melodies which have
236 larger intervals, still using only @code{\relative} mode:
237
238 @lilypond[verbatim,quote,ragged-right]
239 \relative c' {
240   d f a g
241   c b f d
242 }
243 @end lilypond
244
245 @noindent
246 It is not necessary for the first note of the melody to start on
247 the note which specifies the starting pitch.  In the previous
248 example, the first note -- the @code{d} -- is the closest D to
249 middle C.
250
251 By adding (or removing) quotes @code{'} or commas @code{,} from
252 the @w{@code{\relative c' @{}} command, we can change the starting
253 octave:
254
255 @lilypond[verbatim,quote,ragged-right]
256 \relative c'' {  % one octave above middle C
257   e c a c
258 }
259 @end lilypond
260
261 Relative mode can be confusing initially, but is the easiest way
262 to enter most melodies.  Let us see how this relative calculation
263 works in practice.  Starting from a B, which is on the middle line
264 in a treble clef, you can reach a C, D and E within 3 staff spaces
265 going up, and an A, G and F within 3 staff spaces going down.  So
266 if the note following a B is a C, D or E it will be assumed to be
267 above the B, and an A, G or F will be assumed to be below.
268
269 @lilypond[verbatim,quote,ragged-right]
270 \relative c'' {
271   b c  % c is 1 staff space up, so is the c above
272   b d  % d is 2 up or 5 down, so is the d above
273   b e  % e is 3 up or 4 down, so is the e above
274   b a  % a is 6 up or 1 down, so is the a below
275   b g  % g is 5 up or 2 down, so is the g below
276   b f  % f is 4 up or 3 down, so is the f below
277 }
278 @end lilypond
279
280 Exactly the same happens even when any of these notes are
281 sharpened or flattened.  @notation{Accidentals} are
282 @strong{totally ignored} in the calculation of relative position.
283 Precisely the same staff space counting is done from a note at any
284 other position on the staff.
285
286 To add intervals that are larger than three staff spaces, we can
287 raise the @notation{octave} by adding a single quote @code{'} (or
288 apostrophe) to the note name.  We can lower the octave by adding a
289 comma @code{,} to the note name.
290
291 @lilypond[verbatim,quote,ragged-right]
292 \relative c'' {
293   a a, c' f,
294   g g'' a,, f'
295 }
296 @end lilypond
297
298 @noindent
299 To change a note by two (or more!) octaves, we use multiple
300 @code{''} or @code{,,} -- but be careful that you use two single
301 quotes @code{''} and not one double quote @code{"}@tie{}!  The
302 initial value in @w{@code{\relative c'}} may also be modified like
303 this.
304 @c " - keeps quotes in order for context-sensitive editor -td
305
306 @subheading Durations (rhythms)
307
308 Music Glossary: @rglos{beam}, @rglos{duration},
309 @rglos{whole note}, @rglos{half note}, @rglos{quarter note},
310 @rglos{dotted note}.
311
312 The @notation{duration} of a note is specified by a number after
313 the note name.  @code{1} for a @notation{whole note}, @code{2} for
314 a @notation{half note}, @code{4} for a @notation{quarter note} and
315 so on.  @notation{Beams} are added automatically.
316
317 If you do not specify a duration, the previous duration is used
318 for the next note.  The duration of the first note defaults to a
319 quarter.
320
321 @lilypond[verbatim,quote,ragged-right]
322 \relative c'' {
323   a1
324   a2 a4 a8 a
325   a16 a a a a32 a a a a64 a a a a a a a a2
326 }
327 @end lilypond
328
329 To create @notation{dotted notes}, add a dot @code{.} to the
330 duration number.  The duration of a dotted note must be stated
331 explicitly (i.e., with a number).
332
333 @lilypond[verbatim,quote,ragged-right]
334 \relative c'' {
335   a a a4. a8
336   a8. a16 a a8. a8 a4.
337 }
338 @end lilypond
339
340
341 @subheading Rests
342
343 Music Glossary: @rglos{rest}.
344
345 A @notation{rest} is entered just like a note with the name
346 @code{r}@tie{}:
347
348 @lilypond[verbatim,quote,ragged-right]
349 \relative c'' {
350   a r r2
351   r8 a r4 r4. r8
352 }
353 @end lilypond
354
355
356 @subheading Time signature
357
358 Music Glossary: @rglos{time signature}.
359
360 The @notation{time signature} can be set with the @code{\time}
361 command:
362
363 @lilypond[verbatim,quote,ragged-right]
364 \relative c'' {
365   \time 3/4
366   a4 a a
367   \time 6/8
368   a4. a
369   \time 4/4
370   a4 a a a
371 }
372 @end lilypond
373
374
375 @subheading Clef
376
377 Music Glossary: @rglos{clef}.
378
379 The @notation{clef} can be set using the @code{\clef} command:
380
381 @lilypond[verbatim,quote,ragged-right]
382 \relative c' {
383   \clef treble
384   c1
385   \clef alto
386   c1
387   \clef tenor
388   c1
389   \clef bass
390   c1
391 }
392 @end lilypond
393
394
395 @subheading All together
396
397 Here is a small example showing all these elements together:
398
399 @lilypond[verbatim,quote,ragged-right]
400 \relative c, {
401   \time 3/4
402   \clef bass
403   c2 e8 c' g'2.
404   f4 e d c4 c, r4
405 }
406 @end lilypond
407
408
409 @seealso
410
411 Notation Reference: @ruser{Writing pitches},
412 @ruser{Writing rhythms}, @ruser{Writing rests},
413 @ruser{Time signature}, @ruser{Clef}.
414
415
416 @node Working on input files
417 @subsection Working on input files
418
419 LilyPond input files are similar to source files in many common
420 programming languages.  They are case sensitive, and white-space
421 is generally ignored.  Expressions are formed with curly braces
422 @{ @}, and comments are denoted with @code{%} or
423 @w{@code{%@{ ... %@}}}.
424
425 If the previous sentences sound like nonsense, don't worry!  We'll
426 explain what all these terms mean:
427
428 @itemize
429
430 @cindex case sensitive
431 @item
432 @strong{Case sensitive}:
433 it matters whether you enter a letter in lower case (e.g.
434 @w{@code{a, b, s, t}}) or upper case (e.g.  @w{@code{A, B, S, T}}).
435 Notes are lower case: @w{@code{@{ c d e @}}} is valid input;
436 @w{@code{@{ C D E @}}} will produce an error message.
437
438 @item
439 @strong{Whitespace insensitive}:
440 it does not matter how many spaces (or new lines) you add.
441 @w{@code{@{ c d e @}}} means the same thing as
442 @w{@code{@{ c @tie{}} @tie{} @tie{} d e @}} and:
443
444 @example
445 @{ c                        d
446                    e   @}
447 @end example
448
449 @noindent
450 Of course, the previous example is hard to read.  A good rule of
451 thumb is to indent code blocks with either a tab or two spaces:
452
453 @example
454 @{
455   c d e
456 @}
457 @end example
458
459 @item
460 @strong{Expressions}:
461 every piece of LilyPond input needs to have @strong{@{ curly
462 braces @}} placed around the input.  These braces tell LilyPond
463 that the input is a single music expression, just like parentheses
464 @code{()} in mathematics.  The braces should be surrounded by a
465 space unless they are at the beginning or end of a line to avoid
466 ambiguities.
467
468 A LilyPond command followed by a simple expression in braces (such
469 as @w{@code{\relative @{ @}}}) also counts as a single music
470 expression.
471
472 @cindex comments
473 @cindex line comment
474 @cindex block comment
475 @item
476 @strong{Comments}:
477 a comment is a remark for the human reader of the music input; it
478 is ignored while parsing, so it has no effect on the printed
479 output.  There are two types of comments.  The percent symbol
480 @code{%} introduces a line comment; anything after @code{%} on
481 that line is ignored.  By convention, a line comment is placed
482 @emph{above} the code it refers to.
483
484 @example
485 a4 a a a
486 % this comment refers to the Bs
487 b2 b
488 @end example
489
490 A block comment marks a whole section of music input as a comment.
491 Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
492 However, block comments do not @q{nest}.  This means that you
493 cannot place a block comment inside another block comment.  If you
494 try, the first @code{%@}} will terminate @emph{both} block
495 comments.  The following fragment shows possible uses for
496 comments:
497
498 @example
499 % notes for twinkle twinkle follow
500   c4 c g' g a a g2
501
502 %@{
503   This line, and the notes below
504   are ignored, since they are in a
505   block comment.
506
507   f f e e d d c2
508 %@}
509 @end example
510
511 @end itemize
512
513
514 @node How to read the manual
515 @subsection How to read the manual
516
517 LilyPond input must be surrounded by @{ @} marks or a
518 @w{@code{\relative c'' @{ ... @}}}, as we saw in @ref{Working on
519 input files}.  For the rest of this manual, most examples will
520 omit this.  To replicate the examples, you may copy and paste the
521 displayed input, but you @strong{must} add the
522 @w{@code{\relative c'' @{ @}}} like this:
523
524 @example
525 \relative c'' @{
526   ... example goes here...
527 @}
528 @end example
529
530 Why omit the braces?  Most examples in this manual can be inserted
531 into the middle of a longer piece of music.  For these examples,
532 it does not make sense to add @w{@code{\relative c'' @{ @}}} --
533 you should not place a @code{\relative} inside another
534 @code{\relative}!  If we included @w{@code{\relative c'' @{ @}}}
535 around every example, you would not be able to copy a small
536 documentation example and paste it inside a longer piece of your
537 own.  Most people want to add material to an existing piece, so we
538 format the manual this way.
539
540
541 @subheading Clickable examples
542
543 Many people learn programs by trying and fiddling around with the
544 program.  This is also possible with LilyPond.  If you click on a
545 picture in the HTML version of this manual, you will see the exact
546 LilyPond input that was used to generate that image.  Try it on
547 this image:
548
549 @c no verbatim here
550 @lilypond[quote,ragged-right]
551 \relative c'' {
552   c-\markup { \bold \huge { Click here.  } }
553 }
554 @end lilypond
555
556 By cutting and pasting everything in the @qq{ly snippet} section,
557 you have a starting template for experiments.  To see exactly the
558 same output (line-width and all), copy everything from @qq{Start
559 cut-&-pastable section} to the bottom of the file.
560
561 @seealso
562
563 There are more tips for constructing input files in
564 @ref{Suggestions for writing LilyPond input files}.  But it might be
565 best to read through the rest of the tutorial first.
566
567
568
569 @node Single staff notation
570 @section Single staff notation
571
572 This section introduces common notation that is used for one voice
573 on one staff.
574
575 @menu
576 * Accidentals and key signatures::  
577 * Ties and slurs::              
578 * Articulation and dynamics::   
579 * Adding text::                 
580 * Automatic and manual beams::  
581 * Advanced rhythmic commands::  
582 @end menu
583
584
585 @node Accidentals and key signatures
586 @subsection Accidentals and key signatures
587
588 @subheading Accidentals
589
590 Music Glossary: @rglos{sharp}, @rglos{flat}, @rglos{double sharp},
591 @rglos{double flat}, @rglos{accidental}.
592
593 A @notation{sharp} pitch is made by adding @code{is} to the name,
594 and a @notation{flat} pitch by adding @code{es}.  As you might
595 expect, a @notation{double sharp} or @notation{double flat} is
596 made by adding @code{isis} or @code{eses}.  This syntax is derived
597 from note naming conventions in Nordic and Germanic languages,
598 like German and Dutch.  To use other names for
599 @notation{accidentals}, see @ruser{Note names in other languages}.
600
601 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
602 cis1 ees fisis, aeses
603 @end lilypond
604
605 @cindex key signature, setting
606 @subheading Key signatures
607
608 Music Glossary: @rglos{key signature}, @rglos{major},
609 @rglos{minor}.
610
611 The @notation{key signature} is set with the command @code{\key}
612 followed by a pitch and @code{\major} or @code{\minor}.
613
614 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
615 \key d \major
616 a1
617 \key c \minor
618 a
619 @end lilypond
620
621 @smallspace
622
623 @subheading Warning: key signatures and pitches
624
625 Music Glossary: @rglos{accidental}, @rglos{key signature},
626 @rglos{pitch}, @rglos{flat}, @rglos{natural}, @rglos{sharp},
627 @rglos{transposition}.
628
629 To determine whether to print an @notation{accidental}, LilyPond
630 examines the pitches and the @notation{key signature}.  The key
631 signature only affects the @emph{printed} accidentals, not the
632 note's @notation{pitch}!  This is a feature that often causes
633 confusion to newcomers, so let us explain it in more detail.
634
635 LilyPond makes a sharp distinction between musical content and
636 layout.  The alteration (@notation{flat}, @notation{natural sign} or
637 @notation{sharp}) of a note is part of the pitch, and is therefore
638 musical content.  Whether an accidental (a @emph{printed} flat,
639 natural or sharp sign) is printed in front of the corresponding
640 note is a question of layout.  Layout is something that follows
641 rules, so accidentals are printed automatically according to those
642 rules.  The pitches in your music are works of art, so they will
643 not be added automatically, and you must enter what you want to
644 hear.
645
646 In this example:
647
648 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
649 \key d \major
650 d cis fis
651 @end lilypond
652
653 @noindent
654 No note has a printed accidental, but you must still add
655 @code{is} and type @code{cis} and @code{fis} in the input file.
656
657 The code @code{e} does not mean @qq{print a black dot just on
658 the first line of the staff.}  Rather, it means @qq{there is a
659 note with pitch E-natural.}  In the key of A-flat major, it
660 @emph{does} get an accidental:
661
662 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
663 \key aes \major
664 e
665 @end lilypond
666
667 Adding all alterations explicitly might require a little more
668 effort when typing, but the advantage is that
669 @notation{transposing} is easier, and accidentals can be printed
670 according to different conventions.  For some examples how
671 accidentals can be printed according to different rules, see
672 @ruser{Automatic accidentals}.
673
674 @seealso
675
676 Notation Reference: @ruser{Note names in other languages},
677 @ruser{Accidentals}, @ruser{Automatic accidentals},
678 @ruser{Key signature}.
679
680 Music Glossary: @rglos{Pitch names}.
681
682
683 @node Ties and slurs
684 @subsection Ties and slurs
685
686 @cindex ties
687 @subheading Ties
688
689 Music Glossary: @rglos{tie}.
690
691 A @notation{tie} is created by appending a tilde @code{~} to the
692 first note being tied.
693
694 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
695 g4~ g c2~
696 c4 ~ c8 a8 ~ a2
697 @end lilypond
698
699 @cindex slurs
700 @subheading Slurs
701
702 Music Glossary: @rglos{slur}.
703
704 A @notation{slur} is a curve drawn across many notes.  The
705 starting note and ending note are marked with @code{(} and
706 @code{)} respectively.
707
708 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
709 d4( c16) cis( d e c cis d) e( d4)
710 @end lilypond
711
712 @cindex slurs, phrasing
713 @cindex phrasing slurs
714 @subheading Phrasing slurs
715
716 Music Glossary: @rglos{slur}, @rglos{phrasing}.
717
718 Slurs to indicate longer @notation{phrasing} can be entered with
719 @code{\(} and @code{\)}.  You can have both @notation{slurs}
720 and phrasing slurs at the same time, but you cannot have
721 simultaneous slurs or simultaneous phrasing slurs.
722
723 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
724 a8(\( ais b c) cis2 b'2 a4 cis,\)
725 @end lilypond
726
727 @smallspace
728
729 @cindex slurs versus ties
730 @subheading Warnings: slurs vs. ties
731
732 Music Glossary: @rglos{articulation}, @rglos{slur}, @rglos{tie}.
733
734 A @notation{slur} looks like a @notation{tie}, but it has a
735 different meaning.  A tie simply makes the first note longer, and
736 can only be used on pairs of notes with the same pitch.  Slurs
737 indicate the @notation{articulation} of notes, and can be used on
738 larger groups of notes.  Slurs and ties can be nested.
739
740 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
741 c2~( c8 fis fis4 ~ fis2 g2)
742 @end lilypond
743
744 @seealso
745
746 Notation Reference: @ruser{Ties}, @ruser{Slurs},
747 @ruser{Phrasing slurs}.
748
749
750 @node Articulation and dynamics
751 @subsection Articulation and dynamics
752
753 @cindex articulation
754 @cindex accents
755 @cindex staccato
756 @subheading Articulations
757
758 Music Glossary: @rglos{articulation}.
759
760 Common @notation{articulations} can be added to a note using a
761 dash @code{-} and a single character:
762
763 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
764 c-. c-- c-> c-^ c-+ c-_
765 @end lilypond
766
767 @cindex fingering
768 @subheading Fingerings
769
770 Music Glossary: @rglos{fingering}.
771
772
773 Similarly, @notation{fingering} indications can be added to a note
774 using a dash (@code{-}) and the digit to be printed:
775
776 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
777 c-3 e-5 b-2 a-1
778 @end lilypond
779
780 Articulations and fingerings are usually placed automatically, but
781 you can specify a direction by replacing the dash (@code{-}) with
782 @code{^} (up) or @code{_} (down).  You can also use multiple
783 articulations on the same note.  However, in most cases it is best
784 to let LilyPond determine the articulation directions.
785
786 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
787 c_-^1 d^. f^4_2-> e^-_+
788 @end lilypond
789
790 @subheading Dynamics
791
792 Music Glossary: @rglos{dynamics}, @rglos{crescendo},
793 @rglos{decrescendo}.
794
795 @notation{Dynamic} signs are made by adding the markings (with a
796 backslash) to the note:
797
798 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
799 c\ff c\mf c\p c\pp
800 @end lilypond
801
802 @cindex dynamics
803 @cindex decrescendo
804 @cindex crescendo
805
806 @notation{Crescendi} and @notation{decrescendi} are started with
807 the commands @code{\<} and @code{\>}.  The next dynamics sign, for
808 example @code{\f}, will end the (de)crescendo, or the command
809 @code{\!} can be used:
810
811 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
812 c2\< c2\ff\> c2 c2\!
813 @end lilypond
814
815 @seealso
816
817 Notation Reference: @ruser{Articulations and ornamentations},
818 @ruser{Fingering instructions}, @ruser{Dynamics}.
819
820
821 @node Adding text
822 @subsection Adding text
823
824 Text may be added to your scores:
825
826 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
827 c1^"espr" a_"legato"
828 @end lilypond
829
830 Extra formatting may be added with the @code{\markup} command:
831
832 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
833 c1^\markup{ \bold espr}
834 a1_\markup{
835   \dynamic f \italic \small { 2nd } \hspace #0.1 \dynamic p
836 }
837 @end lilypond
838
839
840 @seealso
841
842 Notation Reference: @ruser{Writing text}.
843
844
845 @node Automatic and manual beams
846 @subsection Automatic and manual beams
847
848 Music Glossary: @rglos{beam}.
849
850 @cindex beams, by hand
851 All @notation{beams} are drawn automatically:
852
853 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
854 a8 ais d ees r d c16 b a8
855 @end lilypond
856
857 @noindent
858 If you do not like the automatic beams, they may be overridden
859 manually.  To correct just an occasional beam mark the first note
860 to be beamed with @code{[} and the last one with @code{]}.
861 If you want to turn off automatic beaming entirely or for an
862 extended section of music, use the command @code{\autoBeamingOff}
863 to turn off automatic beaming and @code{\autoBeamingOn} to turn
864 it on again.  It will usually be necessary to manually beam music
865 with lyrics.
866
867 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
868 a8[ ais] d[ ees r d] a b
869 @end lilypond
870
871 @seealso
872
873 Notation Reference: @ruser{Automatic beams}, @ruser{Manual beams}.
874
875
876 @node Advanced rhythmic commands
877 @subsection Advanced rhythmic commands
878
879 @cindex pickup
880 @cindex anacrusis
881 @cindex partial measure
882 @subheading Partial measure
883
884 Music Glossary: @rglos{anacrusis}.
885
886 A pickup (or @notation{anacrusis}) is entered with the keyword
887 @code{\partial}.  It is followed by a duration: @code{\partial 4}
888 is a quarter note pickup and @code{\partial 8} an eighth note.
889
890 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
891 \partial 8
892 f8 c2 d
893 @end lilypond
894
895 @cindex tuplets
896 @cindex triplets
897 @subheading Tuplets
898
899 Music Glossary: @rglos{note value}, @rglos{triplet}.
900
901 @notation{Tuplets} are made with the @code{\times} keyword.  It
902 takes two arguments: a fraction and a piece of music.  The
903 duration of the piece of music is multiplied by the fraction.
904 Triplets make notes occupy 2/3 of their notated duration, so a
905 @notation{triplet} has 2/3 as its fraction
906
907 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
908 \times 2/3 { f8 g a }
909 \times 2/3 { c r c }
910 \times 2/3 { f,8 g16[ a g a] }
911 \times 2/3 { d4 a8 }
912 @end lilypond
913
914 @cindex grace notes
915 @cindex acciaccatura
916 @cindex appoggiatura
917 @subheading Grace notes
918
919 Music Glossary: @rglos{grace notes}, @rglos{acciaccatura},
920 @rglos{appoggiatura}.
921
922 @notation{Grace notes} are created with the @code{\grace} command,
923 although they can also be created by prefixing a music expression
924 with the keyword @code{\appoggiatura} or @code{\acciaccatura}:
925
926 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
927 c2 \grace { a32[ b] } c2
928 c2 \appoggiatura b16 c2
929 c2 \acciaccatura b16 c2
930 @end lilypond
931
932 @seealso
933
934 Notation Reference: @ruser{Grace notes}, @ruser{Tuplets},
935 @ruser{Upbeats}.
936
937
938 @node Multiple notes at once
939 @section Multiple notes at once
940
941 This section introduces having more than one note at the same
942 time: multiple instruments, multiple staves for a single
943 instrument (i.e. piano), and chords.
944
945 Polyphony in music refers to having more than one voice occurring
946 in a piece of music.  Polyphony in LilyPond refers to having more
947 than one voice on the same staff.
948
949 @menu
950 * Music expressions explained::
951 * Multiple staves::
952 * Staff groups::
953 * Combining notes into chords::
954 * Single staff polyphony::
955 @end menu
956
957
958 @node Music expressions explained
959 @subsection Music expressions explained
960
961 In LilyPond input files, music is represented by @emph{music
962 expressions}.  A single note is a music expression:
963
964 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
965 a4
966 @end lilypond
967
968 Enclosing a note in braces creates a @emph{compound music
969 expression}.  Here we have created a compound music expression
970 with two notes:
971
972 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
973 { a4 g4 }
974 @end lilypond
975
976 Putting a group of music expressions (e.g. notes) in braces means
977 that they are in sequence (i.e. each one follows the previous
978 one).  The result is another music expression:
979
980 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
981 { { a4 g } f g }
982 @end lilypond
983
984 @cindex expression
985 @cindex music expression
986 @subheading Analogy: mathematical expressions
987
988 This mechanism is similar to mathematical formulas: a big formula
989 is created by composing small formulas.  Such formulas are called
990 expressions, and they can contain other expressions, so you can
991 make arbitrarily complex and large expressions.  For example,
992
993 @example
994 1
995
996 1 + 2
997
998 (1 + 2) * 3
999
1000 ((1 + 2) * 3) / (4 * 5)
1001 @end example
1002
1003 This is a sequence of expressions, where each expression is
1004 contained in the next (larger) one.  The simplest expressions are
1005 numbers, and larger ones are made by combining expressions with
1006 operators (like @code{+}, @code{*} and @code{/}) and parentheses.
1007 Like mathematical expressions, music expressions can be nested
1008 arbitrarily deep, which is necessary for complex music like
1009 polyphonic scores.
1010
1011
1012 @subheading Simultaneous music expressions: multiple staves
1013
1014 Music Glossary: @rglos{polyphony}.
1015
1016 This technique is useful for @notation{polyphonic} music.  To
1017 enter music with more voices or more staves, we combine
1018 expressions in parallel.  To indicate that two voices should play
1019 at the same time, simply enter a simultaneous combination of music
1020 expressions.  A @q{simultaneous} music expression is formed by
1021 enclosing expressions inside @code{<<} and @code{>>}.  In the
1022 following example, three sequences (all containing two separate
1023 notes) are combined simultaneously:
1024
1025 @lilypond[verbatim,quote,ragged-right]
1026 \relative c'' {
1027   <<
1028     { a4 g }
1029     { f e }
1030     { d b }
1031   >>
1032 }
1033 @end lilypond
1034
1035 Note that we have indented each level of the input with a
1036 different amount of space.  LilyPond does not care how much (or
1037 little) space there is at the beginning of a line, but indenting
1038 LilyPond code like this makes it much easier for humans to read.
1039
1040 @warning{each note is relative to the previous note in
1041 the input, not relative to the @code{c''} in the initial
1042 @code{@bs{}relative} command.}
1043
1044
1045 @subheading Simultaneous music expressions: single staff
1046
1047 To determine the number of staves in a piece, LilyPond looks at
1048 the beginning of the first expression.  If is a single note, there
1049 is one staff; if there is a simultaneous expression, there is more
1050 than one staff.
1051
1052 @lilypond[verbatim,quote,ragged-right]
1053 \relative c'' {
1054   c2 <<c e>>
1055   << { e f } { c <<b d>> } >>
1056 }
1057 @end lilypond
1058
1059 @node Multiple staves
1060 @subsection Multiple staves
1061
1062 LilyPond input files are constructed out of music expressions, as
1063 we saw in @ref{Music expressions explained}.  If the score begins
1064 with simultaneous music expressions, LilyPond creates multiples
1065 staves.  However, it is easier to see what happens if we create
1066 each staff explicitly.
1067
1068 To print more than one staff, each piece of music that makes up a
1069 staff is marked by adding @code{\new Staff} before it.  These
1070 @code{Staff} elements are then combined in parallel with @code{<<}
1071 and @code{>>}:
1072
1073 @lilypond[verbatim,quote,ragged-right]
1074 \relative c'' {
1075   <<
1076     \new Staff { \clef treble c }
1077     \new Staff { \clef bass c,, }
1078   >>
1079 }
1080 @end lilypond
1081
1082 The command @code{\new} introduces a @q{notation context.}  A
1083 notation context is an environment in which musical events (like
1084 notes or @code{\clef} commands) are interpreted.  For simple
1085 pieces, such notation contexts are created automatically.  For
1086 more complex pieces, it is best to mark contexts explicitly.
1087
1088 There are several types of contexts.  @code{Score}, @code{Staff},
1089 and @code{Voice} handle melodic notation, while @code{Lyrics} sets
1090 lyric texts and @code{ChordNames} prints chord names.
1091
1092 In terms of syntax, prepending @code{\new} to a music expression
1093 creates a bigger music expression.  In this way it resembles the
1094 minus sign in mathematics.  The formula @math{(4+5)} is an
1095 expression, so @math{-(4+5)} is a bigger expression.
1096
1097 Time signatures entered in one staff affects all other staves by
1098 default.  On the other hand, the key signature of one staff does
1099 @emph{not} affect other staves.  This different default behavior
1100 is because scores with transposing instruments are more common
1101 than polyrhythmic scores.
1102
1103 @lilypond[verbatim,quote,ragged-right]
1104 \relative c'' {
1105   <<
1106     \new Staff { \clef treble \key d \major \time 3/4 c }
1107     \new Staff { \clef bass c,, }
1108   >>
1109 }
1110 @end lilypond
1111
1112
1113
1114
1115 @node Staff groups
1116 @subsection Staff groups
1117
1118 @cindex piano staff
1119 @cindex choir staff
1120 @cindex grand staff
1121
1122 Music Glossary: @rglos{brace}.
1123
1124 Piano music is typeset in two staves connected by a
1125 @notation{brace}.
1126 Printing such a staff is similar to the polyphonic example in
1127 @ref{Multiple staves}.  However, now this entire expression is
1128 inserted inside a @code{PianoStaff}:
1129
1130 @example
1131 \new PianoStaff <<
1132   \new Staff @dots{}
1133   \new Staff @dots{}
1134 >>
1135 @end example
1136
1137 Here is a small example:
1138
1139 @lilypond[verbatim,quote,ragged-right]
1140 \relative c'' {
1141   \new PianoStaff <<
1142     \new Staff { \time 2/4 c4 e g g, }
1143     \new Staff { \clef bass c,, c' e c }
1144   >>
1145 }
1146 @end lilypond
1147
1148 Other staff groupings are introduced with @code{\new GrandStaff},
1149 suitable for orchestral scores, and @w{@code{\new ChoirStaff}},
1150 suitable for vocal scores.  These staff groups each form another
1151 type of context, one that generates the brace at the left end of
1152 every system and also controls the extent of bar lines.
1153
1154 @seealso
1155
1156 Notation Reference: @ruser{Keyboard instruments},
1157 @ruser{Displaying staves}.
1158
1159
1160 @node Combining notes into chords
1161 @subsection Combining notes into chords
1162
1163 @cindex chords
1164
1165 Music Glossary: @rglos{chord}.
1166
1167 We saw earlier how notes can be combined into @notation{chords} by
1168 indicating they are simultaneous by enclosing them in double angle
1169 brackets.  However, the normal way of indicating a chord is to
1170 surround the pitches with @emph{single} angle brackets.  Note that
1171 all the notes in a chord must have the same duration, and that the
1172 duration is placed after the closing bracket.
1173
1174 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1175 r4 <c e g>4 <c f a>2
1176 @end lilypond
1177
1178 Think of chords as almost equivalent to single notes:
1179 almost everything you can attach to a single note can be attached
1180 to a chord, and everything must go @emph{outside} the angle
1181 brackets.  For example, you can combine markings like beams and
1182 ties with chords.  They must be placed outside the angle brackets.
1183
1184 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1185 r4 <c e g>8[ <c f a>]~ <c f a>2
1186 r4 <c e g>8( <c e g>\> <c e g>4 <c f a>\!)
1187 @end lilypond
1188
1189
1190 @node Single staff polyphony
1191 @subsection Single staff polyphony
1192
1193 @cindex polyphony
1194 @cindex multiple voices
1195 @cindex voices, more -- on a staff
1196 When different melodic lines are combined on a single staff they
1197 are printed as polyphonic voices; each voice has its own stems,
1198 slurs and beams, and the top voice has the stems up, while the
1199 bottom voice has them down.
1200
1201 Entering such parts is done by entering each voice as a sequence
1202 (with @w{@code{@{...@}}}) and combining these simultaneously,
1203 separating the voices with @code{\\}:
1204
1205 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1206 <<
1207   { a4 g2 f4~ f4 } \\
1208   { r4 g4 f2 f4 }
1209 >>
1210 @end lilypond
1211
1212 For polyphonic music typesetting, spacer rests can also be
1213 convenient; these are rests that do not print.  They are useful
1214 for filling up voices that temporarily do not play.  Here is the
1215 same example with a spacer rest (@code{s}) instead of a normal
1216 rest (@code{r}),
1217
1218 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1219 <<
1220   { a4 g2 f4~ f4 } \\
1221   { s4 g4 f2 f4 }
1222 >>
1223 @end lilypond
1224
1225 @noindent
1226 Again, these expressions can be nested arbitrarily.
1227
1228 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
1229 <<
1230   \new Staff <<
1231     { a4 g2 f4~ f4 } \\
1232     { s4 g4 f2 f4 }
1233   >>
1234   \new Staff <<
1235     \clef bass
1236     { <c g>1 ~ <c g>4 } \\
1237     { e,,4 d e2 ~ e4}
1238   >>
1239 >>
1240 @end lilypond
1241
1242 @seealso
1243
1244 Notation Reference: @ruser{Simultaneous notes}.
1245
1246
1247 @node Songs
1248 @section Songs
1249
1250 This section introduces vocal music and simple song sheets.
1251
1252 @menu
1253 * Setting simple songs::
1254 * Aligning lyrics to a melody::
1255 * Lyrics to multiple staves::
1256 @end menu
1257
1258
1259 @node Setting simple songs
1260 @subsection Setting simple songs
1261
1262 @cindex lyrics
1263 @cindex songs
1264
1265 Music Glossary: @rglos{lyrics}.
1266
1267 Here is the start of the melody to a nursery
1268 rhyme, @qq{Girls and boys come out to play}:
1269
1270 @lilypond[verbatim,quote,ragged-right]
1271 \relative c'' {
1272   \key g \major
1273   \time 6/8
1274   d4 b8 c4 a8 d4 b8 g4
1275 }
1276 @end lilypond
1277
1278 The @notation{lyrics} can be set to these notes, combining both
1279 with the @code{\addlyrics} keyword.  Lyrics are entered by
1280 separating each syllable with a space.
1281
1282 @lilypond[verbatim,quote,ragged-right]
1283 <<
1284   \relative c'' {
1285     \key g \major
1286     \time 6/8
1287     d4 b8 c4 a8 d4 b8 g4
1288   }
1289   \addlyrics {
1290     Girls and boys come out to play,
1291   }
1292 >>
1293 @end lilypond
1294
1295 Note the curly brackets delimiting both the music and the lyrics,
1296 and the double angle brackets @w{@code{<< ... >>}} around the
1297 whole piece to show that the music and lyrics are to occur at the
1298 same time.
1299
1300 @node Aligning lyrics to a melody
1301 @subsection Aligning lyrics to a melody
1302
1303 Music Glossary: @rglos{melisma}, @rglos{extender line}.
1304
1305 @cindex melisma
1306 @cindex extender line
1307 @cindex hyphens
1308 @cindex underscore
1309
1310 The next line in the nursery rhyme is @q{The moon doth shine as
1311 bright as day}.  Let's extend it:
1312
1313 @lilypond[verbatim,quote,ragged-right]
1314 <<
1315   \relative c'' {
1316     \key g \major
1317     \time 6/8
1318     d4 b8 c4 a8 d4 b8 g4
1319     g8 a4 b8 c b a d4 b8 g4.
1320   }
1321   \addlyrics {
1322     Girls and boys come out to play,
1323     The moon doth shine as bright as day;
1324   }
1325 >>
1326 @end lilypond
1327
1328 We see the extra lyrics do not align properly with the notes.  The
1329 word @q{shine} should be sung on two notes, not one.  This is
1330 called a @notation{melisma}, a single syllable sung to more than
1331 one note.  There are several ways to spread a syllable over
1332 multiple notes, the simplest being to add a slur across them,
1333 marking the start of the slur with a left bracket, (, and the
1334 end with a right bracket, ), for details, see @ref{Ties and slurs}:
1335
1336 @lilypond[verbatim,quote,ragged-right]
1337 <<
1338   \relative c'' {
1339     \key g \major
1340     \time 6/8
1341     d4 b8 c4 a8 d4 b8 g4
1342     g8 a4 b8 c( b) a d4 b8 g4.
1343   }
1344   \addlyrics {
1345     Girls and boys come out to play,
1346     The moon doth shine as bright as day;
1347   }
1348 >>
1349 @end lilypond
1350
1351 The words now line up correctly with the notes, but the automatic
1352 beaming for the notes above @qq{shine as} does not look right.  We
1353 can correct this by inserting manual beaming commands to override
1354 the automatic beaming here.  We mark the start of the beam with a
1355 left square bracket, [, and the end with a right square bracket, ],
1356 for details, see @ref{Automatic and manual beams}.  Note that the 
1357 slur and beam indications do not need to @qq{nest}, i.e., the order
1358 in which they appear is not important, see @ref{On the 
1359 un-nestedness of brackets and ties}.
1360
1361 @lilypond[verbatim,quote,ragged-right]
1362 <<
1363   \relative c'' {
1364     \key g \major
1365     \time 6/8
1366     d4 b8 c4 a8 d4 b8 g4
1367     g8 a4 b8 c([ b)] a d4 b8 g4.
1368   }
1369   \addlyrics {
1370     Girls and boys come out to play,
1371     The moon doth shine as bright as day;
1372   }
1373 >>
1374 @end lilypond
1375
1376 As an alternative to using slurs, the melismata may be indicated
1377 in just the lyrics by using an underscore, @code{_}, for each
1378 note that should be included in the melisma:
1379
1380 @lilypond[verbatim,quote,ragged-right]
1381 <<
1382   \relative c'' {
1383     \key g \major
1384     \time 6/8
1385     d4 b8 c4 a8 d4 b8 g4
1386     g8 a4 b8 c[ b] a d4 b8 g4.
1387   }
1388   \addlyrics {
1389     Girls and boys come out to play,
1390     The moon doth shine _ as bright as day;
1391   }
1392 >>
1393 @end lilypond
1394
1395 If a syllable extends over several notes or a single very long
1396 note an @notation{extender line} is usually drawn from the
1397 syllable extending under all the notes for that syllable.  It is
1398 entered as two underscores @code{__}.  Here is an example from the
1399 first three bars of Dido's Lament, from Purcell's Dido and Ã†neas:
1400
1401 @lilypond[verbatim,quote,ragged-right]
1402 <<
1403   \relative c'' {
1404     \key g \minor
1405     \time 3/2
1406     g2 a bes bes( a) 
1407     b c4.( bes8 a4. g8 fis4.) g8 fis1
1408   }
1409   \addlyrics {
1410     When I am laid, 
1411     am laid __ in earth,
1412   }
1413 >>
1414 @end lilypond
1415
1416 None of the examples so far have involved words containing more
1417 than one syllable.  Such words are usually split one syllable to a
1418 note, with hyphens between syllables.  Such hyphens are entered as
1419 two dashes, resulting in a centered hyphen between the syllables.
1420 Here is an example showing this and everything we have learned so
1421 far about aligning lyrics to notes.
1422
1423 @c no ragged-right here because otherwise the hyphens get lost,
1424 @c but the example is long enough to avoid looking strange.
1425 @lilypond[verbatim,quote]
1426 <<
1427   \relative c' {
1428     \key g \major
1429     \time 3/4
1430     \partial 4
1431     d4 g4 g a8( b) g4 g4 
1432     b8( c) d4 d e4 c2
1433   }
1434   \addlyrics {
1435     A -- way in a __ man -- ger, 
1436     no __ crib for a bed, __
1437   }
1438 >>
1439 @end lilypond
1440
1441 Some lyrics, especially those in Italian, require the opposite:
1442 setting more than one syllable to a single note.  This is
1443 achieved by linking the syllables together with a single
1444 underscore @code{_} (with no spaces), or enclosing them in
1445 quotes.  Here's an example from Rossini's Figaro, where
1446 @q{al} has to be sung on the same note as the @q{go} of 
1447 @q{Largo} in Figaro's aria @q{Largo al factotum}:
1448
1449 @c no ragged-right here because otherwise the hyphens get lost,
1450 @c but the example is long enough to avoid looking strange.
1451 @lilypond[verbatim,quote]
1452 <<
1453   \relative c' {
1454     \clef bass
1455     \key c \major
1456     \time 6/8
1457     c4.~ c8 d b c([ d)] b c d b c
1458   }
1459   \addlyrics {
1460     Lar -- go_al fac -- to -- tum del -- la cit -- tà
1461   }
1462 >>
1463 @end lilypond
1464
1465
1466 @seealso
1467
1468 Notation Reference: @ruser{Vocal music}.
1469
1470
1471 @node Lyrics to multiple staves
1472 @subsection Lyrics to multiple staves
1473
1474 The simple approach using @code{\addlyrics} can be used for
1475 placing lyrics under more than one staff.  Here is an
1476 example from Handel's Judas Maccabæus:
1477
1478 @lilypond[verbatim,quote,ragged-right]
1479 <<
1480   {
1481     \time 6/8
1482     \partial 8
1483   }
1484   \relative c'' {
1485     \key f \major
1486     c8 c([ bes)] a a([ g)] f f'4. b, c4.~ c4
1487   }
1488   \addlyrics {
1489     Let flee -- cy flocks the hills a -- dorn, __
1490   }
1491   \relative c' {
1492     \key f \major
1493     r8 r4. r4 c8 a'([ g)] f f([ e)] d e([ d)] c bes'4
1494   }
1495   \addlyrics {
1496     Let flee -- cy flocks the hills a -- dorn,
1497   }
1498 >>
1499 @end lilypond
1500
1501 @noindent
1502 but scores any more complex than this simple example are
1503 better produced by separating out the staff structure
1504 from the notes and lyrics with variables.  These are
1505 discussed in @ref{Organizing pieces with variables}.
1506
1507 @seealso
1508
1509 Notation Reference: @ruser{Vocal music}.
1510
1511
1512
1513 @node Final touches
1514 @section Final touches
1515
1516 This is the final section of the tutorial; it demonstrates how to
1517 add the final touches to simple pieces, and provides an
1518 introduction to the rest of the manual.
1519
1520 @menu
1521 * Organizing pieces with variables::  
1522 * Version number::              
1523 * Adding titles::               
1524 * Absolute note names::         
1525 * After the tutorial::          
1526 @end menu
1527
1528
1529 @node Organizing pieces with variables
1530 @subsection Organizing pieces with variables
1531
1532 When all of the elements discussed earlier are combined to produce
1533 larger files, the music expressions get a lot bigger.  In
1534 polyphonic music with many staves, the input files can become very
1535 confusing.  We can reduce this confusion by using
1536 @emph{variables}.
1537
1538 With variables (also known as identifiers or macros), we can break
1539 up complex music expressions.  A variable is assigned as
1540 follows:
1541
1542 @example
1543 namedMusic = @{ @dots{} @}
1544 @end example
1545
1546 The contents of the music expression @code{namedMusic} can be used
1547 later by placing a backslash in front of the name
1548 (@code{\namedMusic}, just like a normal LilyPond command).
1549
1550 @lilypond[verbatim,quote,ragged-right]
1551 violin = \new Staff { \relative c'' {
1552   a4 b c b
1553 }}
1554 cello = \new Staff { \relative c {
1555   \clef bass
1556   e2 d
1557 }}
1558 {
1559   <<
1560     \violin
1561     \cello
1562   >>
1563 }
1564 @end lilypond
1565
1566 @noindent
1567 The name of a variable must have alphabetic characters only, no
1568 numbers, underscores, or dashes.
1569
1570 Variables must be defined @emph{before} the main music
1571 expression, but may be used as many times as required anywhere after
1572 they have been defined.  They may even be used in a later definition
1573 of another variable, giving a way of shortening the input if a
1574 section of music is repeated many times.
1575
1576 @lilypond[verbatim,quote,ragged-right]
1577 tripletA = \times 2/3 { c,8 e g }
1578 barA = { \tripletA \tripletA \tripletA \tripletA }
1579
1580 \relative c'' {
1581  \barA \barA
1582 }
1583 @end lilypond
1584
1585 Variables may be used for many other types of objects in
1586 the input.  For example,
1587
1588 @example
1589 width = 4.5\cm
1590 name = "Wendy"
1591 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1592 @end example
1593
1594 Depending on its contents, the variable can be used in different
1595 places.  The following example uses the above variables:
1596
1597 @example
1598 \paper @{
1599   \aFivePaper
1600   line-width = \width
1601 @}
1602 @{ c4^\name @}
1603 @end example
1604
1605
1606 @node Version number
1607 @subsection Version number
1608
1609 @cindex versioning
1610 The @code{\version} statement records the version of LilyPond that
1611 was used to write the file:
1612
1613 @example
1614 \version @w{"@version{}"}
1615 @end example
1616
1617 @noindent
1618 By convention, this is placed at the top of your LilyPond file.
1619
1620 These annotations make future upgrades of LilyPond go more
1621 smoothly.  Changes in the syntax are handled with a special
1622 program, @file{convert-ly}, and it uses @code{\version} to
1623 determine what rules to apply.  For details, see
1624 @rprogram{Updating files with convert-ly}.
1625
1626
1627 @node Adding titles
1628 @subsection Adding titles
1629
1630 The title, composer, opus number, and similar information are
1631 entered in the @code{\header} block.  This exists outside of the
1632 main music expression; the @code{\header} block is usually placed
1633 underneath the @ref{Version number}.
1634
1635 @example
1636 \version @w{"@version{}"}
1637 \header @{
1638   title = "Symphony"
1639   composer = "Me"
1640   opus = "Op. 9"
1641 @}
1642
1643 @{
1644   @dots{} music @dots{}
1645 @}
1646 @end example
1647
1648 When the file is processed, the title and composer are printed
1649 above the music.  More information on titling can be found in
1650 @ruser{Creating titles}.
1651
1652
1653 @node Absolute note names
1654 @subsection Absolute note names
1655
1656 So far we have always used @code{\relative} to define pitches.
1657 This is the easiest way to enter most music, but another way of
1658 defining pitches exists: absolute mode.
1659
1660 If you omit the @code{\relative}, LilyPond treats all pitches as
1661 absolute values.  A @code{c'} will always mean middle C, a
1662 @code{b} will always mean the note one step below middle C, and a
1663 @code{g,} will always mean the note on the bottom staff of the
1664 bass clef.
1665
1666 @lilypond[verbatim,quote,ragged-right]
1667 {
1668   \clef bass
1669   c' b g, g,
1670   g, f, f c'
1671 }
1672 @end lilypond
1673
1674 Here is a four-octave scale:
1675
1676 @lilypond[verbatim,quote,ragged-right]
1677 {
1678   \clef bass
1679   c, d, e, f,
1680   g, a, b, c
1681   d e f g
1682   a b c' d'
1683   \clef treble
1684   e' f' g' a'
1685   b' c'' d'' e''
1686   f'' g'' a'' b''
1687   c'''1
1688 }
1689 @end lilypond
1690
1691 As you can see, writing a melody in the treble clef involves a lot
1692 of quote @code{'} marks.  Consider this fragment from Mozart:
1693
1694 @lilypond[verbatim,quote,ragged-right]
1695 {
1696   \key a \major
1697   \time 6/8
1698   cis''8. d''16 cis''8 e''4 e''8
1699   b'8. cis''16 b'8 d''4 d''8
1700 }
1701 @end lilypond
1702
1703 All these quotes makes the input less readable and they are a source
1704 of errors.  With @code{\relative}, the previous example is much
1705 easier to read and type:
1706
1707 @lilypond[verbatim,quote,ragged-right]
1708 \relative c'' {
1709   \key a \major
1710   \time 6/8
1711   cis8. d16 cis8 e4 e8
1712   b8. cis16 b8 d4 d8
1713 }
1714 @end lilypond
1715
1716 If you make a mistake with an octave mark (@code{'} or @code{,})
1717 while working in @code{\relative} mode, it is very obvious -- many
1718 notes will be in the wrong octave.  When working in absolute mode,
1719 a single mistake will not be as visible, and will not be as easy
1720 to find.
1721
1722 However, absolute mode is useful for music which has large
1723 intervals, and is extremely useful for computer-generated LilyPond
1724 files.
1725
1726
1727
1728 @node After the tutorial
1729 @subsection After the tutorial
1730
1731 FIXME: rewrite slightly after the rest of the LM has been
1732 stabilized.  Translators, ignore this section for now.
1733
1734 After finishing the tutorial, you should probably try writing a
1735 piece or two.  Start by adding notes to one of the
1736 @ref{Templates}.  If you need any notation that was not covered in
1737 the tutorial, look at the Notation Reference, starting with
1738 @ruser{Musical notation}.  If you want to write for an instrument
1739 ensemble that is not covered in the templates, take a look at
1740 @ref{Extending the templates}.
1741
1742 Once you have written a few short pieces, read the rest of the
1743 Learning Manual (chapters 3-5).  There's nothing wrong with
1744 reading it now, of course!  However, the rest of the Learning
1745 Manual assumes that you are familiar with LilyPond input.  You may
1746 wish to skim these chapters right now, and come back to them after
1747 you have more experience.
1748
1749
1750
1751