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