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