]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/key-engraver.cc
* scm/stencil.scm (fontify-text): reinstate function
[lilypond.git] / lily / key-engraver.cc
index 33f119f47c8d97105744310a3ce2dd07dcb0cfdb..2007350427fa9363fd18daf092f013fb63237ad6 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   */
 
 
@@ -12,7 +12,7 @@
 #include "item.hh"
 #include "bar-line.hh"
 #include "staff-symbol-referencer.hh"
-#include "translator-group.hh"
+#include "context.hh"
 #include "engraver.hh"
 #include "pitch.hh"
 #include "protected-scm.hh"
 class Key_engraver : public Engraver
 {
   void create_key (bool);
-  void read_ev (Key_change_ev const * r);
-  Key_change_ev * key_ev_;
+  void read_ev (Music const * r);
+  Music * key_ev_;
   Item * item_;
 
 public:
-  TRANSLATOR_DECLARATIONS(Key_engraver);
+  TRANSLATOR_DECLARATIONS (Key_engraver);
 
 protected:
   virtual void initialize ();
@@ -64,23 +64,22 @@ Key_engraver::create_key (bool def)
 {
   if (!item_) 
     {
-      item_ = make_item ("KeySignature");
+      item_ = make_item ("KeySignature", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
 
-      item_->set_grob_property ("c0-position",
-                               get_property ("centralCPosition"));
+      item_->set_property ("c0-position",
+                          get_property ("middleCPosition"));
       
-      // todo: put this in basic props.
-      item_->set_grob_property ("old-accidentals", get_property ("lastKeySignature"));
-      item_->set_grob_property ("new-accidentals", get_property ("keySignature"));
+      if (to_boolean (get_property ("printKeyCancellation")))
+       item_->set_property ("old-accidentals", get_property ("lastKeySignature"));
+      item_->set_property ("new-accidentals", get_property ("keySignature"));
 
-      announce_grob(item_, key_ev_ ? key_ev_->self_scm() : SCM_EOL);
     }
 
   if (!def)
     {
       SCM vis = get_property ("explicitKeySignatureVisibility"); 
-      if (gh_procedure_p (vis))
-       item_->set_grob_property ("break-visibility",vis);
+      if (ly_c_procedure_p (vis))
+       item_->set_property ("break-visibility",vis);
     }
 }      
 
@@ -88,7 +87,6 @@ Key_engraver::create_key (bool def)
 bool
 Key_engraver::try_music (Music * ev)
 {
-  //  if (Key_change_ev *kc = dynamic_cast <Key_change_ev *> (ev))
   if (ev->is_mus_type ("key-change-event"))
     {
       if (!key_ev_)
@@ -96,7 +94,7 @@ Key_engraver::try_music (Music * ev)
          /*
            do this only once, just to be on the safe side.
            */      
-         key_ev_ = dynamic_cast<Key_change_ev*> (ev); // UGH.
+         key_ev_ = ev;
          read_ev (key_ev_);
        }
       
@@ -118,7 +116,7 @@ Key_engraver::acknowledge_grob (Grob_info info)
        }
     }
   else if (Bar_line::has_interface (info.grob_)
-          && gh_pair_p (get_property ("keySignature")))
+          && ly_c_pair_p (get_property ("keySignature")))
     {
       create_key (true);
     }
@@ -137,40 +135,36 @@ Key_engraver::process_music ()
 void
 Key_engraver::stop_translation_timestep ()
 {
-  if (item_) 
-    {
-      typeset_grob (item_);
       item_ = 0;
-    }
 }
 
 
 void
-Key_engraver::read_ev (Key_change_ev const * r)
+Key_engraver::read_ev (Music const * r)
 {
-  SCM p = r->get_mus_property ("pitch-alist");
-  if (!gh_pair_p (p))
+  SCM p = r->get_property ("pitch-alist");
+  if (!ly_c_pair_p (p))
     return;
 
   SCM n = scm_list_copy (p);
   SCM accs = SCM_EOL;
   for (SCM s = get_property ("keyAccidentalOrder");
-       gh_pair_p (s); s = ly_cdr (s))
+       ly_c_pair_p (s); s = ly_cdr (s))
     {
-      if (gh_pair_p (scm_member (ly_car (s), n)))
+      if (ly_c_pair_p (scm_member (ly_car (s), n)))
        {
-         accs = gh_cons (ly_car (s), accs);
+         accs = scm_cons (ly_car (s), accs);
          n = scm_delete_x (ly_car (s), n);
        }
     }
   
-  for (SCM s = n ; gh_pair_p (s); s = ly_cdr (s))
-    if (gh_scm2int (ly_cdar (s)))
-      accs = gh_cons (ly_car (s), accs);
+  for (SCM s = n ; ly_c_pair_p (s); s = ly_cdr (s))
+    if (ly_scm2int (ly_cdar (s)))
+      accs = scm_cons (ly_car (s), accs);
 
-  daddy_trans_->set_property ("keySignature", accs);
-  daddy_trans_->set_property ("tonic" ,
-                             r->get_mus_property ("tonic"));
+  context ()->set_property ("keySignature", accs);
+  context ()->set_property ("tonic" ,
+                             r->get_property ("tonic"));
 }
 
 
@@ -178,26 +172,26 @@ void
 Key_engraver::start_translation_timestep ()
 {
   key_ev_ = 0;
-  daddy_trans_->set_property ("lastKeySignature", get_property ("keySignature"));
+  context ()->set_property ("lastKeySignature", get_property ("keySignature"));
 }
 
 
 void
 Key_engraver::initialize ()
 {
-  daddy_trans_->set_property ("keySignature", SCM_EOL);
-  daddy_trans_->set_property ("lastKeySignature", SCM_EOL);
+  context ()->set_property ("keySignature", SCM_EOL);
+  context ()->set_property ("lastKeySignature", SCM_EOL);
 
-  Pitch p(0,0,0);
-  daddy_trans_->set_property ("tonic", p.smobbed_copy ());
+  Pitch p (0,0,0);
+  context ()->set_property ("tonic", p.smobbed_copy ());
 
 }
 
 
-ENTER_DESCRIPTION(Key_engraver,
+ENTER_DESCRIPTION (Key_engraver,
 /* descr */       "",
 /* creats*/       "KeySignature",
 /* accepts */     "key-change-event",
 /* acks  */      "bar-line-interface clef-interface",
-/* reads */       "keySignature lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
+/* reads */       "keySignature printKeyCancellation lastKeySignature explicitKeySignatureVisibility createKeyOnClefChange keyAccidentalOrder keySignature",
 /* write */       "lastKeySignature tonic keySignature");