1 @c -*- coding: latin-1; mode: texinfo; -*-
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 larger 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 to avoid or fix
42 @item Include @code{\version} numbers in every file. Note that all
43 templates contain a @code{\version "2.4.0"} 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[quote,verbatim,raggedright]
80 melody = \relative c' {
95 @subsection Notes and lyrics
97 The next example demonstrates a simple melody with lyrics. Cut and
98 paste, add notes, then words for the lyrics. This example turns off
99 automatic beaming, which is common for vocal parts. If you want to use
100 automatic beaming, you'll have to change or comment out the relevant
103 @lilypond[quote,verbatim,raggedright]
105 melody = \relative c' {
119 \context Voice = one {
123 \lyricsto "one" \new Lyrics \text
126 \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[quote,verbatim,raggedright]
136 melody = \relative c' {
145 harmonies = \chordmode {
146 c4:m f:min7 g:maj c:aug d2:dim b:sus
151 \context ChordNames {
152 \set chordChanges = ##t
155 \context Staff = one \melody
163 @subsection Notes, lyrics, and chords.
165 This template allows you to prepare a song with melody, words, and chords.
167 @lilypond[quote,verbatim,raggedright]
169 melody = \relative c' {
181 harmonies = \chordmode {
187 \context ChordNames {
188 \set chordChanges = ##t
191 \context Voice = one {
195 \lyricsto "one" \new Lyrics \text
198 \midi { \tempo 4=60 }
202 @node Piano templates
203 @section Piano templates
204 @subsection Solo piano
206 Here is a simple piano staff.
208 @lilypond[quote,verbatim,raggedright]
210 upper = \relative c'' {
218 lower = \relative c {
227 \context PianoStaff <<
228 \set PianoStaff.instrument = "Piano "
229 \context Staff = upper \upper
230 \context Staff = lower \lower
233 \midi { \tempo 4=60 }
237 @subsection Piano and melody with lyrics
239 Here is a typical song format: one staff with the melody and lyrics, with
240 piano accompaniment underneath.
242 @lilypond[quote,verbatim,raggedright]
244 melody = \relative c'' {
256 upper = \relative c'' {
264 lower = \relative c {
274 \context Voice = mel {
278 \lyricsto mel \new Lyrics \text
280 \context PianoStaff <<
281 \context Staff = upper \upper
282 \context Staff = lower \lower
286 \context { \RemoveEmptyStaffContext }
288 \midi { \tempo 4=60 }
293 @subsection Piano centered lyrics
295 Instead of having a full staff for the melody and lyrics, you can place
296 the lyrics between the piano staff (and omit the separate melody staff).
298 @lilypond[quote,verbatim,raggedright]
300 upper = \relative c'' {
308 lower = \relative c {
321 \context GrandStaff <<
322 \context Staff = upper {
323 \context Voice = singer \upper }
324 \lyricsto "singer" \new Lyrics \text
325 \context Staff = lower <<
331 \context { \GrandStaff \accepts "Lyrics" }
332 \context { \Lyrics \consists "Bar_engraver" }
334 \midi { \tempo 4=60 }
339 @subsection Piano centered dynamics
341 Many piano scores have the dynamics centered between the two
342 staffs. This requires a bit of tweaking to implement, but
343 since the template is right here, you don't have to do the
346 @lilypond[quote,verbatim,raggedright]
348 upper = \relative c'' {
356 lower = \relative c {
370 s2\sustainDown s2\sustainUp
374 \context PianoStaff <<
375 \context Staff=upper \upper
376 \context Dynamics=dynamics \dynamics
377 \context Staff=lower <<
381 \context Dynamics=pedal \pedal
385 \type "Engraver_group_engraver"
387 \alias Voice % So that \cresc works, for example.
388 \consists "Output_property_engraver"
390 minimumVerticalExtent = #'(-1 . 1)
391 pedalSustainStrings = #'("Ped." "*Ped." "*")
392 pedalUnaCordaStrings = #'("una corda" "" "tre corde")
394 \consists "Piano_pedal_engraver"
395 \consists "Script_engraver"
396 \consists "Dynamic_engraver"
397 \consists "Text_engraver"
399 \override TextScript #'font-size = #2
400 \override TextScript #'font-shape = #'italic
401 \override DynamicText #'extra-offset = #'(0 . 2.5)
402 \override Hairpin #'extra-offset = #'(0 . 2.5)
404 \consists "Skip_event_swallow_translator"
406 \consists "Axis_group_engraver"
411 \override VerticalAlignment #'forced-distance = #7
416 \type "Performer_group_performer"
418 \consists "Piano_pedal_performer"
419 \consists "Span_dynamic_performer"
420 \consists "Dynamic_performer"
432 @section String quartet
433 @subsection String quartet
435 This template demonstrates a string quartet. It also uses a @code{\global}
436 section for time and key signatures.
438 @lilypond[quote,verbatim,raggedright]
446 Violinone = \new Voice { \relative c''{
447 \set Staff.instrument = "Violin 1 "
452 Violintwo = \new Voice { \relative c''{
453 \set Staff.instrument = "Violin 2 "
458 Viola = \new Voice { \relative c' {
459 \set Staff.instrument = "Viola "
465 Cello = \new Voice { \relative c' {
466 \set Staff.instrument = "Cello "
471 \bar "|."}} %**********************************
475 \new Staff << \global \violinOne >>
476 \new Staff << \global \violinTwo >>
477 \new Staff << \global \viola >>
478 \new Staff << \global \cello >>
486 @subsection String quartet parts
488 The previous example produces a nice string quartet, but what if you
489 needed to print parts? This template demonstrates how to use the
490 @code{\tag} feature to easily split a piece into individual parts.
492 You need to split this template into separate files; the filenames
493 are contained in comments at the beginning of each file. @code{piece.ly}
494 contains all the music definitions. The other files -- @code{score.ly},
495 @code{vn1.ly}, @code{vn2.ly}, @code{vla.ly}, and
496 @code{vlc.ly} -- produce the appropiate part.
507 Violinone = \new Voice { \relative c''{
508 \set Staff.instrument = "Violin 1 "
512 \bar "|." }} %*********************************
513 Violintwo = \new Voice { \relative c''{
514 \set Staff.instrument = "Violin 2 "
518 \bar "|." }} %*********************************
519 Viola = \new Voice { \relative c' {
520 \set Staff.instrument = "Viola "
525 \bar "|." }} %*********************************
526 Cello = \new Voice { \relative c' {
527 \set Staff.instrument = "Cello "
532 \bar "|."}} %**********************************
536 \tag #'(score vn1) \new Staff { << \global \Violinone >> }
537 \tag #'(score vn2) \new Staff { << \global \Violintwo>> }
538 \tag #'(score vla) \new Staff { << \global \Viola>> }
539 \tag #'(score vlc) \new Staff { << \global \Cello>> }
548 #(set-global-staff-size 14)
550 \new StaffGroup \keepWithTag #'score \music
552 \midi { \tempo 4 = 60 }
560 \keepWithTag #'vn1 \music
569 \keepWithTag #'vn2 \music
578 \keepWithTag #'vla \music
587 \keepWithTag #'vlc \music
593 @node Vocal ensembles
594 @section Vocal ensembles
596 @subsection SATB vocal score
598 Here is a standard four-part SATB vocal score. With larger ensembles,
599 it's often useful to include a section which is included in all
600 parts. For example, the time signature and key signatures are almost
601 always the same for all parts.
603 @lilypond[quote,verbatim,raggedright]
610 sopMusic = \relative c'' {
613 sopWords = \lyricmode {
617 altoMusic = \relative c' {
620 altoWords =\lyricmode {
624 tenorMusic = \relative c' {
627 tenorWords = \lyricmode {
631 bassMusic = \relative c {
634 bassWords = \lyricmode {
639 \context ChoirStaff <<
640 \context Lyrics = sopranos { s1 }
641 \context Staff = women <<
643 sopranos { \voiceOne << \global \sopMusic >> }
645 altos { \voiceTwo << \global \altoMusic >> }
647 \context Lyrics = altos { s1 }
648 \context Lyrics = tenors { s1 }
649 \context Staff = men <<
652 tenors { \voiceOne <<\global \tenorMusic >> }
654 basses { \voiceTwo <<\global \bassMusic >> }
656 \context Lyrics = basses { s1 }
657 \context Lyrics = sopranos \lyricsto sopranos \sopWords
658 \context Lyrics = altos \lyricsto altos \altoWords
659 \context Lyrics = tenors \lyricsto tenors \tenorWords
660 \context Lyrics = basses \lyricsto basses \bassWords
665 % a little smaller so lyrics
666 % can be closer to the staff
667 \Staff minimumVerticalExtent = #'(-3 . 3)
674 @c bad node name to avoid node name confict
675 @node Ancient notation templates
676 @section Ancient notation templates
678 @subsection Transcription of mensural music
680 When transcribing mensural music, an incipit at the beginning of the
681 piece is useful to indicate the original key and tempo. While today
682 musicians are used to bar lines in order to faster recognize rhythmic
683 patterns, bar lines where not yet invented during the period of
684 mensural music; in fact, the meter often changed after every few
685 notes. As a compromise, bar lines are often printed between the
686 staves rather than on the staves.
688 @lilypond[quote,verbatim,linewidth=11.0\cm]
693 \once \override Score.SystemStartBracket #'transparent = ##t
696 \once \override Staff.TimeSignature #'style = #'neomensural
697 \override Voice.NoteHead #'style = #'neomensural
698 \override Voice.Rest #'style = #'neomensural
699 \set Staff.printKeyCancellation = ##f
700 \cadenzaOn % turn off bar lines
702 \once \override Staff.BarLine #'transparent = ##f
704 \skip 1*1 % need this extra \skip such that clef change comes
709 \cadenzaOff % turn bar lines on again
710 \once \override Staff.Clef #'full-size-change = ##t
711 \set Staff.forceClef = ##t
714 \override Voice.NoteHead #'style = #'default
715 \override Voice.Rest #'style = #'default
717 % FIXME: setting printKeyCancellation back to #t must not
718 % occur in the first bar after the incipit. Dto. for forceClef.
719 % Therefore, we need an extra \skip.
721 \set Staff.printKeyCancellation = ##t
722 \set Staff.forceClef = ##f
726 % last bar contains a brevis (i.e., spans 2 bars);
727 % therefore do not draw this particular bar
732 % let finis bar go through all staves
733 \override Staff.BarLine #'transparent = ##f
741 \set Staff.instrument = "Discantus "
744 \clef "neomensural-c1"
746 \skip 1*8 % eight bars
756 \once \override NoteHead #'transparent = ##t c'1 |
761 discantusLyrics = \lyricmode {
777 \set Staff.instrument = "Altus "
780 \clef "neomensural-c3"
783 \skip 1*7 % seven bars
788 r2 g2. e4 fis g | % two bars
790 fis g4.( fis16 e fis4) |
792 \once \override NoteHead #'transparent = ##t g1 |
797 altusLyrics = \lyricmode {
802 Ju -- bi -- la -- te | % two bars
811 \set Staff.instrument = "Tenor "
814 \clef "neomensural-c4"
827 r2 d'2. d'4 b e' | % two bars
828 \once \override NoteHead #'transparent = ##t e'1 |
833 tenorLyrics = \lyricmode {
838 Ju -- bi -- la -- te | % two bars
845 \set Staff.instrument = "Bassus "
849 r\maxima % eight bars
860 \once \override NoteHead #'transparent = ##t e1 |
865 bassusLyrics = \lyricmode {
876 \context StaffGroup = choirStaff <<
878 discantusNotes << \global \discantusNotes >>
880 discantusLyrics \lyricsto discantusNotes { \discantusLyrics }
882 altusNotes << \global \altusNotes >>
884 altusLyrics \lyricsto altusNotes { \altusLyrics }
886 tenorNotes << \global \tenorNotes >>
888 tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
890 bassusNotes << \global \bassusNotes >>
892 bassusLyrics \lyricsto bassusNotes { \bassusLyrics }
897 \override BarLine #'transparent = ##t
898 \remove "System_start_delimiter_engraver"
902 \override Slur #'transparent = ##t
913 This is a much more complicated template, for a jazz ensemble. Note that all
914 instruments are notated in @code{\key c \major}. This refers to the key in
915 concert pitch; LilyPond will automatically transpose the key if the music
916 is within a @code{\transpose} section.
918 @c TODO must clean up this jazz combo example
919 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
920 @c - one global section, instead of "global" (time) and "key"
921 @c - does it need those wierd macros? sl, nsl, etc.
922 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
923 @c make whatever changes I feel like.
925 @c FIXME: produces a warning ; key change merge.
926 @c The `linewidth' argument is for the \header.
928 @lilypond[quote,verbatim,raggedright,linewidth]
936 tagline = "LilyPond example file by Amelie Zapf,
938 texidoc = "Jazz tune for combo
939 (horns, guitar, piano, bass, drums)."
942 #(set-global-staff-size 16)
943 \include "english.ly"
945 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
948 \override NoteHead #'style = #'slash
949 \override Stem #'transparent = ##t
952 \revert NoteHead #'style
953 \revert Stem #'transparent
955 cr = \override NoteHead #'style = #'cross
956 ncr = \revert NoteHead #'style
958 %% insert chord name style stuff here.
963 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
969 Key = { \key c \major }
971 % ############ Horns ############
973 % ------ Trumpet ------
974 trpt = \transpose c d \relative c'' {
978 trpharmony = \transpose c' d {
983 \set Staff.instrument = #"Trumpet"
990 % ------ Alto Saxophone ------
991 alto = \transpose c a \relative c' {
995 altoharmony = \transpose c' a {
1000 \set Staff.instrument = #"Alto Sax"
1007 % ------ Baritone Saxophone ------
1008 bari = \transpose c a' \relative c {
1010 c1 c \sl d4^"Solo" d d d \nsl
1012 bariharmony = \transpose c' a \chordmode {
1013 \jzchords s1 s d2:maj e:m7
1017 \set Staff.instrument = #"Bari Sax"
1024 % ------ Trombone ------
1025 tbone = \relative c {
1029 tboneharmony = \chordmode {
1034 \set Staff.instrument = #"Trombone"
1041 % ############ Rhythm Section #############
1043 % ------ Guitar ------
1044 gtr = \relative c'' {
1046 c1 \sl b4 b b b \nsl c1
1048 gtrharmony = \chordmode {
1054 \set Staff.instrument = #"Guitar"
1061 %% ------ Piano ------
1062 rhUpper = \relative c'' {
1067 rhLower = \relative c' {
1073 lhUpper = \relative c' {
1078 lhLower = \relative c {
1087 \set Staff.midiInstrument = "acoustic grand"
1089 \context Voice = one \rhUpper
1090 \context Voice = two \rhLower
1096 \set Staff.midiInstrument = "acoustic grand"
1098 \context Voice = one \lhUpper
1099 \context Voice = two \lhLower
1104 \context PianoStaff <<
1105 \set PianoStaff.instrument = #"Piano"
1106 \context Staff = upper \PianoRH
1107 \context Staff = lower \PianoLH
1111 % ------ Bass Guitar ------
1112 Bass = \relative c {
1118 \set Staff.instrument = #"Bass"
1125 % ------ Drums ------
1127 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
1134 bd4 s bd s bd s bd s bd s bd s
1140 \set DrumStaff.instrument = #"Drums"
1141 \new DrumVoice { \voiceOne \up }
1142 \new DrumVoice { \voiceTwo \down }
1146 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
1150 \context StaffGroup = horns <<
1151 \context Staff = trumpet \trumpet
1152 \context Staff = altosax \altosax
1153 \context ChordNames = barichords \bariharmony
1154 \context Staff = barisax \barisax
1155 \context Staff = trombone \trombone
1158 \context StaffGroup = rhythm <<
1159 \context ChordNames = chords \gtrharmony
1160 \context Staff = guitar \guitar
1161 \context PianoStaff = piano \piano
1162 \context Staff = bass \bass
1163 \new DrumStaff { \drumContents }
1168 \context { \RemoveEmptyStaffContext }
1171 \override BarNumber #'padding = #3
1172 \override RehearsalMark #'padding = #2
1177 \midi { \tempo 4 = 75 }
1181 @node Other templates
1182 @section Other templates
1183 @subsection All headers
1185 This template displays all available headers. Some of them are only
1186 used in the Mutopia project; they don't affect the printed output at
1187 all. They are used if you want the piece to be listed with different
1188 information in the Mutopia database than you wish to have printed on the
1189 music. For example, Mutopia lists the composer of the famous D major
1190 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
1191 "Petr Tchaikowski" on your music.
1193 @ The `linewidth' is for \header.
1194 @lilypond[quote,verbatim,raggedright,linewidth]
1197 dedication = "dedication"
1199 subtitle = "Subtitle"
1200 subsubtitle = "Subsubtitle"
1201 composer = "Composer (xxxx-yyyy)"
1204 instrument = "Instrument"
1205 arranger = "Arranger"
1207 texttranslator = "Translator"
1208 copyright = "public domain"
1210 % These are headers used by the Mutopia Project
1211 % http://www.mutopiaproject.org/
1213 mutopiacomposer = ""
1215 mutopiainstrument = ""
1216 date = "composer's dates"
1218 maintainer = "your name here"
1219 maintainerEmail = "your email here"
1220 maintainerWeb = "your home page"
1221 lastupdated = "2004/Aug/26"
1241 @subsection Gregorian template
1243 This example demonstrates how to do modern transcriptions of Gregorian
1244 music. Gregorian music has no measure, no stems; it uses only half and
1245 quarter notes, and two types of barlines, a short one indicating a rest,
1246 and a second one indicating a breath mark.
1248 @lilypond[quote,verbatim,raggedright]
1249 barOne = { \once \override Staff.BarLine #'bar-size = #2
1251 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
1252 \once \override Staff.BarLine #'bar-size = #2
1254 chant = \relative c' {
1255 \set Score.timing = ##f
1256 \override Staff.Stem #'transparent = ##t
1265 \midi { \tempo 4=60 }
1269 @subsection Bagpipe music
1271 Here is an example of bagpipe music. It demonstrates a big strength of
1272 LilyPond, compared to graphical score editors: in LilyPond, you can
1273 very easily reuse small segments of music without writing them out
1274 completely. This template defines a large number of small segments
1275 (@code{taor}, @code{grip}, @code{thrd}, etc), which can be reused easily.
1277 @c TODO - replace Bagpipe template with Andrew McNabb's work?
1278 @c http://www.mcnabbs.org/andrew/linux/lilypond-ghb/
1280 @lilypond[quote,verbatim]
1281 taor = { \grace { g32[ d' g e'] } }
1282 grip = { \grace { g32[ b g ] } }
1283 thrd = { \grace { g32[ d' c'] } }
1284 birl = { \grace { g32[ a g] } }
1285 gstd = { \grace { g'32[ d' g] } }
1286 fgg = { \grace { f32[ g'32] } }
1287 dblb = { \grace { g'32[ b d'] } }
1288 dblc = { \grace { g'32[ c' d'] } }
1289 dble = { \grace { g'32[ e' f'] } }
1290 dblf = { \grace { g'32[ f' g'] } }
1291 dblg = { \grace { g'32[ f'] } }
1292 dbla = { \grace { a'32[ g'] } }
1293 lgg = { \grace { g32 } }
1294 lag = { \grace { a32 } }
1295 cg = { \grace { c'32 } }
1296 eg = { \grace { e'32 } }
1297 gg = { \grace { g'32 } }
1298 dg = { \grace { d'32 } }
1299 hag = { \grace { a'32 } }
1300 gefg = { \grace { g'32[ e' f'] } }
1301 efg = { \grace { e'32[ f'] } }
1302 gdcg = { \grace { g'32[ d' c'] } }
1303 gcdg = { \grace { g'32[ c' d'] } }
1306 #(add-grace-property 'Voice 'Stem 'length 6)
1307 \time 6/8 \partial 4
1312 \gg f'4 e'8 \thrd d'4. |
1314 \gg d'4 f'8 \dble e'4. ( | \noBreak
1315 e'8) d'4 \gg d'4 e'8 |
1319 \dblf f'2.( f'4) d'8 |
1321 \dblg g'4 a'8 \gg a'4. |
1322 \thrd d'4.( d'4) \eg a8 |
1324 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1328 \gg f'4 e'8 \thrd d'4. |
1330 \dblg g'4 a'8 \gg a'4. |
1331 \thrd d'4.( d'4) f'8 |
1334 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1335 \thrd d'4.( d'4) \cg d'8 |
1336 \gg c'4 e'8 \thrd d'4.( |
1342 @node Lilypond-book templates
1343 @section Lilypond-book templates
1345 These templates are for use with @code{lilypond-book}. If you're not familiar
1346 with this program, please refer to @ref{LilyPond-book}.
1350 You can include LilyPond fragments in a LaTeX document.
1353 \documentclass[]@{article@}
1376 You can include LilyPond fragments in Texinfo; in fact, this entire manual
1377 is written in Texinfo.
1385 @@lilypond[verbatim,fragment,raggedright]
1391 @@lilypond[verbatim,fragment,raggedright]