]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
8fa404fa62b64bf4ca24f301e388138a048d44a3
[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 Normal 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 or Cygwin
839 icon.  Notepad is sufficient for editing the LilyPond file.  Viewing
840 the PS file can be done with:
841 @quotation
842 @example
843 @code{gsview32 test.ps}
844 @end example
845 @end quotation
846 You can also print from the command line by executing:
847 @quotation
848 @example
849 @code{gsview32 /s test.ps}
850 @end example
851 @end quotation
852
853
854 @node The first real tune
855 @section The first real tune
856
857
858 The rest of this tutorial will demonstrate how to use Lilypond by
859 presenting examples of input along with resulting output.  We will use
860 English terms for notation.  In case you are not familiar with those,
861 you may consult the glossary that is distributed with LilyPond.
862
863 The examples discussed are included in the distribution, in the
864 subdirectory @file{input/tutorial/}@footnote{When we refer to filenames,
865 they are relative to the top directory of the source package. }
866
867 To demonstrate what LilyPond input looks like, we start off with a
868 full-fledged, yet simple example. It is a convoluted version
869 of the famous minuet in J. S. Bach's @emph{Klavierb@"uchlein}. The file
870 is included in the distribution as  @file{minuet.ly}.
871 @cindex Bach, Johann Sebastian 
872
873 @lilypond[verbatim]
874 % all text after a percent sign is a comment
875 % and is ignored by LilyPond
876 \include "paper16.ly"
877 \score {
878     \notes                        
879     \relative c'' \sequential {
880             \time 3/4                
881             \key g \major
882
883         \repeat "volta" 2 {
884             d4 g,8 a b c d4 g, g |
885             e'4 c8 d e fis g4 g, g |
886             c4 d8( )c b a( )b4 c8 b a g |
887             a4 [b8 a] [g fis] g2.  |
888         }
889
890         b'4 g8 a b g
891         a4 d,8 e fis d |
892         g4 e8 fis g d cis4 b8 cis a4 |
893         a8-. b-. cis-. d-. e-. fis-.
894         g4 fis e |
895         fis a,  r8 cis8
896         d2.-\fermata
897         \bar "|."
898     }
899     \paper {
900        % standard settings are too big and wide for a book
901        indent = 1.0 \cm
902        linewidth = 15.0 \cm
903    }
904 }
905 @end lilypond
906
907 We will analyse the input, line by line.
908 @separate
909 @example
910         % all text after a percent sign is a comment
911         % and is ignored by LilyPond
912 @end example 
913 Percent signs introduce comments: everything after a percent sign is
914 ignored. You can use this to write down mental notes to yourself.  You
915 can also make longer comments by enclosing text in @code{%@{} and
916 @code{%@}}.
917 @cindex comment
918 @cindex block comment
919 @cindex line comment
920 @separate
921 @example 
922
923         \include "paper16.ly"
924  
925 @end example
926 @cindex @code{\include}
927 @cindex point, printer's
928 @cindex staff size, setting
929 @cindex font size, setting
930
931 By default, LilyPond will typeset the music in a size such that each
932 staff is 20 point (0.7 cm, or 0.27 inch) high.  We want smaller output
933 (16 point staff height), so we must import the settings for that size,
934 which is done here.
935 @separate
936 @example 
937
938         \score @{
939  
940 @end example 
941 Music is printed by combining a piece of music with directions for
942 outputting it.  This combination is formed in the @code{\score} block.
943 @separate
944 @example 
945
946         \notes                
947  
948 @end example 
949 Prepare LilyPond for accepting notes.
950 @cindex octaves, choosing
951 @cindex pitch
952 @separate
953 @example 
954
955         \relative c''
956  
957 @end example
958 @cindex relative
959 @c removed duplicate introduction to octave marks /MB
960 @c Shorten even more?
961
962 @c As we will see, each note is described by its note name, duration,
963 @c octave and possibly a chromatic alteration.  In this setup, the octave
964 @c is indicated by using high quotes (@code{'}) and ``lowered quotes''
965 @c (commas: @code{,}).  The central C is denoted by @code{c'}.  The C one
966 @c octave higher is @code{c''}.  One and two octaves below the central C is
967 @c denoted by @code{c} and @code{c,} respectively.
968
969 Even though a piece of music often spans a range of several octaves, it
970 mostly moves in small intervals.  LilyPond has a special entry mode to
971 save typing in this situation.  In this ``relative'' octave mode,
972 octaves of notes without quotes are chosen such that a note is as close
973 as possible (graphically, on the staff) to the preceding note.  If you
974 add a high-quote an extra octave is added.  A lowered quote (a comma)
975 will subtract an extra octave.
976
977 Because the first note has no predecessor,
978 you have to give the (absolute) pitch of the note to start with.
979 @separate
980 @example 
981
982         \sequential @{
983  
984 @end example 
985 What follows is sequential music, i.e.,
986 @cindex sequential music
987 notes that are to be played and printed after each other.
988 @separate
989 @example 
990
991         \time 3/4
992  
993 @end example
994 @cindex time signature, setting
995 @cindex @code{\time}
996 Set (or change) the time signature of the current piece: a 3/4 sign is
997 printed.  The time signature setting is also used to generate bar lines
998 at the right spots.
999 @separate
1000 @example 
1001
1002         \key g \major
1003  
1004 @end example
1005 @cindex key signature, setting
1006 @cindex @code{\key}
1007 Set (or change) the current key signature to G-major.  Although in this
1008 example, the @code{\key} command happened to be entered after the
1009 @code{\time} command, in the output the time signature will be printed
1010 after the key signature; LilyPond knows about music typesetting
1011 conventions.
1012 @separate
1013 @example 
1014
1015         \repeat "volta" 2
1016  
1017 @end example 
1018 The following piece of music is played twice.  The first argument
1019 indicates the type of repeat.  In this case, @code{"volta"} means that
1020 prima volta/secunda volta brackets are used for the alternative
1021 endings---if there were any.
1022
1023 A special notation for repeats allows you to get correct repeats in
1024 MIDI output. However, some extra trickery is needed to get this
1025 working, See @ref{Repeats and MIDI}.  
1026 @separate
1027 @example 
1028
1029         @{
1030  
1031 @end example 
1032 The subject of the repeat is again sequential music.  Since
1033 @code{\sequential} is such a common construct, a shorthand is provided:
1034 just leave off @code{\sequential}, and the result is the same.
1035 @separate
1036 @example 
1037
1038         d4 g,8
1039  
1040 @end example 
1041 Two notes.  The first note is a quarter note with relative pitch
1042 @code{d}.  The relative music was started with a @code{c''}, so the real
1043 pitch of this note is @code{d''}.  The duration of a note is designated
1044 by a number; the @code{4} here represents a quarter note.
1045
1046 The second note is an eight note with relative pitch @code{g,}.  The
1047 pitch is taken relative to the previous @code{d''}, making this
1048 note have real pitch @code{g'}.  The @code{8} represents an eight note.
1049 @separate
1050 @example 
1051
1052         a b
1053  
1054 @end example 
1055 Two more notes, with pitch @code{a} and @code{b}.  Because their
1056 duration is the same as the @code{g,8}, there is no need to enter the
1057 duration, but you may enter it anyway, i.e., @code{a8 b8}
1058 @separate
1059 @example 
1060
1061         d4 g, g |
1062  
1063 @end example
1064 @cindex bar check
1065 @cindex @code{|}
1066 @cindex errors, finding 
1067 Three more notes.  The @code{|} character is a ``bar check''.  LilyPond
1068 will verify that bar checks are found at the start of a measure.  This can
1069 help you track down typing errors.
1070
1071 @cindex alteration, chromatic
1072 @cindex chromatic alteration
1073 @separate
1074 @example 
1075
1076         c8 d e fis
1077
1078 @end example 
1079 So far, no notes were chromatically altered.  Here is the first one that
1080 is: @code{fis}.  LilyPond by default uses Dutch@footnote{Note names are
1081 available in several languages, but we find the Dutch names quite
1082 convenient.} note names, and ``Fis'' is the Dutch note name for ``F
1083 sharp''.  However, there is no sharp sign in the output. The program
1084 keeps track of key signatures, and will only print accidentals if they
1085 are needed.
1086
1087 For groups of eighth notes and shorter, LilyPond can determine how the
1088 notes should form a beam.  In this case, the 4 eights are automatically
1089 printed as a beam.
1090 @separate
1091 @example 
1092
1093         c4 d8( )c b a( )b4 c8 b a g |
1094  
1095 @end example 
1096 The beginning and ending notes of a slur are marked with parentheses,
1097 @code{(} and @code{)} for start and end respectively.  The line above
1098 indicates two slurs.  These slur markers (parentheses) are entered
1099 between the slurred notes.
1100 @separate
1101 @example 
1102
1103         a4 [b8 a] [g fis] 
1104  
1105 @end example 
1106 Automatic beaming can be overridden by inserting beam marks, @code{[}
1107 and @code{]}.  These beam markers (brackets) are put around the notes
1108 you want beamed.
1109 @separate
1110 @example 
1111
1112         g2.  |
1113  
1114 @end example
1115 @cindex augmentation dot
1116 @cindex dotted note
1117 A period adds a dot to the note.
1118 @separate
1119 @example 
1120
1121         @}
1122  
1123 @end example 
1124 The end of the sequential music to be repeated.  LilyPond will typeset a
1125 repeat bar.
1126 @separate
1127 @example 
1128
1129         cis'4 b8 cis a4 |
1130  
1131 @end example 
1132 Accidentals are printed whenever necessary: the first C sharp of the bar
1133 will be printed with an accidental, the second one without.
1134 @separate
1135 @example 
1136
1137         a8-. b-. cis-. d-. e-. fis-.
1138  
1139 @end example
1140 @cindex articulation
1141 You can enter articulation signs either in a verbose form or using a
1142 shorthand.  Here we demonstrate the shorthand: it is formed by a dash
1143 and the character for the articulation to use, e.g. @code{-.} for
1144 staccato as shown above.
1145 @separate
1146 @example 
1147
1148         fis a, r8 cis8
1149  
1150 @end example 
1151  
1152 Rests are denoted by the special note name @code{r}.  
1153 @separate
1154 @example 
1155
1156         d2.-\fermata
1157  
1158 @end example 
1159 All articulations have a verbose form, like @code{\fermata}.  The
1160 command @code{\fermata} is not part of the core of the language, but it
1161 is a shorthand for a more complicated description of a fermata symbol.
1162 @code{\fermata} names that description and is therefore called an
1163 identifier.
1164 @cindex identifier
1165 @cindex @code{\fermata}
1166 @separate
1167 @example
1168         \bar "|."
1169         @}
1170 @end example 
1171 Here the music ends.  LilyPond does not automatically typeset an end
1172 bar, we must explicitly request one, using @code{"|."}.
1173
1174 @separate
1175 @example 
1176
1177         \paper @{
1178                 % standard settings are too big and wide for a book
1179                 indent = 1.0\cm
1180                 linewidth = 15.0\cm
1181         @}
1182  
1183 @end example 
1184 The @code{\paper} block specifies how entered music should be converted
1185 to notation output.  Most of the details of the conversion (font sizes,
1186 dimensions, etc.) have been taken care of, but to fit the output in this
1187 document, it has to be narrower.  We do this by setting the line width
1188 to 14 centimeters (approximately 5.5 inches).
1189 @separate
1190 @example 
1191
1192         @}
1193  
1194 @end example 
1195 The last brace ends the @code{\score} block.
1196
1197
1198
1199
1200 @node Lyrics and chords
1201 @section Lyrics and chords
1202
1203 In this section we show how to typeset a song. This file is
1204 included as @file{flowing.ly}.
1205
1206 @example 
1207 \header @{
1208         title = "The river is flowing"
1209         composer = "Traditional"
1210 @}
1211 \include "paper16.ly"
1212 melody = \notes \relative c' @{
1213         \partial 8
1214         \key c \minor
1215         g8 |
1216         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1217         c4 c8 d [es () d] c4 | d4 es8 d c4.
1218         \bar "|."
1219 @}
1220
1221 text = \lyrics @{
1222         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1223         ri -- ver is flo -- wing down to the sea.
1224 @}
1225
1226 accompaniment =\chords @{
1227         r8
1228         c2:3- f:3-.7 d:min es4 c8:min r8
1229         c2:min f:min7 g:7^3.5 c:min @}
1230
1231 \score @{
1232         \simultaneous @{
1233           %\accompaniment
1234           \context ChordNames \accompaniment
1235
1236           \addlyrics
1237             \context Staff = mel @{        
1238               \property Staff.noAutoBeaming = ##t
1239               \property Staff.automaticMelismata = ##t
1240               \melody 
1241             @}
1242             \context Lyrics \text
1243         @}
1244         \midi  @{ \tempo 4=72 @}
1245         \paper @{ linewidth = 10.0\cm @}
1246 @} 
1247 @end example 
1248
1249
1250 The result would look this.@footnote{The titling and font size shown
1251 may differ, since the titling in this document is not generated by
1252 @code{ly2dvi}.}
1253
1254 @center @strong{The river is flowing}
1255 @center Traditional 
1256
1257 @lilypond[center]
1258 \header {
1259         title = "The river is flowing"
1260         composer = "Traditional"
1261 }
1262 \include "paper16.ly"
1263 melody = \notes \relative c' {
1264         \partial 8
1265         \key c \minor
1266         g8 |
1267         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1268         c4 c8 d [es () d] c4 | d4 es8 d c4.
1269         \bar "|."
1270 }
1271
1272 text = \lyrics {
1273         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
1274         ri -- ver is flo -- wing down to the sea.
1275 }
1276
1277 accompaniment =\chords {
1278         r8
1279         c2:3- f:3-.7 d:min es4 c8:min r8
1280         c2:min f:min7 g:7^3.5 c:min }
1281
1282 \score {
1283         \simultaneous {
1284           %\accompaniment
1285           \context ChordNames \accompaniment
1286
1287           \addlyrics
1288             \context Staff = mel {
1289               \property Staff.noAutoBeaming = ##t
1290               \property Staff.automaticMelismata = ##t
1291               \melody 
1292             }
1293             \context Lyrics \text
1294         }
1295         \midi  { \tempo 4=72 }
1296         \paper { linewidth = 10.0\cm }
1297 }
1298 @end lilypond
1299
1300 Again, we will dissect the file line by line.
1301 @separate
1302 @example 
1303
1304         \header @{
1305  
1306 @end example
1307 @cindex @code{\header}
1308 Information about the music you are about to typeset goes into a
1309 @code{\header} block.  The information in this block is not used by
1310 LilyPond, but it is passed into the output.  @file{ly2dvi} uses this
1311 information to print titles above the music.
1312 @separate
1313 @example 
1314
1315         title = "The river is flowing"
1316         composer = "Traditional (?)"
1317 @end example
1318 @cindex assignments
1319 @cindex identifier assignment
1320 the @code{\header} block contains assignments.  In each assignment, a
1321 variable is set to a value. Lexically, both the variable name and the
1322 assigned value are strings. The values have to be quoted here, because
1323 they contain spaces. The variable names could also be put within quotes
1324 but it is not necessary. 
1325 @separate
1326 @example 
1327
1328         \include "paper16.ly"
1329  
1330 @end example
1331 Smaller size for inclusion in a book.
1332 @separate
1333 @example 
1334
1335         melody = \notes \relative c' @{
1336  
1337 @end example 
1338 The structure of the file will be the same as the previous one, a
1339 @code{\score} block with music in it.  To keep things readable, we will
1340 give names to the different parts of music, and use the names to
1341 construct the music within the score block.
1342
1343 @separate
1344 @example 
1345         \partial 8
1346 @end example 
1347
1348 @cindex @code{\partial}
1349 @cindex anacrusis
1350 The piece starts with an anacrusis of one eighth.
1351 @separate
1352 @example
1353         \key c \minor
1354 @end example
1355 The key is C minor: we have three flats.
1356
1357 @separate
1358 @example 
1359
1360         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
1361         c4 c8 d [es () d] c4 | d4 es8 d c4.
1362         \bar "|."
1363  
1364 @end example 
1365
1366 @cindex manual beaming
1367 @cindex automatic beaming, turning off
1368 We use explicit beaming.  Since this is a song,  we turn automatic
1369 beams off, and use explicit beaming where needed.
1370 @separate
1371 @example 
1372
1373         @}
1374  
1375 @end example 
1376 This ends the definition of @code{melody}.  
1377
1378 @separate
1379 @example 
1380
1381         text = \lyrics @{
1382  
1383 @end example
1384 @cindex lyrics
1385 @cindex identifier assignment
1386 @cindex syllables, entering
1387 Another identifier assignment.  This one is for the lyrics. 
1388 Lyrics are formed by syllables that have duration, and not by
1389 notes. To make LilyPond parse words as syllables,  switch it  into
1390 lyrics mode with @code{\lyrics}.  Again, the brace after @code{\lyrics}
1391 is a shorthand for @code{\sequential @{}.
1392 @separate
1393 @example 
1394
1395   The4 ri -- ver is flo- __ wing,  flo -- wing and gro -- wing, the
1396   ri- ver is flo- __ wing down to the sea.
1397 @}
1398  
1399 @end example
1400 @cindex extenders, lyric
1401 @cindex hyphens, lyric 
1402 The syllables  themselves are  separated by spaces.  You can get syllable
1403 extenders by entering @code{__}, and centered hyphens with
1404 @code{-}@code{-}.  We enter the syllables as if they are all quarter notes
1405 in length (hence the @code{4}), and use a feature to align the
1406 syllables to the music, which obviously isn't all quarter notes.
1407 @separate
1408 @example 
1409
1410         accompaniment =\chords @{
1411  
1412 @end example
1413 @cindex chords
1414 @cindex mode, chords
1415 We'll put chords over the music. To enter them, there is a special mode
1416 analogous to @code{\lyrics} and @code{\notes} mode, where you can give
1417 the names of the chords you want, instead of listing the notes
1418 comprising the chord.
1419 @separate
1420 @example 
1421
1422         r8
1423  
1424 @end example 
1425 There is no accompaniment during the anacrusis.
1426 @separate
1427 @example 
1428
1429         c2:3- f:3-.7
1430  
1431 @end example
1432
1433 @cindex tonic
1434 @cindex chord modifier
1435 @cindex modifier, chord 
1436 A chord is started by  the tonic of the chord. The
1437 first one lasts a half note.  An unadorned note creates a major
1438 triad. Since a minor triad is wanted, @code{3-} is added to modify the
1439 third to be small. @code{7} modifies (adds) a seventh, which is small by
1440 default to create the @code{f a c es} chord.  Multiple modifiers must be
1441 separated by dots.
1442 @separate
1443 @example 
1444
1445         d:min es4 c8:min r8
1446  
1447 @end example
1448
1449 Some modifiers have predefined names, e.g. @code{min} is  the same as
1450 @code{3-}, so @code{d-min} is a minor @code{d} chord.
1451 @separate
1452 @example 
1453
1454         c2:min f:min7 g:7^3.5 c:min @}
1455  
1456 @end example
1457 @cindex named modifier
1458
1459 A named modifier @code{min} and a normal modifier @code{7} do not have
1460 to be separated by a dot.  Tones from a chord are removed with chord
1461 subtractions.  Subtractions are started with a caret, and they are
1462 also separated by dots.  In this example, @code{g:7^3.5} produces a
1463 minor seventh.  The brace ends the sequential music.
1464 @separate
1465 @example 
1466
1467         \score @{
1468                 \simultaneous @{
1469  
1470 @end example 
1471 We assemble the music in the @code{\score} block.  Melody, lyrics and
1472 accompaniment have to sound at the same time, so they should be
1473 @code{\simultaneous}.
1474 @cindex @code{\simultaneous}
1475 @separate
1476 @example 
1477
1478         %\accompaniment
1479  
1480 @end example 
1481 Chord mode generates notes grouped in @code{\simultaneous} music.  If
1482 you remove the comment sign, you can see the chords in normal
1483 notation: they will be printed as note heads on a separate
1484 staff. To print them as chords names, they have to be interpreted as
1485 being chords, not notes. This is done with the following command:  
1486 @separate
1487 @example 
1488
1489         \context ChordNames \accompaniment
1490  
1491 @end example
1492 @cindex context
1493 @cindex interpretation context
1494 @cindex notation context
1495
1496
1497 Normally, the notes that you enter are transformed into note heads.
1498 Note heads alone make no sense, they need surrounding information: a key
1499 signature, a clef, staff lines, etc.  They need @emph{context}.  In
1500 LilyPond, these symbols are created by objects called `interpretation
1501 contexts'.  Interpretation contexts exist for generating notation
1502 (`notation context') and for generating sound (`performance
1503 context'). These objects only exist during a run of LilyPond.
1504
1505 By default, LilyPond will create a Staff context for you.  If you would
1506 remove the @code{%} sign in the previous line, you would see that
1507 mechanism in action.
1508
1509 We don't want that default here, because we want chord names.  The
1510 command above explicitly creates an interpretation context of 
1511 @code{ChordNames} type to interpret the music @code{\accompaniment}. 
1512 @separate
1513 @example 
1514
1515         \addlyrics
1516  
1517 @end example
1518 @cindex @code{\addlyrics}
1519 @cindex lyrics and melody, combining
1520 @cindex combining lyrics and melody
1521
1522 The lyrics should be aligned with the melody.  This is done by
1523 combining both with @code{\addlyrics}.  @code{\addlyrics} takes two
1524 pieces of music (usually a melody and lyrics, in that order) and
1525 aligns the syllables of the second piece under the notes of the
1526 first piece.  If you would reverse the order, the notes would be
1527 aligned on the lyrics, which is not very useful, and looks
1528 silly.
1529 @separate
1530 @example 
1531
1532         \context Staff = mel @{
1533  
1534 @end example
1535
1536 The first argument of @code{\addlyrics} is the melody.  We instantiate
1537 a @code{Staff} context explicitly: should you choose to remove the
1538 comment before the ``note heads'' version of the accompaniment, the
1539 accompaniment will be on a nameless staff.  The melody has to be on
1540 staff different from the accompaniment.  This is accomplished by giving
1541 the melody and accompaniment staves different names.
1542 @separate
1543 @example 
1544
1545         \property Staff.noAutoBeaming = ##t
1546  
1547 @end example
1548 @cindex \property
1549 @cindex context variables
1550 @cindex setting context variables
1551 An interpretation context has variables, called properties, that tune
1552 its behavior.  One of the variables is @code{noAutoBeaming}.  Setting
1553 this @code{Staff}'s property to @code{##t}, which is the boolean value
1554 @var{true}, turns the automatic beaming mechanism off for the current
1555 staff.
1556 @cindex GUILE
1557 @cindex Scheme
1558 @cindex accessing Scheme
1559 @cindex evaluating Scheme
1560 @cindex LISP
1561
1562 LilyPond internally uses GUILE, a Scheme-interpreter. Scheme is a
1563 language from the LISP family. You can learn more about Scheme at
1564 @uref{http://www.scheme.org}. It is used to represent data throughout
1565 the whole program. The hash-sign (@code{#}) accesses GUILE directly: the
1566 code following the hash-sign is evaluated as Scheme.  The boolean value
1567 @var{true} is @code{#t} in Scheme, so for LilyPond @var{true} looks like
1568 @code{##t}.
1569
1570 If Scheme scares you, don't worry. You don't need to know Scheme to
1571 create beautiful sheet music.
1572
1573
1574
1575 @separate
1576 @example 
1577
1578         \property Staff.automaticMelismata = ##t
1579  
1580 @end example
1581 @cindex automaticMelismata
1582 @cindex melismata
1583 @cindex @code{\addlyrics} and slurs
1584 Similarly, we  don't want to print a  syllable when there is
1585 a slur. This sets up @code{\addlyrics} to not put lyrics under each
1586 separate note while there is a slur.
1587 @separate
1588 @example 
1589
1590           \melody
1591         @}
1592  
1593 @end example 
1594 Finally, we put the melody on the current staff.  Note that the
1595 @code{\property} directives and @code{\melody} are grouped in sequential
1596 music,  so the property settings are done before the melody is
1597 processed.
1598 @separate
1599 @example 
1600
1601         \context Lyrics \text
1602  
1603 @end example 
1604 The second argument of @code{\addlyrics} is the text. The text also
1605 should not land on a Staff, but on a interpretation context for
1606 syllables, extenders, hyphens etc.  This context is called
1607 Lyrics.
1608 @separate
1609 @example 
1610
1611         \midi  @{ \tempo 4=72@}
1612  
1613 @end example 
1614 MIDI (Musical Instrument Digital Interface) is a standard for
1615 connecting and recording digital instruments. So a MIDI file is like a
1616 tape recording of an instrument. The @code{\midi} block makes the
1617 music go to a MIDI file, so you can listen to the music you entered.  It
1618 is great for checking the music.  Whenever you hear something weird, you
1619 probably hear a typing error.
1620
1621 Syntactically, @code{\midi} is similar to @code{\paper @{ @}}, since it
1622 also specifies an output method. You can specify the tempo using the
1623 @code{\tempo} command, in this case the tempo of quarter notes is set to
1624 72 beats per minute.
1625 @separate
1626 @example 
1627
1628         \paper @{ linewidth = 10.0\cm @}
1629  
1630 @end example 
1631 We also want notation output.  The linewidth is short so the piece
1632 will be set in two lines.
1633
1634 @node More movements 
1635 @section More movements
1636
1637 [FIXME: merge here with, or move this to: Other ways to run LilyPond]
1638
1639 You probably ran @file{ly2dvi} on the last example, and ended up with a
1640 viewable @file{.dvi} file.  However, between there are a few steps of
1641 which LilyPond is only one. To enhance your understanding of what's
1642 happening under the hood when you run @code{ly2dvi}, we explain what
1643 programs are run.
1644
1645 @code{ly2dvi} is a program that calls a number of programs  in sequence.
1646 The first thing it does, is running LilyPond on the input file. After
1647 some calculations, a @file{.tex} is produced. The contents
1648 of this file are very  low-level instructions.
1649
1650 For example, consider the following file (@file{miniatures.ly}) 
1651
1652 @example
1653 \version "1.4.0"
1654 \header @{
1655   title = "Two miniatures"
1656   tagline = "small is beautiful"
1657 @}
1658
1659 #(set! point-and-click line-column-location)
1660
1661 \paper @{ linewidth = -1.0 @}
1662
1663 \score @{
1664     \notes @{ c'4 d'4 @}
1665     \header @{
1666         opus = "Opus 1."
1667         piece = "Up" @}
1668 @}
1669 \score @{
1670     \notes @{ d'4 c'4 @}
1671     \header @{
1672         opus = "Opus 2."
1673         piece = "Down" @}
1674 @}
1675 @end example
1676
1677 The titling in this manual was not generated by ly2dvi, so we can't
1678 exactly show what it would look like, but the result should resemble this:
1679
1680 @center @strong{Two miniatures}
1681 @flushright
1682 Opus 1.
1683 @end flushright
1684 @flushleft
1685 @var{Up}
1686 @end flushleft
1687 @lilypond
1688   \score {
1689     \notes { c'4 d'4 }
1690     \paper { linewidth = -1.0 }
1691   }
1692 @end lilypond
1693 @flushright
1694 Opus 2.
1695 @end flushright
1696 @flushleft
1697 @var{Down}
1698 @end flushleft
1699 @lilypond
1700   \score {
1701     \notes { d'4 c'4 }
1702     \paper { linewidth = -1.0 }
1703   }
1704 @end lilypond
1705
1706 This file is produced by ly2dvi in a few stages, with the help of text
1707 formatting tools. LilyPond produces two output files,
1708 @file{miniatures.tex} and @file{miniatures-1.tex}.  Both files contain
1709 only graphical music notation. @file{ly2dvi} looks at what output
1710 LilyPond produces, and adds page layout and titling to those files.  The
1711 result is a DVI file called @file{miniatures.dvi}.
1712
1713 Next, now we'll look at the example line by line to explain new things.
1714
1715 @separate
1716 @example 
1717 \version "1.4.0"
1718 @end example 
1719 Lilypond and its language are still under development, and occasionally,
1720 details of the syntax are changed. This fragment indicates for which
1721 version the input file was written. When you compile this file, the
1722 version number will be checked, and you will get a warning when the file
1723 is too old.
1724
1725 This version number is also used by the @code{convert-ly} program (See
1726 @ref{convert-ly}), which is used to update the file to the latest lily
1727 version.
1728
1729 @separate
1730 @example
1731   \header @{
1732     title = "Two miniatures"  @}
1733 @end example
1734 This sets the titling information for the entire file.
1735 @separate
1736 @example
1737     tagline = "small is beautiful" 
1738 @end example
1739 A signature line is printed at the bottom of the last page.
1740  This signature is produced from the @code{tagline} field of
1741 @code{\header}.  Many people find the default "Lily was here,
1742 @var{version number}" too droll. If that is the case,  assign
1743 something else to @code{tagline}, as shown above.
1744 @separate
1745 @example
1746         #(set! point-and-click line-column-location)
1747 @end example
1748
1749 This piece of Scheme code sets the Scheme variable
1750 @code{point-and-click} to the value @var{line-column-location} (which
1751 itself is a Scheme procedure).
1752
1753 Editing input files can be quite complicated if you're working with
1754 large files: if you're digitizing existing music, you have to
1755 synchronize the .ly file, the sheet music on your lap and the sheet
1756 music on the screen.  The point-and-click mechanism makes it easy to
1757 find the origin of an error in the LY file: when you view the file with
1758 Xdvi and click on a note, your editor will jump to the spot where that
1759 note was entered.  For more information, see @ref{Point and click}.
1760
1761 @separate
1762 @example
1763   \paper @{ 
1764 @end example
1765
1766 The @code{\score} blocks that follow in the file don't have
1767 @code{\paper} sections, so the settings of this block are substituted: A
1768 paper block at top level, i.e. not in a @code{\score} block sets the
1769 default page layout.
1770
1771 @separate
1772 @example
1773   linewidth = -1.0 @}
1774 @end example
1775
1776
1777
1778 The variable @code{linewidth} normally sets the length of the systems on
1779 the page. However, a negative value has a special meaning. If
1780 @code{linewidth} is less than 0, no line breaks are inserted into the
1781 score, and the spacing is set to natural length: a short phrase takes up
1782 little space, a longer phrase more space.
1783
1784 @separate
1785 @example
1786   \score @{
1787     \notes @{ c'4 d'4 @}
1788 @end example
1789
1790 In previous examples, notes were specified in relative octaves,
1791 i.e. each note was put in the octave that is closest to its
1792 predecessor. Besides relative, there is also absolute octave
1793 specification, which you get when you don't specify @code{\relative}. In
1794 this input mode, the central C is denoted by @code{c'}. Going down, you
1795 get @code{c} @code{c,} @code{c,,} etc.  Going up, you get @code{c''}
1796 @code{c'''} etc.
1797
1798 When you're copying music from existing sheet music, relative octaves
1799 are probably the easiest to use: it's less typing work and errors are
1800 easily spotted. However, if you write LilyPond input directly, either by
1801 hand (i.e. composing) or by computer, absolute octaves may be easier to use.
1802
1803
1804 @separate
1805 @example
1806     \header @{
1807 @end example
1808
1809 The @code{\header} is normally at the top of the file, where it sets
1810 values for the rest of the file. If you want to typeset different pieces
1811 from one file (for example, if there are multiple movements, or if
1812 you're making an exercise book), you can put different @code{\score}
1813 blocks into the input file. ly2dvi will assemble all LilyPond output
1814 files into a big document. The contents of \header blocks specified
1815 within each score, are used for the titling of each movement.
1816 @separate
1817 @example
1818         opus = "Opus 1."
1819         piece = "Up" @}
1820 @end example
1821 For example, the Opus number is put at the right, and the piece string
1822 will be at the left.
1823
1824
1825
1826 @node A piano excerpt
1827 @section A piano excerpt
1828
1829 Our fourth subject is a piece of piano music.  The fragment in the
1830 input file is a piano reduction of the G major Sinfonia by Giovanni
1831 Battista Sammartini.  It was composed around 1740.  It's in the source
1832 package under the name @file{sammartini.ly}.
1833
1834 @lilypond[verbatim]
1835 \include "paper16.ly"
1836
1837 stemDown = \property Voice.Stem \override #'direction = #-1
1838 stemUp = \property Voice.Stem \override #'direction = #1
1839 stemBoth = \property Voice.Stem \revert #'direction  
1840
1841 viola = \notes \relative c' \context Voice = viola {
1842     <c4-\f-\arpeggio g' c>
1843     \stemDown g'8. b,16
1844     s1 s2. r4
1845     g
1846 }
1847
1848 oboes = \notes \relative c'' \context Voice = oboe {
1849     \stemUp s4  g8. b,16 c8 r <e'8.^\p g> <f16 a>
1850     \grace <e8( g> <d4 )f> <c2 e>
1851     \times 2/3 { <d8 \< f> <e g> <f a> }
1852     <
1853         { \times 2/3 { a8 g c } \! c2 }
1854         \context Voice = oboeTwo {
1855             \stemDown
1856             \grace {
1857                 \property Voice.Stem \override #'direction = #-1
1858                 [f,16 g] 
1859                 \property Voice.Stem \revert #'direction
1860             }
1861             f8 e e2
1862         }
1863     >
1864     \stemBoth
1865     \grace <c,8( e> <)b8. d8.-\trill> <c16 e> | 
1866     [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r  |
1867     [<c16( e>  < )e8. g>] <c8 e,>
1868 }
1869
1870 hoomPah = \repeat unfold 8 \notes
1871     \transpose c' { \stemUp c8 \stemBoth \stemDown g'8 \stemBoth }
1872
1873 bassvoices = \notes \relative c' {
1874     c4 g8. b,16
1875     \autochange Staff \context Voice \hoomPah
1876     \translator Staff = down
1877     \stemDown [c8 c'8] r4
1878     <g d'> r4
1879     < {\stemUp r2 <e4 c'> <c8 g'> }
1880         \context Voice = reallyLow  {\stemDown g2 ~ | g4 c8 } >
1881 }
1882
1883 \score {
1884     \context PianoStaff \notes <
1885         \context Staff = up < \time 2/2
1886             \viola
1887             \oboes
1888         >
1889         \context Staff = down < \time 2/2 \clef bass
1890             \bassvoices
1891         >
1892     >
1893     \midi { }
1894     \paper {
1895         indent = 0.0
1896         linewidth = 15.0 \cm }
1897 }
1898 @end lilypond
1899
1900 If this looks like incomprehensible gibberish to you, you are right.
1901 This example has been doctored to have as many quirks as possible.
1902
1903 As you can see, this example features multiple voices on one staff.  To
1904 make room for those voices, their notes have to be stemmed in opposite
1905 directions.
1906
1907 Printed symbols are internally represented by so-called Graphical
1908 Objects (more colloquially: Grobs).  These statements concern the
1909 grob called `Stem'. Each grob is described by a bunch of settings. These
1910 setting determine the fonts, offsets, sub-routines to be called on the
1911 grob, etc.  The initial values of these settings are set in the Scheme
1912 file @file{scm/grob-description.scm}.
1913
1914 @separate
1915 @example
1916   stemDown = \property Voice.Stem \override #'direction = #-1
1917 @end example
1918
1919 Set a property for all Stem grobs in the current Voice:
1920 @code{direction} is set to @code{-1}, which encodes down.  The setting
1921 remains in effect until it is reverted.
1922
1923 @separate
1924 @example
1925  \property Voice.Stem \revert #'direction  
1926 @end example
1927
1928 Revert the to the previous setting.  The effect of precisely one
1929 @code{\stemDown} or @code{\stemUp} is neutralized.
1930
1931
1932 LilyPond includes the identifiers @code{\stemUp}, @code{\stemDown} along
1933 with some other commonly used formatting instructions, but to explain how
1934 it works, we wrote our own here.  Of course, you should use predefined
1935 identifiers like these if possible: then you will be affected less by
1936 the implementation changes we occasionally make.
1937
1938 @separate
1939 @example 
1940 viola = \notes \relative c'  \context Voice = viola @{ 
1941 @end example 
1942 In this example, you can see multiple parts on a staff.  Each part is
1943 associated with one notation context.  This notation context handles
1944 stems and dynamics (among others).  The type name of this context is
1945 @code{Voice}.  For each part we have to make sure that there is
1946 precisely one @code{Voice} context, so we give it a unique name
1947 (`@code{viola}').
1948
1949 @separate
1950 @example 
1951 <c4-\f-\arpeggio g' c>
1952 @end example 
1953 The delimiters @code{<} and @code{>} are shorthands for
1954 @code{\simultaneous @{} and @code{@}}. The expression enclosed in
1955 @code{<} and @code{>} is a chord.
1956
1957 @cindex dynamics
1958 @cindex loudness
1959 @cindex forte
1960 @cindex arpeggio
1961
1962 @code{\f} places a forte symbol under the chord. The forte applies to
1963 the whole chord, but the syntax requires that commands like forte and
1964 arpeggio are attached to a note, so here we attach them to the first
1965 note.
1966
1967 @code{\arpeggio} typesets an arpeggio sign (a wavy vertical line) before
1968 the chord.
1969
1970 @separate
1971 @example 
1972    \stemDown
1973 @end example 
1974
1975
1976 @separate
1977 @example 
1978         g'8. b,16 
1979 @end example 
1980 Relative octaves work a little differently with chords.  The starting
1981 point for the note following a chord is the first note of the chord.  So
1982 the @code{g} gets an octave up quote: it is a fifth above the starting
1983 note of the previous chord (the central C).
1984
1985 @separate
1986 @example 
1987 s1 s2. r4 
1988 @end example 
1989 @code{s} is a spacer rest.  It does not print anything, but it does have
1990 the duration of a rest. It is useful for filling up voices that
1991 temporarily don't play. In this case, the viola doesn't come until one
1992 and a half measure later.
1993
1994 @separate
1995 @example 
1996 oboes = \notes \relative c'' \context Voice = oboe @{ 
1997 @end example 
1998 Now comes a part for two oboes.  They play homophonically, so we
1999 print the notes as one voice that makes chords. Again, we insure that
2000 these notes are indeed processed by precisely one context with
2001 @code{\context}.
2002 @separate
2003 @example 
2004 \stemUp s4  g8. b,16 c8 r <e'8.-\p g> <f16 a> 
2005 @end example 
2006 @code{\stemUp} is a reference to the @code{\property \override} command
2007 defined above. 
2008 @separate
2009 @example 
2010 \grace <e8 g> < d4 f> <c2 e> 
2011 @end example
2012 @cindex @code{\grace}
2013 @cindex ornaments
2014 @cindex grace notes
2015 @code{\grace} introduces grace notes.  It takes one argument, in this
2016 case a chord.
2017
2018 @ignore
2019 The slur started on the @code{e} of the chord
2020 will be attached to the next note.@footnote{LilyPond will squirm
2021 about unended Slurs.  In this case, you can ignore the warning}.
2022 @end ignore
2023 @separate
2024 @example 
2025 \times 2/3 
2026 @end example
2027 @cindex tuplet
2028 @cindex triplets
2029 Tuplets are made with the @code{\times} keyword.  It takes two
2030 arguments: a fraction and a piece of music.  The duration of the piece
2031 of music is multiplied by the fraction.  Triplets make notes occupy 2/3
2032 of their notated duration, so in this case the fraction is 2/3.
2033 @separate
2034 @example 
2035 @{ <d8 \< f> <e g> <f a> @} 
2036 @end example 
2037 The piece of music to be `tripletted' is sequential music containing
2038 three notes.  On the first chord, a crescendo is started with
2039 @code{\<}. To be precise, the crescendo start is syntactically attached
2040 to the preceding note, the @code{d}.
2041
2042 @cindex dynamics
2043 @cindex crescendo
2044 @cindex @code{\<}
2045
2046 @separate
2047 @example 
2048
2049 @end example 
2050 At this point, the homophonic music splits into two rhythmically
2051 different parts.  We can't use a sequence of chords to enter this, so
2052 we make a `chord' of sequences to do it.  We start with the upper
2053 voice, which continues with upward stems:
2054 @separate
2055 @example 
2056  @{ \times 2/3 @{ a8 g c @} \! c2 @} 
2057 @end example
2058
2059 @cindex @code{\!}
2060
2061 The crescendo is ended at the half note by the escaped exclamation
2062 mark @code{\!}.
2063 @separate
2064 @example 
2065 \context Voice = oboeTwo @{
2066 \stemDown 
2067 @end example 
2068 We can't share stems with the other voice, so we have to create a new
2069 @code{Voice} context.  We give it the name @code{oboeTwo} to distinguish
2070 it from the other context.  Stems go down in this voice.
2071 @separate
2072 @example 
2073 \grace
2074 @end example
2075 @cindex Grace context
2076 When a grace section is processed, a @code{Grace} context is
2077 created. This context acts like a miniature score of its own.  It has
2078 its own time bookkeeping, and you can make notes, beams, slurs
2079 etc. Here we fiddle with a property and make a beam.  The argument of
2080 @code{\grace} is sequential music.
2081
2082 @separate
2083 @example 
2084                 \property Voice.Stem \override #'direction = #-1
2085                 [f,16 g] 
2086                 \property Voice.Stem \revert #'direction
2087 @end example 
2088
2089 Normally, grace notes are always stem up, but in this case, the upper
2090 voice interferes, so we set the stems down here.
2091
2092 As far as relative mode is concerned, the previous note is the
2093 @code{c'''2} of the upper voice, so we have to go an octave down for
2094 the @code{f}.
2095 @separate
2096 @example 
2097
2098   f8 e e2
2099 @} > 
2100 @end example 
2101 This ends the two-part section.
2102 @separate
2103 @example 
2104 \stemBoth
2105 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |  
2106 @end example
2107 @cindex trill
2108 @cindex stemBoth
2109
2110 @code{\stemBoth} ends the forced stem directions. From here, stems are
2111 positioned as if it were single part music.
2112
2113 The bass has a little hoom-pah melody to demonstrate parts switching
2114 between staves.  Since it is repetitive, we use repeats:
2115 @separate
2116 @example 
2117 hoomPah  =  \repeat unfold 8
2118 @end example
2119 @cindex unfolded @code{\repeat}
2120 The unfolded repeat prints the notes in its argument as if they were
2121 written out in full eight times.
2122 @separate
2123 @example
2124 \notes \transpose c' @{
2125 @end example
2126 @cindex transposing
2127 @cindex relative mode and transposing
2128
2129 Transposing can be done with @code{\transpose}, which takes two arguments.
2130 The first specifies what central C should be transposed to.  The second
2131 is the to-be-transposed music.  As you can see, in this case, the
2132 transposition has no effect, as central C stays at central C.
2133
2134 The purpose of this no-op is circumventing relative mode.  Relative mode
2135 can not be used together with transposition, so @code{\relative} will
2136 leave the contents of @code{\hoomPah} alone.  We can use it without
2137 having to worry about getting the motive in a wrong octave.
2138 @separate
2139 @example 
2140 bassvoices = \notes \relative c' @{
2141 c4 g8. b,16
2142 \autochange Staff \hoomPah \context Voice
2143 @end example
2144 @cindex staff switch, automatic
2145 @cindex cross staff voice, automatic
2146 @cindex @code{\autochange}
2147
2148 Voices can switch between staves. The easiest way to get this, is to use
2149 @code{\autochange}. This command looks at the pitch of each note, and if
2150 necessary, will cross to the other staff. For this to work, the two
2151 staves must be called @code{"up"} and @code{"down"}.
2152 @separate
2153 @example
2154         \translator Staff = down
2155 @end example
2156 @cindex staff switch
2157 @cindex cross staff voice
2158 We want the remaining part of this melody on the lower staff, so we do a
2159 manual staff switch here.
2160
2161
2162 @separate
2163 @example 
2164 \context Voice = reallyLow  @{\stemDown g2 ~ | g4 c8 @} > 
2165 @end example
2166 @cindex tie
2167 @cindex @code{~}
2168 After skipping some lines, we see @code{~}.  This mark makes ties.  Note
2169 that ties and slurs are different things.  A tie can only connect two
2170 note heads of the same pitch, whereas a slur can connect many chords
2171 with one curve.
2172
2173 @separate
2174 @example 
2175 \context PianoStaff 
2176 @end example 
2177  A special context is needed to get cross staff beaming right.  This
2178 context is called @code{PianoStaff}.
2179 @separate
2180 @example 
2181 \context Staff = bottom < \time 2/2 \clef bass 
2182 @end example 
2183 The bottom staff must have a different clef.
2184 @separate
2185 @example 
2186 indent = 0.0 
2187 @end example 
2188 To make some more room on the line, the first (in this case the only)
2189 line is not indented.  The line still looks very cramped, but that is due
2190 to the page layout of this document.
2191
2192
2193 @ignore
2194 [TODO:
2195
2196 * font-size, multi-stanza.
2197
2198 * Simple part combining in a Hymn
2199 @end ignore
2200
2201
2202 @node An orchestral score
2203 @section An orchestral score
2204
2205 @menu
2206 * The full score::              
2207 * Extracting an individual part::  
2208 @end menu
2209
2210
2211 Our last two examples show a way to setup the music for an orchestral
2212 score.  When typesetting a piece for several instruments, you'll want to
2213 create a conductor's full score, alongside several individual parts.
2214
2215 LilyPond is well suited for this task.  We will declare the music for
2216 each instrument individually, giving the music of each instrument its
2217 own name.  These pieces of music are then combined in different
2218 @code{\score} blocks to produce different combinations of the score.
2219
2220 This orchestral score example consists of three input files.  In the
2221 first file, @file{os-music.ly}, we define the music for all instruments.
2222 This file will be used both for producing the score and the separate
2223 parts.
2224
2225 If you were to run LilyPond on this file, no printable output would be
2226 produced.
2227
2228 @example
2229 % os-music.ly
2230 \header @{
2231   title = "Zo, goed lieverd?"
2232   subtitle = "How's, this babe?"
2233   composer = "JCN"
2234   opus = "1"
2235   piece = "Laid back"
2236 @}
2237 global = @{
2238   \time 2/4
2239   \skip 2*4 \bar "|."
2240 @}
2241 Key = \notes \key as \major
2242 flautoI = \notes\relative c'' @{
2243   f8 g f g f g f g
2244   bes as bes as bes as bes as
2245 @}
2246 flautoII = \notes\relative c'' @{
2247   as8 bes as bes R1 d4 ~ d
2248 @}
2249 tromboI = \notes\relative c'' @{
2250   c4. c8 c8 c4. es4 r as, r
2251 @}
2252 tromboII = \notes\relative c'' @{
2253   as4. as8 as8 as4. R1*1/2 as4 es'
2254 @}
2255 timpani = \notes\relative c, @{
2256   \times 2/3 @{ f4 f f @}
2257   \times 4/5 @{ as8 as as as as @}
2258   R1
2259 @}
2260 corno = \notes\relative c' @{
2261    bes4 d f, bes d f, bes d
2262 @}
2263 @end example
2264
2265 We will not go through the input line by line, but only indicate and
2266 explain the new elements.
2267
2268
2269 @separate
2270 @example
2271 global = @{
2272   \time 2/4
2273   \skip 2*4 \bar "|.";
2274 @}
2275 @end example
2276
2277 Declare setting to be used globally.  The @code{\skip} command produces
2278 no output, but moves forward in time: in this case, the duration of a
2279 half note (@code{2}), and that four times (@code{*4}).  This brings us
2280 to the end of the piece, and we can set the end bar.
2281
2282 @separate
2283 @example
2284 Key = \notes \key as \major
2285 @end example
2286 Declare the key signature of the piece and assign it to the identifier
2287 @var{Key}.  Later on, we'll use @code{\Key} for all staves except those
2288 for transposing instruments.
2289
2290 @node The full score
2291 @subsection The full score
2292
2293
2294 The second file, @file{os-score.ly} reads the definitions of the first
2295 (@file{os-music.ly}), and defines the @code{\score} block for the full
2296 conductor's score.
2297
2298
2299 @example
2300 % os-score.ly
2301 \include "os-music.ly"
2302 \include "paper13.ly"
2303
2304 #(set! point-and-click line-column-location)
2305 #(define text-flat '((font-relative-size . -2)
2306          (music "accidentals--1")))
2307
2308 \score @{
2309   <
2310     \global
2311     \property Score.BarNumber \override #'padding = #3
2312     \context StaffGroup = woodwind <
2313       \context Staff = flauti <
2314         \property Staff.midiInstrument = #"flute"
2315         \property Staff.instrument = "2 Flauti"
2316         \property Staff.instr = "Fl."
2317         \Key
2318         \context Voice=one @{ \voiceOne \flautoI @}
2319         \context Voice=two @{ \voiceTwo \flautoII @}
2320       >
2321     >
2322     \context StaffGroup = timpani <
2323       \context Staff = timpani <
2324         \property Staff.midiInstrument = #"timpani"
2325         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2326         \property Staff.instr = #"Timp."
2327         \clef bass
2328         \Key
2329         \timpani
2330       >
2331     >
2332     \context StaffGroup = brass <
2333       \context Staff = trombe <
2334         \property Staff.midiInstrument = #"trumpet"
2335         \property Staff.instrument = #`(lines "2 Trombe" "(C)")
2336         \property Staff.instr = #`(lines "Tbe." "(C)")
2337         \Key
2338         \context Voice=one \partcombine Voice
2339           \context Thread=one \tromboI
2340           \context Thread=two \tromboII
2341       >
2342       \context Staff = corni <
2343         \property Staff.midiInstrument = #"french horn"
2344         \property Staff.instrument = #`(lines "Corno"
2345           (columns "(E" ,text-flat ")"))
2346         \property Staff.instr = #`(lines "Cor."
2347           (columns "(E" ,text-flat ")"))
2348         \property Staff.transposing = #3
2349         \notes \key bes \major
2350         \context Voice=one \corno
2351       >
2352     >
2353   >
2354   \paper @{
2355     indent = 15 * \staffspace
2356     linewidth = 60 * \staffspace
2357     textheight = 90 * \staffspace
2358     \translator@{
2359       \HaraKiriStaffContext
2360     @}
2361   @}
2362   \midi @{
2363     \tempo 4 = 75
2364   @}
2365 @}
2366 @end example
2367
2368 @center @strong{Zo, goed lieverd?}
2369 @sp 1
2370 @center How's, this babe?
2371 @flushright
2372 Opus 1.
2373 @end flushright
2374 @flushleft
2375 @sc{Laid back}
2376 @end flushleft
2377
2378 @lilypondfile{os-score.ly}
2379
2380 @separate
2381 @example
2382 \include "os-music.ly"
2383 @end example
2384 First, we need to include the music definitions we made in
2385 @file{os-music.ly}.
2386
2387 @separate
2388 @example
2389 #(set! point-and-click line-column-location)
2390 @end example
2391 In a large orchestral score like this you're bound to make some small
2392 mistakes, so we enable point and click (See @ref{Point and click})
2393 editing.
2394
2395 @separate
2396 @example
2397 #(define text-flat '((font-relative-size . -2)
2398          (music "accidentals--1")))
2399 @end example
2400
2401 When naming the tuning of the french horn, we'll need a piece of text
2402 with a flat sign.  LilyPond has a mechanism for font selection and
2403 kerning called Scheme markup text (See @ref{Text markup}).  The flat
2404 sign is taken from the music font, and its name is @code{accidentals--1}
2405 (The natural sign is called @code{accidentals-0}).  The default font is
2406 too big for text, so we select a relative size of @code{-2}.
2407
2408 @separate
2409 @example
2410   <
2411     \global
2412 @end example
2413 Of course, all staves are simultaneous and use the same global settings.
2414
2415 @separate
2416 @example
2417     \property Score.BarNumber \override #'padding = #3
2418 @end example
2419 LilyPond prints bar numbers at the start of each line, but
2420 unfortunately, they end up a bit too close to the staff in this example.
2421 A bar number internally is a Grob called @var{BarNumber}.  BarNumber
2422 Grobs can be manipulated through their @var{side-position-interface}.  One
2423 of the properties of a @var{side-position-interface} that can be tweaked
2424 is the @var{padding}: the amount of extra space that is put between this
2425 Grob and other Grobs.  We set the padding to three staff spaces.
2426
2427 You can find information on all these kind of properties in LilyPond's
2428 automatically generated documentation in
2429 @ifnottex
2430 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}.
2431 @end ifnottex
2432 @iftex
2433 the online documentation.
2434 @end iftex
2435
2436 @separate
2437 @example
2438     \context StaffGroup = woodwind <
2439       \context Staff = flauti <
2440 @end example
2441 A new notation context: the @code{StaffGroup}.  @code{StaffGroup} can
2442 hold one or more @code{Staff}'s, and will print a big bracket at the
2443 left of the score.  Start a new staff group for the woodwind section
2444 (just the flutes in this case).  Immediately after that, we start the
2445 staff for the two flutes, that also play simultaneously.
2446
2447 @separate
2448 @example
2449         \property Staff.midiInstrument = #"flute"
2450 @end example
2451 Specify the instrument for MIDI output (see @ref{MIDI instrument
2452 names}).
2453
2454 @separate
2455 @example
2456         \property Staff.instrument = "2 Flauti"
2457         \property Staff.instr = "Fl."
2458 @end example
2459 And define the instrument names to be printed in the margin,
2460 @code{instrument} for the first line of the score, @code{instr} for the
2461 rest of the score.
2462
2463 @separate
2464 @example
2465         \Key
2466 @end example
2467 The flutes play in the default key.
2468
2469 @separate
2470 @example
2471         \context Voice=one @{ \voiceOne \flautoI @}
2472         \context Voice=two @{ \voiceTwo \flautoII @}
2473 @end example
2474 Last come the actual flute parts.  Remember that we're still in
2475 simultaneous mode.  We name both voices differently, so that LilyPond
2476 will actually create two Voice contexts.  The flute parts are simple, so
2477 we specify manually which voice is which: @code{\voiceOne} forces the
2478 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
2479 directions down.
2480
2481 @separate
2482 @example
2483       >
2484     >
2485 @end example
2486 Close the flutes staff and woodwind staff group.
2487
2488 @separate
2489 @example
2490         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
2491 @end example
2492 The timpani staff only shows a new piece of scheme markup, it sets two
2493 lines of text.
2494
2495 @separate
2496 @example
2497         \context Voice=one \partcombine Voice
2498           \context Thread=one \tromboI
2499           \context Thread=two \tromboII
2500 @end example
2501 You have seen the notation contexts Staff and Voice, but here's a new
2502 one: Thread.  One or more Threads can be part of a Voice.  The Thread
2503 takes care of note heads and rests, the Voice combine note heads onto a
2504 stem.
2505
2506 For the trumpets we use the automatic part combiner (see @ref{Automatic
2507 part combining}) to combine the two simultaneous trumpet parts onto the
2508 trumpet staff.  Each trumpet gets its own Thread context, which must be
2509 named @code{one} and @code{two}).  The part combiner makes these two
2510 threads share a Voice when they're similar, and splits the threads up
2511 when they're different.
2512
2513 @separate
2514 @example
2515         \property Staff.instrument = #`(lines "Corno"
2516           (columns "(E" ,text-flat ")"))
2517 @end example
2518 The french horn has the most complex scheme markup name, made up of two
2519 lines of text.  The second line has three elements (columns), the @code{(E},
2520 the flat sign @code{text-flat} that we defined before and a final @code{")"}.
2521 Note that we use a backquote instead of an ordinary quote at the
2522 beginning of the Scheme expression to be able to access the
2523 @code{text-flat} identifier, `unquoting' it with a @code{,}.
2524
2525 @separate
2526 @example
2527         \property Staff.transposing = #3
2528 @end example
2529 The french horn is to be tuned in E-flat, so we tell the MIDI backend to
2530 transpose this staff by three steps.
2531
2532 Note how we can choose different tuning for entering, printing and
2533 playing, using @code{\transpose} and the MIDI Staff property
2534 @var{transposing}.
2535
2536 @separate
2537 @example
2538         \notes \key bes \major
2539 @end example
2540 Therefore, it has a different key.
2541
2542 @separate
2543 @example
2544     indent = 15 * \staffspace
2545     linewidth = 60 * \staffspace
2546 @end example
2547 We specify a big indent for the first line and a small linewidth for this
2548 tutorial.
2549
2550 @separate
2551
2552 Usually, LilyPond's predefined setup of notation contexts (Thread,
2553 Voice, Staff, Staffgroup, Score) is just fine.  But in this case, we
2554 want a different type of Staff context.
2555
2556 @example
2557     \translator@{
2558       \HaraKiriStaffContext
2559     @}
2560 @end example
2561
2562 In orchestral scores, it often happens that one instrument has only
2563 rests during one line of the score.  The @code{HaraKiriStaffContext} can
2564 be used as a regular @code{StaffContext} drop-in and will take care of
2565 the automatic removing of empty staves.
2566
2567 @node Extracting an individual part
2568 @subsection Extracting an individual part
2569
2570 The third file, @file{os-flute-2.ly} also reads the definitions of the
2571 first (@file{os-music.ly}), and defines the @code{\score} block for the
2572 second flute part.
2573
2574 @example
2575 \include "os-music.ly"
2576 \include "paper16.ly"
2577
2578 \score @{
2579   \context Staff <
2580     \property Score.skipBars = ##t
2581     \property Staff.midiInstrument = #"flute"
2582     \global
2583     \Key
2584     \flautoII
2585   >
2586   \header @{
2587     instrument = "Flauto II"
2588   @}
2589   \paper @{
2590     linewidth = 80 * \staffspace
2591     textheight = 200 * \staffspace
2592   @}
2593   \midi @{
2594     \tempo 4 = 75
2595   @}
2596 @}
2597 @end example
2598
2599 @center @strong{Zo, goed lieverd?}
2600 @sp 1
2601 @center How's, this babe?
2602 @center @emph{Flauto II}
2603 @flushright
2604 Opus 1.
2605 @end flushright
2606 @flushleft
2607 @sc{Laid back}
2608 @end flushleft
2609 @lilypondfile{os-flute-2.ly}
2610
2611
2612 Because we separated the music definitions from the @code{\score}
2613 instantiations, we can easily define a second score with the music of
2614 the second flute.  This then is the part for the second flute player.
2615 Of course, we make separate parts for all individual instruments.
2616
2617 @separate
2618 @example
2619     \flautoII
2620 @end example
2621 In this individual part the second flute has a whole staff for itself,
2622 so we don't want to force stem or tie directions.
2623
2624 @separate
2625 @example
2626   \header @{
2627     instrument = "Flauto II"
2628   @}
2629 @end example
2630 The @code{\header} definitions were also read from @file{os-music.ly},
2631 but we need to set the instrument for this particular score.
2632
2633 @separate
2634 @example
2635     \property Score.skipBars = ##t
2636 @end example
2637 In the conductor's full score, all bars with rests are printed, but for
2638 the individual parts, we want to contract pieces of consecutive empty
2639 bars.  LilyPond will do this if Score's @var{skipBars} property to
2640 true. 
2641
2642
2643 @node Other ways to run LilyPond
2644 @section Other ways to run LilyPond
2645
2646 Until now, you have been using @file{ly2dvi} to invoke LilyPond.
2647 There are three other routes.  Firstly, there is a script called
2648 @code{lilypond-book}, that allows you to freely mix LilyPond input with
2649 Texinfo or \LaTeX input. For example, this manual was written using
2650 @code{lilypond-book}. It is discussed below and in @ref{lilypond-book}.
2651
2652
2653 Secondly, you can generate PostScript directly. This is useful if you
2654 can not or do not want to run @TeX{} on your system.  To obtain direct
2655 PostScript output, invoke LilyPond as follows:
2656 @cindex PostScript output
2657 @example
2658 lilypond -f ps test.ly
2659 @end example
2660 You have to set some environment variables to view or print this output. 
2661 More information can be found in @ref{Invoking LilyPond}. Since the
2662 direct Postscript generation has some problems, it is recommended
2663 to use @file{ly2dvi}.
2664
2665
2666 Thirdly, if you want to do special things with your output, you can run
2667 invoke LilyPond directly:
2668 @example
2669 lilypond test.ly
2670 @end example
2671 to produce plain @TeX{} output.  Note that La@TeX{} will not work on the
2672 resulting @file{test.tex}.  You must run plain @TeX{} on it.
2673
2674 @cindex @TeX{}
2675
2676
2677
2678
2679
2680 @node Integrating text and music
2681 @section Integrating text and music
2682
2683 Sometimes, you might want to use music examples in a text that you are
2684 writing. For example, if you are writing a musicological treatise, a
2685 songbook, or (like us) the LilyPond manual.  You can make such texts by
2686 hand, simply by importing a PostScript figure into your wordprocessor.
2687 However, there is a also an automated procedure:
2688
2689 If you use La@TeX{} or texinfo, you can mix text and LilyPond code. A
2690 script called @code{lilypond-book} will extract the music fragments, run
2691 LilyPond on them, and put back the resulting notation.  lilypond-book is
2692 described fully in @ref{lilypond-book}, but here we show a small
2693 example. Since the example also contains explanatory text, we won't
2694 comment on the contents.
2695
2696 @example
2697 \documentclass[a4paper]@{article@}
2698 \begin@{document@}
2699
2700 In a lilypond-book document, you can freely mix music and text. For
2701 example:
2702 \begin@{lilypond@}
2703   \score @{ \notes \relative c' @{
2704      c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
2705   @} @}
2706 \end@{lilypond@}
2707 Notice that the music line length matches the margin settings of the
2708 document.
2709
2710 If you have no \verb+\score+ block in the fragment,
2711 \texttt@{lilypond-book@} will supply one:
2712
2713 \begin@{lilypond@}
2714   c'4
2715 \end@{lilypond@}
2716
2717 In the example you see here, a number of things happened: a
2718 \verb+\score+ block was added, and the line width was set to natural
2719 length. You can specify many more options using  \LaTeX style options
2720 in brackets:
2721
2722 \begin[verbatim,11pt,singleline,
2723   fragment,relative,intertext="hi there!"]@{lilypond@}
2724   c'4 f bes es
2725 \end@{lilypond@}
2726
2727 \texttt@{verbatim@} also shows the LilyPond code, \texttt@{11pt@} selects
2728 the default music size, \texttt@{fragment@} adds a score block,
2729 \texttt@{relative@} uses relative mode for the fragment, and
2730 \texttt@{intertext@} specifies what to print between the
2731 \texttt@{verbatim@} code and the music.
2732
2733 If you include large examples into the text, it may be more convenient
2734 to put the example in a separate file:
2735
2736 \lilypondfile[printfilename]@{sammartini.ly@}
2737
2738 The \texttt@{printfilename@} option adds the file name to the output.
2739
2740 \end@{document@}
2741 @end example
2742
2743 Under Unix, you can view the results as follows.
2744 @example
2745 $ cd input/tutorial
2746 $ lilypond-book --outdir=out/ lilbook.tex
2747 lilypond-book (GNU LilyPond) 1.3.146
2748 Reading `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/lilbook.tex'
2749 Reading
2750 `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/sammartini.ly'
2751 @var{lots of stuff deleted}
2752 Writing `out/lilbook.latex'
2753 $ cd out
2754 $ latex lilbook.latex
2755 @var{lots of stuff deleted}
2756 $ xdvi lilbook 
2757 @end example
2758
2759 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
2760 and running latex creates a lot of temporary files, and you wouldn't want
2761 those to clutter up your working directory. Hence, we have them created
2762 in a separate subdirectory.
2763
2764 The result more or less looks like this: 
2765
2766 @separate
2767
2768 In a lilypond-book document, you can freely mix music and text. For
2769 example:
2770 @lilypond
2771   \score { \notes \relative c' {
2772      c2 g'2 \times 2/3 { f8 e d } c'2 g4
2773   } }
2774 @end lilypond
2775 Notice that the music line length matches the margin settings of the
2776 document.
2777
2778 If you have no @code{\score} block in the fragment,
2779 @code{lilypond-book} will supply one:
2780
2781 @lilypond
2782   c'4
2783 @end lilypond
2784
2785 In the example you see here, a number of things happened: a
2786 @code{\score} block was added, and the line width was set to natural
2787 length. You can specify many more options using  La@TeX{} style options
2788 in brackets:
2789
2790 @lilypond[verbatim,11pt,singleline,
2791   fragment,relative,intertext="hi there!"]
2792   c'4 f bes es
2793 @end lilypond
2794
2795 @code{verbatim} also shows the LilyPond code, @code{11pt} selects
2796 the default music size, @code{fragment} adds a score block,
2797 @code{relative} uses relative mode for the fragment, and
2798 @code{intertext} specifies what to print between the
2799 @code{verbatim} code and the music.
2800
2801 If you include large examples into the text, it may be more convenient
2802 to put the example in a separate file:
2803
2804 @lilypondfile[printfilename]{sammartini.ly}
2805
2806 The @code{printfilename} option adds the file name to the output.
2807 @node  End of tutorial
2808 @section End of tutorial
2809          
2810 That's all folks.  From here, you can either try fiddling with input
2811 files, or you can read the reference manual.  You can find more example
2812 files in @file{input} and @file{input/test}.  You can also look at some
2813 real music.  The website @uref{http://www.mutopiaproject.org} has many
2814 examples of real music typeset by LilyPond.
2815
2816
2817
2818 @ignore
2819
2820 [TODO
2821
2822 this should be on mutopia website.
2823
2824 ]
2825
2826
2827 @c waar deze info?  is uiteindelijk wel handig, schat ik.
2828 [TODO: cut blabla]
2829
2830 If you have a big music project, or just a lot of LilyPond input files,
2831 all generated output from LilyPond, @TeX{} and metafont will clutter
2832 your working directory.  LilyPond comes with a one-size-fits-all
2833 pre-cooked makefile that helps you manage producing output.  It will
2834 produce all output in the directory @file{out} , generate and track
2835 dependencies. Also, it helps in preparing your submission to @ref{Mutopia
2836 project}.
2837
2838 @file{make/ly.make}
2839 @example
2840 mkdir my-project
2841 cd my-project
2842 cp /usr/share/lilypond/make/ly.make GNUmakefile
2843 cp /usr/share/doc/lilypond/examples/input/tutorial/minuet.ly .
2844 make minuet
2845 [..]
2846 Generated out/minuet.ps for target minuet.
2847 @end example
2848
2849 Type @samp{make help} to see possible targets.
2850
2851 [TODO]
2852 @file{/usr/share/lilypond/doc/lilypond/examples/input/mutopia-header.ly}
2853
2854
2855
2856
2857
2858 [TODO: rewrite completely.]
2859
2860 @menu
2861 * Songs with additional verses::  
2862 @end menu
2863
2864 @end ignore
2865