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