2 key-engraver.cc -- implement Key_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "bar-line.hh"
11 #include "staff-symbol-referencer.hh"
13 #include "engraver.hh"
14 #include "protected-scm.hh"
18 #include "translator.icc"
21 TODO: The representation of key sigs is all fucked.
25 Make the key signature.
27 class Key_engraver : public Engraver
29 void create_key (bool);
30 void read_event (Music const *r);
36 TRANSLATOR_DECLARATIONS (Key_engraver);
39 virtual void initialize ();
40 virtual void finalize ();
41 virtual bool try_music (Music *event);
42 void stop_translation_timestep ();
43 void process_music ();
45 DECLARE_ACKNOWLEDGER (clef);
46 DECLARE_ACKNOWLEDGER (bar_line);
51 Key_engraver::finalize ()
55 Key_engraver::Key_engraver ()
63 Key_engraver::create_key (bool is_default)
67 item_ = make_item ("KeySignature", key_event_ ? key_event_->self_scm () : SCM_EOL);
69 item_->set_property ("c0-position",
70 get_property ("middleCPosition"));
72 SCM last = get_property ("lastKeySignature");
73 SCM key = get_property ("keySignature");
74 if (to_boolean (get_property ("printKeyCancellation"))
75 && !scm_is_eq (last, key))
77 cancellation_ = make_item ("KeyCancellation", key_event_ ? key_event_->self_scm () : SCM_EOL);
78 cancellation_->set_property ("accidentals", last);
79 cancellation_->set_property ("c0-position",
80 get_property ("middleCPosition"));
82 item_->set_property ("accidentals", key);
87 SCM visibility = get_property ("explicitKeySignatureVisibility");
88 item_->set_property ("break-visibility", visibility);
93 Key_engraver::try_music (Music *event)
95 if (event->is_mus_type ("key-change-event"))
97 /* do this only once, just to be on the safe side. */
101 read_event (key_event_);
109 Key_engraver::acknowledge_clef (Grob_info info)
112 SCM c = get_property ("createKeyOnClefChange");
120 Key_engraver::acknowledge_bar_line (Grob_info info)
123 if (scm_is_pair (get_property ("keySignature")))
130 Key_engraver::process_music ()
133 || get_property ("lastKeySignature") != get_property ("keySignature"))
138 Key_engraver::stop_translation_timestep ()
141 context ()->set_property ("lastKeySignature", get_property ("keySignature"));
147 Key_engraver::read_event (Music const *r)
149 SCM p = r->get_property ("pitch-alist");
150 if (!scm_is_pair (p))
153 SCM n = scm_list_copy (p);
155 for (SCM s = get_property ("keyAccidentalOrder");
156 scm_is_pair (s); s = scm_cdr (s))
158 if (scm_is_pair (scm_member (scm_car (s), n)))
160 accs = scm_cons (scm_car (s), accs);
161 n = scm_delete_x (scm_car (s), n);
165 for (SCM s = n; scm_is_pair (s); s = scm_cdr (s))
166 if (scm_to_int (scm_cdar (s)))
167 accs = scm_cons (scm_car (s), accs);
169 context ()->set_property ("keySignature", accs);
170 context ()->set_property ("tonic",
171 r->get_property ("tonic"));
175 Key_engraver::initialize ()
177 context ()->set_property ("keySignature", SCM_EOL);
178 context ()->set_property ("lastKeySignature", SCM_EOL);
181 context ()->set_property ("tonic", p.smobbed_copy ());
185 ADD_ACKNOWLEDGER (Key_engraver,clef);
186 ADD_ACKNOWLEDGER (Key_engraver,bar_line);
188 ADD_TRANSLATOR (Key_engraver,
190 /* creats*/ "KeySignature",
191 /* accepts */ "key-change-event",
192 /* reads */ "keySignature printKeyCancellation lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
193 /* write */ "lastKeySignature tonic keySignature");