1 @node Example templates
2 @chapter Example templates
4 This section of the manual contains templates with the LilyPond score
5 already set up for you. Just add notes, run LilyPond, and enjoy
6 beautiful printed scores!
9 * Suggestions for writing LilyPond files::
17 @c TODO explain \score{} ? Maybe add a note to the tutorial?
19 @node Suggestions for writing LilyPond files
20 @section Suggestions for writing LilyPond files
22 Now you're ready to begin writing bigger LilyPond files -- not just the
23 little examples in the tutorial, but whole pieces. But how should you
26 The best answer is ``however you want to do it''. As long as LilyPond
27 can understand your files and produces the output that you want, it
28 doesn't matter what your files look like. That said, sometimes we
29 make mistakes when writing files. If LilyPond can't understand your
30 files, or produces output that you don't like, how do you fix the
33 Here are a few suggestions that can help you in avoiding or fixing
37 @item Include @code{\version} numbers in every file. Note that all
38 templates contain a @code{\version "2.3.16"} string. We
39 highly recommend that you always include the @code{\version}, no matter
40 how small your file is. Speaking from personal experience, it's
41 quite frustrating to try to remember which version of LilyPond you were
42 using a few years ago. @code{convert-ly} requires you to declare
43 which version of LilyPond you used.
45 @item Include checks: See @ref{Bar check} and @ref{Octave check}. If you
46 include checks every so often, then if you make a mistake, you can pinpoint
47 it quicker. How often is ``every so often''? It depends on the complexity
48 of the music. For very simple music, perhaps just once or twice. For
49 very complex music, every bar.
51 @item One bar per line. If there's anything complicated, either in the music
52 itself or in the output you desire, it's often good to write only one bar
53 per line. Saving screen space by cramming eight bars per line just isn't
54 worth it if you have to `debug' your files.
56 @item Comment your files, with either bar numbers (every so often) or
57 references to musical themes (``second theme in violins'', ``fourth
58 variation''). You may not need it when you're writing the piece for
59 the first time, but if you want to go back and change something two
60 or three years later, you won't know how your file is structured if you
61 don't comment the file.
67 @subsection Notes only
69 The first example gives you a staff with notes, suitable for a solo
70 instrument or a melodic fragment. Cut and paste this into a file,
71 add notes, and you're finished!
73 @lilypond[verbatim,raggedright]
76 melody = \relative c' {
92 @subsection Notes and lyrics
94 The next example demonstrates a simple melody with lyrics. Cut and
95 paste, add notes, then words for the lyrics. This example turns off
96 automatic beaming, which is common for vocal parts. If you want to use
97 automatic beaming, you'll have to change or comment out the relevant
100 @lilypond[verbatim,raggedright]
103 melody = \relative c' {
117 \context Voice = one {
121 \lyricsto "one" \new Lyrics \text
124 \midi { \tempo 4=60 }
129 @subsection Notes and chords
131 Want to prepare a lead sheet with a melody and chords? Look no farther!
133 @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
164 @subsection Notes, lyrics, and chords.
166 This template allows you to prepare a song with melody, words, and chords.
168 @lilypond[verbatim,raggedright]
171 melody = \relative c' {
183 harmonies = \chordmode {
189 \context ChordNames {
190 \set chordChanges = ##t
193 \context Voice = one {
197 \lyricsto "one" \new Lyrics \text
205 @node Piano templates
206 @section Piano templates
207 @subsection Solo piano
209 Here's a simple piano staff.
211 @lilypond[verbatim,raggedright]
214 upper = \relative c'' {
222 lower = \relative c {
231 \context PianoStaff <<
232 \set PianoStaff.instrument = "Piano "
233 \context Staff = upper \upper
234 \context Staff = lower \lower
237 \midi { \tempo 4=60 }
242 @subsection Piano and melody with lyrics
244 Here's a typical song format: one staff with the melody and lyrics, with
245 piano accompaniment underneath.
247 @lilypond[verbatim,raggedright]
250 melody = \relative c'' {
262 upper = \relative c'' {
270 lower = \relative c {
280 \context Voice = mel {
284 \lyricsto mel \new Lyrics \text
286 \context PianoStaff <<
287 \context Staff = upper \upper
288 \context Staff = lower \lower
292 \context { \RemoveEmptyStaffContext }
299 @node Small ensembles
300 @section Small ensembles
301 @subsection SATB vocal score
303 Here's a standard four-part SATB vocal score. With larger ensembles,
304 it's often useful to include a section which is included in all
305 parts. For example, the time signature and key signatures are almost
306 always the same for all parts.
308 @lilypond[verbatim,raggedright]
316 sopMusic = \relative c'' {
319 sopWords = \lyricmode {
323 altoMusic = \relative c' {
326 altoWords =\lyricmode {
330 tenorMusic = \relative c' {
333 tenorWords = \lyricmode {
337 bassMusic = \relative c {
340 bassWords = \lyricmode {
345 \context ChoirStaff <<
346 \context Lyrics = sopranos { s1 }
347 \context Staff = women <<
348 \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
349 \context Voice = altos { \voiceTwo << \global \altoMusic >> }
351 \context Lyrics = altos { s1 }
352 \context Lyrics = tenors { s1 }
353 \context Staff = men <<
355 \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
356 \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
358 \context Lyrics = basses { s1 }
359 \context Lyrics = sopranos \lyricsto sopranos \sopWords
360 \context Lyrics = altos \lyricsto altos \altoWords
361 \context Lyrics = tenors \lyricsto tenors \tenorWords
362 \context Lyrics = basses \lyricsto basses \bassWords
367 % a little smaller so lyrics can be closer to the staff.
368 \Staff minimumVerticalExtent = #'(-3 . 3)
375 @subsection String quartet
377 This template demonstrates a string quartet. It also uses a @code{\global}
378 section for time and key signatures.
380 @lilypond[verbatim,raggedright]
387 violinOne = \relative c''{
388 \set Staff.instrument = "Violin 1 "
392 violinTwo = \relative c''{
393 \set Staff.instrument = "Violin 2 "
397 viola = \relative c'{
398 \set Staff.instrument = "Viola "
403 cello = \relative c'{
404 \set Staff.instrument = "Cello "
411 \new Staff << \global \violinOne >>
412 \new Staff << \global \violinTwo >>
413 \new Staff << \global \viola >>
414 \new Staff << \global \cello >>
425 This is a much more complicated template, for a jazz ensemble. Note that all
426 instruments are notated @code{\key c \major}. This refers to the key in
427 concert pitch; LilyPond will automatically transpose the key if the music
428 is within a @code{\transpose} section.
430 @c TODO must clean up this jazz combo example
431 @c - transpositions stated in names (ie "trumpet in Bb" or whatever)
432 @c - one global section, instead of "global" (time) and "key"
433 @c - does it need those wierd macros? sl, nsl, etc.
434 @c - maybe ask Amelie Zapf to clean it up, or whether I should just
435 @c make whatever changes I feel like.
437 @c FIXME: produces a warning ; key change merge.
439 @lilypond[verbatim,raggedright]
448 tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
449 texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
452 #(set-global-staff-size 16)
453 \include "english.ly"
455 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
458 \override NoteHead #'style = #'slash
459 \override Stem #'transparent = ##t
462 \revert NoteHead #'style
463 \revert Stem #'transparent
465 cr = \override NoteHead #'style = #'cross
466 ncr = \revert NoteHead #'style
468 %% insert chord name style stuff here.
473 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
479 Key = { \key c \major }
481 % ############ Horns ############
482 % ------ Trumpet ------
483 trpt = \transpose c d \relative c'' {
488 trpharmony = \transpose c' d { \jzchords }
491 \set Staff.instrument = #"Trumpet"
498 % ------ Alto Saxophone ------
499 alto = \transpose c a \relative c' {
504 altoharmony = \transpose c' a { \jzchords }
507 \set Staff.instrument = #"Alto Sax"
514 % ------ Baritone Saxophone ------
515 bari = \transpose c a' \relative c {
517 c1 c \sl d4^"Solo" d d d \nsl
520 bariharmony = \transpose c' a \chordmode { \jzchords s1 s d2:maj e:m7 }
523 \set Staff.instrument = #"Bari Sax"
529 % ------ Trombone ------
530 tbone = \relative c {
535 tboneharmony = \chordmode { \jzchords }
538 \set Staff.instrument = #"Trombone"
544 % ############ Rhythm Section #############
545 % ------ Guitar ------
546 gtr = \relative c'' {
548 c1 \sl b4 b b b \nsl c1
551 gtrharmony = \chordmode { \jzchords
557 \set Staff.instrument = #"Guitar"
564 %% ------ Piano ------
565 rhUpper = \relative c'' {
571 rhLower = \relative c' {
577 lhUpper = \relative c' {
583 lhLower = \relative c {
592 \set Staff.midiInstrument = "acoustic grand"
594 \context Voice = one \rhUpper
595 \context Voice = two \rhLower
602 \set Staff.midiInstrument = "acoustic grand"
604 \context Voice = one \lhUpper
605 \context Voice = two \lhLower
610 \context PianoStaff <<
611 \set PianoStaff.instrument = #"Piano"
612 \context Staff = upper \PianoRH
613 \context Staff = lower \PianoLH
617 % ------ Bass Guitar ------
625 \set Staff.instrument = #"Bass"
632 % ------ Drums ------
635 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
642 bd4 s bd s bd s bd s bd s bd s
648 \set DrumStaff.instrument = #"Drums"
649 \new DrumVoice { \voiceOne \up }
650 \new DrumVoice { \voiceTwo \down }
654 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
658 \context StaffGroup = horns <<
659 \context Staff = trumpet \trumpet
661 \context Staff = altosax \altosax
663 \context ChordNames = barichords \bariharmony
665 \context Staff = barisax \barisax
667 \context Staff = trombone \trombone
670 \context StaffGroup = rhythm <<
671 \context ChordNames = chords \gtrharmony
672 \context Staff = guitar \guitar
673 \context PianoStaff = piano \piano
675 \context Staff = bass \bass
677 \new DrumStaff { \drumContents }
681 \context { \RemoveEmptyStaffContext }
684 \override BarNumber #'padding = #3
685 \override RehearsalMark #'padding = #2
689 \midi { \tempo 4 = 75 }
694 @node Other templates
695 @section Other templates
696 @subsection All headers
698 This template displays all available headers. Some of them are only
699 used in the Mutopia project; they don't affect the printed output at
700 all. They are used if you want the piece to be listed with different
701 information in the Mutopia database than you wish to have printed on the
702 music. For example, Mutopia lists the composer of the famous D major
703 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
704 "Petr Tchaikowski" on your music.
706 @lilypond[verbatim,raggedright]
710 dedication = "dedication"
712 subtitle = "Subtitle"
713 subsubtitle = "Subsubtitle"
714 composer = "Composer (xxxx-yyyy)"
717 instrument = "Instrument"
718 arranger = "Arranger"
720 texttranslator = "Translator"
721 copyright = "public domain"
723 % These are headers used by the Mutopia Project http://www.mutopiaproject.org/
727 mutopiainstrument = ""
728 date = "composer's dates"
730 maintainer = "your name here"
731 maintainerEmail = "your email here"
732 maintainerWeb = "your home page"
733 lastupdated = "2004/Aug/26"
754 @subsection Gregorian template
756 This example demonstrates how to do modern transcriptions of Gregorian
757 music. Gregorian music has no measure, no stems; it uses only half and
758 quarter notes, and two types of barlines, a short one indicating a rest,
759 and a second one indicating a breath mark.
761 @lilypond[verbatim,raggedright]
763 barOne = { \once \override Staff.BarLine #'bar-size = #2
765 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
766 \once \override Staff.BarLine #'bar-size = #2
768 chant = \relative c' {
769 \set Score.timing = ##f
770 \override Staff.Stem #'transparent = ##t
779 \midi { \tempo 4=60 }
784 @subsection Bagpipe music
786 Here's an example of bagpipe music. It demonstrates a big strength of
787 LilyPond, compared to graphical score editors: in LilyPond, you can
788 very easily reuse small segments of music without writing them out
789 completely. This template defines a large number of small segments
790 (@code{taor, grip, thrd,} etc), which can be reused easily.
792 TODO - replace Bagpipe template with Andrew McNabb's work?
794 @lilypond[verbatim,raggedright]
796 taor = { \grace { g32[ d' g e'] } }
797 grip = { \grace { g32[ b g ] } }
798 thrd = { \grace { g32[ d' c'] } }
799 birl = { \grace { g32[ a g] } }
800 gstd = { \grace { g'32[ d' g] } }
801 fgg = { \grace { f32[ g'32] } }
802 dblb = { \grace { g'32[ b d'] } }
803 dblc = { \grace { g'32[ c' d'] } }
804 dble = { \grace { g'32[ e' f'] } }
805 dblf = { \grace { g'32[ f' g'] } }
806 dblg = { \grace { g'32[ f'] } }
807 dbla = { \grace { a'32[ g'] } }
808 lgg = { \grace { g32 } }
809 lag = { \grace { a32 } }
810 cg = { \grace { c'32 } }
811 eg = { \grace { e'32 } }
812 gg = { \grace { g'32 } }
813 dg = { \grace { d'32 } }
814 hag = { \grace { a'32 } }
815 gefg = { \grace { g'32[ e' f'] } }
816 efg = { \grace { e'32[ f'] } }
817 gdcg = { \grace { g'32[ d' c'] } }
818 gcdg = { \grace { g'32[ c' d'] } }
821 #(add-grace-property 'Voice 'Stem 'length 6)
827 \gg f'4 e'8 \thrd d'4. |
829 \gg d'4 f'8 \dble e'4. ( | \noBreak
830 e'8) d'4 \gg d'4 e'8 |
834 \dblf f'2.( f'4) d'8 |
836 \dblg g'4 a'8 \gg a'4. |
837 \thrd d'4.( d'4) \eg a8 |
839 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
843 \gg f'4 e'8 \thrd d'4. |
845 \dblg g'4 a'8 \gg a'4. |
846 \thrd d'4.( d'4) f'8 |
849 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
850 \thrd d'4.( d'4) \cg d'8 |
851 \gg c'4 e'8 \thrd d'4.( |