]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
release: 1.3.142
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*-texinfo-*-
2
3 @node Tutorial
4 @chapter Tutorial
5
6 @menu
7 * Introduction::                
8 * Running LilyPond::            Getting started
9 * The first tune::              The first tune
10 * Lyrics and chords::           Lyrics and chords
11 * More movements ::             
12 * A piano excerpt::             Piano music
13 * An orchestral score::         
14 * Part extraction::             
15 * end of tutorial::             The end
16 * Pre-cooked makefile::         
17 @end menu
18
19 @node Introduction
20 @section Introduction
21
22   
23 LilyPond prints music from a specification that you, the user, supply.
24 You have to give that specification using a @emph{language}.  This
25 chapter is a gentle introduction to that language.
26
27 This tutorial will demonstrate how to use Lilypond by presenting
28 examples of input along with resulting output.  We will use English
29 terms for notation.  In case you are not familiar with those, you may
30 consult the glossary that is distributed with LilyPond.
31
32 @cindex examples, tutorial
33
34 The examples discussed are included in the distribution, in the
35 subdirectory @file{input/tutorial/}.@footnote{When we refer
36 to filenames, they are relative to the top directory of the source
37 package.
38 @cindex file names
39 }. We recommend that you experiment with writing Lilypond input
40 yourself, to get a feel for how the program behaves.
41
42
43 @node Running LilyPond
44 @section Running LilyPond
45
46 Before we dive into describing the input language of LilyPond, we first
47 show you through the procedure for getting notes on your screen and out
48 of your printer.
49
50 The first step is creating an input file. Using your favorite
51 text-editor, create @file{test.ly} containing
52
53 @example
54 \header @{
55  title = "Test";
56 @}
57
58 \score @{
59   \notes @{ c'4 e'4 g'4 @}
60   \paper @{ @}
61 @} 
62 @end example
63
64 @unnumberedsubsec Unix
65
66 @cindex Unix, Running lilypond on
67
68 If you run Unix, proceed as follows: run lilypond on the file, i.e.,
69 @example
70   lilypond test
71 @end example
72 You will see the following on your screen:
73 @example
74 GNU LilyPond 1.3.125.
75 Now processing: `input/tutorial/test.ly'
76 Parsing...
77 Interpreting music...[1]
78 Preprocessing elements... 
79 Calculating column positions... [2]
80 paper output to test.tex...
81 @end example
82
83 Now, run @TeX{}@footnote{@TeX{} is a text-typesetting system that is
84 especially suited for typesetting mathematics.}. The result should
85 resemble this: 
86 @example
87 This is TeX, Version 3.14159 (Web2C 7.3.1)
88 (test.tex (/home/hanwen/usr/share/lilypond/tex/lilyponddefs.tex
89 (/home/hanwen/usr/share/lilypond/tex/lilypond-plaintex.tex
90 LilyPond Plain TeX settings) (/home/hanwen/usr/src/  ...
91 (/home/hanwen/usr/share/lilypond/tex/lily-ps-defs.tex) [footer empty]
92 (/home/hanwen/usr/share/lilypond/tex/fetdefs.tex)) [1] )
93 Output written on test.dvi (1 page, 3716 bytes).
94 Transcript written on test.log.
95 @end example
96 The result of the @TeX{} run is a @TeX{} ``DeVice Independent'' file
97 (@file{test.dvi}).
98 @cindex DVI file
99 @cindex @TeX{}
100
101 @cindex Viewing music
102 @cindex @code{xdvi}
103 To view the output, run Xdvi, i.e.
104 @example
105         xdvi test
106 @end example
107 You should see the following in  a window next to some buttons.
108 @lilypond
109 \header {
110  title = "Test";
111 }
112
113 \score {
114   \notes { c'4 e'4 g'4 }
115   \paper { }
116
117 @end lilypond
118
119 @cindex postscript, converting to
120 When you're satisfied with the result, you can print it. For printing,
121 you have to generate a postscript file:
122 @example
123         dvips -o test.ps test.dvi
124 @end example
125 which looks like this:
126 @example
127 This is dvips(k) 5.86 Copyright 1999 Radical Eye Soft ...
128 ' TeX output 2001.01.27:1806' -> test.ps
129 <texc.pro><special.pro>. [1]
130 @end example
131
132 @cindex PostScript
133 @cindex Printing output
134 @cindex GhostScript
135 @cindex @code{lpr}
136 PostScript is a page description language, similar to PDF. Some printers
137 can understand a postscript file directly, but the cheaper ones need the
138 intervention of GhostScript, an emulator that runs PostScript on your
139 computer instead of your printer. Most Linux distributions nowadays have
140 GhostScript running ``in the background'', so any configured printer
141 will act as a PostScript printer.  Assuming this, the following command
142 will print the file
143 @example
144         lpr test.ps
145 @end example
146 If this does not make your printer produce a page of music, then you
147 should look into installing and configuring ghostscript.  Refer to
148 GhostScript's website at @uref{http://www.ghostscript.com}.  
149
150 There are three other routes: firstly, you can add titling to the
151 output. This is done by a separate program called @file{ly2dvi}: this
152 program first calls LilyPond to process the @file{.ly} file, and then
153 runs @TeX{} on it to produce a @file{.dvi} file with proper margin
154 settings and titling.
155
156 @cindex titles, adding
157 @cindex ly2dvi
158
159 @example
160         ly2dvi test.ly
161 @end example
162 After some disk-activity, you should end up with a @file{.dvi} file.
163 Ly2dvi is further described in the @ref{ly2dvi}.
164
165 Secondly, you can generate PostScript directly. This is  useful if you
166 can not or do not want to  run @TeX{} on your system. 
167 To obtain PS output, invoke LilyPond as follows:
168 @cindex PostScript output
169 @example
170       lilypond -f ps test.ly  
171 @end example
172
173 You have to set some environment variables to view or print this
174 output. More information can be found in the @ref{Invoking
175 LilyPond}.
176
177 Finally, there is a script called lilypond-book, that allows you to
178 freely mix LilyPond input with Texinfo or LaTeX input. For example, this
179 manual was written using lilypond-book. lilypond-book is discussed in
180 @ref{lilypond-book}.
181
182 @unnumberedsubsec Windows
183
184 [TODO]
185
186 * setting of env vars (TFMINPUTS,MFINPUTS,TEXINPUTS)
187 * dvi viewer doesn't display postscript
188
189
190 @node The first tune
191 @section The first tune
192
193
194 To demonstrate what LilyPond input looks like, we start off with a
195 full-fledged, yet simple example. It is a convoluted version
196 of the famous menuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
197 is included in the distribution as  @file{menuet.ly}.
198 @cindex Bach, Johann Sebastian 
199
200 @lilypond[verbatim]
201 % lines preceded by a percent are comments which
202 % are ignored by Lilypond.
203 \include "paper16.ly"
204 \score {
205     \notes                        
206     \relative c'' \sequential{                
207             \time 3/4;                
208             \key g \major;
209
210         \repeat "volta" 2 {
211             d4 g,8 a b c d4 g, g |
212             e'4 c8 d e fis g4 g, g |
213             c4 d8()c b a( )b4 c8 b a g |
214             a4 [b8 a] [g fis] g2.  |
215         }
216
217         b'4 g8 a b g
218         a4 d,8 e fis d |
219         g4 e8 fis g d cis4 b8 cis a4 |
220         a8-. b-. cis-. d-. e-. fis-.
221         g4 fis e |
222         fis a,  r8 cis8
223         d2.-\fermata
224         \bar "|.";
225     }
226     \paper {
227        % standard settings are too wide for a book
228        linewidth = 14.0 \cm;
229    }
230 }
231 @end lilypond
232
233 We will analyse the input, line by line. 
234 @example
235         % lines preceded by a percent are comments which
236         % are ignored by Lilypond.
237 @end example 
238 The percent sign, @code{%}, introduces a line comment.  If you want to
239 make larger comments, you can use block comments. These are delimited
240 by @code{%@{} and @code{%@}}
241 @cindex comment
242 @cindex block comment
243 @cindex line comment
244
245 @example 
246
247         \include "paper16.ly"
248  
249 @end example
250 @cindex @code{\include}
251 @cindex point, printer's
252 @cindex staff size setting 
253 By default, LilyPond will use definitions for a staff that is 20
254 point@footnote {A point is the standard measure of length for printing;
255 one point is 1/72.27 inch. [TODO: mm vs. pt]} high.  We want smaller
256 output (16 point staff height), so we must import the settings for that
257 size, which is done here.
258 @example 
259
260         \score @{
261  
262 @end example 
263 A lilypond file combines music with directions for outputting that
264 music.  The music is combined with the output directions by putting
265 them into a @code{\score} block.
266 @example 
267
268         \notes                
269  
270 @end example 
271  This makes LilyPond ready for accepting notes.
272 @example 
273
274         \relative c''
275  
276 @end example
277
278 @cindex octaves, choosing
279 @cindex pitch
280 As we will see, pitches are combinations of octave, note name and
281 chromatic alteration.  In this scheme, the octave is indicated by
282 using raised quotes (@code{'}) and ``lowered'' quotes (commas:
283 @code{,}).  The central C is denoted by @code{c'}.  The C one octave
284 higher is @code{c''}.  One and two octaves below the central C is
285 denoted by @code{c} and @code{c,} respectively.
286
287 @cindex relative
288 For pitches in a long piece you might have to type many quotes. It is
289 easy to make typing errors with this, so LilyPond has a special entry
290 mode to remedy this.  In this ``relative'' octave mode, octaves of notes
291 without quotes are chosen such that a note is as close as possible
292 (graphically, on the staff) to the the preceding note.  If you add a
293 high-quote an extra octave is added.  The lowered quote (a comma) will
294 subtract an extra octave.  Because the first note has no predecessor,
295 you have to give the (absolute) pitch of the note to start with.
296 @example 
297
298         \sequential @{
299  
300 @end example 
301 What follows is sequential music, i.e.,
302 @cindex sequential music
303 notes that are to be played and printed after each other.
304 @example 
305
306         \time 3/4;
307  
308 @end example
309 @cindex time signature, setting
310 @cindex @code{\time}
311   This command changes the time signature of the current piece: a 3/4
312 sign is printed.  This command is also used to generate bar lines in
313 the right spots.
314 @example 
315
316         \key g \major;
317  
318 @end example
319 @cindex key signature, setting
320 @cindex @code{\key}
321   This command changes the current key signature to G-major.  Although this
322 command comes after the @code{\time} command, in the output, the key
323 signature comes before the time signature: LilyPond knows about music
324 typesetting conventions.
325 @example 
326
327         \repeat "volta" 2
328  
329 @end example 
330   This command tells LilyPond that the following piece of music must be
331 played twice. The first argument indicates the type of repeat. In this
332 case, @code{"volta"} means that volta brackets are be used for
333 alternatives---if there were any.
334 @example 
335
336         @{
337  
338 @end example 
339 The subject of the repeat is again sequential music.  Since
340 @code{\sequential} is such a common construct, a shorthand is provided:
341 just leave off @code{\sequential}, and the result is the same.
342 @example 
343
344         d4
345  
346 @end example 
347  This is a note with pitch @code{d} (determined up to octaves).  The
348 relative music was started with a @code{c''}, so the real pitch of this
349 note is @code{d''}.  The @code{4} designates the duration of the note
350 (it is a quarter note).
351 @example 
352
353         a b
354  
355 @end example 
356 These are notes with pitch @code{a} and @code{b}.  Because their
357 duration is the same as the @code{g}, there is no need to enter the
358 duration (You may enter it anyway, e.g. @code{a4 b4})
359 @example 
360
361         d4 g, g |
362  
363 @end example
364 @cindex bar check
365 @cindex @code{|}
366 @cindex errors, finding 
367  Three more notes.  The @code{|} character is a `bar check'.  When
368 processing the music, LilyPond will verify that bar checks are found at
369 the start of a measure.  This can help you track down errors.
370
371 @cindex alteration, chromatic
372 @cindex chromatic alteration
373 So far, no notes were chromatically altered.  Here is the first one
374 that is: @code{fis}. Lilypond by default uses Dutch note names, and
375 ``Fis'' is the Dutch note name for ``F sharp''.  However, there is no
376 sharp sign in the output. The program keeps track of key signatures,
377 and will only print accidentals if they are needed.
378 @example 
379
380         c8 d e fis
381  
382 @end example 
383 LilyPond guesses were beams can be added to eighth and shorter notes.
384 In this case, a beam over 4 eighths is added.
385 @example 
386
387         c4 d8( )c b a( )b4 c8 b a g |
388  
389 @end example 
390   The next line shows how to make a slur: the beginning and ending note
391 of the slur is marked with an opening and closing parenthesis
392 respectively.  In the line shown above, this is done for two slurs.
393 Slur markers (parentheses) are put between the slurred notes.
394 @example 
395
396         a4 [b8 a] [g fis] 
397  
398 @end example 
399 Automatic beaming can be overridden by inserting beam marks
400 (brackets).  Brackets are put around the notes you want beamed.
401 @example 
402
403         g2.  |
404  
405 @end example
406 @cindex augmentation dot
407 @cindex dot
408 A duration with augmentation dot  is notated
409 with the duration number followed by a period.
410 @example 
411
412         @}
413  
414 @end example 
415   This ends the sequential music to be repeated.  LilyPond will typeset
416 a repeat bar.
417 @example 
418
419         cis'4 b8 cis a4 |
420  
421 @end example 
422  This line shows that Lily will print an accidental if that is
423 needed: the first C sharp of the bar will be printed with an accidental,
424 the second one without.
425 @example 
426
427         a8-. b-. cis-. d-. e-. fis-.
428  
429 @end example
430 @cindex articulation
431 You can enter articulation signs either in a verbose form using a
432 shorthand.  Here we demonstrate the shorthand: it is formed by a dash
433 and the character for the articulation to use, e.g. @code{-.} for
434 staccato as shown above.
435 @example 
436
437         fis a, r8 cis8
438  
439 @end example 
440  
441 Rests are denoted by the special notename @code{r}.  
442 @example 
443
444         d2.-\fermata
445  
446 @end example 
447  All articulations have a verbose form, like @code{\fermata}.  The
448 command @code{\fermata} is not part of the core of the language (most
449 of the other discussed elements are), but it is a shorthand for a more
450 complicated description of a fermata.  @code{\fermata} names that
451 description and is therefore called an identifier.
452 @cindex identifier
453 @cindex @code{\fermata}
454 @example 
455
456         @}
457  
458 @end example 
459  
460 Here the music ends.
461 @example 
462
463         \paper @{
464                 linewidth = 14.0\cm;
465         @}
466  
467 @end example 
468 This specifies a conversion from music to notation output.  Most of
469 the details of this conversions (font sizes, dimensions, etc.) have
470 been taken care of, but  to fit the output  in this document, it has
471 to be smaller.  We do this by setting the line width to 14 centimeters
472 (approximately 5.5 inches).
473 @example 
474
475         @}
476  
477 @end example 
478 The last brace ends the @code{\score} block.
479
480
481
482
483 @node Lyrics and chords
484 @section Lyrics and chords
485
486 In this section we show how to typeset a song. This file is
487 included as @file{flowing.ly}.
488
489 @example 
490 \header @{
491         title = "The river is flowing";
492         composer = "Traditional (?)";
493 @}
494 \include "paper16.ly"
495 melody = \notes \relative c' @{
496         \partial 8;
497         \key c \minor;
498         g8 |
499         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
500         c4 c8 d [es () d] c4 | d4 es8 d c4.
501         \bar "|.";
502 @}
503
504 text = \lyrics @{
505         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
506         ri -- ver is flo -- wing down to the sea.
507 @}
508
509 accompaniment =\chords @{
510         r8
511         c2:3- f:3-.7 d:min es4 c8:min r8
512         c2:min f:min7 g:7^3.5 c:min @}
513
514 \score @{
515         \simultaneous @{
516 %         \accompaniment
517           \context ChordNames \accompaniment
518
519           \addlyrics
520             \context Staff = mel @{        
521               \property Staff.noAutoBeaming = ##t
522               \property Staff.automaticMelismata = ##t
523               \melody 
524             @}
525             \context Lyrics \text
526         @}
527         \midi  @{ \tempo 4=72;@}
528         \paper @{ linewidth = 10.0\cm; @}
529 @} 
530 @end example 
531
532
533 The result would look this.@footnote{The titling and font size shown
534 may differ, since the titling in this document is not generated by
535 @file{ly2dvi}.}
536
537 @center @strong{The river is flowing}
538 @center Traditional 
539
540 @lilypond[center]
541 \header {
542         title = "The river is flowing";
543         composer = "Traditional (?)";
544 }
545 \include "paper16.ly"
546 melody = \notes \relative c' {
547         \partial 8;
548         \key c \minor;
549         g8 |
550         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
551         c4 c8 d [es () d] c4 | d4 es8 d c4.
552         \bar "|.";
553 }
554
555 text = \lyrics {
556         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
557         ri -- ver is flo -- wing down to the sea.
558 }
559
560 accompaniment =\chords {
561         r8
562         c2:3- f:3-.7 d:min es4 c8:min r8
563         c2:min f:min7 g:7^3.5 c:min }
564
565 \score {
566         \simultaneous {
567 %         \accompaniment
568           \context ChordNames \accompaniment
569
570           \addlyrics
571             \context Staff = mel {
572               \property Staff.noAutoBeaming = ##t
573               \property Staff.automaticMelismata = ##t
574               \melody 
575             }
576             \context Lyrics \text
577         }
578         \midi  { \tempo 4=72;}
579         \paper { linewidth = 10.0\cm; }
580 }
581 @end lilypond
582
583 Again, we will dissect the file line by line.
584 @example 
585
586         \header @{
587  
588 @end example
589 @cindex @code{\header}
590 Information about the music you are about to typeset goes into a
591 @code{\header} block.  The information in this block is not used by
592 LilyPond, but it is passed into the output.  @file{ly2dvi} uses this
593 information to print titles above the music.
594 @example 
595
596         title = "The river is flowing";
597         composer = "Traditional (?)"; 
598 @end example
599 @cindex assignments
600 @cindex identifier assignment
601 the @code{\header} block contains assignments.  An assignment starts
602 with a string.  (which is unquoted, in this case). Then comes the
603 equal sign.  After the equal sign comes the expression you
604 want to store.  In this case, you want to put in strings.  The
605 information has to be quoted here, because it contains spaces. Each
606 assignment is finished with a semicolon.
607 @example 
608
609         \include "paper16.ly"
610  
611 @end example
612 Smaller size for inclusion in a book.
613 @example 
614
615         melody = \notes \relative c' @{
616  
617 @end example 
618 The structure of the file will be the same as the previous one, a
619 @code{\score} block with music in it.  To keep things readable, we will
620 give names to the different parts of music, and use the names to
621 construct the music within the score block.
622
623 @example 
624         \partial 8;
625 @end example 
626
627 @cindex @code{\partial}
628 @cindex anacrusis
629 The piece starts with an anacrusis of one eighth.
630 @example
631         \key c \minor;
632 @end example
633 The key is C minor: we have three flats.
634
635 @example 
636
637         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
638         c4 c8 d [es () d] c4 | d4 es8 d c4.
639         \bar "|.";
640  
641 @end example 
642
643 @cindex manual beaming
644 @cindex automatic beaming, turning off
645 We use explicit beaming.  Since this is a song,  we will turn automatic
646 beams off, and use explicit beaming where needed.
647 @example 
648
649         @}
650  
651 @end example 
652 This ends the definition of @code{melody}.  Note that there are no
653 semicolons after assignments at top level.
654 @example 
655
656         text = \lyrics @{
657  
658 @end example
659 @cindex lyrics
660 @cindex identifier assignment
661 @cindex syllables, entering
662 Another identifier assignment.  This one is for the lyrics. 
663 Lyrics are formed by syllables that have duration, and not by
664 notes. To make LilyPond parse words as syllables,  switch it  into
665 lyrics mode with @code{\lyrics}.  Again, the brace after @code{\lyrics}
666 is a shorthand for @code{\sequential @{}.
667 @example 
668
669   The4 ri -- ver is flo- __ wing,  flo -- wing and gro -- wing, the
670   ri- ver is flo- __ wing down to the sea.
671 @}
672  
673 @end example
674 @cindex extenders, lyric
675 @cindex hyphens, lyric 
676 The syllables  themselves are  separated by spaces.  You can get syllable
677 extenders by entering @code{__}, and centered hyphens with
678 `@code{-}@code{-}'.  We enter the syllables as if they are all quarter notes
679 in length (hence the @code{4}), and use a feature to align the
680 syllables to the music (which obviously isn't all quarter notes.)
681 @example 
682
683         accompaniment =\chords @{
684  
685 @end example
686 @cindex chords
687 @cindex mode, chords
688 We'll put chords over the music, to enter them, there is a special mode,
689 called @code{\chords}.  There is a special mode (analogous
690 to @code{\lyrics} and @code{\notes} mode) where you can give the names
691 of the chords you want, instead of the notes comprising the chord.
692 @example 
693
694         r8
695  
696 @end example 
697 There is no accompaniment during the anacrusis.
698 @example 
699
700         c2:3- f:3-.7
701  
702 @end example
703
704 @cindex tonic
705 @cindex chord modifier
706 @cindex modifier, chord 
707 A chord is started by  the tonic of the chord. The
708 first one lasts a half note.  An unadorned note creates a major
709 triad, while a minor triad is wanted.  @code{3-} modifies the third to
710 be small. @code{7} modifies (adds) a seventh, which is small by default
711 to create the @code{f a c es} chord.  Multiple modifiers must be
712 separated by a dot.
713 @example 
714
715         d:min es4 c8:min r8
716  
717 @end example
718
719 Some modifiers have predefined names, eg. @code{min} is  the same as
720 @code{3-}, so @code{d-min} is a minor @code{d} chord.
721 @example 
722
723         c2:min f:min7 g:7^3.5 c:min @}
724  
725 @end example
726 @cindex named modifier
727
728 A named modifier @code{min} and a normal modifier @code{7} do not have
729 to be separated by a dot.  Tones from a chord are removed with chord
730 subtractions.  Subtractions are started with a caret, and they are
731 also separated by dots.  In this example, @code{g:7^3.5} produces a
732 minor seventh.  The brace ends the sequential music.
733 @example 
734
735         \score @{
736                 \simultaneous @{
737  
738 @end example 
739 We assemble the music in the @code{\score} block.  Melody, lyrics and
740 accompaniment have to sound at the same time, so they should be
741 @code{\simultaneous}.
742 @cindex @code{\simultaneous}
743 @example 
744
745         %\accompaniment
746  
747 @end example 
748 Chord mode generates notes grouped in @code{\simultaneous} music.  If
749 you remove the comment sign, you can see the chords in normal
750 notation: they will be printed as note heads on a separate
751 staff.
752 @example 
753
754         \context ChordNames \accompaniment
755  
756 @end example
757 @cindex context
758 @cindex interpretation context
759 @cindex notation context
760 Normally, the notes that you enter are transformed into note heads.
761 The note heads alone make no sense, they need surrounding information:
762 a key signature, a clef, staff lines, etc.  They need @emph{context}.  In
763 LilyPond, these symbols are created by objects called `interpretation
764 contexts'.  Interpretation contexts only exist during a run of
765 LilyPond.  Interpretation contexts that are for printing music (as
766 opposed to playing music) are called `notation contexts'.
767
768 By default, LilyPond will create a Staff context for you.  If you
769 removed the @code{%} sign in the previous line, you would see that
770 mechanism in action.
771
772 We don't want that default here, because we want chord names, not note heads.
773 An interpretation context can also created upon explicit request. The
774 keyword for such a request is @code{\context}.  It takes two arguments.
775 The first is the name of an interpretation context.  The name is a
776 string, it can be quoted with double quotes).  The second argument is
777 the music that should be interpreted in this context.  For the previous
778 line, we could have written @code{\context Staff \accompaniment}, and
779 get the same effect.
780 @example 
781
782         \addlyrics
783  
784 @end example
785 @cindex @code{\addlyrics}
786 @cindex lyrics and melody, combining
787 @cindex combining lyrics and melody
788
789 The lyrics need to be aligned with the melody.  This is done by
790 combining both with @code{\addlyrics}.  @code{\addlyrics} takes two
791 pieces of music (usually a melody and lyrics, in that order) and
792 aligns the syllables of the second piece under the notes of the
793 first piece.  If you would reverse the order, the notes would be
794 aligned on the lyrics, which is not very useful. (Besides, it looks
795 silly.)
796 @example 
797
798         \context Staff = mel @{
799  
800 @end example
801
802 This is the argument of @code{\addlyrics}.  We instantiate a
803 @code{Staff} context explicitly: should you chose to remove the comment
804 before the ``note heads'' version of the accompaniment, the
805 accompaniment will be on a nameless staff.  The melody has to be on a
806 different staff as the accompaniment.  This is accomplished by giving
807 the melody staff a different name.
808 @example 
809
810         \property Staff.noAutoBeaming = ##t
811  
812 @end example
813 @cindex \property
814 @cindex context variables
815 @cindex setting context variables
816 An interpretation context has variables that tune its behaviour.  One of
817 the variables is @code{noAutoBeaming}.  If set to @code{##t}, which is
818 the boolean value @var{true}, LilyPond will not try to put automatic beaming
819 on the current staff.
820
821 @cindex GUILE
822 @cindex Scheme
823 @cindex accessinng Scheme
824 @cindex evaluating Scheme
825 @cindex LISP
826
827 LilyPond internally uses GUILE, a Scheme-interpreter@footnote{Scheme is
828 a language from the LISP family. You can learn more about Scheme at
829 @uref{http://www.scheme.org}.} to represent data throughout the whole
830 program. The hash-sign (@code{#}) accesses GUILE directly: the code
831 following the hash-sign is evaluated as Scheme.  The boolean value
832 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
833 @code{##t}
834
835 @example 
836
837         \property Staff.automaticMelismata = ##t
838  
839 @end example
840 @cindex automaticMelismata
841 @cindex melismata
842 @cindex @code{\addlyrics} and slurs
843 Similarly, we  don't want to print a  syllable when there is
844 a slur. This sets up @code{\addlyrics} to not put lyrics under notes
845 while there is a  slur.
846 @example 
847
848           \melody
849         @}
850  
851 @end example 
852 Finally, we put the melody on the current staff.  Note that the
853 @code{\property} directives and @code{\melody} are grouped in sequential
854 music,  so the property settings are done before the melody is
855 processed.
856 @example 
857
858         \context Lyrics \text
859  
860 @end example 
861 The second argument of @code{\addlyrics} is the text. The text also
862 should not land on a Staff, but on a interpretation context for
863 syllables, extenders, hyphens etc.  This context is called
864 Lyrics.
865 @example 
866
867         @}
868  
869 @end example 
870 This ends @code{\simultaneous}.
871 @example 
872
873         \midi  @{ \tempo 4=72;@}
874  
875 @end example 
876 This makes the music go to a MIDI file.  MIDI is great for checking
877 music you enter.  You listen to the MIDI file: if you hear something
878 unexpected, it's probably a typing error.  @code{\midi} starts an output
879 definition, a declaration that specifies how to output music analogous
880 to @code{\paper @{ @}}. You can specify the tempo using the
881 @code{\tempo} command, in this case the tempo of quarter notes is set to
882 72 beats per minute.
883 @example 
884
885         \paper @{ linewidth = 10.0\cm; @}
886  
887 @end example 
888 We also want notation output.  The linewidth is short so the piece
889 will be set in two lines.
890 @example 
891
892         @}
893  
894 @end example 
895 End the score block.
896
897 @node More movements 
898 @section More movements
899
900 You probably ran @file{ly2dvi} on the last example, and ended up with a
901 viewable @file{.dvi} file.  However, between there are a few steps of
902 which LilyPond is only one. To enhance your understanding of what's
903 happening under the hood when you run @code{ly2dvi}, we explain what
904 programs are run.
905
906 @code{ly2dvi} is a program that calls a number of programs  in sequence.
907 The first thing it does, is running LilyPond on the input file. After
908 some calculations, a @file{.tex} is produced. The contents
909 of this file are very  low-level instructions.
910
911 For example,  the following file (@file{layout.ly}) 
912
913 @example
914   \version "1.3.124";
915   \header @{ title = "Two miniatures";  @}
916   
917   #(set! point-and-click line-column-location)
918   
919   \paper @{
920         linewidth = -1.0; @}
921
922   \score @{
923     \notes @{ c'4 d'4 @}
924     \header @{
925         opus = "Opus 1.";
926         piece = "Up"; @}
927   @}
928   \score @{
929     \notes @{ d'4 c'4  @}
930     \header @{
931         opus = "Opus 2.";
932         piece = "Down"; @}
933   @}
934 @end example
935  results in something like this@footnote{The titling in this manual was
936 not generated by ly2dvi, so details will differ.}
937
938 @center @strong{Two miniatures}
939 @flushright
940 Opus 1.
941 @end flushright
942 @flushleft
943 @var{Up}
944 @end flushleft
945 @lilypond
946   \score {
947     \notes { c'4 d'4 }
948     \paper {
949         linewidth = -1.0; }
950   }
951 @end lilypond
952 @flushright
953 Opus 2.
954 @end flushright
955 @flushleft
956 @var{Down}
957 @end flushleft
958 @lilypond
959   \score {
960     \notes { d'4 c'4 }
961     \paper {
962         linewidth = -1.0; }
963   }
964 @end lilypond
965
966 This file is produced by ly2dvi in a few stages, with the help of text
967 formatting tools. LilyPond produces two output files, @file{layout.tex}
968 and @file{layout-1.tex}.  They both look like this:
969
970 @example
971         ...
972   \placebox@{-5  \outputscale @}%
973   @{  8.7229  \outputscale @}%
974   @{\magfontWXGEomMMBo\char90 @}%
975   
976   \placebox@{-4  \outputscale @}%
977   @{ 81.0647  \outputscale @}%
978         ...
979 @end example
980
981 @file{ly2dvi} analyses the progress indication that LilyPond spews out,
982 and generates a file called @file{layout_ly1.tex}. This file contains
983 formatting instructions for the title and page layout.  A fragment might
984 look like
985 @example
986
987         \geometry@{width=540.602362pt,headheight=2mm, ...
988         \renewcommand@{\@@oddfoot@}@{\parbox@{\textwidth@}@{\mbox@{@}   ...
989         \begin@{document@}
990         \lilypondtitle@{foo@}%
991         \makelilytitle
992         \input@{ly2dvi.tex@}
993
994 @end example
995
996 @file{ly2dvi} runs it through LaTeX. LaTeX is a text-formatting system
997 built on top of @TeX{}. It's very popular in the academic world. If LaTeX
998 is successful, this will produce a @file{.dvi} file, containing both the
999 titling and notes.  @code{ly2dvi} completes its task by deleting the two
1000 temporary files, leaving only @file{layout.dvi}.
1001
1002 Next, now we'll look at the examples line by line to explain new things.
1003
1004 @example 
1005 \version "1.3.124";
1006 @end example 
1007 Lilypond and its language are still under development, and occasionally,
1008 details of the syntax are changed. This fragment indicates for which
1009 version the input file was written. When you compile this file, the
1010 version number will be checked, and you will get a warning when the file
1011 is too old.
1012
1013 This version number is also used by the @code{convert-ly} program (See
1014 @ref{convert-ly}), which uses it update the file to the latest lily
1015 version.
1016
1017 @example
1018   \header @{ title = "Two miniatures";  @}
1019 @end example
1020 This sets the titling information for the entire file.
1021
1022 @example
1023         #(set! point-and-click line-column-location)
1024 @end example
1025
1026 This is Scheme code. It sets the variable @code{point-and-click} to the
1027 value @var{true}. 
1028
1029 Editing input files can be quite complicated if you're working with
1030 large files: if you're digitizing existing music, you have to
1031 synchronize the .ly file, the sheet music on your lap and the sheet
1032 music on the screen.  The point-and-click mechanism makes it easy to
1033 find the origin of an error in the .ly file: @footnote{This feature is
1034 presently only available on X-windows using patched versions of Xdvi and
1035 emacs} when you view the file with Xdvi and click on a note using
1036 control-mousebutton 1@footnote{If you're using a patched xdvik, the
1037 command is control-mousebutton-2}, your editor will jump to the spot
1038 where that note was entered.
1039
1040 More information is in in @ref{Point and click} 
1041
1042 @example
1043   \paper @{ 
1044 @end example
1045
1046 The @code{\score} blocks that follow in the file don't have
1047 @code{\paper} sections, so the settings of this block are substituted: A
1048 paper block, at top-level, i.e. not in a @code{\score} block sets the
1049 default page layout.
1050
1051 @example
1052   linewidth = -1.0; @}
1053 @end example
1054
1055
1056
1057 The variable @code{linewidth} normally sets the length of the systems on
1058 the page. However, a negative value has a special meaning. If
1059 @code{linewidth} is less than 0, no line breaks are inserted into the
1060 score, and the spacing is set to natural length: a short phrase takes up
1061 little space, a longer phrase more space.
1062
1063 @example
1064   \score @{
1065     \notes @{ c'4 d'4 @}
1066 @end example
1067
1068 In previous examples, notes were specified in relative octaves,
1069 i.e. each note was put in the octave that would put it closest to its
1070 predecessor. Besides relative, there is also absolute octave
1071 specification, and it is turned on by default. In this input mode, the
1072 central C is denoted by @code{c'}. Going down, you get @code{c}
1073 @code{c,} @code{c,,} etc.  Going up, you get @code{c''} @code{c'''} etc.
1074
1075 When you're copying music from existing sheet music, relative octaves
1076 are probably the easiest to use: it's less typing work and errors are
1077 easily spotted. However, if you write LilyPond input, either by hand
1078 (ie. composing) or by computer, absolute octaves are probably less work.
1079
1080
1081 @example
1082     \header @{
1083 @end example
1084
1085 The @code{\header} is normally at the top of the file, where it sets
1086 values for the rest of the file. If you want to typeset different pieces
1087 from one file (for example, if there are multiple movements, or if
1088 you're making a etude-book), you can put different @code{\score} blocks
1089 into the input file. ly2dvi will assemble all LilyPond output files into
1090 a big document. The contents of \header blocks specified within each
1091 score, are used for the titling of each movement.
1092 @example
1093         opus = "Opus 1.";
1094         piece = "Up"; @}
1095 @end example
1096 For example, the Opus number is put at the right, and the piece string
1097 will be at the left.
1098
1099
1100
1101 @node A piano excerpt
1102 @section A piano excerpt
1103
1104 Our third subject is a piece of piano music.  The fragment in the input
1105 file is a piano reduction of the G major Sinfonia by Giovanni Battista
1106 Sammartini.  It was composed around 1740.  It's in the source package
1107 under  the name @file{sammartini.ly}.
1108
1109 @lilypond[verbatim]
1110 \include "paper16.ly";
1111
1112 stemDown = \property Voice.Stem \override #'direction = #-1
1113 stemUp = \property Voice.Stem \override #'direction = #1
1114 stemBoth = \property Voice.Stem \revert #'direction  
1115
1116 viola = \notes \relative c' \context Voice = viola {
1117         <c4-\f-\arpeggio g' c>
1118         \stemDown g'8. b,16
1119         s1 s2. r4
1120         g
1121 }
1122
1123 oboes = \notes \relative c'' \context Voice = oboe {
1124         \stemUp s4  g8. b,16 c8 r <e'8.^\p g> <f16 a>
1125         \grace <e8( g> <d4 f> <c2 e> \times 2/3 { <d8 \< f> <e g> <f a> }
1126         <
1127           { \times 2/3 { a8 g c } \! c2 }
1128           \context Voice = oboeTwo {
1129                 \stemDown
1130                 \grace {
1131                   \property Grace.Stem \override #'direction = #-1
1132                   [f,16 g] }
1133                 f8 e e2
1134         } >
1135         \stemBoth
1136         \grace <c,8( e> <)b8. d8.-\trill> <c16 e> | 
1137         [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r  |
1138         [<c16( e>  < )e8. g>] <c8 e,>
1139 }
1140
1141 hoomPah  =  \repeat unfold 8
1142   \notes  \transpose c' { \stemUp c8 \stemBoth \stemDown c'8  \stemBoth  }
1143
1144 bassvoices = \notes \relative c' {
1145         c4 g8. b,16
1146         \autochange Staff \hoomPah
1147         \translator Staff = down
1148         \stemDown [c8 c'8] r4
1149         <g d'> r4
1150         < {\stemUp r2 <e4 c'> <c8 g'> }
1151           \context Voice = reallyLow  {\stemDown g2 ~ | g4 c8 } >
1152 }
1153
1154 \score {
1155         \context PianoStaff \notes <
1156                 \context Staff = up < \time 2/2;
1157                         \viola
1158                         \oboes
1159                 >
1160                 \context Staff = down < \time 2/2; \clef bass;
1161                         \bassvoices
1162                 >
1163         >
1164         \midi { }
1165         \paper {
1166           indent = 0.0;
1167           linewidth = 15.0 \cm; }
1168 }
1169 @end lilypond
1170
1171 If it looks like incomprehensible gibberish to you, then you are right.
1172 This example has been doctored to have as many quirks as possible.
1173
1174 @example
1175  stemDown =  \property Voice.Stem \override #'direction = #-1
1176 @end example
1177
1178 As you can see, this example features more voices on one staff. To make
1179 room for those voices, their notes have to be stemmed in opposite
1180 directions. These are the commands to make that happen.
1181
1182 The symbols that are printed, are internally represented by so-called
1183 Graphical Objects (or more colloquially: Grobs).  These statements
1184 concern the grob called `Stem'. Each grob is described by a bunch of
1185 settings. These setting determine the fonts, offsets, sub-routines to be
1186 called on the grob, etc.  The initial values of these settings are set
1187 in the Scheme file @file{scm/grob-description.scm}.
1188
1189 This statement adds a the setting for all Stem grobs in the current
1190 Voice: @code{direction} is set to @code{-1}, which encodes down. The
1191 setting remains in effect until it is reverted.  
1192
1193 @example
1194  \property Voice.Stem \revert #'direction  
1195 @end example
1196
1197 This statement reverts the old setting. If you do this, the effect of a
1198 @code{\stemDown} or @code{\stemUp} is neutralised.
1199
1200 @code{\override} and @code{\revert} function like a stack: you can push
1201 values onto the grob-setting-stack with @code{\override} and you pop
1202 them with @code{\revert}.
1203
1204 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1205 with some more often used formatting instructions, but to explain how it
1206 works, we wrote our own here.  Of course, you should use predefined
1207 identifiers like these if possible: then you will be affected less by
1208 the implementation changes we occasionally make.
1209
1210 @example 
1211 viola = \notes \relative c'  \context Voice = viola @{ 
1212 @end example 
1213 In this example, you can see multiple parts on a staff.  Each part is
1214 associated with one notation context.  This notation context handles
1215 stems and dynamics (among others).  The name of this context is
1216 @code{Voice}.  For each part we have to make sure that there is
1217 precisely one @code{Voice} context, so we give it an unique name
1218 (`@code{viola}').
1219
1220 @example 
1221 <c4-\f-\arpeggio g' c>
1222 @end example 
1223 The delimiters @code{<} and @code{>} are shorthands for
1224 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1225 @code{<} and @code{>} is a chord.
1226
1227 @cindex dynamics
1228 @cindex loudness
1229 @cindex forte
1230 @cindex arpeggio
1231
1232 @code{\f} places a forte symbol under the chord. The forte applies to
1233 the whole chord, but the syntax requires that commands like forte and
1234 arpeggio are attached to a note, so here we attach them to the first
1235 note.
1236
1237 @code{\arpeggio} draws an vertical wavy line before the chord,
1238 signifying an arpeggio.
1239
1240 @example 
1241    \stemDown
1242 @end example 
1243
1244
1245 @example 
1246         g'8. b,16 
1247 @end example 
1248 Relative octaves work a little differently with chords.  The starting
1249 point for the note following a chord is the first note of the chord.  So
1250 the @code{g} gets an octave up quote: it is a fifth above the starting
1251 note of the previous chord (the central C).
1252
1253 @example 
1254 s1 s2. r4 
1255 @end example 
1256 @code{s} is a spacer rest.  It does not print anything, but it does have
1257 the duration of a rest. It is useful for filling up voices that
1258 temporarily don't play. In this case, the viola doesn't come until one
1259 and a half measure later.
1260
1261 @example 
1262 oboes = \notes \relative c'' \context Voice = oboe @{ 
1263 @end example 
1264 Now comes a part for two oboes.  They play homophonically, so we
1265 print the notes as one voice that makes chords. Again, we insure that
1266 these notes are indeed processed by precisely one context with
1267 @code{\context}.
1268 @example 
1269 \stemUp s4  g8. b,16 c8 r <e'8.-\p g> <f16 a> 
1270 @end example 
1271 @code{\stemUp} is a reference to the @code{\property \override} command
1272 defined above.   .
1273 @example 
1274 \grace <e8 g> < d4 f> <c2 e> 
1275 @end example
1276 @cindex @code{\grace}
1277 @cindex ornaments
1278 @cindex grace notes
1279
1280 @code{\grace} introduces grace notes.  It takes one argument, in this
1281 case a chord.
1282
1283 @ignore
1284 The slur started on the @code{e} of the chord
1285 will be attached to the next note.@footnote{LilyPond will squirm
1286 about unended Slurs.  In this case, you can ignore the warning}.
1287 @end ignore
1288 @example 
1289 \times 2/3 
1290 @end example
1291 @cindex tuplet
1292 @cindex triplets
1293 Tuplets are made with the @code{\times} keyword.  It takes two
1294 arguments: a fraction and a piece of music.  The duration of the piece
1295 of music is multiplied by the fraction.  Triplets make notes occupy 2/3
1296 of their notated duration, so in this case the fraction is 2/3.
1297 @example 
1298 @{ <d8 \< f> <e g> <f a> @} 
1299 @end example 
1300 The piece of music to be `tripletted' is sequential music containing
1301 three notes.  On the first chord, a crescendo is started with
1302 @code{\<}. To be precise, the crescendo start is syntactically attached
1303 to the preceding note, the @code{d}.
1304
1305 @cindex dynamics
1306 @cindex crescendo
1307 @cindex @code{\<}
1308
1309 @example 
1310
1311 @end example 
1312 At this point, the homophonic music splits into two rhythmically
1313 different parts.  We can't use a sequence of chords to enter this, so
1314 we make a `chord' of sequences to do it.  We start with the upper
1315 voice, which continues with upward stems:
1316 @example 
1317  @{ \times 2/3 @{ a8 g c @} \! c2 @} 
1318 @end example
1319
1320 @cindex @code{\!}
1321
1322 The crescendo is ended at the half note by the escaped exclamation
1323 mark @code{\!}.
1324 @example 
1325 \context Voice = oboeTwo @{
1326 \stemDown 
1327 @end example 
1328 We can't share stems with the other voice, so we have to create a new
1329 @code{Voice} context.  We give it the name @code{oboeTwo} to distinguish
1330 it from the other context.  Stems go down in this voice.
1331 @example 
1332 \grace @{  
1333 @end example
1334 @cindex Grace context
1335 When a grace section is processed, a @code{Grace} context is
1336 created. This context acts like a miniature score of its own.  It has
1337 its own time bookkeeping, and you can make notes, beams, slurs
1338 etc. Here we fiddle with a property and make a beam.  The argument of
1339 @code{\grace} is sequential music.
1340
1341 @example 
1342 \property Grace.Stem \override #'direction = #-1
1343 [f,16 g] @}
1344 @end example 
1345
1346 Normally, grace notes are always stem up, but in this case, the upper
1347 voice interferes. We set the stems down here.
1348
1349 As far as relative mode is concerned, the previous note is the
1350 @code{c'''2} of the upper voice, so we have to go an octave down for
1351 the @code{f}.
1352 @example 
1353
1354   f8 e e2
1355 @} > 
1356 @end example 
1357 This ends the two-part section.
1358 @example 
1359 \stemBoth
1360 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |  
1361 @end example
1362 @cindex trill
1363 @cindex stemBoth
1364
1365 @code{\stemBoth} ends the forced stem directions. From here, stems are
1366 positioned as if it were single part music.
1367
1368 The bass has a little hoom-pah melody to demonstrate parts switching
1369 between staffs.  Since it is repetitive, we use repeats:
1370 @example 
1371 hoomPah  =  \repeat unfold 8
1372 @end example
1373 @cindex unfolded @code{\repeat}
1374 This repeat print the following sequence notes eight times.
1375 @example
1376 \notes \transpose c' @{
1377 @end example
1378 @cindex transposing
1379 @cindex relative mode and transposing
1380
1381 Transposing can be done with @code{\transpose}.  It takes two arguments;
1382 the first specifies what central C should be transposed to.  The second
1383 is the to-be-transposed music.  As you can see, in this case, the
1384 transposition is a no-op, as central C stay at central C.
1385
1386 The purpose of this no-op is circumventing relative mode.  Relative mode
1387 can not be used together with transposition, so @code{\relative} will
1388 leave the contents of @code{\hoomPah} alone.  We can use it without
1389 having to worry about getting the motive in a wrong octave.
1390 @example 
1391 bassvoices = \notes \relative c' @{
1392 c4 g8. b,16
1393 \autochange Staff \hoomPah 
1394 @end example
1395 @cindex staff switch, automatic
1396 @cindex cross staff voice, automatic
1397 @cindex @code{\autochange}
1398
1399 Voices can switch between staffs. The easiest way to get this, is to use
1400 @code{\autochange}. This command looks at the pitch of each note, and if
1401 necessary, will cross to the other staff. For this to work, the two
1402 staffs must be called @code{"up"} and @code{"down"}. 
1403 @example
1404         \translator Staff = down
1405 @end example
1406 @cindex staff switch
1407 @cindex cross staff voice
1408 The rest of this melody must be in the lower staff, so we do a manual
1409 staff switch here.
1410
1411
1412 @example 
1413 \context Voice = reallyLow  @{\stemDown g2 ~ | g4 c8 @} > 
1414 @end example
1415 @cindex tie
1416 @cindex @code{~}
1417 After skipping some lines, we see @code{~}.  This mark makes ties.
1418 @example 
1419 \context PianoStaff 
1420 @end example 
1421  A special context is needed to get cross staff beaming right.  This
1422 context is called @code{PianoStaff}.
1423 @example 
1424 \context Staff = bottom < \time 2/2; \clef bass; 
1425 @end example 
1426 The bottom staff must have a different clef.
1427 @example 
1428 indent = 0.0; 
1429 @end example 
1430 To make some more room on the line, the first (in this case the only)
1431 line is not indented.  The line still looks very cramped, but that is due
1432 to the page layout of this document.
1433
1434
1435 @ignore
1436 [TODO:
1437
1438 * font-size, multi-stanza.
1439
1440 * Simple part combining in a Hymn
1441 @end ignore
1442
1443 @node An orchestral score
1444 @section An orchestral score
1445
1446 If you've come this far, you should have seen enough LilyPond source to
1447 feel comfortable with an orchestral score.  We will not go through the
1448 input line by line, but only indicate and explain the new elements.
1449
1450 This orchestral score example consists of three input files.  In the
1451 first file, @file{os-music.ly}, we define the music for all instruments.
1452 This file is to be used by the other two files, as you will see below.
1453 If you run lilypond on this file, no output will be produced.
1454
1455
1456 @example
1457 % os-music.ly
1458 \header @{
1459   title = "Zo, goed lieverd?";
1460   subtitle = "How's, this babe?";
1461   composer = "JCN";
1462   opus = "1";
1463   piece = "Laid back";
1464 @}
1465 global = @{
1466   \time 2/4;
1467   \skip 2*4; \bar "|.";
1468 @}
1469 Key = \notes \key as \major;
1470 flautoI = \notes\relative c'' @{
1471   f8 g f g f g f g
1472   bes as bes as bes as bes as
1473 @}
1474 flautoII = \notes\relative c'' @{
1475   as8 bes as bes R1 d4 ~ d
1476 @}
1477 tromboI = \notes\relative c'' @{
1478   c4. c8 c8 c4. es4 R1*1/2 es4
1479 @}
1480 tromboII = \notes\relative c'' @{
1481   as4. as8 as8 as4. R1*1/2 as4 es'
1482 @}
1483 timpani = \notes\relative c, @{
1484   \times 2/3 @{ f4 f f @}
1485   \times 4/5 @{ as8 as as as as @}
1486   R1
1487 @}
1488 corno = \notes\relative c' @{
1489    bes4 d f, bes d f, bes d
1490 @}
1491 @end example
1492
1493 Things to note here are the definition of @code{\global} where we define
1494 meter, and set the end bar.  And the separate definition of @code{\Key}
1495 that we will use all staffs except staffs for transposing instruments. 
1496
1497 The second file, @file{os-score.ly} reads the definitions of the first
1498 (@file{os-music.ly}), and defines the @code{\score} block for the full
1499 conductor's score.
1500
1501 @example
1502 % os-score.ly
1503 \include "os-music.ly";
1504 \include "paper13.ly";
1505
1506 #(set! point-and-click line-column-location)
1507 #(define text-flat '((font-relative-size . -2)
1508          (music "accidentals--1")))
1509
1510 \score @{
1511   <
1512     \global
1513     \context StaffGroup = woodwind <
1514       \context Staff = flauti <
1515         \property Staff.midiInstrument = #"flute"
1516         \property Staff.instrument = "2 Flauti"
1517         \property Staff.instr = "Fl."
1518         \Key
1519         \context Voice=one @{ \voiceOne \flautoI @}
1520         \context Voice=two @{ \voiceTwo \flautoII @}
1521       >
1522     >
1523     \context StaffGroup = timpani <
1524       \context Staff = timpani <
1525         \property Staff.midiInstrument = #"timpani"
1526         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1527         \property Staff.instr = #"Timp."
1528         \clef bass;
1529         \Key
1530         \timpani
1531       >
1532     >
1533     \context StaffGroup = brass <
1534       \context Staff = trombe <
1535         \property Staff.midiInstrument = #"trumpet"
1536         \property Staff.instrument = #`(lines "2 Trombe" "(C)")
1537         \property Staff.instr = #`(lines "Tbe." "(C)")
1538         \Key
1539         \context Voice=one \partcombine Voice
1540           \context Thread=one \tromboI
1541           \context Thread=two \tromboII
1542       >
1543       \context Staff = corni <
1544         \property Staff.midiInstrument = #"french horn"
1545         \property Staff.instrument = #`(lines "Corno"
1546           (rows "(E" ,text-flat ")"))
1547         \property Staff.instr = #`(lines "Cor."
1548           (rows "(E" ,text-flat ")"))
1549         \property Staff.transposing = #3
1550         \notes \key bes \major;
1551         \context Voice=one \corno
1552       >
1553     >
1554   >
1555   \paper @{
1556     indent = 15 * \staffspace;
1557     linewidth = 60 * \staffspace;
1558     textheight = 90 * \staffspace;
1559     \translator@{
1560       \ThreadContext
1561       \consists "Rest_engraver";
1562     @}
1563     \translator@{
1564       \VoiceContext
1565       \remove "Rest_engraver";
1566       \consists "Multi_measure_rest_engraver";
1567       \consists "Bar_engraver";
1568     @}
1569     \translator@{
1570       \HaraKiriStaffContext
1571       \remove "Multi_measure_rest_engraver";
1572       \remove "Bar_engraver";
1573     @}
1574     \translator @{
1575       \OrchestralScoreContext
1576       BarNumber \override #'padding = #3
1577     @}
1578   @}
1579   \midi @{
1580     \tempo 4 = 75;
1581   @}
1582 @}
1583 @end example
1584
1585 @center @strong{Zo, goed lieverd?}
1586 @sp 1
1587 @center How's, this babe?
1588 @flushright
1589 Opus 1.
1590 @end flushright
1591 @flushleft
1592 @sc{Laid back}
1593 @end flushleft
1594
1595 @lilypondfile{os-score.ly}
1596
1597 First, we need to include the music definitions we made in
1598 @file{os-music.ly}.
1599 @example
1600 \include "os-music.ly";
1601 @end example
1602
1603 In a large orchestral score like this you're bound to make some small
1604 mistakes, so we enable point and click (See @ref{Point and click})
1605 editing.
1606 @example
1607 #(set! point-and-click line-column-location)
1608 @end example
1609
1610 We need a flat sign in text to name the tuning of the french horn, so we
1611 predefine it with bit of scheme markup text (See @ref{Text markup}).
1612 @example
1613 #(define text-flat '((font-relative-size . -2)
1614          (music "accidentals--1")))
1615 @end example
1616
1617 Of course, all staffs are simultaneous and use the same global settings.
1618 @example
1619   <
1620     \global
1621 @end example
1622
1623 Then, we start a new staff group for the woodwind section (just the
1624 flutes in this case).  Immediately after that, we start the staff for
1625 the two flutes, that also play simultaneously.
1626 @example
1627     \context StaffGroup = woodwind <
1628       \context Staff = flauti <
1629 @end example
1630
1631 We specify the intrument for MIDI output (see @ref{MIDI instrument
1632 names}).
1633 @example
1634         \property Staff.midiInstrument = #"flute"
1635 @end example
1636
1637 And define the intrument names to be printed in the margin,
1638 @code{instrument} for the first line of the score, @code{instr} for the
1639 rest of the score.
1640 @example
1641         \property Staff.instrument = "2 Flauti"
1642         \property Staff.instr = "Fl."
1643 @end example
1644
1645 The flutes play in the default key.
1646 @example
1647         \Key
1648 @end example
1649
1650 Last come the actual flute parts.  Remember that we're still in
1651 simultaneous mode.  We name both voices differently, so that LilyPond
1652 will actually create two Voice contexts.  The flute parts are simple, so
1653 we specify manually which voice is which: @code{\voiceOne} forces the
1654 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
1655 directions down.
1656 @example
1657         \context Voice=one @{ \voiceOne \flautoI @}
1658         \context Voice=two @{ \voiceTwo \flautoII @}
1659 @end example
1660
1661 We close the flutes staff and woodwind staff group.
1662 @example
1663       >
1664     >
1665 @end example
1666
1667 The timpani staff only shows a new piece of scheme markup, it sets two
1668 lines of text.
1669 @example
1670         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1671 @end example
1672
1673 For the trumpets we use the automatic part combiner (see @ref{Automatic
1674 part combining}) to combine the two simultaneous trumpet parts onto the
1675 trumpet staff.  Each trumpet gets its own Thread context, which must be
1676 named @code{one} and @code{two}).  The part combiner makes these two
1677 threads share a Voice when they're similar, and splits the threads up
1678 when they're different.
1679 @example
1680         \context Voice=one \partcombine Voice
1681           \context Thread=one \tromboI
1682           \context Thread=two \tromboII
1683 @end example
1684
1685 The french horn has the most complex scheme markup name, made up of two
1686 lines of text.  The second line has two elements (rows), the @code{E}
1687 and the flat sign @code{text-flat} that we defined before.
1688 @example
1689         \property Staff.instrument = #`(lines "Corno"
1690           (rows "(E" ,text-flat ")"))
1691 @end example
1692
1693 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
1694 transpose this staff by three steps.
1695 @example
1696         \property Staff.transposing = #3
1697 @end example
1698
1699 Therefore, it has a different key.
1700 @example
1701         \notes \key bes \major;
1702 @end example
1703
1704 We specify a big indent for the first line and a small linewith for this
1705 tuturial.
1706 @example
1707     indent = 15 * \staffspace;
1708     linewidth = 60 * \staffspace;
1709 @end example
1710
1711 Because we have a Thread representing one instrument, we need to move
1712 the @code{Rest_engraver} from Voice to Thread level.  Similarly, we need
1713 to move the @code{Multi_measure_rest_engraver} from Staff to Voice level.
1714 @example
1715     \translator@{
1716       \ThreadContext
1717       \consists "Rest_engraver";
1718     @}
1719     \translator@{
1720       \VoiceContext
1721       \remove "Rest_engraver";    
1722       \consists "Multi_measure_rest_engraver";
1723       \consists "Bar_engraver";
1724     @}
1725 @end example
1726
1727 In orchestral scores, it often happens that one instrument has only
1728 rests during one line of the score.  The @code{HaraKiriStaffContext} can
1729 be used as a regular @code{StaffContext} drop-in and will take care of
1730 the automatic removing of empty staffs.
1731 @example
1732     \translator@{
1733       \HaraKiriStaffContext
1734       \remove "Multi_measure_rest_engraver";
1735       \remove "Bar_engraver";
1736     @}
1737 @end example
1738
1739 We want bar numbering at score level and want to move the bar number a
1740 few staff spaces up.
1741 @example
1742     \translator @{
1743       \OrchestralScoreContext
1744       BarNumber \override #'padding = #3
1745     @}
1746 @end example
1747
1748 @node Part extraction
1749 @section Part extraction
1750
1751 The third file, @file{os-flute-2.ly} also reads the definitions of the
1752 first (@file{os-music.ly}), and defines the @code{\score} block for the
1753 second flute part.
1754
1755 @example
1756 \include "os-music.ly";
1757 \include "paper16.ly";
1758
1759 \score @{
1760   \context Staff <
1761     \property Staff.midiInstrument = #"flute"
1762     \global
1763     \Key
1764     \flautoII
1765   >
1766   \header @{
1767     instrument = "Flauto II";
1768   @}
1769   \paper @{
1770     linewidth = 80 * \staffspace;
1771     textheight = 200 * \staffspace;
1772     \translator @{
1773       \OrchestralScoreContext
1774       skipBars = ##t
1775     @}
1776   @}
1777   \midi @{
1778     \tempo 4 = 75;
1779   @}
1780 @}
1781 @end example
1782
1783 @center @strong{Zo, goed lieverd?}
1784 @sp 1
1785 @center How's, this babe?
1786 @center @emph{Flauto II}
1787 @flushright
1788 Opus 1.
1789 @end flushright
1790 @flushleft
1791 @sc{Laid back}
1792 @end flushleft
1793 @lilypondfile{os-flute-2.ly}
1794
1795
1796 Because we separated the music definitions from the @code{\score}
1797 instantiations, we can easily define a second score from the music of
1798 the second flute.  This then is the part for the second flute player.
1799 Of course, we make separate parts for all individual instruments.
1800
1801 In this individual part the second flute has a whole staff for itself,
1802 so we don't want to force stem or tie directions.
1803 @example
1804     \flautoII
1805 @end example
1806
1807 The @code{\header} definitions were also read from @file{os-music.ly},
1808 but we need to set the instrument for this particular score.
1809 @example
1810   \header @{
1811     instrument = "Flauto II";
1812   @}
1813 @end example
1814
1815 In the conductor's full score, all bars with rests are printed, but for
1816 the individual parts, we want to contract pieces of consecutive empty
1817 bars.
1818 @example
1819       skipBars = ##t
1820 @end example
1821
1822 @node  end of tutorial
1823 @section The end        
1824          
1825 That's all folks.  From here, you can either try fiddling with input
1826 files, or you can read the reference manual.  You can find more example
1827 files in @file{input} and @file{input/test}.  You can also look at Real
1828 Music (TM), have a look at the @ref{Mutopia project}.
1829
1830
1831
1832 [TODO figure out what to do with this: ]
1833
1834
1835 @node Pre-cooked makefile
1836 @section Pre-cooked makefile
1837
1838 @c waar deze info?  is uiteindelijk wel handig, schat ik.
1839 [TODO: cut blabla]
1840
1841 If you have a big music project, or just a lot of LilyPond input files,
1842 all generated output from LilyPond, @TeX{} and metafont will clutter
1843 your working directory.  LilyPond comes with a one-size-fits-all
1844 pre-cooked makefile that helps you manage producing ouptut.  It will
1845 produce all output in @file{out}, generate and track dependencies.
1846 Also, it helps in preparing your submission to the @ref{Mutopia
1847 project}.
1848
1849 @file{make/ly.make}
1850 @example
1851 mkdir my-project
1852 cd my-project
1853 cp /usr/share/lilypond/make/ly.make GNUmakefile
1854 cp /usr/share/doc/lilypond/examples/input/tutorial/menuet.ly .
1855 make menuet
1856 [..]
1857 Generated out/menuet.ps for target menuet.
1858 @end example
1859
1860 Type @samp{make help} to see possible targets.
1861
1862 [TODO]
1863 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
1864