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"
19 TODO: The representation of key sigs is all fucked.
23 Make the key signature.
25 class Key_engraver : public Engraver
27 void create_key (bool);
28 void read_ev (Music const *r);
34 TRANSLATOR_DECLARATIONS (Key_engraver);
37 virtual void initialize ();
38 virtual void finalize ();
39 virtual bool try_music (Music *ev);
40 PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
41 PRECOMPUTED_VIRTUAL void process_music ();
43 DECLARE_ACKNOWLEDGER(clef);
44 DECLARE_ACKNOWLEDGER(bar_line);
49 Key_engraver::finalize ()
53 Key_engraver::Key_engraver ()
61 Key_engraver::create_key (bool def)
65 item_ = make_item ("KeySignature", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
67 item_->set_property ("c0-position",
68 get_property ("middleCPosition"));
70 SCM last = get_property ("lastKeySignature");
71 SCM key = get_property ("keySignature");
72 if (to_boolean (get_property ("printKeyCancellation"))
73 && !scm_is_eq (last, key))
75 cancellation_ = make_item ("KeyCancellation", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
76 cancellation_->set_property ("old-accidentals", last);
77 cancellation_->set_property ("c0-position",
78 get_property ("middleCPosition"));
80 item_->set_property ("new-accidentals", key);
85 SCM vis = get_property ("explicitKeySignatureVisibility");
86 if (ly_is_procedure (vis))
87 item_->set_property ("break-visibility", vis);
92 Key_engraver::try_music (Music *ev)
94 if (ev->is_mus_type ("key-change-event"))
96 /* do this only once, just to be on the safe side. */
108 Key_engraver::acknowledge_clef (Grob_info info)
110 SCM c = get_property ("createKeyOnClefChange");
118 Key_engraver::acknowledge_bar_line (Grob_info info)
120 if (scm_is_pair (get_property ("keySignature")))
127 Key_engraver::process_music ()
130 || get_property ("lastKeySignature") != get_property ("keySignature"))
135 Key_engraver::stop_translation_timestep ()
138 context ()->set_property ("lastKeySignature", get_property ("keySignature"));
144 Key_engraver::read_ev (Music const *r)
146 SCM p = r->get_property ("pitch-alist");
147 if (!scm_is_pair (p))
150 SCM n = scm_list_copy (p);
152 for (SCM s = get_property ("keyAccidentalOrder");
153 scm_is_pair (s); s = scm_cdr (s))
155 if (scm_is_pair (scm_member (scm_car (s), n)))
157 accs = scm_cons (scm_car (s), accs);
158 n = scm_delete_x (scm_car (s), n);
162 for (SCM s = n; scm_is_pair (s); s = scm_cdr (s))
163 if (scm_to_int (scm_cdar (s)))
164 accs = scm_cons (scm_car (s), accs);
166 context ()->set_property ("keySignature", accs);
167 context ()->set_property ("tonic",
168 r->get_property ("tonic"));
172 Key_engraver::initialize ()
174 context ()->set_property ("keySignature", SCM_EOL);
175 context ()->set_property ("lastKeySignature", SCM_EOL);
178 context ()->set_property ("tonic", p.smobbed_copy ());
181 #include "translator.icc"
183 ADD_ACKNOWLEDGER(Key_engraver,clef);
184 ADD_ACKNOWLEDGER(Key_engraver,bar_line);
185 ADD_TRANSLATOR (Key_engraver,
187 /* creats*/ "KeySignature",
188 /* accepts */ "key-change-event",
190 /* reads */ "keySignature printKeyCancellation lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
191 /* write */ "lastKeySignature tonic keySignature");