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