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