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