2 tie-performer.cc -- implement Tie_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "tie-performer.hh"
11 #include "command-request.hh"
12 #include "audio-item.hh"
13 #include "musical-request.hh"
16 ADD_THIS_TRANSLATOR (Tie_performer);
18 Tie_performer::Tie_performer()
24 Tie_performer::do_try_music (Music *m)
28 if (Tie_req * c = dynamic_cast<Tie_req*> (m))
38 Tie_performer::acknowledge_element (Audio_element_info i)
40 if (Audio_note *nh = dynamic_cast<Audio_note *> (i.elem_l_))
42 Note_req * m = dynamic_cast<Note_req* > (i.req_l_);
45 now_notes_.push (CNote_melodic_tuple (nh, m, now_mom()+ m->length_mom ()));
50 Tie_performer::do_process_music ()
54 Moment now = now_mom ();
55 Link_array<Audio_note> nharr;
57 stopped_notes_.clear ();
58 while (past_notes_pq_.size ()
59 && past_notes_pq_.front ().end_ == now)
60 stopped_notes_.push (past_notes_pq_.get ());
65 Tie_performer::process_acknowledged ()
69 now_notes_.sort (CNote_melodic_tuple::pitch_compare);
70 stopped_notes_.sort(CNote_melodic_tuple::pitch_compare);
74 while ( i < now_notes_.size () && j < stopped_notes_.size ())
77 = Musical_pitch::compare (now_notes_[i].req_l_->pitch_ ,
78 stopped_notes_[j].req_l_->pitch_);
82 (comp < 0) ? i ++ : j++;
89 /* don't go around recreating ties that were already
90 made. Not infallible. Due to reordering in sort (),
91 we will make the wrong ties when notenotes are
93 if (tie_count > tie_p_arr_.size ())
95 Audio_tie * p = new Audio_tie;
96 p->set_note (LEFT, stopped_notes_[j].note_l_);
97 p->set_note (RIGHT, now_notes_[i].note_l_);
99 announce_element (Audio_element_info (p, req_l_));
107 if (!tie_p_arr_.size ())
109 req_l_->origin ()->warning (_("No ties were created!"));
116 Tie_performer::do_pre_move_processing ()
118 for (int i=0; i < now_notes_.size (); i++)
120 past_notes_pq_.insert (now_notes_[i]);
124 for (int i=0; i< tie_p_arr_.size (); i++)
126 //play_element (tie_p_arr_[i]);
127 tie_p_arr_[i]->note_l_drul_[RIGHT]->tie_to (tie_p_arr_[i]->note_l_drul_[LEFT]);
133 Tie_performer::do_post_move_processing ()
136 Moment now = now_mom ();
137 while (past_notes_pq_.size () && past_notes_pq_.front ().end_ < now)
138 past_notes_pq_.delmin ();
142 CNote_melodic_tuple::CNote_melodic_tuple ()
149 CNote_melodic_tuple::CNote_melodic_tuple (Audio_note *h, Melodic_req*m, Moment mom)
157 CNote_melodic_tuple::pitch_compare (CNote_melodic_tuple const&h1,
158 CNote_melodic_tuple const &h2)
160 return Melodic_req::compare (*h1.req_l_, *h2.req_l_);
164 CNote_melodic_tuple::time_compare (CNote_melodic_tuple const&h1,
165 CNote_melodic_tuple const &h2)
167 return (h1.end_ - h2.end_ ).sign ();