]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/tutorial.yo
2ab084682989c4d656e948d4e0ff374c4023134b
[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 identifiers
701   code(\major) and code(\minor) can be used to decide if all the 
702   subsequent code(\key) commands are major or minor, respectively. 
703   The default is major keys. The key of C-minor can 
704   thus be specified as `code(\key es)' or `code(\minor \key c)'.
705   
706 dit(code(\keysignature) var(pitchlist))
707
708 This command changes the current key signature.  Unlike the
709 `code(\key)' command, this command can produce arbitrary key
710 signatures, which can be useful for unconventional keys or modes.  The
711 key signature is given in the form of a list of notes.  The notes will
712 be printed in the key signature in the order that they appear on the list.
713 For example, the key
714 of C-minor can be specified as `code(\keysignature bes es as)'.  The
715 command `code(\keysignature fis es bis)' provides a more exotic
716 example.
717
718
719 dit(code(\time) var(numerator)code(/)var(denominator))
720   This command changes the current time signature.  LilyPond uses the
721   time signature to
722   calculate where to place the bars that start a measure.  These bars
723   in turn are the places where a system can be broken into lines.
724
725   The default value for this time signature is common time (4/4).  You
726   can also tell this from the  Twinkle ``Twinkle Little
727 Star'' example in bind(Figure)ref(fig:twinkle1).  This
728 song actually has a 2/4 time signature, so a metrically more correct
729   version  would start with as follows:
730   mudela(fragment,center,verbatim)(
731     \time 2/4;  c'4 c'  g' g' 
732   )
733
734
735 dit(code(\cadenza) var(togglevalue)) When typesetting music without a
736 regular meter (such as an ad libitum cadenza), no bar lines should be
737 printed.  In LilyPond you can achieve this by issuing the command
738 `code(\cadenza 1)': it turns off the automatically
739 generated bar lines.
740
741 You switch them on again with `code(\cadenza 0)', and then a bar line
742 is printed.  LilyPond will act as if you are again at the start of a
743 measure.
744
745 dit(code(\bar) var(bartype))
746   This command lets you print special bar
747   lines and repeat symbols.  You can also use it to allow line breaks
748   when entering cadenzas.  The argument var(bartype) is a string that
749   describes what kind of bar line to print.
750
751 mudela(fragment,verbatim)(
752     \bar "|:"; c'4 \bar ":|:";    c'4  \bar ":|";  c'4 \bar "||";
753     c'4 \bar "empty"; c'4 \bar "|.";
754 )
755   The command `code(\bar "empty")' does not create any visible bar
756   line, but it does tells LilyPond to allow a linebreak
757   at that position.  The `code(\bar)' command prints the specified
758   symbol immediately.  If you give a `code(\bar)' command at the end
759   of a measure then
760   the specified symbol replaces the automatic bar line; otherwise
761   the specified symbol appears in the middle of the measure.   The
762     code(\bar) command does not affect metric structure.
763
764
765   
766 dit(code(\partial) var(duration)) some music starts with a measure that
767 isn't fully filled, a so-called upstep.  The code(\partial) command
768 allows you to make
769 upsteps. The argument is a duration similar to the duration of a note.
770 The `code(\partial)' command cannot be used to generate partial
771 measures in the middle of the music.  
772 Example:
773   mudela(fragment,verbatim)(
774     \time 4/4;
775     \partial 4;
776     [d'8 dis'] e' c''4 e'8 c''4 
777   )
778
779   dit(code(\grouping) var(durationslist)) sets the metric structure of the measure.
780     Its effect can best be shown by an example:
781     mudela(fragment,verbatim)(
782         \time 5/16;
783         \grouping 16*3 16*2;
784         [c'8 c'16 c'8]
785         \grouping 16*2 16*3;
786         [c'8 c'16 c'8]
787         \grouping 16*5 ;
788         [c'8 c'16 c'8]
789     )
790
791 In practice, you won't be needing this command very often: the
792 grouping is switched automatically when you issue a code(\time)
793 command.  It is set to a combination of groups
794 of 2 and 3 beats, with as many groups of
795 3 as possible (in other words: 4/4 is divided in two times two beats
796 (2+2), 8/8 in 3+3+2)
797 )
798
799 The commands that are described above aren't really music, but they
800 can be used in the same places as notes.  This makes the grammar of the
801 language simpler.  It is possible to put a command into a chord.
802 For example, the following two snippets of Mudela produce identical output.
803 verb(
804   <c4 e g \time 2/4;>
805   \time 2/4; <c4 e g>
806 )
807
808
809
810 sect(Complex music: more than one staff)
811 label(tutorial:more-staffs)
812
813
814 Now we explain how to typeset music that runs in multiple staffs.
815 Consider the following---somewhat unrealistic---example:
816
817 mudela(fragment)(
818  \type GrandStaff <e'4 {\clef bass; g4^""} >
819 )
820
821   The music consists of two notes.  Perhaps this is sheet music for a
822 piano player, and one note is meant to be played with the left hand,
823 and the other with the right hand.  That music would sound the same if
824 it were written as a single chord on a single staff, i.e.,
825 mudela(fragment)(
826   <g4 e'4>
827 )
828
829
830 This is another example where we can see that there can be a difference
831 between a musical idea, and the way it is expressed in notation.
832
833 The Mudela construct for multiple staffs reflects the similarity
834 between the two examples: to get multiple staffs in Mudela you enter a
835 chord, with an additional instruction to tell LilyPond that the chord
836 does not represent notes stacked together, but staffs stacked
837 together.
838
839 If a piece of music is to be interpreted as a staff, then this can be
840 expressed with the code(\type) construct.  The following input says
841 ``the quarter note with pitch e should be put on a staff.''
842
843 verb(
844   \type Staff e'4 
845 )
846
847 The same can be done for the other note, i.e.,
848
849 verb(
850   \type Staff g4 
851 )
852
853 If you want to stack these staffs, you must create a chord of both:
854
855 verb(
856   < \type Staff e'4
857     \type Staff g4 
858   >
859 )
860
861 This looks reasonable, but the effect of this input is not what you
862 might expect (try it!).  When interpreting this chord LilyPond will
863 start with the first entry.  She'll look for a (nameless) staff.  Such a
864 staff is not found, so it is created.  On this staff the code(e) note
865 is put.  When the second code(\type) entry is read, LilyPond will
866 start looking for a nameless staff.   The  staff that contains  the
867 code(e) is found, and the code(g) is put there as well.
868
869 The correct solution is to label both code(\type) constructs with
870 different names, for example code(trebleStaff) and code(bassStaff).
871 This makes LilyPond distinguish between them, and create two staffs:
872
873 mudela(verbatim,fragment)(
874   < \type Staff = trebleStaff e'4
875     \type Staff = bassStaff  g4 
876   >
877 )
878
879 The names that you choose do not matter just as long as they are
880 different.  This is almost right, except for the brace at the left and
881 the clef of the second staff.  The bass clef will be taken care of in
882 the next section. If you want a brace, then you have to tell LilyPond
883 that the chord you just formed is to be interpreted as a so-called
884 grand staff.  This is also done with the code(\type) command.
885 mudela(verbatim,fragment)(
886   \type GrandStaff <
887      \type Staff = treblestaff  e'4 
888      \type Staff = bassstaff  g4 
889   >
890 )
891
892 sect(Appending instead of stacking: sequential music)
893 label(tutorial:voice)
894
895 The previous section dealt with a pretty hypothetical situation: sheet
896 music with two staffs and each staff containing only one single note.
897 In real-life situations staffs contain more than one note.  They
898 contain music that has to be played in sequence.  A staff can contain
899 a em(voice).  We haven't learned  how to make a voice yet: we need a
900 new construct to express this notion of `voice'.
901
902 The construct is called em(sequential) music.  A list of musical
903 objects (e.g., notes, chords or commands) can be made into sequential
904 music by enclosing the list in braces; for example:
905
906 mudela(fragment,verbatim,center)(
907   { c'4 c'4 }
908 )
909 mudela(fragment,verbatim,center)(
910   { <c'4 e'> <e' g'> }
911 )
912
913
914 We could have called this construct more colloquially `voice', but
915 this would cause confusion later on, when a second kind of voice
916 enters the scene.  Similar confusion might arise from the word
917 `chord', therefore from now on, we will talk about `simultaneous
918 music', when we refer to items enclosed in < and >.
919
920
921 The notion of a em(new) construct needs some explanation: we have been
922 using sequential music all the time, except that it was hidden in the
923 red tape in bind(Section)ref(tutorial:introduction).
924
925
926
927 If we want to put whole voices onto a staff, then we have to
928 substitute sequential music for the single notes in the example from
929 the previous section.  A code(\clef) command in the second piece of
930 sequential
931 music  will also set the clef in
932 the bass staff.
933 mudela(fragment,verbatim)(
934     \type GrandStaff <
935      \type Staff = treblestaff  { e'4 f'}
936      \type Staff = bassstaff  {\clef "bass"; g a }
937   >
938 )
939
940 COMMENT(You can nest simultaneous music and chords in any way you want.  If
941 you are interested in the entire story, you should consult
942 bind(Chapter)ref(chap:features), which has a grammar in
943 bind(Section)ref(sec:grammar).)
944
945 sect(Notation context)
946
947 This section is about translation contexts, a topic of LilyPond that
948 is somewhat advanced.  You don't have to understand this to use
949 LilyPond to print simple music.  If you don't want to typeset fancy
950 polyphonic music or tweak the LilyPond notation engine, you can skip
951 the next two sections.
952
953 In bind(Section)ref(tutorial:more-staffs) it was explained, that there
954 are more ways to notate a simple chord: as a single voice on a single
955 staff or in multiple staffs (and we'll soon see, that you can typeset
956 it as multiple voices on a  staff).  Obviously the concept of staff is not
957 really something musical.  But what is it then?
958
959
960 The most simplistic explanation is: a staff is a peculiarity of the
961 notation system.  In other words, a staff is a graphic device, a
962 special picture of five lines on which one can print note heads.  To
963 avoid confusion, we will call this view on the concept of staff
964 `staff symbol' from now on.
965
966
967 There is more to it than meets the eye and mind.  A staff
968 contains---besides a staff symbol--- some more components:
969 itemize(
970 it()A staff can a have a key signature (printed at the left)
971 it()A staff has bar lines
972 it()A staff has a clef (printed at the left)
973 )
974 To explain what a staff really is,   we'll try to print music without
975 these components.  If these components aren't printed, it is still
976 possible to print music:
977 mudela()(\score{
978 \notes \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
979 \paper { 
980   linewidth = -1.;
981   \translator {
982     \type "Line_group_engraver_group";
983     \name Staff ;
984     defaultclef = violin;
985
986     \consists "Timing_engraver";
987     \consists "Separating_line_group_engraver";
988
989     \accepts "Voice";
990   }
991  }
992 })
993
994 As you can see, one can still make out the general form of the melody
995 and the rhythm that is to be played, but the notation is difficult to
996 read and the musical information is not complete.  The stress pattern
997 in the notes can't be deduced from this output.  For this, we need a
998 time signature:
999
1000 mudela()(
1001 \score {
1002   \notes \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
1003   \paper{
1004   linewidth = -1.;
1005     \translator {
1006     \type "Line_group_engraver_group";
1007     defaultclef = violin;\name Staff;
1008     \consists "Time_signature_engraver";
1009     \consists "Separating_line_group_engraver";
1010     \accepts "Voice";
1011   }
1012  }
1013 })
1014
1015 Technically speaking you know where the strong and weak beats are, but
1016 it is difficult to find them quickly.   Bar lines  help you in finding
1017 the location within the measure of the notes:
1018 mudela()(
1019 \score {
1020   \notes \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
1021   \paper{
1022   linewidth = -1.;
1023     \translator {
1024     \type "Line_group_engraver_group";
1025     defaultclef = violin;\name Staff ;
1026     \consists "Bar_engraver";
1027     \consists "Time_signature_engraver";
1028     \consists "Separating_line_group_engraver";
1029     \accepts "Voice";
1030   }
1031  }
1032 })
1033
1034 We can remedy part of the difficulties with reading pitches by adding a staff
1035 symbol:
1036
1037 mudela()(\score{
1038   \notes\relative c' { \time 2/4; g'4 c,4
1039 a'4 f4 e c d2 } \paper {
1040   linewidth = -1.;
1041   \translator {
1042     \type "Line_group_engraver_group";
1043     \name Staff ;
1044     defaultclef = violin;
1045     \consists "Bar_engraver";
1046     \consists "Time_signature_engraver";
1047     \consists "Staff_sym_engraver";
1048     \consists "Separating_line_group_engraver";
1049
1050     \accepts "Voice";
1051   }
1052  }
1053 })
1054
1055 This makes the output decidedly easier to read, but you still don't
1056 know what the pitches of the notes above are.  So this is still not
1057 enough.  But suppose you see the following notation:
1058 mudela()(\score {
1059   \notes \relative c' {\clef alto;  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
1060 \paper {
1061   linewidth = -1.;
1062    \translator {
1063     \type "Line_group_engraver_group";
1064     \name Staff;
1065      defaultclef = violin;
1066     \consists "Bar_engraver";
1067     \consists "Time_signature_engraver";
1068      \consists "Clef_engraver";
1069      \consists "Staff_sym_engraver";
1070      \consists "Timing_engraver";
1071      \consists "Separating_line_group_engraver";
1072
1073     \accepts "Voice";
1074   }
1075  }
1076 })
1077
1078 Now you know the pitch of the notes: you look at the start of the line
1079 and see a clef, with this clef, you can determine the notated pitches.
1080 You have found the em(context) in which the notation is to be
1081 interpreted!
1082
1083 So the context determines the relationship between a piece of music
1084 and its notation: you, the reader, use context to deduce music from
1085 notation.  Because LilyPond is a notation ``writer'' instead of a
1086 reader, context works the other way around for Lily: with context a
1087 piece of music can be converted to notation.
1088 The components of a staff form context, and context is needed to read
1089 and write notation.  This motivates the following definition.
1090
1091 quote(
1092 A bf(notation context) is  a conversion from music to notation.
1093 )
1094
1095 The example focused mainly on on staffs, but a staff is not the only
1096 type of notation context.  Notation contexts may be nested: you can
1097 print polyphonic music by putting multiple `Voice' contexts in one
1098 `Staff' context.  The arguments of the code(\type) command (Staff,
1099 GrandStaff) were in fact all names of different contexts.
1100 The notions of ``current clef'' and ``current position within the
1101 measure'' are all properties of notation contexts.  Commands like
1102 code(\clef) and code(\cadenza) change these properties.  
1103
1104
1105 The following is a list of the contexts that are supported by
1106 LilyPond:
1107 description(
1108
1109 dit(Voice) The code(Voice) context is a context that corresponds to a
1110   voice on a staff.  This context handles the conversion of noteheads,
1111   dynamic signs, stems, beams, super- and subscripts, slurs, ties and rests
1112
1113 dit(Staff) The code(Staff) context handles clefs, bar lines, keys,
1114   accidentals.  A code(Staff) context can contain multiple code(Voice)
1115   contexts.
1116
1117 dit(RhythmicStaff) The code(RhythmicStaff) context is like the staff,
1118   but much simpler: the notes are printed on one line, and pitches are
1119   ignored.  code(RhythmicStaff) can contain code(Voice) contexts.
1120
1121 dit(GrandStaff) A code(GrandStaff) context contains code(Staff)
1122   contexts, and it adds a brace to the output at the
1123   nop(left.)footnote(This is a major deficiency in the current
1124   implementation.    Currently stems,
1125   slurs and beams cannot be printed across two staffs.
1126 In reality, a grand staff is  a hybrid of one big staff and two stacked staffs.)
1127   
1128   A code(GrandStaff) context can contain multiple
1129   code(Staff)s. Typically, it will contain two code(Staff)s, one
1130   treble staff, and one bass staff. The bar lines of the contained
1131   staffs are connected vertically.
1132
1133 dit(StaffGroup) A code(StaffGroup) context contains code(Staff) or
1134   code(Lyrics) contexts, and prints a bracket at the left.  The bar
1135   lines in the participating staffs are connected.
1136
1137 dit(Lyrics) As its name suggests, The code(Lyrics) context deals with
1138   typesetting lyrics.  This topic will be covered in
1139   bind(Section)ref(tutorial:lyrics).
1140   
1141 dit(Score) The code(Score) context is the toplevel context: no context can
1142   contain a code(Score) context.  The code(Score) context handles the
1143   administration of time signatures.  It also makes sure that items
1144   such as clefs, time signatures, and key-signatures are aligned across staffs.
1145   
1146   The code(Score) can contain code(Staff), code(StaffGroup), code(Lyrics), code(GrandStaff) and
1147   code(RhythmicStaff) contexts.
1148
1149 COMMENT(do ChoireStaff)
1150 )
1151
1152
1153   Later on, in bind(Section)ref(tutorial:engravers) we will
1154 explain how you can create your own contexts.
1155
1156 If you are familiar with structured documents (like HTML, SGML or
1157 LaTeX()), you might see the analogy of a context with a stylesheet: a
1158 stylesheet is neither presentation nor information, but rather a
1159 recipe em(how) a specific piece of information should be presented.
1160 Analogously, a notation context is neither music nor notation, but the
1161 conversion between the two.  The big difference with text is that in
1162 music notation the elements provided by context are essential to
1163 understanding what is notated.
1164
1165
1166
1167 sect(Polyphonic music (or: Notation context properties))
1168
1169 In the last section we explained that a notation context can have
1170 properties that influence the conversion from music to notation.  A
1171 simple example of such a property is the clef: the type of clef partially
1172 determines the vertical position of note heads in a staff.  Some of
1173 these properties can be modified by commands such as code(\clef) and
1174 code(\time).   But there is more:  notation contexts  also have
1175 properties are settable in a generic fashion.  We will demonstrate
1176 this feature by printing multiple voices on a staff.
1177
1178 In polyphonic (keyboard) music and orchestral scores often more than
1179 one voice is printed on one staff.  We'll explain how to achieve this
1180 effect with LilyPond.  The effect is not unlike the two stacked staffs
1181 from bind(Section)ref(tutorial:more-staffs), except that we don't want
1182 to stack staffs but voices.  Thus,  the general template is the following:
1183 verb(
1184   \type Staff <
1185     \type Voice = one  ...
1186     \type Voice = two  ...
1187   >
1188 )
1189
1190 On the ellipsis there should be music going from left to right, in
1191 otherr words, there should be sequential music, notes enclosed in
1192 braces.  Let us try the following simple melodies:
1193
1194 mudela(fragment,verbatim)(
1195 \type "Staff" <
1196   \type "Voice" = "one" { r4 as'4 () as'4 g'4 }
1197   \type "Voice" = "two" { g'2 f'4 e'4 }
1198 >)
1199
1200 As you can see the result is not quite perfect.  The notes on the last
1201 two beats look like plain chords and not like separate voices.  What
1202 really happened was that the stems of the upper and lower voices were
1203 printed on top of each other.  If you have tried running this example, you will probably
1204 have noticed a complaint  about ``too many
1205 clashing notecolumns''  during the LilyPond run.
1206 This complaint refers to the overlapping stems.
1207
1208 To remedy this, engravers traditionally make the stems of the upper
1209 and lower voice point in different directions: the stems of the lower
1210 voice point down, and the stems of the upper up, as shown in
1211 bind(Figure)ref(tutorial:multi-voice-fig).
1212
1213 Surely the direction of a single stem is a property of the stem as a
1214 graphical object.  But the fact that all of the stems in a voice point
1215 in the same direction is not directly graphical.  Since this is a
1216 property shared by all the stems in the voice, it is logical to
1217 consider this property to be a property of the context code(Voice).
1218 And this is how it's done in LilyPond: the context code(Voice) has an
1219 attribute whose value is the direction to use
1220 for stems.  You can change it to `up'
1221 by issuing the following phrase:footnote(The name code(ydirection) is
1222 no mistake.  The property also controls the up/down directions of
1223 super-/subscripts, slurs, ties, etc.)
1224
1225 verb(
1226   \property "Voice"."ydirection" = "1"
1227 )
1228
1229 This command should be read as ``change the property called
1230 code(ydirection) within the current code(Voice) context to the value
1231 code(-1).''  For the property code(ydirection) the value code(1) means
1232 `up', and code(-1) means `down'.   The proper way to code the
1233 polyphonic example is given in bind(Figure)ref(tutorial:multi-voice-fig).
1234
1235 latexcommand(\begin{figure}[h])
1236 mudela(fragment,verbatim,center)(
1237   \type "Staff" <
1238     \type "Voice" =  "one"  {
1239       \property Voice.ydirection = "1"
1240       r4 as'4 () as'4 g'4 }
1241     \type "Voice" =  "two"  {
1242       \property Voice.ydirection = "-1"
1243       g'2 f'4 e'4 }
1244   >
1245 )
1246     latexcommand(\caption{multiple voices})
1247     label(tutorial:multi-voice-fig)
1248 latexcommand(\end{figure})
1249
1250 Other properties can also be set, and they can be within different
1251 contexts.  In general, you can set a property by specifying
1252 code(\property) var(contexttype)code(.)var(propertyname) code(=)
1253 var(value).  Both var(ContextType), var(PropertyName) and var(Value)
1254 should be strings.
1255
1256 The effect of a property is pretty much hardwired into the
1257 implementation (and thus subject to change), so we will not deal with
1258 all the possible properties in detail. Among other characteristics that
1259 can be set are the layout of slurs and beams.  The initialisation file
1260 file(property.ly) explains most properties.
1261
1262 We conclude this section with another example of a context property.
1263 Polyphonic music that has three or four voices can't be printed by
1264 simply changing the directions of the stems for each voice, obviously.
1265 Traditionally, some chords are shifted horizontally to print if this many
1266 voices have to be printed.
1267 LilyPond can also do this, and the property that controls the
1268 horizontal shifting is called code(hshift).  The notes in a
1269 code(Voice) context that has code(hshift) set to a true value (i.e.,
1270 non-zero or non-empty), will be shifted horizontally in the case of a
1271 collision.  The following example demonstrates the effect.
1272
1273 mudela(fragment,verbatim)(
1274   \type "Staff" <
1275     \type "Voice" =  "one"  {
1276       \property Voice.ydirection = "1"
1277       r4 as'4 () as'4 g'4 }
1278     \type "Voice" =  "two"  {
1279       \property Voice.ydirection = "1"
1280       \property Voice.hshift = 1
1281       g'2 f'4 e'4 }
1282     \type "Voice" = "three" {
1283       \property Voice.ydirection = "-1"
1284       [d'8 dis'] [d' cis'] [c' b] c'4
1285     }
1286   >
1287 )
1288
1289 sect(Lyrics)
1290 label(tutorial:lyrics)
1291
1292 Now for something completely different: Lyrics.  Lyrics are also
1293 considered to be music, although a lyric by itself does not have any
1294 pitch.  Producing lyrics has two aspects. First, you have to enter the
1295 text, i.e., the syllables along with their durations.  
1296 After this, you have to specify how to convert these to graphics.
1297
1298 Lyrics consist of syllables, which are strings together with
1299 durations.  Previously we only entered note names, so for entering
1300 lyrics we have to instruct LilyPond that what we enter are not note
1301 names but words---or rather: strings.  This instruction is the keyword
1302 code(\lyrics).  After entering this keyword you can enter a musical
1303 construct---sequential music, simultaneous music, code(\type)
1304 entries, etc.--- but with syllables in stead of pitches.  For example:
1305 verb( \lyrics { 'got8 me on my knees4, Le-8 lie! })
1306
1307 The effect of code(\lyrics) can be compared with the effect of the
1308 doublequote character, code("), for it also changes the lexical
1309 meaning of spaces and characters.  This mode is another example of a
1310 handy input feature of the language.
1311
1312 Next comes the conversion to notation.  LilyPond can't (yet) figure
1313 out that lyrics need different treatment than notes.  As a result, the
1314 default conversion will try to put the text you entered as note heads
1315 onto a staff, and this will fail.  This default must be overriden with
1316 a code(\type) keyword.  Printing syllables of text in a line is done
1317 by a context called code(Lyrics).  You can select this context with
1318 the code(\type) keyword.  Here is a simple example:
1319
1320 mudela(fragment,verbatim)(
1321         \type Lyrics \lyrics { 'got8 me on my knees,4 Le-8 lie! })
1322
1323 The result is technically more or less correct, but without a melody it
1324 just doesn't work, so let's add a blob of cream:
1325 mudela(fragment,verbatim)(
1326   <
1327     \type Staff  { c''8. c''16 bes'8. a'16 g'4 f'8 g'4. }
1328     \type Lyrics \lyrics { 'got8. me16 on8. my16 knees,4 Le-8 lie!4. }
1329   >
1330 )
1331
1332 The strings that makes up each syllable in the lyrics block are passed
1333 along to TeX() verbatim, so if you are proficient with TeX() you can
1334 do various nifty things.  Just keep in mind that a syllable either
1335 starts with a letter (a character in the range `code(a)' to `code(z)'
1336 or `code(A)' to `code(Z)'), or it is a string enclosed quotes. It ends
1337 with either a number for the duration, or a space.  A last feature
1338 that should be mentioned is the space-lyric: if you want to enter
1339 a single ``syllable'' that consists of multiple words, i.e., words
1340 separated by  spaces, you should use an
1341 underscore instead of a space.  All these tricks are demonstrated in
1342 the following example:
1343
1344 COMMENT( urg
1345 \type Lyrics \lyrics { 'got_m\textbf{e}4 on8. m$\cal_Y$16 knees,4 Le-8 lie!4.}
1346 \type Lyrics \lyrics { 'got_m{\bf e}4 on8. m$\cal_Y$16 knees,4 Le-8 lie!4.}
1347 )
1348
1349 mudela(fragment,verbatim)(<
1350   \type Staff  { c''8. c''16 bes'8. a'16 g'4 f'8 g'4. }
1351   \type Lyrics \lyrics { 'got_me4 on8. m$\cal_Y$16 "3s,"4 Le-8 lie!4.}
1352 >
1353 )
1354
1355 The spacing in the above example is a bit skewed because Lily can't
1356 tell that the long syllables you entered are not ordinary characters,
1357 but expand to really small symbols.
1358
1359
1360
1361
1362 COMMENT(Rood is de kleur van geluk.)
1363 COMMENT(Dat geldt ook voor haar.)
1364
1365
1366 sect(Toplevel Mudela)
1367
1368 Now the time has come to unravel the red tape that we have hidden from
1369 you in the introduction.  Mudela has a hierarchical structure for we
1370 have seen that sequential and simultaneous music can be nested.
1371 Mudela also has other `blocks' that can be nested.  The general syntax
1372 for a block is code(\keyword { ... }).
1373
1374 When you run LilyPond, what happens is that you define music, and
1375 specify one (or more) conversions to apply to that music, for example
1376 a conversion to notation.  This is done by putting the definition of
1377 the music and the definition of the conversion together in a
1378 code(\score) block, e.g.,
1379 verb(
1380 \score {
1381         % ... music ...
1382         \paper {}
1383 })
1384
1385 This is almost  the context that should be around all
1386 of the previous examples.  The precise context reads thus:
1387 verb(
1388 \score {
1389         \notes { ... }
1390         \paper {}
1391 })
1392 On the ellipsis, you entered what shown as the example input.
1393 You can see that in the
1394 above example, the code(\notes { ... }) forms the music, the
1395 code(\paper {}) is a conversion to paper (notation, that is).  The
1396 code(\paper) definition is copied from a default definition
1397 (which is in the initialisation file file(paper16.ly)).
1398 The paper part also contains
1399 the definition of the contexts.
1400
1401 The keyword code(\notes) is analogous to the code(\lyrics) keyword.  It
1402 will switch the tokenizer into a mode that interprets plain words as
1403 note names.  If it can't recognize the words as a note name, it will
1404 assume that they are strings.  That is the reason why you can write
1405 code(\clef bass) in stead of code(\clef "bass"); most of the strings
1406 in code(\notes) mode can be written without quotes.
1407
1408 The braces that you see after the code(\notes) keyword are the
1409 braces that are around sequential music.  Because of these braces, the
1410 sequences of notes in our simple examples were sequential (and not
1411 simultaneous).  As a result the notes were printed from left to right,
1412 and not stacked.
1413
1414 sect(Identifiers)
1415
1416
1417 Now that we are comfortable with the toplevel entries in a mudela
1418 file, we can investigate some more of the recreations on toplevel, in
1419 particular em(identifiers).  Generally you can define an identifier by
1420 entering code(identifierName = ... )
1421 where there can be a variety of things on the ellipsis.
1422
1423 Here is a (partial) list of what you can abbreviate with identifiers
1424 at top-level.
1425 itemize(
1426 it()The code(\score) block
1427 it()The code(\paper) block
1428 it()The code(\midi) block (to be explained in
1429   bind(Section)ref(tutorial:sound))
1430 it()Music (sequential music, simultaneous music etc.)
1431 it()Durations
1432 it()Strings
1433 it()Translators (to be explained in bind(Section)ref(tutorial:engravers))
1434 it()Integers
1435 it()Reals  
1436 )
1437
1438 When you refer
1439 to the abbreviated entity, you must precede code(identifierName)
1440 with a backslash, i.e., code(\identifierName).  For example:
1441 mudela(verbatim)(
1442   czerny = \notes { [c16 g e g] }
1443   \score {
1444     \notes \type GrandStaff <
1445       { c''2 g''2 }
1446       { \clef bass; \czerny \czerny \czerny \czerny}
1447     >
1448     \paper {
1449       linewidth = -1.0;
1450       stem_length = 6.0*\interline;
1451     }
1452   }
1453 )
1454
1455
1456
1457 Another interesting feature of this example are the assignments within
1458 the paper block.  Some blocks, such as code(\paper), have a scope of
1459 their own.  In the case of the code(\paper) block, these variables
1460 influence the characteristics of the output.  As is shown, you can
1461 tune quantities like the stemlength, and enter simple expressions.
1462 The purpose of the negative linewidth is to prevent the music from
1463 being justified.  The identifiers that are meaningful are for the
1464 paper block is strongly implementation dependent, so they will not be
1465 listed here.  Moreover, since most of the values are predefined to
1466 sensible defaults, there usually is no need to tune these values.
1467
1468 Recall the properties of a context, that could be set with
1469 code(\property).  It is a very general mechanism to tune the output of
1470 the music, that is neatly separated from the real music.
1471 Unfortunately, it is not convenient to type or read, and the precise
1472 effect of a setting property isn't always apparent from its
1473 definition.  To remedy this, we can use an identifier to capture the
1474 meaning of a code(\property).
1475
1476 mudela(verbatim)(
1477 stemup = \property Voice.ydirection = "1"
1478 stemdown = \property Voice.ydirection = "-1"
1479 shift = \property Voice.hshift = "1"
1480 \score {
1481   \type "Staff" \notes <
1482     \type "Voice" =  "one"  {
1483       \stemup
1484       r4 as'4 () as'4 g'4 }
1485     \type "Voice" =  "two"  {
1486       \stemup
1487       \shift
1488       g'2 f'4 e'4 }
1489     \type "Voice" = "three" {
1490       \stemdown
1491       [d'8 dis'] [d' cis'] [c' b] c'4
1492     }
1493   >
1494   \paper{  linewidth = -1.0\pt; }
1495 }
1496 )
1497
1498 Several abbreviations like code(\stemup) are defined in the
1499 standard initialisation file file(property.ly).  Setting or changing
1500 context properties can have a similar effect as the commands that were
1501 discussed in bind(Section)ref(sec:commands).  Don't be fooled by the
1502 similarity in appearance between a declared property-setting entry
1503 and a real command.  Real commands are hardcoded into the language
1504 and they have to be terminated by semicolons.
1505
1506 You can also use identifiers to break up the heavy nesting that can occur
1507 in the code(\score) block.  Another useful application is
1508 parametrisation of the music: if you use identifiers in the
1509 code(\score) block, you can make variations of the music by simply
1510 redefining those identifiers.  One particular application of this is
1511 part extraction: by using identifiers and redefining them, one can
1512 print extracted parts and a full orchestral score from the same
1513 music definition.
1514
1515
1516
1517 sect(Sound output)
1518 label(tutorial:sound)
1519
1520 You get output by combining music with definition a conversion to
1521 output.  Up till now we have only focused on the graphic output of
1522 traditional engraving.  But there is no reason why that should be the
1523 only form of output for music.  LilyPond currently supports one other
1524 conversion: the conversion from abstract music to sound. You can have
1525 LilyPond play the music that you entered.  The format that is used
1526 for this output is MIDI.  
1527
1528 The only information that you need to enter is the
1529  nop(tempo)footnote(Unfortunately,
1530 this the only thing that can be tuned at this
1531 time.  This is a limitation: the tempo of music can vary throughout
1532 the music.) for the performance.  The syntax for the tempo is
1533 code(\tempo )var(duration) = var(beatsperminute);), for example:
1534 verb(
1535 \score {
1536    ...music...
1537    \midi { \tempo 4 = 76; }
1538 }
1539 )
1540
1541 The most useful purpose of this sound output is to prooflisten your
1542 files: typing errors (especially if they involve accidentals)  stand
1543 out when you listen.
1544 The output was implemented in a very rudimentary manner, so it is
1545 probably not worth listening to for any other reason.
1546
1547
1548 sect(Contexts revisited: engravers)
1549 label(tutorial:engravers)
1550
1551 As was promised, we will now take a dive into the more wizardrous parts
1552 of LilyPond: redefining (notation) contexts.  We previously explained
1553 that a context 
1554 itemize(
1555 it()is a conversion from music to notation,
1556 it()can contain other contexts
1557 it()handles specific notation constructs
1558 )
1559
1560 This characterization almost automatically explains what the definition of a
1561 context should look like:
1562 itemize(
1563 it()It should be part of the ``notation output definition,'' i.e., the
1564   code(\paper) block
1565 it()
1566   It should contain a specification of what other contexts may be contained
1567   in the context we're defining.
1568 it()
1569   It should contain a list of the notation constructs  to be
1570   handled.
1571 )
1572
1573 In practice, the context definition
1574 looks like this:
1575 verb(
1576 \translator
1577 {
1578         \type "Engraver_group_engraver";
1579
1580         \name "ContextName";
1581
1582         \accepts "...";
1583         \accepts "...";
1584         \accepts "...";
1585
1586
1587
1588         \consists " ... ";
1589         \consists " ... ";
1590         \consists " ... ";
1591
1592         propertyname = "value";
1593         propertyname = "value";
1594
1595 } )
1596
1597   This is encoded by the 
1598
1599 The code(\translator) keyword opens the block for translation (or
1600 context) definition.  The code(\type) keyword explains to Lily that
1601 the context should be formed by taking an (empty) instance of
1602 code(Engraver_group_engraver).  The code(Engraver_group_engraver) is a
1603 C++ class from the source code to Lily.  The code(\accepts) entries
1604 explain what kind of contexts this context could contain.  If we were
1605 to define a context for a staff, the definition would typically
1606 contain code(\accepts "Voice";).
1607
1608 The code(\consists) entries specify which notation constructs should
1609 be handled. This needs a little explanation: LilyPond contains the
1610 code for quite a large number of basic building blocks for notation
1611 generation, and each building block handles only one notation
1612 construct.  The name of such a building block is `engraver'.  You can
1613 specify which notation construct a context should handle by specifying
1614 which engravers should be part of the context.  The code(\consists
1615 "Foobar") entry really means ``add an instance of code(Foobar) to the
1616 translation group.''
1617
1618
1619 For example if this context should print time signatures, the definition
1620 should include `code(\consists "Time_signature_engraver";)'.  Again
1621 code(Time_signature_engraver) is a class from the source code of LilyPond.
1622
1623
1624
1625 Finally, one can pre-set some properties in a context definition.
1626
1627 As a practical example, we will show you how to typeset polymetric
1628 music, i.e., music where the meter can differ for each staff.  The
1629 solution is not very complicated: normally all timing information
1630 (time signature, rhythmic grouping) is synchronised across each staff.  In
1631 LilyPond this is expressed by having only one registration for timing
1632 information for all staffs.  To be precise, there is only one
1633 code(Timing_engraver), and it is located in the top level context, the
1634 code(Score) context.
1635
1636 All staffs use the information in the global code(Timing_engraver)
1637 for generating bar lines and time signatures.  In polymetric music, this timing
1638 information can be different for every staff, so we should redefine
1639 the code(Staff) context to include and the code(Score) context to exclude the
1640 code(Timing_engraver).  
1641
1642 mudela(verbatim)(
1643 polymetricpaper = \paper {
1644   \translator {
1645     \ScoreContext
1646     \remove "Timing_engraver";
1647   }
1648
1649   \translator {
1650     \StaffContext
1651     \consists "Timing_engraver";
1652   }
1653 }
1654 \score {
1655   \notes <
1656     \type Staff = one { \time 2/4; c'4 c'4 c'4 c'4 c'4 c'4 }
1657     \type Staff = two { \time 3/4; c'4 c'4 c'4 c'4 c'4 c'4 }
1658   >
1659   \paper { \polymetricpaper
1660     linewidth = -1.;
1661   }
1662 }
1663 )
1664
1665 As you can see, we used the identifier code(polymetricpaper) to break
1666 up the large score block.  More of these context definitions appear in
1667 the standard initialisation file file(engraver.ly).
1668
1669 sect(Urtexts and context selection)
1670 label(tutorial:urtext)
1671
1672 In bind(Section)ref(tutorial:more-staffs), we have shown you how to make
1673 multiple staffs, and explained that you have to label every staff (or
1674 more precisely: different contexts), to make sure that new ones are
1675 created when you need them.  In this section, the real power of this
1676 mechanism will unveiled.
1677
1678 By naming other contexts that you create, you can reference other contexts
1679 than the current context from within the music.  For example, from within the music that you
1680 enter for staff code(One), one could enter a small piece of music,
1681 and send it to staff code(Two), e.g.,
1682 mudela(fragment,verbatim)(
1683   <
1684     \type Staff = one { c''4 \type Staff = two { c4 c4 } c''4 }
1685     \type Staff = two { \clef bass; g,4 g,4 g,4 g,4  }    
1686   >
1687 )
1688
1689
1690 Another useful application of this feature is making Urtexts.
1691 em(Urtext) is the German word for `original text'.  The Urtext
1692 edition of a piece of music, is an edition that reflects the original
1693 writing of the composer.  Such editions are useful for musicologists,
1694 and performers that want  to perform authentic interpretations.  However,
1695 for mere mortals, the Urtext can be quite hard to read.  It might not
1696 contain fingering and beaming, and typically it is full of footnotes.
1697 Moreover, common interpretations may have emerged---after the composer
1698 died.  For this reason, the music that can be had as Urtext usually is also
1699 available in enhanced and edited editions.
1700
1701 The mechanism of context selection can be used to fabricate an Urtext
1702 and an edited edition from em(one source).  We will use the first few
1703 bars of bind(J.)bind(S.)Bach's lovely Cello suite bind(no.)I to
1704 demonstrate this.  The example makes heavy use of space rests: a space
1705 rest takes up time, like a rest does, but it doesn't print anything.
1706 It can be used as a placeholder, to attach articulation marks to.  It
1707 is entered as a note with the name code(s).
1708
1709 mudela(verbatim)(
1710   bach =  \notes { [c16 g e' d'] [e' g e' g] }
1711   
1712   staffStuff = \notes { \clef bass; \time 4/4; s1 \bar "|."; }
1713   
1714   slursOne = \notes { s16( s s s s16 s s )s }
1715   slursTwo = \notes { s16-. s s() s s16() s  s ()s }
1716
1717   \score{
1718     { < \type Voice = celloVoice { \bach \bach }
1719         \type Voice = celloVoice { \slursOne \slursOne }
1720         \staffStuff
1721       >
1722       <
1723         \type Voice = celloVoice { \bach \bach }
1724         \type Voice = celloVoice { \slursTwo \slursTwo }
1725         \staffStuff
1726       >
1727     }
1728     \paper {}
1729   }
1730 )
1731
1732  The slurs that you define should be put on the music that is defined
1733 by the code(\bach) identifier.  By labeling a code(Voice) context, and
1734 directing both the articulation and the notes to that same code(Voice)
1735 context, the articulation is put over the right notes.
1736
1737
1738 sect(Transposing)
1739 label(tutorial:more-grammar)
1740
1741 COMMENT(In this section, we will complete the grammar for Music that was
1742 sketched earlier. )
1743 One of the things that you can do with music is
1744 em(transposing) it.  If you want to transpose a piece of music, then
1745 you should prefix the keyword code(\transpose) along with the pitch
1746 (relative to the central C) for the transposition.footnote(the
1747 code(\type Staff) is to make sure that no separate staffs are created
1748 for the code(\scale) and code(\transpose cis' \scale) part.)
1749
1750
1751 mudela(verbatim)(
1752 scale = \notes \relative c' { [c8 d e f] }
1753 \score {
1754   \notes {
1755     \type Staff { \scale \transpose cis'  \scale }
1756     }
1757   \paper { linewidth = -1.0; }
1758 })
1759
1760
1761 sect(Staff switching)
1762
1763 We have seen that contexts can be nested.  This means that they form a
1764 tree.  It is possible to edit this tree: for example, a code(Voice)
1765 context can be taken out of a code(Staff) context, and put into
1766 another.  This has the effect of the voice switching staffs (something
1767 that often happens in keyboard music).  The syntax for this operation
1768 with these particular contexts is code(\translator Staff = newStaffName).
1769
1770 The effect is analogous to the first example in section
1771 ref(tutorial:urtext), but with the code(\translator) construction it
1772 is possible to split the real music and the commands that determine in
1773 which staff the music is printed.  For example:
1774
1775 mudela(verbatim)(
1776
1777 % real music
1778 aVoice = \type Voice = voiceA \notes { c''4 c4 c4 c''4 }
1779 bVoice = \type Voice = voiceB \notes { g,4 g,4 g,4 g,4  }    
1780
1781 % staff switching stuff
1782 switch = \type Voice = voiceA \notes { s4 \translator Staff = staffB s4
1783                    s4 \translator Staff = staffA s4 }
1784
1785 \score {
1786   <
1787     \type Staff = staffA < \aVoice \switch >
1788     \type Staff = staffB < \bVoice \clef bass; >
1789   >
1790   \paper { linewidth = -1.; }
1791 }
1792 )
1793
1794 Don't try to switch staffs when you are in the middle of a slur or
1795 beam, though.  It doesn't work yet.
1796
1797 sect(Hairy durations: triplets)
1798
1799 In the previous section we explained an operation that changes the
1800 pitches of music, transposition.  In this section we will explain an
1801 operation that modifies the duration of the notes that you enter.
1802 When notes are part of a triplet, then the real of duration of the
1803 notes are 2/3 part of what their shape indicates:
1804 mudela(fragment)(
1805 \[/3  c'4 c'4 c'4 \]/1
1806 )
1807
1808 To support this notion, Mudela allows you to modify the duration of a
1809 note by multiplication or division.  A code(c'4) note that would be in  a
1810 triplet is written as code(c'4*2/3).  If you sequence a few of these
1811 notes, you get a triplet.footnote(We added a normal staff in the example to
1812 show the difference.)
1813 mudela(fragment,verbatim)(
1814 <  \type Staff = staffA { c'8*2/3 c'8*2/3 c'8*2/3 c'4}
1815    \type Staff = staffB { c''8 c''8 c''4 } >)
1816
1817 LilyPond knows that these notes are no normal eighth notes, but the
1818 reader doesn't yet.  To help the reader a beam or a bracket with a `3'
1819 should be printed.  The special beam command `code([2/3)' and the
1820 matching close beam `code(]1/1)' will take care of that, and
1821 they also abbreviate the code(*2/3) part.  If you want brackets in
1822 stead of beams, you can use `code(\[2/3])' and `code(\]1/1)'.
1823 mudela(fragment,verbatim)(
1824 < \type Staff = staffA {
1825     [2/3 c'8 c'8 c'8 ]1/1
1826     \[2/3 c'8 c'8 c'8 \]1/1
1827   }
1828   \type Staff = staffB { [c''8 c''8 c''8 c''8] }
1829 >)
1830
1831 Other tuplets  can be entered in the same way.
1832 mudela(fragment,verbatim)(
1833 < \type Staff = staffA {
1834     \time 7/8;
1835     [7/6 c'8 c'8 c'8 c'8 c'8 c'8 ]1/1
1836   }
1837   \type Staff = staffB {
1838     \time 7/8;
1839     [c''8 c''8 c''8 c''8 c''8 c''8 c''8] } >
1840 )
1841
1842 For your convenience, code([2/3) can be further abbreviated to code([/3), and
1843 you can abbreviate code(]1/1) on the closing beam marker to code(]/1).
1844
1845 mudela(fragment,verbatim)(
1846 < \type Staff = staffA {
1847     [/3 c'8 c'8 c'8 ]/1 c'4
1848   }
1849   \type Staff = staffB { [c''8 c''8] c''4 } >
1850 )
1851
1852
1853 bf(Important) the construct with code([/3) and
1854 code([/1) is a hack that sets a mode in the parser.  This means that
1855 verb(id = \notes { c8 c8 c8 }
1856 notATriplet =\notes { [2/3 \id ]1/1 })
1857 does not produce a triplet.  It will hopefully
1858 soon be replaced by a construction that mixes more elegantly with the
1859 grammar for Music.
1860
1861
1862 sect(Shortcuts for octaves)
1863 label(sec:relativeoctaves)
1864
1865 Plain Mudela contains a lot of quotes to get the octaves right.  This
1866 need for quotes can be reduced: most of the pitch intervals in
1867 conventional music are small.  Therefore, it makes sense to leave out
1868 the quotes when the interval is small.  We have built a mode that does
1869 exactly this.  It is called the relative mode for octaves.  You can
1870 switch it on by entering code(\relative).  Then LilyPond will
1871 interpret every note as if they mean the note with the same name
1872 closest to the previous.  You have to specify the first pitch because
1873 the first note of a list obviously has no predecessor.  So, you can
1874 enter a scale without using octavation quotes, e.g.,
1875
1876 mudela(fragment,verbatim)(
1877     \relative c' { c d e f g a b c }
1878 )
1879
1880 For chords, the relative mode works slightly differently.  In a
1881 sequence of chords, the first note of a chord gives the starting point
1882 for the next chord.  We can demonstrate this with our twinkle twinkle example
1883 verb(
1884   \relative c' {
1885   c4       c            <c g'>    <c e g>
1886   <c e a>  <b d a'>     <b2 d g>
1887   <a4 d f> <bes d f>    <bes c e> <g c e>
1888   <e a d>  <a, g' cis'> <d2 f d'>
1889   }
1890 )
1891
1892 LilyPond converts any music with code(\relative) prepended to absolute
1893 music immediately when it is read. Internally it is stored it in
1894 absolute pitches.  Since the tutorial mainly deals with how to specify
1895 musical information, and not how to enter it conveniently, the
1896 tutorial doesn't use it.
1897
1898
1899 sect(Large pieces)
1900 label(tutorial:large-pieces)
1901
1902 In our quest for a clean and powerfull music language, we took the effort
1903 of entering some larger pieces of music as well.  From this we learned
1904 certain things that lead to direct improvements of Mudela, such as the 
1905 relative mode.  We also gained some practial experience, that resulted in a 
1906 compilation of tips that may be of use to you.
1907
1908 Entering a large piece of music will often imply the need to produce a
1909 conductor's score, as well as individual parts for all instruments.  This
1910 can most easily be achieved making use of identifiers and including mudela
1911 files.
1912
1913 subsect(Identifiers)
1914
1915 Briefly introduced before, identifiers are your biggest help in structurising
1916 a large piece of music.  As an example, we'll consider a string quartet.  
1917 In short, it will look like this: verb(
1918     global = \notes{ }
1919     violinoOne = \notes \relative c { .. }
1920     violinoTwo = \notes \relative c { .. }
1921     viola = \notes \relative c { .. }
1922     violoncello = \notes \relative c { .. }
1923 )
1924
1925 The code(\global) part contains everything that is global, i.e., the
1926 same, for each instrument.  This may include time signature, key, repeat
1927 signs, different bar types, time signature- and key changes, rehearsal
1928 marks, etc.
1929
1930 For each instrument, you'll have something vaguely resembling verb(
1931     violinoOneStaff = \type Staff = violinoOne <
1932         \property Staff.midi_instrument = "violin"
1933         \property Staff.instrument = "Violino I"
1934         \property Staff.instr = "Vl. I"
1935         \global
1936         \violinoOne
1937     >
1938 )
1939
1940
1941 [Versions, relative mode,
1942  barchecks, splitting of files]
1943
1944 subsect(Including Mudela files)
1945 ref(subsect:include)
1946
1947 You can include other Mudela files  with the command code(\include):
1948 verb(
1949 \include "paper13.ly"
1950 \score {
1951        ...
1952        \paper { \paper_thirteen }
1953 })
1954
1955 The file is looked for in the  standard search path.
1956
1957
1958 subsect(Grouping of staffs)
1959
1960 subsect(Versioning)
1961
1962 sect(Titling)
1963 label(tutorial:titling)
1964
1965 A piece of sheet music isn't complete without proper opening and
1966 closing titles.  LilyPond does not have any real support for setting
1967 text: that is a job best left to TeX().  But you can pass messages to
1968 TeX() from the input file.   You can  write TeX() macros to handle
1969 these messages.
1970 To do this, you add a code(\header) block
1971 to your input file.  The format is quite simple,
1972
1973 verb(
1974 \header{
1975     "key" =  "value";
1976     "key" =  "value";
1977     "key" =  "value";
1978     % etc.
1979 })
1980
1981 When  the results of the music typesetting are output, the contents of
1982 code(\header) are also up into the TeX() file.  Tools like
1983 code(ly2dvi) can use this information to generate pretty titling for
1984 your input file. Consult the manual page of code(ly2dvi) for more
1985 details.
1986
1987
1988 The code(\header) block should be at toplevel in mudela, and
1989 preferably at the top of the file.  If you have an input file  with
1990 multiple code(\score) blocks, you should add a header to every score,
1991 describing the different sub parts of the music piece, eg.
1992
1993
1994 verb(\header {
1995         "composer" = "Ludwig Van Bavaria";
1996         "title" = "Symphonie Megalomane";
1997     }
1998     \score{
1999        ... % some music
2000        \header { movement = "Mit roher Kraft wild herausfahrend!"; }
2001       \paper { }
2002     }
2003     \score{
2004        ... % some more music
2005        \header { movement = "Saut\'e comme un oeuf."; }
2006       \paper { }
2007     }
2008 )
2009
2010 If you want you can also put the code(\header) block at the top of the
2011 input file; it will then be put into every output file automatically.
2012 This will make it clear what the file contains as soon as you open it.
2013
2014
2015