]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
Second phase of tutorial rewrite.
[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 `test.ly'
176 Parsing...
177 Interpreting music... [1]
178 Preprocessing graphical objects...
179 Calculating line breaks... [2]
180 Layout output to `test.ps'...
181 Converting to `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
350 @node Working on text files
351 @section Working on text files
352
353 LilyPond input files are treated like files in most programming languages:
354 they are case sensitive, white-space insensitive, and expressions are
355 formed with curly braces @{ @}.
356
357 If the previous sentence sounds like nonsense, don't worry!  We'll explain
358 what all these terms mean:
359
360 @itemize
361 @item
362 @strong{Remember:} Every piece of LilyPond input needs to have
363 @strong{@{ curly braces @}} placed around the input.  The braces should
364 be surrounded by
365 a space unless they are at the beginning or end of a line to avoid
366 ambiguities.  For the rest of this manual, most examples will omit
367 these braces, but don't forget them in your own music!
368
369 @cindex Case sensitive
370 @item
371 In addition, LilyPond input is @strong{case sensitive}.  @code{ @{ c d e @} }
372 is valid input; @code{ @{ C D E @} } will produce an error message.
373
374 @c  End of current re-write; more material coming in a few days.  -gp
375 @end itemize
376
377
378
379 @node More about pitches
380 @section More about pitches
381
382 A @rglos{sharp} pitch is made by adding @samp{is} to
383 the name, a @rglos{flat} pitch by adding @samp{es}.  As
384 you might expect, a @rglos{double sharp} or @rglos{double flat} is
385 made by adding @samp{isis} or @samp{eses}@footnote{This syntax
386 derived from note naming conventions in Nordic and Germanic languages,
387 like German and Dutch.}
388
389 @example
390 cis1 ees fisis aeses
391 @end example
392
393 @lilypond[fragment,quote,notime]
394 \set Score.timing = ##f
395 \transpose c c' { cis1 ees fisis aeses s16_" " }
396 @end lilypond
397
398 @cindex key signature, setting
399 The key signature is set with the command @code{\key}, followed by
400 a pitch and @code{\major} or @code{\minor}
401
402 @example
403 \key d \major
404 g1
405 \key c \minor
406 g
407 @end example
408
409 @lilypond[fragment,quote,notime,fragment]
410 \key d \major
411 g'1
412 \key c \minor
413 g'
414 @end lilypond
415
416 @noindent
417 Key signatures together with the pitches (including alterations) are
418 used to determine when to print accidentals.  This is a
419 feature that often causes confusion to newcomers, so let us explain it
420 in more detail.
421
422
423 LilyPond makes a sharp distinction between musical content and
424 layout.  The alteration (flat, natural or sharp) of a note is part of
425 the pitch, and is therefore musical content.  Whether an accidental (a
426 flat, natural or sharp @emph{sign}) is printed in front of the
427 corresponding note is a question of layout.  Layout is something that
428 follows rules, so accidentals are printed automatically according to
429 those rules.  The pitches in your music are works of art, so they will
430 not be added automatically, and you must enter what you want to hear.
431
432 In this example
433
434 @lilypond[quote,notime,fragment]
435 \key d \major
436 d' cis' fis'
437 @end lilypond
438
439 @noindent
440 no note has an explicit accidental, but you still must enter
441
442 @example
443 \key d \major
444 d cis fis
445 @end example
446
447 @noindent
448 The code @samp{d} does not mean @qq{print a black dot just below the
449 staff.}  Rather, it means: @qq{a note with pitch D-natural.}  In the key
450 of A-flat major, it does get an accidental
451
452 @lilypond[quote,notime,fragment,relative=1,verbatim]
453 \key as \major
454 d
455 @end lilypond
456
457 Adding all alterations explicitly might require a little more effort
458 when typing, but the advantage is that transposing is easier, and
459 accidentals can be printed according to different conventions.  See
460 @ref{Automatic accidentals}, for some examples how accidentals can be printed
461 according to different rules.
462
463
464 For more information on
465
466 @quotation
467 @table @asis
468 @item Accidentals
469 see @ref{Automatic accidentals}.
470
471 @item Key signature
472 see @ref{Key signature}.
473 @end table
474 @end quotation
475
476 @node Entering ties
477 @section Entering ties
478
479 @cindex tie
480 A @rglos{tie} is created by appending a tilde @samp{~} to the first
481 note being tied
482
483 @lilypond[quote,notime,fragment,verbatim,relative=3]
484 g4~ g a2~ a4
485 @end lilypond
486
487 For more information on Ties see @ref{Ties}.
488
489
490
491 @node Automatic and manual beams
492 @section Automatic and manual beams
493
494 @cindex beams, by hand
495 All @rglos{beam}s are drawn automatically
496
497 @lilypond[quote,fragment,relative=2,verbatim]
498 a8 ais d es r d
499 @end lilypond
500
501 @noindent
502 If you do not like where beams are put, they can be entered by
503 hand.  Mark the first note to be beamed with @samp{[} and the last one
504 with @samp{]}.
505
506 @lilypond[quote,fragment,relative=2,verbatim]
507 a8[ ais] d[ es r d]
508 @end lilypond
509
510 For more information on beams, see @ref{Manual beams}.
511
512
513 Here are key signatures, accidentals and ties in action
514
515 @lilypond[fragment,quote,noindent,line-width=50\staff-space,verbatim]
516 \relative c'' {
517   \time 4/4
518   \key g \minor
519   \clef treble
520   r4 r8 a8 gis4 b
521   a8 d4.~ d e,8
522   fis4 fis8 fis8 eis4 a8 gis~
523   gis2 r2
524 }
525 @end lilypond
526
527 @cindex accidentals
528
529
530 @noindent
531 There are some interesting points to note in this example.  Bar lines
532 and beams are drawn automatically.  Line breaks are calculated
533 automatically; it does not matter where the line breaks are in the
534 source file.  Finally, the order in which time, key, and clef changes
535 are entered is not relevant: in the printout, these are ordered
536 according to standard notation conventions.
537
538
539
540 @node Octave entry
541 @section Octave entry
542
543
544 @c Tim wants to move this quotes example just before the: quotes-do not-work
545 @c score, but we'd need to remove quotes from the other two (key and
546 @c tie) examples...
547
548 @c better to have this just before the `octaves are bad' snipped
549 @c but we'd need to remove the ', from \key and tie
550 To raise a note by an octave, add a high quote @samp{'} (apostrophe) to
551 the note name, to lower a note one octave, add a @q{low quote} @samp{,}
552 (comma).  Middle C is @code{c'}
553
554 @lilypond[quote,notime,fragment,verbatim]
555 c'4 c'' c''' \clef bass c c,
556 @end lilypond
557
558 An example of the use of quotes is in the following Mozart fragment
559
560 @lilypond[quote,ragged-right,fragment,verbatim]
561 \key a \major
562 \time 6/8
563 cis''8. d''16 cis''8 e''4 e''8
564 b'8. cis''16 b'8 d''4 d''8
565 @end lilypond
566
567 @noindent
568 This example shows that music in a high register needs lots of quotes.
569 This makes the input less readable, and it is a source of errors.  The
570 solution is to use @q{relative octave} mode.   This is the
571 most convenient way to copy existing music.
572
573 In relative mode, a note without octavation quotes (i.e., the @samp{'}
574 or @samp{,} after a note) is chosen so that it is closest to the
575 previous one.  For example, @samp{c f} goes up while @samp{c g} goes
576 down.
577
578 To use relative mode, add @code{\relative} before the piece of
579 music.  The first note is taken relative to the middle C
580 @c no , for this sentence
581 (i.e., @code{c'})
582
583
584
585 @lilypond[quote,notime,fragment,verbatim]
586 \relative {
587   c' f c g c
588 }
589 @end lilypond
590
591
592 Since most music has small intervals, pieces can be written almost
593 without octavation quotes in relative mode.  The previous example is
594 entered as
595
596 @lilypond[quote,ragged-right,verbatim]
597 \relative {
598   \key a \major
599   \time 6/8
600   cis'8. d16 cis8 e4 e8
601   b8. cis16 b8 d4 d8
602 }
603 @end lilypond
604
605 @c needed better, maybe even redundant explanation
606 @c   added another example below.
607 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
608 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
609 Larger intervals are made by adding octavation quotes.
610
611 @lilypond[quote,notime,verbatim,fragment]
612 \relative c {
613   c'' f, f c' c g' c,
614 }
615 @end lilypond
616
617 In summary, quotes or commas no longer determine the absolute height
618 of a note in @code{\relative} mode.  Rather, the height of a note is
619 relative to the previous one, and changing the octave of a single note
620 shifts all following notes an octave up or down.
621
622 For more information on relative octaves see @ref{Relative octaves},
623 and @ref{Octave check}.
624
625
626 @node Music expressions explained
627 @section Music expressions explained
628
629
630 In input files, music is represent by so-called @emph{music
631 expression}s.  We have already seen some in the previous examples;
632 a single note is a music expression
633
634 @lilypond[fragment,quote,verbatim,relative=3]
635 a4
636 @end lilypond
637
638 Enclosing a group of notes in braces creates a new music
639 expression
640
641 @lilypond[fragment,quote,verbatim,relative=3]
642 { a4 g4 }
643 @end lilypond
644
645 Putting a bunch of music expressions (e.g., notes) in braces, means that
646 they should be played in sequence.  The result again is a music
647 expression, which can be grouped with other expressions sequentially.
648 Here, the expression from the previous example is combined with two
649 notes
650
651 @lilypond[fragment,quote,verbatim,relative=3]
652 { { a4 g } f g }
653 @end lilypond
654
655 This technique is useful for non-monophonic music.  To enter music
656 with more voices or more staves, we also combine expressions in
657 parallel.  Two voices that should play at the same time, are entered
658 as a simultaneous combination of two sequences.  A @q{simultaneous}
659 music expression is formed by enclosing expressions in @code{<<} and
660 @code{>>}.  In the following example, three sequences (all containing
661 two separate notes) are combined simultaneously
662
663 @lilypond[fragment,quote,verbatim,relative=3]
664 <<
665   { a4 g }
666   { f e }
667   { d b }
668 >>
669 @end lilypond
670
671 This mechanism is similar to mathematical
672 formulas: a big formula is created by composing small formulas.  Such
673 formulas are called expressions, and their definition is recursive, so
674 you can make arbitrarily complex and large expressions.  For example,
675
676 @example
677 1
678
679 1 + 2
680
681 (1 + 2) * 3
682
683 ((1 + 2) * 3) / (4 * 5)
684 @end example
685
686 @cindex expression
687 @cindex music expression
688 This is a sequence of expressions, where each expression is contained
689 in the next (larger) one.  The simplest expressions are numbers, and larger
690 ones are made by combining expressions with operators (like @samp{+},
691 @samp{*} and @samp{/}) and parentheses.  Like mathematical expressions,
692 music expressions can be nested arbitrarily deep, which is necessary
693 for complex music like polyphonic scores.
694
695 Note that this example only has one staff, whereas
696 the previous example had three separate staves.  That is because this
697 example begins with a single note.  To determine the number of staves,
698 LilyPond looks at the first element.  If it is a single note, there is one
699 staff; if there is a simultaneous expression, there is more than one staff.
700
701 @lilypond[fragment,quote,verbatim,relative=2]
702 {
703   c <<c e>>
704   << { e f } { c <<b d>> } >>
705 }
706 @end lilypond
707
708 Music files with deep nesting can be confusing to enter and
709 maintain.  One convention that helps against this confusion is
710 indenting.  When entering a file with deep nesting of braces and
711 angles, it is customary to use an indent that indicates the nesting
712 level.  Formatting music like this eases reading and helps you insert
713 the right number of closing braces at the end of an expression.  For
714 example,
715
716 @example
717 <<
718   @{
719     @dots{}
720   @}
721   @{
722     @dots{}
723   @}
724 >>
725 @end example
726
727 Some editors have special support for entering LilyPond, and can help
728 indenting source files.  See @ref{Editor support} for more information.
729
730 @node More staves
731 @section More staves
732
733 To print more than one staff, each piece of music that makes up a
734 staff is marked by adding @code{\new Staff} before it.  These
735 @code{Staff} elements are then combined in parallel with @code{<<} and
736 @code{>>}, as demonstrated here
737
738 @lilypond[quote,fragment,verbatim]
739 <<
740   \new Staff { \clef treble c'' }
741   \new Staff { \clef bass c }
742 >>
743 @end lilypond
744
745
746 The command @code{\new} introduces a @q{notation context.}  A notation
747 context is an environment in which musical events (like notes or
748 @code{\clef} commands) are interpreted.  For simple pieces, such
749 notation contexts are created automatically.  For more complex pieces, it
750 is best to mark contexts explicitly.  This ensures that each fragment
751 gets its own stave.
752
753 There are several types of contexts.  @code{Staff}, @code{Voice} and
754 @code{Score} handle melodic notation, while @code{Lyrics} sets lyric
755 texts and @code{ChordNames} prints chord names.
756
757 In terms of syntax, prepending @code{\new} to a music expression
758 creates a bigger music expression.  In this way it resembles the minus
759 sign in mathematics.  The formula @math{(4+5)} is an expression, so
760 @math{-(4+5)} is a bigger expression.
761
762 We can now typeset a melody with two staves
763
764 @c TODO: (c) status of this Paul McCartney (?) song (let's all stand together)
765
766 @lilypond[fragment,quote,verbatim,ragged-right]
767 \relative <<
768   \new Staff {
769     \time 3/4
770     \clef treble
771
772     e'2 d4 c2 b4 a8[ a]
773     b[ b] g[ g] a2.
774   }
775   \new Staff {
776      \clef bass
777      c,,2 e4 g2.
778      f4 e d c2.
779   }
780 >>
781 @end lilypond
782
783 For more information on contexts see the description in
784 @ref{Interpretation contexts}.
785
786
787
788 @node Adding articulation marks to notes
789 @section Adding articulation marks to notes
790
791 @cindex articulation
792 @cindex accents
793 @cindex staccato
794
795 Common accents can be added to a note using a dash (@samp{-}) and a
796 single character
797
798 @lilypond[fragment,quote,verbatim,relative=2]
799 c-.  c-- c-> c-^ c-+ c-_
800 @end lilypond
801
802 @cindex fingering
803 Similarly, fingering indications can be added to a note using a dash
804 (@samp{-}) and the digit to be printed
805
806 @lilypond[fragment,quote,verbatim,relative=2]
807 c-3 e-5 b-2 a-1
808 @end lilypond
809
810 Articulations and fingerings are usually placed automatically, but you
811 can specify a direction using @samp{^} (up) or @samp{_} (down).  You can
812 also use multiple articulations on the same note.  In most cases, however,
813 it is best to let LilyPond determine the articulation directions.
814
815 @lilypond[fragment,quote,verbatim,relative=2]
816 c_-^1 d^. f^4_2-> e^-_+
817 @end lilypond
818
819 Dynamic signs are made by adding the markings (with a backslash) to
820 the note
821
822 @lilypond[fragment,quote,verbatim,relative=2]
823 c\ff c\mf
824 @end lilypond
825
826 @cindex dynamics
827 @cindex decrescendo
828 @cindex crescendo
829
830 Crescendi and decrescendi are started with the commands @code{\<} and
831 @code{\>}.  An ending dynamic, for example @code{\f}, will finish the
832 (de)crescendo, or the command @code{\!} can be used
833
834 @lilypond[fragment,quote,verbatim,relative=2]
835 c2\< c2\ff\> c2 c2\!
836 @end lilypond
837
838
839
840 @cindex slur
841
842 A @rglos{slur} is a curve drawn across many notes, and indicates
843 legato articulation.  The starting note and ending note are marked
844 with @samp{(} and @samp{)}, respectively
845
846 @lilypond[fragment,quote,fragment,relative=2,verbatim]
847 d4( c16) cis( d e c cis d) e( d4)
848 @end lilypond
849
850 @cindex slurs versus ties
851 A slur looks like a @rglos{tie}, but it has a different meaning.  A
852 tie simply makes the first note sound longer, and can only be used on
853 pairs of notes with the same pitch.  Slurs indicate the articulations
854 of notes, and can be used on larger groups of notes.  Slurs and ties
855 can be nested
856
857 @lilypond[quote,fragment,relative=2]
858 c2~( c8 fis fis4 ~ fis2 g2)
859 @end lilypond
860
861 @cindex phrasing slurs
862 Slurs to indicate phrasing can be entered with @code{\(} and
863 @code{\)}, so you can have both legato slurs and phrasing slurs at the
864 same time.  You cannot have simultaneous slurs or simultaneous
865 phrasing slurs.
866
867 @lilypond[quote,fragment,relative=2,verbatim]
868 a8(\( ais b c) cis2 b'2 a4 cis, c\)
869 @end lilypond
870
871
872 For more information on
873
874 @quotation
875 @table @asis
876 @item Fingering
877 see @ref{Fingering instructions}.
878 @item Articulations
879 see @ref{Articulations}.
880 @item Slurs
881 see @ref{Slurs}.
882 @item Phrasing slurs
883 see @ref{Phrasing slurs}.
884 @item Dynamics
885 see @ref{Dynamics}.
886 @end table
887 @end quotation
888
889
890 @node Combining notes into chords
891 @section Combining notes into chords
892
893 @cindex chords
894 Chords can be made by surrounding pitches with angle brackets.
895 Angle brackets are the symbols @samp{<} and @samp{>}.
896
897 @lilypond[quote,relative=1,fragment,verbatim]
898 r4 <c e g>4 <c f a>8
899 @end lilypond
900
901
902 You can combine markings like beams and ties with chords.  They must
903 be placed outside the angled brackets
904
905 @lilypond[quote,relative=1,fragment,verbatim]
906 r4 <c e g>8[ <c f a>]~ <c f a>
907 @end lilypond
908
909 @example
910 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
911 @end example
912
913 @lilypond[quote,relative=1,fragment]
914 \slurUp
915 r4 <c e g>8\>( <c e g> <c e g> <c f a>\!)
916 @end lilypond
917
918
919 @node Advanced rhythmic commands
920 @section Advanced rhythmic commands
921
922 @cindex pickup
923 @cindex anacruse
924 @cindex partial measure
925 A pickup is entered with the keyword @code{\partial}.  It
926 is followed by a duration: @code{\partial 4} is a quarter note upstep
927 and @code{\partial 8} an eighth note
928
929 @lilypond[quote,relative=2,verbatim,fragment]
930 \partial 8
931 f8 c2 d e
932 @end lilypond
933
934 @cindex tuplets
935 @cindex triplets
936 Tuplets are made with the @code{\times} keyword.  It takes two
937 arguments: a fraction and a piece of music.  The duration of the piece
938 of music is multiplied by the fraction.  Triplets make notes occupy
939 2/3 of their notated duration, so a triplet has 2/3 as its fraction
940
941 @lilypond[quote,relative=1,verbatim,fragment]
942 \times 2/3 { f8 g a }
943 \times 2/3 { c r c }
944 @end lilypond
945
946 @cindex grace notes
947 @cindex acciaccatura
948 Grace notes are also made by prefixing a music expression with the
949 keyword @code{\appoggiatura} or @code{\acciaccatura}
950 @cindex appoggiatura
951 @cindex acciaccatura
952
953 @lilypond[quote,relative=2,verbatim,fragment]
954 c4 \appoggiatura b16 c4
955 c4 \acciaccatura b16 c4
956 @end lilypond
957
958 @noindent
959
960 For more information on
961
962 @quotation
963 @table @asis
964 @item Grace notes
965 see @ref{Grace notes},
966 @item Tuplets
967 see @ref{Tuplets},
968 @item Pickups
969 see @ref{Partial measures}.
970 @end table
971 @end quotation
972
973
974 @node Commenting input files
975 @section Commenting input files
976
977 @cindex comments
978 @cindex line comment
979 @cindex block comment
980 A comment is a remark for the human reader of the music input; it is
981 ignored while parsing, so it has no effect on the printed output.
982 There are two types of comments.  The percent symbol @samp{%}
983 introduces a line comment; after @samp{%} the rest of the line is
984 ignored.  A block comment marks a whole section of music
985 input.  Anything that is enclosed in @code{%@{} and @code{%@}} is
986 ignored.  The following fragment shows possible uses for comments
987
988 @example
989 % notes for twinkle twinkle follow
990   c4 c g' g a a g2
991
992 %@{
993     This line, and the notes below
994     are ignored, since they are in a
995     block comment.
996
997     g g f f e e d d c2
998 %@}
999 @end example
1000
1001 @c  TODO   post-2.6 reorg
1002 @c   This is good info, but I wouldn't call it a comment.  IMO it should
1003 @c   be moved somewhere else.
1004
1005 @cindex versioning
1006
1007 There is a special statement that is a kind of comment.  The @code{\version}
1008 statement marks for which version of LilyPond the file was written.
1009 To mark a file for version 2.10.1, use
1010
1011 @example
1012 \version "2.10.1"
1013 @end example
1014
1015 @noindent
1016 These annotations make future upgrades of LilyPond go more
1017 smoothly.  Changes in the syntax are handled with a special program,
1018 @file{convert-ly} (see @ref{Updating files with convert-ly}), and it uses
1019 @code{\version} to determine what rules to apply.
1020
1021
1022 @node Printing lyrics
1023 @section Printing lyrics
1024 @cindex lyrics
1025
1026 @c TODO: (c) status of the Queen fragment.
1027
1028 @cindex Lyrics
1029 @cindex Songs
1030 Lyrics are entered by separating each syllable with a space
1031
1032 @example
1033 I want to break free
1034 @end example
1035
1036 Consider the melody
1037
1038 @lilypond[quote,verbatim,fragment,ragged-right]
1039 \relative {
1040   r4 c \times 2/3 { f g g }
1041   \times 2/3 { g4( a2) }
1042 }
1043 @end lilypond
1044
1045 The lyrics can be set to these notes, combining both with the
1046 @code{\addlyrics} keyword
1047
1048 @lilypond[quote,verbatim,fragment,ragged-right]
1049 <<
1050   \relative {
1051     r4 c \times 2/3 { f g g }
1052     \times 2/3 { g4( a2) }
1053   }
1054   \addlyrics { I want to break free }
1055 >>
1056 @end lilypond
1057
1058 @cindex melisma
1059 @cindex extender line
1060 @c synonyms?
1061 This melody ends on a @rglos{melisma}, a single syllable (@q{free})
1062 sung to more than one note.  This is indicated with an @emph{extender
1063 line}.  It is entered as two underscores, i.e.,
1064
1065 @example
1066 @{ I want to break free __ @}
1067 @end example
1068
1069 @lilypond[fragment,quote,ragged-right]
1070 <<
1071   \relative {
1072     r4 c \times 2/3 { f g g }
1073     \times 2/3 { g4( a2) }
1074   }
1075   \addlyrics { I want to break free __ }
1076 >>
1077 @end lilypond
1078
1079 Similarly, hyphens between words can be entered as two dashes,
1080 resulting in a centered hyphen between two syllables
1081
1082 @example
1083 A -- le gri -- a
1084 @end example
1085
1086 @c no ragged-right here, because otherwise the hypens get lost.
1087 @lilypond[fragment,quote]
1088 <<
1089   \relative {
1090     \time 2/4
1091     f4 f c' c
1092   }
1093   \addlyrics { A -- le gri -- a }
1094 >>
1095 @end lilypond
1096
1097 More options, like putting multiple lines of lyrics below a melody are
1098 discussed in @ref{Vocal music}.
1099
1100
1101 @node A lead sheet
1102 @section A lead sheet
1103
1104 @cindex Lead sheets
1105 @cindex chords
1106 @cindex chord names
1107
1108 @c TODO: revise this, \chords { } is shorter and more intuitive.
1109
1110 In popular music, it is common to denote accompaniment with chord names.
1111 Such chords can be entered like notes,
1112
1113 @lilypond[quote,verbatim,ragged-right]
1114 \chordmode { c2 f4. g8 }
1115 @end lilypond
1116
1117 @noindent
1118 Now each pitch is read as the root of a chord instead of a note.
1119 This mode is switched on with @code{\chordmode}
1120
1121 Other chords can be created by adding modifiers after a colon.  The
1122 following example shows a few common modifiers
1123
1124 @lilypond[quote,verbatim,ragged-right]
1125 \chordmode { c2 f4:m g4:maj7 gis1:dim7 }
1126 @end lilypond
1127
1128 For lead sheets, chords are not printed on staves, but as names on a
1129 line for themselves.  This is achieved by using @code{\chords} instead
1130 of @code{\chordmode}.  This uses the same syntax as @code{\chordmode},
1131 but renders the notes in a @code{ChordNames} context, with the
1132 following result.
1133
1134 @lilypond[quote,verbatim,ragged-right]
1135 \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
1136 @end lilypond
1137
1138 @cindex lead sheet
1139 When put together, chord names, lyrics and a melody form
1140 a lead sheet, for example,
1141
1142 @example
1143 <<
1144   \chords @{ @emph{chords} @}
1145   @emph{the melody}
1146   \addlyrics @{ @emph{the text} @}
1147 >>
1148 @}
1149 @end example
1150
1151 @lilypond[quote,ragged-right]
1152 <<
1153   \chords { r2 c:sus4 f }
1154   \relative {
1155     r4 c' \times 2/3 { f g g }
1156     \times 2/3 { g4( a2) }
1157   }
1158   \addlyrics { I want to break free __ }
1159 >>
1160 @end lilypond
1161
1162 A complete list of modifiers and other options for layout can be found
1163 in @ref{Chords}.
1164
1165
1166 @node Adding titles
1167 @section Adding titles
1168
1169 Bibliographic information is entered in a separate block, the
1170 @code{\header} block.  The name of the piece, its composer, etc., are
1171 entered as an assignment, within @code{\header
1172 @{@tie{}@dots{}@tie{}@}}.  The @code{\header} block is usually put at
1173 the top of the file.  For example,
1174
1175 @example
1176 \header @{
1177   title = "Miniature"
1178   composer = "Igor Stravinsky"
1179 @}
1180
1181 @{ @dots{} @}
1182 @end example
1183
1184
1185 When the file is processed, the title and composer are printed above
1186 the music.  More information on titling can be found in @ref{Creating
1187 titles}.
1188
1189
1190 @node Single staff polyphony
1191 @section Single staff polyphony
1192
1193 @cindex polyphony
1194 @cindex multiple voices
1195 @cindex voices, more -- on a staff
1196 When different melodic lines are combined on a single staff they are
1197 printed as polyphonic voices; each voice has its own stems, slurs and
1198 beams, and the top voice has the stems up, while the bottom voice has
1199 them down.
1200
1201 Entering such parts is done by entering each voice as a sequence (with
1202 @code{@{...@}}), and combining these simultaneously, separating the
1203 voices with @code{\\}
1204
1205 @lilypond[quote,verbatim,relative=2,fragment]
1206 << { a4 g2 f4~ f4 } \\
1207    { r4 g4 f2 f4 } >>
1208 @end lilypond
1209
1210 For polyphonic music typesetting, spacer rests can also be convenient;
1211 these are rests that do not print.  They are useful for filling up
1212 voices that temporarily do not play.  Here is the same example with a
1213 spacer rest (@samp{s}) instead of a normal rest (@samp{r}),
1214
1215 @lilypond[quote,verbatim,relative=2,fragment]
1216 << { a4 g2 f4~ f4 } \\
1217    { s4 g4 f2 f4 } >>
1218 @end lilypond
1219
1220 @noindent
1221 Again, these expressions can be nested arbitrarily
1222
1223 @lilypond[quote,fragment,verbatim,relative=2,fragment]
1224 <<
1225   \new Staff <<
1226     { a4 g2 f4~ f4 } \\
1227     { s4 g4 f2 f4 }
1228   >>
1229   \new Staff <<
1230     \clef bass
1231     { <c g>1 ~ <c g>4 } \\
1232     { e,,4 d e2 ~ e4}
1233   >>
1234 >>
1235 @end lilypond
1236
1237 More features of polyphonic typesetting are described in this manual
1238 in section @ref{Basic polyphony}.
1239
1240
1241 @node Piano staves
1242 @section Piano staves
1243
1244 @cindex staff switch, manual
1245 @cindex cross staff voice, manual
1246 Piano music is typeset in two staves connected by a brace.  Printing
1247 such a staff is similar to the polyphonic example in @ref{More staves},
1248
1249 @example
1250 << \new Staff @{ @dots{} @}
1251    \new Staff @{ @dots{} @} >>
1252 @end example
1253
1254 @noindent
1255 but now this entire expression must be interpreted as a
1256 @code{PianoStaff}
1257
1258 @example
1259 \new PianoStaff << \new Staff @dots{} >>
1260 @end example
1261
1262 Here is a small example
1263
1264 @lilypond[quote,verbatim,relative=1,fragment]
1265 \new PianoStaff <<
1266   \new Staff { \time 2/4 c4 c g' g }
1267   \new Staff { \clef bass c,, c' e c }
1268 >>
1269 @end lilypond
1270
1271 More information on formatting piano music is given in @ref{Piano music}.
1272
1273
1274 @node Organizing larger pieces
1275 @section Organizing larger pieces
1276
1277 When all of the elements discussed earlier are combined to produce
1278 larger files, the @code{\score} blocks get a lot bigger because the
1279 music expressions are longer, and, in the case of polyphonic music,
1280 more deeply nested.  Such large expressions can become unwieldy.
1281
1282 By using variables, also known as identifiers, it is possible to break
1283 up complex music expressions.  An identifier is assigned as follows
1284
1285 @example
1286 namedMusic = @{ @dots{} @}
1287 @end example
1288
1289 @noindent
1290 The contents of the music expression @code{namedMusic}, can be used
1291 later by preceding the name with a backslash, i.e., @code{\namedMusic}.
1292 In the next example, a two-note motive is repeated two times by using
1293 variable substitution
1294
1295 @lilypond[quote,ragged-right,verbatim,nofragment]
1296 seufzer = {
1297   e'4( dis'4)
1298 }
1299 { \seufzer \seufzer }
1300 @end lilypond
1301
1302 The name of an identifier should have alphabetic characters only: no
1303 numbers, underscores, or dashes.  The assignment should be outside of
1304 running music.
1305
1306 It is possible to use variables for many other types of objects in the
1307 input.  For example,
1308
1309 @example
1310 width = 4.5\cm
1311 name = "Wendy"
1312 aFivePaper = \paper @{ paperheight = 21.0 \cm @}
1313 @end example
1314
1315 Depending on its contents, the identifier can be used in different
1316 places.  The following example uses the above variables
1317
1318 @example
1319 \paper @{
1320   \aFivePaper
1321   line-width = \width
1322 @}
1323 @{ c4^\name @}
1324 @end example
1325
1326 More information on the possible uses of identifiers is given in the
1327 technical manual, in @ref{Input variables and Scheme}.
1328 @c fixme: the ref is too technical.
1329
1330
1331 @node An orchestral part
1332 @section An orchestral part
1333
1334 In orchestral music, all notes are printed twice.  Once in a part for
1335 the musicians, and once in a full score for the conductor.  Identifiers can
1336 be used to avoid double work.  The music is entered once, and stored in
1337 a variable.  The contents of that variable is then used to generate
1338 both the part and the full score.
1339
1340 It is convenient to define the notes in a special file.  For example,
1341 suppose that the file @file{horn-music.ly} contains the following part
1342 of a horn/@/bassoon duo
1343
1344 @example
1345 hornNotes = \relative c @{
1346   \time 2/4
1347   r4 f8 a cis4 f e d
1348 @}
1349 @end example
1350
1351 @noindent
1352 Then, an individual part is made by putting the following in a file
1353
1354 @example
1355 \include "horn-music.ly"
1356 \header @{
1357   instrument = "Horn in F"
1358 @}
1359
1360 @{
1361  \transpose f c' \hornNotes
1362 @}
1363 @end example
1364
1365 The line
1366
1367 @example
1368 \include "horn-music.ly"
1369 @end example
1370
1371 @noindent
1372 substitutes the contents of @file{horn-music.ly} at this position in
1373 the file, so @code{hornNotes} is defined afterwards.  The command
1374 @code{\transpose f@tie{}c'} indicates that the argument, being
1375 @code{\hornNotes}, should be transposed by a fifth upwards.  Sounding
1376 @samp{f} is denoted by notated @code{c'}, which corresponds with the
1377 tuning of a normal French Horn in@tie{}F.  The transposition can be seen
1378 in the following output
1379
1380 @lilypond[quote,ragged-right]
1381 \transpose f c' \relative c {
1382   \time 2/4
1383   r4 f8 a cis4 f e d
1384 }
1385 @end lilypond
1386
1387 In ensemble pieces, one of the voices often does not play for many
1388 measures.  This is denoted by a special rest, the multi-measure
1389 rest.  It is entered with a capital @samp{R} followed by a duration
1390 (@code{1}@tie{}for a whole note, @code{2}@tie{}for a half note,
1391 etc.).  By multiplying the
1392 duration, longer rests can be constructed.  For example, this rest
1393 takes 3@tie{}measures in 2/4 time
1394
1395 @example
1396 R2*3
1397 @end example
1398
1399 When printing the part, multi-rests
1400 must be condensed.  This is done by setting a run-time variable
1401
1402 @example
1403 \set Score.skipBars = ##t
1404 @end example
1405
1406 @noindent
1407 This command sets the property @code{skipBars} in the
1408 @code{Score} context to true (@code{##t}).  Prepending the rest and
1409 this option to the music above, leads to the following result
1410
1411 @lilypond[quote,ragged-right]
1412 \transpose f c' \relative c {
1413   \time 2/4
1414   \set Score.skipBars = ##t
1415   R2*3
1416   r4 f8 a cis4 f e d
1417 }
1418 @end lilypond
1419
1420
1421 The score is made by combining all of the music together.  Assuming
1422 that the other voice is in @code{bassoonNotes} in the file
1423 @file{bassoon-music.ly}, a score is made with
1424
1425 @example
1426 \include "bassoon-music.ly"
1427 \include "horn-music.ly"
1428
1429 <<
1430   \new Staff \hornNotes
1431   \new Staff \bassoonNotes
1432 >>
1433 @end example
1434
1435 @noindent
1436 leading to
1437
1438 @lilypond[quote,ragged-right]
1439 \relative c <<
1440   \new Staff {
1441     \time 2/4 R2*3
1442     r4 f8 a cis4 f e d
1443   }
1444   \new Staff {
1445     \clef bass
1446     r4 d,8 f | gis4 c | b bes |
1447     a8 e f4 | g d | gis f
1448   }
1449 >>
1450 @end lilypond
1451
1452 More in-depth information on preparing parts and scores can be found
1453 in the notation manual; see @ref{Orchestral music}.
1454
1455 Setting run-time variables (@q{properties}) is discussed in
1456 @ref{Changing context properties on the fly}.
1457
1458
1459 @node After the tutorial
1460 @section After the tutorial
1461
1462 After finishing the tutorial, you should probably try writing a
1463 piece or two.  Start with one of the @ref{Example templates} and
1464 add notes.  If you need any notation that was not covered in the
1465 tutorial, look at the Notation Reference, starting with
1466 @ref{Basic notation}.  If you want to write for an instrument
1467 ensemble which is not covered in the @ref{Example templates},
1468 take a look at @ref{Extending the templates}.
1469
1470 Once you have written a few short pieces, read the rest of
1471 the Learning Manual (chapters 3-5).  There's nothing wrong
1472 with reading them now, of course!  However, the rest of the
1473 Learning Manual assumes that you are familiar with
1474 LilyPond input.  You may wish to skim these chapters right
1475 now, and come back to them after you have more experience.
1476
1477 @ignore
1478 For more information on
1479
1480 @q uotation
1481 @t able @asis
1482 @i tem Entering pitches and durations
1483 see
1484 @r ef{Pitches}, and @ref{Durations}.
1485 @i tem Clefs
1486 see @ref{Clef}.
1487 @i tem Rests
1488 see @ref{Rests}.
1489 @i tem Time signatures and other timing commands
1490 see @ref{Time signature}.
1491 @e nd table
1492 @e nd quotation
1493 @end ignore
1494
1495