]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/tutorial.itely
f4e9302eae4b5d9ea082e6b21572f6cafd25f666
[lilypond.git] / Documentation / learning / tutorial.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @include included/generating-output.itexi
12
13 @c \version "2.19.21"
14
15 @node Tutorial
16 @chapter Tutorial
17
18 This chapter gives a basic introduction to working with LilyPond.
19
20 @menu
21 * Compiling a file::
22 * How to write input files::
23 * Dealing with errors::
24 * How to read the manuals::
25 @end menu
26
27 @node Compiling a file
28 @section Compiling a file
29
30 This section introduces @qq{compiling}---the processing of
31 LilyPond input files (written by you) to produce output files.
32
33 @menu
34 * Entering input::
35 * MacOS X::
36 * Windows::
37 * Command-line::
38 @end menu
39
40 @node Entering input
41 @subsection Entering input
42
43 @cindex compiling
44 @cindex first example
45 @cindex example, first
46 @cindex case sensitive
47
48 @menu
49 * Producing output::
50 @end menu
51
52 @qq{Compiling} is the term used for processing an input file in
53 LilyPond format to produce output file(s).  Output files are
54 generally PDF (for printing or viewing), MIDI (for playing), and
55 PNG (for online use).  LilyPond input files are simple text files.
56
57 This example shows a simple input file:
58
59 @example
60 \version "@w{@version{}}"
61 @{
62   c' e' g' e'
63 @}
64 @end example
65
66 The graphical output is:
67
68 @c  in this case we don't want verbatim
69 @lilypond[quote]
70 {
71   c' e' g' e'
72 }
73 @end lilypond
74
75 @warning{Notes and lyrics in LilyPond input must always be
76 surrounded by @w{@strong{@{ curly braces @}}}.  The braces
77 should also be surrounded by a space unless they are at the
78 beginning or end of a line to avoid ambiguities.  They may
79 be omitted in some examples in this manual, but don't forget them
80 in your own music!  For more information about the display of
81 examples in the manual, see @ref{How to read the manuals}.}
82
83 In addition, LilyPond input is @strong{case sensitive}.
84 @w{@samp{@{ c d e @}}} is valid input; @w{@samp{@{ C D E @}}} will
85 produce an error message.
86
87
88 @smallspace
89
90 @node Producing output
91 @unnumberedsubsubsec Producing output
92
93 @cindex PDF file
94 @cindex viewing music
95 @cindex text editors
96
97 The method of producing output depends on your operating system
98 and the program(s) you use.
99
100 @itemize
101
102 @item
103 @ref{MacOS X, @sourceimage{logo-macosx,,,}}
104 @ref{MacOS X, MacOS X} (graphical)
105
106 @item
107 @ref{Windows, @sourceimage{logo-windows,,,}}
108 @ref{Windows, Microsoft Windows} (graphical)
109
110 @item
111 @ref{Command-line, @sourceimage{logo-linux,,,}
112 @sourceimage{logo-freebsd,,,}
113 @sourceimage{logo-macosx,,,}
114 @sourceimage{logo-windows,,,}
115 }
116 @ref{Command-line, All operating systems} (command-line)
117
118 @end itemize
119
120 There are several other text editors available with specific
121 support for LilyPond.  For more information, see
122 @rweb{Easier editing}.
123
124 @warning{The first time you ever run LilyPond, it may take a
125 minute or two because all of the system fonts have to be analyzed
126 first.  After this, LilyPond will be much faster!}
127
128
129 @node MacOS X
130 @subsection MacOS X
131
132 @cindex running LilyPond under MacOS X
133 @cindex MacOS X, running LilyPond
134
135 @lilypadOSX
136
137
138 @node Windows
139 @subsection Windows
140
141 @cindex running LilyPond under Windows
142 @cindex Windows, running LilyPond
143
144 @lilypadWindows
145
146
147 @node Command-line
148 @subsection Command-line
149
150 @cindex running LilyPond under Unix
151 @cindex Unix, running LilyPond
152
153 @lilypadCommandLine
154
155 @node How to write input files
156 @section How to write input files
157
158 This section introduces some basic LilyPond syntax to help get you
159 started writing input files.
160
161 @menu
162 * Simple notation::
163 * Working on input files::
164 @end menu
165
166
167 @node Simple notation
168 @subsection Simple notation
169
170 @cindex simple notation
171 @cindex notation, simple
172
173 @menu
174 * Pitches::
175 * Durations (rhythms)::
176 * Rests::
177 * Time signature::
178 * Tempo marks::
179 * Clef::
180 * All together::
181 @end menu
182
183 LilyPond will add some notation elements automatically.  In the
184 next example, we have only specified four pitches, but LilyPond
185 has added a clef, time signature, and rhythms.
186
187 @lilypond[verbatim,quote]
188 {
189   c' e' g' e'
190 }
191 @end lilypond
192
193 @noindent
194 This behavior may be altered, but in most cases these automatic
195 values are useful.
196
197
198 @node Pitches
199 @unnumberedsubsubsec Pitches
200
201 @cindex pitches
202 @cindex relative mode
203 @cindex quote, single
204 @cindex comma
205 @cindex accidentals and relative mode
206 @cindex relative mode, and accidentals
207
208 @funindex \relative
209 @funindex relative
210 @funindex '
211 @funindex ,
212
213 Music Glossary: @rglos{pitch}, @rglos{interval},
214 @rglos{scale}, @rglos{middle C}, @rglos{octave},
215 @rglos{accidental}.
216
217 LilyPond uses lower-case letters for pitches.  The letters
218 @code{c} through@tie{}@code{b} denote pitches in the
219 @q{small octave} below @notation{middle C}.  Added @code{'}
220 or@tie{}@code{,} suffixes indicate higher or lower octaves.
221 Here is a scale starting on @notation{middle C}, and an arpeggio:
222
223 @lilypond[verbatim,quote]
224 { c' d' e' f' g' a' b' c'' g c' e' g' c'' e'' g'' c''' }
225 @end lilypond
226
227 The easiest way to enter notes is by using @code{\relative} mode.
228 In this mode, the octave is chosen automatically by assuming the
229 following note is always to be placed closest to the previous
230 note, i.e., it is to be placed in the octave which is within three
231 staff spaces of the previous note.  We begin by entering the most
232 elementary piece of music, a @notation{scale}, in which every note
233 is within just one staff space of the previous note.
234
235 @lilypond[verbatim,quote]
236 \relative {
237   c' d e f
238   g a b c
239 }
240 @end lilypond
241
242 The initial note is @notation{middle C}, denoted by @code{c'}.
243 Each successive note is
244 placed closest to the previous note -- in other words, the first
245 @code{c} is the closest C to middle C.  This is followed by the
246 closest D to the previous note.  We can create melodies which have
247 larger intervals, still using only @code{\relative} mode:
248
249 @lilypond[verbatim,quote]
250 \relative {
251   d' f a g
252   c b f d
253 }
254 @end lilypond
255
256 @noindent
257 In the previous example, the first note -- the @code{d'} with one
258 @code{'}-mark -- is the D in the octave starting from middle C
259 and going up to B.
260
261 By adding (or removing) quotes @code{'} or commas @code{,} from
262 the first note, we can change the starting octave:
263
264 @lilypond[verbatim,quote]
265 \relative {
266   e'' c a c
267 }
268 @end lilypond
269
270 Relative mode can be confusing initially, but is the easiest way
271 to enter most melodies.  Let us see how this relative calculation
272 works in practice.  Starting from a B, which is on the middle line
273 in a treble clef, you can reach a C, D and E within 3 staff spaces
274 going up, and an A, G and F within 3 staff spaces going down.  So
275 if the note following a B is a C, D or E it will be assumed to be
276 above the B, and an A, G or F will be assumed to be below.
277
278 @lilypond[verbatim,quote]
279 \relative {
280   b' c % c is 1 staff space up, so is the c above
281   b d  % d is 2 up or 5 down, so is the d above
282   b e  % e is 3 up or 4 down, so is the e above
283   b a  % a is 6 up or 1 down, so is the a below
284   b g  % g is 5 up or 2 down, so is the g below
285   b f  % f is 4 up or 3 down, so is the f below
286 }
287 @end lilypond
288
289 Exactly the same happens even when any of these notes are
290 sharpened or flattened.  @notation{Accidentals} are
291 @strong{totally ignored} in the calculation of relative position.
292 Precisely the same staff space counting is done from a note at any
293 other position on the staff.
294
295 To add intervals that are larger than three staff spaces, we can
296 raise the @notation{octave} by adding a single quote @code{'} (or
297 apostrophe) to the note name.  We can lower the octave by adding a
298 comma @code{,} to the note name.
299
300 @lilypond[verbatim,quote]
301 \relative {
302   a' a, c' f,
303   g g'' a,, f'
304 }
305 @end lilypond
306
307 @noindent
308 To change a note by two (or more!) octaves, we use multiple
309 @code{''} or @code{,,} -- but be careful that you use two single
310 quotes @code{''} and not one double quote @code{"}@tie{}!
311 @c " - keeps quotes in order for context-sensitive editor -td
312
313 @node Durations (rhythms)
314 @unnumberedsubsubsec Durations (rhythms)
315
316 @cindex note durations
317 @cindex durations
318 @cindex rhythms
319 @cindex whole note
320 @cindex half note
321 @cindex quarter note
322 @cindex dotted note
323 @cindex notating durations
324
325 Music Glossary: @rglos{beam}, @rglos{duration},
326 @rglos{whole note}, @rglos{half note}, @rglos{quarter note},
327 @rglos{dotted note}.
328
329 The @notation{duration} of a note is specified by a number after
330 the note name:  @code{1} for a @notation{whole note}, @code{2} for
331 a @notation{half note}, @code{4} for a @notation{quarter note} and
332 so on.  @notation{Beams} are added automatically.
333
334 If you do not specify a duration, the previous duration is used
335 for the next note.  The duration of the first note defaults to a
336 quarter note.
337
338 @lilypond[verbatim,quote]
339 \relative {
340   a'1
341   a2 a4 a8 a
342   a16 a a a a32 a a a a64 a a a a a a a a2
343 }
344 @end lilypond
345
346 To create @notation{dotted notes}, add a dot @code{.} to the
347 duration number.  The duration of a dotted note must be stated
348 explicitly (i.e., with a number).
349
350 @lilypond[verbatim,quote]
351 \relative {
352   a'4 a a4. a8
353   a8. a16 a a8. a8 a4.
354 }
355 @end lilypond
356
357 @node Rests
358 @unnumberedsubsubsec Rests
359
360 @cindex rest
361 @cindex notating rests
362
363 Music Glossary: @rglos{rest}.
364
365 A @notation{rest} is entered just like a note with the name
366 @code{r}@tie{}:
367
368 @lilypond[verbatim,quote]
369 \relative {
370   a'4 r r2
371   r8 a r4 r4. r8
372 }
373 @end lilypond
374
375
376 @node Time signature
377 @unnumberedsubsubsec Time signature
378
379 @cindex time signature
380
381 @funindex \time
382 @funindex time
383
384 Music Glossary: @rglos{time signature}.
385
386 The @notation{time signature} can be set with the @code{\time}
387 command:
388
389 @lilypond[verbatim,quote]
390 \relative {
391   \time 3/4
392   a'4 a a
393   \time 6/8
394   a4. a
395   \time 4/4
396   a4 a a a
397 }
398 @end lilypond
399
400 @node Tempo marks
401 @unnumberedsubsubsec Tempo marks
402
403 @cindex tempo marks
404 @cindex metronome marks
405
406 @funindex \tempo
407 @funindex tempo
408
409 Music Glossary: @rglos{tempo indication}, @rglos{metronome}.
410
411 The @notation{tempo indication} and @notation{metronome mark} can be
412 set with the @code{\tempo} command:
413
414 @lilypond[verbatim,quote]
415 \relative {
416   \time 3/4
417   \tempo "Andante"
418   a'4 a a
419   \time 6/8
420   \tempo 4. = 96
421   a4. a
422   \time 4/4
423   \tempo  "Presto" 4 = 120
424   a4 a a a
425 }
426 @end lilypond
427
428
429 @node Clef
430 @unnumberedsubsubsec Clef
431
432 @cindex clef
433 @cindex treble
434 @cindex alto
435 @cindex tenor
436 @cindex bass
437
438 @funindex \clef
439 @funindex clef
440
441 Music Glossary: @rglos{clef}.
442
443 The @notation{clef} can be set using the @code{\clef} command:
444
445 @lilypond[verbatim,quote]
446 \relative {
447   \clef "treble"
448   c'1
449   \clef "alto"
450   c1
451   \clef "tenor"
452   c1
453   \clef "bass"
454   c1
455 }
456 @end lilypond
457
458
459 @node All together
460 @unnumberedsubsubsec All together
461
462 Here is a small example showing all these elements together:
463
464 @lilypond[verbatim,quote]
465 \relative {
466   \clef "bass"
467   \time 3/4
468   \tempo "Andante" 4 = 120
469   c,2 e8 c'
470   g'2.
471   f4 e d
472   c4 c, r
473 }
474 @end lilypond
475
476
477 @seealso
478 Notation Reference: @ruser{Writing pitches},
479 @ruser{Writing rhythms}, @ruser{Writing rests},
480 @ruser{Time signature}, @ruser{Clef}.
481
482
483 @node Working on input files
484 @subsection Working on input files
485
486 @cindex curly braces
487 @cindex braces, curly
488 @cindex comments
489 @cindex line comment
490 @cindex comment, line
491 @cindex block comment
492 @cindex comment, line
493 @cindex case sensitive
494 @cindex whitespace insensitive
495 @cindex expressions
496 @cindex versioning
497 @cindex version
498 @cindex version number
499
500 @funindex \version
501 @funindex { ... }
502 @funindex %
503 @funindex %@{ ... %@}
504
505 LilyPond input files are similar to source files in many common
506 programming languages.  They contain a version statement, are case
507 sensitive, and white-space is generally ignored.  Expressions are
508 formed with curly braces @w{@code{@{ @}}}, and comments are
509 denoted with @code{%} or @w{@code{%@{ @dots{} %@}}}@tie{}.
510
511 If the previous sentences sound like nonsense, don't worry!  We'll
512 explain what all these terms mean:
513
514 @itemize
515
516 @item
517 @strong{Version statement}:
518 Every LilyPond file should contain a version statement.  A version
519 statement is a line that describes the version of LilyPond for which
520 the file was written, as in the following example:
521
522 @example
523 \version "@w{@version{}}"
524 @end example
525
526 By convention, the version statement is placed at the top of the
527 LilyPond file.
528
529 The version statement is important for at least two reasons.  First,
530 it allows automatic updating of the input file as LilyPond syntax
531 changes.  Second, it describes the version of LilyPond needed to
532 compile the file.
533
534 If the version statement is omitted from an input file, LilyPond will print
535 a warning during the compilation of the file.
536
537 @item
538 @strong{Case sensitive}:
539 it matters whether you enter a letter in lower case (e.g.
540 @w{@code{a, b, s, t}}) or upper case (e.g. @w{@code{A, B, S, T}}).
541 Notes are lower case: @w{@samp{@{ c d e @}}} is valid input;
542 @w{@samp{@{ C D E @}}} will produce an error message.
543
544 @item
545 @strong{Whitespace insensitive}:
546 it does not matter how many spaces (or tabs or new lines) you add.
547 @w{@samp{@{ c4 d e @}}} means the same thing as
548 @w{@samp{@{ c4 @tie{} @tie{} @tie{} d e @}}} and:
549
550 @example
551 @{ c4                       d
552                    e   @}
553 @end example
554
555 @noindent
556 Of course, the previous example is hard to read.  A good rule of
557 thumb is to indent code blocks with two spaces:
558
559 @example
560 @{
561   c4 d e
562 @}
563 @end example
564
565 However, whitespace @emph{is} required to separate many
566 syntactical elements from others.  In other words, whitespace can
567 always be @emph{added}, but not always @emph{eliminated}.  Since
568 missing whitespace can give rise to strange errors, it is
569 advisable to always insert whitespace before and after every
570 syntactic element, for example, before and after every curly
571 brace.
572
573 @item
574 @strong{Expressions}:
575 every piece of LilyPond input needs to have
576 @strong{@{@tie{}curly@tie{}braces@tie{}@}} placed around the
577 input.  These braces tell LilyPond that the input is a single
578 music expression, just like parentheses @code{()} in mathematics.
579 The braces should be surrounded by a space unless they are at the
580 beginning or end of a line to avoid ambiguities.
581
582 A LilyPond command followed by a simple expression in braces (such
583 as @q{@w{@code{@bs{}relative @{ @dots{} @}}}}) also counts as a
584 single music expression.
585
586 @cindex comments
587 @cindex line comment
588 @cindex block comment
589 @item
590 @strong{Comments}:
591 a comment is a remark for the human reader of the music input; it
592 is ignored while parsing, so it has no effect on the printed
593 output.  There are two types of comments.  The percent symbol
594 @code{%} introduces a line comment; anything after @code{%} on
595 that line is ignored.  By convention, a line comment is placed
596 @emph{above} the code it refers to.
597
598 @example
599 a4 a a a
600 % this comment refers to the Bs
601 b2 b
602 @end example
603
604 A block comment marks a whole section of music input as a comment.
605 Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
606 However, block comments do not @q{nest}.  This means that you
607 cannot place a block comment inside another block comment.  If you
608 try, the first @code{%@}} will terminate @emph{both} block
609 comments.  The following fragment shows possible uses for
610 comments:
611
612 @example
613 % notes for twinkle twinkle follow
614   c4 c g' g a a g2
615
616 %@{
617   This line, and the notes below are ignored,
618   since they are in a block comment.
619
620   f4 f e e d d c2
621 %@}
622 @end example
623
624 @end itemize
625
626
627 @node Dealing with errors
628 @section Dealing with errors
629
630 @cindex troubleshooting
631
632 Sometimes LilyPond doesn't produce the output you expect.  This
633 section provides some links to help you solve the problems you
634 might encounter.
635
636
637 @menu
638 * General troubleshooting tips::
639 * Some common errors::
640 @end menu
641
642 @node General troubleshooting tips
643 @subsection General troubleshooting tips
644
645 Troubleshooting LilyPond problems can be challenging for
646 people who are used to a graphical interface, because invalid
647 input files can be created.  When this happens, a logical approach
648 is the best way to identify and solve the problem.  Some guidelines
649 to help you learn to do this are provided in @rprogram{Troubleshooting}.
650
651
652 @node Some common errors
653 @subsection Some common errors
654
655 @cindex common errors
656 @cindex errors, common
657
658 There are a few common errors that are difficult to troubleshoot
659 based simply on the error messages that are displayed.  These are
660 described in @rprogram{Common errors}.
661
662
663
664 @node How to read the manuals
665 @section How to read the manuals
666
667 This section shows how to read the documentation efficiently, and
668 also introduces some useful interactive features available in the
669 online version.
670
671 @menu
672 * Omitted material::
673 * Clickable examples::
674 * Overview of manuals::
675 @end menu
676
677
678 @node Omitted material
679 @subsection Omitted material
680
681
682 @cindex how to read the manual
683 @cindex manual, reading
684 @cindex reading the manual
685 @cindex examples, clickable
686 @cindex clickable examples
687 @cindex tips for constructing files
688 @cindex templates
689 @cindex constructing files, tips
690 @cindex files, tips for constructing
691
692 LilyPond input must be surrounded by @code{@{ @}} marks or a
693 @q{@w{@code{@bs{}relative @{ @dots{} @}}}}, as we saw in
694 @ref{Working on input files}.  For the rest of this manual,
695 some short examples will omit this.  To replicate these examples,
696 you can copy displayed input, but paste it between @code{@{}
697 and @code{@}} in your input file.
698
699 @example
700 @{
701   @dots{}example goes here@dots{}
702 @}
703 @end example
704
705 Also, remember that every LilyPond file should have a
706 @code{\version} statement.  Because the examples in the manuals
707 are snippets, not files, the @code{\version} statement is omitted.
708 But you should make a practice of including them in your files.
709
710 @node Clickable examples
711 @subsection Clickable examples
712
713 @warning{This feature is only available in the HTML manuals.}
714
715 Many people learn programs by trying and fiddling around with the
716 program.  This is also possible with LilyPond.  If you click on a
717 picture in the HTML version of this manual, you will see the exact
718 LilyPond input that was used to generate that image.  Try it on
719 this image:
720
721 @c no verbatim here
722 @lilypond[quote]
723 \relative {
724   c''4-\markup { \bold \huge { Click here. } }
725 }
726 @end lilypond
727
728 By cutting and pasting everything in the @qq{ly snippet} section,
729 you have a starting template for experiments.  To see exactly the
730 same output (line-width and all), copy everything from @qq{Start
731 cut-&-pastable section} to the bottom of the file.
732
733
734 @ignore
735 This is item 825
736
737 @n ode Keyboard navigation
738 @s ubsection Keyboard navigation
739
740 @warning{This features is only available in the HTML manuals.}
741
742 @c TODO: once this is figured out, insert it here.
743
744 We are currently working on this feature.
745 @end ignore
746
747 @node Overview of manuals
748 @subsection Overview of manuals
749
750 There is a lot of documentation for LilyPond.  New users are
751 sometimes confused about what part(s) they should read, and
752 occasionally skip over reading vital portions.
753
754 @warning{Please do not skip over important parts of the
755 documentation.  You will find it much harder to understand later
756 sections.}
757
758 @itemize
759
760 @item
761 @strong{Before trying to do @emph{anything}}: read the Learning
762 manual's @ref{Tutorial}, and @ref{Common notation}.  If you
763 encounter musical terms which you do not recognize, please look
764 them up in the @rglosnamed{Top, Glossary}.
765
766 @item
767 @strong{Before trying to write a complete piece of music}: read
768 the Learning manual's @ref{Fundamental concepts}.  After that, you
769 may want to look in relevant sections of the
770 @rusernamed{Top, Notation reference}.
771
772 @item
773 @strong{Before trying to change the default output}: read the
774 Learning manual's @ref{Tweaking output}.
775
776 @item
777 @strong{Before undertaking a large project}: read the Usage
778 document's @rprogram{Suggestions for writing files}.
779
780 @end itemize
781
782
783