]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
* lily/key-performer.cc (create_audio_elements): always use major
[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 lead sheet::                
22 * Listening to output::         
23 * More movements ::             Joining separate pieces of music
24 * Single staff polyphony  ::    
25 * Piano music::                 
26 * Organising larger pieces::    
27 * Fine tuning a piece::         
28 * An orchestral score::         Conductor's score and individual parts
29 * Integrating text and music::  Integrating text and music
30 @end menu
31
32 Operating is done through text files: To print a piece of music, you
33 enter the music in a file.  When LilyPond is run (normally using the
34 program @code{ly2dvi}) on that file, another file containing formatted
35 sheet music, is produced. That file may be printed or viewed.
36
37 This tutorial starts with a small introduction to the LilyPond music
38 language.  After this first contact, we will show which commands to
39 run to produce printed output, so you should then be able to create
40 your first sheets of music.  The tutorial continues with more and more
41 complex examples.
42
43
44 @node First steps
45 @section First steps
46
47 We start off by showing how very simple music is entered in LilyPond:
48 you get a note simply by typing its @htmlref{note name}, from @samp{a}
49 through @samp{g}.  So if you enter
50
51 @example
52 c d e f g a b
53 @end example
54
55 @noindent
56 then the result looks like this:
57
58 @c ?
59 @c \transpose c c' { c d e f g a b }
60 @c @lily pond[notime]
61 @c \property Score.timing = ##f
62 @lilypond[notime, relative=2]
63 c d e f g a b
64 @end lilypond
65
66 We will continue with this format: First we show a snippet of input,
67 then the resulting output.
68
69 The length of a note is specified by adding a number, @samp{1} for a
70 @rglos{whole note}, @samp{2} for a @rglos{half note}, and so on:
71
72 @example
73 a1 a2 a4 a16 a32
74 @end example
75
76 @lilypond[notime]
77 \property Score.timing = ##f
78 \property Staff.autoBeaming = ##f
79 \transpose c c' { a1 a2 a4 a16 a32 s16_" " }
80 @end lilypond
81
82 If you do not specify a @rglos{duration}, the previous one is used: 
83
84 @example
85 a4 a a2 a
86 @end example
87
88 @lilypond[notime]
89 \property Score.timing = ##f
90 \transpose c c' { a a a2 a s16_" " }
91 @end lilypond
92
93 A @rglos{sharp} (@texisharp{}) is made by adding @samp{is}, a
94 @rglos{flat} (@texiflat{}) by adding @samp{es}.  As you might expect,
95 a @rglos{double sharp} or @rglos{double flat} is made by adding
96 @samp{isis} or @samp{eses}:@footnote{This syntax derived from note
97 naming conventions in Nordic and Germanic languages, like German and
98 Dutch}
99
100 @example
101 cis1 ees fisis aeses
102 @end example
103
104 @lilypond[notime]
105 \property Score.timing = ##f
106 \transpose c c' { cis1 ees fisis aeses s16_" " }
107 @end lilypond
108
109 Add a dot @samp{.} after the duration to get a @rglos{dotted note}:
110
111 @example
112 a2. a4 a8. a16
113 @end example
114
115 @lilypond[notime]
116 \property Score.timing = ##f
117 \transpose c c' { a2. a4 a8. a16 s16_" " }
118 @end lilypond
119
120 Entering pitches and durations is fully explained in @ref{Pitches} and
121 @ref{Durations}.
122
123
124 The @rglos{meter} (or @rglos{time signature}) can be set with the
125 @code{\time} command:
126
127 @example
128 \time 3/4
129 \time 6/8
130 \time 4/4
131 @end example
132
133 @c a clef here may lead to confusion
134 @lilypond
135 \property Staff.Clef \set #'transparent = ##t 
136 \time 3/4
137 s4_" "
138 \time 6/8
139 s4_" "
140 \time 4/4
141 s16_" "
142 @end lilypond
143
144 Time signatures and other timing commands are described in @ref{Time
145 signature}.
146
147
148 The @rglos{clef} can be set using the @code{\clef} command:
149
150 @c what is more common name treble or violin?
151 @c in Dutch, its violin.
152 @c in English its definitely treble.
153 @example
154 \clef treble
155 \clef bass
156 \clef alto
157 \clef tenor
158 @end example
159
160 @lilypond[notime]
161 \property Score.timing = ##f
162 \clef violin
163 s4_" "
164 \clef bass
165 s4_" "
166 \clef alto
167 s4_" "
168 \clef tenor
169 s16_" "
170 @end lilypond
171
172 Clefs are fully explained in @ref{Clef}.
173
174
175 When you enter these commands in a file, you must to enclose them in
176 @code{\notes @{@dots{}@}}.  This lets LilyPond know that music (as
177 opposed to @rglos{lyrics}) follows:
178
179 @example
180 \notes @{
181   \time 3/4
182   \clef bass
183   c2 e4 g2.
184   f4 e d c2.
185 @}
186 @end example
187 Now the piece of music is almost ready to be printed.  The final step is to
188 combine the music with a printing command.
189
190 The printing command is the so-called @code{\paper} block.  Later on
191 you will see that the @code{\paper} block is used to customize
192 printing specifics.  The music and the @code{\paper} block are combined by
193 enclosing them in @code{\score @{ ... @}}.  This is what a full source file looks like:
194
195 @example
196 \score @{
197   \notes @{
198     \time 3/4
199     \clef bass
200     c2 e4 g2.
201     f4 e d c2.
202   @}
203   \paper @{ @}
204 @}
205 @end example
206
207 @lilypond[noindent]
208 \score {
209   \notes {
210      \time 3/4
211      \clef bass
212      c2 e4 g2.
213      f4 e d c2.
214   }
215   \paper {
216     linewidth = 55 * \staffspace
217   }
218 }
219 @end lilypond
220
221
222 @node Running LilyPond
223 @section Running LilyPond
224
225 In the last section we explained what kind of things you could enter
226 in a LilyPond file.  In this section we explain what commands to run
227 and how to view or print the output.  If you have not used LilyPond
228 before, want to test your setup, or want to run an example file
229 yourself, read this section.  The instructions that follow are for
230 Unix-like systems.  Some additional instructions for MS Windows are given
231 at the end of this section.
232
233 Begin by opening a terminal window and starting a text editor.
234 For example, you could open an xterm and execute @code{joe}.  In your
235 text editor, enter the following input and save the file as
236 @file{test.ly}:
237
238 @quotation
239 @example
240 \score @{
241   \notes @{ c'4 e' g' @}
242 @} 
243 @end example
244 @end quotation
245
246 @cindex ly2dvi
247
248 @c now this is weird, running ly2dvi to run LilyPond
249 @c (therefore name change proposal) 
250
251 LilyPond is the program that computes the sheet music. All other
252 things, such as adding titles, page breaking and other page layout,
253 are done by a small wrapper program called
254 @code{ly2dvi}. @code{ly2dvi} calls LilyPond to render the music, and
255 then adds the titling and page layout instructions.  To process
256 @file{test.ly} with @code{ly2dvi}, proceed as follows:
257
258 @quotation
259 @example
260 ly2dvi -p test.ly
261 @end example
262 @end quotation
263
264 You will see the following on your screen:
265
266 @quotation
267 @example
268 GNU LilyPond 1.7.16
269 Now processing: `/home/fred/ly/test.ly'
270 Parsing...
271 Interpreting music...[1]
272  @emph{ ... more interesting stuff ... }
273 PDF output to `test.pdf'...
274 DVI output to `test.dvi'...
275 @end example
276 @end quotation
277 @cindex DVI file
278 @cindex Viewing music
279 @cindex xdvi
280
281 The results of the ly2dvi run are two files, @file{test.dvi} and
282 @file{test.pdf}.  The PDF file (@file{test.pdf}) is the one you can
283 print or view.  For example, viewing PDF can be done with ghostview.
284 If a version of ghostview is installed on your system, one of these
285 commands will produce a window with some music notation on your
286 screen:
287 @c eeek
288 @quotation
289 @example
290   gv test.pdf
291   ghostview test.pdf
292   ggv test.pdf
293   kghostview test.pdf
294   xpdf test.pdf
295   gpdf test.pdf
296 @end example
297 @end quotation
298 If the music on your screen looks good, you can print it by clicking
299 File/Print inside ghostview.
300
301 The DVI file (@file{test.dvi}) contains the same sheet music in a
302 different format. DVI files are more easily processed by the computer,
303 so viewing them usually is quicker.  You can run @code{xdvi test.dvi}
304 @c KDVI doesn't grok the PS specials.
305 @c or
306 @c @code{kdvi test.dvi}
307 @c
308 to view the DVI file. In Xdvi, the mouse buttons
309 activate magnifying glasses.  Unfortunately, variable symbols (such as
310 beams and slurs) are not displayed in the magnifying glasses.
311
312
313 @cindex Ghostscript
314 @cindex @code{lpr}
315 @cindex Printing output
316 @cindex PostScript
317 @cindex PDF
318
319 If you are familiar with @TeX{}, be warned: do not use other DVI
320 drivers like @code{dvilj}.  LilyPond DVI use embedded PostScript code
321 and will not render correctly with other DVI drivers besides
322 @code{dvips}.
323
324 @cindex dvips
325 @cindex dvilj
326 @cindex DVI driver
327
328
329 Various commands for formatting and printing music are detailed in
330 @ref{Invoking LilyPond}.
331
332
333 @unnumberedsubsec Windows users
334
335 Windows users can start the terminal by clicking on the LilyPond or
336 Cygwin icon.  Any text editor (such as NotePad, Emacs or Vim) may be
337 used to edit the LilyPond file.  When Cygwin's @code{XFree86} X11
338 window system is installed along with @code{tetex-x11} and
339 @code{ghostscript-x11} packages, then the @code{dvi} output may be
340 viewed with @code{xdvi test.dvi} as described above.  If you have
341 installed a PostScript/PDF viewer, such as @code{GSView} from
342 @uref{http://www.cs.wisc.edu/~ghost}, viewing the PDF file can be done
343 with:
344 @quotation
345 @example
346 @code{gsview32 test.pdf}
347 @end example
348 @end quotation
349 Printing may be done by executing
350 @quotation
351 @example
352 @code{gsview32 /s test.pdf}
353 @end example
354 @end quotation
355
356
357 @node More basics
358 @section More basics 
359
360 We continue with the introduction of more musical constructs.  Normal
361 rests are entered just like notes with the name ``@code{r}'':
362
363 @quotation
364 @example
365 r2 r4 r8 r16
366 @end example
367
368 @lilypond[fragment]
369 \property Score.timing = ##f
370 \property Staff.Clef = \turnOff
371 \property Staff.TimeSignature = \turnOff
372 r2 r4 r8 r16
373 s16_" "
374 @end lilypond
375 @end quotation
376 @separate
377
378 Rests are described in full detail in @ref{Rests}. 
379
380
381 @c Tim wants to move this quotes example just before the: quotes-do not-work
382 @c score, but we'd need to remove quotes from the other two (key and
383 @c tie) examples...
384
385 @c better to have this just before the `octaves are bad' snipped
386 @c but we'd need to remove the ', from \key and tie 
387 To raise a note by an octave, add a high quote @code{'} (apostrophe) to
388 the note name, to lower a note one octave, add a ``low quote'' @code{,}
389 (a comma).  Middle C is @code{c'}:
390
391 @quotation
392 @example
393 c'4 c'' c''' \clef bass c c,
394 @end example
395
396 @lilypond[fragment]
397 \property Score.timing = ##f
398 \property Staff.TimeSignature = \turnOff
399 c'4 c'' c''' \clef bass c c,
400 @end lilypond
401 @end quotation
402 @separate
403
404 A tie is created by adding a tilde ``@code{~}'' to the first note
405 being tied.
406 @quotation
407 @lilypond[fragment,verbatim]
408 g'4-~ g' a'2-~ a'4
409 @end lilypond
410 @end quotation
411 @separate
412 A tie is different from a slur. A tie simply makes the first note
413 sound longer, and can only be used on pairs of notes with the same
414 pitch. Slurs indicate the articulations of notes, and can be used on
415 larger groups of notes. Slurs and ties are also nested in practice:
416 @lilypond[fragment, relative=1]
417 c2-~-( c8 fis fis4 ~ fis2 g2-)
418 @end lilypond
419
420 The notation manual discusses ties in @ref{Ties}.
421
422 The key signature is set with the command ``@code{\key}'', followed by
423 a pitch and  @code{\major} or @code{\minor}:
424 @quotation
425 @example
426 \key d \major
427 g'1
428 \key c \minor
429 g'
430 @end example
431
432 @lilypond[fragment]
433 \property Staff.TimeSignature = \turnOff
434 \key d \major
435 g'1
436 \key c \minor
437 g'
438 @end lilypond
439 @end quotation
440
441
442
443 @c bit on the long/complex/scary taste
444 @c cheating a bit: two lines makes for a friendlier look
445 This example shows notes, ties, octave marks, and rests in action.
446
447 @quotation
448 @example
449 \score @{
450   \notes @{
451     \time 4/4
452     \key d \minor
453     \clef violin
454     r4 r8 d''8 cis''4 e''
455     d''8 a'4.-~ a' b'8
456     cis''4 cis''8 cis'' bis'4 d''8 cis''-~
457     cis''2 r2
458   @}
459   \paper @{ @}
460 @}
461 @end example
462
463 @lilypond
464 \score {
465   \notes {
466     \time 4/4
467     \clef violin
468     \key d \minor
469     r4 r8 d''8 cis''4 e''
470     d''8 a'4.-~ a' b'8
471     cis''4 cis''8 cis'' bis'4 d''8 cis''-~
472     cis''2 r2
473   }
474   \paper { linewidth = 50*\staffspace }
475 }
476 @end lilypond
477 @end quotation
478
479 @c accidentals...
480 There are some interesting points to note in this example.
481 Accidentals (sharps and flats) do not have to be marked explicitly:
482 you just enter the note name, and an accidental is printed
483 automatically, only when necessary.  Bar lines and beams are drawn
484 automatically.  Line breaks are calculated automatically; it does not
485 matter where the lines breaks are in the source file. Finally, the
486 order of time, key and clef changes is not relevant: in the printout,
487 these are ordered using standard notation conventions.
488
489 The example also indicates that a piece of music written in a high
490 register needs lots of quotes.  This makes the input less readable,
491 and is also a potential source of errors.
492
493 The solution is to use ``relative octave'' mode.  In practice, this is
494 the most convenient way to copy existing music.  To use relative mode,
495 add @code{\relative} before the piece of music.  You must also give a
496 note from which relative starts, in this case @code{c''}.  If you do
497 not use octavation quotes (i.e. do not add ' or , after a note),
498 relative mode chooses the note that is closest to the previous one.
499 @c do not use commas or quotes in this sentence
500 For example: @code{c f} goes up; @code{c g} goes down:
501
502 @quotation
503 @example
504 \relative c'' @{
505   c f c g c
506 @}
507 @end example
508
509 @lilypond[fragment]
510 \property Score.timing = ##f
511 \property Staff.TimeSignature = \turnOff
512 \relative c'' {
513   c f c g c
514 }
515 @end lilypond
516 @end quotation
517 @separate
518
519
520 Since most music has small intervals, in relative mode pieces can be
521 written almost without using octavation quotes.
522
523 @c needed better, maybe even redundant explanation
524 @c   added another example below.
525 @c grappig: Pa vond het heel logies, en slim toen-i eenmaal begreep.
526 @c in eerste instantie drong het `relative' niet door zonder extra uitleg.
527 Larger intervals are made by adding octavation quotes.  Quotes or
528 commas do not determine the absolute height of a note; the height of a
529 note is relative to the previous one.
530 @c do not use commas or quotes in this sentence
531 For example: @code{c f,} goes down; @code{f, f} are both the same;
532 @code{c' c} are the same; and @code{c g'} goes up:
533
534 @quotation
535 @example
536 \relative c'' @{
537   c f, f c' c g' c,
538 @}
539 @end example
540
541 @lilypond[fragment]
542 \property Score.timing = ##f
543 \property Staff.TimeSignature = \turnOff
544 \relative c'' {
545   c f, f c' c g' c,
546 }
547 @end lilypond
548 @end quotation
549 @separate
550
551
552 Here is an example of the difference between relative mode and
553 ``normal'' (non-relative) mode:
554
555 @quotation
556 @example
557 \relative a @{
558 \clef bass
559   a d a e d c' d'
560 @}
561 @end example
562
563 @lilypond[fragment]
564 \property Score.timing = ##f
565 \property Staff.TimeSignature = \turnOff
566 \relative a {
567 \clef bass
568   a d a e d c' d'
569 }
570 @end lilypond
571 @end quotation
572 @separate
573
574 @quotation
575 @example
576 \clef bass
577   a d a e d c' d'
578 @end example
579
580 @lilypond[fragment]
581 \property Score.timing = ##f
582 \property Staff.TimeSignature = \turnOff
583 \clef bass
584   a d a e d c' d'
585 @end lilypond
586 @end quotation
587 @separate
588
589 A slur is drawn across many notes, and indicates bound articulation
590 (legato).  The starting note and ending note are marked with a
591 ``@code{(}'' and a ``@code{)}'' respectively:
592
593 @quotation
594 @lilypond[fragment,relative 1, verbatim]
595 d4-( c16-)-( cis d e c cis d e-)-( d4-)
596 @end lilypond
597 @end quotation
598 @separate
599
600 If you need two slurs at the same time (one for articulation, one for
601 phrasing), you can also make a phrasing slur with @code{\(} and
602 @code{\)}.
603
604 @c lousy example
605 @c ? --hwn
606 @c fragment of 1st hrn in Adams' The Chairman Dances, with creative
607 @c chromatic thing pasted in front.  (admittedly the original does not
608 @c have a phrasing slur. The problem is that we do not want the slur
609 @c and the Phrasing slur to collide. We are trying to make a good
610 @c impression here.
611
612 @quotation
613 @lilypond[fragment,relative 1, verbatim]
614 a8-(-\( ais b  c-) cis2 b'2 a4 cis,  c-\)
615 @end lilypond
616 @end quotation
617 @separate
618
619 Beams are drawn automatically, but if you do not like the choices, you
620 can enter beams by hand. Mark the first note to be beamed with
621 @code{[} and the last one with @code{]}:
622 @quotation
623 @lilypond[fragment,relative 1, verbatim]
624 a8-[ ais-] d-[ es r d-]
625 @end lilypond
626 @end quotation
627 @separate
628
629 To print more than one staff, each piece of music that makes up a staff
630 is marked by adding @code{\context Staff} before it.  These
631 @code{Staff}'s are then grouped inside @code{<} and @code{>}, as is
632 demonstrated here:
633
634 @quotation
635 @lilypond[fragment,verbatim]
636 <
637   \context Staff = staffA { \clef violin c'' }
638   \context Staff = staffB { \clef bass c }
639 >
640 @end lilypond
641 @end quotation
642
643 In this example, @code{staffA} and @code{staffB} are names that are
644 given to the staves.  It does not matter what names you give, as long
645 as each staff has a different name. If you give them the same name,
646 they are assumed to belong on the same staff, and will be printed like
647 that.
648
649 @separate
650
651 We can now typeset a melody with two staves:
652
653 @quotation
654 @lilypond[verbatim,singleline]
655 \score {
656   \notes 
657   < \context Staff = staffA {
658       \time 3/4
659       \clef violin
660       \relative c'' {
661         e2-( d4 c2 b4 a8-[ a-]
662         b-[ b-] g-[ g-] a2.-) }  
663     }
664     \context Staff = staffB {
665        \clef bass
666        c2 e4  g2.
667        f4 e d c2.
668     }
669   >
670   \paper {} 
671 }
672 @end lilypond
673 @end quotation
674
675 Notice that the time signature is specified in one melody staff only
676 (the top staff), but is printed on both.  LilyPond knows that the time
677 signature should be the same for all staves.
678
679 @separate
680
681 Common accents can be added to a note using @code{-.}, @code{--}, @code{->}:
682 @quotation
683 @lilypond[verbatim,relative 1]
684 c-. c-- c->
685 @end lilypond
686 @end quotation
687 @separate
688
689 Similarly, fingering indications can be added to a note using @code{-}
690 and the digit to be printed.
691 @lilypond[verbatim,relative 1]
692   c-3 e-5 b-2 a-1
693 @end lilypond
694
695
696   
697
698
699 Dynamic signs are made by adding the markings to the note:
700 @quotation
701 @lilypond[verbatim,relative 1]
702 c-\ff c-\mf
703 @end lilypond
704 @end quotation
705 @separate
706
707 Crescendi and decrescendi are started with the commands @code{\<} and
708 @code{\>}. The command @code{\!} finishes a crescendo on the note it
709 is attached to.
710 @quotation
711 @lilypond[verbatim,relative 1]
712 c2-\<  c2-\!-\ff  c2-\>  c2-\!
713 @end lilypond
714 @end quotation
715 @separate
716
717 Chords can be made by
718 surrounding pitches with @code{<<} and @code{>}>:
719 @quotation
720 @lilypond[relative 0, fragment,verbatim]
721 r4 <<c e g>>4 <<c f a>>8
722 @end lilypond
723 @end quotation
724 @separate
725
726
727 You can combine beams and ties with chords.  Beam and tie markings
728 must be placed outside the chord markers:
729 @quotation
730 @lilypond[relative 0, fragment,verbatim]
731 r4 <<c e g>>8-[ <<c f a>>-]-~ <<c f a>>
732 @end lilypond
733 @end quotation
734
735 @quotation
736 @example
737 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
738 @end example
739 @lilypond[relative 0, fragment]
740 \slurUp
741 r4 <<c e g>>8-\>-( <<c e g>> <<c e g>>  <<c f a>>8-\!-)
742 @end lilypond
743 @end quotation
744 @separate
745
746
747 A pickup (or upstep) is entered with the keyword @code{\partial}. It
748 is followed by a duration: @code{\partial 4} is a quarter note upstep.
749 @lilypond[relative 1,verbatim,fragment]
750   \partial 8
751   f8 c2 d e
752 @end lilypond
753
754 Tuplets are made with the @code{\times} keyword.  It takes two
755 arguments: a fraction and a piece of music.  The duration of the piece
756 of music is multiplied by the fraction.  Triplets make notes occupy
757 2/3 of their notated duration, so for a triplet, the fraction is 2/3.
758 @c
759 @lilypond[relative 0,verbatim,fragment]
760   \times 2/3 { f8 g a }
761   \times 2/3 { c r c }
762 @end lilypond 
763
764
765
766
767 Comments are pieces of the input that are ignored.  There are two
768 types of comments. A line comments are introduced by @code{%}: after
769 that, the rest of that line is ignored.  Block comments span larger
770 sections of input.  Anything that is enclosed in @code{%@{} and
771 @code{%@}} is ignored too. The following fragment shows possible uses
772 for comments.
773
774 @example
775   % notes for twinkle twinkle follow:
776   c4 c   g' g  a a
777   
778   %@{
779   
780     This line, and the notes below
781     are ignored, since they are in a
782     block comment.
783
784     g g f f e e d d c2 
785   %@}
786 @end example
787
788
789
790
791
792 @node Printing lyrics
793 @section Printing lyrics
794 @cindex lyrics
795
796 Lyrics are entered by separating each syllable with a space, and
797 surrounding them with @code{\lyrics @{ @dots{} @}}, for example
798 @example
799   \lyrics @{ I want to break free @}
800 @end example
801
802 Like notes, lyrics are also a form of music, but they must not be
803 printed on a staff, which is the default way to print music. To print
804 them as lyrics, they must be marked with @code{ \context Lyrics}:
805 @example
806   \context Lyrics  \lyrics @{ I want to break free @}
807 @end example
808 The melody for this song is as follows
809 @lilypond[fragment,relative=1]
810    \partial 8
811      c8
812    \times 2/3 {  f4 g g } \times 2/3 { g4-( a2-) }
813 @end lilypond
814
815 The lyrics can be set to these notes, combining both with the
816 @code{\addlyrics} keyword:
817 @example
818  \addlyrics
819     \notes @{ @dots{} @}
820     \context Lyrics @dots{}
821 @end example
822
823 The final result is 
824 @lilypond[singleline,verbatim]
825 \score  {
826  \notes {
827   \addlyrics
828    \relative c' {
829      \partial 8
830      c8
831      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
832    }
833    \context Lyrics  \lyrics { I want to break free }
834  }
835  \paper{ }
836 }
837 @end lilypond
838
839 This melody ends on a @rglos{melisma}, a single syllable (``free'')
840 sung to more than one note. This is indicated with a @emph{extender
841 line}. It is entered as two  underscores, i.e.,
842 @example
843   \lyrics @{ I want to break free __ @}
844 @end example 
845 @lilypond[singleline]
846 \score  {
847  \notes {
848   \addlyrics
849    \relative c' {
850    \partial 8
851      c8
852      \times 2/3 { f g g } \times 2/3 { g4-( a2-) }
853    }
854    \context Lyrics  \lyrics { I want to break free __ }
855  }
856  \paper{ }
857 }
858 @end lilypond
859
860 Similarly, hyphens between words can be entered as two dashes,
861 resulting in a centered hyphen between two syllables.
862 @example
863   Twin -- kle twin -- kle
864 @end example
865 @lilypond[singleline]
866 \score {
867   \addlyrics \notes \relative f' { \time 2/4
868     f4 f c' c' }
869     \context Lyrics \lyrics { Twin -- kle twin -- kle
870  }}
871 @end lilypond
872
873 More options, like putting multiple lines of lyrics below a melody are
874 discussed in @ref{Vocal music}.
875
876
877 @node A lead sheet
878 @section A lead sheet
879
880 In popular music, it is common to denote accompaniment as chord-names.
881 Using them in LilyPond has two parts, just like lyrics: entering the
882 chords (with @code{\chords}), and printing them (with @code{\context
883 ChordNames}).
884
885 Chord names are entered by starting chords mode (with @code{\chords}).
886 In chords mode, you can enter chords with a letter (indicating the
887 root of the chord), and a durations following that.
888 @c
889 @lilypond[verbatim]
890   \chords { c2 f4. g8 } 
891 @end lilypond
892 The result of @code{\chords} is a list of chords, and is  equivalent
893 to entering chords with @code{<<@dots{}>>}.
894
895 Other chords can be created by adding modifiers, after a colon.  The
896 following example shows a few common modifiers
897 @c
898 @lilypond[verbatim]
899   \chords { c2 f4:m g4:maj7 gis1:dim7 }
900 @end lilypond
901
902 Printing chords is done by adding @code{\context ChordNames}
903 before the chords thus entered:
904 @c
905 @lilypond[verbatim]
906  \context ChordNames \chords \chords { c2 f4.:m g4.:maj7 gis8:dim7 }
907 @end lilypond
908
909 A complete list of modifiers, and other options for layout are in the
910 reference manual section @ref{Chords}.
911
912 @cindex lead sheet 
913 When put together,  chord names, lyrics and a melody form
914 a lead sheet, for example:
915 @lilypond[singleline,verbatim]
916 \score  {
917   < 
918    \context ChordNames \chords { r8 c2:sus4 f } 
919    \addlyrics
920     \notes \relative c' {
921      \partial 8
922      c8
923      \times 2/3 { f g g } \times 2/3 { g4-( a2-) } }
924    \context Lyrics  \lyrics { I want to break free __ }
925   >
926  \paper{ }
927 }
928 @end lilypond
929
930
931 @node Listening to output
932 @section Listening to output
933
934 MIDI (Musical Instrument Digital Interface) is a standard for
935 connecting and recording digital instruments.  A MIDI file is like a
936 tape recording of a MIDI instrument. The @code{\midi} block makes the
937 music go to a MIDI file, so you can listen to the music you entered.
938 It is great for checking the music: octaves that are off, or
939 accidentals that were mistyped, stand out very much when listening to
940 the musical transcription.
941
942 @code{\midi} can be used in similarly to @code{\paper @{ @}}, for
943 example
944 @example 
945 \score @{
946     @var{..music..}
947     \midi  @{ \tempo 4=72@}
948     \paper  @{ @}
949 @}
950 @end example 
951
952 Here, the tempo is specified using the @code{\tempo} command.  In this
953 case the tempo of quarter notes is set to 72 beats per minute.
954
955
956 @node More movements 
957 @section More movements
958
959 The program @code{lilypond} only produces sheet music.  Titles,
960 subtitles, and the composer's name are created by a separate program,
961 called use @code{ly2dvi}.  @code{ly2dvi} creates the titles, then
962 calls @code{lilypond} to format the sheet music.  In this section, we
963 show you how to create titles like this:
964
965 @center @strong{Two miniatures}
966 @flushright
967 F. Bar Baz
968
969 Opus 1.
970 @end flushright
971 @flushleft
972 @var{Up}
973 @end flushleft
974 @lilypond
975   \score {
976     \notes { c'4 d'4 }
977     \paper { raggedright = ##t }
978   }
979 @end lilypond
980 @flushright
981 Opus 2.
982 @end flushright
983 @flushleft
984 @var{Down}
985 @end flushleft
986 @lilypond
987   \score {
988     \notes { d'4 c'4 }
989     \paper { linewidth = -1.0 }
990   }
991 @end lilypond
992
993 For example, consider the following file (@file{miniatures.ly}) 
994
995 @example
996 \header @{
997   title = "Two miniatures"
998   composer = "F. Bar Baz" 
999   tagline = "small is beautiful" @}
1000
1001 \score @{
1002     \notes @{ c'4 d'4 @}
1003     \header @{
1004         opus = "Opus 1."
1005         piece = "Up" @}
1006 @}
1007 \score @{
1008     \notes @{ d'4 c'4 @}
1009     \header @{
1010         opus = "Opus 2."
1011         piece = "Down" @}
1012 @}
1013 @end example
1014
1015
1016 The information for the global titling is in a so-called header block.
1017 The information in this block is not used by LilyPond, but it is
1018 passed into @code{ly2dvi}, which uses this information to print titles
1019 above the music.
1020 @cindex assignments
1021 @cindex identifier assignment
1022 the @code{\header} block contains assignments.  In each assignment, a
1023 variable is set to a value. The header block for this file looks like
1024 this
1025 @cindex @code{\header}
1026 @example 
1027   \header @{
1028     title = "Two miniatures" 
1029     composer = "F. Bar Baz"
1030     tagline = "small is beautiful"
1031   @}
1032 @end example
1033
1034 When you process a file with ly2dvi, a signature line is printed at
1035 the bottom of the last page.  Many people find the default (``Lily was
1036 here'' with a version number) too droll.  If that is the case, you can
1037 change @code{tagline} in the @code{\header}, as shown above.
1038
1039 @cindex Lily was here
1040 @cindex signature line
1041 @cindex tag line
1042
1043
1044 @separate
1045 @example
1046     \header @{
1047 @end example
1048
1049 The @code{\header} is normally at the top of the file, where it sets
1050 values for the rest of the file.  If you want to typeset different
1051 pieces from one file (for example, if there are multiple movements, or
1052 if you are making an exercise book), you can put different
1053 @code{\score} blocks into the input file.  @code{ly2dvi} will assemble
1054 all LilyPond output files into a one document.  The contents of
1055 @code{\header} blocks specified within each score is used for the
1056 title of that movement.
1057 @separate
1058 @example
1059         opus = "Opus 1."
1060         piece = "Up" @}
1061 @end example
1062 For example, the Opus number is put at the right, and the "piece" string
1063 will be at the left.
1064
1065
1066 @node Single staff polyphony  
1067 @section Single staff polyphony
1068
1069 When different melodic lines are combined on a single staff, these are
1070 printed as polyphonic voices: each voice has its own stems, slurs
1071 and beams, and the top voice has the stems up, while the bottom voice
1072 has stems down.
1073
1074 Entering such parts is done by entering each voice as a sequence (with
1075 @code{@{ .. @}}), and combing those simultaneously, separating the
1076 voices with @code{\\}:
1077
1078 @lilypond[verbatim,relative]
1079   < { a4 g2 f4-~ f4 } \\
1080     { r4 g4 f2 f4 } >
1081 @end lilypond
1082  
1083 More features of polyphonic typesetting are in the notation manual,
1084 @ref{Polyphony}.
1085
1086 @node Piano staffs
1087 @section Piano staffs
1088
1089 @cindex staff switch, manual
1090 @cindex cross staff voice, manual
1091 @cindex @code{\translator}
1092
1093
1094
1095
1096 @node Organising larger pieces
1097 @section Organising larger pieces
1098
1099 TODO: discuss identifiers, p&c, .
1100
1101 @separate
1102 @example 
1103 \version "1.5.72"
1104 @end example 
1105 Lilypond and its language are still under development, and
1106 occasionally details of the syntax are changed.  The @code{version}
1107 fragment indicates which LilyPond version the input file was written
1108 for.  When you compile this file, the version number will be
1109 checked. When the file is too old, a warning is issued.  The version
1110 number is also used by the @code{convert-ly} program (See
1111 @ref{Invoking convert-ly}), which updates the file to the latest
1112 version automatically.
1113
1114
1115 @separate
1116 @example 
1117 s1 s2. r4 
1118 @end example 
1119 @code{s} is a spacer rest.  It does not print anything, but it does have
1120 the duration of a rest. It is useful for filling up voices that
1121 temporarily do not play. In this case, the viola does not come until one
1122 and a half measure later. 
1123
1124 @separate
1125 @example 
1126 \grace <<e g>>-( <<d f>>4-) <<c e>>2 
1127 @end example
1128 @cindex @code{\grace}
1129 @cindex ornaments
1130 @cindex grace notes
1131 @code{\grace} introduces grace notes.  It takes one argument, in this
1132 case a chord. A slur is introduced starting from the @code{\grace}
1133 ending on the following chord.
1134
1135 @separate
1136 @example 
1137 \times 2/3 
1138 @end example
1139 @cindex tuplet
1140 @cindex triplets
1141
1142 @separate
1143 @example 
1144 @{ <<d f>>8 <<e g>> <<f a>> @} 
1145 @end example 
1146 The piece of music to be `tripletted' is sequential music containing
1147 three chords.
1148
1149
1150 The bass has a little hoom-pah melody to demonstrate parts switching
1151 between staves.  Since it is repetitive, we use repeats:
1152 @separate
1153 @example 
1154 hoomPah  =  \repeat unfold 8
1155 @end example
1156 @cindex unfolded @code{\repeat}
1157 The unfolded repeat prints the notes in its argument as if they were
1158 written out in full eight times.
1159 @separate
1160
1161 @node Fine tuning a piece
1162 @section  Fine tuning a piece
1163
1164 In this section we show some ways to fine tune the final output of a
1165 piece.  We do so using a single measure of a moderately complex piano
1166 piece: a Brahms intermezzo (opus 119, no. 1).  Both fragments (the
1167 tuned and the untuned versions) are in @file{input/tutorial/}.
1168
1169 The code for the untuned example shows us some new things.
1170
1171 @lilypondfile[verbatim]{brahms-original.ly}
1172
1173
1174 @cindex dynamics
1175 @cindex loudness
1176 @cindex forte
1177 @cindex crescendo
1178
1179
1180
1181
1182 Now that we have the basic piece of music entered, we want to fine
1183 tune it so that we get something that resembles the original printed
1184 edition by Schott/Universal Edition:
1185
1186 @lilypondfile{brahms-tweaked.ly}
1187
1188 @cindex tuning graphical objects
1189
1190 Fine tuning involves overriding the defaults of the printing system.
1191 We do this by setting variables which control how Lilypond prints
1192 symbols.  Printed symbols are called graphical objects (often
1193 abbreviated to @emph{grob}). Each object is described by a bunch of
1194 settings.  Every setting is a variable: it has a name and a value
1195 which you can change.  These values determine the fonts, offsets,
1196 sub-routines to be called on the object, etc.  The initial values of
1197 these settings are set in the Scheme file
1198 @file{scm/grob-description.scm}.
1199
1200 @cindex slur attachments
1201
1202 We start with the slur in the upper part, running from F sharp to A.  In
1203 the printed edition, this slur runs from stem to stem; in our version,
1204 the slur begins at the note head of the F sharp.  The following property
1205 setting forces all slurs to run from stem to stem (not from or to note
1206 heads!).
1207
1208 @example
1209   \property Voice.Slur \set #'attachment = #'(stem . stem)
1210 @end example
1211
1212 More precisely, this command modifies the definition of the @code{Slur}
1213 object in the current @code{Voice}.  The variable @code{attachment} is
1214 set to the pair of symbols @code{'(stem . stem)}. 
1215
1216 @cindex internal documentation
1217 @cindex finding graphical objects
1218 @cindex graphical object descriptions 
1219
1220 This command fixes one particular problem with a slur. The rest of
1221 this section explains how to figure out which properties to tune for
1222 your own scores. To discover this, you must have a copy of the
1223 internals document. This is a set of HTML pages which should be
1224 included if you installed a binary distribution.  [TODO: revise for
1225 new site.]  These HTML pages are also available on the web: go to the
1226 LilyPond website, click ``Documentation: Index'' on the side bar, look
1227 in the ``Information for uses'' section, and click on ``Documentation
1228 of internals''.
1229
1230 You might want to bookmark either the HTML files on your disk, or the
1231 one on the web (the HTML on your hard drive will load much faster than
1232 the ones on the web!).  One word of caution: the internals
1233 documentation is generated from the definitions that the program uses.
1234 Hence, the internals documentation is strongly tied to the version you
1235 use.  Before you proceed, make sure that the program and documentation
1236 have matching version numbers.
1237
1238 @c  TODO: the quote is incorrect, although that shouldn't be a big
1239 @c    problem for the reader.
1240 Suppose that you wanted to tune the behavior of the slur.  The first
1241 step is to get some general information on slurs in LilyPond.  Turn to
1242 the index, and look up ``slur''. The section on slurs says
1243 @quotation
1244 The grob for this object is @internalsref{Slur}, generally in
1245 @internalsref{Voice} context.
1246 @end quotation
1247
1248 So the graphical object for this object is called @code{Slur}, and
1249 slurs are created in the @code{Voice} context.  If you are reading
1250 this tutorial in the HTML version, then you can simply click Slur,
1251 otherwise, you should look it up the internal documentation: click
1252 ``grob overview'' and select ``slur'' (the list is alphabetical).
1253
1254 Now you get a list of all the properties that the slur object
1255 supports, along with their default values.  Among the properties we
1256 find the @code{attachment} property with its default setting.  
1257 The property documentation explains that the following setting will
1258 produce the desired effect:
1259 @example 
1260  \property Voice.Slur \set #'attachment = #'(stem . stem)
1261 @end example
1262
1263 @c this is a long section, and adding an extra space here helps to
1264 @c break it into smaller subsections and thus is easier to understand.
1265 @separate
1266
1267 Next we want to move the fingering `3'.  In the printed edition it is
1268 not above the stem, but a little lower and slightly left of the stem.
1269 From the user manual we find that the associated graphical object is
1270 called @code{Fingering}, but how do we know if we should use
1271 @code{Voice} or @code{Staff}?  In many cases, @code{Voice} is a safe
1272 bet, but you can also deduce this information from the internals
1273 documentation: if you visit the documentation of @code{Fingering}, you
1274 will notice
1275 @example
1276 Fingering grobs are created by: Fingering_engraver
1277 @end example
1278
1279 Clicking @code{Fingering_engraver} will show you the documentation of
1280 the module responsible for interpreting the fingering instructions and
1281 translating them to a @code{Fingering} object.  Such a module is called
1282 an @emph{engraver}.  The documentation of the @code{Fingering_engraver}
1283 says
1284 @example
1285 Fingering_engraver is part of contexts: Voice and TabVoice
1286 @end example
1287 so tuning the settings for Fingering should be done using either
1288 @example
1289   \property Voice.Fingering \set @dots{}
1290 @end example
1291 or
1292 @example
1293   \property TabVoice.Fingering \set @dots{}
1294 @end example
1295
1296 Since the @code{TabVoice} is only used for tab notation, we see that
1297 the first guess @code{Voice} was indeed correct.
1298
1299 @cindex setting object properties
1300 @cindex @code{extra-offset}
1301
1302 For shifting the fingering, we use the property @code{extra-offset}.
1303 The following command manually adds an offset to the object.  We move
1304 it a little to the left, and 1.8 staff space downwards.
1305 @example
1306  \once \property Voice.Fingering \set #'extra-offset = #'(-0.3 . -1.8) 
1307 @end example   
1308 The @code{extra-offset} is a low-level feature: it moves around
1309 objects in the printout; the formatting engine is completely oblivious
1310 to these offsets.  The unit of these offsets are staff-spaces.  The
1311 first number controls left-right movement; a positive number will move
1312 the object to the right.  The second number controls up-down movement;
1313 a positive number will move it higher.
1314 We only want to offset a single object, so this statement is adorned
1315 with @code{\once}.
1316
1317 @cindex property types
1318 @cindex translator properties
1319 @cindex grob properties
1320 @cindex music properties
1321 @separate
1322
1323 There are three different types of variables in LilyPond, something
1324 which can be confusing at first (and for some people it stays
1325 confusing).  Variables such as @code{extra-offset} and
1326 @code{attachment} are called grob properties.  They are not the same
1327 as translator properties, like @code{autoBeaming}.  Finally, music
1328 expressions are internally stored using properties (so-called music
1329 properties).  You will encounter music properties if you run Scheme
1330 functions on music using @code{\apply}.
1331
1332 The second fingering instruction should be moved up a little to avoid
1333 a collision with the slur.  This could be achieved with
1334 @code{extra-offset}, but in this case, a simpler mechanism also
1335 works.  We insert an empty text between the 5 and the note. The empty
1336 text pushes the fingering instruction away:
1337 @example
1338   a-)^" "^\markup @{ \finger "5" @} 
1339 @end example
1340
1341 A fingering instruction, which would be entered as @code{^5}, is put
1342 as close to the notes as possible, closer than the space entered to
1343 push away the 5. Hence, the 5 is entered as a normal text, with the
1344 formatting of fingering instructions.
1345  
1346 @separate
1347
1348 Normally one would specify all dynamics in the same voice, so that
1349 dynamics (such as @b{f} and @b{p}) will be aligned with hairpins.  But
1350 in this case, we do not want the decrescendo to be aligned with the
1351 piano sign.  We achieve this by putting the dynamic markings in different
1352 voices.  The crescendo should be above the upper staff.  This can be
1353 forced by using the precooked command 
1354 @example
1355   \dynamicsUp
1356 @end example
1357
1358 However, if you do that the decrescendo will be too close to the upper
1359 voice and collide with the stems.  Looking at the manual for dynamics,
1360 we notice that ``Vertical positioning of these symbols is handled by
1361 the @internalsref{DynamicLineSpanner} grob.''.  If we turn to the
1362 documentation of @code{DynamicLineSpanner}, we find that
1363 @code{DynamicLineSpanner} supports several so-called `interfaces'.
1364 This object not only puts objects next to the staff
1365 (@code{side-position-interface}), but it also groups dynamic objects
1366 (@code{axis-group-interface}), is considered a dynamic sign itself
1367 (@code{dynamic-interface}), and is an spanning object
1368 (@code{spanner-interface}).  It also has the standard
1369 @code{grob-interface} with all the variables that come with it.
1370
1371 For the moment we are interested in side positioning:
1372 @quotation
1373  side-position-interface
1374
1375   Position a victim object (this one) next to other objects (the
1376   support).  In this case, the direction signifies where to put the
1377   victim object relative to the support (left or right, up or down?)
1378 @end quotation
1379 Between the object and its support (in this case, the descending
1380 notes), there should be more space.  This space is controlled by
1381 @code{padding}, so we increase it.
1382 @example
1383  \property Voice.DynamicLineSpanner \override #'padding = #5.0
1384 @end example
1385
1386
1387 (TODO: huh? what's this: )
1388
1389 This command resembles the one for setting slur attachments, but
1390 subtly differs in its details.  Grob properties can be manipulated
1391 with two commands: @code{\override} extends the definition of a grob
1392 with one setting, and @code{\revert} releases this setting.  This has
1393 a theoretical appeal: the operations are simple and symmetric.  For
1394 practical use, it can be cumbersome.  The commands act like
1395 parentheses: you should carefully balance the use of @code{\override}
1396 and @code{\revert}.  The @code{\set} command is more friendly: it
1397 first does a @code{\revert} followed by @code{\override}.
1398
1399 @separate
1400
1401 Brahms uses music notation is a slightly unorthodox way.  Ties
1402 usually happen only within one voice.  In this piece, the composer
1403 gladly produces ties that jump voices.  We deal with this by faking
1404 these ties: whenever we need such a tie, we insert a notehead in a
1405 different voice, and blank the stem.  This is done in the following
1406 snippet of code.
1407
1408 @cindex transparent objects
1409 @cindex removing objects
1410 @cindex invisible objects
1411 @example
1412 \property Voice.Stem \set #'transparent = ##t
1413 d'
1414 @end example
1415 Blanking the stem should be done for only one object. One of the ways
1416 to achieve that, is by setting the property before a note. Reverting
1417 it afterwards is tedious, so for setting a property only once, we have
1418 the syntax @code{\once}: it reverts the property directly before
1419 proceeding to the next step in time.
1420
1421 The @code{\once} keyword is added to @code{\property}.
1422
1423
1424 Finally, the last tie is forced up using @code{\tieUp}.
1425
1426 @separate
1427
1428 Here is the complete ``fine tuned'' version, which includes all the
1429 modifications we discussed in this section:
1430
1431 @lilypondfile[verbatim]{brahms-tweaked.ly}
1432
1433
1434 @node An orchestral score
1435 @section An orchestral score
1436
1437 @menu
1438 * The full score::              
1439 * Extracting an individual part::  
1440 @end menu
1441
1442
1443 Our next two examples demonstrate one way to create an orchestral
1444 score in LilyPond.  When typesetting a piece for several instruments,
1445 you will want to create a full score (for the conductor) along with
1446 several individual parts (for the players).
1447
1448   We will declare the music for each instrument individually, giving
1449 the music of each instrument its own name.  These pieces of music are
1450 then combined in different @code{\score} blocks to produce different
1451 combinations of instruments (for example, one @code{\score} block may
1452 only include the cello part; another @code{\score} block may be for
1453 all the strings, and yet another @code{\score} block may be for all
1454 parts together).
1455
1456 This orchestral score example consists of three input files.  In the
1457 first file, @file{os-music.ly}, we define the music for all
1458 instruments.  This file will be used for producing the score and the
1459 separate parts, but the file does not produce any sheet music itself.
1460 Other files reference it by stating @code{\include "os-music.ly"}.
1461
1462 @example
1463 % os-music.ly
1464 \header @{
1465   title = "Zo, goed lieverd?"
1466   subtitle = "How's, this babe?"
1467   composer = "JCN"
1468   opus = "1"
1469   piece = "Laid back"
1470 @}
1471 global = @{
1472   \time 2/4
1473   \skip 2*4 \bar "|."
1474 @}
1475 Key = \notes \key as \major
1476 flautoI = \notes\relative c'' @{
1477   f8 g f g f g f g
1478   bes as bes as bes as bes as
1479 @}
1480 flautoII = \notes\relative c'' @{
1481   as8 bes as bes R1 d4 ~ d
1482 @}
1483 tromboI = \notes\relative c'' @{
1484   c4. c8 c8 c4. es4 r as, r
1485 @}
1486 tromboII = \notes\relative c'' @{
1487   as4. as8 as8 as4. R1*1/2 as4 es'
1488 @}
1489 timpani = \notes\relative c, @{
1490   \times 2/3 @{ f4 f f @}
1491   \times 4/5 @{ as8 as as as as @}
1492   R1
1493 @}
1494 corno = \notes\relative c' @{
1495    bes4 d f, bes d f, bes d
1496 @}
1497 @end example
1498
1499 We will not examine this example line by line, since you already know
1500 most of it.  We'll examine a few lines which contain new elements.
1501
1502
1503 @separate
1504 @example
1505 global = @{
1506   \time 2/4
1507   \skip 2*4 \bar "|."
1508 @}
1509 @end example
1510
1511 This declares settings to be used globally.  The @code{\skip} command
1512 produces no output, but moves forward in time: in this case, the
1513 duration of a half note (@code{2}), and that four times (@code{*4}).
1514 This brings us to the end of the piece, and we can set the end bar.
1515 You can use @code{s} as a shortcut for @code{\skip} (the last line of
1516 this section would be @code{s2*4 \bar"|."}).
1517
1518 @separate
1519 @example
1520 Key = \notes \key as \major
1521 @end example
1522 This declares the key signature of the piece and assign it to the
1523 identifier @var{Key}.  Later on we will use @code{\Key} for all staves
1524 except those for transposing instruments.
1525
1526 @node The full score
1527 @subsection The full score
1528
1529
1530 The second file, @inputfileref{input/tutorial,os-score.ly}, reads the
1531 definitions of the first (@inputfileref{input/tutorial,os-music.ly}), and
1532 defines the @code{\score} block for the full conductor's score.
1533
1534 @example
1535 \version "1.7.6"
1536
1537 \include "os-music.ly"
1538 \include "paper13.ly"
1539
1540 textFlat = \markup @{\smaller \musicglyph #"accidentals--1"@}
1541 \score @{
1542   <
1543     \global
1544     \property Score.BarNumber \override #'padding = #3
1545     \context StaffGroup = woodwind <
1546       \context Staff = flauti <
1547         \property Staff.midiInstrument = #"flute"
1548         \property Staff.instrument = "2 Flauti"
1549         \property Staff.instr = "Fl."
1550         \Key
1551         \context Voice=one @{ \voiceOne \flautoI @}
1552         \context Voice=two @{ \voiceTwo \flautoII @}
1553       >
1554     >
1555     \context StaffGroup = timpani <
1556       \context Staff = timpani <
1557         \property Staff.midiInstrument = #"timpani"
1558         \property Staff.instrument = \markup @{ \column <<  "Timpani" "(C-G)" >> @}
1559         \property Staff.instr = #"Timp."
1560         \clef bass
1561         \Key
1562         \timpani
1563       >
1564     >
1565     \context StaffGroup = brass <
1566       \context Staff = trombe <
1567         \property Staff.midiInstrument = #"trumpet"
1568         \property Staff.instrument = \markup @{ \column << "2 Trombe" "(C)" >> @}
1569         \property Staff.instr = \markup@{ \column << "Tbe." "(C)">> @}
1570         \Key
1571         \context Voice=one \partcombine Voice
1572           \context Thread=one \tromboI
1573           \context Thread=two \tromboII
1574       >
1575       \context Staff = corni <
1576         \property Staff.midiInstrument = #"french horn"
1577         \property Staff.instrument
1578         = \markup @{ \column << "Corno" @{ "(E"  \textFlat ")" @} >> @}
1579         \property Staff.instr =
1580         \markup @{ \column << "Cor." @{ "(E"  \textFlat ")" @} >> @}
1581         \property Staff.transposing = #3
1582         \notes \key bes \major
1583         \context Voice=one \corno
1584       >
1585     >
1586   >
1587   \paper @{
1588     indent = 15 * \staffspace
1589     linewidth = 60 * \staffspace
1590     textheight = 90 * \staffspace
1591     \translator@{
1592       \VoiceContext
1593       \consists "Multi_measure_rest_engraver"
1594     @}
1595     \translator@{
1596       \HaraKiriStaffContext
1597       \remove "Multi_measure_rest_engraver"
1598     @}
1599   @}
1600   \midi @{
1601     \tempo 4 = 75
1602   @}
1603 @}
1604 @end example
1605
1606 @center @strong{Zo, goed lieverd?}
1607 @sp 1
1608 @center How's, this babe?
1609 @flushright
1610 Opus 1.
1611 @end flushright
1612 @flushleft
1613 @sc{Laid back}
1614 @end flushleft
1615
1616 @lilypondfile{os-score.ly}
1617
1618 @separate
1619 @example
1620 \include "os-music.ly"
1621 @end example
1622 First we need to include the music definitions we made in
1623 @file{os-music.ly}.
1624
1625 @ignore
1626
1627 [TODO: mention in a more relevant place]
1628   
1629 @separate
1630 @example
1631 #(ly:set-point-and-click 'line-column)
1632 @end example
1633
1634 This piece of Scheme code executes the function
1635 @code{ly:set-point-and-click} with the argument
1636 @code{line-column}.  Editing input files can be complicated if you are
1637 working with large files: if you are digitizing existing music, you have
1638 to synchronize the .ly file, the sheet music on your lap and the sheet
1639 music on the screen.  The point-and-click mechanism makes it easy to
1640 find the origin of an error in the LY file: when you view the file with
1641 Xdvi and click on a note, your editor will jump to the spot where that
1642 note was entered.  For more information, see @ref{Point and click}.
1643 @end ignore
1644
1645
1646 @separate
1647 @example
1648 #(define text-flat '((font-relative-size . -2)
1649          (music "accidentals--1")))
1650 @end example
1651
1652 To name the transposition of the french horn, we will need a piece of
1653 text with a flat sign.  LilyPond has a mechanism for font selection and
1654 kerning called Scheme markup text (See @ref{Text markup}).  The flat
1655 sign is taken from the music font, and its name is @code{accidentals--1}
1656 (The natural sign is called @code{accidentals-0}).  The default font is
1657 too big for text, so we select a relative size of @code{-2}.
1658
1659 @separate
1660 @example
1661   <
1662     \global
1663 @end example
1664 All staves are simultaneous and use the same global settings.
1665
1666 @separate
1667 @example
1668     \property Score.BarNumber \override #'padding = #3
1669 @end example
1670 LilyPond prints bar numbers at the start of each line, but
1671 unfortunately they end up a bit too close to the staff in this
1672 example.  In LilyPond, a bar number is called @var{BarNumber}.
1673 BarNumber objects can be manipulated through their
1674 @var{side-position-interface}.  One of the properties of a
1675 @var{side-position-interface} that can be tweaked is @var{padding}:
1676 the amount of extra space that is put between this and other objects.
1677 We set the padding to three staff spaces.
1678
1679 You can find information on all these kind of properties in LilyPond's
1680 automatically generated documentation in
1681 @ifnottex
1682 @ref{ (lilypond-internals)lilypond-internals, LilyPond Internals}
1683 or in @ref{Fine tuning a piece}.
1684 @end ifnottex
1685 @iftex
1686 the online documentation or in the previous section of the tutorial.
1687 @end iftex
1688
1689 @c  REFERENCE MAO
1690
1691 @separate
1692 @example
1693     \context StaffGroup = woodwind <
1694       \context Staff = flauti <
1695 @end example
1696 A new notation context: the @code{StaffGroup}.  @code{StaffGroup} can
1697 hold one or more @code{Staff}s, and will print a big bracket at the
1698 left of the score.  This starts a new staff group for the woodwind
1699 section (just the flutes in this case).  Immediately after that, we
1700 start the staff for the two flutes, who also play simultaneously.
1701
1702 @separate
1703 @example
1704         \property Staff.midiInstrument = #"flute"
1705 @end example
1706 Specify the instrument for MIDI output (see @ref{MIDI instrument
1707 names}).
1708
1709 @separate
1710 @example
1711         \property Staff.instrument = "2 Flauti"
1712         \property Staff.instr = "Fl."
1713 @end example
1714 This defines the instrument names to be printed in the
1715 margin.  @code{instrument} specifies the name for the first line
1716 of the score, @code{instr} is used for the rest of the score.
1717
1718 @separate
1719 @example
1720         \Key
1721 @end example
1722 The flutes play in the default key.
1723
1724 @separate
1725 @example
1726         \context Voice=one @{ \voiceOne \flautoI @}
1727         \context Voice=two @{ \voiceTwo \flautoII @}
1728 @end example
1729 Last come the actual flute parts.  Remember that we are still in
1730 simultaneous mode.  We name both voices differently, so that LilyPond
1731 will create two Voice contexts.  The flute parts are simple, so
1732 we specify manually which voice is which: @code{\voiceOne} forces the
1733 direction of stems, beams, slurs and ties up, @code{\voiceTwo} sets
1734 directions down.
1735
1736 @separate
1737 @example
1738       >
1739     >
1740 @end example
1741 Close the flutes staff and woodwind staff group.
1742
1743 @separate
1744 @example
1745         \property Staff.instrument = #'(lines "Timpani" "(C-G)")
1746 @end example
1747 The timpani staff demonstrates a new piece of scheme markup, it sets two
1748 lines of text.
1749
1750 @separate
1751 @example
1752         \context Voice=one \partcombine Voice
1753           \context Thread=one \tromboI
1754           \context Thread=two \tromboII
1755 @end example
1756 You have seen the notation contexts Staff and Voice, but here is a new
1757 one: Thread.  One or more Threads can be part of a Voice.  Thread
1758 takes care of note heads and rests; Voice combine note heads onto a
1759 stem.
1760
1761 For the trumpets we use the automatic part combiner (see @ref{Automatic
1762 part combining}) to combine the two simultaneous trumpet parts onto the
1763 trumpet staff.  Each trumpet gets its own Thread context, which must be
1764 named @code{one} and @code{two}).  The part combiner makes these two
1765 threads share a Voice when they are similar, and splits the threads up
1766 when they are different.
1767
1768 @separate
1769 @example
1770 \property Staff.instrument = #`(lines "Corno"
1771   (columns "(E" ,text-flat ")"))
1772 @end example
1773 The french horn (``Corno'') has the most complex scheme markup name, made
1774 up of two lines of text.  The second line has three elements (columns) --
1775 the @code{(E}, the flat sign @code{text-flat} that we defined previously,
1776 and a final @code{")"}.  We use a backquote instead of an
1777 ordinary quote at the beginning of the Scheme expression to be able to
1778 access the @code{text-flat} identifier, `unquoting' it with a ``@code{,}''.
1779
1780 @separate
1781 @example
1782         \property Staff.transposing = #3
1783 @end example
1784 The french horn is to be tuned in E-flat, so we tell the MIDI back-end to
1785 transpose this staff by three steps.
1786
1787 Note how we can choose different tunings for the text input, sheet music
1788 output and, and MIDI output, using @code{\transpose} and the MIDI Staff
1789 property @var{transposing}.
1790
1791 @separate
1792 @example
1793         \notes \key bes \major
1794 @end example
1795 Since the horn is transposing, it is in a different key.
1796
1797 @separate
1798 @example
1799     indent = 15 * \staffspace
1800     linewidth = 55 * \staffspace
1801 @end example
1802 We specify a big indent for the first line and a small linewidth for this
1803 tutorial.
1804
1805 @separate
1806
1807 Usually the default setup of notation contexts (Thread, Voice, Staff,
1808 Staffgroup, Score) is just fine.  But in this case we want a different
1809 type of Staff context.
1810
1811 @example
1812     \translator@{
1813       \HaraKiriStaffContext
1814     @}
1815 @end example
1816
1817 In orchestral scores it often happens that one instrument only has
1818 rests during one line of the score.  @code{HaraKiriStaffContext} can
1819 be used as a regular @code{StaffContext} drop-in and will take care of
1820 the automatic removing of empty staves -- so if the strings are the
1821 only instruments playing for a line, LilyPond will only print the string
1822 parts for that line of the score.  This reduces the number of page turns
1823 (and the number of dead trees!) required in a score.
1824
1825 @node Extracting an individual part
1826 @subsection Extracting an individual part
1827
1828 The third file, @file{os-flute-2.ly} also reads the definitions of the
1829 first (@file{os-music.ly}), and defines the @code{\score} block for the
1830 second flute part.
1831
1832 @example
1833 \include "os-music.ly"
1834 \include "paper16.ly"
1835
1836 \score @{
1837   \context Staff <
1838     \property Score.skipBars = ##t
1839     \property Staff.midiInstrument = #"flute"
1840     \global
1841     \Key
1842     \flautoII
1843   >
1844   \header @{
1845     instrument = "Flauto II"
1846   @}
1847   \paper @{
1848     linewidth = 80 * \staffspace
1849     textheight = 200 * \staffspace
1850   @}
1851   \midi @{
1852     \tempo 4 = 75
1853   @}
1854 @}
1855 @end example
1856
1857 @center @strong{Zo, goed lieverd?}
1858 @sp 1
1859 @center How's, this babe?
1860 @center @emph{Flauto II}
1861 @flushright
1862 Opus 1.
1863 @end flushright
1864 @flushleft
1865 @sc{Laid back}
1866 @end flushleft
1867 @lilypondfile{os-flute-2.ly}
1868
1869
1870 Because we separated the music definitions from the @code{\score}
1871 instantiations, we can easily define a second score with the music of
1872 the second flute.  This is the part for the second flute player.  Of
1873 course, we would make separate parts for all individual instruments if
1874 we were preparing the score for an orchestra.
1875
1876 @separate
1877 @example
1878     \flautoII
1879 @end example
1880 In this individual part the second flute has a whole staff for itself,
1881 so we do not want to force stem or tie directions.
1882
1883 @separate
1884 @example
1885   \header @{
1886     instrument = "Flauto II"
1887   @}
1888 @end example
1889 The @code{\header} definitions were also read from @file{os-music.ly},
1890 but we need to set the instrument for this particular score.
1891
1892 @separate
1893 @example
1894     \property Score.skipBars = ##t
1895 @end example
1896 In the conductor's full score, all bars with rests are printed, but for
1897 the individual parts, we want to print one multimeasure rest instead of
1898 many consecutive empty bars.  LilyPond will do this if
1899 @code{Score.skipBars} is set to true (@code{##t}).
1900
1901
1902 @node Integrating text and music
1903 @section Integrating text and music
1904
1905
1906 @cindex La@TeX{}, music in
1907 @cindex HTML, music in
1908 @cindex Texinfo, music in
1909
1910 Sometimes you might want to use music examples in a text that you are
1911 writing (for example a musicological treatise, a songbook, or (like us)
1912 the LilyPond manual).  You can make such texts by hand, simply by
1913 importing a PostScript figure into your word processor.  However,
1914 there is an automated procedure to reduce the amount of work.
1915
1916 If you use HTML, La@TeX{}, or Texinfo, you can mix text and LilyPond
1917 code.  A script called @code{lilypond-book} will extract the music
1918 fragments, run LilyPond on them, and put back the resulting notation.
1919 This program is fully described in @ref{lilypond-book manual}.  Here
1920 we show a small example.  Since the example also contains explanatory
1921 text, we will not comment it further.
1922
1923 @example
1924 \documentclass[a4paper]@{article@}
1925 \begin@{document@}
1926
1927 In a lilypond-book document, you can freely mix music and text. For
1928 example:
1929 \begin@{lilypond@}
1930   \score @{ \notes \relative c' @{
1931      c2 g'2 \times 2/3 @{ f8 e d @} c'2 g4
1932   @} @}
1933 \end@{lilypond@}
1934
1935 Notice that the music line length matches the margin settings of the
1936 document.
1937
1938 If you have no \verb+\score+ block in the fragment,
1939 \texttt@{lilypond-book@} will supply one:
1940
1941 \begin@{lilypond@}
1942   c'4
1943 \end@{lilypond@}
1944
1945 In the example you see here, two things happened: a
1946 \verb+\score+ block was added, and the line width was set to natural
1947 length. You can specify many more options using  \LaTeX style options
1948 in brackets:
1949
1950 \begin[verbatim,11pt,singleline,
1951   fragment,relative,intertext="hi there!"]@{lilypond@}
1952   c'4 f bes es
1953 \end@{lilypond@}
1954
1955 The option \texttt@{verbatim@} prints the LilyPond code in addition to
1956 the graphical score, \texttt@{11pt@} selects the default music size,
1957 \texttt@{fragment@} adds a score block, \texttt@{relative@} uses
1958 relative mode for the fragment, and \texttt@{intertext@} specifies
1959 what to print between the \texttt@{verbatim@} code and the music.
1960
1961 If you want to include large examples into the text, it may be more
1962 convenient to put the example in a separate file:
1963
1964 \lilypondfile[printfilename]@{sammartini.ly@}
1965
1966 The \texttt@{printfilename@} option adds the file name to the output.
1967
1968 \end@{document@}
1969 @end example
1970
1971 Under Unix, you can view the results as follows.
1972 @example
1973 $ cd input/tutorial
1974 $ mkdir -p out/
1975 $ lilypond-book --outdir=out/ lilbook.tex
1976 lilypond-book (GNU LilyPond) 1.7.16
1977 Reading `input/tutorial/lilbook.tex'
1978 Reading `input/tutorial/sammartini.ly'
1979 @var{lots of stuff deleted}
1980 Writing `out/lilbook.latex'
1981 $ cd out
1982 $ latex lilbook.latex
1983 @var{lots of stuff deleted}
1984 $ xdvi lilbook 
1985 @end example
1986
1987 Notice the @code{outdir} option to lilypond-book. Running lilypond-book
1988 and running latex creates a lot of temporary files, and you would not want
1989 those to clutter up your working directory. Hence, we have them created
1990 in a separate subdirectory.
1991
1992 The result looks more or less like this: 
1993
1994 @separate
1995
1996 In a lilypond-book document, you can freely mix music and text. For
1997 example:
1998 @lilypond
1999 \score {
2000   \notes \relative c' {
2001     c2 g'2 \times 2/3 { f8 e d } c'2 g4
2002   }
2003   \paper {
2004     raggedright = ##t
2005   }
2006 }
2007 @end lilypond
2008
2009 Notice that the music line length matches the margin settings of the
2010 document.
2011
2012 If you have no @code{\score} block in the fragment,
2013 @code{lilypond-book} will supply one:
2014
2015 @lilypond
2016   c'4
2017 @end lilypond
2018
2019 In the example you see here, a number of things happened: a
2020 @code{\score} block was added, and the line width was set to natural
2021 length. You can specify many more options using  La@TeX{} style options
2022 in brackets:
2023
2024 @lilypond[verbatim,11pt,singleline,
2025   fragment,relative,intertext="hi there!"]
2026   c'4 f bes es
2027 @end lilypond
2028
2029 The option @code{verbatim} also shows the LilyPond code, @code{11pt} selects
2030 the default music size, @code{fragment} adds a score block,
2031 @code{relative} uses relative mode for the fragment, and
2032 @code{intertext} specifies what to print between the
2033 @code{verbatim} code and the music.
2034
2035 If you include large examples into the text, it may be more convenient
2036 to put the example in a separate file:
2037
2038 @lilypondfile[printfilename]{sammartini.ly}
2039
2040 The @code{printfilename} option adds the file name to the output.
2041