]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/examples.itely
minor editing.
[lilypond.git] / Documentation / user / examples.itely
1 @node Example templates
2 @chapter Example templates
3
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!
7
8 Note that all templates contain a @code{\version "x.y.z"} string.  We
9 highly recommend that you always include the @code{\version}, no matter
10 how small your file is.  Speaking from personal experience, it's
11 quite frustrating to try to remember which version of LilyPond you were
12 using a few years ago.  @code{convert-ly} requires you to declare
13 which version of LilyPond you used.
14
15 @menu
16 * Single staff::
17 * Piano templates::
18 * Small ensembles::
19 * Jazz combo::
20 * Other templates::
21 @end menu
22
23 @c   more sections to come soon.
24 @c  make a note about the \score{} stuff?  It might make more sense
25 @c  to note that in the tutorial, and reserve this section purely
26 @c  for templates.  -GP
27
28
29 @node Single staff
30 @section Single staff
31 @subsection Notes only
32
33 The first example gives you a staff with notes, suitable for a solo
34 instrument or a melodic fragment.  Cut and paste this into a file,
35 add notes, and you're finished!
36
37 @lilypond[verbatim,raggedright]
38
39 \version "2.3.11"
40 melody = \relative c' {
41 \clef treble
42 \key c \major
43 \time 4/4
44
45   a4 b c d
46 }
47
48 \score{
49   \new Staff \melody
50   \paper { }
51   \midi { \tempo 4=60 }
52 }
53
54 @end lilypond
55
56 @subsection Notes and lyrics
57
58 The next example demonstrates a simple melody with lyrics.  Cut and
59 paste, add notes, then words for the lyrics.  This example turns off
60 automatic beaming, which is common for vocal parts.  If you want to use
61 automatic beaming, you'll have to change or comment out the relevant
62 line.
63
64 @lilypond[verbatim,raggedright]
65
66 \version "2.3.11"
67 melody = \relative c' {
68 \clef treble
69 \key c \major
70 \time 4/4
71
72   a4 b c d
73 }
74
75 text = \lyrics {
76   Aaa Bee Cee Dee
77 }
78
79 \score{
80   <<
81     \context Voice = one {
82       \autoBeamOff
83       \melody
84       }
85     \lyricsto "one" \new Lyrics \text
86   >>
87   \paper { }
88   \midi { \tempo 4=60 }
89 }
90
91 @end lilypond
92
93 @subsection Notes and chords
94
95 Want to prepare a lead sheet with a melody and chords?  Look no farther!
96
97 @lilypond[verbatim,raggedright]
98
99 \version "2.3.11"
100 melody =  \relative c' {
101 \clef treble
102 \key c \major
103 \time 4/4
104
105   f4 e8[ c] d4 g |
106   a2 ~ a2 |
107 }
108
109 harmonies = \chords {
110   c4:m f:min7 g:maj c:aug d2:dim b:sus
111 }
112
113 \score {
114    <<
115     \context ChordNames {
116         \set chordChanges = ##t
117         \harmonies
118     }
119     \context Staff = one \melody
120   >>
121
122   \paper{ }
123   \midi  { \tempo 4=60}
124 }
125
126 @end lilypond
127
128 @subsection Notes, lyrics, and chords.
129
130 This template allows you to prepare a song with melody, words, and chords.
131
132 @lilypond[verbatim,raggedright]
133
134 \version "2.3.11"
135 melody =  \relative c' {
136 \clef treble
137 \key c \major
138 \time 4/4
139
140     a b c d
141 }
142
143 text = \lyrics {
144     Aaa Bee Cee Dee
145 }
146
147 harmonies = \chords {
148     a2 c2
149 }
150
151 \score {
152   <<
153     \context ChordNames {
154         \set chordChanges = ##t
155         \harmonies
156     }
157     \context Voice = one {
158         \autoBeamOff
159         \melody
160     }
161     \lyricsto "one" \new Lyrics \text
162   >>
163   \paper { }
164   \midi  { \tempo 4=60}
165 }
166
167 @end lilypond
168
169 @node Piano templates
170 @section Piano templates
171 @subsection Solo piano
172
173 Here's a simple piano staff.
174
175 @lilypond[verbatim,raggedright]
176
177 \version "2.3.11"
178 upper = \relative c'' {
179 \clef treble
180 \key c \major
181 \time 4/4
182
183   a b c d
184 }
185
186 lower = \relative c {
187 \clef bass
188 \key c \major
189 \time 4/4
190
191   a2 c
192 }
193
194 \score {
195   \context PianoStaff <<
196     \set PianoStaff.instrument = "Piano  "
197     \context Staff = upper \upper
198     \context Staff = lower \lower
199     >>  
200   \paper { }  
201   \midi { \tempo 4=60 }  
202 }
203
204 @end lilypond
205
206 @subsection Piano and melody with lyrics
207
208 Here's a typical song format: one staff with the melody and lyrics, with
209 piano accompaniment underneath.
210
211 @lilypond[verbatim,raggedright]
212
213 \version "2.3.11"
214 melody =  \relative c'' {
215 \clef treble
216 \key c \major
217 \time 4/4
218
219   a b c d
220 }
221
222 text = \lyrics {
223   Aaa Bee Cee Dee
224 }
225
226 upper = \relative c'' {
227 \clef treble
228 \key c \major
229 \time 4/4
230
231   a b c d
232 }
233
234 lower = \relative c {
235 \clef bass
236 \key c \major
237 \time 4/4
238
239   a2 c
240 }
241
242 \score {
243   <<
244       \context Voice = mel {
245           \autoBeamOff
246           \melody
247       }
248       \lyricsto mel \new Lyrics \text
249
250       \context PianoStaff <<
251           \context Staff = upper \upper
252           \context Staff = lower \lower
253       >>
254   >>
255   \paper {
256       \context { \RemoveEmptyStaffContext }
257   }  
258   \midi { \tempo 4=60}
259 }
260
261 @end lilypond
262
263 @node Small ensembles
264 @section Small ensembles
265 @subsection SATB vocal score
266
267 Here's a standard four-part SATB vocal score.  With larger ensembles,
268 it's often useful to include a section which is included in all
269 parts.  For example, the time signature and key signatures are almost
270 always the same for all parts.
271
272 @lilypond[verbatim,raggedright]
273
274 \version "2.3.11"
275 global = {
276 \key c \major
277 \time 4/4
278 }
279
280 sopMusic = \relative c'' {
281 c4 c c8[( b)] c4
282 }
283 sopWords = \lyrics { hi4 hi hi hi  }
284
285 altoMusic = \relative c' {
286 e4 f d e 
287 }
288 altoWords =\lyrics { ha4 ha ha ha }
289
290 tenorMusic = \relative c' {
291 g4 a f g
292 }
293 tenorWords = \lyrics { hu4 hu hu hu }
294
295 bassMusic = \relative c {
296 c4 c g c
297 }
298 bassWords = \lyrics { ho4 ho ho ho }
299
300 \score { 
301           \context ChoirStaff <<
302               \context Lyrics = sopranos { s1 }
303               \context Staff = women <<
304                   \context Voice = sopranos { \voiceOne << \global \sopMusic >> }
305                   \context Voice = altos { \voiceTwo << \global \altoMusic >> }
306               >>
307               \context Lyrics = altos { s1 }
308               \context Lyrics = tenors { s1 }
309               \context Staff = men <<
310                   \clef bass
311                   \context Voice = tenors { \voiceOne <<\global \tenorMusic >> }
312                   \context Voice = basses { \voiceTwo <<\global \bassMusic >> }
313               >>
314               \context Lyrics = basses { s1 }
315
316               
317               \context Lyrics = sopranos \lyricsto sopranos \sopWords
318               \context Lyrics = altos \lyricsto altos \altoWords
319               \context Lyrics = tenors \lyricsto tenors \tenorWords
320               \context Lyrics = basses \lyricsto basses \bassWords
321           
322           >>
323   \paper {
324     \context {
325
326         % a little smaller so lyrics can be closer to the staff. 
327         \Staff
328         minimumVerticalExtent = #'(-3 . 3) 
329     }
330   }
331 }
332
333 @end lilypond
334
335 @subsection String quartet
336
337 This template demonstrates a string quartet.  It also uses a @code{\global}
338 section for time and key signatures.
339
340 @lilypond[verbatim,raggedright]
341
342 \version "2.3.11"
343 global = {
344 \time 4/4
345 \key c \major
346 }
347 violinOne = \relative c''{
348 \set Staff.instrument = "Violin 1  "
349 c2 d
350 e1
351 }
352 violinTwo = \relative c''{
353 \set Staff.instrument = "Violin 2  "
354 g2 g
355 g1
356 }
357 viola = \relative c'{
358 \set Staff.instrument = "Viola  "
359 \clef alto
360 e2 d
361 c1
362 }
363 cello = \relative c'{
364 \set Staff.instrument = "Cello  "
365 \clef bass
366 c2 g
367 c,1
368 }
369 \score {
370   \new StaffGroup <<
371     \new Staff << \global \violinOne >>
372     \new Staff << \global \violinTwo >>
373     \new Staff << \global \viola >>
374     \new Staff << \global \cello >>
375   >>
376   \paper { }
377   \midi { \tempo 4=60}
378 }
379
380 @end lilypond
381
382 @node Jazz combo
383 @section Jazz combo
384
385 This is a much more complicated template, for a jazz ensemble.  Note that all
386 instruments are notated @code{\key c \major}.  This refers to the key in
387 concert pitch; LilyPond will automatically transpose the key if the music
388 is within a @code{\transpose} section.
389
390 @c TODO must clean up this example.
391 @c   - transpositions stated in names (ie "trumpet in Bb" or whatever)
392 @c   - one global section, instead of "global" (time) and "key"
393 @c   - does it need those wierd macros?  sl, nsl, etc.
394 @c   - maybe ask Amelie Zapf to clean it up, or whether I should just
395 @c     make whatever changes I feel like.
396
397 @lilypond[verbatim,raggedright]
398
399 \version "2.3.11"
400 \header {
401         title = "Song"
402         subtitle = "(tune)"
403         composer = "Me"
404         meter = "moderato"
405         piece = "Swing"
406         tagline = "LilyPond example file by Amelie Zapf, Berlin 07/07/2003"
407         texidoc = "Jazz tune for combo (horns, guitar, piano, bass, drums)."
408 }
409
410 #(set-global-staff-size 16)
411 \include "english.ly"
412
413 %%%%%%%%%%%% Some macros %%%%%%%%%%%%%%%%%%%
414
415 sl = {
416     \override NoteHead  #'style = #'slash
417     \override Stem  #'transparent = ##t
418 }
419 nsl = {
420     \revert NoteHead #'style
421     \revert Stem #'transparent
422 }
423 cr = \override NoteHead  #'style = #'cross
424 ncr = \revert NoteHead #'style
425
426 %% insert chord name style stuff here.
427
428 jzchords = { } 
429
430
431 %%%%%%%%%%%% Keys'n'thangs %%%%%%%%%%%%%%%%%
432
433 global =  {
434     \time 4/4
435 }
436
437 Key =  { \key c \major }
438
439 % ############ Horns ############
440 % ------ Trumpet ------
441 trpt =  \transpose c d \relative c'' {
442     \Key
443     c1 c c
444 }
445
446 trpharmony = \transpose c' d { \jzchords }
447 trumpet = {
448     \global 
449     \set Staff.instrument = #"Trumpet"
450     \clef treble
451     \context Staff <<
452         \trpt
453     >>
454 }
455
456 % ------ Alto Saxophone ------
457 alto = \transpose c a \relative c' {
458         \Key
459         c1 c c
460 }
461
462 altoharmony = \transpose c' a { \jzchords }
463 altosax = {
464         \global
465         \set Staff.instrument = #"Alto Sax"
466         \clef treble
467         \context Staff <<
468                 \alto
469         >>
470 }
471
472 % ------ Baritone Saxophone ------
473 bari = \transpose c a' \relative c {
474         \Key
475         c1 c \sl d4^"Solo" d d d \nsl
476 }
477
478 bariharmony = \transpose c' a \chords { \jzchords s1 s d2:maj e:m7 }
479 barisax = {
480         \global
481         \set Staff.instrument = #"Bari Sax"
482         \clef treble
483         \context Staff <<
484                 \bari
485         >>
486 }
487 % ------ Trombone ------
488 tbone =  \relative c {
489         \Key
490         c1 c c
491 }
492
493 tboneharmony = \chords { \jzchords }
494 trombone = {
495         \global
496         \set Staff.instrument = #"Trombone"
497         \clef bass
498         \context Staff <<
499                 \tbone
500         >>
501 }
502 % ############ Rhythm Section #############
503 % ------ Guitar ------
504 gtr =  \relative c'' {
505         \Key
506         c1 \sl b4 b b b \nsl c1
507 }
508
509 gtrharmony = \chords { \jzchords
510         s1 c2:min7+ d2:maj9
511 }
512
513 guitar = {
514         \global
515         \set Staff.instrument = #"Guitar"
516         \clef treble
517         \context Staff <<
518                 \gtr
519         >>
520 }
521
522 %% ------ Piano ------
523 rhUpper =  \relative c'' {
524         \voiceOne
525         \Key
526         c1 c c
527 }
528
529 rhLower =  \relative c' {
530         \voiceTwo
531         \Key
532         e1 e e
533 }
534
535 lhUpper =  \relative c' {
536         \voiceOne
537         \Key
538         g1 g g
539 }
540
541 lhLower =  \relative c {
542         \voiceTwo
543         \Key
544         c1 c c
545 }
546
547 PianoRH = {
548         \clef treble
549         \global
550         \set Staff.midiInstrument = "acoustic grand"
551         \context Staff <<
552                 \context Voice = one \rhUpper
553                 \context Voice = two \rhLower
554         >>
555 }
556
557 PianoLH = {
558         \clef bass
559         \global
560         \set Staff.midiInstrument = "acoustic grand"
561         \context Staff <<
562                 \context Voice = one \lhUpper
563                 \context Voice = two \lhLower
564         >>
565 }
566
567 piano = {
568         \context PianoStaff <<
569                 \set PianoStaff.instrument = #"Piano"
570                 \context Staff = upper \PianoRH
571                 \context Staff = lower \PianoLH
572         >>
573 }
574
575 % ------ Bass Guitar ------
576 bass =  \relative c {
577         \Key
578         c1 c c
579 }
580
581 bass = {
582     \global
583     \set Staff.instrument = #"Bass"
584     \clef bass
585     \context Staff <<
586         \bass
587     >>
588 }
589
590                                 % ------ Drums ------
591
592 up = \drums {
593     hh4 <hh sn>4 hh <hh sn> hh <hh sn>4
594     hh4 <hh sn>4
595     hh4 <hh sn>4
596     hh4 <hh sn>4
597 }
598
599 down = \drums {
600     bd4 s bd s bd s bd s bd s bd s
601 }
602
603 drumContents = {
604         \global
605         <<
606                 \set DrumStaff.instrument = #"Drums"
607                 \new DrumVoice { \voiceOne \up }
608                 \new DrumVoice { \voiceTwo \down }
609         >>
610 }
611
612 %%%%%%%%% It All Goes Together Here %%%%%%%%%%%%%%%%%%%%%%
613
614 \score {
615 <<
616         \context StaffGroup = horns <<
617                 \context Staff = trumpet \trumpet
618
619                 \context Staff = altosax \altosax
620
621                 \context ChordNames = barichords \bariharmony
622
623                 \context Staff = barisax \barisax
624
625                 \context Staff = trombone \trombone
626         >>
627
628         \context StaffGroup = rhythm <<
629                 \context ChordNames = chords \gtrharmony
630                 \context Staff = guitar \guitar
631                 \context PianoStaff = piano \piano
632                 
633                 \context Staff = bass \bass
634                 
635                 \new DrumStaff { \drumContents }
636         >>
637 >>
638         \paper {
639                 \context { \RemoveEmptyStaffContext }
640                 \context {
641                         \Score
642                         \override BarNumber #'padding = #3
643                         \override RehearsalMark #'padding = #2
644                         skipBars = ##t
645                 }
646         }
647         \midi { \tempo 4 = 75 }
648 }
649
650 @end lilypond
651
652 @node Other templates
653 @section Other templates
654 @subsection All headers
655
656 This template displays all available headers.  Some of them are only
657 used in the Mutopia project; they don't affect the printed output at
658 all.  They are used  if you want the piece to be listed with different
659 information in the Mutopia database than you wish to have printed on the
660 music.  For example, Mutopia lists the composer of the famous D major
661 violin concerto as TchaikovskyPI, whereas perhaps you wish to print
662 "Petr Tchaikowski" on your music.
663
664 @lilypond[verbatim,raggedright]
665
666 \version "2.3.11"
667 \header {
668   dedication = "dedication"
669   title = "Title"
670   subtitle = "Subtitle"
671   subsubtitle = "Subsubtitle"
672   composer = "Composer (xxxx-yyyy)"
673   opus = "Opus 0"
674   piece = "Piece I"
675   instrument = "Instrument"
676   arranger = "Arranger"
677   poet = "Poet"
678   texttranslator = "Translator"
679   copyright = "public domain"
680
681 %   These are headers used by the Mutopia Project  http://www.mutopiaproject.org/
682  mutopiatitle = ""
683   mutopiacomposer = ""
684   mutopiapoet = ""
685   mutopiainstrument = ""
686   date = "composer's dates"
687   source = "urtext "
688   maintainer = "your name here"
689   maintainerEmail = "your email here"
690   maintainerWeb = "your home page"
691   lastupdated = "2004/Aug/26"
692 }
693
694 \score {
695    \header {
696       piece = "piece1"
697       opus = "opus1"
698     }
699   { c'4 }
700 }
701
702 \score {
703    \header {
704       piece = "piece2"
705       opus = "opus2"
706     }
707   { c'4 }
708 }
709
710 @end lilypond
711
712 @subsection Gregorian template
713
714 This example demonstrates how to do modern transcriptions of Gregorian
715 music.  Gregorian music has no measure, no stems; it uses only half and
716 quarter notes, and two types of barlines, a short one indicating a rest,
717 and a second one indicating a breath mark.
718
719
720 @lilypond[verbatim,raggedright]
721
722 barOne =  { \once \override Staff.BarLine  #'bar-size = #2
723         \bar "|" }
724 barTwo =  { \once \override Staff.BarLine  #'extra-offset = #'(0 . 2)
725         \once \override Staff.BarLine  #'bar-size = #2
726         \bar "|" }
727 chant = \relative c' {
728 \set Score.timing = ##f
729 \override Staff.Stem  #'transparent = ##t
730
731 f4 a2 \barTwo
732 g4 a2 f2 \barOne
733 g4( f) f( g) a2
734 }
735 \score {
736   \chant
737   \paper{ }
738   \midi { \tempo 4=60 }
739 }
740
741 @end lilypond
742
743 @subsection Bagpipe music
744
745 Here's an example of bagpipe music.  It demonstrates a big strength of
746 LilyPond, compared to graphical score editors: in LilyPond, you can
747 very easily reuse small segments of music without writing them out
748 completely.  This template defines a large number of small segments
749 (@code{taor, grip, thrd,} etc), which can be reused easily.
750
751 @lilypond[verbatim,raggedright]
752
753 taor = { \grace { g32[ d' g e'] } }
754 grip = { \grace { g32[ b g ]    } }
755 thrd = { \grace { g32[ d' c']   } }
756 birl = { \grace { g32[ a g]     } }
757 gstd = { \grace { g'32[ d' g]   } }
758 fgg =  { \grace { f32[ g'32]    } }
759 dblb = { \grace { g'32[ b d']   } }
760 dblc = { \grace { g'32[ c' d']  } }
761 dble = { \grace { g'32[ e' f']  } }
762 dblf = { \grace { g'32[ f' g']  } }
763 dblg = { \grace { g'32[ f']     } }
764 dbla = { \grace { a'32[ g']     } }
765 lgg =  { \grace { g32  } }
766 lag =  { \grace { a32  } }
767 cg   = { \grace { c'32 } }
768 eg   = { \grace { e'32 } }
769 gg   = { \grace { g'32 } }
770 dg   = { \grace { d'32 } }
771 hag  = { \grace { a'32 } }
772 gefg = { \grace { g'32[ e' f']  } }
773 efg  = { \grace { e'32[ f']     } }
774 gdcg = { \grace { g'32[ d' c']  } }
775 gcdg = { \grace { g'32[ c' d']  } }
776         
777 \transpose a a' {
778     #(add-grace-property 'Voice 'Stem 'length 6)
779     \time 6/8 \partial 4
780     \tieUp
781     \slurUp
782     
783     f'4 |
784     \gg f'4 e'8 \thrd d'4. |
785     \eg a4.(a4) d'8 |
786     \gg d'4 f'8 \dble e'4. ( | \noBreak
787     e'8) d'4 \gg d'4 e'8 |
788
789     \break
790     \time 9/8
791     \dblf f'2.( f'4) d'8 |
792     \time 6/8
793     \dblg g'4 a'8 \gg a'4. |
794     \thrd d'4.( d'4) \eg a8 |
795     \time 9/8
796     \dble e'4 \lag e'8 \gg  e'16[ d'8. e'8] \gg f'4 g'8 |
797
798     \break
799     \time 6/8
800     \gg f'4 e'8 \thrd d'4. |
801     \eg a4.( a4) d'8 |
802     \dblg g'4 a'8 \gg a'4. |
803     \thrd d'4.( d'4) f'8 |
804
805     \break
806     \dblg g'4 e'8( e'8) \dblf  f'8.[ e'16] |
807     \thrd d'4.( d'4) \cg d'8 |
808     \gg c'4 e'8 \thrd d'4.( |
809     d'4.) \gdcg d'4.
810     
811 }
812
813 @end lilypond
814
815
816
817
818