]> git.donarmstrong.com Git - lilypond.git/commitdiff
only do staffline avoidance if we're inside the staff or inside the
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 12 Jan 2007 21:54:00 +0000 (22:54 +0100)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Fri, 12 Jan 2007 21:54:00 +0000 (22:54 +0100)
ledgers.

lily/include/misc.hh
lily/include/tie-formatting-problem.hh
lily/include/tie-specification.hh
lily/misc.cc
lily/tie-formatting-problem.cc
scm/define-grobs.scm

index d0bb6f417b3f4dcef37ed47e1c73c87415c7ebc8..fad61b1ad381e33ddbdc3f164f08b0757935d6f6 100644 (file)
@@ -38,7 +38,7 @@ linear_interpolate (Real x, Real x1, Real x2, Real y1, Real y2)
 Real directed_round (Real f, Direction d);
 
 Real peak_around (Real epsilon,  Real threshold, Real x);
-Real convex_amplifier (Real standard_x, Real x);
+Real convex_amplifier (Real standard_x, Real increase_factor, Real x);
 string camel_case_to_lisp_identifier (string in);
 
 #endif
index 863712e99e0656828279f52048ef0a25b88440db..ebee98877fd69b4c9f03686ff008fbb250028149 100644 (file)
@@ -30,11 +30,13 @@ struct Tie_configuration_variation
 
 typedef map < Tuple<int, 2>, Skyline> Chord_outline_map;
 typedef map < Tuple<int, 2>, Box> Column_extent_map;
+typedef map <int, Slice> Position_extent_map;
 class Tie_formatting_problem
 {
   Chord_outline_map chord_outlines_;
   Column_extent_map stem_extents_;
   Column_extent_map head_extents_;
+  Position_extent_map head_positions_;
   
   set<int> dot_positions_;
   Interval dot_x_;
@@ -60,6 +62,7 @@ class Tie_formatting_problem
   void set_ties_config_standard_directions (Ties_configuration *tie_configs_ptr);
   void score_ties (Ties_configuration *) const;
   
+  Slice head_positions_slice (int) const;
   Ties_configuration generate_base_chord_configuration ();
   Ties_configuration find_best_variation (Ties_configuration const &base,
                                          vector<Tie_configuration_variation> const &vars);
index 912dc78689522b5195752675efcfd2f2d6994a5d..0a437d312b1c046c8a8c0f42a6c83ba06eef3d97 100644 (file)
@@ -23,6 +23,7 @@ struct Tie_specification
   bool has_manual_position_;
   bool has_manual_dir_;
   bool has_manual_delta_y_;
+  bool has_accidental_;
   
   Real manual_position_;
   Direction manual_dir_;
index 8d10141524466326886bd64b41982c620b8a8d3b..6837df0d744838c4eff0978318902ff3d6324e6c 100644 (file)
@@ -60,9 +60,9 @@ peak_around (Real epsilon,  Real threshold, Real x)
   0 at 0,  1 at standard_x, and increasing thereafter. 
  */
 Real
-convex_amplifier (Real standard_x, Real x)
+convex_amplifier (Real standard_x, Real increase_factor, Real x)
 {
-  return (exp (x / standard_x) - 1.0) / (exp (1) - 1.0); 
+  return (exp (increase_factor * x / standard_x) - 1.0) / (exp (increase_factor) - 1.0); 
 }
 
 string
index 297fd4a1551ba33804939f6a770f6f7a4d2e6867..6c7e2a024f091d0f5af9adae860c0a790b1cb80c 100644 (file)
@@ -168,24 +168,25 @@ Tie_formatting_problem::set_column_chord_outline (vector<Item*> bounds,
       extract_grob_set (stem, "note-heads", heads);
       for (vsize i = 0; i < heads.size(); i ++)
        {
-         if (find (bounds.begin(), bounds.end (), dynamic_cast<Item*> (heads[i])) !=  bounds.end ())
-           continue;
-
-         /*
-           other untied notes in the same chord.
-          */
+         if (find (bounds.begin(), bounds.end (), dynamic_cast<Item*> (heads[i])) ==  bounds.end ())
+           {
+             /*
+               other untied notes in the same chord.
+             */
          
-         Interval y = Staff_symbol_referencer::extent_in_staff (heads[i]);
-         Interval x = heads[i]->extent (x_refpoint_, X_AXIS);
-         boxes.push_back (Box (x, y));
-
+             Interval y = Staff_symbol_referencer::extent_in_staff (heads[i]);
+             Interval x = heads[i]->extent (x_refpoint_, X_AXIS);
+             boxes.push_back (Box (x, y));
+           }
          
          Grob *acc = unsmob_grob (heads[i]->get_object ("accidental-grob"));
-         if (acc && dir == RIGHT)
+         if (acc && acc->is_live () && dir == RIGHT)
            {
              boxes.push_back (Box (acc->extent (x_refpoint_, X_AXIS),
                                    Staff_symbol_referencer::extent_in_staff (acc)));
            }
+
+         head_positions_[column_rank].add_point (int (Staff_symbol_referencer::get_position (heads[i])));
        }
       
     }
@@ -458,37 +459,41 @@ Tie_formatting_problem::generate_configuration (int pos, Direction dir,
        size.
        
        */
-      if (h < details_.intra_space_threshold_ * 0.5 * details_.staff_space_)
+      if (head_positions_slice (columns[LEFT]).contains (pos)
+         || head_positions_slice (columns[RIGHT]).contains (pos)
+         || abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_))
        {
-         if (!Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos)
-             && abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_))
+         if (h < details_.intra_space_threshold_ * 0.5 * details_.staff_space_)
            {
-             conf->center_tie_vertically (details_);
-           }
-         else if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos))
-           {
-             conf->delta_y_ += dir *
-               details_.tip_staff_line_clearance_ * 0.5 *  details_.staff_space_;
+             if (!Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos)
+                 && abs (pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_))
+               {
+                 conf->center_tie_vertically (details_);
+               }
+             else if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, pos))
+               {
+                 conf->delta_y_ += dir *
+                   details_.tip_staff_line_clearance_ * 0.5 *  details_.staff_space_;
+               }
            }
