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