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