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::
19 * Lilypond-book templates::
22 @c TODO explain \score{} ? Maybe add a note to the tutorial?
24 @node Suggestions for writing LilyPond files
25 @section Suggestions for writing LilyPond files
27 Now you're ready to begin writing bigger LilyPond files -- not just the
28 little examples in the tutorial, but whole pieces. But how should you
31 The best answer is ``however you want to do it''. As long as LilyPond
32 can understand your files and produces the output that you want, it
33 doesn't matter what your files look like. That said, sometimes we
34 make mistakes when writing files. If LilyPond can't understand your
35 files, or produces output that you don't like, how do you fix the
38 Here are a few suggestions that can help you in avoiding or fixing
42 @item Include @code{\version} numbers in every file. Note that all
43 templates contain a @code{\version "2.3.22"} string. We
44 highly recommend that you always include the @code{\version}, no matter
45 how small your file is. Speaking from personal experience, it's
46 quite frustrating to try to remember which version of LilyPond you were
47 using a few years ago. @code{convert-ly} requires you to declare
48 which version of LilyPond you used.
50 @item Include checks: See @ref{Bar check} and @ref{Octave check}. If you
51 include checks every so often, then if you make a mistake, you can pinpoint
52 it quicker. How often is ``every so often''? It depends on the complexity
53 of the music. For very simple music, perhaps just once or twice. For
54 very complex music, every bar.
56 @item One bar per line. If there is anything complicated, either in the music
57 itself or in the output you desire, it's often good to write only one bar
58 per line. Saving screen space by cramming eight bars per line just isn't
59 worth it if you have to `debug' your files.
61 @item Comment your files, with either bar numbers (every so often) or
62 references to musical themes (``second theme in violins'', ``fourth
63 variation''). You may not need it when you're writing the piece for
64 the first time, but if you want to go back and change something two
65 or three years later, you won't know how your file is structured if you
66 don't comment the file.
72 @subsection Notes only
74 The first example gives you a staff with notes, suitable for a solo
75 instrument or a melodic fragment. Cut and paste this into a file,
76 add notes, and you're finished!
78 @lilypond[verbatim,raggedright]
81 melody = \relative c' {
97 @subsection Notes and lyrics
99 The next example demonstrates a simple melody with lyrics. Cut and
100 paste, add notes, then words for the lyrics. This example turns off
101 automatic beaming, which is common for vocal parts. If you want to use
102 automatic beaming, you'll have to change or comment out the relevant
105 @lilypond[verbatim,raggedright]
108 melody = \relative c' {
122 \context Voice = one {
126 \lyricsto "one" \new Lyrics \text
129 \midi { \tempo 4=60 }
134 @subsection Notes and chords
136 Want to prepare a lead sheet with a melody and chords? Look no further!
138 @lilypond[verbatim,raggedright]
141 melody = \relative c' {
150 harmonies = \chordmode {
151 c4:m f:min7 g:maj c:aug d2:dim b:sus
156 \context ChordNames {
157 \set chordChanges = ##t
160 \context Staff = one \melody
169 @subsection Notes, lyrics, and chords.
171 This template allows you to prepare a song with melody, words, and chords.
173 @lilypond[verbatim,raggedright]
176 melody = \relative c' {
188 harmonies = \chordmode {
194 \context ChordNames {
195 \set chordChanges = ##t
198 \context Voice = one {
202 \lyricsto "one" \new Lyrics \text
210 @node Piano templates
211 @section Piano templates
212 @subsection Solo piano
214 Here is a simple piano staff.
216 @lilypond[verbatim,raggedright]
219 upper = \relative c'' {
227 lower = \relative c {
236 \context PianoStaff <<
237 \set PianoStaff.instrument = "Piano "
238 \context Staff = upper \upper
239 \context Staff = lower \lower
242 \midi { \tempo 4=60 }
247 @subsection Piano and melody with lyrics
249 Here is a typical song format: one staff with the melody and lyrics, with
250 piano accompaniment underneath.
252 @lilypond[verbatim,raggedright]
255 melody = \relative c'' {
267 upper = \relative c'' {
275 lower = \relative c {
285 \context Voice = mel {
289 \lyricsto mel \new Lyrics \text
291 \context PianoStaff <<
292 \context Staff = upper \upper
293 \context Staff = lower \lower
297 \context { \RemoveEmptyStaffContext }
299 \midi { \tempo 4=60 }
305 @subsection Piano centered lyrics
307 Instead of having a full staff for the melody and lyrics, you can place
308 the lyrics between the piano staff (and omit the separate melody staff).
310 @lilypond[verbatim,raggedright]
313 upper = \relative c'' {
321 lower = \relative c {
334 \context GrandStaff <<
335 \context Staff = upper {
336 \context Voice = singer \upper }
337 \lyricsto "singer" \new Lyrics \text
338 \context Staff = lower <<
344 \context { \GrandStaff \accepts "Lyrics" }
345 \context { \Lyrics \consists "Bar_engraver" }
347 \midi { \tempo 4=60 }
352 @subsection Piano centered dynamics
354 Many piano scores have the dynamics centered between the two
355 staffs. This requires a bit of tweaking to implement, but
356 since the template is right here, you don't have to do the
359 @lilypond[verbatim,raggedright]
362 upper = \relative c'' {
370 lower = \relative c {
384 s2\sustainDown s2\sustainUp
388 \context PianoStaff <<
389 \context Staff=upper \upper
390 \context Dynamics=dynamics \dynamics
391 \context Staff=lower <<
395 \context Dynamics=pedal \pedal
399 \type "Engraver_group_engraver"
401 \alias Voice % So that \cresc works, for example.
402 \consists "Output_property_engraver"
404 minimumVerticalExtent = #'(-1 . 1)
405 pedalSustainStrings = #'("Ped." "*Ped." "*")
406 pedalUnaCordaStrings = #'("una corda" "" "tre corde")
408 \consists "Piano_pedal_engraver"
409 \consists "Script_engraver"
410 \consists "Dynamic_engraver"
411 \consists "Text_engraver"
413 \override TextScript #'font-size = #2
414 \override TextScript #'font-shape = #'italic
415 \override DynamicText #'extra-offset = #'(0 . 2.5)
416 \override Hairpin #'extra-offset = #'(0 . 2.5)
418 \consists "Skip_event_swallow_translator"
420 \consists "Axis_group_engraver"
425 \override VerticalAlignment #'forced-distance = #7
430 \type "Performer_group_performer"
432 \consists "Piano_pedal_performer"
433 \consists "Span_dynamic_performer"
434 \consists "Dynamic_performer"
445 @node Small ensembles
446 @section Small ensembles
447 @subsection String quartet
449 This template demonstrates a string quartet. It also uses a @code{\global}
450 section for time and key signatures.
452 @lilypond[verbatim,raggedright]
459 violinOne = \relative c''{
460 \set Staff.instrument = "Violin 1 "
464 violinTwo = \relative c''{
465 \set Staff.instrument = "Violin 2 "
469 viola = \relative c'{
470 \set Staff.instrument = "Viola "
475 cello = \relative c'{
476 \set Staff.instrument = "Cello "
483 \new Staff << \global \violinOne >>
484 \new Staff << \global \violinTwo >>
485 \new Staff << \global \viola >>
486 \new Staff << \global \cello >>
495 @node Vocal ensembles
496 @section Vocal ensembles
498 @subsection SATB vocal score
500 Here is a standard four-part SATB vocal score. With larger ensembles,
501 it's often useful to include a section which is included in all
502 parts. For example, the time signature and key signatures are almost
503 always the same for all parts.
505 @lilypond[verbatim,raggedright]
513 sopMusic = \relative c'' {
516 sopWords = \lyricmode {
520 altoMusic = \relative c' {
523 altoWords =\lyricmode {
527 tenorMusic = \relative c' {
530 tenorWords = \lyricmode {
534 bassMusic = \relative c {
537 bassWords = \lyricmode {
542 \context ChoirStaff <<
543 \context Lyrics = sopranos { s1 }
544 \context Staff = women <<
545 \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
546 \context Voice = altos { \voiceTwo << \global \altoMusic >> }
548 \context Lyrics = altos { s1 }
549 \context Lyrics = tenors { s1 }
550 \context Staff = men <<
552 \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
553 \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
555 \context Lyrics = basses { s1 }
556 \context Lyrics = sopranos \lyricsto sopranos \sopWords
557 \context Lyrics = altos \lyricsto altos \altoWords
558 \context Lyrics = tenors \lyricsto tenors \tenorWords
559 \context Lyrics = basses \lyricsto basses \bassWords
564 % a little smaller so lyrics can be closer to the staff.
565 \Staff minimumVerticalExtent = #'(-3 . 3)
573 @c bad node name to avoid node name confict
574 @node Ancient notation templates
575 @section Ancient notation templates
577 @subsection Transcription of mensural music
579 When transcribing mensural music, an incipit at the beginning of the
580 piece is useful to indicate the original key and tempo. While today
581 musicians are used to bar lines in order to faster recognize rhythmic
582 patterns, bar lines where not yet invented during the period of
583 mensural music; in fact, the meter often changed after every few
584 notes. As a compromise, bar lines are often printed between the
585 staves rather than on the staves.
587 @lilypond[verbatim,raggedright]
593 \once \override Score.SystemStartBracket #'transparent = ##t
596 \once \override Staff.TimeSignature #'style = #'neomensural
597 \override Voice.NoteHead #'style = #'neomensural
598 \override Voice.Rest #'style = #'neomensural
599 \set Staff.printKeyCancellation = ##f
600 \cadenzaOn % turn off bar lines
602 \once \override Staff.BarLine #'transparent = ##f
604 \skip 1*1 % need this extra \skip such that clef change comes
609 \cadenzaOff % turn bar lines on again
610 \once \override Staff.Clef #'full-size-change = ##t
611 \set Staff.forceClef = ##t
614 \override Voice.NoteHead #'style = #'default
615 \override Voice.Rest #'style = #'default
617 % FIXME: setting printKeyCancellation back to #t must not
618 % occur in the first bar after the incipit. Dto. for forceClef.
619 % Therefore, we need an extra \skip.
621 \set Staff.printKeyCancellation = ##t
622 \set Staff.forceClef = ##f
626 % last bar contains a brevis (i.e. spans 2 bars);
627 % therefore do not draw this particular bar
632 % let finis bar go through all staves
633 \override Staff.BarLine #'transparent = ##f
641 \set Staff.instrument = "Discantus "
644 \clef "neomensural-c1"
646 \skip 1*8 % eight bars
656 \once \override NoteHead #'transparent = ##t c'1 |
661 discantusLyrics = \lyricmode {
677 \set Staff.instrument = "Altus "
680 \clef "neomensural-c3"
683 \skip 1*7 % seven bars
688 r2 g2. e4 fis g | % two bars
690 fis g4.( fis16 e fis4) |
692 \once \override NoteHead #'transparent = ##t g1 |
697 altusLyrics = \lyricmode {
702 Ju -- bi -- la -- te | % two bars
711 \set Staff.instrument = "Tenor "
714 \clef "neomensural-c4"
727 r2 d'2. d'4 b e' | % two bars
728 \once \override NoteHead #'transparent = ##t e'1 |
733 tenorLyrics = \lyricmode {
738 Ju -- bi -- la -- te | % two bars
745 \set Staff.instrument = "Bassus "
749 r\maxima % eight bars
760 \once \override NoteHead #'transparent = ##t e1 |
765 bassusLyrics = \lyricmode {
776 \context StaffGroup = choirStaff <<
777 \context Voice = discantusNotes << \global \discantusNotes >>
778 \context Lyrics = discantusLyrics \lyricsto discantusNotes { \discantusLyrics }
779 \context Voice = altusNotes << \global \altusNotes >>
780 \context Lyrics = altusLyrics \lyricsto altusNotes { \altusLyrics }
781 \context Voice = tenorNotes << \global \tenorNotes >>
782 \context Lyrics = tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
783 \context Voice = bassusNotes << \global \bassusNotes >>
784 \context Lyrics = bassusLyrics \lyricsto bassusNotes { \bassusLyrics }
789 \override BarLine #'transparent = ##t
790 \remove "System_start_delimiter_engraver"
794 \override Slur #'transparent = ##t
806 This is a much more complicated template, for a jazz ensemble. Note that all
807 instruments are notated @code{\key c \major}. This refers to the key in
808 concert pitch; LilyPond will automatically transpose the key if the music
809 is within a @code{\transpose} section.
811 @c TODO must clean up this jazz combo example
812 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
813 @c - one global section, instead of "global" (time) and "key"
814 @c - does it need those wierd macros? sl, nsl, etc.
815 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
816 @c make whatever changes I feel like.
818 @c FIXME: produces a warning ; key change merge.
820 @lilypond[verbatim,raggedright]
829 tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
830 texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
833 #(set-global-staff-size 16)
834 \include "english.ly"
836 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
839 \override NoteHead #'style = #'slash
840 \override Stem #'transparent = ##t
843 \revert NoteHead #'style
844 \revert Stem #'transparent
846 cr = \override NoteHead #'style = #'cross
847 ncr = \revert NoteHead #'style
849 %% insert chord name style stuff here.
854 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
860 Key = { \key c \major }
862 % ############ Horns ############
863 % ------ Trumpet ------
864 trpt = \transpose c d \relative c'' {
869 trpharmony = \transpose c' d { \jzchords }
872 \set Staff.instrument = #"Trumpet"
879 % ------ Alto Saxophone ------
880 alto = \transpose c a \relative c' {
885 altoharmony = \transpose c' a { \jzchords }
888 \set Staff.instrument = #"Alto Sax"
895 % ------ Baritone Saxophone ------
896 bari = \transpose c a' \relative c {
898 c1 c \sl d4^"Solo" d d d \nsl
901 bariharmony = \transpose c' a \chordmode { \jzchords s1 s d2:maj e:m7 }
904 \set Staff.instrument = #"Bari Sax"
910 % ------ Trombone ------
911 tbone = \relative c {
916 tboneharmony = \chordmode { \jzchords }
919 \set Staff.instrument = #"Trombone"
925 % ############ Rhythm Section #############
926 % ------ Guitar ------
927 gtr = \relative c'' {
929 c1 \sl b4 b b b \nsl c1
932 gtrharmony = \chordmode { \jzchords
938 \set Staff.instrument = #"Guitar"
945 %% ------ Piano ------
946 rhUpper = \relative c'' {
952 rhLower = \relative c' {
958 lhUpper = \relative c' {
964 lhLower = \relative c {
973 \set Staff.midiInstrument = "acoustic grand"
975 \context Voice = one \rhUpper
976 \context Voice = two \rhLower
983 \set Staff.midiInstrument = "acoustic grand"
985 \context Voice = one \lhUpper
986 \context Voice = two \lhLower
991 \context PianoStaff <<
992 \set PianoStaff.instrument = #"Piano"
993 \context Staff = upper \PianoRH
994 \context Staff = lower \PianoLH
998 % ------ Bass Guitar ------
1006 \set Staff.instrument = #"Bass"
1013 % ------ Drums ------
1016 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
1023 bd4 s bd s bd s bd s bd s bd s
1029 \set DrumStaff.instrument = #"Drums"
1030 \new DrumVoice { \voiceOne \up }
1031 \new DrumVoice { \voiceTwo \down }
1035 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
1039 \context StaffGroup = horns <<
1040 \context Staff = trumpet \trumpet
1042 \context Staff = altosax \altosax
1044 \context ChordNames = barichords \bariharmony
1046 \context Staff = barisax \barisax
1048 \context Staff = trombone \trombone
1051 \context StaffGroup = rhythm <<
1052 \context ChordNames = chords \gtrharmony
1053 \context Staff = guitar \guitar
1054 \context PianoStaff = piano \piano
1056 \context Staff = bass \bass
1058 \new DrumStaff { \drumContents }
1062 \context { \RemoveEmptyStaffContext }
1065 \override BarNumber #'padding = #3
1066 \override RehearsalMark #'padding = #2
1070 \midi { \tempo 4 = 75 }
1075 @node Other templates
1076 @section Other templates
1077 @subsection All headers
1079 This template displays all available headers. Some of them are only
1080 used in the Mutopia project; they don't affect the printed output at
1081 all. They are used if you want the piece to be listed with different
1082 information in the Mutopia database than you wish to have printed on the
1083 music. For example, Mutopia lists the composer of the famous D major
1084 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
1085 "Petr Tchaikowski" on your music.
1087 @lilypond[verbatim,raggedright]
1091 dedication = "dedication"
1093 subtitle = "Subtitle"
1094 subsubtitle = "Subsubtitle"
1095 composer = "Composer (xxxx-yyyy)"
1098 instrument = "Instrument"
1099 arranger = "Arranger"
1101 texttranslator = "Translator"
1102 copyright = "public domain"
1104 % These are headers used by the Mutopia Project http://www.mutopiaproject.org/
1106 mutopiacomposer = ""
1108 mutopiainstrument = ""
1109 date = "composer's dates"
1111 maintainer = "your name here"
1112 maintainerEmail = "your email here"
1113 maintainerWeb = "your home page"
1114 lastupdated = "2004/Aug/26"
1135 @subsection Gregorian template
1137 This example demonstrates how to do modern transcriptions of Gregorian
1138 music. Gregorian music has no measure, no stems; it uses only half and
1139 quarter notes, and two types of barlines, a short one indicating a rest,
1140 and a second one indicating a breath mark.
1142 @lilypond[verbatim,raggedright]
1144 barOne = { \once \override Staff.BarLine #'bar-size = #2
1146 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
1147 \once \override Staff.BarLine #'bar-size = #2
1149 chant = \relative c' {
1150 \set Score.timing = ##f
1151 \override Staff.Stem #'transparent = ##t
1160 \midi { \tempo 4=60 }
1165 @subsection Bagpipe music
1167 Here is an example of bagpipe music. It demonstrates a big strength of
1168 LilyPond, compared to graphical score editors: in LilyPond, you can
1169 very easily reuse small segments of music without writing them out
1170 completely. This template defines a large number of small segments
1171 (@code{taor, grip, thrd,} etc), which can be reused easily.
1173 TODO - replace Bagpipe template with Andrew McNabb's work?
1175 @lilypond[verbatim,raggedright]
1177 taor = { \grace { g32[ d' g e'] } }
1178 grip = { \grace { g32[ b g ] } }
1179 thrd = { \grace { g32[ d' c'] } }
1180 birl = { \grace { g32[ a g] } }
1181 gstd = { \grace { g'32[ d' g] } }
1182 fgg = { \grace { f32[ g'32] } }
1183 dblb = { \grace { g'32[ b d'] } }
1184 dblc = { \grace { g'32[ c' d'] } }
1185 dble = { \grace { g'32[ e' f'] } }
1186 dblf = { \grace { g'32[ f' g'] } }
1187 dblg = { \grace { g'32[ f'] } }
1188 dbla = { \grace { a'32[ g'] } }
1189 lgg = { \grace { g32 } }
1190 lag = { \grace { a32 } }
1191 cg = { \grace { c'32 } }
1192 eg = { \grace { e'32 } }
1193 gg = { \grace { g'32 } }
1194 dg = { \grace { d'32 } }
1195 hag = { \grace { a'32 } }
1196 gefg = { \grace { g'32[ e' f'] } }
1197 efg = { \grace { e'32[ f'] } }
1198 gdcg = { \grace { g'32[ d' c'] } }
1199 gcdg = { \grace { g'32[ c' d'] } }
1202 #(add-grace-property 'Voice 'Stem 'length 6)
1203 \time 6/8 \partial 4
1208 \gg f'4 e'8 \thrd d'4. |
1210 \gg d'4 f'8 \dble e'4. ( | \noBreak
1211 e'8) d'4 \gg d'4 e'8 |
1215 \dblf f'2.( f'4) d'8 |
1217 \dblg g'4 a'8 \gg a'4. |
1218 \thrd d'4.( d'4) \eg a8 |
1220 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1224 \gg f'4 e'8 \thrd d'4. |
1226 \dblg g'4 a'8 \gg a'4. |
1227 \thrd d'4.( d'4) f'8 |
1230 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1231 \thrd d'4.( d'4) \cg d'8 |
1232 \gg c'4 e'8 \thrd d'4.( |
1240 @node Lilypond-book templates
1241 @section Lilypond-book templates
1243 These templates are for use with @code{lilypond-book}. If you're not familiar
1244 with this program, please refer to @ref{Integrating text and music}.
1248 You can include LilyPond fragments in a LaTeX document.
1251 \documentclass[]@{article@}
1274 You can include LilyPond fragments in texinfo; in fact, this entire manual
1275 is written in texinfo.
1283 @@lilypond[verbatim,fragment,raggedright]
1289 @@lilypond[verbatim,fragment,raggedright]