X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbreak-substitution.cc;h=2cd29707d611a1d60c704d0c9615eaa7a73af35c;hb=ee44e5855df96a91937bdf36e7268bb9feb0f77b;hp=670f7e567b4d3022da3b14746525420948c9be8c;hpb=2c22efe5a46a37065b10c3f51c5d7db00d07d318;p=lilypond.git diff --git a/lily/break-substitution.cc b/lily/break-substitution.cc index 670f7e567b..2cd29707d6 100644 --- a/lily/break-substitution.cc +++ b/lily/break-substitution.cc @@ -1,17 +1,29 @@ /* - break-substitution.cc -- implement grob break substitution. + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2001--2011 Han-Wen Nienhuys - (c) 2001--2005 Han-Wen Nienhuys + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include #include +using namespace std; -#include "grob-array.hh" #include "item.hh" #include "system.hh" +#include "grob-array.hh" static SCM break_criterion; void @@ -138,19 +150,19 @@ do_break_substitution (SCM src) /* Perform substitution on GROB_LIST using a constant amount of stack. */ -Link_array temporary_substition_array; +vector temporary_substition_array; void substitute_grob_array (Grob_array *grob_arr, Grob_array *new_arr) { - Link_array &old_grobs (grob_arr->array_reference ()); - Link_array *new_grobs (new_arr == grob_arr + vector &old_grobs (grob_arr->array_reference ()); + vector *new_grobs (new_arr == grob_arr ? & temporary_substition_array : &new_arr->array_reference ()); - new_grobs->set_size (old_grobs.size ()); - Grob **array = (Grob **) new_grobs->accesses (); + new_grobs->resize (old_grobs.size ()); + Grob **array = (Grob **) new_grobs->data (); Grob **ptr = array; - for (int i = 0; i < old_grobs.size (); i++) + for (vsize i = 0; i < old_grobs.size (); i++) { Grob *orig = old_grobs[i]; Grob *new_grob = substitute_grob (orig); @@ -158,11 +170,9 @@ substitute_grob_array (Grob_array *grob_arr, Grob_array *new_arr) *ptr++ = new_grob; } - new_grobs->set_size (ptr - array); + new_grobs->resize (ptr - array); if (new_arr == grob_arr) - { - new_arr->set_array (*new_grobs); - } + new_arr->set_array (*new_grobs); } /* @@ -221,14 +231,12 @@ spanner_system_range (Spanner *sp) Slice rv; if (System *st = sp->get_system ()) - { - rv = Slice (st->get_rank (), st->get_rank ()); - } + rv = Slice (st->get_rank (), st->get_rank ()); else { if (sp->broken_intos_.size ()) rv = Slice (sp->broken_intos_[0]->get_system ()->get_rank (), - sp->broken_intos_.top ()->get_system ()->get_rank ()); + sp->broken_intos_.back ()->get_system ()->get_rank ()); } return rv; } @@ -266,6 +274,8 @@ grob_system_range (Grob *g) struct Substitution_entry { Grob *grob_; + + /* Assumption: we have less than 32k paper columns. */ short left_; short right_; @@ -285,8 +295,8 @@ struct Substitution_entry } else { - left_ = sr[LEFT]; - right_ = sr[RIGHT]; + left_ = (short) sr[LEFT]; + right_ = (short) sr[RIGHT]; } } Substitution_entry () @@ -325,6 +335,8 @@ Spanner::fast_substitute_grob_array (SCM sym, /* We store items on the left, spanners on the right in this vector. + + FIXME: will not multithread. */ static Substitution_entry *vec; static int vec_room; @@ -340,7 +352,7 @@ Spanner::fast_substitute_grob_array (SCM sym, int spanner_index = len; int item_index = 0; - for (int i = 0; i < grob_array->size (); i++) + for (vsize i = 0; i < grob_array->size (); i++) { Grob *g = grob_array->grob (i); @@ -359,15 +371,15 @@ Spanner::fast_substitute_grob_array (SCM sym, qsort (vec, item_index, sizeof (Substitution_entry), &Substitution_entry::item_compare); - Array item_indices; - Array spanner_indices; + vector item_indices; + vector spanner_indices; for (int i = 0; i <= system_range.length (); i++) { - item_indices.push (Slice (len, 0)); - spanner_indices.push (Slice (len, 0)); + item_indices.push_back (Slice (len, 0)); + spanner_indices.push_back (Slice (len, 0)); } - Array *arrs[] + vector *arrs[] = { &item_indices, &spanner_indices }; @@ -383,14 +395,14 @@ Spanner::fast_substitute_grob_array (SCM sym, is a waste of time -- the staff-spanners screw up the ordering, since they go across the entire score. */ - for (int i = spanner_indices.size (); i--;) + for (vsize i = spanner_indices.size (); i--;) spanner_indices[i] = Slice (spanner_index, len - 1); assert (item_index <= spanner_index); - assert ((broken_intos_.size () == system_range.length () + 1) - || (broken_intos_.is_empty () && system_range.length () == 0)); - for (int i = 0; i < broken_intos_.size (); i++) + assert ((broken_intos_.size () == (vsize)system_range.length () + 1) + || (broken_intos_.empty () && system_range.length () == 0)); + for (vsize i = 0; i < broken_intos_.size (); i++) { Grob *sc = broken_intos_[i]; System *l = sc->get_system (); @@ -400,7 +412,7 @@ Spanner::fast_substitute_grob_array (SCM sym, if (!unsmob_grob_array (newval)) { newval = Grob_array::make_array (); - sc->internal_set_object (sym, newval); + sc->set_object (sym, newval); } Grob_array *new_array = unsmob_grob_array (newval); @@ -491,7 +503,7 @@ Spanner::substitute_one_mutable_property (SCM sym, fast_done = s->fast_substitute_grob_array (sym, grob_array); if (!fast_done) - for (int i = 0; i < s->broken_intos_.size (); i++) + for (vsize i = 0; i < s->broken_intos_.size (); i++) { Grob *sc = s->broken_intos_[i]; System *l = sc->get_system (); @@ -503,15 +515,21 @@ Spanner::substitute_one_mutable_property (SCM sym, if (!unsmob_grob_array (newval)) { newval = Grob_array::make_array (); - sc->internal_set_object (sym, newval); + sc->set_object (sym, newval); } substitute_grob_array (grob_array, unsmob_grob_array (newval)); } else { SCM newval = do_break_substitution (val); - sc->internal_set_object (sym, newval); + sc->set_object (sym, newval); } } } +void +Grob::substitute_object_links (SCM crit, SCM orig) +{ + set_break_subsititution (crit); + object_alist_ = substitute_object_alist (orig, object_alist_); +}