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[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[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[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[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[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[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[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[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[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[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 <<
533 \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
534 \context Voice = altos { \voiceTwo << \global \altoMusic >> }
536 \context Lyrics = altos { s1 }
537 \context Lyrics = tenors { s1 }
538 \context Staff = men <<
540 \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
541 \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
543 \context Lyrics = basses { s1 }
544 \context Lyrics = sopranos \lyricsto sopranos \sopWords
545 \context Lyrics = altos \lyricsto altos \altoWords
546 \context Lyrics = tenors \lyricsto tenors \tenorWords
547 \context Lyrics = basses \lyricsto basses \bassWords
552 % a little smaller so lyrics can be closer to the staff.
553 \Staff minimumVerticalExtent = #'(-3 . 3)
560 @c bad node name to avoid node name confict
561 @node Ancient notation templates
562 @section Ancient notation templates
564 @subsection Transcription of mensural music
566 When transcribing mensural music, an incipit at the beginning of the
567 piece is useful to indicate the original key and tempo. While today
568 musicians are used to bar lines in order to faster recognize rhythmic
569 patterns, bar lines where not yet invented during the period of
570 mensural music; in fact, the meter often changed after every few
571 notes. As a compromise, bar lines are often printed between the
572 staves rather than on the staves.
574 @lilypond[verbatim,linewidth=11.0\cm]
579 \once \override Score.SystemStartBracket #'transparent = ##t
582 \once \override Staff.TimeSignature #'style = #'neomensural
583 \override Voice.NoteHead #'style = #'neomensural
584 \override Voice.Rest #'style = #'neomensural
585 \set Staff.printKeyCancellation = ##f
586 \cadenzaOn % turn off bar lines
588 \once \override Staff.BarLine #'transparent = ##f
590 \skip 1*1 % need this extra \skip such that clef change comes
595 \cadenzaOff % turn bar lines on again
596 \once \override Staff.Clef #'full-size-change = ##t
597 \set Staff.forceClef = ##t
600 \override Voice.NoteHead #'style = #'default
601 \override Voice.Rest #'style = #'default
603 % FIXME: setting printKeyCancellation back to #t must not
604 % occur in the first bar after the incipit. Dto. for forceClef.
605 % Therefore, we need an extra \skip.
607 \set Staff.printKeyCancellation = ##t
608 \set Staff.forceClef = ##f
612 % last bar contains a brevis (i.e. spans 2 bars);
613 % therefore do not draw this particular bar
618 % let finis bar go through all staves
619 \override Staff.BarLine #'transparent = ##f
627 \set Staff.instrument = "Discantus "
630 \clef "neomensural-c1"
632 \skip 1*8 % eight bars
642 \once \override NoteHead #'transparent = ##t c'1 |
647 discantusLyrics = \lyricmode {
663 \set Staff.instrument = "Altus "
666 \clef "neomensural-c3"
669 \skip 1*7 % seven bars
674 r2 g2. e4 fis g | % two bars
676 fis g4.( fis16 e fis4) |
678 \once \override NoteHead #'transparent = ##t g1 |
683 altusLyrics = \lyricmode {
688 Ju -- bi -- la -- te | % two bars
697 \set Staff.instrument = "Tenor "
700 \clef "neomensural-c4"
713 r2 d'2. d'4 b e' | % two bars
714 \once \override NoteHead #'transparent = ##t e'1 |
719 tenorLyrics = \lyricmode {
724 Ju -- bi -- la -- te | % two bars
731 \set Staff.instrument = "Bassus "
735 r\maxima % eight bars
746 \once \override NoteHead #'transparent = ##t e1 |
751 bassusLyrics = \lyricmode {
762 \context StaffGroup = choirStaff <<
763 \context Voice = discantusNotes << \global \discantusNotes >>
764 \context Lyrics = discantusLyrics
765 \lyricsto discantusNotes { \discantusLyrics }
766 \context Voice = altusNotes << \global \altusNotes >>
767 \context Lyrics = altusLyrics \lyricsto altusNotes { \altusLyrics }
768 \context Voice = tenorNotes << \global \tenorNotes >>
769 \context Lyrics = tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
770 \context Voice = bassusNotes << \global \bassusNotes >>
771 \context Lyrics = bassusLyrics
772 \lyricsto bassusNotes { \bassusLyrics }
777 \override BarLine #'transparent = ##t
778 \remove "System_start_delimiter_engraver"
782 \override Slur #'transparent = ##t
793 This is a much more complicated template, for a jazz ensemble. Note that all
794 instruments are notated @code{\key c \major}. This refers to the key in
795 concert pitch; LilyPond will automatically transpose the key if the music
796 is within a @code{\transpose} section.
798 @c TODO must clean up this jazz combo example
799 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
800 @c - one global section, instead of "global" (time) and "key"
801 @c - does it need those wierd macros? sl, nsl, etc.
802 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
803 @c make whatever changes I feel like.
805 @c FIXME: produces a warning ; key change merge.
806 @c The `linewidth' argument is for the \header.
808 @lilypond[verbatim,raggedright,linewidth]
816 tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
817 texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
820 #(set-global-staff-size 16)
821 \include "english.ly"
823 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
826 \override NoteHead #'style = #'slash
827 \override Stem #'transparent = ##t
830 \revert NoteHead #'style
831 \revert Stem #'transparent
833 cr = \override NoteHead #'style = #'cross
834 ncr = \revert NoteHead #'style
836 %% insert chord name style stuff here.
841 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
847 Key = { \key c \major }
849 % ############ Horns ############
850 % ------ Trumpet ------
851 trpt = \transpose c d \relative c'' {
856 trpharmony = \transpose c' d { \jzchords }
859 \set Staff.instrument = #"Trumpet"
866 % ------ Alto Saxophone ------
867 alto = \transpose c a \relative c' {
872 altoharmony = \transpose c' a { \jzchords }
875 \set Staff.instrument = #"Alto Sax"
882 % ------ Baritone Saxophone ------
883 bari = \transpose c a' \relative c {
885 c1 c \sl d4^"Solo" d d d \nsl
888 bariharmony = \transpose c' a \chordmode { \jzchords s1 s d2:maj e:m7 }
891 \set Staff.instrument = #"Bari Sax"
897 % ------ Trombone ------
898 tbone = \relative c {
903 tboneharmony = \chordmode { \jzchords }
906 \set Staff.instrument = #"Trombone"
912 % ############ Rhythm Section #############
913 % ------ Guitar ------
914 gtr = \relative c'' {
916 c1 \sl b4 b b b \nsl c1
919 gtrharmony = \chordmode { \jzchords
925 \set Staff.instrument = #"Guitar"
932 %% ------ Piano ------
933 rhUpper = \relative c'' {
939 rhLower = \relative c' {
945 lhUpper = \relative c' {
951 lhLower = \relative c {
960 \set Staff.midiInstrument = "acoustic grand"
962 \context Voice = one \rhUpper
963 \context Voice = two \rhLower
970 \set Staff.midiInstrument = "acoustic grand"
972 \context Voice = one \lhUpper
973 \context Voice = two \lhLower
978 \context PianoStaff <<
979 \set PianoStaff.instrument = #"Piano"
980 \context Staff = upper \PianoRH
981 \context Staff = lower \PianoLH
985 % ------ Bass Guitar ------
993 \set Staff.instrument = #"Bass"
1000 % ------ Drums ------
1003 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
1010 bd4 s bd s bd s bd s bd s bd s
1016 \set DrumStaff.instrument = #"Drums"
1017 \new DrumVoice { \voiceOne \up }
1018 \new DrumVoice { \voiceTwo \down }
1022 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
1026 \context StaffGroup = horns <<
1027 \context Staff = trumpet \trumpet
1029 \context Staff = altosax \altosax
1031 \context ChordNames = barichords \bariharmony
1033 \context Staff = barisax \barisax
1035 \context Staff = trombone \trombone
1038 \context StaffGroup = rhythm <<
1039 \context ChordNames = chords \gtrharmony
1040 \context Staff = guitar \guitar
1041 \context PianoStaff = piano \piano
1043 \context Staff = bass \bass
1045 \new DrumStaff { \drumContents }
1049 \context { \RemoveEmptyStaffContext }
1052 \override BarNumber #'padding = #3
1053 \override RehearsalMark #'padding = #2
1057 \midi { \tempo 4 = 75 }
1062 @node Other templates
1063 @section Other templates
1064 @subsection All headers
1066 This template displays all available headers. Some of them are only
1067 used in the Mutopia project; they don't affect the printed output at
1068 all. They are used if you want the piece to be listed with different
1069 information in the Mutopia database than you wish to have printed on the
1070 music. For example, Mutopia lists the composer of the famous D major
1071 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
1072 "Petr Tchaikowski" on your music.
1074 @ The `linewidth' is for \header.
1075 @lilypond[verbatim,raggedright,linewidth]
1078 dedication = "dedication"
1080 subtitle = "Subtitle"
1081 subsubtitle = "Subsubtitle"
1082 composer = "Composer (xxxx-yyyy)"
1085 instrument = "Instrument"
1086 arranger = "Arranger"
1088 texttranslator = "Translator"
1089 copyright = "public domain"
1091 % These are headers used by the Mutopia Project http://www.mutopiaproject.org/
1093 mutopiacomposer = ""
1095 mutopiainstrument = ""
1096 date = "composer's dates"
1098 maintainer = "your name here"
1099 maintainerEmail = "your email here"
1100 maintainerWeb = "your home page"
1101 lastupdated = "2004/Aug/26"
1122 @subsection Gregorian template
1124 This example demonstrates how to do modern transcriptions of Gregorian
1125 music. Gregorian music has no measure, no stems; it uses only half and
1126 quarter notes, and two types of barlines, a short one indicating a rest,
1127 and a second one indicating a breath mark.
1129 @lilypond[verbatim,raggedright]
1130 barOne = { \once \override Staff.BarLine #'bar-size = #2
1132 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
1133 \once \override Staff.BarLine #'bar-size = #2
1135 chant = \relative c' {
1136 \set Score.timing = ##f
1137 \override Staff.Stem #'transparent = ##t
1146 \midi { \tempo 4=60 }
1151 @subsection Bagpipe music
1153 Here is an example of bagpipe music. It demonstrates a big strength of
1154 LilyPond, compared to graphical score editors: in LilyPond, you can
1155 very easily reuse small segments of music without writing them out
1156 completely. This template defines a large number of small segments
1157 (@code{taor, grip, thrd,} etc), which can be reused easily.
1159 TODO - replace Bagpipe template with Andrew McNabb's work?
1163 taor = { \grace { g32[ d' g e'] } }
1164 grip = { \grace { g32[ b g ] } }
1165 thrd = { \grace { g32[ d' c'] } }
1166 birl = { \grace { g32[ a g] } }
1167 gstd = { \grace { g'32[ d' g] } }
1168 fgg = { \grace { f32[ g'32] } }
1169 dblb = { \grace { g'32[ b d'] } }
1170 dblc = { \grace { g'32[ c' d'] } }
1171 dble = { \grace { g'32[ e' f'] } }
1172 dblf = { \grace { g'32[ f' g'] } }
1173 dblg = { \grace { g'32[ f'] } }
1174 dbla = { \grace { a'32[ g'] } }
1175 lgg = { \grace { g32 } }
1176 lag = { \grace { a32 } }
1177 cg = { \grace { c'32 } }
1178 eg = { \grace { e'32 } }
1179 gg = { \grace { g'32 } }
1180 dg = { \grace { d'32 } }
1181 hag = { \grace { a'32 } }
1182 gefg = { \grace { g'32[ e' f'] } }
1183 efg = { \grace { e'32[ f'] } }
1184 gdcg = { \grace { g'32[ d' c'] } }
1185 gcdg = { \grace { g'32[ c' d'] } }
1188 #(add-grace-property 'Voice 'Stem 'length 6)
1189 \time 6/8 \partial 4
1194 \gg f'4 e'8 \thrd d'4. |
1196 \gg d'4 f'8 \dble e'4. ( | \noBreak
1197 e'8) d'4 \gg d'4 e'8 |
1201 \dblf f'2.( f'4) d'8 |
1203 \dblg g'4 a'8 \gg a'4. |
1204 \thrd d'4.( d'4) \eg a8 |
1206 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1210 \gg f'4 e'8 \thrd d'4. |
1212 \dblg g'4 a'8 \gg a'4. |
1213 \thrd d'4.( d'4) f'8 |
1216 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1217 \thrd d'4.( d'4) \cg d'8 |
1218 \gg c'4 e'8 \thrd d'4.( |
1226 @node Lilypond-book templates
1227 @section Lilypond-book templates
1229 These templates are for use with @code{lilypond-book}. If you're not familiar
1230 with this program, please refer to @ref{Integrating text and music}.
1234 You can include LilyPond fragments in a LaTeX document.
1237 \documentclass[]@{article@}
1260 You can include LilyPond fragments in texinfo; in fact, this entire manual
1261 is written in texinfo.
1269 @@lilypond[verbatim,fragment,raggedright]
1275 @@lilypond[verbatim,fragment,raggedright]