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