SCM
substitute_grob (Grob *sc)
{
- if (SCM_INUMP (break_criterion))
+ if (scm_is_integer (break_criterion))
{
Item * i = dynamic_cast<Item*> (sc);
Direction d = to_dir (break_criterion);
/* now: sc && sc->get_system () == line */
if (!line)
- return sc->self_scm();
+ return sc->self_scm ();
/*
We don't return SCM_UNDEFINED for
a huge recursion in the GC routine.
*/
- /*
- This was introduced in 1.3.49 as a measure to prevent
- programming errors. It looks rather expensive (?).
-
- TODO:
-
- benchmark , document when (what kind of programming
- errors) this happens.
- */
if (sc->common_refpoint (line, X_AXIS)
&& sc->common_refpoint (line, Y_AXIS))
{
return SCM_UNDEFINED;
}
- return sc->self_scm();
+ return sc->self_scm ();
}
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.
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.
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);
}
}
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
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;
{
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;
}
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;
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;
}
else if (Item* it = dynamic_cast<Item*> (g))
return item_system_range (it);
else
- return Slice();
+ return Slice ();
}
right_ = sr[RIGHT];
}
}
- Substitution_entry()
+ Substitution_entry ()
{
grob_ =0;
left_ = right_ = -2;
static int
spanner_compare (void const * a , void const * b)
{
- return ((Substitution_entry*)a)->length() -
+ return ((Substitution_entry*)a)->length () -
((Substitution_entry*)b)->length ();
}
};
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);
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;
{
*tail = scm_cons (subs, SCM_EOL);
- tail = SCM_CDRLOC(*tail);
+ tail = SCM_CDRLOC (*tail);
}
}
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);
}
#endif
+ /*
+ see below.
+ */
+ if (sym == ly_symbol2scm ("all-elements"))
+ sc->mutable_property_alist_
+ = scm_assq_remove_x (sc->mutable_property_alist_,
+ ly_symbol2scm ("all-elements"));
+
sc->mutable_property_alist_ = scm_acons (sym, newval,
sc->mutable_property_alist_);
}
}
-SCM grob_list_p;
-
/*
Although the substitution can be written as
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
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)
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);
}
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);
SCM newval = (type == grob_list_p)
? substitute_grob_list (val)
- : do_break_substitution(val);
+ : do_break_substitution (val);
+ /*
+ 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.
+
+ Here we clear that list explicitly to free some memory and
+ counter some of the confusion I encountered while debugging
+ another problem
+
+ (hwn 4/2/04)
+ */
+ if (sym == ly_symbol2scm ("all-elements"))
+ sc->mutable_property_alist_
+ = scm_assq_remove_x (sc->mutable_property_alist_,
+ ly_symbol2scm ("all-elements"));
+
sc->mutable_property_alist_ = scm_cons (scm_cons (sym, newval),
sc->mutable_property_alist_);
}