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