]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
18a56224450bb1975fa8bd8ece8c5e045caede62
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @c  Tutorial guidelines:
11 @c    - unless you have a really good reason, use
12 @c      @lilypond[quote,ragged-right,verbatim]
13 @c      (i.e. no fragment or relative in the header.)
14
15
16 @c   old info that will probably be removed.
17 @c TODO:
18 @c   * more details about running lilypond; error messages,
19 @c     compiling/viewing (emacs?)
20 @c   * where to go from First steps+More basics?
21
22 @c  wherever possible, do not include index entries here; the
23 @c  index should point to stuff in the reference manual.  -gp
24
25 @c Your first LilyPond score in 10 minutes?
26
27 @node Tutorial
28 @chapter Tutorial
29
30 This tutorial starts with an introduction to the LilyPond music
31 language and how to produce printed music.  After this first contact we
32 will explain how to create common musical notation.
33
34 @ifhtml
35 Many people learn programs by trying and fiddling around with the
36 program.  This is also possible with LilyPond.  If you click on a
37 picture in the HTML version of this manual, you will see the exact
38 LilyPond input that was used to generate that image.
39 Try it on this image
40
41 @lilypond[fragment,quote,ragged-right,relative=2]
42 c-\markup { \bold \huge { Click here.  } }
43 @end lilypond
44 @end ifhtml
45
46 By cutting and pasting everything from the @qq{Start cut-&-pastable-section},
47 to the end of the file, you have a
48 starting template for experiments.  If you like learning in this way,
49 you will probably want to print out or bookmark
50 @ifhtml
51 the
52 @end ifhtml
53 @ref{Cheat sheet}, which is a table listing of the most common
54 commands for quick reference.
55
56 @menu
57 * First steps (compiling a file)::  
58 * Simple notation::             
59 * Working on text files::       
60 * Accidentals and key signatures::  
61 * Entering ties::               
62 * Automatic and manual beams::  
63 * Octave entry::                
64 * Music expressions explained::  
65 * More staves::                 
66 * Adding articulation marks to notes::  
67 * Combining notes into chords::  
68 * Advanced rhythmic commands::  
69 * Commenting input files::      
70 * Printing lyrics::             
71 * A lead sheet::                
72 * Adding titles::               
73 * Single staff polyphony::      
74 * Piano staves::                
75 * Organizing larger pieces::    
76 * An orchestral part::          
77 * After the tutorial::          
78 @end menu
79
80
81 @node First steps (compiling a file)
82 @section First steps (compiling a file)
83
84 The first example demonstrates how to start working with LilyPond.  To
85 create sheet music, we write a text file that specifies the
86 notation.  For example, if we write
87
88 @example
89 @{
90   c' e' g' e'
91 @}
92 @end example
93
94 @noindent
95 the result looks like this
96
97 @lilypond[quote,ragged-right]
98 {
99   c' e' g' e'
100 }
101 @end lilypond
102
103 @strong{Warning:} Every piece of LilyPond input needs to have @strong{@{ curly
104 braces @}} placed around the input.  The braces should be also be
105 surrounded by a space unless they are at the beginning or end of a
106 line to avoid ambiguities.  These may be omitted in some examples in this
107 manual, but don't forget them in your own music!
108
109 @cindex Case sensitive
110 In addition, LilyPond input is @strong{case sensitive}.  @code{ @{ c d e @} }
111 is valid input; @code{ @{ C D E @} } will produce an error message.
112
113 @sp 1
114
115 @unnumberedsubsec Entering music and viewing output
116
117 In this section we will explain what commands to run
118 and how to view or print the output.
119
120 @unnumberedsubsubsec MacOS X
121
122 If you double click LilyPond.app, it will open with an example
123 file. Save it, for example, to @file{test.ly} on your Desktop, and
124 then process it with the menu command @samp{Compile > Typeset File}.
125 The resulting PDF file will be displayed on your screen.
126
127 Be warned that the first time you ever run lilypond will take a minute
128 or two because all of the system fonts have to be analyzed first.
129
130 For future use of LilyPond, you should begin by selecting "New"
131 or "Open".
132
133 @unnumberedsubsubsec Windows
134
135 On Windows, start up a text-editor@footnote{Any simple or
136 programmer-oriented editor with UTF-8 support will do, for example
137 Notepad.  Do not use a word processor, since these insert formatting
138 codes that will confuse LilyPond.} and enter
139
140 @verbatim
141 {
142   c' e' g' e'
143 }
144 @end verbatim
145
146 Save it on the desktop as @file{test.ly} and make sure that it is not
147 called @file{test.ly.TXT}.  Double clicking @file{test.ly} will process
148 the file and show the resulting PDF file.
149
150
151 @unnumberedsubsubsec Unix
152
153 Begin by opening a terminal window and starting a text editor.  For
154 example, you could open an xterm and execute
155 @code{joe}@footnote{There are macro files for VIM addicts, and there
156 is a @code{LilyPond-mode} for Emacs addicts.  If they have not been
157 installed already, refer to the file @file{INSTALL.txt}.  These
158 easiest editing environment is @file{LilyPondTool}.  See
159 @ref{Editor support} for more information.}.  In your
160 text editor, enter the following input and save the file as
161 @file{test.ly}
162
163 @verbatim
164 {
165   c' e' g' e'
166 }
167 @end verbatim
168
169 @noindent
170 To process @file{test.ly}, proceed as follows
171
172 @example
173 lilypond test.ly
174 @end example
175
176 @noindent
177 You will see something resembling
178
179 @example
180 lilypond test.ly
181 GNU LilyPond 2.10.0
182 Processing `test.ly'
183 Parsing...
184 Interpreting music... [1]
185 Preprocessing graphical objects...
186 Calculating line breaks... [2]
187 Layout output to `test.ps'...
188 Converting to `test.pdf'...
189 @end example
190
191 @cindex PDF file
192 @cindex Viewing music
193
194 @noindent
195 The result is the file @file{test.pdf} which you can print or view
196 with the standard facilities of your operating system.@footnote{If
197 your system does not have any tools installed, you can try
198 @uref{http://@/www@/.cs@/.wisc@/.edu/@/~ghost/,Ghostscript}, a freely
199 available package for viewing and printing PDF and PostScript files.}
200
201
202 @node Simple notation
203 @section Simple notation
204
205 LilyPond will add some notation elements automatically.  In the next
206 example, we have only specified four pitches, but LilyPond has
207 added a clef, time signature, and rhythms.
208
209 @lilypond[quote,ragged-right,verbatim]
210 {
211   c' e' g' e'
212 }
213 @end lilypond
214
215 @noindent
216 This behavior may be altered, but in most cases these automatic values
217 are useful.
218
219
220 @unnumberedsubsec Pitches
221
222 The easiest way to enter notes is by using @code{\relative} mode.  In
223 this mode, the @rglos{interval} between the previous note and the
224 current note is assumed to be within a @rglos{fourth}.  We begin by
225 entering the most elementary piece of music, a @rglos{scale}.
226
227 @lilypond[quote,ragged-right,verbatim]
228 \relative c' {
229   c d e f
230   g a b c
231 }
232 @end lilypond
233
234 The initial note is @rglos{middle C}.  Each successive note
235 is within a fourth of the previous note -- in other words, the first
236 @samp{c} is the closest C to middle C.  This is followed by the closest
237 D to the previous note.  We can create melodies which have larger intervals:
238
239 @lilypond[quote,ragged-right,verbatim]
240 \relative c' {
241   d f a g
242   c b f d
243 }
244 @end lilypond
245
246 @noindent
247 As you may notice, this example does not start on middle C.  The first
248 note -- the @samp{d} -- is the closest D to middle C.
249
250 To add intervals that are larger than a fourth, we can raise the octave
251 by adding a single quote @code{'} (or apostrophe) to the note name.  We can
252 lower the octave by adding a comma @code{,} to the note name.
253
254 @lilypond[quote,ragged-right,verbatim]
255 \relative c'' {
256   a a, c' f,
257   g g'' a,, f'
258 }
259 @end lilypond
260
261 @noindent
262 To change a note by two (or more!) octaves, we use multiple @code{''} or
263 @code{,,} -- but be careful that you use two single quotes @code{''} and
264 not one double quote @code{"}@tie{}!  The initial value in
265 @code{\relative c'} may also be modified like this.
266
267
268 @unnumberedsubsec Durations (rhythms)
269
270 The @rglos{duration} of a note is specified by a number after the note
271 name.  @samp{1} for a @rglos{whole note}, @samp{2} for a @rglos{half note},
272 @samp{4} for a @rglos{quarter note} and so on.  Beams are added
273 automatically.
274
275 @lilypond[quote,ragged-right,verbatim]
276 \relative c'' {
277   a1
278   a2 a4 a8 a
279   a16 a a a a32 a a a a64 a a a a a a a a2
280 }
281 @end lilypond
282
283 @noindent
284 If you do not specify a duration, the previous duration is used
285 for the next note.  The duration of the first note defaults to a quarter.
286
287 To create @rglos{dotted notes}, add a dot @samp{.} to the duration number.
288
289 @lilypond[quote,ragged-right,verbatim]
290 \relative c'' {
291   a a a4. a8
292   a8. a16 a a8. a8 a4.
293 }
294 @end lilypond
295
296
297 @unnumberedsubsec Rests
298
299 A @rglos{rest} is entered just like a note with the name @samp{r}:
300
301 @lilypond[quote,ragged-right,verbatim]
302 \relative c'' {
303   a r r2
304   r8 a r4 r4. r8
305 }
306 @end lilypond
307
308
309 @unnumberedsubsec Time signature
310
311 The @rglos{time signature}) can be set with the @code{\time} command:
312
313 @lilypond[quote,ragged-right,verbatim]
314 \relative c'' {
315   \time 3/4
316   a4 a a
317   \time 6/8
318   a4. a
319   \time 4/4
320   a4 a a a
321 }
322 @end lilypond
323
324
325 @unnumberedsubsec Clef
326
327 The @rglos{clef} can be set using the @code{\clef} command:
328
329 @lilypond[quote,ragged-right,verbatim]
330 \relative c' {
331   \clef treble
332   c1
333   \clef alto
334         c1
335   \clef tenor
336   c1
337   \clef bass
338   c1
339 }
340 @end lilypond
341
342
343 @unnumberedsubsec All together
344
345 Here is a small example showing all these elements together:
346
347 @lilypond[quote,ragged-right,verbatim]
348 \relative c, {
349   \time 3/4
350   \clef bass
351   c2 e8 c' g'2.
352   f4 e d c4 c, r4
353 }
354 @end lilypond
355
356 @c  I don't think these are useful, but I haven't completely made
357 @c  up my mind whether to completely remove them or not.
358 @ignore
359 For more information on
360
361 @q uotation
362 @t able @a sis
363 @i tem Entering pitches and durations
364 see
365 @r ef{Pitches}, and @r ef{Durations}.
366 @i tem Clefs
367 see @r ef{Clef}.
368 @i tem Rests
369 see @r ef{Rests}.
370 @i tem Time signatures and other timing commands
371 see @r ef{Time signature}.
372 @e nd table
373 @e nd quotation
374 @end ignore
375
376
377 @node Working on text files
378 @section Working on text files
379
380 LilyPond input files are treated like files in most programming languages:
381 they are case sensitive, white-space insensitive, and expressions are
382 formed with curly braces @{ @}.
383
384 If the previous sentence sounds like nonsense, don't worry!  We'll explain
385 what all these terms mean:
386
387 @itemize
388
389 @cindex Case sensitive
390 @item @strong{Case sensitive}:
391 it matters whether you enter a letter
392 in lower case (i.e. @code{a, b, s, t}) or upper case (i.e.
393 @code{A, B, S, T}).  Notes are lower case: @code{ @{ c d e @} }
394 is valid input; @code{ @{ C D E @} } will produce an error message.
395
396 @item @strong{Whitespace insensitive}:
397 it does not matter how many
398 spaces (or new lines) you add.  @code{ @{ c d e @}} means the same thing
399 as @code{ @{ c @ @ @ @ @  d e @} } and
400 @example
401           @{
402 c                        d
403   e @}
404 @end example
405
406 @noindent
407 Of course, the previous example is hard to read.  A good rule of thumb
408 is to indent code blocks with either a tab or two spaces:
409 @example
410 @{
411   c d e
412 @}
413 @end example
414
415 @item @strong{Expressions:}
416 Every piece of LilyPond input needs to have
417 @strong{@{ curly braces @}} placed around the input.  These braces tell
418 LilyPond that the input is a single music expression, just like(
419 parenthesis @samp{()} in mathematics.  The braces should
420 be surrounded by a space unless they are at the beginning or end of a
421 line to avoid ambiguities.  For the rest of this manual, most examples
422 will omit these braces@footnote{Why omit the braces?  Most examples
423 in this manual can be inserted into the middle of a longer piece of
424 msuic.  For these examples, it does not make sense to add @{ @}.},
425 but don't forget them in your own music!
426
427 @end itemize
428
429 @c  End of current re-write; more material coming in a few days.  -gp
430
431 @node Accidentals and key signatures
432 @section Accidentals and key signatures
433
434 @unnumberedsubsec Accidentals
435
436 A @rglos{sharp} pitch is made by adding @samp{is} to
437 the name, and a @rglos{flat} pitch by adding @samp{es}.  As
438 you might expect, a @rglos{double sharp} or @rglos{double flat} is
439 made by adding @samp{isis} or @samp{eses}@footnote{This syntax
440 derived from note naming conventions in Nordic and Germanic languages,
441 like German and Dutch.  To use other names for accidentals, see
442 @ref{Note names in other languages}.}
443
444 @lilypond[quote,ragged-right,verbatim]
445 \relative c'' {
446   cis1 ees fisis, aeses
447 }
448 @end lilypond
449
450 @cindex key signature, setting
451 @unnumberedsubsec Key signatures
452
453 The key signature is set with the command @code{\key} followed by
454 a pitch and @code{\major} or @code{\minor}.
455
456 @lilypond[quote,ragged-right,verbatim]
457 \relative c'' {
458   \key d \major
459   a1
460   \key c \minor
461   a
462 }
463 @end lilypond
464
465 @sp 1
466
467 @unnumberedsubsec Warning: key signatures and pitches
468
469 To determine whether to print an accidental, LilyPond examines the
470 pitches and the key signature.  The key signature only effects
471 the @emph{printed} accidentals, not the actual pitches!  This is a
472 feature that often causes confusion to newcomers, so let us explain it
473 in more detail.
474
475 LilyPond makes a sharp distinction between musical content and
476 layout.  The alteration (flat, natural or sharp) of a note is part of
477 the pitch, and is therefore musical content.  Whether an accidental (a
478 @emph{printed} flat, natural or sharp sign) is printed in front of the
479 corresponding note is a question of layout.  Layout is something that
480 follows rules, so accidentals are printed automatically according to
481 those rules.  The pitches in your music are works of art, so they will
482 not be added automatically, and you must enter what you want to hear.
483
484 In this example
485
486 @lilypond[quote,ragged-right,verbatim]
487 \relative c' {
488   \key d \major
489   d cis fis
490 }
491 @end lilypond
492
493 @noindent
494 no note has a printed accidental, but you must still add the @code{-is} to
495 @code{cis} and @code{fis}.
496
497 The code @samp{d} does not mean @qq{print a black dot just below the
498 staff.}  Rather, it means: @qq{a note with pitch D-natural.}  In the key
499 of A-flat major, it @emph{does} get an accidental
500
501 @lilypond[quote,ragged-right,verbatim]
502 \relative c' {
503   \key as \major
504   d
505 }
506 @end lilypond
507
508 Adding all alterations explicitly might require a little more effort
509 when typing, but the advantage is that transposing is easier, and
510 accidentals can be printed according to different conventions.  See
511 @ref{Automatic accidentals}, for some examples how accidentals can be printed
512 according to different rules.
513
514 @c zzz
515
516 @ignore
517 For more information on
518
519 @q uotation
520 @t able @a sis
521 @i tem Accidentals
522 see @r ef{Automatic accidentals}.
523
524 @i tem Key signature
525 see @r ef{Key signature}.
526 @e nd table
527 @e nd quotation
528 @end ignore
529
530
531 @node Entering ties
532 @section Entering ties
533
534 @cindex tie
535 A @rglos{tie} is created by appending a tilde @samp{~} to the first
536 note being tied
537
538 @lilypond[quote,notime,fragment,verbatim,relative=3]
539 g4~ g a2~ a4
540 @end lilypond
541
542 For more information on Ties see @ref{Ties}.
543
544
545
546 @node Automatic and manual beams
547 @section Automatic and manual beams
548
549 @cindex beams, by hand
550 All @rglos{beam}s are drawn automatically
551
552 @lilypond[quote,fragment,relative=2,verbatim]
553 a8 ais d es r d
554 @end lilypond
555
556 @noindent
557 If you do not like where beams are put, they can be entered by
558 hand.  Mark the first note to be beamed with @samp{[} and the last one
559 with @samp{]}.
560
561 @lilypond[quote,fragment,relative=2,verbatim]
562 a8[ ais] d[ es r d]
563 @end lilypond
564
565 For more information on beams, see @ref{Manual beams}.
566
567
568 Here are key signatures, accidentals and ties in action
569
570 @lilypond[fragment,quote,noindent,line-width=50\staff-space,verbatim]
571 \relative c'' {
572   \time 4/4
573   \key g \minor
574   \clef treble
575   r4 r8 a8 gis4 b
576   a8 d4.~ d e,8
577   fis4 fis8 fis8 eis4 a8 gis~
578   gis2 r2
579 }
580 @end lilypond
581
582 @cindex accidentals
583
584
585 @noindent
586 There are some interesting points to note in this example.  Bar lines
587 and beams are drawn automatically.  Line breaks are calculated
588 automatically; it does not matter where the line breaks are in the
589 source file.  Finally, the order in which time, key, and clef changes
590 are entered is not relevant: in the printout, these are ordered
591 according to standard notation conventions.
592
593
594
595 @node Octave entry
596 @section Octave entry
597
598
599 @c Tim wants to move this quotes example just before the: quotes-do not-work
600 @c score, but we'd need to remove quotes from the other two (key and
601 @c tie) examples...
602
603 @c better to have this just before the `octaves are bad' snipped
604 @c but we'd need to remove the ', from \key and tie
605 To raise a note by an octave, add a high quote @samp{'} (apostrophe) to
606 the note name, to lower a note one octave, add a @q{low quote} @samp{,}
607 (comma).  Middle C is @code{c'}
608
609 @lilypond[quote,notime,fragment,verbatim]
610 c'4 c'' c''' \clef bass c c,
611 @end lilypond
612
613 An example of the use of quotes is in the following Mozart fragment
614
615 @lilypond[quote,ragged-right,fragment,verbatim]
616 \key a \major
617 \time 6/8
618 cis''8. d''16 cis''8 e''4 e''8
619 b'8. cis''16 b'8 d''4 d''8
620 @end lilypond
621
622 @noindent
623 This example shows that music in a high register needs lots of quotes.
624 This makes the input less readable, and it is a source of errors.  The
625 solution is to use @q{relative octave} mode.   This is the
626 most convenient way to copy existing music.
627
628 In relative mode, a note without octavation quotes (i.e., the @samp{'}
629 or @samp{,} after a note) is chosen so that it is closest to the
630 previous one.  For example, @samp{c f} goes up while @samp{c g} goes
631 down.
632
633 To use relative mode, add @code{\relative} before the piece of
634 music.  The first note is taken relative to the middle C
635 @c no , for this sentence
636 (i.e., @code{c'})
637
638
639
640 @lilypond[quote,notime,fragment,verbatim]
641 \relative {
642   c' f c g c
643 }
644 @end lilypond
645
646
647 Since most music has small intervals, pieces can be written almost
648 without octavation quotes in relative mode.  The previous example is
649 entered as
650
651 @lilypond[quote,ragged-right,verbatim]
652 \relative {
653   \key a \major
654   \time 6/8
655   cis'8. d16 cis8 e4 e8
656   b8. cis16 b8 d4 d8
657 }
658 @end lilypond
659
660 @c needed better, maybe even redundant explanation
661 @c   added another example below.
662 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
663 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
664 Larger intervals are made by adding octavation quotes.
665
666 @lilypond[quote,notime,verbatim,fragment]
667 \relative c {
668   c'' f, f c' c g' c,
669 }
670 @end lilypond
671
672 In summary, quotes or commas no longer determine the absolute height
673 of a note in @code{\relative} mode.  Rather, the height of a note is
674 relative to the previous one, and changing the octave of a single note
675 shifts all following notes an octave up or down.
676
677 For more information on relative octaves see @ref{Relative octaves},
678 and @ref{Octave check}.
679
680
681 @node Music expressions explained
682 @section Music expressions explained
683
684
685 In input files, music is represent by so-called @emph{music
686 expression}s.  We have already seen some in the previous examples;
687 a single note is a music expression
688
689 @lilypond[fragment,quote,verbatim,relative=3]
690 a4
691 @end lilypond
692
693 Enclosing a group of notes in braces creates a new music
694 expression
695
696 @lilypond[fragment,quote,verbatim,relative=3]
697 { a4 g4 }
698 @end lilypond
699
700 Putting a bunch of music expressions (e.g., notes) in braces, means that
701 they should be played in sequence.  The result again is a music
702 expression, which can be grouped with other expressions sequentially.
703 Here, the expression from the previous example is combined with two
704 notes
705
706 @lilypond[fragment,quote,verbatim,relative=3]
707 { { a4 g } f g }
708 @end lilypond
709
710 This technique is useful for non-monophonic music.  To enter music
711 with more voices or more staves, we also combine expressions in
712 parallel.  Two voices that should play at the same time, are entered
713 as a simultaneous combination of two sequences.  A @q{simultaneous}
714 music expression is formed by enclosing expressions in @code{<<} and
715 @code{>>}.  In the following example, three sequences (all containing
716 two separate notes) are combined simultaneously
717
718 @lilypond[fragment,quote,verbatim,relative=3]
719 <<
720   { a4 g }
721   { f e }
722   { d b }
723 >>
724 @end lilypond
725
726 This mechanism is similar to mathematical
727 formulas: a big formula is created by composing small formulas.  Such
728 formulas are called expressions, and their definition is recursive, so
729 you can make arbitrarily complex and large expressions.  For example,
730
731 @example
732 1
733
734 1 + 2
735
736 (1 + 2) * 3
737
738 ((1 + 2) * 3) / (4 * 5)
739 @end example
740
741 @cindex expression
742 @cindex music expression
743 This is a sequence of expressions, where each expression is contained
744 in the next (larger) one.  The simplest expressions are numbers, and larger
745 ones are made by combining expressions with operators (like @samp{+},
746 @samp{*} and @samp{/}) and parentheses.  Like mathematical expressions,
747 music expressions can be nested arbitrarily deep, which is necessary
748 for complex music like polyphonic scores.
749
750 Note that this example only has one staff, whereas
751 the previous example had three separate staves.  That is because this
752 example begins with a single note.  To determine the number of staves,
753 LilyPond looks at the first element.  If it is a single note, there is one
754 staff; if there is a simultaneous expression, there is more than one staff.
755
756 @lilypond[fragment,quote,verbatim,relative=2]
757 {
758   c <<c e>>
759   << { e f } { c <<b d>> } >>
760 }
761 @end lilypond
762
763 Music files with deep nesting can be confusing to enter and
764 maintain.  One convention that helps against this confusion is
765 indenting.  When entering a file with deep nesting of braces and
766 angles, it is customary to use an indent that indicates the nesting
767 level.  Formatting music like this eases reading and helps you insert
768 the right number of closing braces at the end of an expression.  For
769 example,
770
771 @example
772 <<
773   @{
774     @dots{}
775   @}
776   @{
777     @dots{}
778   @}
779 >>
780 @end example
781
782 Some editors have special support for entering LilyPond, and can help
783 indenting source files.  See @ref{Editor support} for more information.
784
785 @node More staves
786 @section More staves
787
788 To print more than one staff, each piece of music that makes up a
789 staff is marked by adding @code{\new Staff} before it.  These
790 @code{Staff} elements are then combined in parallel with @code{<<} and
791 @code{>>}, as demonstrated here
792
793 @lilypond[quote,fragment,verbatim]
794 <<
795   \new Staff { \clef treble c'' }
796   \new Staff { \clef bass c }
797 >>
798 @end lilypond
799
800
801 The command @code{\new} introduces a @q{notation context.}  A notation
802 context is an environment in which musical events (like notes or
803 @code{\clef} commands) are interpreted.  For simple pieces, such
804 notation contexts are created automatically.  For more complex pieces, it
805 is best to mark contexts explicitly.  This ensures that each fragment
806 gets its own stave.
807
808 There are several types of contexts.  @code{Staff}, @code{Voice} and
809 @code{Score} handle melodic notation, while @code{Lyrics} sets lyric
810 texts and @code{ChordNames} prints chord names.
811
812 In terms of syntax, prepending @code{\new} to a music expression
813 creates a bigger music expression.  In this way it resembles the minus
814 sign in mathematics.  The formula @math{(4+5)} is an expression, so
815 @math{-(4+5)} is a bigger expression.
816
817 We can now typeset a melody with two staves
818
819 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
820
821 @lilypond[fragment,quote,verbatim,ragged-right]
822 \relative <<
823   \new Staff {
824     \time 3/4
825     \clef treble
826
827     e'2 d4 c2 b4 a8[ a]
828     b[ b] g[ g] a2.
829   }
830   \new Staff {
831      \clef bass
832      c,,2 e4 g2.
833      f4 e d c2.
834   }
835 >>
836 @end lilypond
837
838 For more information on contexts see the description in
839 @ref{Interpretation contexts}.
840
841
842
843 @node Adding articulation marks to notes
844 @section Adding articulation marks to notes
845
846 @cindex articulation
847 @cindex accents
848 @cindex staccato
849
850 Common accents can be added to a note using a dash (@samp{-}) and a
851 single character
852
853 @lilypond[fragment,quote,verbatim,relative=2]
854 c-.  c-- c-> c-^ c-+ c-_
855 @end lilypond
856
857 @cindex fingering
858 Similarly, fingering indications can be added to a note using a dash
859 (@samp{-}) and the digit to be printed
860
861 @lilypond[fragment,quote,verbatim,relative=2]
862 c-3 e-5 b-2 a-1
863 @end lilypond
864
865 Articulations and fingerings are usually placed automatically, but you
866 can specify a direction using @samp{^} (up) or @samp{_} (down).  You can
867 also use multiple articulations on the same note.  In most cases, however,
868 it is best to let LilyPond determine the articulation directions.
869
870 @lilypond[fragment,quote,verbatim,relative=2]
871 c_-^1 d^. f^4_2-> e^-_+
872 @end lilypond
873
874 Dynamic signs are made by adding the markings (with a backslash) to
875 the note
876
877 @lilypond[fragment,quote,verbatim,relative=2]
878 c\ff c\mf
879 @end lilypond
880
881 @cindex dynamics
882 @cindex decrescendo
883 @cindex crescendo
884
885 Crescendi and decrescendi are started with the commands @code{\<} and
886 @code{\>}.  An ending dynamic, for example @code{\f}, will finish the
887 (de)crescendo, or the command @code{\!} can be used
888
889 @lilypond[fragment,quote,verbatim,relative=2]
890 c2\< c2\ff\> c2 c2\!
891 @end lilypond
892
893
894
895 @cindex slur
896
897 A @rglos{slur} is a curve drawn across many notes, and indicates
898 legato articulation.  The starting note and ending note are marked
899 with @samp{(} and @samp{)}, respectively
900
901 @lilypond[fragment,quote,fragment,relative=2,verbatim]
902 d4( c16) cis( d e c cis d) e( d4)
903 @end lilypond
904
905 @cindex slurs versus ties
906 A slur looks like a @rglos{tie}, but it has a different meaning.  A
907 tie simply makes the first note sound longer, and can only be used on
908 pairs of notes with the same pitch.  Slurs indicate the articulations
909 of notes, and can be used on larger groups of notes.  Slurs and ties
910 can be nested
911
912 @lilypond[quote,fragment,relative=2]
913 c2~( c8 fis fis4 ~ fis2 g2)
914 @end lilypond
915
916 @cindex phrasing slurs
917 Slurs to indicate phrasing can be entered with @code{\(} and
918 @code{\)}, so you can have both legato slurs and phrasing slurs at the
919 same time.  You cannot have simultaneous slurs or simultaneous
920 phrasing slurs.
921
922 @lilypond[quote,fragment,relative=2,verbatim]
923 a8(\( ais b c) cis2 b'2 a4 cis, c\)
924 @end lilypond
925
926
927 For more information on
928
929 @quotation
930 @table @asis
931 @item Fingering
932 see @ref{Fingering instructions}.
933 @item Articulations
934 see @ref{Articulations}.
935 @item Slurs
936 see @ref{Slurs}.
937 @item Phrasing slurs
938 see @ref{Phrasing slurs}.
939 @item Dynamics
940 see @ref{Dynamics}.
941 @end table
942 @end quotation
943
944
945 @node Combining notes into chords
946 @section Combining notes into chords
947
948 @cindex chords
949 Chords can be made by surrounding pitches with angle brackets.
950 Angle brackets are the symbols @samp{<} and @samp{>}.
951
952 @lilypond[quote,relative=1,fragment,verbatim]
953 r4 <c e g>4 <c f a>8
954 @end lilypond
955
956
957 You can combine markings like beams and ties with chords.  They must
958 be placed outside the angled brackets
959
960 @lilypond[quote,relative=1,fragment,verbatim]
961 r4 <c e g>8[ <c f a>]~ <c f a>
962 @end lilypond
963
964 @example
965 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
966 @end example
967
968 @lilypond[quote,relative=1,fragment]
969 \slurUp
970 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
971 @end lilypond
972
973
974 @node Advanced rhythmic commands
975 @section Advanced rhythmic commands
976
977 @cindex pickup
978 @cindex anacruse
979 @cindex partial measure
980 A pickup is entered with the keyword @code{\partial}.  It
981 is followed by a duration: @code{\partial 4} is a quarter note upstep
982 and @code{\partial 8} an eighth note
983
984 @lilypond[quote,relative=2,verbatim,fragment]
985 \partial 8
986 f8 c2 d e
987 @end lilypond
988
989 @cindex tuplets
990 @cindex triplets
991 Tuplets are made with the @code{\times} keyword.  It takes two
992 arguments: a fraction and a piece of music.  The duration of the piece
993 of music is multiplied by the fraction.  Triplets make notes occupy
994 2/3 of their notated duration, so a triplet has 2/3 as its fraction
995
996 @lilypond[quote,relative=1,verbatim,fragment]
997 \times 2/3 { f8 g a }
998 \times 2/3 { c r c }
999 @end lilypond
1000
1001 @cindex grace notes
1002 @cindex acciaccatura
1003 Grace notes are also made by prefixing a music expression with the
1004 keyword @code{\appoggiatura} or @code{\acciaccatura}
1005 @cindex appoggiatura
1006 @cindex acciaccatura
1007
1008 @lilypond[quote,relative=2,verbatim,fragment]
1009 c4 \appoggiatura b16 c4
1010 c4 \acciaccatura b16 c4
1011 @end lilypond
1012
1013 @noindent
1014
1015 For more information on
1016
1017 @quotation
1018 @table @asis
1019 @item Grace notes
1020 see @ref{Grace notes},
1021 @item Tuplets
1022 see @ref{Tuplets},
1023 @item Pickups
1024 see @ref{Partial measures}.
1025 @end table
1026 @end quotation
1027
1028
1029 @node Commenting input files
1030 @section Commenting input files
1031
1032 @cindex comments
1033 @cindex line comment
1034 @cindex block comment
1035 A comment is a remark for the human reader of the music input; it is
1036 ignored while parsing, so it has no effect on the printed output.
1037 There are two types of comments.  The percent symbol @samp{%}
1038 introduces a line comment; after @samp{%} the rest of the line is
1039 ignored.  A block comment marks a whole section of music
1040 input.  Anything that is enclosed in @code{%@{} and @code{%@}} is
1041 ignored.  The following fragment shows possible uses for comments
1042
1043 @example
1044 % notes for twinkle twinkle follow
1045   c4 c g' g a a g2
1046
1047 %@{
1048     This line, and the notes below
1049     are ignored, since they are in a
1050     block comment.
1051
1052     g g f f e e d d c2
1053 %@}
1054 @end example
1055
1056 @c  TODO   post-2.6 reorg
1057 @c   This is good info, but I wouldn't call it a comment.  IMO it should
1058 @c   be moved somewhere else.
1059
1060 @cindex versioning
1061
1062 There is a special statement that is a kind of comment.  The @code{\version}
1063 statement marks for which version of LilyPond the file was written.
1064 To mark a file for version 2.10.1, use
1065
1066 @example
1067 \version "2.10.1"
1068 @end example
1069
1070 @noindent
1071 These annotations make future upgrades of LilyPond go more
1072 smoothly.  Changes in the syntax are handled with a special program,
1073 @file{convert-ly} (see @ref{Updating files with convert-ly}), and it uses
1074 @code{\version} to determine what rules to apply.
1075
1076
1077 @node Printing lyrics
1078 @section Printing lyrics
1079 @cindex lyrics
1080
1081 @c TODO: (c) status of the Queen fragment.
1082
1083 @cindex Lyrics
1084 @cindex Songs
1085 Lyrics are entered by separating each syllable with a space
1086
1087 @example
1088 I want to break free
1089 @end example
1090
1091 Consider the melody
1092
1093 @lilypond[quote,verbatim,fragment,ragged-right]
1094 \relative {
1095   r4 c \times 2/3 { f g g }
1096   \times 2/3 { g4( a2) }
1097 }
1098 @end lilypond
1099
1100 The lyrics can be set to these notes, combining both with the
1101 @code{\addlyrics} keyword
1102
1103 @lilypond[quote,verbatim,fragment,ragged-right]
1104 <<
1105   \relative {
1106     r4 c \times 2/3 { f g g }
1107     \times 2/3 { g4( a2) }
1108   }
1109   \addlyrics { I want to break free }
1110 >>
1111 @end lilypond
1112
1113 @cindex melisma
1114 @cindex extender line
1115 @c synonyms?
1116 This melody ends on a @rglos{melisma}, a single syllable (@q{free})
1117 sung to more than one note.  This is indicated with an @emph{extender
1118 line}.  It is entered as two underscores, i.e.,
1119
1120 @example
1121 @{ I want to break free __ @}
1122 @end example
1123
1124 @lilypond[fragment,quote,ragged-right]
1125 <<
1126   \relative {
1127     r4 c \times 2/3 { f g g }
1128     \times 2/3 { g4( a2) }
1129   }
1130   \addlyrics { I want to break free __ }
1131 >>
1132 @end lilypond
1133
1134 Similarly, hyphens between words can be entered as two dashes,
1135 resulting in a centered hyphen between two syllables
1136
1137 @example
1138 A -- le gri -- a
1139 @end example
1140
1141 @c no ragged-right here, because otherwise the hypens get lost.
1142 @lilypond[fragment,quote]
1143 <<
1144   \relative {
1145     \time 2/4
1146     f4 f c' c
1147   }
1148   \addlyrics { A -- le gri -- a }
1149 >>
1150 @end lilypond
1151
1152 More options, like putting multiple lines of lyrics below a melody are
1153 discussed in @ref{Vocal music}.
1154
1155
1156 @node A lead sheet
1157 @section A lead sheet
1158
1159 @cindex Lead sheets
1160 @cindex chords
1161 @cindex chord names
1162
1163 @c TODO: revise this, \chords { } is shorter and more intuitive.
1164
1165 In popular music, it is common to denote accompaniment with chord names.
1166 Such chords can be entered like notes,
1167
1168 @lilypond[quote,verbatim,ragged-right]
1169 \chordmode { c2 f4. g8 }
1170 @end lilypond
1171
1172 @noindent
1173 Now each pitch is read as the root of a chord instead of a note.
1174 This mode is switched on with @code{\chordmode}
1175
1176 Other chords can be created by adding modifiers after a colon.  The
1177 following example shows a few common modifiers
1178
1179 @lilypond[quote,verbatim,ragged-right]
1180 \chordmode { c2 f4:m g4:maj7 gis1:dim7 }
1181 @end lilypond
1182
1183 For lead sheets, chords are not printed on staves, but as names on a
1184 line for themselves.  This is achieved by using @code{\chords} instead
1185 of @code{\chordmode}.  This uses the same syntax as @code{\chordmode},
1186 but renders the notes in a @code{ChordNames} context, with the
1187 following result.
1188
1189 @lilypond[quote,verbatim,ragged-right]
1190 \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1191 @end lilypond
1192
1193 @cindex lead sheet
1194 When put together, chord names, lyrics and a melody form
1195 a lead sheet, for example,
1196
1197 @example
1198 <<
1199   \chords @{ @emph{chords} @}
1200   @emph{the melody}
1201   \addlyrics @{ @emph{the text} @}
1202 >>
1203 @}
1204 @end example
1205
1206 @lilypond[quote,ragged-right]
1207 <<
1208   \chords { r2 c:sus4 f }
1209   \relative {
1210     r4 c' \times 2/3 { f g g }
1211     \times 2/3 { g4( a2) }
1212   }
1213   \addlyrics { I want to break free __ }
1214 >>
1215 @end lilypond
1216
1217 A complete list of modifiers and other options for layout can be found
1218 in @ref{Chords}.
1219
1220
1221 @node Adding titles
1222 @section Adding titles
1223
1224 Bibliographic information is entered in a separate block, the
1225 @code{\header} block.  The name of the piece, its composer, etc., are
1226 entered as an assignment, within @code{\header
1227 @{@tie{}@dots{}@tie{}@}}.  The @code{\header} block is usually put at
1228 the top of the file.  For example,
1229
1230 @example
1231 \header @{
1232   title = "Miniature"
1233   composer = "Igor Stravinsky"
1234 @}
1235
1236 @{ @dots{} @}
1237 @end example
1238
1239
1240 When the file is processed, the title and composer are printed above
1241 the music.  More information on titling can be found in @ref{Creating
1242 titles}.
1243
1244
1245 @node Single staff polyphony
1246 @section Single staff polyphony
1247
1248 @cindex polyphony
1249 @cindex multiple voices
1250 @cindex voices, more -- on a staff
1251 When different melodic lines are combined on a single staff they are
1252 printed as polyphonic voices; each voice has its own stems, slurs and
1253 beams, and the top voice has the stems up, while the bottom voice has
1254 them down.
1255
1256 Entering such parts is done by entering each voice as a sequence (with
1257 @code{@{...@}}), and combining these simultaneously, separating the
1258 voices with @code{\\}
1259
1260 @lilypond[quote,verbatim,relative=2,fragment]
1261 << { a4 g2 f4~ f4 } \\
1262    { r4 g4 f2 f4 } >>
1263 @end lilypond
1264
1265 For polyphonic music typesetting, spacer rests can also be convenient;
1266 these are rests that do not print.  They are useful for filling up
1267 voices that temporarily do not play.  Here is the same example with a
1268 spacer rest (@samp{s}) instead of a normal rest (@samp{r}),
1269
1270 @lilypond[quote,verbatim,relative=2,fragment]
1271 << { a4 g2 f4~ f4 } \\
1272    { s4 g4 f2 f4 } >>
1273 @end lilypond
1274
1275 @noindent
1276 Again, these expressions can be nested arbitrarily
1277
1278 @lilypond[quote,fragment,verbatim,relative=2,fragment]
1279 <<
1280   \new Staff <<
1281     { a4 g2 f4~ f4 } \\
1282     { s4 g4 f2 f4 }
1283   >>
1284   \new Staff <<
1285     \clef bass
1286     { <c g>1 ~ <c g>4 } \\
1287     { e,,4 d e2 ~ e4}
1288   >>
1289 >>
1290 @end lilypond
1291
1292 More features of polyphonic typesetting are described in this manual
1293 in section @ref{Basic polyphony}.
1294
1295
1296 @node Piano staves
1297 @section Piano staves
1298
1299 @cindex staff switch, manual
1300 @cindex cross staff voice, manual
1301 Piano music is typeset in two staves connected by a brace.  Printing
1302 such a staff is similar to the polyphonic example in @ref{More staves},
1303
1304 @example
1305 << \new Staff @{ @dots{} @}
1306    \new Staff @{ @dots{} @} >>
1307 @end example
1308
1309 @noindent
1310 but now this entire expression must be interpreted as a
1311 @code{PianoStaff}
1312
1313 @example
1314 \new PianoStaff << \new Staff @dots{} >>
1315 @end example
1316
1317 Here is a small example
1318
1319 @lilypond[quote,verbatim,relative=1,fragment]
1320 \new PianoStaff <<
1321   \new Staff { \time 2/4 c4 c g' g }
1322   \new Staff { \clef bass c,, c' e c }
1323 >>
1324 @end lilypond
1325
1326 More information on formatting piano music is given in @ref{Piano music}.
1327
1328
1329 @node Organizing larger pieces
1330 @section Organizing larger pieces
1331
1332 When all of the elements discussed earlier are combined to produce
1333 larger files, the @code{\score} blocks get a lot bigger because the
1334 music expressions are longer, and, in the case of polyphonic music,
1335 more deeply nested.  Such large expressions can become unwieldy.
1336
1337 By using variables, also known as identifiers, it is possible to break
1338 up complex music expressions.  An identifier is assigned as follows
1339
1340 @example
1341 namedMusic = @{ @dots{} @}
1342 @end example
1343
1344 @noindent
1345 The contents of the music expression @code{namedMusic}, can be used
1346 later by preceding the name with a backslash, i.e., @code{\namedMusic}.
1347 In the next example, a two-note motive is repeated two times by using
1348 variable substitution
1349
1350 @lilypond[quote,ragged-right,verbatim,nofragment]
1351 seufzer = {
1352   e'4( dis'4)
1353 }
1354 { \seufzer \seufzer }
1355 @end lilypond
1356
1357 The name of an identifier should have alphabetic characters only: no
1358 numbers, underscores, or dashes.  The assignment should be outside of
1359 running music.
1360
1361 It is possible to use variables for many other types of objects in the
1362 input.  For example,
1363
1364 @example
1365 width = 4.5\cm
1366 name = "Wendy"
1367 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1368 @end example
1369
1370 Depending on its contents, the identifier can be used in different
1371 places.  The following example uses the above variables
1372
1373 @example
1374 \paper @{
1375   \aFivePaper
1376   line-width = \width
1377 @}
1378 @{ c4^\name @}
1379 @end example
1380
1381 More information on the possible uses of identifiers is given in the
1382 technical manual, in @ref{Input variables and Scheme}.
1383 @c fixme: the ref is too technical.
1384
1385
1386 @node An orchestral part
1387 @section An orchestral part
1388
1389 In orchestral music, all notes are printed twice.  Once in a part for
1390 the musicians, and once in a full score for the conductor.  Identifiers can
1391 be used to avoid double work.  The music is entered once, and stored in
1392 a variable.  The contents of that variable is then used to generate
1393 both the part and the full score.
1394
1395 It is convenient to define the notes in a special file.  For example,
1396 suppose that the file @file{horn-music.ly} contains the following part
1397 of a horn/@/bassoon duo
1398
1399 @example
1400 hornNotes = \relative c @{
1401   \time 2/4
1402   r4 f8 a cis4 f e d
1403 @}
1404 @end example
1405
1406 @noindent
1407 Then, an individual part is made by putting the following in a file
1408
1409 @example
1410 \include "horn-music.ly"
1411 \header @{
1412   instrument = "Horn in F"
1413 @}
1414
1415 @{
1416  \transpose f c' \hornNotes
1417 @}
1418 @end example
1419
1420 The line
1421
1422 @example
1423 \include "horn-music.ly"
1424 @end example
1425
1426 @noindent
1427 substitutes the contents of @file{horn-music.ly} at this position in
1428 the file, so @code{hornNotes} is defined afterwards.  The command
1429 @code{\transpose f@tie{}c'} indicates that the argument, being
1430 @code{\hornNotes}, should be transposed by a fifth upwards.  Sounding
1431 @samp{f} is denoted by notated @code{c'}, which corresponds with the
1432 tuning of a normal French Horn in@tie{}F.  The transposition can be seen
1433 in the following output
1434
1435 @lilypond[quote,ragged-right]
1436 \transpose f c' \relative c {
1437   \time 2/4
1438   r4 f8 a cis4 f e d
1439 }
1440 @end lilypond
1441
1442 In ensemble pieces, one of the voices often does not play for many
1443 measures.  This is denoted by a special rest, the multi-measure
1444 rest.  It is entered with a capital @samp{R} followed by a duration
1445 (@code{1}@tie{}for a whole note, @code{2}@tie{}for a half note,
1446 etc.).  By multiplying the
1447 duration, longer rests can be constructed.  For example, this rest
1448 takes 3@tie{}measures in 2/4 time
1449
1450 @example
1451 R2*3
1452 @end example
1453
1454 When printing the part, multi-rests
1455 must be condensed.  This is done by setting a run-time variable
1456
1457 @example
1458 \set Score.skipBars = ##t
1459 @end example
1460
1461 @noindent
1462 This command sets the property @code{skipBars} in the
1463 @code{Score} context to true (@code{##t}).  Prepending the rest and
1464 this option to the music above, leads to the following result
1465
1466 @lilypond[quote,ragged-right]
1467 \transpose f c' \relative c {
1468   \time 2/4
1469   \set Score.skipBars = ##t
1470   R2*3
1471   r4 f8 a cis4 f e d
1472 }
1473 @end lilypond
1474
1475
1476 The score is made by combining all of the music together.  Assuming
1477 that the other voice is in @code{bassoonNotes} in the file
1478 @file{bassoon-music.ly}, a score is made with
1479
1480 @example
1481 \include "bassoon-music.ly"
1482 \include "horn-music.ly"
1483
1484 <<
1485   \new Staff \hornNotes
1486   \new Staff \bassoonNotes
1487 >>
1488 @end example
1489
1490 @noindent
1491 leading to
1492
1493 @lilypond[quote,ragged-right]
1494 \relative c <<
1495   \new Staff {
1496     \time 2/4 R2*3
1497     r4 f8 a cis4 f e d
1498   }
1499   \new Staff {
1500     \clef bass
1501     r4 d,8 f | gis4 c | b bes |
1502     a8 e f4 | g d | gis f
1503   }
1504 >>
1505 @end lilypond
1506
1507 More in-depth information on preparing parts and scores can be found
1508 in the notation manual; see @ref{Orchestral music}.
1509
1510 Setting run-time variables (@q{properties}) is discussed in
1511 @ref{Changing context properties on the fly}.
1512
1513
1514 @node After the tutorial
1515 @section After the tutorial
1516
1517 After finishing the tutorial, you should probably try writing a
1518 piece or two.  Start with one of the @ref{Example templates} and
1519 add notes.  If you need any notation that was not covered in the
1520 tutorial, look at the Notation Reference, starting with
1521 @ref{Basic notation}.  If you want to write for an instrument
1522 ensemble which is not covered in the @ref{Example templates},
1523 take a look at @ref{Extending the templates}.
1524
1525 Once you have written a few short pieces, read the rest of
1526 the Learning Manual (chapters 3-5).  There's nothing wrong
1527 with reading them now, of course!  However, the rest of the
1528 Learning Manual assumes that you are familiar with
1529 LilyPond input.  You may wish to skim these chapters right
1530 now, and come back to them after you have more experience.
1531
1532