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