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