lilypond-0.1.56
[lilypond.git] / src / clefreg.cc
blobed6f78073b91b0b63f948745e6b56c536acd9a23
1 /*
2 clef.cc -- implement Clef_register
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>,
7 Mats Bengtsson <matsb@s3.kth.se>
8 */
10 #include "clefreg.hh"
11 #include "clefitem.hh"
12 #include "debug.hh"
13 #include "commandrequest.hh"
14 #include "timedescription.hh"
15 #include "complexwalker.hh"
16 #include "staffcolumn.hh"
18 Clef_register::Clef_register(Complex_walker*w)
19 : Request_register(w)
21 clef_p_ = 0;
23 set_type("violin");
25 bool
26 Clef_register::set_type(String s)
28 clef_type_str_ = s;
29 if (clef_type_str_ == "violin") {
30 c0_position_i_= -2;
31 } else if (clef_type_str_ == "alto") {
32 c0_position_i_= 4;
33 } else if (clef_type_str_ == "tenor") {
34 c0_position_i_= 6;
35 } else if (clef_type_str_ == "bass") {
36 c0_position_i_= 10;
37 }else
38 return false;
39 walk_l_->set_c0_position(c0_position_i_);
40 return true;
43 void
44 Clef_register::read_req(Clef_change_req*c_l)
46 if (!set_type(c_l->clef_str_))
47 error("unknown clef type ", c_l->defined_ch_c_l_);
50 bool
51 Clef_register::try_request(Request * r_l)
54 Command_req* creq_l= r_l->command();
55 if (!creq_l || !creq_l->clefchange())
56 return false;
58 accepted_req_arr_.push(creq_l);
59 // do it now! Others have to read c0_pos.
60 read_req(creq_l->clefchange());
61 return true;
64 void
65 Clef_register::process_request()
67 const Time_description *time_l = &walk_l_->time_;
68 if (!accepted_req_arr_.size() &&
69 (!time_l->whole_in_measure_|| !time_l->when_)) {
71 clef_p_ = new Clef_item;
72 clef_p_->change = false;
73 } else if (accepted_req_arr_.size()) {
74 clef_p_ = new Clef_item;
75 clef_p_->change = true;
77 if (clef_p_) {
78 clef_p_->read(*this);
79 // announce_element(Staff_elem_info(clef_p_,
80 // accepted_req_arr_[0], this));
84 void
85 Clef_register::do_pre_move_process()
87 if (!clef_p_)
88 return;
89 if (clef_p_->change) {
90 typeset_breakable_item(new Clef_item(*clef_p_),
91 clef_p_, new Clef_item(*clef_p_) );
92 } else {
93 typeset_breakable_item(0, 0, clef_p_);
95 clef_p_ = 0;