]> git.donarmstrong.com Git - lilypond.git/blob - lily/coherent-ligature-engraver.cc
remove
[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 Juergen Reuter <reuter@ipd.uka.de>
7  */
8
9 #include "coherent-ligature-engraver.hh"
10 #include "item.hh"
11 #include "warn.hh"
12 #include "staff-symbol-referencer.hh"
13 #include "spanner.hh"
14 #include "paper-column.hh"
15
16 /*
17  * This abstract class serves as common superclass for all ligature
18  * engravers thet produce a single connected graphical object of fixed
19  * width, consisting of noteheads and other primitives (see class
20  * Ligature_engraver for more information on the interaction between
21  * this class and its superclass).  In particular, it cares for the
22  * following tasks:
23  *
24  * - provide a function for putting all grobs of the ligature into a
25  * single paper column,
26  *
27  * - delegate actual creation of ligature to concrete subclass,
28  *
29  * - collect all accidentals that occur within the ligature and put
30  * them at the left side of the ligature (TODO; see function
31  * collect_accidentals ()),
32  *
33  * - collapse superflous space after each ligature (TODO).
34  *
35  * Concrete subclasses must implement function build_ligature (Spanner
36  * *, Array<Grob_info>).  This function is responsible for actually
37  * building the ligature by transforming the array of noteheads.
38  *
39  * Currently, there are two subclasses: Gregorian_ligature_engraver
40  * for Gregorian chant notation (also known as plain song or cantus
41  * planus) and Mensural_ligature_engraver for white mensural notation.
42  * Subclasses for other music notation styles such as modal notation
43  * or ars nova notation may eventually be added.
44  */
45
46 /*
47  * TODO: local accidentals: collect accidentals that occur within a
48  * ligature and put them before the ligature.  If an accidental
49  * changes within a ligature, print a warning (user error) and ignore
50  * any further accidental for that pitch within that ligature
51  * (actually, in such a case, the user should split the ligature into
52  * two separate ligatures).  Similarly, any object that, in ordinary
53  * notation, may be put to the left or to the right of a note-head,
54  * should be collected and put before or after the ligature.
55  *
56  * TODO: make spacing more robust: do not screw up spacing if user
57  * erroneously puts rest in ligature.
58  *
59  * TODO: for each ligature, add Rod that represents the total length
60  * of the ligature (to preemptively avoid collision with adjacent
61  * notes); or maybe just additionally create a
62  * mensural/vaticana/whatever-ligature grob (e.g. via
63  * Mensural_ligature::print (SCM)) that just consists of a
64  * bounding box around all primitives of the ligature.
65  *
66  * TODO: Maybe move functions fold_up_primitives () and
67  * join_primitives () from subclasses to here?  N.B. it is not
68  * appropriate to put these into Ligature_engraver, since, for
69  * example, Ligature_bracket_engraver does not share any of this code.
70  */
71
72 /*
73  * TODO: Let superflous space after each ligature collapse.  The
74  * following code should help in doing so (though it does not yet
75  * fully work).  Just put the following code into
76  * Spacing_spanner::do_measure ().  I put it temporarily here as memo
77  * until it really works and I also get Han-Wen's/Jan's permission to
78  * add it to the spacing spanner code.
79  */
80 #if 0 // experimental code to collapse spacing after ligature
81       SCM incr_scm = lc->get_property ("forced-spacing");
82       if (incr_scm != SCM_EOL) /* (Paper_column::is_musical (l)) */
83         {
84           me->warning (_f ("gotcha: ptr=%ul", lc));//debug
85           ly_display_scm (lc->self_scm ());
86           Real distance;
87           if (incr_scm != SCM_EOL)
88             {
89               distance = ly_scm2double (incr_scm);
90             }
91           else
92             {
93               me->warning ("distance undefined, assuming 0.1");
94               distance = 0.1;
95             }
96           me->warning (_f ("distance=%f", distance));//debug
97           Real strength = 1.0;
98           Spaceable_grob::add_spring (lc, rc, distance, strength, false);
99           if (Item *rb = r->find_prebroken_piece (LEFT))
100             Spaceable_grob::add_spring (lc, rb, distance, strength, false);
101
102           continue;
103         }
104 #endif
105
106 Coherent_ligature_engraver::Coherent_ligature_engraver ()
107 {
108 }
109
110 /*
111  * TODO: move this function to class Item?
112  */
113 void
114 Coherent_ligature_engraver::get_set_column (Item *item, Paper_column *column)
115 {
116   Item *parent = dynamic_cast<Item*> (item->get_parent (X_AXIS));
117   if (!parent)
118     {
119       programming_error ("failed tweaking paper column in ligature");
120       return;
121     }
122
123   String name = parent->name ();
124   if (!String::compare (name, "PaperColumn"))
125     {
126       // Change column not only for targeted item (NoteColumn), but
127       // also for all associated grobs (NoteSpacing, SeparationItem).
128       Grob *sl = Staff_symbol_referencer::get_staff_symbol (item);
129       for (SCM tail = parent->get_property ("elements");
130            ly_c_pair_p (tail);
131            tail = ly_cdr (tail))
132         {
133           Item *sibling = unsmob_item (ly_car (tail));
134           if ((sibling) &&
135               (Staff_symbol_referencer::get_staff_symbol (sibling) == sl))
136             {
137 #if 0 // experimental code to collapse spacing after ligature
138               Grob *sibling_parent = sibling->get_parent (X_AXIS);
139               sibling_parent->warning (_f ("Coherent_ligature_engraver: "
140                                            "setting `spacing-increment = "
141                                            "0.01': ptr=%ul", parent));
142               sibling_parent->set_property ("forced-spacing",
143                                               scm_make_real (0.01));
144 #endif
145               sibling->set_parent (column, X_AXIS);
146             }
147         }
148     }
149   else
150     {
151       get_set_column (parent, column);
152     }
153 }
154
155 /*
156  * TODO: This function should collect all accidentals that occur
157  * within the ligature (by scanning through the primitives array) and
158  * place all of them at the left of the ligature.  If there is an
159  * alteration within the ligature (e.g. an "f" followed by a "fis"
160  * somewhere later in the ligature), issue a warning (and maybe create
161  * an additional natural symbol to explicitly make clear that there is
162  * an "f" first?).  The warning should suggest the user to break the
163  * ligature into two or more smaller ligatures such that no alteration
164  * occurs within the broken ligatures any more.
165  */
166 void
167 Coherent_ligature_engraver::collect_accidentals (Spanner *, Array<Grob_info>)
168 {
169   /* TODO */
170 }
171
172 void
173 compute_delta_pitches (Array<Grob_info> primitives)
174 {
175   int prev_pitch = 0;
176   int delta_pitch = 0;
177   Item *prev_primitive = 0, *primitive = 0;
178   for (int i = 0; i < primitives.size (); i++) {
179     primitive = dynamic_cast<Item*> (primitives[i].grob_);
180     Music *music_cause = primitives[i].music_cause ();
181     int pitch =
182       unsmob_pitch (music_cause->get_property ("pitch"))->steps ();
183     if (prev_primitive)
184       {
185         delta_pitch = pitch - prev_pitch;
186         prev_primitive->set_property ("delta-pitch",
187                                            scm_int2num (delta_pitch));
188       }
189     prev_pitch = pitch;
190     prev_primitive = primitive;
191   }
192   primitive->set_property ("delta-pitch", scm_int2num (0));
193 }
194
195 void
196 Coherent_ligature_engraver::build_ligature (Spanner *, Array<Grob_info>)
197 {
198   programming_error ("Coherent_ligature_engraver::build_ligature (): "
199                      "this is an abstract method that should not be called, "
200                      "but overridden by a subclass");
201 }
202
203 void
204 Coherent_ligature_engraver::typeset_ligature (Spanner *ligature,
205                                               Array<Grob_info> primitives)
206 {
207   // compute some commonly needed context info stored as grob
208   // properties
209   compute_delta_pitches (primitives);
210
211   // prepare ligature for typesetting
212   build_ligature (ligature, primitives);
213   collect_accidentals (ligature, primitives);
214 }
215
216 ENTER_DESCRIPTION (Coherent_ligature_engraver,
217 /* descr */       "This is an abstract class.  Subclasses such as Gregorian_ligature_engraver handle ligatures by glueing special ligature heads together.",
218 /* creats*/       "",
219 /* accepts */     "ligature-event",
220 /* acks  */      "note-head-interface rest-interface",
221 /* reads */       "",
222 /* write */       "");