]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/simple-spacer.cc
* lily/ambitus-engraver.cc (create_ambitus): change name to
[lilypond.git] / lily / simple-spacer.cc
index dceebef282f85c7e54ba3da9585340894f58fde2..8aab99bc4fa19410f4cd280b988055f8baa81fc2 100644 (file)
@@ -3,7 +3,7 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 1999--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
   TODO:
   - add support for different stretch/shrink constants?
@@ -122,7 +122,7 @@ Simple_spacer::range_stiffness (int l, int r) const
   Real den =0.0;
   for (int i=l; i < r; i++)
     {
-      if (springs_[i].active_b_)
+      if (springs_[i].is_active_)
        den += 1 / springs_[i].hooke_;
     }
 
@@ -130,11 +130,11 @@ Simple_spacer::range_stiffness (int l, int r) const
 }
 
 Real
-Simple_spacer::active_blocking_force () const
+Simple_spacer::is_activelocking_force () const
 {
   Real bf = - infinity_f; 
   for (int i=0; i < springs_.size (); i++)
-    if (springs_[i].active_b_)
+    if (springs_[i].is_active_)
       {
        bf = bf >? springs_[i].block_force_;
       }
@@ -144,7 +144,7 @@ Simple_spacer::active_blocking_force () const
 Real
 Simple_spacer::active_springs_stiffness () const
 {
-  range_stiffness (0, springs_.size ());
+  return range_stiffness (0, springs_.size ());
 }
 
 void
@@ -152,10 +152,10 @@ Simple_spacer::set_active_states ()
 {
   /* float comparison is safe, since force is only copied.  */
   for (int i=0 ; i <springs_.size (); i++)
-    if (springs_[i].active_b_
+    if (springs_[i].is_active_
        && springs_[i].block_force_ >= force_)
       {
-       springs_[i].active_b_ = false;
+       springs_[i].is_active_ = false;
        active_count_ --; 
       }
 }   
@@ -171,7 +171,7 @@ Simple_spacer::configuration_length () const
 }
 
 bool
-Simple_spacer::active_b () const
+Simple_spacer::is_active () const
 {
   return active_count_; 
 }
@@ -179,9 +179,9 @@ Simple_spacer::active_b () const
 void
 Simple_spacer::my_solve_linelen ()
 {
-  while (active_b ())
+  while (is_active ())
     {
-      force_ = active_blocking_force ();
+      force_ = is_activelocking_force ();
       Real conf = configuration_length ();
 
       if (conf < line_len_)
@@ -198,9 +198,9 @@ Simple_spacer::my_solve_linelen ()
 void
 Simple_spacer::my_solve_natural_len ()
 {
-  while (active_b ())
+  while (is_active ())
     {
-      force_ = active_blocking_force () >? 0.0;
+      force_ = is_activelocking_force () >? 0.0;
 
       if (force_ < 1e-8) // ugh.,
        break;
@@ -212,10 +212,10 @@ Simple_spacer::my_solve_natural_len ()
 void
 Simple_spacer::add_columns (Link_array<Grob> const &icols)
 {
-  Link_array<Grob> cols(icols);
+  Link_array<Grob> cols (icols);
   
   for (int i =  cols.size (); i--;)
-    if (gh_pair_p (cols[i]->get_grob_property ("between-cols")))
+    if (ly_c_pair_p (cols[i]->get_property ("between-cols")))
       {
        loose_cols_.push (cols[i]);
        cols.del (i);
@@ -226,8 +226,8 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
     {
       Spring_smob *spring = 0;
 
-      for (SCM s = cols[i]->get_grob_property ("ideal-distances");
-          !spring && gh_pair_p (s);
+      for (SCM s = cols[i]->get_property ("ideal-distances");
+          !spring && ly_c_pair_p (s);
           s = ly_cdr (s))
        {
          Spring_smob *sp = unsmob_spring (ly_car (s));
@@ -245,7 +245,7 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
        }
       else
        {
-         programming_error (_f("No spring between column %d and next one",
+         programming_error (_f ("No spring between column %d and next one",
                                Paper_column::get_rank (cols[i])
                                ));
          desc.hooke_ = 1.0;
@@ -254,7 +254,7 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
          continue;
        }
 
-      if (!desc.sane_b ())
+      if (!desc.is_sane ())
        {
          programming_error ("Insane spring found. Setting to unit spring.");
 
@@ -264,7 +264,7 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
 
       if (isinf (desc.hooke_))
        {
-         desc.active_b_ = false;
+         desc.is_active_ = false;
          springs_.push (desc);
        }
       else
@@ -285,18 +285,16 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
   for (int i=0; i < cols.size () - 1; i++)
     {
       for (SCM s = Spaceable_grob::get_minimum_distances (cols[i]);
-          gh_pair_p (s); s = ly_cdr (s))
+          ly_c_pair_p (s); s = ly_cdr (s))
        {
          Grob * other = unsmob_grob (ly_caar (s));
          int oi = cols.find_index (other);
          if (oi >= 0)
            {
-             add_rod (i, oi, gh_scm2double (ly_cdar (s)));
+             add_rod (i, oi, ly_scm2double (ly_cdar (s)));
            }
        }
     }
-
-
 }
 
 /*
@@ -317,30 +315,17 @@ Simple_spacer::add_columns (Link_array<Grob> const &icols)
 void
 Simple_spacer::solve (Column_x_positions *positions, bool ragged) 
 {
-  /*
-    TODO: should support natural length on only the last line.
-   */
-  ragged = ragged || (line_len_ < 0) ;
   if (ragged)
     my_solve_natural_len ();
   else
     my_solve_linelen ();
 
-  
   positions->force_ = force_;
-  if ((force_ < 0))
-    {
-
-      /*
-       We used to have a penalty for compression, no matter what, but that
-       fucked up wtk1-fugue2 (taking 3 full pages.)
-
-       maybe this should be tunable?
-       */
-      if (compression_penalty_b_)
-       ; //    positions->force_ *= 2; //  hmm.
-    }
   
+  /*
+    We used to have a penalty for compression, no matter what, but that
+    fucked up wtk1-fugue2 (taking 3 full pages.)
+  */
   positions->config_.push (indent_);
   for (int i=0; i <springs_.size (); i++)
     {
@@ -350,11 +335,31 @@ Simple_spacer::solve (Column_x_positions *positions, bool ragged)
        we have l>= 0 here, up to rounding errors 
       */
     }
+
+  /*
+    For raggedright, we must have a measure of music density: this is
+    to prevent lots of short lines (which all have force = 0).
+    */
+  if (ragged)
+    {
+      Real len = positions->config_.top ();
+      if (line_len_ - len  >= 0)
+       positions->force_ = ((line_len_ - len) *  active_springs_stiffness ());
+      else
+       {
+         positions->force_ = 0.0;
+         /*
+           Don't go past end-of-line in ragged right.
+          */
+         positions->satisfies_constraints_ = false;
+       }
+    }
+
+
   positions->cols_ = spaced_cols_;
   positions->loose_cols_ = loose_cols_;
-  
-  positions->satisfies_constraints_b_ = (line_len_ < 0) || active_b ();
-
+  positions->satisfies_constraints_ =
+    positions->satisfies_constraints_ && is_active ();
 
   /*
     Check if breaking constraints are met.
@@ -363,22 +368,19 @@ Simple_spacer::solve (Column_x_positions *positions, bool ragged)
   int sz =  positions->cols_.size ();
   for (int i = sz; i--; )
     {
-      SCM p = positions->cols_[i]->get_grob_property( "penalty");
-      if (gh_number_p (p))
+      SCM p = positions->cols_[i]->get_property ( "penalty");
+      if (ly_c_number_p (p))
        {
-         if (gh_scm2double (p) < -9999)
+         if (ly_scm2double (p) < -9999)
            break_satisfy = break_satisfy && (i == 0 || i == sz -1);
-         if (gh_scm2double (p) > 9999)
+         if (ly_scm2double (p) > 9999)
            break_satisfy = break_satisfy && !(i == 0 || i == sz -1);
        }
       
     }
 
-  positions->satisfies_constraints_b_ =
-    positions->satisfies_constraints_b_ && break_satisfy;
-
-  if (ragged && force_ < 0)
-    positions->satisfies_constraints_b_ = false;
+  positions->satisfies_constraints_ =
+    positions->satisfies_constraints_ && break_satisfy;
 }
 
 /****************************************************************/
@@ -387,13 +389,13 @@ Spring_description::Spring_description ()
 {
   ideal_ =0.0;
   hooke_ =0.0;
-  active_b_ = true;
+  is_active_ = true;
   block_force_ = 0.0;
 }
 
 
 bool
-Spring_description::sane_b () const
+Spring_description::is_sane () const
 {
   return (hooke_ > 0) &&  !isinf (ideal_) && !isnan (ideal_);
 }
@@ -401,7 +403,7 @@ Spring_description::sane_b () const
 Real
 Spring_description::length (Real f) const
 {
-  if (!active_b_)
+  if (!is_active_)
     f = block_force_;
   return ideal_ + f / hooke_ ;
 }