]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/introduction.itely
88adc92c6dc68dfbceaa5a50eb47c61c2e2f8f37
[lilypond.git] / Documentation / user / introduction.itely
1 @c -*-texinfo-*-
2
3 @node Introduction
4 @chapter Introduction
5
6 LilyPond is a program to print sheet music.  If you have used notation
7 programs before, then the way to use this program might be surprising
8 at first sight.  To print music with lilypond, you have to enter
9 musical codes in a file.  Then you run LilyPond on the file, and the
10 music is produced without any further intervention.  For example,
11 something like this:
12
13 @lilypond[fragment,verbatim, relative 1, intertext="produces this
14
15 "]
16 \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
17 @end lilypond
18
19 @cindex encoding music
20
21 Encoding music using letters and digits may appear strange,
22 intimidating or even clumsy at first. Nevertheless, when you take the
23 effort to learn the codes and the program you will find that it is
24 easier than it seems.  Entering music can be done quickly, and you
25 never have to remember how you made the program do something
26 complicated: it is all in the input code, and you only have to read
27 the file to see how it works. Moreover, when you use LilyPond, you are
28 rewarded with very nicely looking output.
29
30 In this chapter, we will explain the reasoning behind this unusual
31 design, and how this approach affects you as a user.
32
33 @menu
34 * Batch processing::            
35 * Music engraving::             
36 * Music representation::        
37 * Program design::              
38 * Example applications::        
39 * About this manual::           
40 @end menu
41
42 @node Batch processing
43 @section Batch processing
44
45 @cindex GUI
46 @cindex Batch
47 @cindex UNIX
48
49 When we started developing LilyPond, we were still studying at the
50 university.  We were interested in music notation, not as publishers
51 or musicians, but as students and scientists. We wanted to figure to
52 what extent formatting sheet music could be automated.  Back then GUIs
53 were not as ubiquitous as they are today, and we were immersed in the
54 UNIX operating system, where it is very common to use compilers to
55 achieve computing tasks, so our computerized music engraving
56 experiment took on the form of a compiler.
57
58
59 @ignore
60 @cindex free software
61 @cindex sharing software
62
63 You can freely use, modify and redistribute LilyPond. This choice was
64 also motivated by our academic background. In the scientific community
65 it has always been a tradition to share knowledge, also if that
66 knowledge was packaged as software. One of the most visible groups
67 that stimulated this philosophy, was the Free Software Foundation,
68 whose popular GNU project aimed to replace closed and proprietary
69 computing solutions with free (as in ``Libre'') variants. We jumped on
70 that bandwagon, and released LilyPond as free software.  That is the
71 reason that you can get LilyPond at no cost and without any strings
72 attached.
73 @end ignore
74
75
76 @node Music engraving
77 @section Music engraving
78
79
80
81 @cindex engraving
82 @cindex typography
83
84 Making sheet music may seem trivial at first (``you print 5 lines, and
85 then put in the notes at different heights''), @emph{music engraving},
86 i.e. professional music typography, is in another ballpark.  The term
87 `music engraving' derives from the traditional process of music
88 printing.  Only a few decades ago, sheet music was made by cutting and
89 stamping the music into zinc or pewter plates, mirrored. The plate
90 would be inked, and the depressions caused by the cutting and stamping
91 would hold ink.  A positive image was formed by pressing paper to the
92 plate. Stamping and cutting was completely done by hand. Making
93 corrections was cumbersome, so engraving had to be done correctly in
94 one go. As you can imagine this was a highly specialized skill, much
95 more so than the traditional process of printing books.
96 @cindex craftsmanship
97 @cindex master
98 In the traditional German craftsmanship six years of full-time
99 training, more than any other craft, were required before a student
100 could call himself a master of the art. After that many more years of
101 practical experience were needed to become an established music
102 engraver.  Even today, with the use of high-speed computers and
103 advanced software, music requires lots of manual fine tuning before it
104 acceptable to be published.
105
106 When we wanted to write a computer program to do create music
107 typography, we encountered the first problem: there were no sets of
108 musical symbols available: either they were not available freely, or
109 they did not look well to our taste. Not let down, we decided to try
110 font design ourselves. We created a font of musical symbols, relying
111 on nice printouts of hand-engraved music.  The experience helped
112 develop a typographical taste, and it made us appreciate subtle design
113 details. Without that experience, we would not have realized how ugly
114 the fonts were that we admired at first.
115
116
117 @lilypond[noindent]
118 #(define magfact 3.0)
119 \score {  \notes { as'2 r4 }
120           \paper {
121               linewidth = -1.
122               \translator {
123                   \ScoreContext
124                   AccidentalPlacement \override #'right-padding = #3.0
125                   StaffSymbol \override #'transparent =   ##t
126                   Clef \override #'transparent = ##t
127                   TimeSignature \override #'transparent = ##t
128                   Accidental \override #'font-magnification = #magfact
129                   Rest \override #'font-magnification = #magfact
130                   NoteHead \override #'font-magnification = #magfact
131                   Stem \override #'transparent = ##t
132                   } } }
133 @end lilypond
134
135 @cindex musical symbols
136 @cindex font
137 @cindex blackness
138 @cindex balance
139
140 The figure above shows a few notable glyphs. For example, the
141 half-notehead is not elliptic but slightly diamond shaped.  The
142 vertical stem of a flat symbol should be slightly brushed,
143 i.e. becoming wider at the top. Fine endings, such as the one on the
144 bottom of the quarter rest, should not end in sharp points, but rather
145 in rounded shapes.  Taken together, the blackness of the font must be
146 carefully tuned together with the thickness of lines, beams and slurs
147 to give a strong yet balanced overall impression.
148
149 Producing a strong and balanced look is the real challenge of music
150 engraving. It is a recurring theme with many variations.  In spacing,
151 the balance is in a distribution that reflects the character of the
152 music. The spacing should not lead to unnatural clusters of black and
153 big gaps with white space.  The distances between notes should reflect
154 the durations between notes, but adhering with mathematical precision
155 to the duration will lead to a poor result. Shown here is an example
156 of a motive, printed twice. It is printed using both exact,
157 mathematical spacing, and with some corrections. Can you spot which is
158 which?
159
160
161 @cindex optical spacing
162 @lilypond[noindent]
163     \score { \notes {
164       \property Staff.NoteSpacing \set #'stem-spacing-correction
165         = #0.6
166       c'4 e''4 e'4 b'4 |
167        \stemDown b'4 e''4 a'4 e''4| \stemBoth
168       \property Staff.NoteSpacing \override #'stem-spacing-correction
169       = #0.0
170       \property Staff.StaffSpacing \override #'stem-spacing-correction
171       = #0.0
172       c'4 e''4 e'4 b'4 |
173       \stemDown b'4 e''4 a'4 e''4|
174     }
175     \paper { linewidth = -1. } }
176 @end lilypond
177
178 @cindex regular rhythms
179 @cindex regular spacing
180
181 The fragment that was printed uses only quarter notes: notes that are
182 played in a constant rhythm. The spacing should reflect
183 that. Unfortunately, the eye deceives us a little: the eye not only
184 notices the distance between note heads, but also between consecutive
185 stems. The notes of a up-stem/down-stem combination should be put
186 farther apart, and the notes of a down-up combination should be put
187 closer together, all depending on the combined vertical positions of
188 the notes. The first two measures are printed with this correction,
189 the last two measures without. The notes in the last two measures form
190 downstem/upstems clumps of notes.
191
192 We hope that these examples show that music typography is a subtle
193 business, and that it requires skill and knowledge to produce good
194 engraving.  It was our challenge to see if we could put such knowledge
195 into a computer program.
196
197
198 @node Music representation
199 @section Music representation
200
201
202 One of the big questions when making programs, is what kind of input
203 the program should expect. Many music notation programs offer a
204 graphical interface that shows notation, and allow you to enter the
205 music by placing notes on a staff. From our point of view, this design
206 is a form of cheating. After all, the core message of a piece of music
207 notation simply is the music itself. If you start by offering notation
208 to the user, you have already skipped one conversion, even if it is
209 implicit. If we want to generate music notation from something else,
210 then the obvious candidate for the source is the music itself.
211
212 On paper this theory sounds very good. In practice, it opens a can of
213 worms. What really @emph{is} music? Many philosophical treatises must
214 have been written on the subject.  Instead of losing ourselves in
215 philosophical arguments over the essence of music, we have reversed
216 the question to yield a more practical approach. Our assumption is
217 that the printed score contains all of the music of piece. We build a
218 program that uses some input format to produce such a score. Over the
219 course of time, the program evolves. While this happens, we can remove
220 more and more elements of the input format: as the program improves,
221 it can fill in irrelevant details of the input by itself. At some
222 (hypothetical) point, the program is finished: there is no possibility
223 to remove any more elements from the syntax.  What we have left is by
224 definition exactly the musical meaning of the score.
225
226 There are also more practical concerns.  Our users have to key in the
227 music into the file directly, so the input format should have a
228 friendly syntax. As programmers and scientists, we want a
229 clean formal definition. After all, producing music notation is a
230 difficult problem, and in the scientific world, problems can only be
231 solved if they are well-specified. Moreover, formally defined formats
232 are easier to write programs for.
233
234
235 These ideas shaped our music representation: it is a compact format
236 that can easily be typed by hand. It complex musical constructs from
237 simple entities like notes and rests, in much the same way that one
238 builds complex formulas from simple expressions such as numbers and
239 mathematical operators.
240
241 @node Program design
242 @section Program design
243
244 The strict separation between musical information and typesetting also
245 gives a blueprint of the program: first it reads the music
246 representation, then it interprets the music---reading it
247 `left-to-right', and translating the musical information to a layout
248 specification. When the layout is computed, the resulting symbols are
249 written to an output file.
250
251 TODO: more about design? 
252
253 @node Example applications
254 @section Example applications
255
256 TODO: show what sort of things lily can be used for.
257
258
259
260 @node About this manual
261 @section About this manual
262
263 [
264
265 The manual is divided into the following chapters
266 @itemize
267 @item Tutorial
268 gives a gentle introduction into using lilypond
269 @item
270 Reference manual: each aspect of typesetting music is discussed
271 @item
272 Advanced topics: how it works from the inside, scripting lilypond.
273 @item
274 Invoking: running LilyPond and its helper programs. 
275 @end itemize
276
277 This manual is not complete: a part of the functionality is available
278 through a generic system of properties: variables that can be set by
279 the user to override certain functionality. Accompanying this manual
280 is a document that describes all properties available, and all types
281 of typographic and musical objects.
282
283 TODO: rewrite rest of this section too.
284 ]
285
286 As you will notice in the coming pages the program makes good
287 decisions in a lot of cases: what comes out of LilyPond generally
288 looks good.  The default layout of lilypond even is suitable for
289 publication for some specific files. However, some aspects of the
290 formatting are not yet very good. For us programmers, this gives
291 inspiration for improving the program. However, most users are more
292 interested in improving their printouts, and then they have to make
293 manual adjustments to the output.  Another aspect of our system of
294 encoding through ASCII then shows: it can be complicated to fine tune
295 the layout of a piece. There is no graphical user interface, where you
296 can simply click and drag a symbol. On the other hand, if you have
297 written the code for tuning one specific aspect of the layout, then
298 you can simply store the file on disk, retrieve it when you need it:
299 there is no need to remember how you did it, since it is all in the
300 input file.
301
302 @cindex snippets
303 @cindex adjusting output
304
305 Lilypond also comes with a huge collection of snippets that show all
306 kinds of tricks.  This collection is much needed, because of the way
307 LilyPond is structured. It is a large program, but almost all of the
308 internal functionality is exported: that is, the variables that are
309 internally used for formatting the sheet music are available directly
310 to the user. These are variables to control thicknesses, distances,
311 and other formatting options. There are a huge number of them, and it
312 would be impossible to describe them all in a hand-written
313 manual. There is no need to despair, there is an `automatic' manual,
314 that lists all of the variables that are available.  It is directly
315 generated from the definitions that LilyPond itself uses, so it is
316 always up to date. If you are reading this from a screen: it is
317 available from the web, and is included with most binary
318 distributions.  If you are reading this from paper, then we advise you
319 to use the digital version anyway: the hyperlinks make finding topics
320 in the lilypond-internals manual much easier.
321
322 @cindex variables
323 @cindex properties
324 @cindex lilypond-internals
325 @cindex internal documentation
326
327 For those who really want to get their hands dirty: it is even
328 possible to add your own functionality, by extending LilyPond in the
329 built-in scripting language, a dialect of the powerful programming
330 language Scheme. There is no real distinction between what a user can
331 do and what a programmer is allowed to do.
332
333 @cindex Scheme
334 @cindex extending lilypond
335
336 In summary, this manual does not pretend to be exhaustive, but it is
337 merely a guide that tries to explain the most important principles,
338 and shows popular input idioms.  The rest of the manual is structured
339 as follows: it starts with a tutorial that explains how to use
340 lilypond. In the tutorial, a number of fragments of increasing
341 complexity are shown and explained.  Then comes the reference manual,
342 which gives more detailed information on all features. If you are new
343 to lilypond, then you should start reading the tutorial, and
344 experiment for yourself.  If you already have some experience, then
345 you can simply use the manual as reference: there is an extensive
346 index@footnote{If you are looking for something, and you cannot find it
347 by using the index, that is considered a bug.  In that case, please
348 file a bug report}, but the document is also available in One Big Page,
349 @c should have hyperlink?
350 which is is available for text search using your browser's search
351 facility.
352
353 @cindex searchin manual
354 @cindex using the manual
355 @cindex bugreport
356 @cindex index
357 @cindex tutorial
358 @cindex overview of manual
359 @cindex idiom
360
361 [TODO: edit following]
362
363 This is the end of the tutorial.  If you read everything until this point
364 (and understood everything!) then you are now an accomplished lilypond
365 hacker.  From here you should try fiddling with input files or making your
366 own input files.  Come back to the reference manual for more information
367 if you get stuck!
368
369 Do not forget to check out the 
370 @ifhtml
371 @uref{../../../../input/template/out-www/template.html,templates},
372 @uref{../../../../input/test/out-www/test.html,examples} and 
373 @uref{../../../../input/regression/out-www/regression.html,feature tests}.
374 @end ifhtml
375 @ifnothtml
376 templates, examples and feature tests.
377 @end ifnothtml
378 If you want to see real action LilyPond, head over to
379 @uref{http://www.mutopiaproject.org}, which has many examples of
380 classical music typeset with LilyPond.