]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/essay/engraving.itely
Essay: minor build-related fixes.
[lilypond.git] / Documentation / essay / engraving.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.13.4"
11
12 @node Music engraving
13 @chapter Music engraving
14
15 This section covers the overall goals and architecture of
16 LilyPond.
17
18 @menu
19 * Engraving::                   
20 * Automated engraving::         
21 * What symbols to engrave?::    
22 * Music representation::        
23 * Example applications::        
24 @end menu
25
26
27 @node Engraving
28 @unnumberedsec Engraving
29
30 @cindex engraving
31 @cindex typography, music
32 @cindex music typography
33 @cindex plate engraving
34 @cindex music engraving
35
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.
47
48 @iftex
49 @image{pictures/hader-slaan,,7cm}
50 @end iftex
51 @ifnottex
52 @sourceimage{hader-slaan,,,jpg}
53 @end ifnottex
54
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.
61
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.
66
67 @menu
68 * Music Fonts::                 
69 * Optical Spacing::             
70 * Ledger Lines::                
71 * Slurs::                       
72 * Why work so hard?::           
73 @end menu
74
75 @node Music Fonts
76 @unnumberedsubsec Music Fonts
77
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.
86
87 @multitable @columnfractions .25 .25 .25 .25
88 @item @tab
89 @ifnotinfo
90 @iftex
91 @image{pictures/baer-flat-gray,,4cm}
92 @end iftex
93 @ifnottex
94 @image{pictures/baer-flat-gray,,,png}
95 @end ifnottex
96
97 @tab
98 @iftex
99 @image{pictures/henle-flat-gray,,4cm}
100 @end iftex
101 @ifnottex
102 @image{pictures/henle-flat-gray,,,png}
103 @end ifnottex
104
105 @end ifnotinfo
106 @ifinfo
107 @image{lilypond/pictures/henle-flat-bw,,,,png}
108 @image{lilypond/pictures/baer-flat-bw,,,,png}
109 @image{lilypond/pictures/lily-flat-bw,,,,png}
110 @end ifinfo
111
112
113 @item @tab
114 Bärenreiter (1950)
115 @tab
116 Henle (2000)
117
118 @end multitable
119
120 @cindex musical symbols
121 @cindex font
122 @cindex blackness
123 @cindex balance
124
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.
132
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.
136
137 @iftex
138 @image{pictures/pdf/OpusAndFeta,,,}
139 @end iftex
140 @ifnottex
141 @sourceimage{OpusAndFeta,,,png}
142 @end ifnottex
143
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
151 overall impression.
152
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.
158
159 @node Optical Spacing
160 @unnumberedsubsec Optical Spacing
161
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.
167 Which do you prefer?
168
169 @cindex optical spacing
170
171 @lilypond
172 \paper {
173   ragged-right = ##t
174   indent = #0.0
175 }
176
177 music = {
178    c'4 e''4 e'4 b'4 |
179    \stemDown
180    b'8[ e'' a' e'']
181    \stemNeutral
182    e'8[ e'8 e'8 e'8]
183 }
184 \score
185 {
186   \music
187   \layout {
188     \context {
189       \Staff
190       \override NoteSpacing #'stem-spacing-correction = #0.0
191       \override NoteSpacing #'same-direction-correction = #0.0
192       \override StaffSpacing #'stem-spacing-correction = #0.0
193     }
194   }
195 }
196 @end lilypond
197
198 @lilypond
199 \paper {
200   ragged-right = ##t
201   indent = #0.0
202 }
203
204 music = {
205    c'4 e''4 e'4 b'4 |
206    \stemDown
207    b'8[ e'' a' e'']
208    \stemNeutral
209    e'8[ e'8 e'8 e'8]
210 }
211
212 \score
213 {
214   \music
215   \layout {
216     \context {
217       \Staff
218       \override NoteSpacing #'stem-spacing-correction = #0.6
219     }
220   }
221 }
222 @end lilypond
223
224 @cindex regular rhythms
225 @cindex regular spacing
226 @cindex spacing, regular
227
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
239 please the eye.
240
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:
244
245 @lilypond
246 \paper {
247   ragged-right = ##t
248 }
249
250 \score {
251   {
252     c''8 c'' c'' c'' c'' c'' c'' c'' \break
253     a' a' a' a' a' a' a' a'
254   }
255   \layout {
256     \context {
257       \Staff
258       \remove "Time_signature_engraver"
259       \override NoteSpacing #'stem-spacing-correction = #0.7
260     }
261   }
262 }
263 @end lilypond
264
265 @node Ledger Lines
266 @unnumberedsubsec Ledger Lines
267
268 @ifnotinfo
269 @iftex
270 @image{pictures/baer-ledger,4cm}
271 @end iftex
272 @ifnottex
273 @image{pictures/baer-ledger,,,png}
274 @end ifnottex
275 @end ifnotinfo
276 @ifinfo
277 @image{lilypond/pictures/baer-ledger,,,,png}
278 @end ifinfo
279
280 @node Slurs
281 @unnumberedsubsec Slurs
282
283 @node Why work so hard?
284 @unnumberedsubsec Why work so hard?
285
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.
295
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.
302
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.
310
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.
319
320
321 @node Automated engraving
322 @unnumberedsec Automated engraving
323
324 @cindex engraving, automated
325 @cindex automated engraving
326
327 @menu
328 * Beauty contests::             
329 * Notation benchmarking::       
330 * Flexible architecture::       
331 @end menu
332
333 @node Beauty contests
334 @unnumberedsubsec Beauty contests
335
336 @node Notation benchmarking
337 @unnumberedsubsec Notation benchmarking
338
339 Bärenreiter:
340
341 @ifnotinfo
342 @iftex
343 @image{pictures/baer-sarabande,16cm}
344 @end iftex
345 @ifnottex
346 @image{pictures/baer-sarabande,,,png}
347 @end ifnottex
348 @end ifnotinfo
349 @ifinfo
350 @image{lilypond/pictures/baer-sarabande,,,,png}
351 @end ifinfo
352
353 LilyPond 1.4:
354
355 @ifnotinfo
356 @iftex
357 @image{pictures/lily14-sarabande,16cm}
358 @end iftex
359 @ifnottex
360 @image{pictures/lily14-sarabande,,,png}
361 @end ifnottex
362 @end ifnotinfo
363 @ifinfo
364 @image{lilypond/pictures/lily14-sarabande,,,,png}
365 @end ifinfo
366
367 LilyPond @version{}:
368
369 @lilypond[relative=0,staffsize=19,line-width=16\cm]
370 {
371   \clef "bass"
372   \key d \minor
373   \time 3/4
374   \mergeDifferentlyDottedOn
375   << {d8. e16 e4. d16 e} \\ {d4 a2} >>
376   <f' a, d,>4. e8 d c
377   bes g' f e16( f g a bes d,)
378   cis4. b8 a g
379   << {d'8. e16 e4. d16 e} \\ {<f, a>4 a2} >>
380 }
381 @end lilypond
382
383 [LilyPond snippet above not finished]
384
385 [a few bars of LilyPond vs. Finale can go here]
386
387 @node Flexible architecture
388 @unnumberedsubsec Flexible architecture
389
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?
393
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.
402
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
406 of reasons:
407
408 @itemize
409
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.
414
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.
419
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.
424
425 @end itemize
426
427 @cindex Scheme programming language
428
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.
436
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).
443
444 @lilypond[quote,ragged-right]
445 \new Score \with {
446    \override SpacingSpanner #'spacing-increment = #3
447    \override TimeSignature #'transparent = ##t
448 } \relative c' {
449    \stemDown <e g b>4_>-\arpeggio
450    \override Arpeggio #'direction = #RIGHT
451    \stemUp <e g b>4^>-\arpeggio
452 }
453 @end lilypond
454
455 @cindex score formatting
456 @cindex formatting a score
457 @cindex formatting rules
458
459 @noindent
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.
466
467 @lilypond[quote,ragged-right]
468 fragment = {
469    \clef bass f8 as8
470    c'4-~ c'16 as g f e16 g bes c' des'4
471 }
472 <<
473    \new Staff \fragment
474    \new Staff \with {
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)
481       }
482       \fragment
483 >>
484 @end lilypond
485
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.
492
493 @lilypond[quote,ragged-right]
494 #(set-global-staff-size 30)
495
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)
500         (begin
501           (ly:grob-set-property! grob 'stencil
502             (grob-interpret-markup grob
503               (make-lower-markup 0.5
504                 (case pos
505                   ((-5) "m")
506                   ((-3) "c ")
507                   ((-2) (make-smaller-markup (make-bold-markup "2")))
508                   (else "bla")))))))))
509
510 \new Voice \relative c' {
511   \stemUp
512   \set autoBeaming = ##f
513   \time 2/4
514   <d f g>4
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
519   <d f g>4
520   \once \override NoteHead #'style = #'cross
521   <d f g>4
522   \applyOutput #'Voice #mc-squared
523   <d f g>4
524   <<
525     { d8[ es-( fis^^ g] fis2-) }
526     \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
527   >>
528 }
529 @end lilypond
530
531
532 @node What symbols to engrave?
533 @unnumberedsec What symbols to engrave?
534
535 @cindex engraving
536 @cindex typography
537 @cindex engraver
538 @cindex plug-in
539
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.
543
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.
552
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.
562
563 In the following example, we start out with a plug-in for note
564 heads, the @code{Note_heads_engraver}.
565
566 @lilypond[quote,ragged-right]
567 \include "engraver-example.ily"
568
569 \score {
570   \topVoice
571   \layout {
572     \context {
573       \Voice
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"
580     }
581     \context {
582       \Staff
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"
590     }
591   }
592 }
593 @end lilypond
594
595 @noindent
596 Then a @code{Staff_symbol_engraver} adds the staff,
597
598 @lilypond[quote,ragged-right]
599 \include "engraver-example.ily"
600
601 \score {
602   \topVoice
603   \layout {
604     \context {
605       \Voice
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"
612     }
613     \context {
614       \Staff
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"
621     }
622   }
623 }
624 @end lilypond
625
626 @noindent
627 the @code{Clef_engraver} defines a reference point for the staff,
628
629 @lilypond[quote,ragged-right]
630 \include "engraver-example.ily"
631
632 \score {
633   \topVoice
634   \layout {
635     \context {
636       \Voice
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"
643     }
644     \context {
645       \Staff
646       \remove "Accidental_engraver"
647       \remove "Key_engraver"
648       \remove "Bar_engraver"
649       \remove "Time_signature_engraver"
650     }
651   }
652 }
653 @end lilypond
654
655 @noindent
656 and the @code{Stem_engraver} adds stems.
657
658 @lilypond[quote,ragged-right]
659 \include "engraver-example.ily"
660
661 \score {
662   \topVoice
663   \layout {
664     \context {
665       \Voice
666       \remove "Phrasing_slur_engraver"
667       \remove "Slur_engraver"
668       \remove "Script_engraver"
669       \remove "Beam_engraver"
670       \remove "Auto_beam_engraver"
671     }
672     \context {
673       \Staff
674       \remove "Accidental_engraver"
675       \remove "Key_engraver"
676       \remove "Bar_engraver"
677       \remove "Time_signature_engraver"
678     }
679   }
680 }
681 @end lilypond
682
683 @noindent
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.
689
690 @lilypond[quote,ragged-right]
691 \include "engraver-example.ily"
692 \score { \topVoice }
693 @end lilypond
694
695 @cindex polyphony
696 @cindex engraving multiple voices
697 @cindex contexts
698
699 This system works well for monophonic music, but what about
700 polyphony?  In polyphonic notation, many voices can share a staff.
701
702 @lilypond[quote,ragged-right]
703 \include "engraver-example.ily"
704 \new Staff << \topVoice \\ \botVoice >>
705 @end lilypond
706
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.
716
717
718 @seealso
719 Internals Reference: @rinternals{Contexts}.
720
721
722 @lilypond[quote,ragged-right]
723 \include "engraver-example.ily"
724 \score {
725    <<
726       \new Staff << \topVoice \\ \botVoice >>
727       \new Staff << \pah \\ \hoom >>
728    >>
729 }
730 @end lilypond
731
732
733 @node Music representation
734 @unnumberedsec Music representation
735
736 @cindex syntax
737 @cindex recursive structures
738
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.
748
749 The syntax is also the user-interface for LilyPond, hence it is
750 easy to type:
751
752 @example
753 @{
754   c'4 d'8
755 @}
756 @end example
757
758 @noindent
759 to create a quarter note on middle C (C1) and an eighth note on
760 the D above middle C (D1).
761
762 @lilypond[quote]
763 {
764   c'4 d'8
765 }
766 @end lilypond
767
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
774
775 @lilypond[quote,verbatim,fragment,relative=1]
776 f4
777 @end lilypond
778
779 @noindent
780 Simultaneous notes can be constructed by enclosing them with
781 @code{<<} and @code{>>}:
782
783 @example
784 <<c4 d4 e4>>
785 @end example
786
787 @lilypond[quote,fragment,relative=1]
788 \new Voice { <<c4 d4 e>> }
789 @end lilypond
790
791 @noindent
792 This expression is put in sequence by enclosing it in curly braces
793 @code{@{@tie{}@dots{}@tie{}@}}:
794
795 @example
796 @{ f4 <<c4 d4 e4>> @}
797 @end example
798
799 @lilypond[quote,relative=1,fragment]
800 { f4 <<c d e4>> }
801 @end lilypond
802
803 @noindent
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{>>}:
807
808 @example
809 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
810 @end example
811
812 @lilypond[quote,fragment,relative=2]
813 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
814 @end lilypond
815
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.
820
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
829 the source code.
830
831
832 @node Example applications
833 @unnumberedsec Example applications
834
835 @cindex simple examples
836 @cindex examples, simple
837
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.
842
843 @lilypond[quote,relative=1]
844 {
845   \time 2/4
846   c4 c g'4 g a4 a g2
847 }
848 @end lilypond
849
850 @noindent
851 By adding chord names and lyrics we obtain a lead sheet.
852
853 @lilypond[quote,ragged-right]
854 <<
855    \chords { c2 c f2 c }
856    \new Staff
857    \relative c' {
858      \time 2/4
859      c4 c g' g a a g2
860    }
861    \addlyrics { twin -- kle twin -- kle lit -- tle star }
862 >>
863 @end lilypond
864
865 Polyphonic notation and piano music can also be printed.  The
866 following example combines some more exotic constructs.
867
868 @lilypond[quote]
869 \header {
870   title = "Screech and boink"
871   subtitle = "Random complex notation"
872   composer = "Han-Wen Nienhuys"
873 }
874
875 \score {
876   \context PianoStaff <<
877     \new Staff = "up" {
878       \time 4/8
879       \key c \minor
880       << {
881         \revert Stem #'direction
882         \change Staff = down
883         \set subdivideBeams = ##t
884         g16.[
885           \change Staff = up
886           c'''32
887           \change Staff = down
888           g32
889           \change Staff = up
890           c'''32
891           \change Staff = down
892           g16]
893         \change Staff = up
894         \stemUp
895         \set followVoice = ##t
896         c'''32([ b''16 a''16 gis''16 g''32)]
897       } \\ {
898         s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
899       } \\ {
900         s4 \autoBeamOff d''8.. f''32
901       } \\ {
902         s4 es''4
903       } >>
904     }
905
906     \new Staff = "down" {
907       \clef bass
908       \key c \minor
909       \set subdivideBeams = ##f
910       \override Stem  #'french-beaming = ##t
911       \override Beam  #'beam-thickness = #0.3
912       \override Stem  #'thickness = #4.0
913       g'16[ b16 fis16 g16]
914       << \makeClusters {
915         as16 <as b>
916         <g b>
917         <g cis>
918       } \\ {
919         \override Staff.Arpeggio  #'arpeggio-direction =#down
920         <cis, e, gis, b, cis>4\arpeggio
921       }
922     >> }
923   >>
924   \midi {
925     \context {
926       \Score
927       tempoWholesPerMinute = #(ly:make-moment 60 8)
928     }
929   }
930   \layout {
931     \context {
932       \Staff
933       \consists Horizontal_bracket_engraver
934     }
935   }
936 }
937 @end lilypond
938
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.
945
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.
952
953
954 TODO: add extra chapter for computer aesthetics?