lilypond-1.3.69
[lilypond.git] / lily / score-reg.cc
blob35de3a344da22bee594c6557c53b4e7b6234d303
1 /*
2 score-reg.cc -- implement Score_register
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8 #include "super-elem.hh"
9 #include "scoreline.hh"
10 #include "debug.hh"
11 #include "score-elem.hh"
12 #include "bar.hh" // needed for Bar::static_name
13 #include "staffline.hh"
14 #include "score-reg.hh"
15 #include "p-col.hh"
16 #include "p-score.hh"
17 #include "score.hh"
18 #include "musical-request.hh"
19 #include "score-column.hh"
22 void
23 Score_register::set_score(Score *s)
25 Global_acceptor::set_score(s);
26 scoreline_l_ = s->pscore_p_->super_elem_l_->line_of_score_l_;
29 Score_register::Score_register()
31 scoreline_l_ =0;
32 command_column_l_ =0;
33 musical_column_l_ =0;
37 void
38 Score_register::prepare(Moment w)
40 Score_column* c1 = new Score_column(w);
41 Score_column* c2 = new Score_column(w);
43 c1->musical_b_ = false;
44 c2->musical_b_ = true;
46 score_l_->cols_.bottom().add(c1);
47 score_l_->cols_.bottom().add(c2);
48 set_cols(c1,c2);
51 post_move_processing();
53 void
54 Score_register::finish()
56 check_removal();
57 do_removal_processing();
60 void
61 Score_register::do_creation_processing()
63 scoreline_l_->left_col_l_ = get_staff_info().command_pcol_l();
64 scoreline_l_->left_col_l_ ->set_breakable();
65 Register_group_register::do_creation_processing();
68 void
69 Score_register::set_cols(Score_column*c1,Score_column*c2)
71 command_column_l_ = c1;
72 musical_column_l_ = c2;
75 void
76 Score_register::do_removal_processing()
78 Register_group_register::do_removal_processing();
79 scoreline_l_->right_col_l_ = get_staff_info().command_pcol_l();
80 scoreline_l_->right_col_l_ ->set_breakable();
81 typeset_all();
84 void
85 Score_register::process()
87 process_requests();
88 do_announces();
89 pre_move_processing();
90 check_removal();
93 void
94 Score_register::announce_element(Score_elem_info info)
96 info.origin_reg_l_arr_.push(this);
97 if (info.elem_l_->name() == Bar::static_name()) {
98 get_staff_info().command_pcol_l()->set_breakable();
99 } else if ( info.elem_l_->is_type_b( Line_of_staff::static_name() ) &&
100 !scoreline_l_->contains_b( info.elem_l_) )
102 scoreline_l_->add(info.elem_l_);
104 announce_info_arr_.push(info);
106 void
107 Score_register::do_announces()
109 /* All elements are propagated to the top upon announcement. If
110 something was created during one run of
111 Register_group_register::do_announces, then
112 announce_info_arr_.size() will be nonzero again
115 while (announce_info_arr_.size()) {
116 for (int i=0; i <announce_info_arr_.size(); i++)
118 TODO
120 More subtle spacing
122 if (announce_info_arr_[i].req_l_) {
123 Musical_req *m = announce_info_arr_[i].req_l_->musical();
124 if (m&&m->rhythmic()) {
125 musical_column_l_->add_duration( m->duration());
128 Register_group_register::do_announces();
133 void
134 Score_register::typeset_element(Score_elem *elem_p)
136 musical_item_p_arr_.push(elem_p);
139 void
140 Score_register::typeset_breakable_item(Item * nobreak_p)
142 if (nobreak_p) {
143 nobreak_item_p_arr_.push(nobreak_p);
147 void
148 Score_register::typeset_all()
150 PCol * c= get_staff_info().command_pcol_l();
151 PScore *ps_l = score_l_->pscore_p_;
153 for (int i =0; i < nobreak_item_p_arr_.size(); i++) {
154 ps_l->typeset_item(nobreak_item_p_arr_[i], c, 0);
155 scoreline_l_->add(nobreak_item_p_arr_[i]);
157 nobreak_item_p_arr_.set_size(0);
159 for (int i=0; i < musical_item_p_arr_.size(); i++) {
160 PCol* m = get_staff_info().musical_pcol_l();
161 Score_elem *elem_p = musical_item_p_arr_[i];
163 scoreline_l_->add(elem_p);
164 if (elem_p->spanner()) {
165 ps_l->typeset_unbroken_spanner(elem_p->spanner());
166 } else if (elem_p->item()) {
167 ps_l->typeset_item(elem_p->item(), m, 0);
168 } else
169 assert(false);
171 musical_item_p_arr_.set_size(0);
175 void
176 Score_register::do_pre_move_processing()
178 // this generates all items.
179 Register_group_register::do_pre_move_processing();
181 typeset_all();
185 Staff_info
186 Score_register::get_staff_info()const
188 Staff_info inf;
190 inf.command_l_ = command_column_l_;
191 inf.musical_l_ = musical_column_l_;
192 return inf;
195 Paper_def*
196 Score_register::paper()const
198 return score_l_->paper_p_;
203 bool
204 Score_register::do_try_request(Request*r)
206 bool gotcha = false;
207 for (int i =0; !gotcha && i < nongroup_l_arr_.size() ; i++)
208 gotcha = nongroup_l_arr_[i]->try_request(r);
210 return gotcha;
213 IMPLEMENT_IS_TYPE_B1(Score_register,Register_group_register);
214 IMPLEMENT_STATIC_NAME(Score_register);
215 ADD_THIS_REGISTER(Score_register);