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