]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/generating.itely
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[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 * Advanced 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{Advanced 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 Advanced editors
185 @section Advanced editors
186
187 FIXME: add text
188
189 @menu
190 * Denemo::                      
191 * LilyPondTool::                
192 * Emacs::                       
193 * Vim::                         
194 @end menu
195
196
197 @node Denemo
198 @subsection Denemo
199
200 Available on:
201
202
203
204 @node LilyPondTool
205 @subsection LilyPondTool
206
207 Available on:
208
209
210 @node Emacs
211 @subsection Emacs
212
213 Available on: Windows, MacOS X, Unix
214
215
216 @node Vim
217 @subsection Vim
218
219 Available on: Windows, MacOS X, Unix
220
221
222
223
224 @node How to write input files
225 @section How to write input files
226
227 FIXME: insert text
228
229 @menu
230 * Simple notation::             
231 * Working on input files::      
232 @end menu
233
234
235 @node Simple notation
236 @subsection Simple notation
237
238 @cindex simple notation
239 @cindex notation, simple
240
241 LilyPond will add some notation elements automatically.  In the
242 next example, we have only specified four pitches, but LilyPond
243 has added a clef, time signature, and rhythms.
244
245 @lilypond[verbatim,quote]
246 {
247   c' e' g' e'
248 }
249 @end lilypond
250
251 @noindent
252 This behavior may be altered, but in most cases these automatic
253 values are useful.
254
255
256 @subheading Pitches
257
258 @cindex pitches
259 @cindex relative mode
260 @cindex quote, single
261 @cindex comma
262 @cindex accidentals and relative mode
263 @cindex relative mode, and accidentals
264
265 @funindex \relative
266 @funindex relative
267 @funindex '
268 @funindex ,
269
270 Music Glossary: @rglos{pitch}, @rglos{interval},
271 @rglos{scale}, @rglos{middle C}, @rglos{octave},
272 @rglos{accidental}.
273
274 The easiest way to enter notes is by using @code{\relative} mode.
275 In this mode, the octave is chosen automatically by assuming the
276 following note is always to be placed closest to the previous
277 note, i.e., it is to be placed in the octave which is within three
278 staff spaces of the previous note.  We begin by entering the most
279 elementary piece of music, a @notation{scale}, in which every note
280 is within just one staff space of the previous note.
281
282 @lilypond[verbatim,quote]
283 % set the starting point to middle C
284 \relative c' {
285   c d e f
286   g a b c
287 }
288 @end lilypond
289
290 The initial note is @notation{middle C}.  Each successive note is
291 placed closest to the previous note -- in other words, the first
292 @code{c} is the closest C to middle C.  This is followed by the
293 closest D to the previous note.  We can create melodies which have
294 larger intervals, still using only @code{\relative} mode:
295
296 @lilypond[verbatim,quote]
297 \relative c' {
298   d f a g
299   c b f d
300 }
301 @end lilypond
302
303 @noindent
304 It is not necessary for the first note of the melody to start on
305 the note which specifies the starting pitch.  In the previous
306 example, the first note -- the @code{d} -- is the closest D to
307 middle C.
308
309 By adding (or removing) quotes @code{'} or commas @code{,} from
310 the @code{@w{\relative c' @{}} command, we can change the starting
311 octave:
312
313 @lilypond[verbatim,quote]
314 % one octave above middle C
315 \relative c'' {
316   e c a c
317 }
318 @end lilypond
319
320 Relative mode can be confusing initially, but is the easiest way
321 to enter most melodies.  Let us see how this relative calculation
322 works in practice.  Starting from a B, which is on the middle line
323 in a treble clef, you can reach a C, D and E within 3 staff spaces
324 going up, and an A, G and F within 3 staff spaces going down.  So
325 if the note following a B is a C, D or E it will be assumed to be
326 above the B, and an A, G or F will be assumed to be below.
327
328 @lilypond[verbatim,quote]
329 \relative c'' {
330   b c  % c is 1 staff space up, so is the c above
331   b d  % d is 2 up or 5 down, so is the d above
332   b e  % e is 3 up or 4 down, so is the e above
333   b a  % a is 6 up or 1 down, so is the a below
334   b g  % g is 5 up or 2 down, so is the g below
335   b f  % f is 4 up or 3 down, so is the f below
336 }
337 @end lilypond
338
339 Exactly the same happens even when any of these notes are
340 sharpened or flattened.  @notation{Accidentals} are
341 @strong{totally ignored} in the calculation of relative position.
342 Precisely the same staff space counting is done from a note at any
343 other position on the staff.
344
345 To add intervals that are larger than three staff spaces, we can
346 raise the @notation{octave} by adding a single quote @code{'} (or
347 apostrophe) to the note name.  We can lower the octave by adding a
348 comma @code{,} to the note name.
349
350 @lilypond[verbatim,quote]
351 \relative c'' {
352   a a, c' f,
353   g g'' a,, f'
354 }
355 @end lilypond
356
357 @noindent
358 To change a note by two (or more!) octaves, we use multiple
359 @code{''} or @code{,,} -- but be careful that you use two single
360 quotes @code{''} and not one double quote @code{"}@tie{}!  The
361 initial value in @code{@w{\relative c'}} may also be modified like
362 this.
363 @c " - keeps quotes in order for context-sensitive editor -td
364
365 @subheading Durations (rhythms)
366
367 @cindex note durations
368 @cindex durations
369 @cindex rhythms
370 @cindex whole note
371 @cindex half note
372 @cindex quarter note
373 @cindex dotted note
374 @cindex notating durations
375
376 Music Glossary: @rglos{beam}, @rglos{duration},
377 @rglos{whole note}, @rglos{half note}, @rglos{quarter note},
378 @rglos{dotted note}.
379
380 The @notation{duration} of a note is specified by a number after
381 the note name:  @code{1} for a @notation{whole note}, @code{2} for
382 a @notation{half note}, @code{4} for a @notation{quarter note} and
383 so on.  @notation{Beams} are added automatically.
384
385 If you do not specify a duration, the previous duration is used
386 for the next note.  The duration of the first note defaults to a
387 quarter.
388
389 @lilypond[verbatim,quote]
390 \relative c'' {
391   a1
392   a2 a4 a8 a
393   a16 a a a a32 a a a a64 a a a a a a a a2
394 }
395 @end lilypond
396
397 To create @notation{dotted notes}, add a dot @code{.} to the
398 duration number.  The duration of a dotted note must be stated
399 explicitly (i.e., with a number).
400
401 @lilypond[verbatim,quote]
402 \relative c'' {
403   a a a4. a8
404   a8. a16 a a8. a8 a4.
405 }
406 @end lilypond
407
408
409 @subheading Rests
410
411 @cindex rest
412 @cindex notating rests
413
414 Music Glossary: @rglos{rest}.
415
416 A @notation{rest} is entered just like a note with the name
417 @code{r}@tie{}:
418
419 @lilypond[verbatim,quote]
420 \relative c'' {
421   a r r2
422   r8 a r4 r4. r8
423 }
424 @end lilypond
425
426
427 @subheading Time signature
428
429 @cindex time signature
430
431 @funindex \time
432 @funindex time
433
434 Music Glossary: @rglos{time signature}.
435
436 The @notation{time signature} can be set with the @code{\time}
437 command:
438
439 @lilypond[verbatim,quote]
440 \relative c'' {
441   \time 3/4
442   a4 a a
443   \time 6/8
444   a4. a
445   \time 4/4
446   a4 a a a
447 }
448 @end lilypond
449
450
451 @subheading Clef
452
453 @cindex clef
454 @cindex treble
455 @cindex alto
456 @cindex tenor
457 @cindex bass
458
459 @funindex \clef
460 @funindex clef
461
462 Music Glossary: @rglos{clef}.
463
464 The @notation{clef} can be set using the @code{\clef} command:
465
466 @lilypond[verbatim,quote]
467 \relative c' {
468   \clef treble
469   c1
470   \clef alto
471   c1
472   \clef tenor
473   c1
474   \clef bass
475   c1
476 }
477 @end lilypond
478
479
480 @subheading All together
481
482 Here is a small example showing all these elements together:
483
484 @lilypond[verbatim,quote]
485 \relative c, {
486   \time 3/4
487   \clef bass
488   c2 e8 c' g'2.
489   f4 e d c4 c, r4
490 }
491 @end lilypond
492
493
494 @seealso
495 Notation Reference: @ruser{Writing pitches},
496 @ruser{Writing rhythms}, @ruser{Writing rests},
497 @ruser{Time signature}, @ruser{Clef}.
498
499
500 @node Working on input files
501 @subsection Working on input files
502
503 @cindex curly braces
504 @cindex braces, curly
505 @cindex comments
506 @cindex line comment
507 @cindex comment, line
508 @cindex block comment
509 @cindex comment, line
510 @cindex case sensitive
511 @cindex whitespace insensitive
512 @cindex expressions
513
514 @funindex { ... }
515 @funindex %
516 @funindex %@{ ... %@}
517
518 LilyPond input files are similar to source files in many common
519 programming languages.  They are case sensitive, and white-space
520 is generally ignored.  Expressions are formed with curly braces
521 @{ @}, and comments are denoted with @code{%} or
522 @w{@code{%@{ ... %@}}}.
523
524 If the previous sentences sound like nonsense, don't worry!  We'll
525 explain what all these terms mean:
526
527 @itemize
528
529 @item
530 @strong{Case sensitive}:
531 it matters whether you enter a letter in lower case (e.g.
532 @w{@code{a, b, s, t}}) or upper case (e.g.  @w{@code{A, B, S, T}}).
533 Notes are lower case: @w{@code{@{ c d e @}}} is valid input;
534 @w{@code{@{ C D E @}}} will produce an error message.
535
536 @item
537 @strong{Whitespace insensitive}:
538 it does not matter how many spaces (or tabs or new lines) you add.
539 @w{@code{@{ c d e @}}} means the same thing as
540 @w{@code{@{ c @tie{}} @tie{} @tie{} d e @}} and:
541
542 @example
543 @{ c                        d
544                    e   @}
545 @end example
546
547 @noindent
548 Of course, the previous example is hard to read.  A good rule of
549 thumb is to indent code blocks with either a tab or two spaces:
550
551 @example
552 @{
553   c d e
554 @}
555 @end example
556
557 However, whitespace @emph{is} required to separate many syntactical
558 elements from others.  In other words, whitespace can always be
559 @emph{added}, but it cannot be @emph{eliminated}.  As missing
560 whitespace can give rise to strange errors it is advisable to
561 always insert whitespace before and after every syntactic element,
562 for example, before and after every curly brace.
563
564 @item
565 @strong{Expressions}:
566 every piece of LilyPond input needs to have @strong{@{ curly
567 braces @}} placed around the input.  These braces tell LilyPond
568 that the input is a single music expression, just like parentheses
569 @code{()} in mathematics.  The braces should be surrounded by a
570 space unless they are at the beginning or end of a line to avoid
571 ambiguities.
572
573 A LilyPond command followed by a simple expression in braces (such
574 as @w{@code{\relative @{ @}}}) also counts as a single music
575 expression.
576
577 @cindex comments
578 @cindex line comment
579 @cindex block comment
580 @item
581 @strong{Comments}:
582 a comment is a remark for the human reader of the music input; it
583 is ignored while parsing, so it has no effect on the printed
584 output.  There are two types of comments.  The percent symbol
585 @code{%} introduces a line comment; anything after @code{%} on
586 that line is ignored.  By convention, a line comment is placed
587 @emph{above} the code it refers to.
588
589 @example
590 a4 a a a
591 % this comment refers to the Bs
592 b2 b
593 @end example
594
595 A block comment marks a whole section of music input as a comment.
596 Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
597 However, block comments do not @q{nest}.  This means that you
598 cannot place a block comment inside another block comment.  If you
599 try, the first @code{%@}} will terminate @emph{both} block
600 comments.  The following fragment shows possible uses for
601 comments:
602
603 @example
604 % notes for twinkle twinkle follow
605   c4 c g' g a a g2
606
607 %@{
608   This line, and the notes below are ignored,
609   since they are in a block comment.
610
611   f f e e d d c2
612 %@}
613 @end example
614
615 @end itemize
616
617
618 @node How to read the manuals
619 @section How to read the manuals
620
621 FIXME: fluff here
622
623 @menu
624 * Omitting braces::             
625 * Clickable examples::          
626 * Overview of manuals::         
627 @end menu
628
629
630 @node Omitting braces
631 @unnumberedsubsec Omitting braces
632
633
634 @cindex how to read the manual
635 @cindex manual, reading
636 @cindex reading the manual
637 @cindex examples, clickable
638 @cindex clickable examples
639 @cindex tips for constructing files
640 @cindex templates
641 @cindex constructing files, tips
642 @cindex files, tips for constructing
643
644 LilyPond input must be surrounded by @{ @} marks or a
645 @code{@w{\relative c'' @{ ... @}}}, as we saw in @ref{Working on
646 input files}.  For the rest of this manual, most examples will
647 omit this.  To replicate the examples, you may copy and paste the
648 displayed input, but you @strong{must} add the
649 @code{@w{\relative c'' @{ @}}} like this:
650
651 @example
652 \relative c'' @{
653   ... example goes here...
654 @}
655 @end example
656
657 Why omit the braces?  Most examples in this manual can be inserted
658 into the middle of a longer piece of music.  For these examples,
659 it does not make sense to add @code{@w{\relative c'' @{ @}}} --
660 you should not place a @code{\relative} inside another
661 @code{\relative}!  If we included @code{@w{\relative c'' @{ @}}}
662 around every example, you would not be able to copy a small
663 documentation example and paste it inside a longer piece of your
664 own.  Most people want to add material to an existing piece, so we
665 format the manual this way.
666
667
668 @node Clickable examples
669 @unnumberedsubsec Clickable examples
670
671 Many people learn programs by trying and fiddling around with the
672 program.  This is also possible with LilyPond.  If you click on a
673 picture in the HTML version of this manual, you will see the exact
674 LilyPond input that was used to generate that image.  Try it on
675 this image:
676
677 @c no verbatim here
678 @lilypond[quote]
679 \relative c'' {
680   c-\markup { \bold \huge { Click here.  } }
681 }
682 @end lilypond
683
684 By cutting and pasting everything in the @qq{ly snippet} section,
685 you have a starting template for experiments.  To see exactly the
686 same output (line-width and all), copy everything from @qq{Start
687 cut-&-pastable section} to the bottom of the file.
688
689
690
691 @node Overview of manuals
692 @unnumberedsubsec Overview of manuals
693
694 FIXME: a brief discussion about the rest of the LM, and pointers
695 to specific places.  like NR for general reference, AU for
696 suggestions for writing files, etc.
697
698