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