]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/lilypond-overview.doc
release: 1.1.21
[lilypond.git] / Documentation / tex / lilypond-overview.doc
1 %-*-LaTeX-*-
2
3 \documentclass{article}
4 \usepackage{a4}
5 \def\postMudelaExample{\setlength{\parindent}{1em}}
6 \title{LilyPond, a Music Typesetter}
7 \author{HWN}
8 \usepackage{musicnotes}
9 \usepackage{graphics}
10
11
12 \begin{document}
13 \maketitle
14
15 % -*-LaTeX-*-
16 \section{Introduction}
17
18 The Internet has become a popular medium for collaborative work on
19 information.  Its success is partly due to its use of simple, text-based
20 formats.  Examples of these formats are HTML and \LaTeX.  Anyone can
21 produce or modify such files using nothing but a text editor, they are
22 easily processed with run-of-the-mill text tools, and they can be
23 integrated into other text-based formats.
24
25 Software for processing this information and presenting these formats
26 in an elegant form is available freely (Netscape, \LaTeX, etc.).
27 Ubiquitousness of the software and simplicity of the formats have
28 revolutionised the way people publish text-based information
29 nowadays.
30
31 In the field of performed music, where the presentation takes the form
32 of sheet music, such a revolution has not started yet.  Let us review
33 some alternatives that have been available for transmitting sheet
34 music until now:
35 \begin{itemize}
36 \item MIDI\cite{midi}.  This format was designed for interchanging performances
37   of music; one should think of it as a glorified tape recorder
38   format.  It needs dedicated editors, since it is binary.  It does
39   not provide enough information for producing musical scores: some of
40   the abstract musical content of what is performed is thrown away.
41   
42 \item PostScript\cite{Postscript}. This format is a printer control
43   language.  Printed musical scores can be transmitted in PostScript,
44   but once a score is converted to PostScript, it is virtually
45   impossible to modify the score in a meaningful way.
46   
47 \item Formats for various notation programs.  Notation programs either
48   work with binary formats (e.g., NIFF\cite{niff-web}), need specific
49   platforms (e.g., Sibelius\cite{sibelius}, Score\cite{score}), are
50   proprietary or non-portable tools themselves (idem), produce
51   inadequate output (e.g., MUP\cite{mup}), are based on graphical
52   content (e.g., MusixTeX\cite{musixtex1}), or limit themselves to
53   specific subdomains (e.g., ABC\cite{abc2mtex}).
54   
55 \item SMDL\cite{smdl-web}.  This is a very rich ASCII format, that is
56   designed for storing many types of music.  Unfortunately, there is
57   no implementation of a program to print music from SMDL available.
58   Moreover, SMDL is so verbose, that it is not suitable for human
59   production.
60   
61 \item TAB\cite{tablature-web}.  Tab (short for tablature) is a popular
62   format, for interchanging music over e-mail, but it can only be used
63   for guitar music.
64 \end{itemize}
65
66 In summary, sheet music is not published and edited on a wide scale
67 across the internet  because no format for music
68 interchange exists that is:
69 \begin{itemize}
70 \item open, i.e., with publically available specifications.
71 \item based on ASCII, and therefore suitable for human consumption and
72   production.
73 \item rich enough for producing publication quality sheet music from
74   it.
75 \item based on musical content (unlike, for example, PostScript), and
76   therefore suitable for making modifications.
77 \item accompanied by tools for processing it that are freely available
78   across multiple platforms.
79 \end{itemize}
80
81
82 With the creation of LilyPond, we have tried to create both a
83 convenient format for storing sheet music, and a portable,
84 high-quality implementation of a compiler, that compiles the input
85 into a printable score.  You can find a small example of LilyPond
86 input along with output in Figure~\ref{fig:intro-fig}.
87 %
88 \begin{figure}[htbp]
89   \begin{center}
90 \begin{mudela}[verbatim]
91       \score {
92         \notes
93           \type GrandStaff <
94              \transpose c'' { c4 c4 g4 g4 a4 a4 g2 }
95              { \clef "bass"; c4 c'4
96                \type Staff <e'2 {\stemdown c'4 c'4}> f'4 c'4 e'4 c'4 }
97            >
98            \paper { 
99              linewidth = -1.0\cm ;
100            }
101         }      
102 \end{mudela}
103     \caption{A small example of LilyPond input}
104     \label{fig:intro-fig}
105   \end{center}
106 \end{figure}
107 %
108
109  
110 The input language encodes musical events (such as notes and rests) on
111 the basis of their time-ordering.  For example, the grammar includes
112 constructs that specify that notes start simultaneous and that notes
113 are to be played in sequence.  In this encoding some context that is
114 present in sheet music is lost.
115
116 The compiler reconstructs the notation from the encoded music.  Its
117 operation comprises four different steps (see
118 Figure~\ref{fig:intro-steps}).
119
120 \begin{description}
121 \item[Parsing] During parsing, the input is converted in a syntax tree.
122   
123 \item[Interpreting] In the \emph{interpreting} step, it is determined
124   which symbols have to be printed.  Objects that correspond to
125   notation (\emph{Graphical objects}) are created from the syntax tree
126   in this phase. Generally speaking, for every symbol printed there is
127   one graphical object.  These objects are incomplete: their position
128   and their final shape is unknown.
129   
130   The context that was lost by encoding the input in a language is
131   reconstructed during this conversion.
132 \item[Formatting] The next step is determing where symbols are to be
133   placed, this is called \emph{formatting}.
134 \item[Outputting]   
135   Finally, all Graphical objects are outputted as PostScript or \TeX\ code.
136 \end{description}
137
138 \def\staffsym{\vbox to 16pt{
139     \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
140     \vfil
141     \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
142     \vfil
143     \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
144     \vfil
145     \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
146     \vfil
147     \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
148 }}
149
150 \def\vspacer{\vbox to 20pt{\vss}}
151 \begin{figure}[h]
152 \def\spacedhbox#1{\hbox{\ #1\ }}
153 \begin{eqnarray*}
154   {\spacedhbox{Input}\atop \hbox{\texttt{\{c8 c8\}}}} {\spacedhbox{Parsing}\atop\longrightarrow}
155   {\spacedhbox{Syntax tree}\atop\spacedhbox{\textsf{Sequential(Note,Note)}}}
156   {\spacedhbox{Interpreting}\atop\longrightarrow}\\
157   \vspacer\\
158   {\spacedhbox{Graphic objects}\atop\spacedhbox{\texttrebleclef \textquarterhead\texteighthflag\textquarterhead\texteighthflag \staffsym }}
159   {\spacedhbox{Formatting}\atop\longrightarrow}
160   {\spacedhbox{Formatted objects}\atop\hbox{
161     \mudela{c''8 c''8}
162     }}\\
163 \vspacer\\
164   {\spacedhbox{Outputting}\atop\longrightarrow}
165   {\spacedhbox{PostScript code}\atop\hbox{\texttt{\%!PS-Adobe}\ldots}}
166 \end{eqnarray*}
167   \caption{Parsing, Interpreting, Formatting and Outputting}
168     \label{fig:intro-steps}
169 \end{figure}
170
171
172 The second step, the interpretation phase of the compiler, can be
173 manipulated as a separate entity: the interpretation process is
174 composed of many separate modules, and the behaviour of the modules is
175 parameterised.  By recombining these interpretation modules,
176 and changing parameter settings, the same piece of music can be
177 printed differently, as is shown in Figure~\ref{fig:intro-interpret}.
178
179 This makes it easy to extend the program. Moreover, this enables the
180 same music to be printed in different versions, e.g., in a conductors
181 score and in extracted parts.
182
183
184 \begin{figure}[h]
185   \begin{center}
186     \begin{mudela}
187       \score {
188         \notes
189           \type GrandStaff <
190              \transpose c'' { c4 c4 g4 g4 a4 a4 g2 }
191              { \clef "bass"; c4 c'4
192                \type Staff <e'2 {\stemdown c'4 c'4}> f'4 c'4 e'4 c'4 }
193            >
194            \paper { 
195              linewidth = -1.0\cm ;
196              \translator {  
197                 \VoiceContext
198                 \remove "Stem_engraver";
199              }
200            \translator {
201              \StaffContext
202                numberOfStaffLines = 3;
203            }
204           }
205         }
206     \end{mudela}
207     \caption{The interpretation phase can be manipulated: the same
208       music as in Figure~\ref{fig:intro-fig} is interpreted
209       differently: three staff lines and no stems.}
210     \label{fig:intro-interpret}
211   \end{center}
212 \end{figure}
213
214
215
216 \section{Preliminaries}
217
218 To understand the rest of the article, it is necessary to know
219 something about music notation and music typography.  Since both
220 communicate music, we will explain some characteristics of instruments
221 and western music that motivate some notational constructs.
222
223 \subsection{Music}
224
225 Music notation is meant to be read by human performers.  They sing or
226 play instruments that can produce sounds of different pitches.  These
227 sounds are called \emph{notes}. Additionally, the sounds can be
228 articulated in differents ways, e.g., staccato (short and separated)
229 or legato (fluently bound together).  The loudness of the notes can
230 also be varied.  Changes in loudness are called \emph{dynamics}.
231
232 Silence is also an element of music.  The musical terminology for
233 silence within music is \emph{rest}.
234
235 The basic unit of pitch is the \emph{octave}.  The octave corresponds
236 to a frequency ratio of 1:2. For example the pitch denoted by a'
237 (frequency: 440 hertz) is one octave lower than a'' (frequency: 880
238 hertz).  Various instruments have a limited \emph{pitch range}, for
239 example, a trumpet has a range of about 2.5 octaves.  Not all
240 instruments have ranges in the same register: a tuba also has a range
241 of 2.5 octaves, but the range of the tuba is much lower.
242
243 Musicology has a confusing mix of relative and absolute measures for
244 pitches: the term `octave' refers to both a difference between two
245 pitches (the frequency ratio of 1:2), and to a range of pitches.  For
246 example, the term `[eengestreept] octave' refers to the pitch range
247 between 261.6 Hz and 523.3 Hz.
248
249
250 The octave is divided into smaller pitch steps.  In modern western
251 music, every octave is divided into twelve approximately equidistant
252 pitch steps, and each step is called a \emph{semitone}.  Usually, the
253 pitches in a musical piece come from a smaller subset of these twelve
254 possible pitches.  This smaller subset along with the musical
255 functions fo the pitches is called the
256 \emph{tonality}\footnote{Tonality also refers to the relations between
257   and functions of certain pitches.  Since these do not have any
258   impact on notation, we ignore this} of the piece.
259
260
261 The standard tonality that forms the basis of music notation 
262 (the key of C major) is a set of seven pitches within every octave.
263 Each of these seven is denoted by a name. In English, these are names
264 are (in rising pitch) denoted by c, d, e, f, g, a and b.  Pitches that
265 are a semitone higher or lower than one of these seven can be
266 represented by suffixing the name with `sharp' or `flat'
267 respectively (this is called an \emph{chromatic alteration}).
268
269 A pitch therefore can be fully specified by a combination of the
270 octave number, the note name and a chromatic alteration.
271 Figure~\ref{fig:intro-pitches} shows the relation between names and
272 frequencies.
273
274
275
276
277 \begin{figure}[h]
278   \begin{center}
279     [te doen]
280   \end{center}
281   \caption{Pitches in western music.  The octave number is denoted
282     by a superscript.}
283   \label{fig:intro-pitches}
284 \end{figure}
285
286
287 Many instruments can produce more than one note at the same time, e.g.
288 pianos and guitars.  When more notes are played simultaneously, they
289 form a so-called \emph{chord}.
290
291 The unit of duration is the \emph{beat}. When playing, the tempo is
292 determined by setting the number of beats per minute.  In western
293 music, beats are often stressed in a regular pattern: for example
294 Waltzes have a stress pattern that is strong-weak-weak, i.e. every
295 note that starts on a `strong' beat is louder and has more pronounced
296 articulation.  This stress pattern is called \emph{meter}.
297
298 \subsection{Music notation}
299
300 In music notation, sounds and silences are represented by symbols that
301 are called note and rest respectively.\footnote{These names serve a
302   double purpose: the same terms are used to denote the musical
303   concepts.}  The shape of notes and rests indicates their duration
304 (See figure~\ref{noteshapes}) relative to the whole note.
305
306 \begin{figure}[h]
307   \begin{center}
308 \begin{mudela}
309   \score {
310     \notes \transpose c''{ c\longa*1/4 c\breve*1/2 c1 c2 c4 c8 c16 c32 c64 }
311     \paper {
312      \translator {
313        \StaffContext
314        \remove "Staff_symbol_engraver";
315         \remove "Time_signature_engraver";
316         \remove "Bar_engraver";
317         \remove "Clef_engraver";
318  }
319 linewidth = -1.;
320     }
321 }
322 \end{mudela}
323 \begin{mudela}
324   \score {
325     \notes \transpose c''{ r\longa*1/4 r\breve*1/2 r1 r2 r4 r8 r16 r32 r64 }
326     \paper {
327       \translator {
328         \StaffContext
329         \remove "Staff_symbol_engraver";
330         \remove "Time_signature_engraver";
331         \remove "Bar_engraver";
332         \remove "Clef_engraver";
333         }
334       linewidth = -1.;
335     }
336 }
337 \end{mudela}
338     \caption{Note and rest shapes encode the length.  At the top notes
339       are shown, at the bottom rests.  From left to right a quadruple
340       note (\emph{longa}), double (\emph{breve}), whole, half,
341       quarter, eigth, sixteenth, thirtysecond and sixtyfourth. Each
342       note has half of the duration of its predecessor.}
343     \label{fig:noteshapes}
344 \end{center}
345 \end{figure}
346       
347
348 Notes are printed in a grid of horizontal lines called \emph{staff} to
349 denote their pitch: each line represents the pitch of from the 
350
351 \subsection{Music typography}
352
353
354
355
356
357
358
359 \bibliographystyle{hw-plain}
360 \bibliography{engraving,boeken,colorado,computer-notation,other-packages}
361
362
363
364 \end{document}
365
366 The complexity of  music notation was tackled by adopting a modular
367 design: both the formatting system (which encodes the esthetic rules of
368 notation), and the interpretation system (which encodes the semantic
369 rules) are highly modular.
370
371
372 The difficulty in creating a format for music notation is rooted in
373 the fact that music is multi dimensional: each sound has its own
374 duration, pitch, loudness and articulation. Additionally, multiple
375 sounds may be played simultaneously.  Because of this, there is no
376 obvious way to ``flatten'' music into a context-free language.
377
378 The difficulty in creating a printing engine is rooted in the fact
379 that music notation complicated: it is very large graphical
380 ``language'' with many arbitrary esthetic and semantic conventions.
381 Building a system that formats full fledged musical notation is a
382 challenge in itself, regardless of whether it is part of a compiler or
383 an editor.
384
385 The fact that music and its notation are of a different nature,
386 implies that the conversion between input notation is non-trivial.
387
388 In LilyPond we solved the above problem in the following way:
389