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