2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2013--2015 Mike Solomon <mike@mikesolomon.org>
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 "engraver.hh"
23 #include "directional-element-interface.hh"
24 #include "international.hh"
25 #include "note-column.hh"
26 #include "pointer-group-interface.hh"
28 #include "slur-proto-engraver.hh"
30 #include "stream-event.hh"
33 #include "translator.icc"
36 Slur_proto_engraver::derived_mark () const
38 for (vsize i = start_events_.size (); i--;)
40 scm_gc_mark (start_events_[i].slur_->self_scm ());
41 if (start_events_[i].note_)
42 scm_gc_mark (start_events_[i].note_->self_scm ());
44 for (vsize i = stop_events_.size (); i--;)
46 scm_gc_mark (stop_events_[i].slur_->self_scm ());
47 if (stop_events_[i].note_)
48 scm_gc_mark (stop_events_[i].note_->self_scm ());
53 Slur_proto_engraver::listen_slur (Stream_event *ev, Stream_event *note)
55 Direction d = to_dir (ev->get_property ("span-direction"));
57 start_events_.push_back (Event_info (ev, note));
59 stop_events_.push_back (Event_info (ev, note));
60 else ev->origin ()->warning (_f ("direction of %s invalid: %d",
61 event_name_, int (d)));
65 Slur_proto_engraver::listen_note (Stream_event *ev)
67 for (SCM arts = ev->get_property ("articulations");
68 scm_is_pair (arts); arts = scm_cdr (arts))
70 Stream_event *art = unsmob<Stream_event> (scm_car (arts));
71 if (art->in_event_class (event_symbol ()))
72 listen_slur (art, ev);
77 Slur_proto_engraver::acknowledge_note_column (Grob_info info)
79 Grob *e = info.grob ();
80 for (vsize i = slurs_.size (); i--;)
81 Slur::add_column (slurs_[i], e);
82 for (vsize i = end_slurs_.size (); i--;)
83 Slur::add_column (end_slurs_[i], e);
84 // Now cater for slurs starting/ending at a notehead: those override
86 if (note_slurs_[START].empty () && note_slurs_[STOP].empty ())
88 extract_grob_set (e, "note-heads", heads);
89 for (vsize i = heads.size (); i--;)
91 if (Stream_event *ev =
92 unsmob<Stream_event> (heads[i]->get_property ("cause")))
93 for (LEFT_and_RIGHT (d))
95 std::pair<Note_slurs::const_iterator, Note_slurs::const_iterator> its
96 = note_slurs_[d].equal_range (ev);
97 for (Note_slurs::const_iterator it = its.first;
100 it->second->set_bound (d, heads[i]);
106 Slur_proto_engraver::acknowledge_extra_object (Grob_info info)
108 objects_to_acknowledge_.push_back (info);
112 Slur_proto_engraver::acknowledge_inline_accidental (Grob_info info)
114 acknowledge_extra_object (info);
118 Slur_proto_engraver::acknowledge_dots (Grob_info info)
120 acknowledge_extra_object (info);
124 Slur_proto_engraver::acknowledge_fingering (Grob_info info)
126 acknowledge_extra_object (info);
130 Slur_proto_engraver::acknowledge_tuplet_number (Grob_info info)
132 acknowledge_extra_object (info);
136 Slur_proto_engraver::acknowledge_script (Grob_info info)
138 if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
139 acknowledge_extra_object (info);
143 Slur_proto_engraver::acknowledge_text_script (Grob_info info)
145 acknowledge_extra_object (info);
149 Slur_proto_engraver::acknowledge_end_tie (Grob_info info)
151 acknowledge_extra_object (info);
155 Slur_proto_engraver::finalize ()
157 for (vsize i = 0; i < slurs_.size (); i++)
159 slurs_[i]->warning (_f ("unterminated %s", object_name_));
160 slurs_[i]->suicide ();
166 Slur_proto_engraver::create_slur (const string &spanner_id, Event_info evi, Grob *g_cause, Direction dir, bool left_broken)
168 Grob *ccc = left_broken
169 ? unsmob<Grob> (get_property ("currentCommandColumn"))
171 SCM cause = evi.slur_ ? evi.slur_->self_scm () : g_cause->self_scm ();
172 Spanner *slur = make_spanner (grob_name_, cause);
173 slur->set_property ("spanner-id", ly_string2scm (spanner_id));
175 set_grob_direction (slur, dir);
177 slur->set_bound (LEFT, ccc);
178 slurs_.push_back (slur);
180 note_slurs_[START].insert (Note_slurs::value_type (evi.note_, slur));
182 if (double_property_name_
183 && to_boolean (get_property (double_property_name_)))
185 set_grob_direction (slur, DOWN);
186 slur = make_spanner (grob_name_, cause);
187 slur->set_property ("spanner-id", ly_string2scm (spanner_id));
188 set_grob_direction (slur, UP);
190 slur->set_bound (LEFT, ccc);
191 slurs_.push_back (slur);
193 note_slurs_[START].insert(Note_slurs::value_type (evi.note_, slur));
199 Slur_proto_engraver::can_create_slur (const string &id, vsize old_slurs, vsize *event_idx, Stream_event *ev)
201 for (vsize j = slurs_.size (); j--;)
203 Grob *slur = slurs_[j];
204 Direction updown = to_dir (ev->get_property ("direction"));
206 // Check if we already have a slur with the same spanner-id.
207 if (id == robust_scm2string (slur->get_property ("spanner-id"), ""))
211 // We already have an old slur, so give a warning
212 // and completely ignore the new slur.
213 ev->origin ()->warning (_f ("already have %s", object_name_));
215 start_events_.erase (start_events_.begin () + (*event_idx));
219 // If this slur event has no direction, it will not
220 // contribute anything new to the existing slur(s), so
226 Stream_event *c = unsmob<Stream_event> (slur->get_property ("cause"));
230 slur->programming_error (_f ("%s without a cause", object_name_));
234 Direction slur_dir = to_dir (c->get_property ("direction"));
236 // If the existing slur does not have a direction yet,
237 // we'd rather take the new one.
242 slurs_.erase (slurs_.begin () + j);
246 // If the existing slur has the same direction as ours, drop ours
248 if (slur_dir == updown)
256 Slur_proto_engraver::try_to_end (Event_info evi)
258 string id = robust_scm2string (evi.slur_->get_property ("spanner-id"), "");
260 // Find the slurs that are ended with this event (by checking the spanner-id)
262 for (vsize j = slurs_.size (); j--;)
264 if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), ""))
267 end_slurs_.push_back (slurs_[j]);
269 note_slurs_[STOP].insert
270 (Note_slurs::value_type
271 (evi.note_, dynamic_cast <Spanner *> (slurs_[j])));
272 slurs_.erase (slurs_.begin () + j);
279 Slur_proto_engraver::process_music ()
281 for (vsize i = 0; i < stop_events_.size (); i++)
283 string id = robust_scm2string
284 (stop_events_[i].slur_->get_property ("spanner-id"), "");
285 bool ended = try_to_end (stop_events_[i]);
288 // Ignore redundant stop events for this id
289 for (vsize j = stop_events_.size (); --j > i;)
291 if (id == robust_scm2string
292 (stop_events_[j].slur_->get_property ("spanner-id"), ""))
293 stop_events_.erase (stop_events_.begin () + j);
297 stop_events_[i].slur_->origin ()->warning (_f ("cannot end %s", object_name_));
300 vsize old_slurs = slurs_.size ();
301 for (vsize i = start_events_.size (); i--;)
303 Stream_event *ev = start_events_[i].slur_;
304 string id = robust_scm2string (ev->get_property ("spanner-id"), "");
305 Direction updown = to_dir (ev->get_property ("direction"));
307 if (can_create_slur (id, old_slurs, &i, ev))
308 create_slur (id, start_events_[i], 0, updown, false);
311 set_melisma (slurs_.size ());
315 Slur_proto_engraver::set_melisma (bool)
320 Slur_proto_engraver::stop_translation_timestep ()
322 if (Grob *g = unsmob<Grob> (get_property ("currentCommandColumn")))
324 for (vsize i = 0; i < end_slurs_.size (); i++)
325 Slur::add_extra_encompass (end_slurs_[i], g);
327 if (!start_events_.size ())
328 for (vsize i = 0; i < slurs_.size (); i++)
329 Slur::add_extra_encompass (slurs_[i], g);
332 for (vsize i = 0; i < end_slurs_.size (); i++)
334 Spanner *s = dynamic_cast<Spanner *> (end_slurs_[i]);
335 if (!s->get_bound (RIGHT))
336 s->set_bound (RIGHT, unsmob<Grob> (get_property ("currentMusicalColumn")));
337 announce_end_grob (s, SCM_EOL);
340 for (vsize i = 0; i < objects_to_acknowledge_.size (); i++)
341 Slur::auxiliary_acknowledge_extra_object (objects_to_acknowledge_[i], slurs_, end_slurs_);
343 note_slurs_[LEFT].clear ();
344 note_slurs_[RIGHT].clear ();
345 objects_to_acknowledge_.clear ();
347 start_events_.clear ();
348 stop_events_.clear ();
351 // no ADD_ACKNOWLEDGER / ADD_TRANSLATOR macro calls
352 // since this class is abstract