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