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