+ bool completed;
+ for (vsize j = slurs_.size (); !(completed = (j-- == 0));)
+ {
+ // 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 phrasing 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 ("phrasing 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 ("PhrasingSlur", ev->self_scm ());
+ slur->set_property ("spanner-id", ly_string2scm (id));
+ if (updown)
+ set_grob_direction (slur, updown);
+ slurs_.push_back (slur);
+ }