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>
10 #include "bar-line.hh"
11 #include "staff-symbol-referencer.hh"
13 #include "engraver.hh"
14 #include "protected-scm.hh"
18 TODO: The representation of key sigs is all fucked.
22 Make the key signature.
24 class Key_engraver : public Engraver
26 void create_key (bool);
27 void read_ev (Music const * r);
33 TRANSLATOR_DECLARATIONS (Key_engraver);
36 virtual void initialize ();
37 virtual void finalize ();
38 virtual bool try_music (Music *ev);
39 virtual void stop_translation_timestep ();
40 virtual void start_translation_timestep ();
41 virtual void process_music ();
42 virtual void acknowledge_grob (Grob_info);
47 Key_engraver::finalize ()
52 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"));
81 item_->set_property ("new-accidentals", key);
86 SCM vis = get_property ("explicitKeySignatureVisibility");
87 if (ly_c_procedure_p (vis))
88 item_->set_property ("break-visibility",vis);
94 Key_engraver::try_music (Music * ev)
96 if (ev->is_mus_type ("key-change-event"))
98 /* do this only once, just to be on the safe side. */
111 Key_engraver::acknowledge_grob (Grob_info info)
113 if (Clef::has_interface (info.grob_))
115 SCM c = get_property ("createKeyOnClefChange");
121 else if (Bar_line::has_interface (info.grob_)
122 && scm_is_pair (get_property ("keySignature")))
130 Key_engraver::process_music ()
133 get_property ("lastKeySignature") != get_property ("keySignature"))
139 Key_engraver::stop_translation_timestep ()
142 context ()->set_property ("lastKeySignature", get_property ("keySignature"));
148 Key_engraver::read_ev (Music const * r)
150 SCM p = r->get_property ("pitch-alist");
151 if (!scm_is_pair (p))
154 SCM n = scm_list_copy (p);
156 for (SCM s = get_property ("keyAccidentalOrder");
157 scm_is_pair (s); s = scm_cdr (s))
159 if (scm_is_pair (scm_member (scm_car (s), n)))
161 accs = scm_cons (scm_car (s), accs);
162 n = scm_delete_x (scm_car (s), n);
166 for (SCM s = n ; scm_is_pair (s); s = scm_cdr (s))
167 if (scm_to_int (scm_cdar (s)))
168 accs = scm_cons (scm_car (s), accs);
170 context ()->set_property ("keySignature", accs);
171 context ()->set_property ("tonic" ,
172 r->get_property ("tonic"));
177 Key_engraver::start_translation_timestep ()
184 Key_engraver::initialize ()
186 context ()->set_property ("keySignature", SCM_EOL);
187 context ()->set_property ("lastKeySignature", SCM_EOL);
190 context ()->set_property ("tonic", p.smobbed_copy ());
195 ENTER_DESCRIPTION (Key_engraver,
197 /* creats*/ "KeySignature",
198 /* accepts */ "key-change-event",
199 /* acks */ "bar-line-interface clef-interface",
200 /* reads */ "keySignature printKeyCancellation lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
201 /* write */ "lastKeySignature tonic keySignature");