2 complexwalker.cc -- implement Complex_walker
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "associter.hh"
11 #include "musicalrequest.hh"
12 #include "staffcolumn.hh"
15 #include "complexstaff.hh"
17 #include "voicegroupregs.hh"
18 #include "voiceregs.hh"
19 #include "complexwalker.hh"
21 #include "commandrequest.hh"
22 #include "walkregs.hh"
26 Complex_walker::announce_element(Staff_elem_info info
)
28 info
.group_regs_l_
= find_voice_group((Voice
*)info
.voice_l_
);
29 announce_info_arr_
.push(info
);
33 Complex_walker::do_announces()
36 for (int i
= 0; i
< announce_info_arr_
.size(); i
++){
37 Staff_elem_info info
= announce_info_arr_
[i
];
40 info
.req_l_
= &dummy_req
;
42 walk_regs_p_
->acknowledge_element(info
);
43 for (iter_top(voice_reg_list_
,j
); j
.ok(); j
++) {
44 j
->acknowledge_element(info
);
46 for (iter_top ( group_reg_list_
, j
); j
.ok(); j
++) {
47 j
->acknowledge_element(info
);
53 Complex_walker::find_voice_reg(Voice
*v_l
)const
55 for (iter_top(voice_reg_list_
, i
); i
.ok(); i
++) {
56 if (i
->voice_l_
== v_l
)
63 Complex_walker::get_voice_reg(Voice
*v_l
)
65 Voice_registers
*regs_p
=find_voice_reg(v_l
);
69 regs_p
= new Voice_registers(this,v_l
);
70 voice_reg_list_
.bottom().add (regs_p
);
74 Voice_group_registers
*
75 Complex_walker::find_voice_group(Voice
* v_l
)const
77 if (!voice_group_map_
.elt_query(v_l
))
79 else return voice_group_map_
[v_l
];
82 Voice_group_registers
*
83 Complex_walker::find_voice_group(const char *id
)const
85 for (iter_top(group_reg_list_
, i
); i
.ok(); i
++)
86 if (i
->group_id_str_
== id
)
92 Voice_group_registers
*
93 Complex_walker::get_voice_group(Voice
*v_l
)
95 Voice_group_registers
*group_p
= find_voice_group(v_l
);
99 group_p
= new Voice_group_registers(this);
100 group_reg_list_
.bottom().add(group_p
);
101 voice_group_map_
[v_l
] = group_p
;
106 Voice_group_registers
*
107 Complex_walker::get_voice_group(const char* id
)
109 Voice_group_registers
*group_p
= find_voice_group(id
);
112 group_p
= new Voice_group_registers(this,id
);
113 group_reg_list_
.bottom().add(group_p
);
118 Complex_walker::do_change_group(Voice
* v
, String group_id_str
)
120 voice_group_map_
[v
] = get_voice_group(group_id_str
);
124 Complex_walker::try_command_request(Command_req
*req_l
)
127 Voice
*voice_l
= (Voice
*)req_l
->elt_l_
->voice_l_
; // ugh
128 if (req_l
->groupchange()){
129 do_change_group(voice_l
, req_l
->groupchange()->newgroup_str_
);
131 } else if(req_l
->groupfeature()) {
132 Voice_group_registers
* reg_l
= get_voice_group(voice_l
);
133 b
|= reg_l
->try_request(req_l
);
135 b
|= walk_regs_p_
->try_request(req_l
);
141 Complex_walker::try_request(Request
*req
)
144 Voice
*voice_l
= (Voice
*)req
->elt_l_
->voice_l_
; // ahh. This sux
146 if (req
->command()) {
147 b
= try_command_request(req
->command());
148 } else if (Voice_registers::acceptable_request_b(req
)) {
149 Voice_registers
*vregs_l
= get_voice_reg(voice_l
);
150 b
= vregs_l
->try_request(req
);
151 } else if (Voice_group_registers::acceptable_request_b(req
)){
152 Voice_group_registers
* reg_l
= get_voice_group(voice_l
);
153 b
= reg_l
->try_request(req
);
157 warning("junking request: " + String(req
->name()),
158 req
->defined_ch_c_l_
);
162 Complex_walker::process_requests()
164 Staff_column
*c
=ptr();
166 for (int i
=0; i
< c
->commandreq_l_arr_
.size(); i
++) {
167 try_request(c
->commandreq_l_arr_
[i
]);
170 for (int i
=0; i
< c
->musicalreq_l_arr_
.size(); i
++) {
171 try_request(c
->musicalreq_l_arr_
[i
]);
174 regs_process_requests();
179 Complex_walker::regs_process_requests()
181 walk_regs_p_
->process_requests();
182 for (iter_top(voice_reg_list_
, j
); j
.ok(); j
++) {
183 j
->process_requests();
185 for (iter_top(group_reg_list_
, j
); j
.ok(); j
++)
186 j
->process_requests();
190 Complex_walker::typeset_element(Staff_elem
*elem_p
)
194 if (elem_p
->spanner())
195 pscore_l_
->typeset_spanner(elem_p
->spanner(), staff()->pstaff_l_
);
197 ptr()->typeset_musical_item(elem_p
->item());
200 Complex_walker::Complex_walker(Complex_staff
*s
)
201 : Staff_walker(s
, s
->pstaff_l_
->pscore_l_
)
203 walk_regs_p_
= new Walker_registers(this);
208 Complex_walker::~Complex_walker()
213 Complex_walker::c0_position_i()const
215 return c0_position_i_
;
219 Complex_walker::set_c0_position(int p
)
225 Complex_walker::staff()
227 return (Complex_staff
*) staff_l_
;
232 Complex_walker::do_pre_move()
234 walk_regs_p_
->pre_move_processing();
235 for (iter_top(voice_reg_list_
,i
); i
.ok(); i
++) {
236 i
->pre_move_processing();
238 for (iter_top (group_reg_list_
, j
); j
.ok(); j
++)
239 j
->pre_move_processing();
241 ptr()->typeset_breakable_items(prebreak_item_p_arr_
,
243 postbreak_item_p_arr_
);
247 Complex_walker::do_post_move()
249 walk_regs_p_
->post_move_processing();
250 for (iter_top(voice_reg_list_
,i
); i
.ok(); i
++) {
251 i
->post_move_processing();
253 announce_info_arr_
.set_size(0);
254 for (iter_top (group_reg_list_
, j
); j
.ok(); j
++)
255 j
->post_move_processing();
258 Array
<Voice_registers
*>
259 Complex_walker::get_voice_regs(Voice_group_registers
* group_regs_l
) const
262 for (Assoc_iter
<Voice
*,Voice_group_registers
*> i(voice_group_map_
);
264 if (i
.val() == group_regs_l
)
265 l_arr
.push(find_voice_reg(i
.key()));
270 Complex_walker::typeset_breakable_item(Item
* pre_p
, Item
* nobreak_p
,
274 prebreak_item_p_arr_
.push(pre_p
);
276 nobreak_item_p_arr_
.push(nobreak_p
);
278 postbreak_item_p_arr_
.push(post_p
);