2 key-engraver.cc -- implement Key_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "bar-line.hh"
14 #include "staff-symbol-referencer.hh"
16 #include "engraver.hh"
18 #include "protected-scm.hh"
22 TODO: The representation of key sigs is all fucked.
26 Make the key signature.
28 class Key_engraver : public Engraver
30 void create_key (bool);
31 void read_ev (Music const * r);
37 TRANSLATOR_DECLARATIONS (Key_engraver);
40 virtual void initialize ();
41 virtual void finalize ();
42 virtual bool try_music (Music *ev);
43 virtual void stop_translation_timestep ();
44 virtual void start_translation_timestep ();
45 virtual void process_music ();
46 virtual void acknowledge_grob (Grob_info);
51 Key_engraver::finalize ()
56 Key_engraver::Key_engraver ()
65 Key_engraver::create_key (bool def)
69 item_ = make_item ("KeySignature", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
71 item_->set_property ("c0-position",
72 get_property ("middleCPosition"));
74 SCM last = get_property ("lastKeySignature");
75 SCM key = get_property ("keySignature");
76 if (to_boolean (get_property ("printKeyCancellation"))
77 && !scm_is_eq (last, key))
79 cancellation_ = make_item ("KeyCancellation", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
80 cancellation_->set_property ("old-accidentals",last);
81 cancellation_->set_property ("c0-position",
82 get_property ("middleCPosition"));
85 item_->set_property ("new-accidentals", key);
90 SCM vis = get_property ("explicitKeySignatureVisibility");
91 if (ly_c_procedure_p (vis))
92 item_->set_property ("break-visibility",vis);
98 Key_engraver::try_music (Music * ev)
100 if (ev->is_mus_type ("key-change-event"))
102 /* do this only once, just to be on the safe side. */
115 Key_engraver::acknowledge_grob (Grob_info info)
117 if (Clef::has_interface (info.grob_))
119 SCM c = get_property ("createKeyOnClefChange");
125 else if (Bar_line::has_interface (info.grob_)
126 && ly_c_pair_p (get_property ("keySignature")))
134 Key_engraver::process_music ()
137 get_property ("lastKeySignature") != get_property ("keySignature"))
143 Key_engraver::stop_translation_timestep ()
146 context ()->set_property ("lastKeySignature", get_property ("keySignature"));
152 Key_engraver::read_ev (Music const * r)
154 SCM p = r->get_property ("pitch-alist");
155 if (!ly_c_pair_p (p))
158 SCM n = scm_list_copy (p);
160 for (SCM s = get_property ("keyAccidentalOrder");
161 ly_c_pair_p (s); s = ly_cdr (s))
163 if (ly_c_pair_p (scm_member (ly_car (s), n)))
165 accs = scm_cons (ly_car (s), accs);
166 n = scm_delete_x (ly_car (s), n);
170 for (SCM s = n ; ly_c_pair_p (s); s = ly_cdr (s))
171 if (scm_to_int (ly_cdar (s)))
172 accs = scm_cons (ly_car (s), accs);
174 context ()->set_property ("keySignature", accs);
175 context ()->set_property ("tonic" ,
176 r->get_property ("tonic"));
181 Key_engraver::start_translation_timestep ()
188 Key_engraver::initialize ()
190 context ()->set_property ("keySignature", SCM_EOL);
191 context ()->set_property ("lastKeySignature", SCM_EOL);
194 context ()->set_property ("tonic", p.smobbed_copy ());
199 ENTER_DESCRIPTION (Key_engraver,
201 /* creats*/ "KeySignature",
202 /* accepts */ "key-change-event",
203 /* acks */ "bar-line-interface clef-interface",
204 /* reads */ "keySignature printKeyCancellation lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
205 /* write */ "lastKeySignature tonic keySignature");