]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/introduction.itely
* GNUmakefile.in (local-WWW-post): move mutopia-index to toplevel
[lilypond.git] / Documentation / user / introduction.itely
1 @c -*-texinfo-*-
2
3
4 @node Introduction
5 @chapter Introduction
6
7 There are a lot of programs that let you print sheet music with a
8 computer. Unfortunately, most of them do not do good job.  Most
9 computer printouts have a bland, mechanical look, and are unpleasant
10 to play from.  If you agree with us on that, then you will like
11 LilyPond: we have tried to capture the original look of hand-engraved
12 music in a program: we have tuned our algorithms, font-designs, and
13 program settings to make the output match that of the old editions
14 that we love to see and love to play from.
15
16
17 @menu
18 * Music notation and  engraving::  
19 * Notation and engraving in LilyPond::  
20 * Typography and program architecture::  
21 * Music representation::        
22 * Example applications::        
23 * About this manual::           
24 @end menu
25
26 @node Music notation and  engraving
27 @section Music notation and engraving
28
29
30
31 @cindex engraving
32 @cindex typography
33
34 @c eerste zin beetje deur in huis
35 Making sheet music may seem trivial, ``you print 5 lines, and then put
36 in the notes at different heights'', but as you learn more of it, the
37 opposite turns out to be true. One has to master two difficult
38 tasks. First, one has to master music notation: the science of knowing
39 which symbols to use for what. Second, one has to master music
40 engraving: the art of placing symbols such that the result looks
41 pleasing.
42
43
44
45 @lilypondfile[notexidoc]{puer-fragment.ly}
46
47 @center A fragment of neume notation
48
49
50 Common music notation has its roots in the medieval time. In this
51 time, monks started to write down hints that indicated how their
52 sacred music was sung. These hints, neumes, gradually became simpler,
53 and at some point became the note heads.  Lines were added to the
54 neumes, to indicate a reference pitch, which later became the staff.
55 Over many centuries, improvements and extensions were added, while
56 other concepts disappeared. For example, the neume notation did not
57 have an explicit notion of rhythm, but it did have @emph{custodes},
58 symbols at the end of the line to indicate the starting pitch of the
59 next line.  Mensural notation, a notation where each note head takes a
60 fixed amount of time, came into being together with the rise of
61 counterpoint in the early renaissance.  The graphic language of
62 notation is still under development; the innovations of contemporary
63 music require still newer and more complex notations.
64
65
66
67 The term music engraving derives from the traditional process of music
68 printing.  Only a few decades ago, sheet music was made by cutting and
69 stamping the music into zinc or pewter plates, in mirror image. The plate
70 would be inked, and the depressions caused by the cutting and stamping
71 would hold ink.  An image was formed by pressing paper to the
72 plate. The stamping and cutting was completely done by hand. Making
73 corrections was cumbersome, so engraving had to be done correctly in
74 one go. Of course, this was a highly specialized skill, much more so
75 than the traditional process of printing books.
76 @cindex craftsmanship
77 @cindex master
78 In the traditional German system of craftsmanship six years of full-time
79 training, more than any other craft, were required before a student
80 could call himself a master of the art. After that many more years of
81 practical experience were needed to become an established music
82 engraver.  Even today, with the use of high-speed computers and
83 advanced software, music requires lots of manual fine tuning before it
84 is acceptable for publication.
85
86 Sheet music is performance material: everything is done to aid the
87 musician in letting him perform better.  Music often is far away from
88 its reader---it might be on a music stand. To make it clearly
89 readable, traditionally printed sheet music always uses bold symbols,
90 on heavy staff lines, and is printed on large sheets of paper.  This
91 ``strong'' look is also present in the horizontal spacing.  To
92 minimize the number of page breaks, (hand-engraved) sheet music is
93 spaced very tightly. Yet, by a careful distribution of white space,
94 the feeling of balance is retained, and a clutter of symbols is
95 avoided.
96
97
98 @node Notation and engraving in LilyPond
99 @section Notation and engraving in LilyPond
100
101 Common music notation encompasses such a wide scope of music, and
102 therefore inherently is complex: there are many rules, and for every
103 rule there are exceptional situations where they do not apply.  The
104 result is that LilyPond cannot support each and every form of notation
105 in existence. Rather, we focus on a specific style and idiom: we take
106 inspiration from late-romantic music printed at the beginning of the
107 20th century. Most of the contemporary music after that, and most of
108 the music going back to 17th century can be written in this
109 idiom. That is not a fundamental limit, though. There is support for
110 some modern notation like clusters, and older notation, such as white
111 mensural and gregorian notation, is being worked on.
112
113 We have used these observations in designing LilyPond.  The images
114 below show the flat symbol. On the left, a scan from a Henle edition,
115 which was made by a computer, and in the center is the flat from a
116 hand engraved B@"{a}renreiter edition of the same music. The left scan
117 illustrates typical flaws of computer print: the symbol is much
118 lighter, the staff lines are thinner, and the glyph has a straight
119 layout with sharp corners. By contrast, the B@"{a}renreiter has a bold
120 and almost voluptuous rounded look.  Our flat symbol is designed
121 after, among others, this one.  It is tuned it to harmonize with the
122 thickness of our staff lines, which are also much thicker than Henle's
123 lines.
124
125 @multitable @columnfractions  .1 .3 .3 .3
126 @item  @tab
127 @iftex
128 @image{henle-flat-bw,4cm}
129 @end iftex
130 @html
131 <img src=henle-flat-bw.png>
132 @end html
133
134 @tab
135 @iftex
136 @image{baer-flat-bw,4cm}
137 @end iftex
138 @html
139 <img  src=baer-flat-bw.png>
140 @end html
141
142 @tab
143 @iftex
144 @image{lily-flat-bw,4cm}
145 @end iftex
146 @html
147 <img src=lily-flat-bw.png>
148 @end html
149
150 @item
151 Henle (2000)
152 @tab
153 B@"{a}renreiter (1950)
154 @tab
155 LilyPond Feta font (2003)
156
157 @end multitable
158
159
160 @cindex musical symbols
161 @cindex font
162 @cindex blackness
163 @cindex balance
164
165 In spacing, the distribution of space should reflect the durations
166 between notes.  However, adhering with mathematical precision to the
167 duration will lead to a poor result. Shown here is an example of a
168 motive, printed twice. It is printed using exact mathematical spacing,
169 and with some corrections. Can you spot which fragment is which?
170
171 @cindex optical spacing
172 @lilypond[noindent]
173     \score { \notes {
174       \property Staff.NoteSpacing \set #'stem-spacing-correction
175         = #0.6
176       c'4 e''4 e'4 b'4 |
177        \stemDown b'4 e''4 a'4 e''4| \stemBoth
178        \bar "||"
179       \property Staff.NoteSpacing \override #'stem-spacing-correction
180       = #0.0
181       \property Staff.StaffSpacing \override #'stem-spacing-correction
182       = #0.0
183       c'4 e''4 e'4 b'4 |
184       \stemDown b'4 e''4 a'4 e''4|
185     }
186     \paper { raggedright = ##t } }
187 @end lilypond
188
189 @cindex regular rhythms
190 @cindex regular spacing
191
192 The fragment only uses quarter notes: notes that are played in a
193 constant rhythm. The spacing should reflect that. Unfortunately, the
194 eye deceives us a little: not only does it notice the distance between
195 note heads, it also takes into account the distance between
196 consecutive stems. As a result, the notes of an up-stem/down-stem
197 combination should be put farther apart, and the notes of a down-up
198 combination should be put closer together, all depending on the
199 combined vertical positions of the notes. The first two measures are
200 printed with this correction, the last two measures without. The notes
201 in the last two measures form down-stem/up-stems clumps of notes.
202
203 @node Typography and program architecture
204 @section Typography and program architecture
205
206 Producing good engraving requires skill and knowledge.  As the
207 previous examples show, there is a lot of subtlety involved in music
208 engraving, and unfortunately, only a small fraction of these details
209 are documented.  Master engraver must learn all these details from
210 experience or from other engravers, which is why it takes so long to
211 become a master.  As an engraver gets older and wiser, he will be able
212 to produce better and more complex pieces.  A similar situation is
213 present when putting typographical knowledge into a computer program.
214 It is not possible to come up with a definitive solution for a problem
215 at the first try. Instead, we start out with simple solution that
216 might cover 75% of the cases, and gradually refine that solution over
217 the course of months or years, so 90 or 95 % of the cases are
218 handled.
219
220 This has an important implication for the design of the program: at
221 any time, almost every piece of formatting code must be considered as
222 temporary. When the need arises, it is to be replaced a solution that
223 will cover even more cases.  is A ``plug-in'' architecture is a clean
224 way to accomplish this. This is an architecture where new pieces of
225 code can be inserted in the program dynamically.  In such a program, a
226 new solution can be developed along-side the existing code. For
227 testing, it is plugged in, but for production use, the old solution is
228 used. The new module can be perfected separately until it is better
229 than the existing solution, at which point it replaces the old one.
230
231 Until that time, users must have a way to deal with imperfections:
232 these 25%, 10% or 5% of the cases that are not handled
233 automatically. In these cases, a user must be able to override
234 formatting decisions. A way to accomplish this, is to store decisions
235 in generic variables, and let the user manipulate these variables.
236 For example, consider the following fragment of notation:
237
238 @lilypond
239 \score { \notes \relative c'' {
240 \stemUp
241     a4^\f f8
242         }
243 \paper { raggedright = ##t }
244      }
245 @end lilypond
246
247 @noindent
248 The position of the forte symbol is slightly awkward, because it is
249 next to the low note, whereas dynamics should be below notes in
250 general. This may be remedied by inserting extra space between the
251 high note and the `f', as shown in this example:
252
253 @lilypond
254 \score { \notes \relative c'' {
255 \stemUp
256     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
257     a4^\f f8
258         }
259 \paper { raggedright = ##t }
260      }
261 @end lilypond
262
263 This was achieved with the following input statement:
264 @example
265    \once \property Voice. DynamicLineSpanner  \override #'padding = #4.0 
266 @end example
267 It increases the amount of space (@code{padding}) between the note and
268 the dynamic symbol to 4.0 (which is measured in staff space, so 4.0
269 equals the height of a staff). The keyword @code{\once} indicates that
270 this is a tweak: it is only done one time.
271
272 Both design aspects, a plug-in architecture, and formatting variables,
273 are built on top of GUILE, an interpreter for the programming language
274 Scheme, which is a member of the LISP family. Variables are stored as
275 Scheme objects, and attached to graphical objects such as note heads
276 and stems. The variables are a means to adjust formatting details in
277 individual cases, but they are used in a more general manner.
278
279 Consider the case of a publisher that is not satisfied with the in the
280 default layout, and wants heavier stems. Normally, they are @code{1.3}
281 times the thickness of staff lines, but suppose that their editions
282 require them to be twice the thickness of the staff lines. The same
283 mechanism can be used to adjust a setting globally. By issuing the
284 following command, the entire piece is now formatted with thicker stems:
285 @example
286     \property Score.Stem \override #'thickness = #2.0 
287 @end example
288
289 @lilypond
290 \score { \notes \relative c'' {
291     \property Score.Stem \override #'thickness = #2.0 
292     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
293 \stemUp
294     a4^\f f8
295         }
296 \paper { raggedright = ##t }
297      }
298 @end lilypond
299
300 @noindent
301 In effect, by setting these variables, users can define their own
302 layout styles.
303
304 ``Plug-ins'' are also implemented using Scheme.  A formatting
305 ``plug-in'' takes the form of a function written in Scheme (or a C++
306 function made available as a Scheme function), and it is also stored
307 in a variable.  For example, the placement of the forte symbol in the
308 example above is calculated by the function
309 @code{Side_position_interface::aligned_side}.  If we want to replace
310 this function by a more advanced one, we could issue
311 @example
312     \property Voice.DynamicLineSpanner \override #'Y-offset-callbacks
313        = #`(,gee-whiz-gadget)
314 @end example
315
316 @noindent
317 Now, the formatting process will trigger a call to our new
318 @code{gee-whiz-gadget} function when the position of the f symbol has
319 to be determined.
320
321 The full scope of this functionality certainly is intimidating, but
322 there is no need to fear: normally, it is not necessary to define
323 style-sheets or rewrite formatting functions. In fact, LilyPond gets a
324 lot of formatting right automatically, so adjusting individual layout
325 situations is not needed  often at all.
326
327
328 @node Music representation
329 @section Music representation
330
331
332 Our premise is that LilyPond is a system that does music formatting
333 completely automatically. Under this assumption, the output does not
334 have to be touched up. Consequently, an interactive display of the
335 output, where it is possible to reposition notation elements, is
336 superfluous.  This implies that the program should be a batch program:
337 the input is entered in a file, which then is @emph{compiled}, i.e.
338 put through the program.  The final output is produced as a file ready
339 to view or print. The compiler fills in all the details of the
340 notation, those details should be left out of the input file. In other
341 words, the input should mirror the content as closely as possible. In
342 the case of music notation the content is the music itself, so that is
343 what the input should consist of.
344
345 On paper this theory sounds very good. In practice, it opens a can of
346 worms. What really @emph{is} music? Many philosophical treatises must
347 have been written on the subject.  Instead of losing ourselves in
348 philosophical arguments over the essence of music, we have reversed
349 the question to yield a more practical approach. Our assumption is
350 that the printed score contains all of the music of piece. We build a
351 program that uses some input format to produce such a score. Over the
352 course of time, the program evolves. While this happens, we can remove
353 more and more elements of the input format: as the program improves,
354 it can fill in irrelevant details of the input by itself. At some
355 (hypothetical) point, the program is finished: there is no possibility
356 to remove any more elements from the syntax.  What we have left is by
357 definition exactly the musical meaning of the score.
358
359 There are also more practical concerns.  Our users have to key in the
360 music into the file directly, so the input format should have a
361 friendly syntax: a quarter note C is entered as @code{c4}, the code
362 @code{r8.}  signifies a dotted eighth rest. Notes and rests form the
363 simplest musical expressions in the input syntax.  More complex
364 constructs are produced by combining them into compound
365 structures. This is done in much the same way that complex
366 mathematical formulas are built from simple expressions such as
367 numbers and operators.
368
369 In effect, the input format is a language, and the rules of that
370 language can be specified succinctly with a so-called context-free
371 grammar.  The grammar formally specificies what types of input form
372 valid `sentences'.  Reading such languages, and splitting them into
373 grammatical structures is a problem with standard solutions.
374 Moreover, they make the format easier to understand: a concise
375 formal definition permits a simple informal description.
376
377 The user-interface of LilyPond is its syntax.  That part is what users
378 see most.  As a results, some users think that music representation is
379 a very important or interesting problem. In reality, less than 10% of
380 the source code of the program handles reading and representing the
381 input, and they form the easy bits of the program.  In our opinion,
382 producing music notation, and formatting it prettily are much more
383 interesting and important than music representation: solving
384 these problems takes up most of the bulk of the code, and they are the
385 most difficult things to get right.
386
387 @node Example applications
388 @section Example applications
389
390 We have written LilyPond as an experiment of how to condense the art
391 of music engraving into a computer program. Thanks to all that hard
392 work, the program can now be used to perform useful tasks.  The
393 simplest application is printing notes:
394
395 @lilypond[relative=1]
396   \time 2/4 c4 c g'4 g a4 a g2  
397 @end lilypond
398
399 By adding chord names and lyrics we obtain a lead sheet:
400
401 @lilypond[raggedright]
402 \score { <
403   \context ChordNames \chords  { c2 c f2 c }
404   \notes \relative c' { \time 2/4 c4 c g'4 g a4 a g2 }
405   \context Lyrics \lyrics  { twin4 kle twin kle lit tle star2 } > }
406 @end lilypond
407
408 Polyphonic notation and piano music can also be printed. The following
409 example combines some more exotic constructs:
410
411 @lilypondfile{screech-boink.ly}
412
413 The fragments shown above have all been written by hand, but that is
414 not a requirement. Since the formatting engine is mostly automatic, it
415 can serve as an output means for other programs that manipulate
416 music. For example, it can also be used to convert databases of
417 musical fragments to images for use on websites and multimedia
418 presentations.
419
420 This manual also shows an application: the input format is plain text,
421 and can therefore be easily embedded in other text-based formats, such
422 as La@TeX{}, HTML or in the case of this manual, Texinfo.  By means of a
423 special program, the input fragments can be replaced by music images in
424 the resulting PostScript or HTML output files. This makes it easy to
425 mix music and text in documents.
426
427
428
429 @node About this manual
430 @section About this manual
431
432 The manual is divided into the following chapters:
433 @itemize @bullet
434 @item
435 @ifhtml The 
436 @end ifhtml
437 @emph{@ref{Tutorial}}
438 gives a  gentle introduction into typesetting music.
439 First time users should start here. 
440 @item
441 @ifhtml
442 The
443 @end ifhtml
444 @emph{@ref{Notation manual}}
445 discusses topics grouped by notation construct. Once you master the
446 basics, this is the place to lookup details.
447 @item
448 @ifhtml
449 The
450 @end ifhtml
451 @emph{@ref{Literature}}
452 chapter lists useful reference books on notation and engraving. 
453 @item
454 @ifhtml
455  The
456  @end ifhtml
457 @emph{@ref{Technical manual}}
458 @c
459 discusses the general design of the program, and how to extend its
460 functionality.
461 @item
462 @ifhtml
463 The chapter
464 @end ifhtml
465 @emph{@ref{Invoking LilyPond}}  explains how to run LilyPond and its helper
466 programs.
467 @end itemize
468
469 Once you are an experienced user, you can use the manual as reference:
470 there is an extensive index@footnote{If you are looking for something,
471 and you cannot find it by using the index, that is considered a bug.
472 In that case, please file a bug report.}, but the document is also
473 available in
474 @ifnothtml
475 a big HTML page,
476 @end ifnothtml 
477 @ifhtml
478 @uref{../lilypond.html, a big HTML page}
479 @end ifhtml
480 which can be searched easily using the search facility of a web
481 browser.
482 @cindex search in manual
483 @cindex using the manual
484
485
486 If you are not familiar with music notation, or music terminology
487 (especially if you are a non-native English speaker), then it is
488 advisable to consult the glossary as well. The glossary explains
489 musical terms, and includes translations to various languages. It is a
490 @ifhtml
491 @uref{../glossary.html,separate document}.
492 @end ifhtml
493 @ifnothtml
494 separate document, available in HTML and PDF.
495 @end ifnothtml
496 @cindex idiom
497 @cindex jargon
498 @cindex terminology
499 @cindex foreign languages
500 @cindex language
501
502
503 This manual is not complete without a number of other documents. They
504 are not available in print, but should be included with the
505 documentation package for your platform:
506
507 @itemize @bullet
508 @item
509 Program reference
510 @ifhtml
511 (available @uref{../lilypond-internals/lilypond-internals.html,here})
512 @end ifhtml
513
514 The program reference is a set of heavily crosslinked HTML pages,
515 which documents the nit-gritty details of each and every LilyPond
516 class, object and function.  It is produced directly from the
517 formatting definitions used.
518
519 Almost all formatting functionality that is used internally, is
520 available directly to the user. For example, all variables that
521 control thicknesses, distances, etc, can be changed in input
522 files. There are a huge number of formatting options, and all of them
523 are described in the generated documentation.  Each section of the
524 notation manual has a @b{See also} subsection, which refers to the
525 the generated documentation.  In the HTML document, these subsections
526 have clickable links.
527
528 @item
529   Templates
530 @ifhtml
531 (available @uref{../../../input/templates/out-www/collated-files.html,here})
532 @end ifhtml
533
534 After you have gone through the tutorial, in theory you should be able
535 to write input files. In practice, writing files from scratch turns
536 out to be intimidating.  To give you a headstart, we have collected a
537 number of often-used formats in example files.  These files can be
538 used as a start, by copying the template, and adding notes in the
539 appropriate places.
540
541 @item
542   Various input examples
543 @ifhtml
544 (available @uref{../../../input/test/out-www/collated-files.html,here})
545 @end ifhtml
546 @cindex snippets
547
548 These small files show various tips and tricks, and are available as a
549 big HTML document, with pictures and explanatory texts included.
550
551
552 @item
553   The regression test
554 @ifhtml
555 (available @uref{../../../input/regression/out-www/collated-files.html,here})
556 @end ifhtml
557
558 This collection of files tests each notation and engraving feature of
559 LilyPond in one file. The collection is primarily there to help us
560 debug problems, but it can be instructive to see how we excercise the
561 program. The format is like the tips and tricks document.
562
563 @end itemize
564
565
566 In all HTML documents that have music fragments embedded, the LilyPond
567 input that was used to produce that image can be viewed by clicking
568 the image.
569
570 The location of the documentation files that are mentioned here can
571 vary from system to system.  On occasion, this manual refers to
572 initialization and example files.  Throughout this manual, we refer to
573 input files relative to the top-directory of the source archive. For
574 example, @file{input/test/bla.ly} may refer to the file
575 @file{lilypond-1.7.19/input/test/bla.ly}.  On binary packages for the
576 Unix platform, the documentation and examples can typically be found
577 somewhere below @file{/usr/share/doc/lilypond/}. Initialization files,
578 for example @file{scm/lily.scm}, or @file{ly/engraver-init.ly}, are
579 usually found in the directory @file{/usr/share/lilypond/}.
580
581 @cindex adjusting output
582 @cindex variables
583 @cindex properties
584 @cindex lilypond-internals
585 @cindex internal documentation
586 @cindex Scheme
587 @cindex extending lilypond
588 @cindex bugreport
589 @cindex index
590
591 Finally, this and all other manuals, are available online both as PDF
592 files and HTML from the web site, which can be found at
593 @uref{http://www.lilypond.org/}.
594
595 @cindex website 
596 @cindex URL