]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/essay/engraving.itely
Run scripts/auxiliar/update-with-convert-ly.sh
[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.19.21"
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 tidy, 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 motif 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 This also allows staves of different sizes to coexist peacefully when
451 used together on the same page:
452
453 @c Grieg's Violin Sonata Op. 45
454 @lilypond[indent=1.5\cm]
455 global = {
456   \time 6/8
457   \key c \minor
458 }
459
460 \score {
461   <<
462     \new Staff \with {
463       \magnifyStaff #2/3
464     }
465     \relative c' {
466       \global
467       \set Staff.instrumentName = #"Violin"
468       c8.(\f^> b16 c d) ees8.(^> d16 c b)
469       g8.(^> b16 c ees) g8-.^> r r
470       R2.
471     }
472     \new PianoStaff <<
473       \set PianoStaff.instrumentName = #"Piano"
474       \new Staff \relative c' {
475         \global
476         s2.
477         s4. s8 r8 r16 <c f aes c>
478         <c f aes c>4.^> <c ees g>8 r r
479       }
480       \new Staff \relative c {
481         \global
482         \clef "bass"
483         <<
484         {
485           \once \override DynamicText.X-offset = #-3
486           <ees g c>2.~->^\f
487           <ees g c>4.~ <ees g c>8
488         } \\ {
489           <c g c,>2.~
490           <c g c,>4.~ <c g c,>8
491         }
492         >>
493         r8 r16 <f, c' aes'>16
494         <f c' aes'>4.-> <c' g'>8 r r
495       }
496     >>
497   >>
498 }
499 @end lilypond
500
501
502 @node Why work so hard?
503 @unnumberedsubsec Why work so hard?
504
505 Musicians are usually more absorbed with performing than with studying
506 the looks of a piece of music, so nitpicking typographical details may
507 seem academic.  But it is not.  Sheet music is performance material:
508 everything is done to aid the musician in letting her perform better,
509 and anything that is unclear or unpleasant to read is a hindrance.
510
511 Traditionally engraved music uses bold symbols on heavy staff to create
512 a strong, well-balanced look that stands out well when the music is far
513 away from the reader: for example, if it is on a music stand.  A careful
514 distribution of white space allows music to be set very tightly without
515 crowding symbols together.  The result minimizes the number of page
516 turns, which is a great advantage.
517
518 This is a common characteristic of typography.  Layout should be pretty,
519 not only for its own sake, but especially because it helps the reader in
520 his task.  For sheet music this is of double importance because musicians
521 have a limited amount of attention.  The less attention they need for
522 reading, the more they can focus on playing the music.  In other words,
523 better typography translates to better performances.
524
525 These examples demonstrate that music typography is an art that is
526 subtle and complex, and that producing it requires considerable
527 expertise, which musicians usually do not have.  LilyPond is our
528 effort to bring the graphical excellence of hand-engraved music to
529 the computer age, and make it available to normal musicians.  We
530 have tuned our algorithms, font-designs, and program settings to
531 produce prints that match the quality of the old editions we love
532 to see and love to play from.
533
534
535 @node Automated engraving
536 @section Automated engraving
537
538 @cindex engraving, automated
539 @cindex automated engraving
540
541 Here we describe what is required to create software that can mimic the
542 layout of engraved scores: a method of describing good layouts to the
543 computer and a lot of detailed comparisons with real engravings.
544
545 @menu
546 * Beauty contests::
547 * Improvement by benchmarking::
548 * Getting things right::
549 @end menu
550
551 @node Beauty contests
552 @unnumberedsubsec Beauty contests
553
554 How do we actually make formatting decisions?  In other words, which
555 of the three configurations should we choose for the following slur?
556
557 @lilypond
558 \relative c {
559   \clef bass
560   \once \override Slur.positions = #'(1.5 . 1)
561   e8[( f] g[ a b d,)] r4
562   \once \override Slur.positions = #'(2 . 3)
563   e8[( f] g[ a b d,)] r4
564   e8[( f] g[ a b d,)] r4
565 }
566 @end lilypond
567
568 There are a few books on the art of music engraving
569 available.  Unfortunately, they contain simple rules of thumb and some
570 examples.  Such rules can be instructive, but they are a far cry from
571 an algorithm that we could readily implement in a computer.  Following
572 the instructions from literature leads to algorithms with lots of
573 hand-coded exceptions.  Doing all this case analysis is a lot of work,
574 and often not all cases are covered completely:
575
576 @quotation
577 @iftex
578 @sourceimage{ross-beam-scan,7cm,,}
579 @end iftex
580 @ifnottex
581 @sourceimage{ross-beam-scan,,,.jpg}
582 @end ifnottex
583 @end quotation
584
585 (Image source: Ted Ross, @emph{The Art of Music Engraving})
586
587 Rather than trying to write detailed layout rules for every possible
588 scenario, we only have to describe the objectives well enough that
589 LilyPond can judge the attractiveness of several alternatives.  Then,
590 for each possible configuration we compute an ugliness score and we
591 choose the least ugly configuration.
592
593 For example, here are three possible slur configurations, and LilyPond
594 has given each one a score in @q{ugly points}.  The first example gets
595 15.39 points for grazing one of the noteheads:
596
597 @lilypond
598 \relative c {
599   \clef bass
600   \once \override Slur.positions = #'(1.5 . 1)
601   e8[(_"15.39" f] g[ a b d,)] r4
602 }
603 @end lilypond
604
605 The
606 second one is nicer, but the slur doesn't start or end on the note heads.
607 It gets 1.71 points for the left side and 9.37 points for the right
608 side, plus another 2 points because the slur ascends while the melody
609 descends for a total of 13.08 ugly points:
610
611 @lilypond
612 \relative c {
613   \clef bass
614   \once \override Slur.positions = #'(2 . 3)
615   e8[(_"13.08" f] g[ a b d,)] r4
616 }
617 @end lilypond
618
619 The final slur gets 10.04
620 points for the gap on the right and 2 points for the upward slope, but
621 it is the most attractive of the three configurations, so LilyPond
622 selects this one:
623
624 @lilypond
625 \relative {
626   \clef bass
627   e8[(_"12.04" f] g[ a b d,)] r4
628 }
629 @end lilypond
630
631 This technique is quite general, and is used to make optimal decisions
632 for beam configurations, ties and dots in chords, line breaks, and page
633 breaks.  The results of these decisions can be judged by comparison to
634 real engravings.
635
636 @node Improvement by benchmarking
637 @unnumberedsubsec Improvement by benchmarking
638
639 LilyPond's output has improved gradually over time, and it continues to
640 improve by comparing its output to hand-engraved scores.
641
642 For example, here is one line of a benchmark piece from a
643 hand-engraved edition (Bärenreiter BA320):
644
645 @iftex
646 @sourceimage{baer-sarabande-hires,16cm,,}
647 @end iftex
648 @ifnottex
649 @sourceimage{baer-sarabande,,,png}
650 @end ifnottex
651
652 @noindent
653 and the same quotation as engraved by a very old version of LilyPond
654 (version 1.4, May 2001):
655
656 @iftex
657 @sourceimage{pdf/lily14-sarabande,16cm,,}
658 @end iftex
659 @ifnottex
660 @sourceimage{lily14-sarabande,,,png}
661 @end ifnottex
662
663 @noindent The LilyPond 1.4 output is certainly readable, but close
664 comparison with the hand-engraved score showed a lot of errors in the
665 formatting details:
666
667 @iftex
668 @sourceimage{lily14-sarabande-annotated-hires,16cm,,}
669 @end iftex
670 @ifnottex
671 @sourceimage{lily14-sarabande-annotated,,,png}
672 @end ifnottex
673
674 @itemize @bullet
675 @item there is too much space before the time signature
676 @item the stems of the beamed notes are too long
677 @item the second and fourth measures are too narrow
678 @item the slur is awkward-looking
679 @item the trill marks are too big
680 @item the stems are too thin
681 @end itemize
682
683 @noindent
684 (There were also two missing note heads, several missing editorial
685 annotations, and an incorrect pitch!)
686
687 By adjusting the layout rules and font design, the output has improved
688 considerably.  Compare the same reference score and the output
689 from the current version of LilyPond (@version{}):
690
691 @iftex
692 @sourceimage{baer-sarabande-hires,16cm,,}
693 @end iftex
694 @ifnottex
695 @sourceimage{baer-sarabande,,,png}
696 @end ifnottex
697
698 @lilypond[staffsize=17.5,line-width=15.9\cm]
699 \relative c {
700   \clef "bass"
701   \key d \minor
702   \time 3/4
703   \mergeDifferentlyDottedOn
704   <<
705     { \slurDashed d8.-\flageolet( e16) e4.-\trill( d16 e) }
706      \\
707     { d4_2 a2 }
708   >>
709   \slurDashed
710   <f' a, d,>4. e8( d c)
711   \slurSolid
712   bes8 g' f e16( f g_1 a_2 bes_3 d,_2)
713   \slurDashed
714   cis4.-\trill b8_3( a g)
715   <<
716     { \slurDashed d'8.( e16) e4.-\trill( d16 e) }
717      \\
718     { <f, a>4 a2 }
719   >>
720 }
721 @end lilypond
722
723 @noindent
724 The current output is not a clone of the reference edition, but it is
725 much closer to publication quality that the earlier output.
726
727 @node Getting things right
728 @unnumberedsubsec Getting things right
729
730 We can also measure LilyPond's ability to make music engraving decisions
731 automatically by comparing LilyPond's output to the output of a
732 commercial software product.  In this case we have chosen Finale 2008,
733 which is one of the most popular commercial score writers, particularly
734 in North America.  Sibelius is its major rival and appears to be
735 especially strong in the European market.
736
737 For our comparison we selected Bach's Fugue in G minor from the
738 Well-Tempered Clavier, Book I, BWV 861, whose opening subject is
739
740 @lilypond
741 \relative {
742   \key g \minor
743   \clef "treble_8"
744   r8 d' ees g, fis4 g
745   r8 a16 bes c8 bes16 a bes8
746 }
747 @end lilypond
748
749 @noindent
750
751 We made our comparison by engraving the last seven measures of the piece
752 (28--34) in Finale and LilyPond.  This is the point in the piece where
753 the subject returns in a three-part stretto and leads into the closing
754 section.  In the Finale version, we have resisted the temptation to make
755 any adjustments to the default output because we are trying to show the
756 things that each software package gets right without assistance.  The
757 only major edits that we made were adjusting the page size to match this
758 essay and forcing the music onto two systems to make the comparison
759 easier.  By default Finale would have engraved two systems of three
760 measures each and a final, full-width system containing a single
761 measure.
762
763 Many of the differences between the two engravings are visible in
764 measures 28--29, as shown here with Finale first and LilyPond second:
765
766 @iftex
767 @sourceimage{pdf/bwv861mm28-29,14cm,,}
768 @end iftex
769 @ifnottex
770 @sourceimage{bwv861mm28-29,,,png}
771 @end ifnottex
772
773 @lilypond[staffsize=19.5,line-width=14\cm]
774 global = { \key g \minor }
775
776 partI = \relative c' {
777   \voiceOne
778   fis8 d' ees g, fis4 g
779   r8 a16 bes c8 bes16 a d8 r r4
780 }
781
782 partII = \relative c' {
783   \voiceTwo
784   d4 r4 r8 d'16 c bes8 c16 d
785   ees8 d c ees a, r r4
786 }
787
788 partIII = \relative c' {
789   \voiceOne
790   r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
791 }
792
793 partIV = \relative c {
794   \voiceTwo
795   d4 r r2
796   r8 d ees g, fis4 a
797 }
798
799 \score {
800   <<
801     % \set Score.barNumberVisibility = #all-bar-numbers-visible
802     % required in 2.13
803     \set Score.currentBarNumber = #28
804     \bar ""
805     \new PianoStaff <<
806       \new Staff = "RH" <<
807         \global
808         \new Voice = "voiceI" { \partI }
809         \new Voice = "voiceII" { \partII }
810       >>
811       \new Staff = "LH"
812       <<
813         \clef "bass"
814         \global
815         \new Voice = "voiceIII" { \partIII }
816         \new Voice = "voiceIV" { \partIV }
817       >>
818     >>
819   >>
820   \layout {
821     \context {
822       \Staff
823       \remove "Time_signature_engraver"
824     }
825     \context {
826       \PianoStaff
827       \override StaffGrouper.staff-staff-spacing.padding = #1
828     }
829   }
830 }
831 @end lilypond
832
833 Some shortcomings in the unedited Finale output include:
834 @itemize @bullet
835 @item Most of the beams extend too far off the staff.  A beam that points
836 towards the center of the staff should have a length of about one
837 octave, but engravers shorten this when the beam points away from the
838 staff in multi-voice music.  The Finale beaming can easily be improved
839 with their Patterson Beams plug-in, but we elected to skip that step for
840 this example.
841 @item Finale doesn't adjust the positions of interlocking note heads,
842 which makes the music extremely difficult to read when the upper and
843 lower voices exchange positions temporarily:
844
845 @lilypond
846 collide = \once \override NoteColumn.force-hshift = #0
847
848 \score {
849   <<
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" { "good " " bad" }
858   >>
859 }
860 @end lilypond
861
862 @item Finale has placed all of the rests at fixed heights on the staff.
863 The user is free to adjust them as needed, but the software makes no
864 attempt to consider the content of the other voice.  As luck would have
865 it, there are no true collisions between notes and rests in this example,
866 but that has more to do with the positions of the notes than the rest.
867 In other words, Bach deserves more credit for avoiding a complete
868 collision than Finale does.
869
870 @end itemize
871
872 This example is not intended to suggest that Finale cannot be used to
873 produce publication-quality output.  On the contrary, in the hands of a
874 skilled user it can and does, but it requires skill and time.  One of the
875 fundamental differences between LilyPond and commercial scorewriters is
876 that LilyPond hopes to reduce the amount of human intervention to an
877 absolute minimum, while other packages try to provide an attractive
878 interface in which to make these types of edits.
879
880 One particularly glaring omission we found from Finale is a missing flat
881 in measure 33:
882
883 @quotation
884 @iftex
885 @sourceimage{pdf/bwv861mm33-34-annotate,7.93cm,,}
886 @end iftex
887 @ifnottex
888 @sourceimage{bwv861mm33-34-annotate,,,png}
889 @end ifnottex
890 @end quotation
891
892 @noindent
893 The flat symbol is required to cancel out the natural in the same
894 measure, but Finale misses it because it occurred in a different voice.
895 So in addition to running a beaming plug-in and checking the spacing on
896 the noteheads and rests, the user must also check each measure for
897 cross-voice accidentals to avoid interrupting a rehearsal over an
898 engraving error.
899
900 If you are interested in examining these examples in more detail, the
901 full seven-measure excerpt can be found at the end of this essay along
902 with four different published engravings.  Close examination reveals that
903 there is some acceptable variation among the hand-engravings, but that
904 LilyPond compares reasonably well to that acceptable range.  There are
905 still some shortcomings in the LilyPond output, for example, it appears
906 a bit too aggressive in shortening some of the stems, so there is room
907 for further development and fine-tuning.
908
909 Of course, typography relies on human judgment of appearance, so people
910 cannot be replaced completely.  However, much of the dull work can be
911 automated.  If LilyPond solves most of the common situations correctly,
912 this will be a huge improvement over existing software.  Over the course
913 of years, the software can be refined to do more and more things
914 automatically, so manual overrides are less and less necessary.  Where
915 manual adjustments are needed, LilyPond's structure has been designed
916 with that flexibility in mind.
917
918 @node Building software
919 @section Building software
920
921 This section describes some of the programming decisions that we made
922 when designing LilyPond.
923
924 @menu
925 * Music representation::
926 * What symbols to engrave?::
927 * Flexible architecture::
928 @end menu
929
930
931 @node Music representation
932 @unnumberedsubsec Music representation
933
934 @cindex syntax
935 @cindex recursive structures
936
937 Ideally, the input format for any high-level formatting system is
938 an abstract description of the content.  In this case, that would
939 be the music itself.  This poses a formidable problem: how can we
940 define what music really is? Instead of trying to find an answer,
941 we have reversed the question.  We write a program capable of
942 producing sheet music, and adjust the format to be as lean as
943 possible.  When the format can no longer be trimmed down, by
944 definition we are left with content itself.  Our program serves as
945 a formal definition of a music document.
946
947 The syntax is also the user-interface for LilyPond, hence it is
948 easy to type:
949
950 @example
951 @{
952   c'4 d'8
953 @}
954 @end example
955
956 @noindent
957 to create a quarter note on middle C (C1) and an eighth note on
958 the D above middle C (D1).
959
960 @lilypond[quote]
961 {
962   c'4 d'8
963 }
964 @end lilypond
965
966 On a microscopic scale, such syntax is easy to use.  On a larger
967 scale, syntax also needs structure.  How else can you enter
968 complex pieces like symphonies and operas?  The structure is
969 formed by the concept of music expressions: by combining small
970 fragments of music into larger ones, more complex music can be
971 expressed.  For example
972
973 @lilypond[quote,verbatim,fragment,relative=1]
974 f4
975 @end lilypond
976
977 @noindent
978 Simultaneous notes can be constructed by enclosing them with
979 @code{<<} and @code{>>}:
980
981 @example
982 <<c4 d4 e4>>
983 @end example
984
985 @lilypond[quote,fragment,relative=1]
986 \new Voice { <<c4 d4 e>> }
987 @end lilypond
988
989 @noindent
990 This expression is put in sequence by enclosing it in curly braces
991 @code{@{@tie{}@dots{}@tie{}@}}:
992
993 @example
994 @{ f4 <<c4 d4 e4>> @}
995 @end example
996
997 @lilypond[quote,relative=1,fragment]
998 { f4 <<c d e4>> }
999 @end lilypond
1000
1001 @noindent
1002 The above is also an expression, and so it may be combined again
1003 with another simultaneous expression (a half note) using
1004 @code{<<}, @code{\\}, and @code{>>}:
1005
1006 @example
1007 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
1008 @end example
1009
1010 @lilypond[quote,fragment,relative=2]
1011 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
1012 @end lilypond
1013
1014 Such recursive structures can be specified neatly and formally in
1015 a context-free grammar.  The parsing code is also generated from
1016 this grammar.  In other words, the syntax of LilyPond is clearly
1017 and unambiguously defined.
1018
1019 User-interfaces and syntax are what people see and deal with most.
1020 They are partly a matter of taste, and also the subject of much
1021 discussion.  Although discussions on taste do have their merit,
1022 they are not very productive.  In the larger picture of LilyPond,
1023 the importance of input syntax is small: inventing neat syntax is
1024 easy, while writing decent formatting code is much harder.  This
1025 is also illustrated by the line-counts for the respective
1026 components: parsing and representation take up less than 10% of
1027 the source code.
1028
1029 When designing the structures used in LilyPond, we made some different
1030 decisions than are apparent in other software.  Consider the hierarchical
1031 nature of music notation:
1032
1033 @lilypond[quote,fragment]
1034 <<
1035   \new Staff \relative {
1036     \key g \major
1037     \time 3/4
1038     d''4 g,8 a b c d4 g, g
1039   }
1040   \new Staff \relative {
1041     \clef "bass"
1042     \key g \major
1043     <g b d>2 a4 b2.
1044   }
1045 >>
1046 @end lilypond
1047
1048 In this case, there are pitches grouped into chords that belong to
1049 measures, which belong to staves.  This resembles a tidy structure of
1050 nested boxes:
1051
1052 @quotation
1053 @iftex
1054 @sourceimage{pdf/nestedboxes,,4cm,}
1055 @end iftex
1056 @ifnottex
1057 @sourceimage{nestedboxes,,,png}
1058 @end ifnottex
1059 @end quotation
1060
1061 Unfortunately, the structure is tidy because it is based on some
1062 excessively restrictive assumptions.  This becomes apparent if we
1063 consider a more complicated musical example:
1064
1065 @lilypond[quote]
1066 \layout {
1067   \context {
1068     \Score
1069     \remove "Timing_translator"
1070     \remove "Default_bar_line_engraver"
1071   }
1072   \context {
1073     \Staff
1074     \consists "Timing_translator"
1075     \consists "Default_bar_line_engraver"
1076   }
1077 }
1078
1079 \new PianoStaff <<
1080   \new Staff = "RH" <<
1081     \new Voice = "I" \relative c''' {
1082       \time 3/4
1083       \voiceOne
1084       \tuplet 7/6 { g8 g g g g g g }
1085       \oneVoice
1086       r4 <b,, fis' g bes> r4\fermata
1087     }
1088     \new Voice = "II" \relative c' {
1089       \voiceTwo
1090       c4
1091       \tuplet 5/4 {
1092         <c ees>8 f g
1093         \change Staff = "LH" \oneVoice
1094         \stemUp g,( c}
1095       r4
1096       \override Stem.cross-staff = ##t
1097       \override Stem.length = #12
1098       <fis, b>) r\fermata
1099     }
1100   >>
1101   \new Staff = "LH" <<
1102     \new Voice = "III" \relative {
1103       \time 2/4
1104       \clef "bass"
1105       g4 \stopStaff s
1106       \startStaff s2*2
1107     }
1108   >>
1109 >>
1110 @end lilypond
1111
1112 In this example, staves start and stop at will, voices jump around
1113 between staves, and the staves have different time signatures.  Many
1114 software packages would struggle with reproducing this example because
1115 they are built on the nested box structure.  With LilyPond, on the other
1116 hand, we have tried to keep the input format and the structure as
1117 flexible as possible.
1118
1119 @node What symbols to engrave?
1120 @unnumberedsubsec What symbols to engrave?
1121
1122 @cindex engraving
1123 @cindex typography
1124 @cindex engraver
1125 @cindex plug-in
1126
1127 The formatting process decides where to place symbols.  However,
1128 this can only be done once it is decided @emph{what} symbols
1129 should be printed -- in other words, what notation to use.
1130
1131 Common music notation is a system of recording music that has
1132 evolved over the past 1000 years.  The form that is now in common
1133 use dates from the early Renaissance.  Although the basic form
1134 (i.e., note heads on a 5-line staff) has not changed, the details
1135 still evolve to express the innovations of contemporary notation.
1136 Hence, common music notation encompasses some 500 years of music.
1137 Its applications range from monophonic melodies to monstrous
1138 counterpoints for a large orchestra.
1139
1140 How can we get a grip on such a seven-headed beast, and force it
1141 into the confines of a computer program?  Our solution is to break
1142 up the problem of notation (as opposed to engraving, i.e.,
1143 typography) into digestible and programmable chunks: every type of
1144 symbol is handled by a separate module, a so-called plug-in.  Each
1145 plug-in is completely modular and independent, so each can be
1146 developed and improved separately.  Such plug-ins are called
1147 @code{engraver}s, by analogy with craftsmen who translate musical
1148 ideas to graphic symbols.
1149
1150 In the following example, we start out with a plug-in for note
1151 heads, the @code{Note_heads_engraver}.
1152
1153 @lilypond[quote,ragged-right]
1154 \include "engraver-example.ily"
1155
1156 \score {
1157   \topVoice
1158   \layout {
1159     \context {
1160       \Voice
1161       \remove "Stem_engraver"
1162       \remove "Phrasing_slur_engraver"
1163       \remove "Slur_engraver"
1164       \remove "Script_engraver"
1165       \remove "New_fingering_engraver"
1166       \remove "Beam_engraver"
1167       \remove "Auto_beam_engraver"
1168     }
1169     \context {
1170       \Staff
1171       \remove "Accidental_engraver"
1172       \remove "Key_engraver"
1173       \remove "Clef_engraver"
1174       \remove "Bar_engraver"
1175       \remove "Time_signature_engraver"
1176       \remove "Staff_symbol_engraver"
1177       \consists "Pitch_squash_engraver"
1178     }
1179   }
1180 }
1181 @end lilypond
1182
1183 @noindent
1184 Then a @code{Staff_symbol_engraver} adds the staff,
1185
1186 @lilypond[quote,ragged-right]
1187 \include "engraver-example.ily"
1188
1189 \score {
1190   \topVoice
1191   \layout {
1192     \context {
1193       \Voice
1194       \remove "Stem_engraver"
1195       \remove "Phrasing_slur_engraver"
1196       \remove "Slur_engraver"
1197       \remove "Script_engraver"
1198       \remove "New_fingering_engraver"
1199       \remove "Beam_engraver"
1200       \remove "Auto_beam_engraver"
1201     }
1202     \context {
1203       \Staff
1204       \remove "Accidental_engraver"
1205       \remove "Key_engraver"
1206       \remove "Clef_engraver"
1207       \remove "Bar_engraver"
1208       \consists "Pitch_squash_engraver"
1209       \remove "Time_signature_engraver"
1210     }
1211   }
1212 }
1213 @end lilypond
1214
1215 @noindent
1216 the @code{Clef_engraver} defines a reference point for the staff,
1217
1218 @lilypond[quote,ragged-right]
1219 \include "engraver-example.ily"
1220
1221 \score {
1222   \topVoice
1223   \layout {
1224     \context {
1225       \Voice
1226       \remove "Stem_engraver"
1227       \remove "Phrasing_slur_engraver"
1228       \remove "Slur_engraver"
1229       \remove "Script_engraver"
1230       \remove "New_fingering_engraver"
1231       \remove "Beam_engraver"
1232       \remove "Auto_beam_engraver"
1233     }
1234     \context {
1235       \Staff
1236       \remove "Accidental_engraver"
1237       \remove "Key_engraver"
1238       \remove "Bar_engraver"
1239       \remove "Time_signature_engraver"
1240     }
1241   }
1242 }
1243 @end lilypond
1244
1245 @noindent
1246 and the @code{Stem_engraver} adds stems.
1247
1248 @lilypond[quote,ragged-right]
1249 \include "engraver-example.ily"
1250
1251 \score {
1252   \topVoice
1253   \layout {
1254     \context {
1255       \Voice
1256       \remove "Phrasing_slur_engraver"
1257       \remove "Slur_engraver"
1258       \remove "Script_engraver"
1259       \remove "New_fingering_engraver"
1260       \remove "Beam_engraver"
1261       \remove "Auto_beam_engraver"
1262     }
1263     \context {
1264       \Staff
1265       \remove "Accidental_engraver"
1266       \remove "Key_engraver"
1267       \remove "Bar_engraver"
1268       \remove "Time_signature_engraver"
1269     }
1270   }
1271 }
1272 @end lilypond
1273
1274 @noindent
1275 The @code{Stem_engraver} is notified of any note head coming
1276 along.  Every time one (or more, for a chord) note head is seen, a
1277 stem object is created and connected to the note head.  By adding
1278 engravers for beams, slurs, accents, accidentals, bar lines, time
1279 signature, and key signature, we get a complete piece of notation.
1280
1281 @lilypond[quote,ragged-right]
1282 \include "engraver-example.ily"
1283 \score { \topVoice }
1284 @end lilypond
1285
1286 @cindex polyphony
1287 @cindex engraving multiple voices
1288 @cindex contexts
1289
1290 This system works well for monophonic music, but what about
1291 polyphony?  In polyphonic notation, many voices can share a staff.
1292
1293 @lilypond[quote,ragged-right]
1294 \include "engraver-example.ily"
1295 \new Staff << \topVoice \\ \botVoice >>
1296 @end lilypond
1297
1298 In this situation, the accidentals and staff are shared, but the
1299 stems, slurs, beams, etc., are private to each voice.  Hence,
1300 engravers should be grouped.  The engravers for note heads, stems,
1301 slurs, etc., go into a group called @q{Voice context}, while the
1302 engravers for key, accidental, bar, etc., go into a group called
1303 @q{Staff context}.  In the case of polyphony, a single Staff
1304 context contains more than one Voice context.  Similarly, multiple
1305 Staff contexts can be put into a single Score context.  The Score
1306 context is the top level notation context.
1307
1308 @lilypond[quote,ragged-right]
1309 \include "engraver-example.ily"
1310 \score {
1311    <<
1312       \new Staff << \topVoice \\ \botVoice >>
1313       \new Staff << \pah \\ \hoom >>
1314    >>
1315 }
1316 @end lilypond
1317
1318 @seealso
1319 Internals Reference: @rinternals{Contexts}.
1320
1321 @node Flexible architecture
1322 @unnumberedsubsec Flexible architecture
1323
1324 When we started, we wrote the LilyPond program entirely in the C++
1325 programming language; the program's functionality was set in stone
1326 by the developers.  That proved to be unsatisfactory for a number
1327 of reasons:
1328
1329 @itemize
1330
1331 @item When LilyPond makes mistakes, users need to override
1332 formatting decisions.  Therefore, the user must have access to the
1333 formatting engine.  Hence, rules and settings cannot be fixed by
1334 us at compile-time but must be accessible for users at run-time.
1335
1336 @item Engraving is a matter of visual judgment, and therefore a
1337 matter of taste.  As knowledgeable as we are, users can disagree
1338 with our personal decisions.  Therefore, the definitions of
1339 typographical style must also be accessible to the user.
1340
1341 @item Finally, we continually refine the formatting algorithms, so
1342 we need a flexible approach to rules.  The C++ language forces a
1343 certain method of grouping rules that cannot readily be applied to
1344 formatting music notation.
1345
1346 @end itemize
1347
1348 @cindex Scheme programming language
1349
1350 These problems have been addressed by integrating an interpreter
1351 for the Scheme programming language and rewriting parts of
1352 LilyPond in Scheme.  The current formatting architecture is built
1353 around the notion of graphical objects, described by Scheme
1354 variables and functions.  This architecture encompasses formatting
1355 rules, typographical style and individual formatting decisions.
1356 The user has direct access to most of these controls.
1357
1358 Scheme variables control layout decisions.  For example, many
1359 graphical objects have a direction variable that encodes the
1360 choice between up and down (or left and right).  Here you see two
1361 chords, with accents and arpeggios.  In the first chord, the
1362 graphical objects have all directions down (or left).  The second
1363 chord has all directions up (right).
1364
1365 @lilypond[quote,ragged-right]
1366 \score {
1367   \relative c' {
1368     \stemDown <e g b>4_>-\arpeggio
1369     \override Arpeggio.direction = #RIGHT
1370     \stemUp <e g b>4^>-\arpeggio
1371   }
1372   \layout {
1373     \context {
1374       \Score
1375       \override SpacingSpanner.spacing-increment = #3
1376       \hide TimeSignature
1377     }
1378   }
1379 }
1380 @end lilypond
1381
1382 @cindex score formatting
1383 @cindex formatting a score
1384 @cindex formatting rules
1385
1386 @noindent
1387 The process of formatting a score consists of reading and writing
1388 the variables of graphical objects.  Some variables have a preset
1389 value.  For example, the thickness of many lines -- a
1390 characteristic of typographical style -- is a variable with a
1391 preset value.  You are free to alter this value, giving your score
1392 a different typographical impression.
1393
1394 @lilypond[quote,ragged-right]
1395 fragment = {
1396    \clef bass f8 as8
1397    c'4-~ c'16 as g f e16 g bes c' des'4
1398 }
1399 <<
1400    \new Staff \fragment
1401    \new Staff \with {
1402       \override Beam.beam-thickness = #0.3
1403       \override Stem.thickness = #0.5
1404       \override Bar.thickness = #3.6
1405       \override Tie.thickness = #2.2
1406       \override StaffSymbol.thickness = #3.0
1407       \override Tie.extra-offset = #'(0 .  0.3)
1408       }
1409       \fragment
1410 >>
1411 @end lilypond
1412
1413 Formatting rules are also preset variables: each object has
1414 variables containing procedures.  These procedures perform the
1415 actual formatting, and by substituting different ones, we can
1416 change the appearance of objects.  In the following example, the
1417 rule governing which note head objects are used to produce the
1418 note head symbol is changed during the music fragment.
1419
1420 @lilypond[quote,ragged-right]
1421 #(set-global-staff-size 30)
1422
1423 #(define (mc-squared grob orig current)
1424   (let* ((interfaces (ly:grob-interfaces grob))
1425          (pos (ly:grob-property grob 'staff-position)))
1426     (if (memq 'note-head-interface interfaces)
1427         (begin
1428           (ly:grob-set-property! grob 'stencil
1429             (grob-interpret-markup grob
1430               (make-lower-markup 0.5
1431                 (case pos
1432                   ((-5) "m")
1433                   ((-3) "c ")
1434                   ((-2) (make-smaller-markup (make-bold-markup "2")))
1435                   (else "bla")))))))))
1436
1437 \new Voice \relative c' {
1438   \stemUp
1439   \set autoBeaming = ##f
1440   \time 2/4
1441   <d f g>4
1442   \once \override NoteHead.stencil = #note-head::brew-ez-stencil
1443   \once \override NoteHead.font-size = #-7
1444   \once \override NoteHead.font-family = #'sans
1445   \once \override NoteHead.font-series = #'bold
1446   <d f g>4
1447   \once \override NoteHead.style = #'cross
1448   <d f g>4
1449   \applyOutput #'Voice #mc-squared
1450   <d f g>4
1451   <<
1452     { d8[ es-( fis^^ g] fis2-) }
1453     \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
1454   >>
1455 }
1456 @end lilypond
1457
1458
1459
1460 @node Putting LilyPond to work
1461 @section Putting LilyPond to work
1462
1463 @cindex simple examples
1464 @cindex examples, simple
1465
1466 We have written LilyPond as an experiment of how to condense the
1467 art of music engraving into a computer program.  Thanks to all
1468 that hard work, the program can now be used to perform useful
1469 tasks.  The simplest application is printing notes.
1470
1471 @lilypond[quote,relative=1]
1472 {
1473   \time 2/4
1474   c4 c g'4 g a4 a g2
1475 }
1476 @end lilypond
1477
1478 @noindent
1479 By adding chord names and lyrics we obtain a lead sheet.
1480
1481 @lilypond[quote,ragged-right]
1482 <<
1483    \chords { c2 c f2 c }
1484    \new Staff
1485    \relative {
1486      \time 2/4
1487      c'4 c g' g a a g2
1488    }
1489    \addlyrics { twin -- kle twin -- kle lit -- tle star }
1490 >>
1491 @end lilypond
1492
1493 Polyphonic notation and piano music can also be printed.  The
1494 following example combines some more exotic constructs.
1495
1496 @lilypond[quote,line-width=15.9\cm]
1497 \header {
1498   title = "Screech and boink"
1499   subtitle = "Random complex notation"
1500   composer = "Han-Wen Nienhuys"
1501 }
1502
1503 \score {
1504   \context PianoStaff <<
1505     \new Staff = "up" {
1506       \time 4/8
1507       \key c \minor
1508       << {
1509         \revert Stem.direction
1510         \change Staff = down
1511         \set subdivideBeams = ##t
1512         g16.[
1513           \change Staff = up
1514           c'''32
1515           \change Staff = down
1516           g32
1517           \change Staff = up
1518           c'''32
1519           \change Staff = down
1520           g16]
1521         \change Staff = up
1522         \stemUp
1523         \set followVoice = ##t
1524         c'''32([ b''16 a''16 gis''16 g''32)]
1525       } \\ {
1526         s4 \tuplet 3/2 { d'16[ f' g'] } as'32[ b''32 e'' d'']
1527       } \\ {
1528         s4 \autoBeamOff d''8.. f''32
1529       } \\ {
1530         s4 es''4
1531       } >>
1532     }
1533
1534     \new Staff = "down" {
1535       \clef bass
1536       \key c \minor
1537       \set subdivideBeams = ##f
1538       \override Stem.french-beaming = ##t
1539       \override Beam.beam-thickness = #0.3
1540       \override Stem.thickness = #4.0
1541       g'16[ b16 fis16 g16]
1542       << \makeClusters {
1543         as16 <as b>
1544         <g b>
1545         <g cis>
1546       } \\ {
1547         \override Staff.Arpeggio.arpeggio-direction =#down
1548         <cis, e, gis, b, cis>4\arpeggio
1549       }
1550     >> }
1551   >>
1552   \midi {
1553     \tempo 8 = 60
1554   }
1555   \layout {
1556     \context {
1557       \Staff
1558       \consists "Horizontal_bracket_engraver"
1559     }
1560   }
1561 }
1562 @end lilypond
1563
1564 The fragments shown above have all been written by hand, but that
1565 is not a requirement.  Since the formatting engine is mostly
1566 automatic, it can serve as an output means for other programs that
1567 manipulate music.  For example, it can also be used to convert
1568 databases of musical fragments to images for use on websites and
1569 multimedia presentations.
1570
1571 This manual also shows an application: the input format is text, and can
1572 therefore be easily embedded in other text-based formats such as
1573 @LaTeX{}, HTML, or in the case of this manual, Texinfo.  Using the
1574 @command{lilypond-book} program, included with LilyPond, the input
1575 fragments can be replaced by music images in the resulting PDF or HTML
1576 output files.  Another example is the third-party OOoLilyPond extension
1577 for OpenOffice.org or LibreOffice, which makes it extremely easy to
1578 embed musical examples in documents.
1579
1580 For more examples of LilyPond in action, full documentation, and the
1581 software itself, see our main website: www.lilypond.org.
1582
1583 @page
1584 @node Engraved examples (BWV 861)
1585 @section Engraved examples (BWV 861)
1586
1587 This section contains four reference engravings and two
1588 software-engraved versions of Bach's Fugue in G minor from the
1589 Well-Tempered Clavier, Book I, BWV 861 (the last seven measures).
1590
1591 @noindent
1592 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1593 1989):
1594
1595 @iftex
1596 @sourceimage{bwv861-baer,16cm,,}
1597 @end iftex
1598 @ifnottex
1599 @sourceimage{bwv861-baer-small,,,png}
1600 @end ifnottex
1601
1602 @noindent
1603 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1604 1989), an alternate musical source.  Aside from the textual differences,
1605 this demonstrates slight variations in the engraving decisions, even
1606 from the same publisher and edition:
1607
1608 @iftex
1609 @sourceimage{bwv861-baer-alt,16cm,,}
1610 @end iftex
1611 @ifnottex
1612 @sourceimage{bwv861-baer-alt-small,,,png}
1613 @end ifnottex
1614
1615 @noindent
1616 Breitkopf & Härtel, edited by Ferruccio Busoni (Wiesbaden, 1894), also
1617 available from the Petrucci Music Library (IMSLP #22081).  The editorial
1618 markings (fingerings, articulations, etc.) have been removed for clearer
1619 comparison with the other editions here:
1620
1621 @iftex
1622 @sourceimage{bwv861-breitkopf,16cm,,}
1623 @end iftex
1624 @ifnottex
1625 @sourceimage{bwv861-breitkopf-small,,,png}
1626 @end ifnottex
1627
1628 @noindent
1629 Bach-Gesellschaft edition (Leipzig, 1866), available from the Petrucci
1630 Music Library (IMSPL #02221):
1631
1632 @iftex
1633 @sourceimage{bwv861-gessellschaft,16cm,,}
1634 @end iftex
1635 @ifnottex
1636 @sourceimage{bwv861-gessellschaft-small,,,png}
1637 @end ifnottex
1638
1639 @noindent
1640 Finale 2008:
1641
1642 @iftex
1643 @sourceimage{pdf/bwv861-finale2008a,,,}
1644 @end iftex
1645 @ifnottex
1646 @sourceimage{bwv861-finale2008a,,,png}
1647 @end ifnottex
1648
1649 @sp 4
1650 @noindent
1651 LilyPond, version @version{}:
1652
1653 @lilypond[staffsize=14.3,line-width=15.9\cm]
1654 global = {\key g \minor}
1655
1656 partI = \relative c' {
1657   \voiceOne
1658   fis8 d' ees g, fis4 g
1659   r8 a16 bes c8 bes16 a d8 r r4
1660   r2 r8 d16 ees f8 ees16 d
1661   ees4 ~ 16 d c bes a4 r8 ees'16 d
1662   c8 d16 ees d8 e16 fis g8 fis16 g a4 ~
1663   8 d, g f ees d c bes
1664   a2 g\fermata \bar "|."
1665 }
1666
1667 partII = \relative c' {
1668   \voiceTwo
1669   d4 r4 r8 d'16 c bes8 c16 d
1670   ees8 d c ees a, r r4
1671   r8 fis16 g a8 g16 fis g2 ~
1672   2 r8 d' ees g,
1673   fis4 g r8 a16 bes c8 bes16 a
1674   bes4. <g b>8 <a c> r <d, g> r
1675   <ees g>4 <d fis> d2
1676 }
1677 partIII = \relative c' {
1678   \voiceOne
1679   r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
1680   bes2 ~ 8 b16 a g8 a16 b
1681   c4 r r2
1682   R1
1683   r8 d ees g, fis4 g
1684   r8 a16 bes c8 bes16 a b2
1685 }
1686 partIV = \relative c {
1687   \voiceTwo
1688   d4 r r2
1689   r8 d ees g, fis4 a
1690   d,8 d'16 c bes8 c16 d ees2 ~
1691   8 ees16 d c8 d16 ees fis,8 a16 g fis8 g16 a
1692   d,8 d'16 c bes8 c16 d ees8 c a fis'
1693   g f ees d c bes a g
1694   c a d d, g2\fermata
1695 }
1696
1697 \score {
1698   <<
1699     % \set Score.barNumberVisibility = #all-bar-numbers-visible
1700     % required in 2.13
1701     \set Score.currentBarNumber = #28
1702     \bar ""
1703     \new PianoStaff <<
1704       \new Staff = "RH" <<
1705         \global
1706         \new Voice = "voiceI" { \partI }
1707         \new Voice = "voiceII" { \partII }
1708       >>
1709
1710       \new Staff = "LH" <<
1711         \clef "bass"
1712         \global
1713         \new Voice = "voiceIII" { \partIII }
1714         \new Voice = "voiceIV" { \partIV }
1715       >>
1716     >>
1717   >>
1718   \layout {
1719     \context {
1720       \Staff
1721       \remove "Time_signature_engraver"
1722     }
1723     \context {
1724       \PianoStaff
1725       \override StaffGrouper.staff-staff-spacing.padding = #1
1726     }
1727   }
1728 }
1729 @end lilypond