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