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