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