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