]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/essay/engraving.itely
Merge branch 'lilypond/translation' of ssh://jomand@git.sv.gnu.org/srv/git/lilypond
[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 @quotation
49 @iftex
50 @image{pictures/hader-slaan,,7cm}
51 @end iftex
52 @ifnottex
53 @sourceimage{hader-slaan,,,jpg}
54 @end ifnottex
55 @end quotation
56
57 Nowadays, all newly printed music is produced with computers. This has
58 obvious advantages: prints are cheaper to make, editorial work can be
59 delivered by email, and the original data can be easily stored.
60 Unfortunately, computer-generated scores rarely match the quality of
61 hand-engraved scores. Instead, computer printouts have a bland,
62 mechanical look, which makes them unpleasant to play from.
63
64 From the beginning, we designed LilyPond to mimic the beauty of
65 traditional music engraving. Along the way, we have learned a great deal
66 about the work that goes into a well-engraved score. Below we describe
67 several of those aspects that we have tried to imitate in LilyPond.
68
69 @menu
70 * Music Fonts::                 
71 * Optical Spacing::             
72 * Ledger Lines::                
73 * Slurs::                       
74 * Why work so hard?::           
75 @end menu
76
77 @node Music Fonts
78 @unnumberedsubsec Music Fonts
79
80 The images below illustrate the difference between traditional engraving
81 and typical computer output. The left picture shows a scan of a flat
82 symbol from a hand-engraved Bärenreiter edition, while the right picture
83 depicts a symbol from an edition of the same music published in 2000.
84 Although both images are printed in the shame shade of ink, the earlier
85 version looks darker: the staff lines are heavier, and the Bärenreiter
86 flat has a bold, almost voluptuous rounded look. The right scan, on the
87 other hand, has thinner lines and a straight layout with sharp corners.
88
89 @multitable @columnfractions .25 .25 .25 .25
90 @item @tab
91 @ifnotinfo
92 @iftex
93 @image{pictures/baer-flat-gray,,4cm}
94 @end iftex
95 @ifnottex
96 @image{pictures/baer-flat-gray,,,png}
97 @end ifnottex
98
99 @tab
100 @iftex
101 @image{pictures/henle-flat-gray,,4cm}
102 @end iftex
103 @ifnottex
104 @image{pictures/henle-flat-gray,,,png}
105 @end ifnottex
106
107 @end ifnotinfo
108 @ifinfo
109 @image{lilypond/pictures/henle-flat-bw,,,,png}
110 @image{lilypond/pictures/baer-flat-bw,,,,png}
111 @image{lilypond/pictures/lily-flat-bw,,,,png}
112 @end ifinfo
113
114
115 @item @tab
116 Bärenreiter (1950)
117 @tab
118 Henle (2000)
119
120 @end multitable
121
122 @cindex musical symbols
123 @cindex font
124 @cindex blackness
125 @cindex balance
126
127 When we wanted to write a computer program to create music typography,
128 there were no musical fonts freely available that could match the
129 elegance of our favorite scores. Not let down, we created a font of
130 musical symbols, relying on nice printouts of hand-engraved music. The
131 experience helped develop a typographical taste, and it made us
132 appreciate subtle design details. Without that experience, we would not
133 have realized how ugly the fonts were that we admired at first.
134
135 Below is a sample of two music fonts: the upper set is the default font
136 in the Sibelius software (the @emph{Opus} font), and the lower set is
137 our own LilyPond font.
138
139 @quotation
140 @iftex
141 @image{pictures/pdf/OpusAndFeta,,,}
142 @end iftex
143 @ifnottex
144 @sourceimage{OpusAndFeta,,,png}
145 @end ifnottex
146 @end quotation
147
148 The LilyPond symbols are heavier and their weight is more consistent,
149 which makes them easier to read. Fine endings, such as the one on the
150 bottom of the quarter rest, should not end in sharp points, but rather
151 in rounded shapes. This is because sharp corners of the punching dies
152 are fragile and quickly wear out when stamping in metal. Taken together,
153 the blackness of the font must be carefully tuned together with the
154 thickness of lines, beams and slurs to give a strong yet balanced
155 overall impression.
156
157 Also, notice that our half-notehead is not elliptic but slightly diamond
158 shaped. The vertical stem of a flat symbol is slightly brushed, becoming
159 wider at the top. The sharp and the natural are easier to distinguish
160 from a distance because their angled lines have different slopes and the
161 vertical strokes are heavier.
162
163 @node Optical Spacing
164 @unnumberedsubsec Optical Spacing
165
166 In spacing, the distribution of space should reflect the durations
167 between notes.  However, many modern scores adhere to the
168 durations with mathematical precision, which leads to poor
169 results.  In the next example a motive is printed twice: the first time
170 using exact mathematical spacing, and the second with corrections.
171 Which do you prefer?
172
173 @cindex optical spacing
174
175 @lilypond
176 \paper {
177   ragged-right = ##t
178   indent = #0.0
179 }
180
181 music = {
182    c'4 e''4 e'4 b'4 |
183    \stemDown
184    b'8[ e'' a' e'']
185    \stemNeutral
186    e'8[ e'8 e'8 e'8]
187 }
188 \score
189 {
190   \music
191   \layout {
192     \context {
193       \Staff
194       \override NoteSpacing #'stem-spacing-correction = #0.0
195       \override NoteSpacing #'same-direction-correction = #0.0
196       \override StaffSpacing #'stem-spacing-correction = #0.0
197     }
198   }
199 }
200 @end lilypond
201
202 @lilypond
203 \paper {
204   ragged-right = ##t
205   indent = #0.0
206 }
207
208 music = {
209    c'4 e''4 e'4 b'4 |
210    \stemDown
211    b'8[ e'' a' e'']
212    \stemNeutral
213    e'8[ e'8 e'8 e'8]
214 }
215
216 \score
217 {
218   \music
219   \layout {
220     \context {
221       \Staff
222       \override NoteSpacing #'stem-spacing-correction = #0.6
223     }
224   }
225 }
226 @end lilypond
227
228 @cindex regular rhythms
229 @cindex regular spacing
230 @cindex spacing, regular
231
232 Each bar in the fragment only uses notes that are played in a
233 constant rhythm.  The spacing should reflect that.  Unfortunately,
234 the eye deceives us a little; not only does it notice the distance
235 between note heads, it also takes into account the distance
236 between consecutive stems.  As a result, the notes of an
237 up-stem/@/down-stem combination should be put farther apart, and
238 the notes of a down-stem/@/up-stem combination should be put
239 closer together, all depending on the combined vertical positions
240 of the notes.  The upper two measures are printed with this
241 correction, the lower two measures, however, form down-stem/@/up-stem
242 clumps of notes. A master engraver would adjust the spacing as needed to
243 please the eye.
244
245 Another example of optical spacing is the visual interplay between the
246 stems and the bar lines. When an up-stem precedes the bar line, a little
247 more space is needed to keep it from feeling crowded:
248
249 @lilypond
250 \paper {
251   ragged-right = ##t
252 }
253
254 \score {
255   {
256     c''8 c'' c'' c'' c'' c'' c'' c'' \break
257     a' a' a' a' a' a' a' a'
258   }
259   \layout {
260     \context {
261       \Staff
262       \remove "Time_signature_engraver"
263       \override NoteSpacing #'stem-spacing-correction = #0.7
264     }
265   }
266 }
267 @end lilypond
268
269 @node Ledger Lines
270 @unnumberedsubsec Ledger Lines
271
272 @ifnotinfo
273 @iftex
274 @image{pictures/baer-ledger,4cm}
275 @end iftex
276 @ifnottex
277 @image{pictures/baer-ledger,,,png}
278 @end ifnottex
279 @end ifnotinfo
280 @ifinfo
281 @image{lilypond/pictures/baer-ledger,,,,png}
282 @end ifinfo
283
284 @node Slurs
285 @unnumberedsubsec Slurs
286
287 @node Why work so hard?
288 @unnumberedsubsec Why work so hard?
289
290 Musicians are usually more absorbed with performing than with
291 studying the looks of a piece of music, so nitpicking
292 typographical details may seem academic.  But it is not.  In
293 larger pieces with monotonous rhythms, spacing corrections lead to
294 subtle variations in the layout of every line, giving each one a
295 distinct visual signature.  Without this signature all lines would
296 look the same, and they become like a labyrinth.  A distinct visual
297 signature helps to keep musicians from losing their place on the
298 page when they look away or have a lapse in concentration.
299
300 Similarly, the strong visual look of bold symbols on heavy staff
301 lines stands out better when the music is far away from the
302 reader: for example, if it is on a music stand.  A careful
303 distribution of white space allows music to be set very tightly
304 without crowding symbols together.  The result minimizes the
305 number of page turns, which is a great advantage.
306
307 This is a common characteristic of typography.  Layout should be
308 pretty, not only for its own sake, but especially because it helps
309 the reader in her task.  For performance material like sheet
310 music, this is of double importance: musicians have a limited
311 amount of attention.  The less attention they need for reading,
312 the more they can focus on playing the music.  In other words,
313 better typography translates to better performances.
314
315 These examples demonstrate that music typography is an art that is
316 subtle and complex, and that producing it requires considerable
317 expertise, which musicians usually do not have.  LilyPond is our
318 effort to bring the graphical excellence of hand-engraved music to
319 the computer age, and make it available to normal musicians.  We
320 have tuned our algorithms, font-designs, and program settings to
321 produce prints that match the quality of the old editions we love
322 to see and love to play from.
323
324
325 @node Automated engraving
326 @unnumberedsec Automated engraving
327
328 @cindex engraving, automated
329 @cindex automated engraving
330
331 @menu
332 * Beauty contests::             
333 * Notation benchmarking::       
334 * Flexible architecture::       
335 @end menu
336
337 @node Beauty contests
338 @unnumberedsubsec Beauty contests
339
340 @node Notation benchmarking
341 @unnumberedsubsec Notation benchmarking
342
343 Bärenreiter:
344
345 @ifnotinfo
346 @iftex
347 @image{pictures/baer-sarabande,16cm}
348 @end iftex
349 @ifnottex
350 @image{pictures/baer-sarabande,,,png}
351 @end ifnottex
352 @end ifnotinfo
353 @ifinfo
354 @image{lilypond/pictures/baer-sarabande,,,,png}
355 @end ifinfo
356
357 LilyPond 1.4:
358
359 @ifnotinfo
360 @iftex
361 @image{pictures/lily14-sarabande,16cm}
362 @end iftex
363 @ifnottex
364 @image{pictures/lily14-sarabande,,,png}
365 @end ifnottex
366 @end ifnotinfo
367 @ifinfo
368 @image{lilypond/pictures/lily14-sarabande,,,,png}
369 @end ifinfo
370
371 LilyPond @version{}:
372
373 @lilypond[relative=0,staffsize=19,line-width=16\cm]
374 {
375   \clef "bass"
376   \key d \minor
377   \time 3/4
378   \mergeDifferentlyDottedOn
379   << {d8. e16 e4. d16 e} \\ {d4 a2} >>
380   <f' a, d,>4. e8 d c
381   bes g' f e16( f g a bes d,)
382   cis4. b8 a g
383   << {d'8. e16 e4. d16 e} \\ {<f, a>4 a2} >>
384 }
385 @end lilypond
386
387 [LilyPond snippet above not finished]
388
389 [a few bars of LilyPond vs. Finale can go here]
390
391 @node Flexible architecture
392 @unnumberedsubsec Flexible architecture
393
394 How do we go about implementing typography?  If craftsmen need
395 over ten years to become true masters, how could we simple hackers
396 ever write a program to take over their jobs?
397
398 The answer is: we cannot.  Typography relies on human judgment of
399 appearance, so people cannot be replaced completely.  However,
400 much of the dull work can be automated.  If LilyPond solves most
401 of the common situations correctly, this will be a huge
402 improvement over existing software.  The remaining cases can be
403 tuned by hand.  Over the course of years, the software can be
404 refined to do more and more things automatically, so manual
405 overrides are less and less necessary.
406
407 When we started, we wrote the LilyPond program entirely in the C++
408 programming language; the program's functionality was set in stone
409 by the developers.  That proved to be unsatisfactory for a number
410 of reasons:
411
412 @itemize
413
414 @item When LilyPond makes mistakes, users need to override
415 formatting decisions.  Therefore, the user must have access to the
416 formatting engine.  Hence, rules and settings cannot be fixed by
417 us at compile-time but must be accessible for users at run-time.
418
419 @item Engraving is a matter of visual judgment, and therefore a
420 matter of taste.  As knowledgeable as we are, users can disagree
421 with our personal decisions.  Therefore, the definitions of
422 typographical style must also be accessible to the user.
423
424 @item Finally, we continually refine the formatting algorithms, so
425 we need a flexible approach to rules.  The C++ language forces a
426 certain method of grouping rules that cannot readily be applied to
427 formatting music notation.
428
429 @end itemize
430
431 @cindex Scheme programming language
432
433 These problems have been addressed by integrating an interpreter
434 for the Scheme programming language and rewriting parts of
435 LilyPond in Scheme.  The current formatting architecture is built
436 around the notion of graphical objects, described by Scheme
437 variables and functions.  This architecture encompasses formatting
438 rules, typographical style and individual formatting decisions.
439 The user has direct access to most of these controls.
440
441 Scheme variables control layout decisions.  For example, many
442 graphical objects have a direction variable that encodes the
443 choice between up and down (or left and right).  Here you see two
444 chords, with accents and arpeggios.  In the first chord, the
445 graphical objects have all directions down (or left).  The second
446 chord has all directions up (right).
447
448 @lilypond[quote,ragged-right]
449 \new Score \with {
450    \override SpacingSpanner #'spacing-increment = #3
451    \override TimeSignature #'transparent = ##t
452 } \relative c' {
453    \stemDown <e g b>4_>-\arpeggio
454    \override Arpeggio #'direction = #RIGHT
455    \stemUp <e g b>4^>-\arpeggio
456 }
457 @end lilypond
458
459 @cindex score formatting
460 @cindex formatting a score
461 @cindex formatting rules
462
463 @noindent
464 The process of formatting a score consists of reading and writing
465 the variables of graphical objects.  Some variables have a preset
466 value.  For example, the thickness of many lines -- a
467 characteristic of typographical style -- is a variable with a
468 preset value.  You are free to alter this value, giving your score
469 a different typographical impression.
470
471 @lilypond[quote,ragged-right]
472 fragment = {
473    \clef bass f8 as8
474    c'4-~ c'16 as g f e16 g bes c' des'4
475 }
476 <<
477    \new Staff \fragment
478    \new Staff \with {
479       \override Beam #'beam-thickness = #0.3
480       \override Stem #'thickness = #0.5
481       \override Bar #'thickness = #3.6
482       \override Tie #'thickness = #2.2
483       \override StaffSymbol #'thickness = #3.0
484       \override Tie #'extra-offset = #'(0 .  0.3)
485       }
486       \fragment
487 >>
488 @end lilypond
489
490 Formatting rules are also preset variables: each object has
491 variables containing procedures.  These procedures perform the
492 actual formatting, and by substituting different ones, we can
493 change the appearance of objects.  In the following example, the
494 rule governing which note head objects are used to produce the
495 note head symbol is changed during the music fragment.
496
497 @lilypond[quote,ragged-right]
498 #(set-global-staff-size 30)
499
500 #(define (mc-squared grob orig current)
501   (let* ((interfaces (ly:grob-interfaces grob))
502          (pos (ly:grob-property grob 'staff-position)))
503     (if (memq 'note-head-interface interfaces)
504         (begin
505           (ly:grob-set-property! grob 'stencil
506             (grob-interpret-markup grob
507               (make-lower-markup 0.5
508                 (case pos
509                   ((-5) "m")
510                   ((-3) "c ")
511                   ((-2) (make-smaller-markup (make-bold-markup "2")))
512                   (else "bla")))))))))
513
514 \new Voice \relative c' {
515   \stemUp
516   \set autoBeaming = ##f
517   \time 2/4
518   <d f g>4
519   \once \override NoteHead #'stencil = #note-head::brew-ez-stencil
520   \once \override NoteHead #'font-size = #-7
521   \once \override NoteHead #'font-family = #'sans
522   \once \override NoteHead #'font-series = #'bold
523   <d f g>4
524   \once \override NoteHead #'style = #'cross
525   <d f g>4
526   \applyOutput #'Voice #mc-squared
527   <d f g>4
528   <<
529     { d8[ es-( fis^^ g] fis2-) }
530     \repeat unfold 5 { \applyOutput #'Voice #mc-squared s8 }
531   >>
532 }
533 @end lilypond
534
535
536 @node What symbols to engrave?
537 @unnumberedsec What symbols to engrave?
538
539 @cindex engraving
540 @cindex typography
541 @cindex engraver
542 @cindex plug-in
543
544 The formatting process decides where to place symbols.  However,
545 this can only be done once it is decided @emph{what} symbols
546 should be printed -- in other words, what notation to use.
547
548 Common music notation is a system of recording music that has
549 evolved over the past 1000 years.  The form that is now in common
550 use dates from the early Renaissance.  Although the basic form
551 (i.e., note heads on a 5-line staff) has not changed, the details
552 still evolve to express the innovations of contemporary notation.
553 Hence, common music notation encompasses some 500 years of music.
554 Its applications range from monophonic melodies to monstrous
555 counterpoints for a large orchestra.
556
557 How can we get a grip on such a seven-headed beast, and force it
558 into the confines of a computer program?  Our solution is to break
559 up the problem of notation (as opposed to engraving, i.e.,
560 typography) into digestible and programmable chunks: every type of
561 symbol is handled by a separate module, a so-called plug-in.  Each
562 plug-in is completely modular and independent, so each can be
563 developed and improved separately.  Such plug-ins are called
564 @code{engraver}s, by analogy with craftsmen who translate musical
565 ideas to graphic symbols.
566
567 In the following example, we start out with a plug-in for note
568 heads, the @code{Note_heads_engraver}.
569
570 @lilypond[quote,ragged-right]
571 \include "engraver-example.ily"
572
573 \score {
574   \topVoice
575   \layout {
576     \context {
577       \Voice
578       \remove "Stem_engraver"
579       \remove "Phrasing_slur_engraver"
580       \remove "Slur_engraver"
581       \remove "Script_engraver"
582       \remove "Beam_engraver"
583       \remove "Auto_beam_engraver"
584     }
585     \context {
586       \Staff
587       \remove "Accidental_engraver"
588       \remove "Key_engraver"
589       \remove "Clef_engraver"
590       \remove "Bar_engraver"
591       \remove "Time_signature_engraver"
592       \remove "Staff_symbol_engraver"
593       \consists "Pitch_squash_engraver"
594     }
595   }
596 }
597 @end lilypond
598
599 @noindent
600 Then a @code{Staff_symbol_engraver} adds the staff,
601
602 @lilypond[quote,ragged-right]
603 \include "engraver-example.ily"
604
605 \score {
606   \topVoice
607   \layout {
608     \context {
609       \Voice
610       \remove "Stem_engraver"
611       \remove "Phrasing_slur_engraver"
612       \remove "Slur_engraver"
613       \remove "Script_engraver"
614       \remove "Beam_engraver"
615       \remove "Auto_beam_engraver"
616     }
617     \context {
618       \Staff
619       \remove "Accidental_engraver"
620       \remove "Key_engraver"
621       \remove "Clef_engraver"
622       \remove "Bar_engraver"
623       \consists "Pitch_squash_engraver"
624       \remove "Time_signature_engraver"
625     }
626   }
627 }
628 @end lilypond
629
630 @noindent
631 the @code{Clef_engraver} defines a reference point for the staff,
632
633 @lilypond[quote,ragged-right]
634 \include "engraver-example.ily"
635
636 \score {
637   \topVoice
638   \layout {
639     \context {
640       \Voice
641       \remove "Stem_engraver"
642       \remove "Phrasing_slur_engraver"
643       \remove "Slur_engraver"
644       \remove "Script_engraver"
645       \remove "Beam_engraver"
646       \remove "Auto_beam_engraver"
647     }
648     \context {
649       \Staff
650       \remove "Accidental_engraver"
651       \remove "Key_engraver"
652       \remove "Bar_engraver"
653       \remove "Time_signature_engraver"
654     }
655   }
656 }
657 @end lilypond
658
659 @noindent
660 and the @code{Stem_engraver} adds stems.
661
662 @lilypond[quote,ragged-right]
663 \include "engraver-example.ily"
664
665 \score {
666   \topVoice
667   \layout {
668     \context {
669       \Voice
670       \remove "Phrasing_slur_engraver"
671       \remove "Slur_engraver"
672       \remove "Script_engraver"
673       \remove "Beam_engraver"
674       \remove "Auto_beam_engraver"
675     }
676     \context {
677       \Staff
678       \remove "Accidental_engraver"
679       \remove "Key_engraver"
680       \remove "Bar_engraver"
681       \remove "Time_signature_engraver"
682     }
683   }
684 }
685 @end lilypond
686
687 @noindent
688 The @code{Stem_engraver} is notified of any note head coming
689 along.  Every time one (or more, for a chord) note head is seen, a
690 stem object is created and connected to the note head.  By adding
691 engravers for beams, slurs, accents, accidentals, bar lines, time
692 signature, and key signature, we get a complete piece of notation.
693
694 @lilypond[quote,ragged-right]
695 \include "engraver-example.ily"
696 \score { \topVoice }
697 @end lilypond
698
699 @cindex polyphony
700 @cindex engraving multiple voices
701 @cindex contexts
702
703 This system works well for monophonic music, but what about
704 polyphony?  In polyphonic notation, many voices can share a staff.
705
706 @lilypond[quote,ragged-right]
707 \include "engraver-example.ily"
708 \new Staff << \topVoice \\ \botVoice >>
709 @end lilypond
710
711 In this situation, the accidentals and staff are shared, but the
712 stems, slurs, beams, etc., are private to each voice.  Hence,
713 engravers should be grouped.  The engravers for note heads, stems,
714 slurs, etc., go into a group called @q{Voice context,} while the
715 engravers for key, accidental, bar, etc., go into a group called
716 @q{Staff context.}  In the case of polyphony, a single Staff
717 context contains more than one Voice context.  Similarly, multiple
718 Staff contexts can be put into a single Score context.  The Score
719 context is the top level notation context.
720
721
722 @seealso
723 Internals Reference: @rinternals{Contexts}.
724
725
726 @lilypond[quote,ragged-right]
727 \include "engraver-example.ily"
728 \score {
729    <<
730       \new Staff << \topVoice \\ \botVoice >>
731       \new Staff << \pah \\ \hoom >>
732    >>
733 }
734 @end lilypond
735
736
737 @node Music representation
738 @unnumberedsec Music representation
739
740 @cindex syntax
741 @cindex recursive structures
742
743 Ideally, the input format for any high-level formatting system is
744 an abstract description of the content.  In this case, that would
745 be the music itself.  This poses a formidable problem: how can we
746 define what music really is? Instead of trying to find an answer,
747 we have reversed the question.  We write a program capable of
748 producing sheet music, and adjust the format to be as lean as
749 possible.  When the format can no longer be trimmed down, by
750 definition we are left with content itself.  Our program serves as
751 a formal definition of a music document.
752
753 The syntax is also the user-interface for LilyPond, hence it is
754 easy to type:
755
756 @example
757 @{
758   c'4 d'8
759 @}
760 @end example
761
762 @noindent
763 to create a quarter note on middle C (C1) and an eighth note on
764 the D above middle C (D1).
765
766 @lilypond[quote]
767 {
768   c'4 d'8
769 }
770 @end lilypond
771
772 On a microscopic scale, such syntax is easy to use.  On a larger
773 scale, syntax also needs structure.  How else can you enter
774 complex pieces like symphonies and operas?  The structure is
775 formed by the concept of music expressions: by combining small
776 fragments of music into larger ones, more complex music can be
777 expressed.  For example
778
779 @lilypond[quote,verbatim,fragment,relative=1]
780 f4
781 @end lilypond
782
783 @noindent
784 Simultaneous notes can be constructed by enclosing them with
785 @code{<<} and @code{>>}:
786
787 @example
788 <<c4 d4 e4>>
789 @end example
790
791 @lilypond[quote,fragment,relative=1]
792 \new Voice { <<c4 d4 e>> }
793 @end lilypond
794
795 @noindent
796 This expression is put in sequence by enclosing it in curly braces
797 @code{@{@tie{}@dots{}@tie{}@}}:
798
799 @example
800 @{ f4 <<c4 d4 e4>> @}
801 @end example
802
803 @lilypond[quote,relative=1,fragment]
804 { f4 <<c d e4>> }
805 @end lilypond
806
807 @noindent
808 The above is also an expression, and so it may be combined again
809 with another simultaneous expression (a half note) using
810 @code{<<}, @code{\\}, and @code{>>}:
811
812 @example
813 << g2 \\ @{ f4 <<c4 d4 e4>> @} >>
814 @end example
815
816 @lilypond[quote,fragment,relative=2]
817 \new Voice { << g2 \\ { f4 <<c d e>> } >> }
818 @end lilypond
819
820 Such recursive structures can be specified neatly and formally in
821 a context-free grammar.  The parsing code is also generated from
822 this grammar.  In other words, the syntax of LilyPond is clearly
823 and unambiguously defined.
824
825 User-interfaces and syntax are what people see and deal with most.
826 They are partly a matter of taste, and also the subject of much
827 discussion.  Although discussions on taste do have their merit,
828 they are not very productive.  In the larger picture of LilyPond,
829 the importance of input syntax is small: inventing neat syntax is
830 easy, while writing decent formatting code is much harder.  This
831 is also illustrated by the line-counts for the respective
832 components: parsing and representation take up less than 10% of
833 the source code.
834
835
836 @node Example applications
837 @unnumberedsec Example applications
838
839 @cindex simple examples
840 @cindex examples, simple
841
842 We have written LilyPond as an experiment of how to condense the
843 art of music engraving into a computer program.  Thanks to all
844 that hard work, the program can now be used to perform useful
845 tasks.  The simplest application is printing notes.
846
847 @lilypond[quote,relative=1]
848 {
849   \time 2/4
850   c4 c g'4 g a4 a g2
851 }
852 @end lilypond
853
854 @noindent
855 By adding chord names and lyrics we obtain a lead sheet.
856
857 @lilypond[quote,ragged-right]
858 <<
859    \chords { c2 c f2 c }
860    \new Staff
861    \relative c' {
862      \time 2/4
863      c4 c g' g a a g2
864    }
865    \addlyrics { twin -- kle twin -- kle lit -- tle star }
866 >>
867 @end lilypond
868
869 Polyphonic notation and piano music can also be printed.  The
870 following example combines some more exotic constructs.
871
872 @lilypond[quote]
873 \header {
874   title = "Screech and boink"
875   subtitle = "Random complex notation"
876   composer = "Han-Wen Nienhuys"
877 }
878
879 \score {
880   \context PianoStaff <<
881     \new Staff = "up" {
882       \time 4/8
883       \key c \minor
884       << {
885         \revert Stem #'direction
886         \change Staff = down
887         \set subdivideBeams = ##t
888         g16.[
889           \change Staff = up
890           c'''32
891           \change Staff = down
892           g32
893           \change Staff = up
894           c'''32
895           \change Staff = down
896           g16]
897         \change Staff = up
898         \stemUp
899         \set followVoice = ##t
900         c'''32([ b''16 a''16 gis''16 g''32)]
901       } \\ {
902         s4 \times 2/3 { d'16[ f' g'] } as'32[ b''32 e'' d'']
903       } \\ {
904         s4 \autoBeamOff d''8.. f''32
905       } \\ {
906         s4 es''4
907       } >>
908     }
909
910     \new Staff = "down" {
911       \clef bass
912       \key c \minor
913       \set subdivideBeams = ##f
914       \override Stem  #'french-beaming = ##t
915       \override Beam  #'beam-thickness = #0.3
916       \override Stem  #'thickness = #4.0
917       g'16[ b16 fis16 g16]
918       << \makeClusters {
919         as16 <as b>
920         <g b>
921         <g cis>
922       } \\ {
923         \override Staff.Arpeggio  #'arpeggio-direction =#down
924         <cis, e, gis, b, cis>4\arpeggio
925       }
926     >> }
927   >>
928   \midi {
929     \context {
930       \Score
931       tempoWholesPerMinute = #(ly:make-moment 60 8)
932     }
933   }
934   \layout {
935     \context {
936       \Staff
937       \consists Horizontal_bracket_engraver
938     }
939   }
940 }
941 @end lilypond
942
943 The fragments shown above have all been written by hand, but that
944 is not a requirement.  Since the formatting engine is mostly
945 automatic, it can serve as an output means for other programs that
946 manipulate music.  For example, it can also be used to convert
947 databases of musical fragments to images for use on websites and
948 multimedia presentations.
949
950 This manual also shows an application: the input format is text,
951 and can therefore be easily embedded in other text-based formats
952 such as @LaTeX{}, HTML, or in the case of this manual, Texinfo.
953 By means of a special program, the input fragments can be replaced
954 by music images in the resulting PDF or HTML output files.  This
955 makes it easy to mix music and text in documents.
956
957
958 TODO: add extra chapter for computer aesthetics?