- // 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);
+ // 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;
+ }