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