2 @node Example templates
3 @chapter Example templates
5 This section of the manual contains templates with the LilyPond score
6 already set up for you. Just add notes, run LilyPond, and enjoy
7 beautiful printed scores!
10 * Suggestions for writing LilyPond files::
18 @c TODO explain \score{} ? Maybe add a note to the tutorial?
20 @node Suggestions for writing LilyPond files
21 @section Suggestions for writing LilyPond files
23 Now you're ready to begin writing bigger LilyPond files -- not just the
24 little examples in the tutorial, but whole pieces. But how should you
27 The best answer is ``however you want to do it''. As long as LilyPond
28 can understand your files and produces the output that you want, it
29 doesn't matter what your files look like. That said, sometimes we
30 make mistakes when writing files. If LilyPond can't understand your
31 files, or produces output that you don't like, how do you fix the
34 Here are a few suggestions that can help you in avoiding or fixing
38 @item Include @code{\version} numbers in every file. Note that all
39 templates contain a @code{\version "2.3.16"} string. We
40 highly recommend that you always include the @code{\version}, no matter
41 how small your file is. Speaking from personal experience, it's
42 quite frustrating to try to remember which version of LilyPond you were
43 using a few years ago. @code{convert-ly} requires you to declare
44 which version of LilyPond you used.
46 @item Include checks: See @ref{Bar check} and @ref{Octave check}. If you
47 include checks every so often, then if you make a mistake, you can pinpoint
48 it quicker. How often is ``every so often''? It depends on the complexity
49 of the music. For very simple music, perhaps just once or twice. For
50 very complex music, every bar.
52 @item One bar per line. If there is anything complicated, either in the music
53 itself or in the output you desire, it's often good to write only one bar
54 per line. Saving screen space by cramming eight bars per line just isn't
55 worth it if you have to `debug' your files.
57 @item Comment your files, with either bar numbers (every so often) or
58 references to musical themes (``second theme in violins'', ``fourth
59 variation''). You may not need it when you're writing the piece for
60 the first time, but if you want to go back and change something two
61 or three years later, you won't know how your file is structured if you
62 don't comment the file.
68 @subsection Notes only
70 The first example gives you a staff with notes, suitable for a solo
71 instrument or a melodic fragment. Cut and paste this into a file,
72 add notes, and you're finished!
74 @lilypond[verbatim,raggedright]
77 melody = \relative c' {
93 @subsection Notes and lyrics
95 The next example demonstrates a simple melody with lyrics. Cut and
96 paste, add notes, then words for the lyrics. This example turns off
97 automatic beaming, which is common for vocal parts. If you want to use
98 automatic beaming, you'll have to change or comment out the relevant
101 @lilypond[verbatim,raggedright]
104 melody = \relative c' {
118 \context Voice = one {
122 \lyricsto "one" \new Lyrics \text
125 \midi { \tempo 4=60 }
130 @subsection Notes and chords
132 Want to prepare a lead sheet with a melody and chords? Look no further!
134 @lilypond[verbatim,raggedright]
137 melody = \relative c' {
146 harmonies = \chordmode {
147 c4:m f:min7 g:maj c:aug d2:dim b:sus
152 \context ChordNames {
153 \set chordChanges = ##t
156 \context Staff = one \melody
165 @subsection Notes, lyrics, and chords.
167 This template allows you to prepare a song with melody, words, and chords.
169 @lilypond[verbatim,raggedright]
172 melody = \relative c' {
184 harmonies = \chordmode {
190 \context ChordNames {
191 \set chordChanges = ##t
194 \context Voice = one {
198 \lyricsto "one" \new Lyrics \text
206 @node Piano templates
207 @section Piano templates
208 @subsection Solo piano
210 Here is a simple piano staff.
212 @lilypond[verbatim,raggedright]
215 upper = \relative c'' {
223 lower = \relative c {
232 \context PianoStaff <<
233 \set PianoStaff.instrument = "Piano "
234 \context Staff = upper \upper
235 \context Staff = lower \lower
238 \midi { \tempo 4=60 }
243 @subsection Piano and melody with lyrics
245 Here is a typical song format: one staff with the melody and lyrics, with
246 piano accompaniment underneath.
248 @lilypond[verbatim,raggedright]
251 melody = \relative c'' {
263 upper = \relative c'' {
271 lower = \relative c {
281 \context Voice = mel {
285 \lyricsto mel \new Lyrics \text
287 \context PianoStaff <<
288 \context Staff = upper \upper
289 \context Staff = lower \lower
293 \context { \RemoveEmptyStaffContext }
300 @node Small ensembles
301 @section Small ensembles
302 @subsection SATB vocal score
304 Here is a standard four-part SATB vocal score. With larger ensembles,
305 it's often useful to include a section which is included in all
306 parts. For example, the time signature and key signatures are almost
307 always the same for all parts.
309 @lilypond[verbatim,raggedright]
317 sopMusic = \relative c'' {
320 sopWords = \lyricmode {
324 altoMusic = \relative c' {
327 altoWords =\lyricmode {
331 tenorMusic = \relative c' {
334 tenorWords = \lyricmode {
338 bassMusic = \relative c {
341 bassWords = \lyricmode {
346 \context ChoirStaff <<
347 \context Lyrics = sopranos { s1 }
348 \context Staff = women <<
349 \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
350 \context Voice = altos { \voiceTwo << \global \altoMusic >> }
352 \context Lyrics = altos { s1 }
353 \context Lyrics = tenors { s1 }
354 \context Staff = men <<
356 \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
357 \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
359 \context Lyrics = basses { s1 }
360 \context Lyrics = sopranos \lyricsto sopranos \sopWords
361 \context Lyrics = altos \lyricsto altos \altoWords
362 \context Lyrics = tenors \lyricsto tenors \tenorWords
363 \context Lyrics = basses \lyricsto basses \bassWords
368 % a little smaller so lyrics can be closer to the staff.
369 \Staff minimumVerticalExtent = #'(-3 . 3)
376 @subsection Transcription of mensural music
378 When transcribing mensural music, an incipit at the beginning of the
379 piece is useful to indicate the original key and tempo. While today
380 musicians are used to bar lines in order to faster recognize rhythmic
381 patterns, bar lines where not yet invented during the period of
382 mensural music; in fact, the meter often changed after every few
383 notes. As a compromise, bar lines are often printed between the
384 staves rather than on the staves.
386 @lilypond[verbatim,raggedright]
392 \once \override Score.SystemStartBracket #'transparent = ##t
395 \once \override Staff.TimeSignature #'style = #'neomensural
396 \override Voice.NoteHead #'style = #'neomensural
397 \override Voice.Rest #'style = #'neomensural
398 \set Staff.printKeyCancellation = ##f
399 \cadenzaOn % turn off bar lines
401 \once \override Staff.BarLine #'transparent = ##f
403 \skip 1*1 % need this extra \skip such that clef change comes
408 \cadenzaOff % turn bar lines on again
409 \once \override Staff.Clef #'full-size-change = ##t
410 \set Staff.forceClef = ##t
413 \override Voice.NoteHead #'style = #'default
414 \override Voice.Rest #'style = #'default
416 % FIXME: setting printKeyCancellation back to #t must not
417 % occur in the first bar after the incipit. Dto. for forceClef.
418 % Therefore, we need an extra \skip.
420 \set Staff.printKeyCancellation = ##t
421 \set Staff.forceClef = ##f
425 % last bar contains a brevis (i.e. spans 2 bars);
426 % therefore do not draw this particular bar
431 % let finis bar go through all staves
432 \override Staff.BarLine #'transparent = ##f
440 \set Staff.instrument = "Discantus "
443 \clef "neomensural-c1"
445 \skip 1*8 % eight bars
455 \once \override NoteHead #'transparent = ##t c'1 |
460 discantusLyrics = \lyricmode {
476 \set Staff.instrument = "Altus "
479 \clef "neomensural-c3"
482 \skip 1*7 % seven bars
487 r2 g2. e4 fis g | % two bars
489 fis g4.( fis16 e fis4) |
491 \once \override NoteHead #'transparent = ##t g1 |
496 altusLyrics = \lyricmode {
501 Ju -- bi -- la -- te | % two bars
510 \set Staff.instrument = "Tenor "
513 \clef "neomensural-c4"
526 r2 d'2. d'4 b e' | % two bars
527 \once \override NoteHead #'transparent = ##t e'1 |
532 tenorLyrics = \lyricmode {
537 Ju -- bi -- la -- te | % two bars
544 \set Staff.instrument = "Bassus "
548 r\maxima % eight bars
559 \once \override NoteHead #'transparent = ##t e1 |
564 bassusLyrics = \lyricmode {
575 \context StaffGroup = choirStaff <<
576 \context Voice = discantusNotes << \global \discantusNotes >>
577 \context Lyrics = discantusLyrics \lyricsto discantusNotes { \discantusLyrics }
578 \context Voice = altusNotes << \global \altusNotes >>
579 \context Lyrics = altusLyrics \lyricsto altusNotes { \altusLyrics }
580 \context Voice = tenorNotes << \global \tenorNotes >>
581 \context Lyrics = tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
582 \context Voice = bassusNotes << \global \bassusNotes >>
583 \context Lyrics = bassusLyrics \lyricsto bassusNotes { \bassusLyrics }
588 \override BarLine #'transparent = ##t
589 \remove "System_start_delimiter_engraver"
593 \override Slur #'transparent = ##t
603 @subsection String quartet
605 This template demonstrates a string quartet. It also uses a @code{\global}
606 section for time and key signatures.
608 @lilypond[verbatim,raggedright]
615 violinOne = \relative c''{
616 \set Staff.instrument = "Violin 1 "
620 violinTwo = \relative c''{
621 \set Staff.instrument = "Violin 2 "
625 viola = \relative c'{
626 \set Staff.instrument = "Viola "
631 cello = \relative c'{
632 \set Staff.instrument = "Cello "
639 \new Staff << \global \violinOne >>
640 \new Staff << \global \violinTwo >>
641 \new Staff << \global \viola >>
642 \new Staff << \global \cello >>
653 This is a much more complicated template, for a jazz ensemble. Note that all
654 instruments are notated @code{\key c \major}. This refers to the key in
655 concert pitch; LilyPond will automatically transpose the key if the music
656 is within a @code{\transpose} section.
658 @c TODO must clean up this jazz combo example
659 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
660 @c - one global section, instead of "global" (time) and "key"
661 @c - does it need those wierd macros? sl, nsl, etc.
662 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
663 @c make whatever changes I feel like.
665 @c FIXME: produces a warning ; key change merge.
667 @lilypond[verbatim,raggedright]
676 tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
677 texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
680 #(set-global-staff-size 16)
681 \include "english.ly"
683 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
686 \override NoteHead #'style = #'slash
687 \override Stem #'transparent = ##t
690 \revert NoteHead #'style
691 \revert Stem #'transparent
693 cr = \override NoteHead #'style = #'cross
694 ncr = \revert NoteHead #'style
696 %% insert chord name style stuff here.
701 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
707 Key = { \key c \major }
709 % ############ Horns ############
710 % ------ Trumpet ------
711 trpt = \transpose c d \relative c'' {
716 trpharmony = \transpose c' d { \jzchords }
719 \set Staff.instrument = #"Trumpet"
726 % ------ Alto Saxophone ------
727 alto = \transpose c a \relative c' {
732 altoharmony = \transpose c' a { \jzchords }
735 \set Staff.instrument = #"Alto Sax"
742 % ------ Baritone Saxophone ------
743 bari = \transpose c a' \relative c {
745 c1 c \sl d4^"Solo" d d d \nsl
748 bariharmony = \transpose c' a \chordmode { \jzchords s1 s d2:maj e:m7 }
751 \set Staff.instrument = #"Bari Sax"
757 % ------ Trombone ------
758 tbone = \relative c {
763 tboneharmony = \chordmode { \jzchords }
766 \set Staff.instrument = #"Trombone"
772 % ############ Rhythm Section #############
773 % ------ Guitar ------
774 gtr = \relative c'' {
776 c1 \sl b4 b b b \nsl c1
779 gtrharmony = \chordmode { \jzchords
785 \set Staff.instrument = #"Guitar"
792 %% ------ Piano ------
793 rhUpper = \relative c'' {
799 rhLower = \relative c' {
805 lhUpper = \relative c' {
811 lhLower = \relative c {
820 \set Staff.midiInstrument = "acoustic grand"
822 \context Voice = one \rhUpper
823 \context Voice = two \rhLower
830 \set Staff.midiInstrument = "acoustic grand"
832 \context Voice = one \lhUpper
833 \context Voice = two \lhLower
838 \context PianoStaff <<
839 \set PianoStaff.instrument = #"Piano"
840 \context Staff = upper \PianoRH
841 \context Staff = lower \PianoLH
845 % ------ Bass Guitar ------
853 \set Staff.instrument = #"Bass"
860 % ------ Drums ------
863 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
870 bd4 s bd s bd s bd s bd s bd s
876 \set DrumStaff.instrument = #"Drums"
877 \new DrumVoice { \voiceOne \up }
878 \new DrumVoice { \voiceTwo \down }
882 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
886 \context StaffGroup = horns <<
887 \context Staff = trumpet \trumpet
889 \context Staff = altosax \altosax
891 \context ChordNames = barichords \bariharmony
893 \context Staff = barisax \barisax
895 \context Staff = trombone \trombone
898 \context StaffGroup = rhythm <<
899 \context ChordNames = chords \gtrharmony
900 \context Staff = guitar \guitar
901 \context PianoStaff = piano \piano
903 \context Staff = bass \bass
905 \new DrumStaff { \drumContents }
909 \context { \RemoveEmptyStaffContext }
912 \override BarNumber #'padding = #3
913 \override RehearsalMark #'padding = #2
917 \midi { \tempo 4 = 75 }
922 @node Other templates
923 @section Other templates
924 @subsection All headers
926 This template displays all available headers. Some of them are only
927 used in the Mutopia project; they don't affect the printed output at
928 all. They are used if you want the piece to be listed with different
929 information in the Mutopia database than you wish to have printed on the
930 music. For example, Mutopia lists the composer of the famous D major
931 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
932 "Petr Tchaikowski" on your music.
934 @lilypond[verbatim,raggedright]
938 dedication = "dedication"
940 subtitle = "Subtitle"
941 subsubtitle = "Subsubtitle"
942 composer = "Composer (xxxx-yyyy)"
945 instrument = "Instrument"
946 arranger = "Arranger"
948 texttranslator = "Translator"
949 copyright = "public domain"
951 % These are headers used by the Mutopia Project http://www.mutopiaproject.org/
955 mutopiainstrument = ""
956 date = "composer's dates"
958 maintainer = "your name here"
959 maintainerEmail = "your email here"
960 maintainerWeb = "your home page"
961 lastupdated = "2004/Aug/26"
982 @subsection Gregorian template
984 This example demonstrates how to do modern transcriptions of Gregorian
985 music. Gregorian music has no measure, no stems; it uses only half and
986 quarter notes, and two types of barlines, a short one indicating a rest,
987 and a second one indicating a breath mark.
989 @lilypond[verbatim,raggedright]
991 barOne = { \once \override Staff.BarLine #'bar-size = #2
993 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
994 \once \override Staff.BarLine #'bar-size = #2
996 chant = \relative c' {
997 \set Score.timing = ##f
998 \override Staff.Stem #'transparent = ##t
1007 \midi { \tempo 4=60 }
1012 @subsection Bagpipe music
1014 Here is an example of bagpipe music. It demonstrates a big strength of
1015 LilyPond, compared to graphical score editors: in LilyPond, you can
1016 very easily reuse small segments of music without writing them out
1017 completely. This template defines a large number of small segments
1018 (@code{taor, grip, thrd,} etc), which can be reused easily.
1020 TODO - replace Bagpipe template with Andrew McNabb's work?
1022 @lilypond[verbatim,raggedright]
1024 taor = { \grace { g32[ d' g e'] } }
1025 grip = { \grace { g32[ b g ] } }
1026 thrd = { \grace { g32[ d' c'] } }
1027 birl = { \grace { g32[ a g] } }
1028 gstd = { \grace { g'32[ d' g] } }
1029 fgg = { \grace { f32[ g'32] } }
1030 dblb = { \grace { g'32[ b d'] } }
1031 dblc = { \grace { g'32[ c' d'] } }
1032 dble = { \grace { g'32[ e' f'] } }
1033 dblf = { \grace { g'32[ f' g'] } }
1034 dblg = { \grace { g'32[ f'] } }
1035 dbla = { \grace { a'32[ g'] } }
1036 lgg = { \grace { g32 } }
1037 lag = { \grace { a32 } }
1038 cg = { \grace { c'32 } }
1039 eg = { \grace { e'32 } }
1040 gg = { \grace { g'32 } }
1041 dg = { \grace { d'32 } }
1042 hag = { \grace { a'32 } }
1043 gefg = { \grace { g'32[ e' f'] } }
1044 efg = { \grace { e'32[ f'] } }
1045 gdcg = { \grace { g'32[ d' c'] } }
1046 gcdg = { \grace { g'32[ c' d'] } }
1049 #(add-grace-property 'Voice 'Stem 'length 6)
1050 \time 6/8 \partial 4
1055 \gg f'4 e'8 \thrd d'4. |
1057 \gg d'4 f'8 \dble e'4. ( | \noBreak
1058 e'8) d'4 \gg d'4 e'8 |
1062 \dblf f'2.( f'4) d'8 |
1064 \dblg g'4 a'8 \gg a'4. |
1065 \thrd d'4.( d'4) \eg a8 |
1067 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1071 \gg f'4 e'8 \thrd d'4. |
1073 \dblg g'4 a'8 \gg a'4. |
1074 \thrd d'4.( d'4) f'8 |
1077 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1078 \thrd d'4.( d'4) \cg d'8 |
1079 \gg c'4 e'8 \thrd d'4.( |