lilypond-0.0.40
[lilypond.git] / lily / walk-regs.cc
blob0c408025012b2cf5380369419419e2c30ab4b0af
1 /*
2 walkregs.cc -- implement Walker_registers
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
9 #include "debug.hh"
10 #include "clef-reg.hh"
11 #include "local-key-reg.hh"
12 #include "key-reg.hh"
13 #include "meter-reg.hh"
14 #include "bar-reg.hh"
15 #include "bar.hh"
16 #include "walk-regs.hh"
17 #include "staff-elem.hh"
18 #include "staff.hh"
19 #include "complex-walker.hh"
20 #include "staff-column.hh"
21 #include "voice-group-regs.hh"
22 #include "voice-regs.hh"
23 #include "commandrequest.hh"
26 Walker_registers::Walker_registers(Complex_walker *w)
28 walk_l_ = w;
29 add( new Bar_register);
30 add( new Clef_register);
31 add( new Key_register);
32 add( new Meter_register);
33 add( new Local_key_register);
36 void
37 Walker_registers::announce_element(Staff_elem_info info)
39 if (info.elem_p_->name() == Bar::static_name()) {
40 walk_l_->allow_break();
42 announce_info_arr_.push(info);
45 void
46 Walker_registers::acknowledge_element(Staff_elem_info )
48 assert(false);
51 void
52 Walker_registers::do_announces()
54 Request dummy_req;
55 for (int i = 0; i < announce_info_arr_.size(); i++){
56 Staff_elem_info info = announce_info_arr_[i];
58 if (!info.req_l_)
59 info.req_l_ = &dummy_req;
60 Register_group_register::acknowledge_element(info);
62 announce_info_arr_.set_size(0);
65 void
66 Walker_registers::typeset_element(Staff_elem *elem_p)
68 typeset_musical_item(elem_p);
71 void
72 Walker_registers::typeset_musical_item(Staff_elem * elem_p)
74 walk_l_->typeset_element(elem_p);
77 void
78 Walker_registers::typeset_breakable_item(Item * pre_p , Item * nobreak_p,
79 Item * post_p)
81 if (pre_p)
82 prebreak_item_p_arr_.push(pre_p);
83 if (nobreak_p)
84 nobreak_item_p_arr_.push(nobreak_p);
85 if (post_p)
86 postbreak_item_p_arr_.push(post_p);
89 void
90 Walker_registers::pre_move_processing()
92 // this generates all items.
93 Register_group_register::pre_move_processing();
94 walk_l_->ptr()->typeset_breakable_items(prebreak_item_p_arr_,
95 nobreak_item_p_arr_,
96 postbreak_item_p_arr_);
98 void
99 Walker_registers::post_move_processing()
101 Register_group_register::post_move_processing();
104 void
105 Walker_registers::change_group(Group_change_req * greq_l,
106 Voice_registers *voice_regs_l,
107 Voice_group_registers * old_group)
109 Voice_registers *regs_p = (old_group)
110 ? (Voice_registers*) old_group->get_register_p(voice_regs_l)
111 : new Voice_registers(greq_l->voice_l());
112 Voice_group_registers * new_group_l = get_group(greq_l->newgroup_str_);
113 new_group_l->add(regs_p);
115 mtor << "processed change request";
116 print();
119 Voice_group_registers *
120 Walker_registers::get_group(String id)
122 for (int i=0; i < group_l_arr_.size(); i++) {
123 if (group_l_arr_[i]->group_id_str_ == id)
124 return group_l_arr_[i];
126 Voice_group_registers *group_p = new Voice_group_registers(id);
127 group_l_arr_.push(group_p);
128 add(group_p);
129 return group_p;
132 void
133 Walker_registers::terminate_register(Request_register * reg)
135 for (int i=0; i < group_l_arr_.size(); i++) {
136 if (group_l_arr_[i] == reg) {
137 group_l_arr_.del(i);
138 Register_group_register::terminate_register(reg);
139 return;
142 assert(false);
145 bool
146 Walker_registers::try_request(Request * r)
148 bool b = Register_group_register::try_request(r);
149 if (!b) {
150 Command_req * cr_l = r->command() ;
152 if (cr_l && cr_l->groupchange()) {
153 change_group(cr_l->groupchange(), 0, 0);
154 } else
155 warning("junking request: " + String(r->name()),
156 r->defined_ch_c_l_);
158 return b;
162 Staff_info
163 Walker_registers::get_staff_info() return inf;
165 inf.c0_position_i_ = &walk_l_->c0_position_i_;
166 inf.walk_l_ = walk_l_;
167 inf.time_c_l_ = &walk_l_->time_;
168 inf.rhythmic_c_l_ = walk_l_->default_grouping;
170 Paper_def*
171 Walker_registers::paper()const
173 return walk_l_->staff_l_->paper();