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