]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/tutorial.itely
Doc: Added windows w/screenshots to Learning manual
[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.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.12.0"
11
12 @node Tutorial
13 @chapter Tutorial
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 @w{@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.  They 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
81 @smallspace
82
83 @subheading Viewing output
84
85 @c TODO: move index entries
86 @cindex PDF file
87 @cindex viewing music
88 @cindex text editors
89 @cindex running LilyPond under MacOS X
90 @cindex MacOS X, running LilyPond
91 @cindex running LilyPond under Windows
92 @cindex Windows, running LilyPond
93 @cindex running LilyPond under Unix
94 @cindex Unix, running LilyPond
95
96 Producing output depends on your operating system and the
97 program(s) you use.
98
99 @itemize
100
101 @item
102 @ref{MacOS X, @sourceimage{logo-macosx,,,}}
103 @ref{MacOS X, MacOS X} (graphical)
104
105 @item
106 @ref{Windows, @sourceimage{logo-windows,,,}}
107 @ref{Windows, Microsoft Windows} (graphical)
108
109 @item
110 @ref{Command-line, @sourceimage{logo-linux,,,}
111 @sourceimage{logo-freebsd,,,}
112 @sourceimage{logo-macosx,,,}
113 @sourceimage{logo-windows,,,}
114 }
115 @ref{Command-line, All operating systems} (command-line)
116
117 @end itemize
118
119 There are several other text editors available with better support
120 for LilyPond.  For more information, see
121 @rweb{Alternate input}.
122
123 @warning{The first time you ever run LilyPond, it may take a
124 minute or two because all of the system fonts have to be analyzed
125 first.  After this, LilyPond will be much faster!}
126
127
128 @node MacOS X
129 @subsection MacOS X
130
131 @warning{These instructions assume that you are using the Lilypond 
132 application.  If you are using any of the programs described in
133 @rweb{Alternate input}, please consult the documentation for
134 those programs if you have any problems.}
135
136 Double click the @command{LilyPond.app}, an example file will open.
137
138 @sourceimage{Learning_Macos_welcome,,,}
139
140 From the menus along the top left of your screen, select
141 @w{@code{File > Save}}.
142
143 @sourceimage{Learning_Macos_Save_menu,,,}
144
145 Choose a name for your file, for example @file{test.ly}.
146
147 @sourceimage{Learning_Macos_Save_file_with_name,,,}
148
149 From the same menus, select
150 @w{@code{Compile > Tyepset}}.
151
152 @sourceimage{Learning_Macos_Typeset_menu,,,}
153
154 A new window will open showing a progress log of the compilation 
155 of the file you have just saved.
156
157 @sourceimage{Learning_Macos_Compiling_log,,,}
158
159 Once the compilation has finished, a PDF file will be created with
160 the same name as the original file and will be automatically
161 opened in the default PDF viewer and displayed on your screen.
162
163 @sourceimage{Learning_Macos_pdf_output,,,}
164
165 To create new files for LilyPond, begin by selecting
166 @w{@code{File > New}}
167
168 @sourceimage{Learning_Macos_New_menu,,,}
169
170 or @w{@code{File > Open}} to open and edit existing files you have 
171 saved previously.
172
173 @sourceimage{Learning_Macos_Open_menu,,,}
174
175 You must save any new edits you make to your file before you 
176 @w{@code{Compile > Tyepset}} and if the PDF file is not displayed
177 check the window with the progress log for any errors.
178
179 If you are not using the defualt Preview PDF viewer that comes 
180 with the Mac Operating system and you have the PDF file generated 
181 from a previous compilation open, then any further compilations 
182 may fail to generate an update PDF until you close the original.
183
184 @node Windows
185 @subsection Windows
186
187 @warning{These instructions assume that you are using the built-in
188 LilyPad editor.  If you are using any of the programs described in
189 @rweb{Alternate input}, please consult the documentation for
190 those programs if you have any problems compiling a file.}
191
192 Double-click the @command{LilyPond.app}, an example file will open.
193
194 @sourceimage{Learning_Win7_Welcome_File_Whole,,,}
195
196 From the menus that appear alonbg the top of the example file,
197 select @w{@code{File > Save as}}. Do not use the @w{@code{File > Save}}
198 for the example file as this will not work until you have given it a
199 valid Lilypong file name.
200
201 @sourceimage{Learning_Win7_Save_Menu,,,}
202
203 Choose a name for your file, for example @file{test.ly}.
204
205 @sourceimage{Learning_Win7_Save_File_With_Name,,,}
206
207 Depending on what you prefer, to compile your file either:
208
209 Drag-and-drop the file directly onto the LilyPond icon.
210
211 @sourceimage{Learning_Win7_Open_Dragndrop,,,}
212
213 Right-click on the file and from the pop-up context menu choose
214 @w{@code{Open with > LilyPond}}.
215
216 @sourceimage{Learning_Win7_Open_Context_Menu,,,}
217
218 Or simply double-click the @file{test.ly}.
219
220 During the compilation of the @file{test.ly} file, a command window
221 will, very briefly open and then close. Three additional files will
222 have been created during this process.
223
224 @sourceimage{Learning_Win7_All_Files_Created,,,}
225
226 The PDF file contains the engraved @file{test.ly} file.
227
228 @sourceimage{Learning_Win7_Pdf_Output,,,}
229
230 To create a new file, begin by selecting @w{@code{File > New}} from
231 within any previously created file.
232
233 @sourceimage{Learning_Win7_New_Menu,,,}
234
235 or @w{@code{File > Open}} to open and edit any files you have saved
236 before.
237
238 @sourceimage{Learning_Win7_Open_Menu,,,}
239
240 You must save any new edits you make before you compile it and if the
241 PDF file is not created, check the log file that will have been created
242 during the compilation attempt, for any errors.
243
244 @sourceimage{Learning_Win7_Log_File,,,}
245
246 This log file is overwritten each time you compile your lilypond file.
247
248 The PS file is used internally by LilyPond to create the PDF file and
249 can be ignored. It also gets overwritten each time you compile your
250 file.
251
252 If you are viewing your file in a PDF viewer, then you must close the
253 PDF if you wish to make a new compilation as it may fail to create
254 the new PDF while it is still being viewed.
255
256 @node Command-line
257 @subsection Command-line
258
259 @warning{These instructions assume that you are using commond unix
260 command-line programs.  If you are using any of the programs
261 described in @rweb{Alternate input}, please consult the
262 documentation for those programs if you have any problems
263 compiling a file.}
264
265
266 Create a text file called @file{test.ly} and enter:
267
268 @example
269 @{
270   c' e' g' e'
271 @}
272 @end example
273
274 To process @file{test.ly}, proceed as follows:
275
276 @example
277 lilypond test.ly
278 @end example
279
280 @noindent
281 You will see something resembling:
282
283 @example
284 lilypond test.ly
285 GNU LilyPond @version{}
286 Processing `test.ly'
287 Parsing...
288 Interpreting music...
289 Preprocessing graphical objects...
290 Finding the ideal number of pages...
291 Fitting music on 1 page...
292 Drawing systems...
293 Layout output to `test.ps'...
294 Converting to `test.pdf'...
295 @end example
296
297 You may view or print the resulting @file{text.pdf}.
298
299
300 @node How to write input files
301 @section How to write input files
302
303 FIXME: insert text
304
305 @menu
306 * Simple notation::             
307 * Working on input files::      
308 @end menu
309
310
311 @node Simple notation
312 @subsection Simple notation
313
314 @cindex simple notation
315 @cindex notation, simple
316
317 LilyPond will add some notation elements automatically.  In the
318 next example, we have only specified four pitches, but LilyPond
319 has added a clef, time signature, and rhythms.
320
321 @lilypond[verbatim,quote]
322 {
323   c' e' g' e'
324 }
325 @end lilypond
326
327 @noindent
328 This behavior may be altered, but in most cases these automatic
329 values are useful.
330
331
332 @subheading Pitches
333
334 @cindex pitches
335 @cindex relative mode
336 @cindex quote, single
337 @cindex comma
338 @cindex accidentals and relative mode
339 @cindex relative mode, and accidentals
340
341 @funindex \relative
342 @funindex relative
343 @funindex '
344 @funindex ,
345
346 Music Glossary: @rglos{pitch}, @rglos{interval},
347 @rglos{scale}, @rglos{middle C}, @rglos{octave},
348 @rglos{accidental}.
349
350 The easiest way to enter notes is by using @code{\relative} mode.
351 In this mode, the octave is chosen automatically by assuming the
352 following note is always to be placed closest to the previous
353 note, i.e., it is to be placed in the octave which is within three
354 staff spaces of the previous note.  We begin by entering the most
355 elementary piece of music, a @notation{scale}, in which every note
356 is within just one staff space of the previous note.
357
358 @lilypond[verbatim,quote]
359 % set the starting point to middle C
360 \relative c' {
361   c d e f
362   g a b c
363 }
364 @end lilypond
365
366 The initial note is @notation{middle C}.  Each successive note is
367 placed closest to the previous note -- in other words, the first
368 @code{c} is the closest C to middle C.  This is followed by the
369 closest D to the previous note.  We can create melodies which have
370 larger intervals, still using only @code{\relative} mode:
371
372 @lilypond[verbatim,quote]
373 \relative c' {
374   d f a g
375   c b f d
376 }
377 @end lilypond
378
379 @noindent
380 It is not necessary for the first note of the melody to start on
381 the note which specifies the starting pitch.  In the previous
382 example, the first note -- the @code{d} -- is the closest D to
383 middle C.
384
385 By adding (or removing) quotes @code{'} or commas @code{,} from
386 the @code{@w{\relative c' @{}} command, we can change the starting
387 octave:
388
389 @lilypond[verbatim,quote]
390 % one octave above middle C
391 \relative c'' {
392   e c a c
393 }
394 @end lilypond
395
396 Relative mode can be confusing initially, but is the easiest way
397 to enter most melodies.  Let us see how this relative calculation
398 works in practice.  Starting from a B, which is on the middle line
399 in a treble clef, you can reach a C, D and E within 3 staff spaces
400 going up, and an A, G and F within 3 staff spaces going down.  So
401 if the note following a B is a C, D or E it will be assumed to be
402 above the B, and an A, G or F will be assumed to be below.
403
404 @lilypond[verbatim,quote]
405 \relative c'' {
406   b c  % c is 1 staff space up, so is the c above
407   b d  % d is 2 up or 5 down, so is the d above
408   b e  % e is 3 up or 4 down, so is the e above
409   b a  % a is 6 up or 1 down, so is the a below
410   b g  % g is 5 up or 2 down, so is the g below
411   b f  % f is 4 up or 3 down, so is the f below
412 }
413 @end lilypond
414
415 Exactly the same happens even when any of these notes are
416 sharpened or flattened.  @notation{Accidentals} are
417 @strong{totally ignored} in the calculation of relative position.
418 Precisely the same staff space counting is done from a note at any
419 other position on the staff.
420
421 To add intervals that are larger than three staff spaces, we can
422 raise the @notation{octave} by adding a single quote @code{'} (or
423 apostrophe) to the note name.  We can lower the octave by adding a
424 comma @code{,} to the note name.
425
426 @lilypond[verbatim,quote]
427 \relative c'' {
428   a a, c' f,
429   g g'' a,, f'
430 }
431 @end lilypond
432
433 @noindent
434 To change a note by two (or more!) octaves, we use multiple
435 @code{''} or @code{,,} -- but be careful that you use two single
436 quotes @code{''} and not one double quote @code{"}@tie{}!  The
437 initial value in @code{@w{\relative c'}} may also be modified like
438 this.
439 @c " - keeps quotes in order for context-sensitive editor -td
440
441 @subheading Durations (rhythms)
442
443 @cindex note durations
444 @cindex durations
445 @cindex rhythms
446 @cindex whole note
447 @cindex half note
448 @cindex quarter note
449 @cindex dotted note
450 @cindex notating durations
451
452 Music Glossary: @rglos{beam}, @rglos{duration},
453 @rglos{whole note}, @rglos{half note}, @rglos{quarter note},
454 @rglos{dotted note}.
455
456 The @notation{duration} of a note is specified by a number after
457 the note name:  @code{1} for a @notation{whole note}, @code{2} for
458 a @notation{half note}, @code{4} for a @notation{quarter note} and
459 so on.  @notation{Beams} are added automatically.
460
461 If you do not specify a duration, the previous duration is used
462 for the next note.  The duration of the first note defaults to a
463 quarter.
464
465 @lilypond[verbatim,quote]
466 \relative c'' {
467   a1
468   a2 a4 a8 a
469   a16 a a a a32 a a a a64 a a a a a a a a2
470 }
471 @end lilypond
472
473 To create @notation{dotted notes}, add a dot @code{.} to the
474 duration number.  The duration of a dotted note must be stated
475 explicitly (i.e., with a number).
476
477 @lilypond[verbatim,quote]
478 \relative c'' {
479   a a a4. a8
480   a8. a16 a a8. a8 a4.
481 }
482 @end lilypond
483
484
485 @subheading Rests
486
487 @cindex rest
488 @cindex notating rests
489
490 Music Glossary: @rglos{rest}.
491
492 A @notation{rest} is entered just like a note with the name
493 @code{r}@tie{}:
494
495 @lilypond[verbatim,quote]
496 \relative c'' {
497   a r r2
498   r8 a r4 r4. r8
499 }
500 @end lilypond
501
502
503 @subheading Time signature
504
505 @cindex time signature
506
507 @funindex \time
508 @funindex time
509
510 Music Glossary: @rglos{time signature}.
511
512 The @notation{time signature} can be set with the @code{\time}
513 command:
514
515 @lilypond[verbatim,quote]
516 \relative c'' {
517   \time 3/4
518   a4 a a
519   \time 6/8
520   a4. a
521   \time 4/4
522   a4 a a a
523 }
524 @end lilypond
525
526
527 @subheading Clef
528
529 @cindex clef
530 @cindex treble
531 @cindex alto
532 @cindex tenor
533 @cindex bass
534
535 @funindex \clef
536 @funindex clef
537
538 Music Glossary: @rglos{clef}.
539
540 The @notation{clef} can be set using the @code{\clef} command:
541
542 @lilypond[verbatim,quote]
543 \relative c' {
544   \clef treble
545   c1
546   \clef alto
547   c1
548   \clef tenor
549   c1
550   \clef bass
551   c1
552 }
553 @end lilypond
554
555
556 @subheading All together
557
558 Here is a small example showing all these elements together:
559
560 @lilypond[verbatim,quote]
561 \relative c, {
562   \time 3/4
563   \clef bass
564   c2 e8 c' g'2.
565   f4 e d c4 c, r4
566 }
567 @end lilypond
568
569
570 @seealso
571 Notation Reference: @ruser{Writing pitches},
572 @ruser{Writing rhythms}, @ruser{Writing rests},
573 @ruser{Time signature}, @ruser{Clef}.
574
575
576 @node Working on input files
577 @subsection Working on input files
578
579 @cindex curly braces
580 @cindex braces, curly
581 @cindex comments
582 @cindex line comment
583 @cindex comment, line
584 @cindex block comment
585 @cindex comment, line
586 @cindex case sensitive
587 @cindex whitespace insensitive
588 @cindex expressions
589
590 @funindex { ... }
591 @funindex %
592 @funindex %@{ ... %@}
593
594 LilyPond input files are similar to source files in many common
595 programming languages.  They are case sensitive, and white-space
596 is generally ignored.  Expressions are formed with curly braces
597 @{ @}, and comments are denoted with @code{%} or
598 @w{@code{%@{ ... %@}}}.
599
600 If the previous sentences sound like nonsense, don't worry!  We'll
601 explain what all these terms mean:
602
603 @itemize
604
605 @item
606 @strong{Case sensitive}:
607 it matters whether you enter a letter in lower case (e.g.
608 @w{@code{a, b, s, t}}) or upper case (e.g.  @w{@code{A, B, S, T}}).
609 Notes are lower case: @w{@code{@{ c d e @}}} is valid input;
610 @w{@code{@{ C D E @}}} will produce an error message.
611
612 @item
613 @strong{Whitespace insensitive}:
614 it does not matter how many spaces (or tabs or new lines) you add.
615 @w{@code{@{ c d e @}}} means the same thing as
616 @w{@code{@{ c @tie{}} @tie{} @tie{} d e @}} and:
617
618 @example
619 @{ c                        d
620                    e   @}
621 @end example
622
623 @noindent
624 Of course, the previous example is hard to read.  A good rule of
625 thumb is to indent code blocks with either a tab or two spaces:
626
627 @example
628 @{
629   c d e
630 @}
631 @end example
632
633 However, whitespace @emph{is} required to separate many syntactical
634 elements from others.  In other words, whitespace can always be
635 @emph{added}, but it cannot be @emph{eliminated}.  As missing
636 whitespace can give rise to strange errors it is advisable to
637 always insert whitespace before and after every syntactic element,
638 for example, before and after every curly brace.
639
640 @item
641 @strong{Expressions}:
642 every piece of LilyPond input needs to have @strong{@{ curly
643 braces @}} placed around the input.  These braces tell LilyPond
644 that the input is a single music expression, just like parentheses
645 @code{()} in mathematics.  The braces should be surrounded by a
646 space unless they are at the beginning or end of a line to avoid
647 ambiguities.
648
649 A LilyPond command followed by a simple expression in braces (such
650 as @w{@code{\relative @{ @}}}) also counts as a single music
651 expression.
652
653 @cindex comments
654 @cindex line comment
655 @cindex block comment
656 @item
657 @strong{Comments}:
658 a comment is a remark for the human reader of the music input; it
659 is ignored while parsing, so it has no effect on the printed
660 output.  There are two types of comments.  The percent symbol
661 @code{%} introduces a line comment; anything after @code{%} on
662 that line is ignored.  By convention, a line comment is placed
663 @emph{above} the code it refers to.
664
665 @example
666 a4 a a a
667 % this comment refers to the Bs
668 b2 b
669 @end example
670
671 A block comment marks a whole section of music input as a comment.
672 Anything that is enclosed in @code{%@{} and @code{%@}} is ignored.
673 However, block comments do not @q{nest}.  This means that you
674 cannot place a block comment inside another block comment.  If you
675 try, the first @code{%@}} will terminate @emph{both} block
676 comments.  The following fragment shows possible uses for
677 comments:
678
679 @example
680 % notes for twinkle twinkle follow
681   c4 c g' g a a g2
682
683 %@{
684   This line, and the notes below are ignored,
685   since they are in a block comment.
686
687   f f e e d d c2
688 %@}
689 @end example
690
691 @end itemize
692
693
694 @node How to read the manuals
695 @section How to read the manuals
696
697 FIXME: fluff here
698
699 @menu
700 * Omitting braces::             
701 * Clickable examples::          
702 * Keyboard navigation::         
703 * Overview of manuals::         
704 @end menu
705
706
707 @node Omitting braces
708 @subsection Omitting braces
709
710
711 @cindex how to read the manual
712 @cindex manual, reading
713 @cindex reading the manual
714 @cindex examples, clickable
715 @cindex clickable examples
716 @cindex tips for constructing files
717 @cindex templates
718 @cindex constructing files, tips
719 @cindex files, tips for constructing
720
721 LilyPond input must be surrounded by @{ @} marks or a
722 @code{@w{\relative c'' @{ ... @}}}, as we saw in @ref{Working on
723 input files}.  For the rest of this manual, most examples will
724 omit this.  To replicate the examples, you may copy and paste the
725 displayed input, but you @strong{must} add the
726 @code{@w{\relative c'' @{ @}}} like this:
727
728 @example
729 \relative c'' @{
730   ... example goes here...
731 @}
732 @end example
733
734 Why omit the braces?  Most examples in this manual can be inserted
735 into the middle of a longer piece of music.  For these examples,
736 it does not make sense to add @code{@w{\relative c'' @{ @}}} --
737 you should not place a @code{\relative} inside another
738 @code{\relative}!  If we included @code{@w{\relative c'' @{ @}}}
739 around every example, you would not be able to copy a small
740 documentation example and paste it inside a longer piece of your
741 own.  Most people want to add material to an existing piece, so we
742 format the manual this way.
743
744
745 @node Clickable examples
746 @subsection Clickable examples
747
748 @warning{This features is only available in the HTML manuals.}
749
750 Many people learn programs by trying and fiddling around with the
751 program.  This is also possible with LilyPond.  If you click on a
752 picture in the HTML version of this manual, you will see the exact
753 LilyPond input that was used to generate that image.  Try it on
754 this image:
755
756 @c no verbatim here
757 @lilypond[quote]
758 \relative c'' {
759   c-\markup { \bold \huge { Click here.  } }
760 }
761 @end lilypond
762
763 By cutting and pasting everything in the @qq{ly snippet} section,
764 you have a starting template for experiments.  To see exactly the
765 same output (line-width and all), copy everything from @qq{Start
766 cut-&-pastable section} to the bottom of the file.
767
768
769 @node Keyboard navigation
770 @subsection Keyboard navigation
771
772 @warning{This features is only available in the HTML manuals.}
773
774 @c TODO: once this is figured out, insert it here.
775
776 We are currently working on this feature.
777
778
779 @node Overview of manuals
780 @subsection Overview of manuals
781
782 There is a lot of documentation for LilyPond.  New users are
783 sometimes confused about what part(s) they should read, and
784 occasionally skip over reading vital portions.
785
786 @warning{Please do not skip over important parts of the
787 documentation.  You will find it much harder to understand later
788 sections.}
789
790 @itemize
791
792 @item
793 @strong{Before trying to do @emph{anything}}: read the Learning
794 manual's @ref{Tutorial}, and @ref{Common notation}.  If you
795 encounter musical terms which you do not recognize, please look
796 them up in the @rglosnamed{Top, Glossary}.
797
798 @item
799 @strong{Before trying to write a complete piece of music}: read
800 the Learning manual's @ref{Fundamental concepts}.  After that, you
801 may want to look in relevant sections of the
802 @rusernamed{Top, Notation reference}.
803
804 @item
805 @strong{Before trying to change the default output}: read the
806 Learning manual's @ref{Tweaking output}.
807
808 @item
809 @strong{Before undertaking a large project}: read Usage document's
810 @rprogram{Suggestions for writing files}.
811
812 @end itemize
813
814
815