X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fslur-engraver.cc;h=0a36aa10f2afb04439bab69b49c72263871e87ca;hb=c95f2748cdc044c16714c59cd138813eeac222ea;hp=79f04d6203cf6b0f7bc41897a2c401a0b0b38064;hpb=6a1a605d8235d799c5f19f334c9341e19e2d587c;p=lilypond.git diff --git a/lily/slur-engraver.cc b/lily/slur-engraver.cc index 79f04d6203..0a36aa10f2 100644 --- a/lily/slur-engraver.cc +++ b/lily/slur-engraver.cc @@ -71,6 +71,7 @@ protected: void process_music (); virtual void finalize (); + virtual void derived_mark () const; public: TRANSLATOR_DECLARATIONS (Slur_engraver); @@ -80,6 +81,15 @@ Slur_engraver::Slur_engraver () { } +void +Slur_engraver::derived_mark () const +{ + for (vsize i=start_events_.size(); i--;) + scm_gc_mark (start_events_[i]->self_scm ()); + for (vsize i=stop_events_.size(); i--;) + scm_gc_mark (stop_events_[i]->self_scm ()); +} + IMPLEMENT_TRANSLATOR_LISTENER (Slur_engraver, slur); void Slur_engraver::listen_slur (Stream_event *ev) @@ -166,6 +176,7 @@ Slur_engraver::finalize () slurs_[i]->warning (_ ("unterminated slur")); slurs_[i]->suicide (); } + slurs_.clear (); } void @@ -176,54 +187,88 @@ Slur_engraver::process_music () Stream_event *ev = stop_events_[i]; string id = robust_scm2string (ev->get_property ("spanner-id"), ""); - // Find the slur that is ended with this event (by checking the spanner-id) + // Find the slurs that are ended with this event (by checking the spanner-id) bool ended = false; - SCM starter = SCM_BOOL_F; for (vsize j = slurs_.size (); j--;) { if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")) { - // We end only one slur unless several ones have been - // caused by the same event, like with double slurs. - if (!ended || scm_is_eq (starter, - slurs_[j]->get_property ("cause"))) - { - ended = true; - starter = slurs_[j]->get_property ("cause"); - end_slurs_.push_back (slurs_[j]); - slurs_.erase (slurs_.begin () + j); - } + ended = true; + end_slurs_.push_back (slurs_[j]); + slurs_.erase (slurs_.begin () + j); + } + } + if (ended) + { + // Ignore redundant stop events for this id + for (vsize j = stop_events_.size (); --j > i;) + { + if (id == robust_scm2string (stop_events_[j]->get_property ("spanner-id"), "")) + stop_events_.erase (stop_events_.begin() + j); } } - if (!ended) + else ev->origin ()->warning (_ ("cannot end slur")); } + vsize old_slurs = slurs_.size (); for (vsize i = start_events_.size (); i--;) { Stream_event *ev = start_events_[i]; string id = robust_scm2string (ev->get_property ("spanner-id"), ""); - bool have_slur = false; - // Check if we already have a slur with the same spanner-id. - // In that case, don't create a new slur, but print a warning - for (vsize j = 0; j < slurs_.size (); j++) - have_slur = have_slur || (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")); + Direction updown = to_dir (ev->get_property ("direction")); - if (have_slur) + bool completed; + for (vsize j = slurs_.size (); !(completed = (j-- == 0));) { - // We already have a slur, so give a warning and completely ignore - // the new slur. - ev->origin ()->warning (_ ("already have slur")); - start_events_.erase (start_events_.begin () + i); - } - } - for (vsize i = start_events_.size (); i--;) - { - Stream_event *ev = start_events_[i]; - string id = robust_scm2string (ev->get_property ("spanner-id"), ""); + // Check if we already have a slur with the same spanner-id. + if (id == robust_scm2string (slurs_[j]->get_property ("spanner-id"), "")) + { + if (j < old_slurs) + { + // We already have an old slur, so give a warning + // and completely ignore the new slur. + ev->origin ()->warning (_ ("already have slur")); + start_events_.erase (start_events_.begin () + i); + break; + } + + // If this slur event has no direction, it will not + // contribute anything new to the existing slur(s), so + // we can ignore it. + + if (!updown) + break; + + Stream_event *c = unsmob_stream_event (slurs_[j]->get_property ("cause")); + + if (!c) { + slurs_[j]->programming_error ("slur without a cause"); + continue; + } + + Direction slur_dir = to_dir (c->get_property ("direction")); + // If the existing slur does not have a direction yet, + // we'd rather take the new one. + + if (!slur_dir) + { + slurs_[j]->suicide (); + slurs_.erase (slurs_.begin () + j); + continue; + } + + // If the existing slur has the same direction as ours, drop ours + + if (slur_dir == updown) + break; + } + } + // If the loop completed, our slur is new + if (completed) + { Grob *slur = make_spanner ("Slur", ev->self_scm ()); - Direction updown = to_dir (ev->get_property ("direction")); slur->set_property ("spanner-id", ly_string2scm (id)); if (updown) set_grob_direction (slur, updown); @@ -237,6 +282,7 @@ Slur_engraver::process_music () set_grob_direction (slur, UP); slurs_.push_back (slur); } + } } set_melisma (slurs_.size ()); }