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