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