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