lilypond-1.3.31
[lilypond.git] / lily / clef-grav.cc
blobbc981272a490e425e88d362d869797e151abda2f
1 /*
2 clef.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 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;
23 octave_dir_ = CENTER;
27 Ugh. Should have support for Dictionaries in mudela.
29 bool
30 Clef_engraver::set_type (String s)
32 if (s.right_str(2) == "_8") // Down one octave
34 octave_dir_ = DOWN;
35 s = s.left_str(s.length_i() - 2);
37 else if (s.right_str(2) == "^8") // Up one octave
39 octave_dir_ = UP;
40 s = s.left_str(s.length_i() - 2);
42 else
43 octave_dir_ = CENTER;
44 clef_type_str_ = s;
45 if (clef_type_str_ == "violin" || clef_type_str_ == "G" || clef_type_str_ == "G2")
46 c0_position_i_= -6;
47 else if (clef_type_str_ == "french")
48 c0_position_i_= -8;
49 else if (clef_type_str_ == "soprano")
50 c0_position_i_= -4;
51 else if (clef_type_str_ == "mezzosoprano")
52 c0_position_i_ = -2;
53 else if (clef_type_str_ == "alto")
54 c0_position_i_= 0;
55 else if (clef_type_str_ == "tenor")
56 c0_position_i_= 2;
57 else if (clef_type_str_ == "baritone")
58 c0_position_i_ = 4;
59 else if (clef_type_str_ == "varbaritone")
60 c0_position_i_ = 4;
61 else if (clef_type_str_ == "bass" || clef_type_str_ == "F")
62 c0_position_i_= 6;
63 else if (clef_type_str_ == "subbass")
64 c0_position_i_ = 8;
65 else
66 switch(clef_type_str_[0])
68 case 'F': case 'f':
69 c0_position_i_ = 2 * (clef_type_str_[1] - '0') - 2;
70 break;
71 case 'G': case 'g':
72 c0_position_i_ = 2 * (clef_type_str_[1] - '0') - 10;
73 break;
74 case 'C': case 'c':
75 c0_position_i_ = 2 * (clef_type_str_[1] - '0') - 6;
76 break;
77 default:
78 return false;
80 c0_position_i_ -= (int) octave_dir_ * 7;
82 return true;
85 void
86 Clef_engraver::fill_staff_info (Staff_info &i)
88 i.c0_position_i_l_ = &c0_position_i_;
91 void
92 Clef_engraver::read_req (Clef_change_req*c_l)
94 if (!set_type (c_l->clef_str_))
95 c_l->error (_("unknown clef type "));
99 /**
100 Generate a clef at the start of a measure. (when you see a Bar,
101 ie. a breakpoint)
103 void
104 Clef_engraver::acknowledge_element (Score_elem_info info)
106 if (info.elem_l_->is_type_b (Bar::static_name ())
107 && clef_type_str_.length_i())
109 create_clef();
110 if (!clef_req_l_)
111 clef_p_->default_b_ = true;
115 void
116 Clef_engraver::do_creation_processing()
118 Scalar def = get_property ("defaultclef");
119 if (def.operator bool ()) // egcs: Scalar to bool is ambiguous
120 set_type (def);
121 if (clef_type_str_.length_i ())
122 create_clef();
123 clef_p_->default_b_ = false;
126 bool
127 Clef_engraver::do_try_request (Request * r_l)
129 Command_req* creq_l= r_l->command();
130 if (!creq_l || !creq_l->clefchange())
131 return false;
133 clef_req_l_ = creq_l->clefchange();
134 read_req (clef_req_l_);
135 return true;
138 void
139 Clef_engraver::create_clef()
141 if (!clef_p_)
143 clef_p_ = new Clef_item;
144 clef_p_->break_priority_i_ = -2; // ugh
145 announce_element (Score_elem_info (clef_p_,clef_req_l_));
147 clef_p_->read (*this);
150 void
151 Clef_engraver::do_process_requests()
153 if (clef_req_l_)
155 create_clef();
156 clef_p_->default_b_ = false;
160 void
161 Clef_engraver::do_pre_move_processing()
163 if (clef_p_)
165 typeset_element (clef_p_);
166 clef_p_ = 0;
169 void
170 Clef_engraver::do_post_move_processing()
172 clef_req_l_ = 0;
175 void
176 Clef_engraver::do_removal_processing()
178 delete clef_p_;
179 clef_p_ =0;
183 IMPLEMENT_IS_TYPE_B1(Clef_engraver,Engraver);
184 ADD_THIS_TRANSLATOR(Clef_engraver);