]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/tutorial.yo
release: 1.1.13
[lilypond.git] / Documentation / tex / tutorial.yo
1 COMMENT(-*-text-*-)
2
3 redef(var)(1)(whenlatex(latexcommand({\normalfont\scshape )ARG1+latexcommand(}))\
4     whenhtml(sc(ARG1)))
5
6 COMMENT( This document contains Mudela fragments.  You need at least
7 Yodl-1.30.18 to convert this to tex or html.
8
9 TODO
10
11 pipethrough(date) sucks.
12
13 paragraphs have too much space.
14
15 )
16
17 COMMENT(
18         Mainly written by Han-Wen Nienhuys, 
19
20         with help of (among others)
21
22         * Jan Nieuwenhuizen
23
24         * Lambert Meertens,
25
26         * Adrian Mariano
27
28         * Mats Bengtsson
29
30 )
31
32 htmlbodyopt(bgcolor)(white)
33 htmlcommand(<font color=black>)
34
35 latexlayoutcmds(
36     \topmargin -0.25in  
37     \textheight 53\baselineskip
38     \advance\textheight by \topskip
39     \marginparwidth 1 in        %   Width of marginal notes.
40     \oddsidemargin 0.25 in      %   Note that \oddsidemargin = \evensidemargin
41     \evensidemargin 0.25 in
42     \marginparwidth 0.75 in
43     \textwidth 5.875 in % Width of text line.
44     \input mudela-book
45 )
46
47 whenlatex(notableofcontents())
48 whentexinfo(notableofcontents())
49
50 article(Mudela -- Using LilyPond to typeset music)
51       (Han-Wen Nienhuys and Jan Nieuwenhuizen)
52       (nop()PIPETHROUGH(date "+%B %d, %Y")()()nop())
53
54
55 latexcommand(\def\interexample{})
56 latexcommand(\def\preexample{\par})
57 latexcommand(\def\postexample{\par\medskip})
58 latexcommand(\def\file#1{{code(#1)}})
59
60 whenhtml(
61 includefile(html-disclaimer.yo-urg)
62 )
63
64
65 sect(Introduction)
66 label(tutorial:introduction)
67 latexcommand(\parindent2pc)
68   
69 If you are reading this, you probably are interested in printing
70 music.  LilyPond is a program that can print music from a
71 specification that you, the user, supply.  Using LilyPond may be a bit
72 quaint in the beginning, because you have to give that specification
73 using a em(language).  This document is a gentle introduction to that
74 language, which is called Mudela, an abbreviation for Music Definition
75 Language.
76
77 We will demonstrate the working of Mudela by presenting  examples of
78 input alongside with the resulting output.  We will comment on these
79 examples using English terms for notation, so if you are not familiar
80 with these terms, you should consult the glossary that is distributed
81 with LilyPond: it contains a list of musical terms along with
82 explanations and translations in some other languages.
83
84 sect(The first tune)
85 label(sec:firsttune)
86
87 To demonstrate what LilyPond input looks like, we start off with a
88 full fledged, yet simple, example. It is somewhat convoluted version
89 of one of the menuets in bind(J.)bind(S.)Bach's em(Clavierbuchlein).
90
91 mudela(verbatim)(
92 % lines preceded by a percent are comments.
93 \include "paper16.ly"
94 \score {
95     \notes                      
96     \relative c'' {             
97         \key g;
98         \time 3/4;              
99
100         d4 [g,8 a b c] d4 g, g |
101         e'4 [c8 d e fis] g4 g, g |
102         c4 [d8( )c b a( ] )b4 [c8 b a g] |
103         a4 [b8 a g fis] g2.  |
104
105         \bar ":|";              
106
107         b'4 [g8 a b g]
108         a4 [d,8 e fis d] |
109         g4 [e8 fis g d] cis4 [b8 cis] a4 |
110         [a8-. b-. cis-. d-. e-. fis-. ] 
111         g4 fis e |
112         fis a,  r8 cis8
113         d2.-\fermata
114         \bar "|.";
115     }
116     \paper {
117        linewidth = 14.0 \cm; % standard settings are too wide for a book
118    }
119 })
120
121 Before we will discuss the contents of the above, it would be best if
122 you would try to enter and save this text with a text editor, compile
123 it with LilyPond and view the output.  Details of this procedure may
124 vary from system to system.  On a Unix system, you should enter the
125 input in a file ending in file(.ly), such as file(menuet.ly).  To
126 create the output, one would issue code(ly2dvi menuet).
127
128 file(ly2dvi) is a little program that does the job of calling the
129 LilyPond and TeX() and adjusting page margins.
130
131 If all goes well, this will create the output file file(menuet.dvi).
132 To view this output, issue the command code(xdvi menuet).  Now that we
133 are familiar with the procedure to view the output, we will analyse
134 the input itself, line by line.
135
136 verb(% lines preceded by a percent are comments.)COMMENT(
137
138 )The percent sign (code(%)) introduces a line comment.  If you want
139 make larger comments, you can use block comments. These are delimited
140 by code(%{) and code(%})
141
142
143 verb(\input "paper16.ly")
144
145 By default, LilyPond will use definitions for a staff of 20 point
146 high.  If you want smaller output (e.g., 16 point), you have to import
147 the setting for that size.  You can do this by including a file.
148 code(\include "file") is replaced by the contents of  code(file).
149
150
151 verb(\score {
152 ) COMMENT( 
153
154 ) A mudela file combines music with directions for outputting that
155 music.  The music is combined with the output directions by putting
156 them into a code(\score) block.
157 verb(
158    \notes               
159 ) COMMENT( 
160
161 )This makes LilyPond ready for accepting notes.
162 verb(
163     \relative c''
164 )COMMENT(
165
166 ) As we will see, pitches are combinations of octave, note name and
167 chromatic alteration.  In this scheme, the octave is indicated by
168 using raised quotes (`code (')') and ``lowered'' quotes (commas:
169 `code(,)').  The central C is denoted by code(c').  The C one octave
170 higher is code(c'').  One and two octaves below central C is denoted
171 by code(c) and code(c,) respectively.
172
173 If you have to indicate the pitches in a long piece that is written in
174 either a high or very low octave, you would have to type very many
175 quotes.  To remedy this, LilyPond has a so-called "relative" octave
176 entry mode.  In this mode, notes without quotes are chosen in such an
177 octave that they are the closest to the preceding note.  If you add a
178 high-quote an extra octave is added.  The lowered quote will substract
179 an octave.  Because the first note obviously has no predecessor, you
180 have to give the (absolute) pitch of the note to start with.
181 COMMENT(
182
183 )verb(
184        {                          % sequential music follows
185 )COMMENT(
186
187 ) The brace indicates that what follows is sequential music, i.e.,
188 notes that are to be played and printed after each other.  This is in
189 contrast with simultaneous music: notes that are to be played like a
190 chord.  You should be careful not to confuse this brace with the one
191 coming after code(\score).
192
193
194 verb(
195         \time 3/4;              % set the time signature.
196 ) COMMENT(
197
198 ) This command changes the time signature of the current piece: this
199 prints a 3/4 sign.  The 3/4 value is also used to generate bar lines
200 in the right spots.
201 verb(
202         \key g;
203 ) COMMENT(
204
205 ) This command changes the current key to G-major.  Although
206 this command comes after the code(\time) command, in the
207 output, the key comes before the time signature: LilyPond knows about
208 music typesetting conventions.
209 verb(
210         d4
211 ) COMMENT(
212
213 ) This is a code(d) note.  The relative music was started with a
214 code(c''), the real pitch of this note is code(d'').  The 4 
215 designates the duration of the note (it is a quarter note). COMMENT(
216
217 )verb(
218         [g,8
219 )COMMENT(
220
221 )The open bracket starts a beam.  This bracket is connected to the
222 following note, which is an eighth with pitch code(g') (remember
223 relative mode for pitches!)
224 COMMENT(
225
226 )verb(
227         a b
228 )COMMENT(
229
230 )These are notes with pitch code(a') and code(b').  Because their
231 duration is the same as the code(g), there is no need to enter the
232 duration (It is not illegal to enter it anyway.  Then you would have
233 to enter code(a8 b8))
234 COMMENT(
235
236 )verb(
237           c]
238 ) COMMENT(
239
240 ) This ends the beam started four notes earlier, at the code(g).  In
241 the output, you will notice a measure bar following this note.  You do
242 not have to enter anything to make LilyPond create a bar.  Instead
243 Lily will deduce where bars have to be by comparing durations of notes with
244 the current time signature.  COMMENT(
245
246 )verb(
247           d4 g, g |
248 ) COMMENT(
249
250 ) Three more notes:  The code(|) is a "barcheck".  When processing the
251 music, LilyPond will check  that barchecks are found at the start of
252 a bar precisely.  This makes it easy to spot where notes are forgotten. 
253 verb(
254         e'4 [c8 d e fis]
255 ) COMMENT(
256
257 ) So far, no notes were chromatically altered.  Here is the first one
258 that is: code(fis). Mudela by default uses Dutch note names, and
259 ``Fis'' is the Dutch note name for ``F sharp''.  However, there is no
260 sharp sign in the output. The program keeps track of key signatures,
261 and will only print accidentals if they are needed.
262 verb(
263         c4 [d8( )c b a( ] )b4 [c8 b a g] |
264 ) COMMENT(
265
266 ) The next line shows something new: a slur is a symbol that is
267 printed over several notes.  In mudela, one enters a slur by marking
268 the beginning and ending note of the slur with an opening and closing
269 parenthesis respectively.  In the line shown above this is done for
270 two slurs.  Note that parentheses (slur markers) are between the
271 notes, and the brackets (beam markers) around the notes. As you can
272 see, the brackets and parentheses do not have to nest.
273
274 verb(
275         a4 [b8 a g fis] g2.  |
276 ) COMMENT(
277
278 ) A duration that is to be augmented with a duration dot, is notated
279 with a duration number followed by periods, as many as you want
280 augmentation dots.COMMENT(
281
282 )verb(
283         \bar ":|";              % a repeat sign
284 ) COMMENT(
285
286 )
287 Lily can not detect where you want your music to be repeated, so you
288 have to instruct her: a special bar symbol can be entered by the
289 code(\bar) command followed by a string that signifies the bar symbol
290 that you want.  Then comes a semicolon to separate the string from the
291 rest of the notes, analogously with code(\key) and code(\time).
292 verb(
293      cis'4 [b8 cis] a4 |
294 ) COMMENT(
295
296 )
297 This line shows that Lily will print an accidental if that is needed:
298 the first C sharp will be printed with an accidental, the second without.
299 verb(
300         [a8-. b-. cis-. d-. e-. fis-. ] % try some super and subscripts.
301 ) COMMENT(
302
303 )
304 There is more to music than just pitches and rhythms.  An important
305 aspect is articulation.  You can enter articulation signs either in an
306 abbreviated form, by a dash and the the character for the
307 articulation to use,  e.g. code(-.) for staccato as shown above.
308 COMMENT(
309
310 )verb(
311         fis a,  r8 cis8
312 ) COMMENT(
313
314 )
315 Rests are denoted by the special notename code(r).  You can also make
316 an invisible rest by using the special notename code(s).
317 verb(
318         d2.-\fermata
319 ) COMMENT(
320
321 ) Finally, all articulations have a verbose form, like code(\fermata).
322 The ``command'' COMMENT(Hi Adrian :-) code(\fermata) is not part of
323 the core of the language (most of the other discussed elements are),
324 but it is an abbreviation of a more complicated description of a
325 fermata.  code(\fermata) refers to that abbreviation and is therefore
326 called an em(identifier).
327
328 verb(
329         }
330 ) COMMENT(
331
332 )
333 This ends the sequential music.
334
335 verb(\paper {
336             linewidth = 10.0\cm;
337 })
338 This specifies a conversion from music to notation output.  Most of
339 the details of this conversions (font sizes, dimensions, etc.) have
340 been taken care of, but  to fit the output  in this document, it has
341 to be smaller.  We do this by setting the line width to 10 centimeter
342 (approximately 4 inches).
343
344 verb(
345         }
346 )
347 Finally, the last brace ends the code(\score) block.
348
349
350
351 There are a couple of things to note here.  The input format tries to
352 capture the meaning of em(music), and not notation.  Therefore the
353 format contains musical concepts like pitches and durations, instead
354 of symbols and positions.  Second, the format tries to be
355 em(context-free): a note will sound the same regardless of the current
356 time signature, the key nop(etc.)
357
358 The purpose of LilyPond informally is explained by the term `music
359 typesetter'. As you may have figured out by now, this is not a really
360 adequate name: not only does the program print musical symbols, it
361 also tries to make esthetic decisions, and it also em(generates) both
362 the symbols and the decisions from a high-level musical description.
363 In other words, the function of LilyPond would be best described by
364 `music compiler' or `music to notation compiler'.
365
366 We find that ---once you master the language--- there are big
367 advantages of using LilyPond over GUI oriented programs: first,
368 entering music is quite efficient.  Second, it is possible to explain
369 exactly what the meaning piece of mudela is, and you can transform
370 these pieces automatically (eg, by transposing them).  Third, the
371 program that is not interactive, so much less tradeoffs have to be
372 made between processing speed and the beauty of the output: you get
373 prettier output by using LilyPond.
374
375
376 As you can see, the most interesting part of the input is music
377 itself, in this case the sequence of notes.  We will therefore focus
378 on entering music for now.  Consequently, when we mean
379 verb(\score {
380         \notes { XXXX } 
381         \paper {  }
382 })COMMENT(
383
384 ) we will leave out the the repetitive details for now and just print
385 code(XXXX).
386
387
388
389 sect(When you know the notes to nop(print)ellipsis())
390
391 The basic building block of music is the note.  We lightly touched
392 notes in the previous example.  Here comes the full explanation A note
393 is made of a pitch and a duration.  The pitch of the central C is
394 written as code(c').  This is in line with musicological notation;
395 there this pitch is transcribed as nop(c)sups(1) or c'.  A
396 quarter-note duration is written as code(4).  So, to print a quarter
397 note whose pitch is central C, you enter the following code(c'4).
398
399 subsect(Duration)
400
401 The duration of a note is specified as a number: a whole note is
402 denoted by 1, a half note by 2, a quarter by 4, and so on.  If you
403 want to augment a duration with a dot, simply affix a period to the
404 number.  You can also print notes longer than a whole.  You do this by
405 using identifiers (code(\breve) and code(\longa):
406 Here are some random notes to show how it works.
407
408 verb(
409   c'\longa c'\breve  
410   c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64 c'2. c'8. c'16
411 )
412
413 mudela()(
414 \score {
415        \notes {
416          c'\longa c'\breve  
417          c'1 c'2 c'4 c'8 c'16 c'32 c'64 c'64 c'2. c'8. c'16
418          }
419          \paper {
420                 linewidth = -1.0;
421                 \translator { \type "Score_engraver";
422                             \name "Score";
423                             \consists "Note_heads_engraver";
424                             \consists "Stem_engraver";
425                             \consists "Rhythmic_column_engraver";
426          }}}
427          
428 )
429
430 subsect(Basic pitches)
431
432 The pitch code(c')  consists of two parts: one part for the
433 note name, and one for the octave.  The letter specifies which note
434 name to use: note names simply are the letters code(a) to code(g).
435 The number of apostrophes specifies the octave to use: the central C
436 is denoted by code(c').footnote(By convention, the A above central C
437 at concert pitch is the tone that is used to tune instruments.  Its
438 frequency is about 440 Hz.)  The C which is an eighth higher (the C in
439 the ``two-line octave'') is denoted by code(c''): every octave adds a
440 quote.  A note name without quotes designates the pitch below code(c')
441 (the C in the ``small octave''). If you want to go down even further,
442 commas should be added, e.g., the C in the ``contra octave'' is
443 expressed as code(c,,).footnote(The comma is meant to represent a
444 sunken apostrophe.)
445
446 This example demonstrates pitches
447 mudela(fragment,verbatim,center)(
448    c,,4 c, c c' c'' c''' d'4 e'4 f'4 g'4
449 )
450
451
452 subsect(Alterations)
453
454 We have so far ignored chromatically altered pitches.  The names `a'
455 to `g' for entering pitches are convenient: they are short,
456 pronounceable and they resemble the words for pitches in normal
457 musical vocabulary.
458
459 Enter flats and sharps.  In English there is no standard terse word
460 for C sharp or C flat.  For this reason, mudela uses a different,
461 non-English convention for entering altered pitches: a note is made
462 sharp by adding the suffix `--is' to its name, and flat by adding the
463 suffix `--es'.  For a double sharp another `--is' suffix is added, for
464 flats another `--es' nop(suffix.)  footnote(Variations on this
465 convention are used in a number of germanic languages, notably Dutch,
466 German, Swedish, and Norwegian.) The names for the alterations of C
467 are given in bind(Table)ref(notename-tab).
468
469 latexcommand(\begin{table}[h])
470   center(
471     table(2)(ll)(
472       row(cell(english)cell(LilyPond))
473       rowline()
474       row(cell(c double flat)cell(ceses))
475       row(cell(c flat)cell(ces))
476       row(cell(c natural)cell(c))
477       row(cell(c sharp)cell(cis))
478       row(cell(c double sharp)cell(cisis))
479     )
480   )
481   latexcommand(\caption{Default note names})
482   label(notename-tab)
483 latexcommand(\end{table})
484
485 Throughout this document we will continue to use these names.footnote(
486   Mudela defaults to Dutch notenames.  To make (Dutch) pronunciation
487   easier, the a-flat and e-flat are contracted to code(as) and
488   code(es).  Similarly, the a double flat and e double flat are
489   contracted to code(ases) and code(eses).  For consistency, the dutch
490   names also include code(aes), code(aeses), code(ees) and
491   code(eeses)) 
492
493 If you are not comfortable with these names, you can make your own.
494 Note names for different languages are included with the example
495 initialisation files, amongst others English (C sharp is abbreviated
496 to code(cs)), Italian, Swedish and Norwegian.  If you want to use
497 these names, issue code(\include "LANGUAGE.ly") where you could
498 substitute code(italiano), code(deutsch) etc.  for LANGUAGE.  You
499 should include these files at toplevel, i.e., before opening a
500 code(\score) block.
501
502
503 sect(Chords)
504
505 The previous examples all notes   that were to be played sequentially,  one
506 note following the other.  You can also use LilyPond to typeset
507 chords.  You do this  by expressing in mudela simultaneous music,
508 i.e.,   notes that are to be played concurrently. 
509
510 In Mudela you can form simultaneous music by enclosing notes in
511 pointed parentheses, bind(i.e.)bind(langle())bind(and)rangle().  ASCII
512 doesn't really have these delimiters, so Mudela uses the larger-than
513 (code(>)) and smaller-than (code(<)) signs instead.  For example, a
514 D-major chord is expressed as
515 mudela(fragment,verbatim,center)(
516   <d'8  fis'8 a'8 d''8>
517 )
518
519 Chords can be entered in the music in the same places that notes
520 can.  As an example we give a snippet of ``Twinkle Twinkle Little
521 Star'' in chords.  The chords may seem slightly unconventional, but
522 they only serve to show how chords work.  We've aligned the chords in
523 the input on their starting beat just to help you reading it.  This
524 layout does not influence the typesetting result in any way.
525
526 mudela(verbatim, fragment)(
527   \relative c' {
528   \time 2/4;
529   c4       c            <c g'>    <c e g>
530   <c e a>  <b d a'>     <b2 d g>
531   <a4 d f> <bes d f>    <bes c e> <g c e>
532   <e a d>  <a, g' cis'> <d2 f d'>
533   }
534 )
535
536 There is one thing to note, in sequences of chords, the (relative)
537 pitch of a is taken with reference to the first note of the previous
538 chord.
539
540 You can nest simultaneous and sequential music in any way you want,
541 e.g., COMMENT(
542
543 )mudela(verbatim,fragment,center)(
544         < { g''4 g''4 }
545           { c'8 <c' e'> c' <c' e'> } >
546 )COMMENT(
547
548 )
549 As you can see, LilyPond has some difficulty typesetting this
550 elegantly.  To adequately solve this, you have to persuade LilyPond to
551 make separate stems for both sequential music lists.   This is a topic
552 that is covered in bind(Section)ref(sec:polyphonic).
553
554 [Chords and relative mode]
555
556
557 sect(Adding nuances: articulation and dynamics)
558
559 Having just chords and notes does not give you real music.  Real music
560 has more liveliness to it: music can have articulation, dynamics
561 (louder and softer), etc.  This liveliness has notation, so LilyPond
562 can print it.  We'll start out by explaining how to obtain the
563 smallest grains of nuance: the articulation of a single note.  Articulation
564 is entered by writing a dash and the name of the desired articulation
565 mark.  You have to add a backslash in front of the name to distinguish
566 it from the name of a note. COMMENT(
567
568 )mudela(fragment,verbatim)(
569   c''4-\staccato
570   c''4-\tenuto )COMMENT(
571
572 ) Typing a lot of staccato notes in this syntax will get tedious very
573 quickly.  Therefore, Mudela has some handy abbreviations for
574 articulation marks such as staccato and tenuto.  They are shown in the
575 following example: COMMENT(
576
577 )mudela()(
578 \score{ <
579         \property Score.textstyle = typewriter
580         \type Staff \notes {
581                 c''4-.
582                 c''4--
583                 c''4-+
584                 c''4-|
585                 c''4->
586                 c''4-^
587                 }
588         \type Lyrics\lyrics {
589               "."4 "-" "+" "|" ">" "\^{ }" }
590         >
591         \paper { linewidth = 12.\cm; }
592 })COMMENT(
593
594 )Text and digits for fingering can be entered in the same manner: add a
595 dash and the text or digit to be printed:
596 COMMENT(
597
598 )mudela(fragment,verbatim)(c''4-1 g''4-5 c''-"Sul tasto" )
599 COMMENT(Currently, the meaning of the
600 syntax `note-dash-digit/articulation/text' is just ``add a superscript to this
601 note.''  This is not in line with our goal to em (define) music with
602 Mudela.  We hope that this will be fixed in a future version of the
603 language.  In the meantime you can abuse this: the super- and
604 subscripts can be forced into up or down position respectively by entering an
605 a caret (code(^)) or an underscore, code (_) instead of the dash:
606 mudela (fragment,verbatim,center) (
607   c'4-^ c'4^^ c'''4-^ c'''4_^
608 ))
609
610 Dynamic markings are another way to add a nuance to a note.  They are
611 entered by adding the name for the dynamic sign after the note.  You
612 should not enter a dash between the name and the note.footnote(This
613   is inconsistent.  We hope that this will be fixed in a later
614   version of the language.)COMMENT(
615
616 )mudela(verbatim,fragment)(
617   c4 \ff c4 \fp c4 c4 \ppp c4 c4 \sfz
618 )COMMENT(
619 UGH
620
621 )
622
623 sect(Bridging the notes: beams, slurs and ties)
624
625 Music typesetting does not use fixed symbols only.  A lot of symbols
626 are variable: they run from one note to another. In LilyPond
627 terminology, such a symbol is called a em(spanner).  To print a
628 spanner, you have to attach a marker to the note that begins it and to
629 the one that ends it.  These are the spanners that are entered like
630 this:
631
632 description(
633 dit(The slur)
634  The slur has the opening parenthesis as 
635 start marker is.  The stopping marker is the closing parenthesis.
636 For example:
637 mudela(fragment,center,verbatim)( c'4( )c'4 )
638
639   The slur is quite flexible: you can nest nop(slurs,)footnote(This is
640 inconsistent when compared to the syntax for articulation hints.  This
641 will be fixed some time, we hope.) and you can connect a note with a
642 slur on both the left and the right side:
643
644 mudela(fragment,verbatim,center)(
645   c'4((   )c''4 )c'4( )g'4 
646 )
647
648 dit(Beam)
649
650 Another spanner is the beam.  The starting marker is the opening
651 bracket, then ending marker is the closing bracket.  The brackets have
652 to be em(around) the beamed notes.  footnote(Strictly speaking, a
653 beam is not a musical concept: beaming doesn't change the meaning of
654 music, it only clarifies the rhythmic structure.  One might argue that
655 beams should not be present in a ``music'' language.  Unfortunately,
656 LilyPond is not smart enough to insert beams into music on its own.
657
658 LilyPond does have code that guesses what the pattern should look
659 like, so that you don't have to specify the beaming for complicated
660 patterns.  Alas, the algorithm used is not foolproof
661 yet: code([c8. c32 c32]) will produce incorrect results.)
662
663 mudela(fragment,verbatim)(
664 [c'8 c'] [c'16 c' c' c'] [c'16. c'32 c' c'16.]
665 )
666
667 dit(The tie) The tie is similar to the slur: it  looks like a
668 slur, but a slur connects whole chords, whereas the tie connects note
669 heads.  Tied notes should be played as one long note.  In analogy with
670 TeX()'s tie (which ties together words with a space), LilyPond's tie
671 is entered as a tilde, `code(~)'.
672
673 The input convention for the tilde is somewhat peculiar when used in
674 conjunction with chords.  Internally, the extra information that is
675 represented by the tilde has to be attached to a note (or to a rest,
676 for that matter).  For this reason, you can't put the tilde between
677 two chords (as in code( <c' g'> ~ <c' g'>)).  The tilde sign must be
678 directly after a note of the chords.  It does not matter which
679 one. The following example demonstrates the use of ties:
680 mudela(fragment,verbatim,center)(
681   c''1 ~ c''4
682   <c'2. ~  g' es''> <c'4 g' es''> 
683 )
684
685 dit(Hairpins)
686 Crescendi and decrescendi can be printed in hairpin style.  The
687 starting marker for the crescendo is code(\<), and for the decrescendo
688 code(\>).  Both have code(\!) as the ending marker.
689 mudela(fragment, verbatim)(
690    \relative c'' { c4 \< \! c4 \> \! c2
691       < c1
692         { s4 \< \! s4 \> \! s2 } > }
693 )
694 This example shows a trick: by attaching the markings to space rests
695 that run parallel to the whole note, you can have dynamic markings
696 within a note. 
697
698 )
699
700 It is your job to make sure that each spanner that you start, also
701 ends.  If it doesn't, then Bad Things are likely to happen. If you end
702 spanners that are not started, LilyPond will warn you about illegal
703 ending markers.
704
705 sect(Commands)
706 label(sec:commands)
707
708 We have focused on printing notes. Notation contains many other
709 constructs, constructs that help you with reading those notes.
710 Examples of such constructs are clefs, time signatures, keys etc.
711 LilyPond will try to generate these constructs as much as possible,
712 but not all such hints can be inserted automatically, and you can also
713 override some of the settings.  This can be done by inserting various
714 commands between the music.  The general form of these commands is
715 COMMENT(
716
717 )center(code(\keyword argument argument ... ;))
718
719 These are the commands that are currently supported:
720 description(
721 dit(code(\bar) var(bartype))
722   This command makes LilyPond print special bar
723   lines and repeat symbols.  You can also use it to allow line breaks
724   when entering cadenzas.  The argument var(bartype) is a string that
725   describes what kind of bar line to print.
726
727 mudela(fragment,verbatim)(
728     \bar "|:"; c'4 \bar ":|:";    c'4  \bar ":|";  c'4 \bar "||";
729     c'4 \bar "empty"; c'4 \bar "|.";
730 )
731
732   The command `code(\bar "empty")' does not create any visible bar
733   line, but it tells LilyPond to allow a linebreak at that
734   position.  The `code(\bar)' command prints the specified symbol
735   immediately.  If you give a `code(\bar)' command at the end of a
736   measure then the specified symbol replaces the automatic bar line;
737   otherwise the specified symbol appears in the middle of the measure.
738   The code(\bar) command does not affect metric structure.
739
740 dit(code(\cadenza) var(togglevalue)) This command toggles the
741 automatic printing of barlines.  `code(\cadenza 1)' turns off the
742 automatically generated bar lines.  They are switched on again with
743 `code(\cadenza 0)'. Then a bar line is printed, and LilyPond will act
744 as if you are again at the start of a measure.
745
746
747 This is useful when typesetting music without a meter (such as an ad
748  libitum cadenza).
749
750 dit(code(\clef) var(clefname)) This command sets the current clef for notation,
751   i.e., a clef symbol is printed and the notes following this command
752   are shifted vertically.  The argument is a string, the name of the
753   new clef. The default clef is the treble clef.
754   mudela(fragment,verbatim)(
755     \clef "bass"; c'4
756     \clef "treble"; c'4
757     \clef "alto"; c'4    
758   )
759
760 dit(code(\key) var(pitch) var(type)) This command changes the current
761   key signature.  The key signature is printed at the start of every
762   line. The var(type) argument is set to code(\major) or code(\minor)
763   to get major or minor keys, respectively. Omitting the second
764   argument gives major keys. The key of C-minor can thus be specified
765   as `code(\key es)' or `code(\key \c minor)'. 
766   
767 dit(code(\keysignature) var(pitchlist))
768
769 This command changes the current key signature.  Unlike the
770 `code(\key)' command, this command can produce arbitrary key
771 signatures, which can be useful for unconventional keys or modes.  The
772 key signature is given in the form of a list of notes.  The notes will
773 be printed in the key signature in the order that they appear on the
774 list.  For example, the key of C-minor can be specified as
775 `code(\keysignature bes es as)'.  The command `code(\keysignature fis
776 es bis)' provides a more exotic example.
777
778
779 dit(code(\time) var(numerator)code(/)var(denominator))
780   This command changes the current time signature.
781   The default value for this time signature is common time (4/4).
782
783 dit(code(\partial) var(duration))
784   This command allows you to make
785   upsteps at the start of a piece.
786   The var(duration) argument has the same form as the duration of a
787   note.
788
789 The `code(\partial)' command cannot be used to generate partial
790 measures in the middle of the music.  
791 Example:
792   mudela(fragment,verbatim)(
793     \time 4/4;
794     \partial 4;
795     [d'8 dis'] e' c''4 e'8 c''4 
796   )
797
798 dit(code(\grouping) var(durationslist)) sets the metric structure of the measure.
799     Its effect can best be shown by an example:
800     mudela(fragment,verbatim)(
801         \time 5/16;
802         \grouping 16*3 16*2;
803         [c'8 c'16 c'8]
804         \grouping 16*2 16*3;
805         [c'8 c'16 c'8]
806         \grouping 16*5 ;
807         [c'8 c'16 c'8]
808     )
809
810 In practice, you won't be needing this command very often: the
811 grouping is switched automatically when you issue a code(\time)
812 command.  It is set to a combination of groups
813 of 2 and 3 beats, with as many groups of
814 3 as possible (in other words: 4/4 is divided in two times two beats
815 (2+2), 8/8 in 3+3+2)
816 )
817
818 The commands described above aren't really music, but they can best be
819 thought as as notes with no duration.  Since they are grammatically
820 equivalent to notes, these commands can be used in the same places as
821 notes:
822
823 sect(Notation context)
824
825 COMMENT(This section is about translation contexts, a topic of LilyPond that
826 is somewhat advanced.  You don't have to understand this to use
827 LilyPond to print simple music.  If you don't want to typeset fancy
828 polyphonic music or tweak the LilyPond notation engine, you can skip
829 the next two sections.)
830
831 In bind(Section)ref(tutorial:more-staffs) it was explained that there
832 are more ways to notate a simple chord: as a single voice on a single
833 staff or in multiple staffs (and we'll soon see, that you can typeset
834 it as multiple voices on a staff).  Obviously the concept of staff is
835 not really something musical.  But what is it then?
836
837 The most simplistic explanation is: a staff is a graphic peculiarity
838 of the notation system.  In other words, a staff is a graphic device,
839 a special picture of five lines on which one can print note heads.  We
840 will call this view on the concept of staff `staff symbol' from now
841 on.
842
843 But 
844 there is more to a staff than just the symbol.  A staff
845 contains---besides a staff symbol--- some more components:
846 itemize(
847 it()A staff can have a key signature (printed at the left)
848 it()A staff can have a time signature (printed at the left)
849 it()A staff has bar lines
850 it()A staff has a clef (printed at the left)
851 ) COMMENT(
852
853 )
854 To explain what a staff really is, we'll try to print music without
855 these components.   Without those, it is still
856 possible to print music:
857 mudela()(\score{
858 \notes \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
859 \paper { 
860   linewidth = -1.;
861   \translator {
862   \StaffContext
863   \remove "Time_signature_engraver";
864   \remove "Bar_engraver";
865   \remove "Staff_symbol_engraver";
866   \remove "Clef_engraver";
867   \remove "Key_engraver";
868   }
869  }
870 })COMMENT(
871
872 ) As you can see, you can still make out the general form of the
873 melody and the rhythm that is to be played, but the notation is
874 difficult to read.  Moreover, the musical information is not complete.
875 The stress pattern in the notes can't be deduced from this output.
876 For this, we need a time signature:
877
878 mudela()(
879 \score {
880   \notes \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
881   \paper{
882   linewidth = -1.;
883 \translator{
884   \StaffContext
885   \remove "Bar_engraver";
886   \remove "Staff_symbol_engraver";
887   \remove "Clef_engraver";
888   \remove "Key_engraver";
889   }}
890  }) COMMENT(
891
892 )Technically speaking you know where the strong and weak beats are, but
893 it is difficult to find them quickly.   Bar lines  help you in finding
894 the location  of the notes within the measure:
895 mudela()(
896 \score {
897   \notes \relative c' {  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
898   \paper{
899   linewidth = -1.;
900 \translator{
901   \StaffContext
902   \remove "Staff_symbol_engraver";
903   \remove "Clef_engraver";
904   \remove "Key_engraver";}
905   }
906  }
907 )
908
909 We can remedy part of the difficulties with reading pitches by adding a staff
910 symbol:
911
912 mudela()(\score{
913   \notes\relative c' { \time 2/4; g'4 c,4
914 a'4 f4 e c d2 } \paper {
915   linewidth = -1.;
916   \translator {
917   \StaffContext
918
919   \remove "Clef_engraver";
920   \remove "Key_engraver";
921   }
922  }
923 })COMMENT(
924
925 )
926 This makes the output decidedly easier to read, but you still don't
927 know what the pitches of the notes above are.  So this is still not
928 enough.  But suppose you see the following notation:
929 mudela()(\score {
930   \notes \relative c' {\clef alto;  \time 2/4; g'4 c,4 a'4 f4 e c d2 }
931   \paper {
932     linewidth = -1.;
933   }
934 })COMMENT(
935
936 ) Now you know the pitch of the notes: you look at the start of the line
937 and see a clef, with this clef, you can determine the notated pitches.
938 You have found the em(context) in which the notation is to be
939 interpreted!
940
941 So the context determines the relationship between a piece of music
942 and its notation: you, the reader, use context to deduce music from
943 notation.  Because LilyPond is a notation writer instead of a reader,
944 context works the other way around for Lily: with context a piece of
945 music can be converted to notation.
946
947 We see that a staff forms context, and that context is needed to
948 convert between notation and music.  In LilyPond we turn around this
949 reasoning: LilyPond has a notion of notation context, and the staff is
950 just one example of a notation context.  In fact, the arguments of the
951 code(\type) command (Staff, GrandStaff) were all names of different
952 contexts.
953
954 We make one final observation before listing the standard notation
955 contexts.  A score can contain many staffs; A staff can contain many
956 voices.  This suggests that notation contexts are objects that can be
957 nested.
958
959 The following is a list of the contexts that are supported by
960 LilyPond.  Each notation context is characterised by its name, the
961 notation elements it creates, and the contexts that it can contain.
962 description(
963 dit(Voice) The code(Voice) context is a context that corresponds to a
964   voice on a staff.  This context handles the conversion of noteheads,
965   dynamic signs, stems, beams, super- and subscripts, slurs, ties and rests
966
967 dit(Staff) The code(Staff) context handles clefs, bar lines, keys,
968   accidentals.  A code(Staff) context can contain code(Voice)
969   contexts.
970
971 dit(RhythmicStaff) The code(RhythmicStaff) context is like the staff,
972   but much simpler: the notes are printed on one line, and pitches are
973   ignored.  code(RhythmicStaff) can contain code(Voice) contexts.
974
975 dit(GrandStaff) A code(GrandStaff) context contains code(Staff)
976   contexts, and it adds a brace to the output at the
977   nop(left.)footnote(This is a major deficiency in the current
978   implementation.  Currently stems, slurs and beams cannot be printed
979   across two staffs.  In reality, a grand staff is a hybrid of one big
980   staff and two stacked staffs.)
981   
982   A code(GrandStaff) context can contain 
983   code(Staff)s. Typically, it will contain two code(Staff)s, one
984   treble staff, and one bass staff. The bar lines of the contained
985   staffs are connected vertically.
986
987 dit(StaffGroup) A code(StaffGroup) context contains code(Staff) or
988   code(Lyrics) contexts, and prints a bracket at the left.  The bar
989   lines in the participating staffs are connected.
990
991 dit(Lyrics) As its name suggests, The code(Lyrics) context deals with
992   typesetting lyrics.  This topic will be covered in
993   bind(Section)ref(tutorial:lyrics).
994   
995 dit(Score) The code(Score) context is the toplevel context: no context can
996   contain a code(Score) context.  The code(Score) context handles the
997   administration of time signatures.  It also makes sure that items
998   such as clefs, time signatures, and key-signatures are aligned across staffs.
999   
1000   The code(Score) can contain code(Staff), code(StaffGroup),
1001   code(Lyrics), code(GrandStaff) and code(RhythmicStaff) contexts.
1002
1003 COMMENT(do ChoireStaff)
1004 )
1005
1006
1007 If you are familiar with structured documents, you might see the
1008 analogy of a context with a stylesheet: a stylesheet is neither
1009 presentation nor information, but rather a recipe em(how) a specific
1010 piece of information should be presented.  The big difference with
1011 stylesheets is that in music notation the elements provided by context
1012 are essential to understanding what is notated.
1013
1014 The notions of ``current clef'' and ``current position within the
1015 measure'' are all properties of notation contexts.  Commands like
1016 code(\clef) and code(\cadenza) change these properties, and this
1017 explains why they are fundamentally different from musical expressions
1018 like notes and rests.
1019
1020 A notation context is not a primitive element of LilyPond, but rather
1021   Later on, in bind(Section)ref(tutorial:engravers) we will explain
1022   how you can create your own contexts.
1023
1024
1025 sect(Nested music: multiple staffs)
1026 label(tutorial:more-staffs)
1027
1028 Now we explain how to typeset music that runs in multiple staffs.
1029 Consider the following---somewhat unrealistic---example:
1030
1031 mudela(fragment)(
1032  \type GrandStaff <e'4 {\clef bass; g4^""} >
1033 )
1034
1035 In this example the music consists of two notes.  The above would
1036 sound the same if it were written as a single chord on a single staff,
1037 i.e., COMMENT(
1038
1039 )mudela(fragment)(
1040         <g4 e'4>
1041 )COMMENT(
1042
1043 ) The Mudela construct for multiple staffs reflects the similarity
1044 between the two examples: to get multiple staffs in Mudela you enter a
1045 chord, with an additional instruction to tell LilyPond that the chord
1046 does not represent notes stacked together, but staffs stacked
1047 together.
1048
1049 If a piece of music is to be interpreted as a staff, then this can be
1050 expressed with the code(\type) construct.  The following input says
1051 ``the quarter note with pitch e should be put on a staff.''
1052
1053 verb(
1054   \type Staff e'4 
1055 )COMMENT(
1056
1057 ) The same can be done for the other note, i.e.,
1058
1059 verb(
1060   \type Staff g4 
1061 ) COMMENT(
1062
1063 ) If you want to stack these staffs, you must create a chord of both:
1064
1065 verb(
1066   < \type Staff e'4
1067     \type Staff g4 
1068   >
1069 )
1070
1071 This looks reasonable, but the effect of this input is not what you
1072 might expect:
1073 mudela(fragment)(
1074   < \type Staff e'4
1075     \type Staff g4 
1076   >
1077 )COMMENT(
1078
1079 ) Since there are no names specified for the desired staffs, LilyPond
1080 thinks your wishes are fullfilled by putting the code(g) on the same
1081 staff as the code(e).  The correct solution is to label both staffs
1082 with different names, for example code(trebleStaff) and
1083 code(bassStaff).  This makes LilyPond distinguish between them, and
1084 create two staffs:
1085
1086 mudela(verbatim,fragment)(
1087   < \type Staff = trebleStaff e'4
1088     \type Staff = bassStaff  g4 
1089   >
1090 )COMMENT(
1091
1092 ) The names that you choose do not matter just as long as they are
1093 different.  This is almost right, except for the brace at the left and
1094 the clef of the second staff.  If you want a brace, then you have to
1095 tell LilyPond that the chord you just formed is to be interpreted as a
1096 so-called grand staff.  This is also done with the code(\type)
1097 command.  The bass clef is made with a clef command:  COMMENT(
1098
1099 ) mudela(verbatim,fragment)(
1100   \type GrandStaff <
1101         \type Staff = treblestaff e'4
1102         \type Staff = bassstaff { \clef "bass"; g4 }
1103   >)COMMENT(
1104
1105 )
1106
1107 sect(Polyphonic music (or: Notation context properties))
1108 label(sec:polyphonic)
1109
1110 In the section on notation contexts we explained that a notation
1111 context can have properties that influence the conversion from music
1112 to notation.  A simple example of such a property is the clef: the
1113 type of a clef helps determines the vertical position of note heads in
1114 a staff.  Some of these properties can be modified by commands such as
1115 code(\clef) and code(\time).  But there is more: notation contexts
1116 also have properties are settable in a generic fashion.  We will
1117 demonstrate this feature by printing multiple voices on a staff.
1118
1119 Printing more than one voice on a staff, is not unlike printing
1120 multiple   staffs stacked together.  This suggests that  the template
1121 to follow  is this:
1122 verb(
1123   \type Staff <
1124     \type Voice = one  ...
1125     \type Voice = two  ...
1126   >
1127 ) COMMENT(
1128
1129 ) On the ellipsis there should be music going from left to right, in
1130 other words, notes enclosed in braces.  Let us try the following
1131 simple melodies:
1132
1133 mudela(fragment,verbatim)(
1134 \type "Staff" <
1135   \type "Voice" = "one" { r4 as'4 () as'4 g'4 }
1136   \type "Voice" = "two" { g'2 f'4 e'4 }
1137 >)
1138
1139 As you can see the result is not quite perfect.  The notes on the last
1140 two beats look like plain chords and not like separate voices.  What
1141 really happened was that the stems of the upper and lower voices were
1142 printed on top of each other.
1143
1144 To remedy this, engravers traditionally make the stems of the lower
1145 voice point down, and the stems of the upper up, as shown in
1146 bind(Figure)ref(tutorial:multi-voice-fig).
1147
1148 Surely the direction of a single stem is a property of the stem as a
1149 graphical object.  But the fact that all of the stems in a voice point
1150 in the same direction is not directly graphical.  Since this is a
1151 property shared by all the stems in the voice, this property is a
1152 property of the context code(Voice).  The context code(Voice) has an
1153 attribute whose value is the direction to use for stems.  You can
1154 change it to `up' by issuing the following phrase:
1155 verb(
1156   \property "Voice"."ydirection" = "1"
1157 )
1158
1159 This command should be read as ``change the property called
1160 code(ydirection) within the current code(Voice) context to the value
1161 code(-1).''  For the property code(ydirection) the value code(1) means
1162 `up', and code(-1) means `down'. So, the
1163 proper way to code the polyphonic example is given in
1164 bind(Figure)ref(tutorial:multi-voice-fig).
1165
1166 latexcommand(\begin{figure}[h])
1167 mudela(fragment,verbatim,center)(
1168   \type "Staff" <
1169     \type "Voice" =  "one"  {
1170       \property Voice.ydirection = "1"
1171       r4 as'4 () as'4 g'4 }
1172     \type "Voice" =  "two"  {
1173       \property Voice.ydirection = "-1"
1174       g'2 f'4 e'4 }
1175   >
1176 )
1177     latexcommand(\caption{multiple voices})
1178     label(tutorial:multi-voice-fig)
1179 latexcommand(\end{figure})
1180
1181 As you can see, this property also controls the directions of slurs,
1182 which explains the name code(ydirection).COMMENT(hmm)
1183
1184
1185 Other properties can also be set, and they can be within different
1186 contexts.  In general, you can set a property by specifying
1187 code(\property) var(contexttype)code(.)var(propertyname) code(=)
1188 var(value).  Both var(contexttype), var(propertyname) and var(value)
1189 should be strings.
1190
1191 The effect of a property is pretty much hardwired into the
1192 implementation (and thus subject to change), so we will not deal with
1193 all the possible properties in detail. Among other characteristics that
1194 can be set are the layout of slurs and beams.  The initialisation file
1195 file(property.ly) explains most properties.
1196
1197 sect(Lyrics)
1198 label(tutorial:lyrics)
1199
1200 Since a lyrics can have durations just like notes, we consider them to
1201 be music too.  Entering lyrics in mudela has two aspects. First, you
1202 have to enter the text, i.e., the syllables along with their
1203 durations.  After this, you have to specify how to convert these to
1204 graphics.
1205
1206 Lyrics consist of syllables, which are strings together with
1207 durations.  Previously we only entered note names, so for entering
1208 lyrics we have to instruct LilyPond that what we enter are not note
1209 names but strings.  This instruction is the keyword
1210 code(\lyrics).  After entering this keyword you can enter a musical
1211 construct---sequential music, simultaneous music, code(\type)
1212 entries, etc.--- but with syllables instead of pitches.  For example:
1213 COMMENT(
1214
1215 )verb(\lyrics { 'got8 me on my knees4, Le-8 lie! })COMMENT(
1216
1217 ) Next comes the conversion to notation.  LilyPond can't (yet) figure
1218 out that lyrics need different treatment than notes.  As a result, the
1219 default conversion will try to put the text you entered as note heads
1220 onto a staff, and this will fail.  This default must be overridden
1221 with a code(\type) keyword.  Printing syllables of text in a line is
1222 done by a context called code(Lyrics).  You can select this context
1223 with the code(\type) keyword.  Here is a simple example:
1224 COMMENT(
1225
1226 )mudela(fragment,verbatim)(
1227 \type Lyrics \lyrics { 'got8 me on my knees,4 Le-8 lie! })COMMENT(
1228
1229 )The result is technically correct, but it needs a melody to make it
1230 performable: COMMENT(
1231
1232 )mudela(fragment,verbatim)(
1233   <
1234     \type Staff  { c''8. c''16 bes'8. a'16 g'4 f'8 g'4. }
1235     \type Lyrics \lyrics { 'got8. me16 on8. my16 knees,4 Le-8 lie!4. }
1236   >
1237 ) COMMENT(
1238
1239 ) The strings that makes up each syllable in the lyrics block are
1240 passed along to TeX() verbatim, so if you are proficient with TeX()
1241 you can do various nifty things.  Just keep in mind that a syllable
1242 either starts with a letter (a character in the range `code(a)' to
1243 `code(z)' or `code(A)' to `code(Z)'), or it is a string enclosed
1244 quotes. It ends with either a number for the duration, or a space.
1245 These tricks are demonstrated in the following example:
1246 COMMENT( urg
1247 \type Lyrics \lyrics { 'got8 m\textbf{e}8 on8. m$\cal_Y$16 knees,4 Le-8 lie!4.}
1248 \type Lyrics \lyrics { 'got8 m{\bf e}4 on8. m$\cal_Y$16 knees,4 Le-8 lie!4.}
1249 )COMMENT(
1250
1251 )mudela(fragment,verbatim)(<
1252   \type Staff  { c''8. c''16 bes'8. a'16 g'4 f'8 g'4. }
1253   \type Lyrics \lyrics { 'got8 me8 on8. m$\cal_Y$16 "3s,"4 Le-8 lie!4.}
1254 >
1255 )COMMENT(
1256
1257
1258 )
1259 COMMENT(Groen is de kleur van geluk.)
1260 COMMENT(Dat geldt zeker voor Bj"ork)
1261
1262 sect(Toplevel Mudela)
1263
1264 Back in bind(Section)ref(sec:firsttune) we said we would defer
1265 discussion of toplevel constructions (e.g., code(\score)) to a later
1266 moment in time: and now we will look at these constructions.  In
1267 general, Mudela looks like set of nested `blocks'.  The general syntax
1268 for a block is code(\keyword { ... }).
1269
1270 We will now discuss identifiers.  Generally you can define an
1271 identifier by entering code(identifierName = ... ) where there can be
1272 a variety of things on the ellipsis.
1273 COMMENT(
1274 Here is a (partial) list of what you can abbreviate with identifiers
1275 at top-level.
1276 itemize(
1277 it()The code(\score) block
1278 it()The code(\paper) block
1279 it()The code(\midi) block (to be explained in
1280   bind(Section)ref(tutorial:sound))
1281 it()Music (sequential music, simultaneous music etc.)
1282 it()Durations
1283 it()Strings
1284 it()Translators (to be explained in bind(Section)ref(tutorial:engravers))
1285 it()Integers
1286 it()Reals  
1287 )
1288 )
1289
1290 When you refer
1291 to the abbreviated entity, you must precede code(identifierName)
1292 with a backslash, i.e., code(\identifierName).  For example:
1293 mudela(verbatim)(
1294   czerny = \notes { [c16 g e g] }
1295   \score {
1296     \notes \type GrandStaff <
1297       { c''2 g''2 }
1298       { \clef bass; \czerny \czerny \czerny \czerny}
1299     >
1300     \paper {
1301       linewidth = -1.0;
1302       stem_length = 6.0*\interline;
1303     }
1304   }
1305 )
1306
1307
1308 Another interesting feature of this example are the assignments within
1309 the paper block.  Some blocks, such as code(\paper), have a scope of
1310 their own.  In the case of the code(\paper) block, these variables
1311 influence the characteristics of the output.  As is shown, you can
1312 tune quantities like the stemlength, and enter simple
1313 nop(expressions.)footnote(The purpose of the negative linewidth is to
1314 prevent the music from being justified.)  The identifiers that are
1315 meaningful are for the paper block is strongly implementation
1316 dependent, so they will not be listed here.  Moreover, since most of
1317 the values are predefined to sensible defaults, there usually is no
1318 need to tune these values.
1319
1320 Recall the properties of a context, that could be set with
1321 code(\property).  It is a very general mechanism to tune the output of
1322 the music, that is neatly separated from the real music.
1323 Unfortunately, it is not convenient to type or read, and the precise
1324 effect of a setting property isn't always apparent from its
1325 definition.  To remedy this, we can use an identifier to capture the
1326 meaning of a code(\property).
1327
1328 mudela(verbatim)(
1329 stemup = \property Voice.ydirection = "1"
1330 stemdown = \property Voice.ydirection = "-1"
1331 shift = \property Voice.hshift = "1"
1332 \score {
1333   \type "Staff" \notes <
1334     \type "Voice" =  "one"  { \stemup r4 as'4 () as'4 g'4 }
1335     \type "Voice" =  "two"  { \stemup \shift g'2 f'4 e'4 }
1336     \type "Voice" = "three" { \stemdown [d'8 dis'] [d' cis'] [c' b] c'4 } >
1337   \paper{  linewidth = -1.0\pt; }
1338 })
1339
1340 Several abbreviations like code(\stemup) are defined in the standard
1341 initialisation file file(property.ly).  Setting or changing context
1342 properties can have a similar effect as the commands that were
1343 discussed in bind(Section)ref(sec:commands).  Don't be fooled by the
1344 similarity in appearance between a declared property-setting entry and
1345 a real command like code(\clef) or code(\bar).  Real commands are
1346 hardcoded into the language and they have to be terminated by
1347 semicolons.
1348
1349 You can also use identifiers to break up the heavy nesting that can
1350 occur in the code(\score) block.  Another useful application is
1351 parametrisation of the music: if you use identifiers in the
1352 code(\score) block, you can make variations of the music by simply
1353 redefining those identifiers.  One particular application of this is
1354 part extraction: by using identifiers and redefining them, one can
1355 print extracted parts and a full orchestral score from the same music
1356 definition.
1357
1358
1359 sect(Sound output)
1360 label(tutorial:sound)
1361
1362 You get output by combining music with definition a conversion to
1363 output.  LilyPond currently supports one other conversion besides
1364 notation: the conversion from abstract music to sound. You can have
1365 LilyPond play the music that you entered.  The format that is used for
1366 this output is MIDI.  The result is not very pretty, but it is useful
1367 for prooflistening your files: typing errors stand out when you
1368 listen, especially if they involve accidentals.
1369
1370 The only information that you need to enter is the
1371 tempo. (Unfortunately, at this time, this the only thing that can be
1372 tuned.  The syntax for the tempo is code(\tempo )var(duration) =
1373 var(beatsperminute);), for example: COMMENT(
1374
1375
1376 )verb(
1377 \score {
1378    ...music...
1379    \midi { \tempo 4 = 76; }
1380 }) COMMENT(
1381
1382 )
1383
1384 sect(Contexts revisited: engravers)
1385 label(tutorial:engravers)
1386
1387 As was promised, we will now take a dive into the more wizardrous parts
1388 of LilyPond: redefining (notation) contexts.  We previously explained
1389 that a context 
1390 itemize(
1391 it()has a name
1392 it()is a conversion from music to notation,
1393 it()can contain other contexts
1394 it()handles specific notation constructs
1395 )
1396
1397 This characterization almost automatically explains what the definition of a
1398 context should look like:
1399 itemize(
1400 it() It should have a name
1401 it()It should be part of the ``notation output definition,'' i.e., the
1402   code(\paper) block
1403 it()
1404   It should contain a specification of what other contexts may be contained
1405   in the context we're defining.
1406 it()
1407   It should contain a list of the notation constructs  to be
1408   handled.
1409 )
1410
1411 LilyPond can create notation for a large number of symbols.  This code
1412 is split up into basic building blocks. Each building block is called
1413 an em(engraver), and an engraver generally handles only one notation
1414 construct: the code(Clef_engraver) takes care of the clefs, the
1415 code(Time_signature_engraver) takes care of printing time signatures.
1416
1417 A notation context is formed by a group of engravers.  A special class
1418 in LilyPond---the code(Engraver_group_engraver)---allows engravers to
1419 cooperate in a group.  A variant of this grouping object is the
1420 code(Line_group_engraver_group), which puts the output of all the
1421 engravers (clefs, bars, etc) into a compound object, so that these
1422 symbols can be treated as a whole.
1423
1424 This explains the following definition, which is a simplified Staff context:
1425 verb(
1426 \translator
1427 {
1428         \type "Line_group_engraver_group";
1429         \name Staff ;
1430
1431         \consists "Bar_engraver";
1432         \consists "Clef_engraver";
1433         \consists "Key_engraver";
1434         \consists "Local_key_engraver";
1435         \consists "Time_signature_engraver";
1436         \consists "Staff_symbol_engraver";
1437
1438         defaultClef = treble;
1439           
1440         \accepts "Voice";
1441 }) COMMENT(
1442
1443 ) This context, named Staff, puts its graphic objects into a compound
1444 object (a so-called ``Line group'').  At Staff level, bars, clefs,
1445 keys, accidentals, time signatures and the staff symbol are handled.
1446 A staff can contain a Voice context.  You can also preset properties
1447 of contexts: for instance, the clef that is printed upon starting a
1448 Staff, is the treble clef.
1449
1450 You can also declare contexts, and reference them.  This is useful in
1451 combination with code(\remove "..."): code(\remove) does the opposite
1452 of code(\consists).
1453
1454 The real context definitions are in the standard initialisation
1455 file file(engraver.ly).
1456
1457 As a practical example, we will show how to typeset polymetric music,
1458 i.e., music where the meter can differ for each staff.  The solution
1459 is not very complicated: normally all timing information (time
1460 signature, rhythmic grouping) is synchronised across each staff.  This
1461 is done by having only one administration for timing information: in
1462 the default configuration there is only one code(Timing_engraver), in
1463 the code(Score) context.
1464
1465 All staffs use the information in the code(Timing_engraver) for
1466 generating bar lines and time signatures.  So, we can have different
1467 timing for every staff, by moving the code(Timing_engraver) into the
1468  Staff context.
1469
1470 mudela(verbatim)(
1471   \score {
1472    \notes <
1473      \type Staff = one { \time 2/4; c'4 c'4 c'4 c'4 c'4 c'4 }
1474      \type Staff = two { \time 3/4; c'4 c'4 c'4 c'4 c'4 c'4 }
1475    >
1476    \paper { 
1477      linewidth = -1.;
1478      \translator {
1479        \ScoreContext
1480        \remove "Timing_engraver";
1481      }
1482      \translator {
1483        \StaffContext
1484        \consists "Timing_engraver";
1485      }
1486   }
1487 }
1488 )
1489
1490
1491 sect(Urtexts and context selection)
1492 label(tutorial:urtext)
1493
1494 In bind(Section)ref(tutorial:more-staffs), we have shown you how to
1495 make multiple staffs, and explained that you have to label every staff
1496 (or more precisely: different contexts), to make sure that new ones
1497 are created when you need them.  In this section, the real power of
1498 this mechanism will be unveiled.
1499
1500 By naming other contexts that you create, you can reference other
1501 contexts than the current context from within the music.  For example,
1502 from within the music that you enter for staff code(One), one could
1503 enter a small piece of music, and send it to staff code(Two), e.g.,
1504 COMMENT(
1505
1506 ) mudela(fragment,verbatim)(
1507   <
1508     \type Staff = one { c''4 \type Staff = two { c4 c4 } c''4 }
1509     \type Staff = two { \clef bass; g,4 g,4 g,4 g,4  }    
1510   >
1511 )
1512
1513
1514
1515 The mechanism of context selection can be used to fabricate an
1516 nop(Urtext)footnote(em(Urtext) is the German word for `original text'.
1517 The Urtext edition of a piece of music, is an edition that reflects
1518 the original writing of the composer.  Such editions are useful for
1519 musicologists, and performers that want to perform authentic
1520 interpretations.  However, for mere mortals, the Urtext can be quite
1521 hard to read.  It might not contain fingering and beaming, and
1522 typically it is full of footnotes.  Moreover, common interpretations
1523 may have emerged---after the composer died.  For this reason, the
1524 music that can be had as Urtext usually is also available in enhanced
1525 and edited editions.  ) and an edited edition from em(one source).  We
1526 will use the first few bars of bind(J.)bind(S.)Bach's first Cello
1527 suite to demonstrate this.  The example makes heavy use of space
1528 rests; here they are used as a placeholder to attach articulation
1529 marks to.  
1530
1531 mudela(verbatim)(
1532   bach =  \notes \relative c { [g16 d' b' a] [b d, b' d,] }
1533   
1534   staffStuff = \notes { \clef bass; \time 4/4; s1 \bar "|."; }
1535   
1536   slursOne = \notes { s16( s s s s16 s s )s }
1537   slursTwo = \notes { s16-. s s() s s16() s  s ()s }
1538
1539   \score{
1540     { < \type Voice = celloVoice { \bach \bach }
1541         \type Voice = celloVoice { \slursOne \slursOne }
1542         \staffStuff
1543       >
1544       <
1545         \type Voice = celloVoice { \bach \bach }
1546         \type Voice = celloVoice { \slursTwo \slursTwo }
1547         \staffStuff
1548       >
1549     }
1550     \paper { linewidth = -1.;}
1551   }
1552 )
1553
1554 The slurs that you define should be put on the music that is defined
1555 by the code(\bach) identifier.  By labeling a code(Voice) context, and
1556 directing both the articulation and the notes to that same code(Voice)
1557 context, the articulation is put over the right notes.
1558
1559
1560 sect(Transposing)
1561 label(tutorial:more-grammar)
1562
1563
1564 One of the things that you can do with music is
1565 em(transposing) it.  If you want to transpose a piece of music, then
1566 you should prefix the keyword code(\transpose) along with the pitch
1567 (relative to the central C) for the transposition.footnote(the
1568 code(\type Staff) is to make sure that no separate staffs are created
1569 for the code(\scale) and code(\transpose cis' \scale) part.)
1570
1571
1572 mudela(verbatim)(
1573 scale = \notes \relative c' { [c8 d e f] }
1574 \score {
1575   \notes {
1576     \type Staff { \scale \transpose cis'  \scale }
1577     }
1578   \paper { linewidth = -1.0; }
1579 })
1580
1581
1582 sect(Staff switching)
1583
1584 We have seen that contexts can be nested.  This means that they form a
1585 tree.  It is possible to edit this tree: for example, a code(Voice)
1586 context can be taken out of a code(Staff) context, and put into
1587 another.  This has the effect of the voice switching staffs (something
1588 that often happens in keyboard music).  The syntax for this operation
1589 with these particular contexts is code(\translator Staff = newStaffName).
1590
1591 The effect is analogous to the first example in section
1592 ref(tutorial:urtext), but with the code(\translator) construction it
1593 is possible to split the real music and the commands that determine in
1594 which staff the music is printed.  For example:
1595
1596 mudela(verbatim)(
1597
1598 % real music
1599 aVoice = \type Voice = voiceA \notes { c''4 c4 c4 c''4 }
1600 bVoice = \type Voice = voiceB \notes { g,4 g,4 g,4 g,4  }    
1601
1602 % staff switching stuff
1603 switch = \type Voice = voiceA \notes { s4 \translator Staff = staffB s4
1604                    s4 \translator Staff = staffA s4 }
1605
1606 \score {
1607   <
1608     \type Staff = staffA < \aVoice \switch >
1609     \type Staff = staffB < \bVoice \clef bass; >
1610   >
1611   \paper { linewidth = -1.; }
1612 }
1613 )
1614
1615 Don't try to switch staffs when you are in the middle of a slur or
1616 beam, though: the spanners won't switch along.
1617
1618 sect(Hairy durations: triplets)
1619
1620 OUTDATED
1621
1622 In the previous section we explained an operation that changes the
1623 pitches of music, transposition.  In this section we will explain an
1624 operation that modifies the duration of the notes that you enter.
1625 When notes are part of a triplet, then the real of duration of the
1626 notes are 2/3 part of what their shape indicates:
1627 mudela(fragment)(
1628 \times 2/3 {  c'4 c'4 c'4 }
1629 )
1630
1631 To support this notion, Mudela allows you to modify the duration of a
1632 note by multiplication or division.  A code(c'4) note that would be in  a
1633 triplet is written as code(c'4*2/3).  If you sequence a few of these
1634 notes, you get a triplet.footnote(We added a normal staff in the example to
1635 show the difference.)
1636 mudela(fragment,verbatim)(
1637 <  \type Staff = staffA { \times 2/3 { c'8 c'8 c'8 } c'4}
1638    \type Staff = staffB { c''8 c''8 c''4 } >)
1639
1640 LilyPond knows that these notes are no normal eighth notes, but the
1641 reader doesn't yet.  To help the reader a beam or a bracket with a `3'
1642 should be printed.  The special beam command `code([2/3)' and the
1643 matching close beam `code(]1/1)' will take care of that, and
1644 they also abbreviate the code(*2/3) part.  If you want brackets in
1645 stead of beams, you can use `code(\[2/3])' and `code(\]1/1)'.
1646 mudela(fragment,verbatim)(
1647 < \type Staff = staffA {
1648     \times 2/3 { [ c'8 c'8 c'8 }
1649     \times 2/3 {  c'8 c'8 c'8 }
1650   }
1651   \type Staff = staffB { [c''8 c''8 c''8 c''8] }
1652 >)
1653
1654 Other tuplets  can be entered in the same way.
1655 mudela(fragment,verbatim)(
1656 < \type Staff = staffA {
1657     \time 7/8;
1658     \times 7/6 { [c'8 c'8 c'8 c'8 c'8 c'8] }
1659   }
1660   \type Staff = staffB {
1661     \time 7/8;
1662     [c''8 c''8 c''8 c''8 c''8 c''8 c''8] } >
1663 )
1664
1665 For your convenience, code([2/3) can be further abbreviated to code([/3), and
1666 you can abbreviate code(]1/1) on the closing beam marker to code(]/1).
1667
1668 mudela(fragment,verbatim)(
1669 < \type Staff = staffA {
1670     \times 2/3 { c'8 c'8 c'8 } c'4
1671   }
1672   \type Staff = staffB { [c''8 c''8] c''4 } >
1673 )
1674
1675
1676 bf(Important) the construct with code([/3) and
1677 code([/1) is a hack that sets a mode in the parser.  This means that
1678 verb(id = \notes { c8 c8 c8 }
1679 notATriplet =\notes { [2/3 \id ]1/1 })
1680 does not produce a triplet.  It will hopefully
1681 soon be replaced by a construction that mixes more elegantly with the
1682 grammar for Music.
1683
1684
1685
1686
1687
1688 sect(Titling)
1689 label(tutorial:titling)
1690
1691 A piece of sheet music isn't complete without proper opening and
1692 closing titles.  LilyPond does not have any real support for setting
1693 text: that is a job best left to TeX().  But you can pass messages to
1694 TeX() from the input file.   You can  write TeX() macros to handle
1695 these messages.
1696 To do this, you add a code(\header) block
1697 to your input file.  The format is quite simple,
1698
1699 verb(
1700 \header{
1701     "key" =  "value";
1702     "key" =  "value";
1703     "key" =  "value";
1704     % etc.
1705 })
1706
1707 When  the results of the music typesetting are output, the contents of
1708 code(\header) are also up into the TeX() file.  Tools like
1709 code(ly2dvi) can use this information to generate pretty titling for
1710 your input file. Consult the manual page of code(ly2dvi) for more
1711 details.
1712
1713
1714 The code(\header) block should be at toplevel in mudela, and
1715 preferably at the top of the file.  If you have an input file  with
1716 multiple code(\score) blocks, you should add a header to every score,
1717 describing the different sub parts of the music piece, eg.
1718
1719
1720 verb(\header {
1721         "composer" = "Ludwig Van Bavaria";
1722         "title" = "Symphonie Megalomane";
1723     }
1724     \score{
1725        ... % some music
1726        \header { movement = "Mit roher Kraft wild herausfahrend!"; }
1727       \paper { }
1728     }
1729     \score{
1730        ... % some more music
1731        \header { movement = "Saut\'e comme un oeuf."; }
1732       \paper { }
1733     }
1734 )
1735
1736 If you want you can also put the code(\header) block at the top of the
1737 input file; it will then be put into every output file automatically.
1738 This will make it clear what the file contains as soon as you open it.
1739
1740
1741