]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tutorial.itely
release: 1.3.124
[lilypond.git] / Documentation / user / tutorial.itely
1 @c -*-texinfo-*-
2
3 @node Tutorial
4 @chapter Tutorial
5
6 @menu
7 * Introduction::                   Introduction
8 * The first tune::                 The first tune
9 * Lyrics and chords::              Lyrics and chords
10 * More movements::                 More than one movement in a file
11 * Piano music::                    Piano music
12 * end of tutorial::                The end
13 @end menu
14
15 @node Introduction
16 @section Introduction
17
18   
19 LilyPond prints music from a specification that you, the user, supply.
20 You have to give that specification using a @emph{language}.  This
21 document is a gentle introduction to that language, which is called
22 Lilypond, an acronym of Music Definition Language.
23
24 This tutorial will demonstrate how to use Lilypond by presenting
25 examples of input along with resulting output.  We will use English
26 terms for notation.  In case you are not familiar with those, you may
27 consult the glossary that is distributed with LilyPond.
28
29 The examples discussed are included in the distribution, in the
30 subdirectory @file{input/tutorial/}.  It is recommended that you
31 experiment with writing Lilypond input yourself, to get a feel for
32 how LilyPond behaves.
33
34 @node The first tune
35 @section The first tune
36
37
38 To demonstrate what LilyPond input looks like, we start off with a
39 full fledged, yet simple example. It is a convoluted version
40 of the famous menuet in J. S. Bach's @emph{Klavierbuechlein}.
41
42 @lilypond[verbatim]
43 % lines preceded by a percent are comments which
44 % are ignored by Lilypond.
45 \include "paper16.ly"
46 \score {
47     \notes                        
48     \relative c'' \sequential{                
49             \time 3/4;                
50             \key g \major;
51
52         \repeat "volta" 2 {
53             d4 g,8 a b c d4 g, g |
54             e'4 c8 d e fis g4 g, g |
55             c4 d8()c b a( )b4 c8 b a g |
56             a4 [b8 a] [g fis] g2.  |
57         }
58
59         b'4 g8 a b g
60         a4 d,8 e fis d |
61         g4 e8 fis g d cis4 b8 cis a4 |
62         a8-. b-. cis-. d-. e-. fis-.
63         g4 fis e |
64         fis a,  r8 cis8
65         d2.-\fermata
66         \bar "|.";
67     }
68     \paper {
69        % standard settings are too wide for a book
70        linewidth = 14.0 \cm;
71    }
72 }
73 @end lilypond
74
75 Enter it (or copy it, the filename is @file{menuet.ly}), compile it
76 with LilyPond and view the output.  Details of this procedure may vary
77 from system to system.  To create the output, one would issue the
78 command `@code{ly2dvi menuet}'.  @file{ly2dvi} is a program that does
79 the job of running LilyPond and @TeX{}, handling of titles and
80 adjusting of page margins.
81
82 If all goes well, the file @file{menuet.dvi} will be created.
83 To view this output, issue the command `@code{xdvi menuet}'.
84
85 Now that we are familiar with the procedure of producing output, we
86 will analyse the input, line by line.
87 @example
88         % lines preceded by a percent are comments which
89         % are ignored by Lilypond.
90 @end example 
91 The percent sign, `@code{%}', introduces a line comment.  If you want to
92 make larger comments, you can use block comments. These are delimited
93 by `@code{%@{}' and `@code{%@}}'
94 @example 
95
96         \input "paper16.ly"
97  
98 @end example 
99 By default, LilyPond will use definitions for a 20
100 point@footnote{A point is the standard measure of length for
101 printing.  One point is 1/72.27 inch.} high staff.  We want smaller
102 output (16 point staff height), so we must import the settings for
103 that size, which is done.
104 @example 
105
106         \score @{
107  
108 @end example 
109   A lilypond file combines music with directions for outputting that
110 music.  The music is combined with the output directions by putting
111 them into a @code{\score} block.
112 @example 
113
114         \notes                
115  
116 @end example 
117  This makes LilyPond ready for accepting notes.
118 @example 
119
120         \relative c''
121  
122 @end example 
123  As we will see, pitches are combinations of octave, note name and
124 chromatic alteration.  In this scheme, the octave is indicated by
125 using raised quotes (`@code{'}') and ``lowered'' quotes (commas:
126 `@code{,}').  The central C is denoted by @code{c'}.  The C one octave
127 higher is @code{c''}.  One and two octaves below the central C is
128 denoted by @code{c} and @code{c,} respectively.
129
130 For pitches in a long piece you might have to type many quotes.  To
131 remedy this, LilyPond has a ``relative'' octave entry mode.  In this
132 mode, octaves of notes without quotes are chosen such that a note is
133 as close as possible (graphically, on the staff) to the the preceding
134 note.  If you add a high-quote an extra octave is added.  The lowered
135 quote (a comma) will subtract an extra octave.  Because the first note
136 has no predecessor, you have to give the (absolute) pitch of the note
137 to start with.
138 @example 
139
140         \sequential @{
141  
142 @end example 
143   What follows is sequential music, i.e.,
144 notes that are to be played and printed after each other.
145 @example 
146
147         \time 3/4;
148  
149 @end example 
150   This command changes the time signature of the current piece: a 3/4
151 sign is printed.  This command is also used to generate bar lines in
152 the right spots.
153 @example 
154
155         \key g \major;
156  
157 @end example 
158   This command changes the current key to G-major.  Although this
159 command comes after the @code{\time} command, in the output, the key
160 signature comes before the time signature: LilyPond knows about music
161 typesetting conventions.
162 @example 
163
164         \repeat "volta" 2
165  
166 @end example 
167   This command tells LilyPond that the following piece of music must
168 be played twice; @code{"volta"} means that volta brackets should be used
169 for alternatives---if there were any.
170 @example 
171
172         @{
173  
174 @end example 
175 The subject of the repeat is again sequential music.  Since
176 @code{\sequential} is such a common construct, a shorthand is provided:
177 just leave off @code{\sequential}, and the result is the same.
178 @example 
179
180         d4
181  
182 @end example 
183  This is a note with pitch @code{d} (determined up to octaves).  The
184 relative music was started with a @code{c''}, so the real pitch of this
185 note is @code{d''}.  The @code{4} designates the duration of the note
186 (it is a quarter note).
187 @example 
188
189         a b
190  
191 @end example 
192 These are notes with pitch @code{a} and @code{b}.  Because their
193 duration is the same as the @code{g}, there is no need to enter the
194 duration (You may enter it anyway, e.g. @code{a4 b4})
195 @example 
196
197         d4 g, g |
198  
199 @end example 
200  Three more notes.  The `@code{|}' character is a `bar check'.  When
201 processing the music, LilyPond will verify that bar checks are found at
202 the start of a measure.  This can help you track down errors.
203
204  So far, no notes were chromatically altered.  Here is the first one
205 that is: @code{fis}. Lilypond by default uses Dutch note names, and
206 ``Fis'' is the Dutch note name for ``F sharp''.  However, there is no
207 sharp sign in the output. The program keeps track of key signatures,
208 and will only print accidentals if they are needed.
209 @example 
210
211         c8 d e fis
212  
213 @end example 
214 LilyPond guesses were beams can be added to eighth and shorter notes.
215 In this case, a beam over 4 eighths is added.
216 @example 
217
218         c4 d8( )c b a( )b4 c8 b a g |
219  
220 @end example 
221   The next line shows how to make a slur:
222 the beginning and ending note of the slur is marked with an opening and
223 closing parenthesis respectively.  In the line shown above, this is
224 done for two slurs.  Slur markers (parentheses) are put between
225 the notes.
226 @example 
227
228         a4 [b8 a] [g fis] 
229  
230 @end example 
231 Automatic beaming can be overridden by inserting beam marks
232 (brackets).  Brackets are put around the notes you want beamed.
233 @example 
234
235         g2.  |
236  
237 @end example 
238 A duration with augmentation dot  is notated
239 with the duration number followed by a period.
240 @example 
241
242         @}
243  
244 @end example 
245   This ends the sequential music to be repeated.  LilyPond will typeset
246 a repeat bar.
247 @example 
248
249         cis'4 b8 cis a4 |
250  
251 @end example 
252  This line shows that Lily will print an accidental if that is
253 needed: the first C sharp of the bar will be printed with an accidental,
254 the second one without.
255 @example 
256
257         a8-. b-. cis-. d-. e-. fis-.
258  
259 @end example 
260 You can enter articulation signs either in a verbose form using a
261 shorthand.  Here we demonstrate the shorthand: it is formed by a dash
262 and the character for the articulation to use, e.g. `@code{-.}' for
263 staccato as shown above.
264 @example 
265
266         fis a, r8 cis8
267  
268 @end example 
269  
270 Rests are denoted by the special notename `@code{r}'.  You can also enter
271 an invisible rest by using the special notename `@code{s}'.
272 @example 
273
274         d2.-\fermata
275  
276 @end example 
277  All articulations have a verbose form, like @code{\fermata}.  The
278 command `@code{\fermata}' is not part of the core of the language (most
279 of the other discussed elements are), but it is a shorthand for a more
280 complicated description of a fermata.  @code{\fermata} names that
281 description and is therefore called an @emph{identifier}.
282 @example 
283
284         @}
285  
286 @end example 
287  
288 Here the music ends.
289 @example 
290
291         \paper @{
292                 linewidth = 14.0\cm;
293         @}
294  
295 @end example 
296 This specifies a conversion from music to notation output.  Most of
297 the details of this conversions (font sizes, dimensions, etc.) have
298 been taken care of, but  to fit the output  in this document, it has
299 to be smaller.  We do this by setting the line width to 14 centimeters
300 (approximately 6 inches).
301 @example 
302
303         @}
304  
305 @end example 
306 The last brace ends the @code{\score} block.
307
308 There are two things to note here. The format contains musical
309 concepts like pitches and durations, instead of symbols and positions:
310 the input format tries to capture the meaning of @emph{music}, and not
311 notation.  Second, the format tries to be @emph{context-free}:
312 a note will sound the same regardless of the current time signature,
313 the key, etc.
314
315 The purpose of LilyPond is explained informally by the term `music
316 typesetter'.  This is not a fully correct name: not only does the
317 program print musical symbols, it also makes esthetic decisions.  All
318 symbols and their placement is @emph{generated} from a high-level musical
319 description.  In other words,  LilyPond would be best
320 described by `music compiler' or `music to notation compiler'.
321
322
323
324
325 @node Lyrics and chords
326 @section Lyrics and chords
327
328 In this section we show how to typeset a song of unknown
329 origin.@footnote{The author would welcome information about the origin
330 of this song.}.
331
332 @example 
333 \header @{
334         title = "The river is flowing";
335         composer = "Traditional (?)";
336 @}
337 \include "paper16.ly"
338 melody = \notes \relative c' @{
339         \partial 8;
340         \key c \minor;
341         g8 |
342         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
343         c4 c8 d [es () d] c4 | d4 es8 d c4.
344         \bar "|.";
345 @}
346
347 text = \lyrics @{
348         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
349         ri -- ver is flo -- wing down to the sea.
350 @}
351
352 accompaniment =\chords @{
353         r8
354         c2:3- f:3-.7 d:min es4 c8:min r8
355         c2:min f:min7 g:7^3.5 c:min @}
356
357 \score @{
358         \simultaneous @{
359 %         \accompaniment
360           \context ChordNames \accompaniment
361
362           \addlyrics
363             \context Staff = mel @{        
364               \property Staff.noAutoBeaming = ##t
365               \property Staff.automaticMelismata = ##t
366               \melody 
367             @}
368             \context Lyrics \text
369         @}
370         \midi  @{ \tempo 4=72;@}
371         \paper @{ linewidth = 10.0\cm; @}
372 @} 
373 @end example 
374
375
376 The result would look this@footnote{The titling and font size shown
377 may differ, since the titling in this document is not generated by
378 @file{ly2dvi}.}.
379
380 @center @strong{The river is flowing}
381 @center Traditional 
382
383 @lilypond[center]
384 \header {
385         title = "The river is flowing";
386         composer = "Traditional (?)";
387 }
388 \include "paper16.ly"
389 melody = \notes \relative c' {
390         \partial 8;
391         \key c \minor;
392         g8 |
393         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
394         c4 c8 d [es () d] c4 | d4 es8 d c4.
395         \bar "|.";
396 }
397
398 text = \lyrics {
399         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
400         ri -- ver is flo -- wing down to the sea.
401 }
402
403 accompaniment =\chords {
404         r8
405         c2:3- f:3-.7 d:min es4 c8:min r8
406         c2:min f:min7 g:7^3.5 c:min }
407
408 \score {
409         \simultaneous {
410 %         \accompaniment
411           \context ChordNames \accompaniment
412
413           \addlyrics
414             \context Staff = mel {
415               \property Staff.noAutoBeaming = ##t
416               \property Staff.automaticMelismata = ##t
417               \melody 
418             }
419             \context Lyrics \text
420         }
421         \midi  { \tempo 4=72;}
422         \paper { linewidth = 10.0\cm; }
423 }
424 @end lilypond
425
426 Again, we will dissect the file line by line.
427 @example 
428
429         \header @{
430  
431 @end example 
432 Information about the music you are about to typeset goes into a
433 @code{\header} block.  The information in this block is not used by
434 LilyPond, but it is included in the output.  @file{ly2dvi} uses this
435 information to print titles above the music.
436 @example 
437
438         title = "The river is flowing";
439         composer = "Traditional (?)"; 
440 @end example 
441 the @code{\header} block contains assignments.  An assignment starts
442 with a string.  (which is unquoted, in this case). Then comes the
443 equal sign `@code{=}'.  After the equal sign comes the expression you
444 want to store.  In this case, you want to put in strings.  The
445 information has to be quoted here, because it contains spaces. Each
446 assignment is finished with a semicolon.
447 @example 
448
449         \include "paper16.ly"
450  
451 @end example 
452 Smaller size for inclusion in a book.
453 @example 
454
455         melody = \notes \relative c' @{
456  
457 @end example 
458 The structure of the file will be the same as the previous one, a
459 @code{\score} block with music in it.  To keep things readable, we will
460 give names to the different parts of music, and use the names to
461 construct the music within the score block.
462
463 @example 
464         \partial 8;
465 @end example 
466
467 The piece starts with an anacrusis of one eighth.
468 @example
469         \key c \minor;
470 @end example
471 The key is C minor: we have three flats.
472
473 @example 
474
475         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
476         c4 c8 d [es () d] c4 | d4 es8 d c4.
477         \bar "|.";
478  
479 @end example 
480
481 We use explicit beaming.  Since this is a song,  we will turn automatic
482 beams off, and use explicit beaming where needed.
483 @example 
484
485         @}
486  
487 @end example 
488 This ends the definition of @code{melody}.  Note that there are no
489 semicolons after assignments at top level.
490 @example 
491
492         text = \lyrics @{
493  
494 @end example 
495 Another identifier assignment.  This one is for the lyrics. 
496 Lyrics are formed by syllables that have duration, and not by
497 notes. To make LilyPond parse words as syllables,  switch it  into
498 lyrics mode with @code{\lyrics}.  Again, the brace after @code{\lyrics}
499 is a shorthand for @code{\sequential @{}.
500 @example 
501
502   The4 ri -- ver is flo- __ wing,  flo -- wing and gro -- wing, the
503   ri- ver is flo- __ wing down to the sea.
504 @}
505  
506 @end example 
507 The syllables  themselves are  separated by spaces.  You can get syllable
508 extenders by entering `@code{__}', and centered hyphens with
509 `@code{-}@code{-}'.  We enter the syllables as if they are all quarter notes
510 in length (hence the @code{4}), and use a feature to align the
511 syllables to the music (which obviously isn't all quarter notes.)
512 @example 
513
514         accompaniment =\chords @{
515  
516 @end example 
517 We'll put chords over the music.  There is a special mode (analogous
518 to @code{\lyrics} and @code{\notes} mode) where you can give the names
519 of the chords you want, instead of the notes comprising the chord.
520 @example 
521
522         r8
523  
524 @end example 
525 There is no accompaniment during the anacrusis.
526 @example 
527
528         c2:3- f:3-.7
529  
530 @end example 
531 A chord is started by  the tonic of the chord. The
532 first one lasts a half note.  An unadorned note creates a major
533 triad, while a minor triad is wanted.  @code{3-} modifies the third to
534 be small. @code{7} modifies (adds) a seventh, which is small by default
535 to create the @code{f a c es} chord.  Multiple modifiers must be
536 separated by a dot.
537 @example 
538
539         d:min es4 c8:min r8
540  
541 @end example 
542 Some modifiers have predefined names, eg. @code{min} is  the same as
543 @code{3-}, so @code{d-min} is a minor @code{d} chord.
544 @example 
545
546         c2:min f:min7 g:7^3.5 c:min @}
547  
548 @end example 
549 A named modifier @code{min} and a normal modifier @code{7} do not have
550 to be separated by a dot.  Tones from a chord are removed with chord
551 subtractions.  Subtractions are started with a caret, and they are
552 also separated by dots.  In this example, @code{g:7^3.5} produces a
553 minor seventh.  The brace ends the sequential music.
554 @example 
555
556         \score @{
557                 \simultaneous @{
558  
559 @end example 
560 We assemble the music in the @code{\score} block.  Melody, lyrics and
561 accompaniment have to sound at the same time, so they should be
562 @code{\simultaneous}.
563 @example 
564
565         %\accompaniment
566  
567 @end example 
568 Chord mode generates notes grouped in @code{\simultaneous} music.  If
569 you remove the comment sign, you can see the chords in normal
570 notation: they will be printed as note heads on a separate
571 staff.
572 @example 
573
574         \context ChordNames \accompaniment
575  
576 @end example 
577 Normally, the notes that you enter are transformed into note heads.
578 The note heads alone make no sense, they need surrounding information:
579 a key signature, a clef, staff lines, etc.  They need @emph{context}.  In
580 LilyPond, these symbols are created by objects called `interpretation
581 contexts'.  Interpretation contexts only exist during a run of
582 LilyPond.  Interpretation contexts that are for printing music (as
583 opposed to playing music) are called `notation contexts'.
584
585 By default, LilyPond will create a Staff context for you.  If you
586 removed the @code{%} sign in the previous line, you would see that
587 mechanism in action.
588
589 We don't want default contexts here, because we want chord names, not
590 note heads.  An interpretation context can also created upon explicit
591 request. The keyword for such a request is @code{\context}.  It takes
592 two arguments.  The first is the name of an interpretation context.
593 The name is a string, it can be quoted with double quotes).  The
594 second argument is the music that should be interpreted in this
595 context.  For the previous line, we could have written @code{\context
596 Staff \accompaniment}, and get the same effect.
597 @example 
598
599         \addlyrics
600  
601 @end example 
602 The lyrics need to be aligned with the melody.  This is done by
603 combining both with @code{\addlyrics}.  @code{\addlyrics} takes two
604 pieces of music (usually a melody and lyrics, in that order) and
605 aligns the syllables of the second piece under the notes of the
606 first piece.  If you would reverse the order, the notes would be
607 aligned on the lyrics, which is not very useful. (Besides, it looks
608 silly.)
609 @example 
610
611         \context Staff = mel @{
612  
613 @end example 
614 This is the argument of @code{\addlyrics}.  We instantiate a
615 @code{Staff} context explicitly: should you chose to remove the comment
616 before the ``note heads'' version of the accompaniment, the
617 accompaniment will be on a nameless staff.  The melody has to be on a
618 different staff as the accompaniment.  This is accomplished by giving
619 the melody staff a different name.
620 @example 
621
622         \property Staff.noAutoBeaming = ##t
623  
624 @end example 
625 An interpretation context has variables that tune its behaviour.  One
626 of the variables is @code{noAutoBeaming}.  If set and non-zero (i.e.,
627 true) LilyPond will not try to put automatic beaming on the current
628 staff.
629 @example 
630
631         \property Staff.automaticMelismata = ##t
632  
633 @end example 
634 Similarly, we  don't want to print a  syllable when there is
635 a slur. This sets up the Staff context to signal slurs while
636 @code{\addlyrics} is processed.
637 @example 
638
639           \melody
640         @}
641  
642 @end example 
643 Finally, we put the melody on the current staff.  Note that the
644 @code{\property} directives and @code{\melody} are grouped in sequential
645 music,  so the property settings are done before the melody is
646 processed.
647 @example 
648
649         \context Lyrics \text
650  
651 @end example 
652 The second argument of @code{\addlyrics} is the text. The text also
653 should not land on a Staff, but on a interpretation context for
654 syllables, extenders, hyphens etc.  This context is called
655 Lyrics.
656 @example 
657
658         @}
659  
660 @end example 
661 This ends @code{\simultaneous}.
662 @example 
663
664         \midi  @{ \tempo 4=72;@}
665  
666 @end example 
667 This makes the music go to a MIDI file.  MIDI is great for
668 checking music you enter.  You listen to the MIDI file: if you hear
669 something unexpected, it's probably a typing error.  @code{\midi} is an
670 `output definition', a declaration that specifies how to output music
671 analogous to @code{\paper @{ @}}. You can specify the tempo using the
672 @code{\tempo} command, in this case the tempo of quarter notes is set
673 to 72 beats per minute.
674 @example 
675
676         \paper @{ linewidth = 10.0\cm; @}
677  
678 @end example 
679 We also want notation output.  The linewidth is short so the piece
680 will be set in two lines.
681 @example 
682
683         @}
684  
685 @end example 
686 End the score block.
687
688 @node More movements 
689 @section More movements
690
691 You probably ran @file{ly2dvi} on the last example, and ended up with a
692 viewable @file{.dvi} file.  However, between there are a few steps of
693 which LilyPond is only one. To enhance your understanding of what's
694 happening under the hood when you run ly2dvi,  we explain what programs
695 are run.   
696
697 @code{ly2dvi} is a program that calls a number of programs  in sequence.
698 The first thing it does, is running LilyPond on the input file. After
699 some calculations, lily comes up with a @file{.tex} file. The contents
700 of this file are very  low-level instructions.
701
702 For example, if you'd put the following in a file called
703 @file{layout.ly},
704
705 @example
706   \header @{ title = "Two miniatures";  @}
707   
708   #(set point-and-click #t)
709   
710   \paper @{
711         linewidth = -1.0; @}
712
713   \score @{
714     \notes @{ c'4 d'4 @}
715     \header @{
716         opus = "Opus 1.";
717         piece = "Up"; @}
718   @}
719   \score @{
720     \notes @{ d'4 c'4  @}
721     \header @{
722         opus = "Opus 2.";
723         piece = "Down"; @}
724   @}
725 @end example
726
727 The result should look somewhat like this@footnote{The titling in this
728 manual was not generated by ly2dvi, so details will differ.}
729
730 @center @strong{Two miniatures}
731 @flushright
732   Opus 1.
733 @end flushright
734 @flushleft
735 @var{Up}
736 @end flushleft
737 @lilypond
738   \score {
739     \notes { c'4 d'4 }
740     \paper {
741         linewidth = -1.0; }
742   }
743 @end lilypond
744 @flushright
745   Opus 2.
746 @end flushright
747 @flushleft
748 @var{Down}
749 @end flushleft
750 @lilypond
751   \score {
752     \notes { d'4 c'4 }
753     \paper {
754         linewidth = -1.0; }
755   }
756 @end lilypond
757
758 This file is produced by ly2dvi in a few stages, with the help of text
759 formatting tools. LilyPond produces two output files, @file{layout.tex}
760 and @file{layout-1.tex}.  They both look like this:
761
762 @example
763         ...
764   \placebox@{-5  \outputscale @}%
765   @{  8.7229  \outputscale @}%
766   @{\magfontWXGEomMMBo\char90 @}%
767   
768   \placebox@{-4  \outputscale @}%
769   @{ 81.0647  \outputscale @}%
770         ...
771 @end example
772
773 @file{ly2dvi} analyses the progress indication that LilyPond spews out,
774 and generates a file called @file{layout_ly1.tex}. This file contains
775 formatting instructions for the title and page layout.  A fragment might
776 look like
777 @example
778
779         \geometry@{width=540.602362pt,headheight=2mm, ...
780         \renewcommand@{\@@oddfoot@}@{\parbox@{\textwidth@}@{\mbox@{@}   ...
781         \begin@{document@}
782         \lilypondtitle@{foo@}%
783         \makelilytitle
784         \input@{ly2dvi.tex@}
785
786 @end example
787
788 @file{ly2dvi} runs it through LaTeX. LaTeX is a text-formatting system
789 built on top of @TeX. It's very popular in the academic world. If LaTeX
790 is successful, this will produce a @file{.dvi} file, containing both the
791 titling and notes.  @code{ly2dvi} completes its task by deleting the two
792 temporary files, leaving only @file{layout.dvi}.
793
794 @example
795         #(set point-and-click #t)
796 @end example
797
798 Editing input files can be quite complicated if you're working with
799 large files: if you're digitizing existing music, you have to
800 synchronize the .ly file, the sheet music on your lap and the sheet
801 music on the screen.  The point-and-click mechanism makes it easy to
802 find the origin of an error in the .ly file: @footnote{This feature is
803 presently only available on X-windows using a patched version of xdvi
804 and emacs} when you view the file with Xdvi and click on a note using
805 control-right button, [checkme], you editor will jump to the spot where
806 that note was entered.
807
808 More information is in in @ref{Point and click} 
809
810 @example
811   \paper @{ 
812 @end example
813
814 The @code{\score} blocks that follow in the file, don't have
815 @code{\paper} sections, so the settings of this block are substituted: A
816 paper block, at top-level, i.e. not in a @code{\score} block sets the
817 default page layout.
818
819 @example
820   linewidth = -1.0; @}
821 @end example
822
823
824
825 The variable @code{linewidth} normally sets the length of the systems on
826 the page. However, a negative value has a special meaning here. If
827 @code{linewidth} is less than 0, no line breaks are inserted into the
828 score, and the spacing is set to natural length: a short phrase takes up
829 little space, a longer phrase more space.
830
831 @example
832   \score @{
833     \notes @{ c'4 d'4 @}
834 @end example
835
836 In previous examples, notes were specified in relative octaves,
837 i.e. each note was put in the octave that would put it closest to its
838 predecessor. Besides relative, there is also absolute octave
839 specification, and it is turned on by default. In this input mode, the
840 central C is denoted by @code{c'}. Going down, you get @code{c}
841 @code{c,} @code{c,,} etc.  Going up, you get @code{c''} @code{c'''} etc.
842
843 When you're copying music from existing sheet music, relative octaves
844 are probably the easiest to use: it's less typing work and errors are
845 easily spotted. However, if you write LilyPond input, either by hand
846 (ie. composing) or by computer, absolute octaves is probably less work.
847
848
849 @example
850     \header @{
851 @end example
852
853 The @code{\header} is normally at the top of the file, where it sets
854 values for the rest of the file. If you want to typeset different pieces
855 from one file (eg. if there are multiple movements, or if you're making
856 a etude-book), you can put different  @code{\score}
857 blocks into  the input file. ly2dvi will assemble all LilyPond
858 output files into a big document. The contents of \header blocks
859 specified within each score, are used for the titling of each movement.
860 @example
861         opus = "Opus 1.";
862         piece = "Up"; @}
863 @end example
864 For example, the Opus number is put at the right, and the piece string
865 will be at the left.
866
867
868
869 @node Piano music
870 @section Piano music
871
872 Our third subject is a piece of piano music.  The fragment in the input
873 file is a piano reduction of the G major Sinfonia by Giovanni Battista
874 Sammartini.  It was composed around 1740. 
875
876 @lilypond[verbatim]
877
878 \version "1.3.60";
879 \include "paper16.ly";
880
881 viola = \notes \relative c' \context Voice = viola {
882         <c4-\f g' c>
883         \stemDown g'8. b,16
884         s1 s2. r4
885         g
886 }
887
888 oboes = \notes \relative c'' \context Voice = oboe {
889         \stemUp s4  g8. b,16 c8 r <e'8.-\p g> <f16 a>
890         \grace <e8( g> <d4 f> <c2 e> \times 2/3 { <d8 \< f> <e g> <f a> }
891         <
892           { \times 2/3 { a8 g c } \! c2 }
893           \context Voice = oboeTwo {
894                 \stemDown
895                 \grace {
896                     \property Grace.Stem \override #'direction = #-1
897                     [f,16 g] }
898                 f8 e e2
899         } >
900         \stemBoth
901         \grace <c,8( e> <)b8. d8.-\trill> <c16 e> | 
902         [<d ( f> < )f8. a>] <)b,8 d> r [<d16( f> <f8. )a>] <b,8 d> r  |
903         [<c16( e>  < )e8. g>] <c8 e,>
904 }
905
906 hoomPah  = \notes \transpose c' {
907     c8 \translator Staff = top \stemDown 
908     c'8 \translator Staff = bottom \stemUp }
909
910 hoomPahHoomPah = { [\hoomPah \hoomPah] }
911
912 bassvoices = \notes \relative c' {
913         c4 g8. b,16
914         \repeat unfold 4 {\hoomPahHoomPah}
915         \stemDown [c8 c'8] r4
916         <g d'> r4
917         < {\stemUp r2 <e4 c'> <c8 g'> }
918           \context Voice = reallyLow  {\stemDown g2 ~ | g4 c8 } >
919 }
920
921 \score {
922         \context PianoStaff \notes <
923                 \context Staff = top < \time 2/2;
924                         \viola
925                         \oboes
926                 >
927                 \context Staff = bottom < \time 2/2; \clef bass;
928                         \bassvoices
929                 >
930         >
931         \midi { }
932         \paper {
933           indent = 0.0;
934           linewidth = 15.0 \cm; }
935 }
936 @end lilypond
937
938 If it looks like incomprehensible gibberish to you@dots{} Then you are
939 right.  The author has doctored this example to have as many quirks in
940 one system as possible.
941 @example 
942 \version "1.3.61";
943 @end example 
944 Lilypond and the Lilypond language is still under development, therefore
945 it is useful to indicate the Lilypond version of the file. Lilypond 
946 will check the version number and warn you when the syntax has
947 changed. Also, the @code{convert-ly} program will be able to 
948 update most of the syntax changes automatically.
949 @example 
950 viola = \notes \relative c'  \context Voice = viola @{ 
951 @end example 
952 In this example, you can see multiple parts on a staff.  Each part is
953 associated with one notation context.  This notation context handles
954 stems and dynamics (among others).  The name of this context is
955 @code{Voice}.  For each part we have to make sure that there is
956 precisely one Voice context.
957 @example 
958 <c4-\f g' c> 
959 @end example 
960 @code{<} and @code{>} are short hands for @code{\simultaneous @{} and
961 @code{@}}. So the expression enclosed in @code{<} and @code{>} is a
962 chord.  @code{\f} places a forte symbol  under the chord.
963 [FIXME]
964
965 @example 
966    \property Voice.verticalDirection = \down 
967 @end example 
968 @code{verticalDirection} is a property of the voice context. It
969 controls the directions of stems, articulations marks and other
970 symbols.
971
972 If @code{verticalDirection} is set to @code{\down}
973 (identifier for the integer -1) the stems go down,
974 @code{\up} (identifier for the integer 1) makes the stems go up.
975 @example 
976         g'8. b,16 
977 @end example 
978 Relative octaves work a little differently with chords.  The starting
979 point for the note following a chord is the first note of the chord.  So
980 the @code{g} gets an octave up quote: it is a fifth above the starting
981 note of the previous chord (the central C).
982
983 @example 
984 s1 s2. r4 
985 @end example 
986 @code{s} is a `spacer' rest.  It does not print anything,  but it does
987 have the duration of a rest.
988 @example 
989 oboes = \notes \relative c'' \context Voice = oboe @{ 
990 @end example 
991 Now comes a part for two oboes.  They play homophonically, so we
992 print the notes as one voice that makes chords. Again, we insure that
993 these notes are indeed processed by precisely one context with
994 @code{\context}.
995 @example 
996 \stemUp s4  g8. b,16 c8 r <e'8.-\p g> <f16 a> 
997 @end example 
998 @code{\stemUp} is an identifier reference.  It is shorthand for
999 @code{\property Voice.verticalDirection = \up}.  If possible, you
1000 should use predefined identifiers like these for setting properties.
1001 Your input will be less dependent upon the implementation of LilyPond.
1002 @example 
1003 \grace <e8( g> < )d4 f> <c2 e> 
1004 @end example 
1005 @code{\grace} introduces grace notes.  It takes one argument, in this
1006 case a chord.  The slur started on the @code{e} of the chord
1007 will be attached to the next note.@footnote{LilyPond will squirm
1008 about unended Slurs.  In this case, you can ignore the warning}.
1009 @example 
1010 \times 2/3 
1011 @end example 
1012 Tuplets are made with the @code{\times} keyword.  It takes two
1013 arguments: a fraction and a piece of music.  The duration of the
1014 second argument is multiplied by the first argument.  Triplets make
1015 notes occupy 2/3 of their notated duration, so in this case the
1016 fraction is 2/3.
1017 @example 
1018 @{ <d8 \< f> <e g> <f a> @} 
1019 @end example 
1020 The piece of music to be `tripletted' is sequential music containing
1021 three notes.  On the first chord (the @code{d}), a crescendo is started
1022 with @code{\<}.
1023 @example 
1024
1025 @end example 
1026 At this point, the homophonic music splits into two rhythmically
1027 different parts.  We can't use a sequence of chords to enter this, so
1028 we make a `chord' of sequences to do it.  We start with the upper
1029 voice, which continues with upward stems:
1030 @example 
1031  @{ \times 2/3 @{ a8 g c @} \! c2 @} 
1032 @end example 
1033 The crescendo is ended at the half note by the escaped exclamation
1034 mark `@code{\!}'.
1035 @example 
1036 \context Voice = oboeTwo @{
1037 \stemDown 
1038 @end example 
1039 We can't share stems with the other voice, so we have to create a new
1040 @code{Voice} context.  We give it the name @code{oboeTwo} to distinguish
1041 it from the other context.  Stems go down in this voice.
1042 @example 
1043 \grace @{  
1044 @end example 
1045 When a grace section is processed, a @code{Grace} context is
1046 created. This context acts like a miniature score of its own.  It has
1047 its own time bookkeeping, and you can make notes, beams, slurs
1048 etc. Here we fiddle with a property and make a beam.  The argument of
1049 @code{\grace} is sequential music.
1050
1051 @example 
1052 \property Grace.verticalDirection = \down   
1053 [f,16 g] @}
1054   [FIXME]
1055 @end example 
1056 Normally, grace notes are always stem up, but in this case, the upper
1057 voice interferes. We set the stems down here.
1058
1059 As far as relative mode is concerned, the previous note is the
1060 @code{c'''2} of the upper voice, so we have to go an octave down for
1061 the @code{f}.
1062 @example 
1063
1064   f8 e e2
1065 @} > 
1066 @end example 
1067 This ends the two-part section.
1068 @example 
1069 \stemBoth
1070 \grace <c,8( e> <)b8. d8.-\trill> <c16 e> |  
1071 @end example 
1072 @code{\stemBoth} ends the forced stem directions. From here, stems are
1073 positioned as if it were single part music.
1074
1075 The bass has a little hoom-pah melody to demonstrate parts switching
1076 between staffs.  Since it is repetitive, we use identifiers:
1077 @example 
1078 hoomPah  = \notes \transpose c' @{ 
1079 @end example 
1080 Transposing can be done with @code{\transpose}.  It takes two
1081 arguments; the first specifies what central C should be transposed to.
1082 The second is the to-be-transposed music.  As you can see, in this
1083 case, the transposition is a no-op.  Central C is transposed to
1084 central C.
1085
1086 The purpose of this no-op is circumventing relative mode.  Relative
1087 mode can not be used in conjunction with transposition, so relative
1088 mode will leave the contents of @code{\hoomPah} alone.  We can use it
1089 without having to worry about getting the motive in a wrong
1090 octave@footnote{@code{hoomPah = \relative @dots{}} would be more
1091 intuitive to use, but that would not let me plug @code{\transpose}
1092 :-).}.
1093 @example 
1094 c8 \translator Staff = top \stemDown  
1095 @end example 
1096 We assume that the first note will be put in the lower staff.  After
1097 that note we switch to the upper staff with @code{\translator}.  To be
1098 precise, this @code{\translator} entry switches the current voice to a
1099 @code{Staff} named @code{top}. So we have to name the upper staff
1100 `@code{top}'.  Stem directions are set to avoid interfering with the
1101 oboe voices.
1102 @example 
1103 c'8 \translator Staff = bottom \stemUp @} 
1104 @end example 
1105 Then a note is put on the upper staff, and we switch again.  We have
1106 to name the lower staff `@code{bottom}'.
1107 @example 
1108 hoomPahHoomPah = @{ [\hoomPah \hoomPah] @} 
1109 @end example 
1110 Put two of these fragments in sequence, and beam them.@example 
1111 bassvoices = \notes \relative c' @{
1112 c4 g8. b,16
1113 \repeat unfold 4 @{\hoomPahHoomPah @} 
1114 @end example 
1115 Entering the bass part is easy: the hoomPahHoomPah variable is
1116 repeated four times; @code{unfold} means that all four repetitions
1117 should be written out.
1118 @example 
1119 \context Voice = reallyLow  @{\stemDown g2 ~ | g4 c8 @} > 
1120 @end example 
1121 After skipping some lines, we see @code{~}.  This mark makes ties.
1122 @example 
1123 \context PianoStaff 
1124 @end example 
1125 For piano music, a special context is needed to get cross staff
1126 beaming right.  It is called @code{PianoStaff}.
1127 @example 
1128 \context Staff = bottom < \time 2/2; \clef bass; 
1129 @end example 
1130 The bottom staff must have a different clef.
1131 @example 
1132 indent = 0.0; 
1133 @end example 
1134 To make some more room on the line, the first (in this case the only)
1135 line is not indented.  The line still looks very cramped, but that is due
1136 to the format of this tutorial.
1137
1138 This example shows a lot of features, but the organisation isn't
1139 perfect.  For example, it would be less confusing to use a chord
1140 containing sequential music than a sequence of chords for the oboe
1141 parts.
1142
1143 [TODO: demonstrate Hara-Kiri with scores and  part extraction.]
1144
1145 @node  end of tutorial
1146 @section The end        
1147          
1148 That's all folks.  From here, you can either try fiddling with input
1149 files, or you can read the reference manual.