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