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