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