]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/key-engraver.cc
* lily/lyric-engraver.cc (get_current_rest): New function.
[lilypond.git] / lily / key-engraver.cc
index a13b4315a6d869cf6b902c677f199cfd1cc80d9f..3c9283b887b539066a0ac65c4ef4a93e96e6cea4 100644 (file)
@@ -29,9 +29,10 @@ class Key_engraver : public Engraver
 {
   void create_key (bool);
   void read_ev (Music const * r);
-  Music * key_ev_;
-  Item * item_;
 
+  Music *key_ev_;
+  Item *item_;
+  Item *cancellation_;
 public:
   TRANSLATOR_DECLARATIONS (Key_engraver);
 
@@ -56,6 +57,7 @@ Key_engraver::Key_engraver ()
 {
   key_ev_ = 0;
   item_ = 0;
+  cancellation_ = 0;
 }
 
 
@@ -64,16 +66,23 @@ 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_property ("c0-position",
                           get_property ("middleCPosition"));
-      
-      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);
+      SCM last = get_property ("lastKeySignature");
+      SCM key = get_property ("keySignature");
+      if (to_boolean (get_property ("printKeyCancellation"))
+         && !scm_is_eq (last, key))
+       {
+         cancellation_ = make_item ("KeyCancellation", key_ev_ ? key_ev_->self_scm () : SCM_EOL);
+         cancellation_->set_property ("old-accidentals",last);
+         cancellation_->set_property ("c0-position",
+                          get_property ("middleCPosition"));
+      
+       }
+      item_->set_property ("new-accidentals", key);
     }
 
   if (!def)
@@ -90,15 +99,12 @@ Key_engraver::try_music (Music * ev)
 {
   if (ev->is_mus_type ("key-change-event"))
     {
+      /* do this only once, just to be on the safe side.  */
       if (!key_ev_)
        {
-         /*
-           do this only once, just to be on the safe side.
-           */      
          key_ev_ = ev;
          read_ev (key_ev_);
        }
-      
       return true;
     }   
   return  false;
@@ -136,11 +142,9 @@ Key_engraver::process_music ()
 void
 Key_engraver::stop_translation_timestep ()
 {
-  if (item_) 
-    {
-      typeset_grob (item_);
-      item_ = 0;
-    }
+  item_ = 0;
+  context ()->set_property ("lastKeySignature", get_property ("keySignature"));
+  cancellation_ = 0; 
 }
 
 
@@ -164,12 +168,12 @@ Key_engraver::read_ev (Music const * r)
     }
   
   for (SCM s = n ; ly_c_pair_p (s); s = ly_cdr (s))
-    if (ly_scm2int (ly_cdar (s)))
+    if (scm_to_int (ly_cdar (s)))
       accs = scm_cons (ly_car (s), accs);
 
   context ()->set_property ("keySignature", accs);
   context ()->set_property ("tonic" ,
-                             r->get_property ("tonic"));
+                           r->get_property ("tonic"));
 }
 
 
@@ -177,7 +181,6 @@ void
 Key_engraver::start_translation_timestep ()
 {
   key_ev_ = 0;
-  context ()->set_property ("lastKeySignature", get_property ("keySignature"));
 }