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