3 clef-engraver.cc -- implement Clef_engraver
5 source file of the GNU LilyPond music typesetter
7 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
9 Mats Bengtsson <matsb@s3.kth.se>
14 #include "translator-group.hh"
15 #include "key-item.hh"
16 #include "local-key-item.hh"
18 #include "note-head.hh"
19 #include "staff-symbol-referencer.hh"
21 #include "command-request.hh"
22 #include "engraver.hh"
23 #include "direction.hh"
24 #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);
55 Clef_engraver::Clef_engraver ()
65 Clef_engraver::set_type (String s)
67 if (s.right_str (2) == "_8") // Down one octave
70 s = s.left_str (s.length_i () - 2);
72 else if (s.right_str (2) == "^8") // Up one octave
75 s = s.left_str (s.length_i () - 2);
80 SCM c = get_property ("supportedClefTypes");
81 SCM p = get_property ("clefPitches");
85 SCM found = scm_assoc (ly_str02scm (s.ch_C ()), c);
86 if (found == SCM_BOOL_F)
89 SCM glyph = gh_cadr (found);
90 SCM pos = gh_caddr (found);
92 daddy_trans_l_->set_property ("glyph", glyph);
93 daddy_trans_l_->set_property ("position", pos);
95 found = scm_assoc (glyph, p);
96 if (found == SCM_BOOL_F)
99 int c0_position = gh_scm2int (pos) + gh_scm2int (gh_cdr (found));
100 daddy_trans_l_->set_property ("c0-position", gh_int2scm (c0_position));
103 int c0_position = gh_scm2int (get_property ("c0-position"));
104 c0_position -= (int)octave_dir_ * 7;
105 daddy_trans_l_->set_property ("c0-position", gh_int2scm (c0_position));
108 SCM basic = ly_symbol2scm ("Clef");
109 SCM c0 = ly_symbol2scm ("c0-position");
110 SCM gl = ly_symbol2scm ("glyph");
112 daddy_trans_l_->execute_single_pushpop_property (basic, gl, SCM_UNDEFINED);
113 daddy_trans_l_->execute_single_pushpop_property (basic, c0, SCM_UNDEFINED);
114 daddy_trans_l_->execute_single_pushpop_property (basic, gl,
115 get_property ("glyph"));
116 daddy_trans_l_->execute_single_pushpop_property (basic, c0,
117 get_property ("c0_position")
123 Generate a clef at the start of a measure. (when you see a Bar,
127 Clef_engraver::acknowledge_element (Score_element_info info)
129 Item * item =dynamic_cast <Item *> (info.elem_l_);
132 if (Bar::has_interface (info.elem_l_)
133 && gh_string_p (get_property ("glyph")))
137 if (Note_head::has_interface (item)
138 || Local_key_item::has_interface (item))
140 int p = int (Staff_symbol_referencer::position_f (item))
141 + gh_scm2int (get_property ("c0-position"));
142 Staff_symbol_referencer::set_position (item, p);
144 else if (Key_item::has_interface (item))
146 item->set_elt_property ("c0-position", get_property ("c0-position"));
152 Clef_engraver::do_creation_processing ()
154 daddy_trans_l_->set_property ("position", gh_int2scm (0));
155 daddy_trans_l_->set_property ("glyph", SCM_EOL);
156 daddy_trans_l_->set_property ("c0-position", gh_int2scm (0));
158 SCM def = get_property ("defaultClef");
159 if (gh_string_p (def))
161 set_type (ly_scm2string (def));
166 Clef_engraver::do_try_music (Music * r_l)
168 if (Clef_change_req *cl = dynamic_cast <Clef_change_req *> (r_l))
171 if (!set_type (cl->clef_str_))
172 cl->origin ()->warning (_ ("unknown clef type"));
180 Clef_engraver::create_clef ()
184 Item *c= new Item (get_property ("Clef"));
185 announce_element (c, clef_req_l_);
187 Staff_symbol_referencer::set_interface (c);
191 Staff_symbol_referencer::set_position (clef_p_,
192 gh_scm2int (get_property ("position")
196 Item * g = new Item (get_property ("OctavateEight"));
198 Side_position::add_support (g,clef_p_);
200 g->set_parent (clef_p_, Y_AXIS);
201 g->set_parent (clef_p_, X_AXIS);
203 g->set_elt_property ("direction", gh_int2scm (octave_dir_));
205 announce_element (octavate_p_, clef_req_l_);
210 Clef_engraver::do_process_music ()
212 if (clef_req_l_ || first_b_)
215 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
220 Clef_engraver::do_pre_move_processing ()
225 if (to_boolean (clef_p_->get_elt_property ("non-default")))
227 vis = get_property ("explicitClefVisibility");
232 clef_p_->set_elt_property ("visibility-lambda", vis);
234 octavate_p_->set_elt_property ("visibility-lambda", vis);
237 typeset_element (clef_p_);
241 typeset_element (octavate_p_);
250 Clef_engraver::do_post_move_processing ()
255 ADD_THIS_TRANSLATOR (Clef_engraver);