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