]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/refman.yo
release: 1.0.6
[lilypond.git] / Documentation / tex / refman.yo
1 COMMENT(-*-text-*-)
2
3 DEFINEMACRO(var)(1)(whenlatex(latexcommand({\normalfont\scshape )ARG1+latexcommand(}))\
4     whenhtml(sc(ARG1)))
5
6
7
8 COMMENT( This document contains Mudela fragments.  You need at least
9 Yodl-1.30.18 to convert this to tex or html.
10
11 TODO
12
13 in stead <-> instead
14 )
15
16 htmlbodyopt(bgcolor)(white)
17 htmlcommand(<font color=black>)
18
19 latexpackage()(a4wide)
20 latexlayoutcmds(
21 %\usepackage[latin1]{inputenc}
22 \input mudela-book
23 )
24
25 whenlatex(notableofcontents())
26 whentexinfo(notableofcontents())
27
28 report(Mudela, reference manual)
29       (Han-Wen Nienhuys and Jan Nieuwenhuizen)
30       (nop()PIPETHROUGH(date "+%B %d, %Y")()()nop())
31
32 COMMENT(
33
34 * The [ ] look weird
35
36 * paragraphs have too much space.
37
38 )
39
40
41 latexcommand(\def\interexample{})
42 latexcommand(\def\preexample{\par})
43 latexcommand(\def\postexample{\par\medskip})
44 latexcommand(\def\file#1{{code(#1)}})
45 COMMENT(
46 latexcommand(\def\texttt#1{\tt #1})
47 latexcommand(\def\textbf#1{\bf #1})
48 )
49
50
51 bf(This document is not up to date).  All rendered examples of course
52 are current, but the rest probably isn't.  Adjusting the tutorial was
53 considered more important than writing the reference manual.  We
54 apologize for the inconvenience.
55
56
57 This document describes the the GNU LilyPond input format, which is an
58 effective language for defining music.  We call this language (rather
59 arrogantly) The Musical Definition Language or Mudela, for
60 short.footnote(If anybody comes up with a better name, we'd gladly
61   take this. Gourlay already uses Musical Description Language,
62   G-Sharp Score Definition Language.  ISO standard 10743 defines a
63   Standard Music Description Language.  We're not being original here.)
64
65 The first aim of Mudela is to define a piece of music, being complete
66 from both from a musical typesetting, as from a musical performing
67 point of view.
68
69 The Musical Definition Language (Mudela), has a logical structure,
70 making use of identifiers, that allows for flexible input, and
71 definition reuse. See the documentation file file(MANIFESTO), included
72 with the LilyPond sources for reasons and design considerations.
73
74 The below is included for explanatory purposes only (i.e., for a
75 complete and up-to-date definition, see file(lily/parser.yy) and
76 file(lily/lexer.ll)).
77
78 As a related note, you should take a look at the examples and the init
79 files, as this document does not cover every aspect of Mudela yet, and
80 may be out of date.footnote(Ok, I am being pessimistic here.  This
81 just is a disclaimer.  Docs usually are written after the program
82 itself.)  This document intends to give an idea of how it works. It is
83 not a guide on how to use it.
84
85 sect(Files)
86
87 The de-facto extension of Mudela is file(.ly). Files may be included by
88 entering code(\include) at the start of a line:
89
90 verb(
91 \include "a_file.ly"
92 )
93
94
95 sect(Comments)
96
97 Line comments are introduced by a
98 code(%).
99 Block comments are delimited
100 by 
101 code(%{)
102 and
103 code(%}).
104 They do not nest.
105
106
107 sect(Versions)
108
109 Occasionally, small changes in syntax across different versions of
110 Mudela might give syntax errors. To warn you about possible
111 incompatibilities, you can specify the Mudela version for which the
112 inputfile was written,
113 verb(
114 \version "0.0.50";
115 )
116
117 A Python-script which tries to convert to newer versions
118 (file(convert-mudela)) is included in the LilyPond distribution.
119
120 sect(Keywords)
121
122 Keywords are preceded by a backslash: code(\). They contain
123 alphabetic characters only.
124
125
126 sect(Nesting characters)
127
128 Mudela uses the brace, `code({)' and `code(})' for most hierarchical
129 structures.  For chords the code(<) and the code(>) are used as
130 nesting braces.
131
132 sect(Constants)
133
134 verb(
135 "I am a string"
136 -1.2e3          % a real
137 12              % an int
138 )
139
140         
141 sect(Identifiers)
142
143 When assigning identifiers you use
144
145 verb(
146 string = ...
147 )
148
149 If you reuse identifiers, then the previous contents will be thrown
150 away after the right hand is evaluated, e.g.
151 verb(
152 bla = \melodic { \bla }
153 )
154 is legal
155
156 When using identifiers they have to be escaped:
157
158 verb(
159 oboe = \melodic { ... }
160 \score{ \melodic { \oboe }}
161 )
162
163 The left-hand part of the assignment is really a string, so 
164 verb(
165 "Foo bar 4 2 " = \melodic { .. }
166 )
167
168 is also a valid assignment (but you would have trouble referencing to it)
169
170
171 sect(Hierarchical structures)
172
173 The general structure consists of declarations:
174 verb(
175 IDENTIFIER = \TYPE{
176         <type specific data>
177 }
178 )
179 and instantiations:
180
181 verb(
182 \TYPE{ <type specific data> }
183 )
184
185 (Currently, code(\score) is the only type that can be instantiated
186 at top level.)
187
188 Most instantiations that use an IDENTIFIER are specified as follows:
189
190 verb(
191 \TYPE{ \IDENTIFIER [...] }
192 )
193
194 Some exceptions on this rule have been made to prevent inputting
195 Mudela becoming tedious
196
197 sect(Modes:)
198
199 To simplify different aspects of music definition (entering the notes
200 and manipulating them) Mudela has a number of different input "modes":
201
202 description(
203
204
205 dit(Normal mode)
206
207 At the start of parsing, Mudela assumes normal mode.
208 In Normal mode, a word is looked up in the following order:
209 description(
210 dit(code(word))    string
211 dit(code("string")) string
212 dit(code(\word)) keyword, identifier
213 )
214 In normal mode, a word is assumed to start with an alphabetic
215 character, followed by alpha-numeric characters.
216
217 dit(Note mode) Note mode is introduced by the keyword
218   code(\melodic).  In Note mode, a word is looked up in the following
219   order:
220 description(
221 dit(code(word)) notename, string
222 dit(code("string")) string
223 dit(code(\word)) keyword, identifier
224 )
225
226 In Note mode a word is considered to have alphabetic characters only,
227 so the underscore (_) is invalid.  If you accidently mistype a
228 notename, the parser will assume that you are entering a string (and
229 it will most likely complain that you should be in code(\lyric) mode to
230 do lyrics)
231
232
233 dit(Lyric mode) Lyrics mode is introduced by the keyword
234   code(\lyric).  Because of the various control characters that can
235   appear in lyrics, e.g., foreign language accents, the inputting a
236   string containing these has been made very easy.
237
238 In Lyrics mode, a word is looked up in the following order:
239 description(
240 dit(code(word))    string (thus a lyric)
241 dit(code("string")) string
242 dit(code(\word)) keyword, identifier
243 )
244
245 In Lyric mode every sequence of non-digit and non-white characters
246 starting with an alphabetic character or the _ is considered a word.
247
248 verb(
249 a&@&@&TSI|{[    % a word
250 1THtrhortho     % not a "word"
251 Leise DOEXPAND(Fl\)DOEXPAND("u\)ss{}teren meine Sapfe       % 4 words
252 _ _ _ _         % 4 words: 4 spaces
253 )
254 )
255
256 These modes are of a lexical nature. Normal and Note mode largely
257 resemble each other, save the possibility of entering Reals, 
258 meaning of code(_) and the resolution of words
259
260
261
262
263
264 Durations are entered as their reciprocal values
265 mudela(fragment,verbatim,center)(
266 a'1 a'2 a'4 a a'8 a a'16 a'32 a'64
267 )
268 Notice that you only have to specify the duration when it changes: Lily
269 assumes a note has the same duration as the previous one.
270
271 Now we can already write a little tune
272 mudela(fragment,verbatim,center)(
273 c' d' e' c' | c' d' e' c' | e' f' g'2
274 )
275 As you'll probably have guessed,
276 the vertical bar  code(|) may be used to mark
277 measures.
278
279 In the scale shown above
280 we left-out the last c note of the next octave.
281 Postfixing the pitch with a quote code(')
282 produces a note by one octave higher
283 mudela(fragment,verbatim,center)(
284 c c' c''
285 )
286
287 Postfixing the pitch with a comma, code(,)
288 produces a note by one octave lower
289 mudela(fragment,verbatim,center)(
290 a a, a,,
291 )
292
293 sect(Slurs and Ties)
294
295 A tie connects two adjacent note heads
296
297 mudela(fragment,verbatim,center)(
298 e' ~ e'
299 )
300
301 Whereas a slur rather connects `chords', 
302 and tries to avoid crossing stems
303
304 mudela(fragment,verbatim,center)(
305 e'( )e'
306 )
307
308 And of course, such a (legato) slur can span several notes
309 mudela(fragment,verbatim,center)(
310 c'( d' e' )f'
311 )
312
313 sect(Beams and Tuplets)
314
315 A beam is 
316 mudela(fragment,verbatim,center)(
317 [a'8 a'] [a'16 a' a' a']
318 )
319
320 Here's a beamed triplet
321 mudela(fragment,verbatim,center)(
322 [/3 a'8 a' a']/1
323 )
324
325 a triplet without a beam
326 mudela(fragment,verbatim,center)(
327 \[/3 a'4 a'8\]
328 )
329
330 and a combination
331 mudela(fragment,verbatim,center)(
332 [/3 a'8 a'16 a'] a'8 \]
333 )
334
335 Abbreviations
336 mudela(fragment,verbatim,center)(
337 c'1:16 [:16 e'1 g']
338 )
339
340 mudela(fragment,verbatim,center)(
341 c'4:32 [:16 c'8 d'8]
342 )
343
344 sect(Notenames)
345
346 Lily has predefined sets of notenames
347 for various nop(languages)footnote(These 
348 are Dutch, English, German, Italian and Swedish.
349 Simply include the language specific init file file(language.ly).).
350 The default set are the ones we like best are the Dutch notenames.
351
352 A sharp is formed by adding code(is)
353 mudela(fragment,verbatim,center)(
354 cis' dis' eis' fis' gis' ais' bis'
355 )
356
357 and a flat is formed by adding code(es)
358 mudela(fragment,verbatim,center)(
359 ces' des' es' fes' ges' as' bes'
360 )
361
362 With the obvious names for double sharps
363 mudela(fragment,verbatim)(
364 cisis' disis' eisis' fisis' gisis' aisis' bisis'
365 )
366
367 and double flats
368 mudela(fragment,verbatim)(
369 ceses' deses' eses' feses' geses' ases' beses'
370 )
371
372
373 There are two special `notenames', the rest
374 mudela(fragment,verbatim,center)(
375 r16 [a' a' a']
376 )
377
378 and the space
379 mudela(fragment,verbatim,center)(
380 a'2 s-"diminuendo" | a'
381 )
382
383
384 sect(Commands)
385
386 mudela(fragment,verbatim,center)(
387 \clef "bass"; c
388 )
389
390 and a clef-change
391 mudela(fragment,verbatim,center)(
392 \clef "treble"; f' e' \clef "alto"; d' c'
393 )
394
395 mudela(fragment,verbatim,center)(
396 \time 3/4; c' g' g' |
397 )
398
399 mudela(fragment,verbatim,center)(
400 \key d;
401 g a b cis' d' e' fis' g'
402 )
403 Note how Mudela allows you to 
404 convey a musical message and doesn't force  you to produce a list of typesetting commands.
405 If the music has a code(cis), you type a code(cis).
406 Depending on the key and context of the note
407 Lily will determine what accidentals to typeset.
408
409 A reminder accidental can be forced by
410 using an exclamation mark code(!)
411 on a pitch a reminder accidental
412 mudela(fragment,verbatim,center)(
413 cis' d' e' cis' | c'! d' e' c' |
414 )
415
416 mudela(fragment,verbatim)(
417 \time 2/4;
418 \bar "|:"; c' c' \bar ":|:"; c' c' \bar ":|"; c' c' \bar "|."; 
419 )
420
421 sect(Chords and Voices)
422
423 Here's a simple chord
424 mudela(fragment,verbatim,center)(
425 <c e g>
426 )
427
428 here are a few
429 mudela(fragment,verbatim,center)(
430 <
431         { c'()d'()c' }
432         { e'()f'()e' }
433         { g'()a'()g' }
434 >
435 )
436
437 and similarly voices
438 mudela(fragment,verbatim)(
439 <
440         { \voiceone c'4 g' c' g' }
441         { \voicetwo c2 g2 }
442 >
443 )
444
445
446 sect(A complete example)
447 COMMENT(%label(se:complete))
448
449 A Mudela file needs some red tape
450
451 mudela(verbatim)(
452 \score{
453         \melodic {
454                 c' d' e' c' |
455                 c' d' e' c' |
456                 e' f' g'2 |
457         }
458 }
459 )
460
461 sect(Lyrics)
462
463 Lyrics are entered like notes, with pitches substituted
464 by text. 
465
466 All syllables are entered separately, separated by whitespace 
467 verb(
468 Twin-4 kle4 twin-4 kle4 ... 
469 )
470
471 Two syllables or words that compose a single
472 duration entry are bound together using an underscore 
473 verb(
474 He_could4 not4
475 )
476
477
478 COMMENT(
479 URG
480                         Fr\`e-4 re Ja- que
481                         Fr\`e- re Ja- que
482 )
483
484 mudela(verbatim,center)(
485 \score{
486         < 
487                 \melodic  \transpose c''  {
488                         c d e c | c d e c |
489                         e f g'2 | e'4 f g'2
490                         \bar "|.";
491                 }
492                 \type Lyrics \lyric{ 
493                         DOEXPAND(Fr\)`e-4 re Ja- que
494                         DOEXPAND(Fr\)`e- re Ja- que
495                         Dor- mez vous?2
496                         Dor-4 mez vous?2
497                 }
498         >
499 }
500 )
501
502 sect(Composition: forming bigger structures)
503 label(sec:grammar)
504
505 The computer savy user may be interested in a more formal
506 specification.  We can capture what have learned about forming
507 sentences in Mudela in a context-free grammar.
508
509 latexcommand(\smallskip)
510
511 table(2)(lll)(
512         row(cell(em(Music))cell(: em(Note)))
513         row(cell()cell(code(|) em(Rest)))
514         row(cell()cell(code(|) code({) em(MusicList) code(})))
515         row(cell()cell(code(|) code(<) em(MusicList) code(>)))
516         row(cell()cell(code(|) em(Command)))
517         row(cell()cell(code(|) code(\type) em(string) code(=) em(string)  em(Music)))
518         row(cell()cell(;))
519         row(cell(em(MusicList))cell(: em(empty)))
520         row(cell()cell(code(|)  em(MusicList)  em(Music)))
521         row(cell()cell(;))
522 )
523
524 latexcommand(\smallskip)
525
526
527
528
529
530 In mathematics you can form expressions by combining expressions,
531 which are ultimately some kind of atom or terminal symbol.  The same
532 goes for Mudela: there are some basic building blocks, and by
533 combining those you create complex music.
534
535 You can combine music in three ways:
536 itemize(
537 it()If you enclose a sequence of music-elements in braces ( code({)
538     and code(}) ), then you form another kind of music called
539 sequential music
540     with those pieces.
541   The duration of sequential composition is the sum of the durations of its elements
542   verb(
543       { c c g g a a g2 }      % twinkle twinkle
544       { { c c g g} { a a g2 } }
545   )
546 it()You can stack music by enclosing a sequence of music elements
547     with code(<) and code(>). This is called simultaneous music.  
548     The duration of a simultaneous composition is the union of the durations 
549     of its elements Example:
550     verb(
551         <a4 {cis8 cis8} e'4>      % a-major chord
552     )
553 it()You can form music by transposing music:
554     verb(
555     \transpose  
556         d       % from c to the d that's almost one octave down
557                 { e4 f4 }       % the horizontal music
558 )
559 it()verb(\type)
560 it()verb(\property)
561 it()verb(\translator)
562 it()verb(\relative)
563 )
564
565 Of course you can also combine these three mechanisms.
566 verb(
567 { c <c e> <c e g> <c e g \transpose d' dis > }  % 4 increasing chords
568 )
569
570
571 sect(Durations)
572
573 A duration always starts with the duration type (1,2,4 etc), and then
574 any optional multipliers/dots.  `Gregrorian' durations can be entered
575 as follows
576 verb(
577 c'\breve
578 gis'\longa
579 )
580
581
582         
583 sect(Time signatures/groupings)
584
585 A time signature specification has this form:
586 verb(
587 \time 3/4 ;
588 )
589
590 Rhythmic grouping is  a concept closely associated with this. For
591 example, in a 5/8 time signature, the counts are grouped 2+3. In Mudela this is
592 entered as
593 verb(
594 \grouping  8*2 8*3 ;
595 )
596
597 You can start the piece with a partial measure, the command takes a
598 duration as an argument
599 verb(
600 \partial 16*3;
601 )
602
603 Make the piece start with a upstep 
604 lasting 1 3/4 quarter notes.
605
606 These commands  constitute `Music', and have a duration of 0.
607
608
609 sect(Properties)
610
611 By default the same key signature is valid for all octaves, but
612   this can be changed with the property code(keyoctaviation).
613
614
615 The identifier code(\specialkey) sets the property for the Staff.  A
616 key with two flats in one octave and three sharps in the next can be 
617 declared with verb(\specialkey \keysignature bes es fis' cis' gis';)
618
619 sect(Music fragments)
620 label(tutorial:music-fragments)
621
622 Sometimes you only need to print a small fragment of music, perhaps 
623 something much like one of the examples in this document.  Back in
624 section ref(sec:running-lilypond) we told you that the music you
625 enter should be encapsulated in something like:
626 verb(
627 \score<
628         \melodic\relative c{
629                 d
630         }
631         \paper{ }
632         \midi{ }
633 >
634 )
635 where the only interesting information is this particular example is verb(
636         d
637 )
638 The rest of the above example was already nicknamed `red tape'.
639 You may easily get bored if you have to provide this same red tape 
640 for every fragmenty you nop(try)footnote(Of course, in most cases your
641 favourite text editor (TM)
642 will help you out.).
643
644 Luckily there's a trick around this, and it's called file(.fly) files.
645 If you use the extension file(.fly) for Mudela file file(foo),
646 LilyPond will embed your file(foo.fly) nop(in)footnote(Or something very 
647 similar.  If you want to know exactly, see file(init/init.fly)):
648 verb(
649 \score<
650         \melodic\relative c{
651                 <<foo.ly>>
652         }
653         \paper{ }
654         \midi{ }
655 )
656
657 Here's how it works.  If you run LilyPond on your file file(bar.ly), you
658 may notice that she starts-off by reading quite a number of files before
659 she actually reaches your file(bar.ly).  There's no magic going on, Lily
660 by default reads an initialisation file (file(init/init.ly)).  In the
661 initialisation process a lot of things are defined that you'll need for 
662 normal operation, such as notenames and various other mudela shortcuts,
663 engraver and perforer definitions, font sizes, musical dimensions and 
664 paper sizes.  When you use the extension file(.fly), Lily just starts
665 reading another initialisation file (file(init/init.fly)), that includes the 
666 red tape for you too.
667