]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/break-substitution.cc
*** empty log message ***
[lilypond.git] / lily / break-substitution.cc
index 5f2f2d81f168e77a80e118d3175de62eb90f18d4..f7dee18a75b9e204699bb7440c1eb96a08b58f1a 100644 (file)
@@ -45,7 +45,7 @@ substitute_grob (Grob *sc)
 
       /* now: sc && sc->get_system () == line */
       if (!line)
-       return sc->self_scm();
+       return sc->self_scm ();
 
       /*
        We don't return SCM_UNDEFINED for
@@ -65,7 +65,7 @@ substitute_grob (Grob *sc)
       return SCM_UNDEFINED;
     }
 
-  return sc->self_scm();
+  return sc->self_scm ();
 }
 
 
@@ -90,21 +90,19 @@ do_break_substitution (SCM src)
  again:
  
   if (unsmob_grob (src))
+    return substitute_grob (unsmob_grob (src));
+  else if (ly_c_vector_p (src))
     {
-      return substitute_grob (unsmob_grob (src));
-    }
-  else if (gh_vector_p (src))
-    {
-      int  l = SCM_VECTOR_LENGTH (src);
-      SCM nv = scm_c_make_vector (l, SCM_UNDEFINED);
-
-      for (int i  =0 ; i< l ; i++)
+      int len = SCM_VECTOR_LENGTH (src);
+      SCM nv = scm_c_make_vector (len, SCM_UNDEFINED);
+      for (int i = 0; i < len; i++)
        {
          SCM si = scm_int2num (i);
-         scm_vector_set_x (nv, si, do_break_substitution (scm_vector_ref (src, si))); 
+         scm_vector_set_x (nv, si,
+                           do_break_substitution (scm_vector_ref (src, si))); 
        }
     }
-  else if (ly_pair_p (src)) 
+  else if (ly_c_pair_p (src)) 
     {
       /*
        UGH! breaks on circular lists.
@@ -113,7 +111,7 @@ do_break_substitution (SCM src)
       SCM oldcdr = ly_cdr (src);
       
       if (newcar == SCM_UNDEFINED
-         && (gh_pair_p (oldcdr) || oldcdr == SCM_EOL))
+         && (ly_c_pair_p (oldcdr) || oldcdr == SCM_EOL))
        {
          /*
            This is tail-recursion, ie. 
@@ -144,14 +142,14 @@ substitute_grob_list (SCM grob_list)
   SCM l = SCM_EOL;
   SCM * tail = &l;
 
-  for (SCM s = grob_list; gh_pair_p (s); s =  gh_cdr (s))
+  for (SCM s = grob_list; ly_c_pair_p (s); s =  ly_cdr (s))
     {
-      SCM n= substitute_grob (unsmob_grob (gh_car (s)));
+      SCM n= substitute_grob (unsmob_grob (ly_car (s)));
 
       if (n != SCM_UNDEFINED)
        {
-         *tail = gh_cons (n, SCM_EOL);
-         tail = SCM_CDRLOC(*tail);
+         *tail = scm_cons (n, SCM_EOL);
+         tail = SCM_CDRLOC (*tail);
        }
     }
 
@@ -166,8 +164,8 @@ substitute_grob_list (SCM grob_list)
         forall g in p (if grob-list):
          g := substitute (g)
 
-  for spanners since this is O(SYSTEMCOUNT * GROBCOUNT), and SYSTEMCOUNT =
-  O(GROBCOUNT), we have a quadratic algorithm. --for a single spanner
+  for spanners since this is O (SYSTEMCOUNT * GROBCOUNT), and SYSTEMCOUNT =
+  O (GROBCOUNT), we have a quadratic algorithm. --for a single spanner
 
   This is problematic: with large (long) scores, the costs can be
   significant; especially all-elements in System, can become huge. For
@@ -181,15 +179,15 @@ substitute_grob_list (SCM grob_list)
 
      put  grob list in array,
 
-     reorder array so spanners are separate -- O(grobcount)
+     reorder array so spanners are separate -- O (grobcount)
      
      find first and last indexes of grobs on a specific system
 
-     for items this is O(itemcount)
+     for items this is O (itemcount)
 
-     for spanners this is O(sum-of spanner-system-ranges)
+     for spanners this is O (sum-of spanner-system-ranges)
 
-     perform the substitution O(sum-of spanner-system-ranges)
+     perform the substitution O (sum-of spanner-system-ranges)
 
 
   The complexity is harder to determine, but should be subquadratic;
@@ -216,15 +214,15 @@ spanner_system_range (Spanner* sp)
 {
   Slice rv;
   
-  if (System*st = sp->get_system())
+  if (System*st = sp->get_system ())
     {
       rv = Slice (st->rank_, st->rank_);
     }
   else 
     {
-      if (sp->broken_intos_.size())
-       rv = Slice (sp->broken_intos_[0]->get_system()->rank_,
-                   sp->broken_intos_.top()->get_system()->rank_);
+      if (sp->broken_intos_.size ())
+       rv = Slice (sp->broken_intos_[0]->get_system ()->rank_,
+                   sp->broken_intos_.top ()->get_system ()->rank_);
     }
   return rv;
 }
@@ -232,7 +230,7 @@ spanner_system_range (Spanner* sp)
 Slice
 item_system_range (Item* it)
 {
-  if (System*st= it->get_system())
+  if (System*st= it->get_system ())
     return Slice (st->rank_, st->rank_);
 
   Slice sr;
@@ -240,10 +238,10 @@ item_system_range (Item* it)
   do
     {
       Item *bi = it->find_prebroken_piece (d);
-      if (bi && bi->get_system())
-       sr.add_point (bi->get_system()->rank_);
+      if (bi && bi->get_system ())
+       sr.add_point (bi->get_system ()->rank_);
     }
-  while (flip(&d)!=LEFT);
+  while (flip (&d)!=LEFT);
   
   return sr;
 }
@@ -256,7 +254,7 @@ grob_system_range (Grob *g)
  else if (Item* it = dynamic_cast<Item*> (g))
    return item_system_range (it);
  else
-   return Slice();
+   return Slice ();
 }
 
 
@@ -287,7 +285,7 @@ struct Substitution_entry
        right_ = sr[RIGHT];
       }
   }
-  Substitution_entry()
+  Substitution_entry ()
   {
     grob_ =0;
     left_ = right_ = -2;
@@ -304,7 +302,7 @@ struct Substitution_entry
   static int
   spanner_compare (void const * a , void const * b)
   {
-    return ((Substitution_entry*)a)->length() -
+    return ((Substitution_entry*)a)->length () -
       ((Substitution_entry*)b)->length ();
   }
 };
@@ -352,9 +350,9 @@ Spanner::fast_fubstitute_grob_list (SCM sym,
   
   int sp_index = len;
   int it_index = 0;
-  for (SCM s = grob_list; gh_pair_p (s); s = gh_cdr (s))
+  for (SCM s = grob_list; ly_c_pair_p (s); s = ly_cdr (s))
     {
-      Grob * g = unsmob_grob (gh_car(s));
+      Grob * g = unsmob_grob (ly_car (s));
 
       Slice sr = grob_system_range (g);
       sr.intersect (system_range);
@@ -392,18 +390,18 @@ Spanner::fast_fubstitute_grob_list (SCM sym,
    is a waste of time -- the staff-spanners screw up the
    ordering, since they go across the entire score.
  */
