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