2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2003--2011 Juergen Reuter <reuter@ipd.uka.de>
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.
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.
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/>.
20 #include "coherent-ligature-engraver.hh"
23 #include "paper-column.hh"
25 #include "pointer-group-interface.hh"
27 #include "staff-symbol-referencer.hh"
28 #include "stream-event.hh"
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
38 * - provide a function for putting all grobs of the ligature into a
39 * single paper column,
41 * - delegate actual creation of ligature to concrete subclass,
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 ()),
47 * - collapse superflous space after each ligature (TODO).
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.
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.
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.
70 * TODO: make spacing more robust: do not screw up spacing if user
71 * erroneously puts rest in ligature.
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.
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.
87 * TODO: move this function to class Item?
90 Coherent_ligature_engraver::move_related_items_to_column
91 (Item *item, Paper_column *target_column, Real offset)
93 Paper_column *source_column = item->get_column ();
94 Grob *staff_symbol = Staff_symbol_referencer::get_staff_symbol (item);
95 extract_item_set (source_column, "elements", elements);
96 for (vsize i = elements.size (); i--;)
98 Item *sibling = elements[i];
100 // should not occur, but who knows... -jr
103 if (Staff_symbol_referencer::get_staff_symbol (sibling) != staff_symbol)
104 // sibling is from a staff different than that of the item of
108 #if 0 /* experimental code to collapse spacing after ligature */
109 Grob *sibling_parent = sibling->get_parent (X_AXIS);
110 sibling_parent->warning (_f ("Coherent_ligature_engraver: "
111 "setting `spacing-increment="
112 "0.01': ptr=%ul", parent));
113 sibling_parent->set_property ("forced-spacing",
114 scm_from_double (0.01));
117 sibling->set_parent (target_column, X_AXIS);
118 sibling->translate_axis (offset, X_AXIS);
123 * TODO: This function should collect all accidentals that occur
124 * within the ligature (by scanning through the primitives array) and
125 * place all of them at the left of the ligature. If there is an
126 * alteration within the ligature (e.g. an "f" followed by a "fis"
127 * somewhere later in the ligature), issue a warning (and maybe create
128 * an additional natural symbol to explicitly make clear that there is
129 * an "f" first?). The warning should suggest the user to break the
130 * ligature into two or more smaller ligatures such that no alteration
131 * occurs within the broken ligatures any more.
134 Coherent_ligature_engraver::collect_accidentals (Spanner *, vector<Grob_info>)
140 compute_delta_pitches (vector<Grob_info> primitives)
144 Item *prev_primitive = 0, *primitive = 0;
145 for (vsize i = 0; i < primitives.size (); i++)
147 primitive = dynamic_cast<Item *> (primitives[i].grob ());
148 Stream_event *cause = primitives[i].event_cause ();
150 = unsmob_pitch (cause->get_property ("pitch"))->steps ();
153 delta_pitch = pitch - prev_pitch;
154 prev_primitive->set_property ("delta-position",
155 scm_from_int (delta_pitch));
158 prev_primitive = primitive;
160 primitive->set_property ("delta-position", scm_from_int (0));
164 Coherent_ligature_engraver::typeset_ligature (Spanner *ligature,
165 vector<Grob_info> primitives)
167 // compute some commonly needed context info stored as grob
169 compute_delta_pitches (primitives);
171 // prepare ligature for typesetting
172 build_ligature (ligature, primitives);
173 collect_accidentals (ligature, primitives);
176 // no ADD_ACKNOWLEDGER / ADD_ACKNOWLEDGER / ADD_TRANSLATOR macro calls
177 // since this class is abstract