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