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