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"
27 #include "slur-proto-engraver.hh"
29 #include "stream-event.hh"
32 #include "translator.icc"
35 Slur_proto_engraver::derived_mark () const
37 for (vsize i = start_events_.size (); i--;)
38 scm_gc_mark (start_events_[i]->self_scm ());
39 for (vsize i = stop_events_.size (); i--;)
40 scm_gc_mark (stop_events_[i]->self_scm ());
44 Slur_proto_engraver::internal_listen_slur (Stream_event *ev)
46 Direction d = to_dir (ev->get_property ("span-direction"));
48 start_events_.push_back (ev);
50 stop_events_.push_back (ev);
51 else ev->origin ()->warning (_f ("direction of %s invalid: %d",
52 event_name_, int (d)));
56 Slur_proto_engraver::acknowledge_note_column (Grob_info info)
58 Grob *e = info.grob ();
59 for (vsize i = slurs_.size (); i--;)
60 Slur::add_column (slurs_[i], e);
61 for (vsize i = end_slurs_.size (); i--;)
62 Slur::add_column (end_slurs_[i], e);
66 Slur_proto_engraver::acknowledge_extra_object (Grob_info info)
68 objects_to_acknowledge_.push_back (info);
72 Slur_proto_engraver::acknowledge_inline_accidental (Grob_info info)
74 acknowledge_extra_object (info);
78 Slur_proto_engraver::acknowledge_dots (Grob_info info)
80 acknowledge_extra_object (info);
84 Slur_proto_engraver::acknowledge_fingering (Grob_info info)
86 acknowledge_extra_object (info);
90 Slur_proto_engraver::acknowledge_tuplet_number (Grob_info info)
92 acknowledge_extra_object (info);
96 Slur_proto_engraver::acknowledge_script (Grob_info info)
98 if (!info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
99 acknowledge_extra_object (info);
103 Slur_proto_engraver::acknowledge_text_script (Grob_info info)
105 acknowledge_extra_object (info);
109 Slur_proto_engraver::acknowledge_end_tie (Grob_info info)
111 acknowledge_extra_object (info);
115 Slur_proto_engraver::finalize ()
117 for (vsize i = 0; i < slurs_.size (); i++)
119 slurs_[i]->warning (_f ("unterminated %s", object_name_));
120 slurs_[i]->suicide ();
126 Slur_proto_engraver::create_slur (const string &spanner_id, Stream_event *ev_cause, Grob *g_cause, Direction dir, bool left_broken)
128 Grob *ccc = Grob::unsmob (get_property ("currentCommandColumn"));
129 SCM cause = ev_cause ? ev_cause->self_scm () : g_cause->self_scm ();
130 Spanner *slur = make_spanner (grob_name_, cause);
131 slur->set_property ("spanner-id", ly_string2scm (spanner_id));
133 set_grob_direction (slur, dir);
135 slur->set_bound (LEFT, ccc);
136 slurs_.push_back (slur);
137 if (double_property_name_
138 && to_boolean (get_property (double_property_name_)))
140 set_grob_direction (slur, DOWN);
141 slur = make_spanner (grob_name_, cause);
142 slur->set_property ("spanner-id", ly_string2scm (spanner_id));
143 set_grob_direction (slur, UP);
145 slur->set_bound (LEFT, ccc);
146 slurs_.push_back (slur);
152 Slur_proto_engraver::can_create_slur (const string &id, vsize old_slurs, vsize *event_idx, Stream_event *ev)
154 for (vsize j = slurs_.size (); j--;)
156 Grob *slur = slurs_[j];
157 Direction updown = to_dir (ev->get_property ("direction"));
159 // Check if we already have a slur with the same spanner-id.
160 if (id == robust_scm2string (slur->get_property ("spanner-id"), ""))
164 // We already have an old slur, so give a warning
165 // and completely ignore the new slur.
166 ev->origin ()->warning (_f ("already have %s", object_name_));
168 start_events_.erase (start_events_.begin () + (*event_idx));
172 // If this slur event has no direction, it will not
173 // contribute anything new to the existing slur(s), so
179 Stream_event *c = Stream_event::unsmob (slur->get_property ("cause"));
183 slur->programming_error (_f ("%s without a cause", object_name_));
187 Direction slur_dir = to_dir (c->get_property ("direction"));
189 // If the existing slur does not have a direction yet,
190 // we'd rather take the new one.
195 slurs_.erase (slurs_.begin () + j);
199 // If the existing slur has the same direction as ours, drop ours
201 if (slur_dir == updown)
209 Slur_proto_engraver::try_to_end (Stream_event *ev)
211 string id = robust_scm2string (ev->get_property ("spanner-id"), "");
213 // Find the slurs that are ended with this event (by checking the spanner-id)
215 for (vsize j = slurs_.size (); j--;)
217 if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), ""))
220 end_slurs_.push_back (slurs_[j]);
221 slurs_.erase (slurs_.begin () + j);
228 Slur_proto_engraver::process_music ()
230 for (vsize i = 0; i < stop_events_.size (); i++)
232 string id = robust_scm2string (stop_events_[i]->get_property ("spanner-id"), "");
233 bool ended = try_to_end (stop_events_[i]);
236 // Ignore redundant stop events for this id
237 for (vsize j = stop_events_.size (); --j > i;)
239 if (id == robust_scm2string (stop_events_[j]->get_property ("spanner-id"), ""))
240 stop_events_.erase (stop_events_.begin () + j);
244 stop_events_[i]->origin ()->warning (_f ("cannot end %s", object_name_));
247 vsize old_slurs = slurs_.size ();
248 for (vsize i = start_events_.size (); i--;)
250 Stream_event *ev = start_events_[i];
251 string id = robust_scm2string (ev->get_property ("spanner-id"), "");
252 Direction updown = to_dir (ev->get_property ("direction"));
254 if (can_create_slur (id, old_slurs, &i, ev))
255 create_slur (id, ev, 0, updown, false);
258 set_melisma (slurs_.size ());
262 Slur_proto_engraver::set_melisma (bool)
267 Slur_proto_engraver::stop_translation_timestep ()
269 if (Grob *g = Grob::unsmob (get_property ("currentCommandColumn")))
271 for (vsize i = 0; i < end_slurs_.size (); i++)
272 Slur::add_extra_encompass (end_slurs_[i], g);
274 if (!start_events_.size ())
275 for (vsize i = 0; i < slurs_.size (); i++)
276 Slur::add_extra_encompass (slurs_[i], g);
279 for (vsize i = 0; i < end_slurs_.size (); i++)
281 Spanner *s = dynamic_cast<Spanner *> (end_slurs_[i]);
282 if (!s->get_bound (RIGHT))
283 s->set_bound (RIGHT, Grob::unsmob (get_property ("currentMusicalColumn")));
284 announce_end_grob (s, SCM_EOL);
287 for (vsize i = 0; i < objects_to_acknowledge_.size (); i++)
288 Slur::auxiliary_acknowledge_extra_object (objects_to_acknowledge_[i], slurs_, end_slurs_);
290 objects_to_acknowledge_.clear ();
292 start_events_.clear ();
293 stop_events_.clear ();
296 // no ADD_ACKNOWLEDGER / ADD_TRANSLATOR macro calls
297 // since this class is abstract