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