]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/mudela.pod
release: 0.0.53
[lilypond.git] / Documentation / mudela.pod
1 =head1 NAME
2
3 Mudela -  GNU LilyPond input format 0.1
4
5 =head1 DESCRIPTION
6
7 This document describes the the GNU LilyPond input format, which is an
8 effective language for defining music.  We call this language
9 (rather arrogantly) The Musical Definition Language (S<Mudela 0.1>).
10
11 The first aim of Mudela is to define a piece of music, 
12 being complete from both from a musical typesetting, 
13 as from a musical performing point of view.
14
15
16 =head1 Overview
17
18 The Musical Definition Language (Mudela) S<version 2>, has a logical
19 structure, making use of typing and naming (using identifiers), that
20 allows for flexible input, and definition reuse.
21
22 The below included for explanatory purposes only (i.e., for a complete
23 and up-to-date definition, see F<lily/parser.y> and F<lily/lexer.l>):
24
25 As a related note, you should take a look at the examples and the init
26 file, as this document does not cover every aspect of mudela yet.
27
28 =head2 Files
29
30 The de-facto extension of Mudela is F<.ly>. Files may be included by
31 entering C<include> at the start of a line:
32
33         \include "a_file.ly"
34
35 =head2 Comments
36
37 Line comments are introduced by a C<%>
38
39 =head2 Versions
40
41 Occasionally, small changes in syntax across different versions of
42 Mudela might give syntax errors. To warn you about possible
43 incompatibilities, you can specify the Mudela version for which the
44 inputfile was written,
45
46         \version "0.0.50";
47
48 =head2 Words
49
50 Keywords are preceded by a backslash "\". They contain alphabetic
51 characters only. 
52
53 Identifiers in their normal form consist start with a alpha character,
54 followed by alpha-numerics. Identifiers can contain any characters
55 (except whitespace, C<$> and C<%>), if you use this construct:
56
57         $i'm_a_weird###identifier
58
59 (which is the identifier with the name
60 C<i'm_a_weird###identifier> ). C<$> Takes any sequence of
61 characters which are not whitespace, C<$> and C<%>.
62
63         \$i'm_a_weird###escaped_word
64
65 =head2 Nesting characters
66
67 Mudela uses the brace (C<{> and C<}>) for hierarchical structures. To
68 aid the eye in reading, for chords the < and the > are used as
69 nesting braces.
70
71 =head2 Identifiers
72
73 =head2 Hierarchical structures
74
75 The general structure consists of declarations:
76
77         IDENTIFIER = \TYPE{
78                 <type specific data>
79         }
80
81 and instantiations:
82
83         \TYPE{ <type specific data> }
84
85 (Currently, C<\score> is the only type that can be instantiated
86 at top level. Currently declarations can only be done at top level)
87
88 Most instantiations that use an IDENTIFIER are specified as follows:
89
90         \TYPE{ IDENTIFIER [...] }
91
92 Some exceptions on this rule have been made to prevent inputting
93 Mudela becoming tedious
94
95
96 =head2 Simple mudela
97
98 The actual musical part of Mudela that defines a melody, is known as 
99 I<simple mudela>. 
100
101 Simple mudela is the most common type of music.  It consists of a list
102 of notes or lyrics, chords, and commands.
103
104 =head2 Modes:
105
106 To simplify different aspects of music definition (entering the notes
107 and manipulating them) Mudela has a number of different input "modes":
108
109 =over 4
110
111 =item Normal mode
112
113 At the start of parsing, Mudela assumes normal mode.
114 In Normal mode, a word is looked up in the following order:
115
116         word    identifier, string
117         \word   keyword, identifier, string
118
119 In normalmode, a word is assumed to start with an alphabetic
120 character, followed by alpha-numeric characters.
121
122 =item Note mode
123
124 Note mode (and thus Simple mudela) is introduced by the keyword C<\melodic>.
125 In Note mode, a word is looked up in the following order:
126
127         word    notename, string
128         \word   keyword, identifier, string
129
130 In Note mode a word is considered to have alphabetic characters only.
131
132 =item Lyric mode
133
134 Lyrics mode (and thus Simple mudela)  is introduced by the keyword C<\lyrics>.
135
136 In Lyrics mode, a word is looked up in the following order:
137
138         word    string
139         \word   keyword, identifier, string
140
141 In Lyric mode every sequence of non-digit and non-white characters
142 starting with an alphabetic character is considered a word.
143
144         a&@&@&TSI|{[    % a word
145         1THtrhortho     % not a "word"
146         Leise Fl\"u\ss{}teren meine Sapfe       % 4 words
147
148
149 =back
150
151 These modes are of a lexical nature. Normal and Note mode largely
152 resemble each other, save the possibility of entering Reals, 
153 meaning of C<_> and the resolution of words
154
155 =head2 Notes
156
157 Simple mudela basically is a sequence of the notes you want to
158 enter. 
159
160         a'4     % dutch names
161
162 is a A-1 pitched quaver. The ' signifies an octave change.  A-1 is 440
163 Hz concert-pitch. C<c'> is also known as the central c. More examples:
164
165         'a      % 110
166         a       % 220
167         a'      % 440
168         a''     % 880
169
170 another example:
171
172         'as4.*2/3
173
174 This is an A flat, (just below 110 Hz concert-pitch). The C<*2/3>
175 signifies that this note is part of a triplet (3 in stead of 2). The
176 duration is one and a half quaver (C<4.>) times 2/3. 
177
178
179 Notenames are just a special kind of identifiers, and can be declared
180 for any language appropriate (see F<dutch.ini>).  The default language
181 for notenames is defined to be dutch. In dutch, the notenames are
182 a,b,c,d,e,f and g. Sharps are formed by adding the extension "is",
183 flats by adding "es"
184
185         % double sharp
186         cisis disis eisis fisis gisis aisis bisis
187         % sharps
188         cis dis eis fis gis ais bis
189         % naturals
190         c d e f g a b 
191         % flats
192         ces des es fes ges as bes
193         % double flats
194         ceses deses eses feses geses ases beses
195
196 The standard notenames also have uppercase versions, which octavate
197 down:
198
199         a       % 220 concert-pitch
200         A       % 110
201         'A      % 55
202         A'      % 220
203         Cisis
204
205 The rest is named 
206
207         r
208
209 These notenames along with duration are enough material to construct
210 simple melodies:
211
212         c4 c4 g4 g4 a4 a4 g2
213         f4 f4 e4 e4 d4 d4 c2
214
215 Music is able to express more. generally speaking, the other
216 'features' are either connected between notes (slurs, beams: spanning
217 requests) or attached to notes (eg. accents). The former are
218 implemented as START and STOP stop features and then attached to the note.
219
220         []      START/STOP a beam
221         ()      START/STOP a slur
222
223
224 example: 
225
226         [c8 () d8 () e8 ]
227
228 Please note that these two characters do I<not> necessarrily nest, eg:
229
230         [c8 e8(] [)g8 c'8]
231
232
233 Symbols which can be put at either side of a staff are entered as follows:
234
235         a-^     % marcato, direction: default
236         a^-     % portato, direction: above note
237         a_.     % staccato, direction: below note
238         a^\script { "symbolindex"  . . . } % see script.ini for details.
239         a^\fermata      % predefined identifier
240
241 Dynamics can be put after the notename:
242
243         a4 \dynamic { 0 } % 0 = fff, 7 = ppp
244
245 Mudela defines the following dynamic identifiers:
246
247         ppp pp p mp mf df ff fff        % df iso f, f is a notename.
248
249 and the following abbreviations:
250
251         \<      %start crescendo
252         \>      % start decrescendo
253         \!      % end crescendo/decrescendo
254
255 =head2 Text
256
257 To accompany a note with a text (eg, "marcato"), you should say: 
258
259         c_"marcato"
260         c^"marcato"
261         c-"marcato"
262
263 the c- construct chooses the default up/down direction.
264
265
266
267
268 =head2 Defaults
269
270 If omit the duration of a, a default value is substituted. For this
271 default value, there are two modes:
272
273 =over 4
274
275 =item 1
276
277 Use the last duration explicitly entered
278
279 =item 2
280
281 Use the explicitly set "default duration"
282
283 =back
284
285 Thus the following inputs are  equivalent
286
287         c4 c4 c16 c16 c16 s16 c4 c16
288
289         \duration { "last" }
290         c4 c c16 c c c c4 c16
291
292         \duration { 4 }
293         c c c16 c16 c16 c16 c c16
294
295         \duration { 16 }
296         c4 c4 c c c c c4 
297
298 If you are typing music which does not lie in the "small" and "large"
299 octave, you can prevent having to type C<'> all the time by using the
300 C<\octave> command: These two lines have the same pitch.
301
302         c'' d'' e''     
303         \octave{c''} c d e
304
305 By default the setting of C<\octave> is 0.
306
307 =head2 Lyrics
308
309 Lyrics in Mudela resemble Simple mudela a lot, with notes substituted
310 by text. 
311
312 All syllables are entered separately, separated by whitespace 
313
314         Twin-4 kle4 twin-4 kle4 ... 
315
316 Two syllables or words that compose a single
317 duration entry are bound together using an underscore 
318
319         He_could4 not4
320
321 =head2  Music direction
322
323 Mudela reads left to right, but you can still stack voices and
324 Voice_elements which are produced in two directions: horizontal
325 (voice like) and vertical (chord like)
326
327 You can start horizontal music by enclosing a sequence of notes with { and }
328
329         { c c g g a a g2 }      % twinkle twinkle
330
331 You can start vertical music (a "chord") by enclosing a sequence of
332 notes with < and >. Example:
333
334         <a cis e'>      % a-major chord
335
336 You can also put vertical music inside horizontal music:
337
338         { c <c e> <c e g> <c e g c'> }  % 4 increasing chords
339
340 And vice versa
341
342         < \multivoice
343           {c c g g a a g2}              
344           {r2  r2  c c g g a a g2} >    % a canon
345
346 The duration of a chord equals the union of the durations of each of
347 its elements.  The C<\multivoice> is a construct which is explained
348 below.
349
350 You can also glue two horizontal pieces music together with
351 concatenation operator:
352
353         \horOne = \melodic { c c g g }
354         \horTwo = \melodic { a a g2 }
355         \twinkle = \melodic { \horOne ++ \horTwo }
356
357 =head2 Transposition
358
359 You can transpose horizontal music in the following way:
360
361         \transpose {    d       % from c to d that's one octave up.
362                 { e4 f4 }       % the horizontal music
363         }
364
365 =head2 Rhythms
366
367 Rhythms in Mudela are entered identical to Simple mudela.
368 The melodic part of the information is ignored.
369
370 =head2 Durations
371
372 A duration always starts with the duration type (1,2,4 etc), and then
373 any optional multipliers/dots
374
375 =head2 Meters/groupings
376
377 A meter has this form:
378
379         \meter { 3/4 }
380
381 Rhythmic grouping is  a concept closely associated with this. For
382 example, in a 5/8 meter, the counts are grouped 2+3. In mudela this is
383 entered as
384
385         \grouping { 8*2 8*3 }
386
387
388
389 =head1 STRUCTURE
390
391 In concrete, a piece of Mudela has the following structure:
392
393         % declare pieces of music:
394         melody = \music{ <simple mudela> }
395         accompany = \music{ <simple mudela> }
396
397         % instantiate (=create tex, midi output) the score:
398         \score{ 
399                 \staff{ melody }
400                 \staff{ accompany }
401                 \commands{ <score global commands> }
402                 \midi{ <midi definitions> }
403                 \paper{ <paper and layout definitions }
404         }
405
406 =head2 Examples
407
408 Examples are included with the GNU LilyPond distribution. For the sake of
409 maintenance no long examples are included in this document.
410
411
412 =head1 INTERNALS
413
414 This chapter deals with the internals of Mudela. In the end Mudela
415 converted to Voice, which contain Voice_elements which (in turn)
416 contain Requests. The former 2 types are basically containers (lists).
417 Consider the following simple mudela
418
419         \music { c4 <e4 g4> }
420
421 After the parsing, this is converted to: (from the debug output)
422
423         Voice { start: 0
424           voice_element { dur :1/4
425             Stem_req {duration { 4}}
426             Note_req {notename: 0 acc: 0 oct: -1 
427               duration { 4}}
428             Group_change_req {}
429             }
430           voice_element { dur :0
431             Terminate_voice_req {}
432             }
433           }
434
435         Voice { start: 1/4
436           voice_element { dur :1/4
437             Stem_req {duration { 4}}
438             Note_req {notename: 2 acc: 0 oct: -1 
439               duration { 4}}
440             Group_change_req {}
441             }
442           voice_element { dur :0
443             Terminate_voice_req {}
444             }
445           }
446
447         Voice { start: 1/4
448           voice_element { dur :1/4
449             Stem_req {duration { 4}}
450             Note_req {notename: 4 acc: 0 oct: -1 
451               duration { 4}}
452             Group_change_req {}
453             }
454           voice_element { dur :0
455             Terminate_voice_req {}
456             }
457           }
458
459
460 =head2 Requests
461
462 As you can see, most information is stored in the form of a request. 
463 In music typesetting, the user might want to cram a lot more symbols
464 on the paper than actually fits. To reflect this idea (the user asks
465 more than we can do), the container for this data is called Request.
466
467 A request is done to
468 the C<Staff> which contains the C<Voice_element>. The staff decides
469 whether to to honor the request, ignore it, or merge it with other
470 requests. Merging of requests is preferably done with other requests
471 done by members of the same voicegroups (beams, brackets, stems)
472
473
474
475 =head1 HISTORY
476
477
478 This language has a number of roots. First and foremost, GNU LilyPond's
479 predecessor mpp was the inspiration of simple Mudela.  Secondly, the
480 hierarchical structure looks a lot like Rayce's (Rayce is a raytracer
481 that I've written as a hobby project. ), which in turn owes a lot to
482 POVRay.
483
484 Now, we know, musictypesetting and raytracing do not necessarily
485 require the same input format, and we know that a lot more ways exist
486 to convert music to ASCII, but we did give this language some
487 thoughts. As always suggestions are appreciated.
488