3 \documentclass{article}
5 \def\postMudelaExample{\setlength{\parindent}{1em}}
6 \title{LilyPond, a Music Typesetter}
8 \usepackage{musicnotes}
15 [THIS IS WORK IN PROGRESS. THIS PAPER IS NOT FINISHED]
18 \section{Introduction}
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.
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
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
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.
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.
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}).
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
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
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:
72 \item open, i.e., with publically available specifications.
73 \item based on ASCII, and therefore suitable for human consumption and
75 \item rich enough for producing publication quality sheet music from
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.
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}.
92 \begin{mudela}[verbatim]
96 \transpose c'' { c4 c4 g4 g4 a4 a4 g2 }
97 { \clef "bass"; c4 c'4
98 \context Staff <e'2 {\stemdown c'4 c'4}> f'4 c'4 e'4 c'4 }
101 linewidth = -1.0\cm ;
105 \caption{A small example of LilyPond input}
106 \label{fig:intro-fig}
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.
118 The compiler reconstructs the notation from the encoded music. Its
119 operation comprises four different steps (see
120 Figure~\ref{fig:intro-steps}).
123 \item[Parsing] During parsing, the input is converted in a syntax tree.
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.
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}.
137 Finally, all Graphical objects are outputted as PostScript or \TeX\ code.
140 \def\staffsym{\vbox to 16pt{
141 \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
143 \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
145 \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
147 \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
149 \hbox{\vrule width 1cm depth .2pt height .2pt}\nointerlineskip
152 \def\vspacer{\vbox to 20pt{\vss}}
154 \def\spacedhbox#1{\hbox{\ #1\ }}
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}\\
160 {\spacedhbox{Graphic objects}\atop\spacedhbox{\texttrebleclef \textquarterhead\texteighthflag\textquarterhead\texteighthflag \staffsym }}
161 {\spacedhbox{Formatting}\atop\longrightarrow}
162 {\spacedhbox{Formatted objects}\atop\hbox{
166 {\spacedhbox{Outputting}\atop\longrightarrow}
167 {\spacedhbox{PostScript code}\atop\hbox{\texttt{\%!PS-Adobe}\ldots}}
169 \caption{Parsing, Interpreting, Formatting and Outputting}
170 \label{fig:intro-steps}
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}.
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.
191 \context GrandStaff <
192 \transpose c'' { c4 c4 g4 g4 a4 a4 g2 }
193 { \clef "bass"; c4 c'4
194 \context Staff <e'2 {\stemdown c'4 c'4}> f'4 c'4 e'4 c'4 }
197 linewidth = -1.0\cm ;
200 \remove "Stem_engraver";
204 numberOfStaffLines = 3;
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}
218 \section{Preliminaries}
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.
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}.
234 Silence is also an element of music. The musical terminology for
235 silence within music is \emph{rest}.
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.
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.
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.
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}).
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
283 \caption{Pitches in western music. The octave number is denoted
285 \label{fig:intro-pitches}
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}.
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}.
300 \subsection{Music notation}
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}.
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.
317 \notes \transpose c''{ c\longa*1/4 c\breve*1/2 c1 c2 c4 c8 c16 c32 c64 }
321 \remove "Staff_symbol_engraver";
322 \remove "Time_signature_engraver";
323 \remove "Bar_engraver";
324 \remove "Clef_engraver";
332 \notes \transpose c''\context Staff { r\longa*1/4 r\breve*1/2 r1 r2 r4 r8 r16 r32 r64 }
336 \remove "Staff_symbol_engraver";
337 \remove "Time_signature_engraver";
338 \remove "Bar_engraver";
339 \remove "Clef_engraver";
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}
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.
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;
369 \paper { linewidth = 15.\cm; }
372 \caption{Pitches ranging from $a, b, c',\ldots a'$, in different
373 clefs. From left right the bass, alto and treble clef are
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.
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},
393 c'4-> c'4-. g'4 ( b'4 ) g''4
395 \caption{Some articulations. From left to right: extra stress
396 (\emph{marcato}), short (staccato), slurred notes (legato).}
397 \label{fig:articulation}
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
412 g'4\pp \< g'4 \! g'4 \ff \> g'4 g' \! g'\ppp
414 \caption{Dynamics: start very soft (pp), grow to loud (ff) and
415 decrease to extremely soft (ppp)}
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.
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''
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}.
442 \relative c'' {\time 2/4; <c4 e> <d f>
443 \context Staff < \context Voice = VA{
447 \context Voice = VB {
448 \stemup e4 f g8 g4 g8 } >
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).
456 \label{fig:simultaneous}
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).
469 \subsection{Music typography}
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.
477 The motivation behind choices in typography is to represent the idea
478 as clearly as possible. Among others, this results in the following
481 \item The printed score should use visual hints to accentuate the
483 \item The printed score should not contain distracting elements, such
484 as large empty regions or blotted regions.
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}.
498 \relative c'' { \time 3/4; c16 c c c c8 c8 | f4 f, f' }
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. }
508 Another example of music typography is clearly visible in collisions.
509 When chords or separate voices are printed, the notes that start at
510 the same time should be printed aligned (ie., with the same $x$
511 position). If the pitches are close to each other, the note heads
512 would collide. To prevent this, some notes (or note heads) have to be
513 shifted horizontally. An example of this is given in
514 Figure~\ref{fig:collision}.
519 \label{fig:collision}
523 \bibliographystyle{hw-plain}
524 \bibliography{engraving,boeken,colorado,computer-notation,other-packages}
526 \section{Requirements}
533 The input format consists of combining a symbolic representation of
534 music with style sheet that describes how the symbolic presentation
535 can converted to notation. The symbolic representation is based on a
536 context free language called \textsf{music}. Music is a recursively
537 defined construction in the input language. It can be constructed by
538 combining lists of \textsf{music} sequentially or parallel or from
539 terminals like notes or lyrics.
541 The grammar for \textsf{music} is listed below. It has been edited to
542 leave out the syntactic and ergonomic details.
546 Music: & SimpleMusic\\
547 & $|$ REPEATED int Music ALTERNATIVE MusicList\\
548 & $|$ SIMULTANEOUS MusicList\\
549 & $|$ SEQUENTIAL MusicList\\
550 & $|$ CONTEXT STRING '=' STRING Music\\
551 & $|$ TIMES int int Music \\
552 & $|$ TRANSPOSE PITCH Music \\
553 SimpleMusic: & $|$ Note\\
558 Command: & METERCHANGE\\
560 &$|$ PROPERTY STRING '=' STRING\\
561 Chord: &PitchList DURATION\\
562 Rest: &REST DURATION\\
563 Lyric: &STRING DURATION\\
564 Note: &PITCH DURATION\\
568 The terminals are both purely musical concepts that have a duration,
569 and take a non-zero amount of musical time, like notes and lyrics, and
570 commands that behave as if they have no duration.\footnote{The
571 PROPERTY command is a generic mechanism for controlling the
572 interpretation, i.e. the musical style sheets. See [forward ref]}
574 The nonterminal productions can
576 \item Some productions combine multiple elements: one can specify that
577 element are to be played in sequence, simultaneously or repetitively.
578 \item There are productions for transposing music, and for dilating
579 durations of music: the TIMES production can be used to encode a
580 triplet.\footnote{A triplet is a group of three notes marked by a
581 bracket, that are played 3/2 times faster.}
583 There are productions that give directions to the interpretation
584 engine (the CONTEXT production)
588 \section{Context in notation}
590 \section{Interpretation context}
599 The complexity of music notation was tackled by adopting a modular
600 design: both the formatting system (which encodes the esthetic rules of
601 notation), and the interpretation system (which encodes the semantic
602 rules) are highly modular.
605 The difficulty in creating a format for music notation is rooted in
606 the fact that music is multi dimensional: each sound has its own
607 duration, pitch, loudness and articulation. Additionally, multiple
608 sounds may be played simultaneously. Because of this, there is no
609 obvious way to ``flatten'' music into a context-free language.
611 The difficulty in creating a printing engine is rooted in the fact
612 that music notation complicated: it is very large graphical
613 ``language'' with many arbitrary esthetic and semantic conventions.
614 Building a system that formats full fledged musical notation is a
615 challenge in itself, regardless of whether it is part of a compiler or
618 The fact that music and its notation are of a different nature,
619 implies that the conversion between input notation is non-trivial.
621 In LilyPond we solved the above problem in the following way: