]> git.donarmstrong.com Git - lilypond.git/blob - lily/coherent-ligature-engraver.cc
Doc-es: various updates.
[lilypond.git] / lily / coherent-ligature-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2003--2015 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  * - except in Kievan notation, collect all accidentals that occur
44  * within the ligature and put them at the left side of the ligature
45  * (TODO; see function 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  * TODO: move this function to class Item?
88  */
89 void
90 Coherent_ligature_engraver::move_related_items_to_column
91 (Item *item, Paper_column *target_column, Real offset)
92 {
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--;)
97     {
98       Item *sibling = elements[i];
99       if (!sibling)
100         // should not occur, but who knows... -jr
101         continue;
102
103       if (Staff_symbol_referencer::get_staff_symbol (sibling) != staff_symbol)
104         // sibling is from a staff different than that of the item of
105         // interest
106         continue;
107
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));
115 #endif
116
117       sibling->set_parent (target_column, X_AXIS);
118       sibling->translate_axis (offset, X_AXIS);
119     }
120 }
121
122 /*
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.
132  */
133 void
134 Coherent_ligature_engraver::collect_accidentals (Spanner *,
135                                                  vector<Grob_info> const &)
136 {
137   /* TODO */
138   /* NOTE: if implementing such a function, note that in Kievan notation,
139    * the B-flat accidental should not be "collected", but rather prints
140    * immediately before the note head as usual. */
141 }
142
143 void
144 compute_delta_pitches (vector<Grob_info> const &primitives)
145 {
146   int prev_pitch = 0;
147   int delta_pitch = 0;
148   Item *prev_primitive = 0, *primitive = 0;
149   for (vsize i = 0; i < primitives.size (); i++)
150     {
151       primitive = dynamic_cast<Item *> (primitives[i].grob ());
152       Stream_event *cause = primitives[i].event_cause ();
153       int pitch
154         = unsmob<Pitch> (cause->get_property ("pitch"))->steps ();
155       if (prev_primitive)
156         {
157           delta_pitch = pitch - prev_pitch;
158           prev_primitive->set_property ("delta-position",
159                                         scm_from_int (delta_pitch));
160         }
161       prev_pitch = pitch;
162       prev_primitive = primitive;
163     }
164   primitive->set_property ("delta-position", scm_from_int (0));
165 }
166
167 void
168 Coherent_ligature_engraver::typeset_ligature (Spanner *ligature,
169                                               vector<Grob_info> const &primitives)
170 {
171   // compute some commonly needed context info stored as grob
172   // properties
173   compute_delta_pitches (primitives);
174
175   // prepare ligature for typesetting
176   build_ligature (ligature, primitives);
177   collect_accidentals (ligature, primitives);
178 }
179
180 // no ADD_ACKNOWLEDGER / ADD_ACKNOWLEDGER / ADD_TRANSLATOR macro calls
181 // since this class is abstract