]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/tie-formatting-problem.cc
Housekeeping; 2005->2006, remove "notes for 2.6"
[lilypond.git] / lily / tie-formatting-problem.cc
index f1fc92244123ee8c64f8e00dbf32f8c9caa69b1e..439e76cf5069ea5023c0ca5c96b354114876fc2e 100644 (file)
@@ -13,6 +13,7 @@
 #include "directional-element-interface.hh"
 #include "item.hh"
 #include "libc-extension.hh"
+#include "misc.hh"
 #include "note-head.hh"
 #include "rhythmic-head.hh"
 #include "spanner.hh" 
 #include "tie.hh"
 #include "warn.hh"
 
-/*
-   0 at threshold,  1 at 0, with 1/x falloff.
- */
-Real peak_around (Real epsilon,  Real threshold, Real x)
-{
-  if (x < 0)
-    return 1.0;
-  return max (- epsilon * (x - threshold) / ((x + epsilon)  * threshold), 0.0);
-}
 
 void
 Tie_formatting_problem::print_ties_configuration (Ties_configuration const *ties)
@@ -121,7 +113,17 @@ Tie_formatting_problem::set_chord_outline (vector<Item*> bounds,
       Real x = robust_relative_extent (bounds[0],  x_refpoint_, X_AXIS)[-dir];
       chord_outlines_[dir].at (0).height_ = x; 
     }
-         
+  else
+    {
+      Interval x;      
+      for (vsize i = 0; i < head_boxes.size (); i++)
+       {
+         x.unite (head_boxes[i][X_AXIS]);
+       }
+
+      chord_outlines_[dir].at (0).height_ = x[dir];
+    }
+
   for (vsize i = 0; i < boxes.size (); i++)
     insert_extent_into_skyline (&chord_outlines_[dir]  ,
                                boxes[i], Y_AXIS, -dir);
@@ -240,7 +242,13 @@ Tie_formatting_problem::from_ties (vector<Grob*> const &ties)
        }
          
       spec.position_ = Tie::get_position (ties[i]);
-
+      if (scm_is_number (ties[i]->get_property ("staff-position")))
+       {
+         spec.manual_position_ = scm_to_double (ties[i]->get_property ("staff-position"));
+         spec.has_manual_position_ = true;
+         spec.position_ = int (my_round (spec.manual_position_));
+       }
+      
       do
        {
          spec.note_head_drul_[d] = Tie::head (ties[i], d);
@@ -252,7 +260,7 @@ Tie_formatting_problem::from_ties (vector<Grob*> const &ties)
 }
 
 void
-Tie_formatting_problem::from_lv_ties (vector<Grob*> const &lv_ties)
+Tie_formatting_problem::from_semi_ties (vector<Grob*> const &lv_ties, Direction head_dir)
 {
   if (lv_ties.empty ())
     return;
@@ -273,7 +281,7 @@ Tie_formatting_problem::from_lv_ties (vector<Grob*> const &lv_ties)
          spec.position_ = int (Staff_symbol_referencer::get_position (head));
        }
 
-      spec.note_head_drul_[LEFT] = head;
+      spec.note_head_drul_[head_dir] = head;
       heads.push_back (head);
       specifications_.push_back (spec);
     }
@@ -284,20 +292,21 @@ Tie_formatting_problem::from_lv_ties (vector<Grob*> const &lv_ties)
   for (vsize i = 0; i < heads.size (); i++)
     x_refpoint_ = heads[i]->common_refpoint (x_refpoint_, X_AXIS); 
 
-  set_chord_outline (heads, LEFT);
+  set_chord_outline (heads, head_dir);
 
-  Real right_most = - infinity_f;   
+  Real extremal = head_dir * infinity_f;   
 
-  for (vsize i = 0; i < chord_outlines_[LEFT].size (); i++)
+  for (vsize i = 0; i < chord_outlines_[head_dir].size (); i++)
     {
-      right_most = max (right_most, chord_outlines_[LEFT][i].height_);
+      extremal = head_dir * min (head_dir * extremal,
+                                  head_dir * chord_outlines_[head_dir][i].height_);
     }
 
   Skyline_entry right_entry;
   right_entry.width_.set_full ();
-  right_entry.height_ = right_most + 1.5;
+  right_entry.height_ = extremal - head_dir * 1.5;
   
-  chord_outlines_[RIGHT].push_back (right_entry);
+  chord_outlines_[-head_dir].push_back (right_entry);
 }
 
 
@@ -337,7 +346,7 @@ Tie_formatting_problem::generate_configuration (int pos, Direction dir) const
   bool y_tune = true;
   if (dot_positions_.find (pos) != dot_positions_.end ())
     {
-      conf->delta_y_ += 0.25 * details_.staff_space_;
+      conf->delta_y_ += dir * 0.25 * details_.staff_space_;
       y_tune = false;
     }
                
@@ -563,6 +572,15 @@ Tie_formatting_problem::find_optimal_tie_configuration (Tie_specification const
   for (int i = 0; i < details_.single_tie_region_size_; i ++)
     {
       confs.push_back (generate_configuration (pos + i * dir, dir));
+      
+      if (spec.has_manual_position_)
+       {
+         confs.back ()->delta_y_
+           = (spec.manual_position_ - spec.position_)
+           * 0.5 * details_.staff_space_;
+
+         break;
+       }
     }
 
   vector<Real> scores;