]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/introduction.itely
* Documentation/user/preface.itely: small bits
[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 tried 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 philosopy, 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 craftmanship
93 @cindex master
94
95 In fact, in the traditional German craftmanship 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 @cindex optical spacing
156 @lilypond
157     \score { \notes {
158       \property Staff.NoteSpacing \set #'stem-spacing-correction
159         = #0.6
160       c'4 e''4 e'4 b'4 |
161       b'4 e''4 b'4 e''4|
162       \property Staff.NoteSpacing \override #'stem-spacing-correction
163       = #0.0
164       \property Staff.StaffSpacing \override #'stem-spacing-correction
165       = #0.0
166       c'4 e''4 e'4 b'4 |
167       b'4 e''4 b'4 e''4|      
168     }
169     \paper { linewidth = -1. } }
170 @end lilypond
171
172 @cindex regular rhythms
173 @cindex regular spacing
174
175 The fragment that was printed uses only quarter notes: notes that are
176 played in a constant regular rhythm. The spacing should reflect
177 that. Unfortunately, the eye deceives us a little: the eye not only
178 notices the distance between note heads, but also between consecutive
179 stems. Depending on the different vertical positions, the notes of a
180 upstem-downstem combination should be put farther apart, and the notes
181 of a down-up combination should be put closer together. The first two
182 measures are printed with this correction, the last two measures
183 without. The notes in the last two measures form downstem/upstems
184 clumps of notes.
185
186 We hope that these examples serve to show that music typography is a
187 subtle business, and that it requires skill and knowledge to produce
188 good engraving.  It was our challenge to see if we could put such
189 knowledge into a computer program.
190
191
192 @node Music representation
193 @section Music representation
194
195
196 One of the first questions that pop up when you design such a program,
197 is what kind of input the program should expect. Many music notation
198 programs offer a graphical interface that shows notation, and allow
199 you to enter the music by placing notes on a staff. Although this is a
200 obvious way to design a program, from our point of view, this is
201 cheating. After all, the core message of a piece of music notation
202 simply is the music itself. If you start by offering notation to the
203 user, you have already skipped one conversion, even if it perhaps is
204 implicit. If we want to generate music notation from something else,
205 then the obvious candidate for the source should be the music itself.
206
207 Of course, on paper this theory sounds very good. In practice, it
208 opens a can of worms. What really @emph{is} music? Many philosophical
209 treatises must have been written on the subject. Even if you are more
210 practically inclined, you will notice that an enormous number of
211 different ways to represent music in a computer exist, and they are
212 much more incompatible than the formats for wordprocessors and
213 spreadsheets.  Anyone who has tried to exchange data files from
214 between different notation programs can attest to this.
215
216 @cindex music representation
217 @cindex music expressions
218 @cindex input format
219
220 The cause of this problem is that music is inherently two-dimensional:
221 in polyphonic music, notes have time and pitch as their two
222 coordinates, and they often are related in both directions. Computer
223 files on the other hand are essentially one-dimensional: they are a
224 long stream of characters. When you represent music in a file, then
225 you have to flatten this two-dimensional information breaking either
226 timing or pitch relations, and there is no universal agreement on how
227 to do this.
228
229 Luckily, our application has guided us a little with the design of the
230 format: we want to produce a printed score from a music
231 representation.  A music representation is about @emph{music}, so it
232 should be free from notation as much as possible: the format is about
233 pitches and durations, not about symbols and offsets.  Since LilyPond
234 is a compiler, the input format is its user interface, and users have
235 to key in the music into the file directly, requiring that the input
236 format has a friendly syntax. We, as programmers and scientists want a
237 clean formal definition. After all, producing music notation is a
238 difficult problem, and in the scientific world, difficult problems
239 always must be well-specified. Moreover, formally defined formats are
240 easier to write programs for. Finally, enough information should be
241 present to be able to produce a printed score.
242
243 These ideas shaped our music representation which elegantly builds
244 complex musical constructs from simple entities like notes and rests,
245 in much the same way that one builds complex formulae from simple
246 expressions such as numbers and mathematical operators.  The strict
247 separation between musical information and typesetting also gives a
248 blueprint of the program: first it reads the music representation,
249 then it interprets the music---reading it `left-to-right', and
250 translating the musical information to a layout specification. When
251 the layout is computed, the resulting symbols are written to an output
252 file.
253
254
255 @node About this manual
256 @section About this manual
257
258
259
260 As you will notice in the coming pages, and the examples, in a lot of
261 case, the program makes good decisions, and what comes out of lilypond
262 generally looks good. For some specific examples, the default layout
263 of lilypond even is suitable for publication. However, some aspects of
264 the formatting are not yet very good. This gives us programmers
265 inspiration for improving the program. However, most users are more
266 interested in making their printouts look good, and then they have to
267 make manual adjustments to the output.  Another aspect of our system
268 of encoding through ASCII then shows: it can be complicated to fine
269 tune the layout of a piece. There is no graphical user interface,
270 where you can simply click and drag a symbol. On the other hand, if
271 you have written the code for tuning one specific aspect of the
272 layout, then you can simply store the file on disk, retrieve it when
273 you need it: there is no need to remember how you did it.  It's all in
274 the input file. Lilypond also comes with a huge collection of snippets
275 that show all kinds of tricks.
276
277 @cindex snippets
278 @cindex adjusting output
279
280
281 This collection is much needed, because of the way LilyPond is
282 structured. It is a large program, but almost all of the internal
283 functionality is exported: that is, the variables that are internally
284 used to determine formatting of the sheet music are available directly
285 to the user. These are variables to control thicknesses, distances,
286 and other formatting options: there are a huge number of them, and it
287 would be impossible to describe them all in a hand-written
288 manual. There is no need to despair, there is `automatic' manual, that
289 lists all of the variables, symbol types, etc. that are available.  It
290 is directly generated from the definitions that LilyPond itself uses,
291 so it is always up to date. If you are reading this from a screen: it
292 is available from the web, and is included with most binary
293 distributions.  If you're reading this from paper, then we advise you
294 to use the digital version anyway: the hyperlinks make finding topics
295 in the lilypond-internals manual much easier.
296
297 @cindex variables
298 @cindex properties
299 @cindex lilypond-internals
300 @cindex internal documentation 
301
302 For those who really want to get their hands dirty: it is even
303 possible to add your own functionality, by extending LilyPond in the
304 built-in scripting language, a dialect of the powerful programming
305 language Scheme. There is no real distinction between what a user can
306 do and what a programmer is allowed to do.
307
308 @cindex Scheme
309 @cindex extending lilypond
310
311 In short, this manual does not pretend to be exhaustive, but it is
312 merely a guide that tries to explain the most important principles,
313 and shows popular input idioms.  The rest of the manual is structured
314 as follows: it starts with a tutorial that explains how to use
315 lilypond. In the tutorial, a number of fragments of increasing
316 complexity are shown and explained.  Then comes the reference manual,
317 which gives more detailed information on all features of If you're new
318 to lilypond, then you should start reading the tutorial, and
319 experiment for yourself.  If you already have some experience, then
320 you can simply use the manual as reference: there is an extensive
321 index@footnote{If you are looking something, and you can't find it by
322 using the index, that is considered a bug.  In that case, please file
323 a bugreport}
324
325 @cindex bugreport
326 @cindex index
327 @cindex tutorial
328 @cindex overview of manual
329 @cindex idiom
330
331
332