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);
36 TRANSLATOR_DECLARATIONS (Key_engraver);
39 virtual void initialize ();
40 virtual void finalize ();
41 virtual bool try_music (Music *ev);
42 virtual void stop_translation_timestep ();
43 virtual void start_translation_timestep ();
44 virtual void process_music ();
45 virtual void acknowledge_grob (Grob_info);
50 Key_engraver::finalize ()
55 Key_engraver::Key_engraver ()
63 Key_engraver::create_key (bool def)
67 item_ = make_item ("KeySignature");
69 item_->set_property ("c0-position",
70 get_property ("middleCPosition"));
72 if (to_boolean (get_property ("printKeyCancellation")))
73 item_->set_property ("old-accidentals", get_property ("lastKeySignature"));
74 item_->set_property ("new-accidentals", get_property ("keySignature"));
76 announce_grob (item_, key_ev_ ? key_ev_->self_scm () : SCM_EOL);
81 SCM vis = get_property ("explicitKeySignatureVisibility");
82 if (ly_procedure_p (vis))
83 item_->set_property ("break-visibility",vis);
89 Key_engraver::try_music (Music * ev)
91 if (ev->is_mus_type ("key-change-event"))
96 do this only once, just to be on the safe side.
109 Key_engraver::acknowledge_grob (Grob_info info)
111 if (Clef::has_interface (info.grob_))
113 SCM c = get_property ("createKeyOnClefChange");
119 else if (Bar_line::has_interface (info.grob_)
120 && ly_pair_p (get_property ("keySignature")))
128 Key_engraver::process_music ()
131 get_property ("lastKeySignature") != get_property ("keySignature"))
137 Key_engraver::stop_translation_timestep ()
141 typeset_grob (item_);
148 Key_engraver::read_ev (Music const * r)
150 SCM p = r->get_property ("pitch-alist");
154 SCM n = scm_list_copy (p);
156 for (SCM s = get_property ("keyAccidentalOrder");
157 ly_pair_p (s); s = ly_cdr (s))
159 if (ly_pair_p (scm_member (ly_car (s), n)))
161 accs = scm_cons (ly_car (s), accs);
162 n = scm_delete_x (ly_car (s), n);
166 for (SCM s = n ; ly_pair_p (s); s = ly_cdr (s))
167 if (ly_scm2int (ly_cdar (s)))
168 accs = scm_cons (ly_car (s), accs);
170 daddy_context_->set_property ("keySignature", accs);
171 daddy_context_->set_property ("tonic" ,
172 r->get_property ("tonic"));
177 Key_engraver::start_translation_timestep ()
180 daddy_context_->set_property ("lastKeySignature", get_property ("keySignature"));
185 Key_engraver::initialize ()
187 daddy_context_->set_property ("keySignature", SCM_EOL);
188 daddy_context_->set_property ("lastKeySignature", SCM_EOL);
191 daddy_context_->set_property ("tonic", p.smobbed_copy ());
196 ENTER_DESCRIPTION (Key_engraver,
198 /* creats*/ "KeySignature",
199 /* accepts */ "key-change-event",
200 /* acks */ "bar-line-interface clef-interface",
201 /* reads */ "keySignature printKeyCancellation lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
202 /* write */ "lastKeySignature tonic keySignature");