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 update LP 1.4 example with PDF
20 @c annotate typography errors in old LilyPond
22 @c add 'tweaked' versions of LP & Finale BWV 861
23 @c find a good value for #'between-staff-spacing #'padding
24 @c remove 3mm eps bounding box left padding for Sarabande (This will
25 @c require adding a new snippet option to lilypond-book.py
28 @c Incorrect beaming in the Sarabande is a known bug.
31 * The LilyPond story::
33 * Automated engraving::
34 * What symbols to engrave?::
35 * Music representation::
36 * Example applications::
40 @node The LilyPond story
41 @unnumberedsec The LilyPond story
43 Before LilyPond had a community of users around the world, before it had
44 been used to produce university course notes or world-premier opera
45 performance scores, before there was an essay on music engraving or any
46 computer code or even an organized team of developers, LilyPond began
50 Why does most computer output fail to achieve the beauty and balance of
51 a hand-engraved score?
54 Some of the answers can be found by examining the two scores
59 on the following pages.
61 The first score is a beautiful hand-engraved score from 1950 and the
62 second is a modern, computer-engraved edition.
66 Bärenreiter BA 320, @copyright{}1950:
68 @sourceimage{baer-suite1-fullpage,,,png}
71 Henle no. 666, @copyright{}2000:
73 @sourceimage{henle-suite1-fullpage,,,png}
76 The notes here are identical, taken from Bach's first Suite for solo
77 cello, but the appearance is different, especially if you print them out
78 and veiw them from a distance.
80 (The PDF version of this manual has high-resolution images suitable for
83 Try reading or playing from each of the scores and you will find that
84 the hand-engraved score is more enjoyable to use. It has flowing lines
85 and movement, and it feels like a living, breathing piece of music,
86 while the newer edition seems cold and mechanical.
88 It is kind of hard to immediately see what makes the difference with the
89 newer edition. Everything looks neat and tiny, possibly even ``better''
90 because it looks more computerized and uniform. This really puzzled us
91 for quite a while. We wanted to improve computer notation, but we first
92 had to figure out what was wrong with it.
94 The answer lies in the precise, mathematical uniformity of the newer
95 edition. Find the barline in the middle of each line: in the
96 hand-engraved score the position of these barlines has some natural
97 natural variation, while in the newer version they line up almost
98 perfectly. This is shown in these simplified page layout diagrams,
99 traced from the hand-engraved (left) and computer-generated music
104 @sourceimage{pdf/page-layout-comparison,,,}
107 @sourceimage{page-layout-comparison,,,png}
112 In the computer-generated output, even the individual noteheads are
113 aligned in vertical columns, making the contour of the melody disappear
114 into a rigid grid of musical markings.
116 There are other differences as well: in the hand-engraved edition the
117 vertical lines are all stronger, the slurs lie closer to the noteheads,
118 and there is more visual variety in the placement of the beams. Although
119 such details may seem like nitpicking, the result is a score that is
120 easier to read. In the computer-generated output, each line is nearly
121 identical and if the musician looks away for a moment, she will be lost
124 LilyPond was designed to solve the problems we found in existing
125 software and to create beautiful music that mimics the finest
126 hand-engraved scores. Along the way, we have learned a great deal about
127 the work that goes into a well-engraved score. In this essay we describe
128 several of those aspects that we have tried to imitate in LilyPond.
133 Bärenreiter BA 320, @copyright{}1950:
135 @sourceimage{baer-suite1-fullpage,16cm,,}
138 Henle no. 666, @copyright{}2000:
140 @sourceimage{henle-suite1-fullpage,16cm,,}
144 @node Engraving details
145 @unnumberedsec Engraving details
148 @cindex typography, music
149 @cindex music typography
150 @cindex plate engraving
151 @cindex music engraving
153 The art of music typography is called @emph{(plate) engraving}, a term
154 that derives from the manual process of music printing@footnote{Early
155 european printers explored several processes, including hand-carved
156 wooden blocks, movable type, and engraved sheets of thin metal.
157 Typesetting had the advantage of being more easily corrected and
158 facilitating the inclusion of text and lyrics, but only engraving
159 offered the ability to do unimpeded layout and unanticipated notation.
160 In the end, hand-engraved scores became the standard for all printed
161 music, with the exception of some hymnals and songbooks where
162 typesetting was justified by its ease and economy, even into the
163 twentieth century.}. Just a few decades ago, sheet music was made by
164 cutting and stamping the music into a zinc or pewter plate in mirror
165 image. The plate would be inked, and the depressions caused by the
166 cutting and stamping would hold ink. An image was formed by pressing
167 paper to the plate. The stamping and cutting was done completely by hand
168 and making a correction was cumbersome, so the engraving had to be
169 nearly perfect in one go. Engraving was a highly specialized skill; a
170 craftsman had to complete around five years of training before earning
171 the title of master engraver, and another five years of experience were
172 necessary to become truly skilled.
176 @sourceimage{hader-slaan,,7cm,}
179 @sourceimage{hader-slaan,,,jpg}
183 @c Now all newly printed music is produced with computers. This has
184 @c obvious advantages: prints are cheaper to make, editorial work can be
185 @c delivered by email, and the original data can be easily stored.
186 @c Unfortunately, computer-generated scores rarely match the quality of
187 @c hand-engraved scores. Instead, computer printouts have a bland,
188 @c mechanical look, which makes them unpleasant to play from.
195 * Why work so hard?::
199 @unnumberedsubsec Music fonts
201 The images below illustrate some differences between traditional
202 engraving and typical computer output. The left picture shows a scan of
203 a flat symbol from a hand-engraved Bärenreiter edition, while the right
204 picture depicts a symbol from an edition of the same music published in
205 2000. Although both images are printed in the same shade of ink, the
206 earlier version looks darker: the staff lines are heavier, and the
207 Bärenreiter flat has a bold, almost voluptuous rounded look. The right
208 scan, on the other hand, has thinner lines and a straight layout with
211 @multitable @columnfractions .25 .25 .25 .25
215 @sourceimage{baer-flat-gray,,4cm,}
218 @sourceimage{baer-flat-gray,,,png}
223 @sourceimage{henle-flat-gray,,4cm,}
226 @sourceimage{henle-flat-gray,,,png}
231 @sourceimage{henle-flat-bw,,,png}
232 @sourceimage{baer-flat-bw,,,png}
233 @sourceimage{lily-flat-bw,,,png}
244 @cindex musical symbols
249 When we wanted to write a computer program to create music typography,
250 there were no musical fonts freely available that could match the
251 elegance of our favorite scores. Undeterred, we created a font of
252 musical symbols, relying on nice printouts of hand-engraved music. The
253 experience helped develop a typographical taste, and it made us
254 appreciate subtle design details. Without that experience, we would not
255 have realized how ugly the fonts were that we admired at first.
257 Below is a sample of two music fonts: the upper set is the default font
258 in the Sibelius software (the @emph{Opus} font), and the lower set is
259 our own LilyPond font.
263 @sourceimage{pdf/OpusAndFeta,,,}
266 @sourceimage{OpusAndFeta,,,png}
270 The LilyPond symbols are heavier and their weight is more consistent,
271 which makes them easier to read. Fine endings, such as the ones on the
272 sides of the quarter rest, should not end in sharp points, but rather
273 in rounded shapes. This is because sharp corners of the punching dies
274 are fragile and quickly wear out when stamping in metal. Taken together,
275 the blackness of the font must be carefully tuned together with the
276 thickness of lines, beams and slurs to give a strong yet balanced
279 Also, notice that our half-notehead is not elliptic but slightly diamond
280 shaped. The vertical stem of a flat symbol is slightly brushed, becoming
281 wider at the top. The sharp and the natural are easier to distinguish
282 from a distance because their angled lines have different slopes and the
283 vertical strokes are heavier.
285 @node Optical spacing
286 @unnumberedsubsec Optical spacing
288 In spacing, the distribution of space should reflect the durations
289 between notes. However, as we saw in the Bach Suite above, many modern
290 scores adhere to the durations with mathematical precision, which leads
291 to poor results. In the next example a motive is printed twice: the
292 first time using exact mathematical spacing, and the second with
293 corrections. Which do you prefer?
295 @cindex optical spacing
316 \override NoteSpacing #'stem-spacing-correction = #0.0
317 \override NoteSpacing #'same-direction-correction = #0.0
318 \override StaffSpacing #'stem-spacing-correction = #0.0
344 \override NoteSpacing #'stem-spacing-correction = #0.6
350 @cindex regular rhythms
351 @cindex regular spacing
352 @cindex spacing, regular
354 Each bar in the fragment only uses notes that are played in a constant
355 rhythm. The spacing should reflect that. Unfortunately, the eye deceives
356 us a little; not only does it notice the distance between note heads, it
357 also takes into account the distance between consecutive stems. As a
358 result, the notes of an up-stem/@/down-stem combination should be put
359 farther apart, and the notes of a down-stem/@/up-stem combination should
360 be put closer together, all depending on the combined vertical positions
361 of the notes. The lower two measures are printed with this correction,
362 the upper two measures, however, form down-stem/@/up-stem clumps of
363 notes. A master engraver would adjust the spacing as needed to please
366 Another example of optical spacing is the visual interplay between the
367 stems and the bar lines. When an up-stem precedes the bar line, a little
368 more space is needed to keep it from feeling crowded:
377 c''8 c'' c'' c'' c'' c'' c'' c'' \break
378 a' a' a' a' a' a' a' a'
383 \remove "Time_signature_engraver"
384 \override NoteSpacing #'stem-spacing-correction = #0.7
388 \remove "Bar_number_engraver"
395 @unnumberedsubsec Ledger lines
400 Ledger lines present a typographical challenge: they make it more
401 difficult to space musical symbols close together and they must be clear
402 enough to identify the pitch at a glance. In the example below, we see
403 that ledger lines should be thicker than normal staff lines and that an
404 expert engraver will shorten a ledger line to allow closer spacing with
405 accidentals. We have included this feature in LilyPond's engraving.
407 @multitable @columnfractions .25 .25 .25 .25
411 @sourceimage{baer-ledger,3cm,,}
414 @sourceimage{baer-ledger,,,png}
420 @sourceimage{lily-ledger,3cm,,}
423 @sourceimage{lily-ledger,,,png}
430 @unnumberedsubsec Optical sizing
432 Music may need to be printed in a range of sizes. Originally, this was
433 accomplished by creating punching dies in each of the required sizes,
434 which meant that each die was designed to look its best at that size.
435 With the advent of digital fonts, a single outline can be mathematically
436 scaled to any size, which is very convenient, but at the smaller sizes
437 the glyphs will appear very light.
439 In LilyPond, we have created fonts in a range of weights, corresponding
440 to a range of music sizes. This is a LilyPond engraving at staff size
445 @sourceimage{pdf/size26,,23mm,}
448 @sourceimage{size26,,,png}
453 and this is the same engraving set at staff size 11, then
454 magnified by 236% to print at the same size as the previous example:
458 @sourceimage{pdf/size11,,23mm,}
461 @sourceimage{size11,,,png}
465 At smaller sizes, LilyPond uses proportionally heavier lines and so the
466 music will still read well. This also allows staves of different
467 sizes to coexist peacefully when used together on the same page:
469 @c Grieg's Violin Sonata Op. 45
470 @lilypond[indent=1.5cm]
479 \override StaffSymbol #'staff-space = #(magstep -4)
480 \override StaffSymbol #'thickness = #(magstep -3)
484 \set Staff.instrumentName = #"Violin"
485 c8.(\f^> b16 c d) ees8.(^> d16 c b)
486 g8.(^> b16 c ees) g8-.^> r r
490 \set PianoStaff.instrumentName = #"Piano"
491 \new Staff \relative c' {
494 s4. s8 r8 r16 <c f aes c>
495 <c f aes c>4.^> <c ees g>8 r r
497 \new Staff \relative c {
501 \once \override DynamicText #'X-offset = #-3
503 <ees g c>4.~ <ees g c>8
506 <c g c,>4.~ <c g c,>8
508 r8 r16 <f, c' aes'>16
509 <f c' aes'>4.-> <c' g'>8 r r
515 @node Why work so hard?
516 @unnumberedsubsec Why work so hard?
518 Musicians are usually more absorbed with performing than with studying
519 the looks of a piece of music, so nitpicking typographical details may
520 seem academic. But it is not. Sheet music is performance material:
521 everything is done to aid the musician in letting her perform better,
522 and anything that is unclear or unpleasant to read is a hinderance.
524 Traditionally engraved music uses bold symbols on heavy staff to create
525 a strong, well-balanced look that stands out well when the music is far
526 away from the reader: for example, if it is on a music stand. A careful
527 distribution of white space allows music to be set very tightly without
528 crowding symbols together. The result minimizes the number of page
529 turns, which is a great advantage.
531 This is a common characteristic of typography. Layout should be pretty,
532 not only for its own sake, but especially because it helps the reader in
533 his task. For sheet music this is of double importance because musicians
534 have a limited amount of attention. The less attention they need for
535 reading, the more they can focus on playing the music. In other words,
536 better typography translates to better performances.
538 These examples demonstrate that music typography is an art that is
539 subtle and complex, and that producing it requires considerable
540 expertise, which musicians usually do not have. LilyPond is our
541 effort to bring the graphical excellence of hand-engraved music to
542 the computer age, and make it available to normal musicians. We
543 have tuned our algorithms, font-designs, and program settings to
544 produce prints that match the quality of the old editions we love
545 to see and love to play from.
548 @node Automated engraving
549 @unnumberedsec Automated engraving
551 @cindex engraving, automated
552 @cindex automated engraving
556 * Notation benchmarking::
557 * Flexible architecture::
560 @node Beauty contests
561 @unnumberedsubsec Beauty contests
563 Rather than trying to write rules that describe how to draw an
564 attractive slur for every possible scenario, we have written rules that
565 describe an attractive slur and LilyPond finds the nicest possibility.
566 For example, here are three possible slur configurations, and LilyPond
567 has given each one a score in `ugly points':
570 %\layout { #(define debug-slur-scoring #t) }
574 \once \override Slur #'positions = #'(1.5 . 1)
575 e8[(_"15.39" f] g[ a b d,)] r4
576 \once \override Slur #'positions = #'(2 . 3)
577 e8[(_"13.08" f] g[ a b d,)] r4
578 e8[(_"12.04" f] g[ a b d,)] r4
584 The first example gets 15.39 points for grazing one of the notes. The
585 second one is nicer, but the slur doesn't start or end on the noteheads.
586 It gets 1.71 points for the left side and 9.37 points for the right
587 side, plus another 2 points because the slur ascends while the melody
588 descends for a total of 13.08 ulgy points. The final slur gets 10.04
589 points for the gap on the right and 2 points for the upward slope, but
590 it is the most attractive of the three configurations, so LilyPond
593 This technique is quite general, and is used to select beam
594 configurations, ties and dots in chords, line breaks, and page breaks.
596 @node Notation benchmarking
597 @unnumberedsubsec Notation benchmarking
599 We have tuned LilyPond's layout rules by comparing its output to
600 hand-engraved scores. Here is one line of a benchmark piece from a
601 hand-engraved edition (Bärenreiter BA320), and as engraved by an old
602 version of LilyPond (version 1.4, released May 2001):
605 @sourceimage{baer-sarabande-hires,16cm,,}
608 @sourceimage{baer-sarabande,,,png}
612 @sourceimage{lily14-sarabande,16cm,,}
615 @sourceimage{lily14-sarabande,,,png}
618 @noindent The LilyPond 1.4 output is certainly readable, but close
619 comparison with the hand-engraved score showed a lot of errors in the
623 @item most of the stems are too long
624 @item the trill marks are too big
625 @item the second and fourth measures are too narrow
626 @item the slur is awkward-looking
627 @item the stems are too thin
628 @item there was too much space before the time signature
632 (There were also two missing notes, and one wrong one!)
634 By adjusting the layout rules and font design, the output has improved
635 considerably. This is the same musical quotation compared to the output
636 from the current version of LilyPond (@version{}):
639 @sourceimage{baer-sarabande-hires,16cm,,}
642 @sourceimage{baer-sarabande,,,png}
645 @lilypond[staffsize=17.5,line-width=15.9\cm]
650 \mergeDifferentlyDottedOn
651 << {\slurDashed d8.-\flageolet( e16) e4.-\trill( d16 e)}
655 <f' a, d,>4. e8( d c)
657 bes g' f e16( f g_1 a_2 bes_3 d,_2)
659 cis4.-\trill b8_3( a g)
660 << {\slurDashed d'8.( e16) e4.-\trill( d16 e)}
667 The current output is not a clone of the reference edition, but it is
668 much closer to publication quality that the earlier output.
670 [@strong{Andrew H:} This comparison is not finished. I promise not to
671 leave it in such a mess!]
673 Another valuable form of benchmarking is comparing LilyPond's output to
674 the output of a commercial software product. In this case we have chosen
675 Finale 2008, which is one of the most popular commercial scorewriters,
676 particularly in North America. Sibelius is their major rival and they
677 appear to be especially strong in the European market.
679 We have selected the last seven measures of Bach's Fugue in G minor from
680 the Well-Tempered Clavier, Book I, BWV 861. In the final draft there
681 will be pitcures here, but for now please consult the appendix
682 (currently pp. 12--14) for the output from both programs and images from
683 four reference engravings.
688 @item Finale rests are always at the same heights (in v1/v2 situations).
689 @item Finale doesn't interlock notes nicely (mm. 28--29).
690 @item Finale misses the B-flat in mm. 33!
691 @item Finale's beamed stems are almost always too long when they extend
693 @item LilyPond 2.13.5 has a vertical spacing problem (no padding).
694 @item LilyPond could use a little more space before the first note of
696 @item LilyPond's ties to beat 1 of mm. 31 are shorter than any of the
697 reference scores, and Finale's are even worse.
698 @item LilyPond's stems are often shorter than any of the references,
699 especially RH mm. 31.
700 @item In some locations, the Bärenreiter engraver(s) place rests
701 further from the staff than strictly necessary in order to keep them
702 vertically close to the subsequent element in that voice (e.g. mm. 28).
703 @item There is some acceptable variation within the reference scores,
704 although some scores are more attractive than others.
707 @c Han-Wen said once:
708 @c A lot of readers misinterpret the Finale example. Finale is a
709 @c powerful package, and in the hands of a good engraver — which is
710 @c something different from a good musician — it can produce very good
711 @c scores. However, the friendly GUI is misleading: you need a lot of
712 @c time and expertise to get decent scores from Finale.
714 @c How do we go about implementing typography? If craftsmen need
715 @c over ten years to become true masters, how could we simple hackers
716 @c ever write a program to take over their jobs?
718 @c The answer is: we cannot.
720 The last two points lead into this concluding/transition paragraph:
722 Typography relies on human judgment of
723 appearance, so people cannot be replaced completely. However,
724 much of the dull work can be automated. If LilyPond solves most
725 of the common situations correctly, this will be a huge
726 improvement over existing software. The remaining cases can be
727 tuned by hand. Over the course of years, the software can be
728 refined to do more and more things automatically, so manual
729 overrides are less and less necessary. Where manual adjustments are
730 needed, LilyPond's structure must be ...
732 @node Flexible architecture
733 @unnumberedsubsec Flexible architecture
735 When we started, we wrote the LilyPond program entirely in the C++
736 programming language; the program's functionality was set in stone
737 by the developers. That proved to be unsatisfactory for a number
742 @item When LilyPond makes mistakes, users need to override
743 formatting decisions. Therefore, the user must have access to the
744 formatting engine. Hence, rules and settings cannot be fixed by
745 us at compile-time but must be accessible for users at run-time.
747 @item Engraving is a matter of visual judgment, and therefore a
748 matter of taste. As knowledgeable as we are, users can disagree
749 with our personal decisions. Therefore, the definitions of
750 typographical style must also be accessible to the user.
752 @item Finally, we continually refine the formatting algorithms, so
753 we need a flexible approach to rules. The C++ language forces a
754 certain method of grouping rules that cannot readily be applied to
755 formatting music notation.
759 @cindex Scheme programming language
761 These problems have been addressed by integrating an interpreter
762 for the Scheme programming language and rewriting parts of
763 LilyPond in Scheme. The current formatting architecture is built
764 around the notion of graphical objects, described by Scheme
765 variables and functions. This architecture encompasses formatting
766 rules, typographical style and individual formatting decisions.
767 The user has direct access to most of these controls.
769 Scheme variables control layout decisions. For example, many
770 graphical objects have a direction variable that encodes the
771 choice between up and down (or left and right). Here you see two
772 chords, with accents and arpeggios. In the first chord, the
773 graphical objects have all directions down (or left). The second
774 chord has all directions up (right).
776 @lilypond[quote,ragged-right]
778 \override SpacingSpanner #'spacing-increment = #3
779 \override TimeSignature #'transparent = ##t
781 \stemDown <e g b>4_>-\arpeggio
782 \override Arpeggio #'direction = #RIGHT
783 \stemUp <e g b>4^>-\arpeggio
787 @cindex score formatting
788 @cindex formatting a score
789 @cindex formatting rules
792 The process of formatting a score consists of reading and writing
793 the variables of graphical objects. Some variables have a preset
794 value. For example, the thickness of many lines -- a
795 characteristic of typographical style -- is a variable with a
796 preset value. You are free to alter this value, giving your score
797 a different typographical impression.
799 @lilypond[quote,ragged-right]
802 c'4-~ c'16 as g f e16 g bes c' des'4
807 \override Beam #'beam-thickness = #0.3
808 \override Stem #'thickness = #0.5
809 \override Bar #'thickness = #3.6
810 \override Tie #'thickness = #2.2
811 \override StaffSymbol #'thickness = #3.0
812 \override Tie #'extra-offset = #'(0 . 0.3)
818 Formatting rules are also preset variables: each object has
819 variables containing procedures. These procedures perform the
820 actual formatting, and by substituting different ones, we can
821 change the appearance of objects. In the following example, the
822 rule governing which note head objects are used to produce the
823 note head symbol is changed during the music fragment.
825 @lilypond[quote,ragged-right]
826 #(set-global-staff-size 30)
828 #(define (mc-squared grob orig current)
829 (let* ((interfaces (ly:grob-interfaces grob))
830 (pos (ly:grob-property grob 'staff-position)))
831 (if (memq 'note-head-interface interfaces)
833 (ly:grob-set-property! grob 'stencil
834 (grob-interpret-markup grob
835 (make-lower-markup 0.5
839 ((-2) (make-smaller-markup (make-bold-markup "2")))
842 \new Voice \relative c' {
844 \set autoBeaming = ##f
847 \once \override NoteHead #'stencil = #note-head::brew-ez-stencil
848 \once \override NoteHead #'font-size = #-7
849 \once \override NoteHead #'font-family = #'sans
850 \once \override NoteHead #'font-series = #'bold
852 \once \override NoteHead #'style = #'cross
854 \applyOutput #'Voice #mc-squared
857 { d8[ es-( fis^^ g] fis2-) }
858 \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
864 @node What symbols to engrave?
865 @unnumberedsec What symbols to engrave?
872 The formatting process decides where to place symbols. However,
873 this can only be done once it is decided @emph{what} symbols
874 should be printed -- in other words, what notation to use.
876 Common music notation is a system of recording music that has
877 evolved over the past 1000 years. The form that is now in common
878 use dates from the early Renaissance. Although the basic form
879 (i.e., note heads on a 5-line staff) has not changed, the details
880 still evolve to express the innovations of contemporary notation.
881 Hence, common music notation encompasses some 500 years of music.
882 Its applications range from monophonic melodies to monstrous
883 counterpoints for a large orchestra.
885 How can we get a grip on such a seven-headed beast, and force it
886 into the confines of a computer program? Our solution is to break
887 up the problem of notation (as opposed to engraving, i.e.,
888 typography) into digestible and programmable chunks: every type of
889 symbol is handled by a separate module, a so-called plug-in. Each
890 plug-in is completely modular and independent, so each can be
891 developed and improved separately. Such plug-ins are called
892 @code{engraver}s, by analogy with craftsmen who translate musical
893 ideas to graphic symbols.
895 In the following example, we start out with a plug-in for note
896 heads, the @code{Note_heads_engraver}.
898 @lilypond[quote,ragged-right]
899 \include "engraver-example.ily"
906 \remove "Stem_engraver"
907 \remove "Phrasing_slur_engraver"
908 \remove "Slur_engraver"
909 \remove "Script_engraver"
910 \remove "Beam_engraver"
911 \remove "Auto_beam_engraver"
915 \remove "Accidental_engraver"
916 \remove "Key_engraver"
917 \remove "Clef_engraver"
918 \remove "Bar_engraver"
919 \remove "Time_signature_engraver"
920 \remove "Staff_symbol_engraver"
921 \consists "Pitch_squash_engraver"
928 Then a @code{Staff_symbol_engraver} adds the staff,
930 @lilypond[quote,ragged-right]
931 \include "engraver-example.ily"
938 \remove "Stem_engraver"
939 \remove "Phrasing_slur_engraver"
940 \remove "Slur_engraver"
941 \remove "Script_engraver"
942 \remove "Beam_engraver"
943 \remove "Auto_beam_engraver"
947 \remove "Accidental_engraver"
948 \remove "Key_engraver"
949 \remove "Clef_engraver"
950 \remove "Bar_engraver"
951 \consists "Pitch_squash_engraver"
952 \remove "Time_signature_engraver"
959 the @code{Clef_engraver} defines a reference point for the staff,
961 @lilypond[quote,ragged-right]
962 \include "engraver-example.ily"
969 \remove "Stem_engraver"
970 \remove "Phrasing_slur_engraver"
971 \remove "Slur_engraver"
972 \remove "Script_engraver"
973 \remove "Beam_engraver"
974 \remove "Auto_beam_engraver"
978 \remove "Accidental_engraver"
979 \remove "Key_engraver"
980 \remove "Bar_engraver"
981 \remove "Time_signature_engraver"
988 and the @code{Stem_engraver} adds stems.
990 @lilypond[quote,ragged-right]
991 \include "engraver-example.ily"
998 \remove "Phrasing_slur_engraver"
999 \remove "Slur_engraver"
1000 \remove "Script_engraver"
1001 \remove "Beam_engraver"
1002 \remove "Auto_beam_engraver"
1006 \remove "Accidental_engraver"
1007 \remove "Key_engraver"
1008 \remove "Bar_engraver"
1009 \remove "Time_signature_engraver"
1016 The @code{Stem_engraver} is notified of any note head coming
1017 along. Every time one (or more, for a chord) note head is seen, a
1018 stem object is created and connected to the note head. By adding
1019 engravers for beams, slurs, accents, accidentals, bar lines, time
1020 signature, and key signature, we get a complete piece of notation.
1022 @lilypond[quote,ragged-right]
1023 \include "engraver-example.ily"
1024 \score { \topVoice }
1028 @cindex engraving multiple voices
1031 This system works well for monophonic music, but what about
1032 polyphony? In polyphonic notation, many voices can share a staff.
1034 @lilypond[quote,ragged-right]
1035 \include "engraver-example.ily"
1036 \new Staff << \topVoice \\ \botVoice >>
1039 In this situation, the accidentals and staff are shared, but the
1040 stems, slurs, beams, etc., are private to each voice. Hence,
1041 engravers should be grouped. The engravers for note heads, stems,
1042 slurs, etc., go into a group called @q{Voice context,} while the
1043 engravers for key, accidental, bar, etc., go into a group called
1044 @q{Staff context.} In the case of polyphony, a single Staff
1045 context contains more than one Voice context. Similarly, multiple
1046 Staff contexts can be put into a single Score context. The Score
1047 context is the top level notation context.
1051 Internals Reference: @rinternals{Contexts}.
1054 @lilypond[quote,ragged-right]
1055 \include "engraver-example.ily"
1058 \new Staff << \topVoice \\ \botVoice >>
1059 \new Staff << \pah \\ \hoom >>
1065 @node Music representation
1066 @unnumberedsec Music representation
1069 @cindex recursive structures
1071 Ideally, the input format for any high-level formatting system is
1072 an abstract description of the content. In this case, that would
1073 be the music itself. This poses a formidable problem: how can we
1074 define what music really is? Instead of trying to find an answer,
1075 we have reversed the question. We write a program capable of
1076 producing sheet music, and adjust the format to be as lean as
1077 possible. When the format can no longer be trimmed down, by
1078 definition we are left with content itself. Our program serves as
1079 a formal definition of a music document.
1081 The syntax is also the user-interface for LilyPond, hence it is
1091 to create a quarter note on middle C (C1) and an eighth note on
1092 the D above middle C (D1).
1100 On a microscopic scale, such syntax is easy to use. On a larger
1101 scale, syntax also needs structure. How else can you enter
1102 complex pieces like symphonies and operas? The structure is
1103 formed by the concept of music expressions: by combining small
1104 fragments of music into larger ones, more complex music can be
1105 expressed. For example
1107 @lilypond[quote,verbatim,fragment,relative=1]
1112 Simultaneous notes can be constructed by enclosing them with
1113 @code{<<} and @code{>>}:
1119 @lilypond[quote,fragment,relative=1]
1120 \new Voice { <<c4 d4 e>> }
1124 This expression is put in sequence by enclosing it in curly braces
1125 @code{@{@tie{}@dots{}@tie{}@}}:
1128 @{ f4 <<c4 d4 e4>> @}
1131 @lilypond[quote,relative=1,fragment]
1136 The above is also an expression, and so it may be combined again
1137 with another simultaneous expression (a half note) using
1138 @code{<<}, @code{\\}, and @code{>>}:
1141 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
1144 @lilypond[quote,fragment,relative=2]
1145 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
1148 Such recursive structures can be specified neatly and formally in
1149 a context-free grammar. The parsing code is also generated from
1150 this grammar. In other words, the syntax of LilyPond is clearly
1151 and unambiguously defined.
1153 User-interfaces and syntax are what people see and deal with most.
1154 They are partly a matter of taste, and also the subject of much
1155 discussion. Although discussions on taste do have their merit,
1156 they are not very productive. In the larger picture of LilyPond,
1157 the importance of input syntax is small: inventing neat syntax is
1158 easy, while writing decent formatting code is much harder. This
1159 is also illustrated by the line-counts for the respective
1160 components: parsing and representation take up less than 10% of
1164 @node Example applications
1165 @unnumberedsec Example applications
1167 @cindex simple examples
1168 @cindex examples, simple
1170 We have written LilyPond as an experiment of how to condense the
1171 art of music engraving into a computer program. Thanks to all
1172 that hard work, the program can now be used to perform useful
1173 tasks. The simplest application is printing notes.
1175 @lilypond[quote,relative=1]
1183 By adding chord names and lyrics we obtain a lead sheet.
1185 @lilypond[quote,ragged-right]
1187 \chords { c2 c f2 c }
1193 \addlyrics { twin -- kle twin -- kle lit -- tle star }
1197 Polyphonic notation and piano music can also be printed. The
1198 following example combines some more exotic constructs.
1202 title = "Screech and boink"
1203 subtitle = "Random complex notation"
1204 composer = "Han-Wen Nienhuys"
1208 \context PianoStaff <<
1213 \revert Stem #'direction
1214 \change Staff = down
1215 \set subdivideBeams = ##t
1219 \change Staff = down
1223 \change Staff = down
1227 \set followVoice = ##t
1228 c'''32([ b''16 a''16 gis''16 g''32)]
1230 s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
1232 s4 \autoBeamOff d''8.. f''32
1238 \new Staff = "down" {
1241 \set subdivideBeams = ##f
1242 \override Stem #'french-beaming = ##t
1243 \override Beam #'beam-thickness = #0.3
1244 \override Stem #'thickness = #4.0
1245 g'16[ b16 fis16 g16]
1251 \override Staff.Arpeggio #'arpeggio-direction =#down
1252 <cis, e, gis, b, cis>4\arpeggio
1259 tempoWholesPerMinute = #(ly:make-moment 60 8)
1265 \consists Horizontal_bracket_engraver
1271 The fragments shown above have all been written by hand, but that
1272 is not a requirement. Since the formatting engine is mostly
1273 automatic, it can serve as an output means for other programs that
1274 manipulate music. For example, it can also be used to convert
1275 databases of musical fragments to images for use on websites and
1276 multimedia presentations.
1278 This manual also shows an application: the input format is text,
1279 and can therefore be easily embedded in other text-based formats
1280 such as @LaTeX{}, HTML, or in the case of this manual, Texinfo.
1281 By means of a special program, the input fragments can be replaced
1282 by music images in the resulting PDF or HTML output files. This
1283 makes it easy to mix music and text in documents.
1286 TODO: add extra chapter for computer aesthetics?
1290 @unnumberedsec Appendix
1292 This appendix contaions four reference engravings and two
1293 software-engraved versions of Bach's Fugue in G minor from the
1294 Well-Tempered Clavier, Book I, BWV 861 (the last seven measures).
1297 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1301 @sourceimage{bwv861-baer,16cm,,}
1304 @sourceimage{bwv861-baer-small,,,png}
1308 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1309 1989), an alternate musical source. Aside from the textual differences,
1310 this demsontrates slight variations in the engraving decisions, even
1311 from the same publisher and edition:
1314 @sourceimage{bwv861-baer-alt,16cm,,}
1317 @sourceimage{bwv861-baer-alt-small,,,png}
1321 Breitkopf & Härtel, edited by Ferruccio Busoni (Wiesbaden, 1894), also
1322 available from the Petrucci Music Library (IMSLP #22081). The editorial
1323 markings (fingerings, articulations, etc.) have been removed for clearer
1324 comparison with the other editions here:
1327 @sourceimage{bwv861-breitkopf,16cm,,}
1330 @sourceimage{bwv861-breitkopf-small,,,png}
1334 Bach-Gessellschaft edition (Leipzig, 1866), available from the Petrucci
1335 Music Library (IMSPL #02221):
1338 @sourceimage{bwv861-gessellschaft,16cm,,}
1341 @sourceimage{bwv861-gessellschaft-small,,,png}
1348 @sourceimage{pdf/bwv861-finale2008a,,,}
1351 @sourceimage{bwv861-finale2008a,,,png}
1355 LilyPond, version @version{}:
1357 @lilypond[staffsize=14.3,line-width=15.9\cm]
1358 global = {\key g \minor}
1360 partI = \relative c' {
1362 fis8 d' ees g, fis4 g
1363 r8 a16 bes c8 bes16 a d8 r r4
1364 r2 r8 d16 ees f8 ees16 d
1365 ees4 ~ ees16 d c bes a4 r8 ees'16 d
1366 c8 d16 ees d8 e16 fis g8 fis16 g a4 ~
1367 a8 d, g f ees d c bes
1368 a2 g\fermata \bar "|."
1371 partII = \relative c' {
1373 d4 r4 r8 d'16 c bes8 c16 d
1374 ees8 d c ees a, r r4
1375 r8 fis16 g a8 g16 fis g2 ~
1377 fis4 g r8 a16 bes c8 bes16 a
1378 bes4. <g b>8 <a c> r <d, g> r
1381 partIII = \relative c' {
1383 r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
1384 bes2 ~ bes8 b16 a g8 a16 b
1388 r8 a16 bes c8 bes16 a b2
1390 partIV = \relative c {
1394 d,8 d'16 c bes8 c16 d ees2 ~
1395 ees8 ees16 d c8 d16 ees fis,8 a16 g fis8 g16 a
1396 d,8 d'16 c bes8 c16 d ees8 c a fis'
1403 % \set Score.barNumberVisibility = #all-bar-numbers-visible
1405 \set Score.currentBarNumber = #28
1408 \new Staff = "RH" <<
1410 \new Voice = "voiceI" { \partI }
1411 \new Voice = "voiceII" { \partII }
1414 \new Staff = "LH" <<
1417 \new Voice = "voiceIII" { \partIII }
1418 \new Voice = "voiceIV" { \partIV }
1425 \remove "Time_signature_engraver"