X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fbreak-align-interface.cc;h=bcd62a73fc380cffbcb4e6e2ccb47ef0441df9cb;hb=14a80befb9892f9a164db420fdd187792eb2769f;hp=aadb89a9987fb977833f67032b98d3389c63daf2;hpb=604261d8a143f04ee130e679fe1b649758250bda;p=lilypond.git diff --git a/lily/break-align-interface.cc b/lily/break-align-interface.cc index aadb89a998..bcd62a73fc 100644 --- a/lily/break-align-interface.cc +++ b/lily/break-align-interface.cc @@ -17,7 +17,7 @@ #include "lily-guile.hh" #include "break-align-interface.hh" #include "dimensions.hh" -#include "paper-def.hh" +#include "output-def.hh" #include "paper-column.hh" #include "group-interface.hh" #include "align-interface.hh" @@ -28,7 +28,7 @@ SCM Break_align_interface::alignment_callback (SCM element_smob, SCM axis) { Grob *me = unsmob_grob (element_smob); - Axis a = (Axis) gh_scm2int (axis); + Axis a = (Axis) scm_to_int (axis); assert (a == X_AXIS); Grob *par = me->get_parent (a); @@ -38,7 +38,7 @@ Break_align_interface::alignment_callback (SCM element_smob, SCM axis) Break_align_interface::do_alignment (par); } - return gh_double2scm (0); + return scm_make_real (0); } MAKE_SCHEME_CALLBACK (Break_align_interface,self_align_callback,2); @@ -46,7 +46,7 @@ SCM Break_align_interface::self_align_callback (SCM element_smob, SCM axis) { Grob *me = unsmob_grob (element_smob); - Axis a = (Axis) gh_scm2int (axis); + Axis a = (Axis) scm_to_int (axis); assert (a == X_AXIS); Item* item = dynamic_cast (me); @@ -63,49 +63,46 @@ Break_align_interface::self_align_callback (SCM element_smob, SCM axis) } -void -Break_align_interface::order_elements (Grob *grob) +/* + This is tricky: we cannot modify 'elements, since callers are + iterating the same list. Reordering the list in-place, or resetting + 'elements will skip elements in the loops of callers. + + So we return the correct order as an array. + */ +Link_array +Break_align_interface::ordered_elements (Grob *grob) { Item *me = dynamic_cast (grob); SCM elts = me->get_property ("elements"); SCM order_vec = me->get_property ("break-align-orders"); - if (!gh_vector_p (order_vec) - || gh_vector_length (order_vec) < 3) - return ; - + if (!ly_c_vector_p (order_vec) + || ly_vector_length (order_vec) < 3) + return Pointer_group_interface__extract_grobs (me, (Grob*)0, + "elements"); SCM order = scm_vector_ref (order_vec, - gh_int2scm (me->break_status_dir() + 1)); + scm_int2num (me->break_status_dir() + 1)); + /* - Copy in order specified in BREAK-ALIGN-ORDER. We use - Pointer_group_interface__extract_grobs (which reverses the list) - down the line, so it's ok to prepend onto newlist. - */ - SCM new_list = SCM_EOL; - for (; gh_pair_p (order); order = ly_cdr (order)) + Copy in order specified in BREAK-ALIGN-ORDER. + */ + Link_array new_elts; + for (; scm_is_pair (order); order = scm_cdr (order)) { - SCM sym = gh_car (order); - - SCM *tail = &elts; - for (; gh_pair_p (*tail); tail = SCM_CDRLOC(*tail)) + SCM sym = scm_car (order); + + for (SCM s =elts; scm_is_pair (s); s = scm_cdr (s)) { - Grob * g = unsmob_grob (gh_car (*tail)); - if (sym == g->get_property ("break-align-symbol")) + Grob *g = unsmob_grob (scm_car (s)); + if (g && sym == g->get_property ("break-align-symbol")) { - SCM new_pair = *tail; - *tail = gh_cdr (*tail); - if (gh_pair_p (*tail)) - tail = SCM_CDRLOC(*tail); - - gh_set_cdr_x (new_pair, new_list); - new_list = new_pair; - break; + new_elts.push (g); + elts = scm_delq (g->self_scm (), elts); } } } - - new_list = scm_reverse_x (elts, new_list); - me->set_property ("elements", new_list); + return new_elts; } void @@ -119,11 +116,8 @@ Break_align_interface::do_alignment (Grob *grob) { Item * me = dynamic_cast (grob); - order_elements (me); - Link_array elems - = Pointer_group_interface__extract_grobs (me, (Grob*)0, - "elements"); + Link_array elems = ordered_elements (me); Array extents; int last_nonempty = -1; @@ -166,10 +160,10 @@ Break_align_interface::do_alignment (Grob *grob) /* Find the first grob with a space-alist entry. */ - for (SCM s= l->get_property ("elements"); - gh_pair_p (s) ; s = gh_cdr (s)) + for (SCM s = l->get_property ("elements"); + scm_is_pair (s) ; s = scm_cdr (s)) { - Grob *elt = unsmob_grob (gh_car (s)); + Grob *elt = unsmob_grob (scm_car (s)); if (edge_idx < 0 && elt->get_property ("break-align-symbol") @@ -177,7 +171,7 @@ Break_align_interface::do_alignment (Grob *grob) edge_idx = idx; SCM l =elt->get_property ("space-alist"); - if (gh_pair_p (l)) + if (scm_is_pair (l)) { alist= l; break; @@ -192,9 +186,9 @@ Break_align_interface::do_alignment (Grob *grob) reason. */ for (SCM s = r ? r->get_property ("elements") : SCM_EOL; - !gh_symbol_p (rsym) && gh_pair_p (s); s = gh_cdr (s)) + !scm_is_symbol (rsym) && scm_is_pair (s); s = scm_cdr (s)) { - Grob * elt =unsmob_grob (gh_car (s)); + Grob * elt =unsmob_grob (scm_car (s)); rsym = elt->get_property ("break-align-symbol"); } @@ -203,14 +197,14 @@ Break_align_interface::do_alignment (Grob *grob) edge_idx = next_idx; SCM entry = SCM_EOL; - if (gh_symbol_p (rsym)) + if (scm_is_symbol (rsym)) entry = scm_assq (rsym, alist); - bool entry_found = gh_pair_p (entry); + bool entry_found = scm_is_pair (entry); if (!entry_found) { String sym_string; - if (gh_symbol_p (rsym)) + if (scm_is_symbol (rsym)) sym_string = ly_symbol2string (rsym); String orig_string ; @@ -227,10 +221,10 @@ Break_align_interface::do_alignment (Grob *grob) if (entry_found) { - entry = gh_cdr (entry); + entry = scm_cdr (entry); - distance = gh_scm2double (gh_cdr (entry)); - type = gh_car (entry) ; + distance = scm_to_double (scm_cdr (entry)); + type = scm_car (entry) ; } if (r)