lilypond-1.3.122
[lilypond.git] / lily / ties-engraver.cc
blob63a0390e5f31715786043da50c904d851fe5ec1e
1 /*
2 tie-reg.cc -- implement Ties_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "ties-engraver.hh"
10 #include "tie.hh"
11 #include "note-head.hh"
12 #include "musical-request.hh"
13 #include "music-list.hh"
15 Ties_engraver::Ties_engraver()
17 req_l_ = end_req_l_ =0;
18 processed_ack_pass_i_ = 0;
22 void
23 Ties_engraver::do_post_move_processing()
25 processed_ack_pass_i_ =0;
28 bool
29 Ties_engraver::do_try_music (Music*req)
31 if (Tie_req * r = dynamic_cast <Tie_req *> (req))
33 req_l_ = r;
34 return true;
36 return false;
40 void
41 Ties_engraver::acknowledge_element (Score_element_info i)
43 if (!req_l_ && ! end_req_l_)
44 return;
45 if (Note_head * h = dynamic_cast <Note_head *> (i.elem_l_))
47 Melodic_req *m = dynamic_cast <Melodic_req *> (i.req_l_);
49 head_mel_tuple_arr_.push (Head_melodic_tuple (h, m));
53 void
54 Ties_engraver::process_acknowledged ()
56 if (!head_mel_tuple_arr_.size () || processed_ack_pass_i_ ++)
57 return;
59 head_mel_tuple_arr_.sort (Head_melodic_tuple::compare);
60 if (req_l_ && !tie_p_arr_.size ())
62 for (int i=0; i < head_mel_tuple_arr_.size (); i++)
64 Tie* p = new Tie;
65 p->set_head (LEFT,head_mel_tuple_arr_[i].head_l_);
66 // announce_element (Score_element_info (p, req_l_));
67 tie_p_arr_.push (p);
71 if (end_req_l_)
73 for (int i=0; i < end_tie_p_arr_.size (); i++)
75 int j = i;
76 if (j >= head_mel_tuple_arr_.size ())
78 left_head_mel_tuple_arr_[i].mel_l_->warning (_( "Can't find a note head at the right to attach Tie"));
79 j = head_mel_tuple_arr_.size () -1;
82 Tie*p=end_tie_p_arr_[i];
83 p->set_head (RIGHT, head_mel_tuple_arr_[j].head_l_);
84 if (!Melodic_req::compare (*head_mel_tuple_arr_[j].mel_l_,
85 *left_head_mel_tuple_arr_[j].mel_l_))
86 p->same_pitch_b_ = true;
87 announce_element ( Score_element_info (p, end_req_l_));
93 void
94 Ties_engraver::do_pre_move_processing()
96 if (!head_mel_tuple_arr_.size ())
97 return;
100 for (int i =0; i < end_tie_p_arr_.size (); i++)
102 Scalar tie_dir (get_property ("tieYDirection"));
103 Scalar y_dir (get_property ("ydirection"));
104 Direction dir = CENTER;
105 if (tie_dir.length_i () && tie_dir.isnum_b ())
106 dir = (Direction) sign (int (tie_dir));
107 else if (y_dir.length_i () && y_dir.isnum_b ())
108 dir = (Direction) sign (int (y_dir));
110 end_tie_p_arr_[i]->dir_ = dir;
111 typeset_element (end_tie_p_arr_[i]);
114 end_tie_p_arr_ = tie_p_arr_;
115 left_head_mel_tuple_arr_ = head_mel_tuple_arr_;
116 end_req_l_ = req_l_;
118 req_l_ =0;
119 head_mel_tuple_arr_.clear ();
120 tie_p_arr_.clear ();
123 void
124 Ties_engraver::do_removal_processing ()
128 void
129 Ties_engraver::do_process_requests ()
134 ADD_THIS_TRANSLATOR(Ties_engraver);
137 Head_melodic_tuple::Head_melodic_tuple ()
139 head_l_ =0;
140 mel_l_ =0;
143 Head_melodic_tuple::Head_melodic_tuple (Note_head *h, Melodic_req*m)
145 head_l_ = h;
146 mel_l_ = m;
150 Head_melodic_tuple::compare (Head_melodic_tuple const&h1,
151 Head_melodic_tuple const &h2)
153 return Melodic_req::compare (*h1.mel_l_, *h2.mel_l_);