]> git.donarmstrong.com Git - lilypond.git/blob - ly/satb.ly
Issue 3777: Code improvements in satb.ly
[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-defaulting Time)
110          \dynamicUp
111          #(satb-defaulting ,(satb-sym name "Music"))
112        >>
113      }
114      #(satb-lyrics-if-defined ,(satb-sym name "Lyrics") ,name)
115      #(satb-lyrics-if-defined ,(satb-sym name "LyricsOne") ,name)
116      #(satb-lyrics-if-defined ,(satb-sym name "LyricsTwo") ,name)
117      #(satb-lyrics-if-defined ,(satb-sym name "LyricsThree") ,name)
118    >> #})
119
120 #(defmacro satb-two-voice-staff (name clef v1name v2name)
121   `#{ <<
122     \new Staff = #,name \with {
123       instrumentName = \markup \right-column \smallCaps {
124         #(satb-defaulting ,(satb-sym v1name "InstrumentName") ,v1name)
125         #(satb-defaulting ,(satb-sym v2name "InstrumentName") ,v2name)
126       }
127       shortInstrumentName = \markup \right-column \smallCaps {
128         #(satb-short-name ,v1name)
129         #(satb-short-name ,v2name)
130       }
131       midiInstrument = "clarinet"
132     } <<
133       #(satb-defaulting Key)
134       \clef #,clef
135       \new Voice = #,v1name <<
136         #(satb-defaulting Time)
137         \voiceOne
138         \dynamicUp
139         #(satb-defaulting ,(satb-sym v1name "Music"))
140       >>
141       \new Voice = #,v2name <<
142         #(satb-defaulting Time)
143         \voiceTwo
144         #(satb-defaulting ,(satb-sym v2name "Music"))
145       >>
146     >>
147     #(satb-lyrics-if-defined ,(satb-sym v1name "Lyrics") ,v1name ,name)
148     #(satb-lyrics-if-defined ,(satb-sym v1name "LyricsOne") ,v1name ,name)
149     #(satb-lyrics-if-defined ,(satb-sym v1name "LyricsTwo") ,v1name ,name)
150     #(satb-lyrics-if-defined ,(satb-sym v1name "LyricsThree") ,v1name ,name)
151     #(satb-lyrics-if-defined ,(satb-sym v2name "Lyrics") ,v2name)
152     #(satb-lyrics-if-defined ,(satb-sym v2name "LyricsOne") ,v2name)
153     #(satb-lyrics-if-defined ,(satb-sym v2name "LyricsTwo") ,v2name)
154     #(satb-lyrics-if-defined ,(satb-sym v2name "LyricsThree") ,v2name)
155   >> #})
156
157 SATB = <<
158   \new ChoirStaff
159   \with {
160     \override VerticalAxisGroup.remove-empty = ##t
161     \override VerticalAxisGroup.remove-first = ##t
162   }
163   <<
164     #(satb-one-voice-staff "Descant" "treble")
165
166     #(if (satb-defaulting TwoVoicesPerStaff #f)
167       (satb-two-voice-staff "Women" "treble" "Soprano" "Alto")
168       (make-simultaneous-music (list (satb-one-voice-staff "Soprano" "treble")
169                                      (satb-one-voice-staff "Alto" "treble"))))
170
171     #(satb-lyrics-if-defined VerseOne "Soprano")
172     #(satb-lyrics-if-defined VerseTwo "Soprano")
173     #(satb-lyrics-if-defined VerseThree "Soprano")
174     #(satb-lyrics-if-defined VerseFour "Soprano")
175     #(satb-lyrics-if-defined VerseFive "Soprano")
176     #(satb-lyrics-if-defined VerseSix "Soprano")
177     #(satb-lyrics-if-defined VerseSeven "Soprano")
178     #(satb-lyrics-if-defined VerseEight "Soprano")
179     #(satb-lyrics-if-defined VerseNine "Soprano")
180
181     #(if (satb-defaulting TwoVoicesPerStaff #f)
182       (satb-two-voice-staff "Men" "bass" "Tenor" "Bass")
183       (make-simultaneous-music (list (satb-one-voice-staff "Tenor" "treble_8")
184                                      (satb-one-voice-staff "Bass" "bass"))))
185   >>  % End ChoirStaff
186
187   \new PianoStaff
188   \with {
189     instrumentName = \markup \smallCaps
190                        #(satb-defaulting PianoInstrumentName "Piano" )
191     shortInstrumentName = \markup \smallCaps #(satb-short-name "Piano" )
192     \override VerticalAxisGroup.remove-empty = ##t
193     \override VerticalAxisGroup.remove-first = ##t
194   }
195   <<
196     \new Staff {
197       \clef "treble"
198       #(satb-defaulting Key)
199       \new Voice <<
200         #(satb-defaulting Time)
201         #(satb-defaulting PianoRHMusic)
202       >>
203     }
204     \new Dynamics {
205       #(satb-defaulting PianoDynamics)
206     }
207     \new Staff {
208       \clef "bass"
209       #(satb-defaulting Key)
210       \new Voice <<
211         #(satb-defaulting Time)
212         #(satb-defaulting PianoLHMusic)
213       >>
214     }
215   >>
216 >>
217
218 \tagGroup #'(print play)
219
220 \score {
221   \keepWithTag #'print \SATB
222   \layout { $(satb-defaulting Layout) }
223 }
224
225 \score {
226   \keepWithTag #'play \SATB
227   \midi { }
228 }