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.
439 @li lypond[quote,verbatim,raggedright]
447 Violinone = \new Voice { \relative c''{
448 \set Staff.instrument = "Violin 1 "
453 Violintwo = \new Voice { \relative c''{
454 \set Staff.instrument = "Violin 2 "
459 Viola = \new Voice { \relative c' {
460 \set Staff.instrument = "Viola "
466 Cello = \new Voice { \relative c' {
467 \set Staff.instrument = "Cello "
472 \bar "|."}} %**********************************
476 \new Staff << \global \violinOne >>
477 \new Staff << \global \violinTwo >>
478 \new Staff << \global \viola >>
479 \new Staff << \global \cello >>
487 @subsection String quartet parts
489 The previous example produces a nice string quartet, but what if you
490 needed to print parts? This template demonstrates how to use the
491 @code{\tag} feature to easily split a piece into individual parts.
493 You need to split this template into separate files; the filenames
494 are contained in comments at the beginning of each file. @code{piece.ly}
495 contains all the music definitions. The other files -- @code{score.ly},
496 @code{vn1.ly}, @code{vn2.ly}, @code{vla.ly}, and
497 @code{vlc.ly} -- produce the appropiate part.
508 Violinone = \new Voice { \relative c''{
509 \set Staff.instrument = "Violin 1 "
513 \bar "|." }} %*********************************
514 Violintwo = \new Voice { \relative c''{
515 \set Staff.instrument = "Violin 2 "
519 \bar "|." }} %*********************************
520 Viola = \new Voice { \relative c' {
521 \set Staff.instrument = "Viola "
526 \bar "|." }} %*********************************
527 Cello = \new Voice { \relative c' {
528 \set Staff.instrument = "Cello "
533 \bar "|."}} %**********************************
537 \tag #'(score vn1) \new Staff { << \global \Violinone >> }
538 \tag #'(score vn2) \new Staff { << \global \Violintwo>> }
539 \tag #'(score vla) \new Staff { << \global \Viola>> }
540 \tag #'(score vlc) \new Staff { << \global \Cello>> }
549 #(set-global-staff-size 14)
551 \new StaffGroup \keepWithTag #'score \music
553 \midi { \tempo 4 = 60 }
561 \keepWithTag #'vn1 \music
570 \keepWithTag #'vn2 \music
579 \keepWithTag #'vla \music
588 \keepWithTag #'vlc \music
594 @node Vocal ensembles
595 @section Vocal ensembles
597 @subsection SATB vocal score
599 Here is a standard four-part SATB vocal score. With larger ensembles,
600 it's often useful to include a section which is included in all
601 parts. For example, the time signature and key signatures are almost
602 always the same for all parts.
604 @lilypond[quote,verbatim,raggedright]
611 sopMusic = \relative c'' {
614 sopWords = \lyricmode {
618 altoMusic = \relative c' {
621 altoWords =\lyricmode {
625 tenorMusic = \relative c' {
628 tenorWords = \lyricmode {
632 bassMusic = \relative c {
635 bassWords = \lyricmode {
640 \context ChoirStaff <<
641 \context Lyrics = sopranos { s1 }
642 \context Staff = women <<
644 sopranos { \voiceOne << \global \sopMusic >> }
646 altos { \voiceTwo << \global \altoMusic >> }
648 \context Lyrics = altos { s1 }
649 \context Lyrics = tenors { s1 }
650 \context Staff = men <<
653 tenors { \voiceOne <<\global \tenorMusic >> }
655 basses { \voiceTwo <<\global \bassMusic >> }
657 \context Lyrics = basses { s1 }
658 \context Lyrics = sopranos \lyricsto sopranos \sopWords
659 \context Lyrics = altos \lyricsto altos \altoWords
660 \context Lyrics = tenors \lyricsto tenors \tenorWords
661 \context Lyrics = basses \lyricsto basses \bassWords
666 % a little smaller so lyrics
667 % can be closer to the staff
668 \Staff minimumVerticalExtent = #'(-3 . 3)
675 @c bad node name to avoid node name confict
676 @node Ancient notation templates
677 @section Ancient notation templates
679 @subsection Transcription of mensural music
681 When transcribing mensural music, an incipit at the beginning of the
682 piece is useful to indicate the original key and tempo. While today
683 musicians are used to bar lines in order to faster recognize rhythmic
684 patterns, bar lines where not yet invented during the period of
685 mensural music; in fact, the meter often changed after every few
686 notes. As a compromise, bar lines are often printed between the
687 staves rather than on the staves.
689 @lilypond[quote,verbatim,linewidth=11.0\cm]
694 \once \override Score.SystemStartBracket #'transparent = ##t
697 \once \override Staff.TimeSignature #'style = #'neomensural
698 \override Voice.NoteHead #'style = #'neomensural
699 \override Voice.Rest #'style = #'neomensural
700 \set Staff.printKeyCancellation = ##f
701 \cadenzaOn % turn off bar lines
703 \once \override Staff.BarLine #'transparent = ##f
705 \skip 1*1 % need this extra \skip such that clef change comes
710 \cadenzaOff % turn bar lines on again
711 \once \override Staff.Clef #'full-size-change = ##t
712 \set Staff.forceClef = ##t
715 \override Voice.NoteHead #'style = #'default
716 \override Voice.Rest #'style = #'default
718 % FIXME: setting printKeyCancellation back to #t must not
719 % occur in the first bar after the incipit. Dto. for forceClef.
720 % Therefore, we need an extra \skip.
722 \set Staff.printKeyCancellation = ##t
723 \set Staff.forceClef = ##f
727 % last bar contains a brevis (i.e., spans 2 bars);
728 % therefore do not draw this particular bar
733 % let finis bar go through all staves
734 \override Staff.BarLine #'transparent = ##f
742 \set Staff.instrument = "Discantus "
745 \clef "neomensural-c1"
747 \skip 1*8 % eight bars
757 \once \override NoteHead #'transparent = ##t c'1 |
762 discantusLyrics = \lyricmode {
778 \set Staff.instrument = "Altus "
781 \clef "neomensural-c3"
784 \skip 1*7 % seven bars
789 r2 g2. e4 fis g | % two bars
791 fis g4.( fis16 e fis4) |
793 \once \override NoteHead #'transparent = ##t g1 |
798 altusLyrics = \lyricmode {
803 Ju -- bi -- la -- te | % two bars
812 \set Staff.instrument = "Tenor "
815 \clef "neomensural-c4"
828 r2 d'2. d'4 b e' | % two bars
829 \once \override NoteHead #'transparent = ##t e'1 |
834 tenorLyrics = \lyricmode {
839 Ju -- bi -- la -- te | % two bars
846 \set Staff.instrument = "Bassus "
850 r\maxima % eight bars
861 \once \override NoteHead #'transparent = ##t e1 |
866 bassusLyrics = \lyricmode {
877 \context StaffGroup = choirStaff <<
879 discantusNotes << \global \discantusNotes >>
881 discantusLyrics \lyricsto discantusNotes { \discantusLyrics }
883 altusNotes << \global \altusNotes >>
885 altusLyrics \lyricsto altusNotes { \altusLyrics }
887 tenorNotes << \global \tenorNotes >>
889 tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
891 bassusNotes << \global \bassusNotes >>
893 bassusLyrics \lyricsto bassusNotes { \bassusLyrics }
898 \override BarLine #'transparent = ##t
899 \remove "System_start_delimiter_engraver"
903 \override Slur #'transparent = ##t
914 This is a much more complicated template, for a jazz ensemble. Note that all
915 instruments are notated in @code{\key c \major}. This refers to the key in
916 concert pitch; LilyPond will automatically transpose the key if the music
917 is within a @code{\transpose} section.
919 @c TODO must clean up this jazz combo example
920 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
921 @c - one global section, instead of "global" (time) and "key"
922 @c - does it need those wierd macros? sl, nsl, etc.
923 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
924 @c make whatever changes I feel like.
926 @c FIXME: produces a warning ; key change merge.
927 @c The `linewidth' argument is for the \header.
929 @lilypond[quote,verbatim,raggedright,linewidth]
937 tagline = "LilyPond example file by Amelie Zapf,
939 texidoc = "Jazz tune for combo
940 (horns, guitar, piano, bass, drums)."
943 #(set-global-staff-size 16)
944 \include "english.ly"
946 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
949 \override NoteHead #'style = #'slash
950 \override Stem #'transparent = ##t
953 \revert NoteHead #'style
954 \revert Stem #'transparent
956 cr = \override NoteHead #'style = #'cross
957 ncr = \revert NoteHead #'style
959 %% insert chord name style stuff here.
964 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
970 Key = { \key c \major }
972 % ############ Horns ############
974 % ------ Trumpet ------
975 trpt = \transpose c d \relative c'' {
979 trpharmony = \transpose c' d {
984 \set Staff.instrument = #"Trumpet"
991 % ------ Alto Saxophone ------
992 alto = \transpose c a \relative c' {
996 altoharmony = \transpose c' a {
1001 \set Staff.instrument = #"Alto Sax"
1008 % ------ Baritone Saxophone ------
1009 bari = \transpose c a' \relative c {
1011 c1 c \sl d4^"Solo" d d d \nsl
1013 bariharmony = \transpose c' a \chordmode {
1014 \jzchords s1 s d2:maj e:m7
1018 \set Staff.instrument = #"Bari Sax"
1025 % ------ Trombone ------
1026 tbone = \relative c {
1030 tboneharmony = \chordmode {
1035 \set Staff.instrument = #"Trombone"
1042 % ############ Rhythm Section #############
1044 % ------ Guitar ------
1045 gtr = \relative c'' {
1047 c1 \sl b4 b b b \nsl c1
1049 gtrharmony = \chordmode {
1055 \set Staff.instrument = #"Guitar"
1062 %% ------ Piano ------
1063 rhUpper = \relative c'' {
1068 rhLower = \relative c' {
1074 lhUpper = \relative c' {
1079 lhLower = \relative c {
1088 \set Staff.midiInstrument = "acoustic grand"
1090 \context Voice = one \rhUpper
1091 \context Voice = two \rhLower
1097 \set Staff.midiInstrument = "acoustic grand"
1099 \context Voice = one \lhUpper
1100 \context Voice = two \lhLower
1105 \context PianoStaff <<
1106 \set PianoStaff.instrument = #"Piano"
1107 \context Staff = upper \PianoRH
1108 \context Staff = lower \PianoLH
1112 % ------ Bass Guitar ------
1113 Bass = \relative c {
1119 \set Staff.instrument = #"Bass"
1126 % ------ Drums ------
1128 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
1135 bd4 s bd s bd s bd s bd s bd s
1141 \set DrumStaff.instrument = #"Drums"
1142 \new DrumVoice { \voiceOne \up }
1143 \new DrumVoice { \voiceTwo \down }
1147 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
1151 \context StaffGroup = horns <<
1152 \context Staff = trumpet \trumpet
1153 \context Staff = altosax \altosax
1154 \context ChordNames = barichords \bariharmony
1155 \context Staff = barisax \barisax
1156 \context Staff = trombone \trombone
1159 \context StaffGroup = rhythm <<
1160 \context ChordNames = chords \gtrharmony
1161 \context Staff = guitar \guitar
1162 \context PianoStaff = piano \piano
1163 \context Staff = bass \bass
1164 \new DrumStaff { \drumContents }
1169 \context { \RemoveEmptyStaffContext }
1172 \override BarNumber #'padding = #3
1173 \override RehearsalMark #'padding = #2
1178 \midi { \tempo 4 = 75 }
1182 @node Other templates
1183 @section Other templates
1184 @subsection All headers
1186 This template displays all available headers. Some of them are only
1187 used in the Mutopia project; they don't affect the printed output at
1188 all. They are used if you want the piece to be listed with different
1189 information in the Mutopia database than you wish to have printed on the
1190 music. For example, Mutopia lists the composer of the famous D major
1191 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
1192 "Petr Tchaikowski" on your music.
1194 @ The `linewidth' is for \header.
1195 @lilypond[quote,verbatim,raggedright,linewidth]
1198 dedication = "dedication"
1200 subtitle = "Subtitle"
1201 subsubtitle = "Subsubtitle"
1202 composer = "Composer (xxxx-yyyy)"
1205 instrument = "Instrument"
1206 arranger = "Arranger"
1208 texttranslator = "Translator"
1209 copyright = "public domain"
1211 % These are headers used by the Mutopia Project
1212 % http://www.mutopiaproject.org/
1214 mutopiacomposer = ""
1216 mutopiainstrument = ""
1217 date = "composer's dates"
1219 maintainer = "your name here"
1220 maintainerEmail = "your email here"
1221 maintainerWeb = "your home page"
1222 lastupdated = "2004/Aug/26"
1242 @subsection Gregorian template
1244 This example demonstrates how to do modern transcriptions of Gregorian
1245 music. Gregorian music has no measure, no stems; it uses only half and
1246 quarter notes, and two types of barlines, a short one indicating a rest,
1247 and a second one indicating a breath mark.
1249 @lilypond[quote,verbatim,raggedright]
1250 barOne = { \once \override Staff.BarLine #'bar-size = #2
1252 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
1253 \once \override Staff.BarLine #'bar-size = #2
1255 chant = \relative c' {
1256 \set Score.timing = ##f
1257 \override Staff.Stem #'transparent = ##t
1266 \midi { \tempo 4=60 }
1270 @subsection Bagpipe music
1272 Here is an example of bagpipe music. It demonstrates a big strength of
1273 LilyPond, compared to graphical score editors: in LilyPond, you can
1274 very easily reuse small segments of music without writing them out
1275 completely. This template defines a large number of small segments
1276 (@code{taor}, @code{grip}, @code{thrd}, etc), which can be reused easily.
1278 @c TODO - replace Bagpipe template with Andrew McNabb's work?
1279 @c http://www.mcnabbs.org/andrew/linux/lilypond-ghb/
1281 @lilypond[quote,verbatim]
1282 taor = { \grace { g32[ d' g e'] } }
1283 grip = { \grace { g32[ b g ] } }
1284 thrd = { \grace { g32[ d' c'] } }
1285 birl = { \grace { g32[ a g] } }
1286 gstd = { \grace { g'32[ d' g] } }
1287 fgg = { \grace { f32[ g'32] } }
1288 dblb = { \grace { g'32[ b d'] } }
1289 dblc = { \grace { g'32[ c' d'] } }
1290 dble = { \grace { g'32[ e' f'] } }
1291 dblf = { \grace { g'32[ f' g'] } }
1292 dblg = { \grace { g'32[ f'] } }
1293 dbla = { \grace { a'32[ g'] } }
1294 lgg = { \grace { g32 } }
1295 lag = { \grace { a32 } }
1296 cg = { \grace { c'32 } }
1297 eg = { \grace { e'32 } }
1298 gg = { \grace { g'32 } }
1299 dg = { \grace { d'32 } }
1300 hag = { \grace { a'32 } }
1301 gefg = { \grace { g'32[ e' f'] } }
1302 efg = { \grace { e'32[ f'] } }
1303 gdcg = { \grace { g'32[ d' c'] } }
1304 gcdg = { \grace { g'32[ c' d'] } }
1307 #(add-grace-property 'Voice 'Stem 'length 6)
1308 \time 6/8 \partial 4
1313 \gg f'4 e'8 \thrd d'4. |
1315 \gg d'4 f'8 \dble e'4. ( | \noBreak
1316 e'8) d'4 \gg d'4 e'8 |
1320 \dblf f'2.( f'4) d'8 |
1322 \dblg g'4 a'8 \gg a'4. |
1323 \thrd d'4.( d'4) \eg a8 |
1325 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1329 \gg f'4 e'8 \thrd d'4. |
1331 \dblg g'4 a'8 \gg a'4. |
1332 \thrd d'4.( d'4) f'8 |
1335 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1336 \thrd d'4.( d'4) \cg d'8 |
1337 \gg c'4 e'8 \thrd d'4.( |
1343 @node Lilypond-book templates
1344 @section Lilypond-book templates
1346 These templates are for use with @code{lilypond-book}. If you're not familiar
1347 with this program, please refer to @ref{LilyPond-book}.
1351 You can include LilyPond fragments in a LaTeX document.
1354 \documentclass[]@{article@}
1377 You can include LilyPond fragments in Texinfo; in fact, this entire manual
1378 is written in Texinfo.
1386 @@lilypond[verbatim,fragment,raggedright]
1392 @@lilypond[verbatim,fragment,raggedright]