* Documentation/index.texi (Top): cleanup.
[lilypond.git] / Documentation / user / introduction.itely
blob19616e85b23820bda4247a50afa949a7f5f3b637
1 @c -*-texinfo-*-
4 @node Introduction
5 @chapter Introduction
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, than 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.
17 @menu
18 * Music notation and  engraving::  
19 * Computerized typography::     
20 * Music representation::        
21 * Example applications::        
22 * About this manual::           
23 @end menu
25 @node Music notation and  engraving
26 @section Music notation and engraving
30 @cindex engraving
31 @cindex typography
33 Making sheet music may seem trivial, ``you print 5 lines, and then put
34 in the notes at different heights'', but as one learns more of it, the
35 opposite turns out to be true. There are two problems when making
36 sheet music. First, one has to master music notation: the science of
37 knowing which symbols to use when what. Second, one has to master
38 music engraving: the art of placing symbols such that they look
39 elegant.
41 Music notation was first started in the medieval centuries. In this
42 time, monks started to write down hints that indicated how their
43 sacred music was sung. These hints (neumes), gradually evolved, and at
44 some point became the note heads.  Lines were added to the neumes, to
45 indicate a reference pitch, which later became the staff.  Over many
46 centuries, improvements and extensions were added. For example, the
47 first notation did not have an explicit notion of rhythm, and
48 polyphonic music only came into existence in the XXX. The graphic
49 language of notation is still under development; the innovations of
50 contemporary music require still newer and more complex notations. A
51 system of notation encompasses such a wide scope of music inherently
52 is complex: there are many rules, and for every rule there are
53 exceptional situations where they do not apply.
55 The term music engraving derives from the traditional process of
56 music printing.  Only a few decades ago, sheet music was made by
57 cutting and stamping the music into zinc or pewter plates,
58 mirrored. The plate would be inked, and the depressions caused by the
59 cutting and stamping would hold ink.  An image was formed by pressing
60 paper to the plate. The stamping and cutting was completely done by
61 hand. Making corrections was cumbersome, so engraving had to be done
62 correctly in one go. As you can imagine this was a highly specialized
63 skill, much more so than the traditional process of printing books.
64 @cindex craftsmanship
65 @cindex master
66 In the traditional German craftsmanship six years of full-time
67 training, more than any other craft, were required before a student
68 could call himself a master of the art. After that many more years of
69 practical experience were needed to become an established music
70 engraver.  Even today, with the use of high-speed computers and
71 advanced software, music requires lots of manual fine tuning before it
72 is acceptable for publication.
74 Sheet music is performance material, hence everything is done to aid
75 the musician in letting him perform better.  Music often is far away
76 from its reader---it might be on a music stand. To make it clearly
77 readable, traditionally printed sheet music always uses bold symbols,
78 on heavy staff lines, and is printed on large sheets of paper.  This
79 ``strong'' look is also present in the horizontal spacing.  To
80 minimize the number of page breaks, (hand-engraved) sheet music is
81 spaced very tightly. Yet, by a careful distribution of white space,
82 the feeling of balance is retained, and clutters of black are avoided.
84 We have used these observations in designing LilyPond.  The images
85 below shows the flat symbol. On the left, a scan from a Henle edition,
86 which was made by a computer, and in the center is the flat from a
87 B@"{a}renreiter edition of the same music. The symbols have noticeable
88 differences: the left image is much lighter, the staff lines are
89 thinner, and the glyph has straight layout with sharp corners. We have
90 designed our flat symbol after this one, among others, and have tuned
91 it to harmonize with the thickness of our staff lines.
93 @iftex
94 @multitable @columnfractions  .4 .3 .3
95 @item 
96 @image{henle-flat-bw,4cm}
97 @tab
98 @image{baer-flat-bw,4cm}
99 @tab
100 @image{lily-flat-bw,4cm}
101 @end multitable
102 @end iftex
105 @ifhtml
106 @html
108 <a href=henle-flat-bw.png>
109 <img src=henle-flat-bw.png>
110 </a>
112 <a href=baer-flat-bw.png><img width=300 src=baer-flat-bw.png></a>
114 <a src=lily-flat-bw.png>
115 <img src=lily-flat-bw.png>
116 <a/>
117 @end html
118 @end ifhtml
120 @cindex musical symbols
121 @cindex font
122 @cindex blackness
123 @cindex balance
125 In spacing, the distribution of space should reflect the durations
126 between notes.  However, adhering with mathematical precision to the
127 duration will lead to a poor result. Shown here is an example of a
128 motive, printed twice. It is printed using exact mathematical spacing,
129 and with some corrections. Can you spot which fragment is which?
131 @cindex optical spacing
132 @lilypond[noindent]
133     \score { \notes {
134       \property Staff.NoteSpacing \set #'stem-spacing-correction
135         = #0.6
136       c'4 e''4 e'4 b'4 |
137        \stemDown b'4 e''4 a'4 e''4| \stemBoth
138        \bar "||"
139       \property Staff.NoteSpacing \override #'stem-spacing-correction
140       = #0.0
141       \property Staff.StaffSpacing \override #'stem-spacing-correction
142       = #0.0
143       c'4 e''4 e'4 b'4 |
144       \stemDown b'4 e''4 a'4 e''4|
145     }
146     \paper { raggedright = ##t } }
147 @end lilypond
149 @cindex regular rhythms
150 @cindex regular spacing
152 The fragment that was printed uses only quarter notes: notes that are
153 played in a constant rhythm. The spacing should reflect
154 that. Unfortunately, the eye deceives us a little: the eye not only
155 notices the distance between note heads, but also between consecutive
156 stems. As a result, the notes of an up-stem/down-stem combination
157 should be put farther apart, and the notes of a down-up combination
158 should be put closer together, all depending on the combined vertical
159 positions of the notes. The first two measures are printed with this
160 correction, the last two measures without. The notes in the last two
161 measures form down-stem/up-stems clumps of notes.
163 @node Computerized typography
164 @section Computerized typography
166 Producing good engraving requires skill and knowledge.  It was our
167 challenge to see if we could put such typographical knowledge into a
168 computer program. Capturing that knowledge has two aspects: first, it
169 has to be acquired. Then, it has to be encoded in data-structures and
170 algorithms.  As the previous examples show, there is a lot of subtlety
171 involved in music engraving, and unfortunately, only a small fraction
172 of these details are documented.
174 One reason for the time that it takes to become a master engraver, is
175 that all these details must be learned either from experience or from
176 other engravers: as an engraver gets older and wiser, he will be able
177 to produce better and more complex pieces.  A similar situation is
178 present when putting typography into computer programs.  It is not
179 possible to come up with a final solution for a problem at the first
180 try. Instead, we start out with simple solution that might cover 75%
181 of the cases, and gradually refine that solution over the course of
182 months or years, so that 90 or 95 % of the cases are handled.
184 This has an important implication for the design of the
185 program. During development, almost every piece of formatting code
186 must be considered as temporary. When the need arises, is to be
187 replaced a solution that will cover even more cases.  A clean way to
188 accomplish this, is a ``plug-in'' architecture: an architecture where
189 new pieces of code can be inserted in the program dynamically.  In
190 such a program, a new solution can be developed along-side the
191 existing code. It can be perfected separately until it is better than
192 the existing solution, at which point, the new solution is switched on
193 by default, and the old one is removed.
195 Until that time, users must have a way to deal with imperfections:
196 these 25%, 10% or 5% of the cases that are not handled
197 automatically. In these cases, a user must be able to override
198 formatting decisions. A way to accomplish this, is to store decisions
199 in generic variables, and let the user manipulate these variables.
200 For example, consider the following fragment of notation.
202 @lilypond
203 \score { \notes {
204     g'4-\f g4
205         }
206 \paper { raggedright = ##t }
207      }
208 @end lilypond
210 @noindent
211 The position of the forte symbol is slightly awkward, because it is
212 next to the low note, whereas dynamics should be below notes in
213 general. This may be remedied by inserting extra space between the
214 high note and the `f', as shown in this example
216 @lilypond
217 \score { \notes {
218     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
219     g'4-\f g4
220         }
221 \paper { raggedright = ##t }
222      }
223 @end lilypond
225 This was achieved with the input statement
226 @example
227     \property Voice. DynamicLineSpanner  \override #'padding = #4.0 
228 @end example
229 which increases the amount of space (@code{padding}) between the note
230 and the dynamic symbol to 4.0 (which is measured in staff space, so
231 4.0 equals the height of a staff).
233 Both design aspects, a plug-in architecture, and formatting variables,
234 are built on top of GUILE, an interpreter for the programming language
235 Scheme, which is a member of the LISP family. Variables are stored as
236 Scheme objects, and attached to graphical objects such as note heads
237 and stems. The variables are a means to adjust formatting details in
238 individual cases, but they are used in a more general manner.
240 Consider the case of a publisher that is not satisfied with the in the
241 default layout, and wants heavier stems. Normally, they are @code{1.3}
242 times the thickness of staff lines, but suppose that their editions
243 require them to be twice the thickness of the staff lines. The same
244 mechanism can be used to adjust a setting globally. By issuing
245 @example
246     \property Score.Stem \override #'thickness = #2.0 
247 @end example
248 the entire piece is formatted with thick stems:
249 @lilypond
250 \score { \notes {
251     \property Score.Stem \override #'thickness = #2.0 
252     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
253     g'4-\f g4
254         }
255 \paper { raggedright = ##t }
256      }
257 @end lilypond
259 @noindent
260 In effect, by setting these variables, users can define their own
261 layout styles.
263 ``Plug-ins'' are also implemented using Scheme.  A formatting
264 ``plug-in'' takes the form of a function written in Scheme (or a C++
265 function made available as a Scheme function), and it is also stored
266 in a variable.  For example, the placement of the forte symbol in the
267 example above is calculated by the function
268 @code{Side_position_interface::aligned_side}.  If we want to replace
269 this function by a more advanced one, we could issue
270 @example
271     \property Voice.DynamicLineSpanner \override #'Y-offset-callbacks
272        = #`(,gee-whiz-gadget)
273 @end example
275 @noindent
276 Now, the formatting process will trigger a call to our new
277 @code{gee-whiz-gadget} function when the position of the f symbol has
278 to be determined.
280 The full scope of this functionality certainly is intimidating, but
281 there is no need to fear: normally, it is not necessary to define
282 style-sheets or rewrite formatting functions. In fact, LilyPond gets a
283 lot of formatting right automatically, so adjusting individual layout
284 situations is not needed very often at all.
287 @node Music representation
288 @section Music representation
291 One of the big questions when writing batch programs, is what kind of
292 input the program should expect. Many music notation programs offer a
293 graphical interface that shows notation, and allow you to enter the
294 music by placing notes on a staff. From our point of view, this design
295 is a form of cheating. After all, the core message of a piece of music
296 notation simply is the music itself. If you start by offering notation
297 to the user, you have already skipped one conversion, even if it is
298 implicit. If we want to generate music notation from something else,
299 then the obvious candidate for the source is the music itself.
301 On paper this theory sounds very good. In practice, it opens a can of
302 worms. What really @emph{is} music? Many philosophical treatises must
303 have been written on the subject.  Instead of losing ourselves in
304 philosophical arguments over the essence of music, we have reversed
305 the question to yield a more practical approach. Our assumption is
306 that the printed score contains all of the music of piece. We build a
307 program that uses some input format to produce such a score. Over the
308 course of time, the program evolves. While this happens, we can remove
309 more and more elements of the input format: as the program improves,
310 it can fill in irrelevant details of the input by itself. At some
311 (hypothetical) point, the program is finished: there is no possibility
312 to remove any more elements from the syntax.  What we have left is by
313 definition exactly the musical meaning of the score.
315 There are also more practical concerns.  Our users have to key in the
316 music into the file directly, so the input format should have a
317 friendly syntax: a quarter note C is entered as @code{c4}, the code
318 @code{r8.}  signifies a dotted eighth rest.
320 As programmers and scientists, we want a clean formal
321 definition. After all, producing music notation is a difficult
322 problem, and problems can only be solved if they are
323 well-specified. Moreover, formally defined formats are easier to write
324 programs for.  We have chosen for a format that is based on music
325 expressions: complex musical constructs are built from simple entities
326 like notes and rests in much the same way that complex formulas are
327 built from simple expressions such as numbers and mathematical
328 operators.  The language is described by a context-free
329 grammar. Reading such languages robustly is a well studied problem,
330 and we use a standard solution to do it.
332 LilyPond is a batch program, so the syntax of the program is its
333 user-interface.  It is the part that they see most, so it is easy to
334 think that music representation is a very important or interesting
335 problem. In reality, less than 10% of the source code of the program
336 handles reading the input and representation, and they form the easy
337 bits of the program. Converting the music to notation, and calculating
338 a pretty layout is much more difficult.
340 @node Example applications
341 @section Example applications
343 We have written LilyPond as an experiment of how to condense the art
344 of music engraving into a computer program. Thanks to all that hard
345 work, the program can be used to perform useful tasks.  The simplest
346 application is printing notes.
348 @lilypond[relative=1]
349   \time 2/4 c4 c g'4 g a4 a g2  
350 @end lilypond
352 By adding chord names and lyrics we obtain a lead sheet:
353 @lilypond[raggedright]
354 \score { <
355   \context ChordNames \chords  { c2 c f2 c }
356   \notes \relative c' { \time 2/4 c4 c g'4 g a4 a g2 }
357   \context Lyrics \lyrics  { twin4 kle twin kle lit tle star2 } > }
358 @end lilypond
360 Polyphonic notation and piano music can also be printed. The following
361 example combines some more exotic constructs.
363 @lilypondfile{screech-boink.ly}
365 The fragments shown above have all been written by hand, but that is not
366 a requirement. Since the formatting engine is mostly automatic, it can
367 serve as an output means for other programs that manipulate music. It
368 can also be used to convert databases of musical fragments to images for
369 use on websites on multimedia presentations.
371 This manual also shows an application: the input format is plain text,
372 and can therefore be easily embedded in other text-based formats, such
373 as La@TeX{}, HTML or in the case of this manual, Texinfo.  By means of a
374 special program, the input fragments can be replaced by music images in
375 the resulting PostScript or HTML output files. This makes it easy to
376 mix music and text in documents.
380 @node About this manual
381 @section About this manual
383 The manual is divided into the following chapters
384 @itemize @bullet
385 @item
386 @ifhtml The 
387 @end ifhtml
388 @emph{@ref{Tutorial}}
389 gives a  gentle introduction into typesetting music.
390 First time users should start here. 
391 @item
392 @ifhtml
394 @end ifhtml
395 @emph{@ref{Notation manual}}
396 discusses topics grouped by notation construct.
397 @item
398 @ifhtml
399  The
400  @end ifhtml
401 @emph{@ref{Technical manual}}
403 discusses the general design of the program, and how to extend its
404 functionality.
405 @item
406 @ifhtml
407 The chapter
408 @end ifhtml
409 @emph{@ref{Invoking LilyPond}}  explains how to run LilyPond and its helper
410 programs.
411 @end itemize
413 Once you are an experienced user, you can use the manual as reference:
414 there is an extensive index@footnote{If you are looking for something,
415 and you cannot find it by using the index, that is considered a bug.
416 In that case, please file a bug report.}, but the document is also
417 available in
418 @ifnothtml
419 a big HTML page,
420 @end ifnothtml 
421 @ifhtml
422 @uref{../lilypond.html, a big HTML page}
423 @end ifhtml
424 which can be searched easily using the search facility of a web
425 browser.
426 @cindex search in manual
427 @cindex using the manual
429 @c  TODO: advise to buy a book on notation? 
431 If you are not familiar with music notation, or music terminology
432 (especially if you are a foreigner), then it is advisable to consult
433 the glossary as well. The glossary explains musical terms, and
434 includes translations to various languages. It is a
435 @ifhtml
436 @uref{../glossary.html,separate document}
437 @end ifhtml
438 @ifnothtml
439 separate document, available in HTML and PDF and can be printed as
440 well.
441 @end ifnothtml
442 @cindex idiom
443 @cindex jargon
444 @cindex terminology
445 @cindex foreign languages
446 @cindex language
449 This manual is not complete without a number of other documents. They
450 are not available in print, but should be included with the
451 documentation package for your platform
453 @itemize @bullet
454 @item
455 Generated internal documentation.
456 @ifhtml
457 available @uref{../lilypond-internals/lilypond-internals.html,here}
458 @end ifhtml
460 The generated internal documentation is a heavily crosslinked HTML
461 document, produced directly from the formatting definitions used.  It
462 documents the nit-gritty details of each and every LilyPond class,
463 object and function.
465 Almost all formatting functionality that is used internally, is
466 available directly to the user. For example, all variables that
467 control thicknesses, distances, etc, can be changed in input
468 files. There are a huge number of formatting options, and all of them
469 are described in the generated documentation.  Each section of the
470 reference manual has a @b{See also} subsection, which refers to the
471 the generated documentation.  In the HTML document, these subsections
472 have clickable links.
474 @item
475   Templates
476 @ifhtml
477 (available @uref{../../../input/templates/out-www/collated-files.html,here})
478 @end ifhtml
480 After you have gone through the tutorial, in theory you should be able
481 to write input files. In practice, writing files from scratch turns
482 out to be intimidating.  To give a headstart, we have collected a
483 number of often-used formats in example files.  These files can be
484 used as a start, by copying the template, and adding notes in the
485 appropriate places.
487 @item
488   Various input examples
489 @ifhtml
490 available @uref{../../../input/test/out-www/collated-files.html,here}
491 @end ifhtml
492 @cindex snippets
494 These small files show various tips and tricks, and are available as a
495 big HTML document, with pictures and explanatory texts included.
498 @item
499   The regression test
500 @ifhtml
501 available @uref{../../../input/regression/out-www/collated-files.html,here}
502 @end ifhtml
504 We strive to test each feature in one test file. This collection is
505 primarilyt there to help us debug problems, but it can be instructive
506 to see how we excercise the program. The format is like the tips and
507 tricks document.
509 @end itemize
512 The location of the documentation files that are mentioned here can
513 vary from system to system.  On occasion, this manual refers to
514 initialization and example files.  Throughout this manual, we refer to
515 input files relative to the top-directory of the source archive. For
516 example, @file{input/test/bla.ly} may refer to the file
517 @file{lilypond-1.7.19/input/test/bla.ly}.  On binary packages for the
518 Unix platform, the documentation and examples can typically be found
519 somewhere below @file{/usr/share/doc/lilypond/}. Initialization files,
520 for example @file{scm/lily.scm}, or @file{ly/engraver-init.ly}, are
521 usually found in the directory @file{/usr/share/lilypond/}.
523 @cindex adjusting output
524 @cindex variables
525 @cindex properties
526 @cindex lilypond-internals
527 @cindex internal documentation
528 @cindex Scheme
529 @cindex extending lilypond
530 @cindex bugreport
531 @cindex index
533 Finally, this and all other manuals, are available online both as PDF
534 files and HTML from the web site, which can be found at
535 @uref{http://www.lilypond.org/}.
537 @cindex website 
538 @cindex URL