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