X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fcollision.cc;h=8d1f6d1232ca0fa1d63cce82821b665af6be83db;hb=9661ba1fb275f3e14f8a69f2cee2f02a2f893e48;hp=6da2f27f8de99dbf340395a82afd998317df4f07;hpb=07d4d05df6479d58c3c5152c07d7c86b94ee98b4;p=lilypond.git diff --git a/lily/collision.cc b/lily/collision.cc index 6da2f27f8d..8d1f6d1232 100644 --- a/lily/collision.cc +++ b/lily/collision.cc @@ -3,69 +3,92 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1999 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ #include "debug.hh" #include "collision.hh" #include "note-column.hh" -#include "note-head.hh" +#include "rhythmic-head.hh" #include "paper-def.hh" -#include "ly-symbols.hh" -#include "tuple.hh" +#include "axis-group-interface.hh" +#include "item.hh" -Collision::Collision() +void +Collision::add_column (Score_element*me,Score_element* ncol_l) { - set_axes (X_AXIS, Y_AXIS); + ncol_l->add_offset_callback (force_shift_callback, X_AXIS); + Axis_group_interface::add_element (me, ncol_l); + me->add_dependency (ncol_l); } -void -Collision::add_column (Note_column* ncol_l) +Real +Collision::force_shift_callback (Score_element * c, Axis a) { - clash_l_arr_.push (ncol_l); - 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_property ("done"))) + { + me->set_elt_property ("done", me->self_scm_); + do_shifts (me); + } + + return 0.0; } +/* + TODO: make callback of this. + */ void -Collision::do_pre_processing() +Collision::do_shifts(Score_element* me) { - Array autos (automatic_shift ()); - Array hand (forced_shift ()); - Link_array done; + SCM autos (automatic_shift (me)); + SCM hand (forced_shift (me)); - Real wid = paper_l ()->note_width (); - for (int i=0; i < hand.size (); i++) + Link_array done; + + 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. - - TODO: forced hshift - + This should be put into Scheme. */ -Array< Shift_tup > -Collision::automatic_shift () +SCM +Collision::automatic_shift (Score_element *me) { - Drul_array > clash_groups; + Drul_array > clash_groups; Drul_array > shifts; - Array tups; + SCM tups = SCM_EOL; - - for (int i=0; i < clash_l_arr_.size(); i++) + SCM s = me->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::has_interface (se)) + clash_groups[Note_column::dir (se)].push (se); } @@ -73,26 +96,26 @@ Collision::automatic_shift () do { Array & shift (shifts[d]); - Link_array & clashes (clash_groups[d]); + Link_array & clashes (clash_groups[d]); clashes.sort (Note_column::shift_compare); for (int i=0; i < clashes.size (); i++) { SCM sh - = clashes[i]->remove_elt_property (horizontal_shift_scm_sym); + = clashes[i]->get_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.")); + warning (_ ("Too many clashing notecolumns. Ignoring them.")); return tups; } } @@ -106,7 +129,7 @@ Collision::automatic_shift () { 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); @@ -134,17 +157,26 @@ Collision::automatic_shift () all of them again. */ if (extents[UP].size () && extents[DOWN].size ()) { - 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]; + Score_element *cu_l =clash_groups[UP][0]; + Score_element *cd_l =clash_groups[DOWN][0]; + + + /* + TODO. + */ + Score_element * nu_l= Note_column::first_head(cu_l); + Score_element * nd_l = Note_column::first_head(cd_l); + + 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_ - && nu_l->dots_i () == nd_l->dots_i (); + && Rhythmic_head::balltype_i (nu_l) == Rhythmic_head::balltype_i (nd_l); + + + if (!to_boolean (me->get_elt_property ("merge-differently-dotted"))) + merge = merge && Rhythmic_head::dot_count (nu_l) == Rhythmic_head::dot_count (nd_l); /* notes are close, but can not be merged. Shift @@ -160,43 +192,36 @@ Collision::automatic_shift () while ((flip (&d))!= UP); } - 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 -Collision::forced_shift () +SCM +Collision::forced_shift (Score_element *me) { - Array tups; + SCM tups = SCM_EOL; - for (int i=0; i < clash_l_arr_.size (); i++) + SCM s = me->get_elt_property ("elements"); + for (; gh_pair_p (s); s = gh_cdr (s)) { - SCM force = clash_l_arr_[i]->remove_elt_property (force_hshift_scm_sym); - if (force != SCM_BOOL_F) + Score_element * se = unsmob_element (gh_car (s)); + + SCM force = se->remove_elt_property ("force-hshift"); + if (gh_number_p (force)) { - force = SCM_CDR (force); - tups. push (Shift_tup (clash_l_arr_[i], - gh_scm2double (force))); + tups = gh_cons (gh_cons (se->self_scm_, force), + tups); } } return tups; } -void -Collision::do_substitute_element_pointer (Score_element*o_l,Score_element*n_l) -{ - if (o_l) - { - clash_l_arr_.substitute (dynamic_cast (o_l), - dynamic_cast (n_l)); - } -}