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.
53 SCM basic_properties_;
54 Protected_scm current_settings_;
58 Clef_engraver::Clef_engraver()
60 current_settings_ = SCM_EOL;
61 basic_properties_ = SCM_EOL;
63 clef_glyph_ = SCM_EOL;
73 Clef_engraver::set_type (String s)
75 if (s.right_str(2) == "_8") // Down one octave
78 s = s.left_str(s.length_i() - 2);
80 else if (s.right_str(2) == "^8") // Up one octave
83 s = s.left_str(s.length_i() - 2);
88 SCM c = get_property ("supportedClefTypes");
89 SCM p = get_property ("clefPitches");
93 SCM found = scm_assoc (ly_str02scm (s.ch_C()), c);
94 if (found == SCM_BOOL_F)
97 clef_glyph_ = gh_cadr (found);
98 SCM pos = gh_caddr (found);
100 clef_position_i_ = gh_scm2int (pos);
102 found = scm_assoc (clef_glyph_, p);
103 if (found == SCM_BOOL_F)
106 c0_position_i_ = clef_position_i_ + gh_scm2int (gh_cdr (found));
109 c0_position_i_ -= (int) octave_dir_ * 7;
111 current_settings_ = gh_cons (gh_cons (ly_symbol2scm ("glyph"), clef_glyph_), basic_properties_);
113 gh_cons (gh_cons (ly_symbol2scm ("c0-position"),
114 gh_int2scm (c0_position_i_)),
122 Generate a clef at the start of a measure. (when you see a Bar,
126 Clef_engraver::acknowledge_element (Score_element_info info)
128 if (dynamic_cast<Bar*>(info.elem_l_)
129 && gh_string_p (clef_glyph_))
132 /* ugh; should make Clef_referenced baseclass */
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)
141 Staff_symbol_referencer_interface si (it_l);
142 si.set_position (int (si.position_f ()) + c0_position_i_);
144 else if (Key_item *k = dynamic_cast<Key_item*>(it_l))
146 k->set_elt_property ("c0-position", gh_int2scm (c0_position_i_));
152 Clef_engraver::do_creation_processing()
154 basic_properties_ = get_property ("basicClefItemProperties");
156 SCM def = get_property ("defaultClef");
157 if (gh_string_p (def))
159 set_type (ly_scm2string (def));
161 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
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->error (_ ("unknown clef type"));
182 Clef_engraver::create_clef()
186 Clef_item *c= new Clef_item ( current_settings_);
187 announce_element (Score_element_info (c, clef_req_l_));
189 Staff_symbol_referencer_interface si(c);
194 Staff_symbol_referencer_interface si(clef_p_);
196 si.set_position (clef_position_i_);
199 Text_item * g = new Text_item (get_property ("basicOctavateEightProperties"));
200 Side_position_interface spi (g);
201 spi.set_axis (Y_AXIS);
202 spi.add_support (clef_p_);
203 g->set_parent (clef_p_, Y_AXIS);
204 g->set_parent (clef_p_, X_AXIS);
205 g->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
206 g->add_offset_callback (Side_position_interface::centered_on_parent, X_AXIS);
207 g->set_elt_property ("direction", gh_int2scm (octave_dir_));
209 announce_element (Score_element_info (octavate_p_, clef_req_l_));
215 Clef_engraver::do_process_music()
220 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
225 Clef_engraver::do_pre_move_processing()
230 if(to_boolean (clef_p_->get_elt_property("non-default")))
232 vis = ly_symbol2scm ("all-visible");
233 vis = scm_eval (vis);
238 clef_p_->set_elt_property("visibility-lambda", vis);
240 octavate_p_->set_elt_property("visibility-lambda", vis);
243 typeset_element (clef_p_);
247 typeset_element(octavate_p_);
254 Clef_engraver::do_post_move_processing()
259 ADD_THIS_TRANSLATOR(Clef_engraver);