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