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::
28 @unnumberedsec Engraving
31 @cindex typography, music
32 @cindex music typography
33 @cindex plate engraving
34 @cindex music engraving
36 The art of music typography is called @emph{(plate) engraving}. The term
37 derives from the traditional process of music printing. Just a few
38 decades ago, sheet music was made by cutting and stamping the music into
39 a zinc or pewter plate in mirror image. The plate would be inked, and
40 the depressions caused by the cutting and stamping would hold ink. An
41 image was formed by pressing paper to the plate. The stamping and
42 cutting was done completely by hand. Making a correction was cumbersome,
43 so the engraving had to be nearly perfect in one go. Engraving was a
44 highly specialized skill; a craftsman had to complete around five years
45 of training before earning the title of master engraver, and another
46 five years of experience were necessary to become truly skilled.
49 @image{pictures/hader-slaan,,7cm}
52 @sourceimage{hader-slaan,,,jpg}
55 Nowadays, all newly printed music is produced with computers. This has
56 obvious advantages: prints are cheaper to make, editorial work can be
57 delivered by email, and the original data can be easily stored.
58 Unfortunately, computer-generated scores rarely match the quality of
59 hand-engraved scores. Instead, computer printouts have a bland,
60 mechanical look, which makes them unpleasant to play from.
62 From the beginning, we designed LilyPond to mimic the beauty of
63 traditional music engraving. Along the way, we have learned a great deal
64 about the work that goes into a well-engraved score. Below we describe
65 several of those aspects that we have tried to imitate in LilyPond.
76 @unnumberedsubsec Music Fonts
78 The images below illustrate the difference between traditional engraving
79 and typical computer output. The left picture shows a scan of a flat
80 symbol from a hand-engraved Bärenreiter edition, while the right picture
81 depicts a symbol from an edition of the same music published in 2000.
82 Although both images are printed in the shame shade of ink, the earlier
83 version looks darker: the staff lines are heavier, and the Bärenreiter
84 flat has a bold, almost voluptuous rounded look. The right scan, on the
85 other hand, has thinner lines and a straight layout with sharp corners.
87 @multitable @columnfractions .25 .25 .25 .25
91 @image{pictures/baer-flat-gray,,4cm}
94 @image{pictures/baer-flat-gray,,,png}
99 @image{pictures/henle-flat-gray,,4cm}
102 @image{pictures/henle-flat-gray,,,png}
107 @image{lilypond/pictures/henle-flat-bw,,,,png}
108 @image{lilypond/pictures/baer-flat-bw,,,,png}
109 @image{lilypond/pictures/lily-flat-bw,,,,png}
120 @cindex musical symbols
125 When we wanted to write a computer program to create music typography,
126 there were no musical fonts freely available that could match the
127 elegance of our favorite scores. Not let down, we created a font of
128 musical symbols, relying on nice printouts of hand-engraved music. The
129 experience helped develop a typographical taste, and it made us
130 appreciate subtle design details. Without that experience, we would not
131 have realized how ugly the fonts were that we admired at first.
133 Below is a sample of two music fonts: the upper set is the default font
134 in the Sibelius software (the @emph{Opus} font), and the lower set is
135 our own LilyPond font.
138 @image{pictures/pdf/OpusAndFeta,,,}
141 @sourceimage{OpusAndFeta,,,png}
144 The LilyPond symbols are heavier and their weight is more consistent,
145 which makes them easier to read. Fine endings, such as the one on the
146 bottom of the quarter rest, should not end in sharp points, but rather
147 in rounded shapes. This is because sharp corners of the punching dies
148 are fragile and quickly wear out when stamping in metal. Taken together,
149 the blackness of the font must be carefully tuned together with the
150 thickness of lines, beams and slurs to give a strong yet balanced
153 Also, notice that our half-notehead is not elliptic but slightly diamond
154 shaped. The vertical stem of a flat symbol is slightly brushed, becoming
155 wider at the top. The sharp and the natural are easier to distinguish
156 from a distance because their angled lines have different slopes and the
157 vertical strokes are heavier.
159 @node Optical Spacing
160 @unnumberedsubsec Optical Spacing
162 In spacing, the distribution of space should reflect the durations
163 between notes. However, many modern scores adhere to the
164 durations with mathematical precision, which leads to poor
165 results. In the next example a motive is printed twice: the first time
166 using exact mathematical spacing, and the second with corrections.
169 @cindex optical spacing
190 \override NoteSpacing #'stem-spacing-correction = #0.0
191 \override NoteSpacing #'same-direction-correction = #0.0
192 \override StaffSpacing #'stem-spacing-correction = #0.0
218 \override NoteSpacing #'stem-spacing-correction = #0.6
224 @cindex regular rhythms
225 @cindex regular spacing
226 @cindex spacing, regular
228 Each bar in the fragment only uses notes that are played in a
229 constant rhythm. The spacing should reflect that. Unfortunately,
230 the eye deceives us a little; not only does it notice the distance
231 between note heads, it also takes into account the distance
232 between consecutive stems. As a result, the notes of an
233 up-stem/@/down-stem combination should be put farther apart, and
234 the notes of a down-stem/@/up-stem combination should be put
235 closer together, all depending on the combined vertical positions
236 of the notes. The upper two measures are printed with this
237 correction, the lower two measures, however, form down-stem/@/up-stem
238 clumps of notes. A master engraver would adjust the spacing as needed to
241 Another example of optical spacing is the visual interplay between the
242 stems and the bar lines. When an up-stem precedes the bar line, a little
243 more space is needed to keep it from feeling crowded:
252 c''8 c'' c'' c'' c'' c'' c'' c'' \break
253 a' a' a' a' a' a' a' a'
258 \remove "Time_signature_engraver"
259 \override NoteSpacing #'stem-spacing-correction = #0.7
266 @unnumberedsubsec Ledger Lines
270 @image{pictures/baer-ledger,4cm}
273 @image{pictures/baer-ledger,,,png}
277 @image{lilypond/pictures/baer-ledger,,,,png}
281 @unnumberedsubsec Slurs
283 @node Why work so hard?
284 @unnumberedsubsec Why work so hard?
286 Musicians are usually more absorbed with performing than with
287 studying the looks of a piece of music, so nitpicking
288 typographical details may seem academic. But it is not. In
289 larger pieces with monotonous rhythms, spacing corrections lead to
290 subtle variations in the layout of every line, giving each one a
291 distinct visual signature. Without this signature all lines would
292 look the same, and they become like a labyrinth. A distinct visual
293 signature helps to keep musicians from losing their place on the
294 page when they look away or have a lapse in concentration.
296 Similarly, the strong visual look of bold symbols on heavy staff
297 lines stands out better when the music is far away from the
298 reader: for example, if it is on a music stand. A careful
299 distribution of white space allows music to be set very tightly
300 without crowding symbols together. The result minimizes the
301 number of page turns, which is a great advantage.
303 This is a common characteristic of typography. Layout should be
304 pretty, not only for its own sake, but especially because it helps
305 the reader in her task. For performance material like sheet
306 music, this is of double importance: musicians have a limited
307 amount of attention. The less attention they need for reading,
308 the more they can focus on playing the music. In other words,
309 better typography translates to better performances.
311 These examples demonstrate that music typography is an art that is
312 subtle and complex, and that producing it requires considerable
313 expertise, which musicians usually do not have. LilyPond is our
314 effort to bring the graphical excellence of hand-engraved music to
315 the computer age, and make it available to normal musicians. We
316 have tuned our algorithms, font-designs, and program settings to
317 produce prints that match the quality of the old editions we love
318 to see and love to play from.
321 @node Automated engraving
322 @unnumberedsec Automated engraving
324 @cindex engraving, automated
325 @cindex automated engraving
329 * Notation benchmarking::
330 * Flexible architecture::
333 @node Beauty contests
334 @unnumberedsubsec Beauty contests
336 @node Notation benchmarking
337 @unnumberedsubsec Notation benchmarking
343 @image{pictures/baer-sarabande,16cm}
346 @image{pictures/baer-sarabande,,,png}
350 @image{lilypond/pictures/baer-sarabande,,,,png}
357 @image{pictures/lily14-sarabande,16cm}
360 @image{pictures/lily14-sarabande,,,png}
364 @image{lilypond/pictures/lily14-sarabande,,,,png}
369 @lilypond[relative=0,staffsize=19,line-width=16\cm]
374 \mergeDifferentlyDottedOn
375 << {d8. e16 e4. d16 e} \\ {d4 a2} >>
377 bes g' f e16( f g a bes d,)
379 << {d'8. e16 e4. d16 e} \\ {<f, a>4 a2} >>
383 [LilyPond snippet above not finished]
385 [a few bars of LilyPond vs. Finale can go here]
387 @node Flexible architecture
388 @unnumberedsubsec Flexible architecture
390 How do we go about implementing typography? If craftsmen need
391 over ten years to become true masters, how could we simple hackers
392 ever write a program to take over their jobs?
394 The answer is: we cannot. Typography relies on human judgment of
395 appearance, so people cannot be replaced completely. However,
396 much of the dull work can be automated. If LilyPond solves most
397 of the common situations correctly, this will be a huge
398 improvement over existing software. The remaining cases can be
399 tuned by hand. Over the course of years, the software can be
400 refined to do more and more things automatically, so manual
401 overrides are less and less necessary.
403 When we started, we wrote the LilyPond program entirely in the C++
404 programming language; the program's functionality was set in stone
405 by the developers. That proved to be unsatisfactory for a number
410 @item When LilyPond makes mistakes, users need to override
411 formatting decisions. Therefore, the user must have access to the
412 formatting engine. Hence, rules and settings cannot be fixed by
413 us at compile-time but must be accessible for users at run-time.
415 @item Engraving is a matter of visual judgment, and therefore a
416 matter of taste. As knowledgeable as we are, users can disagree
417 with our personal decisions. Therefore, the definitions of
418 typographical style must also be accessible to the user.
420 @item Finally, we continually refine the formatting algorithms, so
421 we need a flexible approach to rules. The C++ language forces a
422 certain method of grouping rules that cannot readily be applied to
423 formatting music notation.
427 @cindex Scheme programming language
429 These problems have been addressed by integrating an interpreter
430 for the Scheme programming language and rewriting parts of
431 LilyPond in Scheme. The current formatting architecture is built
432 around the notion of graphical objects, described by Scheme
433 variables and functions. This architecture encompasses formatting
434 rules, typographical style and individual formatting decisions.
435 The user has direct access to most of these controls.
437 Scheme variables control layout decisions. For example, many
438 graphical objects have a direction variable that encodes the
439 choice between up and down (or left and right). Here you see two
440 chords, with accents and arpeggios. In the first chord, the
441 graphical objects have all directions down (or left). The second
442 chord has all directions up (right).
444 @lilypond[quote,ragged-right]
446 \override SpacingSpanner #'spacing-increment = #3
447 \override TimeSignature #'transparent = ##t
449 \stemDown <e g b>4_>-\arpeggio
450 \override Arpeggio #'direction = #RIGHT
451 \stemUp <e g b>4^>-\arpeggio
455 @cindex score formatting
456 @cindex formatting a score
457 @cindex formatting rules
460 The process of formatting a score consists of reading and writing
461 the variables of graphical objects. Some variables have a preset
462 value. For example, the thickness of many lines -- a
463 characteristic of typographical style -- is a variable with a
464 preset value. You are free to alter this value, giving your score
465 a different typographical impression.
467 @lilypond[quote,ragged-right]
470 c'4-~ c'16 as g f e16 g bes c' des'4
475 \override Beam #'beam-thickness = #0.3
476 \override Stem #'thickness = #0.5
477 \override Bar #'thickness = #3.6
478 \override Tie #'thickness = #2.2
479 \override StaffSymbol #'thickness = #3.0
480 \override Tie #'extra-offset = #'(0 . 0.3)
486 Formatting rules are also preset variables: each object has
487 variables containing procedures. These procedures perform the
488 actual formatting, and by substituting different ones, we can
489 change the appearance of objects. In the following example, the
490 rule governing which note head objects are used to produce the
491 note head symbol is changed during the music fragment.
493 @lilypond[quote,ragged-right]
494 #(set-global-staff-size 30)
496 #(define (mc-squared grob orig current)
497 (let* ((interfaces (ly:grob-interfaces grob))
498 (pos (ly:grob-property grob 'staff-position)))
499 (if (memq 'note-head-interface interfaces)
501 (ly:grob-set-property! grob 'stencil
502 (grob-interpret-markup grob
503 (make-lower-markup 0.5
507 ((-2) (make-smaller-markup (make-bold-markup "2")))
510 \new Voice \relative c' {
512 \set autoBeaming = ##f
515 \once \override NoteHead #'stencil = #note-head::brew-ez-stencil
516 \once \override NoteHead #'font-size = #-7
517 \once \override NoteHead #'font-family = #'sans
518 \once \override NoteHead #'font-series = #'bold
520 \once \override NoteHead #'style = #'cross
522 \applyOutput #'Voice #mc-squared
525 { d8[ es-( fis^^ g] fis2-) }
526 \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
532 @node What symbols to engrave?
533 @unnumberedsec What symbols to engrave?
540 The formatting process decides where to place symbols. However,
541 this can only be done once it is decided @emph{what} symbols
542 should be printed -- in other words, what notation to use.
544 Common music notation is a system of recording music that has
545 evolved over the past 1000 years. The form that is now in common
546 use dates from the early Renaissance. Although the basic form
547 (i.e., note heads on a 5-line staff) has not changed, the details
548 still evolve to express the innovations of contemporary notation.
549 Hence, common music notation encompasses some 500 years of music.
550 Its applications range from monophonic melodies to monstrous
551 counterpoints for a large orchestra.
553 How can we get a grip on such a seven-headed beast, and force it
554 into the confines of a computer program? Our solution is to break
555 up the problem of notation (as opposed to engraving, i.e.,
556 typography) into digestible and programmable chunks: every type of
557 symbol is handled by a separate module, a so-called plug-in. Each
558 plug-in is completely modular and independent, so each can be
559 developed and improved separately. Such plug-ins are called
560 @code{engraver}s, by analogy with craftsmen who translate musical
561 ideas to graphic symbols.
563 In the following example, we start out with a plug-in for note
564 heads, the @code{Note_heads_engraver}.
566 @lilypond[quote,ragged-right]
567 \include "engraver-example.ily"
574 \remove "Stem_engraver"
575 \remove "Phrasing_slur_engraver"
576 \remove "Slur_engraver"
577 \remove "Script_engraver"
578 \remove "Beam_engraver"
579 \remove "Auto_beam_engraver"
583 \remove "Accidental_engraver"
584 \remove "Key_engraver"
585 \remove "Clef_engraver"
586 \remove "Bar_engraver"
587 \remove "Time_signature_engraver"
588 \remove "Staff_symbol_engraver"
589 \consists "Pitch_squash_engraver"
596 Then a @code{Staff_symbol_engraver} adds the staff,
598 @lilypond[quote,ragged-right]
599 \include "engraver-example.ily"
606 \remove "Stem_engraver"
607 \remove "Phrasing_slur_engraver"
608 \remove "Slur_engraver"
609 \remove "Script_engraver"
610 \remove "Beam_engraver"
611 \remove "Auto_beam_engraver"
615 \remove "Accidental_engraver"
616 \remove "Key_engraver"
617 \remove "Clef_engraver"
618 \remove "Bar_engraver"
619 \consists "Pitch_squash_engraver"
620 \remove "Time_signature_engraver"
627 the @code{Clef_engraver} defines a reference point for the staff,
629 @lilypond[quote,ragged-right]
630 \include "engraver-example.ily"
637 \remove "Stem_engraver"
638 \remove "Phrasing_slur_engraver"
639 \remove "Slur_engraver"
640 \remove "Script_engraver"
641 \remove "Beam_engraver"
642 \remove "Auto_beam_engraver"
646 \remove "Accidental_engraver"
647 \remove "Key_engraver"
648 \remove "Bar_engraver"
649 \remove "Time_signature_engraver"
656 and the @code{Stem_engraver} adds stems.
658 @lilypond[quote,ragged-right]
659 \include "engraver-example.ily"
666 \remove "Phrasing_slur_engraver"
667 \remove "Slur_engraver"
668 \remove "Script_engraver"
669 \remove "Beam_engraver"
670 \remove "Auto_beam_engraver"
674 \remove "Accidental_engraver"
675 \remove "Key_engraver"
676 \remove "Bar_engraver"
677 \remove "Time_signature_engraver"
684 The @code{Stem_engraver} is notified of any note head coming
685 along. Every time one (or more, for a chord) note head is seen, a
686 stem object is created and connected to the note head. By adding
687 engravers for beams, slurs, accents, accidentals, bar lines, time
688 signature, and key signature, we get a complete piece of notation.
690 @lilypond[quote,ragged-right]
691 \include "engraver-example.ily"
696 @cindex engraving multiple voices
699 This system works well for monophonic music, but what about
700 polyphony? In polyphonic notation, many voices can share a staff.
702 @lilypond[quote,ragged-right]
703 \include "engraver-example.ily"
704 \new Staff << \topVoice \\ \botVoice >>
707 In this situation, the accidentals and staff are shared, but the
708 stems, slurs, beams, etc., are private to each voice. Hence,
709 engravers should be grouped. The engravers for note heads, stems,
710 slurs, etc., go into a group called @q{Voice context,} while the
711 engravers for key, accidental, bar, etc., go into a group called
712 @q{Staff context.} In the case of polyphony, a single Staff
713 context contains more than one Voice context. Similarly, multiple
714 Staff contexts can be put into a single Score context. The Score
715 context is the top level notation context.
719 Internals Reference: @rinternals{Contexts}.
722 @lilypond[quote,ragged-right]
723 \include "engraver-example.ily"
726 \new Staff << \topVoice \\ \botVoice >>
727 \new Staff << \pah \\ \hoom >>
733 @node Music representation
734 @unnumberedsec Music representation
737 @cindex recursive structures
739 Ideally, the input format for any high-level formatting system is
740 an abstract description of the content. In this case, that would
741 be the music itself. This poses a formidable problem: how can we
742 define what music really is? Instead of trying to find an answer,
743 we have reversed the question. We write a program capable of
744 producing sheet music, and adjust the format to be as lean as
745 possible. When the format can no longer be trimmed down, by
746 definition we are left with content itself. Our program serves as
747 a formal definition of a music document.
749 The syntax is also the user-interface for LilyPond, hence it is
759 to create a quarter note on middle C (C1) and an eighth note on
760 the D above middle C (D1).
768 On a microscopic scale, such syntax is easy to use. On a larger
769 scale, syntax also needs structure. How else can you enter
770 complex pieces like symphonies and operas? The structure is
771 formed by the concept of music expressions: by combining small
772 fragments of music into larger ones, more complex music can be
773 expressed. For example
775 @lilypond[quote,verbatim,fragment,relative=1]
780 Simultaneous notes can be constructed by enclosing them with
781 @code{<<} and @code{>>}:
787 @lilypond[quote,fragment,relative=1]
788 \new Voice { <<c4 d4 e>> }
792 This expression is put in sequence by enclosing it in curly braces
793 @code{@{@tie{}@dots{}@tie{}@}}:
796 @{ f4 <<c4 d4 e4>> @}
799 @lilypond[quote,relative=1,fragment]
804 The above is also an expression, and so it may be combined again
805 with another simultaneous expression (a half note) using
806 @code{<<}, @code{\\}, and @code{>>}:
809 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
812 @lilypond[quote,fragment,relative=2]
813 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
816 Such recursive structures can be specified neatly and formally in
817 a context-free grammar. The parsing code is also generated from
818 this grammar. In other words, the syntax of LilyPond is clearly
819 and unambiguously defined.
821 User-interfaces and syntax are what people see and deal with most.
822 They are partly a matter of taste, and also the subject of much
823 discussion. Although discussions on taste do have their merit,
824 they are not very productive. In the larger picture of LilyPond,
825 the importance of input syntax is small: inventing neat syntax is
826 easy, while writing decent formatting code is much harder. This
827 is also illustrated by the line-counts for the respective
828 components: parsing and representation take up less than 10% of
832 @node Example applications
833 @unnumberedsec Example applications
835 @cindex simple examples
836 @cindex examples, simple
838 We have written LilyPond as an experiment of how to condense the
839 art of music engraving into a computer program. Thanks to all
840 that hard work, the program can now be used to perform useful
841 tasks. The simplest application is printing notes.
843 @lilypond[quote,relative=1]
851 By adding chord names and lyrics we obtain a lead sheet.
853 @lilypond[quote,ragged-right]
855 \chords { c2 c f2 c }
861 \addlyrics { twin -- kle twin -- kle lit -- tle star }
865 Polyphonic notation and piano music can also be printed. The
866 following example combines some more exotic constructs.
870 title = "Screech and boink"
871 subtitle = "Random complex notation"
872 composer = "Han-Wen Nienhuys"
876 \context PianoStaff <<
881 \revert Stem #'direction
883 \set subdivideBeams = ##t
895 \set followVoice = ##t
896 c'''32([ b''16 a''16 gis''16 g''32)]
898 s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
900 s4 \autoBeamOff d''8.. f''32
906 \new Staff = "down" {
909 \set subdivideBeams = ##f
910 \override Stem #'french-beaming = ##t
911 \override Beam #'beam-thickness = #0.3
912 \override Stem #'thickness = #4.0
919 \override Staff.Arpeggio #'arpeggio-direction =#down
920 <cis, e, gis, b, cis>4\arpeggio
927 tempoWholesPerMinute = #(ly:make-moment 60 8)
933 \consists Horizontal_bracket_engraver
939 The fragments shown above have all been written by hand, but that
940 is not a requirement. Since the formatting engine is mostly
941 automatic, it can serve as an output means for other programs that
942 manipulate music. For example, it can also be used to convert
943 databases of musical fragments to images for use on websites and
944 multimedia presentations.
946 This manual also shows an application: the input format is text,
947 and can therefore be easily embedded in other text-based formats
948 such as @LaTeX{}, HTML, or in the case of this manual, Texinfo.
949 By means of a special program, the input fragments can be replaced
950 by music images in the resulting PDF or HTML output files. This
951 makes it easy to mix music and text in documents.
954 TODO: add extra chapter for computer aesthetics?