lilypond-0.1.56
[lilypond.git] / lily / clef-grav.cc
blob5f9a9376e743c1ceb92e2f2a4e35219b8362ce00
1 /*
2 clef.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>,
7 Mats Bengtsson <matsb@s3.kth.se>
8 */
10 #include "bar.hh"
11 #include "clef-grav.hh"
12 #include "clef-item.hh"
13 #include "debug.hh"
14 #include "command-request.hh"
15 #include "time-description.hh"
17 Clef_engraver::Clef_engraver()
19 clef_p_ = 0;
20 clef_req_l_ =0;
21 clef_type_str_ = 0;
22 c0_position_i_ =0;
26 Ugh. Should have support for Dictionaries in mudela.
28 bool
29 Clef_engraver::set_type (String s)
31 clef_type_str_ = s;
32 if (clef_type_str_ == "violin")
33 c0_position_i_= -6;
34 else if (clef_type_str_ == "french")
35 c0_position_i_= -8;
36 else if (clef_type_str_ == "soprano")
37 c0_position_i_= -4;
38 else if (clef_type_str_ == "mezzosoprano")
39 c0_position_i_ = -2;
40 else if (clef_type_str_ == "alto")
41 c0_position_i_= 0;
42 else if (clef_type_str_ == "tenor")
43 c0_position_i_= 2;
44 else if (clef_type_str_ == "baritone")
45 c0_position_i_ = 4;
46 else if (clef_type_str_ == "varbaritone")
47 c0_position_i_ = 4;
48 else if (clef_type_str_ == "bass")
49 c0_position_i_= 6;
50 else if (clef_type_str_ == "subbass")
51 c0_position_i_ = 8;
52 else
53 return false;
55 return true;
58 void
59 Clef_engraver::fill_staff_info (Staff_info &i)
61 i.c0_position_i_l_ = &c0_position_i_;
64 void
65 Clef_engraver::read_req (Clef_change_req*c_l)
67 if (!set_type (c_l->clef_str_))
68 c_l->error (_("unknown clef type "));
72 /**
73 Generate a clef at the start of a measure. (when you see a Bar,
74 ie. a breakpoint)
76 void
77 Clef_engraver::acknowledge_element (Score_elem_info info)
79 if (info.elem_l_->is_type_b (Bar::static_name ())
80 && clef_type_str_.length_i())
82 create_clef();
83 if (!clef_req_l_)
84 clef_p_->default_b_ = true;
88 void
89 Clef_engraver::do_creation_processing()
91 Scalar def = get_property ("defaultclef");
92 if (def.operator bool ()) // egcs: Scalar to bool is ambiguous
93 set_type (def);
94 if (clef_type_str_.length_i ())
95 create_clef();
96 clef_p_->default_b_ = false;
99 bool
100 Clef_engraver::do_try_request (Request * r_l)
102 Command_req* creq_l= r_l->command();
103 if (!creq_l || !creq_l->clefchange())
104 return false;
106 clef_req_l_ = creq_l->clefchange();
107 read_req (clef_req_l_);
108 return true;
111 void
112 Clef_engraver::create_clef()
114 if (!clef_p_)
116 clef_p_ = new Clef_item;
117 clef_p_->break_priority_i_ = -2; // ugh
118 announce_element (Score_elem_info (clef_p_,clef_req_l_));
120 clef_p_->read (*this);
123 void
124 Clef_engraver::do_process_requests()
126 if (clef_req_l_)
128 create_clef();
129 clef_p_->default_b_ = false;
133 void
134 Clef_engraver::do_pre_move_processing()
136 if (clef_p_)
138 typeset_element (clef_p_);
139 clef_p_ = 0;
142 void
143 Clef_engraver::do_post_move_processing()
145 clef_req_l_ = 0;
148 void
149 Clef_engraver::do_removal_processing()
151 delete clef_p_;
152 clef_p_ =0;
156 IMPLEMENT_IS_TYPE_B1(Clef_engraver,Engraver);
157 ADD_THIS_TRANSLATOR(Clef_engraver);