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