]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/mudela.doc
release: 0.1.65
[lilypond.git] / Documentation / tex / mudela.doc
1 % -*-tex-*-
2
3 % this document should be run through the mudela-book script after lilypond
4 % has been installed.  The rules have been precooked into the
5 % Documentation/Rules.make file; do 
6 %
7 %   make out/mudela.dvi
8 %
9 % or
10 %
11 %   mudela-book --outdir=out/ --outname=mudela.mudtex mudela.doc
12 %   latex '\nonstopmode \input out/mudela.mudtex'
13
14 % Hoi Tim, hier staan wat 'enge' commando's (die dingen met een '\'
15 % zoals \documentclass en \def\mudela...).
16 % Daar moet je je niets van aantrekken, ga gewoon naar Introduction
17 % en begin te tiepen.
18
19 \documentclass{report}
20 \usepackage{a4wide}
21 \title{Mudela}
22 \author{Jan Nieuwenhuizen \& Han-Wen Nienhuys}
23
24 \def\file#1{\verb+#1+}
25
26 % ugh: trick to get examples not generate par
27 % these are for 16pt
28 \def\mudelapaperlinewidth{-28.452756}%
29 \def\mudelapaperindent{28.452756}%
30 \def\mudelapaperrulethickness{0.400000}%
31 \def\mudelapaperbarsize{16.000000}%
32 \def\mudelapaperinterline{4.000000}%
33 \def\mudelapapernotewidth{5.930000}%
34 \def\mudelapaperwholewidth{8.640000}%
35 \def\mudelapaperunitspace{22.000000}%
36 \def\mudelapaperbasicspace{4.000000}%
37 \def\mudelapapergeometric{0.000000}%
38 \def\mudelapaperarithmetic_basicspace{2.000000}%
39 \def\mudelapaperarithmetic_multiplier{4.800000}%
40 \def\mudelapaperinterbeam{3.140000}%
41 \def\mudelapapergourlay_energybound{100000.000000}%
42 \def\mudelapapergourlay_maxmeasures{14.000000}%
43 % huh?
44 % \def\exampleheight{2\mudelapaperbarsize pt}
45 \def\exampleheight{2cm}
46
47 % ful of pars, needs the above
48 \input lilyponddefs
49 % generates par
50 \musixsixteendefs
51 \def\musixsixteendefs{}
52 % generates par
53 \turnOnPostScript%
54 \def\turnOnPostScript{}
55 % generates par
56 \def\interscoreline{}
57
58
59 \begin{document}
60 \maketitle
61
62 %\def\interexample{\hskip15mm$\Longrightarrow$\hskip15mm}
63 %\def\interexample{\hbox to10mm{\hfill\hbox to0pt{\hss\vbox to\exampleheight{\vss$\Longrightarrow$\vss}\hss}\hfill}}
64 \def\interexample{}
65 \def\preexample{\par}
66 \def\postexample{\par\medskip}
67
68 \def\file#1{{\texttt{#1}}}
69 \setcounter{secnumdepth}{-1}
70
71 \chapter{A tutorial}
72
73 \emph{\Large ***Under construction: may 98***}
74
75 \section{Introduction}
76
77 This chapter is a gentle introduction to using LilyPond to typeset
78 simple music.
79
80 LilyPond is a so called ``batch'' program.  This means, that you use a
81 text editor (such as \texttt{emacs} or \texttt{vi}) to create an input
82 file.  When you are done editing your input file, you save it, and you
83 run LilyPond on the file.  If Lily finds any errors in your input file
84 then she\footnote{ We're sure that if computer programs could have
85 gender, LilyPond would be a female computer program.  So we will refer
86 to the program as a she. This gender-bending is not to tease you, dear
87 reader.  We do it in real life as well. In the past two years LilyPond
88 has become sort of a baby daughter to us, keeping us awake at night,
89 but also providing us lots of joy.  We hope you do not mind our little
90 aberration from computer-manual tradition.
91
92 % The name LilyPond is actually sort of a girl's name.  Can you guess which
93 % one ?
94 %
95 } will complain.  If everything is well, than she'll generate a file, that
96 you can process further to view or print.
97
98 Using LilyPond to print or view some music is a procedure with four
99 steps.  To get you started we'll run down the full procedure for you
100 once.
101
102 \begin{enumerate}
103 \item
104 Fire up your favourite editor (if you know none, try \texttt{joe silly.ly}),
105 and key in the following text:
106 \begin{verbatim}
107 \score {
108         <
109         \type Staff = aStaff \melodic { g'2 e'4 }
110         \type Lyrics = yell \lyric { Air2 ball!4 }
111         >
112         \paper {}
113 }
114 \end{verbatim}
115
116 Save your file as \file{silly.ly}.
117
118 %The input files for LilyPond have the default extension \file{.ly}.
119
120 \item
121 Run LilyPond on your newly created file: enter \verb+lilypond silly+.
122 LilyPond will then print all kinds of mumbo jumbo that can safely be
123 ignored.  You might see something like this:
124 \begin{verbatim}
125 GNU LilyPond 0.1.55/FlowerLib 1.1.39
126 Parsing ... [/home/hanwen/musix/spacer/init/lily-init.ly[/home/hanwen/
127
128         ... stuff left out here ...
129
130                                 Documentation/silly.ly]
131 Interpreting music ...[1] (time: 0.04 seconds)
132 Preprocessing elements... 
133 Calculating column positions ... [2]
134 Approximated: 1 lines, (with an average of 4.0 columns)
135 Time: 0.01 seconds
136 warning: Can not solve this casting problem exactly; revert to Word_wrap
137 [2]Time: 0.00 seconds
138
139 Postprocessing elements...
140 TeX output to silly.tex ...
141 \end{verbatim}
142 All has gone well; there were some warning but no errors.  The output
143 is a TeX file, and it is called \file{silly.tex}.  \file{TeX} is
144 usually spelled as \TeX.  It is batch program for typesetting text,
145 developed by the great programmer and scientist Donald Knuth to
146 typeset his famous The Art of Computer Programming bookseries.  As you
147 can see \TeX\ can be adapted to do a lot more.  In fact, the document
148 that you are reading now was also done with \TeX.
149 \item
150   To do something useful with the output you have to run \TeX\ on it
151   first.  Run the command \verb+tex silly+.  The output should resemble this:
152 \begin{verbatim}
153 This is TeX, Version 3.14159 (C version 6.1)
154 (silly.tex
155 Babel <v3.6h> and hyphenation patterns for american, dutch, loaded.
156 (/home/hanwen/lib/texmf/tex/lilypond/lilyponddefs.tex
157 (/home/hanwen/lib/texmf/tex/lilypond/dyndefs.tex)
158 (/home/hanwen/lib/texmf/tex/lilypond/fetdefs.tex
159 (/home/hanwen/lib/texmf/tex/lilypond/feta20.tex)
160 (/home/hanwen/lib/texmf/tex/lilypond/lily-ps-defs.tex))) [1] )
161 Output written on silly.dvi (1 page, 3084 bytes).
162 Transcript written on silly.log.
163 \end{verbatim}
164   The human translation is ``everything went OK, the result is one
165   page long, and I put it in \file{silly.dvi}.''
166
167 \item The \file{silly.dvi} file is a description of how a piece of
168 text looks when it is printed.  You can view it, or print it.  If you
169 are using a Unix system equipped with X-Windows, then you can issue
170 the command \file{xdvi silly} to view the result.  If this is not the
171 case, consult your local \TeX\ guru on printing and viewing DVI files.
172 What is in your window should look like this:
173 \begin{mudela}
174 \score {
175         <
176         \type Staff = aStaff \melodic { g'2 e'4 }
177         \type Lyrics = yell \lyric { Air2 ball!4 }
178         >
179 }
180 \end{mudela}
181 \end{enumerate}
182
183 The above is quite a lot of work.  Moreover, the result is pretty
184 crude: the page does include prettily printed titles, composer.  Jan
185 Arne Fagertun wrote a tool to take the above tedious  steps out of
186 your hands.  The tool is called ly2dvi, and it should be on your
187 system if you run Unix.  If you use ly2dvi, then you can do
188 \begin{verbatim}
189         ly2dvi silly.ly
190 \end{verbatim}
191 in stead of steps 2 and 3.  You feel the real win of ly2dvi when you
192 add titling to the music.  This is something that we will discuss in [XXX]
193
194
195 The remainder of this document is not about \TeX, and mostly not even
196 about LilyPond.  What you entered into your text editor in step~1. and
197 fed to LilyPond is a special kind of file composed of notenames,
198 special words and punctation.  The remainder of this document explains
199 how to combine these elements to express a piece of music in the
200 language that LilyPond understands.  In other words, we try to explain
201 how to use LilyPond, and not how LilyPond works.  For want of a better
202 name we call the language Mudela (short for Music Description
203 Language).
204
205 This document does not cover all of Mudela.  Due to technical details,
206 the precise working of Mudela is coupled to the innards of LilyPond.
207 If you really want to know all the details, your best bet would be to
208 get the sources to LilyPond and read the parser and scanner source.
209 They are in \file{lilypond-x.y.z/lily/parser.y},
210 \file{lilypond-x.y.z/lily/lexer.l}\footnote{Of course, it would be even
211 better if you would improve LilyPond and send the resulting diffs to
212 us.  But that would a really different ballpark (And we haven't
213 started with the programming guide yet.)}
214
215 In the following sections the basic elements of Mudela are presented.
216 We don't want to bore you too much with details, so we will leave-out
217 some red tape that's needed for a valid piece of Mudela: to be
218 precise, we will write \verb+X Y Z+, when we really mean
219 \begin{verbatim}
220 \score {
221         \melodic { X Y Z }
222         \paper {}
223 }
224 \end{verbatim}
225 Usually, we will also print the resulting fragment of music on the
226 right just as it was produced by LilyPond.  
227
228 For the remainder we will assume that you can carry out steps 1 to 4
229 from the above instruction.  We will also assume that you know how
230 music notation works.  If you are not familiar with the English terms
231 for music notation, then you should consult XXXX [FIXME], it contains
232 a glossary of musical terms.
233
234 \section{Music copying versus music definition versus music entry}
235
236 If you have done music copying before, then using LilyPond may seem
237 awkward to you in the beginning.  The purpose of LilyPond is informally
238 explained by the term ``music typesetter.''
239
240 This may give the impression that the program is like a drawing tool
241 that lets you control precisely how the music is formatted.  This is
242 not the case: not only does the program print musical symbols,
243 LilyPond also tries to make esthetic decisions---to be precise, we
244 programmed her to do what we find pretty.  You do not have complete
245 control over what is happening.  On the other hand, good engraving is
246 a very complex trade, so it is a Good Thing that you do not have to
247 worry about what is happening.
248
249 Secondly, LilyPond operates on musical definitions.  This really is
250 something different from graphical definitions.  If you copy music by
251 hand from a printed score, you don't have to know what the score
252 means; you just copy the symbols.  With LilyPond such a thing is not
253 possible: we expect you to enter the meaning of the score, not the
254 score itself.  If put more concretely: you do not enter ``black
255 notehead without flag, fourth staff line, with dot'', but ``a dotted
256 quarter note, pitch d$^2$''.  LilyPond will figure out from the
257 musical info what kind of graphic presentation is needed.
258
259 This has some drawbacks: most notably, it is difficult to enter sheet
260 music that you cannot read.  On the other hand, any piece of music
261 once entered can be played and transposed automatically.
262
263 Finally, in some spots we will cheat a bit when it comes to musical
264 definition.  Mudela has some entry modes that help you to make typing
265 mudela pleasant.  For example, the verbose phrase ``a dotted quarter
266 note, pitch d$^2$'' translates to the following longhand 
267 \begin{verbatim}
268    \musical_pitch { 1 2 0 } \duration { 2 1}
269 \end{verbatim}
270 You can be conveniently abbreviate this to \verb+d''4.+, which is
271 considerably shorter.  There are some features that also make the
272 quotes and numbers in \verb+d''4.+ superfluous in some cases.
273
274 \section{When you know the notes to print\ldots}
275
276 The basic building block of music is the note.  You can have LilyPond
277 print a note by specifying its pitch and the duration.  The pitch of
278 the central C, also known as c$^1$, is written as \verb+c'+.  A quarter
279 note duration is written as \verb+4+.  So, to print quarter note with
280 central C pitch, you enter the following
281 \begin{mudela}[fragment,verbatim,center]
282 c'4
283 \end{mudela}
284 The pitch \verb+c'+ actually consists of two parts: one for the note
285 name, and one part for the octave.  The number of apostrophes
286 specifies the octave to use if you are above central c.  If you want
287 the octaves below central c, use the comma, eg, \verb+c,,+ (The comma
288 is meant to represent a ``sunken'' apostrophe). The letter specifies
289 which note name to use.  The note names simply are the letters
290 \verb+a+ to \verb+g+.
291
292 By convention, the \verb+a'+ concert pitch is the tone that is used to
293 tune instruments.  The exact frequency of this tone has wandered: in
294 Baroque time it was 335 Hz, most textbooks will tell you it is 440 Hz,
295 and a lot of orchestras nowadays tune at 441.5 Hz.
296
297 For example,
298 \begin{mudela}[fragment,verbatim]
299   c'4 d'4 e'4 c'4 c''4 d''4 e''4 f''4 g''4 a''4 b''4 c'''4
300 \end{mudela}
301
302 The duration of a note is specified as a number: a whole note is
303 denoted by 1, the half note by 2, the quarter by 4, and so on.  Here
304 are some random notes to show how it works
305 \begin{mudela}[fragment,verbatim]
306 c,8 c8 c'16 c''32 d''64 b'64 c'''2 c1 c'4 d'4 e'4 f'4 g'4 a'4
307 \end{mudela}
308
309 This gives us already enough material to make simple songs:
310 \begin{mudela}[fragment,verbatim]
311         c''4 d''4 e''4 c''4
312         e''4 f''4 g''2
313         g''8 a''8 g''8 f''8 e''4 c''4
314         c''4 g'4 c''2
315 \end{mudela}
316
317 There is only one part about pitches that we haven't told you:
318 chromatically altered pitches.  The names ``a'' to ``g'' for typing
319 pitches are convenient: they are short, pronounceable and they
320 resemble the normal vocabulary for pitches.
321
322 Enter flats and sharps.  In English there is no standard terse word
323 for C sharp or C flat.  For this reason, we implemented a different,
324 non-english convention for entering altered pitches, see
325 table~\ref{notename-tab}: one makes a note sharp by adding the suffix
326 ``--is'' to the name, one makes the a note flat by adding the suffix
327 ``--es.''  For a double sharp you simply add another ``--is'' suffix,
328 flats ditto.
329
330
331 \begin{table}[h]
332   \begin{center}
333     \caption{Default note names}\label{notename-tab}
334     
335     \begin{tabular}{ll}
336       english         &LilyPond\\
337       \hline\\
338       c double flat   &ceses\\
339       c flat          &ces\\
340       c natural       &c\\
341       c sharp         &cis\\
342       c double sharp  &cisis\\
343     \end{tabular}
344     
345   \end{center}
346 \end{table}
347
348 Variations on this convention are used in a number of germanic
349 languages, notably Dutch, German, Swedish, and Norwegian.  To be
350 precise, LilyPond actually defaults to dutch notenames, with aes,
351 aeses, ees and eeses added for consistency.
352
353 If you are not comfortable with these names, you can make your own
354 names.  Included with the example initialisation files are note names
355 for different languages, among others English (C sharp is abbreviated
356 to cs), Italian, Swedish, Norwegian
357
358 \section{[chords]}
359
360 Up till so far we have only considered music that was rather simple.
361 All the music had notes going in one direction, from left to right,
362 the one following the other.  You might be wondering if this is all
363 Lily could do, or whether is possible to stack notes as well (creating
364 \emph{chords}).  Rest assured: we designed LilyPond with the goal mind
365 that she must handle any notation construct that can be expressed
366 conveniently.  Of course, we did not leave out chords.
367
368 In mudela you can form a chord of several notes, by enclosing them in
369 pointed parentheses, ie, $\langle$ and $\rangle$, for example a
370 D-major chord can be described by
371 \begin{mudela}[fragment,verbatim]
372   <d'8  fis'8 a'8 d''8>
373 \end{mudela}
374 Recall what was said in the previous section about flats and sharps:
375 the \texttt{fis} is an f sharp.  Chords can be entered in the music in
376 same places that notes can.  As an example we give a snippet of
377 ``twinkle twinkle little star'' in chords.  The chords may seem, well,
378 unconventional, but they mostly serve to show how chords work 
379 \begin{mudela}[verbatim, fragment]
380   c''4 c''4 <c''4 g''4> <c''4 e''4 g''4>
381   <c''4 e''4 a''4> <b'4 d''4 a''4> <b'2 d''2 g''2>
382   <a'4 d''4 f''4> <bes'4 d''4 f''4> <bes'4 c''4 e''4> <g'4 c''4 e''4>
383   <e'4 a'4 d''4> <a4 g'4 cis''4> <d'2 f'2 d''2>
384 \end{mudela}
385
386 \section{Shortcuts}
387
388 If you have typed the last example in to a mudela file, you will have
389 noticed that the input has lots of repetitions.  You probably made
390 some little errors with the right amount of \texttt{'}'s as well.  For
391 these reasons, saving keystrokes and preventing errors, mudela has
392 some handy shortcuts.  You don't have to type the duration, if it the
393 same as the last duration entered.  This saves a considerable number
394 of keystrokes, and thus it reduces the potential for errors.  The
395 previous example can be reduced to
396 \begin{verbatim}
397   c''4 c'' <c'' g''> <c'' e'' g''>
398   <c'' e'' a''> <b' d'' a''> <b'2 d'' g''>
399   <a'4 d'' f''> <bes' d'' f''> <bes' c'' e''> <g' c'' e''>
400   <e' a' d''> <a g' cis''> <d'2 f' d''>
401 \end{verbatim}
402
403 The need for quotes can also be reduced: most of the pitch intervals
404 in traditional music are small.  Therefore, it makes sense to leave
405 out the quotes when the interval is small.  This is called the
406 relative mode for octaves.  You can switch it on by entering
407 \verb+\relative+.  From then on, the pitch of a note will be the
408 closest to the last one.  You have to specify the first pitch because
409 the first note of a row obviously has no predecessor.  Thus, you can
410 enter a scale without using octavation quotes, eg,
411
412 \begin{mudela}[fragment,verbatim]
413     \relative c' { c d e f g a b c }
414 \end{mudela}
415
416 For chords, the relative mode works slightly differently.  In a
417 sequence of chords, the first note of a chord gives the starting point
418 for the next.  We can demonstrate this with our twinkle twinkle example
419 \begin{verbatim}
420   \relative c' {
421   c4 c <c g'> <c e g>
422   <c e a> <b d a'> <b2 d g>
423   <a4 d f> <bes d f> <bes c e> <g c e>
424   <e a d> <a, g' cis'> <d2 f d'>
425   }
426 \end{verbatim}
427
428
429
430 \section{Finishing touch}
431
432
433
434 \chapter{Features}
435
436 Durations are entered as their reciproce values
437 % a1 a2 a4 a a8 a a16 a a32 a a64 a a a a
438 \begin{mudela}[fragment,verbatim,center]
439 a1 a2 a4 a a8 a a16 a32 a64
440 \end{mudela}
441 note that you only have to specify
442 the duration when it changes:
443 Lily assumes a note has the same duration as the previous one.
444
445 Now we can already write a little tune
446 \begin{mudela}[fragment,verbatim,center]
447 c d e c | c d e c | e f g2
448 \end{mudela}
449 As you'll probably have guessed,
450 the vertical bar (pipe) \verb+|+ may be used to mark
451 measures.
452
453 In the scale shown above
454 we left-out the last c note of the next octave.
455 Postfixing the pitch with a quote \verb+'+
456 produces a note by one octave higher
457 \begin{mudela}[fragment,verbatim,center]
458 c c' c''
459 \end{mudela}
460
461 Prefixing the pitch with a quote \verb+'+
462 produces a note by one octave lower
463 \begin{mudela}[fragment,verbatim,center]
464 a a, a,,
465 \end{mudela}
466
467 \section{Slurs and Ties}
468
469 A tie connects two adjacent noteheads
470
471 \begin{mudela}[fragment,verbatim,center]
472 e' ~ e
473 \end{mudela}
474
475 Whereas a slur rather connects `chords', 
476 and tries to avoid crossing stems
477
478 \begin{mudela}[fragment,verbatim,center]
479 e'( )e
480 \end{mudela}
481
482 And of course, such a (legato) slur can span several notes
483 \begin{mudela}[fragment,verbatim,center]
484 c( d e )f
485 \end{mudela}
486
487 \section{Beams and Plets}
488
489 A beam is 
490 \begin{mudela}[fragment,verbatim,center]
491 [a8 a] [a16 a a a]
492 \end{mudela}
493
494 Here's a beamed triplet
495 \begin{mudela}[fragment,verbatim,center]
496 [/3 a8 a a]/1
497 \end{mudela}
498
499 a triplet without a beam
500 \begin{mudela}[fragment,verbatim,center]
501 \[/3 a4 a8\]
502 \end{mudela}
503
504 and a combination
505 \begin{mudela}[fragment,verbatim,center]
506 [/3 a8 a16 a] a8 \]
507 \end{mudela}
508
509 Abbreviations
510 \begin{mudela}[fragment,verbatim,center]
511 c1:16 [:16 e1 g]
512 \end{mudela}
513
514 \begin{mudela}[fragment,verbatim,center]
515 c4:32 [:16 c8 d8]
516 \end{mudela}
517
518 \section{Notenames}
519
520 Lily has predefined sets of notenames
521 for various languages%
522 \footnote{These are Dutch, English, German, Italian and Swedish.
523 Simply include the language specific init file \file{<language.ly>}.}.
524 The default set are the ones we like best are the Dutch notenames.
525
526 A sharp is formed by adding \verb+is+
527 \begin{mudela}[fragment,verbatim,center]
528 cis dis eis fis gis ais bis
529 \end{mudela}
530
531 and a flat is formed by adding \verb+es+%
532 %\footnote{Exceptions: \verb+es+ and \verb+as+.}
533 \footnote{Exceptions: {\tt es} and {\tt as}.}
534 \begin{mudela}[fragment,verbatim,center]
535 ces des es fes ges as bes
536 \end{mudela}
537
538 With the obvious names for double sharps
539 \begin{mudela}[fragment,verbatim,center]
540 cisis disis eisis fisis gisis aisis bisis
541 \end{mudela}
542
543 and double flats
544 \begin{mudela}[fragment,verbatim,center]
545 ceses deses eses feses geses ases beses
546 \end{mudela}
547 See why we like-em?
548
549 There are two special `notenames', the rest
550 \begin{mudela}[fragment,verbatim,center]
551 r16 [a a a]
552 \end{mudela}
553
554 and the space
555 \begin{mudela}[fragment,verbatim,center]
556 a2 s-"diminuendo" | a
557 \end{mudela}
558
559
560 \section{Commands}
561
562 \begin{mudela}[fragment,verbatim,center]
563 \clef "bass"; c,
564 \end{mudela}
565
566 and a clef-change
567 \begin{mudela}[fragment,verbatim,center]
568 \clef "violin"; f' e' \clef "alto"; d' c'
569 \end{mudela}
570
571 \begin{mudela}[fragment,verbatim,center]
572 \meter 3/4; c g g |
573 \end{mudela}
574
575 \begin{mudela}[fragment,verbatim,center]
576 \key fis cis;
577 g, a, b, cis d e fis g'
578 \end{mudela}
579 Note how Mudela allows you to 
580 convey a musical message
581 rather than forces you to produce a list of typesetting commands.
582 If the music a \verb+cis+, you type a \verb+cis+.
583 Depending on the key and context of the note
584 Lily will determine what accidentals to typeset.
585
586 A reminder accidental can be forced by
587 using an exclamation mark \verb+!+
588 on a pitch a reminder accidental
589 \begin{mudela}[fragment,verbatim,center]
590 cis d e cis | c! d e c |
591 \end{mudela}
592
593 \begin{mudela}[fragment,verbatim,center]
594 \meter 2/4;
595 \bar "|:"; c c \bar ":|:"; c c \bar ":|"; c c \bar "|."; 
596 \end{mudela}
597
598 \section{Chords and Voices}
599
600 Here's a simple chord
601 \begin{mudela}[fragment,verbatim,center]
602 <c e g>
603 \end{mudela}
604
605 here are a few
606 \begin{mudela}[fragment,verbatim,center]
607 <
608         { c()d()c }
609         { e()f()e }
610         { g()a()g }
611 >
612 \end{mudela}
613
614 and similarly voices
615 \begin{mudela}[fragment,verbatim,center]
616 <
617         { \voiceone c g c g }
618         { \voicetwo c,2 g,2 }
619 >
620 \end{mudela}
621
622
623 \section{A complete example}
624 %\label{se:complete}
625
626 A Mudela file needs some red tape
627
628 \begin{mudela}[verbatim,center]
629 \score{
630         \melodic {
631                 \octave c';
632                 c d e c |
633                 c d e c |
634                 e f g2 |
635         }
636 }
637 \end{mudela}
638
639 \section{Lyrics}
640
641 \begin{mudela}[verbatim,center]
642 \score{
643         < 
644                 \melodic{ 
645                         \octave c'; 
646                         c d e c | c d e c |
647                         e f g2 | e4 f g2
648                         \bar "|.";
649                 }
650                 \type Lyrics \lyric{ 
651                         Fr\`e-4 re Ja- que
652                         Fr\`e- re Ja- que
653                         Dor- mez vous?2
654                         Dor-4 mez vous?2
655                 }
656         >
657 }
658 \end{mudela}
659
660 \section{Variables}
661
662
663 \section{Ly2dvi}
664 Check-out this handy little script 
665 that not only may save you quite some keystrokes,
666 but produces titles and takes care of
667 margins and (hopefully) papersizes.
668 See \file{ly2dvi (1)}.
669
670 \chapter{Input format reference}
671
672 October 8, 1997
673
674 This document describes the the GNU LilyPond input format, which is an
675 effective language for defining music.  We call this language (rather
676 arrogantly) The Musical Definition Language or Mudela, for
677 short.\footnote{If anybody comes up with a better name, we'd gladly
678   take this. Gourlay already uses Musical Description Language,
679   G-Sharp Score Definition Language.  ISO standard 10743 defines a
680   Standard Music Description Language.  We're not being original here}
681
682 The first aim of Mudela is to define a piece of music, being complete
683 from both from a musical typesetting, as from a musical performing
684 point of view.
685
686 The Musical Definition Language (Mudela), has a logical structure,
687 making use of identifiers, that allows for flexible input, and
688 definition reuse. See \file{MANIFESTO} for reasons and design considerations.
689
690 The below included for explanatory purposes only (i.e., for a complete
691 and up-to-date definition, see \file{lily/parser.y} and
692 \file{lily/lexer.l}):
693
694 As a related note, you should take a look at the examples and the init
695 files, as this document does not cover every aspect of mudela yet, and
696 may be out of date.\footnote{Ok, I am being pessimistic here.  This
697   just is a disclaimer.  Docs usually are written after the program
698   itself.}  This document intends to give an idea of how it works, it
699 is not a guide on how to use it.  
700
701
702 \section{Basic elements}
703
704 \subsection{Files}
705
706 The de-facto extension of Mudela is \file{.ly}. Files may be included by
707 entering \verb+\include+ at the start of a line:
708
709 \begin{verbatim}
710 \include "a_file.ly"
711 \end{verbatim}
712
713
714 \subsection{Comments}
715
716 Line comments are introduced by a
717 \verb+%+. 
718 Block comments are delimited
719 by 
720 \verb+%{+ 
721 and
722 \verb+%}+. 
723 They do not nest.
724
725 \subsection{Versions}
726
727 Occasionally, small changes in syntax across different versions of
728 Mudela might give syntax errors. To warn you about possible
729 incompatibilities, you can specify the Mudela version for which the
730 inputfile was written,
731 \begin{verbatim}
732 \version "0.0.50";
733 \end{verbatim}
734
735 A perl-script which tries to convert to newer versions
736 (\file{convert-mudela}) is included in the LilyPond distribution.
737
738 \subsection{Words}
739
740 Keywords are preceded by a backslash: \verb+\+. They contain
741 alphabetic characters only.
742
743 Identifiers in their normal form consist start with a backslash, a
744 alpha character, followed by alpha-numerics. Identifiers can contain
745 any characters (except whitespace, 
746  and \verb+%+), if you use this construct:
747
748 \begin{verbatim}
749 \$i'm_a_weird!!!identifier
750 \end{verbatim}
751
752 (which is the identifier with the name
753 \verb+i'm_a_weird!!!identifier+).  \verb+$+ Takes any sequence of
754 characters which are not whitespace, \verb+$+ and \verb+%+.
755 \verb+$i'm_a_weird!!!string+
756 \def\foobar{$} % silly fontlock mode 
757
758 \subsection{Nesting characters}
759
760 Mudela uses the brace (\verb+{+ and \verb+}+) for most hierarchical
761 structures.  For chords the \verb+<+ and the \verb+>+ are used as
762 nesting braces.
763
764 \subsection{Constants}
765
766 Please note that -.5 is not a Real.
767
768 \begin{verbatim}
769 "I am a string"
770 -1.2e3          % a real
771 12              % an int
772 \end{verbatim}
773
774         
775 \subsection{Identifiers}
776
777 When assigning identifiers you use
778
779 \begin{verbatim}
780 string = ...
781 \end{verbatim}
782
783 If you reuse identifiers, then the previous contents will be thrown
784 away after the right hand is evaluated, eg
785 \begin{verbatim}
786 bla = \melodic { \bla }
787 \end{verbatim}
788 is legal
789
790 When using identifiers they have to be escaped:
791
792 \begin{verbatim}
793 oboe = \melodic { ... }
794 \score{ \melodic { \oboe }}
795 \end{verbatim}
796
797 The left-hand part of the assignment is really a string, so 
798 \begin{verbatim}
799 "Foo bar 4 2 " = \melodic { .. }
800 \end{verbatim}
801
802 is also a valid assignment (but you would have trouble referencing to it)
803
804
805 \subsection{Hierarchical structures}
806
807 The general structure consists of declarations:
808 \begin{verbatim}
809 IDENTIFIER = \TYPE{
810         <type specific data>
811 }
812 \end{verbatim}
813 and instantiations:
814
815 \begin{verbatim}
816 \TYPE{ <type specific data> }
817 \end{verbatim}
818
819 (Currently, \verb+\score+ is the only type that can be instantiated
820 at top level. Currently declarations can only be done at top level)
821
822 Most instantiations that use an IDENTIFIER are specified as follows:
823
824 \begin{verbatim}
825 \TYPE{ IDENTIFIER [...] }
826 \end{verbatim}
827
828 Some exceptions on this rule have been made to prevent inputting
829 Mudela becoming tedious
830
831
832 \subsection{Modes:}
833
834 To simplify different aspects of music definition (entering the notes
835 and manipulating them) Mudela has a number of different input "modes":
836
837 \begin{description}
838
839
840 \item[Normal mode]
841
842 At the start of parsing, Mudela assumes normal mode.
843 In Normal mode, a word is looked up in the following order:
844 \begin{description}
845 \item{\verb+word+}    string
846 \item{\verb|"string"|} string
847 \item{\verb|\word|} keyword, identifier
848 \end{description}
849 In normal mode, a word is assumed to start with an alphabetic
850 character, followed by alpha-numeric characters.
851
852 \item[Note mode] Note mode is introduced by the keyword
853   \verb+\melodic+.  In Note mode, a word is looked up in the following
854   order:
855 \begin{description}
856 \item{\verb+word+} notename, string
857 \item{\verb|"string"|} string
858 \item{\verb|\word|} keyword, identifier
859 \end{description}
860
861 In Note mode a word is considered to have alphabetic characters only,
862 so the underscore (\_) is illegal.  If you accidently mistype a
863 notename, the parser will assume that you are entering a string (and
864 it will most likely complain that you should be in \verb|\lyrics| mode to
865 do lyrics)
866
867
868 \item[Lyric mode] Lyrics mode (and thus Simple mudela) is introduced
869   by the keyword \verb+\lyrics+.  Because of the various control
870   characters that can appear in lyrics, eg, ``foreign language''
871   accents, the inputting a string containing these has been made very
872   easy.
873
874 In Lyrics mode, a word is looked up in the following order:
875 \begin{description}
876 \item{\verb+word+}    string (thus a lyric)
877 \item{\verb|"string"|} string
878 \item{\verb|\word|} keyword, identifier
879 \end{description}
880
881 In Lyric mode every sequence of non-digit and non-white characters
882 starting with an alphabetic character or the \_ is considered a word.
883
884 \begin{verbatim}
885 a&@&@&TSI|{[    % a word
886 1THtrhortho     % not a "word"
887 Leise Fl\"u\ss{}teren meine Sapfe       % 4 words
888 _ _ _ _         % 4 words: 4 spaces
889 \end{verbatim}
890 \end{description}
891
892 These modes are of a lexical nature. Normal and Note mode largely
893 resemble each other, save the possibility of entering Reals, 
894 meaning of \verb+_+ and the resolution of words
895
896 \subsection{Notes}
897
898 You enter a note by giving the name and the reciprocal of the duration:
899
900 \begin{mudela}[fragment,verbatim]
901 a'4     % Dutch names
902 \end{mudela}
903
904 is a A-1 pitched crotchet. The ' signifies an octave change.  A-1 is 440
905 Hz concert-pitch. \verb+c'+ is also known as the central c. More examples:
906
907 \begin{mudela}[fragment,verbatim]
908         a,      % 110
909         a       % 220
910         A       % 110, uppercase octavates down
911         a'      % 440
912         a''     % 880
913         'as4.*2/3
914 \end{mudela}
915
916 The last one  is an A flat, (just below 110 Hz concert-pitch). The \verb+*2/3+
917 signifies that this note is part of a triplet (3 in stead of 2). The
918 duration is one and a half quarter note (\verb+4.+) times 2/3.
919
920 Notenames are just a special kind of identifiers, and can be declared
921 for any language appropriate (see \file{init/dutch.ly}).  The default language
922 for notenames is defined to be Dutch. In Dutch, the notenames are
923 a,b,c,d,e,f and g. Sharps are formed by adding the extension "is",
924 flats by adding ``es''
925
926 \begin{verbatim}
927 % double sharp
928 cisis disis eisis fisis gisis aisis bisis
929 % sharps
930 cis dis eis fis gis ais bis
931 % naturals
932 c d e f g a b 
933 % flats
934 ces des es fes ges as bes
935 % double flats
936 ceses deses eses feses geses ases beses
937 \end{verbatim}
938
939 Rests are named r or s
940 \begin{verbatim}
941 r       % print a rest
942 s       % a "space" rest, nothing is printed.
943 \end{verbatim}
944
945 These notenames along with duration are enough material to construct
946 simple melodies:
947
948 \begin{mudela}[verbatim,fragment]
949 \octave c';
950 c4 c4 g4 g4 a4 a4 g2
951 f4 f4 e4 e4 d4 d4 c2
952 \end{mudela}
953
954 Music is able to express more. generally speaking, the other
955 'features' are either connected between notes (slurs, beams: spanning
956 requests) or attached to notes (eg. accents). The former are
957 implemented as START and STOP stop features and then attached to the note.
958
959 \begin{description}
960 \item{[ and ]}      start and stop a beam
961 \item{( and )}      start and stop a slur
962 \end{description}
963
964 example: 
965 \begin{mudela}[verbatim,fragment]
966   \octave c';
967   [c8 () d8 () e8  
968   e8(] [)g8 <c'8] e'8>              % NO nesting!
969   [2/3 c8 c8 c8]1/1       % a triplet
970 \end{mudela}
971
972 Please note that these two characters do \emph{not} necessarrily nest,
973 they should be attached to the note.  For this reason, the construct
974 \verb+[ <c4 c4>]+ will generate a parse error.
975   
976 \subsection{Slurs and Ties}
977
978 Ties connect the noteheads of adjacent notes. They are entered as follows:
979
980 \begin{mudela}[verbatim,fragment]
981 a'4 ~ a''4
982 \end{mudela}
983
984 Slurs connect whole chords, and try to avoid crossing stems. They are
985 entered as follows:
986
987 \begin{mudela}[verbatim,fragment]
988 a'4(  )a''4
989 \end{mudela}
990
991 \subsection{Scripts}
992
993 Symbols which can be put at either side (above or below) of a staff
994 are entered as follows:
995 \begin{mudela}[verbatim,fragment]
996         a-^     % marcato, direction: default
997         %a^-     % portato, direction: above note
998         a_.     % staccato, direction: below note
999         a^\fermata      % predefined identifier
1000         c_"marcato"     % add a text
1001         c^"marcato"
1002         c-"marcato"
1003 \end{mudela}
1004
1005 If you want to define your own scripts refer to \file{init/script.ly} for
1006 details.
1007
1008
1009 Dynamics can be put after the notename:
1010 \begin{verbatim}
1011 a4 \dynamic { 0 } % 0 = fff, 7 = ppp
1012 \end{verbatim}
1013
1014 Mudela defines the following dynamic identifiers:
1015
1016 \begin{verbatim}
1017 ppp pp p mp mf f ff fff sfz fz fp
1018 \end{verbatim}
1019 and the following abbreviations:
1020 \begin{verbatim}
1021 \<      %start crescendo
1022 \>      % start decrescendo
1023 \!      % end crescendo/decrescendo
1024 \end{verbatim}
1025
1026 \subsection{Defaults}
1027
1028 If omit the duration of a note, a default value is substituted. For
1029 this default value mudela uses the last duration explicitly entered.
1030
1031 Thus the following inputs are  equivalent
1032 \begin{verbatim}
1033 c4 c4 c16 c16 c16 s16 c4 c16
1034 c4 c c16 c c c c4 c16
1035 \end{verbatim}
1036
1037 If you are typing music which does not lie in the "small" and "large"
1038 octave, you can prevent having to type \verb+'+ all the time by using the
1039 \verb+\octave+ command: These two lines have the same pitch.
1040 \begin{verbatim}
1041 c'' d'' e'' c d e c d e
1042 \octave c''; c d e ''c ''d ''e \octave c; c d e
1043 \end{verbatim}
1044
1045 By default the setting of \verb+\octave+ is 0.
1046
1047 \subsection{Lyrics}
1048
1049 Lyrics in Mudela resemble Simple mudela a lot, with notes substituted
1050 by text. 
1051
1052 All syllables are entered separately, separated by whitespace 
1053 \begin{verbatim}
1054 Twin-4 kle4 twin-4 kle4 ... 
1055 \end{verbatim}
1056
1057 Two syllables or words that compose a single
1058 duration entry are bound together using an underscore 
1059 \begin{verbatim}
1060 He_could4 not4
1061 \end{verbatim}
1062
1063 \section{Composition: forming bigger structures}
1064
1065 The previous examples tacitly assumed that a sequence of notes is
1066 printed in a left to right manner. This is not entirely correct, you
1067 will get the bigger picture in this section. 
1068
1069 In mathematics you can form expressions by combining expressions,
1070 which are ultimately some kind of atom or terminal symbol.  The same
1071 goes for mudela: there are some basic building blocks, and by
1072 combining those you create complex music.
1073
1074 You can combine music in three ways:
1075 \begin{itemize}
1076 \item If you enclose a sequence of music-elements in braces ( \verb+{+
1077     and \verb+}+ ), then you form another kind of music called (Voice) with those pieces.
1078   The duration of the Voice is the sum of the durations of its elements
1079 \begin{verbatim}
1080 { c c g g a a g2 }      % twinkle twinkle
1081 { { c c g g} { a a g2 } }
1082 \end{verbatim}
1083 \item You can stack music by enclosing a sequence of music elements
1084   with \verb+<+ and \verb+>+. This is called a Chord.  The duration of a Chord is
1085   the union of the durations of its elements Example:
1086 \begin{verbatim}
1087 <a4 {cis8 cis8} e'4>      % a-major chord
1088 \end{verbatim}
1089 \item 
1090   You can form music by transposing music:
1091 \begin{verbatim}
1092 \transpose  
1093                 d       % from c to the d that's one octave down
1094                 { e4 f4 }       % the horizontal music
1095 \end{verbatim}
1096 \end{itemize}
1097
1098 Of course you can also combine these three mechanisms.
1099 \begin{verbatim}
1100 { c <c e> <c e g> <c e g \transpose d' dis > }  % 4 increasing chords
1101 \end{verbatim}
1102
1103 The basic building block in Mudela is called Request. Examples of
1104 Requests are: Timing (such as Meter), Rhythmic, Melodic, Note (which is a combination of
1105 Rhythmic and Melodic), Musicscript (put an accent over a note or
1106 rest), etc.  For the actual up to date listing, you should consult the
1107 LilyPond source code: the Request types form a big class hierarchy.
1108
1109 Normally you don't enter Requests directly, since that would be
1110 tedious.  Mudela has standard abbreviations for the most common
1111 combination of Requests. If you enter \verb+c4+, this is an
1112 abbreviation for:
1113 \begin{verbatim}
1114 Request_chord{
1115   Note_req{
1116     notename: 0 acc: 0 oct: -1
1117     duration { 4}
1118   }
1119   Stem_req{
1120     duration { 4}
1121   }  
1122 }
1123 \end{verbatim}
1124
1125 The \verb+Request_chord+ is a special kind of chord which only allows
1126 Requests as its elements.  The examples of the previous section were
1127 processed with \verb+{+ and \verb+}+ enclosing the input.
1128
1129 \subsection{Durations}
1130
1131 A duration always starts with the duration type (1,2,4 etc), and then
1132 any optional multipliers/dots.  Old fashioned durations can be entered
1133 as follows
1134 \begin{verbatim}
1135 'c\breve
1136 gis'\longa
1137 \end{verbatim}
1138
1139
1140         
1141 \subsection{Meters/groupings}
1142
1143 A meter has this form:
1144 \begin{verbatim}
1145 \meter 3/4 ;
1146 \end{verbatim}
1147
1148 Rhythmic grouping is  a concept closely associated with this. For
1149 example, in a 5/8 meter, the counts are grouped 2+3. In mudela this is
1150 entered as
1151 \begin{verbatim}
1152 \grouping  8*2 8*3 ;
1153 \end{verbatim}
1154 You can start the piece with a partial measure, the command takes the
1155 same syntax as grouping: 
1156 \begin{verbatim}
1157 \partial 16*3 4;
1158 \end{verbatim}
1159
1160 Make the piece start with a upstep [english translation?]
1161 lasting 1 3/4 quarter notes.
1162
1163 These commands are also "voice elements", and constitute ``Music''
1164 (consisting of stuff with duration 0).
1165
1166
1167 \subsection{Voicegroups}
1168
1169
1170 [OUTDATED]
1171
1172 If more than one "voice" is in a staff, then you have the option of
1173 putting the different voices into so called voicegroups: members of
1174 the same voicegroup share certain characteristics, among others:
1175
1176         - dynamics
1177         - text
1178         - beams and stems
1179         - scripts
1180
1181 For the actual list, see the init file \file{init/register.ly}
1182
1183 Putting different musical lines in to the same voicegroup effectively
1184 makes LilyPond try to form chords of all those lines. Putting
1185 different musical lines in to different voicegroups effectively makes
1186 LilyPond try to set those lines as independently as possible. 
1187
1188 [adsolete. Has to be fixed in lily]
1189
1190 You can set the voicegroup of a voice with the command \verb+\group+, e.g.,
1191
1192 \begin{verbatim}        
1193         oboeI = \melodic { 
1194                 \group "oboes"; 
1195                 [e8 f8
1196                 \group "+solo";
1197                 [g16 a16 g16 fis16]
1198                 \group "-";
1199                 g8 f8
1200         }
1201         oboeII = \melodic { \group "oboes";
1202                 c8 d8]
1203                 e4
1204                 e8 d8
1205         }
1206         ///     ...
1207
1208         \staff { 
1209                 melodicregs \melodic{ oboeI }
1210                 \melodic { oboeII}
1211 }
1212 \end{verbatim}
1213
1214 In this example, the two oboe voices share one staff and are initially
1215 in the voicegroup called "oboes". They will share beams, dynamics etc.
1216 After two quarter notes, oboeI "pushes" its group: a new voicegroup is
1217 created, called "oboes+solo". The \verb+\group "-"+ command makes the
1218 voice enter "oboes" again.
1219
1220 Please do note that [] are voicegroup wide; the previous input is
1221 valid: the beam, started in oboeI, voicegroup "oboes" is also ended in
1222 voicegroup "oboes", albeit not in oboeI but oboeII
1223
1224 This concept may seem contorted, but it allows you to set the separate
1225 oboe parts without changing the \verb+oboeI+ and \verb+oboeII+ (assuming that
1226 you edit the [] in the example.)
1227
1228 The construct
1229 \begin{verbatim}
1230 < { .... } {......} >
1231 \end{verbatim}
1232 makes a chord (all horizontal parts are in the same voicegroup). The construct
1233 \begin{verbatim}
1234 \multi 2 < { ....} { .... } >
1235 \end{verbatim}
1236 creates horizontal parts which behave independently. You will have to
1237 set voicegroup features by hand (\verb+\stem+ and \verb+\hshift+. See examples)
1238
1239 The construct
1240 \begin{verbatim}
1241 \multi 3 < { ....} { .... } >
1242 \end{verbatim}
1243 creates  a chord with each part in a different staff
1244
1245
1246 \subsection{Examples}
1247
1248 Examples are included with the GNU LilyPond distribution. For the sake of
1249 maintenance no long examples are included in this document.
1250
1251
1252 \section{History}
1253
1254 This language has a number of roots. First and foremost, GNU
1255 LilyPond's predecessor mpp was the inspiration of the Note-mode input.
1256 Secondly, the hierarchical structure looks a lot like Rayce's (Rayce
1257 is a raytracer that I've written as a hobby project. ), which in turn
1258 owes a lot to POVRay.
1259
1260 Now, we know, musictypesetting and raytracing do not necessarily
1261 require the same input format, and we know that a lot more ways exist
1262 to convert music to ASCII, but we did give this language some
1263 thoughts. As always suggestions are appreciated.
1264
1265 \end{document}
1266
1267