X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Frest-collision.cc;h=e19002ef07bd54937b35a326a7a8281f6d1e5c7c;hb=0b544cfb7332615ef809b71b57ab656741311ae1;hp=fc8a4b401d2880347f687c2b908d62f0d5140f3b;hpb=4a401ca1c60f428daa242dbdd102fdb3f327ebfb;p=lilypond.git diff --git a/lily/rest-collision.cc b/lily/rest-collision.cc index fc8a4b401d..e19002ef07 100644 --- a/lily/rest-collision.cc +++ b/lily/rest-collision.cc @@ -1,7 +1,7 @@ /* This file is part of LilyPond, the GNU music typesetter. - Copyright (C) 1997--2011 Han-Wen Nienhuys + Copyright (C) 1997--2014 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 @@ -34,6 +34,7 @@ using namespace std; #include "staff-symbol-referencer.hh" #include "stem.hh" #include "grob.hh" +#include "unpure-pure-container.hh" #include "warn.hh" MAKE_SCHEME_CALLBACK_WITH_OPTARGS (Rest_collision, force_shift_callback_rest, 2, 1, ""); @@ -72,7 +73,10 @@ Rest_collision::add_column (Grob *me, Grob *p) if (rest) { chain_offset_callback (rest, - Rest_collision::force_shift_callback_rest_proc, Y_AXIS); + ly_make_unpure_pure_container + (Rest_collision::force_shift_callback_rest_proc, + ly_lily_module_constant ("pure-chain-offset-callback")), + Y_AXIS); } } @@ -146,13 +150,10 @@ Rest_collision::calc_positioning_done (SCM smob) rests[d]->warning (_ ("cannot resolve rest collision: rest direction not set")); } - Direction d = LEFT; - do + for (LEFT_and_RIGHT (d)) vector_sort (ordered_rests[d], rest_shift_less); - while (flip (&d) != LEFT) - ; - do + for (LEFT_and_RIGHT (d)) { if (ordered_rests[d].size () < 1) { @@ -162,7 +163,6 @@ Rest_collision::calc_positioning_done (SCM smob) return SCM_BOOL_T; } } - while (flip (&d) != LEFT); Grob *common = common_refpoint_of_array (ordered_rests[DOWN], me, Y_AXIS); common = common_refpoint_of_array (ordered_rests[UP], common, Y_AXIS); @@ -182,7 +182,7 @@ Rest_collision::calc_positioning_done (SCM smob) 2 * int (ceil (diff))); } - do + for (LEFT_and_RIGHT (d)) { for (vsize i = ordered_rests[d].size () - 1; i-- > 0;) { @@ -194,7 +194,6 @@ Rest_collision::calc_positioning_done (SCM smob) Rest::translate (ordered_rests[d][i], d * (int) ceil (diff) * 2); } } - while (flip (&d) != LEFT); } else { @@ -207,11 +206,12 @@ Rest_collision::calc_positioning_done (SCM smob) for (vsize i = 0; i < rests.size (); i++) { Grob *rcol = rests[i]; - Direction dir = Note_column::dir (rcol); + Grob *rest = Note_column::get_rest (rcol); + + Direction dir = get_grob_direction (rest); if (!dir) - continue; + dir = Note_column::dir (rcol); - Grob *rest = Note_column::get_rest (rcol); // Do not compute a translation for pre-positioned rests, // nor count them for the "too many colliding rests" warning if (scm_is_number (rest->get_property ("staff-position"))) @@ -253,19 +253,14 @@ Rest_collision::calc_positioning_done (SCM smob) Real y = dir * max (0.0, -dir * restdim[-dir] + dir * notedim[dir] + minimum_dist); - int stafflines = Staff_symbol_referencer::line_count (me); - if (!stafflines) - { - programming_error ("no staff line count"); - stafflines = 5; - } - // move discretely by half spaces. int discrete_y = dir * int (ceil (y / (0.5 * dir * staff_space))); + Interval staff_span = Staff_symbol_referencer::staff_span (rest); + staff_span.widen (1); // move by whole spaces inside the staff. - if (fabs (Staff_symbol_referencer::get_position (rest) - + discrete_y) < stafflines + 1) + if (staff_span.contains + (Staff_symbol_referencer::get_position (rest) + discrete_y)) { discrete_y = dir * int (ceil (dir * discrete_y / 2.0) * 2.0); }