1 @c -*- coding: utf-8; mode: texinfo; -*-
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
13 @chapter Music engraving
15 This section covers the overall goals and architecture of
19 @c remove 3mm eps bounding box left padding for Sarabande (This will
20 @c require adding a new snippet option to lilypond-book.py
21 @c check formatting of HTML output
25 @c Incorrect beaming in the Sarabande is a known bug.
28 * The LilyPond story::
30 * Automated engraving::
31 * What symbols to engrave?::
32 * Music representation::
33 * Example applications::
37 @node The LilyPond story
38 @unnumberedsec The LilyPond story
40 Before LilyPond had a community of users around the world, before it had
41 been used to produce university course notes or world-premier opera
42 performance scores, before there was an essay on music engraving or any
43 computer code or even an organized team of developers, LilyPond began
47 Why does most computer output fail to achieve the beauty and balance of
48 a hand-engraved score?
52 Some of the answers can be found by examining the two scores
57 on the following pages.
59 The first score is a beautiful hand-engraved score from 1950 and the
60 second is a modern, computer-engraved edition.
64 Bärenreiter BA 320, @copyright{}1950:
66 @sourceimage{baer-suite1-fullpage,,,png}
69 Henle no. 666, @copyright{}2000:
71 @sourceimage{henle-suite1-fullpage,,,png}
74 The notes here are identical, taken from Bach's first Suite for solo
75 cello, but the appearance is different, especially if you print them out
76 and view them from a distance.
78 (The PDF version of this manual has high-resolution images suitable for
81 Try reading or playing from each of the scores and you will find that
82 the hand-engraved score is more enjoyable to use. It has flowing lines
83 and movement, and it feels like a living, breathing piece of music,
84 while the newer edition seems cold and mechanical.
86 It is kind of hard to immediately see what makes the difference with the
87 newer edition. Everything looks neat and tiny, possibly even @qq{better}
88 because it looks more computerized and uniform. This really puzzled us
89 for quite a while. We wanted to improve computer notation, but we first
90 had to figure out what was wrong with it.
92 The answer lies in the precise, mathematical uniformity of the newer
93 edition. Find the bar line in the middle of each line: in the
94 hand-engraved score the position of these bar lines has some
95 natural variation, while in the newer version they line up almost
96 perfectly. This is shown in these simplified page layout diagrams,
97 traced from the hand-engraved (left) and computer-generated music
102 @sourceimage{pdf/page-layout-comparison,,,}
105 @sourceimage{page-layout-comparison,,,png}
110 In the computer-generated output, even the individual note heads are
111 aligned in vertical columns, making the contour of the melody disappear
112 into a rigid grid of musical markings.
114 There are other differences as well: in the hand-engraved edition the
115 vertical lines are all stronger, the slurs lie closer to the note heads,
116 and there is more visual variety in the placement of the beams. Although
117 such details may seem like nitpicking, the result is a score that is
118 easier to read. In the computer-generated output, each line is nearly
119 identical and if the musician looks away for a moment, she will be lost
122 LilyPond was designed to solve the problems we found in existing
123 software and to create beautiful music that mimics the finest
124 hand-engraved scores. Along the way, we have learned a great deal about
125 the work that goes into a well-engraved score. In this essay we describe
126 several of those aspects that we have tried to imitate in LilyPond.
131 Bärenreiter BA 320, @copyright{}1950:
133 @sourceimage{baer-suite1-fullpage,16cm,,}
136 Henle no. 666, @copyright{}2000:
138 @sourceimage{henle-suite1-fullpage,16cm,,}
142 @node Engraving details
143 @unnumberedsec Engraving details
146 @cindex typography, music
147 @cindex music typography
148 @cindex plate engraving
149 @cindex music engraving
151 The art of music typography is called @emph{(plate) engraving}, a term
152 that derives from the manual process of music printing@footnote{Early
153 European printers explored several processes, including hand-carved
154 wooden blocks, movable type, and engraved sheets of thin metal.
155 Typesetting had the advantage of being more easily corrected and
156 facilitating the inclusion of text and lyrics, but only engraving
157 offered the ability to do unimpeded layout and unanticipated notation.
158 In the end, hand-engraved scores became the standard for all printed
159 music, with the exception of some hymnals and songbooks where
160 typesetting was justified by its ease and economy, even into the
161 twentieth century.}. Just a few decades ago, sheet music was made by
162 cutting and stamping the music into a zinc or pewter plate in mirror
163 image. The plate would be inked, and the depressions caused by the
164 cutting and stamping would hold ink. An image was formed by pressing
165 paper to the plate. The stamping and cutting was done completely by hand
166 and making a correction was cumbersome, so the engraving had to be
167 nearly perfect in one go. Engraving was a highly specialized skill; a
168 craftsman had to complete around five years of training before earning
169 the title of master engraver, and another five years of experience were
170 necessary to become truly skilled.
174 @sourceimage{hader-slaan,,7cm,}
177 @sourceimage{hader-slaan,,,jpg}
181 LilyPond is inspired by traditional manual engravings published by
182 European music publishers in and towards the end of the first half of
183 the twentieth century, including Bärenreiter, Duhem, Durand,
184 Hofmeister, Peters, and Schott. This is sometimes regarded as the peak
185 of traditional musical engraving practice.
187 @c Now all newly printed music is produced with computers. This has
188 @c obvious advantages: prints are cheaper to make, editorial work can be
189 @c delivered by email, and the original data can be easily stored.
190 @c Unfortunately, computer-generated scores rarely match the quality of
191 @c hand-engraved scores. Instead, computer printouts have a bland,
192 @c mechanical look, which makes them unpleasant to play from.
199 * Why work so hard?::
203 @unnumberedsubsec Music fonts
205 The images below illustrate some differences between traditional
206 engraving and typical computer output. The left picture shows a scan of
207 a flat symbol from a hand-engraved Bärenreiter edition, while the right
208 picture depicts a symbol from an edition of the same music published in
209 2000. Although both images are printed in the same shade of ink, the
210 earlier version looks darker: the staff lines are heavier, and the
211 Bärenreiter flat has a bold, almost voluptuous rounded look. The right
212 scan, on the other hand, has thinner lines and a straight layout with
215 @multitable @columnfractions .25 .25 .25 .25
219 @sourceimage{baer-flat-gray,,4cm,}
222 @sourceimage{baer-flat-gray,,,png}
227 @sourceimage{henle-flat-gray,,4cm,}
230 @sourceimage{henle-flat-gray,,,png}
235 @sourceimage{henle-flat-bw,,,png}
236 @sourceimage{baer-flat-bw,,,png}
237 @sourceimage{lily-flat-bw,,,png}
248 @cindex musical symbols
253 When we wanted to write a computer program to create music typography,
254 there were no musical fonts freely available that could match the
255 elegance of our favorite scores. Undeterred, we created a font of
256 musical symbols, relying on nice printouts of hand-engraved music. The
257 experience helped develop a typographical taste, and it made us
258 appreciate subtle design details. Without that experience, we would not
259 have realized how ugly the fonts were that we admired at first.
261 Below is a sample of two music fonts: the upper set is the default font
262 in the Sibelius software (the @emph{Opus} font), and the lower set is
263 our own LilyPond font.
267 @sourceimage{pdf/OpusAndFeta,,,}
270 @sourceimage{OpusAndFeta,,,png}
274 The LilyPond symbols are heavier and their weight is more consistent,
275 which makes them easier to read. Fine endings, such as the ones on the
276 sides of the quarter rest, should not end in sharp points, but rather
277 in rounded shapes. This is because sharp corners of the punching dies
278 are fragile and quickly wear out when stamping in metal. Taken together,
279 the blackness of the font must be carefully tuned together with the
280 thickness of lines, beams and slurs to give a strong yet balanced
283 Also, notice that our half-note head is not elliptic but slightly diamond
284 shaped. The vertical stem of a flat symbol is slightly brushed, becoming
285 wider at the top. The sharp and the natural are easier to distinguish
286 from a distance because their angled lines have different slopes and the
287 vertical strokes are heavier.
289 @node Optical spacing
290 @unnumberedsubsec Optical spacing
292 In spacing, the distribution of space should reflect the durations
293 between notes. However, as we saw in the Bach Suite above, many modern
294 scores adhere to the durations with mathematical precision, which leads
295 to poor results. In the next example a motive is printed twice: the
296 first time using exact mathematical spacing, and the second with
297 corrections. Which do you prefer?
299 @cindex optical spacing
320 \override NoteSpacing #'stem-spacing-correction = #0.0
321 \override NoteSpacing #'same-direction-correction = #0.0
322 \override StaffSpacing #'stem-spacing-correction = #0.0
348 \override NoteSpacing #'stem-spacing-correction = #0.6
354 @cindex regular rhythms
355 @cindex regular spacing
356 @cindex spacing, regular
358 Each bar in the fragment only uses notes that are played in a constant
359 rhythm. The spacing should reflect that. Unfortunately, the eye deceives
360 us a little; not only does it notice the distance between note heads, it
361 also takes into account the distance between consecutive stems. As a
362 result, the notes of an up-stem/@/down-stem combination should be put
363 farther apart, and the notes of a down-stem/@/up-stem combination should
364 be put closer together, all depending on the combined vertical positions
365 of the notes. The lower two measures are printed with this correction,
366 the upper two measures, however, form down-stem/@/up-stem clumps of
367 notes. A master engraver would adjust the spacing as needed to please
370 Another example of optical spacing is the visual interplay between the
371 stems and the bar lines. When an up-stem precedes the bar line, a little
372 more space is needed to keep it from feeling crowded:
381 c''8 c'' c'' c'' c'' c'' c'' c'' \break
382 a' a' a' a' a' a' a' a'
387 \remove "Time_signature_engraver"
388 \override NoteSpacing #'stem-spacing-correction = #0.7
392 \remove "Bar_number_engraver"
399 @unnumberedsubsec Ledger lines
404 Ledger lines present a typographical challenge: they make it more
405 difficult to space musical symbols close together and they must be clear
406 enough to identify the pitch at a glance. In the example below, we see
407 that ledger lines should be thicker than normal staff lines and that an
408 expert engraver will shorten a ledger line to allow closer spacing with
409 accidentals. We have included this feature in LilyPond's engraving.
411 @multitable @columnfractions .25 .25 .25 .25
415 @sourceimage{baer-ledger,3cm,,}
418 @sourceimage{baer-ledger,,,png}
424 @sourceimage{lily-ledger,3cm,,}
427 @sourceimage{lily-ledger,,,png}
434 @unnumberedsubsec Optical sizing
436 Music may need to be printed in a range of sizes. Originally, this was
437 accomplished by creating punching dies in each of the required sizes,
438 which meant that each die was designed to look its best at that size.
439 With the advent of digital fonts, a single outline can be mathematically
440 scaled to any size, which is very convenient, but at the smaller sizes
441 the glyphs will appear very light.
443 In LilyPond, we have created fonts in a range of weights, corresponding
444 to a range of music sizes. This is a LilyPond engraving at staff size
449 @sourceimage{pdf/size26,,23mm,}
452 @sourceimage{size26,,,png}
457 and this is the same engraving set at staff size 11, then
458 magnified by 236% to print at the same size as the previous example:
462 @sourceimage{pdf/size11,,23mm,}
465 @sourceimage{size11,,,png}
470 At smaller sizes, LilyPond uses proportionally heavier lines so the
471 music will still read well.
474 This also allows staves of different sizes to coexist peacefully when
475 used together on the same page:
477 @c TODO: are the stems in this example the right thickness? How should
478 @c line weights be scaled for small staves?
480 @c Grieg's Violin Sonata Op. 45
481 @lilypond[indent=1.5cm]
490 \override StaffSymbol #'staff-space = #(magstep -4)
491 \override StaffSymbol #'thickness = #(magstep -3)
495 \set Staff.instrumentName = #"Violin"
496 c8.(\f^> b16 c d) ees8.(^> d16 c b)
497 g8.(^> b16 c ees) g8-.^> r r
501 \set PianoStaff.instrumentName = #"Piano"
502 \new Staff \relative c' {
505 s4. s8 r8 r16 <c f aes c>
506 <c f aes c>4.^> <c ees g>8 r r
508 \new Staff \relative c {
512 \once \override DynamicText #'X-offset = #-3
514 <ees g c>4.~ <ees g c>8
517 <c g c,>4.~ <c g c,>8
519 r8 r16 <f, c' aes'>16
520 <f c' aes'>4.-> <c' g'>8 r r
527 @node Why work so hard?
528 @unnumberedsubsec Why work so hard?
530 Musicians are usually more absorbed with performing than with studying
531 the looks of a piece of music, so nitpicking typographical details may
532 seem academic. But it is not. Sheet music is performance material:
533 everything is done to aid the musician in letting her perform better,
534 and anything that is unclear or unpleasant to read is a hindrance.
536 Traditionally engraved music uses bold symbols on heavy staff to create
537 a strong, well-balanced look that stands out well when the music is far
538 away from the reader: for example, if it is on a music stand. A careful
539 distribution of white space allows music to be set very tightly without
540 crowding symbols together. The result minimizes the number of page
541 turns, which is a great advantage.
543 This is a common characteristic of typography. Layout should be pretty,
544 not only for its own sake, but especially because it helps the reader in
545 his task. For sheet music this is of double importance because musicians
546 have a limited amount of attention. The less attention they need for
547 reading, the more they can focus on playing the music. In other words,
548 better typography translates to better performances.
550 These examples demonstrate that music typography is an art that is
551 subtle and complex, and that producing it requires considerable
552 expertise, which musicians usually do not have. LilyPond is our
553 effort to bring the graphical excellence of hand-engraved music to
554 the computer age, and make it available to normal musicians. We
555 have tuned our algorithms, font-designs, and program settings to
556 produce prints that match the quality of the old editions we love
557 to see and love to play from.
560 @node Automated engraving
561 @unnumberedsec Automated engraving
563 @cindex engraving, automated
564 @cindex automated engraving
566 This section describes what is required to create software that can
567 mimic the layout of engraved scores: a method of explaining good
568 layouts to the computer, detailed comparisons with real engravings,
569 and enough flexibility to deal with the wide range of challenges
570 that printed music can present.
574 * Improvement by benchmarking::
575 * Getting things right::
576 * Flexible architecture::
579 @node Beauty contests
580 @unnumberedsubsec Beauty contests
582 How do we actually make formatting decisions? In other words, which
583 of the three configurations should we choose for the following slur?
588 \once \override Slur #'positions = #'(1.5 . 1)
589 e8[( f] g[ a b d,)] r4
590 \once \override Slur #'positions = #'(2 . 3)
591 e8[( f] g[ a b d,)] r4
592 e8[( f] g[ a b d,)] r4
596 There are a few books on the art of music engraving
597 available. Unfortunately, they contain rules of simple thumbs and some
598 examples. Such rules can be instructive, but they are a far cry from
599 an algorithm that we could readily implement in a computer. Following
600 the instructions from literature leads to algorithms with lots of
601 hand coded exceptions. Doing all this case analysis is a lot of work,
602 and often not all cases are covered completely:
606 @sourceimage{ross-beam-scan,7cm,,}
609 @sourceimage{ross-beam-scan,,,.jpg}
613 (Image source: Ted Ross, @emph{The Art of Music Engraving})
615 Rather than trying to write detailed layout rules for every possible
616 scenario, we only have to describe the objectives well enough that
617 LilyPond can judge the attractiveness of several alternatives. Then,
618 for each possible configuration we compute an ugliness score and we
619 choose the least ugly configuration.
621 For example, here are three possible slur configurations, and LilyPond
622 has given each one a score in @q{ugly points}. The first example gets 15.39
623 points for grazing one of the notes:
628 \once \override Slur #'positions = #'(1.5 . 1)
629 e8[(_"15.39" f] g[ a b d,)] r4
634 second one is nicer, but the slur doesn't start or end on the note heads.
635 It gets 1.71 points for the left side and 9.37 points for the right
636 side, plus another 2 points because the slur ascends while the melody
637 descends for a total of 13.08 ugly points:
642 \once \override Slur #'positions = #'(2 . 3)
643 e8[(_"13.08" f] g[ a b d,)] r4
647 The final slur gets 10.04
648 points for the gap on the right and 2 points for the upward slope, but
649 it is the most attractive of the three configurations, so LilyPond
655 e8[(_"12.04" f] g[ a b d,)] r4
659 This technique is quite general, and is used to make optimal decisions
660 for beam configurations, ties and dots in chords, line breaks, and page
661 breaks. The results of these decisions can be judged by comparison to
664 @node Improvement by benchmarking
665 @unnumberedsubsec Improvement by benchmarking
667 LilyPond's output has improved gradually over time, and it continues to
668 improve by comparing its output to hand-engraved scores.
670 For example, here is one line of a benchmark piece from a
671 hand-engraved edition (Bärenreiter BA320):
674 @sourceimage{baer-sarabande-hires,16cm,,}
677 @sourceimage{baer-sarabande,,,png}
681 and the same quotation as engraved by a very old version of LilyPond
682 (version 1.4, May 2001):
685 @sourceimage{pdf/lily14-sarabande,16cm,,}
688 @sourceimage{lily14-sarabande,,,png}
691 @noindent The LilyPond 1.4 output is certainly readable, but close
692 comparison with the hand-engraved score showed a lot of errors in the
696 @sourceimage{lily14-sarabande-annotated-hires,16cm,,}
699 @sourceimage{lily14-sarabande-annotated,,,png}
703 @item there is too much space before the time signature
704 @item the stems of the beamed notes are too long
705 @item the second and fourth measures are too narrow
706 @item the slur is awkward-looking
707 @item the trill marks are too big
708 @item the stems are too thin
712 (There were also two missing note heads, several missing editorial
713 annotations, and an incorrect pitch!)
715 By adjusting the layout rules and font design, the output has improved
716 considerably. Compare the same reference score and the output
717 from the current version of LilyPond (@version{}):
720 @sourceimage{baer-sarabande-hires,16cm,,}
723 @sourceimage{baer-sarabande,,,png}
726 @lilypond[staffsize=17.5,line-width=15.9\cm]
731 \mergeDifferentlyDottedOn
732 << {\slurDashed d8.-\flageolet( e16) e4.-\trill( d16 e)}
736 <f' a, d,>4. e8( d c)
738 bes g' f e16( f g_1 a_2 bes_3 d,_2)
740 cis4.-\trill b8_3( a g)
741 << {\slurDashed d'8.( e16) e4.-\trill( d16 e)}
748 The current output is not a clone of the reference edition, but it is
749 much closer to publication quality that the earlier output.
751 @node Getting things right
752 @unnumberedsubsec Getting things right
754 We can also measure LilyPond's ability to make music engraving decisions
755 automatically by comparing LilyPond's output to the output of a
756 commercial software product. In this case we have chosen Finale 2008,
757 which is one of the most popular commercial score writers, particularly
758 in North America. Sibelius is their major rival and they appear to be
759 especially strong in the European market.
761 For our comparison we chose Bach's Fugue in G minor from the
762 Well-Tempered Clavier, Book I, BWV 861, whose opening subject is
769 r8 a16 bes c8 bes16 a bes8
775 We made our comparison by engraving the last seven measures of the piece
776 (28--34) in Finale and LilyPond. This is the point in the piece where
777 the subject returns in a three-part stretto and leads into the closing
778 section. In the Finale version, we have resisted the temptation to make
779 any adjustments to the default output because we are trying to show the
780 things that each software package gets right without assistance.
782 Many of the differences between the two engravings are visible in
783 measures 28--29, as shown here with Finale first and LilyPond second:
786 @sourceimage{pdf/bwv861mm28-29,14cm,,}
789 @sourceimage{bwv861mm28-29,,,png}
792 @lilypond[staffsize=19.5,line-width=14\cm]
793 global = {\key g \minor}
795 partI = \relative c' {
797 fis8 d' ees g, fis4 g
798 r8 a16 bes c8 bes16 a d8 r r4
801 partII = \relative c' {
803 d4 r4 r8 d'16 c bes8 c16 d
806 partIII = \relative c' {
808 r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
810 partIV = \relative c {
818 % \set Score.barNumberVisibility = #all-bar-numbers-visible
820 \set Score.currentBarNumber = #28
825 \new Voice = "voiceI" { \partI }
826 \new Voice = "voiceII" { \partII }
832 \new Voice = "voiceIII" { \partIII }
833 \new Voice = "voiceIV" { \partIV }
840 \remove "Time_signature_engraver"
844 \override StaffGrouper #'between-staff-spacing #'padding = #1
850 Some shortcomings in the unedited Finale output include:
852 @item Most of the beams extend too far off the staff. A beam that points
853 towards the center of the staff should have a length of about one
854 octave, but engravers shorten this when the beam points away from the
855 staff in multi-voice music. The Finale beaming can be easily improved
856 with the Patterson Beams plug-in, but we elected to skip that step for
858 @item Finale doesn't adjust the positions of interlocking note heads,
859 which makes the music extremely difficult to read when the upper and
860 lower voices exchange positions temporarily:
863 collide = \once \override NoteColumn #'force-hshift = #0
865 \new Voice = "sample" \relative c''{
868 {\voiceOne g4 \collide g4}
869 \new Voice {\voiceTwo bes \collide bes}
872 \new Lyrics \lyricsto "sample" \lyricmode { "good " " bad" }
876 @item Finale has placed all of the rests at fixed heights on the staff.
877 The user is free to adjust them as needed, but the software makes no
878 attempt to consider the content of the other voice. As luck would have
879 it, there are no true collisions between notes and rests in this example,
880 but that has more to do with the positions of the notes than the rest.
881 In other words, Bach deserves more credit for avoiding a complete
882 collision than Finale does.
886 This example is not intended to suggest that Finale cannot be used to
887 produce beautiful output. On the contrary, in the hands of a skilled
888 user it can and does, but it requires skill and time. One of the
889 fundamental differences between LilyPond and commercial score writers is
890 that LilyPond hopes to reduce the amount of human intervention to an
891 absolute minimum, while other packages try to provide an attractive
892 interface in which to make these types of edits.
894 One particularly glaring omission we found in the Finale sample is a
895 missing flat in measure 33:
899 @sourceimage{pdf/bwv861mm33-34-annotate,7.93cm,,}
902 @sourceimage{bwv861mm33-34-annotate,,,png}
907 The flat symbol is required to cancel out the natural in the same
908 measure, but Finale misses it because it occurred in a different voice.
909 The user must not only remember to run a beaming plug-in and respace the
910 note heads and rests, she must also check each measure for cross-voice
911 accidentals if she is to avoid interrupting a rehearsal for an engraving
914 If you are interested in examining these examples in more detail, the
915 full seven-measure excerpt can be found at the end of this essay in
916 engravings by Finale and LilyPond along with four different published
917 engravings. Close examination reveals that there is some acceptable
918 variation among the hand-engravings, but that LilyPond compares
919 reasonably well to that acceptable range. There are still some
920 shortcomings in the LilyPond output, for example, it appears a bit too
921 aggressive in shortening some of the stems, so there is room for further
922 development and fine-tuning.
924 Of course, typography relies on human judgment of appearance, so people
925 cannot be replaced completely. However, much of the dull work can be
926 automated. If LilyPond solves most of the common situations correctly,
927 this will be a huge improvement over existing software. Over the course
928 of years, the software can be refined to do more and more things
929 automatically, so manual overrides are less and less necessary. Where
930 manual adjustments are needed, LilyPond's structure has been designed
931 with that flexibility in mind.
933 @node Flexible architecture
934 @unnumberedsubsec Flexible architecture
936 When we started, we wrote the LilyPond program entirely in the C++
937 programming language; the program's functionality was set in stone
938 by the developers. That proved to be unsatisfactory for a number
943 @item When LilyPond makes mistakes, users need to override
944 formatting decisions. Therefore, the user must have access to the
945 formatting engine. Hence, rules and settings cannot be fixed by
946 us at compile-time but must be accessible for users at run-time.
948 @item Engraving is a matter of visual judgment, and therefore a
949 matter of taste. As knowledgeable as we are, users can disagree
950 with our personal decisions. Therefore, the definitions of
951 typographical style must also be accessible to the user.
953 @item Finally, we continually refine the formatting algorithms, so
954 we need a flexible approach to rules. The C++ language forces a
955 certain method of grouping rules that cannot readily be applied to
956 formatting music notation.
960 @cindex Scheme programming language
962 These problems have been addressed by integrating an interpreter
963 for the Scheme programming language and rewriting parts of
964 LilyPond in Scheme. The current formatting architecture is built
965 around the notion of graphical objects, described by Scheme
966 variables and functions. This architecture encompasses formatting
967 rules, typographical style and individual formatting decisions.
968 The user has direct access to most of these controls.
970 Scheme variables control layout decisions. For example, many
971 graphical objects have a direction variable that encodes the
972 choice between up and down (or left and right). Here you see two
973 chords, with accents and arpeggios. In the first chord, the
974 graphical objects have all directions down (or left). The second
975 chord has all directions up (right).
977 @lilypond[quote,ragged-right]
979 \override SpacingSpanner #'spacing-increment = #3
980 \override TimeSignature #'transparent = ##t
982 \stemDown <e g b>4_>-\arpeggio
983 \override Arpeggio #'direction = #RIGHT
984 \stemUp <e g b>4^>-\arpeggio
988 @cindex score formatting
989 @cindex formatting a score
990 @cindex formatting rules
993 The process of formatting a score consists of reading and writing
994 the variables of graphical objects. Some variables have a preset
995 value. For example, the thickness of many lines -- a
996 characteristic of typographical style -- is a variable with a
997 preset value. You are free to alter this value, giving your score
998 a different typographical impression.
1000 @lilypond[quote,ragged-right]
1003 c'4-~ c'16 as g f e16 g bes c' des'4
1006 \new Staff \fragment
1008 \override Beam #'beam-thickness = #0.3
1009 \override Stem #'thickness = #0.5
1010 \override Bar #'thickness = #3.6
1011 \override Tie #'thickness = #2.2
1012 \override StaffSymbol #'thickness = #3.0
1013 \override Tie #'extra-offset = #'(0 . 0.3)
1019 Formatting rules are also preset variables: each object has
1020 variables containing procedures. These procedures perform the
1021 actual formatting, and by substituting different ones, we can
1022 change the appearance of objects. In the following example, the
1023 rule governing which note head objects are used to produce the
1024 note head symbol is changed during the music fragment.
1026 @lilypond[quote,ragged-right]
1027 #(set-global-staff-size 30)
1029 #(define (mc-squared grob orig current)
1030 (let* ((interfaces (ly:grob-interfaces grob))
1031 (pos (ly:grob-property grob 'staff-position)))
1032 (if (memq 'note-head-interface interfaces)
1034 (ly:grob-set-property! grob 'stencil
1035 (grob-interpret-markup grob
1036 (make-lower-markup 0.5
1040 ((-2) (make-smaller-markup (make-bold-markup "2")))
1041 (else "bla")))))))))
1043 \new Voice \relative c' {
1045 \set autoBeaming = ##f
1048 \once \override NoteHead #'stencil = #note-head::brew-ez-stencil
1049 \once \override NoteHead #'font-size = #-7
1050 \once \override NoteHead #'font-family = #'sans
1051 \once \override NoteHead #'font-series = #'bold
1053 \once \override NoteHead #'style = #'cross
1055 \applyOutput #'Voice #mc-squared
1058 { d8[ es-( fis^^ g] fis2-) }
1059 \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
1065 @node What symbols to engrave?
1066 @unnumberedsec What symbols to engrave?
1073 The formatting process decides where to place symbols. However,
1074 this can only be done once it is decided @emph{what} symbols
1075 should be printed -- in other words, what notation to use.
1077 Common music notation is a system of recording music that has
1078 evolved over the past 1000 years. The form that is now in common
1079 use dates from the early Renaissance. Although the basic form
1080 (i.e., note heads on a 5-line staff) has not changed, the details
1081 still evolve to express the innovations of contemporary notation.
1082 Hence, common music notation encompasses some 500 years of music.
1083 Its applications range from monophonic melodies to monstrous
1084 counterpoints for a large orchestra.
1086 How can we get a grip on such a seven-headed beast, and force it
1087 into the confines of a computer program? Our solution is to break
1088 up the problem of notation (as opposed to engraving, i.e.,
1089 typography) into digestible and programmable chunks: every type of
1090 symbol is handled by a separate module, a so-called plug-in. Each
1091 plug-in is completely modular and independent, so each can be
1092 developed and improved separately. Such plug-ins are called
1093 @code{engraver}s, by analogy with craftsmen who translate musical
1094 ideas to graphic symbols.
1096 In the following example, we start out with a plug-in for note
1097 heads, the @code{Note_heads_engraver}.
1099 @lilypond[quote,ragged-right]
1100 \include "engraver-example.ily"
1107 \remove "Stem_engraver"
1108 \remove "Phrasing_slur_engraver"
1109 \remove "Slur_engraver"
1110 \remove "Script_engraver"
1111 \remove "Beam_engraver"
1112 \remove "Auto_beam_engraver"
1116 \remove "Accidental_engraver"
1117 \remove "Key_engraver"
1118 \remove "Clef_engraver"
1119 \remove "Bar_engraver"
1120 \remove "Time_signature_engraver"
1121 \remove "Staff_symbol_engraver"
1122 \consists "Pitch_squash_engraver"
1129 Then a @code{Staff_symbol_engraver} adds the staff,
1131 @lilypond[quote,ragged-right]
1132 \include "engraver-example.ily"
1139 \remove "Stem_engraver"
1140 \remove "Phrasing_slur_engraver"
1141 \remove "Slur_engraver"
1142 \remove "Script_engraver"
1143 \remove "Beam_engraver"
1144 \remove "Auto_beam_engraver"
1148 \remove "Accidental_engraver"
1149 \remove "Key_engraver"
1150 \remove "Clef_engraver"
1151 \remove "Bar_engraver"
1152 \consists "Pitch_squash_engraver"
1153 \remove "Time_signature_engraver"
1160 the @code{Clef_engraver} defines a reference point for the staff,
1162 @lilypond[quote,ragged-right]
1163 \include "engraver-example.ily"
1170 \remove "Stem_engraver"
1171 \remove "Phrasing_slur_engraver"
1172 \remove "Slur_engraver"
1173 \remove "Script_engraver"
1174 \remove "Beam_engraver"
1175 \remove "Auto_beam_engraver"
1179 \remove "Accidental_engraver"
1180 \remove "Key_engraver"
1181 \remove "Bar_engraver"
1182 \remove "Time_signature_engraver"
1189 and the @code{Stem_engraver} adds stems.
1191 @lilypond[quote,ragged-right]
1192 \include "engraver-example.ily"
1199 \remove "Phrasing_slur_engraver"
1200 \remove "Slur_engraver"
1201 \remove "Script_engraver"
1202 \remove "Beam_engraver"
1203 \remove "Auto_beam_engraver"
1207 \remove "Accidental_engraver"
1208 \remove "Key_engraver"
1209 \remove "Bar_engraver"
1210 \remove "Time_signature_engraver"
1217 The @code{Stem_engraver} is notified of any note head coming
1218 along. Every time one (or more, for a chord) note head is seen, a
1219 stem object is created and connected to the note head. By adding
1220 engravers for beams, slurs, accents, accidentals, bar lines, time
1221 signature, and key signature, we get a complete piece of notation.
1223 @lilypond[quote,ragged-right]
1224 \include "engraver-example.ily"
1225 \score { \topVoice }
1229 @cindex engraving multiple voices
1232 This system works well for monophonic music, but what about
1233 polyphony? In polyphonic notation, many voices can share a staff.
1235 @lilypond[quote,ragged-right]
1236 \include "engraver-example.ily"
1237 \new Staff << \topVoice \\ \botVoice >>
1240 In this situation, the accidentals and staff are shared, but the
1241 stems, slurs, beams, etc., are private to each voice. Hence,
1242 engravers should be grouped. The engravers for note heads, stems,
1243 slurs, etc., go into a group called @q{Voice context}, while the
1244 engravers for key, accidental, bar, etc., go into a group called
1245 @q{Staff context}. In the case of polyphony, a single Staff
1246 context contains more than one Voice context. Similarly, multiple
1247 Staff contexts can be put into a single Score context. The Score
1248 context is the top level notation context.
1252 Internals Reference: @rinternals{Contexts}.
1255 @lilypond[quote,ragged-right]
1256 \include "engraver-example.ily"
1259 \new Staff << \topVoice \\ \botVoice >>
1260 \new Staff << \pah \\ \hoom >>
1266 @node Music representation
1267 @unnumberedsec Music representation
1270 @cindex recursive structures
1272 Ideally, the input format for any high-level formatting system is
1273 an abstract description of the content. In this case, that would
1274 be the music itself. This poses a formidable problem: how can we
1275 define what music really is? Instead of trying to find an answer,
1276 we have reversed the question. We write a program capable of
1277 producing sheet music, and adjust the format to be as lean as
1278 possible. When the format can no longer be trimmed down, by
1279 definition we are left with content itself. Our program serves as
1280 a formal definition of a music document.
1282 The syntax is also the user-interface for LilyPond, hence it is
1292 to create a quarter note on middle C (C1) and an eighth note on
1293 the D above middle C (D1).
1301 On a microscopic scale, such syntax is easy to use. On a larger
1302 scale, syntax also needs structure. How else can you enter
1303 complex pieces like symphonies and operas? The structure is
1304 formed by the concept of music expressions: by combining small
1305 fragments of music into larger ones, more complex music can be
1306 expressed. For example
1308 @lilypond[quote,verbatim,fragment,relative=1]
1313 Simultaneous notes can be constructed by enclosing them with
1314 @code{<<} and @code{>>}:
1320 @lilypond[quote,fragment,relative=1]
1321 \new Voice { <<c4 d4 e>> }
1325 This expression is put in sequence by enclosing it in curly braces
1326 @code{@{@tie{}@dots{}@tie{}@}}:
1329 @{ f4 <<c4 d4 e4>> @}
1332 @lilypond[quote,relative=1,fragment]
1337 The above is also an expression, and so it may be combined again
1338 with another simultaneous expression (a half note) using
1339 @code{<<}, @code{\\}, and @code{>>}:
1342 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
1345 @lilypond[quote,fragment,relative=2]
1346 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
1349 Such recursive structures can be specified neatly and formally in
1350 a context-free grammar. The parsing code is also generated from
1351 this grammar. In other words, the syntax of LilyPond is clearly
1352 and unambiguously defined.
1354 User-interfaces and syntax are what people see and deal with most.
1355 They are partly a matter of taste, and also the subject of much
1356 discussion. Although discussions on taste do have their merit,
1357 they are not very productive. In the larger picture of LilyPond,
1358 the importance of input syntax is small: inventing neat syntax is
1359 easy, while writing decent formatting code is much harder. This
1360 is also illustrated by the line-counts for the respective
1361 components: parsing and representation take up less than 10% of
1365 @node Example applications
1366 @unnumberedsec Example applications
1368 @cindex simple examples
1369 @cindex examples, simple
1371 We have written LilyPond as an experiment of how to condense the
1372 art of music engraving into a computer program. Thanks to all
1373 that hard work, the program can now be used to perform useful
1374 tasks. The simplest application is printing notes.
1376 @lilypond[quote,relative=1]
1384 By adding chord names and lyrics we obtain a lead sheet.
1386 @lilypond[quote,ragged-right]
1388 \chords { c2 c f2 c }
1394 \addlyrics { twin -- kle twin -- kle lit -- tle star }
1398 Polyphonic notation and piano music can also be printed. The
1399 following example combines some more exotic constructs.
1403 title = "Screech and boink"
1404 subtitle = "Random complex notation"
1405 composer = "Han-Wen Nienhuys"
1409 \context PianoStaff <<
1414 \revert Stem #'direction
1415 \change Staff = down
1416 \set subdivideBeams = ##t
1420 \change Staff = down
1424 \change Staff = down
1428 \set followVoice = ##t
1429 c'''32([ b''16 a''16 gis''16 g''32)]
1431 s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
1433 s4 \autoBeamOff d''8.. f''32
1439 \new Staff = "down" {
1442 \set subdivideBeams = ##f
1443 \override Stem #'french-beaming = ##t
1444 \override Beam #'beam-thickness = #0.3
1445 \override Stem #'thickness = #4.0
1446 g'16[ b16 fis16 g16]
1452 \override Staff.Arpeggio #'arpeggio-direction =#down
1453 <cis, e, gis, b, cis>4\arpeggio
1460 tempoWholesPerMinute = #(ly:make-moment 60 8)
1466 \consists Horizontal_bracket_engraver
1472 The fragments shown above have all been written by hand, but that
1473 is not a requirement. Since the formatting engine is mostly
1474 automatic, it can serve as an output means for other programs that
1475 manipulate music. For example, it can also be used to convert
1476 databases of musical fragments to images for use on websites and
1477 multimedia presentations.
1479 This manual also shows an application: the input format is text,
1480 and can therefore be easily embedded in other text-based formats
1481 such as @LaTeX{}, HTML, or in the case of this manual, Texinfo.
1482 By means of a special program, the input fragments can be replaced
1483 by music images in the resulting PDF or HTML output files. This
1484 makes it easy to mix music and text in documents.
1487 TODO: add extra chapter for computer aesthetics?
1491 @unnumberedsec Appendix
1493 This appendix contains four reference engravings and two
1494 software-engraved versions of Bach's Fugue in G minor from the
1495 Well-Tempered Clavier, Book I, BWV 861 (the last seven measures).
1498 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1502 @sourceimage{bwv861-baer,16cm,,}
1505 @sourceimage{bwv861-baer-small,,,png}
1509 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1510 1989), an alternate musical source. Aside from the textual differences,
1511 this demonstrates slight variations in the engraving decisions, even
1512 from the same publisher and edition:
1515 @sourceimage{bwv861-baer-alt,16cm,,}
1518 @sourceimage{bwv861-baer-alt-small,,,png}
1522 Breitkopf & Härtel, edited by Ferruccio Busoni (Wiesbaden, 1894), also
1523 available from the Petrucci Music Library (IMSLP #22081). The editorial
1524 markings (fingerings, articulations, etc.) have been removed for clearer
1525 comparison with the other editions here:
1528 @sourceimage{bwv861-breitkopf,16cm,,}
1531 @sourceimage{bwv861-breitkopf-small,,,png}
1535 Bach-Gesellschaft edition (Leipzig, 1866), available from the Petrucci
1536 Music Library (IMSPL #02221):
1539 @sourceimage{bwv861-gessellschaft,16cm,,}
1542 @sourceimage{bwv861-gessellschaft-small,,,png}
1549 @sourceimage{pdf/bwv861-finale2008a,,,}
1552 @sourceimage{bwv861-finale2008a,,,png}
1557 LilyPond, version @version{}:
1559 @lilypond[staffsize=14.3,line-width=15.9\cm]
1560 global = {\key g \minor}
1562 partI = \relative c' {
1564 fis8 d' ees g, fis4 g
1565 r8 a16 bes c8 bes16 a d8 r r4
1566 r2 r8 d16 ees f8 ees16 d
1567 ees4 ~ ees16 d c bes a4 r8 ees'16 d
1568 c8 d16 ees d8 e16 fis g8 fis16 g a4 ~
1569 a8 d, g f ees d c bes
1570 a2 g\fermata \bar "|."
1573 partII = \relative c' {
1575 d4 r4 r8 d'16 c bes8 c16 d
1576 ees8 d c ees a, r r4
1577 r8 fis16 g a8 g16 fis g2 ~
1579 fis4 g r8 a16 bes c8 bes16 a
1580 bes4. <g b>8 <a c> r <d, g> r
1583 partIII = \relative c' {
1585 r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
1586 bes2 ~ bes8 b16 a g8 a16 b
1590 r8 a16 bes c8 bes16 a b2
1592 partIV = \relative c {
1596 d,8 d'16 c bes8 c16 d ees2 ~
1597 ees8 ees16 d c8 d16 ees fis,8 a16 g fis8 g16 a
1598 d,8 d'16 c bes8 c16 d ees8 c a fis'
1605 % \set Score.barNumberVisibility = #all-bar-numbers-visible
1607 \set Score.currentBarNumber = #28
1610 \new Staff = "RH" <<
1612 \new Voice = "voiceI" { \partI }
1613 \new Voice = "voiceII" { \partII }
1616 \new Staff = "LH" <<
1619 \new Voice = "voiceIII" { \partIII }
1620 \new Voice = "voiceIV" { \partIV }
1627 \remove "Time_signature_engraver"
1631 \override StaffGrouper #'between-staff-spacing #'padding = #1