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 Clef_engraver::Clef_engraver()
57 clef_glyph_ = SCM_EOL;
67 Clef_engraver::set_type (String s)
69 if (s.right_str(2) == "_8") // Down one octave
72 s = s.left_str(s.length_i() - 2);
74 else if (s.right_str(2) == "^8") // Up one octave
77 s = s.left_str(s.length_i() - 2);
82 SCM c = get_property ("supportedClefTypes");
83 SCM p = get_property ("clefPitches");
87 SCM found = scm_assoc (ly_str02scm (s.ch_C()), c);
88 if (found == SCM_BOOL_F)
91 clef_glyph_ = gh_cadr (found);
92 SCM pos = gh_caddr (found);
94 clef_position_i_ = gh_scm2int (pos);
96 found = scm_assoc (clef_glyph_, p);
97 if (found == SCM_BOOL_F)
100 c0_position_i_ = clef_position_i_ + gh_scm2int (gh_cdr (found));
103 c0_position_i_ -= (int) octave_dir_ * 7;
109 Generate a clef at the start of a measure. (when you see a Bar,
113 Clef_engraver::acknowledge_element (Score_element_info info)
115 if (dynamic_cast<Bar*>(info.elem_l_)
116 && gh_string_p (clef_glyph_))
119 /* ugh; should make Clef_referenced baseclass */
120 Item * it_l =dynamic_cast <Item *> (info.elem_l_);
123 if (dynamic_cast<Note_head*>(it_l)
124 || dynamic_cast<Local_key_item*> (it_l)
128 Staff_symbol_referencer_interface si (it_l);
129 si.set_position (int (si.position_f ()) + c0_position_i_);
131 else if (Key_item *k = dynamic_cast<Key_item*>(it_l))
133 k->set_elt_property ("c0-position", gh_int2scm (c0_position_i_));
139 Clef_engraver::do_creation_processing()
141 SCM def = get_property ("defaultClef");
142 if (gh_string_p (def))
144 set_type (ly_scm2string (def));
146 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
151 Clef_engraver::do_try_music (Music * r_l)
153 if (Clef_change_req *cl = dynamic_cast <Clef_change_req *> (r_l))
156 if (!set_type (cl->clef_str_))
157 cl->error (_ ("unknown clef type"));
167 Clef_engraver::create_clef()
171 Clef_item *c= new Clef_item;
172 c->set_elt_property ("breakable", SCM_BOOL_T);
173 c->set_elt_property ("break-align-symbol", ly_symbol2scm ("Clef_item"));
174 announce_element (Score_element_info (c, clef_req_l_));
176 Staff_symbol_referencer_interface si(c);
181 Staff_symbol_referencer_interface si(clef_p_);
182 clef_p_->set_elt_property ("glyph", clef_glyph_);
183 si.set_position (clef_position_i_);
186 Text_item * g = new Text_item;
187 Side_position_interface spi (g);
188 spi.set_axis (Y_AXIS);
189 spi.add_support (clef_p_);
190 g->set_elt_property ("text", ly_str02scm ( "8"));
191 g->set_elt_property ("style", gh_str02scm ("italic"));
192 g->set_parent (clef_p_, Y_AXIS);
193 g->set_parent (clef_p_, X_AXIS);
195 g->set_elt_property ("self-alignment-X", gh_int2scm (0));
196 g->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
197 g->add_offset_callback (Side_position_interface::centered_on_parent, X_AXIS);
198 g->set_elt_property ("direction", gh_int2scm (octave_dir_));
200 announce_element (Score_element_info (octavate_p_, clef_req_l_));
206 Clef_engraver::do_process_music()
211 clef_p_->set_elt_property ("non-default", SCM_BOOL_T);
216 Clef_engraver::do_pre_move_processing()
220 if(to_boolean (clef_p_->remove_elt_property("non-default")))
222 SCM all = scm_eval (ly_symbol2scm ("all-visible"));
223 clef_p_->set_elt_property("visibility-lambda", all);
225 octavate_p_->set_elt_property("visibility-lambda", all);
227 typeset_element (clef_p_);
231 typeset_element(octavate_p_);
238 Clef_engraver::do_post_move_processing()
243 ADD_THIS_TRANSLATOR(Clef_engraver);