lilypond-1.3.122
[lilypond.git] / lily / ctie-engraver.cc
blob662a55484441e4d70199db6b5cf20f097b68468a
1 /*
2 ctie-engraver.cc -- implement Command_tie_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "ctie-engraver.hh"
11 #include "command-request.hh"
12 #include "note-head.hh"
13 #include "musical-request.hh"
14 #include "tie.hh"
16 Command_tie_engraver::Command_tie_engraver()
18 req_l_ = 0;
22 bool
23 Command_tie_engraver::do_try_music (Music *m)
25 if (Command_tie_req * c = dynamic_cast<Command_tie_req*> (m))
27 req_l_ = c;
28 return true;
30 return false;
33 void
34 Command_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_);
39 now_heads_.push (CHead_melodic_tuple (nh, m, now_moment()+ m->duration ()));
43 void
44 Command_tie_engraver::do_process_requests ()
46 if (req_l_)
48 Moment now = now_moment ();
49 Link_array<Note_head> nharr;
51 stopped_heads_.clear ();
52 while (past_notes_pq_.size ()
53 && past_notes_pq_.front ().end_ == now)
54 stopped_heads_.push (past_notes_pq_.get ());
59 void
60 Command_tie_engraver::process_acknowledged ()
62 if (req_l_)
64 if (now_heads_.size () != stopped_heads_.size ())
66 req_l_->warning ("Unequal number of note heads for tie");
68 int sz = now_heads_.size () <? stopped_heads_.size ();
70 // hmm. Should do something more sensible.
71 // because, we assume no more noteheads come along after the 1st pass.
72 if (sz > tie_p_arr_.size ())
74 now_heads_.sort (CHead_melodic_tuple::pitch_compare);
75 stopped_heads_.sort(CHead_melodic_tuple::pitch_compare);
77 for (int i=0; i < sz; i++)
79 Tie * p = new Tie;
80 p->set_head (LEFT, stopped_heads_[i].head_l_);
81 p->set_head (RIGHT, now_heads_[i].head_l_);
82 tie_p_arr_.push (p);
83 announce_element (Score_element_info (p, req_l_));
89 void
90 Command_tie_engraver::do_pre_move_processing ()
92 for (int i=0; i < now_heads_.size (); i++)
94 past_notes_pq_.insert (now_heads_[i]);
96 now_heads_.clear( );
98 for (int i=0; i< tie_p_arr_.size (); i++)
100 typeset_element (tie_p_arr_[i]);
102 tie_p_arr_.clear ();
105 void
106 Command_tie_engraver::do_post_move_processing ()
108 req_l_ =0;
109 Moment now = now_moment ();
110 while (past_notes_pq_.size () && past_notes_pq_.front ().end_ < now)
111 past_notes_pq_.delmin ();
116 ADD_THIS_TRANSLATOR(Command_tie_engraver);
119 CHead_melodic_tuple::CHead_melodic_tuple ()
121 head_l_ =0;
122 mel_l_ =0;
123 end_ = 0;
126 CHead_melodic_tuple::CHead_melodic_tuple (Note_head *h, Melodic_req*m, Moment mom)
128 head_l_ = h;
129 mel_l_ = m;
130 end_ = mom;
134 CHead_melodic_tuple::pitch_compare (CHead_melodic_tuple const&h1,
135 CHead_melodic_tuple const &h2)
137 return Melodic_req::compare (*h1.mel_l_, *h2.mel_l_);
141 CHead_melodic_tuple::time_compare (CHead_melodic_tuple const&h1,
142 CHead_melodic_tuple const &h2)
144 return (h1.end_ - h2.end_ ).sign ();