#include "rest-collision.hh"
-#include <math.h> // ceil.
+#include <cmath> // ceil.
+using namespace std;
#include "warn.hh"
#include "note-column.hh"
#include "rhythmic-head.hh"
#include "output-def.hh"
#include "rest.hh"
-#include "group-interface.hh"
+#include "pointer-group-interface.hh"
#include "staff-symbol-referencer.hh"
#include "duration.hh"
#include "directional-element-interface.hh"
-MAKE_SCHEME_CALLBACK (Rest_collision, force_shift_callback, 2);
+MAKE_SCHEME_CALLBACK (Rest_collision, force_shift_callback, 1);
SCM
-Rest_collision::force_shift_callback (SCM element_smob, SCM axis)
+Rest_collision::force_shift_callback (SCM smob)
{
- Grob *them = unsmob_grob (element_smob);
- Axis a = (Axis) scm_to_int (axis);
- assert (a == Y_AXIS);
-
+ Grob *them = unsmob_grob (smob);
if (Note_column::has_rests (them))
{
- Grob *rc = unsmob_grob (them->get_property ("rest-collision"));
+ Grob *collision = unsmob_grob (them->get_object ("rest-collision"));
- if (rc && !to_boolean (rc->get_property ("positioning-done")))
+ if (collision)
{
- rc->set_property ("positioning-done", SCM_BOOL_T);
- do_shift (rc);
+ (void) collision->get_property ("positioning-done");
}
}
- return scm_make_real (0.0);
+ return scm_from_double (0.0);
}
MAKE_SCHEME_CALLBACK (Rest_collision, force_shift_callback_rest, 2);
SCM
-Rest_collision::force_shift_callback_rest (SCM rest, SCM axis)
+Rest_collision::force_shift_callback_rest (SCM rest, SCM offset)
{
Grob *rest_grob = unsmob_grob (rest);
- assert ((Axis) scm_to_int (axis) == Y_AXIS);
-
Grob *parent = rest_grob->get_parent (X_AXIS);
+
+ /*
+ translate REST; we need the result of this translation later on,
+ while the offset probably still is 0/calculation-in-progress.
+ */
+ rest_grob->translate_axis (scm_to_double (offset), Y_AXIS);
+
if (Note_column::has_interface (parent))
- return force_shift_callback (parent->self_scm (), axis);
- else
- return scm_make_real (0.0);
+ force_shift_callback (parent->self_scm ());
+
+ return scm_from_double (0.0);
}
void
Rest_collision::add_column (Grob *me, Grob *p)
{
- me->add_dependency (p);
Pointer_group_interface::add_grob (me, ly_symbol2scm ("elements"), p);
/*
(not?)
*/
- p->add_offset_callback (Rest_collision::force_shift_callback_proc, Y_AXIS);
- p->set_property ("rest-collision", me->self_scm ());
+ add_offset_callback (p, Rest_collision::force_shift_callback_proc, Y_AXIS);
+ p->set_object ("rest-collision", me->self_scm ());
- Grob *rest = unsmob_grob (p->get_property ("rest"));
+ Grob *rest = unsmob_grob (p->get_object ("rest"));
if (rest)
{
- rest->add_offset_callback (Rest_collision::force_shift_callback_rest_proc,
- Y_AXIS);
+ chain_offset_callback (rest,
+ Rest_collision::force_shift_callback_rest_proc, Y_AXIS);
}
}
TODO: look at horizontal-shift to determine ordering between rests
for more than two voices.
*/
+MAKE_SCHEME_CALLBACK(Rest_collision, calc_positioning_done, 1);
SCM
-Rest_collision::do_shift (Grob *me)
+Rest_collision::calc_positioning_done (SCM smob)
{
- SCM elts = me->get_property ("elements");
+ Grob *me = unsmob_grob (smob);
+ extract_grob_set (me, "elements", elts);
Link_array<Grob> rests;
Link_array<Grob> notes;
- for (SCM s = elts; scm_is_pair (s); s = scm_cdr (s))
+ for (int i = 0; i < elts.size (); i++)
{
- Grob *e = unsmob_grob (scm_car (s));
- if (unsmob_grob (e->get_property ("rest")))
+ Grob *e = elts[i];
+ if (unsmob_grob (e->get_object ("rest")))
{
/*
Ignore rests under beam.
*/
- Grob *st = unsmob_grob (e->get_property ("stem"));
- if (st && unsmob_grob (st->get_property ("beam")))
+ Grob *st = unsmob_grob (e->get_object ("stem"));
+ if (st && unsmob_grob (st->get_object ("beam")))
continue;
rests.push (e);
Direction d = get_grob_direction (r);
if (d)
- {
- ordered_rests[d].push (rests[i]);
- }
+ ordered_rests[d].push (rests[i]);
else
- rests[d]->warning (_ ("rest direction not set. Cannot resolve collision."));
+ rests[d]->warning (_ ("can't resolve rest collision: rest direction not set"));
}
Direction d = LEFT;
do
- {
- ordered_rests[d].sort (Note_column::shift_compare);
- }
- while (flip (&d) != LEFT);
+ ordered_rests[d].sort (Note_column::shift_compare);
+ while (flip (&d) != LEFT)
+ ;
do
{
Rests and notes.
*/
if (rests.size () > 1)
- {
- warning (_ ("too many colliding rests"));
- }
+ warning (_ ("too many colliding rests"));
Grob *rcol = 0;
Direction dir = CENTER;
Interval notedim;
for (int i = 0; i < notes.size (); i++)
- {
- notedim.unite (notes[i]->extent (common, Y_AXIS));
- }
+ notedim.unite (notes[i]->extent (common, Y_AXIS));
Real dist
- = minimum_dist + dir * (notedim[dir] - restdim[-dir]) >? 0;
+ = minimum_dist + dir * max (notedim[dir] - restdim[-dir], 0.0);
int stafflines = Staff_symbol_referencer::line_count (me);
if (!stafflines)
ADD_INTERFACE (Rest_collision, "rest-collision-interface",
"Move around ordinary rests (not multi-measure-rests) to avoid "
"conflicts.",
- "minimum-distance positioning-done elements");
+
+ /* properties */
+ "minimum-distance "
+ "positioning-done "
+ "elements");