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