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