2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 Mats Bengtsson <matsb@s3.kth.se>
13 #include "translator-group.hh"
14 #include "key-item.hh"
15 #include "local-key-item.hh"
17 #include "note-head.hh"
18 #include "staff-symbol-referencer.hh"
20 #include "command-request.hh"
21 #include "engraver.hh"
22 #include "direction.hh"
23 #include "side-position-interface.hh"
27 /// where is c-0 in the staff?
28 class Clef_engraver : public Engraver
31 VIRTUAL_COPY_CONS (Translator);
34 Direction octave_dir_;
38 virtual void do_process_music ();
39 virtual void do_pre_move_processing ();
40 virtual void do_creation_processing ();
41 virtual void do_post_move_processing ();
42 virtual bool do_try_music (Music*);
43 virtual void acknowledge_element (Score_element_info);
48 Clef_change_req * clef_req_l_;
51 bool set_type (String);
54 Clef_engraver::Clef_engraver ()
64 Clef_engraver::set_type (String s)
66 if (s.right_str (2) == "_8") // Down one octave
69 s = s.left_str (s.length_i () - 2);
71 else if (s.right_str (2) == "^8") // Up one octave
74 s = s.left_str (s.length_i () - 2);
79 SCM c = get_property ("supportedClefTypes");
80 SCM p = get_property ("clefPitches");
84 SCM found = scm_assoc (ly_str02scm (s.ch_C ()), c);
85 if (found == SCM_BOOL_F)
88 SCM glyph = gh_cadr (found);
89 SCM pos = gh_caddr (found);
91 daddy_trans_l_->set_property ("clefGlyph", glyph);
92 daddy_trans_l_->set_property ("clefPosition", pos);
94 found = scm_assoc (glyph, p);
95 if (found == SCM_BOOL_F)
98 int c0_position = gh_scm2int (pos) + gh_scm2int (gh_cdr (found));
99 daddy_trans_l_->set_property ("clefCentralCPosition", gh_int2scm (c0_position));
102 int c0_position = gh_scm2int (get_property ("clefCentralCPosition"));
103 c0_position -= (int)octave_dir_ * 7;
104 daddy_trans_l_->set_property ("clefCentralCPosition", gh_int2scm (c0_position));
107 SCM basic = ly_symbol2scm ("Clef");
108 SCM gl = ly_symbol2scm ("glyph");
110 daddy_trans_l_->execute_single_pushpop_property (basic, gl, SCM_UNDEFINED);
111 daddy_trans_l_->execute_single_pushpop_property (basic, gl,
112 get_property ("clefGlyph"));
118 Generate a clef at the start of a measure. (when you see a Bar,
122 Clef_engraver::acknowledge_element (Score_element_info info)
124 Item * item =dynamic_cast <Item *> (info.elem_l_);
127 if (Bar::has_interface (info.elem_l_)
128 && gh_string_p (get_property ("clefGlyph")))
132 if (Note_head::has_interface (item)
133 || Local_key_item::has_interface (item)
134 || Custos::has_interface (item)
137 int p = int (Staff_symbol_referencer::position_f (item))
138 + gh_scm2int (get_property ("clefCentralCPosition"));
139 Staff_symbol_referencer::set_position (item, p);
141 else if (Key_item::has_interface (item))
144 Key_item adapts its formatting to make sure that the
145 accidentals stay in the upper half of the staff. It needs
146 to know c0-pos for this. (?)
149 item->set_elt_property ("c0-position", get_property ("clefCentralCPosition"));
155 Clef_engraver::do_creation_processing ()
157 daddy_trans_l_->set_property ("clefPosition", gh_int2scm (0));
158 daddy_trans_l_->set_property ("clefGlyph", SCM_EOL);
159 daddy_trans_l_->set_property ("clefCentralCPosition", gh_int2scm (0));
161 SCM def = get_property ("defaultClef");
162 if (gh_string_p (def))
164 set_type (ly_scm2string (def));
169 Clef_engraver::do_try_music (Music * r_l)
171 if (Clef_change_req *cl = dynamic_cast <Clef_change_req *> (r_l))
174 if (!set_type (cl->clef_str_))
175 cl->origin ()->warning (_ ("unknown clef type"));
183 Clef_engraver::create_clef ()
187 Item *c= new Item (get_property ("Clef"));
188 announce_element (c, clef_req_l_);
190 Staff_symbol_referencer::set_interface (c);
194 Staff_symbol_referencer::set_position (clef_p_,
195 gh_scm2int (get_property ("clefPosition")
199 Item * g = new Item (get_property ("OctavateEight"));
201 Side_position::add_support (g,clef_p_);
203 g->set_parent (clef_p_, Y_AXIS);
204 g->set_parent (clef_p_, X_AXIS);
206 g->set_elt_property ("direction", gh_int2scm (octave_dir_));
208 announce_element (octavate_p_, clef_req_l_);
213 Clef_engraver::do_process_music ()
215 if (clef_req_l_ || first_b_)
218 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
223 Clef_engraver::do_pre_move_processing ()
228 if (to_boolean (clef_p_->get_elt_property ("non-default")))
230 vis = get_property ("explicitClefVisibility");
235 clef_p_->set_elt_property ("visibility-lambda", vis);
237 octavate_p_->set_elt_property ("visibility-lambda", vis);
240 typeset_element (clef_p_);
244 typeset_element (octavate_p_);
253 Clef_engraver::do_post_move_processing ()
258 ADD_THIS_TRANSLATOR (Clef_engraver);