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 "x.y.z"} 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 = \chords {
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 = \chords {
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'' {
323 altoMusic = \relative c' {
330 tenorMusic = \relative c' {
333 tenorWords = \lyrics {
337 bassMusic = \relative c {
340 bassWords = \lyrics {
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 @lilypond[verbatim,raggedright]
446 tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
447 texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
450 #(set-global-staff-size 16)
451 \include "english.ly"
453 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
456 \override NoteHead #'style = #'slash
457 \override Stem #'transparent = ##t
460 \revert NoteHead #'style
461 \revert Stem #'transparent
463 cr = \override NoteHead #'style = #'cross
464 ncr = \revert NoteHead #'style
466 %% insert chord name style stuff here.
471 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
477 Key = { \key c \major }
479 % ############ Horns ############
480 % ------ Trumpet ------
481 trpt = \transpose c d \relative c'' {
486 trpharmony = \transpose c' d { \jzchords }
489 \set Staff.instrument = #"Trumpet"
496 % ------ Alto Saxophone ------
497 alto = \transpose c a \relative c' {
502 altoharmony = \transpose c' a { \jzchords }
505 \set Staff.instrument = #"Alto Sax"
512 % ------ Baritone Saxophone ------
513 bari = \transpose c a' \relative c {
515 c1 c \sl d4^"Solo" d d d \nsl
518 bariharmony = \transpose c' a \chords { \jzchords s1 s d2:maj e:m7 }
521 \set Staff.instrument = #"Bari Sax"
527 % ------ Trombone ------
528 tbone = \relative c {
533 tboneharmony = \chords { \jzchords }
536 \set Staff.instrument = #"Trombone"
542 % ############ Rhythm Section #############
543 % ------ Guitar ------
544 gtr = \relative c'' {
546 c1 \sl b4 b b b \nsl c1
549 gtrharmony = \chords { \jzchords
555 \set Staff.instrument = #"Guitar"
562 %% ------ Piano ------
563 rhUpper = \relative c'' {
569 rhLower = \relative c' {
575 lhUpper = \relative c' {
581 lhLower = \relative c {
590 \set Staff.midiInstrument = "acoustic grand"
592 \context Voice = one \rhUpper
593 \context Voice = two \rhLower
600 \set Staff.midiInstrument = "acoustic grand"
602 \context Voice = one \lhUpper
603 \context Voice = two \lhLower
608 \context PianoStaff <<
609 \set PianoStaff.instrument = #"Piano"
610 \context Staff = upper \PianoRH
611 \context Staff = lower \PianoLH
615 % ------ Bass Guitar ------
623 \set Staff.instrument = #"Bass"
630 % ------ Drums ------
633 hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
640 bd4 s bd s bd s bd s bd s bd s
646 \set DrumStaff.instrument = #"Drums"
647 \new DrumVoice { \voiceOne \up }
648 \new DrumVoice { \voiceTwo \down }
652 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
656 \context StaffGroup = horns <<
657 \context Staff = trumpet \trumpet
659 \context Staff = altosax \altosax
661 \context ChordNames = barichords \bariharmony
663 \context Staff = barisax \barisax
665 \context Staff = trombone \trombone
668 \context StaffGroup = rhythm <<
669 \context ChordNames = chords \gtrharmony
670 \context Staff = guitar \guitar
671 \context PianoStaff = piano \piano
673 \context Staff = bass \bass
675 \new DrumStaff { \drumContents }
679 \context { \RemoveEmptyStaffContext }
682 \override BarNumber #'padding = #3
683 \override RehearsalMark #'padding = #2
687 \midi { \tempo 4 = 75 }
692 @node Other templates
693 @section Other templates
694 @subsection All headers
696 This template displays all available headers. Some of them are only
697 used in the Mutopia project; they don't affect the printed output at
698 all. They are used if you want the piece to be listed with different
699 information in the Mutopia database than you wish to have printed on the
700 music. For example, Mutopia lists the composer of the famous D major
701 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
702 "Petr Tchaikowski" on your music.
704 @lilypond[verbatim,raggedright]
708 dedication = "dedication"
710 subtitle = "Subtitle"
711 subsubtitle = "Subsubtitle"
712 composer = "Composer (xxxx-yyyy)"
715 instrument = "Instrument"
716 arranger = "Arranger"
718 texttranslator = "Translator"
719 copyright = "public domain"
721 % These are headers used by the Mutopia Project http://www.mutopiaproject.org/
725 mutopiainstrument = ""
726 date = "composer's dates"
728 maintainer = "your name here"
729 maintainerEmail = "your email here"
730 maintainerWeb = "your home page"
731 lastupdated = "2004/Aug/26"
752 @subsection Gregorian template
754 This example demonstrates how to do modern transcriptions of Gregorian
755 music. Gregorian music has no measure, no stems; it uses only half and
756 quarter notes, and two types of barlines, a short one indicating a rest,
757 and a second one indicating a breath mark.
759 @lilypond[verbatim,raggedright]
761 barOne = { \once \override Staff.BarLine #'bar-size = #2
763 barTwo = { \once \override Staff.BarLine #'extra-offset = #'(0 . 2)
764 \once \override Staff.BarLine #'bar-size = #2
766 chant = \relative c' {
767 \set Score.timing = ##f
768 \override Staff.Stem #'transparent = ##t
777 \midi { \tempo 4=60 }
782 @subsection Bagpipe music
784 Here's an example of bagpipe music. It demonstrates a big strength of
785 LilyPond, compared to graphical score editors: in LilyPond, you can
786 very easily reuse small segments of music without writing them out
787 completely. This template defines a large number of small segments
788 (@code{taor, grip, thrd,} etc), which can be reused easily.
790 TODO - replace Bagpipe template with Andrew McNabb's work?
792 @lilypond[verbatim,raggedright]
794 taor = { \grace { g32[ d' g e'] } }
795 grip = { \grace { g32[ b g ] } }
796 thrd = { \grace { g32[ d' c'] } }
797 birl = { \grace { g32[ a g] } }
798 gstd = { \grace { g'32[ d' g] } }
799 fgg = { \grace { f32[ g'32] } }
800 dblb = { \grace { g'32[ b d'] } }
801 dblc = { \grace { g'32[ c' d'] } }
802 dble = { \grace { g'32[ e' f'] } }
803 dblf = { \grace { g'32[ f' g'] } }
804 dblg = { \grace { g'32[ f'] } }
805 dbla = { \grace { a'32[ g'] } }
806 lgg = { \grace { g32 } }
807 lag = { \grace { a32 } }
808 cg = { \grace { c'32 } }
809 eg = { \grace { e'32 } }
810 gg = { \grace { g'32 } }
811 dg = { \grace { d'32 } }
812 hag = { \grace { a'32 } }
813 gefg = { \grace { g'32[ e' f'] } }
814 efg = { \grace { e'32[ f'] } }
815 gdcg = { \grace { g'32[ d' c'] } }
816 gcdg = { \grace { g'32[ c' d'] } }
819 #(add-grace-property 'Voice 'Stem 'length 6)
825 \gg f'4 e'8 \thrd d'4. |
827 \gg d'4 f'8 \dble e'4. ( | \noBreak
828 e'8) d'4 \gg d'4 e'8 |
832 \dblf f'2.( f'4) d'8 |
834 \dblg g'4 a'8 \gg a'4. |
835 \thrd d'4.( d'4) \eg a8 |
837 \dble e'4 \lag e'8 \gg e'16[ d'8. e'8] \gg f'4 g'8 |
841 \gg f'4 e'8 \thrd d'4. |
843 \dblg g'4 a'8 \gg a'4. |
844 \thrd d'4.( d'4) f'8 |
847 \dblg g'4 e'8( e'8) \dblf f'8.[ e'16] |
848 \thrd d'4.( d'4) \cg d'8 |
849 \gg c'4 e'8 \thrd d'4.( |