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