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 }
305 @subsection Piano centered dynamics
307 Many piano scores have the dynamics centered between the two
308 staffs. This requires a bit of tweaking to implement, but
309 since the template is right here, you don't have to do the
312 @lilypond[verbatim,raggedright]
315 upper = \relative c'' {
323 lower = \relative c {
337 s2\sustainDown s2\sustainUp
341 \context PianoStaff <<
342 \context Staff=upper \upper
343 \context Dynamics=dynamics \dynamics
344 \context Staff=lower <<
348 \context Dynamics=pedal \pedal
352 \type "Engraver_group_engraver"
354 \alias Voice % So that \cresc works, for example.
355 \consists "Output_property_engraver"
357 minimumVerticalExtent = #'(-1 . 1)
358 pedalSustainStrings = #'("Ped." "*Ped." "*")
359 pedalUnaCordaStrings = #'("una corda" "" "tre corde")
361 \consists "Piano_pedal_engraver"
362 \consists "Script_engraver"
363 \consists "Dynamic_engraver"
364 \consists "Text_engraver"
366 \override TextScript #'font-size = #2
367 \override TextScript #'font-shape = #'italic
368 \override DynamicText #'extra-offset = #'(0 . 2.5)
369 \override Hairpin #'extra-offset = #'(0 . 2.5)
371 \consists "Skip_event_swallow_translator"
373 \consists "Axis_group_engraver"
378 \override VerticalAlignment #'forced-distance = #7
383 \type "Performer_group_performer"
385 \consists "Piano_pedal_performer"
386 \consists "Span_dynamic_performer"
387 \consists "Dynamic_performer"
398 @node Small ensembles
399 @section Small ensembles
400 @subsection String quartet
402 This template demonstrates a string quartet. It also uses a @code{\global}
403 section for time and key signatures.
405 @lilypond[verbatim,raggedright]
412 violinOne = \relative c''{
413 \set Staff.instrument = "Violin 1 "
417 violinTwo = \relative c''{
418 \set Staff.instrument = "Violin 2 "
422 viola = \relative c'{
423 \set Staff.instrument = "Viola "
428 cello = \relative c'{
429 \set Staff.instrument = "Cello "
436 \new Staff << \global \violinOne >>
437 \new Staff << \global \violinTwo >>
438 \new Staff << \global \viola >>
439 \new Staff << \global \cello >>
448 @node Vocal ensembles
449 @section Vocal ensembles
451 @subsection SATB vocal score
453 Here is a standard four-part SATB vocal score. With larger ensembles,
454 it's often useful to include a section which is included in all
455 parts. For example, the time signature and key signatures are almost
456 always the same for all parts.
458 @lilypond[verbatim,raggedright]
466 sopMusic = \relative c'' {
469 sopWords = \lyricmode {
473 altoMusic = \relative c' {
476 altoWords =\lyricmode {
480 tenorMusic = \relative c' {
483 tenorWords = \lyricmode {
487 bassMusic = \relative c {
490 bassWords = \lyricmode {
495 \context ChoirStaff <<
496 \context Lyrics = sopranos { s1 }
497 \context Staff = women <<
498 \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
499 \context Voice = altos { \voiceTwo << \global \altoMusic >> }
501 \context Lyrics = altos { s1 }
502 \context Lyrics = tenors { s1 }
503 \context Staff = men <<
505 \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
506 \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
508 \context Lyrics = basses { s1 }
509 \context Lyrics = sopranos \lyricsto sopranos \sopWords
510 \context Lyrics = altos \lyricsto altos \altoWords
511 \context Lyrics = tenors \lyricsto tenors \tenorWords
512 \context Lyrics = basses \lyricsto basses \bassWords
517 % a little smaller so lyrics can be closer to the staff.
518 \Staff minimumVerticalExtent = #'(-3 . 3)
526 @c bad node name to avoid node name confict
527 @node Ancient notation templates
528 @section Ancient notation templates
530 @subsection Transcription of mensural music
532 When transcribing mensural music, an incipit at the beginning of the
533 piece is useful to indicate the original key and tempo. While today
534 musicians are used to bar lines in order to faster recognize rhythmic
535 patterns, bar lines where not yet invented during the period of
536 mensural music; in fact, the meter often changed after every few
537 notes. As a compromise, bar lines are often printed between the
538 staves rather than on the staves.
540 @lilypond[verbatim,raggedright]
546 \once \override Score.SystemStartBracket #'transparent = ##t
549 \once \override Staff.TimeSignature #'style = #'neomensural
550 \override Voice.NoteHead #'style = #'neomensural
551 \override Voice.Rest #'style = #'neomensural
552 \set Staff.printKeyCancellation = ##f
553 \cadenzaOn % turn off bar lines
555 \once \override Staff.BarLine #'transparent = ##f
557 \skip 1*1 % need this extra \skip such that clef change comes
562 \cadenzaOff % turn bar lines on again
563 \once \override Staff.Clef #'full-size-change = ##t
564 \set Staff.forceClef = ##t
567 \override Voice.NoteHead #'style = #'default
568 \override Voice.Rest #'style = #'default
570 % FIXME: setting printKeyCancellation back to #t must not
571 % occur in the first bar after the incipit. Dto. for forceClef.
572 % Therefore, we need an extra \skip.
574 \set Staff.printKeyCancellation = ##t
575 \set Staff.forceClef = ##f
579 % last bar contains a brevis (i.e. spans 2 bars);
580 % therefore do not draw this particular bar
585 % let finis bar go through all staves
586 \override Staff.BarLine #'transparent = ##f
594 \set Staff.instrument = "Discantus "
597 \clef "neomensural-c1"
599 \skip 1*8 % eight bars
609 \once \override NoteHead #'transparent = ##t c'1 |
614 discantusLyrics = \lyricmode {
630 \set Staff.instrument = "Altus "
633 \clef "neomensural-c3"
636 \skip 1*7 % seven bars
641 r2 g2. e4 fis g | % two bars
643 fis g4.( fis16 e fis4) |
645 \once \override NoteHead #'transparent = ##t g1 |
650 altusLyrics = \lyricmode {
655 Ju -- bi -- la -- te | % two bars
664 \set Staff.instrument = "Tenor "
667 \clef "neomensural-c4"
680 r2 d'2. d'4 b e' | % two bars
681 \once \override NoteHead #'transparent = ##t e'1 |
686 tenorLyrics = \lyricmode {
691 Ju -- bi -- la -- te | % two bars
698 \set Staff.instrument = "Bassus "
702 r\maxima % eight bars
713 \once \override NoteHead #'transparent = ##t e1 |
718 bassusLyrics = \lyricmode {
729 \context StaffGroup = choirStaff <<
730 \context Voice = discantusNotes << \global \discantusNotes >>
731 \context Lyrics = discantusLyrics \lyricsto discantusNotes { \discantusLyrics }
732 \context Voice = altusNotes << \global \altusNotes >>
733 \context Lyrics = altusLyrics \lyricsto altusNotes { \altusLyrics }
734 \context Voice = tenorNotes << \global \tenorNotes >>
735 \context Lyrics = tenorLyrics \lyricsto tenorNotes { \tenorLyrics }
736 \context Voice = bassusNotes << \global \bassusNotes >>
737 \context Lyrics = bassusLyrics \lyricsto bassusNotes { \bassusLyrics }
742 \override BarLine #'transparent = ##t
743 \remove "System_start_delimiter_engraver"
747 \override Slur #'transparent = ##t
759 This is a much more complicated template, for a jazz ensemble. Note that all
760 instruments are notated @code{\key c \major}. This refers to the key in
761 concert pitch; LilyPond will automatically transpose the key if the music
762 is within a @code{\transpose} section.
764 @c TODO must clean up this jazz combo example
765 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
766 @c - one global section, instead of "global" (time) and "key"
767 @c - does it need those wierd macros? sl, nsl, etc.
768 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
769 @c make whatever changes I feel like.
771 @c FIXME: produces a warning ; key change merge.
773 @lilypond[verbatim,raggedright]
782 tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
783 texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
786 #(set-global-staff-size 16)
787 \include "english.ly"
789 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
792 \override NoteHead #'style = #'slash
793 \override Stem #'transparent = ##t
796 \revert NoteHead #'style
797 \revert Stem #'transparent
799 cr = \override NoteHead #'style = #'cross
800 ncr = \revert NoteHead #'style
802 %% insert chord name style stuff here.
807 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
813 Key = { \key c \major }
815 % ############ Horns ############
816 % ------ Trumpet ------
817 trpt = \transpose c d \relative c'' {
822 trpharmony = \transpose c' d { \jzchords }
825 \set Staff.instrument = #"Trumpet"
832 % ------ Alto Saxophone ------
833 alto = \transpose c a \relative c' {
838 altoharmony = \transpose c' a { \jzchords }
841 \set Staff.instrument = #"Alto Sax"
848 % ------ Baritone Saxophone ------
849 bari = \transpose c a' \relative c {
851 c1 c \sl d4^"Solo" d d d \nsl
854 bariharmony = \transpose c' a \chordmode { \jzchords s1 s d2:maj e:m7 }
857 \set Staff.instrument = #"Bari Sax"
863 % ------ Trombone ------
864 tbone = \relative c {
869 tboneharmony = \chordmode { \jzchords }
872 \set Staff.instrument = #"Trombone"
878 % ############ Rhythm Section #############
879 % ------ Guitar ------
880 gtr = \relative c'' {
882 c1 \sl b4 b b b \nsl c1
885 gtrharmony = \chordmode { \jzchords
891 \set Staff.instrument = #"Guitar"
898 %% ------ Piano ------
899 rhUpper = \relative c'' {
905 rhLower = \relative c' {
911 lhUpper = \relative c' {
917 lhLower = \relative c {
926 \set Staff.midiInstrument = "acoustic grand"
928 \context Voice = one \rhUpper
929 \context Voice = two \rhLower
936 \set Staff.midiInstrument = "acoustic grand"
938 \context Voice = one \lhUpper
939 \context Voice = two \lhLower
944 \context PianoStaff <<
945 \set PianoStaff.instrument = #"Piano"
946 \context Staff = upper \PianoRH
947 \context Staff = lower \PianoLH
951 % ------ Bass Guitar ------
959 \set Staff.instrument = #"Bass"
966 % ------ Drums ------
969 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
976 bd4 s bd s bd s bd s bd s bd s
982 \set DrumStaff.instrument = #"Drums"
983 \new DrumVoice { \voiceOne \up }
984 \new DrumVoice { \voiceTwo \down }
988 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
992 \context StaffGroup = horns <<
993 \context Staff = trumpet \trumpet
995 \context Staff = altosax \altosax
997 \context ChordNames = barichords \bariharmony
999 \context Staff = barisax \barisax
1001 \context Staff = trombone \trombone
1004 \context StaffGroup = rhythm <<
1005 \context ChordNames = chords \gtrharmony
1006 \context Staff = guitar \guitar
1007 \context PianoStaff = piano \piano
1009 \context Staff = bass \bass
1011 \new DrumStaff { \drumContents }
1015 \context { \RemoveEmptyStaffContext }
1018 \override BarNumber #'padding = #3
1019 \override RehearsalMark #'padding = #2
1023 \midi { \tempo 4 = 75 }
1028 @node Other templates
1029 @section Other templates
1030 @subsection All headers
1032 This template displays all available headers. Some of them are only
1033 used in the Mutopia project; they don't affect the printed output at
1034 all. They are used if you want the piece to be listed with different
1035 information in the Mutopia database than you wish to have printed on the
1036 music. For example, Mutopia lists the composer of the famous D major
1037 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
1038 "Petr Tchaikowski" on your music.
1040 @lilypond[verbatim,raggedright]
1044 dedication = "dedication"
1046 subtitle = "Subtitle"
1047 subsubtitle = "Subsubtitle"
1048 composer = "Composer (xxxx-yyyy)"
1051 instrument = "Instrument"
1052 arranger = "Arranger"
1054 texttranslator = "Translator"
1055 copyright = "public domain"
1057 % These are headers used by the Mutopia Project http://www.mutopiaproject.org/
1059 mutopiacomposer = ""
1061 mutopiainstrument = ""
1062 date = "composer's dates"
1064 maintainer = "your name here"
1065 maintainerEmail = "your email here"
1066 maintainerWeb = "your home page"
1067 lastupdated = "2004/Aug/26"
1088 @subsection Gregorian template
1090 This example demonstrates how to do modern transcriptions of Gregorian
1091 music. Gregorian music has no measure, no stems; it uses only half and
1092 quarter notes, and two types of barlines, a short one indicating a rest,
1093 and a second one indicating a breath mark.
1095 @lilypond[verbatim,raggedright]
1097 barOne = { \once \override Staff.BarLine #'bar-size = #2
1099 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
1100 \once \override Staff.BarLine #'bar-size = #2
1102 chant = \relative c' {
1103 \set Score.timing = ##f
1104 \override Staff.Stem #'transparent = ##t
1113 \midi { \tempo 4=60 }
1118 @subsection Bagpipe music
1120 Here is an example of bagpipe music. It demonstrates a big strength of
1121 LilyPond, compared to graphical score editors: in LilyPond, you can
1122 very easily reuse small segments of music without writing them out
1123 completely. This template defines a large number of small segments
1124 (@code{taor, grip, thrd,} etc), which can be reused easily.
1126 TODO - replace Bagpipe template with Andrew McNabb's work?
1128 @lilypond[verbatim,raggedright]
1130 taor = { \grace { g32[ d' g e'] } }
1131 grip = { \grace { g32[ b g ] } }
1132 thrd = { \grace { g32[ d' c'] } }
1133 birl = { \grace { g32[ a g] } }
1134 gstd = { \grace { g'32[ d' g] } }
1135 fgg = { \grace { f32[ g'32] } }
1136 dblb = { \grace { g'32[ b d'] } }
1137 dblc = { \grace { g'32[ c' d'] } }
1138 dble = { \grace { g'32[ e' f'] } }
1139 dblf = { \grace { g'32[ f' g'] } }
1140 dblg = { \grace { g'32[ f'] } }
1141 dbla = { \grace { a'32[ g'] } }
1142 lgg = { \grace { g32 } }
1143 lag = { \grace { a32 } }
1144 cg = { \grace { c'32 } }
1145 eg = { \grace { e'32 } }
1146 gg = { \grace { g'32 } }
1147 dg = { \grace { d'32 } }
1148 hag = { \grace { a'32 } }
1149 gefg = { \grace { g'32[ e' f'] } }
1150 efg = { \grace { e'32[ f'] } }
1151 gdcg = { \grace { g'32[ d' c'] } }
1152 gcdg = { \grace { g'32[ c' d'] } }
1155 #(add-grace-property 'Voice 'Stem 'length 6)
1156 \time 6/8 \partial 4
1161 \gg f'4 e'8 \thrd d'4. |
1163 \gg d'4 f'8 \dble e'4. ( | \noBreak
1164 e'8) d'4 \gg d'4 e'8 |
1168 \dblf f'2.( f'4) d'8 |
1170 \dblg g'4 a'8 \gg a'4. |
1171 \thrd d'4.( d'4) \eg a8 |
1173 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
1177 \gg f'4 e'8 \thrd d'4. |
1179 \dblg g'4 a'8 \gg a'4. |
1180 \thrd d'4.( d'4) f'8 |
1183 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
1184 \thrd d'4.( d'4) \cg d'8 |
1185 \gg c'4 e'8 \thrd d'4.( |
1193 @node Lilypond-book templates
1194 @section Lilypond-book templates
1196 These templates are for use with @code{lilypond-book}. If you're not familiar
1197 with this program, please refer to @ref{Integrating text and music}.
1201 You can include LilyPond fragments in a LaTeX document.
1204 \documentclass[]@{article@}
1227 You can include LilyPond fragments in texinfo; in fact, this entire manual
1228 is written in texinfo.
1230 TODO: obviously to fill in the example. :) -gp