2 ctie-engraver.cc -- implement Tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "tie-engraver.hh"
11 #include "command-request.hh"
12 #include "note-head.hh"
13 #include "musical-request.hh"
16 Tie_engraver::Tie_engraver()
23 Tie_engraver::do_try_music (Music *m)
25 if (Tie_req * c = dynamic_cast<Tie_req*> (m))
34 Tie_engraver::acknowledge_element (Score_element_info i)
36 if (Note_head *nh = dynamic_cast<Note_head *> (i.elem_l_))
38 Note_req * m = dynamic_cast<Note_req* > (i.req_l_);
41 now_heads_.push (CHead_melodic_tuple (nh, m, now_mom()+ m->length_mom ()));
46 Tie_engraver::do_process_requests ()
50 Moment now = now_mom ();
51 Link_array<Note_head> nharr;
53 stopped_heads_.clear ();
54 while (past_notes_pq_.size ()
55 && past_notes_pq_.front ().end_ == now)
56 stopped_heads_.push (past_notes_pq_.get ());
61 Tie_engraver::process_acknowledged ()
63 bool old_behavior = get_property ("oldTieBehavior", 0).to_bool ();
73 if (now_heads_.size () != stopped_heads_.size ())
75 req_l_->warning ("Unequal number of note heads for tie");
77 int sz = now_heads_.size () <? stopped_heads_.size ();
79 /* hmm. Should do something more sensible.
80 because, we assume no more noteheads come along after the 1st pass.
82 if (sz <= tie_p_arr_.size ())
85 now_heads_.sort (CHead_melodic_tuple::pitch_compare);
86 stopped_heads_.sort(CHead_melodic_tuple::pitch_compare);
88 for (int i=0; i < sz; i++)
91 p->set_head (LEFT, stopped_heads_[i].head_l_);
92 p->set_head (RIGHT, now_heads_[i].head_l_);
94 announce_element (Score_element_info (p, req_l_));
99 now_heads_.sort (CHead_melodic_tuple::pitch_compare);
100 stopped_heads_.sort(CHead_melodic_tuple::pitch_compare);
104 while ( i < now_heads_.size () && j < stopped_heads_.size ())
107 = Musical_pitch::compare (now_heads_[i].req_l_->pitch_ ,
108 stopped_heads_[j].req_l_->pitch_);
112 (comp < 0) ? i ++ : j++;
119 /* don't go around recreating ties that were already
120 made. Not infallible. Due to reordering in sort (),
121 we will make the wrong ties when noteheads are
123 if (tie_count > tie_p_arr_.size ())
126 p->set_head (LEFT, stopped_heads_[j].head_l_);
127 p->set_head (RIGHT, now_heads_[i].head_l_);
129 announce_element (Score_element_info (p, req_l_));
137 if (!tie_p_arr_.size ())
139 req_l_->warning (_("No ties were created!"));
147 Tie_engraver::do_pre_move_processing ()
149 for (int i=0; i < now_heads_.size (); i++)
151 past_notes_pq_.insert (now_heads_[i]);
155 Scalar dir (get_property ("tieVerticalDirection", 0));
156 Scalar dir2 (get_property ("verticalDirection", 0));
158 Direction tie_dir = CENTER;
159 if (dir.length_i () && dir.isnum_b ())
160 tie_dir = (Direction) sign (int(dir));
161 else if (dir2.length_i () && dir2.isnum_b ())
162 tie_dir = (Direction) sign (int (dir2));
164 for (int i=0; i< tie_p_arr_.size (); i++)
166 tie_p_arr_[i]->dir_ = tie_dir;
167 typeset_element (tie_p_arr_[i]);
173 Tie_engraver::do_post_move_processing ()
176 Moment now = now_mom ();
177 while (past_notes_pq_.size () && past_notes_pq_.front ().end_ < now)
178 past_notes_pq_.delmin ();
181 ADD_THIS_TRANSLATOR(Tie_engraver);
184 CHead_melodic_tuple::CHead_melodic_tuple ()
191 CHead_melodic_tuple::CHead_melodic_tuple (Note_head *h, Melodic_req*m, Moment mom)
199 CHead_melodic_tuple::pitch_compare (CHead_melodic_tuple const&h1,
200 CHead_melodic_tuple const &h2)
202 return Melodic_req::compare (*h1.req_l_, *h2.req_l_);
206 CHead_melodic_tuple::time_compare (CHead_melodic_tuple const&h1,
207 CHead_melodic_tuple const &h2)
209 return (h1.end_ - h2.end_ ).sign ();