2 tie-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 ADD_THIS_TRANSLATOR (Tie_engraver);
19 Tie_engraver::Tie_engraver()
26 Tie_engraver::do_try_music (Music *m)
28 if (Tie_req * c = dynamic_cast<Tie_req*> (m))
31 SCM m = get_property ("automaticMelismata",0);
32 bool am = gh_boolean_p (m) &&gh_scm2bool (m);
43 Tie_engraver::set_melisma (bool m)
45 Translator_group *where = daddy_trans_l_;
46 get_property ("tieMelismaBusy", &where);
48 where = daddy_trans_l_;
50 daddy_trans_l_->set_property ("tieMelismaBusy", m ? SCM_BOOL_T : SCM_BOOL_F);
54 Tie_engraver::acknowledge_element (Score_element_info i)
56 if (Note_head *nh = dynamic_cast<Note_head *> (i.elem_l_))
58 Note_req * m = dynamic_cast<Note_req* > (i.req_l_);
61 now_heads_.push (CHead_melodic_tuple (nh, m, now_mom()+ m->length_mom ()));
66 Tie_engraver::do_process_requests ()
70 Moment now = now_mom ();
71 Link_array<Note_head> nharr;
73 stopped_heads_.clear ();
74 while (past_notes_pq_.size ()
75 && past_notes_pq_.front ().end_ == now)
76 stopped_heads_.push (past_notes_pq_.get ());
81 Tie_engraver::process_acknowledged ()
85 now_heads_.sort (CHead_melodic_tuple::pitch_compare);
86 stopped_heads_.sort(CHead_melodic_tuple::pitch_compare);
88 SCM head_list = SCM_EOL;
90 int j = stopped_heads_.size ()-1;
91 int i = now_heads_.size ()-1;
93 while (i >= 0 && j >=0)
96 = Musical_pitch::compare (now_heads_[i].req_l_->pitch_ ,
97 stopped_heads_[j].req_l_->pitch_);
101 (comp < 0) ? j -- : i--;
106 head_list = gh_cons (gh_cons (stopped_heads_[j].head_l_->self_scm_,
107 now_heads_[i].head_l_->self_scm_),
110 past_notes_pq_. insert (now_heads_[i]);
112 stopped_heads_.del (j);
119 SCM sparse = get_property ("sparseTies", 0);
120 if (to_boolean (sparse))
122 int i = scm_ilength (head_list);
127 SCM pair = gh_list_ref (head_list, gh_int2scm (i/2));
130 p->set_head (LEFT, dynamic_cast<Item*> (unsmob_element (gh_car (pair))));
131 p->set_head (RIGHT, dynamic_cast<Item*> (unsmob_element (gh_cdr (pair))));
134 announce_element (Score_element_info (p, req_l_));
136 else for (SCM s = head_list; gh_pair_p (s); s = gh_cdr (s))
139 p->set_head (LEFT, dynamic_cast<Item*> (unsmob_element (gh_caar (s))));
140 p->set_head (RIGHT, dynamic_cast<Item*> (unsmob_element (gh_cdar (s))));
143 announce_element (Score_element_info (p, req_l_));
146 if (!tie_p_arr_.size ())
148 req_l_->warning (_ ("No ties were created!"));
156 Tie_engraver::do_pre_move_processing ()
158 for (int i=0; i < now_heads_.size (); i++)
160 past_notes_pq_.insert (now_heads_[i]);
164 for (int i=0; i< tie_p_arr_.size (); i++)
166 typeset_element (tie_p_arr_[i]);
172 Tie_engraver::do_post_move_processing ()
174 SCM m = get_property ("automaticMelismata",0);
180 Moment now = now_mom ();
181 while (past_notes_pq_.size () && past_notes_pq_.front ().end_ < now)
182 past_notes_pq_.delmin ();
185 CHead_melodic_tuple::CHead_melodic_tuple ()
192 CHead_melodic_tuple::CHead_melodic_tuple (Note_head *h, Melodic_req*m, Moment mom)
200 CHead_melodic_tuple::pitch_compare (CHead_melodic_tuple const&h1,
201 CHead_melodic_tuple const &h2)
203 return Melodic_req::compare (*h1.req_l_, *h2.req_l_);
207 CHead_melodic_tuple::time_compare (CHead_melodic_tuple const&h1,
208 CHead_melodic_tuple const &h2)
210 return (h1.end_ - h2.end_ ).sign ();