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