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 "staff-symbol-referencer.hh"
15 #include "clef-item.hh"
17 #include "command-request.hh"
18 #include "timing-translator.hh"
19 #include "note-head.hh"
20 #include "key-item.hh"
21 #include "local-key-item.hh"
23 #include "engraver.hh"
24 #include "direction.hh"
25 #include "side-position-interface.hh"
26 #include "text-item.hh"
28 /// where is c-0 in the staff?
29 class Clef_engraver : public Engraver {
31 Text_item * octavate_p_;
32 Clef_change_req * clef_req_l_;
35 bool set_type (String);
37 virtual void do_process_music();
38 virtual void do_pre_move_processing();
39 virtual void do_creation_processing();
40 virtual void do_post_move_processing();
41 virtual bool do_try_music (Music*);
42 virtual void acknowledge_element (Score_element_info);
44 VIRTUAL_COPY_CONS(Translator);
48 Direction octave_dir_;
49 SCM clef_glyph_; // no need for protection. Always referenced somewhere else.
55 Protected_scm current_settings_;
59 Clef_engraver::Clef_engraver()
61 current_settings_ = SCM_EOL;
64 clef_glyph_ = SCM_EOL;
74 Clef_engraver::set_type (String s)
76 if (s.right_str(2) == "_8") // Down one octave
79 s = s.left_str(s.length_i() - 2);
81 else if (s.right_str(2) == "^8") // Up one octave
84 s = s.left_str(s.length_i() - 2);
89 SCM c = get_property ("supportedClefTypes");
90 SCM p = get_property ("clefPitches");
94 SCM found = scm_assoc (ly_str02scm (s.ch_C()), c);
95 if (found == SCM_BOOL_F)
98 clef_glyph_ = gh_cadr (found);
99 SCM pos = gh_caddr (found);
101 clef_position_i_ = gh_scm2int (pos);
103 found = scm_assoc (clef_glyph_, p);
104 if (found == SCM_BOOL_F)
107 c0_position_i_ = clef_position_i_ + gh_scm2int (gh_cdr (found));
110 c0_position_i_ -= (int) octave_dir_ * 7;
112 SCM basic = get_property ("basicClefItemProperties");
113 current_settings_ = gh_cons (gh_cons (ly_symbol2scm ("glyph"), clef_glyph_), basic);
115 gh_cons (gh_cons (ly_symbol2scm ("c0-position"),
116 gh_int2scm (c0_position_i_)),
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 if (dynamic_cast<Bar*>(info.elem_l_)
130 && gh_string_p (clef_glyph_))
133 Item * it_l =dynamic_cast <Item *> (info.elem_l_);
136 if (dynamic_cast<Note_head*>(it_l)
137 || dynamic_cast<Local_key_item*> (it_l))
139 Staff_symbol_referencer_interface si (it_l);
140 si.set_position (int (si.position_f ()) + c0_position_i_);
142 else if (Key_item *k = dynamic_cast<Key_item*>(it_l))
144 k->set_elt_property ("c0-position", gh_int2scm (c0_position_i_));
150 Clef_engraver::do_creation_processing()
152 SCM def = get_property ("defaultClef");
153 if (gh_string_p (def))
155 set_type (ly_scm2string (def));
160 Clef_engraver::do_try_music (Music * r_l)
162 if (Clef_change_req *cl = dynamic_cast <Clef_change_req *> (r_l))
165 if (!set_type (cl->clef_str_))
166 cl->error (_ ("unknown clef type"));
176 Clef_engraver::create_clef()
180 Clef_item *c= new Clef_item ( current_settings_);
181 announce_element (Score_element_info (c, clef_req_l_));
183 Staff_symbol_referencer_interface si(c);
188 Staff_symbol_referencer_interface si(clef_p_);
190 si.set_position (clef_position_i_);
193 Text_item * g = new Text_item (get_property ("basicOctavateEightProperties"));
194 Side_position_interface spi (g);
195 spi.set_axis (Y_AXIS);
196 spi.add_support (clef_p_);
197 g->set_parent (clef_p_, Y_AXIS);
198 g->set_parent (clef_p_, X_AXIS);
199 g->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
200 g->add_offset_callback (Side_position_interface::centered_on_parent, X_AXIS);
201 g->set_elt_property ("direction", gh_int2scm (octave_dir_));
203 announce_element (Score_element_info (octavate_p_, clef_req_l_));
209 Clef_engraver::do_process_music()
211 if (clef_req_l_ || first_b_)
214 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
219 Clef_engraver::do_pre_move_processing()
224 if(to_boolean (clef_p_->get_elt_property("non-default")))
226 vis = ly_symbol2scm ("all-visible");
227 vis = scm_eval (vis);
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);