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