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