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