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