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