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