lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Remove routing information from Grob_info


From: David Kastrup
Subject: [PATCH] Remove routing information from Grob_info
Date: Mon, 25 Apr 2016 17:24:01 +0200

It passes information to acknowledgers that does not really belong there and 
instead
manages how information gets there.  Moving this information into arguments for
the various kinds of announce_grob procedure is cleaner and allows to bounce
Grob_info through Scheme without the danger of information loss.
---
 lily/auto-beam-engraver.cc     |  6 ++----
 lily/engraver-group.cc         | 17 +++++++----------
 lily/engraver.cc               |  9 ++++-----
 lily/grob-info.cc              |  4 ----
 lily/include/engraver-group.hh | 15 +++++++++++++--
 lily/include/engraver.hh       |  4 ++--
 lily/include/grob-info.hh      | 17 +++--------------
 lily/include/score-engraver.hh |  2 +-
 lily/score-engraver.cc         |  6 +++---
 lily/span-bar-stub-engraver.cc |  3 +--
 10 files changed, 36 insertions(+), 47 deletions(-)

diff --git a/lily/auto-beam-engraver.cc b/lily/auto-beam-engraver.cc
index 7500ec9..3787257 100644
--- a/lily/auto-beam-engraver.cc
+++ b/lily/auto-beam-engraver.cc
@@ -223,8 +223,7 @@ Auto_beam_engraver::create_beam ()
     Beam::add_stem (beam, (*stems_)[i]);
 
   Grob_info i = make_grob_info (beam, (*stems_)[0]->self_scm ());
-  i.rerouting_daddy_context_ = beam_start_context_.get_context ();
-  announce_grob (i);
+  announce_grob (i, beam_start_context_.get_context ());
 
   return beam;
 }
@@ -283,9 +282,8 @@ Auto_beam_engraver::end_beam ()
       if (finished_beam_)
         {
           Grob_info i = make_grob_info (finished_beam_, SCM_EOL);
-          i.rerouting_daddy_context_ = beam_start_context_.get_context ();
 
-          announce_end_grob (i);
+          announce_end_grob (i, beam_start_context_.get_context ());
           finished_grouping_ = grouping_;
           finished_beaming_options_ = beaming_options_;
         }
diff --git a/lily/engraver-group.cc b/lily/engraver-group.cc
index cf1832f..35c14d4 100644
--- a/lily/engraver-group.cc
+++ b/lily/engraver-group.cc
@@ -92,16 +92,13 @@ Engraver_group::disconnect_from_context ()
 }
 
 void
-Engraver_group::announce_grob (Grob_info info)
+Engraver_group::announce_grob (Grob_info info, Direction dir,
+                               Context *reroute_context)
 {
-  announce_infos_.push_back (info);
+  announce_infos_.push_back (Announce_grob_info (info, dir));
 
-  Context *dad_con = context_->get_parent_context ();
-  if (info.rerouting_daddy_context_)
-    {
-      dad_con = info.rerouting_daddy_context_;
-      info.rerouting_daddy_context_ = 0;
-    }
+  Context *dad_con = reroute_context ? reroute_context
+    : context_->get_parent_context ();
 
   Engraver_group *dad_eng
     = dad_con
@@ -109,7 +106,7 @@ Engraver_group::announce_grob (Grob_info info)
       : 0;
 
   if (dad_eng)
-    dad_eng->announce_grob (info);
+    dad_eng->announce_grob (info, dir);
 }
 
 void
@@ -122,7 +119,7 @@ Engraver_group::acknowledge_grobs ()
 
   for (vsize j = 0; j < announce_infos_.size (); j++)
     {
-      Grob_info info = announce_infos_[j];
+      Announce_grob_info info = announce_infos_[j];
 
       SCM meta = info.grob ()->get_property ("meta");
       SCM nm = scm_assoc (name_sym, meta);
diff --git a/lily/engraver.cc b/lily/engraver.cc
index 7891a1b..25ae579 100644
--- a/lily/engraver.cc
+++ b/lily/engraver.cc
@@ -36,16 +36,15 @@ Engraver::get_daddy_engraver () const
 }
 
 void
-Engraver::announce_grob (Grob_info inf)
+Engraver::announce_grob (Grob_info inf, Context *reroute_context)
 {
-  get_daddy_engraver ()->announce_grob (inf);
+  get_daddy_engraver ()->announce_grob (inf, START, reroute_context);
 }
 
 void
-Engraver::announce_end_grob (Grob_info inf)
+Engraver::announce_end_grob (Grob_info inf, Context *reroute_context)
 {
-  inf.start_end_ = STOP;
-  get_daddy_engraver ()->announce_grob (inf);
+  get_daddy_engraver ()->announce_grob (inf, STOP, reroute_context);
 }
 
 Grob_info
