2 key-engraver.cc -- implement Key_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "command-request.hh"
11 #include "musical-request.hh"
13 #include "bar-line.hh"
14 #include "staff-symbol-referencer.hh"
15 #include "translator-group.hh"
16 #include "engraver.hh"
18 #include "protected-scm.hh"
22 Make the key signature.
24 class Key_engraver : public Engraver
26 void create_key (bool);
27 void read_req (Key_change_req const * r);
28 Key_change_req * keyreq_l_;
32 TRANSLATOR_DECLARATIONS(Key_engraver);
35 virtual void initialize ();
36 virtual void finalize ();
37 virtual bool try_music (Music *req_l);
38 virtual void stop_translation_timestep ();
39 virtual void start_translation_timestep ();
40 virtual void create_grobs ();
41 virtual void acknowledge_grob (Grob_info);
46 Key_engraver::finalize ()
51 Key_engraver::Key_engraver ()
59 Key_engraver::create_key (bool def)
63 item_p_ = new Item (get_property ("KeySignature"));
65 item_p_->set_grob_property ("c0-position",
66 get_property ("centralCPosition"));
68 // todo: put this in basic props.
69 item_p_->set_grob_property ("old-accidentals", get_property ("lastKeySignature"));
70 item_p_->set_grob_property ("new-accidentals", get_property ("keySignature"));
72 announce_grob(item_p_, keyreq_l_ ? keyreq_l_->self_scm() : SCM_EOL);
77 SCM vis = get_property ("explicitKeySignatureVisibility");
78 if (gh_procedure_p (vis))
79 item_p_->set_grob_property ("visibility-lambda",vis);
85 Key_engraver::try_music (Music * req_l)
87 if (Key_change_req *kc = dynamic_cast <Key_change_req *> (req_l))
89 if (keyreq_l_ && !keyreq_l_->equal_b (kc))
91 kc->origin ()->warning (_ ("Conflicting key signatures found."));
92 keyreq_l_->origin ()->warning (_ ("This was the other key definition."));
105 Key_engraver::acknowledge_grob (Grob_info info)
107 if (Clef::has_interface (info.grob_l_))
109 SCM c = get_property ("createKeyOnClefChange");
115 else if (Bar_line::has_interface (info.grob_l_)
116 && gh_pair_p (get_property ("keySignature")))
124 Key_engraver::create_grobs ()
127 get_property ("lastKeySignature") != get_property ("keySignature"))
133 Key_engraver::stop_translation_timestep ()
137 typeset_grob (item_p_);
144 Key_engraver::read_req (Key_change_req const * r)
146 SCM p = r->get_mus_property ("pitch-alist");
150 SCM n = scm_list_copy (p);
152 for (SCM s = get_property ("keyAccidentalOrder");
153 gh_pair_p (s); s = ly_cdr (s))
155 if (gh_pair_p (scm_member (ly_car (s), n)))
157 accs = gh_cons (ly_car (s), accs);
158 n = scm_delete_x (ly_car (s), n);
162 for (SCM s = n ; gh_pair_p (s); s = ly_cdr (s))
163 if (gh_scm2int (ly_cdar (s)))
164 accs = gh_cons (ly_car (s), accs);
166 daddy_trans_l_->set_property ("lastKeySignature",
167 get_property ("keySignature"));
168 daddy_trans_l_->set_property ("keySignature", accs);
173 Key_engraver::start_translation_timestep ()
176 daddy_trans_l_->set_property ("lastKeySignature", get_property ("keySignature"));
181 Key_engraver::initialize ()
183 daddy_trans_l_->set_property ("keySignature", SCM_EOL);
184 daddy_trans_l_->set_property ("lastKeySignature", SCM_EOL);
188 ENTER_DESCRIPTION(Key_engraver,
190 /* creats*/ "KeySignature",
191 /* acks */ "bar-line-interface clef-interface",
192 /* reads */ "keySignature lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
193 /* write */ "lastKeySignature");