]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 4903/3: Restructure slur engravers
authorDavid Kastrup <dak@gnu.org>
Mon, 20 Jun 2016 18:37:46 +0000 (20:37 +0200)
committerDavid Kastrup <dak@gnu.org>
Fri, 24 Jun 2016 20:50:09 +0000 (22:50 +0200)
Replaces data members specific to derived classes of Slur_proto_engraver
with virtual functions.

lily/include/slur-proto-engraver.hh
lily/phrasing-slur-engraver.cc
lily/slur-engraver.cc
lily/slur-proto-engraver.cc

index 61aef237e4a64233884140c368bb404bc3f40035..af4cacf03073f42f49f163ebb816fb24bdf7ee04 100644 (file)
 class Slur_proto_engraver : public Engraver
 {
 protected:
-  Slur_proto_engraver (const char* double_property_name,
-    const char* grob_name, const char* object_name, const char* event_name) :
-      double_property_name_ (double_property_name),
-      grob_name_ (grob_name), object_name_ (object_name),
-      event_name_ (event_name) {}
-
   struct Event_info {
     Stream_event *slur_, *note_;
     Event_info (Stream_event *slur, Stream_event *note)
@@ -48,11 +42,11 @@ protected:
   vector<Grob *> slurs_;
   vector<Grob *> end_slurs_;
   vector<Grob_info> objects_to_acknowledge_;
-  const char* double_property_name_;
-  const char* grob_name_;
-  const char* object_name_;
-  const char* event_name_;
-  virtual SCM event_symbol () = 0;
+
+  virtual SCM event_symbol () const = 0;
+  virtual bool double_property () const = 0;
+  virtual SCM grob_symbol () const = 0;
+  virtual const char* object_name () const = 0;
 
   void acknowledge_inline_accidental (Grob_info);
   void acknowledge_fingering (Grob_info);
index a9ed7be853506ea9e1a12cd83495579e6488dbdf..70b6dc764b922de91e24e5a8c73d45ed227849ab 100644 (file)
 
 class Phrasing_slur_engraver : public Slur_proto_engraver
 {
+  virtual SCM event_symbol () const;
+  virtual bool double_property () const;
+  virtual SCM grob_symbol () const;
+  virtual const char* object_name () const;
+
 protected:
   void listen_phrasing_slur (Stream_event *);
   void acknowledge_slur (Grob_info);
 
 public:
-  SCM event_symbol ();
   TRANSLATOR_DECLARATIONS (Phrasing_slur_engraver);
   TRANSLATOR_INHERIT (Slur_proto_engraver);
 };
 
-Phrasing_slur_engraver::Phrasing_slur_engraver () :
-  Slur_proto_engraver (0, "PhrasingSlur", "phrasing slur", "phrasing-slur-event")
+SCM
+Phrasing_slur_engraver::event_symbol () const
 {
+  return ly_symbol2scm ("phrasing-slur-event");
+}
+
+bool
+Phrasing_slur_engraver::double_property () const
+{
+  return false;
 }
 
 SCM
-Phrasing_slur_engraver::event_symbol ()
+Phrasing_slur_engraver::grob_symbol () const
+{
+  return ly_symbol2scm ("PhrasingSlur");
+}
+
+const char *
+Phrasing_slur_engraver::object_name () const
+{
+  return "phrasing slur";
+}
+
+Phrasing_slur_engraver::Phrasing_slur_engraver ()
 {
-  // Need a string constant for memoization
-  return ly_symbol2scm ("phrasing-slur-event");
 }
 
 void
index 359ab78ef9c1a63bd27a712da9fb59a758d3eb0c..88495f4de2a1d5bc5e4ca808229f0bac7a838716 100644 (file)
 
 class Slur_engraver : public Slur_proto_engraver
 {
+  virtual SCM event_symbol () const;
+  virtual bool double_property () const;
+  virtual SCM grob_symbol () const;
+  virtual const char * object_name () const;
   virtual void set_melisma (bool);
 
 public:
-  SCM event_symbol ();
   TRANSLATOR_DECLARATIONS (Slur_engraver);
   TRANSLATOR_INHERIT (Slur_proto_engraver);
 };
 
-Slur_engraver::Slur_engraver () :
-  Slur_proto_engraver ("doubleSlurs", "Slur", "slur", "slur-event")
+SCM
+Slur_engraver::event_symbol () const
+{
+  return ly_symbol2scm ("slur-event");
+}
+
+bool
+Slur_engraver::double_property () const
 {
+  return to_boolean (get_property ("doubleSlurs"));
 }
 
 SCM
-Slur_engraver::event_symbol ()
+Slur_engraver::grob_symbol () const
+{
+  return ly_symbol2scm ("Slur");
+}
+
+const char *
+Slur_engraver::object_name () const
+{
+  return "slur";
+}
+
+Slur_engraver::Slur_engraver ()
 {
-  // Need a string constant for memoization
-  return ly_symbol2scm ("slur-event");
 }
 
 void
index 99e8e8ebfcd54fd87f8ac370466e01f0b45b82ad..6ba0df6b7cf95b14437deb1ddf5454677a4d95e6 100644 (file)
@@ -58,7 +58,8 @@ Slur_proto_engraver::listen_slur (Stream_event *ev, Stream_event *note)
   else if (d == STOP)
     stop_events_.push_back (Event_info (ev, note));
   else ev->origin ()->warning (_f ("direction of %s invalid: %d",
-                                     event_name_, int (d)));
+                                   ev->name ().c_str (),
+                                   int (d)));
 }
 
 void
