2 gregorian-ligature-engraver.cc -- implement Gregorian_ligature_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2007 Juergen Reuter <reuter@ipd.uka.de>
9 #include "gregorian-ligature-engraver.hh"
11 #include "gregorian-ligature.hh"
12 #include "international.hh"
13 #include "paper-column.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "stream-event.hh"
20 /* ASSIGN_EVENT_ONCE */
21 #include "translator.icc"
24 * This abstract class is the common superclass for all ligature
25 * engravers for Gregorian chant notation. It cares for the musical
26 * handling of the neumes, such as checking for valid combinations of
27 * neumes and providing context information. Notational aspects such
28 * as the glyphs to use or calculating the total width of a ligature,
29 * are left to the concrete subclass. Currently, there is only a
30 * single subclass, Vaticana_ligature_engraver. Other ligature
31 * engravers for Gregorian chant will be added in the future, such as
32 * Medicaea_ligature_engraver or Hufnagel_ligature_engraver.
34 Gregorian_ligature_engraver::Gregorian_ligature_engraver ()
36 pes_or_flexa_req_ = 0;
40 Gregorian_ligature_engraver::listen_pes_or_flexa (Stream_event *ev)
42 ASSIGN_EVENT_ONCE (pes_or_flexa_req_, ev);
45 void fix_prefix (char const *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 (vector<Grob_info> primitives)
87 /* Check for invalid head modifier combinations */
88 for (vsize 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 cannot 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,
157 /* check: inclinatum may be prefixed with auctum or deminutum only */
158 if (prefix_set & INCLINATUM)
160 fix_prefix_set (&prefix_set,
162 INCLINATUM | AUCTUM | DEMINUTUM,
165 /* check: semivocalis (deminutum but not inclinatum) must occur in
166 combination with and only with pes or flexa */
167 else if (prefix_set & DEMINUTUM)
169 fix_prefix_set (&prefix_set,
170 DEMINUTUM | PES_OR_FLEXA,
171 DEMINUTUM | PES_OR_FLEXA,
175 /* check: cavum and linea (either or both) may be applied only
177 if (prefix_set & (CAVUM | LINEA))
179 fix_prefix_set (&prefix_set,
185 /* all other combinations should be valid (unless I made a
188 primitive->set_property ("prefix-set", scm_from_int (prefix_set));
193 * Marks those heads that participate in a pes or flexa.
196 provide_context_info (vector<Grob_info> primitives)
198 Grob *prev_primitive = 0;
199 int prev_prefix_set = 0;
200 int prev_context_info = 0;
202 for (vsize i = 0; i < primitives.size (); i++)
204 Grob *primitive = primitives[i].grob ();
205 Stream_event *event_cause = primitives[i].event_cause ();
206 int context_info = 0;
207 int pitch = unsmob_pitch (event_cause->get_property ("pitch"))->steps ();
208 int prefix_set = scm_to_int (primitive->get_property ("prefix-set"));
210 if (prefix_set & PES_OR_FLEXA)
212 if (!i) // ligature may not start with 2nd head of pes or flexa
213 primitive->warning (_ ("cannot apply `\\~' on first head of ligature"));
214 else if (pitch > prev_pitch) // pes
216 prev_context_info |= PES_LOWER;
217 context_info |= PES_UPPER;
219 else if (pitch < prev_pitch) // flexa
221 prev_context_info |= FLEXA_LEFT;
222 context_info |= FLEXA_RIGHT;
224 else // (pitch == prev_pitch)
225 primitive->warning (_ ("cannot apply `\\~' on heads with identical pitch"));
227 if (prev_prefix_set & DEMINUTUM)
228 context_info |= AFTER_DEMINUTUM;
231 prev_primitive->set_property ("context-info",
232 scm_from_int (prev_context_info));
233 prev_primitive = primitive;
234 prev_prefix_set = prefix_set;
235 prev_context_info = context_info;
239 prev_primitive->set_property ("context-info",
240 scm_from_int (prev_context_info));
244 Gregorian_ligature_engraver::build_ligature (Spanner *ligature,
245 vector<Grob_info> primitives)
247 // apply style-independent checking and transformation
248 check_and_fix_all_prefixes (primitives);
249 provide_context_info (primitives);
251 // apply style-specific transformation (including line-up); to be
252 // implemented by subclass
253 transform_heads (ligature, primitives);
257 Gregorian_ligature_engraver::stop_translation_timestep ()
259 Ligature_engraver::stop_translation_timestep ();
260 pes_or_flexa_req_ = 0;
263 // no ADD_ACKNOWLEDGER / ADD_ACKNOWLEDGER / ADD_TRANSLATOR macro calls
264 // since this class is abstract