-       }
-      else 
-       {
-         Real top_y = y + conf->delta_y_ + conf->dir_ * h;
-         Real top_pos = top_y / (0.5*details_.staff_space_);
-         int round_pos = int (my_round (top_pos));
-
-         /* TODO: should use other variable? */
-         Real clearance = details_.center_staff_line_clearance_;
-         if (fabs (top_pos - round_pos) < clearance
-             && Staff_symbol_referencer::on_staff_line (details_.staff_symbol_referencer_,
-                                                        round_pos))
+         else 
            {
-             Real new_y = (round_pos + clearance * conf->dir_) * 0.5 * details_.staff_space_;
-             conf->delta_y_ = (new_y - top_y);
+             Real top_y = y + conf->delta_y_ + conf->dir_ * h;
+             Real top_pos = top_y / (0.5*details_.staff_space_);
+             int round_pos = int (my_round (top_pos));
+
+             /* TODO: should use other variable? */
+             Real clearance = details_.center_staff_line_clearance_;
+             if (fabs (top_pos - round_pos) < clearance
+                 && Staff_symbol_referencer::on_staff_line (details_.staff_symbol_referencer_,
+                                                            round_pos))
+               {
+                 Real new_y = (round_pos + clearance * conf->dir_) * 0.5 * details_.staff_space_;
+                 conf->delta_y_ = (new_y - top_y);
+               }
            }
        }
-    }
-  
+    }  
   conf->attachment_x_ = get_attachment (y + conf->delta_y_, conf->column_ranks_);
   if (conf->height (details_) < details_.intra_space_threshold_ * 0.5 * details_.staff_space_)
     {
@@ -574,7 +579,8 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
     }
 
   {
-    Real p = details_.vertical_distance_penalty_factor_ * convex_amplifier (1.0, fabs (curve_y - tie_y));
+    Real relevant_dist = max (fabs (curve_y - tie_y) - 0.5, 0.0);
+    Real p = details_.vertical_distance_penalty_factor_ * convex_amplifier (1.0, 0.9, relevant_dist);
     if (ties_conf)
       ties_conf->add_tie_score (p, tie_idx, "vdist");
     else
@@ -595,7 +601,7 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
        TODO: flatten with log or sqrt.
        */
       Real p = details_.horizontal_distance_penalty_factor_
-       * convex_amplifier (1.25, dist);
+       * convex_amplifier (1.25, 1.0, dist);
       if (ties_conf)
        ties_conf->add_tie_score (p, tie_idx,
                                  (d == LEFT) ? "lhdist" : "rhdist");
@@ -646,6 +652,18 @@ Tie_formatting_problem::score_aptitude (Tie_configuration *conf,
 }
 
 
+Slice
+Tie_formatting_problem::head_positions_slice (int rank) const
+{
+  Position_extent_map::const_iterator i (head_positions_.find (rank));
+  if (i != head_positions_.end ())
+    {
+      return  (*i).second; 
+    }
+  Slice empty;
+  return empty;
+}
+
 /*
   Score a configuration, ie. how well these ties looks without regard
   to the note heads that they should connect to.
@@ -682,9 +700,13 @@ Tie_formatting_problem::score_configuration (Tie_configuration *conf) const
                       fabs (top_pos - round_top_pos)),
        "line center");
     }
-  
-  if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_,
-                                       int (rint (tip_pos))))
+
+  int rounded_tip_pos = int (rint (tip_pos));
+  if (Staff_symbol_referencer::on_line (details_.staff_symbol_referencer_, rounded_tip_pos)
+      && (head_positions_slice (conf->column_ranks_[LEFT]).contains (rounded_tip_pos)
+         || head_positions_slice (conf->column_ranks_[RIGHT]).contains (rounded_tip_pos)
+         || abs (rounded_tip_pos) < 2 * Staff_symbol_referencer::staff_radius (details_.staff_symbol_referencer_))
+         )
     {
       conf->add_score (details_.staff_line_collision_penalty_
                       * peak_around (0.1 * details_.tip_staff_line_clearance_,
index 9acbe3beafcd652649b7db7648ef2ec662bcdee2..2130dab4be14fe07b8a65170eec4be5f7316ac56 100644 (file)
                    (height-limit . 1.0)
                    (horizontal-distance-penalty-factor . 10)
                    (same-dir-as-stem-penalty . 8)
-                   (min-length-penalty-factor . 20)
+                   (min-length-penalty-factor . 26)
                    (tie-tie-collision-distance . 0.45) 
                    (tie-tie-collision-penalty . 25.0)
                    (intra-space-threshold . 1.25)