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"
15 #include "translator-group.hh"
17 Tie_engraver::Tie_engraver()
24 Tie_engraver::do_try_music (Music *m)
26 if (Tie_req * c = dynamic_cast<Tie_req*> (m))
29 if (get_property ("automaticMelismas",0).to_bool ())
39 Tie_engraver::set_melisma (bool m)
41 Translator_group *where = daddy_trans_l_;
42 get_property ("tieMelismaBusy", &where);
44 where = daddy_trans_l_;
46 daddy_trans_l_->set_property ("tieMelismaBusy", m ? "1" :"0");
50 Tie_engraver::acknowledge_element (Score_element_info i)
52 if (Note_head *nh = dynamic_cast<Note_head *> (i.elem_l_))
54 Note_req * m = dynamic_cast<Note_req* > (i.req_l_);
57 now_heads_.push (CHead_melodic_tuple (nh, m, now_mom()+ m->length_mom ()));
62 Tie_engraver::do_process_requests ()
66 Moment now = now_mom ();
67 Link_array<Note_head> nharr;
69 stopped_heads_.clear ();
70 while (past_notes_pq_.size ()
71 && past_notes_pq_.front ().end_ == now)
72 stopped_heads_.push (past_notes_pq_.get ());
77 Tie_engraver::process_acknowledged ()
79 bool old_behavior = get_property ("oldTieBehavior", 0).to_bool ();
89 if (now_heads_.size () != stopped_heads_.size ())
91 req_l_->warning ("Unequal number of note heads for tie");
93 int sz = now_heads_.size () <? stopped_heads_.size ();
95 /* hmm. Should do something more sensible.
96 because, we assume no more noteheads come along after the 1st pass.
98 if (sz <= tie_p_arr_.size ())
101 now_heads_.sort (CHead_melodic_tuple::pitch_compare);
102 stopped_heads_.sort(CHead_melodic_tuple::pitch_compare);
104 for (int i=0; i < sz; i++)
107 p->set_head (LEFT, stopped_heads_[i].head_l_);
108 p->set_head (RIGHT, now_heads_[i].head_l_);
110 announce_element (Score_element_info (p, req_l_));
115 now_heads_.sort (CHead_melodic_tuple::pitch_compare);
116 stopped_heads_.sort(CHead_melodic_tuple::pitch_compare);
120 while ( i < now_heads_.size () && j < stopped_heads_.size ())
123 = Musical_pitch::compare (now_heads_[i].req_l_->pitch_ ,
124 stopped_heads_[j].req_l_->pitch_);
128 (comp < 0) ? i ++ : j++;
135 /* don't go around recreating ties that were already
136 made. Not infallible. Due to reordering in sort (),
137 we will make the wrong ties when noteheads are
139 if (tie_count > tie_p_arr_.size ())
142 p->set_head (LEFT, stopped_heads_[j].head_l_);
143 p->set_head (RIGHT, now_heads_[i].head_l_);
145 announce_element (Score_element_info (p, req_l_));
153 if (!tie_p_arr_.size ())
155 req_l_->warning (_("No ties were created!"));
163 Tie_engraver::do_pre_move_processing ()
165 for (int i=0; i < now_heads_.size (); i++)
167 past_notes_pq_.insert (now_heads_[i]);
171 Scalar dir (get_property ("tieVerticalDirection", 0));
172 Scalar dir2 (get_property ("verticalDirection", 0));
174 Direction tie_dir = CENTER;
175 if (dir.length_i () && dir.isnum_b ())
176 tie_dir = (Direction) sign (int(dir));
177 else if (dir2.length_i () && dir2.isnum_b ())
178 tie_dir = (Direction) sign (int (dir2));
180 for (int i=0; i< tie_p_arr_.size (); i++)
182 tie_p_arr_[i]->dir_ = tie_dir;
183 typeset_element (tie_p_arr_[i]);
189 Tie_engraver::do_post_move_processing ()
191 if (get_property ("automaticMelismas",0).to_bool ())
196 Moment now = now_mom ();
197 while (past_notes_pq_.size () && past_notes_pq_.front ().end_ < now)
198 past_notes_pq_.delmin ();
201 ADD_THIS_TRANSLATOR(Tie_engraver);
204 CHead_melodic_tuple::CHead_melodic_tuple ()
211 CHead_melodic_tuple::CHead_melodic_tuple (Note_head *h, Melodic_req*m, Moment mom)
219 CHead_melodic_tuple::pitch_compare (CHead_melodic_tuple const&h1,
220 CHead_melodic_tuple const &h2)
222 return Melodic_req::compare (*h1.req_l_, *h2.req_l_);
226 CHead_melodic_tuple::time_compare (CHead_melodic_tuple const&h1,
227 CHead_melodic_tuple const &h2)
229 return (h1.end_ - h2.end_ ).sign ();