]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/essay/engraving.itely
Doc: ensure two spaces after end of sentence.
[lilypond.git] / Documentation / essay / engraving.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.13.4"
12
13 @node Music engraving
14 @chapter Music engraving
15
16 This essay describes why LilyPond was created and how it can produce
17 such beautiful sheet music.
18
19 @c TODO:
20 @c remove 3mm eps bounding box left padding for Sarabande (This will
21 @c     require adding a new snippet option to lilypond-book.py
22 @c check formatting of HTML output
23
24 @menu
25 * The LilyPond story::
26 * Engraving details::
27 * Automated engraving::
28 * Building software::
29 * Putting LilyPond to work::
30 * Engraved examples (BWV 861)::
31 @end menu
32
33 @node The LilyPond story
34 @section The LilyPond story
35
36 Long before LilyPond had been used to engrave beautiful performance
37 scores, before it could create university course notes or even simple
38 melodies, before there was a community of users around the world or even
39 an essay on music engraving, LilyPond began with a question:
40
41 @quotation
42 Why does most computer output fail to achieve the beauty and balance of
43 a hand-engraved score?
44 @end quotation
45
46 @noindent
47 Some of the answers can be found by examining the two scores
48 @ifnottex
49 below.
50 @end ifnottex
51 @iftex
52 on the following pages.
53 @end iftex
54 The first score is a beautiful hand-engraved score from 1950 and the
55 second is a modern, computer-engraved edition.
56
57 @ifnottex
58 @quotation
59 @noindent
60 Bärenreiter BA 320, @copyright{}1950:
61
62 @sourceimage{baer-suite1-fullpage,,,png}
63 @end quotation
64
65 @quotation
66 @noindent
67 Henle no. 666, @copyright{}2000:
68
69 @sourceimage{henle-suite1-fullpage,,,png}
70 @end quotation
71 @end ifnottex
72
73 The notes here are identical, taken from Bach's first Suite for solo
74 cello, but the appearance is different, especially if you print them out
75 and view them from a distance.
76 @ifnottex
77 (The PDF version of this manual has high-resolution images suitable for
78 printing.)
79 @end ifnottex
80 Try reading or playing from each of the scores and you will find that
81 the hand-engraved score is more enjoyable to use.  It has flowing lines
82 and movement, and it feels like a living, breathing piece of music,
83 while the newer edition seems cold and mechanical.
84
85 It is hard to immediately see what makes the difference with the newer
86 edition.  Everything looks neat and tiny, possibly even @qq{better}
87 because it looks more computerized and uniform.  This really puzzled us
88 for quite a while.  We wanted to improve computer notation, but we first
89 had to figure out what was wrong with it.
90
91 The answer lies in the precise, mathematical uniformity of the newer
92 edition.  Find the bar line in the middle of each line: in the
93 hand-engraved score the position of these bar lines has some
94 natural variation, while in the newer version they line up almost
95 perfectly.  This is shown in these simplified page layout diagrams,
96 traced from the hand-engraved (left) and computer-generated music
97 (right):
98
99 @quotation
100 @iftex
101 @sourceimage{pdf/page-layout-comparison,,,}
102 @end iftex
103 @ifnottex
104 @sourceimage{page-layout-comparison,,,png}
105 @end ifnottex
106 @end quotation
107 @noindent
108
109 In the computer-generated output, even the individual note heads are
110 aligned in vertical columns, making the contour of the melody disappear
111 into a rigid grid of musical markings.
112
113 There are other differences as well: in the hand-engraved edition the
114 vertical lines are all stronger, the slurs lie closer to the note heads,
115 and there is more variety in the slopes of the beams.  Although such
116 details may seem like nitpicking, the result is a score that is easier
117 to read.  In the computer-generated output, each line is nearly identical
118 and if the musician looks away for a moment she will be lost on the
119 page.
120
121 LilyPond was designed to solve the problems we found in existing
122 software and to create beautiful music that mimics the finest
123 hand-engraved scores.
124
125 @iftex
126 @page
127 @noindent
128 Bärenreiter BA 320, @copyright{}1950:
129
130 @sourceimage{baer-suite1-fullpage-hires,16cm,,}
131 @page
132 @noindent
133 Henle no. 666, @copyright{}2000:
134 @sp 3
135 @sourceimage{henle-suite1-fullpage-hires,16cm,,}
136 @page
137 @end iftex
138
139 @node Engraving details
140 @section Engraving details
141
142 @cindex engraving
143 @cindex typography, music
144 @cindex music typography
145 @cindex plate engraving
146 @cindex music engraving
147
148 The art of music typography is called @emph{(plate) engraving}, a term
149 that derives from the manual process of music printing@footnote{Early
150 European printers explored several processes, including hand-carved
151 wooden blocks, movable type, and engraved sheets of thin metal.
152 Typesetting had the advantage of being more easily corrected and
153 facilitating the inclusion of text and lyrics, but only engraving
154 offered the ability to do unimpeded layout and unanticipated notation.
155 In the end, hand-engraved scores became the standard for all printed
156 music, with the exception of some hymnals and songbooks where
157 typesetting was justified by its ease and economy, even into the
158 twentieth century.}.  Just a few decades ago, sheet music was made by
159 cutting and stamping the music into a zinc or pewter plate in mirror
160 image.  The plate would be inked, and the depressions caused by the
161 cutting and stamping would hold ink.  An image was formed by pressing
162 paper to the plate.  The stamping and cutting was done completely by hand
163 and making a correction was cumbersome, so the engraving had to be
164 nearly perfect in one go.  Engraving was a highly specialized skill; a
165 craftsman had to complete around five years of training before earning
166 the title of master engraver, and another five years of experience were
167 necessary to become truly skilled.
168
169 @quotation
170 @iftex
171 @sourceimage{hader-slaan,,7cm,}
172 @end iftex
173 @ifnottex
174 @sourceimage{hader-slaan,,,jpg}
175 @end ifnottex
176 @end quotation
177
178 LilyPond is inspired by traditional manual engravings published by
179 European music publishers in and towards the end of the first half of
180 the twentieth century, including Bärenreiter, Duhem, Durand,
181 Hofmeister, Peters, and Schott.  This is sometimes regarded as the peak
182 of traditional musical engraving practice.  As we have studied these
183 editions we have learned a great deal about what goes into a
184 well-engraved score, and the aspects that we wanted to imitate in
185 LilyPond.
186
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.
193
194 @menu
195 * Music fonts::
196 * Optical spacing::
197 * Ledger lines::
198 * Optical sizing::
199 * Why work so hard?::
200 @end menu
201
202 @node Music fonts
203 @unnumberedsubsec Music fonts
204
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
213 sharp corners.
214
215 @multitable @columnfractions .25 .25 .25 .25
216 @item @tab
217 @ifnotinfo
218 @iftex
219 @sourceimage{baer-flat-gray,,4cm,}
220 @end iftex
221 @ifnottex
222 @sourceimage{baer-flat-gray,,,png}
223 @end ifnottex
224
225 @tab
226 @iftex
227 @sourceimage{henle-flat-gray,,4cm,}
228 @end iftex
229 @ifnottex
230 @sourceimage{henle-flat-gray,,,png}
231 @end ifnottex
232
233 @end ifnotinfo
234 @ifinfo
235 @sourceimage{henle-flat-bw,,,png}
236 @sourceimage{baer-flat-bw,,,png}
237 @sourceimage{lily-flat-bw,,,png}
238 @end ifinfo
239
240
241 @item @tab
242 Bärenreiter (1950)
243 @tab
244 Henle (2000)
245
246 @end multitable
247
248 @cindex musical symbols
249 @cindex font
250 @cindex blackness
251 @cindex balance
252
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.
260
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.
264
265 @quotation
266 @iftex
267 @sourceimage{pdf/OpusAndFeta,,,}
268 @end iftex
269 @ifnottex
270 @sourceimage{OpusAndFeta,,,png}
271 @end ifnottex
272 @end quotation
273
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
281 overall impression.
282
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.
288
289 @node Optical spacing
290 @unnumberedsubsec Optical spacing
291
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?
298
299 @cindex optical spacing
300
301 @lilypond
302 \paper {
303   ragged-right = ##t
304   indent = #0.0
305 }
306
307 music = {
308    c'4 e''4 e'4 b'4
309    \stemDown
310    b'8[ e'' a' e'']
311    \stemNeutral
312    e'8[ e'8 e'8 e'8]
313 }
314 \score
315 {
316   \music
317   \layout {
318     \context {
319       \Staff
320       \override NoteSpacing #'stem-spacing-correction = #0.0
321       \override NoteSpacing #'same-direction-correction = #0.0
322       \override StaffSpacing #'stem-spacing-correction = #0.0
323     }
324   }
325 }
326 @end lilypond
327
328 @lilypond
329 \paper {
330   ragged-right = ##t
331   indent = #0.0
332 }
333
334 music = {
335    c'4 e''4 e'4 b'4 |
336    \stemDown
337    b'8[ e'' a' e'']
338    \stemNeutral
339    e'8[ e'8 e'8 e'8]
340 }
341
342 \score
343 {
344   \music
345   \layout {
346     \context {
347       \Staff
348       \override NoteSpacing #'stem-spacing-correction = #0.6
349     }
350   }
351 }
352 @end lilypond
353
354 @cindex regular rhythms
355 @cindex regular spacing
356 @cindex spacing, regular
357
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
368 the eye.
369
370 The spacing algorithms in LilyPond even take the barlines into account,
371 which is why the final up-stem in the properly spaced example has been
372 given a little more space before the barline to keep it from looking
373 crowded.  A down-stem would not need this adjustment.
374
375 @node Ledger lines
376 @unnumberedsubsec Ledger lines
377
378 @cindex ledger lines
379 @cindex collisions
380
381 Ledger lines present a typographical challenge: they make it more
382 difficult to space musical symbols close together and they must be clear
383 enough to identify the pitch at a glance.  In the example below, we see
384 that ledger lines should be thicker than normal staff lines and that an
385 expert engraver will shorten a ledger line to allow closer spacing with
386 accidentals.  We have included this feature in LilyPond's engraving.
387
388 @multitable @columnfractions .25 .25 .25 .25
389 @item @tab
390
391 @iftex
392 @sourceimage{baer-ledger,3cm,,}
393 @end iftex
394 @ifnottex
395 @sourceimage{baer-ledger,,,png}
396 @end ifnottex
397
398 @tab
399
400 @iftex
401 @sourceimage{lily-ledger,3cm,,}
402 @end iftex
403 @ifnottex
404 @sourceimage{lily-ledger,,,png}
405 @end ifnottex
406
407 @end multitable
408
409
410 @node Optical sizing
411 @unnumberedsubsec Optical sizing
412
413 Music may need to be printed in a range of sizes.  Originally, this was
414 accomplished by creating punching dies in each of the required sizes,
415 which meant that each die was designed to look its best at that size.
416 With the advent of digital fonts, a single outline can be mathematically
417 scaled to any size, which is very convenient, but at the smaller sizes
418 the glyphs will appear very light.
419
420 In LilyPond, we have created fonts in a range of weights, corresponding
421 to a range of music sizes.  This is a LilyPond engraving at staff size
422 26:
423
424 @quotation
425 @iftex
426 @sourceimage{pdf/size26,,23mm,}
427 @end iftex
428 @ifnottex
429 @sourceimage{size26,,,png}
430 @end ifnottex
431 @end quotation
432
433 @noindent
434 and this is the same engraving set at staff size 11, then
435 magnified by 236% to print at the same size as the previous example:
436
437 @quotation
438 @iftex
439 @sourceimage{pdf/size11,,23mm,}
440 @end iftex
441 @ifnottex
442 @sourceimage{size11,,,png}
443 @end ifnottex
444 @end quotation
445
446 @noindent
447 At smaller sizes, LilyPond uses proportionally heavier lines so the
448 music will still read well.
449
450 @ignore
451 This also allows staves of different sizes to coexist peacefully when
452 used together on the same page:
453
454 @c TODO: are the stems in this example the right thickness? How should
455 @c line weights be scaled for small staves?
456
457 @c Grieg's Violin Sonata Op. 45
458 @lilypond[indent=1.5cm]
459 global = {
460   \time 6/8
461   \key c \minor
462 }
463
464 \new Score <<
465   \new Staff \with {
466       fontSize = #-4
467       \override StaffSymbol #'staff-space = #(magstep -4)
468       \override StaffSymbol #'thickness = #(magstep -3)
469     }
470     \relative c' {
471       \global
472       \set Staff.instrumentName = #"Violin"
473       c8.(\f^> b16 c d) ees8.(^> d16 c b)
474       g8.(^> b16 c ees) g8-.^> r r
475       R2.
476     }
477   \new PianoStaff <<
478     \set PianoStaff.instrumentName = #"Piano"
479     \new Staff \relative c' {
480       \global
481       s2.
482       s4. s8 r8 r16 <c f aes c>
483       <c f aes c>4.^> <c ees g>8 r r
484     }
485     \new Staff \relative c {
486       \global
487       \clef "bass"
488       <<
489         {
490           \once \override DynamicText #'X-offset = #-3
491           <ees g c>2.~->^\f
492           <ees g c>4.~ <ees g c>8
493         } \\ {
494           <c g c,>2.~
495           <c g c,>4.~ <c g c,>8
496         }
497       >>
498       r8 r16 <f, c' aes'>16
499       <f c' aes'>4.-> <c' g'>8 r r
500     }
501   >>
502 >>
503 @end lilypond
504 @end ignore
505
506 @node Why work so hard?
507 @unnumberedsubsec Why work so hard?
508
509 Musicians are usually more absorbed with performing than with studying
510 the looks of a piece of music, so nitpicking typographical details may
511 seem academic.  But it is not.  Sheet music is performance material:
512 everything is done to aid the musician in letting her perform better,
513 and anything that is unclear or unpleasant to read is a hindrance.
514
515 Traditionally engraved music uses bold symbols on heavy staff to create
516 a strong, well-balanced look that stands out well when the music is far
517 away from the reader: for example, if it is on a music stand.  A careful
518 distribution of white space allows music to be set very tightly without
519 crowding symbols together.  The result minimizes the number of page
520 turns, which is a great advantage.
521
522 This is a common characteristic of typography.  Layout should be pretty,
523 not only for its own sake, but especially because it helps the reader in
524 his task.  For sheet music this is of double importance because musicians
525 have a limited amount of attention.  The less attention they need for
526 reading, the more they can focus on playing the music.  In other words,
527 better typography translates to better performances.
528
529 These examples demonstrate that music typography is an art that is
530 subtle and complex, and that producing it requires considerable
531 expertise, which musicians usually do not have.  LilyPond is our
532 effort to bring the graphical excellence of hand-engraved music to
533 the computer age, and make it available to normal musicians.  We
534 have tuned our algorithms, font-designs, and program settings to
535 produce prints that match the quality of the old editions we love
536 to see and love to play from.
537
538
539 @node Automated engraving
540 @section Automated engraving
541
542 @cindex engraving, automated
543 @cindex automated engraving
544
545 Here we describe what is required to create software that can mimic the
546 layout of engraved scores: a method of describing good layouts to the
547 computer and a lot of detailed comparisons with real engravings.
548
549 @menu
550 * Beauty contests::
551 * Improvement by benchmarking::
552 * Getting things right::
553 @end menu
554
555 @node Beauty contests
556 @unnumberedsubsec Beauty contests
557
558 How do we actually make formatting decisions?  In other words, which
559 of the three configurations should we choose for the following slur?
560
561 @lilypond
562 \relative c {
563   \clef bass
564   \once \override Slur #'positions = #'(1.5 . 1)
565   e8[( f] g[ a b d,)] r4
566   \once \override Slur #'positions = #'(2 . 3)
567   e8[( f] g[ a b d,)] r4
568   e8[( f] g[ a b d,)] r4
569 }
570 @end lilypond
571
572 There are a few books on the art of music engraving
573 available.  Unfortunately, they contain simple rules of thumb and some
574 examples.  Such rules can be instructive, but they are a far cry from
575 an algorithm that we could readily implement in a computer.  Following
576 the instructions from literature leads to algorithms with lots of
577 hand-coded exceptions.  Doing all this case analysis is a lot of work,
578 and often not all cases are covered completely:
579
580 @quotation
581 @iftex
582 @sourceimage{ross-beam-scan,7cm,,}
583 @end iftex
584 @ifnottex
585 @sourceimage{ross-beam-scan,,,.jpg}
586 @end ifnottex
587 @end quotation
588
589 (Image source: Ted Ross, @emph{The Art of Music Engraving})
590
591 Rather than trying to write detailed layout rules for every possible
592 scenario, we only have to describe the objectives well enough that
593 LilyPond can judge the attractiveness of several alternatives.  Then,
594 for each possible configuration we compute an ugliness score and we
595 choose the least ugly configuration.
596
597 For example, here are three possible slur configurations, and LilyPond
598 has given each one a score in @q{ugly points}.  The first example gets
599 15.39 points for grazing one of the noteheads:
600
601 @lilypond
602 \relative c {
603   \clef bass
604   \once \override Slur #'positions = #'(1.5 . 1)
605   e8[(_"15.39" f] g[ a b d,)] r4
606 }
607 @end lilypond
608
609 The
610 second one is nicer, but the slur doesn't start or end on the note heads.
611 It gets 1.71 points for the left side and 9.37 points for the right
612 side, plus another 2 points because the slur ascends while the melody
613 descends for a total of 13.08 ugly points:
614
615 @lilypond
616 \relative c {
617   \clef bass
618   \once \override Slur #'positions = #'(2 . 3)
619   e8[(_"13.08" f] g[ a b d,)] r4
620 }
621 @end lilypond
622
623 The final slur gets 10.04
624 points for the gap on the right and 2 points for the upward slope, but
625 it is the most attractive of the three configurations, so LilyPond
626 selects this one:
627
628 @lilypond
629 \relative c {
630   \clef bass
631   e8[(_"12.04" f] g[ a b d,)] r4
632 }
633 @end lilypond
634
635 This technique is quite general, and is used to make optimal decisions
636 for beam configurations, ties and dots in chords, line breaks, and page
637 breaks.  The results of these decisions can be judged by comparison to
638 real engravings.
639
640 @node Improvement by benchmarking
641 @unnumberedsubsec Improvement by benchmarking
642
643 LilyPond's output has improved gradually over time, and it continues to
644 improve by comparing its output to hand-engraved scores.
645
646 For example, here is one line of a benchmark piece from a
647 hand-engraved edition (Bärenreiter BA320):
648
649 @iftex
650 @sourceimage{baer-sarabande-hires,16cm,,}
651 @end iftex
652 @ifnottex
653 @sourceimage{baer-sarabande,,,png}
654 @end ifnottex
655
656 @noindent
657 and the same quotation as engraved by a very old version of LilyPond
658 (version 1.4, May 2001):
659
660 @iftex
661 @sourceimage{pdf/lily14-sarabande,16cm,,}
662 @end iftex
663 @ifnottex
664 @sourceimage{lily14-sarabande,,,png}
665 @end ifnottex
666
667 @noindent The LilyPond 1.4 output is certainly readable, but close
668 comparison with the hand-engraved score showed a lot of errors in the
669 formatting details:
670
671 @iftex
672 @sourceimage{lily14-sarabande-annotated-hires,16cm,,}
673 @end iftex
674 @ifnottex
675 @sourceimage{lily14-sarabande-annotated,,,png}
676 @end ifnottex
677
678 @itemize @bullet
679 @item there is too much space before the time signature
680 @item the stems of the beamed notes are too long
681 @item the second and fourth measures are too narrow
682 @item the slur is awkward-looking
683 @item the trill marks are too big
684 @item the stems are too thin
685 @end itemize
686
687 @noindent
688 (There were also two missing note heads, several missing editorial
689 annotations, and an incorrect pitch!)
690
691 By adjusting the layout rules and font design, the output has improved
692 considerably.  Compare the same reference score and the output
693 from the current version of LilyPond (@version{}):
694
695 @iftex
696 @sourceimage{baer-sarabande-hires,16cm,,}
697 @end iftex
698 @ifnottex
699 @sourceimage{baer-sarabande,,,png}
700 @end ifnottex
701
702 @lilypond[staffsize=17.5,line-width=15.9\cm]
703 \relative c {
704   \clef "bass"
705   \key d \minor
706   \time 3/4
707   \mergeDifferentlyDottedOn
708   <<
709     { \slurDashed d8.-\flageolet( e16) e4.-\trill( d16 e) }
710      \\
711     { d4_2 a2 }
712   >>
713   \slurDashed
714   <f' a, d,>4. e8( d c)
715   \slurSolid
716   bes8 g' f e16( f g_1 a_2 bes_3 d,_2)
717   \slurDashed
718   cis4.-\trill b8_3( a g)
719   <<
720     { \slurDashed d'8.( e16) e4.-\trill( d16 e) }
721      \\
722     { <f, a>4 a2 }
723   >>
724 }
725 @end lilypond
726
727 @noindent
728 The current output is not a clone of the reference edition, but it is
729 much closer to publication quality that the earlier output.
730
731 @node Getting things right
732 @unnumberedsubsec Getting things right
733
734 We can also measure LilyPond's ability to make music engraving decisions
735 automatically by comparing LilyPond's output to the output of a
736 commercial software product.  In this case we have chosen Finale 2008,
737 which is one of the most popular commercial score writers, particularly
738 in North America.  Sibelius is their major rival and they appear to be
739 especially strong in the European market.
740
741 For our comparison we selected Bach's Fugue in G minor from the
742 Well-Tempered Clavier, Book I, BWV 861, whose opening subject is
743
744 @lilypond
745 \relative c' {
746   \key g \minor
747   \clef "treble_8"
748   r8 d ees g, fis4 g
749   r8 a16 bes c8 bes16 a bes8
750 }
751 @end lilypond
752
753 @noindent
754
755 We made our comparison by engraving the last seven measures of the piece
756 (28--34) in Finale and LilyPond.  This is the point in the piece where
757 the subject returns in a three-part stretto and leads into the closing
758 section.  In the Finale version, we have resisted the temptation to make
759 any adjustments to the default output because we are trying to show the
760 things that each software package gets right without assistance.  The
761 only major edits that we made were adjusting the page size to match this
762 essay and forcing the music onto two systems to make the comparison
763 easier.  By default Finale would have engraved two systems of three
764 measures each and a final, full-width system containing a single
765 measure.
766
767 Many of the differences between the two engravings are visible in
768 measures 28--29, as shown here with Finale first and LilyPond second:
769
770 @iftex
771 @sourceimage{pdf/bwv861mm28-29,14cm,,}
772 @end iftex
773 @ifnottex
774 @sourceimage{bwv861mm28-29,,,png}
775 @end ifnottex
776
777 @lilypond[staffsize=19.5,line-width=14\cm]
778 global = { \key g \minor }
779
780 partI = \relative c' {
781   \voiceOne
782   fis8 d' ees g, fis4 g
783   r8 a16 bes c8 bes16 a d8 r r4
784 }
785
786 partII = \relative c' {
787   \voiceTwo
788   d4 r4 r8 d'16 c bes8 c16 d
789   ees8 d c ees a, r r4
790 }
791 partIII = \relative c' {
792   \voiceOne
793   r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
794 }
795 partIV = \relative c {
796   \voiceTwo
797   d4 r r2
798   r8 d ees g, fis4 a
799 }
800
801 \score {
802   <<
803     % \set Score.barNumberVisibility = #all-bar-numbers-visible
804     % required in 2.13
805     \set Score.currentBarNumber = #28
806     \bar ""
807     \new PianoStaff <<
808       \new Staff = "RH" <<
809         \global
810         \new Voice = "voiceI" { \partI }
811         \new Voice = "voiceII" { \partII }
812       >>
813       \new Staff = "LH"
814       <<
815         \clef "bass"
816         \global
817         \new Voice = "voiceIII" { \partIII }
818         \new Voice = "voiceIV" { \partIV }
819       >>
820     >>
821   >>
822   \layout {
823     \context {
824       \Staff
825       \remove "Time_signature_engraver"
826     }
827     \context {
828       \PianoStaff
829       \override StaffGrouper #'between-staff-spacing #'padding = #1
830     }
831   }
832 }
833 @end lilypond
834
835 Some shortcomings in the unedited Finale output include:
836 @itemize @bullet
837 @item Most of the beams extend too far off the staff.  A beam that points
838 towards the center of the staff should have a length of about one
839 octave, but engravers shorten this when the beam points away from the
840 staff in multi-voice music.  The Finale beaming can be easily improved
841 with their Patterson Beams plug-in, but we elected to skip that step for
842 this example.
843 @item Finale doesn't adjust the positions of interlocking note heads,
844 which makes the music extremely difficult to read when the upper and
845 lower voices exchange positions temporarily:
846
847 @lilypond
848 collide = \once \override NoteColumn #'force-hshift = #0
849 \new Score <<
850   \new Voice = "sample" \relative c''{
851     \key g \minor
852     <<
853       { \voiceOne g4 \collide g4 }
854       \new Voice { \voiceTwo bes \collide bes }
855     >>
856   }
857   \new Lyrics \lyricsto "sample" \lyricmode { "good " " bad" }
858 >>
859 @end lilypond
860
861 @item Finale has placed all of the rests at fixed heights on the staff.
862 The user is free to adjust them as needed, but the software makes no
863 attempt to consider the content of the other voice.  As luck would have
864 it, there are no true collisions between notes and rests in this example,
865 but that has more to do with the positions of the notes than the rest.
866 In other words, Bach deserves more credit for avoiding a complete
867 collision than Finale does.
868
869 @end itemize
870
871 This example is not intended to suggest that Finale cannot be used to
872 produce publication-quality output.  On the contrary, in the hands of a
873 skilled user it can and does, but it requires skill and time.  One of the
874 fundamental differences between LilyPond and commercial scorewriters is
875 that LilyPond hopes to reduce the amount of human intervention to an
876 absolute minimum, while other packages try to provide an attractive
877 interface in which to make these types of edits.
878
879 One particularly glaring omission we found from Finale is a missing flat
880 in measure 33:
881
882 @quotation
883 @iftex
884 @sourceimage{pdf/bwv861mm33-34-annotate,7.93cm,,}
885 @end iftex
886 @ifnottex
887 @sourceimage{bwv861mm33-34-annotate,,,png}
888 @end ifnottex
889 @end quotation
890
891 @noindent
892 The flat symbol is required to cancel out the natural in the same
893 measure, but Finale misses it because it occurred in a different voice.
894 So in addition to running a beaming plug-in and checking the spacing on
895 the noteheads and rests, the user must also check each measure for
896 cross-voice accidentals to avoid interrupting a rehearsal over an
897 engraving error.
898
899 If you are interested in examining these examples in more detail, the
900 full seven-measure excerpt can be found at the end of this essay along
901 with four different published engravings.  Close examination reveals that
902 there is some acceptable variation among the hand-engravings, but that
903 LilyPond compares reasonably well to that acceptable range.  There are
904 still some shortcomings in the LilyPond output, for example, it appears
905 a bit too aggressive in shortening some of the stems, so there is room
906 for further development and fine-tuning.
907
908 Of course, typography relies on human judgment of appearance, so people
909 cannot be replaced completely.  However, much of the dull work can be
910 automated.  If LilyPond solves most of the common situations correctly,
911 this will be a huge improvement over existing software.  Over the course
912 of years, the software can be refined to do more and more things
913 automatically, so manual overrides are less and less necessary.  Where
914 manual adjustments are needed, LilyPond's structure has been designed
915 with that flexibility in mind.
916
917 @node Building software
918 @section Building software
919
920 This section describes some of the programming decisions that we made
921 when designing LilyPond.
922
923 @menu
924 * Music representation::
925 * What symbols to engrave?::
926 * Flexible architecture::
927 @end menu
928
929
930 @node Music representation
931 @unnumberedsubsec Music representation
932
933 @cindex syntax
934 @cindex recursive structures
935
936 Ideally, the input format for any high-level formatting system is
937 an abstract description of the content.  In this case, that would
938 be the music itself.  This poses a formidable problem: how can we
939 define what music really is? Instead of trying to find an answer,
940 we have reversed the question.  We write a program capable of
941 producing sheet music, and adjust the format to be as lean as
942 possible.  When the format can no longer be trimmed down, by
943 definition we are left with content itself.  Our program serves as
944 a formal definition of a music document.
945
946 The syntax is also the user-interface for LilyPond, hence it is
947 easy to type:
948
949 @example
950 @{
951   c'4 d'8
952 @}
953 @end example
954
955 @noindent
956 to create a quarter note on middle C (C1) and an eighth note on
957 the D above middle C (D1).
958
959 @lilypond[quote]
960 {
961   c'4 d'8
962 }
963 @end lilypond
964
965 On a microscopic scale, such syntax is easy to use.  On a larger
966 scale, syntax also needs structure.  How else can you enter
967 complex pieces like symphonies and operas?  The structure is
968 formed by the concept of music expressions: by combining small
969 fragments of music into larger ones, more complex music can be
970 expressed.  For example
971
972 @lilypond[quote,verbatim,fragment,relative=1]
973 f4
974 @end lilypond
975
976 @noindent
977 Simultaneous notes can be constructed by enclosing them with
978 @code{<<} and @code{>>}:
979
980 @example
981 <<c4 d4 e4>>
982 @end example
983
984 @lilypond[quote,fragment,relative=1]
985 \new Voice { <<c4 d4 e>> }
986 @end lilypond
987
988 @noindent
989 This expression is put in sequence by enclosing it in curly braces
990 @code{@{@tie{}@dots{}@tie{}@}}:
991
992 @example
993 @{ f4 <<c4 d4 e4>> @}
994 @end example
995
996 @lilypond[quote,relative=1,fragment]
997 { f4 <<c d e4>> }
998 @end lilypond
999
1000 @noindent
1001 The above is also an expression, and so it may be combined again
1002 with another simultaneous expression (a half note) using
1003 @code{<<}, @code{\\}, and @code{>>}:
1004
1005 @example
1006 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
1007 @end example
1008
1009 @lilypond[quote,fragment,relative=2]
1010 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
1011 @end lilypond
1012
1013 Such recursive structures can be specified neatly and formally in
1014 a context-free grammar.  The parsing code is also generated from
1015 this grammar.  In other words, the syntax of LilyPond is clearly
1016 and unambiguously defined.
1017
1018 User-interfaces and syntax are what people see and deal with most.
1019 They are partly a matter of taste, and also the subject of much
1020 discussion.  Although discussions on taste do have their merit,
1021 they are not very productive.  In the larger picture of LilyPond,
1022 the importance of input syntax is small: inventing neat syntax is
1023 easy, while writing decent formatting code is much harder.  This
1024 is also illustrated by the line-counts for the respective
1025 components: parsing and representation take up less than 10% of
1026 the source code.
1027
1028 When designing the structures used in LilyPond, we made some different
1029 decisions than are apparent in other software.  Consider the hierarchical
1030 nature of music notation:
1031
1032 @lilypond[quote,fragment]
1033 <<
1034   \new Staff \relative c'' {
1035     \key g \major
1036     \time 3/4
1037     d4 g,8 a b c d4 g, g
1038   }
1039   \new Staff \relative c' {
1040     \clef "bass"
1041     \key g \major
1042     <g b d>2 a4 b2.
1043   }
1044 >>
1045 @end lilypond
1046
1047 In this case, there are pitches grouped into chords that belong to
1048 measures, which belong to staves.  This resembles a tidy structure of
1049 nested boxes:
1050
1051 @quotation
1052 @iftex
1053 @sourceimage{pdf/nestedboxes,,4cm,}
1054 @end iftex
1055 @ifnottex
1056 @sourceimage{nestedboxes,,,png}
1057 @end ifnottex
1058 @end quotation
1059
1060 Unfortunately, the structure is tidy because it is based on some
1061 excessively restrictive assumptions.  This becomes apparent if we
1062 consider a more complicated musical example:
1063
1064 @lilypond[quote]
1065 \layout {
1066   \context {
1067     \Score
1068     \remove "Timing_translator"
1069     \remove "Default_bar_line_engraver"
1070   }
1071   \context {
1072     \Staff
1073     \consists "Timing_translator"
1074     \consists "Default_bar_line_engraver"
1075   }
1076 }
1077
1078 \new PianoStaff <<
1079   \new Staff = "RH" <<
1080     \new Voice = "I" \relative c''' {
1081       \time 3/4
1082       \voiceOne
1083       \times 6/7 { g8 g g g g g g }
1084       \oneVoice
1085       r4 <b,, fis' g bes> r4\fermata
1086     }
1087     \new Voice = "II" \relative c' {
1088       \voiceTwo
1089       c4
1090       \times 4/5 {
1091         <c ees>8 f g
1092         \change Staff = "LH" \oneVoice
1093         \stemUp g,( c}
1094       r4
1095       \override Stem #'cross-staff = ##t
1096       \override Stem #'length = #12
1097       <fis, b>) r\fermata
1098     }
1099   >>
1100   \new Staff = "LH" <<
1101     \new Voice = "III" \relative c' {
1102       \time 2/4
1103       \clef "bass"
1104       g4 \stopStaff s
1105       \startStaff s2*2
1106     }
1107   >>
1108 >>
1109 @end lilypond
1110
1111 In this example, staves start and stop at will, voices jump around
1112 between staves, and the staves have different time signatures.  Many
1113 software packages would struggle with reproducing this example because
1114 they are built on the nested box structure.  With LilyPond, on the other
1115 hand, we have tried to keep the input format and the structure as
1116 flexible as possible.
1117
1118 @node What symbols to engrave?
1119 @unnumberedsubsec What symbols to engrave?
1120
1121 @cindex engraving
1122 @cindex typography
1123 @cindex engraver
1124 @cindex plug-in
1125
1126 The formatting process decides where to place symbols.  However,
1127 this can only be done once it is decided @emph{what} symbols
1128 should be printed -- in other words, what notation to use.
1129
1130 Common music notation is a system of recording music that has
1131 evolved over the past 1000 years.  The form that is now in common
1132 use dates from the early Renaissance.  Although the basic form
1133 (i.e., note heads on a 5-line staff) has not changed, the details
1134 still evolve to express the innovations of contemporary notation.
1135 Hence, common music notation encompasses some 500 years of music.
1136 Its applications range from monophonic melodies to monstrous
1137 counterpoints for a large orchestra.
1138
1139 How can we get a grip on such a seven-headed beast, and force it
1140 into the confines of a computer program?  Our solution is to break
1141 up the problem of notation (as opposed to engraving, i.e.,
1142 typography) into digestible and programmable chunks: every type of
1143 symbol is handled by a separate module, a so-called plug-in.  Each
1144 plug-in is completely modular and independent, so each can be
1145 developed and improved separately.  Such plug-ins are called
1146 @code{engraver}s, by analogy with craftsmen who translate musical
1147 ideas to graphic symbols.
1148
1149 In the following example, we start out with a plug-in for note
1150 heads, the @code{Note_heads_engraver}.
1151
1152 @lilypond[quote,ragged-right]
1153 \include "engraver-example.ily"
1154
1155 \score {
1156   \topVoice
1157   \layout {
1158     \context {
1159       \Voice
1160       \remove "Stem_engraver"
1161       \remove "Phrasing_slur_engraver"
1162       \remove "Slur_engraver"
1163       \remove "Script_engraver"
1164       \remove "Beam_engraver"
1165       \remove "Auto_beam_engraver"
1166     }
1167     \context {
1168       \Staff
1169       \remove "Accidental_engraver"
1170       \remove "Key_engraver"
1171       \remove "Clef_engraver"
1172       \remove "Bar_engraver"
1173       \remove "Time_signature_engraver"
1174       \remove "Staff_symbol_engraver"
1175       \consists "Pitch_squash_engraver"
1176     }
1177   }
1178 }
1179 @end lilypond
1180
1181 @noindent
1182 Then a @code{Staff_symbol_engraver} adds the staff,
1183
1184 @lilypond[quote,ragged-right]
1185 \include "engraver-example.ily"
1186
1187 \score {
1188   \topVoice
1189   \layout {
1190     \context {
1191       \Voice
1192       \remove "Stem_engraver"
1193       \remove "Phrasing_slur_engraver"
1194       \remove "Slur_engraver"
1195       \remove "Script_engraver"
1196       \remove "Beam_engraver"
1197       \remove "Auto_beam_engraver"
1198     }
1199     \context {
1200       \Staff
1201       \remove "Accidental_engraver"
1202       \remove "Key_engraver"
1203       \remove "Clef_engraver"
1204       \remove "Bar_engraver"
1205       \consists "Pitch_squash_engraver"
1206       \remove "Time_signature_engraver"
1207     }
1208   }
1209 }
1210 @end lilypond
1211
1212 @noindent
1213 the @code{Clef_engraver} defines a reference point for the staff,
1214
1215 @lilypond[quote,ragged-right]
1216 \include "engraver-example.ily"
1217
1218 \score {
1219   \topVoice
1220   \layout {
1221     \context {
1222       \Voice
1223       \remove "Stem_engraver"
1224       \remove "Phrasing_slur_engraver"
1225       \remove "Slur_engraver"
1226       \remove "Script_engraver"
1227       \remove "Beam_engraver"
1228       \remove "Auto_beam_engraver"
1229     }
1230     \context {
1231       \Staff
1232       \remove "Accidental_engraver"
1233       \remove "Key_engraver"
1234       \remove "Bar_engraver"
1235       \remove "Time_signature_engraver"
1236     }
1237   }
1238 }
1239 @end lilypond
1240
1241 @noindent
1242 and the @code{Stem_engraver} adds stems.
1243
1244 @lilypond[quote,ragged-right]
1245 \include "engraver-example.ily"
1246
1247 \score {
1248   \topVoice
1249   \layout {
1250     \context {
1251       \Voice
1252       \remove "Phrasing_slur_engraver"
1253       \remove "Slur_engraver"
1254       \remove "Script_engraver"
1255       \remove "Beam_engraver"
1256       \remove "Auto_beam_engraver"
1257     }
1258     \context {
1259       \Staff
1260       \remove "Accidental_engraver"
1261       \remove "Key_engraver"
1262       \remove "Bar_engraver"
1263       \remove "Time_signature_engraver"
1264     }
1265   }
1266 }
1267 @end lilypond
1268
1269 @noindent
1270 The @code{Stem_engraver} is notified of any note head coming
1271 along.  Every time one (or more, for a chord) note head is seen, a
1272 stem object is created and connected to the note head.  By adding
1273 engravers for beams, slurs, accents, accidentals, bar lines, time
1274 signature, and key signature, we get a complete piece of notation.
1275
1276 @lilypond[quote,ragged-right]
1277 \include "engraver-example.ily"
1278 \score { \topVoice }
1279 @end lilypond
1280
1281 @cindex polyphony
1282 @cindex engraving multiple voices
1283 @cindex contexts
1284
1285 This system works well for monophonic music, but what about
1286 polyphony?  In polyphonic notation, many voices can share a staff.
1287
1288 @lilypond[quote,ragged-right]
1289 \include "engraver-example.ily"
1290 \new Staff << \topVoice \\ \botVoice >>
1291 @end lilypond
1292
1293 In this situation, the accidentals and staff are shared, but the
1294 stems, slurs, beams, etc., are private to each voice.  Hence,
1295 engravers should be grouped.  The engravers for note heads, stems,
1296 slurs, etc., go into a group called @q{Voice context}, while the
1297 engravers for key, accidental, bar, etc., go into a group called
1298 @q{Staff context}.  In the case of polyphony, a single Staff
1299 context contains more than one Voice context.  Similarly, multiple
1300 Staff contexts can be put into a single Score context.  The Score
1301 context is the top level notation context.
1302
1303 @lilypond[quote,ragged-right]
1304 \include "engraver-example.ily"
1305 \score {
1306    <<
1307       \new Staff << \topVoice \\ \botVoice >>
1308       \new Staff << \pah \\ \hoom >>
1309    >>
1310 }
1311 @end lilypond
1312
1313 @seealso
1314 Internals Reference: @rinternals{Contexts}.
1315
1316 @node Flexible architecture
1317 @unnumberedsubsec Flexible architecture
1318
1319 When we started, we wrote the LilyPond program entirely in the C++
1320 programming language; the program's functionality was set in stone
1321 by the developers.  That proved to be unsatisfactory for a number
1322 of reasons:
1323
1324 @itemize
1325
1326 @item When LilyPond makes mistakes, users need to override
1327 formatting decisions.  Therefore, the user must have access to the
1328 formatting engine.  Hence, rules and settings cannot be fixed by
1329 us at compile-time but must be accessible for users at run-time.
1330
1331 @item Engraving is a matter of visual judgment, and therefore a
1332 matter of taste.  As knowledgeable as we are, users can disagree
1333 with our personal decisions.  Therefore, the definitions of
1334 typographical style must also be accessible to the user.
1335
1336 @item Finally, we continually refine the formatting algorithms, so
1337 we need a flexible approach to rules.  The C++ language forces a
1338 certain method of grouping rules that cannot readily be applied to
1339 formatting music notation.
1340
1341 @end itemize
1342
1343 @cindex Scheme programming language
1344
1345 These problems have been addressed by integrating an interpreter
1346 for the Scheme programming language and rewriting parts of
1347 LilyPond in Scheme.  The current formatting architecture is built
1348 around the notion of graphical objects, described by Scheme
1349 variables and functions.  This architecture encompasses formatting
1350 rules, typographical style and individual formatting decisions.
1351 The user has direct access to most of these controls.
1352
1353 Scheme variables control layout decisions.  For example, many
1354 graphical objects have a direction variable that encodes the
1355 choice between up and down (or left and right).  Here you see two
1356 chords, with accents and arpeggios.  In the first chord, the
1357 graphical objects have all directions down (or left).  The second
1358 chord has all directions up (right).
1359
1360 @lilypond[quote,ragged-right]
1361 \new Score \with {
1362    \override SpacingSpanner #'spacing-increment = #3
1363    \override TimeSignature #'transparent = ##t
1364 } \relative c' {
1365    \stemDown <e g b>4_>-\arpeggio
1366    \override Arpeggio #'direction = #RIGHT
1367    \stemUp <e g b>4^>-\arpeggio
1368 }
1369 @end lilypond
1370
1371 @cindex score formatting
1372 @cindex formatting a score
1373 @cindex formatting rules
1374
1375 @noindent
1376 The process of formatting a score consists of reading and writing
1377 the variables of graphical objects.  Some variables have a preset
1378 value.  For example, the thickness of many lines -- a
1379 characteristic of typographical style -- is a variable with a
1380 preset value.  You are free to alter this value, giving your score
1381 a different typographical impression.
1382
1383 @lilypond[quote,ragged-right]
1384 fragment = {
1385    \clef bass f8 as8
1386    c'4-~ c'16 as g f e16 g bes c' des'4
1387 }
1388 <<
1389    \new Staff \fragment
1390    \new Staff \with {
1391       \override Beam #'beam-thickness = #0.3
1392       \override Stem #'thickness = #0.5
1393       \override Bar #'thickness = #3.6
1394       \override Tie #'thickness = #2.2
1395       \override StaffSymbol #'thickness = #3.0
1396       \override Tie #'extra-offset = #'(0 .  0.3)
1397       }
1398       \fragment
1399 >>
1400 @end lilypond
1401
1402 Formatting rules are also preset variables: each object has
1403 variables containing procedures.  These procedures perform the
1404 actual formatting, and by substituting different ones, we can
1405 change the appearance of objects.  In the following example, the
1406 rule governing which note head objects are used to produce the
1407 note head symbol is changed during the music fragment.
1408
1409 @lilypond[quote,ragged-right]
1410 #(set-global-staff-size 30)
1411
1412 #(define (mc-squared grob orig current)
1413   (let* ((interfaces (ly:grob-interfaces grob))
1414          (pos (ly:grob-property grob 'staff-position)))
1415     (if (memq 'note-head-interface interfaces)
1416         (begin
1417           (ly:grob-set-property! grob 'stencil
1418             (grob-interpret-markup grob
1419               (make-lower-markup 0.5
1420                 (case pos
1421                   ((-5) "m")
1422                   ((-3) "c ")
1423                   ((-2) (make-smaller-markup (make-bold-markup "2")))
1424                   (else "bla")))))))))
1425
1426 \new Voice \relative c' {
1427   \stemUp
1428   \set autoBeaming = ##f
1429   \time 2/4
1430   <d f g>4
1431   \once \override NoteHead #'stencil = #note-head::brew-ez-stencil
1432   \once \override NoteHead #'font-size = #-7
1433   \once \override NoteHead #'font-family = #'sans
1434   \once \override NoteHead #'font-series = #'bold
1435   <d f g>4
1436   \once \override NoteHead #'style = #'cross
1437   <d f g>4
1438   \applyOutput #'Voice #mc-squared
1439   <d f g>4
1440   <<
1441     { d8[ es-( fis^^ g] fis2-) }
1442     \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
1443   >>
1444 }
1445 @end lilypond
1446
1447
1448
1449 @node Putting LilyPond to work
1450 @section Putting LilyPond to work
1451
1452 @cindex simple examples
1453 @cindex examples, simple
1454
1455 We have written LilyPond as an experiment of how to condense the
1456 art of music engraving into a computer program.  Thanks to all
1457 that hard work, the program can now be used to perform useful
1458 tasks.  The simplest application is printing notes.
1459
1460 @lilypond[quote,relative=1]
1461 {
1462   \time 2/4
1463   c4 c g'4 g a4 a g2
1464 }
1465 @end lilypond
1466
1467 @noindent
1468 By adding chord names and lyrics we obtain a lead sheet.
1469
1470 @lilypond[quote,ragged-right]
1471 <<
1472    \chords { c2 c f2 c }
1473    \new Staff
1474    \relative c' {
1475      \time 2/4
1476      c4 c g' g a a g2
1477    }
1478    \addlyrics { twin -- kle twin -- kle lit -- tle star }
1479 >>
1480 @end lilypond
1481
1482 Polyphonic notation and piano music can also be printed.  The
1483 following example combines some more exotic constructs.
1484
1485 @lilypond[quote,line-width=15.9\cm]
1486 \header {
1487   title = "Screech and boink"
1488   subtitle = "Random complex notation"
1489   composer = "Han-Wen Nienhuys"
1490 }
1491
1492 \score {
1493   \context PianoStaff <<
1494     \new Staff = "up" {
1495       \time 4/8
1496       \key c \minor
1497       << {
1498         \revert Stem #'direction
1499         \change Staff = down
1500         \set subdivideBeams = ##t
1501         g16.[
1502           \change Staff = up
1503           c'''32
1504           \change Staff = down
1505           g32
1506           \change Staff = up
1507           c'''32
1508           \change Staff = down
1509           g16]
1510         \change Staff = up
1511         \stemUp
1512         \set followVoice = ##t
1513         c'''32([ b''16 a''16 gis''16 g''32)]
1514       } \\ {
1515         s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
1516       } \\ {
1517         s4 \autoBeamOff d''8.. f''32
1518       } \\ {
1519         s4 es''4
1520       } >>
1521     }
1522
1523     \new Staff = "down" {
1524       \clef bass
1525       \key c \minor
1526       \set subdivideBeams = ##f
1527       \override Stem  #'french-beaming = ##t
1528       \override Beam  #'beam-thickness = #0.3
1529       \override Stem  #'thickness = #4.0
1530       g'16[ b16 fis16 g16]
1531       << \makeClusters {
1532         as16 <as b>
1533         <g b>
1534         <g cis>
1535       } \\ {
1536         \override Staff.Arpeggio  #'arpeggio-direction =#down
1537         <cis, e, gis, b, cis>4\arpeggio
1538       }
1539     >> }
1540   >>
1541   \midi {
1542     \context {
1543       \Score
1544       tempoWholesPerMinute = #(ly:make-moment 60 8)
1545     }
1546   }
1547   \layout {
1548     \context {
1549       \Staff
1550       \consists Horizontal_bracket_engraver
1551     }
1552   }
1553 }
1554 @end lilypond
1555
1556 The fragments shown above have all been written by hand, but that
1557 is not a requirement.  Since the formatting engine is mostly
1558 automatic, it can serve as an output means for other programs that
1559 manipulate music.  For example, it can also be used to convert
1560 databases of musical fragments to images for use on websites and
1561 multimedia presentations.
1562
1563 This manual also shows an application: the input format is text, and can
1564 therefore be easily embedded in other text-based formats such as
1565 @LaTeX{}, HTML, or in the case of this manual, Texinfo.  Using the
1566 @command{lilypond-book} program, included with LilyPond, the input
1567 fragments can be replaced by music images in the resulting PDF or HTML
1568 output files.  Another example is the third-party OOoLilyPond extension
1569 for OpenOffice.org, which makes it extremely easy to embed musical
1570 examples in documents.
1571
1572 For more examples of LilyPond in action, full documentation, and the
1573 software itself, see our main website: www.lilypond.org.
1574
1575 @page
1576 @node Engraved examples (BWV 861)
1577 @section Engraved examples (BWV 861)
1578
1579 This section contains four reference engravings and two
1580 software-engraved versions of Bach's Fugue in G minor from the
1581 Well-Tempered Clavier, Book I, BWV 861 (the last seven measures).
1582
1583 @noindent
1584 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1585 1989):
1586
1587 @iftex
1588 @sourceimage{bwv861-baer,16cm,,}
1589 @end iftex
1590 @ifnottex
1591 @sourceimage{bwv861-baer-small,,,png}
1592 @end ifnottex
1593
1594 @noindent
1595 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1596 1989), an alternate musical source.  Aside from the textual differences,
1597 this demonstrates slight variations in the engraving decisions, even
1598 from the same publisher and edition:
1599
1600 @iftex
1601 @sourceimage{bwv861-baer-alt,16cm,,}
1602 @end iftex
1603 @ifnottex
1604 @sourceimage{bwv861-baer-alt-small,,,png}
1605 @end ifnottex
1606
1607 @noindent
1608 Breitkopf & Härtel, edited by Ferruccio Busoni (Wiesbaden, 1894), also
1609 available from the Petrucci Music Library (IMSLP #22081).  The editorial
1610 markings (fingerings, articulations, etc.) have been removed for clearer
1611 comparison with the other editions here:
1612
1613 @iftex
1614 @sourceimage{bwv861-breitkopf,16cm,,}
1615 @end iftex
1616 @ifnottex
1617 @sourceimage{bwv861-breitkopf-small,,,png}
1618 @end ifnottex
1619
1620 @noindent
1621 Bach-Gesellschaft edition (Leipzig, 1866), available from the Petrucci
1622 Music Library (IMSPL #02221):
1623
1624 @iftex
1625 @sourceimage{bwv861-gessellschaft,16cm,,}
1626 @end iftex
1627 @ifnottex
1628 @sourceimage{bwv861-gessellschaft-small,,,png}
1629 @end ifnottex
1630
1631 @noindent
1632 Finale 2008:
1633
1634 @iftex
1635 @sourceimage{pdf/bwv861-finale2008a,,,}
1636 @end iftex
1637 @ifnottex
1638 @sourceimage{bwv861-finale2008a,,,png}
1639 @end ifnottex
1640
1641 @sp 4
1642 @noindent
1643 LilyPond, version @version{}:
1644
1645 @lilypond[staffsize=14.3,line-width=15.9\cm]
1646 global = {\key g \minor}
1647
1648 partI = \relative c' {
1649   \voiceOne
1650   fis8 d' ees g, fis4 g
1651   r8 a16 bes c8 bes16 a d8 r r4
1652   r2 r8 d16 ees f8 ees16 d
1653   ees4 ~ ees16 d c bes a4 r8 ees'16 d
1654   c8 d16 ees d8 e16 fis g8 fis16 g a4 ~
1655   a8 d, g f ees d c bes
1656   a2 g\fermata \bar "|."
1657 }
1658
1659 partII = \relative c' {
1660   \voiceTwo
1661   d4 r4 r8 d'16 c bes8 c16 d
1662   ees8 d c ees a, r r4
1663   r8 fis16 g a8 g16 fis g2 ~
1664   g2 r8 d' ees g,
1665   fis4 g r8 a16 bes c8 bes16 a
1666   bes4. <g b>8 <a c> r <d, g> r
1667   <ees g>4 <d fis> d2
1668 }
1669 partIII = \relative c' {
1670   \voiceOne
1671   r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
1672   bes2 ~ bes8 b16 a g8 a16 b
1673   c4 r r2
1674   R1
1675   r8 d ees g, fis4 g
1676   r8 a16 bes c8 bes16 a b2
1677 }
1678 partIV = \relative c {
1679   \voiceTwo
1680   d4 r r2
1681   r8 d ees g, fis4 a
1682   d,8 d'16 c bes8 c16 d ees2 ~
1683   ees8 ees16 d c8 d16 ees fis,8 a16 g fis8 g16 a
1684   d,8 d'16 c bes8 c16 d ees8 c a fis'
1685   g f ees d c bes a g
1686   c a d d, g2\fermata
1687 }
1688
1689 \score {
1690   <<
1691     % \set Score.barNumberVisibility = #all-bar-numbers-visible
1692     % required in 2.13
1693     \set Score.currentBarNumber = #28
1694     \bar ""
1695     \new PianoStaff <<
1696       \new Staff = "RH" <<
1697         \global
1698         \new Voice = "voiceI" { \partI }
1699         \new Voice = "voiceII" { \partII }
1700       >>
1701
1702       \new Staff = "LH" <<
1703         \clef "bass"
1704         \global
1705         \new Voice = "voiceIII" { \partIII }
1706         \new Voice = "voiceIV" { \partIV }
1707       >>
1708     >>
1709   >>
1710   \layout {
1711     \context {
1712       \Staff
1713       \remove "Time_signature_engraver"
1714     }
1715     \context {
1716       \PianoStaff
1717       \override StaffGrouper #'between-staff-spacing #'padding = #1
1718     }
1719   }
1720 }
1721 @end lilypond