]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/introduction.itely
Doc-de: updates from master to NR
[lilypond.git] / Documentation / learning / introduction.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.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.12.0"
11
12 @node Introduction
13 @chapter Introduction
14
15 This chapter gives a basic introduction to working with LilyPond.
16
17 @menu
18 * Compiling a file::            
19 * How to write input files::    
20 * How to read the manuals::     
21 @end menu
22
23 @node Compiling a file
24 @section Compiling a file
25
26 FIXME: insert text
27
28 @menu
29 * Entering input::              
30 * MacOS X::                     
31 * Windows::                     
32 * Command-line::                
33 @end menu
34
35 @node Entering input
36 @subsection Entering input
37
38 @cindex compiling
39 @cindex first example
40 @cindex example, first
41 @cindex case sensitive
42
43 @qq{Compiling} is the term used for processing an input file
44 in LilyPond format to produce a file which can be printed and
45 (optionally) a MIDI file which can be played.  LilyPond input
46 files are simple text files.  The first example
47 shows what a simple input file looks like.
48
49 To create sheet music, we write an input file that specifies the
50 notation.  For example, if we write:
51
52 @example
53 @{
54   c' e' g' e'
55 @}
56 @end example
57
58 @noindent
59 the result looks like this:
60
61 @c  in this case we don't want verbatim
62 @lilypond[quote]
63 {
64   c' e' g' e'
65 }
66 @end lilypond
67
68 @warning{Notes and lyrics in LilyPond input must always be
69 surrounded by @strong{@{ curly braces @}}.  The braces
70 should also be surrounded by a space unless they are at the
71 beginning or end of a line to avoid ambiguities.  The braces may
72 be omitted in some examples in this manual, but don't forget them
73 in your own music!  For more information about the display of
74 examples in the manual, see @ref{How to read the manuals}.}
75
76 In addition, LilyPond input is @strong{case sensitive}.
77 @w{@code{@{ c d e @}}} is valid input; @w{@code{@{ C D E @}}} will
78 produce an error message.
79
80 @smallspace
81
82 @subheading Entering music and viewing output
83
84 @cindex PDF file
85 @cindex viewing music
86 @cindex text editors
87 @cindex running LilyPond under MacOS X
88 @cindex MacOS X, running LilyPond
89 @cindex running LilyPond under Windows
90 @cindex Windows, running LilyPond
91 @cindex running LilyPond under Unix
92 @cindex Unix, running LilyPond
93
94 In this section we will explain what commands to run and how to
95 view or print the output.
96
97 Note that there are several other text editors available with
98 better support for LilyPond.  For more information, see
99 @rgeneral{Alternate input}.
100
101 @warning{The first time you ever run LilyPond, it may take a
102 minute or two because all of the system fonts have to be analyzed
103 first.  After this, LilyPond will be much faster!}
104
105
106 @node MacOS X
107 @subsection MacOS X
108
109 @warning{These instructions assume that you are using the built-in
110 LilyPad editor.  If you are using any of the programs described in
111 @rgeneral{Alternate input}, please consult the documentation for
112 those programs if you have any problems compiling a file.}
113
114
115 If you double click @command{LilyPond.app}, it will open with an
116 example file.  Save it, for example, to @file{test.ly} on your
117 Desktop, and then process it with the menu command
118 @w{@code{Compile > Typeset File}}.  The resulting PDF file will be
119 displayed on your screen.
120
121 For future use of LilyPond, you should begin by selecting @q{New}
122 or @q{Open}.  You must save your file before typesetting it.  If
123 any errors occur in processing, please see the log window.
124
125
126 @node Windows
127 @subsection Windows
128
129 @warning{These instructions assume that you are using the built-in
130 LilyPad editor.  If you are using any of the programs described in
131 @rgeneral{Alternate input}, please consult the documentation for
132 programs if you have any problems compiling a file.}
133
134 On Windows, if you double-click in the LilyPond icon on the
135 Desktop, it will open a simple text editor with an example file.
136 Save it, for example, to @file{test.ly} on your Desktop and then
137 double-click on the file to process it (the file icon looks like a
138 note).  After some seconds, you will get a file @file{test.pdf} on
139 your desktop.  Double-click on this PDF file to view the typeset
140 score.  An alternative method to process the @file{test.ly} file
141 is to drag and drop it onto the LilyPond icon using your mouse
142 pointer.
143
144 To edit an existing @file{.ly} file, right-click on it and
145 select @qq{Edit source}.  To get an empty file to start from, run
146 the editor as described above and use @qq{New} in
147 the @qq{File} menu, or right-click on the desktop and select
148 @qq{New..Text Document}, change its name to a name of your choice
149 and change the file extension to @code{.ly}.  Double-click the
150 icon to type in your LilyPond source code as before.
151
152 Double-clicking the file does not only result in a PDF file, but
153 also produces a @file{.log} file that contains some information on
154 what LilyPond has done to the file.  If any errors occur, please
155 examine this file.
156
157
158 @node Command-line
159 @subsection Command-line
160
161 @warning{These instructions assume that you are using the built-in
162 LilyPad editor.  If you are using any of the programs described in
163 @rgeneral{Alternate input}, please consult the documentation for
164 programs if you have any problems compiling a file.}
165
166
167 Create a text file called @file{test.ly} and enter:
168
169 @example
170 @{
171   c' e' g' e'
172 @}
173 @end example
174
175 To process @file{test.ly}, proceed as follows:
176
177 @example
178 lilypond test.ly
179 @end example
180
181 @noindent
182 You will see something resembling:
183
184 @example
185 lilypond test.ly
186 GNU LilyPond @version{}
187 Processing `test.ly'
188 Parsing...
189 Interpreting music...
190 Preprocessing graphical objects...
191 Finding the ideal number of pages...
192 Fitting music on 1 page...
193 Drawing systems...
194 Layout output to `test.ps'...
195 Converting to `test.pdf'...
196 @end example
197
198
199
200 @node How to write input files
201 @section How to write input files
202
203 FIXME: insert text
204
205 @menu
206 * Simple notation::             
207 * Working on input files::      
208 @end menu
209
210
211 @node Simple notation
212 @subsection Simple notation
213
214 @cindex simple notation
215 @cindex notation, simple
216
217 LilyPond will add some notation elements automatically.  In the
218 next example, we have only specified four pitches, but LilyPond
219 has added a clef, time signature, and rhythms.
220
221 @lilypond[verbatim,quote]
222 {
223   c' e' g' e'
224 }
225 @end lilypond
226
227 @noindent
228 This behavior may be altered, but in most cases these automatic
229 values are useful.
230
231
232 @subheading Pitches
233
234 @cindex pitches
235 @cindex relative mode
236 @cindex quote, single
237 @cindex comma
238 @cindex accidentals and relative mode
239 @cindex relative mode, and accidentals
240
241 @funindex \relative
242 @funindex relative
243 @funindex '
244 @funindex ,
245
246 Music Glossary: @rglos{pitch}, @rglos{interval},
247 @rglos{scale}, @rglos{middle C}, @rglos{octave},
248 @rglos{accidental}.
249
250 The easiest way to enter notes is by using @code{\relative} mode.
251 In this mode, the octave is chosen automatically by assuming the
252 following note is always to be placed closest to the previous
253 note, i.e., it is to be placed in the octave which is within three
254 staff spaces of the previous note.  We begin by entering the most
255 elementary piece of music, a @notation{scale}, in which every note
256 is within just one staff space of the previous note.
257
258 @lilypond[verbatim,quote]
259 % set the starting point to middle C
260 \relative c' {
261   c d e f
262   g a b c
263 }
264 @end lilypond
265
266 The initial note is @notation{middle C}.  Each successive note is
267 placed closest to the previous note -- in other words, the first
268 @code{c} is the closest C to middle C.  This is followed by the
269 closest D to the previous note.  We can create melodies which have
270 larger intervals, still using only @code{\relative} mode:
271
272 @lilypond[verbatim,quote]
273 \relative c' {
274   d f a g
275   c b f d
276 }
277 @end lilypond
278
279 @noindent
280 It is not necessary for the first note of the melody to start on
281 the note which specifies the starting pitch.  In the previous
282 example, the first note -- the @code{d} -- is the closest D to
283 middle C.
284
285 By adding (or removing) quotes @code{'} or commas @code{,} from
286 the @code{@w{\relative c' @{}} command, we can change the starting
287 octave:
288
289 @lilypond[verbatim,quote]
290 % one octave above middle C
291 \relative c'' {
292   e c a c
293 }
294 @end lilypond
295
296 Relative mode can be confusing initially, but is the easiest way
297 to enter most melodies.  Let us see how this relative calculation
298 works in practice.  Starting from a B, which is on the middle line
299 in a treble clef, you can reach a C, D and E within 3 staff spaces
300 going up, and an A, G and F within 3 staff spaces going down.  So
301 if the note following a B is a C, D or E it will be assumed to be
302 above the B, and an A, G or F will be assumed to be below.
303
304 @lilypond[verbatim,quote]
305 \relative c'' {
306   b c  % c is 1 staff space up, so is the c above
307   b d  % d is 2 up or 5 down, so is the d above
308   b e  % e is 3 up or 4 down, so is the e above
309   b a  % a is 6 up or 1 down, so is the a below
310   b g  % g is 5 up or 2 down, so is the g below
311   b f  % f is 4 up or 3 down, so is the f below
312 }
313 @end lilypond
314
315 Exactly the same happens even when any of these notes are
316 sharpened or flattened.  @notation{Accidentals} are
317 @strong{totally ignored} in the calculation of relative position.
318 Precisely the same staff space counting is done from a note at any
319 other position on the staff.
320
321 To add intervals that are larger than three staff spaces, we can
322 raise the @notation{octave} by adding a single quote @code{'} (or
323 apostrophe) to the note name.  We can lower the octave by adding a
324 comma @code{,} to the note name.
325
326 @lilypond[verbatim,quote]
327 \relative c'' {
328   a a, c' f,
329   g g'' a,, f'
330 }
331 @end lilypond
332
333 @noindent
334 To change a note by two (or more!) octaves, we use multiple
335 @code{''} or @code{,,} -- but be careful that you use two single
336 quotes @code{''} and not one double quote @code{"}@tie{}!  The
337 initial value in @code{@w{\relative c'}} may also be modified like
338 this.
339 @c " - keeps quotes in order for context-sensitive editor -td
340
341 @subheading Durations (rhythms)
342
343 @cindex note durations
344 @cindex durations
345 @cindex rhythms
346 @cindex whole note
347 @cindex half note
348 @cindex quarter note
349 @cindex dotted note
350 @cindex notating durations
351
352 Music Glossary: @rglos{beam}, @rglos{duration},
353 @rglos{whole note}, @rglos{half note}, @rglos{quarter note},
354 @rglos{dotted note}.
355
356 The @notation{duration} of a note is specified by a number after
357 the note name:  @code{1} for a @notation{whole note}, @code{2} for
358 a @notation{half note}, @code{4} for a @notation{quarter note} and
359 so on.  @notation{Beams} are added automatically.
360
361 If you do not specify a duration, the previous duration is used
362 for the next note.  The duration of the first note defaults to a
363 quarter.
364
365 @lilypond[verbatim,quote]
366 \relative c'' {
367   a1
368   a2 a4 a8 a
369   a16 a a a a32 a a a a64 a a a a a a a a2
370 }
371 @end lilypond
372
373 To create @notation{dotted notes}, add a dot @code{.} to the
374 duration number.  The duration of a dotted note must be stated
375 explicitly (i.e., with a number).
376
377 @lilypond[verbatim,quote]
378 \relative c'' {
379   a a a4. a8
380   a8. a16 a a8. a8 a4.
381 }
382 @end lilypond
383
384
385 @subheading Rests
386
387 @cindex rest
388 @cindex notating rests
389
390 Music Glossary: @rglos{rest}.
391
392 A @notation{rest} is entered just like a note with the name
393 @code{r}@tie{}:
394
395 @lilypond[verbatim,quote]
396 \relative c'' {
397   a r r2
398   r8 a r4 r4. r8
399 }
400 @end lilypond
401
402
403 @subheading Time signature
404
405 @cindex time signature
406
407 @funindex \time
408 @funindex time
409
410 Music Glossary: @rglos{time signature}.
411
412 The @notation{time signature} can be set with the @code{\time}
413 command:
414
415 @lilypond[verbatim,quote]
416 \relative c'' {
417   \time 3/4
418   a4 a a
419   \time 6/8
420   a4. a
421   \time 4/4
422   a4 a a a
423 }
424 @end lilypond
425
426
427 @subheading Clef
428
429 @cindex clef
430 @cindex treble
431 @cindex alto
432 @cindex tenor
433 @cindex bass
434
435 @funindex \clef
436 @funindex clef
437
438 Music Glossary: @rglos{clef}.
439
440 The @notation{clef} can be set using the @code{\clef} command:
441
442 @lilypond[verbatim,quote]
443 \relative c' {
444   \clef treble
445   c1
446   \clef alto
447   c1
448   \clef tenor
449   c1
450   \clef bass
451   c1
452 }
453 @end lilypond
454
455
456 @subheading All together
457
458 Here is a small example showing all these elements together:
459
460 @lilypond[verbatim,quote]
461 \relative c, {
462   \time 3/4
463   \clef bass
464   c2 e8 c' g'2.
465   f4 e d c4 c, r4
466 }
467 @end lilypond
468
469
470 @seealso
471 Notation Reference: @ruser{Writing pitches},
472 @ruser{Writing rhythms}, @ruser{Writing rests},
473 @ruser{Time signature}, @ruser{Clef}.
474
475
476 @node Working on input files
477 @subsection Working on input files
478
479 @cindex curly braces
480 @cindex braces, curly
481 @cindex comments
482 @cindex line comment
483 @cindex comment, line
484 @cindex block comment
485 @cindex comment, line
486 @cindex case sensitive
487 @cindex whitespace insensitive
488 @cindex expressions
489
490 @funindex { ... }
491 @funindex %
492 @funindex %@{ ... %@}
493
494 LilyPond input files are similar to source files in many common
495 programming languages.  They are case sensitive, and white-space
496 is generally ignored.  Expressions are formed with curly braces
497 @{ @}, and comments are denoted with @code{%} or
498 @w{@code{%@{ ... %@}}}.
499
500 If the previous sentences sound like nonsense, don't worry!  We'll
501 explain what all these terms mean:
502
503 @itemize
504
505 @item
506 @strong{Case sensitive}:
507 it matters whether you enter a letter in lower case (e.g.
508 @w{@code{a, b, s, t}}) or upper case (e.g.  @w{@code{A, B, S, T}}).
509 Notes are lower case: @w{@code{@{ c d e @}}} is valid input;
510 @w{@code{@{ C D E @}}} will produce an error message.
511
512 @item
513 @strong{Whitespace insensitive}:
514 it does not matter how many spaces (or tabs or new lines) you add.
515 @w{@code{@{ c d e @}}} means the same thing as
516 @w{@code{@{ c @tie{}} @tie{} @tie{} d e @}} and:
517
518 @example
519 @{ c                        d
520                    e   @}
521 @end example
522
523 @noindent
524 Of course, the previous example is hard to read.  A good rule of
525 thumb is to indent code blocks with either a tab or two spaces:
526
527 @example
528 @{
529   c d e
530 @}
531 @end example
532
533 However, whitespace @emph{is} required to separate many syntactical
534 elements from others.  In other words, whitespace can always be
535 @emph{added}, but it cannot be @emph{eliminated}.  As missing
536 whitespace can give rise to strange errors it is advisable to
537 always insert whitespace before and after every syntactic element,
538 for example, before and after every curly brace.
539
540 @item
541 @strong{Expressions}:
542 every piece of LilyPond input needs to have @strong{@{ curly
543 braces @}} placed around the input.  These braces tell LilyPond
544 that the input is a single music expression, just like parentheses
545 @code{()} in mathematics.  The braces should be surrounded by a
546 space unless they are at the beginning or end of a line to avoid
547 ambiguities.
548
549 A LilyPond command followed by a simple expression in braces (such
550 as @w{@code{\relative @{ @}}}) also counts as a single music
551 expression.
552
553 @cindex comments
554 @cindex line comment
555 @cindex block comment
556 @item
557 @strong{Comments}:
558 a comment is a remark for the human reader of the music input; it
559 is ignored while parsing, so it has no effect on the printed
560 output.  There are two types of comments.  The percent symbol
561 @code{%} introduces a line comment; anything after @code{%} on
562 that line is ignored.  By convention, a line comment is placed
563 @emph{above} the code it refers to.
564
565 @example
566 a4 a a a
567 % this comment refers to the Bs
568 b2 b
569 @end example
570
571 A block comment marks a whole section of music input as a comment.
572 Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
573 However, block comments do not @q{nest}.  This means that you
574 cannot place a block comment inside another block comment.  If you
575 try, the first @code{%@}} will terminate @emph{both} block
576 comments.  The following fragment shows possible uses for
577 comments:
578
579 @example
580 % notes for twinkle twinkle follow
581   c4 c g' g a a g2
582
583 %@{
584   This line, and the notes below are ignored,
585   since they are in a block comment.
586
587   f f e e d d c2
588 %@}
589 @end example
590
591 @end itemize
592
593
594 @node How to read the manuals
595 @section How to read the manuals
596
597 FIXME: fluff here
598
599 @menu
600 * Omitting braces::             
601 * Clickable examples::          
602 * Keyboard navigation::         
603 * Overview of manuals::         
604 @end menu
605
606
607 @node Omitting braces
608 @unnumberedsubsec Omitting braces
609
610
611 @cindex how to read the manual
612 @cindex manual, reading
613 @cindex reading the manual
614 @cindex examples, clickable
615 @cindex clickable examples
616 @cindex tips for constructing files
617 @cindex templates
618 @cindex constructing files, tips
619 @cindex files, tips for constructing
620
621 LilyPond input must be surrounded by @{ @} marks or a
622 @code{@w{\relative c'' @{ ... @}}}, as we saw in @ref{Working on
623 input files}.  For the rest of this manual, most examples will
624 omit this.  To replicate the examples, you may copy and paste the
625 displayed input, but you @strong{must} add the
626 @code{@w{\relative c'' @{ @}}} like this:
627
628 @example
629 \relative c'' @{
630   ... example goes here...
631 @}
632 @end example
633
634 Why omit the braces?  Most examples in this manual can be inserted
635 into the middle of a longer piece of music.  For these examples,
636 it does not make sense to add @code{@w{\relative c'' @{ @}}} --
637 you should not place a @code{\relative} inside another
638 @code{\relative}!  If we included @code{@w{\relative c'' @{ @}}}
639 around every example, you would not be able to copy a small
640 documentation example and paste it inside a longer piece of your
641 own.  Most people want to add material to an existing piece, so we
642 format the manual this way.
643
644
645 @node Clickable examples
646 @unnumberedsubsec Clickable examples
647
648 Many people learn programs by trying and fiddling around with the
649 program.  This is also possible with LilyPond.  If you click on a
650 picture in the HTML version of this manual, you will see the exact
651 LilyPond input that was used to generate that image.  Try it on
652 this image:
653
654 @c no verbatim here
655 @lilypond[quote]
656 \relative c'' {
657   c-\markup { \bold \huge { Click here.  } }
658 }
659 @end lilypond
660
661 By cutting and pasting everything in the @qq{ly snippet} section,
662 you have a starting template for experiments.  To see exactly the
663 same output (line-width and all), copy everything from @qq{Start
664 cut-&-pastable section} to the bottom of the file.
665
666
667 @node Keyboard navigation
668 @unnumberedsubsec Keyboard navigation
669
670
671
672 @node Overview of manuals
673 @unnumberedsubsec Overview of manuals
674
675 FIXME: a brief discussion about the rest of the LM, and pointers
676 to specific places.  like NR for general reference, AU for
677 suggestions for writing files, etc.
678
679