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