source file of the GNU LilyPond music typesetter
- (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include "debug.hh"
#include "collision.hh"
#include "note-column.hh"
#include "note-head.hh"
#include "paper-def.hh"
-#include "ly-symbols.hh"
+#include "axis-group-interface.hh"
+
Collision::Collision()
{
- set_axes (X_AXIS, Y_AXIS);
+ Axis_group_interface (this).set_interface ();
+ Axis_group_interface (this).set_axes (X_AXIS, Y_AXIS);
}
void
Collision::add_column (Note_column* ncol_l)
{
- clash_l_arr_.push (ncol_l);
- add_element (ncol_l);
+ Axis_group_interface (this).add_element (ncol_l);
add_dependency (ncol_l);
}
+void
+Collision::before_line_breaking ()
+{
+ SCM autos (automatic_shift ());
+ SCM hand (forced_shift ());
+ Link_array<Score_element> done;
+
+ Real wid = paper_l ()->get_var ("collision_note_width");
+ for (; gh_pair_p (hand); hand =gh_cdr (hand))
+ {
+ 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 (; gh_pair_p (autos); autos =gh_cdr (autos))
+ {
+ 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.
- TODO: forced hshift
-
*/
-void
-Collision::do_pre_processing()
+SCM
+Collision::automatic_shift ()
{
Drul_array<Link_array<Note_column> > clash_groups;
Drul_array<Array<int> > shifts;
-
- for (int i=0; i < clash_l_arr_.size(); i++)
+ SCM tups = SCM_EOL;
+
+ SCM s = get_elt_property ("elements");
+ for (; gh_pair_p (s); s = gh_cdr (s))
{
- clash_groups[clash_l_arr_[i]->dir ()].push (clash_l_arr_[i]);
+ SCM car = gh_car (s);
+
+ Score_element * se = unsmob_element (car);
+ if (Note_column * col = dynamic_cast<Note_column*> (se))
+ clash_groups[col->dir ()].push (col);
}
for (int i=0; i < clashes.size (); i++)
{
SCM sh
- = clashes[i]->remove_elt_property (horizontal_shift_scm_sym);
+ = clashes[i]->remove_elt_property ("horizontal-shift");
- if (sh == SCM_BOOL_F)
- shift.push (0);
+ if (gh_number_p (sh))
+ shift.push (gh_scm2int (sh));
else
- shift.push (gh_scm2int (SCM_CDR (sh)));
+ shift.push (0);
}
for (int i=1; i < shift.size (); i++)
{
if (shift[i-1] == shift[i])
{
- warning (_ ("Too many clashing notecolumns. Ignoring them."));
- return;
+ warning (_ ("Too many clashing notecolumns. Ignoring them."));
+ return tups;
}
}
}
{
Note_column *cu_l =clash_groups[UP][0];
Note_column *cd_l =clash_groups[DOWN][0];
- Note_head * nu_l= cu_l->head_l_arr_[0];
- Note_head * nd_l = cd_l->head_l_arr_.top();
- int downpos = cd_l->head_positions_interval ()[BIGGER];
- int uppos = cu_l->head_positions_interval ()[SMALLER];
+
+
+ /*
+ TODO.
+ */
+ 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];
bool merge =
downpos == uppos
- && nu_l->balltype_i_ == nd_l->balltype_i_
- && nu_l->dots_i_ == nd_l->dots_i_;
+ && nu_l->balltype_i () == nd_l->balltype_i ();
+
+
+ if (!to_boolean (get_elt_property ("merge-differently-dotted")))
+ merge = merge && nu_l->dot_count () == nd_l->dot_count ();
/*
notes are close, but can not be merged. Shift
}
while ((flip (&d))!= UP);
}
+
do
{
for (int i=0; i < clash_groups[d].size (); i++)
- {
- SCM force = clash_groups[d][i]->remove_elt_property (force_hshift_scm_sym);
- if (force != SCM_BOOL_F)
- {
- force = SCM_CDR (force);
- offsets[d][i] = gh_scm2double (force);
- }
- }
- }
- while ((flip (&d))!= UP);
-
- Real wid_f = paper_l ()->note_width ();
- do
- {
- for (int i=0; i < clash_groups[d].size (); i++)
- {
- clash_groups[d][i]->translate_axis (offsets[d][i]*wid_f, X_AXIS);
- }
+ tups = gh_cons (gh_cons (clash_groups[d][i]->self_scm_, gh_double2scm (offsets[d][i])),
+ tups);
}
while (flip (&d) != UP);
+ return tups;
}
-void
-Collision::do_substitute_element_pointer (Score_element*o_l,Score_element*n_l)
+SCM
+Collision::forced_shift ()
{
- if (o_l)
+ SCM tups = SCM_EOL;
+
+ SCM s = get_elt_property ("elements");
+ for (; gh_pair_p (s); s = gh_cdr (s))
{
- clash_l_arr_.substitute (dynamic_cast<Note_column *> (o_l),
- dynamic_cast <Note_column *> (n_l));
+ Score_element * se = unsmob_element ( gh_car (s));
+ SCM force = se->remove_elt_property ("force-hshift");
+ if (gh_number_p (force))
+ {
+ tups = gh_cons (gh_cons (se->self_scm_, force),
+ tups);
+ }
}
+ return tups;
}
+
+
+