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