]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/tutorial.yo
9878ae355045ccbabcb76a1b3dd2225578257eb9
[lilypond.git] / Documentation / tex / tutorial.yo
1 COMMENT(-*-text-*-)
2
3 DEFINEMACRO(var)(1)(whenlatex(latexcommand({\normalfont\scshape )ARG1+latexcommand(}))\
4     whenhtml(sc(ARG1)))
5
6
7
8 COMMENT( This document contains Mudela fragments.  You need at least
9 Yodl-1.30.18 to convert this to tex or html.
10
11 TODO
12
13 need to rethink paper size stuff?
14
15 pipethrough(date) sucks.
16
17 paragraphs have too much space.
18
19 in stead <-> instead
20 )
21
22 COMMENT(
23         Mainly written by Han-Wen Nienhuys, 
24
25         with help of (among others)
26
27         * Jan Nieuwenhuizen
28
29         * Lambert Meertens,
30
31         * Adrian Mariano
32
33         * Mats Bengtsson
34
35 )
36
37 htmlbodyopt(bgcolor)(white)
38 htmlcommand(<font color=black>)
39
40 latexlayoutcmds(
41     \topmargin -0.25in  
42     \textheight 53\baselineskip
43     \advance\textheight by \topskip
44     \marginparwidth 1 in        %   Width of marginal notes.
45     \oddsidemargin 0.25 in      %   Note that \oddsidemargin = \evensidemargin
46     \evensidemargin 0.25 in
47     \marginparwidth 0.75 in
48     \textwidth 5.875 in % Width of text line.
49     \input mudela-book
50 )
51
52 whenlatex(notableofcontents())
53 whentexinfo(notableofcontents())
54
55 article(Mudela, the Music-Definition Language)
56       (Han-Wen Nienhuys and Jan Nieuwenhuizen)
57       (nop()PIPETHROUGH(date "+%B %d, %Y")()()nop())
58
59
60 latexcommand(\def\interexample{})
61 latexcommand(\def\preexample{\par})
62 latexcommand(\def\postexample{\par\medskip})
63 latexcommand(\def\file#1{{code(#1)}})
64
65 whenhtml(
66 nsubsect(Disclaimer)
67 This document is written in url(Yodl)(ftp://pcnov095.win.tue.nl/pub/yodl)
68 and should foremost produce nice LaTeX() output.
69 In other formats, such as html, some things will look a bit different,
70 while other things will be simply left out.
71 Therefore, the authoritive version of this document is the PostScript version, 
72 produced via LaTeX().
73 )
74
75 sect(Introduction)
76 label(tutorial:introduction)
77 latexcommand(\parindent2pc)
78   
79 If you are reading this, you probably are interested in printing
80 music.  LilyPond is a program that can print music from a
81 specification that you, the user, supply.  Using LilyPond may be a bit
82 quaint in the beginning, because you have to give that specification
83 using a em(language).  That might not be what you expect if you are
84 familiar with graphical interfaces.  But there are some big
85 advantages: first, once you master the language, entering music can be
86 done quite efficiently.  Secondly, it is possible to explain exactly
87 what the meaning of a language is, i.e., the semantics are much
88 clearer.  Thirdly, since the program is not interactive, no tradeoffs
89 have to be made between processing speed and beauty of the output.
90
91 This chapter is a gentle introduction to Mudela, the language that
92 instructs LilyPond to typeset music.  We will explain Mudela by
93 presenting a series of examples of Mudela input.  The corresponding
94 output will be shown on the right or below, just as it was produced by
95 LilyPond.
96
97 We will assume that you more or less understand the basics of music notation.  
98 If you are not familiar with the English terms for music notation, you 
99 should consult bind(Appendix)ref(glossary): it contains a glossary 
100 of musical terms along with translations in some other languages.
101
102 If you want to try the examples given here, you should have a 
103 look at bind(Section)ref(sec:running-lilypond) first.
104
105 sect(Music copying, music definition and music entry)
106 label(tutorial:copying-vs-def-vs-entry)
107
108 If you have copied music before, using LilyPond may seem awkward
109 to you in the beginning.  The purpose of LilyPond informally is
110 explained by the term `music typesetter'.
111
112 This may give the impression that the program is like a drawing tool
113 and that it lets you control precisely how the music is formatted.
114 This is not the case: not only does the program print musical symbols,
115 LilyPond also tries to make esthetic decisions---to be precise, we
116 programmed her to do what we find nop(pretty.)footnote(We formed our
117 taste by looking at, and reading all about fine music engraving.  Of
118 course, our taste is also bound by all the accepted rules of common
119 music notation.)  You do not have complete control over what is
120 happening.  Usually that is not a big loss, since good engraving is a
121 very complex trade. In other words, you don't have control, so you do
122 not have to worry about what is happening precisely.
123
124 Secondly, we expect you to enter the meaning of the music, not the
125 sheet music itself.  The input to LilyPond is a music definition,
126 which is something different than notation: notation is a graphical
127 system.  Put more concretely: your input to LilyPond should contain
128 information like ``a dotted quarter note, pitch nop(d)sups(2).''
129 LilyPond will figure out from the musical information that a black
130 note head with a stem but without flag, fourth staff line, with dot
131 should be printed.
132
133 When you are copying music by hand from a printed score, you don't have 
134 to know what the score means; you just copy the symbols.  With LilyPond 
135 such a thing is not possible.  You have to enter the meaning of the 
136 symbols, and this might not always be as easy.  On the other hand, once 
137 entered, any piece of music can be played and transposed automatically.
138
139 Finally, in some spots we will cheat a bit when it comes to musical
140 definition.  Mudela has some entry modes that help to make typing
141 Mudela pleasant.  For example, the phrase ``a dotted quarter note,
142 pitch nop(d)sups(2)'' translates to the following longhand:
143 verb(
144 \musicalpitch { 1 2 0 } \duration { 2 1 })
145
146 This data is what we consider the musical em(definition).  Mudela
147 has a special entry mode where you can conveniently abbreviate this to
148 `code(d''4.)'.  There are some features that also make the quotes and
149 numbers in `code(d''4.)'  superfluous in some cases.
150
151 For those who are curious, the numbers in `code(\musicalpitch { 1 2 0
152 })' example mean octave, notename, and accidental respectively.  The
153 numbers in `code(\duration { 2 1 })' are the (negative) logarithm of the
154 duration (2 is a quarter note, 3 is an eighth note, etc.) and the number
155 of augmention dots respectively.
156
157 sect(When you know the notes to nop(print)ellipsis())
158
159 The basic building block of music is the note.  You can have LilyPond
160 print a note by specifying its pitch and duration.  The pitch of the
161 central C is written as code(c').  This is in line with musicological
162 notation; there this pitch is transcribed as nop(c)sups(1) or c'.  A
163 quarter-note duration is written as code(4).  So, to print a quarter
164 note whose pitch is central C, you enter the following:
165 mudela(fragment,verbatim,center)( c'4 )
166
167
168 subsect(Duration)
169
170 The duration of a note is specified as a number: a whole note is
171 denoted by 1, a half note by 2, a quarter by 4, and so on.  If you
172 want to augment a duration with a dot, simply affix a period to the
173 number.  Here are some random notes to show how it works.
174
175 mudela(fragment,verbatim)(
176   c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64 c'2. c'8. c'16
177 )
178
179 subsect(Basic pitches)
180
181 The pitch code(c') actually consists of two parts: one part for the
182 note name, and one for the octave.  The letter specifies which note
183 name to use: note names simply are the letters code(a) to code(g).
184 The number of apostrophes specifies the octave to use: the central C
185 is denoted by code(c').footnote(By convention, the A above central C
186 at concert pitch is the tone that is used to tune instruments.  Its
187 frequency is about 440 Hz.)  The C which is an eighth higher (the C in
188 the ``two-line octave'') is denoted by code(c''): every octave adds a
189 quote.  A note name without quotes designates the pitch below code(c')
190 (the C in the ``small octave''). If you want to go down even further,
191 commas should be added, e.g., the C in the ``contra octave'' is
192 expressed as code(c,,).footnote(The comma is meant to represent a
193 sunken apostrophe.)
194
195
196 This example demonstrates octaves:
197 mudela(fragment,verbatim,center)(
198    c,,4 c,4 c4 c'4 c''4 c'''4
199 )
200
201 And this example demonstrates notenames:
202 mudela(center,fragment,verbatim)(
203   c'4 d'4 e'4 f'4 g'4 a'4 b'4 c''4
204 )
205
206 A rest can be entered as a note with the special name code(r), e.g.,
207 mudela(fragment,verbatim,center)(r4)
208
209 This already gives us enough material to make simple songs. In
210 bind(Figure)ref(fig:twinkle1) a portion of the traditional song
211 ``Twinkle Twinkle Little Star'' is shown.
212
213 latexcommand(\begin{figure}[h])
214   center(
215 mudela(fragment,verbatim)(
216         c''4 c''4 g''4 g''4
217         a''4 a''4 g''2
218 )
219     latexcommand(\caption{Twinkle twinkle little star (version 1)})
220     label(fig:twinkle1)
221   )
222 latexcommand(\end{figure})
223
224
225 subsect(Alterations)
226
227 We have so far ignored chromatically altered pitches.  The names `a'
228 to `g' for entering pitches are convenient: they are short,
229 pronounceable and they resemble the words for pitches in normal
230 musical vocabulary.
231
232 Enter flats and sharps.  In English there is no standard terse word
233 for C sharp or C flat.  For this reason, we implemented a different,
234 non-English convention for entering altered pitches: a note is made
235 sharp by adding the suffix `--is' to its name, and flat by adding the
236 suffix `--es'.  For a double sharp another `--is' suffix is added, for
237 flats another `--es' suffix. The names for the alterations of C are
238 given in bind(Table)ref(notename-tab).
239
240 latexcommand(\begin{table}[h])
241   center(
242     table(2)(ll)(
243       row(cell(english)cell(LilyPond))
244       rowline()
245       row(cell(c double flat)cell(ceses))
246       row(cell(c flat)cell(ces))
247       row(cell(c natural)cell(c))
248       row(cell(c sharp)cell(cis))
249       row(cell(c double sharp)cell(cisis))
250     )
251   )
252   latexcommand(\caption{Default note names})
253   label(notename-tab)
254 latexcommand(\end{table})
255
256 Variations on this convention are used in a number of germanic
257 languages, notably Dutch, German, Swedish, and Norwegian.  To be
258 precise, LilyPond actually defaults to Dutch notenames, with
259 code(aes), code(aeses), code(ees) and code(eeses) added for
260 consistency.
261
262 Throughout this document we will continue to use the Dutch names.  To make
263 (Dutch) pronunciation easier, the a-flat and e-flat are contracted to
264 code(as) and code(es).  Similarly, the a double flat and e double flat are
265 contracted to code(ases) and code(eses).
266
267 If you are not comfortable with these names, you can make your own.
268 Note names for different languages are included with the example
269 initialisation files, amongst others English (C sharp is abbreviated
270 to code(cs)), Italian, Swedish and Norwegian.  If you want to use
271 these names, you should look at bind(Section)ref(subsect:include) for
272 information on how to use include files.
273
274 sect(Running LilyPond)
275 label(sec:running-lilypond)
276
277 In the previous section some basic elements of Mudela were presented.
278 We didn't want to bore you too much with repetitive details, so we
279 left out some red tape that's needed for a  of Mudela in a form that is accepted
280 by LilyPond.  To
281 be precise, we wrote code(X Y Z), when we really meant
282 verb(\score {
283    \melodic { X Y Z }
284    \paper {}
285 })
286 We will continue to leave out the red tape this, until the time is right to explain what 
287 it means.
288
289
290 Because LilyPond uses a language, it  is a so called em(batch)
291 program.
292 This means, that you use a
293 text editor (such as code(emacs) or code(vi)) to create an input
294 file.  When you are done editing your input file, you save it, and you
295 run LilyPond on the file.  If LilyPond finds any errors in your input file
296 then nop(she)footnote(We're sure that if computer programs could have
297   gender, LilyPond would be a female computer program.  So we will
298   refer to the program as a she. This gender-bending is not to tease
299   you, dear reader.  We do it in real life as well. In the past two
300   years LilyPond has become sort of a baby daughter to us, keeping us
301   awake at night, but also providing us with lots of joy.  We hope you do
302   not mind our little aberration from the traditions of computer-manual
303   writing.) COMMENT( 
304  The name LilyPond is actually sort of a girl's name.  Can you guess which
305  one ?)
306 will complain.  If everything went well, then she'll generate a file, that
307 you can process further to view or print.
308
309 Using LilyPond to print or view some music is a four-step procedure.
310 To get you started we'll run down the full procedure for you.
311
312 enumerate(
313 it()
314 Fire up your favourite editor (if you don't
315 know any editors, try code(joe silly.ly)),
316 and key in the example from bind(Figure)ref(fig:twinkle1), with red tape:
317 verb(
318 \score {
319         \melodic {
320           c''4 c''4 g''4 g''4
321           a''4 a''4 g''2
322         }
323         \paper {}
324 }
325 )
326
327 Save your file as file(twinkle.ly).footnote(The default extension for Mudela
328 files is file(.ly).)
329
330 it()
331 Run LilyPond on your newly created file: enter code(lilypond twinkle).
332 LilyPond will then print all kinds of mumbo jumbo that can safely be
333 ignored.  You might see something like this:
334 verb(
335 GNU LilyPond 0.1.55/FlowerLib 1.1.39
336 Parsing ... [/home/hanwen/musix/spacer/init/lily-init.ly[/home/hanwen/
337
338         ... stuff left out here ...
339
340                               ]  Documentation/twinkle.ly]
341 Interpreting music ...[1] (time: 0.04 seconds)
342 Preprocessing elements... 
343 Calculating column positions ... [2]
344 Approximated: 1 lines, (with an average of 4.0 columns)
345 Time: 0.01 seconds
346 warning: Can not solve this casting problem exactly; revert to Word_wrap
347 [2]Time: 0.00 seconds
348
349 Postprocessing elements...
350 TeX output to twinkle.tex ...
351 )
352
353 All has gone well; there were some warnings but no errors.  The run
354 resulted in output, a TeX file called file(twinkle.tex).
355
356 file(TeX) is usually spelled TeX().  It is a batch program for
357 typesetting text. It was developed by the great programmer and
358 scientist Donald Knuth to typeset his famous bookseries em(The Art of
359 Computer Programming).  As you can see, TeX() can be adapted to do a
360 lot more.  whenlatex(In fact, the document that you are reading now was also
361 produced with TeX().) COMMENT(ugh.)
362
363
364 it()
365   To do something useful with the output you have to run TeX() on it
366   first.  Run the command code(tex twinkle).  The output should resemble this:
367 verb(
368 This is TeX, Version 3.14159 (C version 6.1)
369 (twinkle.tex
370 Babel <v3.6h> and hyphenation patterns for american, dutch, loaded.
371 (/home/hanwen/lib/texmf/tex/lilypond/lilyponddefs.tex
372 (/home/hanwen/lib/texmf/tex/lilypond/dyndefs.tex)
373 (/home/hanwen/lib/texmf/tex/lilypond/fetdefs.tex
374 (/home/hanwen/lib/texmf/tex/lilypond/feta20.tex)
375 (/home/hanwen/lib/texmf/tex/lilypond/lily-ps-defs.tex))) [1] )
376 Output written on twinkle.dvi (1 page, 3084 bytes).
377 Transcript written on twinkle.log.
378 )
379   The human translation is ``everything went OK, the result is one
380   page long, and I put it in file(twinkle.dvi).''
381
382 it()The file(twinkle.dvi) file is a description of how a piece of
383 text looks when it is printed.  You can view it, or print it.  If you
384 are using a Unix system equipped with X-Windows, then you can issue
385 the command file(xdvi twinkle) to view the result.  If this is not the
386 case, consult your local TeX() guru on printing and viewing DVI files.
387 What is in your window should approximately look like this:
388 mudela()(
389 \score {
390         \melodic {
391           c''4 c''4 g''4 g''4
392           a''4 a''4 g''2
393         }
394         \paper { linewidth = 13.\cm; }
395 }
396 )
397
398 it()
399 If you want to print file(twinkle.dvi), you should invoke the command
400 code(dvips twinkle).  Running this command should generate a
401 PostScript file called file(twinkle.ps).  This file can be printed on
402 any PostScript compatible printer.  You should not use any other
403 tools: the output from LilyPond contains fragments of PostScript which
404 will not print correctly if you don't use PostScript.  If your printer
405 doesn't understand PostScript, you should check out GhostScript, a
406 PostScript emulator.
407 )
408
409
410
411 The four-pass procedure sketched above is a bit clumsy.  Moreover, the
412 result is pretty crude: the page does not include prettily printed
413 titles and if you are unlucky, the margins don't come out well.  Jan
414 Arne Fagertun wrote a tool to take the above steps out of your hands,
415 make neat margins and print titling.  The tool is called file(ly2dvi),
416 and it should be on your system if you use Lily on a Unix platform.
417 If you use file(ly2dvi), then you can do verb(ly2dvi twinkle.ly ) in
418 stead of steps 2 and 3.  You will feel the real advantage of using
419 file(ly2dvi) when you add titling to the music.  This is something
420 that we will discuss in bind(Section)ref(tutorial:titling).
421
422
423 COMMENT(This document does not cover all of Mudela.  Due to technical details,
424 the precise working of Mudela is coupled to the innards of LilyPond.
425 If you really want to know all the details, your best bet would be to
426 get the sources to LilyPond and read the parser and scanner source.
427 They are in file(lilypond-x.y.z/lily/parser.yy) and
428 file(lilypond-x.y.z/lily/lexer.ll).)
429
430
431
432 sect(Chords)
433
434 Up till now we have only considered music that was rather simple.  All
435 the music had notes going in one direction, from left to right, one
436 note following the other.  You might be wondering if this is all Lily
437 can do, or whether it is possible to stack notes as well (creating
438 em(chords)).  Rest assured: we designed LilyPond while keeping in mind
439 that she must be able to handle any notation construct that can be
440 expressed conveniently.  Of course we did not leave out chords.
441
442 In Mudela you can form a chord of several notes by enclosing them in
443 pointed parentheses, bind(i.e.)bind(langle())bind(and)rangle().  ASCII
444 doesn't really have these delimiters, so Mudela uses the larger-than
445 (code(>)) and smaller-than (code(<)) signs instead.  For example, a
446 D-major nop(chord)footnote(Recall what was said in the previous
447 section about flats and sharps: the word code(fis) means an f sharp.)
448 can be described by the following fragment:
449 mudela(fragment,verbatim,center)(
450   <d'8  fis'8 a'8 d''8>
451 )
452
453   Chords can be entered in the music in the same places that notes
454 can.  As an example we give a snippet of ``Twinkle Twinkle Little
455 Star'' in chords.  The chords may seem, slightly unconventional, but they
456 only serve to show how chords work.  We've aligned the chords
457 in the input on their starting beat just to help you reading it.
458 This layout does not influence the typesetting result in any way.
459
460 mudela(verbatim, fragment)(
461   c''4             c''4              <c''4 g''4>       <c''4 e''4 g''4>
462   <c''4 e''4 a''4> <b'4 d''4 a''4>   <b'2 d''2 g''2>
463   <a'4 d''4 f''4>  <bes'4 d''4 f''4> <bes'4 c''4 e''4> <g'4 c''4 e''4>
464   <e'4 a'4 d''4>   <a4 g'4 cis''4>   <d'2 f'2 d''2>
465 )
466
467
468
469 sect(Shortcuts for duration)
470
471 If you typed the last example into a Mudela file, you will have
472 noticed that the input has lots of repetitions.  You will probably
473 have made some errors with the right durations and number of
474 octavation quotes.
475 To save keystrokes and prevent errors Mudela
476 has some handy shortcuts.  The simplest is the shortcut for
477 durations.  You don't have to type the duration if it
478 is the same as the last duration entered.  This saves a considerable
479 number of keystrokes, and thus reduces the potential for errors.  The
480 previous example can be reduced to verb(
481   c''4          c''            <c'' g''>        <c'' e'' g''>
482   <c'' e'' a''> <b' d'' a''>   <b'2 d'' g''>
483   <a'4 d'' f''> <bes' d'' f''> <bes' c'' e''> <g' c'' e''>
484   <e' a' d''>   <a g' cis''>   <d'2 f' d''>
485 )
486
487
488 If you entered this, you probably made some little errors with the
489 right amount of quotes as well.  To remedy this, mudela has another
490 feature called `relative octaves', which reduces the number of quotes
491 needed.  If you want to enter large pieces of music em(now) we
492 recommend you make an excursion to
493 bind(Section)ref(sec:relativeoctaves) and learn about relative
494 octaves.
495
496
497
498 sect(Comments)
499
500 If you want to make some private notes about the Mudela code that you
501 entered, you can do so by inserting comments into your file.  The
502 contents of these comments are ignored by LilyPond.  Mudela has two  comment
503 styles: line comments and block comments.  The line comment
504 is introduced by the percent sign:
505 verb(
506   c''4
507   c''4   % shouldn't this be a different pitch?
508 )
509
510 Block comments are enclosed in code(%{) and code(%}).
511
512 verb(
513   c''4
514         %{
515         Ludwig van Bavaria's  original manuscript has an fffff dynamic sign.  
516         Clearly one can see the onset of paranoid schizophrenia in the
517         composer from these subtle nuances in his writings.
518         %}
519   c''4 
520 )
521
522
523 sect(Adding nuances: articulation and dynamics)
524
525 Having just chords and notes does not give you real music.  Real music
526 has more liveliness to it: music can have articulation, dynamics
527 (louder and softer), etc.  This liveliness has notation, so LilyPond
528 can print it.  We'll start out by explaining how to obtain the
529 smallest grains of nuance: the articulation of a single note.  Articulation
530 is entered by writing a dash and the name of the desired articulation
531 mark.  You have to add a backslash in front of the name to distinguish
532 it from the name of a note.  mudela(fragment,verbatim)(
533   c''4-\staccato
534   c''4-\tenuto )
535
536 Typing a lot of staccato notes in this syntax will get tedious very
537 quickly.  Therefore, Mudela has some handy abbreviations for
538 articulation marks such as staccato and tenuto.  They are shown in the
539 following example:
540
541 mudela()(
542 \score{ \melodic {
543         \property Voice.textstyle = typewriter
544         c''4-._"c''4-." s4
545         c''4--_"c''4--"  s4
546         c''4-+_"c''4-+" s4
547         c''4-|_"c''4-|" s4
548         c''4->_"c''4->"  s4
549         c''4-^_"c''4-\\^{ }"  s4 }
550         \paper { linewidth = 12.\cm; }})
551
552
553
554 Text and digits for fingering can be entered in the same manner: add a
555 dash and the text or digit to be printed:
556 mudela(fragment,verbatim)(
557   c''4-1 g''4-5 c''-"Sul tasto" )
558 Currently, the meaning of the
559 syntax `note-dash-digit/articulation/text' is just ``add a superscript to this
560 note.''  This is not in line with our goal to em(define) music with
561 Mudela.  We hope that this will be fixed in a future version of the
562 language.  In the meantime you can abuse this: the super- and
563 subscripts can be forced into up or down position respectively by entering an
564 a caret (code(^)) or an underscore, code(_) instead of the dash:
565 mudela(fragment,verbatim,center)(
566   c'4-^ c'4^^ c'''4-^ c'''4_^
567 )
568
569 Dynamic markings are another way to add a nuance to a note.  They are
570 entered by adding the name for the dynamic sign after the note.  You
571 should not enter a dash between the name and the note.footnote(This
572   is inconsistent.  We hope that this will be fixed in a later
573   version of the language.)
574 mudela(verbatim,fragment)(
575   c4 \ff c4 \fp c4 c4 \ppp c4 c4 \sfz
576 )
577 COMMENT(UGH)
578
579 sect(Bridging the notes: beams, slurs and ties)
580
581 Up till now most of the typesetting concerned simple fixed symbols
582 only.  Now we turn to variable symbols: symbols that run from one note
583 to another. In LilyPond terminology, such a symbol is called a
584 em(spanner).  To print a spanner, you have to attach a marker to the
585 note that begins it and to the one that ends it.
586
587
588 The first example of such a symbol is the slur.  For the slur, the
589 start marker is the opening parenthesis. It won't be a surprise that
590 the stopping marker is the closing parenthesis.
591 For example:
592 mudela(fragment,center,verbatim)( c'4( )c'4 )
593
594 otice that the parentheses should be between the notes.footnote(The
595 location of the parentheses might be changed in a future version of
596 the language.)
597
598 It is your job to make sure that each slur that you start also ends.
599 If it doesn't end, then Bad Things are likely to happen.  The slur is
600 quite flexible: you can nest nop(slurs,)footnote(This is inconsistent when
601 compared to the syntax for articulation hints.  This will probably be
602 fixed soon.) and you can connect a note with a slur on both the left and the
603 right side:
604
605 mudela(fragment,verbatim,center)(
606   c'4((   )c''4 )c'4( )g'4 
607 )
608
609 Another spanner is the beam (see bind(Figure)ref(mud:beam)).  It
610 indicates the duration of the connected notes, and thus it acts like an
611 extended version of the flag.  Secondly, the pattern of
612 left/right-pointing beams hints at the metric structure of the
613 measure.
614
615
616 latexcommand(\begin{figure}[h])
617   center(
618     mudela(fragment)([c'8 c'8] [c'16 c'16 c'16 c'16] [c'16. c'32 c'32 c'16.] )
619     latexcommand(\caption{Some beams})
620     label(mud:beam)
621   )
622 latexcommand(\end{figure})
623
624
625 Strictly speaking, a beam is not a musical concept.  The pattern of a
626 beam can be derived from the structure of the time signature and the durations
627 of the notes. It is merely a device that helps you understand the
628 rhythms notated. Unfortunately, LilyPond is not smart enough to insert
629 beams into your music on her own. You will have to instruct her by
630 marking the starting and stopping point of the beam with `code([)' and
631 `code(])' respectively, e.g.
632
633 mudela(fragment,verbatim,center)(
634   [g'8 g'8]
635 )
636
637 LilyPond has code that guesses what the pattern should look like, so
638 that you don't have to specify the beaming for complicated
639 patterns.footnote(Unfortunately the algorithm used is not foolproof yet:
640   code([c8. c32 c32]) will produce incorrect results.)
641
642 Again, it is your responsibility to make sure that you end every beam
643 that you start.
644
645 A third spanner is similar to the slur: the tie.  The tie looks like a
646 slur, but a slur connects whole chords, whereas the tie connects
647 note heads.  Tied notes should be played as one long note.
648 In analogy with TeX()'s tie (which  ties together words with a
649 space), LilyPond's tie is entered as a tilde, ~.  
650 mudela(verbatim,center,fragment)(c''1 ~ c''4)
651
652 The input convention for the tilde is somewhat peculiar when used in
653 conjunction with chords.  Internally, the extra information that is
654 represented by the tilde has to be attached to a note (or to a rest,
655 for that matter).  For this reason, you can't put the tilde between
656 two chords (as in code( <c' g'> ~ <c' g'>)).  The tilde sign must be
657 directly after a note of the chords.  It does not matter which
658 one. The following example demonstrates this:
659 mudela(fragment,verbatim,center)(
660   <c'1 ~  g' es''> <c'4 g' es''> 
661 )
662
663 sect(Commands)
664 label(sec:commands)
665
666 Up till now, we only printed notes, and correspondingly only entered
667 notes. But notation contains many other constructs, constructs that
668 help you with reading those notes.  Examples of such constructs are
669 clefs, time signatures, keys etc.
670
671 If you look carefully at the example in
672 bind(Figure)ref(fig:twinkle1), you will notice that the output
673 includes some bar lines and clefs, and that there are no references to
674 those in the input.  They were generated automatically.
675
676 Not all such hints can be inserted automatically, and you can also
677 override some of the settings.  This can be done by inserting various
678 commands between the music.  The general form of these commands is
679 center(
680   em(keyword) sc(arguments)
681 )
682
683 em(keyword)s are words that have a special meaning to the parser of
684 Mudela.  Because the parser must be able to distinguish the keywords
685 from note names, they have to be preceded by a so-called escape
686 character, the backslash, `code(\)'.  To separate the arguments from
687 any notes that might follow the arguments, you have to end your
688 command with a semicolon.  An added benefit of this construction is
689 that the commands stand out between your notes, because of the
690 backslashes.
691
692 So the general form actually is `code(\keyword argument argument ... ;)'
693 Let us review these commands:
694
695 description(
696 dit(code(\clef) var(clefname)) This command sets the current clef for notation,
697   i.e., a clef symbol is printed and the notes following this command
698   are shifted vertically.  The argument is a string, the name of the
699   new clef. The default clef is the treble clef.
700   mudela(fragment,verbatim)(
701     \clef "bass"; c'4
702     \clef "treble"; c'4
703     \clef "alto"; c'4    
704   )
705 dit(code(\key) var(pitch)) This command changes the current key signature.  The
706   key signature is printed at the start of every line.  The argument
707   is the name of the corresponding major key.  The key of C-minor can 
708   thus be specified as `code(\key es)'.
709   
710 dit(code(\keysignature) var(pitchlist))
711
712 This command changes the current key signature.  Unlike the
713 `code(\key)' command, this command can produce arbitrary key
714 signatures, which can be useful for unconventional keys or modes.  The
715 key signature is given in the form of a list of notes.  The notes will
716 be printed in the key signature in the order that they appear on the list.
717 For example, the key
718 of C-minor can be specified as `code(\accidentals bes es as)'.  The
719 command `code(\accidentals fis es bis)' provides a more exotic
720 example.
721
722
723 dit(code(\time) var(numerator)code(/)var(denominator))
724   This command changes the current time signature.  LilyPond uses the
725   time signature to
726   calculate where to place the bars that start a measure.  These bars
727   in turn are the places where a system can be broken into lines.
728
729   The default value for this time signature is common time (4/4).  You
730   can also tell this from the  Twinkle ``Twinkle Little
731 Star'' example in bind(Figure)ref(fig:twinkle1).  This
732 song actually has a 2/4 time signature, so a metrically more correct
733   version  would start with as follows:
734   mudela(fragment,center,verbatim)(
735     \time 2/4;  c'4 c'  g' g' 
736   )
737
738
739 dit(code(\cadenza) var(togglevalue)) When typesetting music without a
740 regular meter (such as an ad libitum cadenza), no bar lines should be
741 printed.  In LilyPond you can achieve this by issuing the command
742 `code(\cadenza 1)': it turns off the automatically
743 generated bar lines.
744
745 You switch them on again with `code(\cadenza 0)', and then a bar line
746 is printed.  LilyPond will act as if you are again at the start of a
747 measure.
748
749 dit(code(\bar) var(bartype))
750   This command lets you print special bar
751   lines and repeat symbols.  You can also use it to allow line breaks
752   when entering cadenzas.  The argument var(bartype) is a string that
753   describes what kind of bar line to print.
754
755 mudela(fragment,verbatim)(
756     \bar "|:"; c'4 \bar ":|:";    c'4  \bar ":|";  c'4 \bar "||";
757     c'4 \bar "empty"; c'4 \bar "|.";
758 )
759   The command `code(\bar "empty")' does not create any visible bar
760   line, but it does tells LilyPond to allow a linebreak
761   at that position.  The `code(\bar)' command prints the specified
762   symbol immediately.  If you give a `code(\bar)' command at the end
763   of a measure then
764   the specified symbol replaces the automatic bar line; otherwise
765   the specified symbol appears in the middle of the measure.   The
766     code(\bar) command does not affect metric structure.
767
768
769   
770 dit(code(\partial) var(duration)) some music starts with a measure that
771 isn't fully filled, a so-called upstep.  The code(\partial) command
772 allows you to make
773 upsteps. The argument is a duration similar to the duration of a note.
774 The `code(\partial)' command cannot be used to generate partial
775 measures in the middle of the music.  
776 Example:
777   mudela(fragment,verbatim)(
778     \time 4/4;
779     \partial 4;
780     [d'8 dis'] e' c''4 e'8 c''4 
781   )
782
783   dit(code(\grouping) var(durationslist)) sets the metric structure of the measure.
784     Its effect can best be shown by an example:
785     mudela(fragment,verbatim)(
786         \time 5/16;
787         \grouping 16*3 16*2;
788         [c'8 c'16 c'8]
789         \grouping 16*2 16*3;
790         [c'8 c'16 c'8]
791         \grouping 16*5 ;
792         [c'8 c'16 c'8]
793     )
794
795 In practice, you won't be needing this command very often: the
796 grouping is switched automatically when you issue a code(\time)
797 command.  It is set to a combination of groups
798 of 2 and 3 beats, with as many groups of
799 3 as possible (in other words: 4/4 is divided in two times two beats
800 (2+2), 8/8 in 3+3+2)
801 )
802
803 The commands that are described above aren't really music, but they
804 can be used in the same places as notes.  This makes the grammar of the
805 language simpler.  It is possible to put a command into a chord.
806 For example, the following two snippets of Mudela produce identical output.
807 verb(
808   <c4 e g \time 2/4;>
809   \time 2/4; <c4 e g>
810 )
811
812
813
814 sect(Complex music: more than one staff)
815 label(tutorial:more-staffs)
816
817
818 Now we explain how to typeset music that runs in multiple staffs.
819 Consider the following---somewhat unrealistic---example:
820
821 mudela(fragment)(
822  \type GrandStaff <e'4 {\clef bass; g4^""} >
823 )
824
825   The music consists of two notes.  Perhaps this is sheet music for a
826 piano player, and one note is meant to be played with the left hand,
827 and the other with the right hand.  That music would sound the same if
828 it were written as a single chord on a single staff, i.e.,
829 mudela(fragment)(
830   <g4 e'4>
831 )
832
833
834 This is another example where we can see that there can be a difference
835 between a musical idea, and the way it is expressed in notation.
836
837 The Mudela construct for multiple staffs reflects the similarity
838 between the two examples: to get multiple staffs in Mudela you enter a
839 chord, with an additional instruction to tell LilyPond that the chord
840 does not represent notes stacked together, but staffs stacked
841 together.
842
843 If a piece of music is to be interpreted as a staff, then this can be
844 expressed with the code(\type) construct.  The following input says
845 ``the quarter note with pitch e should be put on a staff.''
846
847 verb(
848   \type Staff e'4 
849 )
850
851 The same can be done for the other note, i.e.,
852
853 verb(
854   \type Staff g4 
855 )
856
857 If you want to stack these staffs, you must create a chord of both:
858
859 verb(
860   < \type Staff e'4
861     \type Staff g4 
862   >
863 )
864
865 This looks reasonable, but the effect of this input is not what you
866 might expect (try it!).  When interpreting this chord LilyPond will
867 start with the first entry.  She'll look for a (nameless) staff.  Such a
868 staff is not found, so it is created.  On this staff the code(e) note
869 is put.  When the second code(\type) entry is read, LilyPond will
870 start looking for a nameless staff.   The  staff that contains  the
871 code(e) is found, and the code(g) is put there as well.
872
873 The correct solution is to label both code(\type) constructs with
874 different names, for example code(trebleStaff) and code(bassStaff).
875 This makes LilyPond distinguish between them, and create two staffs:
876
877 mudela(verbatim,fragment)(
878   < \type Staff = trebleStaff e'4
879     \type Staff = bassStaff  g4 
880   >
881 )
882
883 The names that you choose do not matter just as long as they are
884 different.  This is almost right, except for the brace at the left and
885 the clef of the second staff.  The bass clef will be taken care of in
886 the next section. If you want a brace, then you have to tell LilyPond
887 that the chord you just formed is to be interpreted as a so-called
888 grand staff.  This is also done with the code(\type) command.
889 mudela(verbatim,fragment)(
890   \type GrandStaff <
891      \type Staff = treblestaff  e'4 
892      \type Staff = bassstaff  g4 
893   >
894 )
895
896 sect(Appending instead of stacking: sequential music)
897 label(tutorial:voice)
898
899 The previous section dealt with a pretty hypothetical situation: sheet
900 music with two staffs and each staff containing only one single note.
901 In real-life situations staffs contain more than one note.  They
902 contain music that has to be played in sequence.  A staff can contain
903 a em(voice).  We haven't learned  how to make a voice yet: we need a
904 new construct to express this notion of `voice'.
905
906 The construct is called em(sequential) music.  A list of musical
907 objects (e.g., notes, chords or commands) can be made into sequential
908 music by enclosing the list in braces; for example:
909
910 mudela(fragment,verbatim,center)(
911   { c'4 c'4 }
912 )
913 mudela(fragment,verbatim,center)(
914   { <c'4 e'> <e' g'> }
915 )
916
917
918 We could have called this construct more colloquially `voice', but
919 this would cause confusion later on, when a second kind of voice
920 enters the scene.  Similar confusion might arise from the word
921 `chord', therefore from now on, we will talk about `simultaneous
922 music', when we refer to items enclosed in < and >.
923
924
925 The notion of a em(new) construct needs some explanation: we have been
926 using sequential music all the time, except that it was hidden in the
927 red tape in bind(Section)ref(tutorial:introduction).
928
929
930
931 If we want to put whole voices onto a staff, then we have to
932 substitute sequential music for the single notes in the example from
933 the previous section.  A code(\clef) command in the second piece of
934 sequential
935 music  will also set the clef in
936 the bass staff.
937 mudela(fragment,verbatim)(
938     \type GrandStaff <
939      \type Staff = treblestaff  { e'4 f'}
940      \type Staff = bassstaff  {\clef "bass"; g a }
941   >
942 )
943
944 COMMENT(You can nest simultaneous music and chords in any way you want.  If
945 you are interested in the entire story, you should consult
946 bind(Chapter)ref(chap:features), which has a grammar in
947 bind(Section)ref(sec:grammar).)
948
949 sect(Notation context)
950
951 This section is about translation contexts, a topic of LilyPond that
952 is somewhat advanced.  You don't have to understand this to use
953 LilyPond to print simple music.  If you don't want to typeset fancy
954 polyphonic music or tweak the LilyPond notation engine, you can skip
955 the next two sections.
956
957 In bind(Section)ref(tutorial:more-staffs) it was explained, that there
958 are more ways to notate a simple chord: as a single voice on a single
959 staff or in multiple staffs (and we'll soon see, that you can typeset
960 it as multiple voices on a  staff).  Obviously the concept of staff is not
961 really something musical.  But what is it then?
962
963
964 The most simplistic explanation is: a staff is a peculiarity of the
965 notation system.  In other words, a staff is a graphic device, a
966 special picture of five lines on which one can print note heads.  To
967 avoid confusion, we will call this view on the concept of staff
968 `staff symbol' from now on.
969
970
971 There is more to it than meets the eye and mind.  A staff
972 contains---besides a staff symbol--- some more components:
973 itemize(
974 it()A staff can a have a key signature (printed at the left)
975 it()A staff has bar lines
976 it()A staff has a clef (printed at the left)
977 )
978 To explain what a staff really is,   we'll try to print music without
979 these components.  If these components aren't printed, it is still
980 possible to print music:
981 mudela()(\score{
982 \melodic \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
983 \paper { 
984   linewidth = -1.;
985   Staff = \translator {
986     \type "Line_group_engraver_group";
987
988     defaultclef = violin;
989
990     \consists "Timing_engraver";
991     \consists "Separating_line_group_engraver";
992
993     \accepts "Voice";
994   }
995  }
996 })
997
998 As you can see, one can still make out the general form of the melody
999 and the rhythm that is to be played, but the notation is difficult to
1000 read and the musical information is not complete.  The stress pattern
1001 in the notes can't be deduced from this output.  For this, we need a
1002 time signature:
1003
1004 mudela()(
1005 \score {
1006   \melodic \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
1007   \paper{
1008   linewidth = -1.;
1009     Staff = \translator {
1010     \type "Line_group_engraver_group";
1011     defaultclef = violin;
1012     \consists "Time_signature_engraver";
1013     \consists "Separating_line_group_engraver";
1014     \accepts "Voice";
1015   }
1016  }
1017 })
1018
1019 Technically speaking you know where the strong and weak beats are, but
1020 it is difficult to find them quickly.   Bar lines  help you in finding
1021 the location within the measure of the notes:
1022 mudela()(
1023 \score {
1024   \melodic \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
1025   \paper{
1026   linewidth = -1.;
1027     Staff = \translator {
1028     \type "Line_group_engraver_group";
1029     defaultclef = violin;
1030     \consists "Bar_engraver";
1031     \consists "Time_signature_engraver";
1032     \consists "Separating_line_group_engraver";
1033     \accepts "Voice";
1034   }
1035  }
1036 })
1037
1038 We can remedy part of the difficulties with reading pitches by adding a staff
1039 symbol:
1040
1041 mudela()(\score{
1042   \melodic\relative c' { \time 2/4; g'4 c,4
1043 a'4 f4 e c d2 } \paper {
1044   linewidth = -1.;
1045   Staff = \translator {
1046     \type "Line_group_engraver_group";
1047
1048     defaultclef = violin;
1049     \consists "Bar_engraver";
1050     \consists "Time_signature_engraver";
1051     \consists "Staff_sym_engraver";
1052     \consists "Separating_line_group_engraver";
1053
1054     \accepts "Voice";
1055   }
1056  }
1057 })
1058
1059 This makes the output decidedly easier to read, but you still don't
1060 know what the pitches of the notes above are.  So this is still not
1061 enough.  But suppose you see the following notation:
1062 mudela()(\score {
1063   \melodic \relative c' {\clef alto;  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
1064 \paper {
1065   linewidth = -1.;
1066   Staff = \translator {
1067     \type "Line_group_engraver_group";
1068
1069      defaultclef = violin;
1070     \consists "Bar_engraver";
1071     \consists "Time_signature_engraver";
1072      \consists "Clef_engraver";
1073      \consists "Staff_sym_engraver";
1074      \consists "Timing_engraver";
1075      \consists "Separating_line_group_engraver";
1076
1077     \accepts "Voice";
1078   }
1079  }
1080 })
1081
1082 Now you know the pitch of the notes: you look at the start of the line
1083 and see a clef, with this clef, you can determine the notated pitches.
1084 You have found the em(context) in which the notation is to be
1085 interpreted!
1086
1087 So the context determines the relationship between a piece of music
1088 and its notation: you, the reader, use context to deduce music from
1089 notation.  Because LilyPond is a notation ``writer'' instead of a
1090 reader, context works the other way around for Lily: with context a
1091 piece of music can be converted to notation.
1092 The components of a staff form context, and context is needed to read
1093 and write notation.  This motivates the following definition.
1094
1095 quote(
1096 A bf(notation context) is  a conversion from music to notation.
1097 )
1098
1099 The example focused mainly on on staffs, but a staff is not the only
1100 type of notation context.  Notation contexts may be nested: you can
1101 print polyphonic music by putting multiple `Voice' contexts in one
1102 `Staff' context.  The arguments of the code(\type) command (Staff,
1103 GrandStaff) were in fact all names of different contexts.
1104 The notions of ``current clef'' and ``current position within the
1105 measure'' are all properties of notation contexts.  Commands like
1106 code(\clef) and code(\cadenza) change these properties.  
1107
1108
1109 The following is a list of the contexts that are supported by
1110 LilyPond:
1111 description(
1112
1113 dit(Voice) The code(Voice) context is a context that corresponds to a
1114   voice on a staff.  This context handles the conversion of noteheads,
1115   dynamic signs, stems, beams, super- and subscripts, slurs, ties and rests
1116
1117 dit(Staff) The code(Staff) context handles clefs, bar lines, keys,
1118   accidentals.  A code(Staff) context can contain multiple code(Voice)
1119   contexts.
1120
1121 dit(RhythmicStaff) The code(RhythmicStaff) context is like the staff,
1122   but much simpler: the notes are printed on one line, and pitches are
1123   ignored.  code(RhythmicStaff) can contain code(Voice) contexts.
1124
1125 dit(GrandStaff) A code(GrandStaff) context contains code(Staff)
1126   contexts, and it adds a brace to the output at the
1127   nop(left.)footnote(This is a major deficiency in the current
1128   implementation.    Currently stems,
1129   slurs and beams cannot be printed across two staffs.
1130 In reality, a grand staff is  a hybrid of one big staff and two stacked staffs.)
1131   
1132   A code(GrandStaff) context can contain multiple
1133   code(Staff)s. Typically, it will contain two code(Staff)s, one
1134   treble staff, and one bass staff. The bar lines of the contained
1135   staffs are connected vertically.
1136
1137 dit(StaffGroup) A code(StaffGroup) context contains code(Staff) or
1138   code(Lyrics) contexts, and prints a bracket at the left.  The bar
1139   lines in the participating staffs are connected.
1140
1141 dit(Lyrics) As its name suggests, The code(Lyrics) context deals with
1142   typesetting lyrics.  This topic will be covered in
1143   bind(Section)ref(tutorial:lyrics).
1144   
1145 dit(Score) The code(Score) context is the toplevel context: no context can
1146   contain a code(Score) context.  The code(Score) context handles the
1147   administration of time signatures.  It also makes sure that items
1148   such as clefs, time signatures, and key-signatures are aligned across staffs.
1149   
1150   The code(Score) can contain code(Staff), code(StaffGroup), code(Lyrics), code(GrandStaff) and
1151   code(RhythmicStaff) contexts.
1152
1153 COMMENT(do ChoireStaff)
1154 )
1155
1156
1157   Later on, in bind(Section)ref(tutorial:engravers) we will
1158 explain how you can create your own contexts.
1159
1160 If you are familiar with structured documents (like HTML, SGML or
1161 LaTeX()), you might see the analogy of a context with a stylesheet: a
1162 stylesheet is neither presentation nor information, but rather a
1163 recipe em(how) a specific piece of information should be presented.
1164 Analogously, a notation context is neither music nor notation, but the
1165 conversion between the two.  The big difference with text is that in
1166 music notation the elements provided by context are essential to
1167 understanding what is notated.
1168
1169
1170
1171 sect(Polyphonic music (or: Notation context properties))
1172
1173 In the last section we explained that a notation context can have
1174 properties that influence the conversion from music to notation.  A
1175 simple example of such a property is the clef: the type of clef partially
1176 determines the vertical position of note heads in a staff.  Some of
1177 these properties can be modified by commands such as code(\clef) and
1178 code(\time).   But there is more:  notation contexts  also have
1179 properties are settable in a generic fashion.  We will demonstrate
1180 this feature by printing multiple voices on a staff.
1181
1182 In polyphonic (keyboard) music and orchestral scores often more than
1183 one voice is printed on one staff.  We'll explain how to achieve this
1184 effect with LilyPond.  The effect is not unlike the two stacked staffs
1185 from bind(Section)ref(tutorial:more-staffs), except that we don't want
1186 to stack staffs but voices.  Thus,  the general template is the following:
1187 verb(
1188   \type Staff <
1189     \type Voice = one  ...
1190     \type Voice = two  ...
1191   >
1192 )
1193
1194 On the ellipsis there should be music going from left to right, in
1195 otherr words, there should be sequential music, notes enclosed in
1196 braces.  Let us try the following simple melodies:
1197
1198 mudela(fragment,verbatim)(
1199 \type "Staff" <
1200   \type "Voice" = "one" { r4 as'4 () as'4 g'4 }
1201   \type "Voice" = "two" { g'2 f'4 e'4 }
1202 >)
1203
1204 As you can see the result is not quite perfect.  The notes on the last
1205 two beats look like plain chords and not like separate voices.  What
1206 really happened was that the stems of the upper and lower voices were
1207 printed on top of each other.  If you have tried running this example, you will probably
1208 have noticed a complaint  about ``too many
1209 clashing notecolumns''  during the LilyPond run.
1210 This complaint refers to the overlapping stems.
1211
1212 To remedy this, engravers traditionally make the stems of the upper
1213 and lower voice point in different directions: the stems of the lower
1214 voice point down, and the stems of the upper up, as shown in
1215 bind(Figure)ref(tutorial:multi-voice-fig).
1216
1217 Surely the direction of a single stem is a property of the stem as a
1218 graphical object.  But the fact that all of the stems in a voice point
1219 in the same direction is not directly graphical.  Since this is a
1220 property shared by all the stems in the voice, it is logical to
1221 consider this property to be a property of the context code(Voice).
1222 And this is how it's done in LilyPond: the context code(Voice) has an
1223 attribute whose value is the direction to use
1224 for stems.  You can change it to `up'
1225 by issuing the following phrase:footnote(The name code(ydirection) is
1226 no mistake.  The property also controls the up/down directions of
1227 super-/subscripts, slurs, ties, etc.)
1228
1229 verb(
1230   \property "Voice"."ydirection" = "1"
1231 )
1232
1233 This command should be read as ``change the property called
1234 code(ydirection) within the current code(Voice) context to the value
1235 code(-1).''  For the property code(ydirection) the value code(1) means
1236 `up', and code(-1) means `down'.   The proper way to code the
1237 polyphonic example is given in bind(Figure)ref(tutorial:multi-voice-fig).
1238
1239 latexcommand(\begin{figure}[h])
1240 mudela(fragment,verbatim,center)(
1241   \type "Staff" <
1242     \type "Voice" =  "one"  {
1243       \property Voice.ydirection = "1"
1244       r4 as'4 () as'4 g'4 }
1245     \type "Voice" =  "two"  {
1246       \property Voice.ydirection = "-1"
1247       g'2 f'4 e'4 }
1248   >
1249 )
1250     latexcommand(\caption{multiple voices})
1251     label(tutorial:multi-voice-fig)
1252 latexcommand(\end{figure})
1253
1254 Other properties can also be set, and they can be within different
1255 contexts.  In general, you can set a property by specifying
1256 code(\property) var(contexttype)code(.)var(propertyname) code(=)
1257 var(value).  Both var(ContextType), var(PropertyName) and var(Value)
1258 should be strings.
1259
1260 The effect of a property is pretty much hardwired into the
1261 implementation (and thus subject to change), so we will not deal with
1262 all the possible properties in detail. Among other characteristics that
1263 can be set are the layout of slurs and beams.  The initialisation file
1264 file(property.ly) explains most properties.
1265
1266 We conclude this section with another example of a context property.
1267 Polyphonic music that has three or four voices can't be printed by
1268 simply changing the directions of the stems for each voice, obviously.
1269 Traditionally, some chords are shifted horizontally to print if this many
1270 voices have to be printed.
1271 LilyPond can also do this, and the property that controls the
1272 horizontal shifting is called code(hshift).  The notes in a
1273 code(Voice) context that has code(hshift) set to a true value (i.e.,
1274 non-zero or non-empty), will be shifted horizontally in the case of a
1275 collision.  The following example demonstrates the effect.
1276
1277 mudela(fragment,verbatim)(
1278   \type "Staff" <
1279     \type "Voice" =  "one"  {
1280       \property Voice.ydirection = "1"
1281       r4 as'4 () as'4 g'4 }
1282     \type "Voice" =  "two"  {
1283       \property Voice.ydirection = "1"
1284       \property Voice.hshift = 1
1285       g'2 f'4 e'4 }
1286     \type "Voice" = "three" {
1287       \property Voice.ydirection = "-1"
1288       [d'8 dis'] [d' cis'] [c' b] c'4
1289     }
1290   >
1291 )
1292
1293 sect(Lyrics)
1294 label(tutorial:lyrics)
1295
1296 Now for something completely different: Lyrics.  Lyrics are also
1297 considered to be music, although a lyric by itself does not have any
1298 pitch.  Producing lyrics has two aspects. First, you have to enter the
1299 text, i.e., the syllables along with their durations.  
1300 After this, you have to specify how to convert these to graphics.
1301
1302 Lyrics consist of syllables, which are strings together with
1303 durations.  Previously we only entered note names, so for entering
1304 lyrics we have to instruct LilyPond that what we enter are not note
1305 names but words---or rather: strings.  This instruction is the keyword
1306 code(\lyric).  After entering this keyword you can enter a musical
1307 construct---sequential music, simultaneous music, code(\type)
1308 entries, etc.--- but with syllables in stead of pitches.  For example:
1309 verb( \lyric { 'got8 me on my knees4, Le-8 lie! })
1310
1311 The effect of code(\lyric) can be compared with the effect of the
1312 doublequote character, code("), for it also changes the lexical
1313 meaning of spaces and characters.  This mode is another example of a
1314 handy input feature of the language.
1315
1316 Next comes the conversion to notation.  LilyPond can't (yet) figure
1317 out that lyrics need different treatment than notes.  As a result, the
1318 default conversion will try to put the text you entered as note heads
1319 onto a staff, and this will fail.  This default must be overriden with
1320 a code(\type) keyword.  Printing syllables of text in a line is done
1321 by a context called code(Lyrics).  You can select this context with
1322 the code(\type) keyword.  Here is a simple example:
1323
1324 mudela(fragment,verbatim)(
1325         \type Lyrics \lyric { 'got8 me on my knees,4 Le-8 lie! })
1326
1327 The result is technically more or less correct, but without a melody it
1328 just doesn't work, so let's add a blob of cream:
1329 mudela(fragment,verbatim)(
1330   <
1331     \type Staff  { c''8. c''16 bes'8. a'16 g'4 f'8 g'4. }
1332     \type Lyrics \lyric { 'got8. me16 on8. my16 knees,4 Le-8 lie!4. }
1333   >
1334 )
1335
1336 The strings that makes up each syllable in the lyrics block are passed
1337 along to TeX() verbatim, so if you are proficient with TeX() you can
1338 do various nifty things.  Just keep in mind that a syllable either
1339 starts with a letter (a character in the range `code(a)' to `code(z)'
1340 or `code(A)' to `code(Z)'), or it is a string enclosed quotes. It ends
1341 with either a number for the duration, or a space.  A last feature
1342 that should be mentioned is the space-lyric: if you want to enter
1343 a single ``syllable'' that consists of multiple words, i.e., words
1344 separated by  spaces, you should use an
1345 underscore instead of a space.  All these tricks are demonstrated in
1346 the following example:
1347
1348 COMMENT( urg
1349 \type Lyrics \lyric { 'got_m\textbf{e}4 on8. m$\cal_Y$16 knees,4 Le-8 lie!4.}
1350 \type Lyrics \lyric { 'got_m{\bf e}4 on8. m$\cal_Y$16 knees,4 Le-8 lie!4.}
1351 )
1352
1353 mudela(fragment,verbatim)(<
1354   \type Staff  { c''8. c''16 bes'8. a'16 g'4 f'8 g'4. }
1355   \type Lyrics \lyric { 'got_me4 on8. m$\cal_Y$16 "3s,"4 Le-8 lie!4.}
1356 >
1357 )
1358
1359 The spacing in the above example is a bit skewed because Lily can't
1360 tell that the long syllables you entered are not ordinary characters,
1361 but expand to really small symbols.
1362
1363
1364
1365
1366 COMMENT(Rood is de kleur van geluk.)
1367 COMMENT(Dat geldt ook voor haar.)
1368
1369
1370 sect(Toplevel Mudela)
1371
1372 Now the time has come to unravel the red tape that we have hidden from
1373 you in the introduction.  Mudela has a hierarchical structure for we
1374 have seen that sequential and simultaneous music can be nested.
1375 Mudela also has other `blocks' that can be nested.  The general syntax
1376 for a block is code(\keyword { ... }).
1377
1378 When you run LilyPond, what happens is that you define music, and
1379 specify one (or more) conversions to apply to that music, for example
1380 a conversion to notation.  This is done by putting the definition of
1381 the music and the definition of the conversion together in a
1382 code(\score) block, e.g.,
1383 verb(
1384 \score {
1385         % ... music ...
1386         \paper {}
1387 })
1388
1389 This is almost  the context that should be around all
1390 of the previous examples.  The precise context reads thus:
1391 verb(
1392 \score {
1393         \melodic { ... }
1394         \paper {}
1395 })
1396 On the ellipsis, you entered what shown as the example input.
1397 You can see that in the
1398 above example, the code(\melodic { ... }) forms the music, the
1399 code(\paper {}) is a conversion to paper (notation, that is).  The
1400 code(\paper) definition is copied from a default definition
1401 (which is in the initialisation file file(paper16.ly)).
1402 The paper part also contains
1403 the definition of the contexts.
1404
1405 The keyword code(\melodic) is analogous to the code(\lyric) keyword.  It
1406 will switch the tokenizer into a mode that interprets plain words as
1407 note names.  If it can't recognize the words as a note name, it will
1408 assume that they are strings.  That is the reason why you can write
1409 code(\clef bass) in stead of code(\clef "bass"); most of the strings
1410 in code(\melodic) mode can be written without quotes.
1411
1412 The braces that you see after the code(\melodic) keyword are the
1413 braces that are around sequential music.  Because of these braces, the
1414 sequences of notes in our simple examples were sequential (and not
1415 simultaneous).  As a result the notes were printed from left to right,
1416 and not stacked.
1417
1418 sect(Identifiers)
1419
1420
1421 Now that we are comfortable with the toplevel entries in a mudela
1422 file, we can investigate some more of the recreations on toplevel, in
1423 particular em(identifiers).  Generally you can define an identifier by
1424 entering code(identifierName = ... )
1425 where there can be a variety of things on the ellipsis.
1426
1427 Here is a (partial) list of what you can abbreviate with identifiers
1428 at top-level.
1429 itemize(
1430 it()The code(\score) block
1431 it()The code(\paper) block
1432 it()The code(\midi) block (to be explained in
1433   bind(Section)ref(tutorial:sound))
1434 it()Music (sequential music, simultaneous music etc.)
1435 it()Durations
1436 it()Strings
1437 it()Translators (to be explained in bind(Section)ref(tutorial:engravers))
1438 it()Integers
1439 it()Reals  
1440 )
1441
1442 When you refer
1443 to the abbreviated entity, you must precede code(identifierName)
1444 with a backslash, i.e., code(\identifierName).  For example:
1445 mudela(verbatim)(
1446   czerny = \melodic { [c16 g e g] }
1447   \score {
1448     \melodic \type GrandStaff <
1449       { c''2 g''2 }
1450       { \clef bass; \czerny \czerny \czerny \czerny}
1451     >
1452     \paper {
1453       linewidth = -1.0;
1454       stem_length = 12.0*\internote;
1455     }
1456   }
1457 )
1458
1459
1460
1461 Another interesting feature of this example are the assignments within
1462 the paper block.  Some blocks, such as code(\paper), have a scope of
1463 their own.  In the case of the code(\paper) block, these variables
1464 influence the characteristics of the output.  As is shown, you can
1465 tune quantities like the stemlength, and enter simple expressions.
1466 The purpose of the negative linewidth is to prevent the music from
1467 being justified.  The identifiers that are meaningful are for the
1468 paper block is strongly implementation dependent, so they will not be
1469 listed here.  Moreover, since most of the values are predefined to
1470 sensible defaults, there usually is no need to tune these values.
1471
1472 Recall the properties of a context, that could be set with
1473 code(\property).  It is a very general mechanism to tune the output of
1474 the music, that is neatly separated from the real music.
1475 Unfortunately, it is not convenient to type or read, and the precise
1476 effect of a setting property isn't always apparent from its
1477 definition.  To remedy this, we can use an identifier to capture the
1478 meaning of a code(\property).
1479
1480 mudela(verbatim)(
1481 stemup = \property Voice.ydirection = "1"
1482 stemdown = \property Voice.ydirection = "-1"
1483 shift = \property Voice.hshift = "1"
1484 \score {
1485   \type "Staff" \melodic <
1486     \type "Voice" =  "one"  {
1487       \stemup
1488       r4 as'4 () as'4 g'4 }
1489     \type "Voice" =  "two"  {
1490       \stemup
1491       \shift
1492       g'2 f'4 e'4 }
1493     \type "Voice" = "three" {
1494       \stemdown
1495       [d'8 dis'] [d' cis'] [c' b] c'4
1496     }
1497   >
1498   \paper{  linewidth = -1.0\pt; }
1499 }
1500 )
1501
1502 Several abbreviations like code(\stemup) are defined in the
1503 standard initialisation file file(property.ly).  Setting or changing
1504 context properties can have a similar effect as the commands that were
1505 discussed in bind(Section)ref(sec:commands).  Don't be fooled by the
1506 similarity in appearance between a declared property-setting entry
1507 and a real command.  Real commands are hardcoded into the language
1508 and they have to be terminated by semicolons.
1509
1510 You can also use identifiers to break up the heavy nesting that can occur
1511 in the code(\score) block.  Another useful application is
1512 parametrisation of the music: if you use identifiers in the
1513 code(\score) block, you can make variations of the music by simply
1514 redefining those identifiers.  One particular application of this is
1515 part extraction: by using identifiers and redefining them, one can
1516 print extracted parts and a full orchestral score from the same
1517 music definition.
1518
1519
1520
1521 sect(Sound output)
1522 label(tutorial:sound)
1523
1524 You get output by combining music with definition a conversion to
1525 output.  Up till now we have only focused on the graphic output of
1526 traditional engraving.  But there is no reason why that should be the
1527 only form of output for music.  LilyPond currently supports one other
1528 conversion: the conversion from abstract music to sound. You can have
1529 LilyPond play the music that you entered.  The format that is used
1530 for this output is MIDI.  
1531
1532 The only information that you need to enter is the
1533  nop(tempo)footnote(Unfortunately,
1534 this the only thing that can be tuned at this
1535 time.  This is a limitation: the tempo of music can vary throughout
1536 the music.) for the performance.  The syntax for the tempo is
1537 code(\tempo )var(duration) = var(beatsperminute);), for example:
1538 verb(
1539 \score {
1540    ...music...
1541    \midi { \tempo 4 = 76; }
1542 }
1543 )
1544
1545 The most useful purpose of this sound output is to prooflisten your
1546 files: typing errors (especially if they involve accidentals)  stand
1547 out when you listen.
1548 The output was implemented in a very rudimentary manner, so it is
1549 probably not worth listening to for any other reason.
1550
1551
1552 sect(Contexts revisited: engravers)
1553 label(tutorial:engravers)
1554
1555 As was promised, we will now take a dive into the more wizardrous parts
1556 of LilyPond: redefining (notation) contexts.  We previously explained
1557 that a context 
1558 itemize(
1559 it()is a conversion from music to notation,
1560 it()can contain other contexts
1561 it()handles specific notation constructs
1562 )
1563
1564 This characterization almost automatically explains what the definition of a
1565 context should look like:
1566 itemize(
1567 it()It should be part of the ``notation output definition,'' i.e., the
1568   code(\paper) block
1569 it()
1570   It should contain a specification of what other contexts may be contained
1571   in the context we're defining.
1572 it()
1573   It should contain a list of the notation constructs  to be
1574   handled.
1575 )
1576
1577 In practice, the context definition
1578 looks like this:
1579 verb(
1580 \translator
1581 {
1582         \type "Engraver_group_engraver";
1583         \accepts "...";
1584         \accepts "...";
1585         \accepts "...";
1586
1587         \consists " ... ";
1588         \consists " ... ";
1589         \consists " ... ";
1590
1591         propertyname = "value";
1592         propertyname = "value";
1593
1594 } )
1595
1596   This is encoded by the 
1597
1598 The code(\translator) keyword opens the block for translation (or
1599 context) definition.  The code(\type) keyword explains to Lily that
1600 the context should be formed by taking an (empty) instance of
1601 code(Engraver_group_engraver).  The code(Engraver_group_engraver) is a
1602 C++ class from the source code to Lily.  The code(\accepts) entries
1603 explain what kind of contexts this context could contain.  If we were
1604 to define a context for a staff, the definition would typically
1605 contain code(\accepts "Voice";).
1606
1607 The code(\consists) entries specify which notation constructs should
1608 be handled. This needs a little explanation: LilyPond contains the
1609 code for quite a large number of basic building blocks for notation
1610 generation, and each building block handles only one notation
1611 construct.  The name of such a building block is `engraver'.  You can
1612 specify which notation construct a context should handle by specifying
1613 which engravers should be part of the context.  The code(\consists
1614 "Foobar") entry really means ``add an instance of code(Foobar) to the
1615 translation group.''
1616
1617
1618 For example if this context should print time signatures, the definition
1619 should include `code(\consists "Time_signature_engraver";)'.  Again
1620 code(Time_signature_engraver) is a class from the source code of LilyPond.
1621
1622
1623
1624 Finally, one can pre-set some properties in a context definition.
1625
1626 As a practical example, we will show you how to typeset polymetric
1627 music, i.e., music where the meter can differ for each staff.  The
1628 solution is not very complicated: normally all timing information
1629 (time signature, rhythmic grouping) is synchronised across each staff.  In
1630 LilyPond this is expressed by having only one registration for timing
1631 information for all staffs.  To be precise, there is only one
1632 code(Timing_engraver), and it is located in the top level context, the
1633 code(Score) context.
1634
1635 All staffs use the information in the global code(Timing_engraver)
1636 for generating bar lines and time signatures.  In polymetric music, this timing
1637 information can be different for every staff, so we should redefine
1638 the code(Staff) context to include and the code(Score) context to exclude the
1639 code(Timing_engraver).  
1640
1641 mudela(verbatim)(
1642 polymetricpaper = \paper {
1643   Score = \translator {
1644     \type Score_engraver;
1645     \consists "Score_priority_engraver";
1646     \consists "Priority_horizontal_align_engraver";
1647     \consists "Vertical_align_engraver";
1648     % \consists "Timing_engraver"; % removed Timing_engraver
1649     \accepts "Staff";
1650   }
1651
1652   Staff = \translator {
1653     \type "Line_group_engraver_group";
1654
1655     defaultclef = violin;
1656
1657     \consists "Bar_engraver";
1658     \consists "Clef_engraver";
1659     \consists "Key_engraver";
1660     \consists "Local_key_engraver";
1661     \consists "Time_signature_engraver";
1662     \consists "Timing_engraver";  % added Timing_engraver
1663     \consists "Staff_sym_engraver";
1664     \consists "Separating_line_group_engraver";
1665
1666     \accepts "Voice";
1667   }
1668 }
1669 \score {
1670   \melodic <
1671     \type Staff = one { \time 2/4; c'4 c'4 c'4 c'4 c'4 c'4 }
1672     \type Staff = two { \time 3/4; c'4 c'4 c'4 c'4 c'4 c'4 }
1673   >
1674   \paper { \polymetricpaper
1675     linewidth = -1.;
1676   }
1677 }
1678 )
1679
1680 As you can see, we used the identifier code(polymetricpaper) to break
1681 up the large score block.  More of these context definitions appear in
1682 the standard initialisation file file(engraver.ly).
1683
1684 sect(Urtexts and context selection)
1685 label(tutorial:urtext)
1686
1687 In bind(Section)ref(tutorial:more-staffs), we have shown you how to make
1688 multiple staffs, and explained that you have to label every staff (or
1689 more precisely: different contexts), to make sure that new ones are
1690 created when you need them.  In this section, the real power of this
1691 mechanism will unveiled.
1692
1693 By naming other contexts that you create, you can reference other contexts
1694 than the current context from within the music.  For example, from within the music that you
1695 enter for staff code(One), one could enter a small piece of music,
1696 and send it to staff code(Two), e.g.,
1697 mudela(fragment,verbatim)(
1698   <
1699     \type Staff = one { c''4 \type Staff = two { c4 c4 } c''4 }
1700     \type Staff = two { \clef bass; g,4 g,4 g,4 g,4  }    
1701   >
1702 )
1703
1704
1705 Another useful application of this feature is making Urtexts.
1706 em(Urtext) is the German word for `original text'.  The Urtext
1707 edition of a piece of music, is an edition that reflects the original
1708 writing of the composer.  Such editions are useful for musicologists,
1709 and performers that want  to perform authentic interpretations.  However,
1710 for mere mortals, the Urtext can be quite hard to read.  It might not
1711 contain fingering and beaming, and typically it is full of footnotes.
1712 Moreover, common interpretations may have emerged---after the composer
1713 died.  For this reason, the music that can be had as Urtext usually is also
1714 available in enhanced and edited editions.
1715
1716 The mechanism of context selection can be used to fabricate an Urtext
1717 and an edited edition from em(one source).  We will use the first few
1718 bars of bind(J.)bind(S.)Bach's lovely Cello suite bind(no.)I to
1719 demonstrate this.  The example makes heavy use of space rests: a space
1720 rest takes up time, like a rest does, but it doesn't print anything.
1721 It can be used as a placeholder, to attach articulation marks to.  It
1722 is entered as a note with the name code(s).
1723
1724 mudela(verbatim)(
1725   bach =  \melodic { [c16 g e' d'] [e' g e' g] }
1726   
1727   staffStuff = \melodic { \clef bass; \time 4/4; s1 \bar "|."; }
1728   
1729   slursOne = \melodic { s16( s s s s16 s s )s }
1730   slursTwo = \melodic { s16-. s s() s s16() s  s ()s }
1731
1732   \score{
1733     { < \type Voice = celloVoice { \bach \bach }
1734         \type Voice = celloVoice { \slursOne \slursOne }
1735         \staffStuff
1736       >
1737       <
1738         \type Voice = celloVoice { \bach \bach }
1739         \type Voice = celloVoice { \slursTwo \slursTwo }
1740         \staffStuff
1741       >
1742     }
1743     \paper {}
1744   }
1745 )
1746
1747  The slurs that you define should be put on the music that is defined
1748 by the code(\bach) identifier.  By labeling a code(Voice) context, and
1749 directing both the articulation and the notes to that same code(Voice)
1750 context, the articulation is put over the right notes.
1751
1752
1753 sect(Transposing)
1754 label(tutorial:more-grammar)
1755
1756 COMMENT(In this section, we will complete the grammar for Music that was
1757 sketched earlier. )
1758 One of the things that you can do with music is
1759 em(transposing) it.  If you want to transpose a piece of music, then
1760 you should prefix the keyword code(\transpose) along with the pitch
1761 (relative to the central C) for the transposition.footnote(the
1762 code(\type Staff) is to make sure that no separate staffs are created
1763 for the code(\scale) and code(\transpose cis' \scale) part.)
1764
1765
1766 mudela(verbatim)(
1767 scale = \melodic \relative c' { [c8 d e f] }
1768 \score {
1769   \melodic {
1770     \type Staff { \scale \transpose cis'  \scale }
1771     }
1772   \paper { linewidth = -1.0; }
1773 })
1774
1775
1776 sect(Staff switching)
1777
1778 We have seen that contexts can be nested.  This means that they form a
1779 tree.  It is possible to edit this tree: for example, a code(Voice)
1780 context can be taken out of a code(Staff) context, and put into
1781 another.  This has the effect of the voice switching staffs (something
1782 that often happens in keyboard music).  The syntax for this operation
1783 with these particular contexts is code(\translator Staff = newStaffName).
1784
1785 The effect is analogous to the first example in section
1786 ref(tutorial:urtext), but with the code(\translator) construction it
1787 is possible to split the real music and the commands that determine in
1788 which staff the music is printed.  For example:
1789
1790 mudela(verbatim)(
1791
1792 % real music
1793 aVoice = \type Voice = voiceA \melodic { c''4 c4 c4 c''4 }
1794 bVoice = \type Voice = voiceB \melodic { g,4 g,4 g,4 g,4  }    
1795
1796 % staff switching stuff
1797 switch = \type Voice = voiceA \melodic { s4 \translator Staff = staffB s4
1798                    s4 \translator Staff = staffA s4 }
1799
1800 \score {
1801   <
1802     \type Staff = staffA < \aVoice \switch >
1803     \type Staff = staffB < \bVoice \clef bass; >
1804   >
1805   \paper { linewidth = -1.; }
1806 }
1807 )
1808
1809 Don't try to switch staffs when you are in the middle of a slur or
1810 beam, though.  It doesn't work yet.
1811
1812 sect(Hairy durations: triplets)
1813
1814 In the previous section we explained an operation that changes the
1815 pitches of music, transposition.  In this section we will explain an
1816 operation that modifies the duration of the notes that you enter.
1817 When notes are part of a triplet, then the real of duration of the
1818 notes are 2/3 part of what their shape indicates:
1819 mudela(fragment)(
1820 \[/3  c'4 c'4 c'4 \]/1
1821 )
1822
1823 To support this notion, Mudela allows you to modify the duration of a
1824 note by multiplication or division.  A code(c'4) note that would be in  a
1825 triplet is written as code(c'4*2/3).  If you sequence a few of these
1826 notes, you get a triplet.footnote(We added a normal staff in the example to
1827 show the difference.)
1828 mudela(fragment,verbatim)(
1829 <  \type Staff = staffA { c'8*2/3 c'8*2/3 c'8*2/3 c'4}
1830    \type Staff = staffB { c''8 c''8 c''4 } >)
1831
1832 LilyPond knows that these notes are no normal eighth notes, but the
1833 reader doesn't yet.  To help the reader a beam or a bracket with a `3'
1834 should be printed.  The special beam command `code([2/3)' and the
1835 matching close beam `code(]1/1)' will take care of that, and
1836 they also abbreviate the code(*2/3) part.  If you want brackets in
1837 stead of beams, you can use `code(\[2/3])' and `code(\]1/1)'.
1838 mudela(fragment,verbatim)(
1839 < \type Staff = staffA {
1840     [2/3 c'8 c'8 c'8 ]1/1
1841     \[2/3 c'8 c'8 c'8 \]1/1
1842   }
1843   \type Staff = staffB { [c''8 c''8 c''8 c''8] }
1844 >)
1845
1846 Other tuplets  can be entered in the same way.
1847 mudela(fragment,verbatim)(
1848 < \type Staff = staffA {
1849     \time 7/8;
1850     [7/6 c'8 c'8 c'8 c'8 c'8 c'8 ]1/1
1851   }
1852   \type Staff = staffB {
1853     \time 7/8;
1854     [c''8 c''8 c''8 c''8 c''8 c''8 c''8] } >
1855 )
1856
1857 For your convenience, code([2/3) can be further abbreviated to code([/3), and
1858 you can abbreviate code(]1/1) on the closing beam marker to code(]/1).
1859
1860 mudela(fragment,verbatim)(
1861 < \type Staff = staffA {
1862     [/3 c'8 c'8 c'8 ]/1 c'4
1863   }
1864   \type Staff = staffB { [c''8 c''8] c''4 } >
1865 )
1866
1867
1868 bf(Important) the construct with code([/3) and
1869 code([/1) is a hack that sets a mode in the parser.  This means that
1870 verb(id = \melodic { c8 c8 c8 }
1871 notATriplet =\melodic { [2/3 \id ]1/1 })
1872 does not produce a triplet.  It will hopefully
1873 soon be replaced by a construction that mixes more elegantly with the
1874 grammar for Music.
1875
1876
1877 sect(Shortcuts for octaves)
1878 label(sec:relativeoctaves)
1879
1880 Plain Mudela contains a lot of quotes to get the octaves right.  This
1881 need for quotes can be reduced: most of the pitch intervals in
1882 conventional music are small.  Therefore, it makes sense to leave out
1883 the quotes when the interval is small.  We have built a mode that does
1884 exactly this.  It is called the relative mode for octaves.  You can
1885 switch it on by entering code(\relative).  Then LilyPond will
1886 interpret every note as if they mean the note with the same name
1887 closest to the previous.  You have to specify the first pitch because
1888 the first note of a list obviously has no predecessor.  So, you can
1889 enter a scale without using octavation quotes, e.g.,
1890
1891 mudela(fragment,verbatim)(
1892     \relative c' { c d e f g a b c }
1893 )
1894
1895 For chords, the relative mode works slightly differently.  In a
1896 sequence of chords, the first note of a chord gives the starting point
1897 for the next chord.  We can demonstrate this with our twinkle twinkle example
1898 verb(
1899   \relative c' {
1900   c4       c            <c g'>    <c e g>
1901   <c e a>  <b d a'>     <b2 d g>
1902   <a4 d f> <bes d f>    <bes c e> <g c e>
1903   <e a d>  <a, g' cis'> <d2 f d'>
1904   }
1905 )
1906
1907 LilyPond converts any music with code(\relative) prepended to absolute
1908 music immediately when it is read. Internally it is stored it in
1909 absolute pitches.  Since the tutorial mainly deals with how to specify
1910 musical information, and not how to enter it conveniently, the
1911 tutorial doesn't use it.
1912
1913
1914 sect(Large pieces)
1915 label(tutorial:large-pieces)
1916
1917 In our quest for a clean and powerfull music language, we took the effort
1918 of entering some larger pieces of music as well.  From this we learned
1919 certain things that lead to direct improvements of Mudela, such as the 
1920 relative mode.  We also gained some practial experience, that resulted in a 
1921 compilation of tips that may be of use to you.
1922
1923 Entering a large piece of music will often imply the need to produce a
1924 conductor's score, as well as individual parts for all instruments.  This
1925 can most easily be achieved making use of identifiers and including mudela
1926 files.
1927
1928 subsect(Identifiers)
1929
1930 Briefly introduced before, identifiers are your biggest help in structurising
1931 a large piece of music.  As an example, we'll consider a string quartet.  
1932 In short, it will look like this: verb(
1933     global = \melodic{ }
1934     violinoOne = \melodic \relative c { .. }
1935     violinoTwo = \melodic \relative c { .. }
1936     viola = \melodic \relative c { .. }
1937     violoncello = \melodic \relative c { .. }
1938 )
1939
1940 The code(\global) part contains everything that is global, i.e., the
1941 same, for each instrument.  This may include time signature, key, repeat
1942 signs, different bar types, time signature- and key changes, rehearsal
1943 marks, etc.
1944
1945 For each instrument, you'll have something vaguely resembling verb(
1946     violinoOneStaff = \type Staff = violinoOne <
1947         \property Staff.midi_instrument = "violin"
1948         \property Staff.instrument = "Violino I"
1949         \property Staff.instr = "Vl. I"
1950         \global
1951         \violinoOne
1952     >
1953 )
1954
1955
1956 [Versions, relative mode,
1957  barchecks, splitting of files]
1958
1959 subsect(Including Mudela files)
1960 ref(subsect:include)
1961
1962 You can include other Mudela files  with the command code(\include):
1963 verb(
1964 \include "paper13.ly"
1965 \score {
1966        ...
1967        \paper { \paper_thirteen }
1968 })
1969
1970 The file is looked for in the  standard search path.
1971
1972
1973 subsect(Grouping of staffs)
1974
1975 subsect(Versioning)
1976
1977 sect(Titling)
1978 label(tutorial:titling)
1979
1980 A piece of sheet music isn't complete without proper opening and
1981 closing titles.  LilyPond does not have any real support for setting
1982 text: that is a job best left to TeX().  But you can pass messages to
1983 TeX() from the input file.   You can  write TeX() macros to handle
1984 these messages.
1985 To do this, you add a code(\header) block
1986 to your input file.  The format is quite simple,
1987
1988 verb(
1989 \header{
1990     "key" =  "value";
1991     "key" =  "value";
1992     "key" =  "value";
1993     % etc.
1994 })
1995
1996 When  the results of the music typesetting are output, the contents of
1997 code(\header) are also up into the TeX() file.  Tools like
1998 code(ly2dvi) can use this information to generate pretty titling for
1999 your input file. Consult the manual page of code(ly2dvi) for more
2000 details.
2001
2002
2003 The code(\header) block should be at toplevel in mudela, and
2004 preferably at the top of the file.  If you have an input file  with
2005 multiple code(\score) blocks, you should add a header to every score,
2006 describing the different sub parts of the music piece, eg.
2007
2008
2009 verb(\header {
2010         "composer" = "Ludwig Van Bavaria";
2011         "title" = "Symphonie Megalomane";
2012     }
2013     \score{
2014        ... % some music
2015        \header { movement = "Mit roher Kraft wild herausfahrend!"; }
2016       \paper { }
2017     }
2018     \score{
2019        ... % some more music
2020        \header { movement = "Saut\'e comme un oeuf."; }
2021       \paper { }
2022     }
2023 )
2024
2025 If you want you can also put the code(\header) block at the top of the
2026 input file; it will then be put into every output file automatically.
2027 This will make it clear what the file contains as soon as you open it.
2028
2029
2030