]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dynamic-engraver.cc
* lily/include/translator.icc: new file.
[lilypond.git] / lily / dynamic-engraver.cc
index 9396c97f9a5498765a84f7019435a68328eca26d..97bafa4c00dd3e9b52926eb81876ebf8ebb1eae6 100644 (file)
@@ -19,6 +19,8 @@
 #include "side-position-interface.hh"
 #include "staff-symbol-referencer.hh"
 #include "warn.hh"
+#include "self-alignment-interface.hh"
+#include "pointer-group-interface.hh"
 
 /*
   TODO:
@@ -27,7 +29,7 @@
   line-spanner
 
   - TODO: this engraver is too complicated. We should split it into
-  the handling of the basic grobs and the  linespanner
+  the handling of the basic grobs and the linespanner
 
   - TODO: the line-spanner is not killed after the (de)crescs are
   finished.
@@ -61,11 +63,10 @@ protected:
   virtual void finalize ();
   virtual void acknowledge_grob (Grob_info);
   virtual bool try_music (Music *req);
-  virtual void stop_translation_timestep ();
-  virtual void process_music ();
+  PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
+  PRECOMPUTED_VIRTUAL void process_music ();
 };
 
-
 Dynamic_engraver::Dynamic_engraver ()
 {
   script_ = 0;
@@ -112,7 +113,7 @@ Dynamic_engraver::process_music ()
       if (!line_spanner_)
        {
          Music *rq = accepted_spanreqs_drul_[START];
-         line_spanner_ = make_spanner ("DynamicLineSpanner", rq ? rq->self_scm (): SCM_EOL);
+         line_spanner_ = make_spanner ("DynamicLineSpanner", rq ? rq->self_scm () : SCM_EOL);
 
          if (script_ev_)
            rq = script_ev_;
@@ -144,8 +145,8 @@ Dynamic_engraver::process_music ()
       Axis_group_interface::add_element (line_spanner_, script_);
     }
 
-  Music *stop_ev = accepted_spanreqs_drul_ [STOP] ?
-    accepted_spanreqs_drul_[STOP] : script_ev_;
+  Music *stop_ev = accepted_spanreqs_drul_ [STOP]
+    accepted_spanreqs_drul_[STOP] : script_ev_;
 
   if (accepted_spanreqs_drul_[STOP] || script_ev_)
     {
@@ -158,11 +159,12 @@ Dynamic_engraver::process_music ()
        {
          assert (!finished_cresc_ && cresc_);
 
-         cresc_->set_bound (RIGHT, script_
-                            ? script_
-                            : unsmob_grob (get_property ("currentMusicalColumn")));
-         add_bound_item (line_spanner_, cresc_->get_bound (RIGHT));
-
+         if (script_)
+           {
+             cresc_->set_bound (RIGHT, script_);
+             add_bound_item (line_spanner_, script_);
+           }
+         
          finished_cresc_ = cresc_;
          cresc_ = 0;
          current_cresc_ev_ = 0;
@@ -172,7 +174,6 @@ Dynamic_engraver::process_music ()
          accepted_spanreqs_drul_[STOP]->origin ()->warning (_ ("can't find start of (de)crescendo"));
          stop_ev = 0;
        }
-
     }
 
   if (accepted_spanreqs_drul_[START])
@@ -184,7 +185,7 @@ Dynamic_engraver::process_music ()
            msg = _ ("already have a crescendo");
 
          accepted_spanreqs_drul_[START]->origin ()->warning (msg);
-         current_cresc_ev_->origin ()->warning (_ ("Cresc started here"));
+         current_cresc_ev_->origin ()->warning (_ ("cresc starts here"));
        }
       else
        {
@@ -225,7 +226,6 @@ Dynamic_engraver::process_music ()
              cresc_->set_property ("grow-direction",
                                    scm_int2num ((start_type == "crescendo")
                                                 ? BIGGER : SMALLER));
-
            }
 
          /*
@@ -266,13 +266,14 @@ Dynamic_engraver::process_music ()
 void
 Dynamic_engraver::stop_translation_timestep ()
 {
-  typeset_all ();
-  if (!current_cresc_ev_)
+  if (!current_cresc_ev_ && line_spanner_)
     {
+      assert (!finished_line_spanner_);
       finished_line_spanner_ = line_spanner_;
       line_spanner_ = 0;
-      typeset_all ();
     }
+  
+  typeset_all ();
 
   if (cresc_ && !cresc_->get_bound (LEFT))
     {
@@ -370,33 +371,47 @@ Dynamic_engraver::acknowledge_grob (Grob_info info)
   if (!line_spanner_)
     return;
 
-  if (Note_column::has_interface (info.grob_))
+  if (Note_column::has_interface (info.grob ()))
     {
       if (line_spanner_
          /* Don't refill killed spanner */
          && line_spanner_->is_live ())
        {
-         Side_position_interface::add_support (line_spanner_, info.grob_);
-         add_bound_item (line_spanner_, dynamic_cast<Item *> (info.grob_));
+         Side_position_interface::add_support (line_spanner_, info.grob ());
+         add_bound_item (line_spanner_, dynamic_cast<Item *> (info.grob ()));
        }
 
       if (script_ && !script_->get_parent (X_AXIS))
        {
-         SCM head = scm_last_pair (info.grob_->get_property ("note-heads"));
-         if (scm_is_pair (head))
-           script_->set_parent (unsmob_grob (scm_car (head)), X_AXIS);
+         extract_grob_set (info.grob (), "note-heads", heads);
+         if (heads.size())
+           {
+             Grob *head = heads[0];
+             script_->set_parent (head, X_AXIS);
+             script_->add_offset_callback (Self_alignment_interface::centered_on_parent_proc,
+                                           X_AXIS);
+
+           }
        }
 
-      if (cresc_ && !cresc_->get_bound (LEFT))
+      if (cresc_)
        {
-         cresc_->set_bound (LEFT, info.grob_);
-         add_bound_item (line_spanner_, cresc_->get_bound (LEFT));
+         if (!cresc_->get_bound (LEFT))
+           {
+             cresc_->set_bound (LEFT, info.grob ());
+             add_bound_item (line_spanner_, cresc_->get_bound (LEFT));
+           }
        }
 
+      if (finished_cresc_ && !finished_cresc_->get_bound (RIGHT))
+       {
+         finished_cresc_->set_bound (RIGHT, info.grob ());
+       }
     }
-  else if (Script_interface::has_interface (info.grob_) && script_)
+  
+  else if (Script_interface::has_interface (info.grob ()) && script_)
     {
-      SCM p = info.grob_->get_property ("script-priority");
+      SCM p = info.grob ()->get_property ("script-priority");
 
       /*
        UGH.
@@ -406,10 +421,12 @@ Dynamic_engraver::acknowledge_grob (Grob_info info)
       if (scm_is_number (p)
          && scm_to_int (p)
          < scm_to_int (script_->get_property ("script-priority")))
-       Side_position_interface::add_support (line_spanner_, info.grob_);
+       Side_position_interface::add_support (line_spanner_, info.grob ());
     }
 }
 
+#include "translator.icc"
+
 ADD_TRANSLATOR (Dynamic_engraver,
                /* descr */
                "This engraver creates hairpins, dynamic texts, and their vertical\n"