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!
9 @c bad node name for ancient notation to avoid confict
11 * Suggestions for writing LilyPond files::
16 * Ancient notation templates::
21 @c TODO explain \score{} ? Maybe add a note to the tutorial?
23 @node Suggestions for writing LilyPond files
24 @section Suggestions for writing LilyPond files
26 Now you're ready to begin writing bigger LilyPond files -- not just the
27 little examples in the tutorial, but whole pieces. But how should you
30 The best answer is ``however you want to do it''. As long as LilyPond
31 can understand your files and produces the output that you want, it
32 doesn't matter what your files look like. That said, sometimes we
33 make mistakes when writing files. If LilyPond can't understand your
34 files, or produces output that you don't like, how do you fix the
37 Here are a few suggestions that can help you in avoiding or fixing
41 @item Include @code{\version} numbers in every file. Note that all
42 templates contain a @code{\version "2.3.22"} string. We
43 highly recommend that you always include the @code{\version}, no matter
44 how small your file is. Speaking from personal experience, it's
45 quite frustrating to try to remember which version of LilyPond you were
46 using a few years ago. @code{convert-ly} requires you to declare
47 which version of LilyPond you used.
49 @item Include checks: See @ref{Bar check} and @ref{Octave check}. If you
50 include checks every so often, then if you make a mistake, you can pinpoint
51 it quicker. How often is ``every so often''? It depends on the complexity
52 of the music. For very simple music, perhaps just once or twice. For
53 very complex music, every bar.
55 @item One bar per line. If there is anything complicated, either in the music
56 itself or in the output you desire, it's often good to write only one bar
57 per line. Saving screen space by cramming eight bars per line just isn't
58 worth it if you have to `debug' your files.
60 @item Comment your files, with either bar numbers (every so often) or
61 references to musical themes (``second theme in violins'', ``fourth
62 variation''). You may not need it when you're writing the piece for
63 the first time, but if you want to go back and change something two
64 or three years later, you won't know how your file is structured if you
65 don't comment the file.
71 @subsection Notes only
73 The first example gives you a staff with notes, suitable for a solo
74 instrument or a melodic fragment. Cut and paste this into a file,
75 add notes, and you're finished!
77 @lilypond[verbatim,raggedright]
80 melody = \relative c' {
96 @subsection Notes and lyrics
98 The next example demonstrates a simple melody with lyrics. Cut and
99 paste, add notes, then words for the lyrics. This example turns off
100 automatic beaming, which is common for vocal parts. If you want to use
101 automatic beaming, you'll have to change or comment out the relevant
104 @lilypond[verbatim,raggedright]
107 melody = \relative c' {
121 \context Voice = one {
125 \lyricsto "one" \new Lyrics \text
128 \midi { \tempo 4=60 }
133 @subsection Notes and chords
135 Want to prepare a lead sheet with a melody and chords? Look no further!
137 @lilypond[verbatim,raggedright]
140 melody = \relative c' {
149 harmonies = \chordmode {
150 c4:m f:min7 g:maj c:aug d2:dim b:sus
155 \context ChordNames {
156 \set chordChanges = ##t
159 \context Staff = one \melody
168 @subsection Notes, lyrics, and chords.
170 This template allows you to prepare a song with melody, words, and chords.
172 @lilypond[verbatim,raggedright]
175 melody = \relative c' {
187 harmonies = \chordmode {
193 \context ChordNames {
194 \set chordChanges = ##t
197 \context Voice = one {
201 \lyricsto "one" \new Lyrics \text
209 @node Piano templates
210 @section Piano templates
211 @subsection Solo piano
213 Here is a simple piano staff.
215 @lilypond[verbatim,raggedright]
218 upper = \relative c'' {
226 lower = \relative c {
235 \context PianoStaff <<
236 \set PianoStaff.instrument = "Piano "
237 \context Staff = upper \upper
238 \context Staff = lower \lower
241 \midi { \tempo 4=60 }
246 @subsection Piano and melody with lyrics
248 Here is a typical song format: one staff with the melody and lyrics, with
249 piano accompaniment underneath.
251 @lilypond[verbatim,raggedright]
254 melody = \relative c'' {
266 upper = \relative c'' {
274 lower = \relative c {
284 \context Voice = mel {
288 \lyricsto mel \new Lyrics \text
290 \context PianoStaff <<
291 \context Staff = upper \upper
292 \context Staff = lower \lower
296 \context { \RemoveEmptyStaffContext }
304 @subsection Piano centered dynamics
306 Many piano scores have the dynamics centered between the two
307 staffs. This requires a bit of tweaking to implement, but
308 since the template is right here, you don't have to do the
311 @lilypond[verbatim,raggedright]
314 upper = \relative c'' {
322 lower = \relative c {
336 s2\sustainDown s2\sustainUp
340 \context PianoStaff <<
341 \context Staff=upper \upper
342 \context Dynamics=dynamics \dynamics
343 \context Staff=lower <<
347 \context Dynamics=pedal \pedal
351 \type "Engraver_group_engraver"
353 \alias Voice % So that \cresc works, for example.
354 \consists "Output_property_engraver"
356 minimumVerticalExtent = #'(-1 . 1)
357 pedalSustainStrings = #'("Ped." "*Ped." "*")
358 pedalUnaCordaStrings = #'("una corda" "" "tre corde")
360 \consists "Piano_pedal_engraver"
361 \consists "Script_engraver"
362 \consists "Dynamic_engraver"
363 \consists "Text_engraver"
365 \override TextScript #'font-size = #2
366 \override TextScript #'font-shape = #'italic
367 \override DynamicText #'extra-offset = #'(0 . 2.5)
368 \override Hairpin #'extra-offset = #'(0 . 2.5)
370 \consists "Skip_event_swallow_translator"
372 \consists "Axis_group_engraver"
377 \override VerticalAlignment #'forced-distance = #7
382 \type "Performer_group_performer"
384 \consists "Piano_pedal_performer"
385 \consists "Span_dynamic_performer"
386 \consists "Dynamic_performer"
397 @node Small ensembles
398 @section Small ensembles
399 @subsection String quartet
401 This template demonstrates a string quartet. It also uses a @code{\global}
402 section for time and key signatures.
404 @lilypond[verbatim,raggedright]
411 violinOne = \relative c''{
412 \set Staff.instrument = "Violin 1 "
416 violinTwo = \relative c''{
417 \set Staff.instrument = "Violin 2 "
421 viola = \relative c'{
422 \set Staff.instrument = "Viola "
427 cello = \relative c'{
428 \set Staff.instrument = "Cello "
435 \new Staff << \global \violinOne >>
436 \new Staff << \global \violinTwo >>
437 \new Staff << \global \viola >>
438 \new Staff << \global \cello >>
447 @node Vocal ensembles
448 @section Vocal ensembles
450 @subsection SATB vocal score
452 Here is a standard four-part SATB vocal score. With larger ensembles,
453 it's often useful to include a section which is included in all
454 parts. For example, the time signature and key signatures are almost
455 always the same for all parts.
457 @lilypond[verbatim,raggedright]
465 sopMusic = \relative c'' {
468 sopWords = \lyricmode {
472 altoMusic = \relative c' {
475 altoWords =\lyricmode {
479 tenorMusic = \relative c' {
482 tenorWords = \lyricmode {
486 bassMusic = \relative c {
489 bassWords = \lyricmode {
494 \context ChoirStaff <<
495 \context Lyrics = sopranos { s1 }
496 \context Staff = women <<
497 \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
498 \context Voice = altos { \voiceTwo << \global \altoMusic >> }
500 \context Lyrics = altos { s1 }
501 \context Lyrics = tenors { s1 }
502 \context Staff = men <<
504 \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
505 \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
507 \context Lyrics = basses { s1 }
508 \context Lyrics = sopranos \lyricsto sopranos \sopWords
509 \context Lyrics = altos \lyricsto altos \altoWords
510 \context Lyrics = tenors \lyricsto tenors \tenorWords
511 \context Lyrics = basses \lyricsto basses \bassWords
516 % a little smaller so lyrics can be closer to the staff.
517 \Staff minimumVerticalExtent = #'(-3 . 3)
525 @c bad node name to avoid node name confict
526 @node Ancient notation templates
527 @section Ancient notation templates
529 @subsection Transcription of mensural music
531 When transcribing mensural music, an incipit at the beginning of the
532 piece is useful to indicate the original key and tempo. While today
533 musicians are used to bar lines in order to faster recognize rhythmic
534 patterns, bar lines where not yet invented during the period of
535 mensural music; in fact, the meter often changed after every few
536 notes. As a compromise, bar lines are often printed between the
537 staves rather than on the staves.
539 @lilypond[verbatim,raggedright]
545 \once \override Score.SystemStartBracket #'transparent = ##t
548 \once \override Staff.TimeSignature #'style = #'neomensural
549 \override Voice.NoteHead #'style = #'neomensural
550 \override Voice.Rest #'style = #'neomensural
551 \set Staff.printKeyCancellation = ##f
552 \cadenzaOn % turn off bar lines
554 \once \override Staff.BarLine #'transparent = ##f
556 \skip 1*1 % need this extra \skip such that clef change comes
561 \cadenzaOff % turn bar lines on again
562 \once \override Staff.Clef #'full-size-change = ##t
563 \set Staff.forceClef = ##t
566 \override Voice.NoteHead #'style = #'default
567 \override Voice.Rest #'style = #'default
569 % FIXME: setting printKeyCancellation back to #t must not
570 % occur in the first bar after the incipit. Dto. for forceClef.
571 % Therefore, we need an extra \skip.
573 \set Staff.printKeyCancellation = ##t
574 \set Staff.forceClef = ##f
578 % last bar contains a brevis (i.e. spans 2 bars);
579 % therefore do not draw this particular bar
584 % let finis bar go through all staves
585 \override Staff.BarLine #'transparent = ##f
593 \set Staff.instrument = "Discantus "
596 \clef "neomensural-c1"
598 \skip 1*8 % eight bars
608 \once \override NoteHead #'transparent = ##t c'1 |
613 discantusLyrics = \lyricmode {
629 \set Staff.instrument = "Altus "
632 \clef "neomensural-c3"
635 \skip 1*7 % seven bars
640 r2 g2. e4 fis g | % two bars
642 fis g4.( fis16 e fis4) |
644 \once \override NoteHead #'transparent = ##t g1 |
649 altusLyrics = \lyricmode {
654 Ju -- bi -- la -- te | % two bars
663 \set Staff.instrument = "Tenor "
666 \clef "neomensural-c4"
679 r2 d'2. d'4 b e' | % two bars
680 \once \override NoteHead #'transparent = ##t e'1 |
685 tenorLyrics = \lyricmode {
690 Ju -- bi -- la -- te | % two bars
697 \set Staff.instrument = "Bassus "
701 r\maxima % eight bars
712 \once \override NoteHead #'transparent = ##t e1 |
717 bassusLyrics = \lyricmode {
728 \context StaffGroup = choirStaff <<
729 \context Voice = discantusNotes << \global \discantusNotes >>
730 \context Lyrics = discantusLyrics \lyricsto discantusNotes { \discantusLyrics }
731 \context Voice = altusNotes << \global \altusNotes >>
732 \context Lyrics = altusLyrics \lyricsto altusNotes { \altusLyrics }
733 \context Voice = tenorNotes << \global \tenorNotes >>
734 \context Lyrics = tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
735 \context Voice = bassusNotes << \global \bassusNotes >>
736 \context Lyrics = bassusLyrics \lyricsto bassusNotes { \bassusLyrics }
741 \override BarLine #'transparent = ##t
742 \remove "System_start_delimiter_engraver"
746 \override Slur #'transparent = ##t
758 This is a much more complicated template, for a jazz ensemble. Note that all
759 instruments are notated @code{\key c \major}. This refers to the key in
760 concert pitch; LilyPond will automatically transpose the key if the music
761 is within a @code{\transpose} section.
763 @c TODO must clean up this jazz combo example
764 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
765 @c - one global section, instead of "global" (time) and "key"
766 @c - does it need those wierd macros? sl, nsl, etc.
767 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
768 @c make whatever changes I feel like.
770 @c FIXME: produces a warning ; key change merge.
772 @lilypond[verbatim,raggedright]
781 tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
782 texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
785 #(set-global-staff-size 16)
786 \include "english.ly"
788 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
791 \override NoteHead #'style = #'slash
792 \override Stem #'transparent = ##t
795 \revert NoteHead #'style
796 \revert Stem #'transparent
798 cr = \override NoteHead #'style = #'cross
799 ncr = \revert NoteHead #'style
801 %% insert chord name style stuff here.
806 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
812 Key = { \key c \major }
814 % ############ Horns ############
815 % ------ Trumpet ------
816 trpt = \transpose c d \relative c'' {
821 trpharmony = \transpose c' d { \jzchords }
824 \set Staff.instrument = #"Trumpet"
831 % ------ Alto Saxophone ------
832 alto = \transpose c a \relative c' {
837 altoharmony = \transpose c' a { \jzchords }
840 \set Staff.instrument = #"Alto Sax"
847 % ------ Baritone Saxophone ------
848 bari = \transpose c a' \relative c {
850 c1 c \sl d4^"Solo" d d d \nsl
853 bariharmony = \transpose c' a \chordmode { \jzchords s1 s d2:maj e:m7 }
856 \set Staff.instrument = #"Bari Sax"
862 % ------ Trombone ------
863 tbone = \relative c {
868 tboneharmony = \chordmode { \jzchords }
871 \set Staff.instrument = #"Trombone"
877 % ############ Rhythm Section #############
878 % ------ Guitar ------
879 gtr = \relative c'' {
881 c1 \sl b4 b b b \nsl c1
884 gtrharmony = \chordmode { \jzchords
890 \set Staff.instrument = #"Guitar"
897 %% ------ Piano ------
898 rhUpper = \relative c'' {
904 rhLower = \relative c' {
910 lhUpper = \relative c' {
916 lhLower = \relative c {
925 \set Staff.midiInstrument = "acoustic grand"
927 \context Voice = one \rhUpper
928 \context Voice = two \rhLower
935 \set Staff.midiInstrument = "acoustic grand"
937 \context Voice = one \lhUpper
938 \context Voice = two \lhLower
943 \context PianoStaff <<
944 \set PianoStaff.instrument = #"Piano"
945 \context Staff = upper \PianoRH
946 \context Staff = lower \PianoLH
950 % ------ Bass Guitar ------
958 \set Staff.instrument = #"Bass"
965 % ------ Drums ------
968 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
975 bd4 s bd s bd s bd s bd s bd s
981 \set DrumStaff.instrument = #"Drums"
982 \new DrumVoice { \voiceOne \up }
983 \new DrumVoice { \voiceTwo \down }
987 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
991 \context StaffGroup = horns <<
992 \context Staff = trumpet \trumpet
994 \context Staff = altosax \altosax
996 \context ChordNames = barichords \bariharmony
998 \context Staff = barisax \barisax
1000 \context Staff = trombone \trombone
1003 \context StaffGroup = rhythm <<
1004 \context ChordNames = chords \gtrharmony
1005 \context Staff = guitar \guitar
1006 \context PianoStaff = piano \piano
1008 \context Staff = bass \bass
1010 \new DrumStaff { \drumContents }
1014 \context { \RemoveEmptyStaffContext }
1017 \override BarNumber #'padding = #3
1018 \override RehearsalMark #'padding = #2
1022 \midi { \tempo 4 = 75 }
1027 @node Other templates
1028 @section Other templates
1029 @subsection All headers
1031 This template displays all available headers. Some of them are only
1032 used in the Mutopia project; they don't affect the printed output at
1033 all. They are used if you want the piece to be listed with different
1034 information in the Mutopia database than you wish to have printed on the
1035 music. For example, Mutopia lists the composer of the famous D major
1036 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
1037 "Petr Tchaikowski" on your music.
1039 @lilypond[verbatim,raggedright]
1043 dedication = "dedication"
1045 subtitle = "Subtitle"
1046 subsubtitle = "Subsubtitle"
1047 composer = "Composer (xxxx-yyyy)"
1050 instrument = "Instrument"
1051 arranger = "Arranger"
1053 texttranslator = "Translator"
1054 copyright = "public domain"
1056 % These are headers used by the Mutopia Project http://www.mutopiaproject.org/
1058 mutopiacomposer = ""
1060 mutopiainstrument = ""
1061 date = "composer's dates"
1063 maintainer = "your name here"
1064 maintainerEmail = "your email here"
1065 maintainerWeb = "your home page"
1066 lastupdated = "2004/Aug/26"
1087 @subsection Gregorian template
1089 This example demonstrates how to do modern transcriptions of Gregorian
1090 music. Gregorian music has no measure, no stems; it uses only half and
1091 quarter notes, and two types of barlines, a short one indicating a rest,
1092 and a second one indicating a breath mark.
1094 @lilypond[verbatim,raggedright]
1096 barOne = { \once \override Staff.BarLine #'bar-size = #2
1098 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
1099 \once \override Staff.BarLine #'bar-size = #2
1101 chant = \relative c' {
1102 \set Score.timing = ##f
1103 \override Staff.Stem #'transparent = ##t
1112 \midi { \tempo 4=60 }
1117 @subsection Bagpipe music
1119 Here is an example of bagpipe music. It demonstrates a big strength of
1120 LilyPond, compared to graphical score editors: in LilyPond, you can
1121 very easily reuse small segments of music without writing them out
1122 completely. This template defines a large number of small segments
1123 (@code{taor, grip, thrd,} etc), which can be reused easily.
1125 TODO - replace Bagpipe template with Andrew McNabb's work?
1127 @lilypond[verbatim,raggedright]
1129 taor = { \grace { g32[ d' g e'] } }
1130 grip = { \grace { g32[ b g ] } }
1131 thrd = { \grace { g32[ d' c'] } }
1132 birl = { \grace { g32[ a g] } }
1133 gstd = { \grace { g'32[ d' g] } }
1134 fgg = { \grace { f32[ g'32] } }
1135 dblb = { \grace { g'32[ b d'] } }
1136 dblc = { \grace { g'32[ c' d'] } }
1137 dble = { \grace { g'32[ e' f'] } }
1138 dblf = { \grace { g'32[ f' g'] } }
1139 dblg = { \grace { g'32[ f'] } }
1140 dbla = { \grace { a'32[ g'] } }
1141 lgg = { \grace { g32 } }
1142 lag = { \grace { a32 } }
1143 cg = { \grace { c'32 } }
1144 eg = { \grace { e'32 } }
1145 gg = { \grace { g'32 } }
1146 dg = { \grace { d'32 } }
1147 hag = { \grace { a'32 } }
1148 gefg = { \grace { g'32[ e' f'] } }
1149 efg = { \grace { e'32[ f'] } }
1150 gdcg = { \grace { g'32[ d' c'] } }
1151 gcdg = { \grace { g'32[ c' d'] } }
1154 #(add-grace-property 'Voice 'Stem 'length 6)
1155 \time 6/8 \partial 4
1160 \gg f'4 e'8 \thrd d'4. |
1162 \gg d'4 f'8 \dble e'4. ( | \noBreak
1163 e'8) d'4 \gg d'4 e'8 |
1167 \dblf f'2.( f'4) d'8 |
1169 \dblg g'4 a'8 \gg a'4. |
1170 \thrd d'4.( d'4) \eg a8 |
1172 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1176 \gg f'4 e'8 \thrd d'4. |
1178 \dblg g'4 a'8 \gg a'4. |
1179 \thrd d'4.( d'4) f'8 |
1182 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1183 \thrd d'4.( d'4) \cg d'8 |
1184 \gg c'4 e'8 \thrd d'4.( |