#include "note-head.hh"
#include "paper-def.hh"
#include "axis-group-interface.hh"
+#include "item.hh"
-
-Collision::Collision()
+void
+Collision::add_column (Note_column* ncol_l)
{
- axis_group (this).set_axes (X_AXIS, Y_AXIS);
+ ncol_l->add_offset_callback (force_shift_callback, X_AXIS);
+ Axis_group_interface (elt_l_).add_element (ncol_l);
+ elt_l_->add_dependency (ncol_l);
}
-void
-Collision::add_column (Note_column* ncol_l)
+Real
+Collision::force_shift_callback (Score_element const * c, Axis a)
{
- axis_group (this).add_element (ncol_l);
- add_dependency (ncol_l);
+ assert (a == X_AXIS);
+
+ Score_element * me = c->parent_l (a);
+ /*
+ ugh. the way DONE is done is not clean
+ */
+ if (!unsmob_element (me->get_elt_pointer ("done")))
+ {
+ me->set_elt_pointer ("done", me->self_scm_);
+ do_shifts (me);
+ }
+
+ return 0.0;
}
/*
- UGH. junk Shift_tup .
+ TODO: make callback of this.
*/
-
void
-Collision::before_line_breaking ()
+Collision::do_shifts(Score_element* me)
{
- Array<Shift_tup> autos (automatic_shift ());
- Array<Shift_tup> hand (forced_shift ());
+ SCM autos (automatic_shift (me));
+ SCM hand (forced_shift (me));
+
Link_array<Score_element> done;
- Real wid = paper_l ()->get_var ("collision_note_width");
- for (int i=0; i < hand.size (); i++)
+ Real wid = me->paper_l ()->get_var ("collision_note_width"); // elt prop
+ for (; gh_pair_p (hand); hand =gh_cdr (hand))
{
- hand[i].e1_->translate_axis (hand[i].e2_ *wid, X_AXIS);
- done.push (hand[i].e1_);
+ Score_element * s = unsmob_element (gh_caar (hand));
+ Real amount = gh_scm2double (gh_cdar (hand));
+
+ s->translate_axis (amount *wid, X_AXIS);
+ done.push (s);
}
-
- for (int i=0; i < autos.size (); i++)
+ for (; gh_pair_p (autos); autos =gh_cdr (autos))
{
- if (!done.find_l (autos[i].e1_))
- autos[i].e1_->translate_axis (autos[i].e2_ * wid, X_AXIS);
+ Score_element * s = unsmob_element (gh_caar (autos));
+ Real amount = gh_scm2double (gh_cdar (autos));
+
+ if (!done.find_l (s))
+ s->translate_axis (amount * wid, X_AXIS);
}
}
/** This complicated routine moves note columns around horizontally to
ensure that notes don't clash.
- This should be done better, probably.
-
+ This should be put into Scheme.
*/
-Array< Shift_tup >
-Collision::automatic_shift ()
+SCM
+Collision::automatic_shift (Score_element *me)
{
Drul_array<Link_array<Note_column> > clash_groups;
Drul_array<Array<int> > shifts;
- Array<Shift_tup> tups;
-
+ SCM tups = SCM_EOL;
- SCM s = get_elt_property ("elements");
+ SCM s = me->get_elt_pointer ("elements");
for (; gh_pair_p (s); s = gh_cdr (s))
{
SCM car = gh_car (s);
for (int i=0; i < clashes.size (); i++)
{
SCM sh
- = clashes[i]->remove_elt_property ("horizontal-shift");
+ = clashes[i]->get_elt_property ("horizontal-shift");
if (gh_number_p (sh))
shift.push (gh_scm2int (sh));
{
for (int i=0; i < clash_groups[d].size (); i++)
{
- Slice s(clash_groups[d][i]->head_positions_interval ());
+ Slice s(Note_column::head_positions_interval (clash_groups[d][i]));
s[LEFT] --;
s[RIGHT]++;
extents[d].push (s);
Note_head * nu_l= cu_l->first_head();
Note_head * nd_l = cd_l->first_head();
- int downpos = cd_l->head_positions_interval ()[BIGGER];
- int uppos = cu_l->head_positions_interval ()[SMALLER];
+ int downpos = Note_column::head_positions_interval (cd_l)[BIGGER];
+ int uppos = Note_column::head_positions_interval (cu_l)[SMALLER];
bool merge =
downpos == uppos
&& nu_l->balltype_i () == nd_l->balltype_i ();
- if (!to_boolean (get_elt_property ("merge-differently-dotted")))
+ if (!to_boolean (me->get_elt_property ("merge-differently-dotted")))
merge = merge && nu_l->dot_count () == nd_l->dot_count ();
/*
do
{
for (int i=0; i < clash_groups[d].size (); i++)
- tups.push (Shift_tup (clash_groups[d][i], offsets[d][i]));
+ tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm_, gh_double2scm (offsets[d][i])),
+ tups);
}
while (flip (&d) != UP);
return tups;
}
-Array <Shift_tup>
-Collision::forced_shift ()
+SCM
+Collision::forced_shift (Score_element *me)
{
- Array<Shift_tup> tups;
+ SCM tups = SCM_EOL;
- SCM s = get_elt_property ("elements");
+ SCM s = me->get_elt_pointer ("elements");
for (; gh_pair_p (s); s = gh_cdr (s))
{
- Score_element * se = unsmob_element ( gh_car (s));
+ Score_element * se = unsmob_element (gh_car (s));
SCM force = se->remove_elt_property ("force-hshift");
if (gh_number_p (force))
{
- tups. push (Shift_tup (se, gh_scm2double (force)));
+ tups = gh_cons (gh_cons (se->self_scm_, force),
+ tups);
}
}
return tups;
+Collision::Collision (Score_element* c)
+{
+ elt_l_ = c;
+}