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