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