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