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