- We could sort stopped_heads_ as well (and use a linear alg. in
- stead of nested loop), but we'd have to use a stable sorting
- algorithm, since the ordering of the stopped heads (of the
- same pitch) is relevant.
- */
-
- SCM head_list = SCM_EOL;
-
- for (int i = now_heads_.size(); i--;)
- {
- for (int j = stopped_heads_.size(); j--;)
- {
- int comp
- = head_pitch_compare (now_heads_[i], stopped_heads_[j]);
-
- if (!comp)
- {
- head_list = gh_cons (gh_cons (stopped_heads_[j]->self_scm (),
- now_heads_[i]->self_scm ()),
- head_list);
-
- now_heads_.del (i);
- stopped_heads_.del (j);
- break ;
- }
- }
- }
-
- SCM basic = get_property ("Tie");
- SCM sparse = get_property ("sparseTies");
- if (to_boolean (sparse))
- {
- int i = scm_ilength (head_list);
-
- if (!i)
- return;
-
- SCM pair = scm_list_ref (head_list, gh_int2scm (i/2));
-
- Spanner * p = new Spanner (basic);
-
- Tie::set_interface (p); // cannot remove.
- Tie::set_head (p,LEFT, dynamic_cast<Item*> (unsmob_grob (ly_car (pair))));
- Tie::set_head (p,RIGHT, dynamic_cast<Item*> (unsmob_grob (ly_cdr (pair))));
-
- ties_.push (p);
- announce_grob(p, event_->self_scm());
- }
- else for (SCM s = head_list; gh_pair_p (s); s = ly_cdr (s))
- {
- Grob * p = new Spanner (basic);
- Tie::set_interface (p); // cannot remove yet!
-
- Tie::set_head (p, LEFT, dynamic_cast<Item*> (unsmob_grob (ly_caar (s))));
- Tie::set_head (p, RIGHT, dynamic_cast<Item*> (unsmob_grob (ly_cdar (s))));
-
- ties_.push (p);
- announce_grob(p, event_->self_scm());
- }
-
- if (ties_.size () > 1 && !tie_column_)
- {
- tie_column_ = new Spanner (get_property ("TieColumn"));
-
- for (int i = ties_.size (); i--;)
- Tie_column::add_tie (tie_column_,ties_ [i]);
- announce_grob(tie_column_, SCM_EOL);
- }
+ maybe should check positions too.
+ */
+ if (!right_ev || !left_ev)
+ continue;
+
+ /*
+ Make a tie only if pitches are equal or if event end was not generated by
+ Completion_heads_engraver.
+ */
+ SCM p1 = left_ev->get_property ("pitch");
+ SCM p2 = right_ev->get_property ("pitch");
+ if ((enharmonic
+ ? (unsmob<Pitch> (p1) && unsmob<Pitch> (p2) &&
+ unsmob<Pitch> (p1)->tone_pitch () == unsmob<Pitch> (p2)->tone_pitch ())
+ : ly_is_equal (p1, p2))
+ && (!Tie_engraver::has_autosplit_end (left_ev)))
+ {
+ Spanner *p = heads_to_tie_[i].tie_;
+ Moment end = heads_to_tie_[i].end_moment_;
+
+ Stream_event *cause = heads_to_tie_[i].tie_event_
+ ? heads_to_tie_[i].tie_event_
+ : heads_to_tie_[i].tie_stream_event_;
+
+ announce_end_grob (p, cause->self_scm ());
+
+ Tie::set_head (p, LEFT, th);
+ Tie::set_head (p, RIGHT, h);
+
+ if (is_direction (cause->get_property ("direction")))
+ {
+ Direction d = to_dir (cause->get_property ("direction"));
+ p->set_property ("direction", scm_from_int (d));
+ }
+
+ ties_.push_back (p);
+ heads_to_tie_.erase (heads_to_tie_.begin () + i);
+
+ found = true;
+ /*
+ Prevent all other tied notes ending at the same moment (assume
+ implicitly the notes have also started at the same moment!)
+ from triggering an "unterminated tie" warning. Needed e.g. for
+ <c e g>~ g
+ */
+ for (vsize j = heads_to_tie_.size (); j--;)
+ {
+ if (heads_to_tie_[j].end_moment_ == end)
+ heads_to_tie_[j].tie_from_chord_created = true;
+ }
+ break;
+ }