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