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