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