]> git.donarmstrong.com Git - lilypond.git/blob - ly/satb.ly
Doc: Issue 4323: Ensure all contexts in satb.ly template stay alive
[lilypond.git] / ly / satb.ly
1 %\version "2.19.17"
2
3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4 %%                                                %%
5 %%     Accompanied Choir with Multiple Verses     %%
6 %%                                                %%
7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8
9 %{
10   This file may be \include'd in a score to provide the
11   context structure for a score arrangement consisting
12   of the following staves:
13
14   Descant Staff
15   Soprano and Alto (optionally on two Staves or one Staff)
16   Multiple verses (up to 9)
17   Tenor and Bass (optionally on two Staves or one Staff)
18   Piano Staff
19
20   It is intended primarily to hide the complexity of the context
21   structure from newcomers to LilyPond, but is also useful as a
22   shorthand for seasoned users.
23
24   Usage:
25
26   satb.ly should be included at the *end* of the input file. Before
27   it are placed the required music and lyrics by redefining specific
28   variables, like this:
29
30   \paper { ... }
31   \header { ... }
32   TwoVoicesPerStaff = ##f or ##t
33   Key = { ... }
34   Time = { ... }
35   Layout = \layout { ... }
36   DescantMusic = \relative { ... }
37   DescantLyrics = \lyricmode { ... }
38   SopranoMusic = \relative { ... }
39   SopranoLyrics = \lyricmode { ... }
40   AltoMusic = \relative { ... }
41   AltoLyrics = \lyricmode { ... }
42   VerseOne = \lyricmode { ... }
43   VerseTwo = \lyricmode { ... }
44   ...
45   VerseNine = \lyricmode { ... }
46   TenorMusic = \relative { ... }
47   TenorLyrics = \lyricmode { ... }
48   BassMusic = \relative { ... }
49   BassLyrics = \lyricmode { ... }
50   PianoRHMusic = \relative { ... }
51   PianoDynamics = { ... }
52   PianoLHMusic = \relative { ... }
53   \include "satb.ly"
54
55   All of the definitions are optional. Staves with no music will be
56   omitted from the output.
57
58   Other variables, such as the instrumentName, can also be changed by
59   defining variables like AltoInstrumentName.  The key is defined in
60   the variable Key, and the structure of time and repeats in the
61   variable Time, using spacer rests.  A \layout block may be defined in
62   the variable Layout.  There is no default \header block and no default
63   \paper block.
64
65   Music may be tagged with #'print or #'play to be included only in
66   the printed score or in the MIDI file respectively.
67
68 %}
69
70 #(defmacro satb-defaulting (name . default)
71   (if (defined? name) name (if (pair? default) (car default) *unspecified*)))
72
73 #(define (satb-sym . strings) (string->symbol (apply string-append strings)))
74
75 #(defmacro satb-short-name (part)
76   "Use PartShortInstrumentName, or the first letter of
77 PartInstrumentName or its default."
78   (if (defined? (satb-sym part "Music"))
79     (let ((sname (satb-sym part "ShortInstrumentName")))
80       (if (defined? sname)
81         sname
82         `(substring (satb-defaulting ,(satb-sym part "InstrumentName") ,part)
83                     0 1)))
84     ""))
85
86 #(defmacro satb-lyrics-if-defined (name voice . optionals)
87   (let ((above (and (pair? optionals) (car optionals))))
88     (if (defined? name)
89       `(make-music 'ContextSpeccedMusic
90          'create-new #t
91          'context-type 'Lyrics
92          'property-operations ',(if above `((assign alignAboveContext ,above)) '())
93          'element (make-music 'LyricCombineMusic
94                    'associated-context ,voice
95                    'element ,name))
96       *unspecified*)))
97
98 #(defmacro satb-one-voice-staff (name clef)
99   `#{ <<
100      \new Staff = #,name \with {
101        instrumentName = \markup \smallCaps
102          #(satb-defaulting ,(satb-sym name "InstrumentName") ,name)
103        shortInstrumentName = \markup \smallCaps #(satb-short-name ,name)
104        midiInstrument = "clarinet"
105      } {
106        #(satb-defaulting Key)
107        \clef #,clef
108        \new Voice = #,name <<
109          \satb-spacers
110          #(satb-defaulting Time)
111          \dynamicUp
112          #(satb-defaulting ,(satb-sym name "Music"))
113        >>
114      }
115      #(satb-lyrics-if-defined ,(satb-sym name "Lyrics") ,name)
116      #(satb-lyrics-if-defined ,(satb-sym name "LyricsOne") ,name)
117      #(satb-lyrics-if-defined ,(satb-sym name "LyricsTwo") ,name)
118      #(satb-lyrics-if-defined ,(satb-sym name "LyricsThree") ,name)
119    >> #})
120
121 #(defmacro satb-two-voice-staff (name clef v1name v2name)
122   `#{ <<
123     \new Staff = #,name \with {
124       instrumentName = \markup \right-column \smallCaps {
125         #(satb-defaulting ,(satb-sym v1name "InstrumentName") ,v1name)
126         #(satb-defaulting ,(satb-sym v2name "InstrumentName") ,v2name)
127       }
128       shortInstrumentName = \markup \right-column \smallCaps {
129         #(satb-short-name ,v1name)
130         #(satb-short-name ,v2name)
131       }
132       midiInstrument = "clarinet"
133     } <<
134       #(satb-defaulting Key)
135       \clef #,clef
136       \new Voice = #,v1name <<
137         \satb-spacers
138         #(satb-defaulting Time)
139         \voiceOne
140         \dynamicUp
141         #(satb-defaulting ,(satb-sym v1name "Music"))
142       >>
143       \new Voice = #,v2name <<
144         \satb-spacers
145         #(satb-defaulting Time)
146         \voiceTwo
147         #(satb-defaulting ,(satb-sym v2name "Music"))
148       >>
149     >>
150     #(satb-lyrics-if-defined ,(satb-sym v1name "Lyrics") ,v1name ,name)
151     #(satb-lyrics-if-defined ,(satb-sym v1name "LyricsOne") ,v1name ,name)
152     #(satb-lyrics-if-defined ,(satb-sym v1name "LyricsTwo") ,v1name ,name)
153     #(satb-lyrics-if-defined ,(satb-sym v1name "LyricsThree") ,v1name ,name)
154     #(satb-lyrics-if-defined ,(satb-sym v2name "Lyrics") ,v2name)
155     #(satb-lyrics-if-defined ,(satb-sym v2name "LyricsOne") ,v2name)
156     #(satb-lyrics-if-defined ,(satb-sym v2name "LyricsTwo") ,v2name)
157     #(satb-lyrics-if-defined ,(satb-sym v2name "LyricsThree") ,v2name)
158   >> #})
159
160 satb-define-if-unused =
161 #(define-void-function (parser location syms) (symbol-list?)
162    (for-each
163       (lambda (sym)
164         (if (null? (ly:parser-lookup parser sym))
165             (ly:parser-define! parser sym *unspecified*)))
166       syms))
167
168 \satb-define-if-unused
169   #'(
170     DescantMusic
171     SopranoMusic
172     AltoMusic
173     TenorMusic
174     BassMusic
175   )
176
177 satb-AllChoirMusic = <<
178   \DescantMusic
179   \SopranoMusic
180   \AltoMusic
181   \TenorMusic
182   \BassMusic
183 >>
184
185 #(define satb-spacers (skip-of-length satb-AllChoirMusic))
186
187 SATB = <<
188   \new ChoirStaff
189   \with {
190     \override VerticalAxisGroup.remove-empty = ##t
191     \override VerticalAxisGroup.remove-first = ##t
192   }
193   <<
194     #(satb-one-voice-staff "Descant" "treble")
195
196     #(if (satb-defaulting TwoVoicesPerStaff #f)
197       (satb-two-voice-staff "Women" "treble" "Soprano" "Alto")
198       (make-simultaneous-music (list (satb-one-voice-staff "Soprano" "treble")
199                                      (satb-one-voice-staff "Alto" "treble"))))
200
201     #(satb-lyrics-if-defined VerseOne "Soprano")
202     #(satb-lyrics-if-defined VerseTwo "Soprano")
203     #(satb-lyrics-if-defined VerseThree "Soprano")
204     #(satb-lyrics-if-defined VerseFour "Soprano")
205     #(satb-lyrics-if-defined VerseFive "Soprano")
206     #(satb-lyrics-if-defined VerseSix "Soprano")
207     #(satb-lyrics-if-defined VerseSeven "Soprano")
208     #(satb-lyrics-if-defined VerseEight "Soprano")
209     #(satb-lyrics-if-defined VerseNine "Soprano")
210
211     #(if (satb-defaulting TwoVoicesPerStaff #f)
212       (satb-two-voice-staff "Men" "bass" "Tenor" "Bass")
213       (make-simultaneous-music (list (satb-one-voice-staff "Tenor" "treble_8")
214                                      (satb-one-voice-staff "Bass" "bass"))))
215   >>  % End ChoirStaff
216
217   \new PianoStaff
218   \with {
219     instrumentName = \markup \smallCaps
220                        #(satb-defaulting PianoInstrumentName "Piano" )
221     shortInstrumentName = \markup \smallCaps #(satb-short-name "Piano" )
222     \override VerticalAxisGroup.remove-empty = ##t
223     \override VerticalAxisGroup.remove-first = ##t
224   }
225   <<
226     \new Staff {
227       \clef "treble"
228       #(satb-defaulting Key)
229       \new Voice <<
230         \satb-spacers
231         #(satb-defaulting Time)
232         #(satb-defaulting PianoRHMusic)
233       >>
234     }
235     \new Dynamics {
236       #(satb-defaulting PianoDynamics)
237     }
238     \new Staff {
239       \clef "bass"
240       #(satb-defaulting Key)
241       \new Voice <<
242         \satb-spacers
243         #(satb-defaulting Time)
244         #(satb-defaulting PianoLHMusic)
245       >>
246     }
247   >>
248 >>
249
250 \tagGroup #'(print play)
251
252 \score {
253   \keepWithTag #'print \SATB
254   \layout { $(satb-defaulting Layout) }
255 }
256
257 \score {
258   \keepWithTag #'play \SATB
259   \midi { }
260 }