]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
release: 1.5.9
[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 @menu
10 * First steps::                 Music language of LilyPond
11 * Simple legend::               Small table of music language symbols
12 * Running LilyPond::            Printing music
13 * The first real tune::         The first real tune
14 * Lyrics and chords::           Lyrics and chords
15 * More movements ::             Joining separate pieces of music
16 * A piano excerpt::             Piano music
17 * An orchestral score::         Conductor's score and individual parts
18 * Other ways to run LilyPond::  Other ways to run LilyPond
19 * Integrating text and music::  Integrating text and music
20 * End of tutorial::             The end
21 @end menu
22
23
24 The music is described in a text file, using a simple music language.
25 LilyPond reads that text file and generates music that you can print or
26 view.
27
28 Therefore, creating music notation with LilyPond is done in two steps.
29 Using a text editor, you write down the notes to print.  Then, you run
30 LilyPond to get your printed output.
31
32 This tutorial starts with a small introduction to the LilyPond music
33 language.  After this first contact, we will show you how to run
34 LilyPond to produce printed output; you should then be able to create
35 your first sheets of music.
36
37 The tutorial continues with a slightly more elaborate example of real music.
38 This piece introduces and explains some finer details of LilyPond.
39 Then, a number of more complex examples follow, that will help you to
40 produce most complex music with LilyPond.
41
42
43 @c title?
44
45 @node First steps
46 @section First steps
47
48 @c @node Music language of LilyPond
49 @c @section Music language of LilyPond
50
51 This section shows how easy writing music with LilyPond actually is.  If
52 you have not seen LilyPond input source before, this section is for you.
53
54 The next section has a table (see @ref{Simple legend}) of all symbols
55 that are introduced here, you may want to keep an eye on that.
56
57 Writing music with LilyPond is explained below by a number of small
58 examples.  Each example has a small piece of text; the LilyPond input
59 that you should type, with the resulting music printed below it.
60
61 You get a simple note by typing its note name, from @code{a} through
62 @code{g}:
63
64 @quotation
65 @example
66 c d e f g a b
67 @end example
68
69 @lilypond[fragment]
70 \property Score.timing = ##f
71 \property Staff.TimeSignature = \turnOff
72 \transpose c'' { c d e f g a b }
73 @end lilypond
74 @end quotation
75 @separate
76
77 The length of a note is specified by adding a number, ``@code{1}'' for a
78 whole note, ``@code{2}'' for a half note, and so on:
79
80 @quotation
81 @example
82 a1 a2 a4 a16 a32
83 @end example
84
85 @c missing clef seems to raise more questions than actual pitch of notes,
86 @c as these are snippets anyway
87 @lilypond[fragment]
88 \property Score.timing = ##f
89 \property Staff.TimeSignature = \turnOff
90 \property Staff.noAutoBeaming = ##t
91 %\property Staff.Clef = \turnOff
92 \transpose c'' { a1 a2 a4 a16 a32 }
93 s16_" "
94 @end lilypond
95 @end quotation
96 @separate
97
98 If you don't specify a duration, the previous duration is used: 
99
100 @quotation
101 @example
102 a a a2 a
103 @end example
104
105 @c missing clef seems to raise more questions than actual pitch of notes,
106 @c as these are snippets anyway
107 @lilypond[fragment]
108 \property Score.timing = ##f
109 \property Staff.TimeSignature = \turnOff
110 %\property Staff.Clef = \turnOff
111 \transpose c'' { a a a2 a }
112 s16_" "
113 @end lilypond
114 @end quotation
115 @separate
116
117 A sharp (@texisharp{}) is made by adding ``@code{is}'', a flat
118 (@texiflat{}) by adding ``@code{es}'':
119
120 @quotation
121 @example
122 cis1 ees fisis aeses
123 @end example
124
125 @lilypond[fragment]
126 \property Score.timing = ##f
127 \property Staff.TimeSignature = \turnOff
128 \transpose c'' { cis1 ees fisis aeses }
129 s16_" "
130 @end lilypond
131 @end quotation
132 @separate
133
134 Add a dot ``@code{.}'' after the duration to get a dotted note:
135 @quotation
136 @example
137 a2. a4 a8. a16
138 @end example
139
140 @c missing clef seems to raise more questions than actual pitch of notes,
141 @c as these are snippets anyway
142 @lilypond[fragment]
143 \property Score.timing = ##f
144 \property Staff.TimeSignature = \turnOff
145 %\property Staff.Clef = \turnOff
146 \transpose c'' { a2. a4 a8. a16 }
147 s16_" "
148 @end lilypond
149 @end quotation
150 @separate
151
152 The meter (or time signature) can be set with the ``@code{\time}'' command:
153
154 @quotation
155 @example
156 \time 3/4
157 \time 6/8
158 \time 4/4
159 @end example
160
161 @c a clef here may lead to confusion
162 @lilypond[fragment]
163 \property Staff.Clef = \turnOff
164 \time 3/4
165 s4_" "
166 \time 6/8
167 s4_" "
168 \time 4/4
169 s16_" "
170 @end lilypond
171 @end quotation
172 @separate
173
174 The clef can be set using the ``@code{\clef}'' command:
175
176 @c what is more common name treble or violin?
177 @c in Dutch, its violin.
178 @quotation
179 @example
180 \clef violin
181 \clef bass
182 \clef alto
183 \clef tenor
184 @end example
185
186 @lilypond[fragment]
187 \property Score.timing = ##f
188 \property Staff.TimeSignature = \turnOff
189 \clef violin
190 s4_" "
191 \clef bass
192 s4_" "
193 \clef alto
194 s4_" "
195 \clef tenor
196 s16_" "
197 @end lilypond
198 @end quotation
199 @separate
200
201 From these commands and notes, a piece of music can be formed.  A piece
202 of music is made by enclosing it in ``@code{\notes @{ ... @}}''.
203 LilyPond then knows that music follows (and not lyrics, for example):
204
205 @quotation
206 @example
207 \notes @{
208    \time 3/4
209    \clef bass
210    c2 e4 g2.
211    f4 e d c2.
212 @}
213 @end example
214 @end quotation
215 @separate
216
217 At this point, the piece of music is ready to be printed.  This is done
218 by combining the music with a printing command.
219
220 The printing command is the so-called ``@code{\paper}'' block.  You will
221 see later that the \paper block is necessary to customize all kinds of
222 printing specifics.  The music and the \paper block are combined by
223 enclosing them in ``@code{\score @{ ... @}}''.  This is what a full
224 LilyPond source file looks like:
225
226 @quotation
227 @example
228 \score @{
229   \notes @{
230      \time 3/4
231      \clef bass
232      c2 e4 g2.
233      f4 e d c2.
234   @}
235   \paper @{ @}
236 @}
237 @end example
238
239 @lilypond
240 \score {
241   \notes {
242      \time 3/4
243      \clef bass
244      c2 e4 g2.
245      f4 e d c2.
246   }
247   \paper { linewidth = 60 * \staffspace }
248 }
249 @end lilypond
250 @end quotation
251 @separate
252
253
254 We continue with the introduction of the remaining musical constructs.
255
256 @c maybe legend here?
257
258 Rests are entered just like notes with the name ``@code{r}'':
259
260 @quotation
261 @example
262 r2 r4 r8 r16
263 @end example
264
265 @lilypond[fragment]
266 \property Score.timing = ##f
267 \property Staff.Clef = \turnOff
268 \property Staff.TimeSignature = \turnOff
269 r2 r4 r8 r16
270 s16_" "
271 @end lilypond
272 @end quotation
273 @separate
274
275 @c Tim wants to move this quotes example just before the: quotes-don't-work
276 @c score, but we'd need to remove quotes from the other two (key and
277 @c tie) examples...
278
279 @c better to have this just before the `octaves are bad' snipped
280 @c but we'd need to remove the ', from \key and tie 
281 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
282 the note name, to lower a note one octave, add a ``low quote'' @code{,}
283 (a comma).  The central C is @code{c'}:
284
285 @quotation
286 @example
287 c'4 c'' c''' \clef bass c c,
288 @end example
289
290 @lilypond[fragment]
291 \property Score.timing = ##f
292 \property Staff.TimeSignature = \turnOff
293 c'4 c'' c''' \clef bass c c,
294 @end lilypond
295 @end quotation
296 @separate
297
298 A tie is created by entering a tilde ``@code{~}'' between the notes to
299 be tied.  A tie between two notes means that the second note must not be
300 played separately, but just makes the first note sound longer:
301
302 @quotation
303 @lilypond[fragment,verbatim]
304 g'4 ~ g' a'2 ~ a'4
305 @end lilypond
306 @end quotation
307 @separate
308
309 The key signature is set with the command ``@code{\key}'':
310 @quotation
311 @example
312 \key d \major
313 g'1
314 \key c \minor
315 g'
316 @end example
317
318 @lilypond[fragment]
319 \property Staff.TimeSignature = \turnOff
320 \key d \major
321 g'1
322 \key c \minor
323 g'
324 @end lilypond
325 @end quotation
326
327
328 @c bit on the long/complex/scary taste
329 @c cheating a bit: two lines makes for a friendlier look
330 This example shows notes, ties, octave marks, and rests in action.
331 Don't worry about all the quotes.
332
333 @quotation
334 @example
335 \score @{
336   \notes @{
337     \time 4/4
338     \clef violin
339     \key d \minor
340     r4 r8 d''8 cis''4 e''
341     d''8 a'4. ~ a' b'8
342     cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
343     cis''2 r2
344   @}
345   \paper @{ @}
346 @}
347 @end example
348
349 @lilypond
350 \score {
351   \notes {
352     \time 4/4
353     \clef violin
354     \key d \minor
355     r4 r8 d''8 cis''4 e''
356     d''8 a'4. ~ a' b'8
357     cis''4 cis''8 cis'' bis'4 d''8 cis'' ~
358     cis''2 r2
359   }
360   \paper { linewidth = 50*\staffspace }
361 }
362 @end lilypond
363 @end quotation
364
365 @c accidentals...
366 There are some interesting points to note in this example.  Firstly,
367 accidentals (sharps and flats) don't have to be marked explicitly: you
368 just enter the note name, and LilyPond determines whether or not to
369 print an accidental.  Secondly, bar lines and beams are drawn
370 automatically.  Thirdly, LilyPond calculates line breaks for you; it
371 doesn't matter where you make new lines in the source file.
372
373 The example also indicates that a piece of music written in a high
374 register needs lots of quotes.  This makes the input a bit unreadable,
375 and is therefore also a potential source of errors.
376
377 @separate
378
379 The solution is to use ``relative octave'' mode.  In practice, most
380 music is entered using this mode.
381
382 To use relative mode, add @code{\relative} before the piece of music.
383 You must also give a note from which relative starts, in this case
384 @code{c''}.
385
386 @c In relative octave mode, quotes are used to mark large jumps in the
387 @c melody.  Without any quotes or commas, the interval between a note and
388 @c its predecessor is assumed to be a fourth or less.  Quotes and commas
389 @c add octaves in up and down direction.
390
391 If you type no octaviation quotes, relative mode chooses the note that
392 is closest to the previous one, which is often just the one you need.
393 @c don't use commas or quotes in this sentence
394 For example: @code{c f} goes up; @code{c g} goes down:
395
396 @quotation
397 @example
398 \relative c'' @{
399   c f c g c
400 @}
401 @end example
402
403 @lilypond[fragment]
404 \property Score.timing = ##f
405 \property Staff.TimeSignature = \turnOff
406 \relative c'' {
407   c f c g c
408 }
409 @end lilypond
410 @end quotation
411 @separate
412
413 @c needed better, maybe even redundant explanation
414 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
415 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
416 You can make a large interval by adding octaviation quotes.  Note that
417 quotes or commas do not determine the absolute height of a note;
418 the height of a note is relative to the previous one.
419 @c don't use commas or quotes in this sentence
420 For example: @code{c f,} goes down; @code{f, f} are both the same;
421 @code{c c'} are the same; and @code{c g'} goes up:
422
423 @quotation
424 @example
425 \relative c'' @{
426   c f, f c' c g' c,
427 @}
428 @end example
429
430 @lilypond[fragment]
431 \property Score.timing = ##f
432 \property Staff.TimeSignature = \turnOff
433 \relative c'' {
434   c f, f c' c g' c,
435 }
436 @end lilypond
437 @end quotation
438 @separate
439
440 A slur is drawn across many notes, and indicates bound articulation
441 (legato).  The starting note and ending note are marked with a
442 ``@code{(}'' and a ``@code{)}'' respectively:
443
444 @quotation
445 @lilypond[fragment,relative 1, verbatim]
446 d4( )c16( cis d e c cis d )e( )d4
447 @end lilypond
448 @end quotation
449 @separate
450
451 If you need two slurs at the same time (one for articulation, one for
452 phrasing), you can also make a phrasing slur with @code{\(} and
453 @code{\)}.
454
455 @c lousy example
456 @quotation
457 @lilypond[fragment,relative 1, verbatim]
458 a8(\( ais b ) c cis2 b'2 a4 cis, \) c
459 @end lilypond
460 @end quotation
461 @separate
462
463 Beams are drawn automatically, but if you don't like the choices, you
464 can enter beams by hand. Surround the notes to be grouped with @code{[}
465 and @code{]}:
466 @quotation
467 @lilypond[fragment,relative 1, verbatim]
468 [a8 ais] [d es r d]
469 @end lilypond
470 @end quotation
471 @separate
472
473 To print more than one staff, each piece of music that makes up a staff
474 is marked by adding @code{\context Staff} before it.  These
475 @code{Staff}'s can be grouped inside @code{<} and @code{>}, as is
476 demonstrated here:
477
478 @quotation
479 @lilypond[fragment,verbatim]
480 <
481   \context Staff = staffA { \clef violin c'' }
482   \context Staff = staffB { \clef bass c }
483 >
484 @end lilypond
485 @end quotation
486
487 In this example, @code{staffA} and @code{staffB} are names that are
488 given to the staves.  For now, it doesn't matter what names you give, as
489 long as each staff has a unique name.
490
491 @separate
492
493 We can typeset a melody with two staves now:
494
495 @quotation
496 @lilypond[verbatim]
497 \score {
498   \notes 
499   < \context Staff = staffA {
500       \time 3/4
501       \clef violin
502       \relative c'' { e2 ( d4 c2 b4 [a8 a] [b b] [g g] )a2. }  
503     }
504     \context Staff = staffB {
505        \clef bass
506        c2 e4  g2.
507        f4 e d c2.
508     }
509   >
510   \paper {} 
511 }
512 @end lilypond
513 @end quotation
514
515 Notice that the time signature is specified in one melody staff only
516 (the top staff), but is printed on both.  LilyPond knows that the time
517 signature should be the same for all staves.
518
519 @separate
520
521 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
522 @quotation
523 @lilypond[verbatim,relative 1]
524 c-. c-- c->
525 @end lilypond
526 @end quotation
527 @separate
528
529 Dynamic signs are made by adding the markings to the note:
530 @quotation
531 @lilypond[verbatim,relative 1]
532 c-\ff c-\mf
533 @end lilypond
534 @end quotation
535 @separate
536
537 Crescendi are started with the commands @code{\<}  and @code{\>}. The
538 command @code{\!} finishes a crescendo on the following note.
539 @quotation
540 @lilypond[verbatim,relative 1]
541 c2\<  \!c2-\ff  \>c2  \!c2
542 @end lilypond
543 @end quotation
544 @separate
545
546 Chords can be made by surrounding notes with @code{<} and @code{>}:
547 @quotation
548 @lilypond[relative 0, fragment,verbatim]
549 r4 <c e g> <c f a> 
550 @end lilypond
551 @end quotation
552 @separate
553
554 @ignore
555 @c te diepzinnig?
556 @c hmm, te losjes, iig
557 In general, @code{ < @var{stuff} > } is used when @var{stuff} all
558 happens at the same time, like in chords, or (like in the two-staff
559 example above) in a bunch of stacked staves.
560 @end ignore
561
562 Of course, you can combine beams and ties with chords.  Notice that
563 beam and tie markings are placed outside the chord markers:
564 @quotation
565 @lilypond[relative 0, fragment,verbatim]
566 r4 [<c8 e g> <c8 f a>] ~ <c8 f a>
567 @end lilypond
568 @end quotation
569
570 When you want to combine chords with slurs and dynamics, an annoying
571 technical detail crops up: you have type these commands next to the
572 notes, which means that they have to be inside the @code{< >}:
573
574 @quotation
575 @lilypond[relative 0, fragment,verbatim]
576 r4 <c8 e g \> ( > <c e g> <c e g>  < ) \! c8 f a>
577 @end lilypond
578 @end quotation
579 @separate
580
581 A nasty technical detail also crops up when you start a score with a
582 chord:
583
584 @quotation
585 @lilypond[verbatim,singleline]
586 \score { \notes <c'1 e'1> }
587 @end lilypond
588 @end quotation
589 @separate
590
591 The program can not guess that you want the notes on only one staff. To
592 force the chord on a staff, add @code{\context Staff} like this:
593
594 @quotation
595 @lilypond[verbatim,singleline]
596 \score { \notes \context Staff <c'1 e'1> }
597 @end lilypond
598 @end quotation
599 @separate
600
601
602
603
604 @ignore
605 [TODO add some more here
606
607 * lyrics, chords (?)
608
609 * \header
610
611 * identifiers?
612
613 ]
614 @end ignore
615
616 This is the end of the simple tutorial. You know the basic ingredients
617 of a music file, so this is the right moment to try your at hand at
618 doing it yourself: try to type some simple examples, and experiment a
619 little.
620
621 When you're comfortable with the basics, then you might want to read the
622 rest of this chapter. It also a manual in tutorial-style, but it is much
623 more in-depth. It will also be very intimidating if you're not familiar
624 with the basics.  It deals with some of the more advanced features of
625 LilyPond. Topics include lyrics, chords, orchestral scores and parts,
626 fine tuning output, polyphonic music, and integrating text and music.
627
628
629 @c refer to this section
630 @node Simple legend
631 @section Simple legend
632
633
634 @c need texinfo-4.0a or later for this
635
636
637 @c both Tim and my father came independently with a request for a
638 @c `legend' like this.
639
640 @c what should be in it?
641
642
643
644 @quotation
645 @multitable @columnfractions .10 .20 .40
646
647 @item @code{[ ]}
648 @tab beam
649 @tab
650 @lilypond[fragment, relative 1]
651 \property Score.timing = ##f
652 \property Staff.TimeSignature = \turnOff
653 \property Staff.noAutoBeaming = ##t
654 \property Staff.Clef = \turnOff
655 [a8 b]
656 @end lilypond
657
658 @item @code{~}
659 @tab tie
660 @tab
661 @lilypond[fragment, relative 1]
662 \property Score.timing = ##f
663 \property Staff.TimeSignature = \turnOff
664 \property Staff.noAutoBeaming = ##t
665 \property Staff.Clef = \turnOff
666 d ~ d
667 @end lilypond
668
669 @item @code{( )}
670 @tab slur
671 @tab
672 @lilypond[fragment, relative 1]
673 \property Score.timing = ##f
674 \property Staff.TimeSignature = \turnOff
675 \property Staff.noAutoBeaming = ##t
676 \property Staff.Clef = \turnOff
677 c( d )e
678 @end lilypond
679 @item @code{'}
680 @tab raise octave
681 @tab
682 @lilypond[fragment, relative 1]
683 \property Score.timing = ##f
684 \property Staff.TimeSignature = \turnOff
685 \property Staff.noAutoBeaming = ##t
686 \property Staff.Clef = \turnOff
687 a a'
688 @end lilypond
689
690 @item @code{,}
691 @tab lower octave
692 @tab
693 @lilypond[fragment, relative 1]
694 \property Score.timing = ##f
695 \property Staff.TimeSignature = \turnOff
696 \property Staff.noAutoBeaming = ##t
697 \property Staff.Clef = \turnOff
698 c c,
699 @end lilypond
700
701 @item @code{< >}
702 @tab chord
703 @tab
704 @lilypond[fragment, relative 1]
705 \property Score.timing = ##f
706 \property Staff.TimeSignature = \turnOff
707 \property Staff.noAutoBeaming = ##t
708 \property Staff.Clef = \turnOff
709 \context Voice { <a c> }
710 @end lilypond
711
712 @item @code{\< \!}
713 @tab crescendo
714 @tab
715 @lilypond[fragment, relative 1]
716 \property Score.timing = ##f
717 \property Staff.TimeSignature = \turnOff
718 \property Staff.noAutoBeaming = ##t
719 \property Staff.Clef = \turnOff
720 a\< a \!a
721 @end lilypond
722
723 @item @code{\> \!}
724 @tab decrescendo
725 @tab
726 @lilypond[fragment, relative 1]
727 \property Score.timing = ##f
728 \property Staff.TimeSignature = \turnOff
729 \property Staff.noAutoBeaming = ##t
730 \property Staff.Clef = \turnOff
731 a\> a \!a
732 @end lilypond
733
734 @end multitable
735 @end quotation
736
737
738
739 @node Running LilyPond
740 @section Running LilyPond
741
742 You write music with LilyPond as follows: first you edit a text file
743 containing a description of the notes.  Then you run LilyPond on the
744 file. This leaves you with an output file, which you can view or print.
745
746 In this section we explain how to run LilyPond, and view or print the
747 output.  If you have not used LilyPond before, want to test your setup
748 of LilyPond, or try to run an example file yourself, then read this
749 section.
750
751 The instructions that follow are for running LilyPond on Unix-like
752 systems.  Some additional instructions for running LilyPond on Windows
753 are given at the end of this section.
754
755 You begin with opening a terminal window, and start up a text editor.
756 For example, open an xterm and execute @code{joe}.  In your text editor,
757 enter the following input, and save the file as @file{test.ly}:
758
759 @quotation
760 @example
761 \score @{
762   \notes @{ c'4 e' g' @}
763 @} 
764 @end example
765 @end quotation
766
767 @cindex ly2dvi
768
769 @c now this is weird, running ly2dvi to run LilyPond
770 @c (therefore name change proposal) 
771
772 To run LilyPond, you invoke ly2dvi to compile your LilyPond source file:
773
774 @quotation
775 @example
776 ly2dvi -P test.ly
777 @end example
778 @end quotation
779
780 You will see the following on your screen:
781
782 @quotation
783 @example
784 GNU LilyPond 1.4.0
785 Now processing: `/home/fred/ly/test.ly'
786 Parsing...
787 Interpreting music...[1]
788  @emph{ ... more interesting stuff ... }
789 PS output to `test.ps'...
790 DVI output to `test.dvi'...
791 @end example
792 @end quotation
793 @cindex DVI file
794 @cindex Viewing music
795 @cindex xdvi
796
797 The results of the ly2dvi run are two files, @file{test.dvi} and
798 @file{test.ps}.  The PS file (@file{test.ps}) is the one you can print.
799 You can view the PS file using the program ghostview.  If a version of
800 ghostview is installed on your system, one of these commands will
801 produce a window with some music notation on your screen:
802 @c eeek
803 @quotation
804 @example
805   gv test.ps
806   ghostview test.ps
807   ggv test.ps
808   kghostview test.ps
809 @end example
810 @end quotation
811 If you are satisfied with the looks of the music displayed on your
812 screen, you can print the PS file by clicking File/Print inside
813 ghostview.
814
815 The DVI file (@file{test.dvi}) contains the same sheet music in a
816 different format. DVI files are more easily processed by the computer,
817 so viewing them usually is quicker.  Execute @code{xdvi test.dvi}
818 to view the DVI file.
819
820 If your DVI viewer does not have a "Print" button, you can print the
821 file by executing @code{lpr test.ps}.
822
823 @c volgende alinea schrappen?  
824
825 If you can't get the examples to print, then you should look into
826 installing and configuring ghostscript.  Refer to GhostScript's website
827 at @uref{http://www.ghostscript.com}.
828
829 @cindex GhostScript
830 @cindex @code{lpr}
831 @cindex Printing output
832 @cindex PostScript
833
834 @unnumberedsubsec Windows users
835 Windows users start the terminal by clicking on the LilyPond icon.
836 Notepad is sufficient for editing the LilyPond file. Viewing the PS file
837 can be done with @code{gsview32 test.ps}.  Viewing DVI files can be done
838 with @code{yap test.dvi}.  The "print" button in Yap will print files.
839 You can also print from the command line by executing @code{gsview32 /s
840 test.ps}
841
842
843 @node The first real tune
844 @section The first real tune
845
846
847 The rest of this tutorial will demonstrate how to use Lilypond by
848 presenting examples of input along with resulting output.  We will use
849 English terms for notation.  In case you are not familiar with those,
850 you may consult the glossary that is distributed with LilyPond.
851
852 The examples discussed are included in the distribution, in the
853 subdirectory @file{input/tutorial/}@footnote{When we refer to filenames,
854 they are relative to the top directory of the source package. }
855
856 To demonstrate what LilyPond input looks like, we start off with a
857 full-fledged, yet simple example. It is a convoluted version
858 of the famous minuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
859 is included in the distribution as  @file{minuet.ly}.
860 @cindex Bach, Johann Sebastian 
861
862 @lilypond[verbatim]
863 % all text after a percent sign is a comment
864 % and is ignored by LilyPond
865 \include "paper16.ly"
866 \score {
867     \notes                        
868     \relative c'' \sequential {
869             \time 3/4                
870             \key g \major
871
872         \repeat "volta" 2 {
873             d4 g,8 a b c d4 g, g |
874             e'4 c8 d e fis g4 g, g |
875             c4 d8( )c b a( )b4 c8 b a g |
876             a4 [b8 a] [g fis] g2.  |
877         }
878
879         b'4 g8 a b g
880         a4 d,8 e fis d |
881         g4 e8 fis g d cis4 b8 cis a4 |
882         a8-. b-. cis-. d-. e-. fis-.
883         g4 fis e |
884         fis a,  r8 cis8
885         d2.-\fermata
886         \bar "|."
887     }
888     \paper {
889        % standard settings are too big and wide for a book
890        indent = 1.0 \cm
891        linewidth = 15.0 \cm
892    }
893 }
894 @end lilypond
895
896 We will analyse the input, line by line.
897 @separate
898 @example
899         % all text after a percent sign is a comment
900         % and is ignored by LilyPond
901 @end example 
902 Percent signs introduce comments: everything after a percent sign is
903 ignored. You can use this to write down mental notes to yourself.  You
904 can also make longer comments by enclosing text in @code{%@{} and
905 @code{%@}}.
906 @cindex comment
907 @cindex block comment
908 @cindex line comment
909 @separate
910 @example 
911
912         \include "paper16.ly"
913  
914 @end example
915 @cindex @code{\include}
916 @cindex point, printer's
917 @cindex staff size setting 
918 By default, LilyPond will typeset the music in a size such that each
919 staff is 20 point (0.7 cm, or 0.27 inch) high.  We want smaller output
920 (16 point staff height), so we must import the settings for that size,
921 which is done here.
922 @separate
923 @example 
924
925         \score @{
926  
927 @end example 
928 Music is printed by combining a piece of music with directions for
929 outputting it.  This combination is formed in the @code{\score} block.
930 @separate
931 @example 
932
933         \notes                
934  
935 @end example 
936 Prepare LilyPond for accepting notes.
937 @cindex octaves, choosing
938 @cindex pitch
939 @separate
940 @example 
941
942         \relative c''
943  
944 @end example
945 @cindex relative
946 @c removed duplicate introduction to octave marks /MB
947 @c Shorten even more?
948
949 @c As we will see, each note is described by its note name, duration,
950 @c octave and possibly a chromatic alteration.  In this setup, the octave
951 @c is indicated by using high quotes (@code{'}) and ``lowered quotes''
952 @c (commas: @code{,}).  The central C is denoted by @code{c'}.  The C one
953 @c octave higher is @code{c''}.  One and two octaves below the central C is
954 @c denoted by @code{c} and @code{c,} respectively.
955
956 Even though a piece of music often spans a range of several octaves, it
957 mostly moves in small intervals.  LilyPond has a special entry mode to
958 save typing in this situation.  In this ``relative'' octave mode,
959 octaves of notes without quotes are chosen such that a note is as close
960 as possible (graphically, on the staff) to the preceding note.  If you
961 add a high-quote an extra octave is added.  A lowered quote (a comma)
962 will subtract an extra octave.
963
964 Because the first note has no predecessor,
965 you have to give the (absolute) pitch of the note to start with.
966 @separate
967 @example 
968
969         \sequential @{
970  
971 @end example 
972 What follows is sequential music, i.e.,
973 @cindex sequential music
974 notes that are to be played and printed after each other.
975 @separate
976 @example 
977
978         \time 3/4
979  
980 @end example
981 @cindex time signature, setting
982 @cindex @code{\time}
983 Set (or change) the time signature of the current piece: a 3/4 sign is
984 printed.  The time signature setting is also used to generate bar lines
985 at the right spots.
986 @separate
987 @example 
988
989         \key g \major
990  
991 @end example
992 @cindex key signature, setting
993 @cindex @code{\key}
994 Set (or change) the current key signature to G-major.  Although in this
995 example, the @code{\key} command happened to be entered after the
996 @code{\time} command, in the output the time signature will be printed
997 after the key signature; LilyPond knows about music typesetting
998 conventions.
999 @separate
1000 @example 
1001
1002         \repeat "volta" 2
1003  
1004 @end example 
1005 The following piece of music is played twice.  The first argument
1006 indicates the type of repeat.  In this case, @code{"volta"} means that
1007 prima volta/secunda volta brackets are used for the alternative
1008 endings---if there were any.
1009 @separate
1010 @example 
1011
1012         @{
1013  
1014 @end example 
1015 The subject of the repeat is again sequential music.  Since
1016 @code{\sequential} is such a common construct, a shorthand is provided:
1017 just leave off @code{\sequential}, and the result is the same.
1018 @separate
1019 @example 
1020
1021         d4 g,8
1022  
1023 @end example 
1024 Two notes.  The first note is a quarter note with relative pitch
1025 @code{d}.  The relative music was started with a @code{c''}, so the real
1026 pitch of this note is @code{d''}.  The duration of a note is designated
1027 by a number; the @code{4} here represents a quarter note.
1028
1029 The second note is an eight note with relative pitch @code{g,}.  The
1030 pitch is taken relative to the previous @code{d''}, making this
1031 note have real pitch @code{g'}.  The @code{8} represents an eight note.
1032 @separate
1033 @example 
1034
1035         a b
1036  
1037 @end example 
1038 Two more notes, with pitch @code{a} and @code{b}.  Because their
1039 duration is the same as the @code{g,8}, there is no need to enter the
1040 duration, but you may enter it anyway, i.e., @code{a4 b4}
1041 @separate
1042 @example 
1043
1044         d4 g, g |
1045  
1046 @end example
1047 @cindex bar check
1048 @cindex @code{|}
1049 @cindex errors, finding 
1050 Three more notes.  The @code{|} character is a ``bar check''.  LilyPond
1051 will verify that bar checks are found at the start of a measure.  This can
1052 help you track down typing errors.
1053
1054 @cindex alteration, chromatic
1055 @cindex chromatic alteration
1056 @separate
1057 @example 
1058
1059         c8 d e fis
1060
1061 @end example 
1062 So far, no notes were chromatically altered.  Here is the first one that
1063 is: @code{fis}.  LilyPond by default uses Dutch@footnote{Note names are
1064 available in several languages, but we find the Dutch names quite
1065 convenient.} note names, and ``Fis'' is the Dutch note name for ``F
1066 sharp''.  However, there is no sharp sign in the output. The program
1067 keeps track of key signatures, and will only print accidentals if they
1068 are needed.
1069
1070 For groups of eighth notes and shorter, LilyPond can determine how the
1071 notes should form a beam.  In this case, the 4 eights are automatically
1072 printed as a beam.
1073 @separate
1074 @example 
1075
1076         c4 d8( )c b a( )b4 c8 b a g |
1077  
1078 @end example 
1079 The beginning and ending notes of a slur are marked with parentheses,
1080 @code{(} and @code{)} for start and end respectively.  The line above
1081 indicates two slurs.  These slur markers (parentheses) are entered
1082 between the slurred notes.
1083 @separate
1084 @example 
1085
1086         a4 [b8 a] [g fis] 
1087  
1088 @end example 
1089 Automatic beaming can be overridden by inserting beam marks, @code{[}
1090 and @code{]}.  These beam markers (brackets) are put around the notes
1091 you want beamed.
1092 @separate
1093 @example 
1094
1095         g2.  |
1096  
1097 @end example
1098 @cindex augmentation dot
1099 @cindex dotted note
1100 A period adds a dot to the note.
1101 @separate
1102 @example 
1103
1104         @}
1105  
1106 @end example 
1107 The end of the sequential music to be repeated.  LilyPond will typeset a
1108 repeat bar.
1109 @separate
1110 @example 
1111
1112         cis'4 b8 cis a4 |
1113  
1114 @end example 
1115 Accidentals are printed whenever necessary: the first C sharp of the bar
1116 will be printed with an accidental, the second one without.
1117 @separate
1118 @example 
1119
1120         a8-. b-. cis-. d-. e-. fis-.
1121  
1122 @end example
1123 @cindex articulation
1124 You can enter articulation signs either in a verbose form or using a
1125 shorthand.  Here we demonstrate the shorthand: it is formed by a dash
1126 and the character for the articulation to use, e.g. @code{-.} for
1127 staccato as shown above.
1128 @separate
1129 @example 
1130
1131         fis a, r8 cis8
1132  
1133 @end example 
1134  
1135 Rests are denoted by the special note name @code{r}.  
1136 @separate
1137 @example 
1138
1139         d2.-\fermata
1140  
1141 @end example 
1142 All articulations have a verbose form, like @code{\fermata}.  The
1143 command @code{\fermata} is not part of the core of the language, but it
1144 is a shorthand for a more complicated description of a fermata symbol.
1145 @code{\fermata} names that description and is therefore called an
1146 identifier.
1147 @cindex identifier
1148 @cindex @code{\fermata}
1149 @separate
1150 @example
1151         \bar "|."
1152         @}
1153 @end example 
1154 Here the music ends.  LilyPond does not automatically typeset an end
1155 bar, we must explicitly request one, using @code{"|."}.
1156
1157 @separate
1158 @example 
1159
1160         \paper @{
1161                 % standard settings are too big and wide for a book
1162                 indent = 1.0\cm
1163                 linewidth = 15.0\cm
1164         @}
1165  
1166 @end example 
1167 The @code{\paper} block specifies how entered music should be converted
1168 to notation output.  Most of the details of the conversion (font sizes,
1169 dimensions, etc.) have been taken care of, but to fit the output in this
1170 document, it has to be narrower.  We do this by setting the line width
1171 to 14 centimeters (approximately 5.5 inches).
1172 @separate
1173 @example 
1174
1175         @}
1176  
1177 @end example 
1178 The last brace ends the @code{\score} block.
1179
1180
1181
1182
1183 @node Lyrics and chords
1184 @section Lyrics and chords
1185
1186 In this section we show how to typeset a song. This file is
1187 included as @file{flowing.ly}.
1188
1189 @example 
1190 \header @{
1191         title = "The river is flowing"
1192         composer = "Traditional"
1193 @}
1194 \include "paper16.ly"
1195 melody = \notes \relative c' @{
1196         \partial 8
1197         \key c \minor
1198         g8 |
1199         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1200         c4 c8 d [es () d] c4 | d4 es8 d c4.
1201         \bar "|."
1202 @}
1203
1204 text = \lyrics @{
1205         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1206         ri -- ver is flo -- wing down to the sea.
1207 @}
1208
1209 accompaniment =\chords @{
1210         r8
1211         c2:3- f:3-.7 d:min es4 c8:min r8
1212         c2:min f:min7 g:7^3.5 c:min @}
1213
1214 \score @{
1215         \simultaneous @{
1216           %\accompaniment
1217           \context ChordNames \accompaniment
1218
1219           \addlyrics
1220             \context Staff = mel @{        
1221               \property Staff.noAutoBeaming = ##t
1222               \property Staff.automaticMelismata = ##t
1223               \melody 
1224             @}
1225             \context Lyrics \text
1226         @}
1227         \midi  @{ \tempo 4=72 @}
1228         \paper @{ linewidth = 10.0\cm @}
1229 @} 
1230 @end example 
1231
1232
1233 The result would look this.@footnote{The titling and font size shown
1234 may differ, since the titling in this document is not generated by
1235 @code{ly2dvi}.}
1236
1237 @center @strong{The river is flowing}
1238 @center Traditional 
1239
1240 @lilypond[center]
1241 \header {
1242         title = "The river is flowing"
1243         composer = "Traditional"
1244 }
1245 \include "paper16.ly"
1246 melody = \notes \relative c' {
1247         \partial 8
1248         \key c \minor
1249         g8 |
1250         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1251         c4 c8 d [es () d] c4 | d4 es8 d c4.
1252         \bar "|."
1253 }
1254
1255 text = \lyrics {
1256         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1257         ri -- ver is flo -- wing down to the sea.
1258 }
1259
1260 accompaniment =\chords {
1261         r8
1262         c2:3- f:3-.7 d:min es4 c8:min r8
1263         c2:min f:min7 g:7^3.5 c:min }
1264
1265 \score {
1266         \simultaneous {
1267           %\accompaniment
1268           \context ChordNames \accompaniment
1269
1270           \addlyrics
1271             \context Staff = mel {
1272               \property Staff.noAutoBeaming = ##t
1273               \property Staff.automaticMelismata = ##t
1274               \melody 
1275             }
1276             \context Lyrics \text
1277         }
1278         \midi  { \tempo 4=72 }
1279         \paper { linewidth = 10.0\cm }
1280 }
1281 @end lilypond
1282
1283 Again, we will dissect the file line by line.
1284 @separate
1285 @example 
1286
1287         \header @{
1288  
1289 @end example
1290 @cindex @code{\header}
1291 Information about the music you are about to typeset goes into a
1292 @code{\header} block.  The information in this block is not used by
1293 LilyPond, but it is passed into the output.  @file{ly2dvi} uses this
1294 information to print titles above the music.
1295 @separate
1296 @example 
1297
1298         title = "The river is flowing"
1299         composer = "Traditional (?)"
1300 @end example
1301 @cindex assignments
1302 @cindex identifier assignment
1303 the @code{\header} block contains assignments.  In each assignment, a
1304 variable is set to a value. Lexically, both the variable name and the
1305 assigned value are strings. The values have to be quoted here, because
1306 they contain spaces. The variable names could also be put within quotes
1307 but it is not necessary. 
1308 @separate
1309 @example 
1310
1311         \include "paper16.ly"
1312  
1313 @end example
1314 Smaller size for inclusion in a book.
1315 @separate
1316 @example 
1317
1318         melody = \notes \relative c' @{
1319  
1320 @end example 
1321 The structure of the file will be the same as the previous one, a
1322 @code{\score} block with music in it.  To keep things readable, we will
1323 give names to the different parts of music, and use the names to
1324 construct the music within the score block.
1325
1326 @separate
1327 @example 
1328         \partial 8
1329 @end example 
1330
1331 @cindex @code{\partial}
1332 @cindex anacrusis
1333 The piece starts with an anacrusis of one eighth.
1334 @separate
1335 @example
1336         \key c \minor
1337 @end example
1338 The key is C minor: we have three flats.
1339
1340 @separate
1341 @example 
1342
1343         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1344         c4 c8 d [es () d] c4 | d4 es8 d c4.
1345         \bar "|."
1346  
1347 @end example 
1348
1349 @cindex manual beaming
1350 @cindex automatic beaming, turning off
1351 We use explicit beaming.  Since this is a song,  we turn automatic
1352 beams off, and use explicit beaming where needed.
1353 @separate
1354 @example 
1355
1356         @}
1357  
1358 @end example 
1359 This ends the definition of @code{melody}.  
1360
1361 @separate
1362 @example 
1363
1364         text = \lyrics @{
1365  
1366 @end example
1367 @cindex lyrics
1368 @cindex identifier assignment
1369 @cindex syllables, entering
1370 Another identifier assignment.  This one is for the lyrics. 
1371 Lyrics are formed by syllables that have duration, and not by
1372 notes. To make LilyPond parse words as syllables,  switch it  into
1373 lyrics mode with @code{\lyrics}.  Again, the brace after @code{\lyrics}
1374 is a shorthand for @code{\sequential @{}.
1375 @separate
1376 @example 
1377
1378   The4 ri -- ver is flo- __ wing,  flo -- wing and gro -- wing, the
1379   ri- ver is flo- __ wing down to the sea.
1380 @}
1381  
1382 @end example
1383 @cindex extenders, lyric
1384 @cindex hyphens, lyric 
1385 The syllables  themselves are  separated by spaces.  You can get syllable
1386 extenders by entering @code{__}, and centered hyphens with
1387 @code{-}@code{-}.  We enter the syllables as if they are all quarter notes
1388 in length (hence the @code{4}), and use a feature to align the
1389 syllables to the music, which obviously isn't all quarter notes.
1390 @separate
1391 @example 
1392
1393         accompaniment =\chords @{
1394  
1395 @end example
1396 @cindex chords
1397 @cindex mode, chords
1398 We'll put chords over the music. To enter them, there is a special mode
1399 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
1400 the names of the chords you want, instead of listing the notes
1401 comprising the chord.
1402 @separate
1403 @example 
1404
1405         r8
1406  
1407 @end example 
1408 There is no accompaniment during the anacrusis.
1409 @separate
1410 @example 
1411
1412         c2:3- f:3-.7
1413  
1414 @end example
1415
1416 @cindex tonic
1417 @cindex chord modifier
1418 @cindex modifier, chord 
1419 A chord is started by  the tonic of the chord. The
1420 first one lasts a half note.  An unadorned note creates a major
1421 triad. Since a minor triad is wanted, @code{3-} is added to modify the
1422 third to be small. @code{7} modifies (adds) a seventh, which is small by
1423 default to create the @code{f a c es} chord.  Multiple modifiers must be
1424 separated by dots.
1425 @separate
1426 @example 
1427
1428         d:min es4 c8:min r8
1429  
1430 @end example
1431
1432 Some modifiers have predefined names, e.g. @code{min} is  the same as
1433 @code{3-}, so @code{d-min} is a minor @code{d} chord.
1434 @separate
1435 @example 
1436
1437         c2:min f:min7 g:7^3.5 c:min @}
1438  
1439 @end example
1440 @cindex named modifier
1441
1442 A named modifier @code{min} and a normal modifier @code{7} do not have
1443 to be separated by a dot.  Tones from a chord are removed with chord
1444 subtractions.  Subtractions are started with a caret, and they are
1445 also separated by dots.  In this example, @code{g:7^3.5} produces a
1446 minor seventh.  The brace ends the sequential music.
1447 @separate
1448 @example 
1449
1450         \score @{
1451                 \simultaneous @{
1452  
1453 @end example 
1454 We assemble the music in the @code{\score} block.  Melody, lyrics and
1455 accompaniment have to sound at the same time, so they should be
1456 @code{\simultaneous}.
1457 @cindex @code{\simultaneous}
1458 @separate
1459 @example 
1460
1461         %\accompaniment
1462  
1463 @end example 
1464 Chord mode generates notes grouped in @code{\simultaneous} music.  If
1465 you remove the comment sign, you can see the chords in normal
1466 notation: they will be printed as note heads on a separate
1467 staff. To print them as chords names, they have to be interpreted as
1468 being chords, not notes. This is done with the following command:  
1469 @separate
1470 @example 
1471
1472         \context ChordNames \accompaniment
1473  
1474 @end example
1475 @cindex context
1476 @cindex interpretation context
1477 @cindex notation context
1478
1479
1480 Normally, the notes that you enter are transformed into note heads.
1481 Note heads alone make no sense, they need surrounding information: a key
1482 signature, a clef, staff lines, etc.  They need @emph{context}.  In
1483 LilyPond, these symbols are created by objects called `interpretation
1484 contexts'.  Interpretation contexts exist for generating notation
1485 (`notation context') and for generating sound (`performance
1486 context'). These objects only exist during a run of LilyPond.
1487
1488 By default, LilyPond will create a Staff context for you.  If you would
1489 remove the @code{%} sign in the previous line, you would see that
1490 mechanism in action.
1491
1492 We don't want that default here, because we want chord names.  The
1493 command above explicitly creates an interpretation context of 
1494 @code{ChordNames} type to interpret the music @code{\accompaniment}. 
1495 @separate
1496 @example 
1497
1498         \addlyrics
1499  
1500 @end example
1501 @cindex @code{\addlyrics}
1502 @cindex lyrics and melody, combining
1503 @cindex combining lyrics and melody
1504
1505 The lyrics should be aligned with the melody.  This is done by
1506 combining both with @code{\addlyrics}.  @code{\addlyrics} takes two
1507 pieces of music (usually a melody and lyrics, in that order) and
1508 aligns the syllables of the second piece under the notes of the
1509 first piece.  If you would reverse the order, the notes would be
1510 aligned on the lyrics, which is not very useful, and looks
1511 silly.
1512 @separate
1513 @example 
1514
1515         \context Staff = mel @{
1516  
1517 @end example
1518
1519 The first argument of @code{\addlyrics} is the melody.  We instantiate
1520 a @code{Staff} context explicitly: should you choose to remove the
1521 comment before the ``note heads'' version of the accompaniment, the
1522 accompaniment will be on a nameless staff.  The melody has to be on
1523 staff different from the accompaniment.  This is accomplished by giving
1524 the melody and accompaniment staves different names.
1525 @separate
1526 @example 
1527
1528         \property Staff.noAutoBeaming = ##t
1529  
1530 @end example
1531 @cindex \property
1532 @cindex context variables
1533 @cindex setting context variables
1534 An interpretation context has variables, called properties, that tune
1535 its behavior.  One of the variables is @code{noAutoBeaming}.  Setting
1536 this @code{Staff}'s property to @code{##t}, which is the boolean value
1537 @var{true}, turns the automatic beaming mechanism off for the current
1538 staff.
1539 @cindex GUILE
1540 @cindex Scheme
1541 @cindex accessing Scheme
1542 @cindex evaluating Scheme
1543 @cindex LISP
1544
1545 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
1546 language from the LISP family. You can learn more about Scheme at
1547 @uref{http://www.scheme.org}. It is used to represent data throughout
1548 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
1549 code following the hash-sign is evaluated as Scheme.  The boolean value
1550 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
1551 @code{##t}.
1552
1553 If Scheme scares you, don't worry. You don't need to know Scheme to
1554 create beautiful sheet music.
1555
1556
1557
1558 @separate
1559 @example 
1560
1561         \property Staff.automaticMelismata = ##t
1562  
1563 @end example
1564 @cindex automaticMelismata
1565 @cindex melismata
1566 @cindex @code{\addlyrics} and slurs
1567 Similarly, we  don't want to print a  syllable when there is
1568 a slur. This sets up @code{\addlyrics} to not put lyrics under each
1569 separate note while there is a slur.
1570 @separate
1571 @example 
1572
1573           \melody
1574         @}
1575  
1576 @end example 
1577 Finally, we put the melody on the current staff.  Note that the
1578 @code{\property} directives and @code{\melody} are grouped in sequential
1579 music,  so the property settings are done before the melody is
1580 processed.
1581 @separate
1582 @example 
1583
1584         \context Lyrics \text
1585  
1586 @end example 
1587 The second argument of @code{\addlyrics} is the text. The text also
1588 should not land on a Staff, but on a interpretation context for
1589 syllables, extenders, hyphens etc.  This context is called
1590 Lyrics.
1591 @separate
1592 @example 
1593
1594         \midi  @{ \tempo 4=72@}
1595  
1596 @end example 
1597 MIDI (Musical Instrument Digital Interface) is a standard for
1598 connecting and recording digital instruments. So a MIDI file is like a
1599 tape recording of an instrument. The @code{\midi} block makes the
1600 music go to a MIDI file, so you can listen to the music you entered.  It
1601 is great for checking the music.  Whenever you hear something weird, you
1602 probably hear a typing error.
1603
1604 Syntactically, @code{\midi} is similar to @code{\paper @{ @}}, since it
1605 also specifies an output method. You can specify the tempo using the
1606 @code{\tempo} command, in this case the tempo of quarter notes is set to
1607 72 beats per minute.
1608 @separate
1609 @example 
1610
1611         \paper @{ linewidth = 10.0\cm @}
1612  
1613 @end example 
1614 We also want notation output.  The linewidth is short so the piece
1615 will be set in two lines.
1616
1617 @node More movements 
1618 @section More movements
1619
1620 [FIXME: merge here with, or move this to: Other ways to run LilyPond]
1621
1622 You probably ran @file{ly2dvi} on the last example, and ended up with a
1623 viewable @file{.dvi} file.  However, between there are a few steps of
1624 which LilyPond is only one. To enhance your understanding of what's
1625 happening under the hood when you run @code{ly2dvi}, we explain what
1626 programs are run.
1627
1628 @code{ly2dvi} is a program that calls a number of programs  in sequence.
1629 The first thing it does, is running LilyPond on the input file. After
1630 some calculations, a @file{.tex} is produced. The contents
1631 of this file are very  low-level instructions.
1632
1633 For example, consider the following file (@file{miniatures.ly}) 
1634
1635 @example
1636 \version "1.4.0"
1637 \header @{
1638   title = "Two miniatures"
1639   tagline = "small is beautiful"
1640 @}
1641
1642 #(set! point-and-click line-column-location)
1643
1644 \paper @{ linewidth = -1.0 @}
1645
1646 \score @{
1647     \notes @{ c'4 d'4 @}
1648     \header @{
1649         opus = "Opus 1."
1650         piece = "Up" @}
1651 @}
1652 \score @{
1653     \notes @{ d'4 c'4 @}
1654     \header @{
1655         opus = "Opus 2."
1656         piece = "Down" @}
1657 @}
1658 @end example
1659
1660 The titling in this manual was not generated by ly2dvi, so we can't
1661 exactly show what it would look like, but the result should resemble this:
1662
1663 @center @strong{Two miniatures}
1664 @flushright
1665 Opus 1.
1666 @end flushright
1667 @flushleft
1668 @var{Up}
1669 @end flushleft
1670 @lilypond
1671   \score {
1672     \notes { c'4 d'4 }
1673     \paper { linewidth = -1.0 }
1674   }
1675 @end lilypond
1676 @flushright
1677 Opus 2.
1678 @end flushright
1679 @flushleft
1680 @var{Down}
1681 @end flushleft
1682 @lilypond
1683   \score {
1684     \notes { d'4 c'4 }
1685     \paper { linewidth = -1.0 }
1686   }
1687 @end lilypond
1688
1689 This file is produced by ly2dvi in a few stages, with the help of text
1690 formatting tools. LilyPond produces two output files,
1691 @file{miniatures.tex} and @file{miniatures-1.tex}.  Both files contain
1692 only graphical music notation. @file{ly2dvi} looks at what output
1693 LilyPond produces, and adds page layout and titling to those files.  The
1694 result is a DVI file called @file{miniatures.dvi}.
1695
1696 Next, now we'll look at the example line by line to explain new things.
1697
1698 @separate
1699 @example 
1700 \version "1.4.0"
1701 @end example 
1702 Lilypond and its language are still under development, and occasionally,
1703 details of the syntax are changed. This fragment indicates for which
1704 version the input file was written. When you compile this file, the
1705 version number will be checked, and you will get a warning when the file
1706 is too old.
1707
1708 This version number is also used by the @code{convert-ly} program (See
1709 @ref{convert-ly}), which is used to update the file to the latest lily
1710 version.
1711
1712 @separate
1713 @example
1714   \header @{
1715     title = "Two miniatures"  @}
1716 @end example
1717 This sets the titling information for the entire file.
1718 @separate
1719 @example
1720     tagline = "small is beautiful" 
1721 @end example
1722 A signature line is printed at the bottom of the last page.
1723  This signature is produced from the @code{tagline} field of
1724 @code{\header}.  Many people find the default "Lily was here,
1725 @var{version number}" too droll. If that is the case,  assign
1726 something else to @code{tagline}, as shown above.
1727 @separate
1728 @example
1729         #(set! point-and-click line-column-location)
1730 @end example
1731
1732 This piece of Scheme code sets the Scheme variable
1733 @code{point-and-click} to the value @var{line-column-location} (which
1734 itself is a Scheme procedure).
1735
1736 Editing input files can be quite complicated if you're working with
1737 large files: if you're digitizing existing music, you have to
1738 synchronize the .ly file, the sheet music on your lap and the sheet
1739 music on the screen.  The point-and-click mechanism makes it easy to
1740 find the origin of an error in the LY file: when you view the file with
1741 Xdvi and click on a note, your editor will jump to the spot where that
1742 note was entered.  For more information, see @ref{Point and click}.
1743
1744 @separate
1745 @example
1746   \paper @{ 
1747 @end example
1748
1749 The @code{\score} blocks that follow in the file don't have
1750 @code{\paper} sections, so the settings of this block are substituted: A
1751 paper block at top level, i.e. not in a @code{\score} block sets the
1752 default page layout.
1753
1754 @separate
1755 @example
1756   linewidth = -1.0 @}
1757 @end example
1758
1759
1760
1761 The variable @code{linewidth} normally sets the length of the systems on
1762 the page. However, a negative value has a special meaning. If
1763 @code{linewidth} is less than 0, no line breaks are inserted into the
1764 score, and the spacing is set to natural length: a short phrase takes up
1765 little space, a longer phrase more space.
1766
1767 @separate
1768 @example
1769   \score @{
1770     \notes @{ c'4 d'4 @}
1771 @end example
1772
1773 In previous examples, notes were specified in relative octaves,
1774 i.e. each note was put in the octave that is closest to its
1775 predecessor. Besides relative, there is also absolute octave
1776 specification, which you get when you don't specify @code{\relative}. In
1777 this input mode, the central C is denoted by @code{c'}. Going down, you
1778 get @code{c} @code{c,} @code{c,,} etc.  Going up, you get @code{c''}
1779 @code{c'''} etc.
1780
1781 When you're copying music from existing sheet music, relative octaves
1782 are probably the easiest to use: it's less typing work and errors are
1783 easily spotted. However, if you write LilyPond input directly, either by
1784 hand (i.e. composing) or by computer, absolute octaves may be easier to use.
1785
1786
1787 @separate
1788 @example
1789     \header @{
1790 @end example
1791
1792 The @code{\header} is normally at the top of the file, where it sets
1793 values for the rest of the file. If you want to typeset different pieces
1794 from one file (for example, if there are multiple movements, or if
1795 you're making an exercise book), you can put different @code{\score}
1796 blocks into the input file. ly2dvi will assemble all LilyPond output
1797 files into a big document. The contents of \header blocks specified
1798 within each score, are used for the titling of each movement.
1799 @separate
1800 @example
1801         opus = "Opus 1."
1802         piece = "Up" @}
1803 @end example
1804 For example, the Opus number is put at the right, and the piece string
1805 will be at the left.
1806
1807
1808
1809 @node A piano excerpt
1810 @section A piano excerpt
1811
1812 Our fourth subject is a piece of piano music.  The fragment in the input
1813 file is a piano reduction of the G major Sinfonia by Giovanni Battista
1814 Sammartini.  It was composed around 1740.  It's in the source package
1815 under  the name @file{sammartini.ly}.
1816
1817 @lilypond[verbatim]
1818 \include "paper16.ly"
1819
1820 stemDown = \property Voice.Stem \override #'direction = #-1
1821 stemUp = \property Voice.Stem \override #'direction = #1
1822 stemBoth = \property Voice.Stem \revert #'direction  
1823
1824 viola = \notes \relative c' \context Voice = viola {
1825     <c4-\f-\arpeggio g' c>
1826     \stemDown g'8. b,16
1827     s1 s2. r4
1828     g
1829 }
1830
1831 oboes = \notes \relative c'' \context Voice = oboe {
1832     \stemUp s4  g8. b,16 c8 r <e'8.^\p g> <f16 a>
1833     \grace <e8( g> <d4 )f> <c2 e>
1834     \times 2/3 { <d8 \< f> <e g> <f a> }
1835     <
1836         { \times 2/3 { a8 g c } \! c2 }
1837         \context Voice = oboeTwo {
1838             \stemDown
1839             \grace {
1840                 \property Voice.Stem \override #'direction = #-1
1841                 [f,16 g] 
1842                 \property Voice.Stem \revert #'direction
1843             }
1844             f8 e e2
1845         }
1846     >
1847     \stemBoth
1848     \grace <c,8( e> <)b8. d8.-\trill> <c16 e> | 
1849     [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r  |
1850     [<c16( e>  < )e8. g>] <c8 e,>
1851 }
1852
1853 hoomPah = \repeat unfold 8 \notes
1854     \transpose c' { \stemUp c8 \stemBoth \stemDown c'8 \stemBoth }
1855
1856 bassvoices = \notes \relative c' {
1857     c4 g8. b,16
1858     \autochange Staff \hoomPah
1859     \translator Staff = down
1860     \stemDown [c8 c'8] r4
1861     <g d'> r4
1862     < {\stemUp r2 <e4 c'> <c8 g'> }
1863         \context Voice = reallyLow  {\stemDown g2 ~ | g4 c8 } >
1864 }
1865
1866 \score {
1867     \context PianoStaff \notes <
1868         \context Staff = up < \time 2/2
1869             \viola
1870             \oboes
1871         >
1872         \context Staff = down < \time 2/2 \clef bass
1873             \bassvoices
1874         >
1875     >
1876     \midi { }
1877     \paper {
1878         indent = 0.0
1879         linewidth = 15.0 \cm }
1880 }
1881 @end lilypond
1882
1883 If this looks like incomprehensible gibberish to you, you are right.
1884 This example has been doctored to have as many quirks as possible.
1885
1886 As you can see, this example features multiple voices on one staff.  To
1887 make room for those voices, their notes have to be stemmed in opposite
1888 directions.
1889
1890 Printed symbols are internally represented by so-called Graphical
1891 Objects (more colloquially: Grobs).  These statements concern the
1892 grob called `Stem'. Each grob is described by a bunch of settings. These
1893 setting determine the fonts, offsets, sub-routines to be called on the
1894 grob, etc.  The initial values of these settings are set in the Scheme
1895 file @file{scm/grob-description.scm}.
1896
1897 @separate
1898 @example
1899   stemDown = \property Voice.Stem \override #'direction = #-1
1900 @end example
1901
1902 Set a property for all Stem grobs in the current Voice:
1903 @code{direction} is set to @code{-1}, which encodes down.  The setting
1904 remains in effect until it is reverted.
1905
1906 @separate
1907 @example
1908  \property Voice.Stem \revert #'direction  
1909 @end example
1910
1911 Revert the to the previous setting.  The effect of precisely one
1912 @code{\stemDown} or @code{\stemUp} is neutralized.
1913
1914
1915 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1916 with some other commonly used formatting instructions, but to explain how
1917 it works, we wrote our own here.  Of course, you should use predefined
1918 identifiers like these if possible: then you will be affected less by
1919 the implementation changes we occasionally make.
1920
1921 @separate
1922 @example 
1923 viola = \notes \relative c'  \context Voice = viola @{ 
1924 @end example 
1925 In this example, you can see multiple parts on a staff.  Each part is
1926 associated with one notation context.  This notation context handles
1927 stems and dynamics (among others).  The type name of this context is
1928 @code{Voice}.  For each part we have to make sure that there is
1929 precisely one @code{Voice} context, so we give it a unique name
1930 (`@code{viola}').
1931
1932 @separate
1933 @example 
1934 <c4-\f-\arpeggio g' c>
1935 @end example 
1936 The delimiters @code{<} and @code{>} are shorthands for
1937 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1938 @code{<} and @code{>} is a chord.
1939
1940 @cindex dynamics
1941 @cindex loudness
1942 @cindex forte
1943 @cindex arpeggio
1944
1945 @code{\f} places a forte symbol under the chord. The forte applies to
1946 the whole chord, but the syntax requires that commands like forte and
1947 arpeggio are attached to a note, so here we attach them to the first
1948 note.
1949
1950 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line) before
1951 the chord.
1952
1953 @separate
1954 @example 
1955    \stemDown
1956 @end example 
1957
1958
1959 @separate
1960 @example 
1961         g'8. b,16 
1962 @end example 
1963 Relative octaves work a little differently with chords.  The starting
1964 point for the note following a chord is the first note of the chord.  So
1965 the @code{g} gets an octave up quote: it is a fifth above the starting
1966 note of the previous chord (the central C).
1967
1968 @separate
1969 @example 
1970 s1 s2. r4 
1971 @end example 
1972 @code{s} is a spacer rest.  It does not print anything, but it does have
1973 the duration of a rest. It is useful for filling up voices that
1974 temporarily don't play. In this case, the viola doesn't come until one
1975 and a half measure later.
1976
1977 @separate
1978 @example 
1979 oboes = \notes \relative c'' \context Voice = oboe @{ 
1980 @end example 
1981 Now comes a part for two oboes.  They play homophonically, so we
1982 print the notes as one voice that makes chords. Again, we insure that
1983 these notes are indeed processed by precisely one context with
1984 @code{\context}.
1985 @separate
1986 @example 
1987 \stemUp s4  g8. b,16 c8 r <e'8.-\p g> <f16 a> 
1988 @end example 
1989 @code{\stemUp} is a reference to the @code{\property \override} command
1990 defined above. 
1991 @separate
1992 @example 
1993 \grace <e8 g> < d4 f> <c2 e> 
1994 @end example
1995 @cindex @code{\grace}
1996 @cindex ornaments
1997 @cindex grace notes
1998 @code{\grace} introduces grace notes.  It takes one argument, in this
1999 case a chord.
2000
2001 @ignore
2002 The slur started on the @code{e} of the chord
2003 will be attached to the next note.@footnote{LilyPond will squirm
2004 about unended Slurs.  In this case, you can ignore the warning}.
2005 @end ignore
2006 @separate
2007 @example 
2008 \times 2/3 
2009 @end example
2010 @cindex tuplet
2011 @cindex triplets
2012 Tuplets are made with the @code{\times} keyword.  It takes two
2013 arguments: a fraction and a piece of music.  The duration of the piece
2014 of music is multiplied by the fraction.  Triplets make notes occupy 2/3
2015 of their notated duration, so in this case the fraction is 2/3.
2016 @separate
2017 @example 
2018 @{ <d8 \< f> <e g> <f a> @} 
2019 @end example 
2020 The piece of music to be `tripletted' is sequential music containing
2021 three notes.  On the first chord, a crescendo is started with
2022 @code{\<}. To be precise, the crescendo start is syntactically attached
2023 to the preceding note, the @code{d}.
2024
2025 @cindex dynamics
2026 @cindex crescendo
2027 @cindex @code{\<}
2028
2029 @separate
2030 @example 
2031
2032 @end example 
2033 At this point, the homophonic music splits into two rhythmically
2034 different parts.  We can't use a sequence of chords to enter this, so
2035 we make a `chord' of sequences to do it.  We start with the upper
2036 voice, which continues with upward stems:
2037 @separate
2038 @example 
2039  @{ \times 2/3 @{ a8 g c @} \! c2 @} 
2040 @end example
2041
2042 @cindex @code{\!}
2043
2044 The crescendo is ended at the half note by the escaped exclamation
2045 mark @code{\!}.
2046 @separate
2047 @example 
2048 \context Voice = oboeTwo @{
2049 \stemDown 
2050 @end example 
2051 We can't share stems with the other voice, so we have to create a new
2052 @code{Voice} context.  We give it the name @code{oboeTwo} to distinguish
2053 it from the other context.  Stems go down in this voice.
2054 @separate
2055 @example 
2056 \grace
2057 @end example
2058 @cindex Grace context
2059 When a grace section is processed, a @code{Grace} context is
2060 created. This context acts like a miniature score of its own.  It has
2061 its own time bookkeeping, and you can make notes, beams, slurs
2062 etc. Here we fiddle with a property and make a beam.  The argument of
2063 @code{\grace} is sequential music.
2064
2065 @separate
2066 @example 
2067                 \property Voice.Stem \override #'direction = #-1
2068                 [f,16 g] 
2069                 \property Voice.Stem \revert #'direction
2070 @end example 
2071
2072 Normally, grace notes are always stem up, but in this case, the upper
2073 voice interferes, so we set the stems down here.
2074
2075 As far as relative mode is concerned, the previous note is the
2076 @code{c'''2} of the upper voice, so we have to go an octave down for
2077 the @code{f}.
2078 @separate
2079 @example 
2080
2081   f8 e e2
2082 @} > 
2083 @end example 
2084 This ends the two-part section.
2085 @separate
2086 @example 
2087 \stemBoth
2088 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |  
2089 @end example
2090 @cindex trill
2091 @cindex stemBoth
2092
2093 @code{\stemBoth} ends the forced stem directions. From here, stems are
2094 positioned as if it were single part music.
2095
2096 The bass has a little hoom-pah melody to demonstrate parts switching
2097 between staves.  Since it is repetitive, we use repeats:
2098 @separate
2099 @example 
2100 hoomPah  =  \repeat unfold 8
2101 @end example
2102 @cindex unfolded @code{\repeat}
2103 The unfolded repeat prints the notes in its argument as if they were
2104 written out in full eight times.
2105 @separate
2106 @example
2107 \notes \transpose c' @{
2108 @end example
2109 @cindex transposing
2110 @cindex relative mode and transposing
2111
2112 Transposing can be done with @code{\transpose}, which takes two arguments.
2113 The first specifies what central C should be transposed to.  The second
2114 is the to-be-transposed music.  As you can see, in this case, the
2115 transposition has no effect, as central C stays at central C.
2116
2117 The purpose of this no-op is circumventing relative mode.  Relative mode
2118 can not be used together with transposition, so @code{\relative} will
2119 leave the contents of @code{\hoomPah} alone.  We can use it without
2120 having to worry about getting the motive in a wrong octave.
2121 @separate
2122 @example 
2123 bassvoices = \notes \relative c' @{
2124 c4 g8. b,16
2125 \autochange Staff \hoomPah 
2126 @end example
2127 @cindex staff switch, automatic
2128 @cindex cross staff voice, automatic
2129 @cindex @code{\autochange}
2130
2131 Voices can switch between staves. The easiest way to get this, is to use
2132 @code{\autochange}. This command looks at the pitch of each note, and if
2133 necessary, will cross to the other staff. For this to work, the two
2134 staves must be called @code{"up"} and @code{"down"}.
2135 @separate
2136 @example
2137         \translator Staff = down
2138 @end example
2139 @cindex staff switch
2140 @cindex cross staff voice
2141 We want the remaining part of this melody on the lower staff, so we do a
2142 manual staff switch here.
2143
2144
2145 @separate
2146 @example 
2147 \context Voice = reallyLow  @{\stemDown g2 ~ | g4 c8 @} > 
2148 @end example
2149 @cindex tie
2150 @cindex @code{~}
2151 After skipping some lines, we see @code{~}.  This mark makes ties.  Note
2152 that ties and slurs are different things.  A tie can only connect two
2153 note heads of the same pitch, whereas a slur can connect many chords
2154 with one curve.
2155
2156 @separate
2157 @example 
2158 \context PianoStaff 
2159 @end example 
2160  A special context is needed to get cross staff beaming right.  This
2161 context is called @code{PianoStaff}.
2162 @separate
2163 @example 
2164 \context Staff = bottom < \time 2/2 \clef bass 
2165 @end example 
2166 The bottom staff must have a different clef.
2167 @separate
2168 @example 
2169 indent = 0.0 
2170 @end example 
2171 To make some more room on the line, the first (in this case the only)
2172 line is not indented.  The line still looks very cramped, but that is due
2173 to the page layout of this document.
2174
2175
2176 @ignore
2177 [TODO:
2178
2179 * font-size, multi-stanza.
2180
2181 * Simple part combining in a Hymn
2182 @end ignore
2183
2184
2185 @node An orchestral score
2186 @section An orchestral score
2187
2188 @menu
2189 * The full score::              
2190 * Extracting an individual part::  
2191 @end menu
2192
2193
2194 Our last two examples show a way to setup the music for an orchestral
2195 score.  When typesetting a piece for several instruments, you'll want to
2196 create a conductor's full score, alongside several individual parts.
2197
2198 LilyPond is well suited for this task.  We will declare the music for
2199 each instrument individually, giving the music of each instrument its
2200 own name.  These pieces of music are then combined in different
2201 @code{\score} blocks to produce different combinations of the score.
2202
2203 This orchestral score example consists of three input files.  In the
2204 first file, @file{os-music.ly}, we define the music for all instruments.
2205 This file will be used both for producing the score and the separate
2206 parts.
2207
2208 If you were to run LilyPond on this file, no printable output would be
2209 produced.
2210
2211 @example
2212 % os-music.ly
2213 \header @{
2214   title = "Zo, goed lieverd?"
2215   subtitle = "How's, this babe?"
2216   composer = "JCN"
2217   opus = "1"
2218   piece = "Laid back"
2219 @}
2220 global = @{
2221   \time 2/4
2222   \skip 2*4 \bar "|."
2223 @}
2224 Key = \notes \key as \major
2225 flautoI = \notes\relative c'' @{
2226   f8 g f g f g f g
2227   bes as bes as bes as bes as
2228 @}
2229 flautoII = \notes\relative c'' @{
2230   as8 bes as bes R1 d4 ~ d
2231 @}
2232 tromboI = \notes\relative c'' @{
2233   c4. c8 c8 c4. es4 r as, r
2234 @}
2235 tromboII = \notes\relative c'' @{
2236   as4. as8 as8 as4. R1*1/2 as4 es'
2237 @}
2238 timpani = \notes\relative c, @{
2239   \times 2/3 @{ f4 f f @}
2240   \times 4/5 @{ as8 as as as as @}
2241   R1
2242 @}
2243 corno = \notes\relative c' @{
2244    bes4 d f, bes d f, bes d
2245 @}
2246 @end example
2247
2248 We will not go through the input line by line, but only indicate and
2249 explain the new elements.
2250
2251
2252 @separate
2253 @example
2254 global = @{
2255   \time 2/4
2256   \skip 2*4 \bar "|.";
2257 @}
2258 @end example
2259
2260 Declare setting to be used globally.  The @code{\skip} command produces
2261 no output, but moves forward in time: in this case, the duration of a
2262 half note (@code{2}), and that four times (@code{*4}).  This brings us
2263 to the end of the piece, and we can set the end bar.
2264
2265 @separate
2266 @example
2267 Key = \notes \key as \major
2268 @end example
2269 Declare the key signature of the piece and assign it to the identifier
2270 @var{Key}.  Later on, we'll use @code{\Key} for all staves except those
2271 for transposing instruments.
2272
2273 @node The full score
2274 @subsection The full score
2275
2276
2277 The second file, @file{os-score.ly} reads the definitions of the first
2278 (@file{os-music.ly}), and defines the @code{\score} block for the full
2279 conductor's score.
2280
2281
2282 @example
2283 % os-score.ly
2284 \include "os-music.ly"
2285 \include "paper13.ly"
2286
2287 #(set! point-and-click line-column-location)
2288 #(define text-flat '((font-relative-size . -2)
2289          (music "accidentals--1")))
2290
2291 \score @{
2292   <
2293     \global
2294     \property Score.BarNumber \override #'padding = #3
2295     \context StaffGroup = woodwind <
2296       \context Staff = flauti <
2297         \property Staff.midiInstrument = #"flute"
2298         \property Staff.instrument = "2 Flauti"
2299         \property Staff.instr = "Fl."
2300         \Key
2301         \context Voice=one @{ \voiceOne \flautoI @}
2302         \context Voice=two @{ \voiceTwo \flautoII @}
2303       >
2304     >
2305     \context StaffGroup = timpani <
2306       \context Staff = timpani <
2307         \property Staff.midiInstrument = #"timpani"
2308         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2309         \property Staff.instr = #"Timp."
2310         \clef bass
2311         \Key
2312         \timpani
2313       >
2314     >
2315     \context StaffGroup = brass <
2316       \context Staff = trombe <
2317         \property Staff.midiInstrument = #"trumpet"
2318         \property Staff.instrument = #`(lines "2 Trombe" "(C)")
2319         \property Staff.instr = #`(lines "Tbe." "(C)")
2320         \Key
2321         \context Voice=one \partcombine Voice
2322           \context Thread=one \tromboI
2323           \context Thread=two \tromboII
2324       >
2325       \context Staff = corni <
2326         \property Staff.midiInstrument = #"french horn"
2327         \property Staff.instrument = #`(lines "Corno"
2328           (columns "(E" ,text-flat ")"))
2329         \property Staff.instr = #`(lines "Cor."
2330           (columns "(E" ,text-flat ")"))
2331         \property Staff.transposing = #3
2332         \notes \key bes \major
2333         \context Voice=one \corno
2334       >
2335     >
2336   >
2337   \paper @{
2338     indent = 15 * \staffspace
2339     linewidth = 60 * \staffspace
2340     textheight = 90 * \staffspace
2341     \translator@{
2342       \HaraKiriStaffContext
2343     @}
2344   @}
2345   \midi @{
2346     \tempo 4 = 75
2347   @}
2348 @}
2349 @end example
2350
2351 @center @strong{Zo, goed lieverd?}
2352 @sp 1
2353 @center How's, this babe?
2354 @flushright
2355 Opus 1.
2356 @end flushright
2357 @flushleft
2358 @sc{Laid back}
2359 @end flushleft
2360
2361 @lilypondfile{os-score.ly}
2362
2363 @separate
2364 @example
2365 \include "os-music.ly"
2366 @end example
2367 First, we need to include the music definitions we made in
2368 @file{os-music.ly}.
2369
2370 @separate
2371 @example
2372 #(set! point-and-click line-column-location)
2373 @end example
2374 In a large orchestral score like this you're bound to make some small
2375 mistakes, so we enable point and click (See @ref{Point and click})
2376 editing.
2377
2378 @separate
2379 @example
2380 #(define text-flat '((font-relative-size . -2)
2381          (music "accidentals--1")))
2382 @end example
2383
2384 When naming the tuning of the french horn, we'll need a piece of text
2385 with a flat sign.  LilyPond has a mechanism for font selection and
2386 kerning called Scheme markup text (See @ref{Text markup}).  The flat
2387 sign is taken from the music font, and its name is @code{accidentals--1}
2388 (The natural sign is called @code{accidentals-0}).  The default font is
2389 too big for text, so we select a relative size of @code{-2}.
2390
2391 @separate
2392 @example
2393   <
2394     \global
2395 @end example
2396 Of course, all staves are simultaneous and use the same global settings.
2397
2398 @separate
2399 @example
2400     \property Score.BarNumber \override #'padding = #3
2401 @end example
2402 LilyPond prints bar numbers at the start of each line, but
2403 unfortunately, they end up a bit too close to the staff in this example.
2404 A bar number internally is a Grob called @var{BarNumber}.  BarNumber
2405 Grobs can be manipulated through their @var{side-position-interface}.  One
2406 of the properties of a @var{side-position-interface} that can be tweaked
2407 is the @var{padding}: the amount of extra space that is put between this
2408 Grob and other Grobs.  We set the padding to three staff spaces.
2409
2410 You can find information on all these kind of properties in LilyPond's
2411 automatically generated documentation in
2412 @ifnottex
2413 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}.
2414 @end ifnottex
2415 @iftex
2416 the online documentation.
2417 @end iftex
2418
2419 @separate
2420 @example
2421     \context StaffGroup = woodwind <
2422       \context Staff = flauti <
2423 @end example
2424 A new notation context: the @code{StaffGroup}.  @code{StaffGroup} can
2425 hold one or more @code{Staff}'s, and will print a big bracket at the
2426 left of the score.  Start a new staff group for the woodwind section
2427 (just the flutes in this case).  Immediately after that, we start the
2428 staff for the two flutes, that also play simultaneously.
2429
2430 @separate
2431 @example
2432         \property Staff.midiInstrument = #"flute"
2433 @end example
2434 Specify the instrument for MIDI output (see @ref{MIDI instrument
2435 names}).
2436
2437 @separate
2438 @example
2439         \property Staff.instrument = "2 Flauti"
2440         \property Staff.instr = "Fl."
2441 @end example
2442 And define the instrument names to be printed in the margin,
2443 @code{instrument} for the first line of the score, @code{instr} for the
2444 rest of the score.
2445
2446 @separate
2447 @example
2448         \Key
2449 @end example
2450 The flutes play in the default key.
2451
2452 @separate
2453 @example
2454         \context Voice=one @{ \voiceOne \flautoI @}
2455         \context Voice=two @{ \voiceTwo \flautoII @}
2456 @end example
2457 Last come the actual flute parts.  Remember that we're still in
2458 simultaneous mode.  We name both voices differently, so that LilyPond
2459 will actually create two Voice contexts.  The flute parts are simple, so
2460 we specify manually which voice is which: @code{\voiceOne} forces the
2461 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
2462 directions down.
2463
2464 @separate
2465 @example
2466       >
2467     >
2468 @end example
2469 Close the flutes staff and woodwind staff group.
2470
2471 @separate
2472 @example
2473         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2474 @end example
2475 The timpani staff only shows a new piece of scheme markup, it sets two
2476 lines of text.
2477
2478 @separate
2479 @example
2480         \context Voice=one \partcombine Voice
2481           \context Thread=one \tromboI
2482           \context Thread=two \tromboII
2483 @end example
2484 You have seen the notation contexts Staff and Voice, but here's a new
2485 one: Thread.  One or more Threads can be part of a Voice.  The Thread
2486 takes care of note heads and rests, the Voice combine note heads onto a
2487 stem.
2488
2489 For the trumpets we use the automatic part combiner (see @ref{Automatic
2490 part combining}) to combine the two simultaneous trumpet parts onto the
2491 trumpet staff.  Each trumpet gets its own Thread context, which must be
2492 named @code{one} and @code{two}).  The part combiner makes these two
2493 threads share a Voice when they're similar, and splits the threads up
2494 when they're different.
2495
2496 @separate
2497 @example
2498         \property Staff.instrument = #`(lines "Corno"
2499           (columns "(E" ,text-flat ")"))
2500 @end example
2501 The french horn has the most complex scheme markup name, made up of two
2502 lines of text.  The second line has three elements (columns), the @code{(E},
2503 the flat sign @code{text-flat} that we defined before and a final @code{")"}.
2504 Note that we use a backquote instead of an ordinary quote at the
2505 beginning of the Scheme expression to be able to access the
2506 @code{text-flat} identifier, `unquoting' it with a @code{,}.
2507
2508 @separate
2509 @example
2510         \property Staff.transposing = #3
2511 @end example
2512 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
2513 transpose this staff by three steps.
2514
2515 Note how we can choose different tuning for entering, printing and
2516 playing, using @code{\transpose} and the MIDI Staff property
2517 @var{transposing}.
2518
2519 @separate
2520 @example
2521         \notes \key bes \major
2522 @end example
2523 Therefore, it has a different key.
2524
2525 @separate
2526 @example
2527     indent = 15 * \staffspace
2528     linewidth = 60 * \staffspace
2529 @end example
2530 We specify a big indent for the first line and a small linewidth for this
2531 tutorial.
2532
2533 @separate
2534
2535 Usually, LilyPond's predefined setup of notation contexts (Thread,
2536 Voice, Staff, Staffgroup, Score) is just fine.  But in this case, we
2537 want a different type of Staff context.
2538
2539 @example
2540     \translator@{
2541       \HaraKiriStaffContext
2542     @}
2543 @end example
2544
2545 In orchestral scores, it often happens that one instrument has only
2546 rests during one line of the score.  The @code{HaraKiriStaffContext} can
2547 be used as a regular @code{StaffContext} drop-in and will take care of
2548 the automatic removing of empty staves.
2549
2550 @node Extracting an individual part
2551 @subsection Extracting an individual part
2552
2553 The third file, @file{os-flute-2.ly} also reads the definitions of the
2554 first (@file{os-music.ly}), and defines the @code{\score} block for the
2555 second flute part.
2556
2557 @example
2558 \include "os-music.ly"
2559 \include "paper16.ly"
2560
2561 \score @{
2562   \context Staff <
2563     \property Score.skipBars = ##t
2564     \property Staff.midiInstrument = #"flute"
2565     \global
2566     \Key
2567     \flautoII
2568   >
2569   \header @{
2570     instrument = "Flauto II"
2571   @}
2572   \paper @{
2573     linewidth = 80 * \staffspace
2574     textheight = 200 * \staffspace
2575   @}
2576   \midi @{
2577     \tempo 4 = 75
2578   @}
2579 @}
2580 @end example
2581
2582 @center @strong{Zo, goed lieverd?}
2583 @sp 1
2584 @center How's, this babe?
2585 @center @emph{Flauto II}
2586 @flushright
2587 Opus 1.
2588 @end flushright
2589 @flushleft
2590 @sc{Laid back}
2591 @end flushleft
2592 @lilypondfile{os-flute-2.ly}
2593
2594
2595 Because we separated the music definitions from the @code{\score}
2596 instantiations, we can easily define a second score with the music of
2597 the second flute.  This then is the part for the second flute player.
2598 Of course, we make separate parts for all individual instruments.
2599
2600 @separate
2601 @example
2602     \flautoII
2603 @end example
2604 In this individual part the second flute has a whole staff for itself,
2605 so we don't want to force stem or tie directions.
2606
2607 @separate
2608 @example
2609   \header @{
2610     instrument = "Flauto II"
2611   @}
2612 @end example
2613 The @code{\header} definitions were also read from @file{os-music.ly},
2614 but we need to set the instrument for this particular score.
2615
2616 @separate
2617 @example
2618     \property Score.skipBars = ##t
2619 @end example
2620 In the conductor's full score, all bars with rests are printed, but for
2621 the individual parts, we want to contract pieces of consecutive empty
2622 bars.  LilyPond will do this if Score's @var{skipBars} property to
2623 true. 
2624
2625
2626 @node Other ways to run LilyPond
2627 @section Other ways to run LilyPond
2628
2629 Until now, you have been using @file{ly2dvi} to invoke LilyPond.
2630 There are three other routes.  Firstly, there is a script called
2631 @code{lilypond-book}, that allows you to freely mix LilyPond input with
2632 Texinfo or \LaTeX input. For example, this manual was written using
2633 @code{lilypond-book}. It is discussed below and in @ref{lilypond-book}.
2634
2635
2636 Secondly, you can generate PostScript directly. This is useful if you
2637 can not or do not want to run @TeX{} on your system.  To obtain direct
2638 PostScript output, invoke LilyPond as follows:
2639 @cindex PostScript output
2640 @example
2641 lilypond -f ps test.ly
2642 @end example
2643 You have to set some environment variables to view or print this output. 
2644 More information can be found in @ref{Invoking LilyPond}. Since the
2645 direct Postscript generation has some problems, it is recommended
2646 to use @file{ly2dvi}.
2647
2648
2649 Thirdly, if you want to do special things with your output, you can run
2650 invoke LilyPond directly:
2651 @example
2652 lilypond test.ly
2653 @end example
2654 to produce plain @TeX{} output.  Note that La@TeX{} will not work on the
2655 resulting @file{test.tex}.  You must run plain @TeX{} on it.
2656
2657 @cindex @TeX{}
2658
2659
2660
2661
2662
2663 @node Integrating text and music
2664 @section Integrating text and music
2665
2666 Sometimes, you might want to use music examples in a text that you are
2667 writing. For example, if you are writing a musicological treatise, a
2668 songbook, or (like us) the LilyPond manual.  You can make such texts by
2669 hand, simply by importing a PostScript figure into your wordprocessor.
2670 However, there is a also an automated procedure:
2671
2672 If you use La@TeX{} or texinfo, you can mix text and LilyPond code. A
2673 script called @code{lilypond-book} will extract the music fragments, run
2674 LilyPond on them, and put back the resulting notation.  lilypond-book is
2675 described fully in @ref{lilypond-book}, but here we show a small
2676 example. Since the example also contains explanatory text, we won't
2677 comment on the contents.
2678
2679 @example
2680 \documentclass[a4paper]@{article@}
2681 \begin@{document@}
2682
2683 In a lilypond-book document, you can freely mix music and text. For
2684 example:
2685 \begin@{lilypond@}
2686   \score @{ \notes \relative c' @{
2687      c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2688   @} @}
2689 \end@{lilypond@}
2690 Notice that the music line length matches the margin settings of the
2691 document.
2692
2693 If you have no \verb+\score+ block in the fragment,
2694 \texttt@{lilypond-book@} will supply one:
2695
2696 \begin@{lilypond@}
2697   c'4
2698 \end@{lilypond@}
2699
2700 In the example you see here, a number of things happened: a
2701 \verb+\score+ block was added, and the line width was set to natural
2702 length. You can specify many more options using  \LaTeX style options
2703 in brackets:
2704
2705 \begin[verbatim,11pt,singleline,
2706   fragment,relative,intertext="hi there!"]@{lilypond@}
2707   c'4 f bes es
2708 \end@{lilypond@}
2709
2710 \texttt@{verbatim@} also shows the LilyPond code, \texttt@{11pt@} selects
2711 the default music size, \texttt@{fragment@} adds a score block,
2712 \texttt@{relative@} uses relative mode for the fragment, and
2713 \texttt@{intertext@} specifies what to print between the
2714 \texttt@{verbatim@} code and the music.
2715
2716 If you include large examples into the text, it may be more convenient
2717 to put the example in a separate file:
2718
2719 \lilypondfile[printfilename]@{sammartini.ly@}
2720
2721 The \texttt@{printfilename@} option adds the file name to the output.
2722
2723 \end@{document@}
2724 @end example
2725
2726 Under Unix, you can view the results as follows.
2727 @example
2728 $ cd input/tutorial
2729 $ lilypond-book --outdir=out/ lilbook.tex
2730 lilypond-book (GNU LilyPond) 1.3.146
2731 Reading `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/lilbook.tex'
2732 Reading
2733 `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/sammartini.ly'
2734 @var{lots of stuff deleted}
2735 Writing `out/lilbook.latex'
2736 $ cd out
2737 $ latex lilbook.latex
2738 @var{lots of stuff deleted}
2739 $ xdvi lilbook 
2740 @end example
2741
2742 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2743 and running latex creates a lot of temporary files, and you wouldn't want
2744 those to clutter up your working directory. Hence, we have them created
2745 in a separate subdirectory.
2746
2747 The result more or less looks like this: 
2748
2749 @separate
2750
2751 In a lilypond-book document, you can freely mix music and text. For
2752 example:
2753 @lilypond
2754   \score { \notes \relative c' {
2755      c2 g'2 \times 2/3 { f8 e d } c'2 g4
2756   } }
2757 @end lilypond
2758 Notice that the music line length matches the margin settings of the
2759 document.
2760
2761 If you have no @code{\score} block in the fragment,
2762 @code{lilypond-book} will supply one:
2763
2764 @lilypond
2765   c'4
2766 @end lilypond
2767
2768 In the example you see here, a number of things happened: a
2769 @code{\score} block was added, and the line width was set to natural
2770 length. You can specify many more options using  La@TeX{} style options
2771 in brackets:
2772
2773 @lilypond[verbatim,11pt,singleline,
2774   fragment,relative,intertext="hi there!"]
2775   c'4 f bes es
2776 @end lilypond
2777
2778 @code{verbatim} also shows the LilyPond code, @code{11pt} selects
2779 the default music size, @code{fragment} adds a score block,
2780 @code{relative} uses relative mode for the fragment, and
2781 @code{intertext} specifies what to print between the
2782 @code{verbatim} code and the music.
2783
2784 If you include large examples into the text, it may be more convenient
2785 to put the example in a separate file:
2786
2787 @lilypondfile[printfilename]{sammartini.ly}
2788
2789 The @code{printfilename} option adds the file name to the output.
2790 @node  End of tutorial
2791 @section End of tutorial
2792          
2793 That's all folks.  From here, you can either try fiddling with input
2794 files, or you can read the reference manual.  You can find more example
2795 files in @file{input} and @file{input/test}.  You can also look at some
2796 real music.  The website @uref{http://www.mutopiaproject.org} has many
2797 examples of real music typeset by LilyPond.
2798
2799
2800
2801 @ignore
2802
2803 [TODO
2804
2805 this should be on mutopia website.
2806
2807 ]
2808
2809
2810 @c waar deze info?  is uiteindelijk wel handig, schat ik.
2811 [TODO: cut blabla]
2812
2813 If you have a big music project, or just a lot of LilyPond input files,
2814 all generated output from LilyPond, @TeX{} and metafont will clutter
2815 your working directory.  LilyPond comes with a one-size-fits-all
2816 pre-cooked makefile that helps you manage producing output.  It will
2817 produce all output in the directory @file{out} , generate and track
2818 dependencies. Also, it helps in preparing your submission to @ref{Mutopia
2819 project}.
2820
2821 @file{make/ly.make}
2822 @example
2823 mkdir my-project
2824 cd my-project
2825 cp /usr/share/lilypond/make/ly.make GNUmakefile
2826 cp /usr/share/doc/lilypond/examples/input/tutorial/minuet.ly .
2827 make minuet
2828 [..]
2829 Generated out/minuet.ps for target minuet.
2830 @end example
2831
2832 Type @samp{make help} to see possible targets.
2833
2834 [TODO]
2835 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
2836
2837
2838
2839
2840
2841 [TODO: rewrite completely.]
2842
2843 @menu
2844 * Songs with additional verses::  
2845 @end menu
2846
2847 @end ignore
2848