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