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