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