From 56af2a2f7956a0c1aca65f96f73320415c3d3854 Mon Sep 17 00:00:00 2001
From: Carl Sorensen <carl.d.sorensen@gmail.com>
Date: Sun, 18 Sep 2016 15:50:32 -0600
Subject: [PATCH] Change the algorithm for placing dots next to chords.

---
 lily/dot-column.cc                | 12 +++++++-----
 lily/dot-configuration.cc         | 21 ++++++++++++++++++++-
 lily/dot-formatting-problem.cc    |  2 ++
 lily/include/dot-configuration.hh |  8 +++++++-
 4 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/lily/dot-column.cc b/lily/dot-column.cc
index 7ac3140..d7d352a 100644
--- a/lily/dot-column.cc
+++ b/lily/dot-column.cc
@@ -172,11 +172,11 @@ Dot_column::calc_positioning_done (SCM smob)
                             + scm_to_int (chord_dots_limit)) / 2;
           int total_dots = dots_each_stem[j].size ();
           // remove excessive dots from the ends of the stem
-          for (int first_dot = 0; total_dots > total_room; total_dots--)
-            if (0 == (total_dots - total_room) % 2)
-              dots_each_stem[j][first_dot++]->suicide ();
-            else
-              dots_each_stem[j][first_dot + total_dots - 1]->suicide ();
+//          for (int first_dot = 0; total_dots > total_room; total_dots--)
+//            if (0 == (total_dots - total_room) % 2)
+//              dots_each_stem[j][first_dot++]->suicide ();
+//            else
+//              dots_each_stem[j][first_dot + total_dots - 1]->suicide ();
         }
     }
 
@@ -223,6 +223,8 @@ Dot_column::calc_positioning_done (SCM smob)
 
   problem.register_configuration (cfg);
 
+  cfg.suicide_excess_dots (scm_to_int (chord_dots_limit));
+
   for (Dot_configuration::const_iterator i (cfg.begin ());
        i != cfg.end (); i++)
     {
diff --git a/lily/dot-configuration.cc b/lily/dot-configuration.cc
index 25d35eb..3a86699 100644
--- a/lily/dot-configuration.cc
+++ b/lily/dot-configuration.cc
@@ -20,6 +20,7 @@
 #include <cstdio>
 #include "dot-configuration.hh"
 #include "dot-formatting-problem.hh"
+#include "grob.hh"
 #include "staff-symbol-referencer.hh"
 
 int
@@ -51,7 +52,7 @@ Dot_configuration::print () const
   printf ("dotconf { ");
   for (Dot_configuration::const_iterator i (begin ());
        i != end (); i++)
-    printf ("%d, ", i->first);
+    printf ("[%d, %d, %d], ", i->first, i->second.pos_, i->second.dir_);
   printf ("}\n");
 }
 
@@ -147,6 +148,24 @@ Dot_configuration::remove_collision (int p)
     }
 }
 
+/*
+  Suicide any dots that are farther than shift_limit from the
+  notehead staff position
+*/
+
+void
+Dot_configuration::suicide_excess_dots (int shift_limit)
+{
+  for (Dot_configuration::const_iterator i (begin ());
+       i != end (); i++)
+     if (abs(i->first - i->second.pos_) > shift_limit)
+     {
+       Grob *d = i->second.dot_;
+       d->suicide ();
+     }
+}
+
+
 Dot_configuration::Dot_configuration (Dot_formatting_problem const &problem)
 {
   problem_ = &problem;
diff --git a/lily/dot-formatting-problem.cc b/lily/dot-formatting-problem.cc
index 221ab58..99777f4 100644
--- a/lily/dot-formatting-problem.cc
+++ b/lily/dot-formatting-problem.cc
@@ -30,6 +30,8 @@ void
 Dot_formatting_problem::register_configuration (Dot_configuration const &src)
 {
   int b = src.badness ();
+  printf ("In register_configuration\n");
+  src.print ();
   if (b < score_)
     {
       delete best_;
diff --git a/lily/include/dot-configuration.hh b/lily/include/dot-configuration.hh
index b4e2219..ef5f897 100644
--- a/lily/include/dot-configuration.hh
+++ b/lily/include/dot-configuration.hh
@@ -28,7 +28,7 @@
 
 struct Dot_position
 {
-  int pos_;
+  int pos_;      // staff position of dot
   Direction dir_;
   Grob *dot_;
   Box dot_extents_;
@@ -42,6 +42,11 @@ struct Dot_position
   }
 };
 
+
+// The int used for the key in the Dot_configuration map
+// is the staff position of the notehead that caused
+// the dot.
+
 struct Dot_configuration : public map<int, Dot_position>
 {
   Dot_formatting_problem const *problem_;
@@ -52,6 +57,7 @@ struct Dot_configuration : public map<int, Dot_position>
   void print () const;
   Dot_configuration shifted (int k, Direction d) const;
   void remove_collision (int p);
+  void suicide_excess_dots (int shift_limit);
 };
 
 #endif
-- 
2.1.4

