]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/tutorial.itely
a35017866623a3a14846da6dd9d685e30b6dbad5
[lilypond.git] / Documentation / learning / tutorial.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
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 \version "2.12.0"
11
12 @ignore
13 Tutorial guidelines:  (different from policy.txt!)
14 - unless you have a really good reason, use either
15     @lilypond[verbatim,quote]
16   or
17     @lilypond[verbatim,quote,relative=2]
18
19   Don't use any other relative=X commands.
20
21 - use "aes" and "ees" instead of "as" and "es".  I know it's not
22   correct Dutch naming, but let's not confuse people with this
23   until we get to the Basic notation chapter.
24
25 - Add "Music Glossary: @rglos{foo}" to the *top* of the relevant
26   portions of the tutorial.
27
28 @end ignore
29
30
31 @node Common notation
32 @chapter Common notation
33
34 This tutorial starts with an introduction to the LilyPond music
35 language and explains how to produce printed music.  After this first
36 contact we will explain how to create beautiful printed music
37 containing common musical notation.
38
39 @menu
40 * Single staff notation::
41 * Multiple notes at once::
42 * Songs::
43 * Final touches::
44 @end menu
45
46
47 @node Single staff notation
48 @section Single staff notation
49
50 This section introduces common notation that is used for one voice
51 on one staff.
52
53 @menu
54 * Accidentals and key signatures::
55 * Ties and slurs::
56 * Articulation and dynamics::
57 * Adding text::
58 * Automatic and manual beams::
59 * Advanced rhythmic commands::
60 @end menu
61
62
63 @node Accidentals and key signatures
64 @subsection Accidentals and key signatures
65
66 @subheading Accidentals
67
68 @cindex accidentals
69 @cindex accidentals and key signatures
70 @cindex sharp
71 @cindex double sharp
72 @cindex sharp, double
73 @cindex flat
74 @cindex double flat
75 @cindex flat, double
76
77 @funindex es
78 @funindex is
79 @funindex eses
80 @funindex isis
81
82 Music Glossary: @rglos{sharp}, @rglos{flat}, @rglos{double sharp},
83 @rglos{double flat}, @rglos{accidental}.
84
85 A @notation{sharp} pitch is made by adding @code{is} to the name,
86 and a @notation{flat} pitch by adding @code{es}.  As you might
87 expect, a @notation{double sharp} or @notation{double flat} is
88 made by adding @code{isis} or @code{eses}.  This syntax is derived
89 from note naming conventions in Nordic and Germanic languages,
90 like German and Dutch.  To use other names for
91 @notation{accidentals}, see @ruser{Note names in other languages}.
92
93 @lilypond[verbatim,quote,relative=2]
94 cis1 ees fisis, aeses
95 @end lilypond
96
97 @cindex key signature, setting
98 @subheading Key signatures
99
100 @cindex key signature
101 @cindex major
102 @cindex minor
103 @cindex accidentals and key signature
104 @cindex content vs. layout
105 @cindex layout vs. content
106
107 @funindex \key
108 @funindex key
109 @funindex \major
110 @funindex major
111 @funindex \minor
112 @funindex minor
113
114 Music Glossary: @rglos{key signature}, @rglos{major},
115 @rglos{minor}.
116
117 The @notation{key signature} is set with the command @code{\key}
118 followed by a pitch and @code{\major} or @code{\minor}.
119
120 @lilypond[verbatim,quote,relative=2]
121 \key d \major
122 a1
123 \key c \minor
124 a
125 @end lilypond
126
127 @smallspace
128
129 @subheading Warning: key signatures and pitches
130
131 Music Glossary: @rglos{accidental}, @rglos{key signature},
132 @rglos{pitch}, @rglos{flat}, @rglos{natural}, @rglos{sharp},
133 @rglos{transposition}.
134
135 To determine whether to print an @notation{accidental}, LilyPond
136 examines the pitches and the @notation{key signature}.  The key
137 signature only affects the @emph{printed} accidentals, not the
138 note's @notation{pitch}!  This is a feature that often causes
139 confusion to newcomers, so let us explain it in more detail.
140
141 LilyPond makes a sharp distinction between musical content and
142 layout.  The alteration (@notation{flat}, @notation{natural sign} or
143 @notation{sharp}) of a note is part of the pitch, and is therefore
144 musical content.  Whether an accidental (a @emph{printed} flat,
145 natural or sharp sign) is printed in front of the corresponding
146 note is a question of layout.  Layout is something that follows
147 rules, so accidentals are printed automatically according to those
148 rules.  The pitches in your music are works of art, so they will
149 not be added automatically, and you must enter what you want to
150 hear.
151
152 In this example:
153
154 @lilypond[verbatim,quote,relative=2]
155 \key d \major
156 d cis fis
157 @end lilypond
158
159 @noindent
160 No note has a printed accidental, but you must still add
161 @code{is} and type @code{cis} and @code{fis} in the input file.
162
163 The code @code{b} does not mean @qq{print a black dot just on
164 the middle line of the staff.}  Rather, it means @qq{there is a
165 note with pitch B-natural.}  In the key of A-flat major, it
166 @emph{does} get an accidental:
167
168 @lilypond[verbatim,quote,relative=2]
169 \key aes \major
170 b
171 @end lilypond
172
173 Adding all alterations explicitly might require a little more
174 effort when typing, but the advantage is that
175 @notation{transposing} is easier, and accidentals can be printed
176 according to different conventions.  For some examples how
177 accidentals can be printed according to different rules, see
178 @ruser{Automatic accidentals}.
179
180
181 @seealso
182 Notation Reference: @ruser{Note names in other languages},
183 @ruser{Accidentals}, @ruser{Automatic accidentals},
184 @ruser{Key signature}.
185
186 Music Glossary: @rglos{Pitch names}.
187
188
189 @node Ties and slurs
190 @subsection Ties and slurs
191
192 @cindex tie
193 @cindex slur
194 @cindex slur, phrasing
195 @cindex phrasing slur
196
197 @funindex ~
198 @funindex ( ... )
199 @funindex \( ... \)
200
201 @subheading Ties
202
203
204 Music Glossary: @rglos{tie}.
205
206 A @notation{tie} is created by appending a tilde @code{~} to the
207 first note being tied.
208
209 @lilypond[verbatim,quote,relative=2]
210 g4~ g c2~
211 c4 ~ c8 a8 ~ a2
212 @end lilypond
213
214 @subheading Slurs
215
216
217 Music Glossary: @rglos{slur}.
218
219 A @notation{slur} is a curve drawn across many notes.  The
220 starting note and ending note are marked with @code{(} and
221 @code{)} respectively.
222
223 @lilypond[verbatim,quote,relative=2]
224 d4( c16) cis( d e c cis d) e( d4)
225 @end lilypond
226
227 @subheading Phrasing slurs
228
229 Music Glossary: @rglos{slur}, @rglos{phrasing}.
230
231 Slurs to indicate longer @notation{phrasing} can be entered with
232 @code{\(} and @code{\)}.  You can have both @notation{slurs}
233 and phrasing slurs at the same time, but you cannot have
234 simultaneous slurs or simultaneous phrasing slurs.
235
236 @lilypond[verbatim,quote,relative=2]
237 a8(\( ais b c) cis2 b'2 a4 cis,\)
238 @end lilypond
239
240 @smallspace
241
242 @cindex slurs versus ties
243 @subheading Warnings: slurs vs. ties
244
245 Music Glossary: @rglos{articulation}, @rglos{slur}, @rglos{tie}.
246
247 A @notation{slur} looks like a @notation{tie}, but it has a
248 different meaning.  A tie simply makes the first note longer, and
249 can only be used on pairs of notes with the same pitch.  Slurs
250 indicate the @notation{articulation} of notes, and can be used on
251 larger groups of notes.  Slurs and ties can be nested.
252
253 @lilypond[verbatim,quote,relative=2]
254 c2~( c8 fis fis4 ~ fis2 g2)
255 @end lilypond
256
257
258 @seealso
259 Notation Reference: @ruser{Ties}, @ruser{Slurs},
260 @ruser{Phrasing slurs}.
261
262
263 @node Articulation and dynamics
264 @subsection Articulation and dynamics
265
266
267 @subheading Articulations
268
269 @cindex articulation
270 @cindex accent
271 @cindex staccato
272
273 Music Glossary: @rglos{articulation}.
274
275 Common @notation{articulations} can be added to a note using a
276 dash @code{-} and a single character:
277
278 @lilypond[verbatim,quote,relative=2]
279 c-. c-- c-> c-^ c-+ c-_
280 @end lilypond
281
282 @subheading Fingerings
283
284 @cindex fingering
285
286 @funindex ^
287 @funindex _
288
289 Music Glossary: @rglos{fingering}.
290
291 Similarly, @notation{fingering} indications can be added to a note
292 using a dash (@code{-}) and the digit to be printed:
293
294 @lilypond[verbatim,quote,relative=2]
295 c-3 e-5 b-2 a-1
296 @end lilypond
297
298 Articulations and fingerings are usually placed automatically, but
299 you can specify a direction by replacing the dash (@code{-}) with
300 @code{^} (up) or @code{_} (down).  You can also use multiple
301 articulations on the same note.  However, in most cases it is best
302 to let LilyPond determine the articulation directions.
303
304 @lilypond[verbatim,quote,relative=2]
305 c_-^1 d^. f^4_2-> e^-_+
306 @end lilypond
307
308 @subheading Dynamics
309
310 @cindex dynamics
311 @cindex decrescendo
312 @cindex crescendo
313
314 @funindex \f
315 @funindex \ff
316 @funindex \mp
317 @funindex \p
318 @funindex \mf
319 @funindex \pp
320 @funindex \<
321 @funindex <
322 @funindex \>
323 @funindex >
324 @funindex \!
325 @funindex !
326
327 Music Glossary: @rglos{dynamics}, @rglos{crescendo},
328 @rglos{decrescendo}.
329
330 @notation{Dynamic} signs are made by adding the markings (with a
331 backslash) to the note:
332
333 @lilypond[verbatim,quote,relative=2]
334 c\ff c\mf c\p c\pp
335 @end lilypond
336
337
338 @notation{Crescendi} and @notation{decrescendi} are started with
339 the commands @code{\<} and @code{\>}.  The next dynamics sign, for
340 example @code{\f}, will end the (de)crescendo, or the command
341 @code{\!} can be used:
342
343 @lilypond[verbatim,quote,relative=2]
344 c2\< c2\ff\> c2 c2\!
345 @end lilypond
346
347
348 @seealso
349 Notation Reference: @ruser{Articulations and ornamentations},
350 @ruser{Fingering instructions}, @ruser{Dynamics}.
351
352
353 @node Adding text
354 @subsection Adding text
355
356 @cindex text, adding
357 @cindex adding text
358 @cindex markup
359
360 @funindex \markup
361 @funindex markup
362
363 Text may be added to your scores:
364
365 @lilypond[verbatim,quote,relative=2]
366 c1^"espr" a_"legato"
367 @end lilypond
368
369 Extra formatting may be added with the @code{\markup} command:
370
371 @lilypond[verbatim,quote,relative=2]
372 c1^\markup{ \bold espr}
373 a1_\markup{
374   \dynamic f \italic \small { 2nd } \hspace #0.1 \dynamic p
375 }
376 @end lilypond
377
378
379 @seealso
380 Notation Reference: @ruser{Writing text}.
381
382
383 @node Automatic and manual beams
384 @subsection Automatic and manual beams
385
386 @cindex beaming
387 @cindex automatic beams
388 @cindex manual beams
389 @cindex beams, automatic
390 @cindex beams, manual
391 @cindex beams, by hand
392
393 @funindex [ ... ]
394 @funindex [
395 @funindex ]
396 @funindex \autoBeamOff
397 @funindex autoBeamOff
398 @funindex \autoBeamOn
399 @funindex autoBeamOn
400
401 Music Glossary: @rglos{beam}.
402
403 All @notation{beams} are drawn automatically:
404
405 @lilypond[verbatim,quote,relative=2]
406 a8 ais d ees r d c16 b a8
407 @end lilypond
408
409 If you do not like the automatic beams, they may be overridden
410 manually.  To correct just an occasional beam mark the first note
411 to be beamed with @code{[} and the last one with @code{]}.
412
413 @lilypond[verbatim,quote,relative=2]
414 a8[ ais] d[ ees r d] a b
415 @end lilypond
416
417 If you want to turn off automatic beaming entirely or for an
418 extended section of music, use the command @code{\autoBeamOff}
419 to turn off automatic beaming and @code{\autoBeamOn} to turn it
420 on again.
421
422 @lilypond[verbatim,quote,relative=2]
423 \autoBeamOff
424 a8 c b4 d8. c16 b4
425 \autoBeamOn
426 a8 c b4 d8. c16 b4
427 @end lilypond
428
429
430 @seealso
431 Notation Reference: @ruser{Automatic beams}, @ruser{Manual beams}.
432
433
434 @node Advanced rhythmic commands
435 @subsection Advanced rhythmic commands
436
437 @subheading Partial measure
438
439 @cindex pickup
440 @cindex anacrusis
441 @cindex partial measure
442
443 @funindex \partial
444 @funindex partial
445
446 Music Glossary: @rglos{anacrusis}.
447
448 A pickup (or @notation{anacrusis}) is entered with the keyword
449 @code{\partial}.  It is followed by a duration: @code{\partial 4}
450 is a quarter note pickup and @code{\partial 8} an eighth note.
451
452 @lilypond[verbatim,quote,relative=2]
453 \partial 8
454 f8 c2 d
455 @end lilypond
456
457 @subheading Tuplets
458
459 @cindex tuplets
460 @cindex triplets
461
462 @funindex \times
463 @funindex times
464
465 Music Glossary: @rglos{note value}, @rglos{triplet}.
466
467 @notation{Tuplets} are made with the @code{\times} keyword.  It
468 takes two arguments: a fraction and a piece of music.  The
469 duration of the piece of music is multiplied by the fraction.
470 Triplets make notes occupy 2/3 of their notated duration, so a
471 @notation{triplet} has 2/3 as its fraction
472
473 @lilypond[verbatim,quote,relative=2]
474 \times 2/3 { f8 g a }
475 \times 2/3 { c r c }
476 \times 2/3 { f,8 g16[ a g a] }
477 \times 2/3 { d4 a8 }
478 @end lilypond
479
480 @subheading Grace notes
481
482 @cindex grace notes
483 @cindex acciaccatura
484 @cindex appoggiatura
485
486 @funindex \grace
487 @funindex grace
488 @funindex \acciaccatura
489 @funindex acciaccatura
490 @funindex \appoggiatura
491 @funindex acciaccatura
492
493 Music Glossary: @rglos{grace notes}, @rglos{acciaccatura},
494 @rglos{appoggiatura}.
495
496 @notation{Grace notes} are created with the @code{\grace} command,
497 although they can also be created by prefixing a music expression
498 with the keyword @code{\appoggiatura} or @code{\acciaccatura}:
499
500 @lilypond[verbatim,quote,relative=2]
501 c2 \grace { a32[ b] } c2
502 c2 \appoggiatura b16 c2
503 c2 \acciaccatura b16 c2
504 @end lilypond
505
506
507 @seealso
508 Notation Reference: @ruser{Grace notes}, @ruser{Tuplets},
509 @ruser{Upbeats}.
510
511
512 @node Multiple notes at once
513 @section Multiple notes at once
514
515 This section introduces having more than one note at the same
516 time: multiple instruments, multiple staves for a single
517 instrument (i.e. piano), and chords.
518
519 Polyphony in music refers to having more than one voice occurring
520 in a piece of music.  Polyphony in LilyPond refers to having more
521 than one voice on the same staff.
522
523 @menu
524 * Music expressions explained::
525 * Multiple staves::
526 * Staff groups::
527 * Combining notes into chords::
528 * Single staff polyphony::
529 @end menu
530
531
532 @node Music expressions explained
533 @subsection Music expressions explained
534
535 @cindex music expression
536 @cindex expression, music
537 @cindex compound music expression
538 @cindex music expression, compound
539
540 In LilyPond input files, music is represented by @emph{music
541 expressions}.  A single note is a music expression:
542
543 @lilypond[verbatim,quote,relative=2]
544 a4
545 @end lilypond
546
547 Enclosing a note in braces creates a @emph{compound music
548 expression}.  Here we have created a compound music expression
549 with two notes:
550
551 @lilypond[verbatim,quote,relative=2]
552 { a4 g4 }
553 @end lilypond
554
555 Putting a group of music expressions (e.g. notes) in braces means
556 that they are in sequence (i.e. each one follows the previous
557 one).  The result is another music expression:
558
559 @lilypond[verbatim,quote,relative=2]
560 { { a4 g } f g }
561 @end lilypond
562
563 @subheading Analogy: mathematical expressions
564
565 This mechanism is similar to mathematical formulas: a big formula
566 is created by composing small formulas.  Such formulas are called
567 expressions, and they can contain other expressions, so you can
568 make arbitrarily complex and large expressions.  For example,
569
570 @example
571 1
572
573 1 + 2
574
575 (1 + 2) * 3
576
577 ((1 + 2) * 3) / (4 * 5)
578 @end example
579
580 This is a sequence of expressions, where each expression is
581 contained in the next (larger) one.  The simplest expressions are
582 numbers, and larger ones are made by combining expressions with
583 operators (like @code{+}, @code{*} and @code{/}) and parentheses.
584 Like mathematical expressions, music expressions can be nested
585 arbitrarily deep, which is necessary for complex music like
586 polyphonic scores.
587
588
589 @subheading Simultaneous music expressions: multiple staves
590
591 @cindex multiple staves
592 @cindex staves, multiple
593 @cindex polyphony
594 @cindex combining expressions in parallel
595 @cindex parallel expressions
596 @cindex expressions, parallel
597 @cindex relative notes and simultaneous music
598 @cindex relative notes and parallel expressions
599 @cindex simultaneous music and relative notes
600 @cindex parallel expressions and relative notes
601
602 @funindex <<
603 @funindex >>
604 @funindex << ... >>
605
606 Music Glossary: @rglos{polyphony}.
607
608 This technique is useful for @notation{polyphonic} music.  To
609 enter music with more voices or more staves, we combine
610 expressions in parallel.  To indicate that two voices should play
611 at the same time, simply enter a simultaneous combination of music
612 expressions.  A @q{simultaneous} music expression is formed by
613 enclosing expressions inside @code{<<} and @code{>>}.  In the
614 following example, three sequences (all containing two separate
615 notes) are combined simultaneously:
616
617 @lilypond[verbatim,quote]
618 \relative c'' {
619   <<
620     { a4 g }
621     { f e }
622     { d b }
623   >>
624 }
625 @end lilypond
626
627 Note that we have indented each level of the input with a
628 different amount of space.  LilyPond does not care how much (or
629 little) space there is at the beginning of a line, but indenting
630 LilyPond code like this makes it much easier for humans to read.
631
632 @warning{each note is relative to the previous note in
633 the input, not relative to the @code{c''} in the initial
634 @code{@bs{}relative} command.}
635
636
637 @subheading Simultaneous music expressions: single staff
638
639 To determine the number of staves in a piece, LilyPond looks at
640 the beginning of the first expression.  If there is a single note,
641 there is one staff; if there is a simultaneous expression, there
642 is more than one staff.  The following example shows a complex
643 expression, but as it begins with a single note it will be set
644 out on a single staff.
645
646 @lilypond[verbatim,quote]
647 \relative c'' {
648   c2 <<c e>>
649   << { e f } { c <<b d>> } >>
650 }
651 @end lilypond
652
653 @node Multiple staves
654 @subsection Multiple staves
655
656 @cindex multiple staves
657 @cindex staves, multiple
658 @cindex context
659 @cindex context, notation
660 @cindex notation context
661
662 @funindex \new Staff
663 @funindex new Staff
664 @funindex Staff
665 @funindex \new
666 @funindex new
667 @funindex Score
668 @funindex Voice
669 @funindex Lyrics
670 @funindex ChordNames
671
672 LilyPond input files are constructed out of music expressions, as
673 we saw in @ref{Music expressions explained}.  If the score begins
674 with simultaneous music expressions, LilyPond creates multiples
675 staves.  However, it is easier to see what happens if we create
676 each staff explicitly.
677
678 To print more than one staff, each piece of music that makes up a
679 staff is marked by adding @code{\new Staff} before it.  These
680 @code{Staff} elements are then combined in parallel with @code{<<}
681 and @code{>>}:
682
683 @lilypond[verbatim,quote]
684 \relative c'' {
685   <<
686     \new Staff { \clef treble c }
687     \new Staff { \clef bass c,, }
688   >>
689 }
690 @end lilypond
691
692 The command @code{\new} introduces a @q{notation context.}  A
693 notation context is an environment in which musical events (like
694 notes or @code{\clef} commands) are interpreted.  For simple
695 pieces, such notation contexts are created automatically.  For
696 more complex pieces, it is best to mark contexts explicitly.
697
698 There are several types of contexts.  @code{Score}, @code{Staff},
699 and @code{Voice} handle melodic notation, while @code{Lyrics} sets
700 lyric texts and @code{ChordNames} prints chord names.
701
702 In terms of syntax, prepending @code{\new} to a music expression
703 creates a bigger music expression.  In this way it resembles the
704 minus sign in mathematics.  The formula @math{(4+5)} is an
705 expression, so @math{-(4+5)} is a bigger expression.
706
707 Time signatures entered in one staff affects all other staves by
708 default.  On the other hand, the key signature of one staff does
709 @emph{not} affect other staves.  This different default behavior
710 is because scores with transposing instruments are more common
711 than polyrhythmic scores.
712
713 @lilypond[verbatim,quote]
714 \relative c'' {
715   <<
716     \new Staff { \clef treble \key d \major \time 3/4 c }
717     \new Staff { \clef bass c,, }
718   >>
719 }
720 @end lilypond
721
722
723
724
725 @node Staff groups
726 @subsection Staff groups
727
728 @cindex piano staff
729 @cindex staff, piano
730 @cindex choir staff
731 @cindex staff, choir
732 @cindex grand staff
733 @cindex staff, grand
734 @cindex staff group
735
736 @funindex PianoStaff
737 @funindex GrandStaff
738 @funindex ChoirStaff
739
740 Music Glossary: @rglos{brace}.
741
742 Piano music is typeset in two staves connected by a
743 @notation{brace}.
744 Printing such a staff is similar to the polyphonic example in
745 @ref{Multiple staves}.  However, now this entire expression is
746 inserted inside a @code{PianoStaff}:
747
748 @example
749 \new PianoStaff <<
750   \new Staff @dots{}
751   \new Staff @dots{}
752 >>
753 @end example
754
755 Here is a small example:
756
757 @lilypond[verbatim,quote]
758 \relative c'' {
759   \new PianoStaff <<
760     \new Staff { \time 2/4 c4 e g g, }
761     \new Staff { \clef bass c,, c' e c }
762   >>
763 }
764 @end lilypond
765
766 Other staff groupings are introduced with @code{\new GrandStaff},
767 suitable for orchestral scores, and @w{@code{\new ChoirStaff}},
768 suitable for vocal scores.  These staff groups each form another
769 type of context, one that generates the brace at the left end of
770 every system and also controls the extent of bar lines.
771
772
773 @seealso
774 Notation Reference: @ruser{Keyboard and other multi-staff
775 instruments},
776 @ruser{Displaying staves}.
777
778
779 @node Combining notes into chords
780 @subsection Combining notes into chords
781
782 @cindex chords
783 @cindex note durations in chords
784
785 @funindex <
786 @funindex >
787 @funindex < ... >
788
789 Music Glossary: @rglos{chord}.
790
791 We saw earlier how notes can be combined into @notation{chords} by
792 indicating they are simultaneous by enclosing them in double angle
793 brackets.  However, the normal way of indicating a chord is to
794 surround the pitches with @emph{single} angle brackets.  Note that
795 all the notes in a chord must have the same duration, and that the
796 duration is placed after the closing bracket.
797
798 @lilypond[verbatim,quote,relative=2]
799 r4 <c e g>4 <c f a>2
800 @end lilypond
801
802 Think of chords as almost equivalent to single notes:
803 almost everything you can attach to a single note can be attached
804 to a chord, and everything must go @emph{outside} the angle
805 brackets.  For example, you can combine markings like beams and
806 ties with chords.  They must be placed outside the angle brackets.
807
808 @lilypond[verbatim,quote,relative=2]
809 r4 <c e g>8[ <c f a>]~ <c f a>2
810 r4 <c e g>8( <c e g>\> <c e g>4 <c f a>\!)
811 @end lilypond
812
813
814 @node Single staff polyphony
815 @subsection Single staff polyphony
816
817 @cindex polyphony
818 @cindex multiple voices
819 @cindex voices, more on one staff
820 @cindex single staff polyphony
821 @cindex spacer rest
822 @cindex rest, spacer
823
824 @funindex << ... \\ ... >>
825 @funindex <<
826 @funindex \\
827 @funindex >>
828
829 Polyphonic music in lilypond, while not difficult, uses concepts
830 that we haven't discussed yet, so we're not going to introduce
831 them here. Instead, the following sections introduce these concepts
832 and explain them thoroughly.
833
834 @seealso
835 Learning Manual: @ref{Voices contain music}.
836
837 Notation Reference: @ruser{Simultaneous notes}.
838
839 @node Songs
840 @section Songs
841
842 This section introduces vocal music and simple song sheets.
843
844 @menu
845 * Setting simple songs::
846 * Aligning lyrics to a melody::
847 * Lyrics to multiple staves::
848 @end menu
849
850
851 @node Setting simple songs
852 @subsection Setting simple songs
853
854 @cindex lyrics
855 @cindex songs
856
857 @funindex \addlyrics
858 @funindex addlyrics
859
860 Music Glossary: @rglos{lyrics}.
861
862 Here is the start of the melody to a nursery
863 rhyme, @notation{Girls and boys come out to play}:
864
865 @lilypond[verbatim,quote]
866 \relative c'' {
867   \key g \major
868   \time 6/8
869   d4 b8 c4 a8 d4 b8 g4
870 }
871 @end lilypond
872
873 The @notation{lyrics} can be set to these notes, combining both
874 with the @code{\addlyrics} keyword.  Lyrics are entered by
875 separating each syllable with a space.
876
877 @lilypond[verbatim,quote]
878 <<
879   \relative c'' {
880     \key g \major
881     \time 6/8
882     d4 b8 c4 a8 d4 b8 g4
883   }
884   \addlyrics {
885     Girls and boys come out to play,
886   }
887 >>
888 @end lilypond
889
890 Note the curly brackets delimiting both the music and the lyrics,
891 and the double angle brackets @w{@code{<< ... >>}} around the
892 whole piece to show that the music and lyrics are to occur at the
893 same time.
894
895 @node Aligning lyrics to a melody
896 @subsection Aligning lyrics to a melody
897
898 @cindex melisma
899 @cindex extender line
900 @cindex hyphens
901 @cindex underscore
902 @cindex lyrics, aligning
903 @cindex aligning lyrics
904 @cindex lyrics, multi-syllable words
905 @cindex words with multiple syllables in lyrics
906
907 Music Glossary: @rglos{melisma}, @rglos{extender line}.
908
909 The next line in the nursery rhyme is @notation{The moon doth
910 shine as bright as day}.  Let's extend it:
911
912 @lilypond[verbatim,quote]
913 <<
914   \relative c'' {
915     \key g \major
916     \time 6/8
917     d4 b8 c4 a8 d4 b8 g4
918     g8 a4 b8 c b a d4 b8 g4.
919   }
920   \addlyrics {
921     Girls and boys come out to play,
922     The moon doth shine as bright as day;
923   }
924 >>
925 @end lilypond
926
927 We see the extra lyrics do not align properly with the notes.  The
928 word @notation{shine} should be sung on two notes, not one.  This
929 is called a @notation{melisma}, a single syllable sung to more
930 than one note.  There are several ways to spread a syllable over
931 multiple notes, the simplest being to add a slur across them, for
932 details, see @ref{Ties and slurs}:
933
934 @lilypond[verbatim,quote]
935 <<
936   \relative c'' {
937     \key g \major
938     \time 6/8
939     d4 b8 c4 a8 d4 b8 g4
940     g8 a4 b8 c( b) a d4 b8 g4.
941   }
942   \addlyrics {
943     Girls and boys come out to play,
944     The moon doth shine as bright as day;
945   }
946 >>
947 @end lilypond
948
949 The words now line up correctly with the notes, but the automatic
950 beaming for the notes above @notation{shine as} does not look right.
951 We can correct this by inserting manual beaming commands to override
952 the automatic beaming here, for details, see @ref{Automatic and
953 manual beams}.
954
955 @lilypond[verbatim,quote]
956 <<
957   \relative c'' {
958     \key g \major
959     \time 6/8
960     d4 b8 c4 a8 d4 b8 g4
961     g8 a4 b8 c([ b]) a d4 b8 g4.
962   }
963   \addlyrics {
964     Girls and boys come out to play,
965     The moon doth shine as bright as day;
966   }
967 >>
968 @end lilypond
969
970 As an alternative to using slurs, the melismata may be indicated
971 in just the lyrics by using an underscore @code{_} for each note
972 that should be included in the melisma:
973
974 @lilypond[verbatim,quote]
975 <<
976   \relative c'' {
977     \key g \major
978     \time 6/8
979     d4 b8 c4 a8 d4 b8 g4
980     g8 a4 b8 c[ b] a d4 b8 g4.
981   }
982   \addlyrics {
983     Girls and boys come out to play,
984     The moon doth shine _ as bright as day;
985   }
986 >>
987 @end lilypond
988
989 If a syllable extends over several notes or a single very long
990 note an @notation{extender line} is usually drawn from the
991 syllable extending under all the notes for that syllable.  It is
992 entered as two underscores @code{__}.  Here is an example from the
993 first three bars of @notation{Dido's Lament}, from Purcell's
994 @notation{Dido and Ã†neas}:
995
996 @lilypond[verbatim,quote]
997 <<
998   \relative c'' {
999     \key g \minor
1000     \time 3/2
1001     g2 a bes bes( a)
1002     b c4.( bes8 a4. g8 fis4.) g8 fis1
1003   }
1004   \addlyrics {
1005     When I am laid,
1006     am laid __ in earth,
1007   }
1008 >>
1009 @end lilypond
1010
1011 None of the examples so far have involved words containing more
1012 than one syllable.  Such words are usually split one syllable to a
1013 note, with hyphens between syllables.  Such hyphens are entered as
1014 two dashes, resulting in a centered hyphen between the syllables.
1015 Here is an example showing this and everything we have learned so
1016 far about aligning lyrics to notes.
1017
1018 @c no ragged-right here because otherwise the hyphens get lost,
1019 @c but the example is long enough to avoid looking strange.
1020 @lilypond[verbatim,quote,noragged-right]
1021 <<
1022   \relative c' {
1023     \key g \major
1024     \time 3/4
1025     \partial 4
1026     d4 g4 g a8( b) g4 g4
1027     b8( c) d4 d e4 c2
1028   }
1029   \addlyrics {
1030     A -- way in a __ man -- ger,
1031     no __ crib for a bed, __
1032   }
1033 >>
1034 @end lilypond
1035
1036 Some lyrics, especially those in Italian, require the opposite:
1037 setting more than one syllable to a single note.  This is
1038 achieved by linking the syllables together with a single
1039 underscore @code{_} (with no spaces), or enclosing them in quotes.
1040 Here's an example from Rossini's @notation{Figaro}, where
1041 @notation{al} has to be sung on the same note as the @notation{go} of
1042 @notation{Largo} in Figaro's aria @notation{Largo al factotum}:
1043
1044 @c no ragged-right here because otherwise the hyphens get lost,
1045 @c but the example is long enough to avoid looking strange.
1046 @lilypond[verbatim,quote,noragged-right]
1047 <<
1048   \relative c' {
1049     \clef bass
1050     \key c \major
1051     \time 6/8
1052     c4.~ c8 d b c([ d]) b c d b c
1053   }
1054   \addlyrics {
1055     Lar -- go_al fac -- to -- tum del -- la cit -- tà
1056   }
1057 >>
1058 @end lilypond
1059
1060
1061 @seealso
1062 Notation Reference: @ruser{Vocal music}.
1063
1064
1065 @node Lyrics to multiple staves
1066 @subsection Lyrics to multiple staves
1067
1068 @cindex lyrics and multiple staves
1069 @cindex multiple staves and lyrics
1070
1071 The simple approach using @code{\addlyrics} can be used for
1072 placing lyrics under more than one staff.  Here is an
1073 example from Handel's @notation{Judas Maccabæus}:
1074
1075 @lilypond[verbatim,quote]
1076 <<
1077   \relative c'' {
1078     \key f \major
1079     \time 6/8
1080     \partial 8
1081     c8 c([ bes]) a a([ g]) f f'4. b, c4.~ c4
1082   }
1083   \addlyrics {
1084     Let flee -- cy flocks the hills a -- dorn, __
1085   }
1086   \relative c' {
1087     \key f \major
1088     \time 6/8
1089     \partial 8
1090     r8 r4. r4 c8 a'([ g]) f f([ e]) d e([ d]) c bes'4
1091   }
1092   \addlyrics {
1093     Let flee -- cy flocks the hills a -- dorn,
1094   }
1095 >>
1096 @end lilypond
1097
1098 Scores any more complex than this simple example are better
1099 produced by separating out the score structure from the notes and
1100 lyrics with variables.  These are discussed in @ref{Organizing
1101 pieces with variables}.
1102
1103
1104 @seealso
1105 Notation Reference: @ruser{Vocal music}.
1106
1107
1108 @node Final touches
1109 @section Final touches
1110
1111 This is the final section of the tutorial; it demonstrates how to
1112 add the final touches to simple pieces, and provides an
1113 introduction to the rest of the manual.
1114
1115 @menu
1116 * Organizing pieces with variables::
1117 * Version number::
1118 * Adding titles::
1119 * Absolute note names::
1120 * After the tutorial::
1121 @end menu
1122
1123
1124 @node Organizing pieces with variables
1125 @subsection Organizing pieces with variables
1126
1127 @cindex variables
1128 @cindex variables, defining
1129 @cindex identifiers
1130 @cindex macros
1131 @cindex assigning variables
1132 @cindex using variables
1133 @cindex variables, using
1134 @cindex variables, characters allowed in
1135 @cindex characters allowed in variables
1136
1137 When all of the elements discussed earlier are combined to produce
1138 larger files, the music expressions get a lot bigger.  In
1139 polyphonic music with many staves, the input files can become very
1140 confusing.  We can reduce this confusion by using
1141 @emph{variables}.
1142
1143 With variables (also known as identifiers or macros), we can break
1144 up complex music expressions.  A variable is assigned as
1145 follows:
1146
1147 @example
1148 namedMusic = @{ @dots{} @}
1149 @end example
1150
1151 The contents of the music expression @code{namedMusic} can be used
1152 later by placing a backslash in front of the name
1153 (@code{\namedMusic}, just like a normal LilyPond command).
1154
1155 @lilypond[verbatim,quote]
1156 violin = \new Staff {
1157   \relative c'' {
1158     a4 b c b
1159   }
1160 }
1161 cello = \new Staff {
1162   \relative c {
1163     \clef bass
1164     e2 d
1165   }
1166 }
1167 {
1168   <<
1169     \violin
1170     \cello
1171   >>
1172 }
1173 @end lilypond
1174
1175 @noindent
1176 The name of a variable must have alphabetic characters only, no
1177 numbers, underscores, or dashes.
1178
1179 Variables must be defined @emph{before} the main music
1180 expression, but may be used as many times as required anywhere after
1181 they have been defined.  They may even be used in a later definition
1182 of another variable, giving a way of shortening the input if a
1183 section of music is repeated many times.
1184
1185 @lilypond[verbatim,quote]
1186 tripletA = \times 2/3 { c,8 e g }
1187 barA = { \tripletA \tripletA \tripletA \tripletA }
1188
1189 \relative c'' {
1190  \barA \barA
1191 }
1192 @end lilypond
1193
1194 Variables may be used for many other types of objects in
1195 the input.  For example,
1196
1197 @example
1198 width = 4.5\cm
1199 name = "Wendy"
1200 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1201 @end example
1202
1203 Depending on its contents, the variable can be used in different
1204 places.  The following example uses the above variables:
1205
1206 @example
1207 \paper @{
1208   \aFivePaper
1209   line-width = \width
1210 @}
1211 @{
1212   c4^\name
1213 @}
1214 @end example
1215
1216
1217 @node Version number
1218 @subsection Version number
1219
1220 @cindex versioning
1221 @cindex version
1222 @cindex version number
1223 @cindex upgrades
1224 @cindex future upgrades
1225 @cindex updating files
1226 @cindex files, updating
1227
1228 @funindex \version
1229 @funindex version
1230 @funindex convert-ly
1231
1232 The @code{\version} statement records the version of LilyPond that
1233 was used to write the file:
1234
1235 @example
1236 \version @w{"@version{}"}
1237 @end example
1238
1239 @noindent
1240 By convention, this is placed at the top of your LilyPond file.
1241
1242 These annotations make future upgrades of LilyPond go more
1243 smoothly.  Changes in the syntax are handled with a special
1244 program, @command{convert-ly}, and it uses @code{\version} to
1245 determine what rules to apply.  For details, see
1246 @rprogram{Updating files with convert-ly}.
1247
1248
1249 @node Adding titles
1250 @subsection Adding titles
1251
1252 @cindex title
1253 @cindex headers
1254 @cindex header block
1255
1256 @funindex \header
1257 @funindex header
1258
1259 The title, composer, opus number, and similar information are
1260 entered in the @code{\header} block.  This exists outside of the
1261 main music expression; the @code{\header} block is usually placed
1262 underneath the version number.
1263
1264 @example
1265 \version @w{"@version{}"}
1266 \header @{
1267   title = "Symphony"
1268   composer = "Me"
1269   opus = "Op. 9"
1270 @}
1271
1272 @{
1273   @dots{} music @dots{}
1274 @}
1275 @end example
1276
1277 When the file is processed, the title and composer are printed
1278 above the music.  More information on titling can be found in
1279 @ruser{Creating titles}.
1280
1281
1282 @node Absolute note names
1283 @subsection Absolute note names
1284
1285 @cindex note names
1286 @cindex note names, absolute
1287 @cindex absolute mode
1288 @cindex absolute values for pitches
1289 @cindex pitches, absolute values
1290 @cindex absolute note names
1291
1292 So far we have always used @code{\relative} to define pitches.
1293 This is the easiest way to enter most music, but another way of
1294 defining pitches exists: absolute mode.
1295
1296 If you omit the @code{\relative}, LilyPond treats all pitches as
1297 absolute values.  A @code{c'} will always mean middle C, a
1298 @code{b} will always mean the note one step below middle C, and a
1299 @code{g,} will always mean the note on the bottom staff of the
1300 bass clef.
1301
1302 @lilypond[verbatim,quote]
1303 {
1304   \clef bass
1305   c' b g, g,
1306   g, f, f c'
1307 }
1308 @end lilypond
1309
1310 Here is a four-octave scale:
1311
1312 @lilypond[verbatim,quote]
1313 {
1314   \clef bass
1315   c, d, e, f,
1316   g, a, b, c
1317   d e f g
1318   a b c' d'
1319   \clef treble
1320   e' f' g' a'
1321   b' c'' d'' e''
1322   f'' g'' a'' b''
1323   c'''1
1324 }
1325 @end lilypond
1326
1327 As you can see, writing a melody in the treble clef involves a lot
1328 of quote @code{'} marks.  Consider this fragment from Mozart:
1329
1330 @lilypond[verbatim,quote]
1331 {
1332   \key a \major
1333   \time 6/8
1334   cis''8. d''16 cis''8 e''4 e''8
1335   b'8. cis''16 b'8 d''4 d''8
1336 }
1337 @end lilypond
1338
1339 All these quotes makes the input less readable and they are a source
1340 of errors.  With @code{\relative}, the previous example is much
1341 easier to read and type:
1342
1343 @lilypond[verbatim,quote]
1344 \relative c'' {
1345   \key a \major
1346   \time 6/8
1347   cis8. d16 cis8 e4 e8
1348   b8. cis16 b8 d4 d8
1349 }
1350 @end lilypond
1351
1352 If you make a mistake with an octave mark (@code{'} or @code{,})
1353 while working in @code{\relative} mode, it is very obvious -- many
1354 notes will be in the wrong octave.  When working in absolute mode,
1355 a single mistake will not be as visible, and will not be as easy
1356 to find.
1357
1358 However, absolute mode is useful for music which has large
1359 intervals, and is extremely useful for computer-generated LilyPond
1360 files.
1361
1362
1363
1364 @node After the tutorial
1365 @subsection After the tutorial
1366
1367 After finishing the tutorial, you should probably try writing a
1368 piece or two.  Start by adding notes to one of the
1369 @ref{Templates}.  If you need any notation that was not covered in
1370 the tutorial, look at the Notation Reference, starting with
1371 @ruser{Musical notation}.  If you want to write for an instrument
1372 ensemble that is not covered in the templates, take a look at
1373 @ref{Extending the templates}.
1374
1375 Once you have written a few short pieces, read the rest of the
1376 Learning Manual (chapters 3-5).  There's nothing wrong with
1377 reading it now, of course!  However, the rest of the Learning
1378 Manual assumes that you are familiar with LilyPond input.  You may
1379 wish to skim these chapters right now, and come back to them after
1380 you have more experience.
1381
1382 In this tutorial and in the rest of the Learning Manual, there is a
1383 paragraph @strong{See also} at the end of each section, which contains
1384 cross-references to other sections: you should not follow these
1385 cross-references at first reading; when you have read all of the
1386 Learning Manual, you may want to read some sections again and follow
1387 cross-references for further reading.
1388
1389 If you have not done so already, @emph{please} read
1390 FIXME FIXME FIXME @c @ref{About the documentation}.
1391 There is a lot of information about LilyPond, so
1392 newcomers often do not know where they should look for help.  If
1393 you spend five minutes reading that section carefully, you might
1394 save yourself hours of frustration looking in the wrong places!
1395