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