2 key-engraver.cc -- implement Key_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 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"
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);
31 TRANSLATOR_DECLARATIONS(Key_engraver);
33 Key_change_req * keyreq_l_;
35 Protected_scm old_accs_; // ugh. -> property
38 virtual void initialize ();
39 virtual void finalize ();
40 virtual bool try_music (Music *req_l);
41 virtual void stop_translation_timestep ();
42 virtual void start_translation_timestep ();
43 virtual void create_grobs ();
44 virtual void acknowledge_grob (Grob_info);
49 Key_engraver::finalize ()
51 old_accs_ = SCM_EOL; // unprotect can not be called from dtor.
54 Key_engraver::Key_engraver ()
61 Key_engraver::create_key (bool def)
65 item_p_ = new Item (get_property ("KeySignature"));
67 item_p_->set_grob_property ("c0-position", gh_int2scm (0));
69 // todo: put this in basic props.
70 item_p_->set_grob_property ("old-accidentals", old_accs_);
71 item_p_->set_grob_property ("new-accidentals", get_property ("keySignature"));
73 Staff_symbol_referencer::set_interface (item_p_);
74 Key_item::set_interface (item_p_);
77 announce_grob (item_p_,keyreq_l_);
83 SCM vis = get_property ("explicitKeySignatureVisibility");
84 if (gh_procedure_p (vis))
85 item_p_->set_grob_property ("visibility-lambda",vis);
91 Key_engraver::try_music (Music * req_l)
93 if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req_l))
95 if (keyreq_l_ && !keyreq_l_->equal_b (kc))
97 kc->origin ()->warning (_ ("Conflicting key signatures found."));
98 keyreq_l_->origin ()->warning (_ ("This was the other key definition."));
102 read_req (keyreq_l_);
110 Key_engraver::acknowledge_grob (Grob_info info)
112 if (Clef::has_interface (info.grob_l_))
114 SCM c = get_property ("createKeyOnClefChange");
120 else if (Bar::has_interface (info.grob_l_)
121 && gh_pair_p (get_property ("keySignature")))
129 Key_engraver::create_grobs ()
131 if (keyreq_l_ || old_accs_ != get_property ("keySignature"))
138 Key_engraver::stop_translation_timestep ()
142 typeset_grob (item_p_);
148 Key_engraver::read_req (Key_change_req const * r)
150 SCM p = r->get_mus_property ("pitch-alist");
154 SCM n = scm_list_copy (p);
156 for (SCM s = get_property ("keyAccidentalOrder");
157 gh_pair_p (s); s = ly_cdr (s))
159 if (gh_pair_p (scm_member (ly_car (s), n)))
161 accs = gh_cons (ly_car (s), accs);
162 n = scm_delete_x (ly_car (s), n);
165 for (SCM s = n ; gh_pair_p (s); s = ly_cdr (s))
166 if (gh_scm2int (ly_cdar (s)))
167 accs = gh_cons (ly_car (s), accs);
169 old_accs_ = get_property ("keySignature");
170 daddy_trans_l_->set_property ("keySignature", accs);
174 Key_engraver::start_translation_timestep ()
177 old_accs_ = get_property ("keySignature");
181 Key_engraver::initialize ()
183 daddy_trans_l_->set_property ("keySignature", SCM_EOL);
190 ENTER_DESCRIPTION(Key_engraver,
192 /* creats*/ "KeySignature",
193 /* acks */ "bar-line-interface clef-interface",
194 /* reads */ "keySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",