]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/hu/essay/engraving.itely
Merge remote branch 'origin/master' into release/unstable
[lilypond.git] / Documentation / hu / essay / engraving.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: e5d3fb33ceaec6d10e06af0c667e4e982a0028ce
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.2"
12
13 @node A kottaszedés
14 @chapter A kottaszedés
15 @translationof Music engraving
16
17 Ez az esszé leírja, miért született a LilyPond, és hogyan képes ilyen gyönyörű kottákat előállítani.
18
19
20 @c TODO:
21 @c remove 3mm eps bounding box left padding for Sarabande (This will
22 @c     require adding a new snippet option to lilypond-book.py
23 @c check formatting of HTML output
24
25 @menu
26 * A LilyPond története::
27 * A kottaszedés fortélyai::
28 * Automated engraving::
29 * Building software::
30 * Putting LilyPond to work::
31 * Engraved examples (BWV 861)::
32 @end menu
33
34 @node A LilyPond története
35 @section A LilyPond története
36 @translationof The LilyPond story
37
38 Mielőtt a LilyPondot koncerteken használt csodaszép kották szedésére kezdtük volna használni, mielőtt zenetudományi dokumentumok zenei idézeteit vagy akár egyszerű dallamokat le lehetett volna vele kottázni, mielőtt szerte a világon a felhasználók széles körben kezdték volna használni, vagy ez az esszé megszületett volna, a LilyPond története egy kérdéssel kezdődött: 
39
40 @quotation
41 Miért nem adják vissza a számítógép által szedett kották a kézzel szedett kották szépségét és kiegyensúlyozottságát?
42 @end quotation
43
44 @noindent
45 Erre többnyire választ kaphatunk, ha górcső alá vesszük a következő két kottát. Az első példa egy gondosan kézzel szedett kotta 1950-ből, a második egy modern, számítógéppel szedett kiadás.
46
47 @ifnottex
48 @quotation
49 @noindent
50 Bärenreiter BA 320, @copyright{}1950:
51
52 @sourceimage{baer-suite1-fullpage,,,png}
53 @end quotation
54
55 @quotation
56 @noindent
57 Henle no. 666, @copyright{}2000:
58
59 @sourceimage{henle-suite1-fullpage,,,png}
60 @end quotation
61 @end ifnottex
62
63 J. S. Bach első, csellóra írt szólószvitjének két kiadása hangról hangra megegyezik, mégis megjelenésükben merőben különbözőek, különösen, ha kinyomtatjuk és megszokott távolságból szemléljük őket. Próbáljuk meg mindkét kottapéldát elolvasni, illetve játszani belőlük, és meg fogjuk állapítani, hogy a kézzel szedett kotta használata kellemesebb. Folyékonysága és dinamikája egy élő, lélegző zenemű érzetét kelti, miközben az újabb kiadás hidegnek és mechanikusnak hat.
64
65 Nehéz egyből észrevenni, miben rejlik a különbség a kották között. Az új kotta első ránézésre rendezett és pontos, talán még „jobb” is, mivel számítógéphez illőbb és egységes a megjelenése. Ez gondolkodóba ejtett minket egy időre. Javítani akartunk a számítógép által szedett kottaképen, de ehhez előbb rá kellett jönnünk, mi volt a gond vele.
66
67 A válasz az új kotta precíz, matematikai pontosságú egyformaságában rejlik. Keressük csak meg minden sor közepén az ütemvonalakat: a kézzel szedett változatban az ütemvonalak elhelyezkedése természetes módon változik, míg a számítógép szinte pontosan egymás alá, középre szedte őket. Ezt mutatja be a következő egyszerűsített ábra, melyen a kézzel (balra), ill. a komputerrel szedett változat (jobbra) elrendezése látható:
68
69 @quotation
70 @iftex
71 @sourceimage{pdf/page-layout-comparison,,,}
72 @end iftex
73 @ifnottex
74 @sourceimage{page-layout-comparison,,,png}
75 @end ifnottex
76 @end quotation
77 @noindent
78
79 A számítógép által előállított szedésben még az egyes kottafejek is függőlegesen egymáshoz lettek igazítva, ami azt az érzetet kelti, mintha a dallamvonal eltűnne egy szimbólumokból álló merev rács mögött.
80
81 További különbségek is vannak: a kézzel szedett változat függőleges vonalai erősebbek, a kötőívek szorosabban tapadnak a kottafejekhez, és a gerendák szögeiben is nagyobb változatosság figyelhető meg. Noha az ilyen részletes elemzés szőrszálhasogatásnak tűnhet, végeredménye egy olyan kotta, ami egyszerűbben olvasható. A számítógépes kottában minden sor szinte egyforma, és ha a zenész egy pillanatra máshová tekint, hamar elveszítheti a tájékozódást az oldalon.
82
83 A LilyPond megalkotásának célja az volt, hogy kiküszöböljük a többi kottaszedő szoftver szépséghibáit, és segítségével olyan kottákat lehessen előállítani, melyek szépsége a legigényesebb kézzel szedett kottákéval vetélkedik.
84
85 @iftex
86 @page
87 @noindent
88 Bärenreiter BA 320, @copyright{}1950:
89
90 @sourceimage{baer-suite1-fullpage-hires,16cm,,}
91 @page
92 @noindent
93 Henle no. 666, @copyright{}2000:
94 @sp 3
95 @sourceimage{henle-suite1-fullpage-hires,16cm,,}
96 @page
97 @end iftex
98
99 @node A kottaszedés fortélyai
100 @section A kottaszedés fortélyai
101 @translationof Engraving details
102
103 @cindex engraving
104 @cindex typography, music
105 @cindex music typography
106 @cindex plate engraving
107 @cindex music engraving
108
109 A zeneművek nyomdai előkészítését @emph{kottaszedésnek} nevezik. Ez a kifejezés a kották nyomtatásának  hagyományos, kézi módszerére utal.@footnote{A régi idők nyomdászai különböző technikákat próbáltak ki, mint például a kézzel metszett fa nyomóformák (nyomódúc), a mozgatható betű- és nyomóelemek, illetve a gravírozott vékony fémlemezek. A mozgatható betű- és nyomóelemekkel való szedésnek megvolt az az előnye, hogy gyorsan bele lehetett javítani és egyszerűen lehetett szöveget is beleilleszteni. De csak a fémlemezre végzett hangjegymetszés tette lehetővé a hibátlan elrendezést és az új kottaelemek gyors bevezetését. Végül ez utóbbi technika lett a szabvány, és még a 20. század elején is ez volt a helyzet, pár korálkönyv és daloskönyv kivételével, ahol a sablonelemek használatát annak gazdaságossága és gyorsasága indokolta.} Ez a folyamat még a 20. században első felében is úgy nézett ki, hogy a kotta elemeit kivágták, majd tükrözve belemélyesztették egy cink- vagy ónlemezbe. A lemezre ezután festéket hordtak fel, és a festék a bemélyedésekben maradt. A lemez a papírra rányomva a kotta képét adta. A metszést teljesen kézzel végezték, és bárminemű javítás nagyon körülményes volt, így a kottakép elsőre tökéletes kellett, hogy legyen. A kottaszedés tudománya nagyon különleges szakma, ahol a kézművesnek körülbelül öt éves képzést kellett elvégeznie, mielőtt a mester címet kérvényezhette. További öt év volt szükséges ahhoz, hogy a szakma minden csínját-bínját valóban magáénak tudhassa.
110
111 @quotation
112 @iftex
113 @sourceimage{hader-slaan,,7cm,}
114 @end iftex
115 @ifnottex
116 @sourceimage{hader-slaan,,,jpg}
117 @end ifnottex
118 @end quotation
119
120 A LilyPond megalkotását azok a kézzel szedett kották inspirálták, amelyeket a 20. század közepe felé az európai kottakiadók (többek között Bärenreiter, Duhem, Durand, Hofmeister, Peters és Schott) hoztak forgalomba. Munkásságukat bizonyos szempontból a hagyományos kottaszedés csúcsának lehet tekinteni. Kiadványaik tanulmányozásával rengeteget tanultunk arról, mik az ismertetőjelei egy szép tipográfiájú kottának, és milyen szempontokat szeretnénk a LilyPonddal utánozni.
121
122 @c Now all newly printed music is produced with computers.  This has
123 @c obvious advantages: prints are cheaper to make, editorial work can be
124 @c delivered by email, and the original data can be easily stored.
125 @c Unfortunately, computer-generated scores rarely match the quality of
126 @c hand-engraved scores.  Instead, computer printouts have a bland,
127 @c mechanical look, which makes them unpleasant to play from.
128
129 @menu
130 * A kottában használt betűtípusok::
131 * Optical spacing::
132 * Ledger lines::
133 * Optical sizing::
134 * Why work so hard?::
135 @end menu
136
137 @node A kottában használt betűtípusok
138 @unnumberedsubsec A kottában használt betűtípusok
139 @translationof Music fonts
140
141 A lenti ábra jól mutatja a különbséget egy hagyományosan és egy számítógép által szedett kottaelem közt. A bal oldali képen egy beszkennelt b módosítójel látható egy kézi Bärenreiter kiadásból, míg a jobb oldali ugyanennek a zeneműnek 2000-ben kiadott változatából származik. Noha mindkét képet ugyanolyan árnyalatú tintával nyomtatták, a régebbi verzió sötétebb: a kottasorok vonalai vastagabbak, és a Bärenreiter b-je gömbölyded, majdhogynem érzékien kerek. A jobb oldali kép vonalai ezzel szemben vékonyabbak, elrendezése szögletes, sarkai élesek.
142
143 @multitable @columnfractions .25 .25 .25 .25
144 @item @tab
145 @ifnotinfo
146 @iftex
147 @sourceimage{baer-flat-gray,,4cm,}
148 @end iftex
149 @ifnottex
150 @sourceimage{baer-flat-gray,,,png}
151 @end ifnottex
152
153 @tab
154 @iftex
155 @sourceimage{henle-flat-gray,,4cm,}
156 @end iftex
157 @ifnottex
158 @sourceimage{henle-flat-gray,,,png}
159 @end ifnottex
160
161 @end ifnotinfo
162 @ifinfo
163 @sourceimage{henle-flat-bw,,,png}
164 @sourceimage{baer-flat-bw,,,png}
165 @sourceimage{lily-flat-bw,,,png}
166 @end ifinfo
167
168
169 @item @tab
170 Bärenreiter (1950)
171 @tab
172 Henle (2000)
173
174 @end multitable
175
176 @cindex musical symbols
177 @cindex font
178 @cindex blackness
179 @cindex balance
180
181 Amikor úgy döntöttük, hogy írunk egy kottaszedő programot, nem volt olyan, szabad felhasználású zenei betűtípus, ami jól passzolt volna kedvenc kottáink elegáns kottaképéhez. Ezen felbuzdulva megalkottunk egy zenei szimbólumokból álló betűtípust, amely a kézzel szedett kották szemrevaló kinézetét veszi alapul. A betűtípus megtervezése során szerzett tapasztalatok nélkül soha nem ismertük volna fel, milyen csúnyák is azok a betűtípusok, amiket eleinte csodáltunk.
182
183 Lent két zenei betűkészletre láthatunk példát: a felső a Sibelius alapbeállítású készlete (@emph{Opus}), az alsó a LilyPondé.
184
185 @quotation
186 @iftex
187 @sourceimage{pdf/OpusAndFeta,,,}
188 @end iftex
189 @ifnottex
190 @sourceimage{OpusAndFeta,,,png}
191 @end ifnottex
192 @end quotation
193
194 A LilyPond kottaelemei vastagabbak, valamint vastagságuk konzisztensebb, ami miatt jóval egyszerűbb az olvasásuk. A vonalaknak, mint például a negyed szünet szárnyai, nem hegyes végük van, hanem finoman legömbölyített. Ennek oka, hogy a hegyes végek a hagyományos nyomóformán nagyon törékenyek, és a használat közben gyorsan elkopnak. Összefoglalva, a jelkészlet teltségét gondosan össze kell hangolni a vonalak (gerendák, ívek) vastagságával, hogy erős, mégis kiegyensúlyozott összképet kapjunk.
195
196 Vegyük észre továbbá, hogy a félkotta feje nem ellipszis, hanem enyhén rombusz alakú. A b módosítójel függőleges szára felfelé némileg kiszélesedik. A keresztet és a feloldójelet egyszerűbb távolról megkülönböztetni, mert ferde vonalaiknak eltérő a dőlésszöge, illetve függőleges vonalaik különböző vastagságúak.
197
198 @node Optical spacing
199 @unnumberedsubsec Optical spacing
200
201 In spacing, the distribution of space should reflect the durations
202 between notes.  However, as we saw in the Bach Suite above, many modern
203 scores adhere to the durations with mathematical precision, which leads
204 to poor results.  In the next example a motif is printed twice: the
205 first time using exact mathematical spacing, and the second with
206 corrections.  Which do you prefer?
207
208 @cindex optical spacing
209
210 @lilypond
211 \paper {
212   ragged-right = ##t
213   indent = #0.0
214 }
215
216 music = {
217    c'4 e''4 e'4 b'4
218    \stemDown
219    b'8[ e'' a' e'']
220    \stemNeutral
221    e'8[ e'8 e'8 e'8]
222 }
223 \score
224 {
225   \music
226   \layout {
227     \context {
228       \Staff
229       \override NoteSpacing.stem-spacing-correction = #0.0
230       \override NoteSpacing.same-direction-correction = #0.0
231       \override StaffSpacing.stem-spacing-correction = #0.0
232     }
233   }
234 }
235 @end lilypond
236
237 @lilypond
238 \paper {
239   ragged-right = ##t
240   indent = #0.0
241 }
242
243 music = {
244    c'4 e''4 e'4 b'4 |
245    \stemDown
246    b'8[ e'' a' e'']
247    \stemNeutral
248    e'8[ e'8 e'8 e'8]
249 }
250
251 \score
252 {
253   \music
254   \layout {
255     \context {
256       \Staff
257       \override NoteSpacing.stem-spacing-correction = #0.6
258     }
259   }
260 }
261 @end lilypond
262
263 @cindex regular rhythms
264 @cindex regular spacing
265 @cindex spacing, regular
266
267 Each bar in the fragment only uses notes that are played in a constant
268 rhythm.  The spacing should reflect that.  Unfortunately, the eye deceives
269 us a little; not only does it notice the distance between note heads, it
270 also takes into account the distance between consecutive stems.  As a
271 result, the notes of an up-stem/@/down-stem combination should be put
272 farther apart, and the notes of a down-stem/@/up-stem combination should
273 be put closer together, all depending on the combined vertical positions
274 of the notes.  The lower two measures are printed with this correction,
275 the upper two measures, however, form down-stem/@/up-stem clumps of
276 notes.  A master engraver would adjust the spacing as needed to please
277 the eye.
278
279 The spacing algorithms in LilyPond even take the barlines into account,
280 which is why the final up-stem in the properly spaced example has been
281 given a little more space before the barline to keep it from looking
282 crowded.  A down-stem would not need this adjustment.
283
284 @node Ledger lines
285 @unnumberedsubsec Ledger lines
286
287 @cindex ledger lines
288 @cindex collisions
289
290 Ledger lines present a typographical challenge: they make it more
291 difficult to space musical symbols close together and they must be clear
292 enough to identify the pitch at a glance.  In the example below, we see
293 that ledger lines should be thicker than normal staff lines and that an
294 expert engraver will shorten a ledger line to allow closer spacing with
295 accidentals.  We have included this feature in LilyPond's engraving.
296
297 @multitable @columnfractions .25 .25 .25 .25
298 @item @tab
299
300 @iftex
301 @sourceimage{baer-ledger,3cm,,}
302 @end iftex
303 @ifnottex
304 @sourceimage{baer-ledger,,,png}
305 @end ifnottex
306
307 @tab
308
309 @iftex
310 @sourceimage{lily-ledger,3cm,,}
311 @end iftex
312 @ifnottex
313 @sourceimage{lily-ledger,,,png}
314 @end ifnottex
315
316 @end multitable
317
318
319 @node Optical sizing
320 @unnumberedsubsec Optical sizing
321
322 Music may need to be printed in a range of sizes.  Originally, this was
323 accomplished by creating punching dies in each of the required sizes,
324 which meant that each die was designed to look its best at that size.
325 With the advent of digital fonts, a single outline can be mathematically
326 scaled to any size, which is very convenient, but at the smaller sizes
327 the glyphs will appear very light.
328
329 In LilyPond, we have created fonts in a range of weights, corresponding
330 to a range of music sizes.  This is a LilyPond engraving at staff size
331 26:
332
333 @quotation
334 @iftex
335 @sourceimage{pdf/size26,,23mm,}
336 @end iftex
337 @ifnottex
338 @sourceimage{size26,,,png}
339 @end ifnottex
340 @end quotation
341
342 @noindent
343 and this is the same engraving set at staff size 11, then
344 magnified by 236% to print at the same size as the previous example:
345
346 @quotation
347 @iftex
348 @sourceimage{pdf/size11,,23mm,}
349 @end iftex
350 @ifnottex
351 @sourceimage{size11,,,png}
352 @end ifnottex
353 @end quotation
354
355 @noindent
356 At smaller sizes, LilyPond uses proportionally heavier lines so the
357 music will still read well.
358
359 This also allows staves of different sizes to coexist peacefully when
360 used together on the same page:
361
362 @c Grieg's Violin Sonata Op. 45
363 @lilypond[indent=1.5\cm]
364 global = {
365   \time 6/8
366   \key c \minor
367 }
368
369 \score {
370   <<
371     \new Staff \with {
372       \magnifyStaff #2/3
373     }
374     \relative c' {
375       \global
376       \set Staff.instrumentName = #"Violin"
377       c8.(\f^> b16 c d) ees8.(^> d16 c b)
378       g8.(^> b16 c ees) g8-.^> r r
379       R2.
380     }
381     \new PianoStaff <<
382       \set PianoStaff.instrumentName = #"Piano"
383       \new Staff \relative c' {
384         \global
385         s2.
386         s4. s8 r8 r16 <c f aes c>
387         <c f aes c>4.^> <c ees g>8 r r
388       }
389       \new Staff \relative c {
390         \global
391         \clef "bass"
392         <<
393         {
394           \once \override DynamicText.X-offset = #-3
395           <ees g c>2.~->^\f
396           <ees g c>4.~ <ees g c>8
397         } \\ {
398           <c g c,>2.~
399           <c g c,>4.~ <c g c,>8
400         }
401         >>
402         r8 r16 <f, c' aes'>16
403         <f c' aes'>4.-> <c' g'>8 r r
404       }
405     >>
406   >>
407 }
408 @end lilypond
409
410
411 @node Why work so hard?
412 @unnumberedsubsec Why work so hard?
413
414 Musicians are usually more absorbed with performing than with studying
415 the looks of a piece of music, so nitpicking typographical details may
416 seem academic.  But it is not.  Sheet music is performance material:
417 everything is done to aid the musician in letting her perform better,
418 and anything that is unclear or unpleasant to read is a hindrance.
419
420 Traditionally engraved music uses bold symbols on heavy staff to create
421 a strong, well-balanced look that stands out well when the music is far
422 away from the reader: for example, if it is on a music stand.  A careful
423 distribution of white space allows music to be set very tightly without
424 crowding symbols together.  The result minimizes the number of page
425 turns, which is a great advantage.
426
427 This is a common characteristic of typography.  Layout should be pretty,
428 not only for its own sake, but especially because it helps the reader in
429 his task.  For sheet music this is of double importance because musicians
430 have a limited amount of attention.  The less attention they need for
431 reading, the more they can focus on playing the music.  In other words,
432 better typography translates to better performances.
433
434 These examples demonstrate that music typography is an art that is
435 subtle and complex, and that producing it requires considerable
436 expertise, which musicians usually do not have.  LilyPond is our
437 effort to bring the graphical excellence of hand-engraved music to
438 the computer age, and make it available to normal musicians.  We
439 have tuned our algorithms, font-designs, and program settings to
440 produce prints that match the quality of the old editions we love
441 to see and love to play from.
442
443
444 @node Automated engraving
445 @section Automated engraving
446
447 @cindex engraving, automated
448 @cindex automated engraving
449
450 Here we describe what is required to create software that can mimic the
451 layout of engraved scores: a method of describing good layouts to the
452 computer and a lot of detailed comparisons with real engravings.
453
454 @menu
455 * Beauty contests::
456 * Improvement by benchmarking::
457 * Getting things right::
458 @end menu
459
460 @node Beauty contests
461 @unnumberedsubsec Beauty contests
462
463 How do we actually make formatting decisions?  In other words, which
464 of the three configurations should we choose for the following slur?
465
466 @lilypond
467 \relative c {
468   \clef bass
469   \once \override Slur.positions = #'(1.5 . 1)
470   e8[( f] g[ a b d,)] r4
471   \once \override Slur.positions = #'(2 . 3)
472   e8[( f] g[ a b d,)] r4
473   e8[( f] g[ a b d,)] r4
474 }
475 @end lilypond
476
477 There are a few books on the art of music engraving
478 available.  Unfortunately, they contain simple rules of thumb and some
479 examples.  Such rules can be instructive, but they are a far cry from
480 an algorithm that we could readily implement in a computer.  Following
481 the instructions from literature leads to algorithms with lots of
482 hand-coded exceptions.  Doing all this case analysis is a lot of work,
483 and often not all cases are covered completely:
484
485 @quotation
486 @iftex
487 @sourceimage{ross-beam-scan,7cm,,}
488 @end iftex
489 @ifnottex
490 @sourceimage{ross-beam-scan,,,.jpg}
491 @end ifnottex
492 @end quotation
493
494 (Image source: Ted Ross, @emph{The Art of Music Engraving})
495
496 Rather than trying to write detailed layout rules for every possible
497 scenario, we only have to describe the objectives well enough that
498 LilyPond can judge the attractiveness of several alternatives.  Then,
499 for each possible configuration we compute an ugliness score and we
500 choose the least ugly configuration.
501
502 For example, here are three possible slur configurations, and LilyPond
503 has given each one a score in @q{ugly points}.  The first example gets
504 15.39 points for grazing one of the noteheads:
505
506 @lilypond
507 \relative c {
508   \clef bass
509   \once \override Slur.positions = #'(1.5 . 1)
510   e8[(_"15.39" f] g[ a b d,)] r4
511 }
512 @end lilypond
513
514 The
515 second one is nicer, but the slur doesn't start or end on the note heads.
516 It gets 1.71 points for the left side and 9.37 points for the right
517 side, plus another 2 points because the slur ascends while the melody
518 descends for a total of 13.08 ugly points:
519
520 @lilypond
521 \relative c {
522   \clef bass
523   \once \override Slur.positions = #'(2 . 3)
524   e8[(_"13.08" f] g[ a b d,)] r4
525 }
526 @end lilypond
527
528 The final slur gets 10.04
529 points for the gap on the right and 2 points for the upward slope, but
530 it is the most attractive of the three configurations, so LilyPond
531 selects this one:
532
533 @lilypond
534 \relative c {
535   \clef bass
536   e8[(_"12.04" f] g[ a b d,)] r4
537 }
538 @end lilypond
539
540 This technique is quite general, and is used to make optimal decisions
541 for beam configurations, ties and dots in chords, line breaks, and page
542 breaks.  The results of these decisions can be judged by comparison to
543 real engravings.
544
545 @node Improvement by benchmarking
546 @unnumberedsubsec Improvement by benchmarking
547
548 LilyPond's output has improved gradually over time, and it continues to
549 improve by comparing its output to hand-engraved scores.
550
551 For example, here is one line of a benchmark piece from a
552 hand-engraved edition (Bärenreiter BA320):
553
554 @iftex
555 @sourceimage{baer-sarabande-hires,16cm,,}
556 @end iftex
557 @ifnottex
558 @sourceimage{baer-sarabande,,,png}
559 @end ifnottex
560
561 @noindent
562 and the same quotation as engraved by a very old version of LilyPond
563 (version 1.4, May 2001):
564
565 @iftex
566 @sourceimage{pdf/lily14-sarabande,16cm,,}
567 @end iftex
568 @ifnottex
569 @sourceimage{lily14-sarabande,,,png}
570 @end ifnottex
571
572 @noindent The LilyPond 1.4 output is certainly readable, but close
573 comparison with the hand-engraved score showed a lot of errors in the
574 formatting details:
575
576 @iftex
577 @sourceimage{lily14-sarabande-annotated-hires,16cm,,}
578 @end iftex
579 @ifnottex
580 @sourceimage{lily14-sarabande-annotated,,,png}
581 @end ifnottex
582
583 @itemize @bullet
584 @item there is too much space before the time signature
585 @item the stems of the beamed notes are too long
586 @item the second and fourth measures are too narrow
587 @item the slur is awkward-looking
588 @item the trill marks are too big
589 @item the stems are too thin
590 @end itemize
591
592 @noindent
593 (There were also two missing note heads, several missing editorial
594 annotations, and an incorrect pitch!)
595
596 By adjusting the layout rules and font design, the output has improved
597 considerably.  Compare the same reference score and the output
598 from the current version of LilyPond (@version{}):
599
600 @iftex
601 @sourceimage{baer-sarabande-hires,16cm,,}
602 @end iftex
603 @ifnottex
604 @sourceimage{baer-sarabande,,,png}
605 @end ifnottex
606
607 @lilypond[staffsize=17.5,line-width=15.9\cm]
608 \relative c {
609   \clef "bass"
610   \key d \minor
611   \time 3/4
612   \mergeDifferentlyDottedOn
613   <<
614     { \slurDashed d8.-\flageolet( e16) e4.-\trill( d16 e) }
615      \\
616     { d4_2 a2 }
617   >>
618   \slurDashed
619   <f' a, d,>4. e8( d c)
620   \slurSolid
621   bes8 g' f e16( f g_1 a_2 bes_3 d,_2)
622   \slurDashed
623   cis4.-\trill b8_3( a g)
624   <<
625     { \slurDashed d'8.( e16) e4.-\trill( d16 e) }
626      \\
627     { <f, a>4 a2 }
628   >>
629 }
630 @end lilypond
631
632 @noindent
633 The current output is not a clone of the reference edition, but it is
634 much closer to publication quality that the earlier output.
635
636 @node Getting things right
637 @unnumberedsubsec Getting things right
638
639 We can also measure LilyPond's ability to make music engraving decisions
640 automatically by comparing LilyPond's output to the output of a
641 commercial software product.  In this case we have chosen Finale 2008,
642 which is one of the most popular commercial score writers, particularly
643 in North America.  Sibelius is its major rival and appears to be
644 especially strong in the European market.
645
646 For our comparison we selected Bach's Fugue in G minor from the
647 Well-Tempered Clavier, Book I, BWV 861, whose opening subject is
648
649 @lilypond
650 \relative c' {
651   \key g \minor
652   \clef "treble_8"
653   r8 d ees g, fis4 g
654   r8 a16 bes c8 bes16 a bes8
655 }
656 @end lilypond
657
658 @noindent
659
660 We made our comparison by engraving the last seven measures of the piece
661 (28--34) in Finale and LilyPond.  This is the point in the piece where
662 the subject returns in a three-part stretto and leads into the closing
663 section.  In the Finale version, we have resisted the temptation to make
664 any adjustments to the default output because we are trying to show the
665 things that each software package gets right without assistance.  The
666 only major edits that we made were adjusting the page size to match this
667 essay and forcing the music onto two systems to make the comparison
668 easier.  By default Finale would have engraved two systems of three
669 measures each and a final, full-width system containing a single
670 measure.
671
672 Many of the differences between the two engravings are visible in
673 measures 28--29, as shown here with Finale first and LilyPond second:
674
675 @iftex
676 @sourceimage{pdf/bwv861mm28-29,14cm,,}
677 @end iftex
678 @ifnottex
679 @sourceimage{bwv861mm28-29,,,png}
680 @end ifnottex
681
682 @lilypond[staffsize=19.5,line-width=14\cm]
683 global = { \key g \minor }
684
685 partI = \relative c' {
686   \voiceOne
687   fis8 d' ees g, fis4 g
688   r8 a16 bes c8 bes16 a d8 r r4
689 }
690
691 partII = \relative c' {
692   \voiceTwo
693   d4 r4 r8 d'16 c bes8 c16 d
694   ees8 d c ees a, r r4
695 }
696
697 partIII = \relative c' {
698   \voiceOne
699   r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
700 }
701
702 partIV = \relative c {
703   \voiceTwo
704   d4 r r2
705   r8 d ees g, fis4 a
706 }
707
708 \score {
709   <<
710     % \set Score.barNumberVisibility = #all-bar-numbers-visible
711     % required in 2.13
712     \set Score.currentBarNumber = #28
713     \bar ""
714     \new PianoStaff <<
715       \new Staff = "RH" <<
716         \global
717         \new Voice = "voiceI" { \partI }
718         \new Voice = "voiceII" { \partII }
719       >>
720       \new Staff = "LH"
721       <<
722         \clef "bass"
723         \global
724         \new Voice = "voiceIII" { \partIII }
725         \new Voice = "voiceIV" { \partIV }
726       >>
727     >>
728   >>
729   \layout {
730     \context {
731       \Staff
732       \remove "Time_signature_engraver"
733     }
734     \context {
735       \PianoStaff
736       \override StaffGrouper.staff-staff-spacing.padding = #1
737     }
738   }
739 }
740 @end lilypond
741
742 Some shortcomings in the unedited Finale output include:
743 @itemize @bullet
744 @item Most of the beams extend too far off the staff.  A beam that points
745 towards the center of the staff should have a length of about one
746 octave, but engravers shorten this when the beam points away from the
747 staff in multi-voice music.  The Finale beaming can easily be improved
748 with their Patterson Beams plug-in, but we elected to skip that step for
749 this example.
750 @item Finale doesn't adjust the positions of interlocking note heads,
751 which makes the music extremely difficult to read when the upper and
752 lower voices exchange positions temporarily:
753
754 @lilypond
755 collide = \once \override NoteColumn.force-hshift = #0
756
757 \score {
758   <<
759     \new Voice = "sample" \relative c''{
760       \key g \minor
761       <<
762         { \voiceOne g4 \collide g4 }
763         \new Voice { \voiceTwo bes \collide bes }
764       >>
765     }
766     \new Lyrics \lyricsto "sample" { "good " " bad" }
767   >>
768 }
769 @end lilypond
770
771 @item Finale has placed all of the rests at fixed heights on the staff.
772 The user is free to adjust them as needed, but the software makes no
773 attempt to consider the content of the other voice.  As luck would have
774 it, there are no true collisions between notes and rests in this example,
775 but that has more to do with the positions of the notes than the rest.
776 In other words, Bach deserves more credit for avoiding a complete
777 collision than Finale does.
778
779 @end itemize
780
781 This example is not intended to suggest that Finale cannot be used to
782 produce publication-quality output.  On the contrary, in the hands of a
783 skilled user it can and does, but it requires skill and time.  One of the
784 fundamental differences between LilyPond and commercial scorewriters is
785 that LilyPond hopes to reduce the amount of human intervention to an
786 absolute minimum, while other packages try to provide an attractive
787 interface in which to make these types of edits.
788
789 One particularly glaring omission we found from Finale is a missing flat
790 in measure 33:
791
792 @quotation
793 @iftex
794 @sourceimage{pdf/bwv861mm33-34-annotate,7.93cm,,}
795 @end iftex
796 @ifnottex
797 @sourceimage{bwv861mm33-34-annotate,,,png}
798 @end ifnottex
799 @end quotation
800
801 @noindent
802 The flat symbol is required to cancel out the natural in the same
803 measure, but Finale misses it because it occurred in a different voice.
804 So in addition to running a beaming plug-in and checking the spacing on
805 the noteheads and rests, the user must also check each measure for
806 cross-voice accidentals to avoid interrupting a rehearsal over an
807 engraving error.
808
809 If you are interested in examining these examples in more detail, the
810 full seven-measure excerpt can be found at the end of this essay along
811 with four different published engravings.  Close examination reveals that
812 there is some acceptable variation among the hand-engravings, but that
813 LilyPond compares reasonably well to that acceptable range.  There are
814 still some shortcomings in the LilyPond output, for example, it appears
815 a bit too aggressive in shortening some of the stems, so there is room
816 for further development and fine-tuning.
817
818 Of course, typography relies on human judgment of appearance, so people
819 cannot be replaced completely.  However, much of the dull work can be
820 automated.  If LilyPond solves most of the common situations correctly,
821 this will be a huge improvement over existing software.  Over the course
822 of years, the software can be refined to do more and more things
823 automatically, so manual overrides are less and less necessary.  Where
824 manual adjustments are needed, LilyPond's structure has been designed
825 with that flexibility in mind.
826
827 @node Building software
828 @section Building software
829
830 This section describes some of the programming decisions that we made
831 when designing LilyPond.
832
833 @menu
834 * Music representation::
835 * What symbols to engrave?::
836 * Flexible architecture::
837 @end menu
838
839
840 @node Music representation
841 @unnumberedsubsec Music representation
842
843 @cindex syntax
844 @cindex recursive structures
845
846 Ideally, the input format for any high-level formatting system is
847 an abstract description of the content.  In this case, that would
848 be the music itself.  This poses a formidable problem: how can we
849 define what music really is? Instead of trying to find an answer,
850 we have reversed the question.  We write a program capable of
851 producing sheet music, and adjust the format to be as lean as
852 possible.  When the format can no longer be trimmed down, by
853 definition we are left with content itself.  Our program serves as
854 a formal definition of a music document.
855
856 The syntax is also the user-interface for LilyPond, hence it is
857 easy to type:
858
859 @example
860 @{
861   c'4 d'8
862 @}
863 @end example
864
865 @noindent
866 to create a quarter note on middle C (C1) and an eighth note on
867 the D above middle C (D1).
868
869 @lilypond[quote]
870 {
871   c'4 d'8
872 }
873 @end lilypond
874
875 On a microscopic scale, such syntax is easy to use.  On a larger
876 scale, syntax also needs structure.  How else can you enter
877 complex pieces like symphonies and operas?  The structure is
878 formed by the concept of music expressions: by combining small
879 fragments of music into larger ones, more complex music can be
880 expressed.  For example
881
882 @lilypond[quote,verbatim,fragment,relative=1]
883 f4
884 @end lilypond
885
886 @noindent
887 Simultaneous notes can be constructed by enclosing them with
888 @code{<<} and @code{>>}:
889
890 @example
891 <<c4 d4 e4>>
892 @end example
893
894 @lilypond[quote,fragment,relative=1]
895 \new Voice { <<c4 d4 e>> }
896 @end lilypond
897
898 @noindent
899 This expression is put in sequence by enclosing it in curly braces
900 @code{@{@tie{}@dots{}@tie{}@}}:
901
902 @example
903 @{ f4 <<c4 d4 e4>> @}
904 @end example
905
906 @lilypond[quote,relative=1,fragment]
907 { f4 <<c d e4>> }
908 @end lilypond
909
910 @noindent
911 The above is also an expression, and so it may be combined again
912 with another simultaneous expression (a half note) using
913 @code{<<}, @code{\\}, and @code{>>}:
914
915 @example
916 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
917 @end example
918
919 @lilypond[quote,fragment,relative=2]
920 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
921 @end lilypond
922
923 Such recursive structures can be specified neatly and formally in
924 a context-free grammar.  The parsing code is also generated from
925 this grammar.  In other words, the syntax of LilyPond is clearly
926 and unambiguously defined.
927
928 User-interfaces and syntax are what people see and deal with most.
929 They are partly a matter of taste, and also the subject of much
930 discussion.  Although discussions on taste do have their merit,
931 they are not very productive.  In the larger picture of LilyPond,
932 the importance of input syntax is small: inventing neat syntax is
933 easy, while writing decent formatting code is much harder.  This
934 is also illustrated by the line-counts for the respective
935 components: parsing and representation take up less than 10% of
936 the source code.
937
938 When designing the structures used in LilyPond, we made some different
939 decisions than are apparent in other software.  Consider the hierarchical
940 nature of music notation:
941
942 @lilypond[quote,fragment]
943 <<
944   \new Staff \relative c'' {
945     \key g \major
946     \time 3/4
947     d4 g,8 a b c d4 g, g
948   }
949   \new Staff \relative c' {
950     \clef "bass"
951     \key g \major
952     <g b d>2 a4 b2.
953   }
954 >>
955 @end lilypond
956
957 In this case, there are pitches grouped into chords that belong to
958 measures, which belong to staves.  This resembles a tidy structure of
959 nested boxes:
960
961 @quotation
962 @iftex
963 @sourceimage{pdf/nestedboxes,,4cm,}
964 @end iftex
965 @ifnottex
966 @sourceimage{nestedboxes,,,png}
967 @end ifnottex
968 @end quotation
969
970 Unfortunately, the structure is tidy because it is based on some
971 excessively restrictive assumptions.  This becomes apparent if we
972 consider a more complicated musical example:
973
974 @lilypond[quote]
975 \layout {
976   \context {
977     \Score
978     \remove "Timing_translator"
979     \remove "Default_bar_line_engraver"
980   }
981   \context {
982     \Staff
983     \consists "Timing_translator"
984     \consists "Default_bar_line_engraver"
985   }
986 }
987
988 \new PianoStaff <<
989   \new Staff = "RH" <<
990     \new Voice = "I" \relative c''' {
991       \time 3/4
992       \voiceOne
993       \tuplet 7/6 { g8 g g g g g g }
994       \oneVoice
995       r4 <b,, fis' g bes> r4\fermata
996     }
997     \new Voice = "II" \relative c' {
998       \voiceTwo
999       c4
1000       \tuplet 5/4 {
1001         <c ees>8 f g
1002         \change Staff = "LH" \oneVoice
1003         \stemUp g,( c}
1004       r4
1005       \override Stem.cross-staff = ##t
1006       \override Stem.length = #12
1007       <fis, b>) r\fermata
1008     }
1009   >>
1010   \new Staff = "LH" <<
1011     \new Voice = "III" \relative c' {
1012       \time 2/4
1013       \clef "bass"
1014       g4 \stopStaff s
1015       \startStaff s2*2
1016     }
1017   >>
1018 >>
1019 @end lilypond
1020
1021 In this example, staves start and stop at will, voices jump around
1022 between staves, and the staves have different time signatures.  Many
1023 software packages would struggle with reproducing this example because
1024 they are built on the nested box structure.  With LilyPond, on the other
1025 hand, we have tried to keep the input format and the structure as
1026 flexible as possible.
1027
1028 @node What symbols to engrave?
1029 @unnumberedsubsec What symbols to engrave?
1030
1031 @cindex engraving
1032 @cindex typography
1033 @cindex engraver
1034 @cindex plug-in
1035
1036 The formatting process decides where to place symbols.  However,
1037 this can only be done once it is decided @emph{what} symbols
1038 should be printed -- in other words, what notation to use.
1039
1040 Common music notation is a system of recording music that has
1041 evolved over the past 1000 years.  The form that is now in common
1042 use dates from the early Renaissance.  Although the basic form
1043 (i.e., note heads on a 5-line staff) has not changed, the details
1044 still evolve to express the innovations of contemporary notation.
1045 Hence, common music notation encompasses some 500 years of music.
1046 Its applications range from monophonic melodies to monstrous
1047 counterpoints for a large orchestra.
1048
1049 How can we get a grip on such a seven-headed beast, and force it
1050 into the confines of a computer program?  Our solution is to break
1051 up the problem of notation (as opposed to engraving, i.e.,
1052 typography) into digestible and programmable chunks: every type of
1053 symbol is handled by a separate module, a so-called plug-in.  Each
1054 plug-in is completely modular and independent, so each can be
1055 developed and improved separately.  Such plug-ins are called
1056 @code{engraver}s, by analogy with craftsmen who translate musical
1057 ideas to graphic symbols.
1058
1059 In the following example, we start out with a plug-in for note
1060 heads, the @code{Note_heads_engraver}.
1061
1062 @lilypond[quote,ragged-right]
1063 \include "engraver-example.ily"
1064
1065 \score {
1066   \topVoice
1067   \layout {
1068     \context {
1069       \Voice
1070       \remove "Stem_engraver"
1071       \remove "Phrasing_slur_engraver"
1072       \remove "Slur_engraver"
1073       \remove "Script_engraver"
1074       \remove "New_fingering_engraver"
1075       \remove "Beam_engraver"
1076       \remove "Auto_beam_engraver"
1077     }
1078     \context {
1079       \Staff
1080       \remove "Accidental_engraver"
1081       \remove "Key_engraver"
1082       \remove "Clef_engraver"
1083       \remove "Bar_engraver"
1084       \remove "Time_signature_engraver"
1085       \remove "Staff_symbol_engraver"
1086       \consists "Pitch_squash_engraver"
1087     }
1088   }
1089 }
1090 @end lilypond
1091
1092 @noindent
1093 Then a @code{Staff_symbol_engraver} adds the staff,
1094
1095 @lilypond[quote,ragged-right]
1096 \include "engraver-example.ily"
1097
1098 \score {
1099   \topVoice
1100   \layout {
1101     \context {
1102       \Voice
1103       \remove "Stem_engraver"
1104       \remove "Phrasing_slur_engraver"
1105       \remove "Slur_engraver"
1106       \remove "Script_engraver"
1107       \remove "New_fingering_engraver"
1108       \remove "Beam_engraver"
1109       \remove "Auto_beam_engraver"
1110     }
1111     \context {
1112       \Staff
1113       \remove "Accidental_engraver"
1114       \remove "Key_engraver"
1115       \remove "Clef_engraver"
1116       \remove "Bar_engraver"
1117       \consists "Pitch_squash_engraver"
1118       \remove "Time_signature_engraver"
1119     }
1120   }
1121 }
1122 @end lilypond
1123
1124 @noindent
1125 the @code{Clef_engraver} defines a reference point for the staff,
1126
1127 @lilypond[quote,ragged-right]
1128 \include "engraver-example.ily"
1129
1130 \score {
1131   \topVoice
1132   \layout {
1133     \context {
1134       \Voice
1135       \remove "Stem_engraver"
1136       \remove "Phrasing_slur_engraver"
1137       \remove "Slur_engraver"
1138       \remove "Script_engraver"
1139       \remove "New_fingering_engraver"
1140       \remove "Beam_engraver"
1141       \remove "Auto_beam_engraver"
1142     }
1143     \context {
1144       \Staff
1145       \remove "Accidental_engraver"
1146       \remove "Key_engraver"
1147       \remove "Bar_engraver"
1148       \remove "Time_signature_engraver"
1149     }
1150   }
1151 }
1152 @end lilypond
1153
1154 @noindent
1155 and the @code{Stem_engraver} adds stems.
1156
1157 @lilypond[quote,ragged-right]
1158 \include "engraver-example.ily"
1159
1160 \score {
1161   \topVoice
1162   \layout {
1163     \context {
1164       \Voice
1165       \remove "Phrasing_slur_engraver"
1166       \remove "Slur_engraver"
1167       \remove "Script_engraver"
1168       \remove "New_fingering_engraver"
1169       \remove "Beam_engraver"
1170       \remove "Auto_beam_engraver"
1171     }
1172     \context {
1173       \Staff
1174       \remove "Accidental_engraver"
1175       \remove "Key_engraver"
1176       \remove "Bar_engraver"
1177       \remove "Time_signature_engraver"
1178     }
1179   }
1180 }
1181 @end lilypond
1182
1183 @noindent
1184 The @code{Stem_engraver} is notified of any note head coming
1185 along.  Every time one (or more, for a chord) note head is seen, a
1186 stem object is created and connected to the note head.  By adding
1187 engravers for beams, slurs, accents, accidentals, bar lines, time
1188 signature, and key signature, we get a complete piece of notation.
1189
1190 @lilypond[quote,ragged-right]
1191 \include "engraver-example.ily"
1192 \score { \topVoice }
1193 @end lilypond
1194
1195 @cindex polyphony
1196 @cindex engraving multiple voices
1197 @cindex contexts
1198
1199 This system works well for monophonic music, but what about
1200 polyphony?  In polyphonic notation, many voices can share a staff.
1201
1202 @lilypond[quote,ragged-right]
1203 \include "engraver-example.ily"
1204 \new Staff << \topVoice \\ \botVoice >>
1205 @end lilypond
1206
1207 In this situation, the accidentals and staff are shared, but the
1208 stems, slurs, beams, etc., are private to each voice.  Hence,
1209 engravers should be grouped.  The engravers for note heads, stems,
1210 slurs, etc., go into a group called @q{Voice context}, while the
1211 engravers for key, accidental, bar, etc., go into a group called
1212 @q{Staff context}.  In the case of polyphony, a single Staff
1213 context contains more than one Voice context.  Similarly, multiple
1214 Staff contexts can be put into a single Score context.  The Score
1215 context is the top level notation context.
1216
1217 @lilypond[quote,ragged-right]
1218 \include "engraver-example.ily"
1219 \score {
1220    <<
1221       \new Staff << \topVoice \\ \botVoice >>
1222       \new Staff << \pah \\ \hoom >>
1223    >>
1224 }
1225 @end lilypond
1226
1227 @seealso
1228 Internals Reference: @rinternals{Contexts}.
1229
1230 @node Flexible architecture
1231 @unnumberedsubsec Flexible architecture
1232
1233 When we started, we wrote the LilyPond program entirely in the C++
1234 programming language; the program's functionality was set in stone
1235 by the developers.  That proved to be unsatisfactory for a number
1236 of reasons:
1237
1238 @itemize
1239
1240 @item When LilyPond makes mistakes, users need to override
1241 formatting decisions.  Therefore, the user must have access to the
1242 formatting engine.  Hence, rules and settings cannot be fixed by
1243 us at compile-time but must be accessible for users at run-time.
1244
1245 @item Engraving is a matter of visual judgment, and therefore a
1246 matter of taste.  As knowledgeable as we are, users can disagree
1247 with our personal decisions.  Therefore, the definitions of
1248 typographical style must also be accessible to the user.
1249
1250 @item Finally, we continually refine the formatting algorithms, so
1251 we need a flexible approach to rules.  The C++ language forces a
1252 certain method of grouping rules that cannot readily be applied to
1253 formatting music notation.
1254
1255 @end itemize
1256
1257 @cindex Scheme programming language
1258
1259 These problems have been addressed by integrating an interpreter
1260 for the Scheme programming language and rewriting parts of
1261 LilyPond in Scheme.  The current formatting architecture is built
1262 around the notion of graphical objects, described by Scheme
1263 variables and functions.  This architecture encompasses formatting
1264 rules, typographical style and individual formatting decisions.
1265 The user has direct access to most of these controls.
1266
1267 Scheme variables control layout decisions.  For example, many
1268 graphical objects have a direction variable that encodes the
1269 choice between up and down (or left and right).  Here you see two
1270 chords, with accents and arpeggios.  In the first chord, the
1271 graphical objects have all directions down (or left).  The second
1272 chord has all directions up (right).
1273
1274 @lilypond[quote,ragged-right]
1275 \score {
1276   \relative c' {
1277     \stemDown <e g b>4_>-\arpeggio
1278     \override Arpeggio.direction = #RIGHT
1279     \stemUp <e g b>4^>-\arpeggio
1280   }
1281   \layout {
1282     \context {
1283       \Score
1284       \override SpacingSpanner.spacing-increment = #3
1285       \hide TimeSignature
1286     }
1287   }
1288 }
1289 @end lilypond
1290
1291 @cindex score formatting
1292 @cindex formatting a score
1293 @cindex formatting rules
1294
1295 @noindent
1296 The process of formatting a score consists of reading and writing
1297 the variables of graphical objects.  Some variables have a preset
1298 value.  For example, the thickness of many lines -- a
1299 characteristic of typographical style -- is a variable with a
1300 preset value.  You are free to alter this value, giving your score
1301 a different typographical impression.
1302
1303 @lilypond[quote,ragged-right]
1304 fragment = {
1305    \clef bass f8 as8
1306    c'4-~ c'16 as g f e16 g bes c' des'4
1307 }
1308 <<
1309    \new Staff \fragment
1310    \new Staff \with {
1311       \override Beam.beam-thickness = #0.3
1312       \override Stem.thickness = #0.5
1313       \override Bar.thickness = #3.6
1314       \override Tie.thickness = #2.2
1315       \override StaffSymbol.thickness = #3.0
1316       \override Tie.extra-offset = #'(0 .  0.3)
1317       }
1318       \fragment
1319 >>
1320 @end lilypond
1321
1322 Formatting rules are also preset variables: each object has
1323 variables containing procedures.  These procedures perform the
1324 actual formatting, and by substituting different ones, we can
1325 change the appearance of objects.  In the following example, the
1326 rule governing which note head objects are used to produce the
1327 note head symbol is changed during the music fragment.
1328
1329 @lilypond[quote,ragged-right]
1330 #(set-global-staff-size 30)
1331
1332 #(define (mc-squared grob orig current)
1333   (let* ((interfaces (ly:grob-interfaces grob))
1334          (pos (ly:grob-property grob 'staff-position)))
1335     (if (memq 'note-head-interface interfaces)
1336         (begin
1337           (ly:grob-set-property! grob 'stencil
1338             (grob-interpret-markup grob
1339               (make-lower-markup 0.5
1340                 (case pos
1341                   ((-5) "m")
1342                   ((-3) "c ")
1343                   ((-2) (make-smaller-markup (make-bold-markup "2")))
1344                   (else "bla")))))))))
1345
1346 \new Voice \relative c' {
1347   \stemUp
1348   \set autoBeaming = ##f
1349   \time 2/4
1350   <d f g>4
1351   \once \override NoteHead.stencil = #note-head::brew-ez-stencil
1352   \once \override NoteHead.font-size = #-7
1353   \once \override NoteHead.font-family = #'sans
1354   \once \override NoteHead.font-series = #'bold
1355   <d f g>4
1356   \once \override NoteHead.style = #'cross
1357   <d f g>4
1358   \applyOutput #'Voice #mc-squared
1359   <d f g>4
1360   <<
1361     { d8[ es-( fis^^ g] fis2-) }
1362     \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
1363   >>
1364 }
1365 @end lilypond
1366
1367
1368
1369 @node Putting LilyPond to work
1370 @section Putting LilyPond to work
1371
1372 @cindex simple examples
1373 @cindex examples, simple
1374
1375 We have written LilyPond as an experiment of how to condense the
1376 art of music engraving into a computer program.  Thanks to all
1377 that hard work, the program can now be used to perform useful
1378 tasks.  The simplest application is printing notes.
1379
1380 @lilypond[quote,relative=1]
1381 {
1382   \time 2/4
1383   c4 c g'4 g a4 a g2
1384 }
1385 @end lilypond
1386
1387 @noindent
1388 By adding chord names and lyrics we obtain a lead sheet.
1389
1390 @lilypond[quote,ragged-right]
1391 <<
1392    \chords { c2 c f2 c }
1393    \new Staff
1394    \relative c' {
1395      \time 2/4
1396      c4 c g' g a a g2
1397    }
1398    \addlyrics { twin -- kle twin -- kle lit -- tle star }
1399 >>
1400 @end lilypond
1401
1402 Polyphonic notation and piano music can also be printed.  The
1403 following example combines some more exotic constructs.
1404
1405 @lilypond[quote,line-width=15.9\cm]
1406 \header {
1407   title = "Screech and boink"
1408   subtitle = "Random complex notation"
1409   composer = "Han-Wen Nienhuys"
1410 }
1411
1412 \score {
1413   \context PianoStaff <<
1414     \new Staff = "up" {
1415       \time 4/8
1416       \key c \minor
1417       << {
1418         \revert Stem.direction
1419         \change Staff = down
1420         \set subdivideBeams = ##t
1421         g16.[
1422           \change Staff = up
1423           c'''32
1424           \change Staff = down
1425           g32
1426           \change Staff = up
1427           c'''32
1428           \change Staff = down
1429           g16]
1430         \change Staff = up
1431         \stemUp
1432         \set followVoice = ##t
1433         c'''32([ b''16 a''16 gis''16 g''32)]
1434       } \\ {
1435         s4 \tuplet 3/2 { d'16[ f' g'] } as'32[ b''32 e'' d'']
1436       } \\ {
1437         s4 \autoBeamOff d''8.. f''32
1438       } \\ {
1439         s4 es''4
1440       } >>
1441     }
1442
1443     \new Staff = "down" {
1444       \clef bass
1445       \key c \minor
1446       \set subdivideBeams = ##f
1447       \override Stem.french-beaming = ##t
1448       \override Beam.beam-thickness = #0.3
1449       \override Stem.thickness = #4.0
1450       g'16[ b16 fis16 g16]
1451       << \makeClusters {
1452         as16 <as b>
1453         <g b>
1454         <g cis>
1455       } \\ {
1456         \override Staff.Arpeggio.arpeggio-direction =#down
1457         <cis, e, gis, b, cis>4\arpeggio
1458       }
1459     >> }
1460   >>
1461   \midi {
1462     \tempo 8 = 60
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, and can
1481 therefore be easily embedded in other text-based formats such as
1482 @LaTeX{}, HTML, or in the case of this manual, Texinfo.  Using the
1483 @command{lilypond-book} program, included with LilyPond, the input
1484 fragments can be replaced by music images in the resulting PDF or HTML
1485 output files.  Another example is the third-party OOoLilyPond extension
1486 for OpenOffice.org or LibreOffice, which makes it extremely easy to
1487 embed musical examples in documents.
1488
1489 For more examples of LilyPond in action, full documentation, and the
1490 software itself, see our main website: www.lilypond.org.
1491
1492 @page
1493 @node Engraved examples (BWV 861)
1494 @section Engraved examples (BWV 861)
1495
1496 This section contains four reference engravings and two
1497 software-engraved versions of Bach's Fugue in G minor from the
1498 Well-Tempered Clavier, Book I, BWV 861 (the last seven measures).
1499
1500 @noindent
1501 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1502 1989):
1503
1504 @iftex
1505 @sourceimage{bwv861-baer,16cm,,}
1506 @end iftex
1507 @ifnottex
1508 @sourceimage{bwv861-baer-small,,,png}
1509 @end ifnottex
1510
1511 @noindent
1512 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1513 1989), an alternate musical source.  Aside from the textual differences,
1514 this demonstrates slight variations in the engraving decisions, even
1515 from the same publisher and edition:
1516
1517 @iftex
1518 @sourceimage{bwv861-baer-alt,16cm,,}
1519 @end iftex
1520 @ifnottex
1521 @sourceimage{bwv861-baer-alt-small,,,png}
1522 @end ifnottex
1523
1524 @noindent
1525 Breitkopf & Härtel, edited by Ferruccio Busoni (Wiesbaden, 1894), also
1526 available from the Petrucci Music Library (IMSLP #22081).  The editorial
1527 markings (fingerings, articulations, etc.) have been removed for clearer
1528 comparison with the other editions here:
1529
1530 @iftex
1531 @sourceimage{bwv861-breitkopf,16cm,,}
1532 @end iftex
1533 @ifnottex
1534 @sourceimage{bwv861-breitkopf-small,,,png}
1535 @end ifnottex
1536
1537 @noindent
1538 Bach-Gesellschaft edition (Leipzig, 1866), available from the Petrucci
1539 Music Library (IMSPL #02221):
1540
1541 @iftex
1542 @sourceimage{bwv861-gessellschaft,16cm,,}
1543 @end iftex
1544 @ifnottex
1545 @sourceimage{bwv861-gessellschaft-small,,,png}
1546 @end ifnottex
1547
1548 @noindent
1549 Finale 2008:
1550
1551 @iftex
1552 @sourceimage{pdf/bwv861-finale2008a,,,}
1553 @end iftex
1554 @ifnottex
1555 @sourceimage{bwv861-finale2008a,,,png}
1556 @end ifnottex
1557
1558 @sp 4
1559 @noindent
1560 LilyPond, version @version{}:
1561
1562 @lilypond[staffsize=14.3,line-width=15.9\cm]
1563 global = {\key g \minor}
1564
1565 partI = \relative c' {
1566   \voiceOne
1567   fis8 d' ees g, fis4 g
1568   r8 a16 bes c8 bes16 a d8 r r4
1569   r2 r8 d16 ees f8 ees16 d
1570   ees4 ~ 16 d c bes a4 r8 ees'16 d
1571   c8 d16 ees d8 e16 fis g8 fis16 g a4 ~
1572   8 d, g f ees d c bes
1573   a2 g\fermata \bar "|."
1574 }
1575
1576 partII = \relative c' {
1577   \voiceTwo
1578   d4 r4 r8 d'16 c bes8 c16 d
1579   ees8 d c ees a, r r4
1580   r8 fis16 g a8 g16 fis g2 ~
1581   2 r8 d' ees g,
1582   fis4 g r8 a16 bes c8 bes16 a
1583   bes4. <g b>8 <a c> r <d, g> r
1584   <ees g>4 <d fis> d2
1585 }
1586 partIII = \relative c' {
1587   \voiceOne
1588   r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
1589   bes2 ~ 8 b16 a g8 a16 b
1590   c4 r r2
1591   R1
1592   r8 d ees g, fis4 g
1593   r8 a16 bes c8 bes16 a b2
1594 }
1595 partIV = \relative c {
1596   \voiceTwo
1597   d4 r r2
1598   r8 d ees g, fis4 a
1599   d,8 d'16 c bes8 c16 d ees2 ~
1600   8 ees16 d c8 d16 ees fis,8 a16 g fis8 g16 a
1601   d,8 d'16 c bes8 c16 d ees8 c a fis'
1602   g f ees d c bes a g
1603   c a d d, g2\fermata
1604 }
1605
1606 \score {
1607   <<
1608     % \set Score.barNumberVisibility = #all-bar-numbers-visible
1609     % required in 2.13
1610     \set Score.currentBarNumber = #28
1611     \bar ""
1612     \new PianoStaff <<
1613       \new Staff = "RH" <<
1614         \global
1615         \new Voice = "voiceI" { \partI }
1616         \new Voice = "voiceII" { \partII }
1617       >>
1618
1619       \new Staff = "LH" <<
1620         \clef "bass"
1621         \global
1622         \new Voice = "voiceIII" { \partIII }
1623         \new Voice = "voiceIV" { \partIV }
1624       >>
1625     >>
1626   >>
1627   \layout {
1628     \context {
1629       \Staff
1630       \remove "Time_signature_engraver"
1631     }
1632     \context {
1633       \PianoStaff
1634       \override StaffGrouper.staff-staff-spacing.padding = #1
1635     }
1636   }
1637 }
1638 @end lilypond