]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/mudela-man.doc
release: 0.1.20
[lilypond.git] / Documentation / mudela-man.doc
1 % -*-latex-*-
2
3 % this document should be run through the mudela-book script after lilypond
4 % has been installed. 
5
6 \documentclass{article}
7 \usepackage{a4wide}
8 \title{GNU LilyPond input format 0.1}
9 \author{Han-Wen Nienhuys}
10
11 \begin{document}
12 \maketitle
13 \def\interexample{\par Produces the following:\par}
14 \def\preexample{\par\medskip}
15 \def\postexample{\par\medskip}
16 \def\file#1{{\texttt{#1}}}
17
18 \emph{This document is not complete yet}
19
20 \section{Introduction}
21
22 This document describes the the GNU LilyPond input format, which is an
23 effective language for defining music.  We call this language (rather
24 arrogantly) The Musical Definition Language or Mudela, for
25 short.\footnote{If anybody comes up with a better name, we'd gladly
26   take this. Gourlay already uses Musical Description Language,
27   G-Sharp Score Definition Language.  ISO standard 10743 defines a
28   Standard Music Description Language.  We're not being original here}
29
30 The first aim of Mudela is to define a piece of music, being complete
31 from both from a musical typesetting, as from a musical performing
32 point of view.
33
34 The Musical Definition Language (Mudela), has a logical structure,
35 making use of identifiers, that allows for flexible input, and
36 definition reuse. See \file{MANIFESTO} for reasons and design considerations.
37
38 The below included for explanatory purposes only (i.e., for a complete
39 and up-to-date definition, see \file{lily/parser.y} and
40 \file{lily/lexer.l}):
41
42 As a related note, you should take a look at the examples and the init
43 files, as this document does not cover every aspect of mudela yet, and
44 may be out of date.\footnote{Ok, I am being pessimistic here.  This
45   just is a disclaimer.  Docs usually are written after the program
46   itself.}  This document intends to give an idea of how it works, it
47 is not a guide on how to use it.  
48
49
50 \section{Basic elements}
51
52 \subsection{Files}
53
54 The de-facto extension of Mudela is \file{.ly}. Files may be included by
55 entering \verb+\include+ at the start of a line:
56
57 \begin{verbatim}
58 \include "a_file.ly"
59 \end{verbatim}
60
61
62 \subsection{Comments}
63
64 Line comments are introduced by a
65 \verb+%+. 
66 Block comments are delimited
67 by 
68 \verb+%{+ 
69 and
70 \verb+%}+. 
71 They do not nest.
72
73 \subsection{Versions}
74
75 Occasionally, small changes in syntax across different versions of
76 Mudela might give syntax errors. To warn you about possible
77 incompatibilities, you can specify the Mudela version for which the
78 inputfile was written,
79 \begin{verbatim}
80 \version "0.0.50";
81 \end{verbatim}
82
83 A perl-script which tries to convert to newer versions
84 (\file{convert-mudela}) is included in the LilyPond distribution.
85
86 \subsection{Words}
87
88 Keywords are preceded by a backslash: \verb+\+. They contain
89 alphabetic characters only.
90
91 Identifiers in their normal form consist start with a backslash, a
92 alpha character, followed by alpha-numerics. Identifiers can contain
93 any characters (except whitespace, 
94  and \verb+%+), if you use this construct:
95
96 \begin{verbatim}
97 \$i'm_a_weird!!!identifier
98 \end{verbatim}
99
100 (which is the identifier with the name
101 \verb+i'm_a_weird!!!identifier+).  \verb+$+ Takes any sequence of
102 characters which are not whitespace, \verb+$+ and \verb+%+.
103 \verb+$i'm_a_weird!!!string+
104 \def\foobar{$} % silly fontlock mode 
105
106 \subsection{Nesting characters}
107
108 Mudela uses the brace (\verb+{+ and \verb+}+) for most hierarchical
109 structures.  For chords the \verb+<+ and the \verb+>+ are used as
110 nesting braces.
111
112 \subsection{Constants}
113
114 Please note that -.5 is not a Real.
115
116 \begin{verbatim}
117 "I am a string"
118 -1.2e3          % a real
119 12              % an int
120 \end{verbatim}
121
122         
123 \subsection{Identifiers}
124
125 When assigning identifiers you use
126
127 \begin{verbatim}
128 string = ...
129 \end{verbatim}
130
131 If you reuse identifiers, then the previous contents will be thrown
132 away after the right hand is evaluated, eg
133 \begin{verbatim}
134 bla = \melodic { \bla }
135 \end{verbatim}
136 is legal
137
138 When using identifiers they have to be escaped:
139
140 \begin{verbatim}
141 oboe = \melodic { ... }
142 \score{ \melodic { \oboe }}
143 \end{verbatim}
144
145 The left-hand part of the assignment is really a string, so 
146 \begin{verbatim}
147 "Foo bar 4 2 " = \melodic { .. }
148 \end{verbatim}
149
150 is also a valid assignment (but you would have trouble referencing to it)
151
152
153 \subsection{Hierarchical structures}
154
155 The general structure consists of declarations:
156 \begin{verbatim}
157 IDENTIFIER = \TYPE{
158         <type specific data>
159 }
160 \end{verbatim}
161 and instantiations:
162
163 \begin{verbatim}
164 \TYPE{ <type specific data> }
165 \end{verbatim}
166
167 (Currently, \verb+\score+ is the only type that can be instantiated
168 at top level. Currently declarations can only be done at top level)
169
170 Most instantiations that use an IDENTIFIER are specified as follows:
171
172 \begin{verbatim}
173 \TYPE{ IDENTIFIER [...] }
174 \end{verbatim}
175
176 Some exceptions on this rule have been made to prevent inputting
177 Mudela becoming tedious
178
179
180 \subsection{Modes:}
181
182 To simplify different aspects of music definition (entering the notes
183 and manipulating them) Mudela has a number of different input "modes":
184
185 \begin{description}
186
187
188 \item[Normal mode]
189
190 At the start of parsing, Mudela assumes normal mode.
191 In Normal mode, a word is looked up in the following order:
192 \begin{description}
193 \item{\verb+word+}    string
194 \item{\verb|"string"|} string
195 \item{\verb|\word|} keyword, identifier
196 \end{description}
197 In normal mode, a word is assumed to start with an alphabetic
198 character, followed by alpha-numeric characters.
199
200 \item[Note mode] Note mode is introduced by the keyword
201   \verb+\melodic+.  In Note mode, a word is looked up in the following
202   order:
203 \begin{description}
204 \item{\verb+word+} notename, string
205 \item{\verb|"string"|} string
206 \item{\verb|\word|} keyword, identifier
207 \end{description}
208
209 In Note mode a word is considered to have alphabetic characters only,
210 so the underscore (\_) is illegal.  If you accidently mistype a
211 notename, the parser will assume that you are entering a string (and
212 it will most likely complain that you should be in \verb|\lyrics| mode to
213 do lyrics)
214
215
216 \item[Lyric mode] Lyrics mode (and thus Simple mudela) is introduced
217   by the keyword \verb+\lyrics+.  Because of the various control
218   characters that can appear in lyrics, eg, ``foreign language''
219   accents, the inputting a string containing these has been made very
220   easy.
221
222 In Lyrics mode, a word is looked up in the following order:
223 \begin{description}
224 \item{\verb+word+}    string (thus a lyric)
225 \item{\verb|"string"|} string
226 \item{\verb|\word|} keyword, identifier
227 \end{description}
228
229 In Lyric mode every sequence of non-digit and non-white characters
230 starting with an alphabetic character or the \_ is considered a word.
231
232 \begin{verbatim}
233 a&@&@&TSI|{[    % a word
234 1THtrhortho     % not a "word"
235 Leise Fl\"u\ss{}teren meine Sapfe       % 4 words
236 _ _ _ _         % 4 words: 4 spaces
237 \end{verbatim}
238 \end{description}
239
240 These modes are of a lexical nature. Normal and Note mode largely
241 resemble each other, save the possibility of entering Reals, 
242 meaning of \verb+_+ and the resolution of words
243
244 \subsection{Notes}
245
246 You enter a note by giving the name and the reciprocal of the duration:
247
248 \begin[fragment,verbatim]{mudela}
249 a'4     % Dutch names
250 \end{mudela}
251
252 is a A-1 pitched crotchet. The ' signifies an octave change.  A-1 is 440
253 Hz concert-pitch. \verb+c'+ is also known as the central c. More examples:
254
255 \begin[fragment,verbatim]{mudela}
256         'a      % 110
257         a       % 220
258         A       % 110, uppercase octavates down
259         a'      % 440
260         a''     % 880
261         'as4.*2/3
262 \end{mudela}
263
264 The last one  is an A flat, (just below 110 Hz concert-pitch). The \verb+*2/3+
265 signifies that this note is part of a triplet (3 in stead of 2). The
266 duration is one and a half quarter note (\verb+4.+) times 2/3.
267
268 Notenames are just a special kind of identifiers, and can be declared
269 for any language appropriate (see \file{init/dutch.ly}).  The default language
270 for notenames is defined to be Dutch. In Dutch, the notenames are
271 a,b,c,d,e,f and g. Sharps are formed by adding the extension "is",
272 flats by adding ``es''
273
274 \begin{verbatim}
275 % double sharp
276 cisis disis eisis fisis gisis aisis bisis
277 % sharps
278 cis dis eis fis gis ais bis
279 % naturals
280 c d e f g a b 
281 % flats
282 ces des es fes ges as bes
283 % double flats
284 ceses deses eses feses geses ases beses
285 \end{verbatim}
286
287 Rests are named r or s
288 \begin{verbatim}
289 r       % print a rest
290 s       % a "space" rest, nothing is printed.
291 \end{verbatim}
292
293 These notenames along with duration are enough material to construct
294 simple melodies:
295
296 \begin[verbatim,fragment]{mudela}
297 \octave c';
298 c4 c4 g4 g4 a4 a4 g2
299 f4 f4 e4 e4 d4 d4 c2
300 \end{mudela}
301
302 Music is able to express more. generally speaking, the other
303 'features' are either connected between notes (slurs, beams: spanning
304 requests) or attached to notes (eg. accents). The former are
305 implemented as START and STOP stop features and then attached to the note.
306
307 \begin{description}
308 \item{[ and ]}      start and stop a beam
309 \item{( and )}      start and stop a slur
310 \end{description}
311
312 example: 
313 \begin[verbatim,fragment]{mudela}
314   \octave c';
315   [c8 () d8 () e8  
316   e8(] [)g8 <c'8] e'8>              % NO nesting!
317   [2/3 c8 c8 c8]1/1       % a triplet
318 \end{mudela}
319
320 Please note that these two characters do \emph{not} necessarrily nest,
321 they should be attached to the note.  For this reason, the construct
322 \verb+[ <c4 c4>]+ will generate a parse error.
323   
324 \subsection{Slurs and Ties}
325
326 Ties connect the noteheads of adjacent notes. They are entered as follows:
327
328 \begin[verbatim,fragment]{mudela}
329 a'4 ~ a''4
330 \end{mudela}
331
332 Slurs connect whole chords, and try to avoid crossing stems. They are
333 entered as follows:
334
335 \begin[verbatim,fragment]{mudela}
336 a'4(  )a''4
337 \end{mudela}
338
339 \subsection{Scripts}
340
341 Symbols which can be put at either side (above or below) of a staff
342 are entered as follows:
343 \begin[verbatim,fragment]{mudela}
344         a-^     % marcato, direction: default
345         %a^-     % portato, direction: above note
346         a_.     % staccato, direction: below note
347         a^\fermata      % predefined identifier
348         c_"marcato"     % add a text
349         c^"marcato"
350         c-"marcato"
351 \end{mudela}
352
353 If you want to define your own scripts refer to \file{init/script.ly} for
354 details.
355
356
357 Dynamics can be put after the notename:
358 \begin{verbatim}
359 a4 \dynamic { 0 } % 0 = fff, 7 = ppp
360 \end{verbatim}
361
362 Mudela defines the following dynamic identifiers:
363
364 \begin{verbatim}
365 ppp pp p mp mf f ff fff sfz fz fp
366 \end{verbatim}
367 and the following abbreviations:
368 \begin{verbatim}
369 \<      %start crescendo
370 \>      % start decrescendo
371 \!      % end crescendo/decrescendo
372 \end{verbatim}
373
374 \subsection{Defaults}
375
376 If omit the duration of a note, a default value is substituted. For
377 this default value mudela uses the last duration explicitly entered.
378
379 Thus the following inputs are  equivalent
380 \begin{verbatim}
381 c4 c4 c16 c16 c16 s16 c4 c16
382 c4 c c16 c c c c4 c16
383 \end{verbatim}
384
385 If you are typing music which does not lie in the "small" and "large"
386 octave, you can prevent having to type \verb+'+ all the time by using the
387 \verb+\octave+ command: These two lines have the same pitch.
388 \begin{verbatim}
389 c'' d'' e'' c d e c d e
390 \octave c''; c d e ''c ''d ''e \octave c; c d e
391 \end{verbatim}
392
393 By default the setting of \verb+\octave+ is 0.
394
395 \subsection{Lyrics}
396
397 Lyrics in Mudela resemble Simple mudela a lot, with notes substituted
398 by text. 
399
400 All syllables are entered separately, separated by whitespace 
401 \begin{verbatim}
402 Twin-4 kle4 twin-4 kle4 ... 
403 \end{verbatim}
404
405 Two syllables or words that compose a single
406 duration entry are bound together using an underscore 
407 \begin{verbatim}
408 He_could4 not4
409 \end{verbatim}
410
411 \section{Composition: forming bigger structures}
412
413 The previous examples tacitly assumed that a sequence of notes is
414 printed in a left to right manner. This is not entirely correct, you
415 will get the bigger picture in this section. 
416
417 In mathematics you can form expressions by combining expressions,
418 which are ultimately some kind of atom or terminal symbol.  The same
419 goes for mudela: there are some basic building blocks, and by
420 combining those you create complex music.
421
422 You can combine music in three ways:
423 \begin{itemize}
424 \item If you enclose a sequence of music-elements in braces ( \verb+{+
425     and \verb+}+ ), then you form another kind of music called (Voice) with those pieces.
426   The duration of the Voice is the sum of the durations of its elements
427 \begin{verbatim}
428 { c c g g a a g2 }      % twinkle twinkle
429 { { c c g g} { a a g2 } }
430 \end{verbatim}
431 \item You can stack music by enclosing a sequence of music elements
432   with \verb+<+ and \verb+>+. This is called a Chord.  The duration of a Chord is
433   the union of the durations of its elements Example:
434 \begin{verbatim}
435 <a4 {cis8 cis8} e'4>      % a-major chord
436 \end{verbatim}
437 \item 
438   You can form music by transposing music:
439 \begin{verbatim}
440 \transpose  
441                 d       % from c to the d that's one octave down
442                 { e4 f4 }       % the horizontal music
443 \end{verbatim}
444 \end{itemize}
445
446 Of course you can also combine these three mechanisms.
447 \begin{verbatim}
448 { c <c e> <c e g> <c e g \transpose d' dis > }  % 4 increasing chords
449 \end{verbatim}
450
451 The basic building block in Mudela is called Request. Examples of
452 Requests are: Timing (such as Meter), Rhythmic, Melodic, Note (which is a combination of
453 Rhythmic and Melodic), Musicscript (put an accent over a note or
454 rest), etc.  For the actual up to date listing, you should consult the
455 LilyPond source code: the Request types form a big class hierarchy.
456
457 Normally you don't enter Requests directly, since that would be
458 tedious.  Mudela has standard abbreviations for the most common
459 combination of Requests. If you enter \verb+c4+, this is an
460 abbreviation for:
461 \begin{verbatim}
462 Request_chord{
463   Note_req{
464     notename: 0 acc: 0 oct: -1
465     duration { 4}
466   }
467   Stem_req{
468     duration { 4}
469   }  
470 }
471 \end{verbatim}
472
473 The \verb+Request_chord+ is a special kind of chord which only allows
474 Requests as its elements.  The examples of the previous section were
475 processed with \verb+{+ and \verb+}+ enclosing the input.
476
477 \subsection{Durations}
478
479 A duration always starts with the duration type (1,2,4 etc), and then
480 any optional multipliers/dots
481
482 \subsection{Meters/groupings}
483
484 A meter has this form:
485 \begin{verbatim}
486 \meter 3/4 ;
487 \end{verbatim}
488
489 Rhythmic grouping is  a concept closely associated with this. For
490 example, in a 5/8 meter, the counts are grouped 2+3. In mudela this is
491 entered as
492 \begin{verbatim}
493 \grouping  8*2 8*3 ;
494 \end{verbatim}
495 You can start the piece with a partial measure, the command takes the
496 same syntax as grouping: 
497 \begin{verbatim}
498 \partial 16*3 4;
499 \end{verbatim}
500
501 Make the piece start with a upstep [english translation?]
502 lasting 1 3/4 quarter notes.
503
504 These commands are also "voice elements", and constitute ``Music''
505 (consisting of stuff with duration 0).
506
507
508 \subsection{Voicegroups}
509
510
511 [OUTDATED]
512
513 If more than one "voice" is in a staff, then you have the option of
514 putting the different voices into so called voicegroups: members of
515 the same voicegroup share certain characteristics, among others:
516
517         - dynamics
518         - text
519         - beams and stems
520         - scripts
521
522 For the actual list, see the init file \file{init/register.ly}
523
524 Putting different musical lines in to the same voicegroup effectively
525 makes LilyPond try to form chords of all those lines. Putting
526 different musical lines in to different voicegroups effectively makes
527 LilyPond try to set those lines as independently as possible. 
528
529 [adsolete. Has to be fixed in lily]
530
531 You can set the voicegroup of a voice with the command \verb+\group+, e.g.,
532
533 \begin{verbatim}        
534         oboeI = \melodic { 
535                 \group "oboes"; 
536                 [e8 f8
537                 \group "+solo";
538                 [g16 a16 g16 fis16]
539                 \group "-";
540                 g8 f8
541         }
542         oboeII = \melodic { \group "oboes";
543                 c8 d8]
544                 e4
545                 e8 d8
546         }
547         ///     ...
548
549         \staff { 
550                 melodicregs \melodic{ oboeI }
551                 \melodic { oboeII}
552 }
553 \end{verbatim}
554
555 In this example, the two oboe voices share one staff and are initially
556 in the voicegroup called "oboes". They will share beams, dynamics etc.
557 After two quarter notes, oboeI "pushes" its group: a new voicegroup is
558 created, called "oboes+solo". The \verb+\group "-"+ command makes the
559 voice enter "oboes" again.
560
561 Please do note that [] are voicegroup wide; the previous input is
562 valid: the beam, started in oboeI, voicegroup "oboes" is also ended in
563 voicegroup "oboes", albeit not in oboeI but oboeII
564
565 This concept may seem contorted, but it allows you to set the separate
566 oboe parts without changing the \verb+oboeI+ and \verb+oboeII+ (assuming that
567 you edit the [] in the example.)
568
569 The construct
570 \begin{verbatim}
571 < { .... } {......} >
572 \end{verbatim}
573 makes a chord (all horizontal parts are in the same voicegroup). The construct
574 \begin{verbatim}
575 \multi 2 < { ....} { .... } >
576 \end{verbatim}
577 creates horizontal parts which behave independently. You will have to
578 set voicegroup features by hand (\verb+\stem+ and \verb+\hshift+. See examples)
579
580 The construct
581 \begin{verbatim}
582 \multi 3 < { ....} { .... } >
583 \end{verbatim}
584 creates  a chord with each part in a different staff
585
586
587 \subsection{Examples}
588
589 Examples are included with the GNU LilyPond distribution. For the sake of
590 maintenance no long examples are included in this document.
591
592
593 \section{History}
594
595 This language has a number of roots. First and foremost, GNU
596 LilyPond's predecessor mpp was the inspiration of the Note-mode input.
597 Secondly, the hierarchical structure looks a lot like Rayce's (Rayce
598 is a raytracer that I've written as a hobby project. ), which in turn
599 owes a lot to POVRay.
600
601 Now, we know, musictypesetting and raytracing do not necessarily
602 require the same input format, and we know that a lot more ways exist
603 to convert music to ASCII, but we did give this language some
604 thoughts. As always suggestions are appreciated.
605
606 \end{document}
607