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