2 key-engraver.cc -- implement Key_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "command-request.hh"
11 #include "musical-request.hh"
14 #include "timing-translator.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "translator-group.hh"
17 #include "engraver.hh"
18 #include "musical-pitch.hh"
19 #include "protected-scm.hh"
23 Make the key signature.
25 class Key_engraver : public Engraver
27 void create_key(bool);
28 void read_req (Key_change_req const * r);
33 VIRTUAL_COPY_CONS(Translator);
35 Key_change_req * keyreq_l_;
37 Protected_scm old_accs_; // ugh. -> property
40 virtual void do_creation_processing();
41 virtual void do_removal_processing ();
42 virtual bool do_try_music (Music *req_l);
43 virtual void do_process_music();
44 virtual void do_pre_move_processing();
45 virtual void do_post_move_processing();
46 virtual void acknowledge_element (Score_element_info);
51 Key_engraver::do_removal_processing ()
53 old_accs_ = SCM_EOL; // unprotect can not be called from dtor.
56 Key_engraver::Key_engraver ()
63 Key_engraver::create_key (bool def)
67 item_p_ = new Item ( get_property ("basicKeyProperties"));
69 item_p_->set_elt_property ("c0-position", gh_int2scm (0));
71 // todo: put this in basic props.
72 item_p_->set_elt_property ("old-accidentals", old_accs_);
73 item_p_->set_elt_property ("new-accidentals", get_property ("keySignature"));
75 Staff_symbol_referencer::set_interface (item_p_);
76 Key_item::set_interface (item_p_);
78 SCM prop = get_property ("keyOctaviation");
79 bool multi = to_boolean (prop);
82 item_p_->set_elt_property ("multi-octave", gh_bool2scm (multi));
84 announce_element (item_p_,keyreq_l_);
88 item_p_->set_elt_property ("visibility-lambda",
89 scm_eval2 (ly_symbol2scm ("all-visible"),
96 Key_engraver::do_try_music (Music * req_l)
98 if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req_l))
101 warning (_ ("FIXME: key change merge"));
103 read_req (keyreq_l_);
110 Key_engraver::acknowledge_element (Score_element_info info)
112 if (Clef::has_interface (info.elem_l_))
114 SCM c = get_property ("createKeyOnClefChange");
120 else if (Bar::has_interface (info.elem_l_)
121 && gh_pair_p (get_property ("keySignature")))
129 Key_engraver::do_process_music ()
131 if (keyreq_l_ || old_accs_ != get_property ("keySignature"))
138 Key_engraver::do_pre_move_processing ()
142 typeset_element (item_p_);
148 Key_engraver::read_req (Key_change_req const * r)
150 SCM p = r->get_mus_property ("pitch-alist");
151 if (p == SCM_UNDEFINED)
154 SCM n = scm_list_copy (p);
156 for (SCM s = get_property ("keyAccidentalOrder");
157 gh_pair_p (s); s = gh_cdr (s))
159 if (gh_pair_p (scm_member (gh_car (s), n)))
161 accs = gh_cons (gh_car (s), accs);
162 n = scm_delete_x (gh_car (s), n);
165 for (SCM s = n ; gh_pair_p (s); s = gh_cdr (s))
166 if (gh_scm2int (gh_cdar (s)))
167 accs = gh_cons (gh_car (s), accs);
169 old_accs_ = get_property ("keySignature");
170 daddy_trans_l_->set_property ("keySignature", accs);
174 Key_engraver::do_post_move_processing ()
177 old_accs_ = get_property ("keySignature");
181 Key_engraver::do_creation_processing ()
183 daddy_trans_l_->set_property ("keySignature", SCM_EOL);
188 ADD_THIS_TRANSLATOR (Key_engraver);