]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/tutorial.yo
release: 1.1.68
[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
26 htmlbodyopt(bgcolor)(white)
27 htmlcommand(<font color=black>)
28
29 latexlayoutcmds(
30     \topmargin -0.25in  
31     \textheight 53\baselineskip
32     \advance\textheight by \topskip
33     \marginparwidth 1 in        %   Width of marginal notes.
34     \oddsidemargin 0.25 in      %   Note that \oddsidemargin = \evensidemargin
35     \evensidemargin 0.25 in
36     \marginparwidth 0.75 in
37     \textwidth 5.875 in % Width of text line.
38     \input mudela-book
39 )
40
41 whenlatex(notableofcontents())
42 whentexinfo(notableofcontents())
43
44 article(Typesetting music with LilyPond)
45       (Han-Wen Nienhuys and Jan Nieuwenhuizen)
46       (nop()PIPETHROUGH(date "+%B %d, %Y")()()nop())
47
48
49 latexcommand(\def\interexample{})
50 latexcommand(\def\preexample{\par})
51 latexcommand(\def\postexample{\par\medskip})
52 latexcommand(\def\file#1{{code(#1)}})
53
54 whenhtml(
55 includefile(html-disclaimer.yo-urg)
56 )
57
58
59 sect(Introduction)
60 label(tutorial:introduction)
61 latexcommand(\parindent2pc)
62   
63 LilyPond prints music from a specification that you, the user, supply.
64 You have to give that specification using a em(language).  This
65 document is a gentle introduction to that language, which is called
66 Mudela, an abbreviation for Music Definition Language.
67
68 This tutorial will demonstrate how to use Mudela by presenting
69 examples of input along with resulting output.  We will use English
70 terms for notation, so if you are not familiar with those, you should
71 consult the glossary that is distributed with LilyPond.
72
73 The examples discussed are included in the distribution, in the
74 subdirectory file(input/tutorial/).  It is recommended that you
75 experiment  with input yourself, to get a feel for how LilyPond behaves.
76
77 sect(The first tune)
78 label(sec:firsttune)
79
80 To demonstrate what LilyPond input looks like, we start off with a
81 full fledged, yet simple example. It is a convoluted version
82 of the famous menuet in bind(J.)bind(S.)Bach's em(Klavierbuechlein).
83
84 mudela(verbatim)(% lines preceded by a percent are comments.
85 \include "paper16.ly"
86 \score {
87     \notes                      
88     \relative c'' {             
89             \key g;
90             \time 3/4;          
91
92         \repeat "volta" 2 {
93             d4 g,8 a b c d4 g, g |
94             e'4 c8 d e fis g4 g, g |
95             c4 d8()c b a( )b4 c8 b a g |
96             a4 [b8 a] [g fis] g2.  |
97         }
98
99         b'4 g8 a b g
100         a4 d,8 e fis d |
101         g4 e8 fis g d cis4 b8 cis a4 |
102         a8-. b-. cis-. d-. e-. fis-.
103         g4 fis e |
104         fis a,  r8 cis8
105         d2.-\fermata
106         \bar "|.";
107     }
108     \paper {
109        linewidth = 14.0 \cm; % standard settings are too wide for a book
110    }
111 })
112
113 Enter it (or copy it, the filename is file(menuet.ly)), and compile it
114 with LilyPond and view the output.  Details of this procedure may vary
115 from system to system.  To create the output, one would issue
116 code(ly2dvi menuet).  file(ly2dvi) is a program that does the job of
117 calling LilyPond and TeX() and adjusting page margins.
118
119 If all goes well, this will create the  file file(menuet.dvi).
120 To view this output, issue the command code(xdvi menuet).
121
122 Now that we are familiar with the procedure to produce output, we will
123 analyse the input itself, line by line.
124
125 verb(% lines preceded by a percent are comments.)COMMENT(
126
127 )The percent sign, `code(%)', introduces a line comment.  If you want to
128 make larger comments, you can use block comments. These are delimited
129 by `code(%{)' and `code(%})'COMMENT(
130
131 )verb(\input "paper16.ly")COMMENT(
132
133 )By default, LilyPond will use definitions for a staff of 20
134 nop(point)footnote(A point is the standard measure of length for
135 printing.  One point is 1/72.27 inch.)  high.  We want smaller output
136 (16 point staff height), you have to import the settings for that
137 size, which is done.COMMENT(
138
139 )verb(\score {) COMMENT(
140
141 ) A mudela file combines music with directions for outputting that
142 music.  The music is combined with the output directions by putting
143 them into a code(\score) block.
144 verb(
145    \notes               
146 ) COMMENT( 
147
148 )This makes LilyPond ready for accepting notes.
149 verb(
150     \relative c''
151 )COMMENT(
152
153 ) As we will see, pitches are combinations of octave, note name and
154 chromatic alteration.  In this scheme, the octave is indicated by
155 using raised quotes (`code(')') and ``lowered'' quotes (commas:
156 `code(,)').  The central C is denoted by code(c').  The C one octave
157 higher is code(c'').  One and two octaves below central C is denoted
158 by code(c) and code(c,) respectively.
159
160 For pitches in a long piece you might have to type many quotes.  To
161 remedy this, LilyPond has a ``relative'' octave entry mode.  In this
162 mode, octaves of notes without quotes are chosen such that a note is
163 as close as possible to the the preceding note.  If you add a
164 high-quote an extra octave is added.  The lowered quote (a comma) will
165 subtract an extra octave.  Because the first note has no predecessor,
166 you have to give the (absolute) pitch of the note to start with.
167 COMMENT(
168
169 )verb(
170        \sequential {
171 )COMMENT(
172
173 )  What follows is sequential music, i.e.,
174 notes that are to be played and printed after each other.
175 COMMENT(
176
177 )verb(
178         \time 3/4;
179 ) COMMENT(
180
181 ) This command changes the time signature of the current piece: a 3/4
182 sign is printed.  This commond is also used to generate bar lines
183 in the right spots.COMMENT(
184
185 )verb(
186         \key g;
187 ) COMMENT(
188
189 ) This command changes the current key to G-major.  Although this
190 command comes after the code(\time) command, in the output, the key
191 signature comes before the time signature: LilyPond knows about music
192 typesetting conventions. COMMENT(
193
194 )verb( \repeat "volta" 2  ) COMMENT(
195
196 ) This command tells LilyPond that the following piece of music must
197 be played twice; code("volta") volta brackets should be used for
198 alternatives---if there were any.
199 COMMENT(
200
201 )verb( { ) COMMENT(
202
203 )The subject of the repeat are again sequential notes.   Since
204 code(\sequential) is such a common construct, a abbreviation is
205 provided: just leave off code(\sequential), and the result is the
206 same. COMMENT(
207
208 )verb(d4) COMMENT(
209
210 ) This is a note with pitch code(d) (determined up to octaves).  The
211 relative music was started with a code(c''), so the real pitch of this
212 note is code(d'').  The code(4) designates the duration of the note
213 (it is a quarter note). COMMENT(
214
215 )verb(
216         a b
217 )COMMENT(
218
219 )These are notes with pitch code(a') and code(b').  Because their
220 duration is the same as the code(g), there is no need to enter the
221 duration (You may enter it anyway, eg. code(a4 b4)) COMMENT(
222
223 )verb(
224           d4 g, g |
225 ) COMMENT(
226
227 ) Three more notes.  The `code(|)' character is a `barcheck'.  When processing the
228 music, LilyPond will check  that barchecks are found at the start of
229 a measure.  This can help you track down errors.
230 COMMENT(
231
232 )verb(
233         e'4 
234 ) COMMENT(
235
236 ) So far, no notes were chromatically altered.  Here is the first one
237 that is: code(fis). Mudela by default uses Dutch note names, and
238 ``Fis'' is the Dutch note name for ``F sharp''.  However, there is no
239 sharp sign in the output. The program keeps track of key signatures,
240 and will only print accidentals if they are needed.
241 COMMENT(
242
243 )verb(c8 d e fis)COMMENT(
244
245 )LilyPond guesses were beams can be added to eighth and shorter notes.
246 In this case, a beam over 4 eighths is added.
247 COMMENT(
248
249 )verb(
250         c4 d8( )c b a( )b4 c8 b a g |
251 ) COMMENT(
252
253 ) The next line shows how to make a slur:
254 the beginning and ending note of the slur is marked with an opening and
255 closing parenthesis respectively.  In the line shown above this is
256 done for two slurs.  Slur markers (parentheses) are between
257 the notes.COMMENT( 
258 )verb(
259         a4 [b8 a] [g fis] 
260 )COMMENT(
261
262 )Automatic beaming can be overridden by inserting beam marks
263 (brackets).  Brackets are put around notes you want beamed.COMMENT(
264
265 )verb(g2.  |)COMMENT(
266
267 )A duration with augmentation dot  is notated
268 with the duration number followed by a period.COMMENT(
269 )verb(
270         }
271 ) COMMENT(
272
273 ) This ends the sequential music to be repeated.  LilyPond will typset
274 a repeat bar.  COMMENT(
275
276 )verb(
277      cis'4 b8 cis a4 |
278 ) COMMENT(
279
280 )This line shows that Lily will print an accidental if that is
281 needed: the first C sharp will be printed with an accidental, the
282 second one without.  COMMENT(
283
284 )verb( a8-. b-. cis-. d-. e-. fis-. )COMMENT(
285
286 )You can enter articulation signs either in a verbose or in an
287 abbreviated form.  Here we demonstrate the abbreviated form: it is
288 formed by a dash and the the character for the articulation to use,
289 e.g. code(-.) for staccato as shown above.  COMMENT(
290
291 )verb(
292         fis a,  r8 cis8
293 ) COMMENT(
294
295 )
296 Rests are denoted by the special notename code(r).  You can also enter
297 an invisible rest by using the special notename code(s).
298 verb(
299         d2.-\fermata
300 ) COMMENT(
301
302 )All articulations have a verbose form, like code(\fermata).  The
303 `command'  code(\fermata) is not part of the
304 core of the language (most of the other discussed elements are), but
305 it is an abbreviation of a more complicated description of a fermata.
306 code(\fermata) names that description and is therefore called an
307 em(identifier). COMMENT(
308
309 )verb( } ) COMMENT(
310
311 )
312 Here the music ends.
313 COMMENT(
314
315 )verb(\paper {
316             linewidth = 14.0\cm;
317 })COMMENT(
318
319 )This specifies a conversion from music to notation output.  Most of
320 the details of this conversions (font sizes, dimensions, etc.) have
321 been taken care of, but  to fit the output  in this document, it has
322 to be smaller.  We do this by setting the line width to 10 centimeters
323 (approximately 4 inches).
324 COMMENT(
325
326 )verb(
327         }
328 )COMMENT(
329
330 )The last brace ends the code(\score) block.
331
332 There are two things to note here. The format contains musical
333 concepts like pitches and durations, instead of symbols and positions:
334 the input format tries to capture the meaning of em(music), and not
335 notation.  Therefore Second, the format tries to be em(context-free):
336 a note will sound the same regardless of the current time signature,
337 the key, etc.
338
339 The purpose of LilyPond informally is explained by the term `music
340 typesetter'.  This is not a fully correct name: not only does the
341 program print musical symbols, it also makes esthetic decisions.  All
342 symbols and their placement is em(generated) from a high-level musical
343 description.  In other words,  LilyPond would be best
344 described by `music compiler' or `music to notation compiler'.
345
346
347 sect(Lyrics and chords)
348
349 In this section we show how to typeset a song of (unknown
350 origin).footnote(The author would welcome information about the origin
351 of this song.)
352
353 verb(\header {
354         title = "The river is flowing";
355         composer = "Traditonal (?)";
356 }
357 \include "paper16.ly"
358 melody = \notes \relative c' {
359         \partial 8;
360         g8 |
361         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
362         c4 c8 d [es () d] c4 | d4 es8 d c4.
363         \bar "|.";
364 }
365
366 text = \lyrics {
367         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
368         ri -- ver is flo -- wing down to the sea.
369 }
370
371 accompaniment =\chords {
372         r8
373         c2-3- f-3-.7 d-min es4 c8-min r8
374         c2-min f-min7 g-7^3.5 c-min }
375
376 \score {
377         \simultaneous {
378 %         \accompaniment
379           \context ChordNames \accompaniment
380
381           \addlyrics
382              \context Staff = mel
383              {  \property Staff.noAutoBeaming = "1"
384                 \property Staff.automaticMelismas = "1"
385                 \melody }
386              \context Lyrics \text
387         }
388         \midi  { }
389         \paper { linewidth = 10.0\cm; }
390 })
391
392
393 The result would look this.footnote(The titling and font size shown
394 may differ, since the titling in this document is not generated by
395 file(ly2dvi))
396
397 center(bf(The river is flowing)
398
399 var(Traditonal (?))
400 )
401
402 mudela()(\header {
403         title = "The river is flowing";
404         composer = "Traditonal (?)";
405 }
406 \include "paper16.ly"
407 melody = \notes \relative c' {
408         \partial 8;
409         g8 |
410         c4 c8 d [es () d] c4 | f4 f8 g [es() d] c g |
411         c4 c8 d [es () d] c4 | d4 es8 d c4.
412         \bar "|.";
413 }
414
415 text = \lyrics {
416         The ri -- ver is flo- __ wing, flo -- wing and gro -- wing, the
417         ri -- ver is flo -- wing down to the sea.
418 }
419
420 accompaniment =\chords {
421         r8
422         c2-3- f-3-.7 d-min es4 c8-min r8
423         c2-min f-min7 g-7^3.5 c-min }
424
425 \score {
426         \simultaneous {
427 %         \accompaniment
428           \context ChordNames \accompaniment
429
430           \addlyrics
431              \context Staff = mel
432              {  \property Staff.noAutoBeaming = "1"
433                 \property Staff.automaticMelismas = "1"
434                 \melody }
435              \context Lyrics \text
436         }
437         \midi  { }
438         \paper { linewidth = 10.0\cm; }
439 })
440
441 Again, we will dissect the file line by line.COMMENT(
442
443 )verb(\header {)COMMENT(
444
445 )Information about the music you are about to typeset goes into a
446 code(\header) block.  The information in this block is not used by
447 LilyPond, but it is included in the output.  file(ly2dvi) uses this
448 information to print titles above the music.
449 verb(
450         title = "The river is flowing";
451         composer = "Traditonal (?)";)COMMENT(
452
453 )the code(\header) contains block assignments.  An assignment starts
454 with a string.  (which is unquoted, in this case). Then comes the
455 equal sign `code(=)'.  After the equal sign comes the expression you
456 want to store.  In this case, you want to put in strings.  The
457 information have to be quoted, because they contain spaces. The
458 assignment is finished with a semicolon.COMMENT(
459
460 )code(\include "paper16.ly")COMMENT(
461
462 )Smaller size for inclusion in a book.COMMENT(
463
464 )verb(melody = \notes \relative c' {)COMMENT(
465
466 )The structure of the file will be the same as the previous one, a
467 code(\score) block with music in it.  To keep things readable, we will
468 give the different parts of music names, and use names to construct
469 music within the score block.
470
471 verb(\partial 8;)
472
473 The piece starts an anacrusis of one eighth.  COMMENT(
474
475 )verb(c4 c8 d [es () d] c4  | f4 f8 g [es() d] c g |
476 c4 c8 d [es () d] c4 | d4 es8 d c4.
477 \bar "|.";
478 )COMMENT(
479
480 )We use explicit beaming.  Since this is a song,  we turn automatic
481 beams off, and use explicit beaming where needed.COMMENT(
482
483 )verb(})COMMENT(
484
485 )This ends the definition of code(melody).  Note that there are no
486 semicolons after declarations at top level.COMMENT( 
487
488 )verb(text = \lyrics {)COMMENT(
489
490 )Another identifier assignment.  This one is for the lyrics. 
491 Lyrics are formed by syllables that have duration, and not by
492 notes. To make LilyPond parse words as syllables,  switch it  into
493 lyrics mode with code(\lyrics).   The brace after code(\lyrics) again
494 is an abbreviation of code(\sequential {). COMMENT(
495
496 )code(The4 ri -- ver is flo- __ wing,  flo -- wing and gro -- wing, the
497     ri- ver is flo- __ wing down to the sea.
498     })COMMENT(
499
500 )The syllables themselves.  They are separated by spaces.  You can get
501 syllable extenders by entering code(__), and centered hyphens with
502 code(--).  We enter the syllables as if they are all quarter notes in
503 length (hence the code(4)), and use a feature to align  the syllables
504 to the music, which isn't all quarter notes.
505 COMMENT(
506
507 )verb(
508 accompaniment =\chords {
509 )COMMENT(
510
511 )We'll put chords over the music.  There is a special mode (analogous
512 to code(\lyrics) and code(\notes) mode) where you can give the names
513 of the chords you want, in stead of the notes comprising the chord.
514 COMMENT(
515
516 )verb(r8)COMMENT(
517
518 )There is no accompaniment during the anacrusis.COMMENT(
519
520 )verb(c2-3- f-3-.7
521 )A chords is started by a note that is the tonic of the chord. The
522 first one lasts a half note.  An unadorned note creates a major
523 triad, while a minor triad is wanted.  code(3-) modifies the third to
524 be small. code(7) modifies (adds) a seventh, which is small by default
525 to create the code(f a c es) chord.   Multiple modifiers must be
526 separated by  a dot.
527 COMMENT(
528
529 )verb(d-min es4 c8-min r8)COMMENT(
530
531 )Some modifiers have predefined names, eg. code(min) is  the same as
532 code(3-), so code(d-min) is a minor code(d) chord.COMMENT(
533
534 )verb(c2-min f-min7 g-7^3.5 c-min })COMMENT(
535
536 )You may leave out the dot between a named modifier code(min) and a
537 normal modifier code(7).  Tones from a chord are removed with chord
538 substractions.  Substractions are started with a caret, and they are
539 also separated by dots.  In this example, code(g-7^3.5) produces a
540 minor seventh.  The brace ends the sequential music. COMMENT(
541
542 )verb(\score {
543         \simultaneous {)COMMENT(
544
545 )We put the music together in score block.  Melody, lyrics and
546 accompaniment have to sound at the same time, so they should be
547 code(\simultaneous).COMMENT(
548
549 )verb(  %         \accompaniment)COMMENT(
550
551 )Chords mode generates notes grouped in code(\simultaneous) music.  If
552 want to see the chords in normal notation, you can remove the comment
553 sign.  The chords are then printed on a staff with noteheads. COMMENT(
554
555 )verb(\context ChordNames \accompaniment)COMMENT(
556
557 )Normally, the notes that you enter are transformed into noteheads.
558 The note heads alone make no sense, they need surrounding information:
559 a key signature, a clef, staff lines, etc.  They need em(context).
560 This context also is a thing that has to be created. This is done by
561 code(\context). It takes two arguments. The first is the name of a
562 em(notation) or em(interpration context).  The name is a string, it
563 can be quoted with code(") quotes).  The second argument is the music
564 that should be interpreted in this context.
565
566 By default, LilyPond will create a Staff context for you.  If you
567 would remove the code(%) sign in the previous line, you see that
568 mechanism in action.  For the previous line, we could have written
569 code(\context Staff \accompaniment), and get the same effect.COMMENT(
570
571 )verb(\addlyrics)COMMENT(
572         
573 )The lyrics need to be aligned with the melody.  This is done by
574 combining both with code(\addlyrics).  code(\addlyrics) takes two
575 pieces of music (usually a melody and lyrics, in that order) and
576 aligns the lyrics syllables of the second piece under the notes of the
577 first piece.  If you would reverse the order, the notes would be
578 aligned on the lyrics, which is not very useful. (Besides, it looks
579 silly).COMMENT(
580
581 )verb(     \context Staff = mel {)COMMENT(
582
583 )This is first piece of music.  We instantiate a code(Staff) context
584 explicitly: should you chose to remove comment before the ``note
585 heads'' version of the accompaniment, the accompaniment will be on a
586 nameless staff.  In that case, the melody has to be on a different
587 staff as the accompaniment.  This is accomplished by giving the melody
588 staff a different name.COMMENT(
589
590 )verb({ \property Staff.noAutoBeaming = "1")COMMENT(
591
592 )An interpretation context has variables that tune its behavior.  One
593 of the variables is code(noAutoBeaming).  If set and non-zero (i.e.,
594 true) LilyPond will not try to automatic beaming on the current
595 staff.COMMENT(
596
597 )verb(  \property Staff.automaticMelismas = "1")COMMENT(
598
599 )Similarly, we want do not want to put a lyric syllable when there is
600 a slur. This sets up the Staff context to signal slurs while
601 code(\addlyrics) is processed. COMMENT(
602
603 )verb(          \melody })COMMENT(
604
605 )Finally, we put the melody on the current. Note that the
606 code(\property) directives and code(\melody) are grouped in sequential
607 music.  So the property settings are done before the melody is
608 processed.  COMMENT(
609
610 )verb(       \context Lyrics \text)COMMENT(
611
612 )The second argument of code(\addlyrics) is the text.   Text also
613 should  land on a  Staff, but on a context for syllables,
614 extenders, hyphens etc.  This context is called Lyrics.COMMENT(
615
616 )verb(  })COMMENT(
617
618 )This ends code(\simultaneous).COMMENT(
619
620 )verb(  \midi  { })COMMENT(
621
622 )This makes the music go to a MIDI file as well.  MIDI is great for
623 checking music you enter.  You listen to the MIDI file, if you hear
624 something weird, its probably a typing error. code(\midi) is a `output
625 definition', a declaration that specifies how to output music
626 analogous to code(\paper { }).COMMENT(
627
628 )verb(  \paper { linewidth = 10.0\cm; })COMMENT(
629
630 )We also want notation output.COMMENT(
631
632 )verb(})COMMENT(
633
634 )End the score block.