]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/tex/lilypond-overview.doc
eae2c17b7c20efc56fca77484c35d81f688f534e
[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 [THIS IS WORK IN PROGRESS.  THIS PAPER IS NOT FINISHED]
16
17 % -*-LaTeX-*-
18 \section{Introduction}
19
20 The Internet has become a popular medium for collaborative work on
21 information.  Its success is partly due to its use of simple, text-based
22 formats.  Examples of these formats are HTML and \LaTeX.  Anyone can
23 produce or modify such files using nothing but a text editor, they are
24 easily processed with run-of-the-mill text tools, and they can be
25 integrated into other text-based formats.
26
27 Software for processing this information and presenting these formats
28 in an elegant form is available freely (Netscape, \LaTeX, etc.).
29 Ubiquitousness of the software and simplicity of the formats have
30 revolutionised the way people publish text-based information
31 nowadays.
32
33 In the field of performed music, where the presentation takes the form
34 of sheet music, such a revolution has not started yet.  Let us review
35 some alternatives that have been available for transmitting sheet
36 music until now:
37 \begin{itemize}
38 \item MIDI\cite{midi}.  This format was designed for interchanging performances
39   of music; one should think of it as a glorified tape recorder
40   format.  It needs dedicated editors, since it is binary.  It does
41   not provide enough information for producing musical scores: some of
42   the abstract musical content of what is performed is thrown away.
43   
44 \item PostScript\cite{Postscript}. This format is a printer control
45   language.  Printed musical scores can be transmitted in PostScript,
46   but once a score is converted to PostScript, it is virtually
47   impossible to modify the score in a meaningful way.
48   
49 \item Formats for various notation programs.  Notation programs either
50   work with binary formats (e.g., NIFF\cite{niff-web}), need specific
51   platforms (e.g., Sibelius\cite{sibelius}, Score\cite{score}), are
52   proprietary or non-portable tools themselves (idem), produce
53   inadequate output (e.g., MUP\cite{mup}), are based on graphical
54   content (e.g., MusixTeX\cite{musixtex1}), or limit themselves to
55   specific subdomains (e.g., ABC\cite{abc2mtex}).
56   
57 \item SMDL\cite{smdl-web}.  This is a very rich ASCII format, that is
58   designed for storing many types of music.  Unfortunately, there is
59   no implementation of a program to print music from SMDL available.
60   Moreover, SMDL is so verbose, that it is not suitable for human
61   production.
62   
63 \item TAB\cite{tablature-web}.  Tab (short for tablature) is a popular
64   format, for interchanging music over e-mail, but it can only be used
65   for guitar music.
66 \end{itemize}
67
68 In summary, sheet music is not published and edited on a wide scale
69 across the internet  because no format for music
70 interchange exists that is:
71 \begin{itemize}
72 \item open, i.e., with publically available specifications.
73 \item based on ASCII, and therefore suitable for human consumption and
74   production.
75 \item rich enough for producing publication quality sheet music from
76   it.
77 \item based on musical content (unlike, for example, PostScript), and
78   therefore suitable for making modifications.
79 \item accompanied by tools for processing it that are freely available
80   across multiple platforms.
81 \end{itemize}
82
83
84 With the creation of LilyPond, we have tried to create both a
85 convenient format for storing sheet music, and a portable,
86 high-quality implementation of a compiler, that compiles the input
87 into a printable score.  You can find a small example of LilyPond
88 input along with output in Figure~\ref{fig:intro-fig}.
89 %
90 \begin{figure}[htbp]
91   \begin{center}
92 \begin{mudela}[verbatim]
93       \score {
94         \notes
95           \type GrandStaff <
96              \transpose c'' { c4 c4 g4 g4 a4 a4 g2 }
97              { \clef "bass"; c4 c'4
98                \type Staff <e'2 {\stemdown c'4 c'4}> f'4 c'4 e'4 c'4 }
99            >
100            \paper { 
101              linewidth = -1.0\cm ;
102            }
103         }      
104 \end{mudela}
105     \caption{A small example of LilyPond input}
106     \label{fig:intro-fig}
107   \end{center}
108 \end{figure}
109 %
110
111  
112 The input language encodes musical events (such as notes and rests) on
113 the basis of their time-ordering.  For example, the grammar includes
114 constructs that specify that notes start simultaneous and that notes
115 are to be played in sequence.  In this encoding some context that is
116 present in sheet music is lost.
117
118 The compiler reconstructs the notation from the encoded music.  Its
119 operation comprises four different steps (see
120 Figure~\ref{fig:intro-steps}).
121
122 \begin{description}
123 \item[Parsing] During parsing, the input is converted in a syntax tree.
124   
125 \item[Interpreting] In the \emph{interpreting} step, it is determined
126   which symbols have to be printed.  Objects that correspond to
127   notation (\emph{Graphical objects}) are created from the syntax tree
128   in this phase. Generally speaking, for every symbol printed there is
129   one graphical object.  These objects are incomplete: their position
130   and their final shape is unknown.
131   
132   The context that was lost by encoding the input in a language is
133   reconstructed during this conversion.
134 \item[Formatting] The next step is determing where symbols are to be
135   placed, this is called \emph{formatting}.
136 \item[Outputting]   
137   Finally, all Graphical objects are outputted as PostScript or \TeX\ code.
138 \end{description}
139
140 \def\staffsym{\vbox to 16pt{
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     \vfil
149     \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
150 }}
151
152 \def\vspacer{\vbox to 20pt{\vss}}
153 \begin{figure}[h]
154 \def\spacedhbox#1{\hbox{\ #1\ }}
155 \begin{eqnarray*}
156   {\spacedhbox{Input}\atop \hbox{\texttt{\{c8 c8\}}}} {\spacedhbox{Parsing}\atop\longrightarrow}
157   {\spacedhbox{Syntax tree}\atop\spacedhbox{\textsf{Sequential(Note,Note)}}}
158   {\spacedhbox{Interpreting}\atop\longrightarrow}\\
159   \vspacer\\
160   {\spacedhbox{Graphic objects}\atop\spacedhbox{\texttrebleclef \textquarterhead\texteighthflag\textquarterhead\texteighthflag \staffsym }}
161   {\spacedhbox{Formatting}\atop\longrightarrow}
162   {\spacedhbox{Formatted objects}\atop\hbox{
163     \mudela{c''8 c''8}
164     }}\\
165 \vspacer\\
166   {\spacedhbox{Outputting}\atop\longrightarrow}
167   {\spacedhbox{PostScript code}\atop\hbox{\texttt{\%!PS-Adobe}\ldots}}
168 \end{eqnarray*}
169   \caption{Parsing, Interpreting, Formatting and Outputting}
170     \label{fig:intro-steps}
171 \end{figure}
172
173
174 The second step, the interpretation phase of the compiler, can be
175 manipulated as a separate entity: the interpretation process is
176 composed of many separate modules, and the behaviour of the modules is
177 parameterised.  By recombining these interpretation modules,
178 and changing parameter settings, the same piece of music can be
179 printed differently, as is shown in Figure~\ref{fig:intro-interpret}.
180
181 This makes it easy to extend the program. Moreover, this enables the
182 same music to be printed in different versions, e.g., in a conductors
183 score and in extracted parts.
184
185
186 \begin{figure}[h]
187   \begin{center}
188     \begin{mudela}
189       \score {
190         \notes
191           \type GrandStaff <
192              \transpose c'' { c4 c4 g4 g4 a4 a4 g2 }
193              { \clef "bass"; c4 c'4
194                \type Staff <e'2 {\stemdown c'4 c'4}> f'4 c'4 e'4 c'4 }
195            >
196            \paper { 
197              linewidth = -1.0\cm ;
198              \translator {  
199                 \VoiceContext
200                 \remove "Stem_engraver";
201              }
202            \translator {
203              \StaffContext
204                numberOfStaffLines = 3;
205            }
206           }
207         }
208     \end{mudela}
209     \caption{The interpretation phase can be manipulated: the same
210       music as in Figure~\ref{fig:intro-fig} is interpreted
211       differently: three staff lines and no stems.}
212     \label{fig:intro-interpret}
213   \end{center}
214 \end{figure}
215
216
217
218 \section{Preliminaries}
219
220 To understand the rest of the article, it is necessary to know
221 something about music notation and music typography.  Since both
222 communicate music, we will explain some characteristics of instruments
223 and western music that motivate some notational constructs.
224
225 \subsection{Music}
226
227 Music notation is meant to be read by human performers.  They sing or
228 play instruments that can produce sounds of different pitches.  These
229 sounds are called \emph{notes}. Additionally, the sounds can be
230 articulated in differents ways, e.g., staccato (short and separated)
231 or legato (fluently bound together).  The loudness of the notes can
232 also be varied.  Changes in loudness are called \emph{dynamics}.
233
234 Silence is also an element of music.  The musical terminology for
235 silence within music is \emph{rest}.
236
237 The basic unit of pitch is the \emph{octave}.  The octave corresponds
238 to a frequency ratio of 1:2. For example the pitch denoted by a'
239 (frequency: 440 hertz) is one octave lower than a'' (frequency: 880
240 hertz).  Various instruments have a limited \emph{pitch range}, for
241 example, a trumpet has a range of about 2.5 octaves.  Not all
242 instruments have ranges in the same register: a tuba also has a range
243 of 2.5 octaves, but the range of the tuba is much lower.
244
245 Musicology has a confusing mix of relative and absolute measures for
246 pitches: the term `octave' refers to both a difference between two
247 pitches (the frequency ratio of 1:2), and to a range of pitches.  For
248 example, the term `[eengestreept] octave' refers to the pitch range
249 between 261.6 Hz and 523.3 Hz.
250
251
252 The octave is divided into smaller pitch steps.  In modern western
253 music, every octave is divided into twelve approximately equidistant
254 pitch steps, and each step is called a \emph{semitone}.  Usually, the
255 pitches in a musical piece come from a smaller subset of these twelve
256 possible pitches.  This smaller subset along with the musical
257 functions fo the pitches is called the
258 \emph{tonality}\footnote{Tonality also refers to the relations between
259   and functions of certain pitches.  Since these do not have any
260   impact on notation, we ignore this} of the piece.
261
262
263 The standard tonality that forms the basis of music notation 
264 (the key of C major) is a set of seven pitches within every octave.
265 Each of these seven is denoted by a name. In English, these are names
266 are (in rising pitch) denoted by c, d, e, f, g, a and b.  Pitches that
267 are a semitone higher or lower than one of these seven can be
268 represented by suffixing the name with `sharp' or `flat'
269 respectively (this is called an \emph{chromatic alteration}).
270
271 A pitch therefore can be fully specified by a combination of the
272 octave number, the note name and a chromatic alteration.
273 Figure~\ref{fig:intro-pitches} shows the relation between names and
274 frequencies.
275
276
277
278
279 \begin{figure}[h]
280   \begin{center}
281     [te doen]
282   \end{center}
283   \caption{Pitches in western music.  The octave number is denoted
284     by a superscript.}
285   \label{fig:intro-pitches}
286 \end{figure}
287
288
289 Many instruments can produce more than one note at the same time, e.g.
290 pianos and guitars.  When more notes are played simultaneously, they
291 form a so-called \emph{chord}.
292
293 The unit of duration is the \emph{beat}. When playing, the tempo is
294 determined by setting the number of beats per minute.  In western
295 music, beats are often stressed in a regular pattern: for example
296 Waltzes have a stress pattern that is strong-weak-weak, i.e. every
297 note that starts on a `strong' beat is louder and has more pronounced
298 articulation.  This stress pattern is called \emph{meter}.
299
300 \subsection{Music notation}
301
302 Music notation is a system that tries to represent musical ideas
303 through printed symbols.  Music notation has no precise definition,
304 but most conventions have described in reference manuals on music
305 notation\cite{read-notation}.
306
307 In music notation, sounds and silences are represented by symbols that
308 are called note and rest respectively.\footnote{These names serve a
309   double purpose: the same terms are used to denote the musical
310   concepts.}  The shape of notes and rests indicates their duration
311 (See figure~\ref{noteshapes}) relative to the whole note.
312
313 \begin{figure}[h]
314   \begin{center}
315 \begin{mudela}
316   \score {
317     \notes \transpose c''{ c\longa*1/4 c\breve*1/2 c1 c2 c4 c8 c16 c32 c64 }
318     \paper {
319      \translator {
320        \StaffContext
321        \remove "Staff_symbol_engraver";
322         \remove "Time_signature_engraver";
323         \remove "Bar_engraver";
324         \remove "Clef_engraver";
325  }
326 linewidth = -1.;
327     }
328 }
329 \end{mudela}
330 \begin{mudela}
331   \score {
332     \notes \transpose c''{ r\longa*1/4 r\breve*1/2 r1 r2 r4 r8 r16 r32 r64 }
333     \paper {
334       \translator {
335         \StaffContext
336         \remove "Staff_symbol_engraver";
337         \remove "Time_signature_engraver";
338         \remove "Bar_engraver";
339         \remove "Clef_engraver";
340         }
341       linewidth = -1.;
342     }
343 }
344 \end{mudela}
345     \caption{Note and rest shapes encode the length.  At the top notes
346       are shown, at the bottom rests.  From left to right a quadruple
347       note (\emph{longa}), double (\emph{breve}), whole, half,
348       quarter, eigth, sixteenth, thirtysecond and sixtyfourth. Each
349       note has half of the duration of its predecessor.}
350     \label{fig:noteshapes}
351 \end{center}
352 \end{figure}
353
354 Notes are printed in a grid of horizontal lines called \emph{staff} to
355 denote their pitch: each line represents the pitch of from the
356 standard scale (c, d, e, f, g, a, b).  The reference point is the
357 \emph{clef}, eg., the treble clef marks the location of the $g^1$
358 pitch.  The notes are printed in their time order, from left to right.
359
360
361 \begin{figure}[h]
362   \begin{center}
363     \begin{mudela}
364       \score { \notes {
365       a4 b c d e f g a \clef bass;
366       a4 b c d e f g a \clef alto;
367       a4 b c d e f g a \clef treble;
368       }
369       \paper { linewidth = 15.\cm; }
370       }
371     \end{mudela}
372     \caption{Pitches ranging from $a, b, c',\ldots a'$, in different
373       clefs.  From left right the bass, alto and treble clef are
374       featured.}
375     \label{fig:pitches}
376   \end{center}
377 \end{figure}
378
379 The chromatic alterations are indicated by printing a flat sign or a
380 sharp sign in front of the note head.  If these chromatic alterations
381 occur systematically (if they are part of the tonality of the piece),
382 then this indicated with a \emph{key signature}.  This is a list of
383 sharp/flat signs which is printed next to the clef.
384
385 Articulation is notated by marking the note shapes wedges, hats and
386 dots all indicate specific articulations.  If the notes are to be
387 bound fluently (legato), the note shapes are encompassed by a smooth
388 curve called \emph{slur},
389
390 \begin{figure}[h]
391   \begin{center}
392     \begin{mudela}
393       c'4-> c'4-. g'4 ( b'4  ) g''4
394     \end{mudela}
395     \caption{Some articulations.  From left to right: extra stress
396       (\emph{marcato}), short (staccato), slurred notes (legato).}
397     \label{fig:articulation}
398   \end{center}
399 \end{figure}
400
401
402
403 Dynamics are notated in two ways: absolute dynamics are indicated by
404 letters: \textbf{f} (from Italian ``forte'') stands for loud,
405 \textbf{p} (from Italian ``piano'') means soft.  Gradual changes in
406 loudness are notated by (de)crescendos.  These are hairpin like shapes
407 below the staff.
408
409 \begin{figure}[h]
410   \begin{center}
411     \begin{mudela}
412       g'4\pp \<  g'4 \! g'4 \ff \> g'4 g' \! g'\ppp
413     \end{mudela}
414     \caption{Dynamics: start very soft (pp), grow to loud (ff) and
415       decrease to extremely soft (ppp)}
416     \label{fig:dynamics}
417   \end{center}
418 \end{figure}
419
420
421 The meter is indicated by barlines: every start of the stress pattern
422 is preceded by a vertical line, the \emph{bar line}.  The space
423 between two bar lines is called measure.  It is therefore the unit of
424 the rhythmic pattern.
425
426 The time signature also indicates what kind of rhythmic pattern is
427 desired.  The time signature takes the form of two numbers stacked
428 vertically. The top number is the number of beats in one measure, the
429 bottom number is the duration (relative to the whole note) of the note
430 that takes  one beat.  Example: 2/4  time signature means ``two beats
431 per measure, and a quarter note takes one beat''
432
433 Chords are written by attaching multiple note heads to one stem.  When
434 the composer wants to emphasize the horizontal relationships between
435 notes, the simultaneous notes can be written as voices (where every
436 note head has its own stem).  A small example is given in
437 Figure~\ref{fig:simultaneous}.
438
439 \begin{figure}[h]
440   \begin{center}
441     \begin{mudela}
442       \relative c'' {\time 2/4;  <c4 e> <d f>
443                 \type Staff < \type Voice = VA{
444                   \stemdown
445                   c4 d
446                   b16 b b b b b b b }
447                 \type Voice = VB {
448                   \stemup e4 f g8 g4 g8 } >
449           }
450     \end{mudela}
451     \caption{Notes sounding together.  Chord notation (left, before
452       the bar line) emphasizes vertical relations, voice notation
453       emphasizes horizontal relations. Separate voices needn't have
454       synchronous rhythms (third measure). 
455       }
456     \label{fig:simultaneous}
457   \end{center}
458 \end{figure}
459
460 Separate voices do not have to share one rhythmic pattern---this is
461 also demonstrated in Figure~\ref{fig:simultaneous}--- they are in a sense%vaag
462 independent.  A different way to express this in notation, is by
463 printing each voice on a different staff.  This is customary when
464 writing for piano (both left and right hand have a staff of their own)
465 and for ensemble (every instrument has a staff of its own).
466
467
468
469 \subsection{Music typography}
470
471 Music typography is the art of placing symbols in esthetically
472 pleasing configuration.  Little is explicitly known about music
473 typography.  There are only a few reference works
474 available\cite{ross,wanske}.  Most of the knowledge of this art has
475 been transmitted verbally, and was subsequently lost.
476
477 The motivation behind choices in typography is to represent the idea
478 as clearly as possible. Among others, this results in the following
479 guidelines:
480 \begin{itemize}
481 \item The printed score should use visual hints to accentuate the
482   musical content
483 \item The printed score should not contain distracting elements, such
484   as large empty regions or blotted regions.
485 \end{itemize}
486
487 An example of the first guideline in action is the horizontal spacing.
488 The amount of space following a note should reflect the duration of
489 that note: short notes get a small amount of space, long notes larger
490 amounts.  Such spacing constraints can be quite subtle, for the
491 ``amount of space'' is only the impression that should be conveyed; there
492 has to be some correction for optical illusions.  See
493 Figure~\ref{fig:spacing}.
494
495 \begin{figure}[h]
496   \begin{center}
497     \begin{mudela}
498       \relative c'' { \time 3/4; c16 c c c c8 c8 | f4 f, f'  }
499     \end{mudela}
500     \caption{Spacing conveys information about duration. Sixteenth
501       notes at the left get less space than quarter notes in the
502       middle. Spacing is ``visual'', there should be more space
503       after  the first note of the last measure, and  less after second. }
504     \label{fig:spacing}
505   \end{center}
506 \end{figure}
507
508 Another clearly visible example of music typography is visible in
509 collisions.  When chords or separate voices are printed, the notes
510 that start at the same time should be printed aligned (ie., with the
511 same $x$ position).  If the pitches are close to each other, the note
512 heads would collide. To prevent this, some notes (or note heads) have
513 to be shifted horizontally.  An example of this is given in Figure~\ref{fig:collision}.
514 \begin{figure}[h]
515   \begin{center}
516     \begin{mudela}
517       c4
518     \end{mudela}
519     \caption{Collisions}
520     \label{fig:collision}
521   \end{center}
522 \end{figure}
523
524 \bibliographystyle{hw-plain}
525 \bibliography{engraving,boeken,colorado,computer-notation,other-packages}
526
527
528
529 \end{document}
530
531 The complexity of  music notation was tackled by adopting a modular
532 design: both the formatting system (which encodes the esthetic rules of
533 notation), and the interpretation system (which encodes the semantic
534 rules) are highly modular.
535
536
537 The difficulty in creating a format for music notation is rooted in
538 the fact that music is multi dimensional: each sound has its own
539 duration, pitch, loudness and articulation. Additionally, multiple
540 sounds may be played simultaneously.  Because of this, there is no
541 obvious way to ``flatten'' music into a context-free language.
542
543 The difficulty in creating a printing engine is rooted in the fact
544 that music notation complicated: it is very large graphical
545 ``language'' with many arbitrary esthetic and semantic conventions.
546 Building a system that formats full fledged musical notation is a
547 challenge in itself, regardless of whether it is part of a compiler or
548 an editor.
549
550 The fact that music and its notation are of a different nature,
551 implies that the conversion between input notation is non-trivial.
552
553 In LilyPond we solved the above problem in the following way:
554