]> git.donarmstrong.com Git - lilypond.git/blob - lily/gregorian-ligature-engraver.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[lilypond.git] / lily / gregorian-ligature-engraver.cc
1 /*
2   gregorian-ligature-engraver.cc -- implement Gregorian_ligature_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2003 Juergen Reuter <reuter@ipd.uka.de>
7  */
8
9 #include "gregorian-ligature-engraver.hh"
10
11 #include "gregorian-ligature.hh"
12 #include "warn.hh"
13 #include "staff-symbol-referencer.hh"
14 #include "spanner.hh"
15 #include "paper-column.hh"
16
17 /*
18  * This abstract class is the common superclass for all ligature
19  * engravers for Gregorian chant notation.  It cares for the musical
20  * handling of the neumes, such as checking for valid combinations of
21  * neumes and providing context information.  Notational aspects such
22  * as the glyphs to use or calculating the total width of a ligature,
23  * are left to the concrete subclass.  Currently, there is only a
24  * single subclass, Vaticana_ligature_engraver.  Other ligature
25  * engravers for Gregorian chant will be added in the future, such as
26  * Medicaea_ligature_engraver or Hufnagel_ligature_engraver.
27  */
28 Gregorian_ligature_engraver::Gregorian_ligature_engraver ()
29 {
30   pes_or_flexa_req_ = 0;
31 }
32
33 bool
34 Gregorian_ligature_engraver::try_music (Music *m)
35 {
36   if (m->is_mus_type ("pes-or-flexa-event"))
37     {
38       pes_or_flexa_req_ = m;
39       return true;
40     }
41   else
42     return Ligature_engraver::try_music (m);
43 }
44
45 void fix_prefix (char *name, int mask,
46                  int *current_set, int min_set, int max_set,
47                  Grob *primitive)
48 {
49   bool current = *current_set & mask;
50   bool min = min_set & mask;
51   bool max = max_set & mask;
52   if (max < min)
53     {
54       programming_error ("min_set > max_set");
55       return;
56     }
57   if (min && !current)
58     {
59       primitive->warning (_f ("\\%s ignored", name));
60       *current_set &= ~mask;
61     }
62   if (!max && current)
63     {
64       primitive->warning (_f ("implied \\%s added", name));
65       *current_set |= mask;
66     }
67 }
68
69 void fix_prefix_set (int *current_set, int min_set, int max_set, Grob *primitive)
70 {
71   fix_prefix ("virga", VIRGA, current_set, min_set, max_set, primitive);
72   fix_prefix ("stropha", STROPHA, current_set, min_set, max_set, primitive);
73   fix_prefix ("inclinatum", INCLINATUM, current_set, min_set, max_set, primitive);
74   fix_prefix ("auctum", AUCTUM, current_set, min_set, max_set, primitive);
75   fix_prefix ("descendens", DESCENDENS, current_set, min_set, max_set, primitive);
76   fix_prefix ("ascendens", ASCENDENS, current_set, min_set, max_set, primitive);
77   fix_prefix ("oriscus", ORISCUS, current_set, min_set, max_set, primitive);
78   fix_prefix ("quilisma", QUILISMA, current_set, min_set, max_set, primitive);
79   fix_prefix ("deminutum", DEMINUTUM, current_set, min_set, max_set, primitive);
80   fix_prefix ("cavum", CAVUM, current_set, min_set, max_set, primitive);
81   fix_prefix ("linea", LINEA, current_set, min_set, max_set, primitive);
82   fix_prefix ("pes_or_flexa", LINEA, current_set, min_set, max_set, primitive);
83 }
84
85 void check_and_fix_all_prefixes (Array<Grob_info> primitives)
86 {
87   /* Check for illegal head modifier combinations */
88   for (int i = 0; i < primitives.size (); i++)
89     {
90     Grob *primitive = primitives[i].grob_;
91
92     /* compute head prefix set by inspecting primitive grob properties */
93     int prefix_set =
94       (VIRGA * to_boolean (primitive->get_property ("virga"))) |
95       (STROPHA * to_boolean (primitive->get_property ("stropha"))) |
96       (INCLINATUM * to_boolean (primitive->get_property ("inclinatum"))) |
97       (AUCTUM * to_boolean (primitive->get_property ("auctum"))) |
98       (DESCENDENS * to_boolean (primitive->get_property ("descendens"))) |
99       (ASCENDENS * to_boolean (primitive->get_property ("ascendens"))) |
100       (ORISCUS * to_boolean (primitive->get_property ("oriscus"))) |
101       (QUILISMA * to_boolean (primitive->get_property ("quilisma"))) |
102       (DEMINUTUM * to_boolean (primitive->get_property ("deminutum"))) |
103       (CAVUM * to_boolean (primitive->get_property ("cavum"))) |
104       (LINEA * to_boolean (primitive->get_property ("linea"))) |
105       (PES_OR_FLEXA * to_boolean (primitive->get_property ("pes-or-flexa")));
106
107     /* check: ascendens and descendens exclude each other; same with
108        auctum and deminutum */
109     if (prefix_set & DESCENDENS)
110       {
111         fix_prefix_set (&prefix_set,
112                         prefix_set & ~ASCENDENS,
113                         prefix_set & ~ASCENDENS,
114                         primitive);
115       }
116     if (prefix_set & AUCTUM)
117       {
118         fix_prefix_set (&prefix_set,
119                         prefix_set & ~DEMINUTUM,
120                         prefix_set & ~DEMINUTUM,
121                         primitive);
122       }
123
124     /* check: virga, quilisma and oriscus can not be combined with any
125        other prefix, but may be part of a pes or flexa */
126     if (prefix_set & VIRGA)
127       {
128         fix_prefix_set (&prefix_set,
129                         VIRGA,
130                         VIRGA | PES_OR_FLEXA,
131                         primitive);
132       }
133     if (prefix_set & QUILISMA)
134       {
135         fix_prefix_set (&prefix_set,
136                         QUILISMA,
137                         QUILISMA | PES_OR_FLEXA,
138                         primitive);
139       }
140     if (prefix_set & ORISCUS)
141       {
142         fix_prefix_set (&prefix_set,
143                         ORISCUS,
144                         ORISCUS | PES_OR_FLEXA,
145                         primitive);
146       }
147
148     /* check: auctum is the only valid optional prefix for stropha */
149     if (prefix_set & STROPHA)
150       {
151         fix_prefix_set (&prefix_set,
152                         STROPHA,
153                         STROPHA | AUCTUM,
154                         primitive);
155       }
156
157
158     /* check: inclinatum may be prefixed with auctum or deminutum only */
159     if (prefix_set & INCLINATUM)
160       {
161         fix_prefix_set (&prefix_set,
162                         INCLINATUM,
163                         INCLINATUM | AUCTUM | DEMINUTUM,
164                         primitive);
165       }
166     /* check: semivocalis (deminutum but not inclinatum) must occur in
167        combination with and only with pes or flexa */
168     else if (prefix_set & DEMINUTUM)
169       {
170         fix_prefix_set (&prefix_set,
171                         DEMINUTUM | PES_OR_FLEXA,
172                         DEMINUTUM | PES_OR_FLEXA,
173                         primitive);
174       }
175
176     /* check: cavum and linea (either or both) may be applied only
177        upon core punctum */
178     if (prefix_set & (CAVUM | LINEA))
179       {
180         fix_prefix_set (&prefix_set,
181                         0,
182                         CAVUM | LINEA,
183                         primitive);
184       }
185
186     /* all other combinations should be valid (unless I made a
187        mistake) */
188
189     primitive->set_property ("prefix-set", scm_int2num (prefix_set));
190   }
191 }
192
193 /*
194  * Marks those heads that participate in a pes or flexa.
195  */
196 void
197 provide_context_info (Array<Grob_info> primitives)
198 {
199   Grob *prev_primitive = 0;
200   int prev_prefix_set = 0;
201   int prev_context_info = 0;
202   int prev_pitch = 0;
203   for (int i = 0; i < primitives.size (); i++) {
204     Grob *primitive = primitives[i].grob_;
205     Music *music_cause = primitives[i].music_cause ();
206     int context_info = 0;
207     int pitch = unsmob_pitch (music_cause->get_property ("pitch"))->steps ();
208     int prefix_set = scm_to_int (primitive->get_property ("prefix-set"));
209
210     if (prefix_set & PES_OR_FLEXA)
211       if (!i) // ligature may not start with 2nd head of pes or flexa
212           {
213             primitive->warning ("may not apply `\\~' on first head of "
214                                 "ligature; ignoring `\\~'");
215           }
216       else if (pitch > prev_pitch) // pes
217         {
218           prev_context_info |= PES_LOWER;
219           context_info |= PES_UPPER;
220         }
221       else if (pitch < prev_pitch) // flexa
222         {
223           prev_context_info |= FLEXA_LEFT;
224           context_info |= FLEXA_RIGHT;
225         }
226       else // (pitch == prev_pitch)
227         {
228           primitive->warning ("may not apply `\\~' on heads with "
229                               "identical pitch; ignoring `\\~'");
230         }
231     if (prev_prefix_set & DEMINUTUM)
232       {
233         context_info |= AFTER_DEMINUTUM;
234       }
235
236     if (prev_primitive)
237       prev_primitive->set_property ("context-info",
238                                          scm_int2num (prev_context_info));
239     prev_primitive = primitive;
240     prev_prefix_set = prefix_set;
241     prev_context_info = context_info;
242     prev_pitch = pitch;
243   }
244   if (prev_primitive)
245     prev_primitive->set_property ("context-info",
246                                        scm_int2num (prev_context_info));
247 }
248
249 void
250 Gregorian_ligature_engraver::transform_heads (Spanner *, Array<Grob_info>)
251 {
252   programming_error ("Gregorian_ligature_engraver::transform_heads (): "
253                      "this is an abstract method that should not be called, "
254                      "but overridden by a subclass");
255 }
256
257 void
258 Gregorian_ligature_engraver::build_ligature (Spanner *ligature,
259                                              Array<Grob_info> primitives)
260 {
261   // apply style-independent checking and transformation
262   check_and_fix_all_prefixes (primitives);
263   provide_context_info (primitives);
264
265   // apply style-specific transformation (including line-up); to be
266   // implemented by subclass
267   transform_heads (ligature, primitives);
268 }
269
270 void
271 Gregorian_ligature_engraver::stop_translation_timestep ()
272 {
273   Ligature_engraver::stop_translation_timestep ();
274   pes_or_flexa_req_ = 0;
275 }
276
277 ENTER_DESCRIPTION (Gregorian_ligature_engraver,
278 /* descr */       "This is an abstract class.  Subclasses such as Vaticana_ligature_engraver handle ligatures by glueing special ligature heads together.",
279 /* creats*/       "",
280 /* accepts */     "ligature-event",
281 /* acks  */      "note-head-interface rest-interface",
282 /* reads */       "",
283 /* write */       "");