]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/examples.itely
Numerous editorial and stylistic changes to manual.
[lilypond.git] / Documentation / user / examples.itely
1 @node Example templates
2 @chapter Example templates
3
4 This section of the manual contains templates with the LilyPond score
5 already set up for you.  Just add notes, run LilyPond, and enjoy
6 beautiful printed scores!
7
8 @menu
9 * Suggestions for writing LilyPond files::
10 * Single staff::
11 * Piano templates::
12 * Small ensembles::
13 * Jazz combo::
14 * Other templates::
15 @end menu
16
17 @c TODO explain \score{} ?  Maybe add a note to the tutorial?
18
19 @node Suggestions for writing LilyPond files
20 @section Suggestions for writing LilyPond files
21
22 Now you're ready to begin writing bigger LilyPond files -- not just the
23 little examples in the tutorial, but whole pieces.  But how should you
24 go about doing it?
25
26 The best answer is ``however you want to do it''.  As long as LilyPond
27 can understand your files and produces the output that you want, it
28 doesn't matter what your files look like.  That said, sometimes we
29 make mistakes when writing files.  If LilyPond can't understand your
30 files, or produces output that you don't like, how do you fix the
31 problem?
32
33 Here are a few suggestions that can help you in avoiding or fixing
34 problems:
35
36 @itemize @bullet
37 @item Include @code{\version} numbers in every file.  Note that all
38 templates contain a @code{\version "x.y.z"} string.  We
39 highly recommend that you always include the @code{\version}, no matter
40 how small your file is.  Speaking from personal experience, it's
41 quite frustrating to try to remember which version of LilyPond you were
42 using a few years ago.  @code{convert-ly} requires you to declare
43 which version of LilyPond you used.
44
45 @item Include checks:  See @ref{Bar check} and @ref{Octave check}.  If you
46 include checks every so often, then if you make a mistake, you can pinpoint
47 it quicker.  How often is ``every so often''?  It depends on the complexity
48 of the music.  For very simple music, perhaps just once or twice.  For
49 very complex music, every bar.
50
51 @item One bar per line.  If there's anything complicated, either in the music
52 itself or in the output you desire, it's often good to write only one bar
53 per line.  Saving screen space by cramming eight bars per line just isn't
54 worth it if you have to `debug' your files.
55
56 @item Comment your files, with either bar numbers (every so often) or
57 references to musical themes (``second theme in violins'', ``fourth
58 variation'').  You may not need it when you're writing the piece for
59 the first time, but if you want to go back and change something two
60 or three years later, you won't know how your file is structured if you
61 don't comment the file.
62
63 @end itemize
64
65 @node Single staff
66 @section Single staff
67 @subsection Notes only
68
69 The first example gives you a staff with notes, suitable for a solo
70 instrument or a melodic fragment.  Cut and paste this into a file,
71 add notes, and you're finished!
72
73 @lilypond[verbatim,raggedright]
74
75 \version "2.3.11"
76 melody = \relative c' {
77    \clef treble
78    \key c \major
79    \time 4/4
80
81    a4 b c d
82 }
83
84 \score{
85    \new Staff \melody
86    \paper { }
87    \midi { \tempo 4=60 }
88 }
89
90 @end lilypond
91
92 @subsection Notes and lyrics
93
94 The next example demonstrates a simple melody with lyrics.  Cut and
95 paste, add notes, then words for the lyrics.  This example turns off
96 automatic beaming, which is common for vocal parts.  If you want to use
97 automatic beaming, you'll have to change or comment out the relevant
98 line.
99
100 @lilypond[verbatim,raggedright]
101
102 \version "2.3.11"
103 melody = \relative c' {
104    \clef treble
105    \key c \major
106    \time 4/4
107
108    a4 b c d
109 }
110
111 text = \lyrics {
112    Aaa Bee Cee Dee
113 }
114
115 \score{
116    <<
117       \context Voice = one {
118          \autoBeamOff
119          \melody
120       }
121       \lyricsto "one" \new Lyrics \text
122    >>
123    \paper { }
124    \midi { \tempo 4=60 }
125 }
126
127 @end lilypond
128
129 @subsection Notes and chords
130
131 Want to prepare a lead sheet with a melody and chords?  Look no farther!
132
133 @lilypond[verbatim,raggedright]
134
135 \version "2.3.11"
136 melody =  \relative c' {
137    \clef treble
138    \key c \major
139    \time 4/4
140
141    f4 e8[ c] d4 g |
142    a2 ~ a2 |
143 }
144
145 harmonies = \chords {
146    c4:m f:min7 g:maj c:aug d2:dim b:sus
147 }
148
149 \score {
150    <<
151       \context ChordNames {
152          \set chordChanges = ##t
153          \harmonies
154       }
155    \context Staff = one \melody
156    >>
157
158    \paper{ }
159    \midi  { \tempo 4=60}
160 }
161
162 @end lilypond
163
164 @subsection Notes, lyrics, and chords.
165
166 This template allows you to prepare a song with melody, words, and chords.
167
168 @lilypond[verbatim,raggedright]
169
170 \version "2.3.11"
171 melody =  \relative c' {
172    \clef treble
173    \key c \major
174    \time 4/4
175
176    a b c d
177 }
178
179 text = \lyrics {
180    Aaa Bee Cee Dee
181 }
182
183 harmonies = \chords {
184    a2 c2
185 }
186
187 \score {
188    <<
189       \context ChordNames {
190          \set chordChanges = ##t
191          \harmonies
192       }
193    \context Voice = one {
194       \autoBeamOff
195       \melody
196    }
197    \lyricsto "one" \new Lyrics \text
198    >>
199    \paper { }
200    \midi  { \tempo 4=60}
201 }
202
203 @end lilypond
204
205 @node Piano templates
206 @section Piano templates
207 @subsection Solo piano
208
209 Here's a simple piano staff.
210
211 @lilypond[verbatim,raggedright]
212
213 \version "2.3.11"
214 upper = \relative c'' {
215    \clef treble
216    \key c \major
217    \time 4/4
218
219    a b c d
220 }
221
222 lower = \relative c {
223    \clef bass
224    \key c \major
225    \time 4/4
226
227    a2 c
228 }
229
230 \score {
231    \context PianoStaff <<
232       \set PianoStaff.instrument = "Piano  "
233       \context Staff = upper \upper
234       \context Staff = lower \lower
235    >>  
236    \paper { }  
237    \midi { \tempo 4=60 }  
238 }
239
240 @end lilypond
241
242 @subsection Piano and melody with lyrics
243
244 Here's a typical song format: one staff with the melody and lyrics, with
245 piano accompaniment underneath.
246
247 @lilypond[verbatim,raggedright]
248
249 \version "2.3.11"
250 melody =  \relative c'' {
251    \clef treble
252    \key c \major
253    \time 4/4
254
255    a b c d
256 }
257
258 text = \lyrics {
259    Aaa Bee Cee Dee
260 }
261
262 upper = \relative c'' {
263    \clef treble
264    \key c \major
265    \time 4/4
266
267    a b c d
268 }
269
270 lower = \relative c {
271    \clef bass
272    \key c \major
273    \time 4/4
274
275    a2 c
276 }
277
278 \score {
279    <<
280       \context Voice = mel {
281           \autoBeamOff
282           \melody
283       }
284       \lyricsto mel \new Lyrics \text
285
286       \context PianoStaff <<
287          \context Staff = upper \upper
288          \context Staff = lower \lower
289       >>
290    >>
291    \paper {
292       \context { \RemoveEmptyStaffContext }
293    }  
294    \midi { \tempo 4=60}
295 }
296
297 @end lilypond
298
299 @node Small ensembles
300 @section Small ensembles
301 @subsection SATB vocal score
302
303 Here's a standard four-part SATB vocal score.  With larger ensembles,
304 it's often useful to include a section which is included in all
305 parts.  For example, the time signature and key signatures are almost
306 always the same for all parts.
307
308 @lilypond[verbatim,raggedright]
309
310 \version "2.3.11"
311 global = {
312    \key c \major
313    \time 4/4
314 }
315
316 sopMusic = \relative c'' {
317    c4 c c8[( b)] c4
318 }
319 sopWords = \lyrics {
320    hi hi hi hi
321 }
322
323 altoMusic = \relative c' {
324    e4 f d e 
325 }
326 altoWords =\lyrics {
327    ha ha ha ha
328 }
329
330 tenorMusic = \relative c' {
331    g4 a f g
332 }
333 tenorWords = \lyrics {
334    hu hu hu hu
335 }
336
337 bassMusic = \relative c {
338    c4 c g c
339 }
340 bassWords = \lyrics {
341    ho ho ho ho
342 }
343
344 \score { 
345    \context ChoirStaff <<
346       \context Lyrics = sopranos { s1 }
347       \context Staff = women <<
348          \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
349          \context Voice = altos { \voiceTwo << \global \altoMusic >> }
350       >>
351       \context Lyrics = altos { s1 }
352       \context Lyrics = tenors { s1 }
353       \context Staff = men <<
354          \clef bass
355          \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
356          \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
357       >>
358       \context Lyrics = basses { s1 }
359       \context Lyrics = sopranos \lyricsto sopranos \sopWords
360       \context Lyrics = altos \lyricsto altos \altoWords
361       \context Lyrics = tenors \lyricsto tenors \tenorWords
362       \context Lyrics = basses \lyricsto basses \bassWords
363    >>
364
365    \paper {
366       \context {
367          % a little smaller so lyrics can be closer to the staff. 
368          \Staff minimumVerticalExtent = #'(-3 . 3) 
369       }
370    }
371 }
372
373 @end lilypond
374
375 @subsection String quartet
376
377 This template demonstrates a string quartet.  It also uses a @code{\global}
378 section for time and key signatures.
379
380 @lilypond[verbatim,raggedright]
381
382 \version "2.3.11"
383 global = {
384    \time 4/4
385    \key c \major
386 }
387 violinOne = \relative c''{
388    \set Staff.instrument = "Violin 1  "
389    c2 d
390    e1
391 }
392 violinTwo = \relative c''{
393    \set Staff.instrument = "Violin 2  "
394    g2 g
395    g1
396 }
397 viola = \relative c'{
398    \set Staff.instrument = "Viola  "
399    \clef alto
400    e2 d
401    c1
402 }
403 cello = \relative c'{
404    \set Staff.instrument = "Cello  "
405    \clef bass
406    c2 g
407    c,1
408 }
409 \score {
410    \new StaffGroup <<
411       \new Staff << \global \violinOne >>
412       \new Staff << \global \violinTwo >>
413       \new Staff << \global \viola >>
414       \new Staff << \global \cello >>
415    >>
416    \paper { }
417    \midi { \tempo 4=60}
418 }
419
420 @end lilypond
421
422 @node Jazz combo
423 @section Jazz combo
424
425 This is a much more complicated template, for a jazz ensemble.  Note that all
426 instruments are notated @code{\key c \major}.  This refers to the key in
427 concert pitch; LilyPond will automatically transpose the key if the music
428 is within a @code{\transpose} section.
429
430 @c TODO must clean up this jazz combo example
431 @c   - transpositions stated in names (ie "trumpet in Bb" or whatever)
432 @c   - one global section, instead of "global" (time) and "key"
433 @c   - does it need those wierd macros?  sl, nsl, etc.
434 @c   - maybe ask Amelie Zapf to clean it up, or whether I should just
435 @c     make whatever changes I feel like.
436
437 @lilypond[verbatim,raggedright]
438
439 \version "2.3.11"
440 \header {
441         title = "Song"
442         subtitle = "(tune)"
443         composer = "Me"
444         meter = "moderato"
445         piece = "Swing"
446         tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
447         texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
448 }
449
450 #(set-global-staff-size 16)
451 \include "english.ly"
452
453 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
454
455 sl = {
456     \override NoteHead  #'style = #'slash
457     \override Stem  #'transparent = ##t
458 }
459 nsl = {
460     \revert NoteHead #'style
461     \revert Stem #'transparent
462 }
463 cr = \override NoteHead  #'style = #'cross
464 ncr = \revert NoteHead #'style
465
466 %% insert chord name style stuff here.
467
468 jzchords = { } 
469
470
471 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
472
473 global =  {
474     \time 4/4
475 }
476
477 Key =  { \key c \major }
478
479 % ############ Horns ############
480 % ------ Trumpet ------
481 trpt =  \transpose c d \relative c'' {
482     \Key
483     c1 c c
484 }
485
486 trpharmony = \transpose c' d { \jzchords }
487 trumpet = {
488     \global 
489     \set Staff.instrument = #"Trumpet"
490     \clef treble
491     \context Staff <<
492         \trpt
493     >>
494 }
495
496 % ------ Alto Saxophone ------
497 alto = \transpose c a \relative c' {
498         \Key
499         c1 c c
500 }
501
502 altoharmony = \transpose c' a { \jzchords }
503 altosax = {
504         \global
505         \set Staff.instrument = #"Alto Sax"
506         \clef treble
507         \context Staff <<
508                 \alto
509         >>
510 }
511
512 % ------ Baritone Saxophone ------
513 bari = \transpose c a' \relative c {
514         \Key
515         c1 c \sl d4^"Solo" d d d \nsl
516 }
517
518 bariharmony = \transpose c' a \chords { \jzchords s1 s d2:maj e:m7 }
519 barisax = {
520         \global
521         \set Staff.instrument = #"Bari Sax"
522         \clef treble
523         \context Staff <<
524                 \bari
525         >>
526 }
527 % ------ Trombone ------
528 tbone =  \relative c {
529         \Key
530         c1 c c
531 }
532
533 tboneharmony = \chords { \jzchords }
534 trombone = {
535         \global
536         \set Staff.instrument = #"Trombone"
537         \clef bass
538         \context Staff <<
539                 \tbone
540         >>
541 }
542 % ############ Rhythm Section #############
543 % ------ Guitar ------
544 gtr =  \relative c'' {
545         \Key
546         c1 \sl b4 b b b \nsl c1
547 }
548
549 gtrharmony = \chords { \jzchords
550         s1 c2:min7+ d2:maj9
551 }
552
553 guitar = {
554         \global
555         \set Staff.instrument = #"Guitar"
556         \clef treble
557         \context Staff <<
558                 \gtr
559         >>
560 }
561
562 %% ------ Piano ------
563 rhUpper =  \relative c'' {
564         \voiceOne
565         \Key
566         c1 c c
567 }
568
569 rhLower =  \relative c' {
570         \voiceTwo
571         \Key
572         e1 e e
573 }
574
575 lhUpper =  \relative c' {
576         \voiceOne
577         \Key
578         g1 g g
579 }
580
581 lhLower =  \relative c {
582         \voiceTwo
583         \Key
584         c1 c c
585 }
586
587 PianoRH = {
588         \clef treble
589         \global
590         \set Staff.midiInstrument = "acoustic grand"
591         \context Staff <<
592                 \context Voice = one \rhUpper
593                 \context Voice = two \rhLower
594         >>
595 }
596
597 PianoLH = {
598         \clef bass
599         \global
600         \set Staff.midiInstrument = "acoustic grand"
601         \context Staff <<
602                 \context Voice = one \lhUpper
603                 \context Voice = two \lhLower
604         >>
605 }
606
607 piano = {
608         \context PianoStaff <<
609                 \set PianoStaff.instrument = #"Piano"
610                 \context Staff = upper \PianoRH
611                 \context Staff = lower \PianoLH
612         >>
613 }
614
615 % ------ Bass Guitar ------
616 bass =  \relative c {
617         \Key
618         c1 c c
619 }
620
621 bass = {
622     \global
623     \set Staff.instrument = #"Bass"
624     \clef bass
625     \context Staff <<
626         \bass
627     >>
628 }
629
630                                 % ------ Drums ------
631
632 up = \drums {
633     hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
634     hh4 <hh sn>4
635     hh4 <hh sn>4
636     hh4 <hh sn>4
637 }
638
639 down = \drums {
640     bd4 s bd s bd s bd s bd s bd s
641 }
642
643 drumContents = {
644         \global
645         <<
646                 \set DrumStaff.instrument = #"Drums"
647                 \new DrumVoice { \voiceOne \up }
648                 \new DrumVoice { \voiceTwo \down }
649         >>
650 }
651
652 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
653
654 \score {
655 <<
656         \context StaffGroup = horns <<
657                 \context Staff = trumpet \trumpet
658
659                 \context Staff = altosax \altosax
660
661                 \context ChordNames = barichords \bariharmony
662
663                 \context Staff = barisax \barisax
664
665                 \context Staff = trombone \trombone
666         >>
667
668         \context StaffGroup = rhythm <<
669                 \context ChordNames = chords \gtrharmony
670                 \context Staff = guitar \guitar
671                 \context PianoStaff = piano \piano
672                 
673                 \context Staff = bass \bass
674                 
675                 \new DrumStaff { \drumContents }
676         >>
677 >>
678         \paper {
679                 \context { \RemoveEmptyStaffContext }
680                 \context {
681                         \Score
682                         \override BarNumber #'padding = #3
683                         \override RehearsalMark #'padding = #2
684                         skipBars = ##t
685                 }
686         }
687         \midi { \tempo 4 = 75 }
688 }
689
690 @end lilypond
691
692 @node Other templates
693 @section Other templates
694 @subsection All headers
695
696 This template displays all available headers.  Some of them are only
697 used in the Mutopia project; they don't affect the printed output at
698 all.  They are used  if you want the piece to be listed with different
699 information in the Mutopia database than you wish to have printed on the
700 music.  For example, Mutopia lists the composer of the famous D major
701 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
702 "Petr Tchaikowski" on your music.
703
704 @lilypond[verbatim,raggedright]
705
706 \version "2.3.11"
707 \header {
708    dedication = "dedication"
709    title = "Title"
710    subtitle = "Subtitle"
711    subsubtitle = "Subsubtitle"
712    composer = "Composer (xxxx-yyyy)"
713    opus = "Opus 0"
714    piece = "Piece I"
715    instrument = "Instrument"
716    arranger = "Arranger"
717    poet = "Poet"
718    texttranslator = "Translator"
719    copyright = "public domain"
720
721 % These are headers used by the Mutopia Project  http://www.mutopiaproject.org/
722    mutopiatitle = ""
723    mutopiacomposer = ""
724    mutopiapoet = ""
725    mutopiainstrument = ""
726    date = "composer's dates"
727    source = "urtext "
728    maintainer = "your name here"
729    maintainerEmail = "your email here"
730    maintainerWeb = "your home page"
731    lastupdated = "2004/Aug/26"
732 }
733
734 \score {
735    \header {
736       piece = "piece1"
737       opus = "opus1"
738    }
739    { c'4 }
740 }
741
742 \score {
743    \header {
744       piece = "piece2"
745       opus = "opus2"
746    }
747    { c'4 }
748 }
749
750 @end lilypond
751
752 @subsection Gregorian template
753
754 This example demonstrates how to do modern transcriptions of Gregorian
755 music.  Gregorian music has no measure, no stems; it uses only half and
756 quarter notes, and two types of barlines, a short one indicating a rest,
757 and a second one indicating a breath mark.
758
759 @lilypond[verbatim,raggedright]
760
761 barOne = { \once \override Staff.BarLine  #'bar-size = #2
762    \bar "|" }
763 barTwo = { \once \override Staff.BarLine  #'extra-offset = #'(0 . 2)
764    \once \override Staff.BarLine  #'bar-size = #2
765    \bar "|" }
766 chant = \relative c' {
767    \set Score.timing = ##f
768    \override Staff.Stem  #'transparent = ##t
769
770    f4 a2 \barTwo
771    g4 a2 f2 \barOne
772    g4( f) f( g) a2
773 }
774 \score {
775    \chant
776    \paper{ }
777    \midi { \tempo 4=60 }
778 }
779
780 @end lilypond
781
782 @subsection Bagpipe music
783
784 Here's an example of bagpipe music.  It demonstrates a big strength of
785 LilyPond, compared to graphical score editors: in LilyPond, you can
786 very easily reuse small segments of music without writing them out
787 completely.  This template defines a large number of small segments
788 (@code{taor, grip, thrd,} etc), which can be reused easily.
789
790 TODO - replace Bagpipe template with Andrew McNabb's work?
791
792 @lilypond[verbatim,raggedright]
793
794 taor = { \grace { g32[ d' g e'] } }
795 grip = { \grace { g32[ b g ]    } }
796 thrd = { \grace { g32[ d' c']   } }
797 birl = { \grace { g32[ a g]     } }
798 gstd = { \grace { g'32[ d' g]   } }
799 fgg =  { \grace { f32[ g'32]    } }
800 dblb = { \grace { g'32[ b d']   } }
801 dblc = { \grace { g'32[ c' d']  } }
802 dble = { \grace { g'32[ e' f']  } }
803 dblf = { \grace { g'32[ f' g']  } }
804 dblg = { \grace { g'32[ f']     } }
805 dbla = { \grace { a'32[ g']     } }
806 lgg =  { \grace { g32  } }
807 lag =  { \grace { a32  } }
808 cg   = { \grace { c'32 } }
809 eg   = { \grace { e'32 } }
810 gg   = { \grace { g'32 } }
811 dg   = { \grace { d'32 } }
812 hag  = { \grace { a'32 } }
813 gefg = { \grace { g'32[ e' f']  } }
814 efg  = { \grace { e'32[ f']     } }
815 gdcg = { \grace { g'32[ d' c']  } }
816 gcdg = { \grace { g'32[ c' d']  } }
817         
818 \transpose a a' {
819     #(add-grace-property 'Voice 'Stem 'length 6)
820     \time 6/8 \partial 4
821     \tieUp
822     \slurUp
823     
824     f'4 |
825     \gg f'4 e'8 \thrd d'4. |
826     \eg a4.(a4) d'8 |
827     \gg d'4 f'8 \dble e'4. ( | \noBreak
828     e'8) d'4 \gg d'4 e'8 |
829
830     \break
831     \time 9/8
832     \dblf f'2.( f'4) d'8 |
833     \time 6/8
834     \dblg g'4 a'8 \gg a'4. |
835     \thrd d'4.( d'4) \eg a8 |
836     \time 9/8
837     \dble e'4 \lag e'8 \gg  e'16[ d'8. e'8] \gg f'4 g'8 |
838
839     \break
840     \time 6/8
841     \gg f'4 e'8 \thrd d'4. |
842     \eg a4.( a4) d'8 |
843     \dblg g'4 a'8 \gg a'4. |
844     \thrd d'4.( d'4) f'8 |
845
846     \break
847     \dblg g'4 e'8( e'8) \dblf  f'8.[ e'16] |
848     \thrd d'4.( d'4) \cg d'8 |
849     \gg c'4 e'8 \thrd d'4.( |
850     d'4.) \gdcg d'4.
851     
852 }
853
854 @end lilypond
855
856