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