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