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