- now_notes_.sort (CNote_melodic_tuple::pitch_compare);
- stopped_notes_.sort(CNote_melodic_tuple::pitch_compare);
- int i=0;
- int j=0;
- int tie_count=0;
- while ( i < now_notes_.size () && j < stopped_notes_.size ())
- {
- int comp
- = Pitch::compare (*unsmob_pitch (now_notes_[i].req_l_->get_mus_property ("pitch") ),
- *unsmob_pitch (stopped_notes_[j].req_l_->get_mus_property ("pitch")));
-
- if (comp)
- {
- (comp < 0) ? i ++ : j++;
- continue;
- }
- else
- {
- tie_count ++;
-
- /* don't go around recreating ties that were already
- made. Not infallible. Due to reordering in sort (),
- we will make the wrong ties when notenotes are
- added. */
- if (tie_count > tie_p_arr_.size ())
- {
- Audio_tie * p = new Audio_tie;
- p->set_note (LEFT, stopped_notes_[j].note_l_);
- p->set_note (RIGHT, now_notes_[i].note_l_);
- tie_p_arr_.push (p);
- announce_element (Audio_element_info (p, req_l_));
- }
- i++;
- j++;
-
- }
- }
-
- if (!tie_p_arr_.size ())
- {
- req_l_->origin ()->warning (_("No ties were created!"));
- }
-
+ // for each tied note, store the info and its end moment, so we can
+ // later on check whether (1) the note is still ongoing and (2) how
+ // long the skip is with tieWaitForNote
+ Head_audio_event_tuple inf_mom (inf, now_mom () + an->length_mom_);
+ if (an->tie_event_)
+ now_tied_heads_.push_back (inf_mom);
+ else
+ now_heads_.push_back (inf_mom);
+
+ // Find a previous note that ties to the current note. If it exists,
+ // remove it from the heads_to_tie vector and create the tie
+ list<Head_audio_event_tuple>::iterator it;
+ bool found = false;
+ Stream_event *right_mus = inf.event_;
+ for (it = heads_to_tie_.begin ();
+ !found && (it != heads_to_tie_.end ());
+ it++)
+ {
+ Audio_element_info et = (*it).head_;
+ Audio_note *th = dynamic_cast<Audio_note *> (et.elem_);
+ Stream_event *left_mus = et.event_;
+
+ if (th && right_mus && left_mus
+ && ly_is_equal (right_mus->get_property ("pitch"),
+ left_mus->get_property ("pitch")))
+ {
+ found = true;
+ // (*it).moment_ already stores the end of the tied note!
+ Moment skip = now_mom () - (*it).end_moment_;
+ an->tie_to (th, skip);
+ it = heads_to_tie_.erase (it);
+ }
+ }