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>
12 #include "staff-symbol-referencer.hh"
14 #include "clef-item.hh"
16 #include "command-request.hh"
17 #include "timing-translator.hh"
18 #include "note-head.hh"
19 #include "key-item.hh"
20 #include "local-key-item.hh"
22 #include "engraver.hh"
23 #include "direction.hh"
25 /// where is c-0 in the staff?
26 class Clef_engraver
: public Engraver
{
28 Clef_change_req
* clef_req_l_
;
30 bool set_type (String
);
32 virtual void do_process_requests();
33 virtual void do_pre_move_processing();
34 virtual void do_creation_processing();
35 virtual void do_post_move_processing();
36 virtual bool do_try_music (Music
*);
37 virtual void acknowledge_element (Score_element_info
);
39 VIRTUAL_COPY_CONS(Translator
);
43 Direction octave_dir_
;
44 SCM clef_glyph_
; // no need for protection. Always referenced somewhere else.
50 Clef_engraver::Clef_engraver()
52 clef_glyph_
= SCM_EOL
;
61 Clef_engraver::set_type (String s
)
63 if (s
.right_str(2) == "_8") // Down one octave
66 s
= s
.left_str(s
.length_i() - 2);
68 else if (s
.right_str(2) == "^8") // Up one octave
71 s
= s
.left_str(s
.length_i() - 2);
76 SCM c
= get_property ("supportedClefTypes",0);
77 SCM p
= get_property ("clefPitches", 0);
81 SCM found
= scm_assoc (ly_str02scm (s
.ch_C()), c
);
82 if (found
== SCM_BOOL_F
)
85 clef_glyph_
= gh_cadr (found
);
86 SCM pos
= gh_caddr (found
);
88 clef_position_i_
= gh_scm2int (pos
);
90 found
= scm_assoc (clef_glyph_
, p
);
91 if (found
== SCM_BOOL_F
)
94 c0_position_i_
= clef_position_i_
+ gh_scm2int (gh_cdr (found
));
97 c0_position_i_
-= (int) octave_dir_
* 7;
103 Generate a clef at the start of a measure. (when you see a Bar,
107 Clef_engraver::acknowledge_element (Score_element_info info
)
109 if (dynamic_cast<Bar
*>(info
.elem_l_
)
110 && gh_string_p (clef_glyph_
))
113 /* ugh; should make Clef_referenced baseclass */
114 Item
* it_l
=dynamic_cast <Item
*> (info
.elem_l_
);
117 if (dynamic_cast<Note_head
*>(it_l
)
118 || dynamic_cast<Local_key_item
*> (it_l
)
122 Staff_symbol_referencer_interface
si (it_l
);
123 si
.set_position (int (si
.position_f ()) + c0_position_i_
);
125 else if (Key_item
*k
= dynamic_cast<Key_item
*>(it_l
))
127 k
-> set_c_position (c0_position_i_
);
133 Clef_engraver::do_creation_processing()
135 SCM def
= get_property ("defaultClef", 0);
136 if (gh_string_p (def
))
138 set_type (ly_scm2string (def
));
140 clef_p_
->set_elt_property ("non-default", SCM_BOOL_T
);
145 Clef_engraver::do_try_music (Music
* r_l
)
147 if (Clef_change_req
*cl
= dynamic_cast <Clef_change_req
*> (r_l
))
150 if (!set_type (cl
->clef_str_
))
151 cl
->error (_ ("unknown clef type"));
161 Clef_engraver::create_clef()
165 Clef_item
*c
= new Clef_item
;
166 c
->set_elt_property ("breakable", SCM_BOOL_T
);
167 c
->set_elt_property ("break-aligned", SCM_BOOL_T
);
168 announce_element (Score_element_info (c
, clef_req_l_
));
170 Staff_symbol_referencer_interface
si(c
);
175 Staff_symbol_referencer_interface
si(clef_p_
);
176 clef_p_
->set_elt_property ("glyph", clef_glyph_
);
177 si
.set_position (clef_position_i_
);
180 clef_p_
->set_elt_property ("octave-dir", gh_int2scm (octave_dir_
));
186 Clef_engraver::do_process_requests()
191 clef_p_
->set_elt_property ("non-default", SCM_BOOL_T
);
196 Clef_engraver::do_pre_move_processing()
200 if(to_boolean (clef_p_
->remove_elt_property("non-default")))
201 clef_p_
->set_elt_property("visibility-lambda",
202 ly_eval_str ("all-visibility"));
204 typeset_element (clef_p_
);
210 Clef_engraver::do_post_move_processing()
218 ADD_THIS_TRANSLATOR(Clef_engraver
);