2 gregorian-ligature-engraver.cc -- implement Gregorian_ligature_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2003 Juergen Reuter <reuter@ipd.uka.de>
9 #include "gregorian-ligature-engraver.hh"
10 #include "gregorian-ligature.hh"
13 #include "staff-symbol-referencer.hh"
15 #include "paper-column.hh"
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.
28 Gregorian_ligature_engraver::Gregorian_ligature_engraver ()
30 pes_or_flexa_req_ = 0;
34 Gregorian_ligature_engraver::try_music (Music *m)
36 if (m->is_mus_type ("pes-or-flexa-event"))
38 pes_or_flexa_req_ = m;
42 return Ligature_engraver::try_music (m);
45 void fix_prefix (char *name, int mask,
46 int *current_set, int min_set, int max_set,
49 bool current = *current_set & mask;
50 bool min = min_set & mask;
51 bool max = max_set & mask;
54 programming_error ("min_set > max_set");
59 primitive->warning (_f ("\\%s ignored", name));
60 *current_set &= ~mask;
64 primitive->warning (_f ("implied \\%s added", name));
69 void fix_prefix_set (int *current_set, int min_set, int max_set, Grob *primitive)
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);
85 void check_and_fix_all_prefixes (Array<Grob_info> primitives)
87 /* Check for illegal head modifier combinations */
88 for (int i = 0; i < primitives.size (); i++)
90 Grob *primitive = primitives[i].grob_;
92 /* compute head prefix set by inspecting primitive grob properties */
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")));
107 /* check: ascendens and descendens exclude each other; same with
108 auctum and deminutum */
109 if (prefix_set & DESCENDENS)
111 fix_prefix_set (&prefix_set,
112 prefix_set & ~ASCENDENS,
113 prefix_set & ~ASCENDENS,
116 if (prefix_set & AUCTUM)
118 fix_prefix_set (&prefix_set,
119 prefix_set & ~DEMINUTUM,
120 prefix_set & ~DEMINUTUM,
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)
128 fix_prefix_set (&prefix_set,
130 VIRGA | PES_OR_FLEXA,
133 if (prefix_set & QUILISMA)
135 fix_prefix_set (&prefix_set,
137 QUILISMA | PES_OR_FLEXA,
140 if (prefix_set & ORISCUS)
142 fix_prefix_set (&prefix_set,
144 ORISCUS | PES_OR_FLEXA,
148 /* check: auctum is the only valid optional prefix for stropha */
149 if (prefix_set & STROPHA)
151 fix_prefix_set (&prefix_set,
158 /* check: inclinatum may be prefixed with auctum or deminutum only */
159 if (prefix_set & INCLINATUM)
161 fix_prefix_set (&prefix_set,
163 INCLINATUM | AUCTUM | DEMINUTUM,
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)
170 fix_prefix_set (&prefix_set,
171 DEMINUTUM | PES_OR_FLEXA,
172 DEMINUTUM | PES_OR_FLEXA,
176 /* check: cavum and linea (either or both) may be applied only
178 if (prefix_set & (CAVUM | LINEA))
180 fix_prefix_set (&prefix_set,
186 /* all other combinations should be valid (unless I made a
189 primitive->set_property ("prefix-set", gh_int2scm (prefix_set));
194 * Marks those heads that participate in a pes or flexa.
197 provide_context_info (Array<Grob_info> primitives)
199 Grob *prev_primitive = 0;
200 int prev_prefix_set = 0;
201 int prev_context_info = 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 = gh_scm2int (primitive->get_property ("prefix-set"));
210 if (prefix_set & PES_OR_FLEXA)
211 if (!i) // ligature may not start with 2nd head of pes or flexa
213 primitive->warning ("may not apply `\\~' on first head of "
214 "ligature; ignoring `\\~'");
216 else if (pitch > prev_pitch) // pes
218 prev_context_info |= PES_LOWER;
219 context_info |= PES_UPPER;
221 else if (pitch < prev_pitch) // flexa
223 prev_context_info |= FLEXA_LEFT;
224 context_info |= FLEXA_RIGHT;
226 else // (pitch == prev_pitch)
228 primitive->warning ("may not apply `\\~' on heads with "
229 "identical pitch; ignoring `\\~'");
231 if (prev_prefix_set & DEMINUTUM)
233 context_info |= AFTER_DEMINUTUM;
237 prev_primitive->set_property ("context-info",
238 gh_int2scm (prev_context_info));
239 prev_primitive = primitive;
240 prev_prefix_set = prefix_set;
241 prev_context_info = context_info;
245 prev_primitive->set_property ("context-info",
246 gh_int2scm (prev_context_info));
250 Gregorian_ligature_engraver::transform_heads (Spanner *, Array<Grob_info>)
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");
258 Gregorian_ligature_engraver::build_ligature (Spanner *ligature,
259 Array<Grob_info> primitives)
261 // apply style-independent checking and transformation
262 check_and_fix_all_prefixes (primitives);
263 provide_context_info (primitives);
265 // apply style-specific transformation (including line-up); to be
266 // implemented by subclass
267 transform_heads (ligature, primitives);
271 Gregorian_ligature_engraver::stop_translation_timestep ()
273 Ligature_engraver::stop_translation_timestep ();
274 pes_or_flexa_req_ = 0;
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.",
280 /* accepts */ "ligature-event",
281 /* acks */ "note-head-interface rest-interface",