1 @c -*- coding: utf-8; mode: texinfo; -*-
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
13 @chapter Music engraving
15 This section covers the overall goals and architecture of
20 * Automated engraving::
21 * What symbols to engrave?::
22 * Music representation::
23 * Example applications::
29 @unnumberedsec Engraving
32 @cindex typography, music
33 @cindex music typography
34 @cindex plate engraving
35 @cindex music engraving
37 The art of music typography is called @emph{(plate) engraving}, a term
38 that derives from the manual process of music printing@footnote{Early
39 european printers explored several processes, including hand-carved
40 wooden blocks, movable type, and engraved sheets of thin metal.
41 Typesetting had the advantage of being more easily corrected and
42 facilitating the inclusion of text and lyrics, but only engraving
43 offered the ability to do unimpeded layout and unanticipated notation.
44 In the end, hand-engraved scores became the standard for all printed
45 music, with the exception of some hymnals and songbooks where
46 typesetting was justified by its ease and economy, even into the
47 twentieth century.}. Just a few decades ago, sheet music was made by
48 cutting and stamping the music into a zinc or pewter plate in mirror
49 image. The plate would be inked, and the depressions caused by the
50 cutting and stamping would hold ink. An image was formed by pressing
51 paper to the plate. The stamping and cutting was done completely by hand
52 and making a correction was cumbersome, so the engraving had to be
53 nearly perfect in one go. Engraving was a highly specialized skill; a
54 craftsman had to complete around five years of training before earning
55 the title of master engraver, and another five years of experience were
56 necessary to become truly skilled.
60 @sourceimage{hader-slaan,,7cm,}
63 @sourceimage{hader-slaan,,,jpg}
67 Now all newly printed music is produced with computers. This has
68 obvious advantages: prints are cheaper to make, editorial work can be
69 delivered by email, and the original data can be easily stored.
70 Unfortunately, computer-generated scores rarely match the quality of
71 hand-engraved scores. Instead, computer printouts have a bland,
72 mechanical look, which makes them unpleasant to play from.
74 From the beginning, we designed LilyPond to mimic the beauty of
75 traditional music engraving. Along the way, we have learned a great deal
76 about the work that goes into a well-engraved score. Below we describe
77 several of those aspects that we have tried to imitate in LilyPond.
88 @unnumberedsubsec Music fonts
90 The images below illustrate some differences between traditional
91 engraving and typical computer output. The left picture shows a scan of
92 a flat symbol from a hand-engraved Bärenreiter edition, while the right
93 picture depicts a symbol from an edition of the same music published in
94 2000. Although both images are printed in the shame shade of ink, the
95 earlier version looks darker: the staff lines are heavier, and the
96 Bärenreiter flat has a bold, almost voluptuous rounded look. The right
97 scan, on the other hand, has thinner lines and a straight layout with
100 @multitable @columnfractions .25 .25 .25 .25
104 @sourceimage{baer-flat-gray,,4cm,}
107 @sourceimage{baer-flat-gray,,,png}
112 @sourceimage{henle-flat-gray,,4cm,}
115 @sourceimage{henle-flat-gray,,,png}
120 @sourceimage{henle-flat-bw,,,png}
121 @sourceimage{baer-flat-bw,,,png}
122 @sourceimage{lily-flat-bw,,,png}
133 @cindex musical symbols
138 When we wanted to write a computer program to create music typography,
139 there were no musical fonts freely available that could match the
140 elegance of our favorite scores. Not let down, we created a font of
141 musical symbols, relying on nice printouts of hand-engraved music. The
142 experience helped develop a typographical taste, and it made us
143 appreciate subtle design details. Without that experience, we would not
144 have realized how ugly the fonts were that we admired at first.
146 Below is a sample of two music fonts: the upper set is the default font
147 in the Sibelius software (the @emph{Opus} font), and the lower set is
148 our own LilyPond font.
152 @sourceimage{pdf/OpusAndFeta,,,}
155 @sourceimage{OpusAndFeta,,,png}
159 The LilyPond symbols are heavier and their weight is more consistent,
160 which makes them easier to read. Fine endings, such as the one on the
161 bottom of the quarter rest, should not end in sharp points, but rather
162 in rounded shapes. This is because sharp corners of the punching dies
163 are fragile and quickly wear out when stamping in metal. Taken together,
164 the blackness of the font must be carefully tuned together with the
165 thickness of lines, beams and slurs to give a strong yet balanced
168 Also, notice that our half-notehead is not elliptic but slightly diamond
169 shaped. The vertical stem of a flat symbol is slightly brushed, becoming
170 wider at the top. The sharp and the natural are easier to distinguish
171 from a distance because their angled lines have different slopes and the
172 vertical strokes are heavier.
174 @node Optical spacing
175 @unnumberedsubsec Optical spacing
177 In spacing, the distribution of space should reflect the durations
178 between notes. However, many modern scores adhere to the
179 durations with mathematical precision, which leads to poor
180 results. In the next example a motive is printed twice: the first time
181 using exact mathematical spacing, and the second with corrections.
184 @cindex optical spacing
205 \override NoteSpacing #'stem-spacing-correction = #0.0
206 \override NoteSpacing #'same-direction-correction = #0.0
207 \override StaffSpacing #'stem-spacing-correction = #0.0
233 \override NoteSpacing #'stem-spacing-correction = #0.6
239 @cindex regular rhythms
240 @cindex regular spacing
241 @cindex spacing, regular
243 Each bar in the fragment only uses notes that are played in a
244 constant rhythm. The spacing should reflect that. Unfortunately,
245 the eye deceives us a little; not only does it notice the distance
246 between note heads, it also takes into account the distance
247 between consecutive stems. As a result, the notes of an
248 up-stem/@/down-stem combination should be put farther apart, and
249 the notes of a down-stem/@/up-stem combination should be put
250 closer together, all depending on the combined vertical positions
251 of the notes. The upper two measures are printed with this
252 correction, the lower two measures, however, form down-stem/@/up-stem
253 clumps of notes. A master engraver would adjust the spacing as needed to
256 Another example of optical spacing is the visual interplay between the
257 stems and the bar lines. When an up-stem precedes the bar line, a little
258 more space is needed to keep it from feeling crowded:
267 c''8 c'' c'' c'' c'' c'' c'' c'' \break
268 a' a' a' a' a' a' a' a'
273 \remove "Time_signature_engraver"
274 \override NoteSpacing #'stem-spacing-correction = #0.7
281 @unnumberedsubsec Ledger lines
286 Ledger lines present a typographical challenge: they make it more
287 difficult to space musical symbols close together and they must be clear
288 enough to identify the pitch at a glance. In the example below, we see
289 that ledger lines should be thicker than normal staff lines and that an
290 expert engraver will shorten a ledger line to allow closer spacing with
291 accidentals. We have included this feature in LilyPond's engraving.
293 @multitable @columnfractions .25 .25 .25 .25
297 @sourceimage{baer-ledger,3cm,,}
300 @sourceimage{baer-ledger,,,png}
306 @sourceimage{lily-ledger,3cm,,}
309 @sourceimage{lily-ledger,,,png}
316 @unnumberedsubsec Optical sizing
318 Music may need to be printed in a range of sizes. Originally, this was
319 accomplished by creating punching dies in each of the required sizes,
320 which meant that each die was designed to look its best at that size.
321 With the advent of digital fonts, a single outline can be mathematically
322 scaled to any size, which is very convenient, but at the smaller sizes
323 the glyphs will appear very light.
325 In LilyPond, we have created fonts in a range of weights, corresponding
326 to a range of music sizes. This is a LilyPond engraving at staff size
331 @sourceimage{pdf/size26,,23mm,}
334 @sourceimage{size26,,,png}
339 and this is the same engraving set at staff size 11, then
340 magnified by 236% to print at the same size as the previous example:
344 @sourceimage{pdf/size11,,23mm,}
347 @sourceimage{size11,,,png}
351 At smaller sizes, LilyPond uses proportionally heavier lines and so the
352 music will still read well. This also allows staves of different
353 sizes to coexist peacefully when used together on the same page:
355 @c Grieg's Violin Sonata Op. 45
356 @lilypond[indent=1.5cm]
365 \override StaffSymbol #'staff-space = #(magstep -4)
366 \override StaffSymbol #'thickness = #(magstep -3)
370 \set Staff.instrumentName = #"Violin"
371 c8.(\f^> b16 c d) ees8.(^> d16 c b)
372 g8.(^> b16 c ees) g8-.^> r r
376 \set PianoStaff.instrumentName = #"Piano"
377 \new Staff \relative c' {
380 s4. s8 r8 r16 <c f aes c>
381 <c f aes c>4.^> <c ees g>8 r r
383 \new Staff \relative c {
387 \once \override DynamicText #'X-offset = #-3
389 <ees g c>4.~ <ees g c>8
392 <c g c,>4.~ <c g c,>8
394 r8 r16 <f, c' aes'>16
395 <f c' aes'>4.-> <c' g'>8 r r
401 @node Why work so hard?
402 @unnumberedsubsec Why work so hard?
404 Musicians are usually more absorbed with performing than with studying
405 the looks of a piece of music, so nitpicking typographical details may
406 seem academic. But it is not. Sheet music is performance material:
407 everything is done to aid the musician in letting her perform better,
408 and anything that is unclear or unpleasant to read is a hinderance.
410 Traditionally engraved music uses bold symbols on heavy staff to create
411 a strong, well-balanced look that stands out well when the music is far
412 away from the reader: for example, if it is on a music stand. A careful
413 distribution of white space allows music to be set very tightly without
414 crowding symbols together. The result minimizes the number of page
415 turns, which is a great advantage.
417 This is a common characteristic of typography. Layout should be pretty,
418 not only for its own sake, but especially because it helps the reader in
419 his task. For sheet music this is of double importance because musicians
420 have a limited amount of attention. The less attention they need for
421 reading, the more they can focus on playing the music. In other words,
422 better typography translates to better performances.
424 These examples demonstrate that music typography is an art that is
425 subtle and complex, and that producing it requires considerable
426 expertise, which musicians usually do not have. LilyPond is our
427 effort to bring the graphical excellence of hand-engraved music to
428 the computer age, and make it available to normal musicians. We
429 have tuned our algorithms, font-designs, and program settings to
430 produce prints that match the quality of the old editions we love
431 to see and love to play from.
434 @node Automated engraving
435 @unnumberedsec Automated engraving
437 @cindex engraving, automated
438 @cindex automated engraving
442 * Notation benchmarking::
443 * Flexible architecture::
446 @node Beauty contests
447 @unnumberedsubsec Beauty contests
449 Rather than trying to write rules that describe how to draw an
450 attractive slur for every possible scenario, we have written rules that
451 describe an attractive slur and LilyPond finds the nicest possibility.
452 For example, here are three possible slur configurations, and LilyPond
453 has given each one a score in `ugly points':
456 %\layout { #(define debug-slur-scoring #t) }
460 \once \override Slur #'positions = #'(1.5 . 1)
461 e8[(_"15.39" f] g[ a b d,)] r4
462 \once \override Slur #'positions = #'(2 . 3)
463 e8[(_"13.08" f] g[ a b d,)] r4
464 e8[(_"12.04" f] g[ a b d,)] r4
470 The first example gets 15.39 points for grazing one of the notes. The
471 second one is nicer, but the slur doesn't start or end on the noteheads.
472 It gets 1.71 points for the left side and 9.37 points for the right
473 side, plus another 2 points because the slur ascends while the melody
474 descends for a total of 13.08 ulgy points. The final slur gets 10.04
475 points for the gap on the right and 2 points for the upward slope, but
476 it is the most attractive of the three configurations, so LilyPond
479 This technique is quite general, and is used to select beam
480 configurations, ties and dots in chords, line breaks, and page breaks.
482 @node Notation benchmarking
483 @unnumberedsubsec Notation benchmarking
485 We have tuned LilyPond's layout rules by comparing its output to
486 hand-engraved scores. Here is one line of a benchmark piece from a
487 hand-engraved edition (Bärenreiter BA320), and as engraved by LilyPond
491 @sourceimage{baer-sarabande-hires,16cm,,}
494 @sourceimage{baer-sarabande,,,png}
498 @sourceimage{lily14-sarabande,16cm,,}
501 @sourceimage{lily14-sarabande,,,png}
504 @noindent The LilyPond 1.4 output is certainly readable, but close
505 comparison with the hand-engraved score showed a lot of errors in the
509 @item most of the stems are too long
510 @item the trill marks are too big
511 @item the second and fourth measures are too narrow
512 @item the slur is awkward-looking
513 @item the stems are too thin
514 @item there was too much space before the time signature
518 (There were also two missing notes, and one wrong one!)
520 By adjusting the layout rules and font design, the output has improved
521 considerably. This is the same musical quotation compared to the output
522 from the current version of LilyPond (@version{}):
525 @sourceimage{baer-sarabande-hires,16cm,,}
528 @sourceimage{baer-sarabande,,,png}
531 @lilypond[staffsize=17.5,line-width=15.9\cm]
536 \mergeDifferentlyDottedOn
537 << {\slurDashed d8.-\flageolet( e16) e4.-\trill( d16 e)}
541 <f' a, d,>4. e8( d c)
543 bes g' f e16( f g_1 a_2 bes_3 d,_2)
545 cis4.-\trill b8_3( a g)
546 << {\slurDashed d'8.( e16) e4.-\trill( d16 e)}
553 The current output is not a clone of the reference edition, but it is
554 much closer to publication quality that the earlier output.
556 @c TODO: remove 3mm eps bounding box left padding for this example
557 @c This will require adding a new snippet option to lilypond-book.py
558 @c TODO: Why is the beaming in measure 3 wrong in 2.13.5?
560 [@strong{Andrew H:} This comparison is not finished. I promise not to
561 leave it in such a mess!]
563 Another valuable form of benchmarking is comparing LilyPond's output to
564 the output of a commercial software product. In this case we have chosen
565 Finale 2008, which is one of the most popular commercial scorewriters,
566 particularly in North America. Sibelius is their major rival and they
567 appear to be especially strong in the European market.
569 We have selected the last seven measures of Bach's Fugue in G minor from
570 the Well-Tempered Clavier, Book I, BWV 861. In the final draft there
571 will be pitcures here, but for now please consult the appendix
572 (currently pp. 12--14) for the output from both programs and images from
573 four reference engravings.
578 @item Finale rests are always at the same heights (in v1/v2 situations).
579 @item Finale doesn't interlock notes nicely (mm. 28--29).
580 @item Finale misses the B-flat in mm. 33!
581 @item Finale's beamed stems are almost always too long when they extend
583 @item LilyPond 2.13.5 has a vertical spacing problem (no padding).
584 @item LilyPond could use a little more space before the first note of
586 @item LilyPond's ties to beat 1 of mm. 31 are shorter than any of the
587 reference scores, and Finale's are even worse.
588 @item LilyPond's stems are often shorter than any of the references,
589 especially RH mm. 31.
590 @item In some locations, the Bärenreiter engraver(s) place rests
591 further from the staff than strictly necessary in order to keep them
592 vertically close to the subsequent element in that voice (e.g. mm. 28).
593 @item There is some acceptable variation within the reference scores,
594 although some scores are more attractive than others.
597 @c How do we go about implementing typography? If craftsmen need
598 @c over ten years to become true masters, how could we simple hackers
599 @c ever write a program to take over their jobs?
601 @c The answer is: we cannot.
603 The last two points lead into this concluding/transition paragraph:
605 Typography relies on human judgment of
606 appearance, so people cannot be replaced completely. However,
607 much of the dull work can be automated. If LilyPond solves most
608 of the common situations correctly, this will be a huge
609 improvement over existing software. The remaining cases can be
610 tuned by hand. Over the course of years, the software can be
611 refined to do more and more things automatically, so manual
612 overrides are less and less necessary. Where manual adjustments are
613 needed, LilyPond's structure must be ...
615 @node Flexible architecture
616 @unnumberedsubsec Flexible architecture
618 When we started, we wrote the LilyPond program entirely in the C++
619 programming language; the program's functionality was set in stone
620 by the developers. That proved to be unsatisfactory for a number
625 @item When LilyPond makes mistakes, users need to override
626 formatting decisions. Therefore, the user must have access to the
627 formatting engine. Hence, rules and settings cannot be fixed by
628 us at compile-time but must be accessible for users at run-time.
630 @item Engraving is a matter of visual judgment, and therefore a
631 matter of taste. As knowledgeable as we are, users can disagree
632 with our personal decisions. Therefore, the definitions of
633 typographical style must also be accessible to the user.
635 @item Finally, we continually refine the formatting algorithms, so
636 we need a flexible approach to rules. The C++ language forces a
637 certain method of grouping rules that cannot readily be applied to
638 formatting music notation.
642 @cindex Scheme programming language
644 These problems have been addressed by integrating an interpreter
645 for the Scheme programming language and rewriting parts of
646 LilyPond in Scheme. The current formatting architecture is built
647 around the notion of graphical objects, described by Scheme
648 variables and functions. This architecture encompasses formatting
649 rules, typographical style and individual formatting decisions.
650 The user has direct access to most of these controls.
652 Scheme variables control layout decisions. For example, many
653 graphical objects have a direction variable that encodes the
654 choice between up and down (or left and right). Here you see two
655 chords, with accents and arpeggios. In the first chord, the
656 graphical objects have all directions down (or left). The second
657 chord has all directions up (right).
659 @lilypond[quote,ragged-right]
661 \override SpacingSpanner #'spacing-increment = #3
662 \override TimeSignature #'transparent = ##t
664 \stemDown <e g b>4_>-\arpeggio
665 \override Arpeggio #'direction = #RIGHT
666 \stemUp <e g b>4^>-\arpeggio
670 @cindex score formatting
671 @cindex formatting a score
672 @cindex formatting rules
675 The process of formatting a score consists of reading and writing
676 the variables of graphical objects. Some variables have a preset
677 value. For example, the thickness of many lines -- a
678 characteristic of typographical style -- is a variable with a
679 preset value. You are free to alter this value, giving your score
680 a different typographical impression.
682 @lilypond[quote,ragged-right]
685 c'4-~ c'16 as g f e16 g bes c' des'4
690 \override Beam #'beam-thickness = #0.3
691 \override Stem #'thickness = #0.5
692 \override Bar #'thickness = #3.6
693 \override Tie #'thickness = #2.2
694 \override StaffSymbol #'thickness = #3.0
695 \override Tie #'extra-offset = #'(0 . 0.3)
701 Formatting rules are also preset variables: each object has
702 variables containing procedures. These procedures perform the
703 actual formatting, and by substituting different ones, we can
704 change the appearance of objects. In the following example, the
705 rule governing which note head objects are used to produce the
706 note head symbol is changed during the music fragment.
708 @lilypond[quote,ragged-right]
709 #(set-global-staff-size 30)
711 #(define (mc-squared grob orig current)
712 (let* ((interfaces (ly:grob-interfaces grob))
713 (pos (ly:grob-property grob 'staff-position)))
714 (if (memq 'note-head-interface interfaces)
716 (ly:grob-set-property! grob 'stencil
717 (grob-interpret-markup grob
718 (make-lower-markup 0.5
722 ((-2) (make-smaller-markup (make-bold-markup "2")))
725 \new Voice \relative c' {
727 \set autoBeaming = ##f
730 \once \override NoteHead #'stencil = #note-head::brew-ez-stencil
731 \once \override NoteHead #'font-size = #-7
732 \once \override NoteHead #'font-family = #'sans
733 \once \override NoteHead #'font-series = #'bold
735 \once \override NoteHead #'style = #'cross
737 \applyOutput #'Voice #mc-squared
740 { d8[ es-( fis^^ g] fis2-) }
741 \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
747 @node What symbols to engrave?
748 @unnumberedsec What symbols to engrave?
755 The formatting process decides where to place symbols. However,
756 this can only be done once it is decided @emph{what} symbols
757 should be printed -- in other words, what notation to use.
759 Common music notation is a system of recording music that has
760 evolved over the past 1000 years. The form that is now in common
761 use dates from the early Renaissance. Although the basic form
762 (i.e., note heads on a 5-line staff) has not changed, the details
763 still evolve to express the innovations of contemporary notation.
764 Hence, common music notation encompasses some 500 years of music.
765 Its applications range from monophonic melodies to monstrous
766 counterpoints for a large orchestra.
768 How can we get a grip on such a seven-headed beast, and force it
769 into the confines of a computer program? Our solution is to break
770 up the problem of notation (as opposed to engraving, i.e.,
771 typography) into digestible and programmable chunks: every type of
772 symbol is handled by a separate module, a so-called plug-in. Each
773 plug-in is completely modular and independent, so each can be
774 developed and improved separately. Such plug-ins are called
775 @code{engraver}s, by analogy with craftsmen who translate musical
776 ideas to graphic symbols.
778 In the following example, we start out with a plug-in for note
779 heads, the @code{Note_heads_engraver}.
781 @lilypond[quote,ragged-right]
782 \include "engraver-example.ily"
789 \remove "Stem_engraver"
790 \remove "Phrasing_slur_engraver"
791 \remove "Slur_engraver"
792 \remove "Script_engraver"
793 \remove "Beam_engraver"
794 \remove "Auto_beam_engraver"
798 \remove "Accidental_engraver"
799 \remove "Key_engraver"
800 \remove "Clef_engraver"
801 \remove "Bar_engraver"
802 \remove "Time_signature_engraver"
803 \remove "Staff_symbol_engraver"
804 \consists "Pitch_squash_engraver"
811 Then a @code{Staff_symbol_engraver} adds the staff,
813 @lilypond[quote,ragged-right]
814 \include "engraver-example.ily"
821 \remove "Stem_engraver"
822 \remove "Phrasing_slur_engraver"
823 \remove "Slur_engraver"
824 \remove "Script_engraver"
825 \remove "Beam_engraver"
826 \remove "Auto_beam_engraver"
830 \remove "Accidental_engraver"
831 \remove "Key_engraver"
832 \remove "Clef_engraver"
833 \remove "Bar_engraver"
834 \consists "Pitch_squash_engraver"
835 \remove "Time_signature_engraver"
842 the @code{Clef_engraver} defines a reference point for the staff,
844 @lilypond[quote,ragged-right]
845 \include "engraver-example.ily"
852 \remove "Stem_engraver"
853 \remove "Phrasing_slur_engraver"
854 \remove "Slur_engraver"
855 \remove "Script_engraver"
856 \remove "Beam_engraver"
857 \remove "Auto_beam_engraver"
861 \remove "Accidental_engraver"
862 \remove "Key_engraver"
863 \remove "Bar_engraver"
864 \remove "Time_signature_engraver"
871 and the @code{Stem_engraver} adds stems.
873 @lilypond[quote,ragged-right]
874 \include "engraver-example.ily"
881 \remove "Phrasing_slur_engraver"
882 \remove "Slur_engraver"
883 \remove "Script_engraver"
884 \remove "Beam_engraver"
885 \remove "Auto_beam_engraver"
889 \remove "Accidental_engraver"
890 \remove "Key_engraver"
891 \remove "Bar_engraver"
892 \remove "Time_signature_engraver"
899 The @code{Stem_engraver} is notified of any note head coming
900 along. Every time one (or more, for a chord) note head is seen, a
901 stem object is created and connected to the note head. By adding
902 engravers for beams, slurs, accents, accidentals, bar lines, time
903 signature, and key signature, we get a complete piece of notation.
905 @lilypond[quote,ragged-right]
906 \include "engraver-example.ily"
911 @cindex engraving multiple voices
914 This system works well for monophonic music, but what about
915 polyphony? In polyphonic notation, many voices can share a staff.
917 @lilypond[quote,ragged-right]
918 \include "engraver-example.ily"
919 \new Staff << \topVoice \\ \botVoice >>
922 In this situation, the accidentals and staff are shared, but the
923 stems, slurs, beams, etc., are private to each voice. Hence,
924 engravers should be grouped. The engravers for note heads, stems,
925 slurs, etc., go into a group called @q{Voice context,} while the
926 engravers for key, accidental, bar, etc., go into a group called
927 @q{Staff context.} In the case of polyphony, a single Staff
928 context contains more than one Voice context. Similarly, multiple
929 Staff contexts can be put into a single Score context. The Score
930 context is the top level notation context.
934 Internals Reference: @rinternals{Contexts}.
937 @lilypond[quote,ragged-right]
938 \include "engraver-example.ily"
941 \new Staff << \topVoice \\ \botVoice >>
942 \new Staff << \pah \\ \hoom >>
948 @node Music representation
949 @unnumberedsec Music representation
952 @cindex recursive structures
954 Ideally, the input format for any high-level formatting system is
955 an abstract description of the content. In this case, that would
956 be the music itself. This poses a formidable problem: how can we
957 define what music really is? Instead of trying to find an answer,
958 we have reversed the question. We write a program capable of
959 producing sheet music, and adjust the format to be as lean as
960 possible. When the format can no longer be trimmed down, by
961 definition we are left with content itself. Our program serves as
962 a formal definition of a music document.
964 The syntax is also the user-interface for LilyPond, hence it is
974 to create a quarter note on middle C (C1) and an eighth note on
975 the D above middle C (D1).
983 On a microscopic scale, such syntax is easy to use. On a larger
984 scale, syntax also needs structure. How else can you enter
985 complex pieces like symphonies and operas? The structure is
986 formed by the concept of music expressions: by combining small
987 fragments of music into larger ones, more complex music can be
988 expressed. For example
990 @lilypond[quote,verbatim,fragment,relative=1]
995 Simultaneous notes can be constructed by enclosing them with
996 @code{<<} and @code{>>}:
1002 @lilypond[quote,fragment,relative=1]
1003 \new Voice { <<c4 d4 e>> }
1007 This expression is put in sequence by enclosing it in curly braces
1008 @code{@{@tie{}@dots{}@tie{}@}}:
1011 @{ f4 <<c4 d4 e4>> @}
1014 @lilypond[quote,relative=1,fragment]
1019 The above is also an expression, and so it may be combined again
1020 with another simultaneous expression (a half note) using
1021 @code{<<}, @code{\\}, and @code{>>}:
1024 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
1027 @lilypond[quote,fragment,relative=2]
1028 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
1031 Such recursive structures can be specified neatly and formally in
1032 a context-free grammar. The parsing code is also generated from
1033 this grammar. In other words, the syntax of LilyPond is clearly
1034 and unambiguously defined.
1036 User-interfaces and syntax are what people see and deal with most.
1037 They are partly a matter of taste, and also the subject of much
1038 discussion. Although discussions on taste do have their merit,
1039 they are not very productive. In the larger picture of LilyPond,
1040 the importance of input syntax is small: inventing neat syntax is
1041 easy, while writing decent formatting code is much harder. This
1042 is also illustrated by the line-counts for the respective
1043 components: parsing and representation take up less than 10% of
1047 @node Example applications
1048 @unnumberedsec Example applications
1050 @cindex simple examples
1051 @cindex examples, simple
1053 We have written LilyPond as an experiment of how to condense the
1054 art of music engraving into a computer program. Thanks to all
1055 that hard work, the program can now be used to perform useful
1056 tasks. The simplest application is printing notes.
1058 @lilypond[quote,relative=1]
1066 By adding chord names and lyrics we obtain a lead sheet.
1068 @lilypond[quote,ragged-right]
1070 \chords { c2 c f2 c }
1076 \addlyrics { twin -- kle twin -- kle lit -- tle star }
1080 Polyphonic notation and piano music can also be printed. The
1081 following example combines some more exotic constructs.
1085 title = "Screech and boink"
1086 subtitle = "Random complex notation"
1087 composer = "Han-Wen Nienhuys"
1091 \context PianoStaff <<
1096 \revert Stem #'direction
1097 \change Staff = down
1098 \set subdivideBeams = ##t
1102 \change Staff = down
1106 \change Staff = down
1110 \set followVoice = ##t
1111 c'''32([ b''16 a''16 gis''16 g''32)]
1113 s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
1115 s4 \autoBeamOff d''8.. f''32
1121 \new Staff = "down" {
1124 \set subdivideBeams = ##f
1125 \override Stem #'french-beaming = ##t
1126 \override Beam #'beam-thickness = #0.3
1127 \override Stem #'thickness = #4.0
1128 g'16[ b16 fis16 g16]
1134 \override Staff.Arpeggio #'arpeggio-direction =#down
1135 <cis, e, gis, b, cis>4\arpeggio
1142 tempoWholesPerMinute = #(ly:make-moment 60 8)
1148 \consists Horizontal_bracket_engraver
1154 The fragments shown above have all been written by hand, but that
1155 is not a requirement. Since the formatting engine is mostly
1156 automatic, it can serve as an output means for other programs that
1157 manipulate music. For example, it can also be used to convert
1158 databases of musical fragments to images for use on websites and
1159 multimedia presentations.
1161 This manual also shows an application: the input format is text,
1162 and can therefore be easily embedded in other text-based formats
1163 such as @LaTeX{}, HTML, or in the case of this manual, Texinfo.
1164 By means of a special program, the input fragments can be replaced
1165 by music images in the resulting PDF or HTML output files. This
1166 makes it easy to mix music and text in documents.
1169 TODO: add extra chapter for computer aesthetics?
1173 @unnumberedsec Appendix
1175 This appendix contaions four reference engravings and two
1176 software-engraved versions of Bach's Fugue in G minor from the
1177 Well-Tempered Clavier, Book I, BWV 861 (the last seven measures).
1180 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1184 @sourceimage{bwv861-baer,16cm,,}
1187 @sourceimage{bwv861-baer-small,,,png}
1191 Bärenreiter BA5070 (Neue Ausgabe Sämtlicher Werke, Serie V, Band 6.1,
1192 1989), an alternate musical source. Aside from the textual differences,
1193 this demsontrates slight variations in the engraving decisions, even
1194 from the same publisher and edition:
1197 @sourceimage{bwv861-baer-alt,16cm,,}
1200 @sourceimage{bwv861-baer-alt-small,,,png}
1204 Breitkopf & Härtel, edited by Ferruccio Busoni (Wiesbaden, 1894), also
1205 available from the Petrucci Music Library (IMSLP #22081). The editorial
1206 markings (fingerings, articulations, etc.) have been removed for clearer
1207 comparison with the other editions here:
1210 @sourceimage{bwv861-breitkopf,16cm,,}
1213 @sourceimage{bwv861-breitkopf-small,,,png}
1217 Bach-Gessellschaft edition (Leipzig, 1866), available from the Petrucci
1218 Music Library (IMSPL #02221):
1221 @sourceimage{bwv861-gessellschaft,16cm,,}
1224 @sourceimage{bwv861-gessellschaft-small,,,png}
1231 @sourceimage{pdf/bwv861-finale2008a,,,}
1234 @sourceimage{bwv861-finale2008a,,,png}
1238 LilyPond, version @version{}:
1240 @lilypond[staffsize=14.3,line-width=15.9\cm]
1241 global = {\key g \minor}
1243 partI = \relative c' {
1245 fis8 d' ees g, fis4 g
1246 r8 a16 bes c8 bes16 a d8 r r4
1247 r2 r8 d16 ees f8 ees16 d
1248 ees4 ~ ees16 d c bes a4 r8 ees'16 d
1249 c8 d16 ees d8 e16 fis g8 fis16 g a4 ~
1250 a8 d, g f ees d c bes
1251 a2 g\fermata \bar "|."
1254 partII = \relative c' {
1256 d4 r4 r8 d'16 c bes8 c16 d
1257 ees8 d c ees a, r r4
1258 r8 fis16 g a8 g16 fis g2 ~
1260 fis4 g r8 a16 bes c8 bes16 a
1261 bes4. <g b>8 <a c> r <d, g> r
1264 partIII = \relative c' {
1266 r2 r8 d ees g, fis4 g r8 a16 bes c8 bes16 a
1267 bes2 ~ bes8 b16 a g8 a16 b
1271 r8 a16 bes c8 bes16 a b2
1273 partIV = \relative c {
1277 d,8 d'16 c bes8 c16 d ees2 ~
1278 ees8 ees16 d c8 d16 ees fis,8 a16 g fis8 g16 a
1279 d,8 d'16 c bes8 c16 d ees8 c a fis'
1286 % \set Score.barNumberVisibility = #all-bar-numbers-visible
1288 \set Score.currentBarNumber = #28
1291 \new Staff = "RH" <<
1293 \new Voice = "voiceI" { \partI }
1294 \new Voice = "voiceII" { \partII }
1297 \new Staff = "LH" <<
1300 \new Voice = "voiceIII" { \partIII }
1301 \new Voice = "voiceIV" { \partIV }
1308 \remove "Time_signature_engraver"