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