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