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 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[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"
431 @node Small ensembles
432 @section Small ensembles
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]
445 violinOne = \relative c''{
446 \set Staff.instrument = "Violin 1 "
451 violinTwo = \relative c''{
452 \set Staff.instrument = "Violin 2 "
457 viola = \relative c'{
458 \set Staff.instrument = "Viola "
464 cello = \relative c'{
465 \set Staff.instrument = "Cello "
473 \new Staff << \global \violinOne >>
474 \new Staff << \global \violinTwo >>
475 \new Staff << \global \viola >>
476 \new Staff << \global \cello >>
484 @node Vocal ensembles
485 @section Vocal ensembles
487 @subsection SATB vocal score
489 Here is a standard four-part SATB vocal score. With larger ensembles,
490 it's often useful to include a section which is included in all
491 parts. For example, the time signature and key signatures are almost
492 always the same for all parts.
494 @lilypond[quote,verbatim,raggedright]
501 sopMusic = \relative c'' {
504 sopWords = \lyricmode {
508 altoMusic = \relative c' {
511 altoWords =\lyricmode {
515 tenorMusic = \relative c' {
518 tenorWords = \lyricmode {
522 bassMusic = \relative c {
525 bassWords = \lyricmode {
530 \context ChoirStaff <<
531 \context Lyrics = sopranos { s1 }
532 \context Staff = women <<
534 sopranos { \voiceOne << \global \sopMusic >> }
536 altos { \voiceTwo << \global \altoMusic >> }
538 \context Lyrics = altos { s1 }
539 \context Lyrics = tenors { s1 }
540 \context Staff = men <<
543 tenors { \voiceOne <<\global \tenorMusic >> }
545 basses { \voiceTwo <<\global \bassMusic >> }
547 \context Lyrics = basses { s1 }
548 \context Lyrics = sopranos \lyricsto sopranos \sopWords
549 \context Lyrics = altos \lyricsto altos \altoWords
550 \context Lyrics = tenors \lyricsto tenors \tenorWords
551 \context Lyrics = basses \lyricsto basses \bassWords
556 % a little smaller so lyrics
557 % can be closer to the staff
558 \Staff minimumVerticalExtent = #'(-3 . 3)
565 @c bad node name to avoid node name confict
566 @node Ancient notation templates
567 @section Ancient notation templates
569 @subsection Transcription of mensural music
571 When transcribing mensural music, an incipit at the beginning of the
572 piece is useful to indicate the original key and tempo. While today
573 musicians are used to bar lines in order to faster recognize rhythmic
574 patterns, bar lines where not yet invented during the period of
575 mensural music; in fact, the meter often changed after every few
576 notes. As a compromise, bar lines are often printed between the
577 staves rather than on the staves.
579 @lilypond[quote,verbatim,linewidth=11.0\cm]
584 \once \override Score.SystemStartBracket #'transparent = ##t
587 \once \override Staff.TimeSignature #'style = #'neomensural
588 \override Voice.NoteHead #'style = #'neomensural
589 \override Voice.Rest #'style = #'neomensural
590 \set Staff.printKeyCancellation = ##f
591 \cadenzaOn % turn off bar lines
593 \once \override Staff.BarLine #'transparent = ##f
595 \skip 1*1 % need this extra \skip such that clef change comes
600 \cadenzaOff % turn bar lines on again
601 \once \override Staff.Clef #'full-size-change = ##t
602 \set Staff.forceClef = ##t
605 \override Voice.NoteHead #'style = #'default
606 \override Voice.Rest #'style = #'default
608 % FIXME: setting printKeyCancellation back to #t must not
609 % occur in the first bar after the incipit. Dto. for forceClef.
610 % Therefore, we need an extra \skip.
612 \set Staff.printKeyCancellation = ##t
613 \set Staff.forceClef = ##f
617 % last bar contains a brevis (i.e. spans 2 bars);
618 % therefore do not draw this particular bar
623 % let finis bar go through all staves
624 \override Staff.BarLine #'transparent = ##f
632 \set Staff.instrument = "Discantus "
635 \clef "neomensural-c1"
637 \skip 1*8 % eight bars
647 \once \override NoteHead #'transparent = ##t c'1 |
652 discantusLyrics = \lyricmode {
668 \set Staff.instrument = "Altus "
671 \clef "neomensural-c3"
674 \skip 1*7 % seven bars
679 r2 g2. e4 fis g | % two bars
681 fis g4.( fis16 e fis4) |
683 \once \override NoteHead #'transparent = ##t g1 |
688 altusLyrics = \lyricmode {
693 Ju -- bi -- la -- te | % two bars
702 \set Staff.instrument = "Tenor "
705 \clef "neomensural-c4"
718 r2 d'2. d'4 b e' | % two bars
719 \once \override NoteHead #'transparent = ##t e'1 |
724 tenorLyrics = \lyricmode {
729 Ju -- bi -- la -- te | % two bars
736 \set Staff.instrument = "Bassus "
740 r\maxima % eight bars
751 \once \override NoteHead #'transparent = ##t e1 |
756 bassusLyrics = \lyricmode {
767 \context StaffGroup = choirStaff <<
769 discantusNotes << \global \discantusNotes >>
771 discantusLyrics \lyricsto discantusNotes { \discantusLyrics }
773 altusNotes << \global \altusNotes >>
775 altusLyrics \lyricsto altusNotes { \altusLyrics }
777 tenorNotes << \global \tenorNotes >>
779 tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
781 bassusNotes << \global \bassusNotes >>
783 bassusLyrics \lyricsto bassusNotes { \bassusLyrics }
788 \override BarLine #'transparent = ##t
789 \remove "System_start_delimiter_engraver"
793 \override Slur #'transparent = ##t
804 This is a much more complicated template, for a jazz ensemble. Note that all
805 instruments are notated @code{\key c \major}. This refers to the key in
806 concert pitch; LilyPond will automatically transpose the key if the music
807 is within a @code{\transpose} section.
809 @c TODO must clean up this jazz combo example
810 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
811 @c - one global section, instead of "global" (time) and "key"
812 @c - does it need those wierd macros? sl, nsl, etc.
813 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
814 @c make whatever changes I feel like.
816 @c FIXME: produces a warning ; key change merge.
817 @c The `linewidth' argument is for the \header.
819 @lilypond[quote,verbatim,raggedright,linewidth]
827 tagline = "LilyPond example file by Amelie Zapf,
829 texidoc = "Jazz tune for combo
830 (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 ############
864 % ------ Trumpet ------
865 trpt = \transpose c d \relative c'' {
869 trpharmony = \transpose c' d {
874 \set Staff.instrument = #"Trumpet"
881 % ------ Alto Saxophone ------
882 alto = \transpose c a \relative c' {
886 altoharmony = \transpose c' a {
891 \set Staff.instrument = #"Alto Sax"
898 % ------ Baritone Saxophone ------
899 bari = \transpose c a' \relative c {
901 c1 c \sl d4^"Solo" d d d \nsl
903 bariharmony = \transpose c' a \chordmode {
904 \jzchords s1 s d2:maj e:m7
908 \set Staff.instrument = #"Bari Sax"
915 % ------ Trombone ------
916 tbone = \relative c {
920 tboneharmony = \chordmode {
925 \set Staff.instrument = #"Trombone"
932 % ############ Rhythm Section #############
934 % ------ Guitar ------
935 gtr = \relative c'' {
937 c1 \sl b4 b b b \nsl c1
939 gtrharmony = \chordmode {
945 \set Staff.instrument = #"Guitar"
952 %% ------ Piano ------
953 rhUpper = \relative c'' {
958 rhLower = \relative c' {
964 lhUpper = \relative c' {
969 lhLower = \relative c {
978 \set Staff.midiInstrument = "acoustic grand"
980 \context Voice = one \rhUpper
981 \context Voice = two \rhLower
987 \set Staff.midiInstrument = "acoustic grand"
989 \context Voice = one \lhUpper
990 \context Voice = two \lhLower
995 \context PianoStaff <<
996 \set PianoStaff.instrument = #"Piano"
997 \context Staff = upper \PianoRH
998 \context Staff = lower \PianoLH
1002 % ------ Bass Guitar ------
1003 Bass = \relative c {
1009 \set Staff.instrument = #"Bass"
1016 % ------ Drums ------
1018 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
1025 bd4 s bd s bd s bd s bd s bd s
1031 \set DrumStaff.instrument = #"Drums"
1032 \new DrumVoice { \voiceOne \up }
1033 \new DrumVoice { \voiceTwo \down }
1037 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
1041 \context StaffGroup = horns <<
1042 \context Staff = trumpet \trumpet
1043 \context Staff = altosax \altosax
1044 \context ChordNames = barichords \bariharmony
1045 \context Staff = barisax \barisax
1046 \context Staff = trombone \trombone
1049 \context StaffGroup = rhythm <<
1050 \context ChordNames = chords \gtrharmony
1051 \context Staff = guitar \guitar
1052 \context PianoStaff = piano \piano
1053 \context Staff = bass \bass
1054 \new DrumStaff { \drumContents }
1059 \context { \RemoveEmptyStaffContext }
1062 \override BarNumber #'padding = #3
1063 \override RehearsalMark #'padding = #2
1068 \midi { \tempo 4 = 75 }
1072 @node Other templates
1073 @section Other templates
1074 @subsection All headers
1076 This template displays all available headers. Some of them are only
1077 used in the Mutopia project; they don't affect the printed output at
1078 all. They are used if you want the piece to be listed with different
1079 information in the Mutopia database than you wish to have printed on the
1080 music. For example, Mutopia lists the composer of the famous D major
1081 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
1082 "Petr Tchaikowski" on your music.
1084 @ The `linewidth' is for \header.
1085 @lilypond[quote,verbatim,raggedright,linewidth]
1088 dedication = "dedication"
1090 subtitle = "Subtitle"
1091 subsubtitle = "Subsubtitle"
1092 composer = "Composer (xxxx-yyyy)"
1095 instrument = "Instrument"
1096 arranger = "Arranger"
1098 texttranslator = "Translator"
1099 copyright = "public domain"
1101 % These are headers used by the Mutopia Project
1102 % http://www.mutopiaproject.org/
1104 mutopiacomposer = ""
1106 mutopiainstrument = ""
1107 date = "composer's dates"
1109 maintainer = "your name here"
1110 maintainerEmail = "your email here"
1111 maintainerWeb = "your home page"
1112 lastupdated = "2004/Aug/26"
1132 @subsection Gregorian template
1134 This example demonstrates how to do modern transcriptions of Gregorian
1135 music. Gregorian music has no measure, no stems; it uses only half and
1136 quarter notes, and two types of barlines, a short one indicating a rest,
1137 and a second one indicating a breath mark.
1139 @lilypond[quote,verbatim,raggedright]
1140 barOne = { \once \override Staff.BarLine #'bar-size = #2
1142 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
1143 \once \override Staff.BarLine #'bar-size = #2
1145 chant = \relative c' {
1146 \set Score.timing = ##f
1147 \override Staff.Stem #'transparent = ##t
1156 \midi { \tempo 4=60 }
1160 @subsection Bagpipe music
1162 Here is an example of bagpipe music. It demonstrates a big strength of
1163 LilyPond, compared to graphical score editors: in LilyPond, you can
1164 very easily reuse small segments of music without writing them out
1165 completely. This template defines a large number of small segments
1166 (@code{taor, grip, thrd,} etc), which can be reused easily.
1168 TODO - replace Bagpipe template with Andrew McNabb's work?
1170 @lilypond[quote,verbatim]
1171 taor = { \grace { g32[ d' g e'] } }
1172 grip = { \grace { g32[ b g ] } }
1173 thrd = { \grace { g32[ d' c'] } }
1174 birl = { \grace { g32[ a g] } }
1175 gstd = { \grace { g'32[ d' g] } }
1176 fgg = { \grace { f32[ g'32] } }
1177 dblb = { \grace { g'32[ b d'] } }
1178 dblc = { \grace { g'32[ c' d'] } }
1179 dble = { \grace { g'32[ e' f'] } }
1180 dblf = { \grace { g'32[ f' g'] } }
1181 dblg = { \grace { g'32[ f'] } }
1182 dbla = { \grace { a'32[ g'] } }
1183 lgg = { \grace { g32 } }
1184 lag = { \grace { a32 } }
1185 cg = { \grace { c'32 } }
1186 eg = { \grace { e'32 } }
1187 gg = { \grace { g'32 } }
1188 dg = { \grace { d'32 } }
1189 hag = { \grace { a'32 } }
1190 gefg = { \grace { g'32[ e' f'] } }
1191 efg = { \grace { e'32[ f'] } }
1192 gdcg = { \grace { g'32[ d' c'] } }
1193 gcdg = { \grace { g'32[ c' d'] } }
1196 #(add-grace-property 'Voice 'Stem 'length 6)
1197 \time 6/8 \partial 4
1202 \gg f'4 e'8 \thrd d'4. |
1204 \gg d'4 f'8 \dble e'4. ( | \noBreak
1205 e'8) d'4 \gg d'4 e'8 |
1209 \dblf f'2.( f'4) d'8 |
1211 \dblg g'4 a'8 \gg a'4. |
1212 \thrd d'4.( d'4) \eg a8 |
1214 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1218 \gg f'4 e'8 \thrd d'4. |
1220 \dblg g'4 a'8 \gg a'4. |
1221 \thrd d'4.( d'4) f'8 |
1224 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1225 \thrd d'4.( d'4) \cg d'8 |
1226 \gg c'4 e'8 \thrd d'4.( |
1232 @node Lilypond-book templates
1233 @section Lilypond-book templates
1235 These templates are for use with @code{lilypond-book}. If you're not familiar
1236 with this program, please refer to @ref{Integrating text and music}.
1240 You can include LilyPond fragments in a LaTeX document.
1243 \documentclass[]@{article@}
1266 You can include LilyPond fragments in texinfo; in fact, this entire manual
1267 is written in texinfo.
1275 @@lilypond[verbatim,fragment,raggedright]
1281 @@lilypond[verbatim,fragment,raggedright]