diff --git a/lily/grob-info.cc b/lily/grob-info.cc
index ef99141..aab0d3c 100644
--- a/lily/grob-info.cc
+++ b/lily/grob-info.cc
@@ -29,8 +29,6 @@ Grob_info::Grob_info (Translator *t, Grob *g)
 {
   origin_trans_ = t;
   grob_ = g;
-  start_end_ = START;
-  rerouting_daddy_context_ = 0;
 
   /*
     assert here, because this is easier to debug.
@@ -41,9 +39,7 @@ Grob_info::Grob_info (Translator *t, Grob *g)
 Grob_info::Grob_info ()
 {
   grob_ = 0;
-  start_end_ = START;
   origin_trans_ = 0;
-  rerouting_daddy_context_ = 0;
 }
 
 Stream_event *
diff --git a/lily/include/engraver-group.hh b/lily/include/engraver-group.hh
index aa3cd47..39e52f3 100644
--- a/lily/include/engraver-group.hh
+++ b/lily/include/engraver-group.hh
@@ -23,10 +23,20 @@
 #include "engraver.hh"
 #include "translator-group.hh"
 
+class Announce_grob_info : public Grob_info
+{
+  Direction start_end_;
+public:
+  Announce_grob_info (Grob_info gi, Direction start_end)
+    : Grob_info (gi), start_end_ (start_end)
+  { }
+  Direction start_end () const { return start_end_; }
+};
+
 class Engraver_group : public Translator_group
 {
 protected:
-  vector<Grob_info> announce_infos_;
+  vector<Announce_grob_info> announce_infos_;
   Drul_array<SCM> acknowledge_hash_table_drul_;
   void override (SCM);
   void revert (SCM);
@@ -37,7 +47,8 @@ public:
   void do_announces ();
   virtual void connect_to_context (Context *c);
   virtual void disconnect_from_context ();
-  virtual void announce_grob (Grob_info);
+  virtual void announce_grob (Grob_info, Direction start_end,
+                              Context *reroute_context = 0);
   bool pending_grobs () const;
 private:
   virtual void acknowledge_grobs ();
diff --git a/lily/include/engraver.hh b/lily/include/engraver.hh
index 70e168d..956f493 100644
--- a/lily/include/engraver.hh
+++ b/lily/include/engraver.hh
@@ -41,8 +41,8 @@ protected:
     Default: ignore the info
   */
   virtual void acknowledge_grob (Grob_info) {}
-  virtual void announce_grob (Grob_info);
-  virtual void announce_end_grob (Grob_info);
+  virtual void announce_grob (Grob_info, Context *reroute_context = 0);
+  virtual void announce_end_grob (Grob_info, Context *reroute_context = 0);
   Engraver_group *get_daddy_engraver () const;
 
 public:
diff --git a/lily/include/grob-info.hh b/lily/include/grob-info.hh
index 1df88ce..6d41837 100644
--- a/lily/include/grob-info.hh
+++ b/lily/include/grob-info.hh
@@ -17,8 +17,8 @@
   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#ifndef STAFFELEMINFO_HH
-#define STAFFELEMINFO_HH
+#ifndef GROB_INFO_HH
+#define GROB_INFO_HH
 
 #include "lily-guile.hh"
 #include "lily-proto.hh"
@@ -31,11 +31,8 @@ class Grob_info
 {
   Translator *origin_trans_;
   Grob *grob_;
-  Direction start_end_;
 
-  friend class Engraver;
 public:
-  Direction start_end () const { return start_end_; }
   Grob *grob () const { return grob_; }
   Translator *origin_translator () const { return origin_trans_; }
 
@@ -49,14 +46,6 @@ public:
   Item *item () const;
   Spanner *spanner () const;
   static bool less (Grob_info i, Grob_info j);
-
-  /*
-    For contexts that change staves, it may be desirable to emit a
-    grob into a staff other than the current one.  If this is non-null,
-    this grob should be announced in this context instead of the
-    daddy_context_.
-  */
-  Context *rerouting_daddy_context_;
 };
 
-#endif // STAFFELEMINFO_HH
+#endif // GROB_INFO_HH
diff --git a/lily/include/score-engraver.hh b/lily/include/score-engraver.hh
index 9b7927d..d0ec782 100644
--- a/lily/include/score-engraver.hh
+++ b/lily/include/score-engraver.hh
@@ -41,7 +41,7 @@ protected:
   virtual void disconnect_from_context ();
   virtual void initialize ();
   virtual void finalize ();
-  virtual void announce_grob (Grob_info);
+  virtual void announce_grob (Grob_info, Direction dir, Context 
*reroute_context = 0);
   void stop_translation_timestep ();
 
   /*
diff --git a/lily/score-engraver.cc b/lily/score-engraver.cc
index 0415d5e..06efa7f 100644
--- a/lily/score-engraver.cc
+++ b/lily/score-engraver.cc
@@ -155,10 +155,10 @@ Score_engraver::one_time_step (SCM)
 }
 
 void
-Score_engraver::announce_grob (Grob_info info)
+Score_engraver::announce_grob (Grob_info info, Direction start_end, Context 
*reroute_context)
 {
-  Engraver_group::announce_grob (info);
-  if (info.start_end () == START)
+  Engraver_group::announce_grob (info, START, reroute_context);
+  if (start_end == START)
     {
       pscore_->root_system ()->typeset_grob (info.grob ());
       elems_.push_back (info.grob ());
diff --git a/lily/span-bar-stub-engraver.cc b/lily/span-bar-stub-engraver.cc
index 3517c3f..3045643 100644
--- a/lily/span-bar-stub-engraver.cc
+++ b/lily/span-bar-stub-engraver.cc
@@ -148,8 +148,7 @@ Span_bar_stub_engraver::process_acknowledged ()
           Item *it = new Item (Grob_property_info (affected_contexts[j], 
ly_symbol2scm ("SpanBarStub")).updated ());
           it->set_parent (spanbars_[i], X_AXIS);
           Grob_info gi = make_grob_info (it, spanbars_[i]->self_scm ());
-          gi.rerouting_daddy_context_ = affected_contexts[j];
-          announce_grob (gi);
+          announce_grob (gi, affected_contexts[j]);
           if (!keep_extent[j])
             it->suicide ();
         }
-- 
2.7.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]