]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/introduction.itely
(Introduction): rewrite
[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, 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.
15
16
17 @menu
18 * Music notation and  engraving::  
19 * Computerized typography::     
20 * Music representation::        
21 * Example applications::        
22 * About this manual::           
23 @end menu
24
25 @node Music notation and  engraving
26 @section Music notation and engraving
27
28
29
30 @cindex engraving
31 @cindex typography
32
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.
40
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.
54
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.
73
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.
83
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. By
90 contrast, the B@"{a}renreiter has a bold and almost voluptuous rounded
91 look.  Our flat symbol is designed after, among others, this one.  It
92 is tuned it to harmonize with the thickness of our staff lines, which
93 are also much thicker than Henle's lines.
94
95 @multitable @columnfractions  .4 .3 .3
96 @item 
97 @iftex
98 @image{henle-flat-bw,4cm}
99 @end iftex
100 @html
101 <p>
102 <a href=henle-flat-bw.png>
103 <img src=henle-flat-bw.png>
104 </a>
105
106 @end html
107
108 @tab
109 @iftex
110 @image{baer-flat-bw,4cm}
111 @end iftex
112 @html
113 <a href=baer-flat-bw.png>
114 <img  src=baer-flat-bw.png></a>
115 @end html
116
117 @tab
118 @iftex
119 @image{lily-flat-bw,4cm}
120 @end iftex
121 @html
122 <a href="lily-flat-bw.png">
123 <img src=lily-flat-bw.png>
124 </a>
125 @end html
126
127 @item
128 Henle (2000)
129 @tab
130 B@"{a}renreiter (1950)
131 @tab
132 LilyPond Feta font (2003)
133
134 @end multitable
135
136
137 @cindex musical symbols
138 @cindex font
139 @cindex blackness
140 @cindex balance
141
142 In spacing, the distribution of space should reflect the durations
143 between notes.  However, adhering with mathematical precision to the
144 duration will lead to a poor result. Shown here is an example of a
145 motive, printed twice. It is printed using exact mathematical spacing,
146 and with some corrections. Can you spot which fragment is which?
147
148 @cindex optical spacing
149 @lilypond[noindent]
150     \score { \notes {
151       \property Staff.NoteSpacing \set #'stem-spacing-correction
152         = #0.6
153       c'4 e''4 e'4 b'4 |
154        \stemDown b'4 e''4 a'4 e''4| \stemBoth
155        \bar "||"
156       \property Staff.NoteSpacing \override #'stem-spacing-correction
157       = #0.0
158       \property Staff.StaffSpacing \override #'stem-spacing-correction
159       = #0.0
160       c'4 e''4 e'4 b'4 |
161       \stemDown b'4 e''4 a'4 e''4|
162     }
163     \paper { raggedright = ##t } }
164 @end lilypond
165
166 @cindex regular rhythms
167 @cindex regular spacing
168
169 The fragment that was printed uses only quarter notes: notes that are
170 played in a constant rhythm. The spacing should reflect
171 that. Unfortunately, the eye deceives us a little: the eye not only
172 notices the distance between note heads, but also between consecutive
173 stems. As a result, the notes of an up-stem/down-stem combination
174 should be put farther apart, and the notes of a down-up combination
175 should be put closer together, all depending on the combined vertical
176 positions of the notes. The first two measures are printed with this
177 correction, the last two measures without. The notes in the last two
178 measures form down-stem/up-stems clumps of notes.
179
180 @node Computerized typography
181 @section Computerized typography
182
183 Producing good engraving requires skill and knowledge.  It was our
184 challenge to see if we could put such typographical knowledge into a
185 computer program. Capturing that knowledge has two aspects: first, it
186 has to be acquired. Then, it has to be encoded in data-structures and
187 algorithms.  As the previous examples show, there is a lot of subtlety
188 involved in music engraving, and unfortunately, only a small fraction
189 of these details are documented.
190
191 One reason for the time that it takes to become a master engraver, is
192 that all these details must be learned either from experience or from
193 other engravers: as an engraver gets older and wiser, he will be able
194 to produce better and more complex pieces.  A similar situation is
195 present when putting typography into computer programs.  It is not
196 possible to come up with a final solution for a problem at the first
197 try. Instead, we start out with simple solution that might cover 75%
198 of the cases, and gradually refine that solution over the course of
199 months or years, so that 90 or 95 % of the cases are handled.
200
201 This has an important implication for the design of the
202 program. During development, almost every piece of formatting code
203 must be considered as temporary. When the need arises, is to be
204 replaced a solution that will cover even more cases.  A clean way to
205 accomplish this, is a ``plug-in'' architecture: an architecture where
206 new pieces of code can be inserted in the program dynamically.  In
207 such a program, a new solution can be developed along-side the
208 existing code. It can be perfected separately until it is better than
209 the existing solution, at which point, the new solution is switched on
210 by default, and the old one is removed.
211
212 Until that time, users must have a way to deal with imperfections:
213 these 25%, 10% or 5% of the cases that are not handled
214 automatically. In these cases, a user must be able to override
215 formatting decisions. A way to accomplish this, is to store decisions
216 in generic variables, and let the user manipulate these variables.
217 For example, consider the following fragment of notation.
218
219 @lilypond
220 \score { \notes {
221     g'4-\f g4
222         }
223 \paper { raggedright = ##t }
224      }
225 @end lilypond
226
227 @noindent
228 The position of the forte symbol is slightly awkward, because it is
229 next to the low note, whereas dynamics should be below notes in
230 general. This may be remedied by inserting extra space between the
231 high note and the `f', as shown in this example
232
233 @lilypond
234 \score { \notes {
235     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
236     g'4-\f g4
237         }
238 \paper { raggedright = ##t }
239      }
240 @end lilypond
241
242 This was achieved with the input statement
243 @example
244     \property Voice. DynamicLineSpanner  \override #'padding = #4.0 
245 @end example
246 which increases the amount of space (@code{padding}) between the note
247 and the dynamic symbol to 4.0 (which is measured in staff space, so
248 4.0 equals the height of a staff).
249
250 Both design aspects, a plug-in architecture, and formatting variables,
251 are built on top of GUILE, an interpreter for the programming language
252 Scheme, which is a member of the LISP family. Variables are stored as
253 Scheme objects, and attached to graphical objects such as note heads
254 and stems. The variables are a means to adjust formatting details in
255 individual cases, but they are used in a more general manner.
256
257 Consider the case of a publisher that is not satisfied with the in the
258 default layout, and wants heavier stems. Normally, they are @code{1.3}
259 times the thickness of staff lines, but suppose that their editions
260 require them to be twice the thickness of the staff lines. The same
261 mechanism can be used to adjust a setting globally. By issuing
262 @example
263     \property Score.Stem \override #'thickness = #2.0 
264 @end example
265 the entire piece is formatted with thick stems:
266 @lilypond
267 \score { \notes {
268     \property Score.Stem \override #'thickness = #2.0 
269     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
270     g'4-\f g4
271         }
272 \paper { raggedright = ##t }
273      }
274 @end lilypond
275
276 @noindent
277 In effect, by setting these variables, users can define their own
278 layout styles.
279
280 ``Plug-ins'' are also implemented using Scheme.  A formatting
281 ``plug-in'' takes the form of a function written in Scheme (or a C++
282 function made available as a Scheme function), and it is also stored
283 in a variable.  For example, the placement of the forte symbol in the
284 example above is calculated by the function
285 @code{Side_position_interface::aligned_side}.  If we want to replace
286 this function by a more advanced one, we could issue
287 @example
288     \property Voice.DynamicLineSpanner \override #'Y-offset-callbacks
289        = #`(,gee-whiz-gadget)
290 @end example
291
292 @noindent
293 Now, the formatting process will trigger a call to our new
294 @code{gee-whiz-gadget} function when the position of the f symbol has
295 to be determined.
296
297 The full scope of this functionality certainly is intimidating, but
298 there is no need to fear: normally, it is not necessary to define
299 style-sheets or rewrite formatting functions. In fact, LilyPond gets a
300 lot of formatting right automatically, so adjusting individual layout
301 situations is not needed very often at all.
302
303
304 @node Music representation
305 @section Music representation
306
307
308 One of the big questions when writing batch programs, is what kind of
309 input the program should expect. Many music notation programs offer a
310 graphical interface that shows notation, and allow you to enter the
311 music by placing notes on a staff. From our point of view, this design
312 is a form of cheating. After all, the core message of a piece of music
313 notation simply is the music itself. If you start by offering notation
314 to the user, you have already skipped one conversion, even if it is
315 implicit. If we want to generate music notation from something else,
316 then the obvious candidate for the source is the music itself.
317
318 On paper this theory sounds very good. In practice, it opens a can of
319 worms. What really @emph{is} music? Many philosophical treatises must
320 have been written on the subject.  Instead of losing ourselves in
321 philosophical arguments over the essence of music, we have reversed
322 the question to yield a more practical approach. Our assumption is
323 that the printed score contains all of the music of piece. We build a
324 program that uses some input format to produce such a score. Over the
325 course of time, the program evolves. While this happens, we can remove
326 more and more elements of the input format: as the program improves,
327 it can fill in irrelevant details of the input by itself. At some
328 (hypothetical) point, the program is finished: there is no possibility
329 to remove any more elements from the syntax.  What we have left is by
330 definition exactly the musical meaning of the score.
331
332 There are also more practical concerns.  Our users have to key in the
333 music into the file directly, so the input format should have a
334 friendly syntax: a quarter note C is entered as @code{c4}, the code
335 @code{r8.}  signifies a dotted eighth rest.
336
337 As programmers and scientists, we want a clean formal
338 definition. After all, producing music notation is a difficult
339 problem, and problems can only be solved if they are
340 well-specified. Moreover, formally defined formats are easier to write
341 programs for.  We have chosen for a format that is based on music
342 expressions: complex musical constructs are built from simple entities
343 like notes and rests in much the same way that complex formulas are
344 built from simple expressions such as numbers and mathematical
345 operators.  The language is described by a context-free
346 grammar. Reading such languages robustly is a well studied problem,
347 and we use a standard solution to do it.
348
349 LilyPond is a batch program, so the syntax of the program is its
350 user-interface.  It is the part that they see most, so it is easy to
351 think that music representation is a very important or interesting
352 problem. In reality, less than 10% of the source code of the program
353 handles reading and representing the input, and they form the easy
354 bits of the program. Converting the music to notation, and calculating
355 a pretty layout is much more difficult.
356
357 @node Example applications
358 @section Example applications
359
360 We have written LilyPond as an experiment of how to condense the art
361 of music engraving into a computer program. Thanks to all that hard
362 work, the program can now be used to perform useful tasks.  The
363 simplest application is printing notes.
364
365 @lilypond[relative=1]
366   \time 2/4 c4 c g'4 g a4 a g2  
367 @end lilypond
368
369 By adding chord names and lyrics we obtain a lead sheet:
370 @lilypond[raggedright]
371 \score { <
372   \context ChordNames \chords  { c2 c f2 c }
373   \notes \relative c' { \time 2/4 c4 c g'4 g a4 a g2 }
374   \context Lyrics \lyrics  { twin4 kle twin kle lit tle star2 } > }
375 @end lilypond
376
377 Polyphonic notation and piano music can also be printed. The following
378 example combines some more exotic constructs.
379
380 @lilypondfile{screech-boink.ly}
381
382 The fragments shown above have all been written by hand, but that is not
383 a requirement. Since the formatting engine is mostly automatic, it can
384 serve as an output means for other programs that manipulate music. It
385 can also be used to convert databases of musical fragments to images for
386 use on websites on multimedia presentations.
387
388 This manual also shows an application: the input format is plain text,
389 and can therefore be easily embedded in other text-based formats, such
390 as La@TeX{}, HTML or in the case of this manual, Texinfo.  By means of a
391 special program, the input fragments can be replaced by music images in
392 the resulting PostScript or HTML output files. This makes it easy to
393 mix music and text in documents.
394
395
396
397 @node About this manual
398 @section About this manual
399
400 The manual is divided into the following chapters
401 @itemize @bullet
402 @item
403 @ifhtml The 
404 @end ifhtml
405 @emph{@ref{Tutorial}}
406 gives a  gentle introduction into typesetting music.
407 First time users should start here. 
408 @item
409 @ifhtml
410 The
411 @end ifhtml
412 @emph{@ref{Notation manual}}
413 discusses topics grouped by notation construct.
414 @item
415 @ifhtml
416  The
417  @end ifhtml
418 @emph{@ref{Technical manual}}
419 @c
420 discusses the general design of the program, and how to extend its
421 functionality.
422 @item
423 @ifhtml
424 The chapter
425 @end ifhtml
426 @emph{@ref{Invoking LilyPond}}  explains how to run LilyPond and its helper
427 programs.
428 @end itemize
429
430 Once you are an experienced user, you can use the manual as reference:
431 there is an extensive index@footnote{If you are looking for something,
432 and you cannot find it by using the index, that is considered a bug.
433 In that case, please file a bug report.}, but the document is also
434 available in
435 @ifnothtml
436 a big HTML page,
437 @end ifnothtml 
438 @ifhtml
439 @uref{../lilypond.html, a big HTML page}
440 @end ifhtml
441 which can be searched easily using the search facility of a web
442 browser.
443 @cindex search in manual
444 @cindex using the manual
445
446 @c  TODO: advise to buy a book on notation? 
447
448 If you are not familiar with music notation, or music terminology
449 (especially if you are a foreigner), then it is advisable to consult
450 the glossary as well. The glossary explains musical terms, and
451 includes translations to various languages. It is a
452 @ifhtml
453 @uref{../glossary.html,separate document}
454 @end ifhtml
455 @ifnothtml
456 separate document, available in HTML and PDF and can be printed as
457 well.
458 @end ifnothtml
459 @cindex idiom
460 @cindex jargon
461 @cindex terminology
462 @cindex foreign languages
463 @cindex language
464
465
466 This manual is not complete without a number of other documents. They
467 are not available in print, but should be included with the
468 documentation package for your platform
469
470 @itemize @bullet
471 @item
472 Generated internal documentation.
473 @ifhtml
474 available @uref{../lilypond-internals/lilypond-internals.html,here}
475 @end ifhtml
476
477 The generated internal documentation is a heavily crosslinked HTML
478 document, produced directly from the formatting definitions used.  It
479 documents the nit-gritty details of each and every LilyPond class,
480 object and function.
481
482 Almost all formatting functionality that is used internally, is
483 available directly to the user. For example, all variables that
484 control thicknesses, distances, etc, can be changed in input
485 files. There are a huge number of formatting options, and all of them
486 are described in the generated documentation.  Each section of the
487 reference manual has a @b{See also} subsection, which refers to the
488 the generated documentation.  In the HTML document, these subsections
489 have clickable links.
490
491 @item
492   Templates
493 @ifhtml
494 (available @uref{../../../input/templates/out-www/collated-files.html,here})
495 @end ifhtml
496
497 After you have gone through the tutorial, in theory you should be able
498 to write input files. In practice, writing files from scratch turns
499 out to be intimidating.  To give a headstart, we have collected a
500 number of often-used formats in example files.  These files can be
501 used as a start, by copying the template, and adding notes in the
502 appropriate places.
503
504 @item
505   Various input examples
506 @ifhtml
507 available @uref{../../../input/test/out-www/collated-files.html,here}
508 @end ifhtml
509 @cindex snippets
510
511 These small files show various tips and tricks, and are available as a
512 big HTML document, with pictures and explanatory texts included.
513
514
515 @item
516   The regression test
517 @ifhtml
518 available @uref{../../../input/regression/out-www/collated-files.html,here}
519 @end ifhtml
520
521 We strive to test each feature in one test file. This collection is
522 primarilyt there to help us debug problems, but it can be instructive
523 to see how we excercise the program. The format is like the tips and
524 tricks document.
525
526 @end itemize
527
528
529 The location of the documentation files that are mentioned here can
530 vary from system to system.  On occasion, this manual refers to
531 initialization and example files.  Throughout this manual, we refer to
532 input files relative to the top-directory of the source archive. For
533 example, @file{input/test/bla.ly} may refer to the file
534 @file{lilypond-1.7.19/input/test/bla.ly}.  On binary packages for the
535 Unix platform, the documentation and examples can typically be found
536 somewhere below @file{/usr/share/doc/lilypond/}. Initialization files,
537 for example @file{scm/lily.scm}, or @file{ly/engraver-init.ly}, are
538 usually found in the directory @file{/usr/share/lilypond/}.
539
540 @cindex adjusting output
541 @cindex variables
542 @cindex properties
543 @cindex lilypond-internals
544 @cindex internal documentation
545 @cindex Scheme
546 @cindex extending lilypond
547 @cindex bugreport
548 @cindex index
549
550 Finally, this and all other manuals, are available online both as PDF
551 files and HTML from the web site, which can be found at
552 @uref{http://www.lilypond.org/}.
553
554 @cindex website 
555 @cindex URL