- for (int i = sp_indices.size(); i--;)
+ for (int i = sp_indices.size (); i--;)
    sp_indices[i]= Slice (sp_index, len-1);
 
  
   assert (it_index <= sp_index);
 
   assert (broken_intos_.size () == system_range.length () + 1); 
-  for (int i = 0; i < broken_intos_.size(); i++)
+  for (int i = 0; i < broken_intos_.size (); i++)
     {
       Grob * sc = broken_intos_[i];
       System * l = sc->get_system ();
-      set_break_subsititution (l ? l->self_scm(): SCM_UNDEFINED);
+      set_break_subsititution (l ? l->self_scm (): SCM_UNDEFINED);
 
       SCM newval = SCM_EOL;
       SCM * tail = &newval;
@@ -416,7 +414,7 @@ Spanner::fast_fubstitute_grob_list (SCM sym,
              {
                *tail = scm_cons (subs, SCM_EOL);
                
-               tail = SCM_CDRLOC(*tail);
+               tail = SCM_CDRLOC (*tail);
              }
 
          }
@@ -425,7 +423,7 @@ Spanner::fast_fubstitute_grob_list (SCM sym,
      
       printf ("%d (%d), sp %d (%d)\n",
              it_indices [i].length (), it_index,
-             sp_indices[i].length() , len -sp_index);
+             sp_indices[i].length () , len -sp_index);
              
       {
        SCM l1 =substitute_grob_list (grob_list);
@@ -449,8 +447,6 @@ Spanner::fast_fubstitute_grob_list (SCM sym,
 }
 
 
-SCM grob_list_p; 
-
 /*
   Although the substitution can be written as
 
@@ -458,7 +454,7 @@ SCM grob_list_p;
 
   we have a special function here: we want to invoke a special
   function for lists of grobs. These can be very long for large
-  orchestral scores (eg. 1M elements). do_break_substitution() can
+  orchestral scores (eg. 1M elements). do_break_substitution () can
   recurse many levels, taking lots of stack space.
 
   This becomes a problem if lily is linked against guile with
@@ -467,15 +463,14 @@ SCM grob_list_p;
 SCM
 substitute_mutable_property_alist (SCM alist)
 {
-  if (!grob_list_p)
-    grob_list_p = scm_c_eval_string ("grob-list?");
+  SCM grob_list_p = ly_scheme_function ("grob-list?");
 
   SCM l = SCM_EOL;
   SCM *tail = &l;
-  for (SCM s = alist; gh_pair_p (s); s = gh_cdr (s))
+  for (SCM s = alist; ly_c_pair_p (s); s = ly_cdr (s))
     {
-      SCM sym = gh_caar(s);
-      SCM val = gh_cdar(s);
+      SCM sym = ly_caar (s);
+      SCM val = ly_cdar (s);
       SCM type = scm_object_property (sym, ly_symbol2scm ("backend-type?"));
 
       if (type == grob_list_p)
@@ -483,7 +478,7 @@ substitute_mutable_property_alist (SCM alist)
       else
        val = do_break_substitution (val);
 
-      *tail = gh_cons (gh_cons (sym, val), SCM_EOL);
+      *tail = scm_cons (scm_cons (sym, val), SCM_EOL);
       tail = SCM_CDRLOC (*tail);
     }
 
@@ -499,6 +494,7 @@ Spanner::substitute_one_mutable_property (SCM sym,
   Spanner*s = this;
   
   bool fast_done = false;
+  SCM grob_list_p = ly_scheme_function ("grob-list?");
   if (type == grob_list_p)
     fast_done = s->fast_fubstitute_grob_list (sym, val);
 
@@ -517,7 +513,7 @@ Spanner::substitute_one_mutable_property (SCM sym,
          For the substitution of a single property, we tack the result onto
          mutable_property_alist_ ; mutable_property_alist_ is empty after
          Grob::Grob (Grob const&), except that System has all-elements set,
-         as a side product of typeset_grob() on newly copied spanners.
+         as a side product of typeset_grob () on newly copied spanners.
 
          Here we clear that list explicitly to free some memory and
          counter some of the confusion I encountered while debugging