@@ -156,7 +157,7 @@ Slur_proto_engraver::finalize ()
 {
   for (vsize i = 0; i < slurs_.size (); i++)
     {
-      slurs_[i]->warning (_f ("unterminated %s", object_name_));
+      slurs_[i]->warning (_f ("unterminated %s", object_name ()));
       slurs_[i]->suicide ();
     }
   slurs_.clear ();
@@ -169,7 +170,7 @@ Slur_proto_engraver::create_slur (const string &spanner_id, Event_info evi, Grob
     ? unsmob<Grob> (get_property ("currentCommandColumn"))
     : 0; // efficiency
   SCM cause = evi.slur_ ? evi.slur_->self_scm () : g_cause->self_scm ();
-  Spanner *slur = make_spanner (grob_name_, cause);
+  Spanner *slur = make_spanner (grob_symbol (), cause);
   slur->set_property ("spanner-id", ly_string2scm (spanner_id));
   if (dir)
     set_grob_direction (slur, dir);
@@ -179,11 +180,10 @@ Slur_proto_engraver::create_slur (const string &spanner_id, Event_info evi, Grob
   if (evi.note_)
     note_slurs_[START].insert (Note_slurs::value_type (evi.note_, slur));
 
-  if (double_property_name_
-      && to_boolean (get_property (double_property_name_)))
+  if (double_property ())
   {
     set_grob_direction (slur, DOWN);
-    slur = make_spanner (grob_name_, cause);
+    slur = make_spanner (grob_symbol (), cause);
     slur->set_property ("spanner-id", ly_string2scm (spanner_id));
     set_grob_direction (slur, UP);
     if (left_broken)
@@ -210,7 +210,7 @@ Slur_proto_engraver::can_create_slur (const string &id, vsize old_slurs, vsize *
             {
               // We already have an old slur, so give a warning
               // and completely ignore the new slur.
-              ev->origin ()->warning (_f ("already have %s", object_name_));
+              ev->origin ()->warning (_f ("already have %s", object_name ()));
               if (event_idx)
                 start_events_.erase (start_events_.begin () + (*event_idx));
               return false;
@@ -227,7 +227,7 @@ Slur_proto_engraver::can_create_slur (const string &id, vsize old_slurs, vsize *
 
           if (!c)
             {
-              slur->programming_error (_f ("%s without a cause", object_name_));
+              slur->programming_error (_f ("%s without a cause", object_name ()));
               return true;
             }
 
@@ -294,7 +294,7 @@ Slur_proto_engraver::process_music ()
             }
         }
       else
-        stop_events_[i].slur_->origin ()->warning (_f ("cannot end %s", object_name_));
+        stop_events_[i].slur_->origin ()->warning (_f ("cannot end %s", object_name ()));
     }
 
   vsize old_slurs = slurs_.size ();