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