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