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