2 coherent-ligature-engraver.cc -- implement Coherent_ligature_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2006 Juergen Reuter <reuter@ipd.uka.de>
9 #include "coherent-ligature-engraver.hh"
12 #include "paper-column.hh"
14 #include "pointer-group-interface.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "stream-event.hh"
20 * This abstract class serves as common superclass for all ligature
21 * engravers thet produce a single connected graphical object of fixed
22 * width, consisting of noteheads and other primitives (see class
23 * Ligature_engraver for more information on the interaction between
24 * this class and its superclass). In particular, it cares for the
27 * - provide a function for putting all grobs of the ligature into a
28 * single paper column,
30 * - delegate actual creation of ligature to concrete subclass,
32 * - collect all accidentals that occur within the ligature and put
33 * them at the left side of the ligature (TODO; see function
34 * collect_accidentals ()),
36 * - collapse superflous space after each ligature (TODO).
38 * Concrete subclasses must implement function build_ligature (Spanner
39 * *, vector<Grob_info>). This function is responsible for actually
40 * building the ligature by transforming the array of noteheads.
42 * Currently, there are two subclasses: Gregorian_ligature_engraver
43 * for Gregorian chant notation (also known as plain song or cantus
44 * planus) and Mensural_ligature_engraver for white mensural notation.
45 * Subclasses for other music notation styles such as modal notation
46 * or ars nova notation may eventually be added.
50 * TODO: local accidentals: collect accidentals that occur within a
51 * ligature and put them before the ligature. If an accidental
52 * changes within a ligature, print a warning (user error) and ignore
53 * any further accidental for that pitch within that ligature
54 * (actually, in such a case, the user should split the ligature into
55 * two separate ligatures). Similarly, any object that, in ordinary
56 * notation, may be put to the left or to the right of a note-head,
57 * should be collected and put before or after the ligature.
59 * TODO: make spacing more robust: do not screw up spacing if user
60 * erroneously puts rest in ligature.
62 * TODO: for each ligature, add Rod that represents the total length
63 * of the ligature (to preemptively avoid collision with adjacent
64 * notes); or maybe just additionally create a
65 * mensural/vaticana/whatever-ligature grob (e.g. via
66 * Mensural_ligature::print (SCM)) that just consists of a
67 * bounding box around all primitives of the ligature.
69 * TODO: Maybe move functions fold_up_primitives () and
70 * join_primitives () from subclasses to here? N.B. it is not
71 * appropriate to put these into Ligature_engraver, since, for
72 * example, Ligature_bracket_engraver does not share any of this code.
77 * TODO: move this function to class Item?
80 Coherent_ligature_engraver::get_set_column (Item *item, Paper_column *column)
82 Item *parent = dynamic_cast<Item *> (item->get_parent (X_AXIS));
85 programming_error ("failed tweaking paper column in ligature");
89 string name = parent->name ();
90 if (name != "PaperColumn")
92 // Change column not only for targeted item (NoteColumn), but
93 // also for all associated grobs (NoteSpacing, SeparationItem).
94 Grob *sl = Staff_symbol_referencer::get_staff_symbol (item);
96 extract_item_set (parent, "elements", elements);
98 for (vsize i = elements.size (); i--;)
100 Item *sibling = elements[i];
102 && (Staff_symbol_referencer::get_staff_symbol (sibling) == sl))
104 #if 0 /* experimental code to collapse spacing after ligature */
105 Grob *sibling_parent = sibling->get_parent (X_AXIS);
106 sibling_parent->warning (_f ("Coherent_ligature_engraver: "
107 "setting `spacing-increment="
108 "0.01': ptr=%ul", parent));
109 sibling_parent->set_property ("forced-spacing",
110 scm_from_double (0.01));
112 sibling->set_parent (column, X_AXIS);
117 get_set_column (parent, column);
121 * TODO: This function should collect all accidentals that occur
122 * within the ligature (by scanning through the primitives array) and
123 * place all of them at the left of the ligature. If there is an
124 * alteration within the ligature (e.g. an "f" followed by a "fis"
125 * somewhere later in the ligature), issue a warning (and maybe create
126 * an additional natural symbol to explicitly make clear that there is
127 * an "f" first?). The warning should suggest the user to break the
128 * ligature into two or more smaller ligatures such that no alteration
129 * occurs within the broken ligatures any more.
132 Coherent_ligature_engraver::collect_accidentals (Spanner *, vector<Grob_info>)
138 compute_delta_pitches (vector<Grob_info> primitives)
142 Item *prev_primitive = 0, *primitive = 0;
143 for (vsize i = 0; i < primitives.size (); i++)
145 primitive = dynamic_cast<Item *> (primitives[i].grob ());
146 Stream_event *cause = primitives[i].event_cause ();
148 = unsmob_pitch (cause->get_property ("pitch"))->steps ();
151 delta_pitch = pitch - prev_pitch;
152 prev_primitive->set_property ("delta-position",
153 scm_from_int (delta_pitch));
156 prev_primitive = primitive;
158 primitive->set_property ("delta-position", scm_from_int (0));
162 Coherent_ligature_engraver::typeset_ligature (Spanner *ligature,
163 vector<Grob_info> primitives)
165 // compute some commonly needed context info stored as grob
167 compute_delta_pitches (primitives);
169 // prepare ligature for typesetting
170 build_ligature (ligature, primitives);
171 collect_accidentals (ligature, primitives);
174 // no ADD_ACKNOWLEDGER / ADD_ACKNOWLEDGER / ADD_TRANSLATOR macro calls
175 // since this class is abstract