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