]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/examples.itely
* ly/a4-init.ly (vsize): remove papersize init files.
[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 "2.3.16"} 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.16"
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.16"
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 = \lyricmode {
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.16"
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 = \chordmode {
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.16"
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 = \lyricmode {
180    Aaa Bee Cee Dee
181 }
182
183 harmonies = \chordmode {
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.16"
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.16"
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 = \lyricmode {
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.16"
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 = \lyricmode {
320    hi hi hi hi
321 }
322
323 altoMusic = \relative c' {
324    e4 f d e 
325 }
326 altoWords =\lyricmode {
327    ha ha ha ha
328 }
329
330 tenorMusic = \relative c' {
331    g4 a f g
332 }
333 tenorWords = \lyricmode {
334    hu hu hu hu
335 }
336
337 bassMusic = \relative c {
338    c4 c g c
339 }
340 bassWords = \lyricmode {
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.16"
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 @c FIXME: produces a warning ; key change merge.
438
439 @lilypond[verbatim,raggedright]
440
441 \version "2.3.16"
442 \header {
443         title = "Song"
444         subtitle = "(tune)"
445         composer = "Me"
446         meter = "moderato"
447         piece = "Swing"
448         tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
449         texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
450 }
451
452 #(set-global-staff-size 16)
453 \include "english.ly"
454
455 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
456
457 sl = {
458     \override NoteHead  #'style = #'slash
459     \override Stem  #'transparent = ##t
460 }
461 nsl = {
462     \revert NoteHead #'style
463     \revert Stem #'transparent
464 }
465 cr = \override NoteHead  #'style = #'cross
466 ncr = \revert NoteHead #'style
467
468 %% insert chord name style stuff here.
469
470 jzchords = { } 
471
472
473 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
474
475 global =  {
476     \time 4/4
477 }
478
479 Key =  { \key c \major }
480
481 % ############ Horns ############
482 % ------ Trumpet ------
483 trpt =  \transpose c d \relative c'' {
484     \Key
485     c1 c c
486 }
487
488 trpharmony = \transpose c' d { \jzchords }
489 trumpet = {
490     \global 
491     \set Staff.instrument = #"Trumpet"
492     \clef treble
493     \context Staff <<
494         \trpt
495     >>
496 }
497
498 % ------ Alto Saxophone ------
499 alto = \transpose c a \relative c' {
500         \Key
501         c1 c c
502 }
503
504 altoharmony = \transpose c' a { \jzchords }
505 altosax = {
506         \global
507         \set Staff.instrument = #"Alto Sax"
508         \clef treble
509         \context Staff <<
510                 \alto
511         >>
512 }
513
514 % ------ Baritone Saxophone ------
515 bari = \transpose c a' \relative c {
516         \Key
517         c1 c \sl d4^"Solo" d d d \nsl
518 }
519
520 bariharmony = \transpose c' a \chordmode { \jzchords s1 s d2:maj e:m7 }
521 barisax = {
522         \global
523         \set Staff.instrument = #"Bari Sax"
524         \clef treble
525         \context Staff <<
526                 \bari
527         >>
528 }
529 % ------ Trombone ------
530 tbone =  \relative c {
531         \Key
532         c1 c c
533 }
534
535 tboneharmony = \chordmode { \jzchords }
536 trombone = {
537         \global
538         \set Staff.instrument = #"Trombone"
539         \clef bass
540         \context Staff <<
541                 \tbone
542         >>
543 }
544 % ############ Rhythm Section #############
545 % ------ Guitar ------
546 gtr =  \relative c'' {
547         \Key
548         c1 \sl b4 b b b \nsl c1
549 }
550
551 gtrharmony = \chordmode { \jzchords
552         s1 c2:min7+ d2:maj9
553 }
554
555 guitar = {
556         \global
557         \set Staff.instrument = #"Guitar"
558         \clef treble
559         \context Staff <<
560                 \gtr
561         >>
562 }
563
564 %% ------ Piano ------
565 rhUpper =  \relative c'' {
566         \voiceOne
567         \Key
568         c1 c c
569 }
570
571 rhLower =  \relative c' {
572         \voiceTwo
573         \Key
574         e1 e e
575 }
576
577 lhUpper =  \relative c' {
578         \voiceOne
579         \Key
580         g1 g g
581 }
582
583 lhLower =  \relative c {
584         \voiceTwo
585         \Key
586         c1 c c
587 }
588
589 PianoRH = {
590         \clef treble
591         \global
592         \set Staff.midiInstrument = "acoustic grand"
593         \context Staff <<
594                 \context Voice = one \rhUpper
595                 \context Voice = two \rhLower
596         >>
597 }
598
599 PianoLH = {
600         \clef bass
601         \global
602         \set Staff.midiInstrument = "acoustic grand"
603         \context Staff <<
604                 \context Voice = one \lhUpper
605                 \context Voice = two \lhLower
606         >>
607 }
608
609 piano = {
610         \context PianoStaff <<
611                 \set PianoStaff.instrument = #"Piano"
612                 \context Staff = upper \PianoRH
613                 \context Staff = lower \PianoLH
614         >>
615 }
616
617 % ------ Bass Guitar ------
618 bass =  \relative c {
619         \Key
620         c1 c c
621 }
622
623 bass = {
624     \global
625     \set Staff.instrument = #"Bass"
626     \clef bass
627     \context Staff <<
628         \bass
629     >>
630 }
631
632                                 % ------ Drums ------
633
634 up = \drummode {
635     hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
636     hh4 <hh sn>4
637     hh4 <hh sn>4
638     hh4 <hh sn>4
639 }
640
641 down = \drummode {
642     bd4 s bd s bd s bd s bd s bd s
643 }
644
645 drumContents = {
646         \global
647         <<
648                 \set DrumStaff.instrument = #"Drums"
649                 \new DrumVoice { \voiceOne \up }
650                 \new DrumVoice { \voiceTwo \down }
651         >>
652 }
653
654 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
655
656 \score {
657 <<
658         \context StaffGroup = horns <<
659                 \context Staff = trumpet \trumpet
660
661                 \context Staff = altosax \altosax
662
663                 \context ChordNames = barichords \bariharmony
664
665                 \context Staff = barisax \barisax
666
667                 \context Staff = trombone \trombone
668         >>
669
670         \context StaffGroup = rhythm <<
671                 \context ChordNames = chords \gtrharmony
672                 \context Staff = guitar \guitar
673                 \context PianoStaff = piano \piano
674                 
675                 \context Staff = bass \bass
676                 
677                 \new DrumStaff { \drumContents }
678         >>
679 >>
680         \paper {
681                 \context { \RemoveEmptyStaffContext }
682                 \context {
683                         \Score
684                         \override BarNumber #'padding = #3
685                         \override RehearsalMark #'padding = #2
686                         skipBars = ##t
687                 }
688         }
689         \midi { \tempo 4 = 75 }
690 }
691
692 @end lilypond
693
694 @node Other templates
695 @section Other templates
696 @subsection All headers
697
698 This template displays all available headers.  Some of them are only
699 used in the Mutopia project; they don't affect the printed output at
700 all.  They are used  if you want the piece to be listed with different
701 information in the Mutopia database than you wish to have printed on the
702 music.  For example, Mutopia lists the composer of the famous D major
703 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
704 "Petr Tchaikowski" on your music.
705
706 @lilypond[verbatim,raggedright]
707
708 \version "2.3.16"
709 \header {
710    dedication = "dedication"
711    title = "Title"
712    subtitle = "Subtitle"
713    subsubtitle = "Subsubtitle"
714    composer = "Composer (xxxx-yyyy)"
715    opus = "Opus 0"
716    piece = "Piece I"
717    instrument = "Instrument"
718    arranger = "Arranger"
719    poet = "Poet"
720    texttranslator = "Translator"
721    copyright = "public domain"
722
723 % These are headers used by the Mutopia Project  http://www.mutopiaproject.org/
724    mutopiatitle = ""
725    mutopiacomposer = ""
726    mutopiapoet = ""
727    mutopiainstrument = ""
728    date = "composer's dates"
729    source = "urtext "
730    maintainer = "your name here"
731    maintainerEmail = "your email here"
732    maintainerWeb = "your home page"
733    lastupdated = "2004/Aug/26"
734 }
735
736 \score {
737    \header {
738       piece = "piece1"
739       opus = "opus1"
740    }
741    { c'4 }
742 }
743
744 \score {
745    \header {
746       piece = "piece2"
747       opus = "opus2"
748    }
749    { c'4 }
750 }
751
752 @end lilypond
753
754 @subsection Gregorian template
755
756 This example demonstrates how to do modern transcriptions of Gregorian
757 music.  Gregorian music has no measure, no stems; it uses only half and
758 quarter notes, and two types of barlines, a short one indicating a rest,
759 and a second one indicating a breath mark.
760
761 @lilypond[verbatim,raggedright]
762
763 barOne = { \once \override Staff.BarLine  #'bar-size = #2
764    \bar "|" }
765 barTwo = { \once \override Staff.BarLine  #'extra-offset = #'(0 . 2)
766    \once \override Staff.BarLine  #'bar-size = #2
767    \bar "|" }
768 chant = \relative c' {
769    \set Score.timing = ##f
770    \override Staff.Stem  #'transparent = ##t
771
772    f4 a2 \barTwo
773    g4 a2 f2 \barOne
774    g4( f) f( g) a2
775 }
776 \score {
777    \chant
778    \paper{ }
779    \midi { \tempo 4=60 }
780 }
781
782 @end lilypond
783
784 @subsection Bagpipe music
785
786 Here's an example of bagpipe music.  It demonstrates a big strength of
787 LilyPond, compared to graphical score editors: in LilyPond, you can
788 very easily reuse small segments of music without writing them out
789 completely.  This template defines a large number of small segments
790 (@code{taor, grip, thrd,} etc), which can be reused easily.
791
792 TODO - replace Bagpipe template with Andrew McNabb's work?
793
794 @lilypond[verbatim,raggedright]
795
796 taor = { \grace { g32[ d' g e'] } }
797 grip = { \grace { g32[ b g ]    } }
798 thrd = { \grace { g32[ d' c']   } }
799 birl = { \grace { g32[ a g]     } }
800 gstd = { \grace { g'32[ d' g]   } }
801 fgg =  { \grace { f32[ g'32]    } }
802 dblb = { \grace { g'32[ b d']   } }
803 dblc = { \grace { g'32[ c' d']  } }
804 dble = { \grace { g'32[ e' f']  } }
805 dblf = { \grace { g'32[ f' g']  } }
806 dblg = { \grace { g'32[ f']     } }
807 dbla = { \grace { a'32[ g']     } }
808 lgg =  { \grace { g32  } }
809 lag =  { \grace { a32  } }
810 cg   = { \grace { c'32 } }
811 eg   = { \grace { e'32 } }
812 gg   = { \grace { g'32 } }
813 dg   = { \grace { d'32 } }
814 hag  = { \grace { a'32 } }
815 gefg = { \grace { g'32[ e' f']  } }
816 efg  = { \grace { e'32[ f']     } }
817 gdcg = { \grace { g'32[ d' c']  } }
818 gcdg = { \grace { g'32[ c' d']  } }
819         
820 \transpose a a' {
821     #(add-grace-property 'Voice 'Stem 'length 6)
822     \time 6/8 \partial 4
823     \tieUp
824     \slurUp
825     
826     f'4 |
827     \gg f'4 e'8 \thrd d'4. |
828     \eg a4.(a4) d'8 |
829     \gg d'4 f'8 \dble e'4. ( | \noBreak
830     e'8) d'4 \gg d'4 e'8 |
831
832     \break
833     \time 9/8
834     \dblf f'2.( f'4) d'8 |
835     \time 6/8
836     \dblg g'4 a'8 \gg a'4. |
837     \thrd d'4.( d'4) \eg a8 |
838     \time 9/8
839     \dble e'4 \lag e'8 \gg  e'16[ d'8. e'8] \gg f'4 g'8 |
840
841     \break
842     \time 6/8
843     \gg f'4 e'8 \thrd d'4. |
844     \eg a4.( a4) d'8 |
845     \dblg g'4 a'8 \gg a'4. |
846     \thrd d'4.( d'4) f'8 |
847
848     \break
849     \dblg g'4 e'8( e'8) \dblf  f'8.[ e'16] |
850     \thrd d'4.( d'4) \cg d'8 |
851     \gg c'4 e'8 \thrd d'4.( |
852     d'4.) \gdcg d'4.
853     
854 }
855
856 @end lilypond
857
858