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