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