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.
50 @image{pictures/hader-slaan,,7cm}
53 @image{pictures/hader-slaan,,,jpg}
57 @image{lilypond/pictures/hader-slaan,,,,jpg}
60 Nowadays, all newly printed music is produced with computers. This has
61 obvious advantages: prints are cheaper to make, editorial work can be
62 delivered by email, and the original data can be easily stored.
63 Unfortunately, computer-generated scores rarely match the quality of
64 hand-engraved scores. Instead, computer printouts have a bland,
65 mechanical look, which makes them unpleasant to play from.
67 From the beginning, we designed LilyPond to mimic the beauty of
68 traditional music engraving. Along the way, we have learned a great deal
69 about the work that goes into a well-engraved score. Below we describe
70 several of those aspects that we have tried to imitate in LilyPond.
73 @unnumberedsubsec Music Fonts
75 The images below illustrate the difference between traditional engraving
76 and typical computer output. The left picture shows a scan of a flat
77 symbol from a hand-engraved Bärenreiter edition, while the right picture
78 depicts a symbol from an edition of the same music published in 2000.
79 Although both images are printed in the shame shade of ink, the earlier
80 version looks darker: the staff lines are heavier, and the Bärenreiter
81 flat has a bold, almost voluptuous rounded look. The right scan, on the
82 other hand, has thinner lines and a straight layout with sharp corners.
84 @multitable @columnfractions .25 .25 .25 .25
88 @image{pictures/baer-flat-gray,,4cm}
91 @image{pictures/baer-flat-gray,,,png}
96 @image{pictures/henle-flat-gray,,4cm}
99 @image{pictures/henle-flat-gray,,,png}
104 @image{lilypond/pictures/henle-flat-bw,,,,png}
105 @image{lilypond/pictures/baer-flat-bw,,,,png}
106 @image{lilypond/pictures/lily-flat-bw,,,,png}
117 @cindex musical symbols
122 When we wanted to write a computer program to create music typography,
123 there were no musical fonts freely available that could match the
124 elegance of our favorite scores. Not let down, we created a font of
125 musical symbols, relying on nice printouts of hand-engraved music. The
126 experience helped develop a typographical taste, and it made us
127 appreciate subtle design details. Without that experience, we would not
128 have realized how ugly the fonts were that we admired at first.
130 Below is a sample of two music fonts: the upper set is the default font
131 in the Sibelius software (the @emph{Opus} font), and the lower set is
132 our own LilyPond font.
136 @image{pictures/pdf/OpusAndFeta,,,}
139 @image{pictures/OpusAndFeta,,,png}
143 @image{lilypond/pictures/OpusAndFeta,,,,png}
146 The LilyPond symbols are heavier and their weight is more consistent,
147 which makes them easier to read. Fine endings, such as the one on the
148 bottom of the quarter rest, should not end in sharp points, but rather
149 in rounded shapes. This is because sharp corners of the punching dies
150 are fragile and quickly wear out when stamping in metal. Taken together,
151 the blackness of the font must be carefully tuned together with the
152 thickness of lines, beams and slurs to give a strong yet balanced
155 Also, notice that our half-notehead is not elliptic but slightly diamond
156 shaped. The vertical stem of a flat symbol is slightly brushed, becoming
157 wider at the top. The sharp and the natural are easier to distinguish
158 from a distance because their angled lines have different slopes and the
159 vertical strokes are heavier.
161 @node Optical Spacing
162 @unnumberedsubsec Optical Spacing
164 In spacing, the distribution of space should reflect the durations
165 between notes. However, many modern scores adhere to the
166 durations with mathematical precision, which leads to poor
167 results. In the next example a motive is printed twice: the first time
168 using exact mathematical spacing, and the second with corrections.
171 @cindex optical spacing
192 \override NoteSpacing #'stem-spacing-correction = #0.0
193 \override NoteSpacing #'same-direction-correction = #0.0
194 \override StaffSpacing #'stem-spacing-correction = #0.0
220 \override NoteSpacing #'stem-spacing-correction = #0.6
226 @cindex regular rhythms
227 @cindex regular spacing
228 @cindex spacing, regular
230 Each bar in the fragment only uses notes that are played in a
231 constant rhythm. The spacing should reflect that. Unfortunately,
232 the eye deceives us a little; not only does it notice the distance
233 between note heads, it also takes into account the distance
234 between consecutive stems. As a result, the notes of an
235 up-stem/@/down-stem combination should be put farther apart, and
236 the notes of a down-stem/@/up-stem combination should be put
237 closer together, all depending on the combined vertical positions
238 of the notes. The upper two measures are printed with this
239 correction, the lower two measures, however, form down-stem/@/up-stem
240 clumps of notes. A master engraver would adjust the spacing as needed to
243 Another example of optical spacing is the visual interplay between the
244 stems and the bar lines. When an up-stem precedes the bar line, a little
245 more space is needed to keep it from feeling crowded:
254 c''8 c'' c'' c'' c'' c'' c'' c'' \break
255 a' a' a' a' a' a' a' a'
260 \remove "Time_signature_engraver"
261 \override NoteSpacing #'stem-spacing-correction = #0.7
268 @unnumberedsubsec Ledger Lines
272 @image{pictures/baer-ledger,4cm}
275 @image{pictures/baer-ledger,,,png}
279 @image{lilypond/pictures/baer-ledger,,,,png}
283 @unnumberedsubsec Slurs
285 @node Why work so hard?
286 @unnumberedsubsec Why work so hard?
288 Musicians are usually more absorbed with performing than with
289 studying the looks of a piece of music, so nitpicking
290 typographical details may seem academic. But it is not. In
291 larger pieces with monotonous rhythms, spacing corrections lead to
292 subtle variations in the layout of every line, giving each one a
293 distinct visual signature. Without this signature all lines would
294 look the same, and they become like a labyrinth. A distinct visual
295 signature helps to keep musicians from losing their place on the
296 page when they look away or have a lapse in concentration.
298 Similarly, the strong visual look of bold symbols on heavy staff
299 lines stands out better when the music is far away from the
300 reader: for example, if it is on a music stand. A careful
301 distribution of white space allows music to be set very tightly
302 without crowding symbols together. The result minimizes the
303 number of page turns, which is a great advantage.
305 This is a common characteristic of typography. Layout should be
306 pretty, not only for its own sake, but especially because it helps
307 the reader in her task. For performance material like sheet
308 music, this is of double importance: musicians have a limited
309 amount of attention. The less attention they need for reading,
310 the more they can focus on playing the music. In other words,
311 better typography translates to better performances.
313 These examples demonstrate that music typography is an art that is
314 subtle and complex, and that producing it requires considerable
315 expertise, which musicians usually do not have. LilyPond is our
316 effort to bring the graphical excellence of hand-engraved music to
317 the computer age, and make it available to normal musicians. We
318 have tuned our algorithms, font-designs, and program settings to
319 produce prints that match the quality of the old editions we love
320 to see and love to play from.
323 @node Automated engraving
324 @unnumberedsec Automated engraving
326 @cindex engraving, automated
327 @cindex automated engraving
329 @node Beauty contests
330 @unnumberedsubsec Beauty contests
332 @node Notation benchmarking
333 @unnumberedsubsec Notation benchmarking
339 @image{pictures/baer-sarabande,16cm}
342 @image{pictures/baer-sarabande,,,png}
346 @image{lilypond/pictures/baer-sarabande,,,,png}
353 @image{pictures/lily14-sarabande,16cm}
356 @image{pictures/lily14-sarabande,,,png}
360 @image{lilypond/pictures/lily14-sarabande,,,,png}
363 LilyPond 2.13.x (can this number be generated?):
365 @lilypond[relative=0,staffsize=19,line-width=16\cm]
370 \mergeDifferentlyDottedOn
371 << {d8. e16 e4. d16 e} \\ {d4 a2} >>
373 bes g' f e16( f g a bes d,)
375 << {d'8. e16 e4. d16 e} \\ {<f, a>4 a2} >>
379 [LilyPond snippet above not finished]
381 [a few bars of LilyPond vs. Finale can go here]
383 @node Flexible architecture
384 @unnumberedsubsec Flexible architecture
386 How do we go about implementing typography? If craftsmen need
387 over ten years to become true masters, how could we simple hackers
388 ever write a program to take over their jobs?
390 The answer is: we cannot. Typography relies on human judgment of
391 appearance, so people cannot be replaced completely. However,
392 much of the dull work can be automated. If LilyPond solves most
393 of the common situations correctly, this will be a huge
394 improvement over existing software. The remaining cases can be
395 tuned by hand. Over the course of years, the software can be
396 refined to do more and more things automatically, so manual
397 overrides are less and less necessary.
399 When we started, we wrote the LilyPond program entirely in the C++
400 programming language; the program's functionality was set in stone
401 by the developers. That proved to be unsatisfactory for a number
406 @item When LilyPond makes mistakes, users need to override
407 formatting decisions. Therefore, the user must have access to the
408 formatting engine. Hence, rules and settings cannot be fixed by
409 us at compile-time but must be accessible for users at run-time.
411 @item Engraving is a matter of visual judgment, and therefore a
412 matter of taste. As knowledgeable as we are, users can disagree
413 with our personal decisions. Therefore, the definitions of
414 typographical style must also be accessible to the user.
416 @item Finally, we continually refine the formatting algorithms, so
417 we need a flexible approach to rules. The C++ language forces a
418 certain method of grouping rules that cannot readily be applied to
419 formatting music notation.
423 @cindex Scheme programming language
425 These problems have been addressed by integrating an interpreter
426 for the Scheme programming language and rewriting parts of
427 LilyPond in Scheme. The current formatting architecture is built
428 around the notion of graphical objects, described by Scheme
429 variables and functions. This architecture encompasses formatting
430 rules, typographical style and individual formatting decisions.
431 The user has direct access to most of these controls.
433 Scheme variables control layout decisions. For example, many
434 graphical objects have a direction variable that encodes the
435 choice between up and down (or left and right). Here you see two
436 chords, with accents and arpeggios. In the first chord, the
437 graphical objects have all directions down (or left). The second
438 chord has all directions up (right).
440 @lilypond[quote,ragged-right]
442 \override SpacingSpanner #'spacing-increment = #3
443 \override TimeSignature #'transparent = ##t
445 \stemDown <e g b>4_>-\arpeggio
446 \override Arpeggio #'direction = #RIGHT
447 \stemUp <e g b>4^>-\arpeggio
451 @cindex score formatting
452 @cindex formatting a score
453 @cindex formatting rules
456 The process of formatting a score consists of reading and writing
457 the variables of graphical objects. Some variables have a preset
458 value. For example, the thickness of many lines -- a
459 characteristic of typographical style -- is a variable with a
460 preset value. You are free to alter this value, giving your score
461 a different typographical impression.
463 @lilypond[quote,ragged-right]
466 c'4-~ c'16 as g f e16 g bes c' des'4
471 \override Beam #'beam-thickness = #0.3
472 \override Stem #'thickness = #0.5
473 \override Bar #'thickness = #3.6
474 \override Tie #'thickness = #2.2
475 \override StaffSymbol #'thickness = #3.0
476 \override Tie #'extra-offset = #'(0 . 0.3)
482 Formatting rules are also preset variables: each object has
483 variables containing procedures. These procedures perform the
484 actual formatting, and by substituting different ones, we can
485 change the appearance of objects. In the following example, the
486 rule governing which note head objects are used to produce the
487 note head symbol is changed during the music fragment.
489 @lilypond[quote,ragged-right]
490 #(set-global-staff-size 30)
492 #(define (mc-squared grob orig current)
493 (let* ((interfaces (ly:grob-interfaces grob))
494 (pos (ly:grob-property grob 'staff-position)))
495 (if (memq 'note-head-interface interfaces)
497 (ly:grob-set-property! grob 'stencil
498 (grob-interpret-markup grob
499 (make-lower-markup 0.5
503 ((-2) (make-smaller-markup (make-bold-markup "2")))
506 \new Voice \relative c' {
508 \set autoBeaming = ##f
511 \once \override NoteHead #'stencil = #note-head::brew-ez-stencil
512 \once \override NoteHead #'font-size = #-7
513 \once \override NoteHead #'font-family = #'sans
514 \once \override NoteHead #'font-series = #'bold
516 \once \override NoteHead #'style = #'cross
518 \applyOutput #'Voice #mc-squared
521 { d8[ es-( fis^^ g] fis2-) }
522 \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
528 @node What symbols to engrave?
529 @unnumberedsec What symbols to engrave?
536 The formatting process decides where to place symbols. However,
537 this can only be done once it is decided @emph{what} symbols
538 should be printed -- in other words, what notation to use.
540 Common music notation is a system of recording music that has
541 evolved over the past 1000 years. The form that is now in common
542 use dates from the early Renaissance. Although the basic form
543 (i.e., note heads on a 5-line staff) has not changed, the details
544 still evolve to express the innovations of contemporary notation.
545 Hence, common music notation encompasses some 500 years of music.
546 Its applications range from monophonic melodies to monstrous
547 counterpoints for a large orchestra.
549 How can we get a grip on such a seven-headed beast, and force it
550 into the confines of a computer program? Our solution is to break
551 up the problem of notation (as opposed to engraving, i.e.,
552 typography) into digestible and programmable chunks: every type of
553 symbol is handled by a separate module, a so-called plug-in. Each
554 plug-in is completely modular and independent, so each can be
555 developed and improved separately. Such plug-ins are called
556 @code{engraver}s, by analogy with craftsmen who translate musical
557 ideas to graphic symbols.
559 In the following example, we start out with a plug-in for note
560 heads, the @code{Note_heads_engraver}.
562 @lilypond[quote,ragged-right]
563 \include "engraver-example.ily"
570 \remove "Stem_engraver"
571 \remove "Phrasing_slur_engraver"
572 \remove "Slur_engraver"
573 \remove "Script_engraver"
574 \remove "Beam_engraver"
575 \remove "Auto_beam_engraver"
579 \remove "Accidental_engraver"
580 \remove "Key_engraver"
581 \remove "Clef_engraver"
582 \remove "Bar_engraver"
583 \remove "Time_signature_engraver"
584 \remove "Staff_symbol_engraver"
585 \consists "Pitch_squash_engraver"
592 Then a @code{Staff_symbol_engraver} adds the staff,
594 @lilypond[quote,ragged-right]
595 \include "engraver-example.ily"
602 \remove "Stem_engraver"
603 \remove "Phrasing_slur_engraver"
604 \remove "Slur_engraver"
605 \remove "Script_engraver"
606 \remove "Beam_engraver"
607 \remove "Auto_beam_engraver"
611 \remove "Accidental_engraver"
612 \remove "Key_engraver"
613 \remove "Clef_engraver"
614 \remove "Bar_engraver"
615 \consists "Pitch_squash_engraver"
616 \remove "Time_signature_engraver"
623 the @code{Clef_engraver} defines a reference point for the staff,
625 @lilypond[quote,ragged-right]
626 \include "engraver-example.ily"
633 \remove "Stem_engraver"
634 \remove "Phrasing_slur_engraver"
635 \remove "Slur_engraver"
636 \remove "Script_engraver"
637 \remove "Beam_engraver"
638 \remove "Auto_beam_engraver"
642 \remove "Accidental_engraver"
643 \remove "Key_engraver"
644 \remove "Bar_engraver"
645 \remove "Time_signature_engraver"
652 and the @code{Stem_engraver} adds stems.
654 @lilypond[quote,ragged-right]
655 \include "engraver-example.ily"
662 \remove "Phrasing_slur_engraver"
663 \remove "Slur_engraver"
664 \remove "Script_engraver"
665 \remove "Beam_engraver"
666 \remove "Auto_beam_engraver"
670 \remove "Accidental_engraver"
671 \remove "Key_engraver"
672 \remove "Bar_engraver"
673 \remove "Time_signature_engraver"
680 The @code{Stem_engraver} is notified of any note head coming
681 along. Every time one (or more, for a chord) note head is seen, a
682 stem object is created and connected to the note head. By adding
683 engravers for beams, slurs, accents, accidentals, bar lines, time
684 signature, and key signature, we get a complete piece of notation.
686 @lilypond[quote,ragged-right]
687 \include "engraver-example.ily"
692 @cindex engraving multiple voices
695 This system works well for monophonic music, but what about
696 polyphony? In polyphonic notation, many voices can share a staff.
698 @lilypond[quote,ragged-right]
699 \include "engraver-example.ily"
700 \new Staff << \topVoice \\ \botVoice >>
703 In this situation, the accidentals and staff are shared, but the
704 stems, slurs, beams, etc., are private to each voice. Hence,
705 engravers should be grouped. The engravers for note heads, stems,
706 slurs, etc., go into a group called @q{Voice context,} while the
707 engravers for key, accidental, bar, etc., go into a group called
708 @q{Staff context.} In the case of polyphony, a single Staff
709 context contains more than one Voice context. Similarly, multiple
710 Staff contexts can be put into a single Score context. The Score
711 context is the top level notation context.
715 Internals Reference: @rinternals{Contexts}.
718 @lilypond[quote,ragged-right]
719 \include "engraver-example.ily"
722 \new Staff << \topVoice \\ \botVoice >>
723 \new Staff << \pah \\ \hoom >>
729 @node Music representation
730 @unnumberedsec Music representation
733 @cindex recursive structures
735 Ideally, the input format for any high-level formatting system is
736 an abstract description of the content. In this case, that would
737 be the music itself. This poses a formidable problem: how can we
738 define what music really is? Instead of trying to find an answer,
739 we have reversed the question. We write a program capable of
740 producing sheet music, and adjust the format to be as lean as
741 possible. When the format can no longer be trimmed down, by
742 definition we are left with content itself. Our program serves as
743 a formal definition of a music document.
745 The syntax is also the user-interface for LilyPond, hence it is
755 to create a quarter note on middle C (C1) and an eighth note on
756 the D above middle C (D1).
764 On a microscopic scale, such syntax is easy to use. On a larger
765 scale, syntax also needs structure. How else can you enter
766 complex pieces like symphonies and operas? The structure is
767 formed by the concept of music expressions: by combining small
768 fragments of music into larger ones, more complex music can be
769 expressed. For example
771 @lilypond[quote,verbatim,fragment,relative=1]
776 Simultaneous notes can be constructed by enclosing them with
777 @code{<<} and @code{>>}:
783 @lilypond[quote,fragment,relative=1]
784 \new Voice { <<c4 d4 e>> }
788 This expression is put in sequence by enclosing it in curly braces
789 @code{@{@tie{}@dots{}@tie{}@}}:
792 @{ f4 <<c4 d4 e4>> @}
795 @lilypond[quote,relative=1,fragment]
800 The above is also an expression, and so it may be combined again
801 with another simultaneous expression (a half note) using
802 @code{<<}, @code{\\}, and @code{>>}:
805 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
808 @lilypond[quote,fragment,relative=2]
809 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
812 Such recursive structures can be specified neatly and formally in
813 a context-free grammar. The parsing code is also generated from
814 this grammar. In other words, the syntax of LilyPond is clearly
815 and unambiguously defined.
817 User-interfaces and syntax are what people see and deal with most.
818 They are partly a matter of taste, and also the subject of much
819 discussion. Although discussions on taste do have their merit,
820 they are not very productive. In the larger picture of LilyPond,
821 the importance of input syntax is small: inventing neat syntax is
822 easy, while writing decent formatting code is much harder. This
823 is also illustrated by the line-counts for the respective
824 components: parsing and representation take up less than 10% of
828 @node Example applications
829 @unnumberedsec Example applications
831 @cindex simple examples
832 @cindex examples, simple
834 We have written LilyPond as an experiment of how to condense the
835 art of music engraving into a computer program. Thanks to all
836 that hard work, the program can now be used to perform useful
837 tasks. The simplest application is printing notes.
839 @lilypond[quote,relative=1]
847 By adding chord names and lyrics we obtain a lead sheet.
849 @lilypond[quote,ragged-right]
851 \chords { c2 c f2 c }
857 \addlyrics { twin -- kle twin -- kle lit -- tle star }
861 Polyphonic notation and piano music can also be printed. The
862 following example combines some more exotic constructs.
866 title = "Screech and boink"
867 subtitle = "Random complex notation"
868 composer = "Han-Wen Nienhuys"
872 \context PianoStaff <<
877 \revert Stem #'direction
879 \set subdivideBeams = ##t
891 \set followVoice = ##t
892 c'''32([ b''16 a''16 gis''16 g''32)]
894 s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
896 s4 \autoBeamOff d''8.. f''32
902 \new Staff = "down" {
905 \set subdivideBeams = ##f
906 \override Stem #'french-beaming = ##t
907 \override Beam #'beam-thickness = #0.3
908 \override Stem #'thickness = #4.0
915 \override Staff.Arpeggio #'arpeggio-direction =#down
916 <cis, e, gis, b, cis>4\arpeggio
923 tempoWholesPerMinute = #(ly:make-moment 60 8)
929 \consists Horizontal_bracket_engraver
935 The fragments shown above have all been written by hand, but that
936 is not a requirement. Since the formatting engine is mostly
937 automatic, it can serve as an output means for other programs that
938 manipulate music. For example, it can also be used to convert
939 databases of musical fragments to images for use on websites and
940 multimedia presentations.
942 This manual also shows an application: the input format is text,
943 and can therefore be easily embedded in other text-based formats
944 such as @LaTeX{}, HTML, or in the case of this manual, Texinfo.
945 By means of a special program, the input fragments can be replaced
946 by music images in the resulting PDF or HTML output files. This
947 makes it easy to mix music and text in documents.
950 TODO: add extra chapter for computer aesthetics?