]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/introduction.itely
* GNUmakefile.in: remove no kpathsea hack.
[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.  If you
9 regularly from both recent and old music, you can probably agree with
10 us on that.  Most computer printouts have a bland, mechanical look,
11 and are unpleasant to play from.  Musicians are usually more absorbed
12 with performing the music than with studying its looks, so they
13 usually cannot pinpoint what exactly is so disconcerting about
14 computer prints.
15
16 However, it only takes a little attention to see for yourself what is
17
18
19
20    oftenmostly itself,
21 than studying the looks of , and will so most l playing Since we
22 normally don't For normal users, it is difficult If you are familiar
23 with this sensation, you will probably not be able to pinpoint what
24 exactly causes this feeling.
25
26
27
28
29  Normally, one notices these details only subconsiously. The best way
30 to become conscious of these differences is to compare a traditionally
31 printed and a computer printed edition of the same piece, preferably
32 with a magnifying glass. If you are not sure: traditional engraving is
33 photographically reproduced hand-work, and can be recognized by
34 slightly irregularities in symbol placement, and small blotches due to
35 the reproduction process.
36
37
38
39 By contrast, we try to mimick traditional plate engraving in the
40 general impression, layout algorithms, and the font
41 design. Consequently, our output often beats our competitors when it
42 comes to good looks.
43
44
45
46
47 LilyPond is an automated music engraving system.
48
49   
50 With LilyPond is a program that lets you print sheet music. It is
51 certainly not unique in that sense.  
52
53
54 it is more than that 
55
56  If you are reading this 
57
58 What is LilyPond?
59
60 Automatic notation, so that means I can play the music, and then it
61 rolls out of the printer?
62
63 There are other program that do notation. What's so special about yours?
64 What is wrong with other computer printed scores?
65
66 What is engraving?
67
68 Music notation  vs. Engraving. (vs. composing)
69
70 Why do you care about engraving?
71
72 Why would I care about engraving?
73
74 You say your program is special; you must be trying to sell it?
75
76 Freedom
77
78 Preserving/reinventing the art of engraving 
79
80 Typography in LilyPond.
81
82 Input format.  Issue is overrated.
83
84
85
86
87 ************
88
89
90 LilyPond is a program to print sheet music.  If you have used notation
91 programs before, then the way to use this program might be surprising
92 at first sight: in order to print music you have to enter musical
93 codes in a file.  Then you run the program on the file, and the music
94 is produced without any further intervention.  For example, something
95 like this:
96
97
98 @lilypond[fragment,verbatim, relative 1, intertext="produces this:
99
100 "]
101 \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
102 @end lilypond
103
104 @cindex encoding music
105
106 Encoding music using letters and digits may appear strange,
107 intimidating or even clumsy at first. Nevertheless, when you take the
108 effort to learn the codes and the program you will find that it is
109 easier than it seems.  Entering music can be done quickly, and you
110 never have to remember how you made the program do something
111 complicated: it is all in the input code, and you only have to read
112 the file to see how it works. Moreover, you are rewarded with very
113 nicely looking output.
114
115 In this chapter, we will explain the reasoning behind this unusual
116 design, and how this approach affects you as a user.
117
118
119
120 @menu
121 * Batch processing::            
122 * Music engraving::             
123 * Computerized typography ::    
124 * Music representation::        
125 * Example applications::        
126 * About this manual::           
127 @end menu
128
129 @node Batch processing
130 @section Batch processing
131
132 @cindex GUI
133 @cindex Batch
134 @cindex UNIX
135
136 LilyPond is a @emph{batch} program. To use it, one enters commands in a
137 file, and runs the program on that file. The output is produced without
138 requiring any further interaction.
139
140 When we started developing LilyPond, we were still studying at the
141 university.  We were interested in music notation, not as publishers
142 or musicians, but as programmers and scientists. We wanted to figure
143 to what extent formatting sheet music could be automated.  Back then
144 GUIs were not as ubiquitous as they are today, and we were immersed in
145 the UNIX operating system, where it is very common to use compilers to
146 achieve computing tasks. So, our computerized music engraving
147 experiment took on the form of a compiler.
148
149
150 @ignore
151 @cindex free software
152 @cindex sharing software
153
154 You can freely use, modify and redistribute LilyPond. This choice was
155 also motivated by our academic background. In the scientific community
156 it has always been a tradition to share knowledge, also if that
157 knowledge was packaged as software. One of the most visible groups
158 that stimulated this philosophy, was the Free Software Foundation,
159 whose popular GNU project aimed to replace closed and proprietary
160 computing solutions with free (as in ``Libre'') variants. We jumped on
161 that bandwagon, and released LilyPond as free software.  That is the
162 reason that you can get LilyPond at no cost and without any strings
163 attached.
164 @end ignore
165
166
167 @node Music engraving
168 @section Music engraving
169
170
171
172 @cindex engraving
173 @cindex typography
174
175 Making sheet music may seem trivial at first (``you print 5 lines, and
176 then put in the notes at different heights''),
177
178
179 Hier over notatie.
180
181 @emph{music engraving}, i.e. professional music typography, is in
182 another ballpark.  The term `music engraving' derives from the
183 traditional process of music printing.  Only a few decades ago, sheet
184 music was made by cutting and stamping the music into zinc or pewter
185 plates, mirrored. The plate would be inked, and the depressions caused
186 by the cutting and stamping would hold ink.  An image was formed by
187 pressing paper to the plate. Stamping and cutting was completely done
188 by hand. Making corrections was cumbersome, so engraving had to be
189 done correctly in one go. As you can imagine this was a highly
190 specialized skill, much more so than the traditional process of
191 printing books.
192 @cindex craftsmanship
193 @cindex master
194 In the traditional German craftsmanship six years of full-time
195 training, more than any other craft, were required before a student
196 could call himself a master of the art. After that many more years of
197 practical experience were needed to become an established music
198 engraver.  Even today, with the use of high-speed computers and
199 advanced software, music requires lots of manual fine tuning before it
200 is acceptable for publication.
201
202 When we wanted to write a computer program to create music typography,
203 we encountered the first problem: there were no sets of musical
204 symbols available: either they were not available freely, or they did
205 not look well to our taste. Not let down, we decided to try font
206 design ourselves. We created a font of musical symbols, relying on
207 nice printouts of hand-engraved music.  The experience helped develop
208 a typographical taste, and it made us appreciate subtle design
209 details. Without that experience, we would not have realized the
210 shortcomings of the fonts were that we admired at first.
211
212
213 @lilypond[noindent]
214 #(define magfact 3.0)
215 \score {  \notes { as'2 r4 }
216           \paper {
217                  raggedright = ##t
218               \translator {
219                   \ScoreContext
220                   AccidentalPlacement \override #'right-padding = #3.0
221                   StaffSymbol \override #'transparent =   ##t
222                   Clef \override #'transparent = ##t
223                   TimeSignature \override #'transparent = ##t
224                   Accidental \override #'font-magnification = #magfact
225                   Rest \override #'font-magnification = #magfact
226                   NoteHead \override #'font-magnification = #magfact
227                   Stem \override #'transparent = ##t
228                   } } }
229 @end lilypond
230
231 @cindex musical symbols
232 @cindex font
233 @cindex blackness
234 @cindex balance
235
236
237 The figure above shows a few notable glyphs.  For example, the
238 vertical stem of the flat symbol should be brushed slightly,
239 i.e. becoming wider at the top. the half-notehead is not elliptic but
240 slightly diamond shaped.  Fine endings, such as the one on the bottom
241 of the quarter rest, should not end in sharp points, but rather in
242 rounded shapes.  Taken together, the blackness of the font must be
243 carefully tuned together with the thickness of lines, beams and slurs
244 to give a strong yet balanced overall impression.
245
246 Producing a strong and balanced look is the real challenge of music
247 engraving. It is a recurring theme with many variations.  In spacing,
248 strength and balance are in layout that is `heavy' enough---without
249 big gaps of space--- and without big clusters of black.  The
250 distribution of space should reflect the character of the music.
251
252 Spacing is an example of a subtlety of formatting music. The distances
253 between notes should reflect the durations between notes, but adhering
254 with mathematical precision to the duration will lead to a poor
255 result. Shown here is an example of a motive, printed twice. It is
256 printed using exact mathematical spacing, and with some
257 corrections. Can you spot which fragment is which?
258
259
260 @cindex optical spacing
261 @lilypond[noindent]
262     \score { \notes {
263       \property Staff.NoteSpacing \set #'stem-spacing-correction
264         = #0.6
265       c'4 e''4 e'4 b'4 |
266        \stemDown b'4 e''4 a'4 e''4| \stemBoth
267       \property Staff.NoteSpacing \override #'stem-spacing-correction
268       = #0.0
269       \property Staff.StaffSpacing \override #'stem-spacing-correction
270       = #0.0
271       c'4 e''4 e'4 b'4 |
272       \stemDown b'4 e''4 a'4 e''4|
273     }
274     \paper { raggedright = ##t } }
275 @end lilypond
276
277 @cindex regular rhythms
278 @cindex regular spacing
279
280 The fragment that was printed uses only quarter notes: notes that are
281 played in a constant rhythm. The spacing should reflect
282 that. Unfortunately, the eye deceives us a little: the eye not only
283 notices the distance between note heads, but also between consecutive
284 stems. As a result, the notes of a up-stem/down-stem combination
285 should be put farther apart, and the notes of a down-up combination
286 should be put closer together, all depending on the combined vertical
287 positions of the notes. The first two measures are printed with this
288 correction, the last two measures without. The notes in the last two
289 measures form down-stem/up-stems clumps of notes.
290
291 @node Computerized typography
292 @section Computerized typography
293
294 The example in the previous section is one illustration of how subtle
295 music engraving can be is a subtle. Producing good engraving requires
296 skill and knowledge.
297
298
299 It was our challenge to see if we could put typographical knowledge
300 into a computer program. Capturing that knowledge has two aspects:
301 first, it has to be acquired. Then, it has to be encoded in
302 data-structures and algorithms.  As the previous example shows, there
303 is a lot of subtlety involved in music engraving, and unfortunately,
304 only a small fraction of these tiny details are documented.
305
306 One reason for the time that it takes to become a master engraver, is
307 that all these details must be learned either from experience or from
308 other engravers: as an engraver gets older and wiser, he will be able
309 to produce better and more complex pieces.  A similar situation is
310 present when putting typography into computer programs.  It is not
311 possible to come up with a final solution for a problem at the first
312 try. Instead, we start out with simple solution that might cover 75%
313 of the cases, and gradually refine that solution over the course of
314 months or years, so that 90 or 95 % of the cases are handled.
315
316 This has an important implication for the design of the
317 program. During development, almost every piece of formatting code
318 must be considered as temporary. When the need arises, is to be
319 replaced a solution that will cover even more cases.  A clean way to
320 accomplish this, is a ``plug-in'' architecture: an architecture where
321 new pieces of code can be inserted in the program dynamically.  In
322 such a program, a new solution can be developed along-side the
323 existing code. It can be perfected separately until it is better than
324 the existing solution, at which point, the new solution is switched on
325 by default, and the old one is removed.
326
327 Until that time, users must have a way to deal with imperfections:
328 these 25%, 10% or 5% of the cases that are not handled
329 automatically. In these cases, a user must be able to override
330 formatting decisions. A way to accomplish this, is to store decisions
331 in generic variables, and let the user manipulate these variables.
332 For example, consider the following fragment of notation.
333
334 @lilypond
335 \score { \notes {
336     g'4-\f g4
337         }
338 \paper { raggedright = ##t }
339      }
340 @end lilypond
341
342 @noindent
343 The position of the forte symbol is slightly awkward, because it is
344 next to the low note, whereas dynamics should be below notes in
345 general. This may be remedied by inserting extra space between the
346 high note and the `f', as shown in this example
347
348 @lilypond
349 \score { \notes {
350     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
351     g'4-\f g4
352         }
353 \paper { raggedright = ##t }
354      }
355 @end lilypond
356
357 This was achieved with the input statement
358 @example
359     \property Voice. DynamicLineSpanner  \override #'padding = #4.0 
360 @end example
361 which increases the amount of space (@code{padding}) between the note
362 and the dynamic symbol to 4.0 (which is measured in staff space, so
363 4.0 equals the height of a staff).
364
365 Both design aspects, a plug-in architecture, and formatting variables,
366 are built on top of GUILE, an interpreter for the programming language
367 Scheme, which is a member of the LISP family. Variables are stored as
368 Scheme objects, and attached to graphical objects such as note heads
369 and stems. The variables are a means to adjust formatting details in
370 individual cases, but they are used in a more general manner.
371
372 Consider the case of a publisher that is not satisfied with the in the
373 default layout, and wants heavier stems. Normally, they are @code{1.3}
374 times the thickness of staff lines, but suppose that their editions
375 require them to be twice the thickness of the staff lines. The same
376 mechanism can be used to adjust a setting globally. By issuing
377 @example
378     \property Score.Stem \override #'thickness = #2.0 
379 @end example
380 the entire piece is formatted with thick stems:
381 @lilypond
382 \score { \notes {
383     \property Score.Stem \override #'thickness = #2.0 
384     \once\property Voice. DynamicLineSpanner  \override #'padding = #4.0 
385     g'4-\f g4
386         }
387 \paper { raggedright = ##t }
388      }
389 @end lilypond
390
391 @noindent
392 In effect, by setting these variables, users can define their own
393 layout styles.
394
395 ``Plug-ins'' are also implemented using Scheme.  A formatting
396 ``plug-in'' takes the form of a function written in Scheme (or a C++
397 function made available as a Scheme function), and it is also stored
398 in a variable.  For example, the placement of the forte symbol in the
399 example above is calculated by the function
400 @code{Side_position_interface::aligned_side}.  If we want to replace
401 this function by a more advanced one, we could issue
402 @example
403     \property Voice.DynamicLineSpanner \override #'Y-offset-callbacks
404        = #`(,gee-whiz-gadget)
405 @end example
406
407 @noindent
408 Now, the formatting process will trigger a call to our new
409 @code{gee-whiz-gadget} function when the position of the f symbol has
410 to be determined.
411
412 The full scope of this functionality certainly is intimidating, but
413 there is no need to fear: normally, it is not necessary to define
414 style-sheets or rewrite formatting functions. In fact, LilyPond gets a
415 lot of formatting right automatically, so adjusting individual layout
416 situations is not needed very often at all.
417
418
419 @node Music representation
420 @section Music representation
421
422
423 One of the big questions when writing batch programs, is what kind of
424 input the program should expect. Many music notation programs offer a
425 graphical interface that shows notation, and allow you to enter the
426 music by placing notes on a staff. From our point of view, this design
427 is a form of cheating. After all, the core message of a piece of music
428 notation simply is the music itself. If you start by offering notation
429 to the user, you have already skipped one conversion, even if it is
430 implicit. If we want to generate music notation from something else,
431 then the obvious candidate for the source is the music itself.
432
433 On paper this theory sounds very good. In practice, it opens a can of
434 worms. What really @emph{is} music? Many philosophical treatises must
435 have been written on the subject.  Instead of losing ourselves in
436 philosophical arguments over the essence of music, we have reversed
437 the question to yield a more practical approach. Our assumption is
438 that the printed score contains all of the music of piece. We build a
439 program that uses some input format to produce such a score. Over the
440 course of time, the program evolves. While this happens, we can remove
441 more and more elements of the input format: as the program improves,
442 it can fill in irrelevant details of the input by itself. At some
443 (hypothetical) point, the program is finished: there is no possibility
444 to remove any more elements from the syntax.  What we have left is by
445 definition exactly the musical meaning of the score.
446
447 There are also more practical concerns.  Our users have to key in the
448 music into the file directly, so the input format should have a
449 friendly syntax. As programmers and scientists, we want a
450 clean formal definition. After all, producing music notation is a
451 difficult problem, and in the scientific world, problems can only be
452 solved if they are well-specified. Moreover, formally defined formats
453 are easier to write programs for.
454
455 These ideas shaped our music representation: it is a compact format
456 that can easily be typed by hand. It complex musical constructs from
457 simple entities like notes and rests, in much the same way that one
458 builds complex formulas from simple expressions such as numbers and
459 mathematical operators.
460
461 @node Example applications
462 @section Example applications
463
464 As programmers and hedonists we enjoy beauty in code, and code that
465 produces beautiful typeset music, but nevertheless this program can
466 applied to do useful things. In this section, we show a few small
467 examples of what is possible.
468
469 The simplest application is printing notes.
470
471 @lilypond[relative=1]
472   \time 2/4 c4 c g'4 g a4 a g2  
473 @end lilypond
474
475 To these notes, chord names and lyrics  may be added, yielding
476 a lead sheet.
477
478 @lilypond[raggedright]
479 \score { <
480   \context ChordNames \chords  { c2 c f2 c }
481   \notes \relative c' { \time 2/4 c4 c g'4 g a4 a g2 }
482   \context Lyrics \lyrics  { twin4 kle twin kle lit tle star2 } > }
483 @end lilypond
484
485 The following example combines some more exotic uses of notation
486
487 @lilypondfile{screech-boink.ly}
488
489 The fragments shown above have all been written by hand, but that is not
490 a requirement. Since the formatting engine is mostly automatic, it can
491 serve as an output means for other programs that manipulate music. It
492 can also be used to convert databases of musical fragments to images for
493 use on websites on multimedia presentations.
494
495 This manual also shows an application: the input format is plain text,
496 and can therefore be easily embedded in other text-based formats, such
497 as La@TeX{}, HTML or in the case of this manual, Texinfo.  By means of a
498 special program, the input fragments can be replaced by music images in
499 the resulting PostScript or HTML output files. This makes it easy to
500 mix music and text in documents.
501
502
503
504 @node About this manual
505 @section About this manual
506
507 The manual is divided into the following chapters
508 @itemize @bullet
509 @item
510 @ifhtml The 
511 @end ifhtml
512 @emph{@ref{Tutorial}}
513 gives a  gentle introduction into typesetting music.
514 First time users should start here. 
515 @item
516 @ifhtml
517 The
518 @end ifhtml
519 @emph{@ref{Notation manual}}
520 discusses topics grouped by notation construct.
521 @item
522 @ifhtml
523  The
524  @end ifhtml
525 @emph{@ref{Technical manual}}
526 @c
527 discusses the general design of the program, and how to extend 
528 functionality.
529 @item
530 @ifhtml
531  The chapter
532 @end ifhtml
533 @emph{@ref{Invoking LilyPond}}  explains how to run LilyPond and its helper
534 programs.
535 @end itemize
536
537 Once you are experienced, you can simply use the manual as reference:
538 there is an extensive index@footnote{If you are looking for something,
539 and you cannot find it by using the index, that is considered a bug.
540 In that case, please file a bug report.}, but the document is also
541 available in
542 @ifnothtml
543 a big HTML page,
544 @end ifnothtml 
545 @ifhtml
546 @uref{../lilypond.html, a big HTML page}
547 @end ifhtml
548 which can be searched easily using the search facility of a web
549 browser.
550 @cindex search in manual
551 @cindex using the manual
552
553 @c  TODO: advise to buy a book on notation? 
554
555 If you are not familiar with music notation, or music terminology
556 (especially if you are a foreigner), then it is advisable to consult
557 the glossary as well. The glossary explains musical terms, and
558 includes translations to various languages. It is a
559 @ifhtml
560 @uref{../glossary.html,separate document}
561 @end ifhtml
562 @ifnothtml
563 separate document, available in HTML and PDF and can be printed as
564 well.
565 @end ifnothtml
566 @cindex idiom
567 @cindex jargon
568 @cindex terminology
569 @cindex foreign languages
570 @cindex language
571
572
573 This manual is not complete without a number of other documents. They
574 are not available in print, but should be included with the
575 documentation package for your platform
576
577 @itemize @bullet
578 @item
579 Generated internal documentation.
580 @ifhtml
581 available @uref{../lilypond-internals/lilypond-internals.html,here}
582 @end ifhtml
583
584 Almost all formatting functionality that is used internally, is
585 available directly to the user. For example, all variables that
586 control thicknesses, distances, etc, can be changed in input
587 files. There are a huge number of formatting options, and it would be
588 impossible to describe them all in a hand-written manual. The
589 generated internal documentation is a heavily crosslinked HTML
590 document, produced directly from the formatting definitions used.  It
591 documents the nit-gritty details of each and every LilyPond class, object and
592 function.
593
594 Each section of the reference manual has a @b{See also}
595 subsection, with links (in the HTML document, at least) to the
596 generated documentation.
597
598 @item
599   Templates
600 @ifhtml
601 (available @uref{../../../input/templates/out-www/collated-files.html,here})
602 @end ifhtml
603
604 When you have gone through the tutorial, in theory you are able to
605 start writing input files. In practice, writing files from scratch
606 turns out to be intimidating.  To give a headstart, we have collected
607 a number of often-used formats in example files.  These files can be
608 used as a start, by copying the template, and adding notes in the
609 appropriate places.
610
611 @item
612   Various input examples
613 @ifhtml
614 available @uref{../../../input/test/out-www/collated-files.html,here}
615 @end ifhtml
616 @cindex snippets
617
618 These small files show various tips and tricks, and are available as a
619 big HTML document, with pictures and explanatory texts included.
620
621
622 @item
623   The regression test
624 @ifhtml
625 available @uref{../../../input/regression/out-www/collated-files.html,here}
626 @end ifhtml
627
628 We strive to test each feature in one test file. This collection of is
629 primarily to help us debug problems, but it can be instructive to see
630 how we excercise the program. The format is like the input examples.
631
632 @end itemize
633
634
635 The location of the documentation files that are mentioned here can
636 vary from system to system.  On occasion, this manual refers to
637 initialization and example files.  Throughout this manual, we refer to
638 input files relative to the top-directory of the source archive. For
639 example, @file{input/test/bla.ly} may refer to the file
640 @file{lilypond-1.7.19/input/test/bla.ly}.  On binary packages for the
641 Unix platform, the documentation and examples can typically be found
642 somewhere below @file{/usr/share/doc/lilypond/}. Initialization files,
643 for example @file{scm/lily.scm}, or @file{ly/engraver-init.ly}, are
644 usually found in the directory @file{/usr/share/lilypond/}.
645
646 @cindex adjusting output
647 @cindex variables
648 @cindex properties
649 @cindex lilypond-internals
650 @cindex internal documentation
651 @cindex Scheme
652 @cindex extending lilypond
653 @cindex bugreport
654 @cindex index
655
656 Finally, this and all other manuals, are available online both as PDF
657 files for print and HTML files for browsing. They are available from
658 the web site, which can be found at @uref{http://www.lilypond.org/}.
659
660 @cindex website 
661 @cindex URL